forked from Expensify/App
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjest.config.js
More file actions
72 lines (69 loc) · 4.72 KB
/
Copy pathjest.config.js
File metadata and controls
72 lines (69 loc) · 4.72 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
const testFileExtension = 'ts?(x)';
// Reassure runs only the performance tests, matched by the `.perf-test` suffix / `__perf__` folder,
// which it passes to Jest as `--testMatch`. We detect that from the test-runner argv so we can leave
// `performance` real for perf runs only: enabling Jest's modern fake timers globally also fakes
// `performance`, and React's Scheduler captures that (frozen) clock once at module load, which zeroes
// every React Profiler render duration — and thus every Reassure `[render]` measurement.
const isPerfTestRun = process.argv.some((arg) => arg.includes('perf-test') || arg.includes('__perf__'));
// With `--coverage`, Jest also instruments every file matched by `collectCoverageFrom` that no test loaded, so
// untested files show up at 0%. Under `--shard=N/M` each shard would repeat that pass over all of `src/**`
// (~7k files, 10-60s per shard). Only the first shard emits the untested files, the others report just what
// their tests load. Codecov unions the per-shard reports, so the merged totals are unchanged.
const shardMatch = process.argv.map((arg) => /^--shard=(\d+)\/\d+$/.exec(arg)).find(Boolean);
const emitsUntestedFiles = !shardMatch || shardMatch[1] === '1';
module.exports = {
preset: 'jest-expo',
collectCoverageFrom: emitsUntestedFiles ? ['<rootDir>/src/**/*.{ts,tsx,js,jsx}', '!<rootDir>/src/**/__mocks__/**', '!<rootDir>/src/**/tests/**', '!**/*.d.ts'] : undefined,
// Keeps the instrumented set identical to `collectCoverageFrom` above on the shards that skip it.
coveragePathIgnorePatterns: ['/node_modules/', '<rootDir>/(?!src/)', '/__mocks__/', '<rootDir>/src/.*/tests/', '\\.d\\.ts$'],
testMatch: [
`<rootDir>/tests/ui/**/*.${testFileExtension}`,
`<rootDir>/tests/unit/**/*.${testFileExtension}`,
`<rootDir>/tests/actions/**/*.${testFileExtension}`,
`<rootDir>/tests/navigation/**/*.${testFileExtension}`,
`<rootDir>/?(*.)+(spec|test).${testFileExtension}`,
],
transform: {
// OXC + esbuild is native and stays fast without TurboFan, where Babel was measured as
// roughly half of each Reassure measure job. The transformer sends test files, mocks and
// node_modules to babel-jest itself, so `jest.mock` is still hoisted there.
'^.+\\.[jt]sx?$': '<rootDir>/config/babel/oxcJestTransformer.js',
'^.+\\.svg?$': 'jest-transformer-svg',
},
transformIgnorePatterns: [
'<rootDir>/node_modules/(?!.*(react-native|expo|react-navigation|uuid|@shopify\/flash-list).*/)',
// Prevent Babel from transforming worklets in this file so they are treated as normal functions, otherwise FormatSelectionUtilsTest won't run.
'<rootDir>/node_modules/@expensify/react-native-live-markdown/lib/commonjs/parseExpensiMark.js',
],
// tests/tooling/ covers .github/ and scripts/ and runs under `bun test` instead (see the `test:bun` npm
// script), so those files import `bun:test` rather than Jest's globals. They aren't in testMatch above, and
// this keeps them out even if a future testMatch entry broadens to all of tests/.
testPathIgnorePatterns: ['<rootDir>/node_modules', '<rootDir>/tests/tooling/'],
// .worktrees/ and .claude/worktrees/ hold parallel git worktrees a developer may check out locally.
// Each one carries its own modules/hybrid-app/package.json, which trips
// jest-haste-map's "duplicate package name" assertion. Skip them entirely.
modulePathIgnorePatterns: ['<rootDir>/.worktrees/', '<rootDir>/.claude/worktrees/'],
globals: {
__DEV__: true,
WebSocket: {},
// Build-time define from config/rsbuild/rsbuild.common.ts. SkiaWebChart reads it when mounting CanvasKit.
__CANVASKIT_WASM_URL__: '/canvaskit-test.wasm',
},
fakeTimers: {
enableGlobally: true,
// `nextTick` is never faked because Onyx notifies its subscribers on process.nextTick.
// `performance` is left real only for perf runs (see isPerfTestRun above).
doNotFake: isPerfTestRun ? ['nextTick', 'performance'] : ['nextTick'],
},
testEnvironment: 'jsdom',
setupFiles: ['<rootDir>/jest/setup.ts', './node_modules/@react-native-google-signin/google-signin/jest/build/setup.js'],
setupFilesAfterEnv: ['<rootDir>/jest/setupAfterEnv.ts', '<rootDir>/tests/perf-test/setupAfterEnv.ts'],
cacheDirectory: '<rootDir>/.jest-cache',
coverageReporters: ['json', 'lcov', 'text-summary'],
moduleNameMapper: {
'\\.(lottie)$': '<rootDir>/__mocks__/fileMock.ts',
'^@lottiefiles/dotlottie-react$': '<rootDir>/__mocks__/@lottiefiles/dotlottie-react.tsx',
'^group-ib-fp$': '<rootDir>/__mocks__/group-ib-fp.ts',
'^parse-imports-exports$': '<rootDir>/node_modules/parse-imports-exports/index.cjs',
},
};