[Proposal] Use Jest with Mocha Runner#6442
Conversation
e45e795 to
774365f
Compare
|
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. |
|
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": { |
There was a problem hiding this comment.
wouldn't we need to alias packages/* to their respective src directories to have a great watch mode?
There was a problem hiding this comment.
I think I'm missing something, because I'm not sure that I understood that
There was a problem hiding this comment.
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.
@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 👌
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).
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. ( 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, 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 |
|
Time comparison on my machine: Before:After: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 Which by the way you could run full Jest tests and (Mocha + Jest) tests at the same time I think that the watcher would still need to be run cross package linking. |
package.json
Outdated
| "jest": { | ||
| "runner": "jest-runner-mocha", | ||
| "testMatch": [ | ||
| "<rootDir>/packages/**/test/*.js" |
There was a problem hiding this comment.
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).
There was a problem hiding this comment.
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() { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
I'm fine with doing a special case for this if we want to use jest
|
Could you please include the |
|
I think we can just rebase and land this ourselves if we are good |
|
@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 |
|
Sorry for the delays again! Even suggested if someone had time we could instead of you 😁. Thanks again |
|
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 |
|
Closing in favor of #7455 |


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.
--projectsand slowly migrate the tests to use Jest as a test frameworkjest --projects jest-mocha.config.js jest.config.jsPending Items
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 7packages/babel-register/test/index.jsThanks for everything!