Repository navigation
Expand file tree
/
Copy pathjest.config.js
More file actions
174 lines (163 loc) · 5.33 KB
/
Copy pathjest.config.js
File metadata and controls
174 lines (163 loc) · 5.33 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
/**
* Jest configuration with separate projects for different test environments.
*
* We use two separate projects:
* 1. "unit" - Node environment for pure unit tests (no DOM needed)
* 2. "integration" - jsdom environment for React integration tests
*
* This allows us to run tests with the correct environment automatically
* without needing @jest-environment comments in every test file.
*/
// Shared configuration
const sharedConfig = {
preset: "ts-jest",
setupFilesAfterEnv: ["<rootDir>/tests/setup/jest.setup.ts"],
// Performance: Use 50% of CPU cores for parallel execution
maxWorkers: "50%",
moduleNameMapper: {
// Mock CSS files (before path alias resolution)
// CSS/static assets cannot be executed in tests and must be mocked
"^@/.*\\.(css|less|scss|sass)$": "<rootDir>/tests/setup/mocks/cssMock.js",
"^katex/dist/katex.min.css$": "<rootDir>/tests/setup/mocks/cssMock.js",
"\\.(css|less|scss|sass)$": "<rootDir>/tests/setup/mocks/cssMock.js",
// Mock static file imports
"\\.(jpg|jpeg|png|gif|svg|woff|woff2|ttf|eot)$":
"<rootDir>/tests/setup/fileMock.js",
// Mock specific components that have complex dependencies
"^@/providers/UserProvider$":
"<rootDir>/tests/setup/mocks/components/UserProvider.tsx",
// Path aliases (must come after specific mocks)
"^@/(.*)$": "<rootDir>/src/$1",
"^@tests/(.*)$": "<rootDir>/tests/$1",
"^@opal$": "<rootDir>/lib/opal/src/index.ts",
"^@opal/(.*)$": "<rootDir>/lib/opal/src/$1",
},
testPathIgnorePatterns: ["/node_modules/", "/tests/e2e/", "/.next/"],
// Transform ES Modules in node_modules to CommonJS for Jest compatibility
// Add packages here when you encounter: "SyntaxError: Unexpected token 'export'"
// These packages ship as ESM and need to be transformed to work in Jest
transformIgnorePatterns: [
"/node_modules/(?!(" +
[
// Auth & Security
"jose",
// UI Libraries
"@radix-ui",
"@headlessui",
"@phosphor-icons",
// Testing & Mocking
"msw",
"until-async",
// Language Detection
"linguist-languages",
// Markdown & Syntax Highlighting
"react-markdown",
"remark-.*", // All remark packages
"rehype-.*", // All rehype packages
"unified",
"lowlight",
"highlight\\.js",
// Markdown Utilities
"bail",
"is-plain-obj",
"trough",
"vfile",
"vfile-.*", // All vfile packages
"unist-.*", // All unist packages
"mdast-.*", // All mdast packages
"hast-.*", // All hast packages
"hastscript",
"micromark.*", // All micromark packages
"decode-named-character-reference",
"character-entities",
"devlop",
"comma-separated-tokens",
"property-information",
"space-separated-tokens",
"html-void-elements",
"html-url-attributes",
"aria-attributes",
"web-namespaces",
"svg-tag-names",
"style-to-object",
"inline-style-parser",
"ccount",
"escape-string-regexp",
"markdown-table",
"longest-streak",
"zwitch",
"trim-lines",
"stringify-entities",
"estree-.*", // All estree packages
].join("|") +
")/)",
],
transform: {
"^.+\\.(t|j)sx?$": [
"ts-jest",
{
// Performance: Disable type-checking in tests (types are checked by tsc)
isolatedModules: true,
tsconfig: {
jsx: "react-jsx",
// Allow ts-jest to process JavaScript files from node_modules
allowJs: true,
},
},
],
},
// Performance: Cache results between runs
cache: true,
cacheDirectory: "<rootDir>/.jest-cache",
collectCoverageFrom: [
"src/**/*.{ts,tsx}",
"!src/**/*.d.ts",
"!src/**/*.stories.tsx",
],
coveragePathIgnorePatterns: ["/node_modules/", "/tests/", "/.next/"],
// Performance: Clear mocks automatically between tests
clearMocks: true,
resetMocks: false,
restoreMocks: false,
};
module.exports = {
projects: [
{
displayName: "unit",
...sharedConfig,
testEnvironment: "node",
testMatch: [
// Pure unit tests that don't need DOM
"**/src/**/codeUtils.test.ts",
"**/src/lib/**/*.test.ts",
"**/src/app/**/services/*.test.ts",
"**/src/app/**/utils/*.test.ts",
"**/src/app/**/hooks/*.test.ts", // Pure packet processor tests
"**/src/hooks/**/*.test.ts",
"**/src/refresh-components/**/*.test.ts",
"**/src/refresh-pages/**/*.test.ts",
"**/src/sections/**/*.test.ts",
"**/src/components/**/*.test.ts",
"**/lib/opal/**/*.test.ts",
// Add more patterns here as you add more unit tests
],
},
{
displayName: "integration",
...sharedConfig,
testEnvironment: "jsdom",
testMatch: [
// React component integration tests
"**/src/app/**/*.test.tsx",
"**/src/components/**/*.test.tsx",
"**/src/lib/**/*.test.tsx",
"**/src/providers/**/*.test.tsx",
"**/src/refresh-components/**/*.test.tsx",
"**/src/refresh-pages/**/*.test.tsx",
"**/src/hooks/**/*.test.tsx",
"**/src/sections/**/*.test.tsx",
// Add more patterns here as you add more integration tests
],
},
],
};
2C26