-
-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathjest.setup.js
More file actions
36 lines (30 loc) · 838 Bytes
/
Copy pathjest.setup.js
File metadata and controls
36 lines (30 loc) · 838 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
// Use Node.js's native Web Crypto API
const { webcrypto } = require('crypto');
// Define it on all possible global objects
const globalObjects = [global, globalThis];
if (typeof window === 'undefined') {
global.window = {};
}
globalObjects.push(global.window);
// Apply crypto to all global objects
globalObjects.forEach(obj => {
if (obj) {
Object.defineProperty(obj, 'crypto', {
value: webcrypto,
writable: true,
enumerable: true,
configurable: true,
});
}
});
// Ensure subtle is available
if (!global.crypto.subtle) {
throw new Error('Crypto subtle API not available after polyfill');
}
if (typeof self === 'undefined') {
global.self = global;
}
if (self && !self.crypto) {
self.crypto = webcrypto;
}
console.log('✅ Native Web Crypto API set up successfully for Jest environment');