-
-
Notifications
You must be signed in to change notification settings - Fork 5.8k
Migrate tests to Jest #5359
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
Migrate tests to Jest #5359
Conversation
|
@montogeek, thanks for your PR! By analyzing the history of the files in this pull request, we identified @ChauTNguyen, @motiz88 and @hzoo to be potential reviewers. |
|
I think if we want to add |
|
@montogeek I have not seen that this is PR in 7.0 =) |
|
Hey @montogeek! It looks like one or more of your builds have failed. I've copied the relevant info below to save you some time. |
package.json
Outdated
| "gulp-util": "^3.0.7", | ||
| "gulp-watch": "^4.3.5", | ||
| "lerna": "2.0.0-beta.37", | ||
| "lerna": "2.0.0-beta.23", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why the rollback?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From the PR description:
lerna version was reverted to 2.0.0-beta.23 to make relative requires work, not sure what it is necessary to make it work with latest beta release.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this mean that it started failing at beta.24?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@hzoo Didn't try every beta, will try later what version make it fails
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@hzoo It definitely breaks with v2.0.0-beta.28, in v2.0.0-beta.27 works
| t.toStatement(node); | ||
| }); | ||
| assert.strictEqual(t.toStatement(node, /* ignore = */ true), false); | ||
| }).toThrow(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would be nice to specify what should be thrown (jest can take in a constructor (for instanceof check), string or regexp), but that definitely should be done in a later PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agree
| testContext.global = testContext; | ||
|
|
||
| const jest = {}; | ||
| jest.expect = global.expect; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not adding expect to the testContext?
It would also be really nice to get describe/it working inside the exec fixtures, but that would need a significant rework of how they are written.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this assignment necessary here? Why wouldn't you just use expect instead of jest.expect?
Also you can remove chai from imports.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@thymikee Because expect is used in the code: https://github.com/babel/babel/pull/5359/files/e6ed1494d94cae8094b890ebe93cbe46f5ec4718#diff-37b0c62f94b613936e9195f14a3320aeR123
I can't remove chai because is still used, but maybe we can't remove the vm stuff, I'm investigating it
.eslintrc
Outdated
| "node": true, | ||
| "mocha": true | ||
| "jest": true, | ||
| "jasmine": true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we need Jasmine? Isn't this: https://facebook.github.io/jest/docs/setup-teardown.html#scoping the reason why you would actually want Jasmine?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can remove this, I added is because this reason:
Previously a timeout of 10 seconds was set globally for all tests, I moved it locally to just babel-cli tests: https://github.com/babel/babel/compare/7.0...montogeek:feat/migrate-test-to-jest?expand=1#diff-ab3a365851f93959d9be46529b9b1500R147
But I made that config global and forgot to change it, thanks for pointing it out!
|
Hey @montogeek! It looks like one or more of your builds have failed. I've copied the relevant info below to save you some time. |
test/testSetupFile.js
Outdated
| @@ -0,0 +1 @@ | |||
| jasmine.DEFAULT_TIMEOUT_INTERVAL = 70000; No newline at end of file | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a reason why this is set to 70000? If I understand it correctly, previously in Mocha it was set to 10000.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To try to make run tests on CI
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On my Mac, tests run within 10000
|
I do not have a lot of experience with Bash, but if somebody does and have a better way to handle this: e989503 Please do |
aaronang
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
By any chance, do you maybe an idea why the tests have to be run sequentially instead of parallel on Travis?
.travis.yml
Outdated
| script: | ||
| - 'if [ "$JOB" = "test" ]; then make test-ci; fi' | ||
| - 'if [ "$JOB" = "test-coverage" ]; then make test-ci-coverage; fi' | ||
| - 'if [ "$JOB" = "test" ]; then CI=true make test-ci; fi' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You don't need to pass CI as a variable because it is set by Travis by default: https://docs.travis-ci.com/user/environment-variables/#Default-Environment-Variables.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh! Thanks, they have to run sequentially because Travis machine resources are limited, by default Jest spawn child processes that consume more resources
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
By any chance, do you maybe an idea why the tests have to be run sequentially instead of parallel on Travis?
It's because most CI services don't handle parallel test runs well. You can read more about this in Jest's doc on Troubleshooting CI
| }); | ||
|
|
||
| test("label", function () { | ||
| it("label", function () { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Jest supports either test or it so this is unnecessary (unless you like it better 👍)
scripts/test-cov.sh
Outdated
| runSequentially="" | ||
|
|
||
| if [ "$CI" ]; then | ||
| runSequentially="--i" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure why this works, but technically it should be either --runInBand or -i.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are right. If I may, in addition, I would suggest using --runInBand because it might be more self-explanatory than the alias -i.
scripts/test.sh
Outdated
|
|
||
| $node node_modules/mocha/bin/_mocha `scripts/_get-test-directories.sh` --opts test/mocha.opts --grep "$TEST_GREP" | ||
| if [ "$CI" ]; then | ||
| runSequentially="--i" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here
|
Great work. Out of curiosity, did you use Jeat Codemods? https://github.com/skovhus/jest-codemods The codemod should be able to handle most of this. And if not, then let me know. : ) |
|
Ouch, ran straight into jestjs/jest#1652 when trying to debug this :( |
|
Followed immediately by node-inspector/node-inspector#905 :( |
|
Hey @montogeek! It looks like one or more of your builds have failed. I've copied the relevant info below to save you some time. |
|
Hey @loganfsmyth! It looks like one or more of your builds have failed. I've copied the relevant info below to save you some time. |
|
I pushed a new commit to try something, but it looks like an unrelated issue caused some failures. |
|
Hey @loganfsmyth! It looks like one or more of your builds have failed. I've copied the relevant info below to save you some time. |
|
@montogeek I did my best, I have no idea why it's running out of memory now. It passes in parallel but I think running with |
|
@loganfsmyth can you try using Jest from master? We had an issue with babel-polyfill (which jest was auto requiring if found) causing memory leaks, and forgot to merge the fix into v19. It will be available in v19.1 which should happen this week |
|
@thymikee How can I install Jest from master? Since it is a Lerna repo, I can't just do |
|
Setting this directly in package.json doesn't work? |
|
It does, I ran |
|
Let's wait to 19.1 then |
|
jest@next was tagged. |
|
I have to admit I'm very concerned with this PR because of the debugging issues in #5359 (comment). I use |
|
There is a third party module |
|
It seems like everybody is on board with this change; Jest 20 just came out with a ton of new features. @montogeek, are you planning on bringing this over the finish line? :) |
|
@cpojer I do, will take a look today! |
|
Can we close this in favor of #6179? It includes @montogeek work. |
Closes #5197
Migrated tests infrastructure from Mocha to Jest 19.
All tests pass locally:
Test Suites: 86 passed, 86 total Tests: 7 skipped, 1720 passed, 1727 total Snapshots: 0 total Time: 92.977s Ran all test suites.Previously a timeout of 10 seconds was set globally for all tests, I moved it locally to just
babel-clitests: https://github.com/babel/babel/compare/7.0...montogeek:feat/migrate-test-to-jest?expand=1#diff-ab3a365851f93959d9be46529b9b1500R147Migrated
babel-helper-transform-fixture-test-runnerto use Jest as well since it is used as a test utility.lernaversion was reverted to2.0.0-beta.23to make relativerequires work, not sure what it is necessary to make it work with latest beta release.There is more work to do, delete all Mocha related code, update Makefile, etc. I wanted to submit it to see I am doing things right