-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjest.config.mjs
67 lines (58 loc) · 1.72 KB
/
jest.config.mjs
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
/** @type {import('ts-jest').JestConfigWithTsJest} */
// Coverage thresholds aligned with project requirements
const COVERAGE_THRESHOLD = {
branches: 80, // Updated threshold to 80% to match project standards
functions: 80,
lines: 80,
statements: 80
};
/**
* Jest configuration for TypeScript project with ESM support
* Version constraints:
* - Jest v29.x.x for ESM and TypeScript compatibility
* - ts-jest for TypeScript transformation
*/
const config = {
// Always collect coverage
collectCoverage: true,
coverageDirectory: '<rootDir>/coverage',
// Exclude test files and type definitions from coverage
coveragePathIgnorePatterns: [
'<rootDir>/node_modules/',
'<rootDir>/dist/',
'\\.test\\.ts$',
'<rootDir>/src/types/',
'<rootDir>/scripts/',
'<rootDir>/src/tests/utils/mockHttpClient.ts',
'<rootDir>/src/tests/helpers/'
],
// Generate various coverage report formats
coverageReporters: ['text', 'lcov', 'html'],
// Coverage thresholds
coverageThreshold: {
global: COVERAGE_THRESHOLD
},
// ESM support
extensionsToTreatAsEsm: ['.ts'],
// Automatically clear mock calls between every test
clearMocks: true,
// Projects configuration for different test types
projects: [
{
displayName: 'unit',
preset: 'ts-jest/presets/default-esm',
testMatch: ['**/*.test.ts'],
transform: {
'^.+\\.tsx?$': ['ts-jest', { useESM: true, tsconfig: 'tsconfig.test.json' }]
},
moduleNameMapper: {
'^(\\.{1,2}/.*)\\.js$': '$1',
'^(\\.{1,2}/.*)\\.ts$': '$1'
},
injectGlobals: true,
testEnvironment: 'node',
setupFilesAfterEnv: ['<rootDir>/src/tests/setup.ts']
}
]
};
export default config;