-
-
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
jsdom integration with custom resource loader doesn't work in parallel mode #8701
Comments
Jsdom is supposed to be used as a custom environment, did you try that? |
testEnvironmentOptions: {
runScripts: "dangerously",
resources: new CustomResourceLoader(),
}, This won't work as the config is serialized (we probably should throw an error...) to a string, so your instance is lost. What you have to do, as @thymikee alludes to (and I wrote in the issue you linked to), is create a custom test environment. I can quickly put together an example (untested) const JSDOMEnvironment = require('jest-environment-jsdom-thirteen');
const {ResourceLoader} = require('jsdom');
class CustomResourceLoader extends ResourceLoader {}
module.exports = class JSDOMEnvironmentWithResources extends JSDOMEnvironment {
constructor(config, options) {
super(
{
...config,
testEnvironmentOptions: {
...config.testEnvironmentOptions,
resources: new CustomResourceLoader(),
},
},
options,
);
}
}; For Jest 28 and after the constructor arguments of environments were changed (in #12461). So new example is: const {default: JSDOMEnvironment} = require('jest-environment-jsdom');
const {ResourceLoader} = require('jsdom');
class CustomResourceLoader extends ResourceLoader {}
module.exports = class JSDOMEnvironmentWithResources extends JSDOMEnvironment {
constructor(config, options) {
super(
{
...config,
projectConfig: {
...config.projectConfig,
testEnvironmentOptions: {
...config.projectConfig.testEnvironmentOptions,
resources: new CustomResourceLoader(),
},
},
},
options,
);
}
};
Agreed - it will be (as mentioned) addressed in #7185 |
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. |
🐛 Bug Report
JSDOM integration with custom resource loader doesn't work in parallel mode.
JSDOM ResourceLoader: https://github.com/jsdom/jsdom#advanced-configuration
testEnvironmentOptions
is serialized to simple JSON to pass to the worker thus causing custom resource loader to be JSONified. Tests do not work as expected in parallel mode and are producing cryptic error:Related to #8393
To Reproduce
jest-config.js
package.json:
It should be at least 2 tests and jest cache cleared to trigger parallel build.
Expected behavior
Ideally, there should be another way to pass environment options to jest worker, worker compatible. If it is not possible, jest should at least try to detect attempts to pass classes as
testEnvironmentOptions
and raise an error or warning clearly stating the problem.Link to repl or repo (highly encouraged)
Will provide if needed. Seems like issue is well-known.
Run
npx envinfo --preset jest
Paste the results here:
The text was updated successfully, but these errors were encountered: