Skip to content

[Proposal] Use Jest with Mocha Runner#6442

Closed
rogeliog wants to merge 5 commits intobabel:masterfrom
rogeliog:jest-runner-mocha
Closed

[Proposal] Use Jest with Mocha Runner#6442
rogeliog wants to merge 5 commits intobabel:masterfrom
rogeliog:jest-runner-mocha

Conversation

@rogeliog
Copy link
Copy Markdown

@rogeliog rogeliog commented Oct 7, 2017

Q                       A
Fixed Issues?
Patch: Bug Fix?
Major: Breaking Change?
Minor: New Feature?
Tests Added + Pass? 👍
Documentation PR
Any Dependency Changes? 👍

This is just a proposal, and I completely understand if you don't want to move forward with this, or if it does not align with the direction of the project.

Jest 21 comes with support for custom runners, jest-runner-mocha enables a Mocha code base to run on Jest.

  • Allows the codebase to start using Jest as a test runner, while still use Mocha as a test framework
  • Once Jest is being used as a test runner, we could add multiple --projects and slowly migrate the tests to use Jest as a test framework jest --projects jest-mocha.config.js jest.config.js
  • Requires minimal code changes
  • I've seen this WIP: Migrate to jest #6179, which I hope that this proposal would help as a stepping stone for it.
  • It reduces the total test run time 😄

Pending Items

  • Use Jest in the package.json scripts
  • Remove unused files as a result of this change
  • Remove any unused dependencies as a result of this change
  • Enable jest --coverage... This should not be that much trouble, it already works with other codebases, but I think it there are some caveats with to make it work with Babel 7
  • Reenable skipped tests... I was having some trouble with two tests in packages/babel-register/test/index.js

screen shot 2017-10-07 at 3 48 12 pm

screen shot 2017-10-07 at 3 48 41 pm

Thanks for everything!

@Andarist
Copy link
Copy Markdown
Member

Andarist commented Oct 7, 2017

Im new to the project, cant speak for others. From my perspective it would be really great to migrate to jest and eventually leverage its snapshots feature with the interactive mode.

@babel-bot
Copy link
Copy Markdown
Collaborator

babel-bot commented Oct 7, 2017

Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/6961/

"eslint --format=codeframe --rulesdir='./scripts/eslint_rules'"
]
},
"jest": {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

wouldn't we need to alias packages/* to their respective src directories to have a great watch mode?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

I think I'm missing something, because I'm not sure that I understood that

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Sorry if I was not clear. The source code in packages gets transpiled in a build step, to have great save+watch tests experience I think it would be better to integrate transpiling into jest, rather than run separate build with watch mode.

Because packages are linked and treated as regular npm dependencies, the regular node's dependency algorithm kicks in and jest will search for the built files rather than source ones.

@hzoo
Copy link
Copy Markdown
Member

hzoo commented Oct 8, 2017

This is just a proposal, and I completely understand if you don't want to move forward with this, or if it does not align with the direction of the project.

@rogeliog thanks for the PR (and appreciate you opening it as a proposal)! This is really cool, and since it's small easier to review 👌

I've seen this #6179, which I hope that this proposal would help as a stepping stone for it.

Yeah that got blocked/delayed a few times 😄 so this could definetely be a great way to switch over. Babel basically has it's own version of a lot of the tooling and even though it's not really an issue most of the time it would be nice to remove a lot of the code we have to handle testing (own our fixture setup -> snapshots assuming they work well enough).

It reduces the total test run time

The last time we tried this it seemed really slow and we weren't sure why, if that's not the case anymore then great. (make test-only current is 50s-1min on my machine)


If we could remove https://github.com/babel/babel/blob/master/scripts/test.sh, https://github.com/babel/babel/blob/master/scripts/_get-test-directories.sh,
https://github.com/babel/babel/tree/master/packages/babel-helper-plugin-test-runner
https://github.com/babel/babel/tree/master/packages/babel-helper-transform-fixture-test-runner

Assuming jest + maybe something like https://github.com/babel-utils/babel-plugin-tester can cover those, would like to use a better watch mode than what we say in https://github.com/babel/babel/blob/master/CONTRIBUTING.md#running-lintingtests. And we don't have the easier setup in updated fixtures without just rm the files

@rogeliog
Copy link
Copy Markdown
Author

rogeliog commented Oct 8, 2017

Time comparison on my machine:

Before:

screen shot 2017-10-08 at 11 27 19 am

After:

screen shot 2017-10-08 at 2 19 00 pm

NOTE: Running with Jest is resulting in 68 tests that it is still not picking up, I'll need to investigate that.

Yes I think we could remove https://github.com/babel/babel/blob/master/scripts/test.sh and https://github.com/babel/babel/blob/master/scripts/_get-test-directories.sh...

For https://github.com/babel/babel/tree/master/packages/babel-helper-plugin-test-runner and
https://github.com/babel/babel/tree/master/packages/babel-helper-transform-fixture-test-runner I think that would need to happen until tests are being run by Jest.

Which by the way you could run full Jest tests and (Mocha + Jest) tests at the same time jest --projects and slowly migrate all of them or whatever it the best path for it.

I think that the watcher would still need to be run cross package linking.

@xtuc xtuc added area: tests PR: Internal 🏠 A type of pull request used for our changelog categories labels Oct 9, 2017
package.json Outdated
"jest": {
"runner": "jest-runner-mocha",
"testMatch": [
"<rootDir>/packages/**/test/*.js"
Copy link
Copy Markdown
Member

@existentialism existentialism Oct 9, 2017

Choose a reason for hiding this comment

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

Should include codemods/. (experimental/ as well, though babel-preset-env will need a bit of work to work with jest, I imagine... can do that in a followup PR).

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Just FYI, now, the experimental doesn't exists anymore. Only codemods must be included here.

const DATA_ES2015 = require.resolve("./__data__/es2015");

describe("babel-register", function() {
xdescribe("babel-register", function() {
Copy link
Copy Markdown
Member

@danez danez Oct 13, 2017

Choose a reason for hiding this comment

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

So the babel-register test also don't work with jest-mocha-runner? That was the biggest blocker for the other PR because there is no way in jest to test require hooks.

So we would either need to make a special case for these tests and not run them with jest or stay with mocha/ava.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I'm fine with doing a special case for this if we want to use jest

@xtuc
Copy link
Copy Markdown
Member

xtuc commented Feb 23, 2018

Could you please include the codemods folder in the tests?

@hzoo
Copy link
Copy Markdown
Member

hzoo commented Feb 23, 2018

I think we can just rebase and land this ourselves if we are good

@rogeliog
Copy link
Copy Markdown
Author

rogeliog commented Feb 25, 2018

@hzoo Perfect! I'm working on rebasing it today, and but there are some issues with one test. I'll try to have something up by today/tomorrow

@hzoo
Copy link
Copy Markdown
Member

hzoo commented Feb 25, 2018

Sorry for the delays again! Even suggested if someone had time we could instead of you 😁. Thanks again

@rogeliog
Copy link
Copy Markdown
Author

I'm more than happy to get this to a point where is mergable! I just pushed after rebasing, I need to step away from my computer today, but I'll keep working on it tomorrow

@danez danez mentioned this pull request Feb 28, 2018
@rogeliog
Copy link
Copy Markdown
Author

Closing in favor of #7455

@rogeliog rogeliog closed this Feb 28, 2018
@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

area: tests 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.

8 participants