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

Clone to new test environment options while create test environments #8420

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
- `[jest-runtime]` Fix virtual mocks not being unmockable after previously being mocked ([#8396](https://github.com/facebook/jest/pull/8396))
- `[jest-transform]` Replace special characters in transform cache filenames to support Windows ([#8353](https://github.com/facebook/jest/pull/8353))
- `[jest-config]` Allow exactly one project ([#7498](https://github.com/facebook/jest/pull/7498))
- `[jest-environment-jsdom]` `[jest-environment-node]` Fix `testEnvironmentOptions` affected in the test process ([#8420](https://github.com/facebook/jest/pull/8420))

### Chore & Maintenance

Expand Down
21 changes: 14 additions & 7 deletions packages/jest-environment-jsdom/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,20 @@ class JSDOMEnvironment implements JestEnvironment {
moduleMocker: ModuleMocker | null;

constructor(config: Config.ProjectConfig, options: EnvironmentContext = {}) {
this.dom = new JSDOM('<!DOCTYPE html>', {
pretendToBeVisual: true,
runScripts: 'dangerously',
url: config.testURL,
virtualConsole: new VirtualConsole().sendTo(options.console || console),
...config.testEnvironmentOptions,
});
this.dom = new JSDOM(
'<!DOCTYPE html>',
Object.assign(
{
pretendToBeVisual: true,
runScripts: 'dangerously',
url: config.testURL,
virtualConsole: new VirtualConsole().sendTo(
options.console || console,
),
},
Object.create(config.testEnvironmentOptions || null),
),
);
const global = (this.global = this.dom.window.document.defaultView as Win);

if (!global) {
Expand Down
5 changes: 4 additions & 1 deletion packages/jest-environment-node/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,10 @@ class NodeEnvironment implements JestEnvironment {
this.context = vm.createContext();
const global = (this.global = vm.runInContext(
'this',
Object.assign(this.context, config.testEnvironmentOptions),
Object.assign(
this.context,
Object.create(config.testEnvironmentOptions || null),
),
));
global.global = global;
global.clearInterval = clearInterval;
Expand Down