Skip to content
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

Tests fail since config not passed to babel-jest in v22 #5185

Closed
gricard opened this issue Dec 27, 2017 · 7 comments
Closed

Tests fail since config not passed to babel-jest in v22 #5185

gricard opened this issue Dec 27, 2017 · 7 comments

Comments

@gricard
Copy link
Contributor

gricard commented Dec 27, 2017

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

@SimenB
Copy link
Member

SimenB commented Dec 27, 2017

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

@SimenB
Copy link
Member

SimenB commented Dec 27, 2017

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

@SimenB
Copy link
Member

SimenB commented Dec 27, 2017

If config is not passed, we should pass in undefined so that the defaults of babel are picked up

@gricard
Copy link
Contributor Author

gricard commented Dec 28, 2017

Thanks, @SimenB. That works!

@SimenB
Copy link
Member

SimenB commented Dec 30, 2017

Closing as it was wrong api usage. It worked previously because not all arguments were used, but they were part of the API

@JamesMcGuigan
Copy link

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 webpack-babel-jest@1.0.4 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”
}
}
‘’’

@github-actions
Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 11, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants