vitest-native 0.9.0 → 0.10.0

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.
Files changed (53) hide show
  1. package/CHANGELOG.md +731 -0
  2. package/README.md +32 -1
  3. package/dist/cli.cjs +163 -27
  4. package/dist/cli.mjs +162 -26
  5. package/dist/{ecosystem-EFtHnKS9.mjs → ecosystem-CO5vqExO.mjs} +77 -15
  6. package/dist/{ecosystem-BIWaVwYL.cjs → ecosystem-IuZ-Gv0R.cjs} +78 -16
  7. package/dist/errors-Dm5yLNTF.mjs +64 -0
  8. package/dist/errors-flXDIeWk.cjs +75 -0
  9. package/dist/errors.d.mts +46 -0
  10. package/dist/errors.mjs +78 -0
  11. package/dist/helpers.cjs +6 -23
  12. package/dist/helpers.d.cts +0 -6
  13. package/dist/helpers.d.mts +0 -6
  14. package/dist/helpers.mjs +6 -23
  15. package/dist/{index-CEgRDdhd.d.cts → index-BJL4cQ-l.d.cts} +9 -4
  16. package/dist/{index-j-0tueBr.d.mts → index-CvCU0cLl.d.mts} +9 -4
  17. package/dist/index.d.mts +8 -6
  18. package/dist/index.mjs +245 -59
  19. package/dist/jest-compat/interop.mjs +15 -0
  20. package/dist/jest-compat/setup.mjs +102 -7
  21. package/dist/matchers.cjs +16 -7
  22. package/dist/matchers.mjs +16 -7
  23. package/dist/native/hooks.mjs +75 -1
  24. package/dist/native/loader.mjs +26 -6
  25. package/dist/native/module-reset.mjs +63 -0
  26. package/dist/native/registry.mjs +80 -11
  27. package/dist/native/resolve.d.mts +22 -0
  28. package/dist/native/resolve.mjs +21 -13
  29. package/dist/native/runner.mjs +21 -0
  30. package/dist/native/setup.mjs +4 -2
  31. package/dist/native/transform.mjs +108 -3
  32. package/dist/native/worker.mjs +59 -16
  33. package/dist/{pool-CJmjRgsB.mjs → pool-Bcxp4Qrg.mjs} +2 -1
  34. package/dist/{pool-DzsEo9vv.cjs → pool-CFND7plG.cjs} +2 -1
  35. package/dist/{preset-map-CNsZKfvu.mjs → preset-map-BpDG_D5m.mjs} +0 -1
  36. package/dist/{preset-map-CG4FMtsl.cjs → preset-map-DxilQ4pI.cjs} +0 -1
  37. package/dist/{presets-C4faM3ds.cjs → presets-BGTqVH6C.cjs} +94 -50
  38. package/dist/{presets-CuDrNA_W.mjs → presets-CK85x8ey.mjs} +94 -50
  39. package/dist/presets.d.mts +1 -1
  40. package/dist/presets.mjs +1 -1
  41. package/dist/rntl-matchers.d.ts +35 -0
  42. package/dist/serializer.cjs +33 -3
  43. package/dist/serializer.mjs +33 -3
  44. package/dist/setup.mjs +234 -71
  45. package/docs/release-readiness.md +22 -5
  46. package/docs/versioning.md +133 -0
  47. package/package.json +25 -35
  48. package/dist/index.cjs +0 -788
  49. package/dist/index.d.cts +0 -14
  50. package/dist/presets.cjs +0 -18
  51. package/dist/presets.d.cts +0 -2
  52. package/dist/setup.cjs +0 -2702
  53. package/dist/setup.d.cts +0 -1
package/CHANGELOG.md CHANGED
@@ -1,5 +1,736 @@
1
1
  # vitest-native
2
2
 
3
+ ## 0.10.0
4
+
5
+ ### Minor Changes
6
+
7
+ - f21986f: The mock engine's Animated surface now matches React Native's
8
+
9
+ Nine members React Native has were missing from the mock, so valid React Native code
10
+ calling any of them threw under `engine: 'mock'` while working under `engine: 'native'`:
11
+ `Animated.Node`, `Animated.Event`, `Animated.Interpolation`, `attachNativeEvent`,
12
+ `Value.track`, `Value.stopTracking`, `Value.animate`, `hasListeners` and `toJSON`. All
13
+ are implemented, following React Native's own semantics — `track()` kicks the tracking
14
+ node immediately and replaces any previous one, `animate()` stops a running animation
15
+ before starting the next and reports completion, `toJSON()` returns the current value.
16
+
17
+ `stopAnimation` and `resetAnimation` moved off the shared base class onto `Value` and
18
+ `Color`, which is where React Native puts them. They were reaching interpolations,
19
+ which are derived and cannot be animated.
20
+
21
+ `getValue()` remains — it is not a React Native API, and real React Native exposes only
22
+ `__getValue()` — but now warns once per process, because the same call throws under the
23
+ native engine. Use `__getValue()` for code that must run on both. It is the only
24
+ remaining difference in this surface, and is recorded on the published fidelity page.
25
+
26
+ - 261b9ef: Make every declared entry point loadable, and require Node >= 20.19
27
+
28
+ `require("vitest-native")` threw. The package's `main`, the `require` condition of the
29
+ root export, and the `require` conditions of `./setup` and `./presets` all pointed at
30
+ transpiled CommonJS bundles that could not be loaded at all: the root re-exports the
31
+ presets, every preset imports `vi` from vitest at module scope, and vitest throws when
32
+ it is reached through `require()`. A previous release gated this and recorded the three
33
+ entries as known-unloadable rather than fixing them.
34
+
35
+ The fix is not to change how the presets are written. Node has loaded ES modules from
36
+ `require()` since 20.19, and the ESM build was always fine — only the transpiled
37
+ CommonJS build tripped vitest's guard. Those three subpaths now declare a single ESM
38
+ target for both conditions, and the dead CommonJS bundles are no longer emitted.
39
+ `const { reactNative, presets } = require("vitest-native")` works, on both the oldest
40
+ and newest supported Node. No documented API changed.
41
+
42
+ `engines` now requires Node >= 20.19.0, the version that added `require(esm)` and the
43
+ oldest version the matrix has ever tested. The previous `>= 20` advertised support for
44
+ Node 20.0–20.18, which was never exercised and where the root entry cannot be required.
45
+
46
+ Two gates were extended to keep this fixed:
47
+
48
+ - `tests/package-exports.test.ts` resolves and loads every subpath by specifier under
49
+ both `require` and `import`, rather than only loading declared targets by path. The
50
+ original defect was invisible from the path side, since `dist/index.mjs` loaded fine
51
+ throughout.
52
+ - `scripts/check-exports.mjs` no longer ignores `cjs-resolves-to-esm` package-wide.
53
+ Subpaths that are ESM-only on purpose are declared explicitly and checked against the
54
+ manifest in both directions; every other subpath is checked with the rule enforced, so
55
+ a dual entry cannot quietly lose its CommonJS build. Deriving that split from the
56
+ manifest was tried and rejected: removing a `.cjs` moved the entry into the excused
57
+ bucket, and the gate stayed green on the defect it exists to catch.
58
+
59
+ - a70c9f2: `hotRuntime` now isolates modules per file instead of repairing them
60
+
61
+ A hot worker stays alive across test files, which is where its speed comes from —
62
+ a fresh worker costs roughly 200ms of boot, and that dominates a run at scale. What
63
+ it kept along with the worker was state: everything Vitest externalizes lives in
64
+ Node's require cache, outside the reach of Vitest's own per-file reset.
65
+
66
+ The previous model kept those modules resident and undid their damage afterwards,
67
+ from a boot snapshot plus a call-stack heuristic that attributed each listener to
68
+ import phase or test phase. That was approximate by construction, and wrong for a
69
+ whole class: a `node_modules` singleton mutated by one file stayed mutated for the
70
+ next, where stock isolation gives every file a fresh copy.
71
+
72
+ The engine now re-executes instead of repairing. Anything the worker loaded to
73
+ bootstrap itself stays; anything a test file caused to load is dropped and runs again
74
+ on the next file. That is affordable because of the precompiled registry —
75
+ re-instantiating React Native costs about 4ms in a warm worker.
76
+
77
+ Measured: the idiomatic parity suite runs 135/135 under both engines with zero
78
+ hot-specific failures, at 11.1× the default engine's speed; against Jest at 200 files,
79
+ 2.54× with 3.4× less peak memory.
80
+
81
+ React, the renderers and `@testing-library/react-native` stay resident deliberately.
82
+ Test files reach them through ESM `import`, which caches them in a registry Node
83
+ offers no way to invalidate, so dropping the CommonJS entry would not replace them —
84
+ it would add a second copy, and the two halves of the test stack would stop
85
+ recognising each other.
86
+
87
+ **Known limit.** A package a test file `import`s, rather than `require`s, cannot be
88
+ evicted; only the CommonJS cache can be reset. Packages the engine inlines are
89
+ unaffected, since those live in Vitest's own graph.
90
+
91
+ `hotRuntime` remains opt-in. Making it the default needs validation against real
92
+ applications, not only this repository's suites.
93
+
94
+ - 0bee726: Presets no longer declare named exports the real package does not have
95
+
96
+ A preset shadows a package: under the native engine the real source never loads, so
97
+ whatever the preset lists in `exports` becomes that module's named-export surface.
98
+ Four presets declared names the real package has never exported, which made the mock
99
+ more permissive than reality — code importing those names passed under vitest-native
100
+ and failed under Metro, the one divergence a green run cannot reveal.
101
+
102
+ - `expo-constants` declared twelve properties of the default `Constants` object
103
+ (`expoConfig`, `isDevice`, `manifest`, …) as named exports. They are now reachable
104
+ only on the default, as in the real package, and the three enums the package really
105
+ does export — `AppOwnership`, `ExecutionEnvironment`, `UserInterfaceIdiom` — are
106
+ provided instead.
107
+ - `react-native-reanimated` declared `View`, `Text`, `Image`, `ScrollView` and
108
+ `FlatList`. These are properties of the default export (`Animated.View`) and remain
109
+ available there.
110
+ - `react-native-safe-area-context` declared `EdgeInsets`, `Rect` and `Metrics`, which
111
+ are interfaces with no runtime binding.
112
+ - `@shopify/flash-list` declared `ViewToken`, also an interface.
113
+
114
+ A test now reads each preset package's real runtime surface with the TypeScript
115
+ checker and fails when a preset declares a name that surface lacks. Names removed by
116
+ a newer major of a package are kept deliberately, since presets are not pinned to one
117
+ major; each is listed with the version it belongs to, and a stale entry that the
118
+ package has regained is itself a failure.
119
+
120
+ Suites that imported the removed names will need to read them from the default export
121
+ or drop them — the same change their production code needs.
122
+
123
+ - a70c9f2: Add `vitest-native/rntl-matchers`: types for React Native Testing Library's matchers under Vitest
124
+
125
+ RNTL's matchers run correctly under this plugin but had no types for it. RNTL declares
126
+ them only for Jest — augmenting the global `jest` namespace and the `@jest/expect`
127
+ module — and neither reaches Vitest's `Assertion`. Every `expect(el).toHaveTextContent(...)`,
128
+ `toHaveStyle`, `toBeVisible`, `toBeOnTheScreen` and the rest was
129
+ `Property 'x' does not exist on type 'Assertion<...>'` for anyone who typechecks, despite
130
+ passing at runtime.
131
+
132
+ Reference the new types entry once, anywhere in the project:
133
+
134
+ ```ts
135
+ /// <reference types="vitest-native/rntl-matchers" />
136
+ ```
137
+
138
+ or add `"vitest-native/rntl-matchers"` to `compilerOptions.types`.
139
+
140
+ It is opt-in rather than folded into the main types because
141
+ `@testing-library/react-native` is an optional peer. A type import of an absent package
142
+ is invisible under `skipLibCheck: true`, React Native's own default, but reports `TS2307`
143
+ under `skipLibCheck: false` — which would break projects using the mock engine without
144
+ RNTL. A project that references nothing loads nothing: the file is not part of the
145
+ TypeScript program unless asked for.
146
+
147
+ ### Patch Changes
148
+
149
+ - a70c9f2: `toHaveAnimatedStyle` and `toHaveAnimatedProps` now throw for a value that is not a rendered element
150
+
151
+ Both matchers returned `{ pass: false }` when handed something without a `props`
152
+ object. Under `.not` that result is inverted, so
153
+ `expect(null).not.toHaveAnimatedStyle({ opacity: 1 })` passed — a query that matched
154
+ nothing, or a value of the wrong shape, produced a green assertion.
155
+
156
+ They now throw with the same message, which `.not` cannot invert. This matches React
157
+ Native Testing Library, whose `checkHostElement` raises for the same case rather than
158
+ failing softly.
159
+
160
+ The positive form still fails as before; only the negative form changes, from
161
+ silently passing to reporting the wrong receiver.
162
+
163
+ - a70c9f2: Cross-check the Animated API surface, not just its behaviour
164
+
165
+ Every existing probe pins a behaviour, which cannot catch a member the mock invents:
166
+ code written against one passes under the mock engine and throws under the native
167
+ engine, because real React Native has no such method. Comparing the two surfaces
168
+ directly found five such members, and nine real React Native members the mock does not
169
+ implement — the same trap in reverse, where valid React Native code throws under the
170
+ mock.
171
+
172
+ The corpus now compares the member lists of `Animated`, `Animated.Value`,
173
+ `Animated.ValueXY` and interpolations under both engines. Today's divergences are
174
+ enumerated in an allowlist so they are reviewed rather than invisible, and anything new
175
+ on either side fails. They are also recorded in the published known-differences table:
176
+
177
+ - Extra on the mock: `getValue()` on values and interpolations (real React Native
178
+ exposes only the internal `__getValue()`), plus `resetAnimation()`/`stopAnimation()`
179
+ on interpolations.
180
+ - Missing from the mock: `Animated.Node`, `Animated.Event`, `Animated.Interpolation`,
181
+ `attachNativeEvent`, `Value.track`, `Value.stopTracking`, `Value.animate`,
182
+ `hasListeners`, `ValueXY.toJSON`.
183
+
184
+ - f21986f: Name the cause of two failures that used to arrive unexplained
185
+
186
+ A suite calling `jest.mock()` without `jestMockTransform()` in its plugins now says so.
187
+ Vitest only hoists mocks written on the `vi`/`vitest` identifier, so the call runs after
188
+ the imports it is meant to intercept and the mock silently does not apply — the test
189
+ fails comparing real output against expected mock output, with nothing pointing at the
190
+ cause. Reported once per run, with the config line to add.
191
+
192
+ Two resolvable copies of React are now reported at startup. React throws
193
+ `Cannot read properties of null (reading 'use')` when hooks run through a second copy,
194
+ which React Native Testing Library surfaces as a failure to detect host component names
195
+ and attributes to "an issue with your configuration". The warning names both paths and
196
+ which package pulled the second copy in. `resolve.dedupe` still prevents the common
197
+ case; this covers the ones it cannot reach.
198
+
199
+ Two existing messages also say more: an unknown `hotRuntime` option now suggests the
200
+ closest valid name and lists them all, matching what the top-level option check already
201
+ did, and the reanimated preset explains why a React Native component was unavailable
202
+ instead of only stating that it was.
203
+
204
+ - f21986f: The fidelity page now states what the cross-check covers, and the corpus reaches further
205
+
206
+ A matching probe count says how many comparisons pass, not how much of the mock they
207
+ reach. It reached 9 of 27 mocked APIs, and the page listed 81 green ticks without
208
+ mentioning that — a reader would reasonably infer broader coverage than existed. The
209
+ page now reports the covered fraction and names every API and component no probe
210
+ touches. It is computed when the page is generated, so it moves with the corpus instead
211
+ of going stale.
212
+
213
+ Four probes were added over the untouched surface, chosen where a difference would be a
214
+ real mock bug rather than an unavoidable device difference: the full `Easing` curve set
215
+ including `bezier` and the parameterised `elastic`/`back`/`bounce`, `InteractionManager`,
216
+ and a `DeviceEventEmitter` round trip.
217
+
218
+ That found one: `InteractionManager.runAfterInteractions()` runs its task synchronously
219
+ under the mock engine, while real React Native defers it a tick. Both run it exactly
220
+ once, so this is timing rather than behaviour — but a test asserting immediately after
221
+ the call passes under the mock and fails under the native engine. It is now recorded as
222
+ a known difference; awaiting a tick, or using a `findBy*` query, works under both.
223
+
224
+ - 79e8b16: `doctor` now reports whether the config actually uses the plugin
225
+
226
+ The config check was a substring test for "vitest-native", so a config whose only
227
+ mention was a `// TODO: migrate to vitest-native` comment reported "uses
228
+ vitest-native" and "No blocking problems found" — on a project where every React
229
+ Native import fails. A config that imports the plugin but never adds it to
230
+ `plugins: [...]`, or where the import has been commented out, read the same way.
231
+ Diagnosing exactly that is the command's purpose.
232
+
233
+ The check now reads the import, takes the binding name from it so an aliased import
234
+ still counts, and confirms that binding is called. Import forms it does not recognise
235
+ are accepted rather than risking a false alarm on a working project.
236
+
237
+ `vite.config.*` is also recognised now. Vitest reads it when there is no
238
+ `vitest.config.*`, but it was missing from the list, so a correct setup was told to
239
+ run `vitest-native init` — advice that writes a second config which then takes
240
+ precedence over the working one.
241
+
242
+ - b62e24f: `doctor` reports the run, not the directory it was typed in
243
+
244
+ Two false reports from a workspace migration.
245
+
246
+ Peers and engine detection resolved from the working directory. That is frequently
247
+ not where the Vitest config lives, and under pnpm a package's node_modules holds only
248
+ its declared dependencies — so a hoisted `@react-native/babel-preset` does not
249
+ resolve from the package even though the real run finds it. `doctor` announced
250
+ "engine 'auto' resolves to MOCK" for a project whose run banner said native.
251
+
252
+ Resolution still happens from the directory the command was invoked in, which sees
253
+ the most: Node resolution walks upward, so that directory already reaches its own
254
+ dependencies and everything declared above it. The nearest directory holding both a
255
+ Vitest config and a manifest is consulted only when something does not resolve there
256
+ — the case where the command was run above the package that declares it — and the
257
+ report says when it fell back.
258
+
259
+ A config that builds on a shared one — common in a workspace — was also reported as
260
+ not referencing vitest-native. It legitimately never mentions it, because the plugin
261
+ is wired up in the package it extends. That case is now described rather than warned
262
+ about, since this cannot tell from the file alone.
263
+
264
+ - a70c9f2: `doctor` no longer reports a blocking problem for an optional peer it does not block on
265
+
266
+ A `@testing-library/react-native` version outside the supported range made `doctor`
267
+ print "Blocking problems found" and exit non-zero. The plugin does not block on it —
268
+ RNTL is an optional peer, and a version outside the range is a `console.warn` there
269
+ — so a project that runs its tests fine could still fail a `doctor` check. It is now
270
+ reported as a warning, matching what actually happens at run time. The genuine
271
+ blocker in that area is unchanged: RNTL 14 on a Node below 22.13 still fails, because
272
+ RNTL 14 declares `engines: ^22.13.0 || >=24`.
273
+
274
+ The supported range was also written three times — in this package's
275
+ `peerDependencies`, in the plugin's startup check, and again as a hardcoded major
276
+ comparison inside `doctor` — with nothing holding them together. It now comes from
277
+ the same table the other peers use, and a test asserts that table against the
278
+ published `peerDependencies` so the two cannot drift apart.
279
+
280
+ - b773a2d: Auto-detected CommonJS packages expose all of their named exports again
281
+
282
+ Node decides a CommonJS module's named exports with `cjs-module-lexer`, which reads
283
+ the source statically and stops at shapes it cannot follow. Given ordinary
284
+ hand-written CommonJS:
285
+
286
+ ```js
287
+ module.exports = { Banner({ label }) {}, renderCount: () => n };
288
+ ```
289
+
290
+ Node reports the named exports as `["Banner", "default", "module.exports"]` —
291
+ `renderCount` is missing, and a name that is not an export appears. That is plain
292
+ Node behaviour, reproducible with no plugin involved.
293
+
294
+ It became reachable when auto-detected React Native packages moved from Vite's graph,
295
+ whose interop enumerates the real object at run time, into Node's. `import { useFoo }
296
+ from 'some-rn-lib'` could then fail with "does not provide an export named", for the
297
+ hand-written CommonJS libraries auto-detection exists to support.
298
+
299
+ Transformed packages are now served with the dead `0 && (module.exports = { … })`
300
+ hint that the lexer does understand — the same mechanism React Native's own index
301
+ facade already used. Names come from the transform's own output, read from its AST,
302
+ rather than from requiring the module: the ESM hook runs on the module-loader thread,
303
+ where the CommonJS hooks that compile JSX are not installed, so requiring there fails
304
+ outright. A module whose shape is not statically knowable (`module.exports =
305
+ someValue`) emits no hint and keeps Node's own detection, which is no worse than
306
+ before.
307
+
308
+ The package budget is re-baselined to ~5% above the measured artifact, which is what
309
+ its own policy asks for, rather than left to fail on the next change.
310
+
311
+ - c1c973d: Gate that every declared entry point actually loads
312
+
313
+ The published `exports` map declares eleven subpaths, and a test checked that each
314
+ one points at a file that exists. Existing is not loading: three of the declared
315
+ CommonJS entries throw the moment they are required, and nothing noticed because
316
+ nothing ever loaded them.
317
+
318
+ `./dist/index.cjs` — the package's `main`, and the `require` condition of the root
319
+ export — is one of them. The root entry re-exports the presets, every preset imports
320
+ `vi` from vitest at module scope, and vitest refuses to be required from CommonJS. So
321
+ `const { reactNative } = require("vitest-native")` fails, while the ESM entry the
322
+ plugin is normally loaded through works. `./dist/presets.cjs` and `./dist/setup.cjs`
323
+ fail for the same reason.
324
+
325
+ Each declared runtime entry is now imported (or required, by extension) during the
326
+ suite. The three that cannot load are listed explicitly with the reason, and one that
327
+ starts loading fails as a stale entry, so the list cannot outlive the problem it
328
+ describes. Every `vi` call sits inside a preset factory that only runs in a worker, so
329
+ moving the import is a fix to how the presets are written rather than to the export
330
+ map; it is not part of this change.
331
+
332
+ - 3189ff9: Thrown errors now carry a class and a stable code
333
+
334
+ Errors raised by the plugin were plain `Error` instances whose only identity was their
335
+ message text. They are now `VitestNativeError`, or `VitestNativeTypeError` where a
336
+ `TypeError` is the right shape, each carrying a `code` from a fixed set.
337
+
338
+ What this changes for a consumer is the `name` on the error: it reads
339
+ `VitestNativeError` rather than `Error`, and that survives Vitest's serialisation of
340
+ errors out of a worker, which keeps `name`, `message` and `stack`. The `code` is
341
+ readable on errors thrown in the Vite main process — configuration and resolution
342
+ failures — but is an own property, so it does not survive that same serialisation for
343
+ errors raised inside a worker.
344
+
345
+ The classes and an `isVitestNativeError` guard are not importable from the package:
346
+ there is no `vitest-native/errors` entry point, and the main entry does not re-export
347
+ them. Adding one is a separate decision, since it is a twelfth public export path to
348
+ support, and it would also let the bundled entries self-reference `errors.mjs` instead
349
+ of carrying a second copy of it.
350
+
351
+ - a70c9f2: Flow enums are no longer dropped by the native engine's transform
352
+
353
+ React Native's Babel preset carries both `@babel/plugin-transform-flow-strip-types` and
354
+ `babel-plugin-transform-flow-enums`, but in separate `overrides` entries that Babel
355
+ merges into a single pass with strip-types first. It therefore deleted `export enum
356
+ Foo {}` as if it were a type annotation, while leaving the code that referenced `Foo`
357
+ in place — a module that loaded cleanly and threw `ReferenceError` on a path nothing
358
+ had warned about. In React Native 0.86 this made `VirtualViewMode` and
359
+ `VirtualViewRenderState` undefined when imported from `react-native`.
360
+
361
+ The enum plugin now runs ahead of the preset, which Babel's plugin/preset ordering
362
+ guarantees. Measured identical on preset 0.85.3 and 0.86.1, so this is the preset's
363
+ ordering rather than a version mismatch.
364
+
365
+ The precompiled registry's cache key now includes the transform's version too. It
366
+ stores transformed module source, and neither the preset version, the Babel version nor
367
+ the package version changes when the transform's own configuration does — so a warm
368
+ registry would have kept serving modules built before this fix.
369
+
370
+ - a70c9f2: Remove the hot runtime's last dependency on Vitest's internal worker state
371
+
372
+ The hot runtime re-enabled Vitest's per-file isolation by mutating
373
+ `state.ctx.config.isolate` inside the worker — a shape nothing contracts. It now
374
+ performs the two operations that flag was buying (`mocker.reset()` and a clear of the
375
+ evaluated module graph) directly, through public API: the `onModuleRunner` hook of
376
+ `vitest/worker`'s `init()`, and Vite's `ModuleRunner.clearCache()`.
377
+
378
+ - a70c9f2: Complete the `jest` global's API surface
379
+
380
+ Eleven documented Jest members were absent from the `jest` global, so a migrated suite
381
+ calling one got `TypeError: jest.X is not a function` — the bare failure the shim's
382
+ signposting already existed to prevent. The gaps included siblings of members that
383
+ were covered: `isolateModules` was signposted but not `isolateModulesAsync`,
384
+ `deepUnmock` but not `dontMock`.
385
+
386
+ Three had a Vitest equivalent under a different name and now use it:
387
+
388
+ - `jest.dontMock(m)` → `vi.doUnmock(m)`
389
+ - `jest.setMock(m, exports)` → `vi.doMock(m, () => exports)`
390
+ - `jest.now()` → the current clock, faked or real
391
+
392
+ The rest throw an error naming the API and its closest migration, as the other
393
+ unsupported members already did: `isolateModulesAsync`, `unstable_mockModule`,
394
+ `replaceProperty`, and the automock family (`enableAutomock`, `disableAutomock`,
395
+ `autoMockOff`, `autoMockOn`, `onGenerateMock`), which has no Vitest counterpart at all.
396
+
397
+ - e6cb458: `jest.mock` with an async factory keeps its named exports
398
+
399
+ `jestMockTransform()` wraps each `jest.mock` factory so its return passes through
400
+ Jest's CommonJS interop. The wrapper handled a synchronous return only. An async
401
+ factory — or any factory returning a promise — handed the promise itself to the
402
+ interop, where it matched the object branch: a promise has no own enumerable keys and
403
+ no `default`, so the result was `{ default: Promise }`. Every named export
404
+ disappeared, and the failure surfaced as
405
+
406
+ No "readSetting" export is defined on the "./settings-store" mock.
407
+ Did you forget to return it from "vi.mock"?
408
+
409
+ naming a `vi.mock` the author never wrote.
410
+
411
+ Interop now applies to the resolved module. The check is by object tag rather than for
412
+ a `then` method: a module may legitimately export a function named `then`, and
413
+ awaiting that calls it with `(resolve, reject)` and never settles, hanging the test
414
+ file instead of failing it. `async` functions and `Promise.resolve` only ever produce
415
+ native promises, which the tag identifies across realms.
416
+
417
+ - a70c9f2: `jest.setTimeout(ms)` now applies instead of being ignored
418
+
419
+ The jest-compat shim stubbed `jest.setTimeout` as a no-op, on the grounds that `vi`
420
+ had no equivalent. `vi.setConfig({ testTimeout })` is one, and it applies for the rest
421
+ of the file — the same scope Jest gives `jest.setTimeout`, since Vitest resets the
422
+ config after each test file.
423
+
424
+ The no-op did not crash anything, which is what made it costly. A suite opening with
425
+ `jest.setTimeout(30000)`, routine for slower React Native suites, silently kept
426
+ Vitest's 5s default: its slow tests failed on time while the line meant to prevent
427
+ that sat above them. A 6s test under `jest.setTimeout(20000)` failed with "Test timed
428
+ out in 5000ms" before this change and passes after it.
429
+
430
+ A non-numeric argument is still ignored rather than written into the config.
431
+
432
+ - a70c9f2: Add `LayoutAnimation.easeInEaseOut()`, `.linear()`, `.spring()`, `.setEnabled()` and `.checkConfig()` to the mock engine
433
+
434
+ The preset shortcuts were missing entirely, so `LayoutAnimation.easeInEaseOut()` — the
435
+ idiomatic one-liner in a React Native codebase — threw "is not a function" under the
436
+ mock engine while the same call worked under the native one. They now bind to
437
+ `configureNext` with the matching preset, exactly as React Native defines them, so a
438
+ test asserting on `configureNext` sees the call either way.
439
+
440
+ Found by diffing the mock's member list against real React Native's across every mocked
441
+ namespace. A behavioural test cannot catch a member that is not there, so the
442
+ cross-check corpus now covers this shape too.
443
+
444
+ - a70c9f2: Stop claiming a preset covers the legacy `react-native-vector-icons` package
445
+
446
+ The preset auto-detect map listed both `@react-native-vector-icons/common` and the
447
+ unscoped `react-native-vector-icons` against the `vectorIcons` preset. That preset
448
+ shadows exactly one module — the shared factory the v10+ scoped icon-set packages
449
+ are built on. The legacy package predates that split and does not use it, so the
450
+ preset had nothing to give it.
451
+
452
+ A package name in that map means "a preset shadows this, so its real source never
453
+ loads", and three things act on it: the package is excluded from React Native
454
+ ecosystem auto-inlining, and both `doctor` and `migrate` report it as already
455
+ handled. A project on the legacy package therefore had its untranspiled source
456
+ neither shadowed nor transformed, which is the parse failure auto-inlining exists to
457
+ prevent, while the tooling reported it as covered.
458
+
459
+ The mapping is removed, so `react-native-vector-icons` is auto-inlined and
460
+ transformed like any other React Native ecosystem package. Projects on the scoped
461
+ packages are unaffected.
462
+
463
+ Presets are also now checked against the map: every package name it lists must be
464
+ one the named preset actually declares a module for. Only packages installed in this
465
+ repository's own test suites exercised that link before, so a mapping that pointed
466
+ nowhere could go unnoticed.
467
+
468
+ - 1c4c7f7: Update `magic-string` to 1.x
469
+
470
+ `magic-string` is one of the package's two runtime dependencies, so the major bump
471
+ changes what consumers install. The four methods the `jest.mock` hoisting transform
472
+ uses — `overwrite`, `appendLeft`, `appendRight`, and `generateMap` — are unchanged in
473
+ behaviour, and the hoisting suite passes against the new version.
474
+
475
+ - c1c973d: Resolve `.json` imports, and try extensions in Metro's order
476
+
477
+ The plugin replaces Vite's `resolve.extensions` wholesale with a platform-ordered
478
+ list, so anything missing from that list stops resolving. `json` was missing, while
479
+ Metro treats it as a source extension — `import config from './config'` next to a
480
+ `config.json` worked in the app and failed in the test, with a bare "Cannot find
481
+ module".
482
+
483
+ The order within each platform group was also inverted relative to Metro. Metro's
484
+ default `sourceExts` are `["js", "jsx", "json", "ts", "tsx"]`, so it picks `Foo.js`
485
+ over `Foo.tsx`; the plugin picked `Foo.tsx`. A project with a compiled file beside
486
+ its source therefore tested a different file than it shipped. Both graphs now try
487
+ `.<platform>.{js,jsx,json,ts,tsx}`, then `.native.*`, then the bare extensions, which
488
+ is Metro's own order.
489
+
490
+ `.mjs` and `.cjs` remain unresolvable without an explicit extension, matching Metro.
491
+
492
+ The list was written out twice — once for the Vite graph and once for the Node
493
+ graph — with nothing holding the two together; a divergence would have resolved one
494
+ file in one graph and a different file in the other for the same import. Both are
495
+ now derived from a single definition, and a test asserts they agree.
496
+
497
+ - a70c9f2: `migrate` no longer emits Jest's `<rootDir>` token into the config it generates
498
+
499
+ A Jest `setupFiles` or `setupFilesAfterEnv` entry written as `<rootDir>/jest.setup.js`
500
+ — the form nearly every real Jest config uses — was copied into the generated Vitest
501
+ config verbatim. Vitest does not substitute `<rootDir>`, so it resolved the string as
502
+ written and every test file failed to load with
503
+ `Cannot find module .../<rootDir>/jest.setup.js`, while the migration report listed
504
+ the mapping under "Mapped automatically".
505
+
506
+ Setup-file paths are now rewritten the same way `moduleNameMapper` targets already
507
+ were, as `fileURLToPath(new URL('./jest.setup.js', import.meta.url))`. `testMatch`,
508
+ `include` and `moduleNameMapper` already stripped the token; setup files were the one
509
+ path that did not.
510
+
511
+ - 599d0e0: Give React Native ecosystem packages a single owner
512
+
513
+ The native engine runs two module systems: Vite resolves the test graph, and Node's
514
+ CJS resolver serves everything externalized. Auto-detected ecosystem packages were
515
+ inlined, so Vite executed them — which left Node either unable to load them at all,
516
+ or holding a second copy with its own module-level state.
517
+
518
+ The second case is the dangerous one. Nothing fails: a store configured through one
519
+ copy simply reads back unset through the other, so a translated label renders as an
520
+ empty string and the test compares empty output against expected text with nothing
521
+ pointing at the cause.
522
+
523
+ They are now externalized and transformed by the Node hooks, exactly as React Native
524
+ itself already is, so one graph owns them and a single instance follows from the
525
+ design rather than from Vitest's externalization heuristics.
526
+
527
+ Both properties inlining provided are kept, and were measured rather than assumed:
528
+ `vi.mock()` still intercepts these packages, and their module state still resets
529
+ between test files. Node can now also load them at all — previously a `require` of
530
+ an ecosystem package failed on its untranspiled source, since the hooks transformed
531
+ only React Native and the packages named in `transform`.
532
+
533
+ This also fixes a reported failure that looked unrelated: a Flow type import inside a
534
+ PLATFORM VARIANT of an auto-detected package — `datetimepicker.ios.js` — failed to
535
+ compile until the project named the package in `transform` by hand. The detector had
536
+ not missed it; the package declares react-native in peerDependencies and was found.
537
+ The variant was simply reached through Node, which had no way to strip Flow from a
538
+ package Vite owned. One owner fixes both halves: the resolver picks the variant and
539
+ the same hooks that transform React Native strip its types.
540
+
541
+ - 4be3eab: Switch a single auto-detected preset off with `presets: { name: false }`
542
+
543
+ `presets` accepted only an array, and providing one replaced auto-detection entirely.
544
+ A project that needed to drop one preset — for example the navigation preset, because
545
+ its stub means a real `NavigationContainer` never fires `onReady` — had to enumerate
546
+ every other detected preset by hand. That list then rots silently as dependencies
547
+ change: add a library and its preset is not applied, because the hand-written array
548
+ does not mention it.
549
+
550
+ Passing an object keeps auto-detection and names only what to drop. The array form is
551
+ unchanged.
552
+
553
+ - b015c89: Rebuild the React Native registry when React changes
554
+
555
+ Upgrading React while staying on the same React Native served a precompiled registry
556
+ built against the previous React. The native engine then failed in ways that look
557
+ nothing like a stale cache:
558
+
559
+ ```
560
+ TypeError: Cannot read properties of null (reading 'useContext')
561
+ AssertionError: expected [Function Dimensions] to be [Function Dimensions]
562
+ ```
563
+
564
+ — a null React dispatcher and React Native singletons that no longer compare equal,
565
+ which is the duplicate-instance failure the registry exists to prevent.
566
+
567
+ The registry is disk-cached under `node_modules/.cache/vitest-native` and keyed on
568
+ React Native, `@babel/core`, `@react-native/babel-preset`, the platform, and this
569
+ package's own version. `react` was missing, and the manifest check could not stand in
570
+ for it: that stats React Native's own files, which do not change when React alone is
571
+ upgraded. The cache was therefore reused when it should not have been, and deleting
572
+ the cache directory by hand was the only way out.
573
+
574
+ `react` is now part of the key. Because the failure is self-clearing on a later run,
575
+ it was easy to read as flakiness rather than as a stale cache.
576
+
577
+ - 9428119: Report when the precompiled React Native registry cannot be built
578
+
579
+ The native engine compiles React Native's module graph into a single file, and falls
580
+ back to per-file module loading when it cannot. The fallback is correct — tests still
581
+ run and no result changes — which is what made it hard to notice: a degraded run
582
+ looked exactly like a healthy one, only slower. Measured on this package's own native
583
+ suite, roughly 1.4x, and the per-file cost compounds on a larger suite.
584
+
585
+ Neither failure path said so. The build path logged only under `diagnostics`, which
586
+ is off by default, and the cache-directory path returned without a message under any
587
+ setting. Both now warn once per distinct cause, naming the cause and stating that
588
+ results are unaffected. Setting `VITEST_NATIVE_NO_REGISTRY=1` remains silent, since
589
+ that path is a request rather than a failure.
590
+
591
+ - 44432f0: `jest.requireActual` resolves relative paths against the calling file
592
+
593
+ Jest resolves `jest.requireActual('../thing')` against the module that called it. The
594
+ compat layer backed it with a single `createRequire` anchored at the project root, so
595
+ bare specifiers worked and relative ones escaped the source tree: MODULE_NOT_FOUND,
596
+ with a requireStack pointing at `<projectRoot>/package.json` — a confusing place to
597
+ be sent when the file sits beside the test. A migration reported this breaking five
598
+ files until they shimmed around it.
599
+
600
+ Relative specifiers now resolve from the caller, taken from the stack, since these
601
+ are runtime calls on the `jest` global rather than rewritten imports. Bare specifiers
602
+ still resolve from the project, and a caller-relative miss is reported rather than
603
+ retried against the root, which could otherwise resolve an unrelated file that
604
+ happens to sit at the same relative path.
605
+
606
+ - a70c9f2: `resetAllMocks()` now resets every stateful mock, including `NativeAppEventEmitter`
607
+
608
+ The helper reset a hand-written list of seven mocks. `NativeAppEventEmitter` is a
609
+ second event-emitter instance — the mock registry builds one per name, so it is not
610
+ the same object as `DeviceEventEmitter` — and it was not on the list. A listener
611
+ registered on it survived `resetAllMocks()` and fired again in the next test.
612
+
613
+ The helper now resets every mock that exposes a `_reset`, so a stateful mock added
614
+ later is covered on arrival rather than needing to be remembered here.
615
+
616
+ - 69c761b: Report when a package resolves to two different files across the two module systems
617
+
618
+ The native engine runs two resolvers: Vite resolves the test graph, and Node's CJS
619
+ resolver serves everything externalized. The plugin points Vite at React Native's
620
+ fields — `react-native`, `module`, `jsnext:main`, `jsnext` — and `main`, which is all
621
+ Node's resolver consults, is not among them.
622
+
623
+ Any package publishing a `react-native` field, which is ordinary across the ecosystem,
624
+ or a `module` field, which is ordinary for anything dual-format, therefore resolves to
625
+ a different file on each side. When both graphs load it the package exists twice, with
626
+ separate module-level state, and nothing says so: a store written through one copy
627
+ reads back unset through the other, so values arrive empty and the failure surfaces far
628
+ from its cause.
629
+
630
+ The Node-side resolver now compares each package it resolves against the file Vite's
631
+ field order would choose, and reports the pair once per package when they differ,
632
+ naming the field responsible and what diverging state means. It does not fire on a
633
+ suite where the two agree.
634
+
635
+ This is a diagnostic, not a fix: making the two resolvers agree is a separate change.
636
+
637
+ - 599d0e0: Resolve format-only package fields the way Node does, so they load once
638
+
639
+ The native engine runs two module systems. Vitest forwards `resolve.conditions` to
640
+ the worker's Node, so packages using an `exports` map resolve identically on both
641
+ sides. Legacy top-level fields have no such bridge: Vite reads `module`, Node reads
642
+ `main`, and a package publishing both is loaded twice with separate module-level
643
+ state. Nothing fails — a store written through one copy reads back unset through the
644
+ other, so values arrive empty and the failure surfaces far from its cause.
645
+
646
+ A `module` field selects a different FORMAT of the same code, so Vite is now pointed
647
+ at `main` for those packages and the pair collapses into a single instance.
648
+
649
+ A `react-native` field is left exactly as it was. That one selects a different
650
+ IMPLEMENTATION — the native build rather than the web build — and Metro resolves it
651
+ ahead of `main`, so the engine must too. Aligning it downward would quietly load the
652
+ web build, which is a fidelity regression rather than a fix; packages using it stay
653
+ split and are reported by the duplicate-instance warning instead.
654
+
655
+ Packages the engine inlines and transforms are also untouched, since Vite is meant to
656
+ own their source.
657
+
658
+ - 3a0dc69: Cover the native-stack surface in the screens preset
659
+
660
+ A real native-stack never reached `onReady`, so the screen stayed empty with nothing
661
+ thrown, until the project shipped its own mock of react-native-screens. The preset
662
+ declared 12 exports where the package has 26.
663
+
664
+ The gap was closed against react-native-screens 4.26.2's published type surface
665
+ rather than against the names that had been noticed missing — the report named six,
666
+ and checking the package found sixteen. `ScreenStackItem` is the one that matters
667
+ most, since native-stack renders through it.
668
+
669
+ `ScreenContext` is a real React context rather than a component stub, because
670
+ native-stack calls `useContext` on it, and `useTransitionProgress` returns a progress
671
+ shape rather than an empty mock. The v3 names `NativeScreen` and
672
+ `NativeScreenContainer` are kept so a project on the older major does not lose them.
673
+
674
+ Not covered: `RNSScreensRefContext` and `GHContext`, which are not entry-point
675
+ exports — they live in the package's `contexts` module and are reached by deep
676
+ import.
677
+
678
+ - a70c9f2: The snapshot serializer no longer throws on a circular prop, and produces stable output
679
+
680
+ Three fixes to the serializer registered for every project by the plugin's setup file.
681
+
682
+ A prop holding a circular object — a navigation object, a store, anything with a
683
+ parent back-reference — raised `TypeError: Converting circular structure to JSON`, so
684
+ the test failed with a type error instead of producing a snapshot. Cycles now print
685
+ as `[Circular]`.
686
+
687
+ Object keys inside a prop value are sorted, so two structurally equal props serialize
688
+ identically. Previously `{ a: 1, b: 2 }` and `{ b: 2, a: 1 }` produced different
689
+ snapshots, and a rewrite that changed nothing could churn a snapshot file. Prop names
690
+ were already sorted; this applies the same rule inside values. Array order is
691
+ preserved, since it is meaningful.
692
+
693
+ Functions and `undefined` nested inside a prop are shown rather than dropped:
694
+ `{ onPress: fn }` used to print as `{}`, an empty object that reads like missing data.
695
+
696
+ Non-element children are also indented one level less, matching sibling elements.
697
+
698
+ - 687b79f: Document the versioning contract, and check it against the build
699
+
700
+ The package shipped stability _labels_ — which surfaces are release-supported, which
701
+ are experimental — but never a semver contract: which exports and options are covered,
702
+ what a major may break, how the peer ranges may move, and what a deprecation cycle
703
+ looks like. `docs/versioning.md` states all of it, and ships with the package.
704
+
705
+ The document enumerates the public surface, so it is checked rather than trusted.
706
+ `tests/versioning-contract.test.ts` loads each documented entry point and asserts the
707
+ export lists match exactly in both directions, that the stated preset-factory count is
708
+ right, and that the documented plugin options are exactly the keys the validator
709
+ accepts. A surface added without a contract update fails the suite, as does a contract
710
+ naming something that does not exist.
711
+
712
+ - 4285a77: Auto-detection sees workspace members, so running from a monorepo root works
713
+
714
+ Package auto-detection walked manifests upwards from the run root. In a workspace the
715
+ run root is frequently _above_ the package under test — Nx invokes tasks from the
716
+ workspace root, and Vitest's root follows the working directory — so the app's own
717
+ dependencies live in a manifest that walking up never reaches.
718
+
719
+ A workspace library therefore missed detection, stayed in Vite's graph while Node
720
+ loaded it too, and came apart into two module instances with separate module-level
721
+ state. Reproduced in a pnpm workspace: the same config and the same code passed from
722
+ the app directory and failed from the workspace root, with state written through one
723
+ graph reading back unset through the other.
724
+
725
+ Detection now also reads the manifests of workspace members declared by any manifest
726
+ it finds, including pnpm's separate `pnpm-workspace.yaml` list, and resolves each
727
+ candidate from whichever of those directories can see it — necessary under pnpm,
728
+ where a workspace package is linked only into the package that depends on it.
729
+
730
+ The consumer gate now runs the monorepo fixture from the workspace root as well as
731
+ from the app directory, so the invocation that exposed this is covered rather than
732
+ assumed.
733
+
3
734
  ## 0.9.0
4
735
 
5
736
  ### Minor Changes