vitest-native 0.12.0 → 0.14.0-rc.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +343 -0
- package/README.md +138 -48
- package/dist/cli.cjs +70 -5
- package/dist/cli.d.cts +2 -3
- package/dist/cli.d.mts +2 -3
- package/dist/cli.mjs +70 -5
- package/dist/{ecosystem-Duw40-mO.mjs → ecosystem-DFbU_MPe.mjs} +389 -18
- package/dist/{ecosystem-CEIF_-jq.cjs → ecosystem-DI1AhK_k.cjs} +408 -25
- package/dist/errors.d.mts +12 -0
- package/dist/helpers.cjs +51 -3
- package/dist/helpers.d.cts +14 -8
- package/dist/helpers.d.mts +14 -8
- package/dist/helpers.mjs +51 -4
- package/dist/{index-CPGq6p95.d.cts → index-BxzW2D7K.d.cts} +33 -9
- package/dist/{index-CmETArCM.d.mts → index-CEbwa4QU.d.mts} +33 -9
- package/dist/index.d.mts +4 -4
- package/dist/index.mjs +436 -95
- package/dist/jest-compat/aliases.d.mts +5 -0
- package/dist/jest-compat/aliases.mjs +65 -0
- package/dist/jest-compat/caller.mjs +53 -0
- package/dist/jest-compat/setup.mjs +72 -36
- package/dist/jest-compat.cjs +1 -3
- package/dist/jest-compat.d.cts +4 -5
- package/dist/jest-compat.d.mts +4 -5
- package/dist/jest-compat.mjs +1 -1
- package/dist/matchers.d.cts +9 -9
- package/dist/matchers.d.mts +9 -9
- package/dist/memory-6EPHrJA1.cjs +144 -0
- package/dist/memory-FYbP0_gg.mjs +126 -0
- package/dist/native/boundary.mjs +13 -2
- package/dist/native/bounded-process.mjs +165 -0
- package/dist/native/export-condition-recovery-preload.mjs +5 -0
- package/dist/native/export-condition-recovery.mjs +195 -0
- package/dist/native/globals.mjs +154 -7
- package/dist/native/hooks.mjs +133 -62
- package/dist/native/loader.mjs +52 -28
- package/dist/native/match.d.mts +3 -0
- package/dist/native/match.mjs +38 -2
- package/dist/native/metro-profile-compiler.mjs +234 -0
- package/dist/native/metro-profile.mjs +115 -0
- package/dist/native/module-reset.mjs +111 -6
- package/dist/native/ownership.d.mts +105 -0
- package/dist/native/ownership.mjs +474 -0
- package/dist/native/registry-compiler.mjs +43 -0
- package/dist/native/registry-process.mjs +124 -0
- package/dist/native/registry.mjs +148 -29
- package/dist/native/reset.mjs +305 -135
- package/dist/native/resolve.d.mts +14 -3
- package/dist/native/resolve.mjs +51 -8
- package/dist/native/rntl-hooks.mjs +76 -0
- package/dist/native/setup.mjs +82 -33
- package/dist/native/state-manifest.d.mts +22 -0
- package/dist/native/state-manifest.mjs +136 -0
- package/dist/native/transform.mjs +21 -8
- package/dist/native/worker.mjs +52 -4
- package/dist/pool-B4yesGhI.cjs +121 -0
- package/dist/pool-DjpOjOf3.mjs +119 -0
- package/dist/{presets-CwO_c4aL.cjs → presets-BYHmi7-W.cjs} +125 -20
- package/dist/{presets-IStcJEOa.mjs → presets-DC-eM5IA.mjs} +125 -20
- package/dist/presets.d.mts +1 -1
- package/dist/presets.mjs +1 -1
- package/dist/rntl-matchers.d.ts +58 -12
- package/dist/serializer.cjs +4 -2
- package/dist/serializer.d.cts +3 -4
- package/dist/serializer.d.mts +3 -4
- package/dist/serializer.mjs +4 -2
- package/dist/setup.mjs +86 -51
- package/dist/worker-vitest-BGPo0ek6.mjs +49 -0
- package/dist/worker-vitest-BfiQB8ND.cjs +62 -0
- package/docs/hot-default-design.md +175 -88
- package/docs/migrating-from-jest.md +12 -5
- package/docs/migrating-from-vitest-react-native.md +5 -5
- package/docs/release-readiness.md +39 -13
- package/docs/versioning.md +19 -18
- package/package.json +43 -32
- package/dist/pool-BU-1ecIF.cjs +0 -122
- package/dist/pool-Bcxn9a3I.mjs +0 -118
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,348 @@
|
|
|
1
1
|
# vitest-native
|
|
2
2
|
|
|
3
|
+
## 0.14.0
|
|
4
|
+
|
|
5
|
+
### Upgrading from 0.13
|
|
6
|
+
|
|
7
|
+
- **The native engine reuses workers by default.** `hotRuntime` now defaults to `'auto'` (it was
|
|
8
|
+
`false`): workers are reused across test files, with React Native, the app and test modules, and
|
|
9
|
+
verified process state reset per file. It keeps Vitest's per-file isolation whenever the run cannot
|
|
10
|
+
be bounded, or when you set a pool or `test.isolate` yourself, in the config or on the command line.
|
|
11
|
+
- **How to tell, and how to opt out.** When it is active, the startup banner names it, as in
|
|
12
|
+
`(platform ios, hot runtime)`. If a test passes on its own but fails alongside others, see
|
|
13
|
+
[troubleshooting](https://danfry1.github.io/vitest-native/guide/troubleshooting#a-test-passes-on-its-own-but-fails-when-run-with-other-files);
|
|
14
|
+
`hotRuntime: false` restores per-file isolation.
|
|
15
|
+
- **`hotRuntime: true` is stricter.** Combined with a configured pool, `test.isolate`, or a conflicting
|
|
16
|
+
CLI flag, it now fails at startup with `HOT_RUNTIME_OVERRIDDEN` instead of warning and overriding.
|
|
17
|
+
|
|
18
|
+
### Minor Changes
|
|
19
|
+
|
|
20
|
+
- 87d8dd0: Use the hot runtime for suites migrated from Jest under `hotRuntime: 'auto'`
|
|
21
|
+
|
|
22
|
+
`'auto'`, the default, no longer keeps per-file isolation for suites set up with
|
|
23
|
+
`jestMockTransform()` or the jest-compat setup. The jest-compat surface — `jest.mock` in
|
|
24
|
+
its hoisted, partial, factory-less and runtime forms, spies on React Native APIs, `console`
|
|
25
|
+
and package exports, fake timers and `jest.setSystemTime`, `jest.setTimeout`, globals,
|
|
26
|
+
`process.env`, snapshot state, React Native Testing Library cleanup, and a project setup
|
|
27
|
+
file's top-level mocks, matchers and globals — now has its own cross-file isolation gate
|
|
28
|
+
under the hot runtime. `hotRuntime: false` keeps
|
|
29
|
+
per-file isolation for a suite that needs it.
|
|
30
|
+
|
|
31
|
+
- d0d968a: Use the hot runtime by default where it can be bounded
|
|
32
|
+
|
|
33
|
+
`hotRuntime` now defaults to `'auto'` under the native engine. A run reuses workers and resets
|
|
34
|
+
React Native's registry, the app/test module graph and the verified process state per file
|
|
35
|
+
whenever the scheduler provides recyclable boundaries (at least two workers within the memory
|
|
36
|
+
plan), no other pool is configured, and the worker and the project resolve the same Vitest
|
|
37
|
+
version; otherwise it keeps Vitest's per-file isolation, as before. Suites set up for Jest
|
|
38
|
+
migration are included (see the separate entry on admitting them).
|
|
39
|
+
|
|
40
|
+
When hot is selected, concurrency follows the hot memory plan, which caps automatic workers at
|
|
41
|
+
four. Set implicitly, `'auto'` is quiet about both its fallbacks and that cap;
|
|
42
|
+
`diagnostics: true`, or setting `hotRuntime: 'auto'` explicitly, reports them.
|
|
43
|
+
`hotRuntime: false` restores per-file isolation unconditionally, and `hotRuntime: true` still
|
|
44
|
+
requires hot mode and fails closed when it cannot be bounded — including on a Vitest version
|
|
45
|
+
mismatch, which `'auto'` treats as a reason to fall back.
|
|
46
|
+
|
|
47
|
+
- 2581950: Add an experimental `metroConfig` option that reads the project's Metro resolution profile
|
|
48
|
+
|
|
49
|
+
`reactNative({ metroConfig: true })` evaluates the project's Metro config (or Expo's defaults)
|
|
50
|
+
in a short-lived, memory-bounded child process and applies its declarative resolution profile:
|
|
51
|
+
source extensions and their order, and asset extensions. Main fields and conditions are
|
|
52
|
+
reported under `diagnostics`. `metroConfig: { configFile }` points at a config outside the
|
|
53
|
+
project root. A custom `resolver.resolveRequest` is code and does not run under Vitest; the
|
|
54
|
+
extensions still apply and one warning names the gap. Default: `false`.
|
|
55
|
+
|
|
56
|
+
### Patch Changes
|
|
57
|
+
|
|
58
|
+
- 7f70965: Fix multi-project runs failing when a native project uses the hot runtime
|
|
59
|
+
|
|
60
|
+
Vitest runs projects that share a `sequence.groupOrder` (0 unless set) as one group, and stops
|
|
61
|
+
the run when they resolve to different `maxWorkers` ("Projects … have different 'maxWorkers'
|
|
62
|
+
but same 'sequence.groupOrder'"). The hot runtime's memory plan caps workers at four, while a
|
|
63
|
+
project beside it, such as a mock-engine or non-React-Native project, gets Vitest's default of one
|
|
64
|
+
fewer than the CPUs. So a config with a native project and another project failed on any machine
|
|
65
|
+
with more than five cores. `hotRuntime: 'auto'` now keeps Vitest's isolation and worker count for
|
|
66
|
+
that project and says why. An explicit `hotRuntime: true` fails with `HOT_RUNTIME_OVERRIDDEN`,
|
|
67
|
+
because a distinct `test.sequence.groupOrder` is what lets the two run as separate groups.
|
|
68
|
+
|
|
69
|
+
- 0063f23: Fix `environment: 'jsdom'` failing to start any test worker
|
|
70
|
+
|
|
71
|
+
Vitest forwards the project's resolve conditions, including the `react-native` condition both
|
|
72
|
+
engines add, to each worker as Node `--conditions` flags. Vitest also loads the test environment
|
|
73
|
+
in that worker. jsdom depends on lru-cache, whose 11.5.3 export map names a `react-native`
|
|
74
|
+
CommonJS build it does not publish, so every worker failed with "Cannot find module
|
|
75
|
+
…/lru-cache/dist/commonjs/react-native/index.min.js". The plugin now preloads a resolver
|
|
76
|
+
recovery in each worker. When Node fails because a package's `react-native` export target does
|
|
77
|
+
not exist, the same export is resolved with the process's other conditions, as Node would
|
|
78
|
+
without `react-native`. Every other resolution is left exactly as Node makes it. jsdom and
|
|
79
|
+
happy-dom now work with both engines, with and without the hot runtime.
|
|
80
|
+
|
|
81
|
+
- 49975e0: Keep Vitest's own settings under `hotRuntime: 'auto'`, including CLI flags
|
|
82
|
+
|
|
83
|
+
- An explicit `test.isolate` (or `--isolate` / `--no-isolate`) is now a reason for `'auto'` to keep
|
|
84
|
+
Vitest's semantics instead of selecting the hot runtime: `true` gets a fresh worker per file,
|
|
85
|
+
`false` one module graph shared across files, as Vitest documents them.
|
|
86
|
+
- On Vitest 4, CLI flags such as `--maxWorkers=1`, `--no-file-parallelism`, `--pool` and
|
|
87
|
+
`--no-isolate` reach the resolved config only after plugins' config hooks run, so `'auto'` chose
|
|
88
|
+
the hot runtime without seeing them. `vitest run --maxWorkers=1` then failed with
|
|
89
|
+
`HOT_MEMORY_UNBOUNDED` and did not exit. The choice is now re-checked against the resolved config
|
|
90
|
+
before any worker starts, per project and on both Vitest majors: `'auto'` falls back to Vitest's
|
|
91
|
+
settings (including its worker count) and says so.
|
|
92
|
+
- An explicit `hotRuntime: true` no longer overrides a configured pool or `test.isolate` with a
|
|
93
|
+
warning, or a conflicting CLI flag silently: it fails at startup with `HOT_RUNTIME_OVERRIDDEN`.
|
|
94
|
+
- `--pool=vmThreads` / `--pool=vmForks` on the command line now fail with `UNSUPPORTED_POOL`, as
|
|
95
|
+
the same pools in the config already did.
|
|
96
|
+
- The engine banner names the hot runtime when it is in use, so a cross-file failure points at
|
|
97
|
+
`hotRuntime: false` from the first line of the log.
|
|
98
|
+
|
|
99
|
+
- 49975e0: Fix inline `test.projects` on Vitest 5 running without vitest-native's setup
|
|
100
|
+
|
|
101
|
+
Vitest 5 lets an inline project (`projects: [{ extends: true, … }]`) share the declaring
|
|
102
|
+
config's Vite server and builds its `test` options from the raw user config, before any
|
|
103
|
+
plugin's `config` hook runs. Those projects lost everything vitest-native adds to `test` —
|
|
104
|
+
setup files, module ownership, env, the hot runtime — and their tests failed to load. The
|
|
105
|
+
plugin now pins each inline project's `root` to the root it inherits anyway, which makes Vitest
|
|
106
|
+
resolve it through the config file with the plugin, as on Vitest 4. This works in a nested
|
|
107
|
+
config too, where `test.sharedViteServer` (read only from the top-level config) cannot help. A
|
|
108
|
+
project that still reaches the run without the plugin's setup fails with `SHARED_VITE_SERVER`.
|
|
109
|
+
|
|
110
|
+
- 49975e0: Fix React Native 0.87 failing to load in a project with no `node_modules` of its own
|
|
111
|
+
|
|
112
|
+
A project whose dependencies are hoisted to a parent directory — a monorepo package, or a Vitest
|
|
113
|
+
project rooted in a subdirectory — had its precompiled React Native registry cached in the OS
|
|
114
|
+
temp directory. Code in that registry resolved React Native's deep self-imports from the cache
|
|
115
|
+
file's location, which cannot see the install, and failed with "Cannot find module
|
|
116
|
+
'react-native/src/private/…'". The cache now lives under the project's own `node_modules`, or else the nearest
|
|
117
|
+
one above it that contains React Native, and resolution from the registry's own code starts at the
|
|
118
|
+
project, so a cache in the temp directory (a read-only `node_modules`, or macOS's symlinked `/var`)
|
|
119
|
+
works too.
|
|
120
|
+
|
|
121
|
+
- 9ab8270: Report project-source ownership risks consistently for extensionless and platform-specific Node resolution. The warning now distinguishes resolution from proven execution or duplicate instances, and respects Node-owned, delegated and overridden ownership policies. Resolution warnings remain nonfatal.
|
|
122
|
+
- 9ab8270: Bound the native hot runtime by effective host/container memory
|
|
123
|
+
|
|
124
|
+
Hot mode now derives one worker-total plan from `os.totalmem()` and
|
|
125
|
+
`process.constrainedMemory()`, reserves main-process and worker-replacement RSS,
|
|
126
|
+
caps automatic concurrency at four, and recycles one worker at a time on local heap
|
|
127
|
+
or process RSS. It fails before starting more work at the hard RSS boundary so a
|
|
128
|
+
container reports a useful `HOT_MEMORY_BUDGET_EXCEEDED` error instead of relying on
|
|
129
|
+
an OOM kill.
|
|
130
|
+
|
|
131
|
+
Current Vitest batches every file into one unrecyclable task at one worker. Hot mode
|
|
132
|
+
now rejects that configuration with `HOT_MEMORY_UNBOUNDED` rather than silently
|
|
133
|
+
claiming its limits are active. An externally bounded run can explicitly accept the
|
|
134
|
+
risk with `hotRuntime: { allowUnboundedMemory: true }`.
|
|
135
|
+
|
|
136
|
+
The policy is covered by unit and recycle-soak gates plus a packed RN 0.87 / RNTL 14
|
|
137
|
+
Docker gate: 512 MiB and 1 GiB fail closed before registry compilation, while 2 GiB
|
|
138
|
+
caps an eight-worker request to four, passes 405 files, and demonstrably recycles.
|
|
139
|
+
|
|
140
|
+
- 9ab8270: Bound cold React Native registry compilation outside the long-lived Vite process
|
|
141
|
+
|
|
142
|
+
Cold registry cache misses now compile in a short-lived child with a 96 MiB old-space
|
|
143
|
+
cap and a 256 MiB retry only for a recognized V8 heap OOM. The parent validates the
|
|
144
|
+
atomic cache result, warm runs remain spawn-free, and ordinary failures keep the
|
|
145
|
+
visible correctness-preserving per-file fallback. Registry keys now include
|
|
146
|
+
normalized asset extensions, which affect emitted module code.
|
|
147
|
+
|
|
148
|
+
A real 438-module production gate checks artifact parity, persistent-parent RSS,
|
|
149
|
+
warm lookup, bounded latency, and concurrent cold writers.
|
|
150
|
+
|
|
151
|
+
- 290bc53: `vitest-native doctor` no longer warns that Expo core and expo-router setups "can hit known limits" and points at a migration-guide section that no longer exists. Those setups work under the native engine; doctor now reports the Expo version as covered and links the Expo guide, mentioning `vitest-native migrate` for jest-expo projects.
|
|
152
|
+
- ff77511: Install React Native's ErrorUtils under the native engine; gate expo-router end to end
|
|
153
|
+
|
|
154
|
+
`global.ErrorUtils` — React Native's error-guard polyfill, installed on device by
|
|
155
|
+
InitializeCore — is read at module scope by Expo's `Expo.fx`
|
|
156
|
+
(`ErrorUtils.getGlobalHandler()`), so importing anything from `expo` under the
|
|
157
|
+
native engine failed with "ErrorUtils is not defined". The engine now installs the
|
|
158
|
+
real `@react-native/js-polyfills` implementation, resolved through the installed
|
|
159
|
+
React Native and compiled by the same hooks as the rest of its sources, once per
|
|
160
|
+
realm; nothing is hand-mocked.
|
|
161
|
+
|
|
162
|
+
The packed Expo consumer fixture gains an expo-router leg: a real SDK 56 project
|
|
163
|
+
with file-based `app/` routes (a stack layout, a home screen, a dynamic
|
|
164
|
+
`details/[id]` route), tested through expo-router's own `expo-router/testing-library`
|
|
165
|
+
— `renderRouter("./app")`, `testRouter.push`/`back`, `toHavePathname`,
|
|
166
|
+
`useLocalSearchParams` — exactly as its documentation shows and as a jest-expo
|
|
167
|
+
suite already contains. It runs against the real `@react-navigation/*` stack with
|
|
168
|
+
`presets: { navigation: false }` and the jest-compat layer, from a packed install
|
|
169
|
+
in the consumer gate.
|
|
170
|
+
|
|
171
|
+
- 9ab8270: Preserve CommonJS re-exports across hot worker file boundaries
|
|
172
|
+
|
|
173
|
+
Hot cleanup now invalidates stale Node relative-resolution lookups after deleting
|
|
174
|
+
per-file CommonJS cache entries. This prevents later ESM imports of direct CJS
|
|
175
|
+
re-exports from silently receiving empty exports on affected Node versions.
|
|
176
|
+
|
|
177
|
+
The compatibility layer preserves named exports, cycles, retry behavior and fresh
|
|
178
|
+
module identities. It does not evaluate user modules during cleanup; incompatible
|
|
179
|
+
loader behavior fails with an actionable worker-isolation fallback. Runtime
|
|
180
|
+
defaults are unchanged. The Node upstream fix remains the long-term replacement
|
|
181
|
+
for this internal-loader compatibility layer.
|
|
182
|
+
|
|
183
|
+
- e3faa95: Fix three cross-file leaks under the hot runtime and relative paths in `jest.setMock`
|
|
184
|
+
|
|
185
|
+
- A `jest.doMock`/`vi.doMock` issued after a file's last import was applied to the next
|
|
186
|
+
file's imports. Vitest queues such mocks until the next import, and the per-file reset
|
|
187
|
+
cleared the mock registries but not that queue; it now clears it too.
|
|
188
|
+
- React Native Testing Library, which the hot runtime keeps loaded once per worker,
|
|
189
|
+
registered its automatic cleanup and act-environment hooks only in the first file that
|
|
190
|
+
imported it. Later files left their trees mounted, and `screen` could return the previous
|
|
191
|
+
file's tree. When a file imports a resident RNTL, its entry module now re-runs against the
|
|
192
|
+
resident instances, so each file that imports RNTL gets RNTL's own hooks and a file that
|
|
193
|
+
does not import it gets none, as under per-file isolation.
|
|
194
|
+
- `jest.setMock` and `jest.dontMock` resolved a relative path against the jest-compat shim
|
|
195
|
+
instead of the calling test file, so the mock (or unmock) applied to the wrong module.
|
|
196
|
+
Relative paths are now anchored at the caller, as Jest resolves them. Finding the caller
|
|
197
|
+
also no longer skips a test file that lives in a directory named `jest-compat`.
|
|
198
|
+
|
|
199
|
+
- 9ab8270: Reset hot-runtime state before a test file's own setup files run
|
|
200
|
+
|
|
201
|
+
The hot runtime restored the previous file's realm state (fake timers, stubbed
|
|
202
|
+
globals and environment, listeners) from this package's setup file, which Vitest
|
|
203
|
+
runs after the project's own setup files. A project setup file that installs fake
|
|
204
|
+
timers therefore found the previous file's timers still installed and failed with
|
|
205
|
+
"Can't install fake timers twice", failing every file after the first. The reset
|
|
206
|
+
now runs at the file boundary, before any setup file.
|
|
207
|
+
|
|
208
|
+
- 01a9afc: Stop printing React Native's deprecation notices on every import under the native engine. The `react-native` facade read every export while it initialised, and React Native prints the notice for a deprecated or extracted member (`SafeAreaView`, `Clipboard`, `PushNotificationIOS`, …) from that member's getter, so importing only `Pressable` printed all of them. Deprecated members are now exposed as getters and read only when used, so a notice appears only in tests that use the member. The export-name parser also no longer picks up keys from code after the exports object.
|
|
209
|
+
- 8300ec6: Build native-engine preset mocks on first use in each test file
|
|
210
|
+
|
|
211
|
+
The native setup rebuilt every auto-detected preset mock for every test file — in
|
|
212
|
+
a project with twenty presets, about 900 `vi.fn()` mocks per file, most for
|
|
213
|
+
packages the file never imports. Vitest keeps every mock it has created (for
|
|
214
|
+
`vi.clearAllMocks()`), so under the hot runtime each file's unused mocks stayed
|
|
215
|
+
reachable for the rest of the run: worker heap grew about 4 MB per file and a
|
|
216
|
+
1,000-file single-worker run ran out of memory. Each preset mock is now built
|
|
217
|
+
the first time a file uses it, and still fresh for every file. On the same run,
|
|
218
|
+
worker heap after 562 tests fell from about 2.4 GB to about 0.45 GB and 1,000
|
|
219
|
+
files complete in about 1.5 GB.
|
|
220
|
+
|
|
221
|
+
- 99f3013: Fix the matcher type augmentations for Vitest 4 and Vitest 5. Under Vitest 4, `expect(x).toHaveAnimatedStyle(...)` and `toHaveAnimatedProps(...)` from `vitest-native/matchers` were untyped: the published declaration file augmented the `vitest` module without referencing it, which Vitest 4's type layout needs for the augmentation to merge. The declarations now reference `vitest`, and both `vitest-native/matchers` and `vitest-native/rntl-matchers` use Vitest 5's `Assertion<R, T>` type parameters. The matchers are typed on both majors; a Vitest 4 project that checks declaration files (`skipLibCheck: false`) reports TS2428 for the differing type parameters.
|
|
222
|
+
- 525eb42: Translate jest-expo presets in `vitest-native migrate`
|
|
223
|
+
|
|
224
|
+
`migrate` reported `preset: 'jest-expo'` as needing attention and pointed at known limits
|
|
225
|
+
that no longer apply. It now translates the preset: `jest-expo` and `jest-expo/ios` become
|
|
226
|
+
`reactNative()`, `jest-expo/android` becomes `reactNative({ platform: 'android' })`, and
|
|
227
|
+
`jest-expo/universal`, `jest-expo/web` and `jest-expo/node` are reported with what to do
|
|
228
|
+
instead. jest-expo does not mock React Navigation, so when a `@react-navigation/*` package is
|
|
229
|
+
installed (which activates the navigation preset) the suggested config sets
|
|
230
|
+
`presets: { navigation: false }`, keeping screens in real navigators as under Jest; a
|
|
231
|
+
project with its own root `__mocks__/@react-navigation` keeps the preset. The packed Expo
|
|
232
|
+
SDK 57 consumer gate now also runs expo-router's testing library under the configuration
|
|
233
|
+
`migrate --write` generates from a jest-expo setup.
|
|
234
|
+
|
|
235
|
+
- 4e5130f: Navigation preset matches @react-navigation/native's shape; a disabled preset's package detects like any other
|
|
236
|
+
|
|
237
|
+
Two gaps that both surfaced by rendering router-driven screens under the native
|
|
238
|
+
engine — the shape most Expo apps have.
|
|
239
|
+
|
|
240
|
+
`createNavigatorFactory(Navigator)` now returns the real factory shape, yielding
|
|
241
|
+
`{ Navigator, Screen, Group }`. It returned a bare mock function whose result was
|
|
242
|
+
undefined, so any library building on the public factory API — expo-router extracts
|
|
243
|
+
its `Screen`/`Group` primitives through `createNavigatorFactory({})()` — failed at
|
|
244
|
+
import with "Cannot read properties of undefined (reading 'Screen')". The preset
|
|
245
|
+
also gains the exports `@react-navigation/native` adds on top of core:
|
|
246
|
+
`LinkingContext`, `LocaleDirContext`, `UNSTABLE_UnhandledLinkingContext`,
|
|
247
|
+
`DefaultTheme`, `DarkTheme` (real colors and platform font stacks), `createStaticNavigation`,
|
|
248
|
+
`ServerContainer`, `useLinkBuilder`, `useLinkProps`, `useLocale`, `useRoutePath`.
|
|
249
|
+
`ThemeContext` is seeded with `DefaultTheme`, as in the real package.
|
|
250
|
+
|
|
251
|
+
Disabling a preset — `presets: { navigation: false }` — now returns its packages to
|
|
252
|
+
ordinary ecosystem detection. Detection used to skip every preset package
|
|
253
|
+
unconditionally, so turning the preset off un-shadowed `@react-navigation/*` but
|
|
254
|
+
left it undetected: nothing compiled its untranspiled `lib/module` source and it
|
|
255
|
+
failed at load. That is the configuration under which the real React Navigation
|
|
256
|
+
stack, and expo-router's own `expo-router/testing-library` on top of it, run under
|
|
257
|
+
the native engine — `renderRouter` renders and `router.push` navigates.
|
|
258
|
+
|
|
259
|
+
- 3f62964: `jest.requireActual` and `jest.requireMock` now apply the project's `resolve.alias` string entries. A partial mock such as `jest.mock('@/services/api', () => ({ ...jest.requireActual('@/services/api'), fn: jest.fn() }))` threw "Cannot find module" because `requireActual` resolves through Node, which does not apply Vite's aliases. Aliases match on the whole specifier or a `/` boundary (an `@` alias does not capture `@scope/pkg`), the longest match wins, and an extensionless result is resolved with the platform's extension order (`@/Button` → `Button.ios.tsx`). Regex aliases and custom resolvers cannot reach the test worker; when one is configured, an unresolved specifier reports that instead of a bare "Cannot find module".
|
|
260
|
+
- d4ae5bf: Report the resolver-agreement warning (`'x' resolves to two different files`) only under `diagnostics`. The check compares Node's resolution against the package manifest and cannot see Vite's module graph, so it fired for packages that only Node ever requires — `test-renderer` (required by React Native Testing Library), `nanoid` (required by postcss) and Babel's source-map packages — printing on every test file. The warning now also states that it is a risk rather than a proven duplicate, and that its comparison uses Vite's default main fields.
|
|
261
|
+
- 963b35e: Type React Native Testing Library's matchers on RNTL 12 and 13
|
|
262
|
+
|
|
263
|
+
`vitest-native/rntl-matchers` imported RNTL's matcher interface from
|
|
264
|
+
`dist/matchers/types`, a path that exists only from RNTL 14; RNTL 12 and 13 keep it
|
|
265
|
+
under `build/`. On those versions the import resolved to nothing, and under
|
|
266
|
+
`skipLibCheck: true` the failure was silent: `toHaveTextContent`, `toBeVisible`,
|
|
267
|
+
`toBeDisabled` and the other matchers stayed untyped although the peer range is
|
|
268
|
+
`>=12 <15`. The entry now declares the interface itself, taking the element type from
|
|
269
|
+
RNTL's public `screen` API, and a test compares its members with the installed RNTL's
|
|
270
|
+
on each supported major. Typechecked against RNTL 12.9, 13.3 and 14.0 with Vitest 4
|
|
271
|
+
and 5 and TypeScript 6 and 7.
|
|
272
|
+
|
|
273
|
+
- 8893464: Fix `vitest-native/rntl-matchers` under TypeScript 7 with RNTL 14. RNTL 14 adds its matchers to the global `jest.Matchers<R>`, which Vitest's `JestAssertion` extends with `R = void`; the entry added them again with Vitest's assertion type, and TypeScript 7 rejects the two differing declarations (TS2320) for projects that typecheck declaration files (`skipLibCheck: false`). The entry now uses the same instantiation, so the declarations agree and the matchers stay typed.
|
|
274
|
+
- 9ab8270: Add conservative automatic selection for the bounded native hot runtime
|
|
275
|
+
|
|
276
|
+
`hotRuntime: "auto"` enables persistent native workers only when the current
|
|
277
|
+
configuration has recyclable task boundaries, enough host/container memory for at
|
|
278
|
+
least two workers, and no explicitly selected pool; otherwise it preserves stock
|
|
279
|
+
per-file isolation. Selection runs after other Vite config hooks, so
|
|
280
|
+
later-contributed pools and setup files cannot create a mixed runtime. (In this
|
|
281
|
+
release `'auto'` also becomes the default, falls back quietly unless set explicitly
|
|
282
|
+
or `diagnostics` is on, and includes suites migrated from Jest — see the minor
|
|
283
|
+
changes above.)
|
|
284
|
+
|
|
285
|
+
A packed consumer gate proves safe enablement and the one-worker and explicit-pool
|
|
286
|
+
fallbacks. Explicit `hotRuntime: true` keeps its existing fail-closed semantics.
|
|
287
|
+
|
|
288
|
+
- 9ab8270: Verify and restore hot-runtime shared-realm state between test files
|
|
289
|
+
|
|
290
|
+
Hot mode now uses an ordered state manifest for Vitest timers and stubs, native
|
|
291
|
+
boundary overrides, known React Native state, environment changes, process and RN
|
|
292
|
+
listeners, global and console property descriptors, ErrorUtils, and the Expo
|
|
293
|
+
compatibility runtime. Every restore is followed by final-realm verification, and a
|
|
294
|
+
failure names the responsible entry instead of surfacing later as an order-dependent
|
|
295
|
+
test failure.
|
|
296
|
+
|
|
297
|
+
An adversarial two-file suite contaminates every supported surface. A mutation gate
|
|
298
|
+
disables all eleven restore actions one at a time and requires each omission to fail,
|
|
299
|
+
covering both the normal precompiled registry and the resident-RN fallback path.
|
|
300
|
+
|
|
301
|
+
## 0.13.0
|
|
302
|
+
|
|
303
|
+
### Minor Changes
|
|
304
|
+
|
|
305
|
+
- 0c25e74: New helper `extendPresetMock(pkg, overrides)`: merge overrides into a preset's module mock (and its `default` export) — e.g. to give expo-constants a real `expoConfig` or add an export a library calls that the preset does not model. Undone by `resetAllMocks()`.
|
|
306
|
+
- 1283531: React Native 0.87 joins the supported matrix
|
|
307
|
+
|
|
308
|
+
The verified range is now 0.81–0.87: the CI matrix gains a 0.87 row (and the
|
|
309
|
+
Vitest 5 column moves its newest-RN cell up), the workspace pins 0.87, and the
|
|
310
|
+
published range statements follow. 0.87 removed InteractionManager, so its
|
|
311
|
+
cross-check probe is version-gated rather than deleted — the 0.81–0.86 legs
|
|
312
|
+
still compare it, and the published corpus count on the pinned version drops
|
|
313
|
+
from 85 to 84 with the retirement recorded deliberately via the report's
|
|
314
|
+
--allow-corpus-shrink flag.
|
|
315
|
+
|
|
316
|
+
### Patch Changes
|
|
317
|
+
|
|
318
|
+
- 9f4fd3c: Complete the expo-linking preset mock: add `addEventListener`, `resolveScheme` and `getInitialURL`, which expo-router's linking layer calls at render time.
|
|
319
|
+
- 4216b1f: Fabricated native-module stubs follow Expo method conventions: unknown `*Async` properties resolve a Promise (fixes expo-notifications crashing at import), and unknown PascalCase properties are memoized classes extending `SharedObject` (fixes expo-file-system's `class File extends ExpoFileSystem.FileSystemFile`).
|
|
320
|
+
- 36a1625: Mock registries are null-prototype objects, so a module or package name of `__proto__` becomes an ordinary entry instead of re-prototyping the registry. Hardens the published `mockNativeModule()` surface against prototype-polluting names — the same class CodeQL flagged on `extendPresetMock()`.
|
|
321
|
+
- b127e6d: Resolve React Native 0.87's gated deep imports, and mock its new AssetRegistry export
|
|
322
|
+
|
|
323
|
+
React Native 0.87 ships an `exports` map whose deep-import surface sits behind
|
|
324
|
+
Metro's `react-native-legacy-deep-imports` condition — and its Babel preset now
|
|
325
|
+
compiles RN's own relative imports into bare deep specifiers
|
|
326
|
+
(`react-native/src/private/…`), so RN's compiled graph self-references through
|
|
327
|
+
paths plain Node refuses with `ERR_PACKAGE_PATH_NOT_EXPORTED`. Under the native
|
|
328
|
+
engine that failed almost every suite at collection. The engine now mirrors
|
|
329
|
+
Metro: when Node's resolver rejects a `react-native/*` or `@react-native/*` deep
|
|
330
|
+
specifier, the file is located by path from the package's real directory,
|
|
331
|
+
platform extensions included, in the require hook, the ESM loader, and the
|
|
332
|
+
precompiled registry's fall-through — where resolving by path keeps deep files
|
|
333
|
+
on the registry's instances instead of loading twins. Inert on 0.86 and earlier,
|
|
334
|
+
which have no exports map to reject anything.
|
|
335
|
+
|
|
336
|
+
The mock engine gains `AssetRegistry` (a top-level export since 0.87),
|
|
337
|
+
mirroring `@react-native/assets-registry/registry` down to its 1-based truthy
|
|
338
|
+
ids. The compatibility checker no longer misreads the bare `get() {` inside
|
|
339
|
+
0.87's new `Object.defineProperty` export blocks as an export named `get`, and
|
|
340
|
+
the InteractionManager probe is version-gated: 0.87 removed the API outright,
|
|
341
|
+
so the matrix keeps running it on every version that ships it.
|
|
342
|
+
|
|
343
|
+
React Native 0.87 is not yet in the supported matrix — its release is inside
|
|
344
|
+
the dependency cooldown window; adoption follows separately.
|
|
345
|
+
|
|
3
346
|
## 0.12.0
|
|
4
347
|
|
|
5
348
|
### Minor Changes
|
package/README.md
CHANGED
|
@@ -4,9 +4,11 @@
|
|
|
4
4
|
|
|
5
5
|
Run your React Native tests under Vitest, against **real React Native** — the same JavaScript that ships in your app, with only the native-module boundary mocked. That is the default and the point of the project. A lightweight pure-JS mock engine is available as an opt-in for fast, RN-free unit tests.
|
|
6
6
|
|
|
7
|
-
> **Beta.** The release-supported native engine is validated across React Native 0.81–0.
|
|
8
|
-
> Vite 6–8, Vitest 4, RNTL 12–14, bare apps, Expo
|
|
9
|
-
>
|
|
7
|
+
> **Beta.** The release-supported native engine is validated across React Native 0.81–0.87,
|
|
8
|
+
> Vite 6–8, Vitest 4–5, RNTL 12–14, bare apps, Expo SDK 57 (including expo-router's own testing
|
|
9
|
+
> library), and hoisted monorepos. The hot
|
|
10
|
+
> runtime (on by default where it can be bounded) is marked experimental because it uses Vitest's
|
|
11
|
+
> experimental custom-pool APIs.
|
|
10
12
|
>
|
|
11
13
|
> Maintained successor to [`vitest-community/vitest-react-native`](https://github.com/vitest-community/vitest-react-native) — same core idea (externalize RN, run its real JS under Node), rebuilt for modern Vitest (4+). Coming from it? See [Migrating from `vitest-react-native`](#migrating-from-vitest-react-native).
|
|
12
14
|
|
|
@@ -146,7 +148,7 @@ export default defineConfig({
|
|
|
146
148
|
diagnostics: false, // Enable verbose logging
|
|
147
149
|
assetExts: [".lottie"], // Additional asset extensions to stub
|
|
148
150
|
transform: [], // Extra native-engine packages to Flow/TS transform
|
|
149
|
-
hotRuntime:
|
|
151
|
+
hotRuntime: "auto", // 'auto' (default) | true | false | HotRuntimeOptions
|
|
150
152
|
}),
|
|
151
153
|
],
|
|
152
154
|
});
|
|
@@ -161,7 +163,35 @@ export default defineConfig({
|
|
|
161
163
|
| `diagnostics` | `boolean` | `false` | Log plugin activity to the console for debugging. |
|
|
162
164
|
| `assetExts` | `string[]` | `[]` | Additional file extensions to stub as asset imports (beyond the built-in set). |
|
|
163
165
|
| `transform` | `string[]` | `[]` | **`engine: 'native'` only.** Extra `node_modules` packages whose source the native engine should transform (Flow/TS/JSX stripped) as it loads them — for third-party RN libraries that ship untranspiled source (e.g. `react-native-reanimated`). Analogous to Jest's `transformIgnorePatterns` allowlist. |
|
|
164
|
-
| `hotRuntime` | `boolean \| HotRuntimeOptions` | `
|
|
166
|
+
| `hotRuntime` | `boolean \| 'auto' \| HotRuntimeOptions` | `'auto'` | `engine: 'native'` only. Reuse workers while keeping app/test modules isolated per file. `'auto'` (the default) uses it when the run can be bounded and recycled, and per-file isolation otherwise; `false` always isolates per worker. See [Hot runtime](#hot-runtime). |
|
|
167
|
+
|
|
168
|
+
### Experimental Metro configuration
|
|
169
|
+
|
|
170
|
+
Pass `metroConfig: true` to use your project's Metro source-extension order and
|
|
171
|
+
asset list in both Vite and Node resolution. This is opt-in while the framework
|
|
172
|
+
and package-manager compatibility matrix is being validated:
|
|
173
|
+
|
|
174
|
+
```ts
|
|
175
|
+
reactNative({ metroConfig: true });
|
|
176
|
+
// Config outside the project root:
|
|
177
|
+
reactNative({ metroConfig: { configFile: "../../metro.config.cjs" } });
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
Expo's defaults prefer TypeScript over JavaScript when both variants exist;
|
|
181
|
+
bare React Native's defaults prefer JavaScript. The profile is evaluated in a
|
|
182
|
+
short-lived child using the project's own Metro tooling. Explicit `assetExts`
|
|
183
|
+
additions still apply. Metro transforms are not installed: source formats such as
|
|
184
|
+
SVG need a corresponding Vitest/Vite transform.
|
|
185
|
+
|
|
186
|
+
A custom `resolver.resolveRequest` is code and does not run under Vitest: the
|
|
187
|
+
source and asset extensions still apply, and a warning names the gap. Where one of
|
|
188
|
+
its redirects matters to tests, reproduce it with `resolve.alias`. Package
|
|
189
|
+
main fields and conditions remain governed by the engine's ownership policy;
|
|
190
|
+
`diagnostics: true` reports the observed Metro values. Config is evaluated on
|
|
191
|
+
startup; changing it requires restarting the run.
|
|
192
|
+
|
|
193
|
+
Default: `false`. Findings and remaining gates are recorded in
|
|
194
|
+
[the investigation log](docs/metro-profile-investigation.md).
|
|
165
195
|
|
|
166
196
|
### `engine`
|
|
167
197
|
|
|
@@ -186,6 +216,12 @@ Choose how React Native is provided to your tests:
|
|
|
186
216
|
reactNative({ engine: "native" });
|
|
187
217
|
```
|
|
188
218
|
|
|
219
|
+
On the first cold run, the native engine compiles React Native's synchronous module graph into a
|
|
220
|
+
factory registry in a short-lived, heap-bounded child process. The child exits before test workers
|
|
221
|
+
start, so Babel's compilation heap does not become a permanent Vite-process RSS watermark. Later
|
|
222
|
+
runs validate and reuse the cache in-process without launching the compiler. A failed optimization
|
|
223
|
+
remains visible and falls back to the slower per-file loader without changing test results.
|
|
224
|
+
|
|
189
225
|
#### Fidelity
|
|
190
226
|
|
|
191
227
|
Jest's `react-native` preset replaces many real modules with stubs, so behavior they
|
|
@@ -204,8 +240,34 @@ the cross-check/fidelity harnesses in the repository's `bench/` directory.
|
|
|
204
240
|
|
|
205
241
|
#### Hot runtime
|
|
206
242
|
|
|
207
|
-
|
|
208
|
-
|
|
243
|
+
Vitest's default isolation gives each test file a fresh worker, so React Native would reload for
|
|
244
|
+
every file. By default (`hotRuntime: 'auto'`) the native engine instead reuses workers and resets
|
|
245
|
+
modules per file whenever that can be done safely:
|
|
246
|
+
|
|
247
|
+
`'auto'` selects persistent workers when the current scheduler provides recyclable task boundaries,
|
|
248
|
+
the host/container memory plan admits at least two workers, no other pool was explicitly
|
|
249
|
+
selected, and `test.isolate` is not set explicitly — an explicit Vitest isolation choice, `true` or
|
|
250
|
+
`false`, is always kept. The same holds for CLI flags (`--pool`, `--isolate`, `--no-isolate`,
|
|
251
|
+
`--maxWorkers=1`, `--no-file-parallelism`). With `hotRuntime: true` instead, any of these fails at
|
|
252
|
+
startup with `HOT_RUNTIME_OVERRIDDEN` rather than being overridden. `'auto'` also keeps Vitest's
|
|
253
|
+
isolation when another project in the same `sequence.groupOrder` runs a different worker count,
|
|
254
|
+
which Vitest does not allow; give the native project its own `test.sequence.groupOrder` to keep hot.
|
|
255
|
+
Suites migrated from Jest (`jestMockTransform()`, the jest-compat setup) are included: the
|
|
256
|
+
jest-compat surface — `jest.mock` in its forms, runtime mocks, spies, timers, React Native Testing
|
|
257
|
+
Library cleanup — has its own cross-file isolation gate under the hot runtime. The decision runs
|
|
258
|
+
after other Vite config hooks, so a pool contributed by a later plugin is included rather than
|
|
259
|
+
producing a mixed runtime. When it falls
|
|
260
|
+
back to per-file isolation it does so quietly; `diagnostics: true`, or setting `hotRuntime: 'auto'`
|
|
261
|
+
explicitly, prints the reason. To always isolate per worker:
|
|
262
|
+
|
|
263
|
+
```ts
|
|
264
|
+
reactNative({
|
|
265
|
+
engine: "native",
|
|
266
|
+
hotRuntime: false,
|
|
267
|
+
});
|
|
268
|
+
```
|
|
269
|
+
|
|
270
|
+
To require hot mode and fail closed when it cannot be bounded, use the explicit form:
|
|
209
271
|
|
|
210
272
|
```ts
|
|
211
273
|
reactNative({
|
|
@@ -214,22 +276,26 @@ reactNative({
|
|
|
214
276
|
});
|
|
215
277
|
```
|
|
216
278
|
|
|
217
|
-
The hot runtime keeps React Native's
|
|
218
|
-
the app/test module graph for every file.
|
|
219
|
-
|
|
220
|
-
|
|
279
|
+
The hot runtime keeps React Native's precompiled factory registry and worker realm warm while
|
|
280
|
+
resetting the registry's module instances and the app/test module graph for every file. An ordered
|
|
281
|
+
state manifest also restores and verifies timers/Vitest stubs, direct `process.env` changes,
|
|
282
|
+
process and RN listeners, complete global and console property descriptors, known RN state,
|
|
283
|
+
ErrorUtils, Expo runtime state, and plugin boundary mocks. A mutation gate removes each of its
|
|
284
|
+
eleven restore actions in turn and requires the cross-file isolation suite to fail by name.
|
|
285
|
+
|
|
286
|
+
When hot is enabled, the plugin derives a worker-total memory plan from the lower of host and
|
|
287
|
+
container/cgroup memory. It reserves main-process and replacement headroom, caps automatic
|
|
288
|
+
concurrency at four, recycles workers on local heap or process RSS, and stops before starting more
|
|
289
|
+
work at the hard RSS boundary. Run with `diagnostics: true` or `vitest-native doctor` to see the
|
|
290
|
+
chosen envelope.
|
|
221
291
|
|
|
222
|
-
**Known limitation.**
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
see that, move the affected suite (or the project) back to the default per-file isolation. This is
|
|
230
|
-
why the hot runtime is opt-in and experimental rather than the default; closing the gap for all
|
|
231
|
-
suites depends on a per-file module reset inside a persistent worker that Vitest does not yet
|
|
232
|
-
provide.
|
|
292
|
+
**Known limitation.** No shared-realm sanitizer can generically discover arbitrary mutable state in
|
|
293
|
+
every resident third-party singleton. The registry resets React Native's own in-memory module
|
|
294
|
+
instances, and the manifest handles the supported runtime surfaces above; unknown process-wide
|
|
295
|
+
state is still the library's or test fixture's responsibility. A test that passes alone but fails
|
|
296
|
+
after another file is a correctness signal: set `hotRuntime: false` for that suite and report the
|
|
297
|
+
small reproduction. The hot runtime depends on Vitest's custom worker APIs, which Vitest labels
|
|
298
|
+
experimental.
|
|
233
299
|
|
|
234
300
|
For additional leak containment:
|
|
235
301
|
|
|
@@ -244,15 +310,20 @@ reactNative({
|
|
|
244
310
|
});
|
|
245
311
|
```
|
|
246
312
|
|
|
247
|
-
Recycling is applied between Vitest scheduler tasks. Vitest
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
313
|
+
Recycling is applied between Vitest scheduler tasks. Current Vitest batches every file into one
|
|
314
|
+
uninterruptible task at `maxWorkers: 1`, so the default `'auto'` keeps per-file isolation there and
|
|
315
|
+
`hotRuntime: true` fails that configuration rather than claim an inert memory bound. Use at least
|
|
316
|
+
two workers for hot mode. If an external scheduler
|
|
317
|
+
already provides a hard boundary, you can deliberately accept the risk with
|
|
318
|
+
`hotRuntime: { allowUnboundedMemory: true }`; this disables the automatic worker cap and
|
|
319
|
+
process-RSS enforcement and prints a warning when the batch is observed. `preserveGlobals` is an
|
|
320
|
+
exact allowlist for registries created by resident external dependencies; Storybook's preview
|
|
321
|
+
registry is preserved automatically.
|
|
252
322
|
|
|
253
323
|
This mode uses Vitest's custom pool and worker APIs, so it remains experimental. CI runs the
|
|
254
|
-
complete native suite under both the lockfile Vitest and the newest supported Vitest
|
|
255
|
-
plus a generated 100-file isolation soak
|
|
324
|
+
complete native suite under both the lockfile Vitest and the newest supported Vitest release,
|
|
325
|
+
plus a generated 100-file isolation soak, an end-to-end memory-triggered recycling test, and a
|
|
326
|
+
packed auto-selection matrix covering enablement and every guarded fallback class.
|
|
256
327
|
|
|
257
328
|
---
|
|
258
329
|
|
|
@@ -490,20 +561,26 @@ renders through real React Native).
|
|
|
490
561
|
|
|
491
562
|
### Expo
|
|
492
563
|
|
|
493
|
-
The `expo` preset shadows the common Expo modules
|
|
494
|
-
`expo-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
564
|
+
Expo apps need no Expo-specific package. The `expo` preset shadows the common Expo modules
|
|
565
|
+
(`expo-constants`, `expo-status-bar`, `expo-font`, `expo-asset`, `expo-splash-screen`,
|
|
566
|
+
`expo-linking`) the way `jest-expo` mocks them, and Expo's own JavaScript — `expo` itself,
|
|
567
|
+
expo-router and React Navigation — runs for real under the native engine.
|
|
568
|
+
|
|
569
|
+
- **Coming from jest-expo:** `npx vitest-native migrate --write` translates the `jest-expo`
|
|
570
|
+
presets (`jest-expo/android` → `platform: 'android'`) and, because jest-expo does not mock React
|
|
571
|
+
Navigation, turns the navigation preset off when a `@react-navigation/*` package is installed.
|
|
572
|
+
- **expo-router screens:** `expo-router/testing-library` (`renderRouter`, `testRouter`,
|
|
573
|
+
`toHavePathname`) runs as written with the jest-compat layer. From SDK 57 expo-router bundles its
|
|
574
|
+
own React Navigation; before SDK 57, also set `presets: { navigation: false }`.
|
|
498
575
|
- **Expo modules without a built-in preset** (e.g. `expo-image`, `expo-haptics`) still need a
|
|
499
|
-
setup-file `vi.mock
|
|
500
|
-
libraries to Node, so imports made entirely inside that externalized graph cannot be intercepted
|
|
501
|
-
by Vitest's mocker.
|
|
576
|
+
setup-file `vi.mock`.
|
|
502
577
|
- **Expo SDK trails React Native.** Pin your `react-native` to the version your Expo SDK supports
|
|
503
|
-
(
|
|
578
|
+
(SDK 54 and later are within this plugin's validated range), not the newest RN release.
|
|
504
579
|
|
|
505
|
-
A packed Expo
|
|
506
|
-
|
|
580
|
+
A packed Expo SDK 57 app is installed from the release tarball and tested in CI: Expo module
|
|
581
|
+
auto-detection and rendering, expo-router's testing library against file-based `app/` routes, and
|
|
582
|
+
the same routes under the configuration `migrate` generates from a jest-expo setup. See the
|
|
583
|
+
[Expo guide](https://danfry1.github.io/vitest-native/guide/expo).
|
|
507
584
|
|
|
508
585
|
---
|
|
509
586
|
|
|
@@ -557,6 +634,12 @@ with a worked real-app example, is in **[docs/migrating-from-jest.md](docs/migra
|
|
|
557
634
|
|
|
558
635
|
## Troubleshooting
|
|
559
636
|
|
|
637
|
+
**`npm error Cannot read properties of null (reading 'edgesOut')` during install**
|
|
638
|
+
npm 10 (the version bundled with Node 22) crashes while resolving Vite 8.2+'s optional peer
|
|
639
|
+
chain when the project pins Vitest 4, because that chain resolves to the latest Vitest (5.x).
|
|
640
|
+
This is an npm bug, fixed in npm 11 ([vitest#11245](https://github.com/vitest-dev/vitest/issues/11245)).
|
|
641
|
+
Upgrade npm (`npm install --global npm@11`), or use pnpm, Yarn or Bun.
|
|
642
|
+
|
|
560
643
|
**`@react-native/babel-preset not found — using the mock engine`**
|
|
561
644
|
You asked for the default (`auto`) engine but the native babel deps aren't installed, so it
|
|
562
645
|
fell back to the mock engine. To run real React Native, install them:
|
|
@@ -604,9 +687,9 @@ export default defineConfig({
|
|
|
604
687
|
});
|
|
605
688
|
```
|
|
606
689
|
|
|
607
|
-
The
|
|
608
|
-
|
|
609
|
-
budget.
|
|
690
|
+
The hot runtime (the default where it can be bounded) also helps: it keeps React Native's precompiled
|
|
691
|
+
factory registry warm, resets its module instances from memory per file, and recycles workers on a
|
|
692
|
+
memory/file budget.
|
|
610
693
|
|
|
611
694
|
**`Vitest caught N unhandled errors` in error-boundary tests**
|
|
612
695
|
A test that intentionally throws inside a component (to exercise an error boundary) makes React log
|
|
@@ -873,10 +956,17 @@ that API.
|
|
|
873
956
|
|
|
874
957
|
Every release must pass:
|
|
875
958
|
|
|
876
|
-
- Linux on Node 20.19
|
|
959
|
+
- Linux on Node 20.19, 22.13, and 24, plus macOS and Windows on Node 22.13.
|
|
877
960
|
- The mock, native iOS, native Android, hot-runtime, isolation, and 100-file soak suites.
|
|
878
|
-
- React Native 0.81–0.
|
|
879
|
-
|
|
961
|
+
- React Native 0.81–0.87 against both locked and newest-supported Vitest, plus the Vitest 4 floor
|
|
962
|
+
on 0.81 and 0.87.
|
|
963
|
+
- Vitest's own behaviour under the defaults, on Vitest 5 and the Vitest 4 floor: config and CLI
|
|
964
|
+
flags, projects, watch mode, the jsdom and happy-dom environments, `--typecheck`, `vitest bench`,
|
|
965
|
+
and the HTML reporter.
|
|
966
|
+
- Packed consumers: bare RN 0.83/RNTL 12, a Jest-migration project, Expo SDK 57/RNTL 13 (with
|
|
967
|
+
expo-router and a `migrate`-generated jest-expo config), a mock-engine RNTL 14 project, npm- and
|
|
968
|
+
pnpm-workspace monorepos on Vite 8, and an RN 0.86 Android project.
|
|
969
|
+
- Packed V8 and Istanbul coverage maps/counts matching default isolation exactly under hot workers.
|
|
880
970
|
- Mock-versus-real-RN behavioral cross-checks, example-app tests, typecheck, lint, formatting, and
|
|
881
971
|
package export analysis.
|
|
882
972
|
|
|
@@ -895,9 +985,9 @@ see [versioning and stability](docs/versioning.md).
|
|
|
895
985
|
| -------------------------------------------- | ----------------------------------------- |
|
|
896
986
|
| `react` | >= 18; use RN's matching React version |
|
|
897
987
|
| `vite` | ^6.4.2, ^7.3.2, or ^8.0.5 |
|
|
898
|
-
| `vitest` | 4.x
|
|
988
|
+
| `vitest` | 4.x or 5.x |
|
|
899
989
|
| `node` | >= 20.19; RN/RNTL may impose a higher floor |
|
|
900
|
-
| `react-native` (native engine) | 0.81–0.
|
|
990
|
+
| `react-native` (native engine) | 0.81–0.87 validated |
|
|
901
991
|
| `@react-native/babel-preset` (native engine) | Match the installed React Native minor |
|
|
902
992
|
| `@testing-library/react-native` (optional) | 12.x, 13.x, or 14.x |
|
|
903
993
|
|