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