forked from LedgerHQ/ledger-live
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjest.config.js
More file actions
146 lines (141 loc) · 5.47 KB
/
Copy pathjest.config.js
File metadata and controls
146 lines (141 loc) · 5.47 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
const { compilerOptions } = require("./tsconfig");
// Helper function to convert TypeScript paths to Jest moduleNameMapper
// This replaces pathsToModuleNameMapper from ts-jest which is not available in @swc/jest
function pathsToModuleNameMapper(paths, { prefix = "<rootDir>/" } = {}) {
const jestPaths = {};
if (!paths) return jestPaths;
Object.keys(paths).forEach(pathKey => {
// tsconfig uses "*": ["./*"] instead of baseUrl; mapping (.*) -> $1 breaks every module in Jest
if (pathKey === "*") return;
const pathValues = Array.isArray(paths[pathKey]) ? paths[pathKey] : [paths[pathKey]];
pathValues.forEach(pathValue => {
// Convert TypeScript path pattern to Jest regex pattern
// Use /\*$/ for key (wildcard at end) but /\*/ for value (wildcard can be anywhere)
const jestKey = pathKey.replace(/\*$/, "(.*)");
const jestValue = pathValue.replace(/\*/g, "$1");
jestPaths[jestKey] = `${prefix}${jestValue}`;
});
});
return jestPaths;
}
const transformIncludePatterns = [
"@react-native/polyfills",
"(jest-)?react-native",
"@react-native(-community)?",
"@react-navigation",
"react-native-worklets",
"react-native-reanimated",
"react-native-modal",
"@hashgraph/sdk",
"react-native-startup-time",
"@segment/analytics-react-native",
"uuid",
"react-native-ble-plx",
"react-native-android-location-services-dialog-box",
"react-native-qrcode-svg",
"react-native-video",
"ky",
"@gorhom/bottom-sheet",
"react-native-safe-area-context",
"react-native-gesture-handler",
"@shopify/flash-list",
"@ledgerhq/lumen-.*",
"immer",
"@features/.*",
"@sbaiahmed1/react-native-blur",
"@mysten",
"@scure",
"@noble",
"d3-.*",
"internmap",
];
/** @type {import('@swc/jest').JestConfigWithTsJest} */
module.exports = {
/** CI sets `JEST_MAX_WORKERS` (e.g. `100%`); local default leaves laptops headroom. */
maxWorkers: process.env.JEST_MAX_WORKERS || "50%",
// CI: `verbose: false` so Jest uses BufferedConsole and jest-quiet-reporter
// can replay captured logs only on failure. Local: keep verbose streaming so
// engineers see per-test logs live.
verbose: !process.env.CI,
preset: "react-native",
workerIdleMemoryLimit: "1GB",
modulePaths: [compilerOptions.baseUrl ?? "."],
setupFilesAfterEnv: [
"./node_modules/react-native-gesture-handler/jestSetup.js",
"./__tests__/jest-setup.js",
],
testMatch: ["**/src/**/*.test.(ts|tsx)"],
transform: {
"^.+\\.(t)sx?$": [
"@swc/jest",
{
jsc: {
target: "esnext",
transform: {
react: {
runtime: "automatic",
},
},
},
},
],
"^.+\\.mjs$": [
"@swc/jest",
{
jsc: {
target: "esnext",
},
},
],
},
transformIgnorePatterns: [
`node_modules/(?!(.pnpm|${transformIncludePatterns.join("|")})/)`,
"\\.pnp\\.[^\\/]+$",
],
testPathIgnorePatterns: ["<rootDir>/node_modules/"],
moduleDirectories: ["node_modules"],
collectCoverageFrom: [
"src/**/*.{ts,tsx}",
"!src/**/*.test.{ts,tsx}",
"!src/**/*.spec.{ts,tsx}",
"!src/**/__integration__/**",
"!src/**/__integrations__/**",
"!src/**/__tests__/**",
],
coverageReporters: ["json", ["lcov", { projectRoot: "../" }], "json-summary"],
reporters: [
// CI: jest-quiet-reporter buffers stdout/stderr per test and flushes only on
// failure, keeping passing-run logs out of the workflow output. Local: keep
// the default reporter so engineers see live streaming logs.
process.env.CI ? "jest-quiet-reporter" : "default",
// CI: emit GitHub Actions ::error file=… annotations. We use a thin subclass
// of the built-in github-actions reporter that writes via fs.writeSync(2, …)
// instead of process.stderr.write — jest-quiet-reporter's __wrapStdio replaces
// process.stderr.write with a swallow-everything stub, so the built-in
// string reporter's annotations would otherwise be dropped on the floor.
...(process.env.CI ? [["<rootDir>/scripts/jestGithubActionsReporter.js", {}]] : []),
["jest-sonar", { outputName: "sonar-executionTests-report.xml", reportedFilePath: "absolute" }],
],
resolver: "<rootDir>/scripts/resolver.js",
moduleNameMapper: {
...pathsToModuleNameMapper(compilerOptions.paths),
"^@ledgerhq/lumen-ui-rnative$":
"<rootDir>/node_modules/@ledgerhq/lumen-ui-rnative/src/index.ts",
"^@ledgerhq/lumen-design-core$": "<rootDir>/node_modules/@ledgerhq/lumen-design-core",
"^react$": "<rootDir>/node_modules/react",
"^react/(.*)$": "<rootDir>/node_modules/react/$1",
"^react-native/(.*)$": "<rootDir>/node_modules/react-native/$1",
"^react-native$": "<rootDir>/node_modules/react-native",
"^react-native-gesture-handler$": "<rootDir>/node_modules/react-native-gesture-handler",
"^react-native-gesture-handler/(.*)$": "<rootDir>/node_modules/react-native-gesture-handler/$1",
"styled-components":
"<rootDir>/node_modules/styled-components/native/dist/styled-components.native.cjs.js",
"^react-redux": "<rootDir>/node_modules/react-redux",
"^@tanstack/react-query$":
"<rootDir>/../../node_modules/.pnpm/@tanstack+react-query@5.28.9_react@19.0.0/node_modules/@tanstack/react-query",
// Redirect to mock for pre-compiled dependencies (like @ledgerhq/native-ui)
"^react-native-worklets$": "<rootDir>/__mocks__/react-native-worklets.js",
// Global mock for .lottie (dotLottie) files
"\\.(lottie)$": "<rootDir>/__mocks__/lottieMock.js",
},
};