-
-
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
Support testEnvironment=jest-environment-jsdom with pnpm #6145
Conversation
Thank you for your pull request and welcome to our community. We require contributors to sign our Contributor License Agreement, and we don't seem to have you on file. In order for us to review and merge your code, please sign up at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need the corporate CLA signed. If you have received this in error or have any questions, please contact us at cla@fb.com. Thanks! |
Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Facebook open source project. Thanks! |
Codecov Report
@@ Coverage Diff @@
## master #6145 +/- ##
=======================================
Coverage 64.19% 64.19%
=======================================
Files 219 219
Lines 8423 8423
Branches 4 4
=======================================
Hits 5407 5407
Misses 3015 3015
Partials 1 1 Continue to review full report at Codecov.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we do this, it should also include jest-environment-node
, and remove them from jest-config
.
Also please update the changelog
Sorta related #5913 |
because that's where we do the require
Another possibility is to do @cpojer @thymikee @rickhanlonii thoughts? I'd also like to not paint us into a corner with regards to #5913 (maybe even solve it at the same time) |
This issue is affecting my application also, because we have to install two versions of Jest side by side. In our specific case, the
PNPM brings the problem to light, but this is fundamentally an architectural problem with Jest not just a compatibility issue: In the modern world, libraries cannot naively call The approach suggested in this PR would help the simple case where you get jsdom as your default. However the jsdom dependency is like 11MB with all its dependencies. Forcing everyone to install that and probably also It also poses a backwards compatibility problem: If A better solution would be to make |
I tried creating a PR that would illustrate how to allow something like this: // jest.config.js
module.exports = {
verbose: true,
testEnvironment: require('my-custom-environment'),
}; or for jest.config.json {
"verbose": true,
"testEnvironment": "../node_modules/my-custom-environment"
} However I cannot seem to get the master branch of Jest to build at all, on Windows or Mac. The |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doing require.resolve
from within jest-config
and pass a full path through to the runner might make the most sense. However, this change should work, and is better than nothing
Leaving this one for @arcanis to merge. |
@arcanis friendly ping :) |
@@ -12,8 +12,6 @@ | |||
"babel-jest": "^22.4.1", | |||
"chalk": "^2.0.1", | |||
"glob": "^7.1.1", | |||
"jest-environment-jsdom": "^22.4.1", | |||
"jest-environment-node": "^22.4.1", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You cannot remove them from here, because they are required by the following line:
https://github.com/facebook/jest/blob/master/packages/jest-config/src/utils.js#L123
If you remove them from the package list, you start relying on the hoisting to make sure that the environments are siblings of jest-config
, which is an unsafe assumption.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like a require based on a runtime variable is done in both jest-runner and jest-config. I guess that has implications on @SimenB's suggestion "pass a full path through to the runner" too.
I suppose that leaves us with the option of some refactoring towards dependency injection, and maybe @pgonzal's suggestion with a require done at config time is a simple way to do that.
@solsson mind taking a look at @arcanis #6145 (comment)? |
It's been a month already without a sign of interest, closing. Happy to reopen once the feedback is addressed :) |
This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Summary
The dynamic require of testEnvironment (transpiled to
const testFramework = require(config.testRunner)
in published source) is incompatible with pnpm.I agree with pnpm/pnpm#1130 (comment).
For environment to be truly pluggable, with stricter npm install, I guess this PR needs to consider how to support environments other than jsdom. It could be argued that a class should be injected, rather than
require
d using a runtime value. In practice though I think the suggested addition to package.json solves the problem.Test plan
Fixes #5369