Skip to content

Conversation

@montogeek
Copy link

@montogeek montogeek commented Feb 22, 2017

Closes #5197

Q A
Patch: Bug Fix? No
Major: Breaking Change? No
Minor: New Feature? Yes
Deprecations? No
Spec Compliancy? Yes
Tests Added/Pass? Yes
Fixed Tickets Fixes #5197
License MIT
Doc PR No
Dependency Changes Yes

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-cli tests: https://github.com/babel/babel/compare/7.0...montogeek:feat/migrate-test-to-jest?expand=1#diff-ab3a365851f93959d9be46529b9b1500R147

Migrated babel-helper-transform-fixture-test-runner to use Jest as well since it is used as a test utility.

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 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

@mention-bot
Copy link

@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.

@oleksandr-kuzmenko
Copy link
Contributor

I think if we want to add yarn.lock we all should to start using yarn. This is a good idea, as for me. But then we have to edit Makefile and CONTRIBUTING.md. I think this is better done through a separate PR. I could do this.

@montogeek
Copy link
Author

@oleksandr-kuzmenko
Copy link
Contributor

oleksandr-kuzmenko commented Feb 22, 2017

@montogeek I have not seen that this is PR in 7.0 =)
maybe it's worth to rename PR? [7.0] Migrate tests to Jest

@babel-bot
Copy link
Collaborator

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.

@existentialism existentialism added PR: Internal 🏠 A type of pull request used for our changelog categories WIP labels Feb 23, 2017
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",
Copy link
Member

Choose a reason for hiding this comment

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

Why the rollback?

Copy link
Author

@montogeek montogeek Feb 23, 2017

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.

Copy link
Member

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?

Copy link
Author

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

Copy link
Author

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();
Copy link
Member

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.

Copy link
Author

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;
Copy link
Member

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.

Copy link
Contributor

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.

Copy link
Author

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
Copy link
Member

@aaronang aaronang Feb 23, 2017

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?

Copy link
Author

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!

@babel-bot
Copy link
Collaborator

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.

@@ -0,0 +1 @@
jasmine.DEFAULT_TIMEOUT_INTERVAL = 70000; No newline at end of file
Copy link
Member

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.

Copy link
Author

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

Copy link
Author

@montogeek montogeek Feb 23, 2017

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

@montogeek
Copy link
Author

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

Copy link
Member

@aaronang aaronang left a 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'
Copy link
Member

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.

Copy link
Author

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

Copy link
Contributor

@thymikee thymikee Feb 23, 2017

Choose a reason for hiding this comment

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

@aaronang

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 () {
Copy link
Contributor

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 👍)

runSequentially=""

if [ "$CI" ]; then
runSequentially="--i"
Copy link
Contributor

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.

Copy link
Member

@aaronang aaronang Feb 23, 2017

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"
Copy link
Contributor

Choose a reason for hiding this comment

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

Same here

@skovhus
Copy link

skovhus commented Feb 24, 2017

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. : )

@loganfsmyth
Copy link
Member

Ouch, ran straight into jestjs/jest#1652 when trying to debug this :(

@loganfsmyth
Copy link
Member

Followed immediately by node-inspector/node-inspector#905 :(

@babel-bot
Copy link
Collaborator

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.

@babel-bot
Copy link
Collaborator

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.

@loganfsmyth
Copy link
Member

I pushed a new commit to try something, but it looks like an unrelated issue caused some failures.

@babel-bot
Copy link
Collaborator

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.

@loganfsmyth
Copy link
Member

@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 -i it fails.

@thymikee
Copy link
Contributor

@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

@montogeek
Copy link
Author

montogeek commented Mar 15, 2017

@thymikee How can I install Jest from master? Since it is a Lerna repo, I can't just do yarn add -D https://github.com/facebook/jest#master

@thymikee
Copy link
Contributor

Setting this directly in package.json doesn't work?

"jest": "facebook/jest" 

@montogeek
Copy link
Author

It does, I ran yarn on node_modules/jest, the postinstall hook runs without problem, then I ran ./node_modules/jest/jest but it throws an error saying that cannot find jest-util module

@thymikee
Copy link
Contributor

Let's wait to 19.1 then

@cpojer
Copy link
Member

cpojer commented Mar 17, 2017

jest@next was tagged.

@loganfsmyth
Copy link
Member

I have to admit I'm very concerned with this PR because of the debugging issues in #5359 (comment). I use --inspect for all of my debugging these days, and falling back to node-inspector failed miserably for me.

@cpojer
Copy link
Member

cpojer commented Mar 17, 2017

There is a third party module jest-environment-node-debug which should work with --inspect until node/v8 finally implement --inspect for contexts. Currently they are blocked on the deprecation of the old debugger :(

@cpojer
Copy link
Member

cpojer commented May 11, 2017

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? :)

@montogeek
Copy link
Author

@cpojer I do, will take a look today!

@danez danez mentioned this pull request Aug 31, 2017
@danez danez closed this Aug 31, 2017
@danez danez reopened this Aug 31, 2017
@danez danez changed the base branch from 7.0 to master August 31, 2017 18:25
@xtuc
Copy link
Member

xtuc commented Sep 11, 2017

Can we close this in favor of #6179? It includes @montogeek work.

@jridgewell jridgewell closed this Sep 12, 2017
@montogeek montogeek deleted the feat/migrate-test-to-jest branch March 22, 2018 13:23
@lock lock bot added the outdated A closed issue/PR that is archived due to age. Recommended to make a new issue label Oct 5, 2019
@lock lock bot locked as resolved and limited conversation to collaborators Oct 5, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Has PR outdated A closed issue/PR that is archived due to age. Recommended to make a new issue PR: Internal 🏠 A type of pull request used for our changelog categories

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[7.0] Tests: switch to jest