forked from pmmmwh/react-refresh-webpack-plugin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
jest-environment.js
33 lines (26 loc) · 889 Bytes
/
jest-environment.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
const NodeEnvironment = require('jest-environment-node');
const puppeteer = require('puppeteer');
const semver = require('semver');
const yn = require('yn');
class SandboxEnvironment extends NodeEnvironment {
async setup() {
await super.setup();
this.global.__DEBUG__ = yn(process.env.DEBUG);
this.global.WEBPACK_VERSION = parseInt(process.env.WEBPACK_VERSION || '5', 10);
this.global.WDS_VERSION = semver.major(process.version) < 12 ? 3 : 4;
const wsEndpoint = process.env.PUPPETEER_WS_ENDPOINT;
if (!wsEndpoint) {
throw new Error('Puppeteer wsEndpoint not found!');
}
this.global.browser = await puppeteer.connect({
browserWSEndpoint: wsEndpoint,
});
}
async teardown() {
await super.teardown();
if (this.global.browser) {
await this.global.browser.disconnect();
}
}
}
module.exports = SandboxEnvironment;