-
Notifications
You must be signed in to change notification settings - Fork 130
Expand file tree
/
Copy pathjsdomEnvironmentWithProxy.js
More file actions
26 lines (19 loc) · 1002 Bytes
/
jsdomEnvironmentWithProxy.js
File metadata and controls
26 lines (19 loc) · 1002 Bytes
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
require('global-agent/bootstrap');
// To use proxy, SET GLOBAL_AGENT_HTTP_PROXY=http://localhost:8888
const JSDOMEnvironment = require('jest-environment-jsdom').TestEnvironment;
class JSDOMEnvironmentWithProxy extends JSDOMEnvironment {
setup() {
if (process.env.GLOBAL_AGENT_HTTP_PROXY) {
const { ResourceLoader } = require('jsdom');
const resources = new ResourceLoader({ strictSSL: false });
// HACK: We cannot set ResourceLoader thru testEnvironmentOptions.resources.
// This is because the ResourceLoader instance constructor is of "slightly" different type when on runtime (probably Jest magic).
// Thus, when we set it thru testEnvironmentOptions.resources, it will fail on "--watch" but succeed when running without watch.
this.global._resourceLoader = resources;
}
// Make native fetch available in jsdom environment
this.global.fetch = fetch;
return super.setup();
}
}
module.exports = JSDOMEnvironmentWithProxy;