-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathjest.preset.ts
More file actions
60 lines (55 loc) · 2.36 KB
/
jest.preset.ts
File metadata and controls
60 lines (55 loc) · 2.36 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
export const nxPreset = {
// This is one of the patterns that jest finds by default https://jestjs.io/docs/configuration#testmatch-arraystring
testMatch: ['**/?(*.)+(spec|test).[jt]s?(x)'],
resolver: '@nx/jest/plugins/resolver',
moduleFileExtensions: ['ts', 'js', 'mjs', 'html'],
coverageReporters: ['html'],
// setupFiles runs BEFORE modules are loaded - critical for preventing Winston memory leak
setupFiles: ['<rootDir>/../../jest.env-setup.ts'],
setupFilesAfterEnv: ['<rootDir>/../../jest.setup.ts'],
transform: {
'^.+\\.(ts|js|html)$': [
'ts-jest',
{
tsconfig: '<rootDir>/tsconfig.spec.json',
isolatedModules: true, // Faster compilation, less memory
},
],
},
testEnvironment: 'jsdom',
/**
* manually set the exports names to load in common js, to mimic the behaviors of jest 27
* before jest didn't fully support package exports and would load in common js code (typically via main field). now jest 28+ will load in the browser esm code, but jest esm support is not fully supported.
* In this case we will tell jest to load in the common js code regardless of environment.
*
* this can be removed via just overriding this setting in it's usage
*
* @example
* module.exports = {
* ...nxPreset,
* testEnvironmentOptions: {},
* }
*/
testEnvironmentOptions: {
customExportConditions: ['node', 'require', 'default'],
},
testTimeout: 20000, // 20 seconds
passWithNoTests: true, // Allow packages without tests to pass
// Memory optimizations
maxWorkers: 3, // Limit parallel workers to reduce memory pressure
workerIdleMemoryLimit: '512MB', // Kill workers using more than 512MB when idle
// Force worker cleanup to prevent JSDOM hanging issues
// Even with proper test cleanup, JSDOM can leave open handles (especially with XHR/network mocks)
// This forces Jest to exit cleanly after all tests complete
forceExit: true,
// Clear mocks and cache between tests
clearMocks: true,
resetMocks: true,
restoreMocks: true,
// Debug flags - enable with JEST_DEBUG=true for memory leak detection
// Disabled by default as they add 10-20% overhead
detectLeaks: process.env.JEST_DEBUG === 'true',
detectOpenHandles: process.env.JEST_DEBUG === 'true',
// Force garbage collection between test files (requires --expose-gc flag)
// This is handled in the test script
};