Repository navigation
Expand file tree
/
Copy pathjest.config.js
More file actions
145 lines (142 loc) · 9.46 KB
/
Copy pathjest.config.js
File metadata and controls
145 lines (142 loc) · 9.46 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
const path = require('node:path');
const fs = require('node:fs');
// pro/ is a git submodule: the directory exists even when not checked out, so detect a
// real file inside it (package.json). Mirrors metro.config.js's proExists. When pro IS
// checked out (store builds + the pro repo's PAT in CI), we run the pro-dependent suites
// against the REAL pro package instead of stubbing it — so a green public-CI run that
// pulled the submodule actually exercises TTS/MCP/audio, not a stub. Only when pro is
// genuinely absent (open-core CI without the PAT) do we ignore those suites and map
// @offgrid/pro to the null stub, so the open-core suite still runs and stays green.
const proExists = fs.existsSync(path.resolve(__dirname, 'pro/package.json'));
// Suites under THIS repo's __tests__ that import @offgrid/pro. Ignored ONLY when pro is
// absent. (pro/'s OWN suite is always ignored here — it runs in the pro repo's CI.)
const proDependentTestPaths = [
'/__tests__/pro/',
'/__tests__/unit/audio/',
'/__tests__/unit/engine/',
'/__tests__/integration/audio/',
'__tests__/unit/audioProgressCaption.test.ts',
'__tests__/unit/mcp/McpToolExtension.test.ts',
'__tests__/unit/services/ttsService.test.ts',
'__tests__/unit/stores/ttsStore.test.ts',
'__tests__/integration/stores/tts.test.ts',
'__tests__/rntl/components/ChatInputModeToggle.test.tsx',
'__tests__/rntl/components/PlaybackControls.test.tsx',
'__tests__/rntl/components/VoiceModelsPanel.test.tsx',
'__tests__/rntl/components/KokoroTTSBridge.test.tsx',
'__tests__/rntl/components/McpAddServerSheet.test.tsx',
'__tests__/rntl/components/McpServersScreen.test.tsx',
'__tests__/unit/tools/mcpPresets.test.ts',
];
module.exports = {
preset: 'react-native',
// Balances CI's --shard runs by recorded suite run time (scripts/jest-timings.json).
testSequencer: '<rootDir>/scripts/jest-sequencer.js',
setupFilesAfterEnv: ['<rootDir>/jest.setup.ts'],
testMatch: ['**/__tests__/**/*.test.ts', '**/__tests__/**/*.test.tsx'],
testPathIgnorePatterns: [
'/node_modules/', '/android/', '/ios/', '/e2e/',
// pro/ ships its own suite run in the pro repo's CI — never run those from here.
// Anchored to <rootDir>/pro/ so it ignores ONLY the submodule's own tests, NOT this
// repo's __tests__/pro/** pro-dependent suites (a bare '/pro/' matched both).
// The pro-DEPENDENT suites under this repo's __tests__ DO run against the real pro
// when it's checked out, and are ignored only when pro is genuinely absent.
'<rootDir>/pro/',
...(proExists ? [] : proDependentTestPaths),
],
// Stale agent git-worktrees under .claude/worktrees/ each carry a full repo copy (incl. their own
// pro/package.json named @offgrid/pro), which collide in Haste's module map and make require('@offgrid/pro')
// throw ("looked up in the Haste module map ... several different files"). Exclude them so the ONE real
// @offgrid/pro resolves — and so those copies aren't test-collected as duplicates.
modulePathIgnorePatterns: ['<rootDir>/.claude/worktrees/'],
moduleNameMapper: {
// Mirrors metro.config.js: @offgrid/i18n's JSX runtime lives in the shared repo, which has no React,
// so its `react/jsx-runtime` must be this app's React.
'^react/jsx-runtime$': '<rootDir>/node_modules/react/jsx-runtime.js',
'^react/jsx-dev-runtime$': '<rootDir>/node_modules/react/jsx-dev-runtime.js',
// Mirrors metro.config.js: the translated catalogs beside the i18n package.
'^@offgrid/i18n/catalogs/(.*)$': '<rootDir>/../shared/packages/i18n/catalogs/$1',
'^@/(.*)$': '<rootDir>/src/$1',
// Mirrors the metro alias so tests can import pro modules that reference core.
'^@offgrid/core/(.*)$': '<rootDir>/src/$1',
// Mirrors the metro alias: the real pro package when present on disk, else the null
// stub so open-core tests resolve @offgrid/pro cleanly.
'^@offgrid/pro$': proExists ? '<rootDir>/pro' : '<rootDir>/src/bootstrap/proStub.js',
'^@offgrid/pro/(.*)$': proExists ? '<rootDir>/pro/$1' : '<rootDir>/src/bootstrap/proStub.js',
// Mirrors the metro alias: 'react-native-fs' resolves to the maintained fork
// (the only RNFS native module we ship — see metro.config.js).
'^react-native-fs$': '<rootDir>/src/shims/react-native-fs.ts',
// @offgrid/sync: test against SOURCE (jest transforms the TS) rather than the tsup dist,
// which references @babel/runtime helpers not resolvable from the out-of-root package. Keep
// these subpaths in step with metro.config.js's aliases and the package's exports map.
// @offgrid/design: the one token source, tested from source like sync.
'^@offgrid/design$': '<rootDir>/../shared/packages/design/src/index.ts',
'^@offgrid/sync$': '<rootDir>/../shared/packages/sync/src/index.ts',
'^@offgrid/sync/rn$': '<rootDir>/../shared/packages/sync/src/adapters/rn-tcp.ts',
'^@offgrid/sync/rn-discovery$': '<rootDir>/../shared/packages/sync/src/adapters/rn-discovery.ts',
'^@offgrid/sync/portable$': '<rootDir>/../shared/packages/sync/src/portable/index.ts',
// Scribe and Notes logic, also tested against SOURCE for the same reason as @offgrid/sync.
'^@offgrid/writing$': '<rootDir>/../shared/packages/writing/src/index.ts',
'^@offgrid/notes$': '<rootDir>/../shared/packages/notes/src/index.ts',
// The sync source lives out-of-root; when jest transforms it, babel injects @babel/runtime
// helper imports that would otherwise resolve from ../shared (where they aren't installed).
// Pin them to mobile's own copy.
'^@babel/runtime/(.*)$': '<rootDir>/node_modules/@babel/runtime/$1',
},
transformIgnorePatterns: ['node_modules/(?!(react-native|@react-native|@react-navigation|react-native-.*|@react-native-.*|moti|@motify|@gorhom|@shopify|@ronradtke|@op-engineering|@offgrid)/)',],
testEnvironment: 'node',
clearMocks: true,
verbose: true,
testTimeout: 10000,
collectCoverageFrom: [
'src/**/*.{ts,tsx}',
'!src/**/index.ts',
'!src/types/**',
'!src/navigation/**',
// Measure the pro submodule too when it's checked out (the pro-dependent suites here
// exercise it). Skip barrels (index.ts) + type decls; index.tsx (real components) stays.
...(proExists
? ['pro/**/*.{ts,tsx}', '!pro/**/index.ts', '!pro/**/*.d.ts', '!pro/**/__tests__/**', '!pro/**/*.test.{ts,tsx}']
: []),
],
coverageReporters: ['text', 'text-summary', 'lcov', 'json-summary'],
coverageThreshold: {
// `global` gates src/ at 75. A glob key REMOVES matching files from `global` and gates
// them separately — so the pro group below carves pro out of the src gate.
global: {
statements: 75,
branches: 75,
functions: 75,
lines: 75,
},
// pro/ is MEASURED here (visible in the core report + regression-guarded), carved out
// of the src `global` gate into its own group. The pro-dependent suites in this repo
// (incl. the __tests__/pro/** real-behavior tests) cover ~60% of pro; this floor
// ratchets that so it can't slide, and is raised as more pro tests land. New pro
// modules also add their own per-file 100 key. NOTE: this is a DIRECTORY key (not a
// glob) so jest aggregates all pro files into ONE group — a glob (`pro/**`) would apply
// per-file and fail on the many pro files no core suite imports.
// Pro is measured separately because this directory key removes it from the global group.
'./pro': { statements: 75, branches: 75, functions: 75, lines: 75 },
// New standalone modules in this change set are held to 100% on every axis. Changed
// legacy files have their NEW branches covered by the suites but aren't whole-file-100%.
'./src/services/imageModelIntegrity.ts': { statements: 100, branches: 100, functions: 100, lines: 100 },
'./src/utils/imageGenAdvice.ts': { statements: 100, branches: 100, functions: 100, lines: 100 },
'./src/services/modelLoadErrors.ts': { statements: 100, branches: 100, functions: 100, lines: 100 },
'./src/components/ImageGenAdviceCard.tsx': { statements: 100, branches: 100, functions: 100, lines: 100 },
'./src/components/VoiceRecordButton/derive.ts': { statements: 100, branches: 100, functions: 100, lines: 100 },
// Opt-in analytics (docs/ANALYTICS.md): every new module is held to 100% on every axis.
'./src/services/analytics/analytics.ts': { statements: 100, branches: 100, functions: 100, lines: 100 },
'./src/services/analytics/client.ts': { statements: 100, branches: 100, functions: 100, lines: 100 },
'./src/services/analytics/consentPrompt.ts': { statements: 100, branches: 100, functions: 100, lines: 100 },
'./src/services/analytics/featureSnapshot.ts': { statements: 100, branches: 100, functions: 100, lines: 100 },
'./src/services/analytics/modelFacts.ts': { statements: 100, branches: 100, functions: 100, lines: 100 },
'./src/services/analytics/scrub.ts': { statements: 100, branches: 100, functions: 100, lines: 100 },
'./src/services/analytics/uncleanExit.ts': { statements: 100, branches: 100, functions: 100, lines: 100 },
'./src/services/analytics/values.ts': { statements: 100, branches: 100, functions: 100, lines: 100 },
'./src/services/problemReport.ts': { statements: 100, branches: 100, functions: 100, lines: 100 },
'./src/components/AnalyticsConsentPrompt.tsx': { statements: 100, branches: 100, functions: 100, lines: 100 },
'./src/screens/AnalyticsInfoScreen.tsx': { statements: 100, branches: 100, functions: 100, lines: 100 },
'./src/screens/SettingsAnalyticsSection.tsx': { statements: 100, branches: 100, functions: 100, lines: 100 },
},
};