Skip to content

Commit

Permalink
Merge pull request #2 from irega/feature/UpgradeJsdom16
Browse files Browse the repository at this point in the history
removed vm context
  • Loading branch information
lh0x00 committed Mar 20, 2020
2 parents 00b5e22 + 783a81d commit e6ed90b
Showing 1 changed file with 7 additions and 9 deletions.
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

0 comments on commit e6ed90b

Please sign in to comment.