Skip to content

Commit f76d6fb

Browse files
committed
Reuse JSDOM between tests, clear compiled cache before tests
1 parent cabd5f9 commit f76d6fb

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

packages/app/src/sandbox/eval/tests/jest-lite.ts

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
import { dispatch, actions, listen } from 'codesandbox-api';
32
import { react, reactTs } from '@codesandbox/common/lib/templates';
43
import expect from 'jest-matchers';
@@ -84,6 +83,8 @@ export default class TestRunner {
8483
manager: Manager;
8584
watching: boolean = true;
8685

86+
dom: any;
87+
8788
constructor(manager: Manager) {
8889
this.manager = manager;
8990
this.ranTests = new Set();
@@ -118,11 +119,7 @@ export default class TestRunner {
118119
});
119120
};
120121

121-
const { JSDOM } = (window as any).JSDOM;
122-
const { window: jsdomWindow } = new JSDOM('<!DOCTYPE html>', {
123-
pretendToBeVisual: true,
124-
url: document.location.origin,
125-
});
122+
const { window: jsdomWindow } = this.dom;
126123
const { document: jsdomDocument } = jsdomWindow;
127124

128125
// Date is not set correctly on window in JSDOM. This breaks Jest
@@ -227,6 +224,14 @@ export default class TestRunner {
227224

228225
await getJSDOM();
229226

227+
const { JSDOM } = (window as any).JSDOM;
228+
229+
this.manager.clearCompiledCache();
230+
this.dom = new JSDOM('<!DOCTYPE html>', {
231+
pretendToBeVisual: true,
232+
url: document.location.origin,
233+
});
234+
230235
this.sendMessage('total_test_start');
231236

232237
let testModule = null;
@@ -423,4 +428,4 @@ export default class TestRunner {
423428

424429
// We stub this, because old versions of CodeSandbox still needs this
425430
reportError = () => {};
426-
}
431+
}

0 commit comments

Comments
 (0)