-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
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
Multiple Jest projects bleed module file extension resolution between environments #5597
Comments
FWIW node has whatwg url, This issue is still very much valid of course 🙂 @cpojer is this known? |
Yep, separate issue that comes down to webpack polyfilling |
Yeah that's a bug. |
I checked out the repository but couldn't reproduce this. Are still seeing the issue?
|
@mkubilayk It's dependent on which tests run first. If the |
@paularmstrong I'm not really sure where the best place to start looking is, but I'd take a look at Might be that the |
The resolver itself does not have any shared cache between instances, so that sounds like a reasonable suspicion. However, It appears that a new hastemap and resolver are created within the |
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: const normalizeMissingOptions = (options: InitialOptions): InitialOptions => {
if (!options.name) {
options.name = crypto
.createHash('md5')
.update(options.rootDir)
.digest('hex');
}
options.projects = (options.projects || []).map(project => {
if (!project.name) {
project.name =
crypto
.createHash('md5')
.update(project.rootDir)
.digest('hex') || '';
}
return project;
});
if (!options.setupFiles) {
options.setupFiles = [];
}
return options;
}; 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. |
@cbelsole Thanks! Adding an explicit |
@paularmstrong I put together a PR with tests but I could use some help on the types. I don't have any experience with flow. |
@cbelsole I can help with that today. What's the easiest way to collaborate and get the typings on your branch? |
@paularmstrong I made you a collaborator on my fork. You should be able to push to the repo. |
🎉I'm on it @cbelsole |
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. |
Do 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 powerfulwindow.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
andconfig/jest/web.js
. These run the tests in the appropriate environment (node
andjsdom
, 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
andyarn 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.
The text was updated successfully, but these errors were encountered: