-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathjest.config.js
More file actions
209 lines (193 loc) · 6.03 KB
/
jest.config.js
File metadata and controls
209 lines (193 loc) · 6.03 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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
import { createRequire } from 'module';
const commonModuleNameMapper = {
// Path aliases from tsconfig
'^@/(.*)$': '<rootDir>/src/$1',
'^@types$': '<rootDir>/src/types/index.ts',
// Handle .js imports and map them to .ts
'^(\\.{1,2}/.*)\\.js$': '$1',
// Test support mappings
'^@test/fixtures/(.*)$': '<rootDir>/test/__support__/fixtures/$1',
'^@test/utilities/(.*)$': '<rootDir>/test/__support__/utilities/$1',
'^@test/mocks/(.*)$': '<rootDir>/test/__support__/mocks/$1',
};
const commonTsConfig = {
module: 'ES2022',
moduleResolution: 'bundler',
target: 'ES2022',
allowSyntheticDefaultImports: true,
esModuleInterop: true,
isolatedModules: true,
};
const commonTransform = {
'^.+\\.tsx?$': [
'ts-jest',
{
useESM: true,
tsconfig: commonTsConfig,
},
],
};
/** @type {import('jest').Config} */
export default {
preset: 'ts-jest/presets/default-esm',
testEnvironment: 'node',
extensionsToTreatAsEsm: ['.ts'],
// Multiple test configurations for different test types
projects: [
{
displayName: 'unit',
testMatch: ['<rootDir>/test/unit/**/*.test.ts'],
setupFilesAfterEnv: ['<rootDir>/test/__support__/setup/unit-setup.ts'],
testEnvironment: 'node',
moduleNameMapper: commonModuleNameMapper,
transform: commonTransform,
transformIgnorePatterns: ['node_modules/(?!(@kubernetes/client-node)/)'],
collectCoverageFrom: [
'src/**/*.ts',
'!src/**/*.d.ts',
'!src/**/*.test.ts',
'!src/**/*.spec.ts',
'!src/**/index.ts',
],
coveragePathIgnorePatterns: ['/node_modules/', '/test/'],
testPathIgnorePatterns: [
'/node_modules/',
'/dist/',
'test/unit/lib/kubernetes.test.ts',
],
maxWorkers: 1, // Run unit tests serially to prevent worker shutdown issues
},
{
displayName: 'integration',
testMatch: ['<rootDir>/test/integration/**/*.test.ts'],
setupFilesAfterEnv: ['<rootDir>/test/__support__/setup/integration-setup.ts'],
testEnvironment: 'node',
moduleNameMapper: commonModuleNameMapper,
transform: commonTransform,
transformIgnorePatterns: ['node_modules/(?!(@kubernetes/client-node)/)'],
collectCoverageFrom: [
'src/**/*.ts',
'!src/**/*.d.ts',
'!src/**/*.test.ts',
'!src/**/*.spec.ts',
'!src/**/index.ts',
],
coveragePathIgnorePatterns: ['/node_modules/', '/test/'],
testPathIgnorePatterns: [
'/node_modules/',
'/dist/',
// ES module issues resolved - all integration tests enabled
],
workerIdleMemoryLimit: '512MB', // Force worker restart after integration tests
},
{
displayName: 'e2e',
testMatch: ['<rootDir>/test/e2e/**/*.test.ts'],
setupFilesAfterEnv: ['<rootDir>/test/__support__/setup/e2e-setup.ts'],
testEnvironment: 'node',
moduleNameMapper: commonModuleNameMapper,
transform: commonTransform,
transformIgnorePatterns: ['node_modules/(?!(@kubernetes/client-node)/)'],
collectCoverageFrom: [
'src/**/*.ts',
'!src/**/*.d.ts',
'!src/**/*.test.ts',
'!src/**/*.spec.ts',
'!src/**/index.ts',
],
coveragePathIgnorePatterns: ['/node_modules/', '/test/'],
maxWorkers: 1,
},
{
displayName: 'llm-integration',
testMatch: ['<rootDir>/test/llm-integration/**/*.test.ts'],
testEnvironment: 'node',
moduleNameMapper: {
...commonModuleNameMapper,
// Mock kubernetes dependencies for LLM tests
'@kubernetes/client-node': '<rootDir>/test/__support__/mocks/kubernetes-mock.ts',
},
transform: commonTransform,
collectCoverageFrom: [
'src/**/*.ts',
'!src/**/*.d.ts',
'!src/**/*.test.ts',
'!src/**/*.spec.ts',
'!src/**/index.ts',
],
coveragePathIgnorePatterns: ['/node_modules/', '/test/'],
maxWorkers: 1, // Serial execution for LLM tests to avoid rate limits
testTimeout: 180000, // 3 minute timeout for LLM interactions
},
],
// Transform ESM packages
transformIgnorePatterns: ['node_modules/(?!(@kubernetes/client-node)/)'],
// Performance optimizations
maxWorkers: '50%', // Use half of available CPU cores
workerIdleMemoryLimit: '512MB', // Force worker restart to prevent memory leaks
cache: true,
cacheDirectory: '<rootDir>/node_modules/.cache/jest',
// Coverage configuration
collectCoverageFrom: [
'src/**/*.ts',
'!src/**/*.d.ts',
'!src/**/*.test.ts',
'!src/**/*.spec.ts',
'!src/**/index.ts',
],
coverageDirectory: 'coverage',
coverageReporters: ['text', 'lcov', 'html', 'json-summary'],
coverageThreshold: {
global: {
branches: 47,
functions: 60,
lines: 56,
statements: 56,
},
'./src/app/': {
branches: 55,
functions: 80,
lines: 74,
statements: 74,
},
'./src/infra/': {
branches: 50,
functions: 60,
lines: 55,
statements: 55,
},
'./src/tools/': {
branches: 50,
functions: 64,
lines: 63,
statements: 63,
},
'./src/lib/': {
branches: 50,
functions: 50,
lines: 60,
statements: 60,
},
},
// File extensions and test configuration
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'],
roots: ['<rootDir>/src', '<rootDir>/test'],
testPathIgnorePatterns: [
'/node_modules/',
'/dist/',
'test/unit/lib/kubernetes.test.ts',
'test/llm-integration/**/*.test.ts', // Exclude LLM integration tests from default runs
],
// Timeout handling for different test types
testTimeout: 30000, // Default 30s
// Better error reporting
verbose: false, // Reduce noise for CI
silent: false,
// Fail fast for development
bail: false, // Continue running tests to get full picture
// Global setup and teardown
globalSetup: '<rootDir>/test/__support__/setup/global-setup.ts',
globalTeardown: '<rootDir>/test/__support__/setup/global-teardown.ts',
// Setup files
setupFilesAfterEnv: ['<rootDir>/test/setup.ts'],
};