-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjest.config.coverage.js
More file actions
227 lines (199 loc) · 5.66 KB
/
jest.config.coverage.js
File metadata and controls
227 lines (199 loc) · 5.66 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
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
const nextJest = require('next/jest');
const path = require('path');
const createJestConfig = nextJest({
dir: './',
});
/**
* Enhanced Jest Configuration for Comprehensive Coverage Collection
* Optimized for claude-flow-ui with advanced coverage reporting
*/
const coverageJestConfig = {
// Use the optimized setup from main config
extends: '<rootDir>/jest.config.js',
// Enhanced setup files for coverage collection
setupFilesAfterEnv: [
'<rootDir>/tests/setup-comprehensive.ts',
'<rootDir>/tests/coverage/setup-coverage.ts'
],
setupFiles: ['<rootDir>/tests/jest.setup.reliable.js'],
testEnvironment: 'jsdom',
// Comprehensive test matching for coverage
testMatch: [
'<rootDir>/tests/**/*.{test,spec}.{js,jsx,ts,tsx}',
'<rootDir>/src/**/__tests__/**/*.{test,spec}.{js,jsx,ts,tsx}',
'<rootDir>/src/**/*.{test,spec}.{js,jsx,ts,tsx}',
// Include integration tests
'<rootDir>/tests/integration/**/*.{test,spec}.{js,jsx,ts,tsx}',
// Include API tests
'<rootDir>/tests/api/**/*.{test,spec}.{js,jsx,ts,tsx}',
],
// Path aliases for consistent imports
moduleNameMapper: {
'^@/(.*)$': '<rootDir>/src/$1',
'^@tests/(.*)$': '<rootDir>/tests/$1',
'^@components/(.*)$': '<rootDir>/src/components/$1',
'^@lib/(.*)$': '<rootDir>/src/lib/$1',
'^@hooks/(.*)$': '<rootDir>/src/hooks/$1',
'^@services/(.*)$': '<rootDir>/src/services/$1',
'^@utils/(.*)$': '<rootDir>/src/utils/$1',
// Handle static assets and CSS
'\\.(css|less|scss|sass)$': 'identity-obj-proxy',
'\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$': 'jest-transform-stub',
// Mock WebSocket for tests
'^socket.io-client$': '<rootDir>/tests/mocks/socket.io-client.js',
},
// Ignore patterns for node_modules
transformIgnorePatterns: [
'node_modules/(?!(socket.io-client|@xterm/xterm|@xterm/addon-.*|uuid|es6-promise|p-map|p-limit|unique-filename)/)'
],
// Comprehensive coverage collection
collectCoverage: true,
collectCoverageFrom: [
// Source files
'src/**/*.{js,jsx,ts,tsx}',
// Server files
'unified-server.js',
'websocket-server.js',
// Exclude files that don't need coverage
'!src/**/*.d.ts',
'!src/**/*.stories.{js,jsx,ts,tsx}',
'!src/**/*.config.{js,jsx,ts,tsx}',
'!src/**/*.test.{js,jsx,ts,tsx}',
'!src/**/*.spec.{js,jsx,ts,tsx}',
'!src/**/__tests__/**',
// Exclude Next.js specific files
'!src/app/layout.tsx',
'!src/app/page.tsx',
'!src/app/globals.css',
// Exclude generated files
'!src/**/*.generated.{js,jsx,ts,tsx}',
'!**/node_modules/**',
'!**/.next/**',
'!**/coverage/**',
'!**/build/**',
'!**/dist/**',
],
// Enhanced coverage reporting
coverageReporters: [
'text',
'text-summary',
'lcov',
'html',
'json',
'json-summary',
'cobertura',
'clover'
],
coverageDirectory: 'coverage/jest',
// Realistic coverage thresholds for gradual improvement
coverageThreshold: {
global: {
branches: 75,
functions: 80,
lines: 80,
statements: 80,
},
// Higher thresholds for critical components
'./src/hooks/**/*.{js,jsx,ts,tsx}': {
branches: 85,
functions: 90,
lines: 90,
statements: 90,
},
'./src/lib/**/*.{js,jsx,ts,tsx}': {
branches: 85,
functions: 90,
lines: 90,
statements: 90,
},
'./src/services/**/*.{js,jsx,ts,tsx}': {
branches: 80,
functions: 85,
lines: 85,
statements: 85,
},
// Slightly lower for UI components (harder to test)
'./src/components/**/*.{js,jsx,ts,tsx}': {
branches: 70,
functions: 75,
lines: 75,
statements: 75,
},
},
// Enhanced reporting for CI/CD
reporters: [
'default',
['jest-junit', {
outputDirectory: 'coverage/jest',
outputName: 'junit.xml',
classNameTemplate: '{classname}',
titleTemplate: '{title}',
ancestorSeparator: ' › ',
usePathForSuiteName: true
}],
...(process.env.CI ? [
['jest-sonar-reporter', {
outputDirectory: 'coverage/jest',
outputName: 'sonar-report.xml'
}]
] : [])
],
// Performance settings for coverage
testTimeout: 45000,
maxWorkers: process.env.CI ? 2 : '50%',
// Coverage-specific settings
collectCoverageOnlyFrom: {
'src/**/*.{js,jsx,ts,tsx}': true,
'unified-server.js': true,
'websocket-server.js': true,
},
// Additional coverage options
coveragePathIgnorePatterns: [
'/node_modules/',
'/tests/',
'/coverage/',
'/.next/',
'/build/',
'/dist/',
'\\.stories\\.',
'\\.test\\.',
'\\.spec\\.',
'__tests__',
'__mocks__',
],
// Mock and cleanup configuration
clearMocks: true,
resetMocks: true,
restoreMocks: true,
// Error handling
errorOnDeprecated: false,
bail: false,
detectOpenHandles: false,
forceExit: true,
// CI-specific settings
...(process.env.CI === 'true' && {
runInBand: true,
ci: true,
updateSnapshot: false,
}),
// Watch mode configuration
watchPathIgnorePatterns: [
'<rootDir>/node_modules/',
'<rootDir>/.next/',
'<rootDir>/coverage/',
'<rootDir>/.swarm/',
'<rootDir>/rest-api/',
],
// Global test setup/teardown
globalSetup: '<rootDir>/tests/utils/globalSetup.js',
globalTeardown: '<rootDir>/tests/utils/globalTeardown.js',
// Verbose output for debugging coverage issues
verbose: process.env.COVERAGE_DEBUG === 'true',
// Custom test environment options
testEnvironmentOptions: {
url: 'http://localhost:11235',
runScripts: 'dangerously',
resources: 'usable',
},
};
module.exports = createJestConfig(coverageJestConfig);