Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade to babel@7 #1043

Merged
merged 6 commits into from
Oct 24, 2018
Merged

Upgrade to babel@7 #1043

merged 6 commits into from
Oct 24, 2018

Conversation

Andarist
Copy link
Contributor

@Andarist Andarist commented Oct 10, 2018

Obviously I can't be 100% sure if this covers everything - I'd appreciate review on that. I've check build + tests and they seems to work fine.

I'd also like to get your opinion on 1 thing as it stays unfinished. Currently each test for eact versions runs ALL versions instead of a specific one. We can fix it in 2 ways:

  • make each test script run only test files in specific directory
  • run tests from all directories in a single jest process

Which one do you prefer? (I would argue latter is better, simpler & coverage might be collected to a single file)

@netlify
Copy link

netlify bot commented Oct 10, 2018

Deploy preview for react-redux-docs ready!

Built with commit 65af5d9

https://deploy-preview-1043--react-redux-docs.netlify.com

@markerikson
Copy link
Contributor

@cellog , any thoughts on the test setup stuff?

@cellog
Copy link
Contributor

cellog commented Oct 13, 2018

Sorry I've been awol, things are still going to keep me away for a couple more weeks. If there is a specific thing I can look at quickly, feel free to ping me on Discord and I'll comment here

@Andarist
Copy link
Contributor Author

@cellog you can skip the code changes and just read the description of this PR

@cellog
Copy link
Contributor

cellog commented Oct 15, 2018

The point is to run tests against all versions of React supported by react-redux. So this should remain unchanged. Coverage is generated for all, and codecov just picks up one of them automatically. Since we don't have code that runs differently in different versions, it doesn't really matter. But running against all versions does. 5.1.0-test-1 broke prior to this because it wasn't possible to test against other versions.

Thus, you can't run them in a single jest process, as it would require unloading/reloading react (which isn't possible)

@cellog
Copy link
Contributor

cellog commented Oct 15, 2018

P.S. thank you for this contribution! (should have said that first). Looks great, I think (on a cursory visual scan)

@Andarist
Copy link
Contributor Author

Thus, you can't run them in a single jest process, as it would require unloading/reloading react (which isn't possible)

I wasnt talking about restructuring how tests are written now. It's possible (I think) to rung them all in a single process as each test directory (one per react version) has its own react version located in its node_modules, so each test should find correct (local~) react version. I'll give it a try to showcase what I'm talking about.

@cellog
Copy link
Contributor

cellog commented Oct 15, 2018

Hi again. Actually, my first attempt to write this did exactly what you suggested. Perhaps jest 26 is different, but with 24, it would always load react from the global package.json. Then, when loading enzyme (which we used at the time) it would error out in weird ways. I couldn't convince jest to load the local package versions of dependencies of the packages in the local package.json (I think: memory is foggy on exact details of the error). In essence it's npm's cute little version of Windows 3.1 DLL hell :).

FYI, it is possible to run only one react version using:

REACT=16.4 npm test

For example. Would that solve the issue you're experiencing?

@cellog
Copy link
Contributor

cellog commented Oct 15, 2018

Incidentally, we need to add 16.5 as a test version, if anyone is up to it

@Andarist
Copy link
Contributor Author

Andarist commented Oct 15, 2018

I've tweaked the PR - it's still possible to run tests against a single version of react, but tests for all versions are ran within single jest process (coverage is collected only from a single version) - this might be slightly faster as we dont have to spawn X processes, one after another. The bigger gain is that watch mode might be used slightly more efficiently. I understand that we copy both source and test files to version directories, so it's not ideal as changes in true sources & tests wont be reflected, but its still better than before as we can edit files contained in any directory within a single watch process.

I've confirmed that tests are not ran against a single react version - each directory requires its own version of react.

Additionally I've added tests against react@16.5 as requested.

@@ -0,0 +1,7 @@
import enzyme from 'enzyme'
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this seems like leftover from refactoring fro menzyme to react-testing-library, should I remove all those files (they are in each, or most, directories)?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, references to them were removed in #998.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, looks like that removed the react/${version}/test/ directory, which is needed. Can you add empty .keep files back to keep the dirs in git, or add something to the install script to create them?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

// every directory has the same coverage, so we collect it only from one
collectCoverageFrom: [`react/${LATEST_VERSION}/src/**.js`]
}
npmRun.execSync(`node ./node_modules/.bin/jest -c '${JSON.stringify(allVersionsConfig)}'`, { stdio: 'inherit' })
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it seems to me that node ./node_modules/.bin/jest can be used when testing a specific version too, combining this with rootDir option would allow us to remove usage of npm-run here, removing cd dance & removing 'artificial' test scripts from nested package.jsons

WDYT?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

First, if we're using npm-run, then this should just be jest -c .... That module automatically adds the .bin dir to the PATH.

We could actually make use of jest --projects in this case. That might be easier, as each version of React would be testable in isolation and without as much tooling.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

First, if we're using npm-run, then this should just be jest -c .... That module automatically adds the .bin dir to the PATH.

Cool, didnt know that - gonna chang it in a minute.

We could actually make use of jest --projects in this case. That might be easier, as each version of React would be testable in isolation and without as much tooling.

I thought about it, but I think that would require keeping a copy of the jest config per each react version and is IMHO annoying in a long run (when it needs updating).

Also I wasnt sure how to collect coverage in --projects case as we wont to collect it only from a single project.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Damn, it doesn't do per-project coverage? That seems like an oversight.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess it might have, we just have exactly the same coverage here per project as noticed by @cellog. I guess overcollecting the coverage doesnt do us harm, but im not sure how CI takes the coverage for its report. Is the path configurable? Gonna look into that later as im on the mobile right now. If its configurable then i guess we might just point to the latest react directory and be done with it (leting jest collect in each directory).

There is still an issue of having to duplicate jest config all over the place though (if u want to use the projects feature)

Copy link
Member

@timdorr timdorr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

@Andarist
Copy link
Contributor Author

@markerikson any thoughts? :)

@timdorr
Copy link
Member

timdorr commented Oct 24, 2018

I'm pretty content with just merging this in. The conflicts for #995 and #1000 should be relatively minimal and easily resolved.

So, I'll do that now :)

@timdorr timdorr merged commit 2093fbb into reduxjs:master Oct 24, 2018
@Andarist Andarist deleted the babel7 branch October 24, 2018 19:04
@Andarist
Copy link
Contributor Author

Cool, thanks!

albertodev7 pushed a commit to albertodev7/react-redux that referenced this pull request Dec 8, 2022
* Upgrade to babel@7

* Run tests for all versions of React in a single jest process

* Add tests against react@16.5

* Simplify test script

* Remove unused getTestDeps.js files & adjusted CONTRIBUTING.md info

* Create test directories if they are missing
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants