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

removed vm context #2

Merged
merged 2 commits into from Mar 20, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 7 additions & 9 deletions packages/jest-environment-jsdom/src/index.ts
Expand Up @@ -14,7 +14,7 @@ import {
LolexFakeTimers,
} from '@jest/fake-timers';
import {EnvironmentContext, JestEnvironment} from '@jest/environment';
import {DOMWindow, JSDOM, VirtualConsole} from 'jsdom';
import {JSDOM, VirtualConsole} from 'jsdom';

// The `Window` interface does not have an `Error.stackTraceLimit` property, but
// `JSDOMEnvironment` assumes it is there.
Expand All @@ -27,7 +27,6 @@ type Win = Window &

class JSDOMEnvironment implements JestEnvironment {
dom: JSDOM | null;
vm: DOMWindow | null;
fakeTimers: LegacyFakeTimers<number> | null;
fakeTimersLolex: LolexFakeTimers | null;
global: Win;
Expand All @@ -43,8 +42,6 @@ class JSDOMEnvironment implements JestEnvironment {
...config.testEnvironmentOptions,
});

this.vm = this.dom.getInternalVMContext();

const global = (this.global = this.dom.window.document.defaultView as Win);
if (!global) {
throw new Error('JSDOM did not return a Window object');
Expand Down Expand Up @@ -127,21 +124,22 @@ class JSDOMEnvironment implements JestEnvironment {
// @ts-ignore
this.global = null;
this.dom = null;
this.vm = null;
this.fakeTimers = null;
this.fakeTimersLolex = null;
}

runScript<T = unknown>(script: Script): T | null {
if (this.vm) {
return script.runInContext(this.vm);
if (this.dom) {
return script.runInContext(this.dom.getInternalVMContext());
}

return null;
}

getVmContext() {
return this.vm;
if (this.dom) {
return this.dom.getInternalVMContext();
}
return null;
}
}

Expand Down