-
Notifications
You must be signed in to change notification settings - Fork 87
Expand file tree
/
Copy pathjest.config.js
More file actions
66 lines (63 loc) · 2.78 KB
/
jest.config.js
File metadata and controls
66 lines (63 loc) · 2.78 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
const os = require("node:os");
// Use cgroup-aware memory when available (containers), fall back to host RAM.
// process.constrainedMemory() returns the cgroup v2 limit (Node 19.6+),
// or 0/undefined outside a cgroup.
const totalMemoryBytes =
(typeof process.constrainedMemory === "function" &&
process.constrainedMemory()) ||
os.totalmem();
const cpuWorkerCap = Math.max(1, Math.floor(os.cpus().length * 0.5));
const memoryWorkerCap = Math.floor(
totalMemoryBytes / (1024 * 1024 * 1024) / 1.5,
);
const maxWorkers = Math.max(1, Math.min(cpuWorkerCap, memoryWorkerCap));
/** @type {import('jest').Config} */
module.exports = {
testEnvironment: "node",
testMatch: ["<rootDir>/src/**/*.test.ts", "<rootDir>/tests/**/*.test.ts"],
collectCoverageFrom: [
"src/**/*.ts",
"!src/**/*.d.ts",
"!src/desktop/preload.ts",
"!src/browser/api.ts",
"!src/cli/**/*",
"!src/desktop/main.ts",
],
setupFilesAfterEnv: ["<rootDir>/tests/setup.ts"],
moduleNameMapper: {
// Vite query suffixes and binary assets must be matched BEFORE the @/ alias
"^@/(.+)\\.svg\\?react$": "<rootDir>/tests/__mocks__/svgReactMock.js",
"^@/(.+)\\.txt\\?raw$": "<rootDir>/tests/__mocks__/textMock.js",
"^@/(.*)$": "<rootDir>/src/$1",
// lottie-web probes canvas on import, which crashes in happy-dom/jsdom
"^lottie-react$": "<rootDir>/tests/__mocks__/lottieReactMock.js",
"^chalk$": "<rootDir>/tests/__mocks__/chalk.js",
"^jsdom$": "<rootDir>/tests/__mocks__/jsdom.js",
// Mock static assets for full App rendering
"\\.css$": "<rootDir>/tests/__mocks__/styleMock.js",
"\\.txt$": "<rootDir>/tests/__mocks__/textMock.js",
"\\.svg$": "<rootDir>/tests/__mocks__/svgMock.js",
},
// Storybook UI tests use bun:test and are run via `bun test`, so Jest must skip them.
testPathIgnorePatterns: ["<rootDir>/tests/ui/storybook/"],
// Avoid haste module collision with vscode extension
modulePathIgnorePatterns: ["<rootDir>/vscode/"],
transform: {
"^.+\\.(ts|tsx|js|mjs)$": ["babel-jest"],
},
// Transform ESM-only packages. Use negative lookahead to transform everything
// EXCEPT known CJS packages, which is more maintainable than listing all ESM packages.
transformIgnorePatterns: [
// Transform all node_modules - ESM packages need babel transformation
// This is slower but ensures compatibility
"node_modules/(?!\\.pnpm)(?!.*)",
],
// High core-count containers with limited cgroup memory (for example 96 cores /
// 32 GB) can OOM if Jest uses CPU-only parallelism, so keep roughly 1.5 GB
// per worker.
maxWorkers,
// Force exit after tests complete to avoid hanging on lingering handles
forceExit: true,
// 10 minute timeout for integration tests, 10s for unit tests
testTimeout: process.env.TEST_INTEGRATION === "1" ? 600000 : 10000,
};