-
Notifications
You must be signed in to change notification settings - Fork 8
/
jest.env.js
37 lines (33 loc) · 1.22 KB
/
jest.env.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
34
35
36
37
const Environment = require("jest-environment-node");
const nodeCrypto = require("crypto");
const { TextDecoder, TextEncoder } = require("util");
module.exports = class extends Environment {
/**
* @summary adds TextEncoder and TextDecoder needed by `nats` dependency into Node test environment
*/
async setup() {
await super.setup();
if (typeof this.global.TextEncoder === "undefined") {
this.global.TextEncoder = TextEncoder;
this.global.TextDecoder = TextDecoder;
this.global.crypto = {
getRandomValues: function (buffer) {
return nodeCrypto.randomFillSync(buffer);
},
};
}
this.setupBrowserEnv();
}
setupBrowserEnv() {
const { process } = this.global;
Object.defineProperty(this.global.process.release, "name", {
...Object.getOwnPropertyDescriptor(process.release, "name"),
writable: true,
});
this.global.process.release.name = "node";
Object.defineProperty(this.global.process.release, "name", {
...Object.getOwnPropertyDescriptor(process.release, "name"),
writable: false,
});
}
};