vitest-native 0.8.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.
- package/CHANGELOG.md +1063 -0
- package/README.md +47 -2
- package/dist/cli.cjs +642 -0
- package/dist/cli.d.cts +4 -0
- package/dist/cli.d.mts +4 -0
- package/dist/cli.mjs +638 -0
- package/dist/ecosystem-CO5vqExO.mjs +318 -0
- package/dist/ecosystem-IuZ-Gv0R.cjs +356 -0
- package/dist/errors-Dm5yLNTF.mjs +64 -0
- package/dist/errors-flXDIeWk.cjs +75 -0
- package/dist/errors.d.mts +46 -0
- package/dist/errors.mjs +78 -0
- package/dist/helpers.cjs +6 -23
- package/dist/helpers.d.cts +0 -6
- package/dist/helpers.d.mts +0 -6
- package/dist/helpers.mjs +6 -23
- package/dist/{index-vlK4zxuK.d.mts → index-BJL4cQ-l.d.cts} +22 -7
- package/dist/{index-YjjYELG7.d.cts → index-CvCU0cLl.d.mts} +20 -9
- package/dist/index.d.mts +8 -6
- package/dist/index.mjs +563 -232
- package/dist/jest-compat/interop.mjs +15 -0
- package/dist/jest-compat/setup.mjs +164 -5
- package/dist/matchers.cjs +16 -7
- package/dist/matchers.mjs +16 -7
- package/dist/native/boundary.mjs +108 -30
- package/dist/native/compile-cache.mjs +10 -5
- package/dist/native/explain.mjs +69 -0
- package/dist/native/hooks.mjs +151 -4
- package/dist/native/loader.mjs +61 -12
- package/dist/native/match.mjs +107 -8
- package/dist/native/module-reset.mjs +63 -0
- package/dist/native/registry.mjs +540 -0
- package/dist/native/reset.mjs +18 -12
- package/dist/native/resolve.d.mts +22 -0
- package/dist/native/resolve.mjs +21 -13
- package/dist/native/runner.mjs +34 -7
- package/dist/native/setup.mjs +19 -3
- package/dist/native/transform.mjs +195 -21
- package/dist/native/worker.mjs +69 -17
- package/dist/pool-Bcxp4Qrg.mjs +118 -0
- package/dist/pool-CFND7plG.cjs +122 -0
- package/dist/{preset-map-DCWaM08s.mjs → preset-map-BpDG_D5m.mjs} +1 -1
- package/dist/{preset-map-BY9zk9Pj.cjs → preset-map-DxilQ4pI.cjs} +1 -1
- package/dist/{presets-7eMfp7o2.cjs → presets-BGTqVH6C.cjs} +227 -52
- package/dist/{presets-23FJ76O4.mjs → presets-CK85x8ey.mjs} +222 -53
- package/dist/presets.d.mts +2 -2
- package/dist/presets.mjs +2 -2
- package/dist/rntl-matchers.d.ts +35 -0
- package/dist/serializer.cjs +33 -3
- package/dist/serializer.mjs +33 -3
- package/dist/setup.mjs +544 -193
- package/docs/hot-default-design.md +129 -0
- package/docs/migrating-from-jest.md +43 -7
- package/docs/migrating-from-vitest-react-native.md +1 -1
- package/docs/release-readiness.md +24 -6
- package/docs/versioning.md +133 -0
- package/package.json +40 -38
- package/dist/index.cjs +0 -643
- package/dist/index.d.cts +0 -14
- package/dist/pool-B7LBfcMQ.mjs +0 -67
- package/dist/pool-p54QV1dQ.cjs +0 -69
- package/dist/presets.cjs +0 -17
- package/dist/presets.d.cts +0 -2
- package/dist/setup.cjs +0 -2514
- package/dist/setup.d.cts +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,1068 @@
|
|
|
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
|
+
|
|
734
|
+
## 0.9.0
|
|
735
|
+
|
|
736
|
+
### Minor Changes
|
|
737
|
+
|
|
738
|
+
- 3b08c19: Actionable errors and engine transparency for migration failure points.
|
|
739
|
+
|
|
740
|
+
- **Untransformed-package explainer**: when an externalized `node_modules` file throws a SyntaxError that fingerprints as untranspiled JSX/Flow/TypeScript (`Unexpected token '<'` and friends), the error now names the owning package and states the fix — `reactNative({ transform: ['<pkg>'] })` — with a link to the migration guide, instead of a bare Node compile stack. This is the single most common migration blocker observed in real-app bake-offs.
|
|
741
|
+
- **Decorated Babel failures**: a Babel crash inside the native transform now reports the file, platform, and owning package at the single transform choke point (ESM loader, CJS require hook, and `requireActual` all inherit it), chaining the original error as `cause`.
|
|
742
|
+
- **Engine banner**: one log line per process states which engine actually ran (`engine: native — real react-native@X` / `engine: mock — …`), so a silent `auto` fallback can never masquerade as real-RN testing.
|
|
743
|
+
- **Config-time fail-fast**: explicit `engine: 'native'` without `@react-native/babel-preset` / `@babel/core` now fails at config time with install instructions, instead of starting the run and dying inside the loader. The `auto`→mock fallback notice is now emitted via `console.warn`, and the Flow-strip parse-failure warning is always visible (no longer diagnostics-gated).
|
|
744
|
+
- **jest-compat signposts**: `jest.isolateModules`, `jest.createMockFromModule`, `jest.genMockFromModule`, and `jest.deepUnmock` now throw errors that name the API and its closest Vitest migration instead of bare `is not a function` TypeErrors; `jest.retryTimes` warns once and continues instead of crashing the suite.
|
|
745
|
+
|
|
746
|
+
- a6a6ae3: The mock engine's Animated is now a live node graph, matching real React Native's semantics (previously it was a snapshot system — the largest known fidelity gap, and the class real-app bake-offs had to monkeypatch around).
|
|
747
|
+
|
|
748
|
+
- **Derived nodes are live.** `interpolate()` (numeric AND string), `add`/`subtract`/`multiply`/`divide`/`modulo`, and `diffClamp` recompute from their sources on every read and re-notify listeners when any source moves. Numeric interpolations chain; derived nodes are valid operands (previously coerced to 0); chaining off a string interpolation still throws like RN.
|
|
749
|
+
- **Animated components re-render.** `Animated.View`/`Text`/`Image`/`ScrollView`/`FlatList`/`SectionList` and `createAnimatedComponent` wrappers subscribe to every node in their style — a `setValue()` or `timing().start()` after render updates the rendered style, so `toHaveStyle` assertions see current values. Gated against real React Native by three new crosscheck probes (post-render `setValue`, live interpolation, live transform) — the corpus is now 78/78.
|
|
750
|
+
- **Offsets are real.** `setOffset`/`flattenOffset`/`extractOffset` implement RN's semantics (the canonical PanResponder drag pattern) on `Value` and `ValueXY`; `ValueXY.addListener` now reports the joint `{x, y}` value.
|
|
751
|
+
- **`__getValue()` exists on plain values** (RN's own tests call it), and `AnimatedValueXY`/`AnimatedColor` gained `__getValue`/`getValue` parity.
|
|
752
|
+
- **`useAnimatedValue`/`useAnimatedValueXY`/`useAnimatedColor` are real hooks**: the value is `useRef`-memoized and survives re-renders (previously every render minted a fresh node, silently resetting animation state — and rebuilt the entire Animated namespace to do it). Consequently they must now be called inside a component, exactly like on-device.
|
|
753
|
+
|
|
754
|
+
- ac70dec: Compile React Native packages from `node_modules` automatically
|
|
755
|
+
|
|
756
|
+
Most of the React Native ecosystem publishes untranspiled source — JSX, Flow, or
|
|
757
|
+
TypeScript — assuming Metro will compile it. Node cannot run that, so every project
|
|
758
|
+
had to discover its own allowlist one `SyntaxError: Unexpected token '<'` at a time
|
|
759
|
+
and maintain it by hand in `transform: [...]`.
|
|
760
|
+
|
|
761
|
+
`engine: 'native'` now detects those packages: any dependency declaring `react-native`
|
|
762
|
+
in **its own** manifest is compiled with the project's React Native Babel preset and
|
|
763
|
+
inlined into the test graph. The manifest is the authority rather than a name pattern —
|
|
764
|
+
`react-native-*` misses `@gorhom/bottom-sheet` and would wrongly claim `react-native`
|
|
765
|
+
itself.
|
|
766
|
+
|
|
767
|
+
Because those packages land in the graph Vitest owns rather than being externalized,
|
|
768
|
+
`vi.mock('the-package')` now reaches them too. Mocking `react-native` itself still does
|
|
769
|
+
not change what a library sees — its own imports compile to `require`, which reaches
|
|
770
|
+
React Native directly.
|
|
771
|
+
|
|
772
|
+
Dependencies are read from the project's manifest and every manifest above it, so a
|
|
773
|
+
workspace that declares its React Native libraries at the repository root is covered.
|
|
774
|
+
|
|
775
|
+
Excluded automatically: packages a preset already shadows (their real source never
|
|
776
|
+
loads) and the test infrastructure — `@testing-library/react-native` and the renderers,
|
|
777
|
+
where a second copy in the graph corrupts rendering. `transform: [...]` keeps its
|
|
778
|
+
existing meaning for anything detection misses, and takes precedence over it.
|
|
779
|
+
|
|
780
|
+
- bbbfc5d: Stub Expo's dev-server messageSocket under the native engine.
|
|
781
|
+
|
|
782
|
+
`expo`'s `Expo.fx` requires `async-require/messageSocket` whenever `__DEV__ && globalThis.expo`, and that module throws at load time when the bundle wasn't served over HTTP ("Cannot create devtools websocket connections in embedded environments"). Under the native engine this took down any suite importing an `expo-*` package (e.g. `expo-image`) — the primary blocker for Expo apps. The module's only job is a devtools websocket to a live dev server, an environment that doesn't exist under Node, so it is now stubbed to a no-op via the boundary mechanism — matching Jest's dev-server-layer mocks. All published variants are covered (`build/` output and `src/` TS sources, plain and `.native`), and the `.ts`/`.tsx` require handlers now consult boundary stubs, which previously only `.js` did.
|
|
783
|
+
|
|
784
|
+
Validated against the obytes Expo template bake-off: the login-form suite (previously import-time dead) now passes, 34/40 → 38/40 overall with the two remaining failures pre-existing and unrelated (bottom-sheet mock completeness).
|
|
785
|
+
|
|
786
|
+
- 1a3bcea: New CLI: `npx vitest-native init | doctor | migrate`.
|
|
787
|
+
|
|
788
|
+
- **`init`** writes a ready-to-run Vitest config (`--jest-compat` for the exact jest-compat block the migration guide documents; refuses to overwrite without `--force`).
|
|
789
|
+
- **`doctor`** diagnoses the environment read-only: Node floor (including the RNTL 14 ⇄ Node 22.13 interaction, which previously surfaced only as a raw runtime failure), required peers against supported ranges, which engine `auto` resolves to and why, every auto-detected preset, Expo presence with known-limits pointer, and config presence. Exits non-zero on blocking problems.
|
|
790
|
+
- **`migrate`** analyzes the project's Jest configuration (`package.json#jest` or `jest.config.{js,cjs,json}`) and reports key-by-key what maps automatically (setup files, path aliases, `transformIgnorePatterns` allowlists → `transform: [...]`, timeouts, mock hygiene flags), what the auto-detected presets already cover (deletable manual `__mocks__` and setup lines), what needs a human, and what drops — ending with a complete suggested config. Dry-run by default; `--write` saves it. Test files are never edited (`jestMockTransform()` handles top-level `jest.mock` at runtime).
|
|
791
|
+
|
|
792
|
+
The packed-tarball consumer suite exercises the bin end-to-end (`npx vitest-native doctor|migrate`).
|
|
793
|
+
|
|
794
|
+
- ac70dec: Precompile React Native's require graph so isolated test files stop paying to re-load it
|
|
795
|
+
|
|
796
|
+
The native engine runs React Native's real JavaScript, and with isolation on — the
|
|
797
|
+
default — that graph was re-instantiated for every test file: roughly 440 separate
|
|
798
|
+
Node module loads each time, one per RN source file. Measured on RN 0.86, that cost
|
|
799
|
+
~59ms for a typical test's slice of React Native and ~110ms for the full public API,
|
|
800
|
+
per file.
|
|
801
|
+
|
|
802
|
+
React Native's graph is now walked once per (RN version × platform × Babel
|
|
803
|
+
toolchain) and emitted as a single file of lazy per-module factories with every
|
|
804
|
+
require target resolved ahead of time. A test file pays one read and one compile
|
|
805
|
+
instead of ~440. The registry is built in the Vite process, so the cost is paid once
|
|
806
|
+
per run, and it is cached under `node_modules/.cache/vitest-native` keyed by a
|
|
807
|
+
manifest of the files it was built from — a reinstalled or patched React Native
|
|
808
|
+
rebuilds it rather than serving stale code.
|
|
809
|
+
|
|
810
|
+
Measured on this repository's native suite: aggregate import time 8.8s → 1.9s
|
|
811
|
+
(4.6×), wall clock 1.81s → 1.05s.
|
|
812
|
+
|
|
813
|
+
Semantics are unchanged by design. Module identity is preserved, so React Native's
|
|
814
|
+
singletons behave exactly as before and a deep `react-native/Libraries/...` require
|
|
815
|
+
from an ecosystem package resolves to the same instance the app sees. Laziness is
|
|
816
|
+
preserved, so a test that touches `View` and `StyleSheet` still does not execute the
|
|
817
|
+
rest of React Native. Anything the registry cannot serve — a computed require, a
|
|
818
|
+
module outside the entry graph, a package listed in `transform` — falls through to
|
|
819
|
+
the per-file loader hooks, and a registry that cannot be built leaves the engine
|
|
820
|
+
running exactly as it did before.
|
|
821
|
+
|
|
822
|
+
- ac70dec: `vi.mock('react-native')` now works under the native engine
|
|
823
|
+
|
|
824
|
+
React Native runs in Node's module graph under `engine: 'native'`, which put it
|
|
825
|
+
outside Vitest's module registry — so `vi.mock('react-native', …)`, the single most
|
|
826
|
+
common thing an existing Jest suite does, silently had no effect. It was the most
|
|
827
|
+
frequently hit blocker when moving a real suite over.
|
|
828
|
+
|
|
829
|
+
The app and test graph now import React Native through a facade module the plugin
|
|
830
|
+
serves. The facade re-exports the same instances Node's graph holds, so React
|
|
831
|
+
Native's behaviour and object identity are unchanged — an externalized library and
|
|
832
|
+
your test still see the very same `Dimensions`, `Platform`, and `StyleSheet`. What
|
|
833
|
+
changes is that Vitest owns the module id, which is what lets it intercept:
|
|
834
|
+
|
|
835
|
+
```ts
|
|
836
|
+
vi.mock("react-native", async (importOriginal) => ({
|
|
837
|
+
...(await importOriginal<typeof import("react-native")>()),
|
|
838
|
+
Alert: { alert: vi.fn() },
|
|
839
|
+
}));
|
|
840
|
+
```
|
|
841
|
+
|
|
842
|
+
`importOriginal()` returns real React Native, everything left unmocked stays real,
|
|
843
|
+
and components still render React Native's own host components (`RCTView`, not a
|
|
844
|
+
stand-in).
|
|
845
|
+
|
|
846
|
+
One limit worth knowing: the interception covers modules in your project's graph —
|
|
847
|
+
your app and test code. A third-party package that Vitest externalizes resolves
|
|
848
|
+
React Native through Node and will still see the unmocked module. Add such a package
|
|
849
|
+
to `transform: [...]` if its view of React Native needs to be mocked too.
|
|
850
|
+
|
|
851
|
+
- ac70dec: Support Vitest 5
|
|
852
|
+
|
|
853
|
+
The peer range widens from `>=4 <5` to `>=4 <6`. Nothing in the package needed to
|
|
854
|
+
change for it: the native engine, the mock engine, the precompiled React Native
|
|
855
|
+
registry, the `react-native` facade, and the hot runtime all run unmodified on Vitest
|
|
856
|
+
5, including its `@experimental` worker API.
|
|
857
|
+
|
|
858
|
+
The claim is backed the same way the Vitest 4 support is. The CI matrix gains a
|
|
859
|
+
Vitest 5 column — run against the oldest and newest supported React Native, since it
|
|
860
|
+
varies the runner rather than RN — and it is blocking, because a declared peer range
|
|
861
|
+
is a promise about every release inside it. Each cell runs the native suite stock and
|
|
862
|
+
hot plus the mock-vs-real-RN cross-check, exactly as the Vitest 4 columns do.
|
|
863
|
+
|
|
864
|
+
While 5.x is still prerelease it is reachable only through its `beta` tag; the
|
|
865
|
+
repository's install-age policy still applies, so CI resolves the newest beta at least
|
|
866
|
+
a week old rather than whatever published that day.
|
|
867
|
+
|
|
868
|
+
- 2d07b7a: Add a built-in `react-native-worklets` preset (auto-detected). Worklets is Reanimated's low-level runtime and is also imported directly by apps (e.g. `import { scheduleOnUI } from 'react-native-worklets'`). It ships a Jest mock at `react-native-worklets/lib/module/mock` that is ESM ending in `module.exports = …`; under the native engine React Native and its ecosystem are externalized, so requiring that file through Node throws `module is not defined in ES module scope` and takes down the whole test file. The preset shadows the package with a self-contained mock modelled on worklets' own `mock.js` API (schedulers run their worklet synchronously, matching the Reanimated preset), so worklets-using suites load and render without a hand-written mock.
|
|
869
|
+
|
|
870
|
+
### Patch Changes
|
|
871
|
+
|
|
872
|
+
- e49168e: Bound hot-runtime memory by default. When `hotRuntime` is enabled on the native engine and neither `memoryLimit` nor `recycleAfterFiles` is configured, a default per-worker memory ceiling of `clamp(totalmem * 0.25, 768MB, 1.5GB)` is now applied. Hot workers keep React Native resident and accumulate roughly 4 MB per file, so without a bound a long suite could grow toward OOM; the default lets multi-worker runs recycle a worker once it crosses the ceiling, keeping total memory bounded out of the box.
|
|
873
|
+
|
|
874
|
+
An explicit `memoryLimit` or `recycleAfterFiles` is respected unchanged. Single-worker hot still cannot recycle (Vitest batches all files into one scheduler task), so the bound is inert there and the existing one-time "recycling INACTIVE" warning advises running with `maxWorkers >= 2`.
|
|
875
|
+
|
|
876
|
+
- 0d38401: Fix two `mock` engine divergences from real React Native, found by the behavioral cross-check:
|
|
877
|
+
|
|
878
|
+
- `Pressable` now resolves function `style` and `children` (`({ pressed }) => …`) against its press state, matching real RN's resting render and updating while pressed. Previously the functions were passed through untouched, so the style was never applied and function children never rendered.
|
|
879
|
+
- `processColor()` returns `undefined` for an unparseable color (matching real RN's normalizer) instead of coercing to opaque black.
|
|
880
|
+
|
|
881
|
+
Also publishes the cross-check as a generated, drift-guarded fidelity report — a live badge and a docs page listing the full corpus and what is deliberately left ungated — and expands the corpus to 75 probes.
|
|
882
|
+
|
|
883
|
+
- 6c29566: Expand the "Migrating from Jest" guide with the empirically-derived limits of a real migration: a "Known limits" section covering assertions coupled to Jest's RN mock internals that don't port under a real-RN engine (`jest.spyOn(View.prototype, …)`, mocks of RN internal submodules, raw `source`-shape assertions, `jest.mock` nested in callbacks), an Expo-core caveat, and concrete guidance for the `transformIgnorePatterns` → `transform` allowlist (including the JSX-in-`.js` third-party-lib parse error and its fix).
|
|
884
|
+
- ac70dec: Narrow the mock engine's Flow-strip, and stop `migrate` opting packages out of auto-compilation
|
|
885
|
+
|
|
886
|
+
**Flow-strip targeting.** The mock engine compiles React Native ecosystem packages
|
|
887
|
+
pulled into the Vite graph, selected by testing for `react-native` anywhere in the
|
|
888
|
+
file's path. That also matched every dependency of a project in a directory called
|
|
889
|
+
`react-native-app`, and packages like `eslint-plugin-react-native` — running a Flow
|
|
890
|
+
parser over files with nothing to do with React Native. It now matches the package
|
|
891
|
+
name after `node_modules`: a name beginning with `react-native` (scoped or not, so
|
|
892
|
+
`@shopify/react-native-skia` counts) or a scope beginning with `@react-native`.
|
|
893
|
+
Everything the substring test legitimately caught is still caught, and nothing else
|
|
894
|
+
is.
|
|
895
|
+
|
|
896
|
+
**`npx vitest-native migrate`.** It translated Jest's `transformIgnorePatterns` into
|
|
897
|
+
`transform: [...]` entries for packages the engine now detects and compiles by itself.
|
|
898
|
+
That was worse than redundant: an explicit `transform` entry takes precedence, so the
|
|
899
|
+
suggested config would have opted those packages back out of inlining, losing
|
|
900
|
+
`vi.mock` support for no gain. Packages declaring `react-native` are now reported as
|
|
901
|
+
already handled.
|
|
902
|
+
|
|
903
|
+
Also adds a test that the plugin's virtual `react-native` module exports exactly what
|
|
904
|
+
the mock provides — the two lists were in step, but only by hand.
|
|
905
|
+
|
|
906
|
+
- f6c4c5b: Provide `SourceCode.getConstants().scriptURL` at the native boundary. RN's `getDevServer` (`Libraries/Core/Devtools/getDevServer.js`) reads `scriptURL` and calls `.match()` on it; under the native engine the value was `undefined`, so `getDevServer` threw and took down any test whose module graph reached it. The boundary now returns a `file://` (bundled) URL for the `SourceCode` native module. It is deliberately not an `http(s)` URL: `getDevServer` only treats `http(s)` script URLs as a live dev server, so a `file://` value keeps `bundleLoadedFromServer` false — tests run as if loaded from a bundle rather than a Metro dev server, which prevents RN internals and third-party SDKs from believing they're connected to a packager and attempting real network I/O against `localhost:8081`. This mirrors the intent of RN's own Jest mock (which keeps that flag off).
|
|
907
|
+
- ac70dec: Explain why `engine: 'native'` cannot run on a VM pool
|
|
908
|
+
|
|
909
|
+
Now that a configured `pool` is respected rather than overridden, `vmThreads` and
|
|
910
|
+
`vmForks` reach the native engine — where they cannot work. VM pools execute test code
|
|
911
|
+
in a `vm` context whose module executor bypasses Node's loader, and `module.register()`
|
|
912
|
+
(how the engine installs the ESM hook that Flow-strips React Native and resolves its
|
|
913
|
+
platform files) throws there outright. The failure surfaced far from its cause, as
|
|
914
|
+
`Platform.OS` being undefined deep inside `NativeEventEmitter`.
|
|
915
|
+
|
|
916
|
+
The plugin now refuses at config time and names the alternatives: `threads` (the
|
|
917
|
+
default), `forks`, or `engine: 'mock'`, which needs no hooks.
|
|
918
|
+
|
|
919
|
+
- ac70dec: Stop overriding a configured `pool`, and refuse a mismatched Vitest instead of reporting nothing
|
|
920
|
+
|
|
921
|
+
Two fixes to the native engine's pool handling.
|
|
922
|
+
|
|
923
|
+
**A configured `pool` is no longer discarded.** A plugin's `config()` result is merged
|
|
924
|
+
over the user's config, and the native engine returned `pool: 'threads'`
|
|
925
|
+
unconditionally — so a project asking for `forks`, `vmThreads`, or its own custom pool
|
|
926
|
+
silently got `threads`, with no warning and no way to tell from the outside. `threads`
|
|
927
|
+
is now only a default, applied when no pool was configured. (`hotRuntime` still
|
|
928
|
+
supplies its own pool, since opting into it _is_ choosing one, and now warns when that
|
|
929
|
+
overrides a configured pool.)
|
|
930
|
+
|
|
931
|
+
**`hotRuntime` now fails loudly when its worker would load a different Vitest.** The
|
|
932
|
+
hot worker entry ships inside vitest-native, so its `import 'vitest/worker'` resolves
|
|
933
|
+
from this package's location rather than the project's. Where a monorepo has more than
|
|
934
|
+
one Vitest install — a linked package, a hoisted `node_modules`, mixed versions across
|
|
935
|
+
workspaces — the worker and the host end up on different installations. Nothing about
|
|
936
|
+
that was visible: the start handshake succeeded, the run request was accepted, no
|
|
937
|
+
result was ever reported, and Vitest printed "No test files found" with no error at
|
|
938
|
+
all. The pool now compares the two resolved paths at config time and throws, naming
|
|
939
|
+
both, rather than letting a run pass having tested nothing.
|
|
940
|
+
|
|
941
|
+
- ac70dec: Resolve React Native package entries the way Metro does
|
|
942
|
+
|
|
943
|
+
Both engines set `resolve.conditions: ['react-native']`, which governs Vite's _client_
|
|
944
|
+
environment. Vitest runs tests in the **ssr** environment, which keeps its own list —
|
|
945
|
+
Vite drops both `conditions` and `mainFields` when deriving it — so neither was ever
|
|
946
|
+
applied to anything a test imported.
|
|
947
|
+
|
|
948
|
+
Any package shipping a distinct React Native build behind that condition therefore
|
|
949
|
+
loaded its web build instead:
|
|
950
|
+
|
|
951
|
+
```jsonc
|
|
952
|
+
"exports": { ".": { "react-native": "./native.js", "default": "./web.js" } }
|
|
953
|
+
```
|
|
954
|
+
|
|
955
|
+
The same held for the legacy mechanism, still used by packages published before
|
|
956
|
+
`exports`:
|
|
957
|
+
|
|
958
|
+
```jsonc
|
|
959
|
+
"main": "./web.js", "react-native": "./native.js"
|
|
960
|
+
```
|
|
961
|
+
|
|
962
|
+
Metro resolves both ahead of the standard fields, so tests were exercising code the
|
|
963
|
+
app never runs, with nothing to indicate it. Both are now set for the ssr environment
|
|
964
|
+
as well as the client one, under both engines, with a regression test each.
|
|
965
|
+
|
|
966
|
+
`browser` is deliberately not added to `mainFields` even though Metro lists it: under
|
|
967
|
+
Node it would pull the web build of any package that has a browser field and no
|
|
968
|
+
react-native one.
|
|
969
|
+
|
|
970
|
+
**Upgrade note.** The `react-native` field is honoured wherever it appears, not only
|
|
971
|
+
on React Native libraries — Algolia's clients, `nanoid` and `msgpackr` all ship one,
|
|
972
|
+
usually pointing at a browser or ESM build. Metro resolves those the same way, so this
|
|
973
|
+
is the build the app actually runs, but a dependency may now load a different file
|
|
974
|
+
than it did before. If that is a problem for one package, `transform: ['the-package']`
|
|
975
|
+
or an explicit `resolve.alias` pins it.
|
|
976
|
+
|
|
977
|
+
- ac70dec: Fix a stale-registry hazard and restore React Native's stack frames
|
|
978
|
+
|
|
979
|
+
Two defects in the precompiled registry, both found by reviewing it adversarially
|
|
980
|
+
rather than by a failing test.
|
|
981
|
+
|
|
982
|
+
**The cache key ignored the boundary mocks' content.** It hashed their module _names_,
|
|
983
|
+
but the mocks are compiled into the registry, so changing one — a maintainer editing a
|
|
984
|
+
mock, or a user upgrading to a release that changed one — left the cached registry
|
|
985
|
+
valid and kept serving the previous behaviour with nothing to indicate it. The key now
|
|
986
|
+
hashes the rendered mock source, and this package's own version alongside it, covering
|
|
987
|
+
everything else it contributes.
|
|
988
|
+
|
|
989
|
+
**Stack frames from inside React Native lost their file.** Collapsing ~440 modules
|
|
990
|
+
into one file meant an RN-internal failure reported
|
|
991
|
+
`registry/rn-ios-<hash>.cjs:253:7638` instead of
|
|
992
|
+
`Libraries/Animated/nodes/AnimatedInterpolation.js` — the useful part of the frame.
|
|
993
|
+
The registry now emits a source map attributing every generated line to the React
|
|
994
|
+
Native file it came from, and enables Node's source-map support before compiling
|
|
995
|
+
itself. Failure output names real React Native files again, at no runtime cost.
|
|
996
|
+
|
|
997
|
+
Also relaxes the `hotRuntime` Vitest guard added alongside it: it compared resolved
|
|
998
|
+
paths, so a monorepo with the same Vitest version installed in two trees was refused
|
|
999
|
+
even though those interoperate fine. Only a version difference is an error now.
|
|
1000
|
+
|
|
1001
|
+
- 4c567c1: Make native-engine turboStubs identity-stable and spy-able. Unmocked native modules were served by a Proxy that minted a fresh stub object on every property access and whose get trap never consulted the target — so `NativeModules.Foo !== NativeModules.Foo`, and `vi.spyOn(NativeModules.Foo, 'method')` silently recorded nothing (the spy landed on a throwaway object). Stubs are now memoized per module name in the shared boundary state (`NativeModules.Foo === TurboModuleRegistry.get('Foo')`, matching bridgeless RN), methods are memoized on first read, and explicitly-set properties win — so spies record and restore correctly. A `has` trap reports all properties present, consistent with the get trap's serve-anything behavior, which `vi.spyOn`'s existence check requires. Under the hot runtime, per-file overrides (spies, memoized methods) are cleared between files via the surgical-reset registry while stub identity is preserved for resident libraries holding references.
|
|
1002
|
+
- 57f155d: Fix three silent resolution-fidelity gaps around deep (subpath) imports.
|
|
1003
|
+
|
|
1004
|
+
- **`react-native` subpath default exports are now the leaf module.** `import Platform from 'react-native/Libraries/Utilities/Platform'` previously received the entire mock object as `Platform`, so `Platform.OS` was silently `undefined`. The virtual subpath modules (ESM) and the CJS bridge now derive the intended export from the subpath's basename and serve it as the default — CJS requires get Babel-interop shape (`{ __esModule, default }` via a live wrapper) so both `require('.../Platform').OS` and `_interopRequireDefault(...)` consumers work. Unknown leaves keep the previous whole-mock fallback.
|
|
1005
|
+
- **`react-native/package.json` (and preset `pkg/package.json`) resolve to the real manifest.** Version gates like `require('react-native/package.json').version` previously read the mock and got `undefined`. Both the Vite-graph and CJS-bridge interception now exempt the manifest; when the package is not installed, the previous mock fallback is kept rather than erroring.
|
|
1006
|
+
- **Preset shadowing now covers subpath imports.** `import Swipeable from 'react-native-gesture-handler/Swipeable'` (and CJS equivalents, including requires nested inside externalized third-party libraries) previously bypassed the preset mock entirely and loaded the package's real native-runtime code — or failed resolution outright on package versions that no longer ship the deep file. All three redirect layers (Vite plugin, ESM loader hook, CJS require hook) now match subpaths of preset packages and serve the mock export named by the subpath's leaf, falling back to the root mock. JSON and asset-extension subpaths are exempt so manifests and font/image files keep resolving from disk. CJS interop wrappers are memoized per specifier (keyed by the live mock set, so hot-runtime per-file rebuilds stay correct) to keep module identity stable across repeated requires.
|
|
1007
|
+
|
|
1008
|
+
- 3b1c396: Native-engine transform cache rework: project-local, content-keyed, lazy Babel.
|
|
1009
|
+
|
|
1010
|
+
- **The transform disk cache moves from `os.tmpdir()` to the project's `node_modules/.cache/vitest-native/`** (tmpdir fallback when node_modules is absent or unwritable). tmpdir is ephemeral on CI runners — every job paid a full cold Babel transform of React Native's ~250-file boot graph — and macOS purges it periodically. The new location persists across runs and is restorable by standard CI dependency-cache actions. The V8 compile cache is colocated.
|
|
1011
|
+
- **Disk entries are keyed by content hash (platform + path + source), not mtime + size.** Content keys survive fresh installs, Docker mtime normalization, and CI cache restores — and eliminate the stale-hit class where a same-size, same-mtime file with different content served wrong executable code. The path stays in the key because Babel's output embeds the filename (`_jsxFileName` in transformed JSX), so identical sources at different paths must not share an entry; restores are valid wherever the checkout path is stable, which CI workspaces are. The cache directory name now also carries the `@babel/core` version alongside the preset version, so a Babel upgrade invalidates cleanly.
|
|
1012
|
+
- **`@babel/core` loads lazily, only on a cache miss.** Loading Babel costs ~35ms vs ~0.5ms for the resolve-only version check, and under the default engine every isolated worker paid it even when every file came from the disk cache. Measured on the package's own native suite (warm cache): aggregate worker setup down ~30%, wall clock ~11% — the effect scales with test-file count.
|
|
1013
|
+
|
|
1014
|
+
- ac70dec: Match `transform: [...]` packages by their real location, not by name anywhere in the path
|
|
1015
|
+
|
|
1016
|
+
The pattern behind `transform` tested for `/<package-name>/` anywhere in a file's
|
|
1017
|
+
path, so any **directory** sharing a package's name was treated as that package. A
|
|
1018
|
+
project folder called `expo`, or a source directory named after the library it
|
|
1019
|
+
implements, made every file beneath it get compiled and externalized as third-party
|
|
1020
|
+
source — including, in one case, this package's own runtime, which then failed with
|
|
1021
|
+
`Vitest cannot be imported in a CommonJS module using require()`.
|
|
1022
|
+
|
|
1023
|
+
A file now matches only if it is inside the package's resolved directory, or under
|
|
1024
|
+
`node_modules/<name>/`. Both rules are needed: the resolved directory covers workspace
|
|
1025
|
+
and `file:` dependencies, which resolve to a real path with no `node_modules` segment,
|
|
1026
|
+
while the `node_modules` rule covers additional copies of a package that a single
|
|
1027
|
+
resolution cannot see.
|
|
1028
|
+
|
|
1029
|
+
- 091a572: Three hardening fixes:
|
|
1030
|
+
|
|
1031
|
+
- **Prerelease peer versions no longer fail validation.** A prerelease sharing the minimum's major.minor (e.g. vitest `4.0.0-beta.3` against the `4.0.0` floor) parsed with `NaN` in the patch slot, failed the minimum check, and hard-errored at startup for installs running betas/RCs. Prerelease/build metadata is now stripped before comparison; a prerelease of the minimum itself is accepted.
|
|
1032
|
+
- **Mock-engine asset stubs match the native loader's semantics.** The extension match is now case-insensitive (`LOGO.PNG` stubs like `logo.png`), user-supplied `assetExts` entries are regex-escaped, and the stubbed basename is JSON-stringified so filenames containing quotes emit valid JS.
|
|
1033
|
+
- **The mock engine's Flow-strip transform skips unparseable files instead of throwing.** The `@flow` filter is a heuristic — the marker can appear inside a string or comment of a file `flow-remove-types` then fails to parse; that parse error previously took down the whole transform pipeline.
|
|
1034
|
+
|
|
1035
|
+
- ac70dec: Fix `importOriginal()` inside a test's own `vi.mock('react-native')` under the mock engine
|
|
1036
|
+
|
|
1037
|
+
A test that registered its own `vi.mock('react-native', …)` replaced the registration
|
|
1038
|
+
the setup file makes, and the factory's `importOriginal()` then resolved to an empty
|
|
1039
|
+
module. The near-universal spread-and-override form therefore dropped every export
|
|
1040
|
+
the test did not name:
|
|
1041
|
+
|
|
1042
|
+
```ts
|
|
1043
|
+
vi.mock("react-native", async (importOriginal) => ({
|
|
1044
|
+
...(await importOriginal()), // was empty
|
|
1045
|
+
Alert: { alert: vi.fn() },
|
|
1046
|
+
}));
|
|
1047
|
+
// -> No "Platform" export is defined on the "react-native" mock
|
|
1048
|
+
```
|
|
1049
|
+
|
|
1050
|
+
The virtual `react-native` module now re-exports the runtime mock, so
|
|
1051
|
+
`importOriginal()` returns the full surface and unnamed exports survive.
|
|
1052
|
+
|
|
1053
|
+
- ac70dec: Stop the hot runtime's legacy-runner import from breaking on Vitest 5
|
|
1054
|
+
|
|
1055
|
+
`hotRuntime`'s test runner imported `vitest/runners` as a fallback for Vitest 4.0.x,
|
|
1056
|
+
guarded by a runtime check. The guard does not help: a literal specifier is resolved
|
|
1057
|
+
when the module is transformed, not when the branch runs. Vitest 5 removed that
|
|
1058
|
+
subpath, so the resolve failed on every test file — and the failure mode was the worst
|
|
1059
|
+
kind, reporting unhandled errors, running no tests, and still exiting 0.
|
|
1060
|
+
|
|
1061
|
+
The fallback specifier is now computed, so it stays invisible to the resolver: Vitest
|
|
1062
|
+
4.0.x keeps its fallback and Vitest 5 never looks for it.
|
|
1063
|
+
|
|
1064
|
+
- a756f6a: Make `jest.requireActual('react-native')` return a writable facade. Jest suites commonly clone-and-override React Native — `const RN = jest.requireActual('react-native'); RN.Platform = {...}; return RN`. Under the native engine RN's index is a facade of lazy getters with no setters, so assigning to it threw `Cannot set property … which has only a getter` and failed to load the whole test file. `requireActual('react-native')` now returns a write-through proxy: reads fall through to the real (lazy) facade, and assignments are captured so the override wins on later reads — matching Jest's mutable module. Only `react-native` is wrapped; its submodules and other packages are ordinary mutable CommonJS.
|
|
1065
|
+
|
|
3
1066
|
## 0.8.0
|
|
4
1067
|
|
|
5
1068
|
### Minor Changes
|