Do you want to request a _feature_ or report a _bug_?
There seems to be a bug in jest 22 / babel-jest 22 where the config is not passed to babel-jest, so it fails when trying to access config.moduleFileExtensions on line 107 of node_modules/babel-jest/build/index.js
I modified that file to log what it was receiving for arguments in the process() call and only the first two args were passed in.
What is the current behavior?
All tests fail with error in preprocessor. My preprocess is a basic babel + webpack setup.
My preprocessor:
var config = require('../webpack.test.config.js');
var aliasPreprocessor = require('jest-alias-preprocessor')(config);
var babelJest = require('babel-jest');
module.exports = {
process: function(src, filename) {
if (filename.indexOf('node_modules') === -1) {
src = babelJest.process(src, filename);
src = aliasPreprocessor.process(src, filename);
}
return src;
},
};
The call to babel-jest fails:
FAIL src/plugins/foo.test.js
● Test suite failed to run
TypeError: Cannot read property 'moduleFileExtensions' of undefined
10 | process: function(src, filename) {
11 | if (filename.indexOf('node_modules') === -1) {
> 12 | src = babelJest.process(src, filename);
13 | src = aliasPreprocessor.process(src, filename);
14 | }
15 | return src;
at Object.process (node_modules/babel-jest/build/index.js:107:30)
at Object.process (test/preprocessor.js:12:29)
If the current behavior is a bug, please provide the steps to reproduce and
either a repl.it demo through https://repl.it/languages/jest or a minimal
repository on GitHub that we can yarn install and yarn test.
Reproduction repo: https://github.com/gricard/jest-preproc-bug-repro/
You can reproduce with this repo by running npm run test
What is the expected behavior?
Tests should run as they normally do.
Please provide your exact Jest configuration and mention your Jest, node,
yarn/npm version and operating system.
node v8.4.0
npm 5.4.2
jest 22.0.4
Windows 7
Also occurs in:
Mac OS 10.11
node v9.3.0
npm 5.6.0
jest 22.0.4
Seems like #5110 messed something up. Wanna send a PR guarding against missing config?
EDIT: I suppose that's not the correct fix, you should send config through, I don't know if it's available, though...
Wait, the fix on your side is this diff:
diff --git i/test/preprocessor.js w/test/preprocessor.js
index 1e4703f..f6a801d 100644
--- i/test/preprocessor.js
+++ w/test/preprocessor.js
@@ -7,10 +7,10 @@ var aliasPreprocessor = require('jest-alias-preprocessor')(config);
var babelJest = require('babel-jest');
module.exports = {
- process: function(src, filename) {
+ process: function(src, filename, ...rest) {
if (filename.indexOf('node_modules') === -1) {
- src = babelJest.process(src, filename);
- src = aliasPreprocessor.process(src, filename);
+ src = babelJest.process(src, filename, ...rest);
+ src = aliasPreprocessor.process(src, filename, ...rest);
}
return src;
},
It means we have a breaking change on our hands though, so we should still guard against missing configuration
If config is not passed, we should pass in undefined so that the defaults of babel are picked up
Thanks, @SimenB. That works!
Closing as it was wrong api usage. It worked previously because not all arguments were used, but they were part of the API
Had the same issue, even though I had not explicitly upgraded beyond jest v21
After a day of debugging, and diffing yarn.lock files between releases and running yarn list:
culprit turned out to be [email protected] depends on babel-jest@>5.0.0.
Bug fix was to put explicit dependency resolution in the package.json file
‘’’
{
“resolutions”: {
“babel-jest”: “^21.2.0”,
“babel-plugin-jest-hoist”: “^21.2.0”,
“babel-preset-jest”: “^21.2.0”
}
}
‘’’
Most helpful comment
Wait, the fix on your side is this diff:
It means we have a breaking change on our hands though, so we should still guard against missing
configuration