-
-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathjest.setup.js
More file actions
73 lines (67 loc) · 1.96 KB
/
jest.setup.js
File metadata and controls
73 lines (67 loc) · 1.96 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
61
62
63
64
65
66
67
68
69
70
71
72
73
/**
* Jest setup file to polyfill import.meta for test environments
*/
// Ensure NODE_ENV is set to 'test' for proper NodeCache configuration
process.env.NODE_ENV = 'test';
// Polyfill import.meta for Jest
if (typeof globalThis.importMeta === 'undefined') {
globalThis.importMeta = {
url: `file://${process.cwd()}/src/tools/loader.js`
};
}
// Make import.meta available globally for ES modules in Jest
if (typeof global !== 'undefined') {
// Polyfill import.meta in the global scope for Jest
Object.defineProperty(global, 'import', {
value: {
meta: {
url: `file://${process.cwd()}/src/tools/loader.js`
}
},
writable: true,
configurable: true
});
}
// Global cleanup for rate limiters
afterAll(async () => {
// Try both source and built versions for robustness
try {
// Try built version first
const { cleanupRateLimiters } = await import('./dist/utils/rate-limiter.js');
if (cleanupRateLimiters) {
cleanupRateLimiters();
}
} catch (error) {
try {
// Fallback to source version
const { cleanupRateLimiters } = await import('./src/utils/rate-limiter.ts');
if (cleanupRateLimiters) {
cleanupRateLimiters();
}
} catch (fallbackError) {
// Ignore all cleanup errors - this is best effort
}
}
// Force clear all timers as a last resort
jest.clearAllTimers();
});
// Also clean after each test file to prevent cross-file contamination
afterEach(async () => {
try {
// Try built version first
const { cleanupRateLimiters } = await import('./dist/utils/rate-limiter.js');
if (cleanupRateLimiters) {
cleanupRateLimiters();
}
} catch (error) {
try {
// Fallback to source version
const { cleanupRateLimiters } = await import('./src/utils/rate-limiter.ts');
if (cleanupRateLimiters) {
cleanupRateLimiters();
}
} catch (fallbackError) {
// Ignore all cleanup errors - this is best effort
}
}
});