-
Notifications
You must be signed in to change notification settings - Fork 50
Expand file tree
/
Copy pathjest.setup.ts
More file actions
41 lines (35 loc) · 1.12 KB
/
jest.setup.ts
File metadata and controls
41 lines (35 loc) · 1.12 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
/**
* Global Jest setup for test isolation and deterministic execution
*
* This file ensures proper cleanup of shared state between tests
* to enable parallel test execution without flakiness.
*/
import { WebhookStore } from './src/webhooks/webhook.store.js';
import { resetAllMetrics } from './src/metrics.js';
// Clean up webhook store after each test
afterEach(() => {
WebhookStore.clear();
});
// Reset Prometheus metrics after each test to prevent cross-test pollution
afterEach(() => {
resetAllMetrics();
});
// Ensure environment variables are properly isolated
const originalEnv = { ...process.env };
afterEach(() => {
// Restore original environment variables
// Only restore keys that were originally present
Object.keys(process.env).forEach((key) => {
if (!(key in originalEnv)) {
delete process.env[key];
}
});
Object.keys(originalEnv).forEach((key) => {
process.env[key] = originalEnv[key];
});
});
// Ensure all async operations complete before moving to next test
afterEach(async () => {
// Allow pending promises to resolve
await new Promise((resolve) => setImmediate(resolve));
});