Multiple Jest projects bleed module file extension resolution between environments
See original GitHub issueDo you want to request a feature or report a bug?
Bug
What is the current behavior?
I’ve created a test-case repo that illustrates this behavior: paularmstrong/jest-project-bleed.
In some cases, we want to have code that is defined differently for a node.js environment than a browser/DOM environment. We do this to avoid needing to polyfill node.js’s url
module in the browser when we already have access to a powerful window.URL
API in a browser (which is not available in node.js).
To do this, we set up our build environment to build server-side code with moduleFileExtensions
to resolve *.node.js
files before *.js
files.
In Jest, we create two separate project configurations: config/jest/node.js
and config/jest/web.js
. These run the tests in the appropriate environment (node
and jsdom
, respectively).
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
.
I’ve created a test-case repo that illustrates this behavior: paularmstrong/jest-project-bleed.
What is the expected behavior?
I expect all tests to pass, given their environment and correct module file resolution.
Please provide your exact Jest configuration and mention your Jest, node, yarn/npm version and operating system.
Please see the repo test case: paularmstrong/jest-project-bleed.
- yarn 0.27.5
- node 8.9.0
"devDependencies": {
"babel-core": "^6.26.0",
"babel-jest": "^22.2.2",
"babel-preset-env": "^1.6.1",
"jest": "^22.3.0"
},
Issue Analytics
- State:
- Created 6 years ago
- Comments:15 (5 by maintainers)
Top GitHub Comments
I was able to repro this bug and I noticed when I printed out the project configs that they had the same md5 hash name which is what jest uses to pick out the right resolver. I found that in the normalizer if the name is not set it will set a name.
After fiddling around with the normalizer I came up with this code:
Now if the names on the projects were not set they would have their own unique name. This fixed the error since by having a unique name the right resolver was chosen.
Yeah that’s a bug.