-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjest.config.js
More file actions
136 lines (115 loc) · 3.11 KB
/
jest.config.js
File metadata and controls
136 lines (115 loc) · 3.11 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
/**
* Jest Configuration for Macau Law Knowledge Base
* Configures testing environment for TypeScript, React, and Node.js components
*/
const nextJest = require('next/jest');
const createJestConfig = nextJest({
// Provide the path to your Next.js app to load next.config.js and .env files
dir: './',
});
// Add any custom config to be passed to Jest
const customJestConfig = {
// Setup files to run before each test
setupFilesAfterEnv: ['<rootDir>/jest.setup.js'],
setupFiles: ['<rootDir>/jest.env-setup.js'],
// Test environment for React components
testEnvironment: 'jest-environment-jsdom',
// Module name mapping for path aliases
moduleNameMapper: {
'^@/(.*)$': '<rootDir>/src/$1',
'^@/tests/(.*)$': '<rootDir>/tests/$1',
},
// Test file patterns
testMatch: [
'<rootDir>/tests/**/*.test.{js,jsx,ts,tsx}',
'<rootDir>/src/**/*.test.{js,jsx,ts,tsx}',
],
// Files to ignore during testing
testPathIgnorePatterns: [
'<rootDir>/.next/',
'<rootDir>/node_modules/',
'<rootDir>/dist/',
'<rootDir>/build/',
],
// Coverage collection configuration
collectCoverageFrom: [
'src/**/*.{js,jsx,ts,tsx}',
'!src/**/*.d.ts',
'!src/app/layout.tsx',
'!src/app/page.tsx',
'!src/app/**/page.tsx',
'!src/app/**/layout.tsx',
'!src/app/globals.css',
'!src/middleware.ts',
],
// Coverage thresholds
coverageThreshold: {
global: {
branches: 70,
functions: 70,
lines: 70,
statements: 70,
},
// Specific thresholds for critical files
'src/lib/auth-service.ts': {
branches: 80,
functions: 80,
lines: 80,
statements: 80,
},
'src/lib/db.ts': {
branches: 80,
functions: 80,
lines: 80,
statements: 80,
},
'src/lib/database-new.ts': {
branches: 75,
functions: 75,
lines: 75,
statements: 75,
},
},
// Coverage output directory
coverageDirectory: '<rootDir>/coverage',
// Coverage reporters
coverageReporters: [
'text',
'text-summary',
'html',
'lcov',
'json',
],
// Transform configuration
transform: {
'^.+\\.(js|jsx|ts|tsx)$': ['babel-jest', { presets: ['next/babel'] }],
},
// Module file extensions
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'],
// Global test timeout
testTimeout: 30000,
// Verbose output
verbose: true,
// Clear mocks between tests
clearMocks: true,
// Restore mocks after each test
restoreMocks: true,
// Error handling
errorOnDeprecated: true,
// Watch mode configuration
watchPathIgnorePatterns: [
'<rootDir>/node_modules/',
'<rootDir>/.next/',
'<rootDir>/coverage/',
],
// Globals available in tests
globals: {
'ts-jest': {
tsconfig: {
jsx: 'react-jsx',
},
},
},
};
// createJestConfig is exported this way to ensure that next/jest can load the Next.js config which is async
module.exports = createJestConfig(customJestConfig);