-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathjest.setup.js
More file actions
48 lines (41 loc) · 1.17 KB
/
jest.setup.js
File metadata and controls
48 lines (41 loc) · 1.17 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
/**
* Global Jest setup for Log Engine testing
* Optimized for CI environments with better error handling
*/
// Global Jest setup to suppress console output during tests
global.console = {
...console,
// Suppress error logs during tests to avoid confusing output
error: jest.fn(),
// Keep other console methods for debugging
log: console.log,
warn: console.warn,
info: console.info
};
// Optimized timeout for faster feedback
jest.setTimeout(10000);
// Handle uncaught promise rejections in tests
process.on('unhandledRejection', (reason, promise) => {
console.error('Unhandled Rejection at:', promise, 'reason:', reason);
// In test environment, we want to know about these
if (process.env.NODE_ENV === 'test') {
throw reason;
}
});
// Global cleanup optimized for CI
afterAll(async () => {
// Clear any remaining timers immediately
jest.clearAllTimers();
jest.clearAllMocks();
// Force garbage collection if available
if (global.gc) {
global.gc();
}
});
afterEach(async () => {
// Fast cleanup after each test
jest.restoreAllMocks();
jest.clearAllMocks();
// Clear any timers that might be hanging around
jest.clearAllTimers();
});