-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathjest.config.mjs
More file actions
60 lines (56 loc) · 1.62 KB
/
jest.config.mjs
File metadata and controls
60 lines (56 loc) · 1.62 KB
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
// jest.setup.js
// ESM compatible test setup
// Mock for the Node.js crypto module
const mockCrypto = {
randomBytes: jest.fn((size) => {
const buffer = Buffer.alloc(size);
// Fill with predictable pattern for testing
for (let i = 0; i < size; i++) {
buffer[i] = i % 256;
}
return buffer;
}),
createHash: jest.fn((algorithm) => {
const mockHashInstance = {
update: jest.fn(() => mockHashInstance),
digest: jest.fn((encoding) => {
if (encoding) {
return '0123456789abcdef0123456789abcdef';
}
return Buffer.from('0123456789abcdef0123456789abcdef', 'hex');
})
};
return mockHashInstance;
}),
createHmac: jest.fn((algorithm, key) => {
const mockHmacInstance = {
update: jest.fn(() => mockHmacInstance),
digest: jest.fn((encoding) => {
if (encoding) {
return '0123456789abcdef0123456789abcdef';
}
return Buffer.from('0123456789abcdef0123456789abcdef', 'hex');
})
};
return mockHmacInstance;
}),
pbkdf2Sync: jest.fn((password, salt, iterations, keylen, digest) => {
return Buffer.alloc(keylen).fill(0xAA);
}),
scryptSync: jest.fn((password, salt, keylen, options) => {
return Buffer.alloc(keylen).fill(0xBB);
})
};
// Set up global mocks
global.crypto = {
getRandomValues: (buffer) => {
for (let i = 0; i < buffer.length; i++) {
buffer[i] = i % 256;
}
return buffer;
}
};
// Setup Jest mocks for modules
jest.mock('crypto', () => mockCrypto);
// Set environment variables
process.env.NODE_ENV = 'test';