forked from ethereumjs/ethereumjs-wallet
-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathjest-bundle-browser-env.js
More file actions
36 lines (31 loc) · 963 Bytes
/
jest-bundle-browser-env.js
File metadata and controls
36 lines (31 loc) · 963 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
27
28
29
30
31
32
33
34
35
36
const JSDOMEnvironment = require('jest-environment-jsdom').default;
const nodeCrypto = require('crypto');
class CustomJSDOMEnvironment extends JSDOMEnvironment {
/*
// doesn't work in jest 28
constructor(config, context) {
super({
...config,
// @see https://github.com/facebook/jest/issues/12586#issuecomment-1073298261
globals: {
...config.globals,
Uint32Array,
Uint8Array,
ArrayBuffer,
},
}, context);
}
*/
async setup() {
await super.setup();
this.global.Uint8Array = Uint8Array;
this.global.ArrayBuffer = ArrayBuffer;
// window.crypto is not defined in jsdom
this.global.crypto = {
getRandomValues: function(buffer) {
return nodeCrypto.randomFillSync(buffer);
}
};
}
}
module.exports = CustomJSDOMEnvironment;