vitest-native 0.14.0-rc.6 → 0.14.0-rc.9
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 +76 -8
- package/README.md +43 -34
- package/dist/cli.cjs +63 -28
- package/dist/cli.mjs +63 -28
- package/dist/{ecosystem-BzWGVo_T.mjs → ecosystem-D6e1OVOg.mjs} +54 -5
- package/dist/{ecosystem-DTozsAyV.cjs → ecosystem-MFwkbnaC.cjs} +59 -4
- package/dist/{index-bZ7AHqLc.d.cts → index-CzQazgp9.d.cts} +5 -5
- package/dist/{index-BSyUeoga.d.mts → index-xw43lBlv.d.mts} +5 -5
- package/dist/index.d.mts +1 -1
- package/dist/index.mjs +11 -8
- package/dist/jest-compat/setup.mjs +6 -0
- package/dist/native/babel-preset.d.mts +14 -0
- package/dist/native/babel-preset.mjs +56 -0
- package/dist/native/boundary.mjs +14 -2
- package/dist/native/expo-module-mocks.mjs +432 -0
- package/dist/native/expo-module-table-57.mjs +1925 -0
- package/dist/native/expo-module-table-58.mjs +2045 -0
- package/dist/native/expo-module-tables.mjs +6 -0
- package/dist/native/expo-native-modules.mjs +66 -0
- package/dist/native/globals.mjs +118 -3
- package/dist/native/hooks.mjs +24 -0
- package/dist/native/loader.mjs +105 -16
- package/dist/native/registry.mjs +4 -1
- package/dist/native/runner.mjs +33 -1
- package/dist/native/setup.mjs +21 -8
- package/dist/native/transform.mjs +51 -28
- package/dist/native/worker.mjs +87 -11
- package/dist/{preset-map-DO-dKDgr.mjs → preset-map-BlBriTA0.mjs} +29 -1
- package/dist/{preset-map-B-T1CcPr.cjs → preset-map-jSFsNy1Q.cjs} +34 -0
- package/dist/{presets-C8vJ2Vnl.mjs → presets--zrEWQC2.mjs} +32 -4
- package/dist/{presets-Bpy47wwV.cjs → presets-9f83H0WW.cjs} +32 -4
- package/dist/presets.d.mts +1 -1
- package/dist/presets.mjs +1 -1
- package/dist/setup.mjs +2 -2
- package/docs/migrating-from-vitest-react-native.md +2 -2
- package/docs/release-readiness.md +10 -7
- package/docs/versioning.md +1 -1
- package/package.json +10 -9
package/CHANGELOG.md
CHANGED
|
@@ -4,14 +4,20 @@
|
|
|
4
4
|
|
|
5
5
|
### Upgrading from 0.13
|
|
6
6
|
|
|
7
|
-
- **
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
- **
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
7
|
+
- **Node 22.13 or later on Node 22, or Node 24.3 or later.** `engines.node` is
|
|
8
|
+
`>=22.13.0 <23 || >=24.3.0` (it was `>=20.19.0`): Node 20 reached end of life in April 2026, and
|
|
9
|
+
on Node 24.0–24.2 `jest.mock`, `jest.isolateModules` and `jest.resetModules` do not reach modules
|
|
10
|
+
Node loads. `vitest-native doctor` checks the range.
|
|
11
|
+
- **Per-file isolation stays the default.** `hotRuntime` defaults to `false`, as in 0.13.0: under
|
|
12
|
+
the native engine each test file runs in a fresh worker. The hot runtime, which reuses workers
|
|
13
|
+
across files and is faster on most suites, is available with `hotRuntime: 'auto'`. Four known
|
|
14
|
+
differences from per-file isolation are listed in
|
|
15
|
+
[troubleshooting](https://danfry1.github.io/vitest-native/guide/troubleshooting#a-test-passes-on-its-own-but-fails-when-run-with-other-files).
|
|
16
|
+
Release candidates 0.14.0-rc.1 to rc.8 defaulted to `'auto'`, so a project that relied on that
|
|
17
|
+
sets `hotRuntime: 'auto'` to keep it.
|
|
18
|
+
- **How to tell.** When the hot runtime is active, the startup banner names it, as in
|
|
19
|
+
`(platform ios, hot runtime)`. With `'auto'`, it keeps Vitest's per-file isolation whenever the run
|
|
20
|
+
cannot be bounded, or when you set a pool or `test.isolate` yourself, and prints the reason.
|
|
15
21
|
- **Expo path aliases resolve.** In an Expo project on Vite 8, imports through tsconfig `paths` (the
|
|
16
22
|
template's `@/…`) now resolve as Metro resolves them; a `vite-tsconfig-paths` plugin or a hand-written
|
|
17
23
|
alias for them can go.
|
|
@@ -45,9 +51,55 @@
|
|
|
45
51
|
- **Presets of your own are listed by path.** A preset object of a project's own passed to `presets`
|
|
46
52
|
used to shadow its packages with undefined exports; it is now refused at startup. List the module that
|
|
47
53
|
exports it instead: `presets: { './test/presets/my-lib.ts': true }`.
|
|
54
|
+
- **Expo SDK 56–58 projects run real React Native with nothing extra installed.** When
|
|
55
|
+
`@react-native/babel-preset` does not resolve (from SDK 56, `babel-preset-expo` no longer depends on
|
|
56
|
+
it), the native engine compiles with Expo's preset, as Metro does. `reactNative()` used the mock
|
|
57
|
+
engine there before.
|
|
58
|
+
- **Expo's globals are installed before your setup files, and `fetch` stays Node's.** A `fetch` mocked
|
|
59
|
+
in a setup file, an MSW server, nock and undici's `MockAgent` keep working whether or not a test
|
|
60
|
+
imports `expo`. Every test file in an Expo project now sees Expo's `URL`, `structuredClone` and
|
|
61
|
+
`DOMException` polyfills, as under jest-expo.
|
|
62
|
+
- **Expo modules' own native-module mocks are served.** Values that were `undefined` are the mock's
|
|
63
|
+
(`digestStringAsync` resolves `""`), and a member a mock leaves out is `undefined` where the generic
|
|
64
|
+
stub gave a function.
|
|
65
|
+
- **An optional native module that is not installed reads as absent.** `requireOptionalNativeModule`
|
|
66
|
+
returns `null` for a module a package only probes for and no installed package defines, as on a
|
|
67
|
+
device.
|
|
68
|
+
- **Expo modules run as their installed packages.** Under the native engine, the `expo` preset no
|
|
69
|
+
longer replaces `expo-constants`, `expo-status-bar`, `expo-font`, `expo-asset`, `expo-splash-screen`
|
|
70
|
+
and `expo-linking`, so their whole API is the installed SDK's (`hide()`, `setOptions()`,
|
|
71
|
+
`useAssets` …) and their values are jest-expo's: `Constants.expoConfig` is `{}`,
|
|
72
|
+
`Linking.createURL()` needs a scheme mocked into `expo-constants`, and `Font.isLoaded()` is `false`
|
|
73
|
+
until a font loads. The Minor Changes entry lists each value; `presets: { expo: true }` keeps the
|
|
74
|
+
preset while a suite moves off it.
|
|
48
75
|
|
|
49
76
|
### Minor Changes
|
|
50
77
|
|
|
78
|
+
- 7cee4a7: **Breaking:** vitest-native supports Node 22.13 or later on Node 22, and Node 24.3 or later (`engines.node` is `>=22.13.0 <23 || >=24.3.0`; it was `>=20.19.0`). Node 20 reached end of life in April 2026. Node 22.13 is the first Node 22 that both RNTL 14 and the engine's CommonJS entry points (`require(esm)`) support. On Node 24.0–24.2, `jest.mock`, `jest.isolateModules` and `jest.resetModules` do not reach modules Node loads, with either loader. Node 23 is past its end of life. `doctor` checks the whole range. RNTL 12, 13 and 14 stay supported, and CI runs RNTL 12 and 13 on Node 22.13 instead of Node 20.
|
|
79
|
+
|
|
80
|
+
- 191c286: Under the native engine, Expo modules run as their installed packages, answering as they do under jest-expo. The `expo` preset no longer replaces `expo-constants`, `expo-status-bar`, `expo-font`, `expo-asset`, `expo-splash-screen` and `expo-linking` there; their own JavaScript runs, so their whole API is present and current with the installed SDK. `import { hide } from 'expo-splash-screen'`, Expo's call since SDK 52, was `undefined` under the preset (#319), as were `setOptions`, `useAssets`, `getLoadedFonts`, `canOpenURL` and others.
|
|
81
|
+
|
|
82
|
+
Their native modules answer as jest-expo answers them: from a package's own `mocks/`, else from Expo's table of the native modules, which jest-expo ships and vitest-native now carries for each SDK, extracted from jest-expo 57.0.6 and 58.0.12 (`src/native/expo-module-table-<sdk>.mjs`; a weekly check compares each with the newest jest-expo of its SDK, and fails when a new SDK has no table). The installed `expo`'s SDK picks the table. This also gives every other Expo module jest-expo's values: `Device.modelName` is `'mock'`, `Constants.statusBarHeight` is `54`. A constant the installed SDK's table does not list is `undefined`, as under jest-expo; on an SDK with no table of its own, the nearest SDK's table answers the members it lists and such a member keeps the stub's no-op function. On an Expo SDK 58 app, every probe of these six packages matches jest-expo (17 of 17, against 4 with the preset). One difference is deliberate: an asset a test `require`s is registered as Metro registers it, so `Asset.fromModule()` and `Font.loadAsync()` of it load, where jest-expo throws that it is missing from the asset registry.
|
|
83
|
+
|
|
84
|
+
What a suite that relied on the preset sees instead, each as under jest-expo:
|
|
85
|
+
|
|
86
|
+
- `Constants.expoConfig` is `{}` (was `{ name: 'test-app', slug: 'test-app', version: '1.0.0', extra: {} }`), so `expoConfig.name` and `expoConfig.extra` are `undefined`. `Constants.appOwnership` is `null` (was `'standalone'`), `executionEnvironment` is `'mock'` (was `'storeClient'`), and `getWebViewUserAgentAsync()` resolves `undefined`.
|
|
87
|
+
- `Linking.createURL()` and `Linking.parse()` throw for want of a scheme in the Expo manifest (they returned `exp://localhost:19000/…` URLs). A test that needs them mocks `expo-constants` with a scheme through `jest.mock` (the jest-compat layer), which now reaches expo-linking's own import of it, or mocks `expo-linking`; a `vi.mock` of `expo-constants` does not reach it yet (#322).
|
|
88
|
+
- `Font.isLoaded()` is `false` until a font is loaded (was always `true`), and `Asset.fromModule()` of a number that is not a bundled asset throws (it returned a made-up asset). Bundled images and fonts load through the real expo-asset and expo-font.
|
|
89
|
+
- `preventAutoHideAsync()` and `hideAsync()` resolve `undefined` (were `true`).
|
|
90
|
+
|
|
91
|
+
A suite can keep the preset while it moves off it with `reactNative({ presets: { expo: true } })`. The mock engine keeps the preset, whose `expo-splash-screen` now has `hide()` and `setOptions()`.
|
|
92
|
+
|
|
93
|
+
Three engine changes come with it. A module the ESM loader compiles is now loaded through Node's CommonJS loader, so an import and a require share one instance (expo-asset 57's asset registry was a second, empty copy) and a `jest.mock` factory reaches a package's own require of the mocked module. TypeScript under node_modules from a package nothing selected for compiling is compiled rather than refused (an Expo module installed without `expo`). `doctor` and `migrate` describe the new behaviour.
|
|
94
|
+
|
|
95
|
+
- 7b9b795: React Native 0.88 and Expo SDK 58 join the supported matrix
|
|
96
|
+
|
|
97
|
+
The verified range is now 0.81–0.88: the CI matrix gains a 0.88 row (and the Vitest 4 floor's newest-RN cell moves up to it), the workspace pins 0.88, and the published range statements follow. All 85 cross-check probes match on 0.88 and `check-compat` covers every stable export.
|
|
98
|
+
|
|
99
|
+
The packed Expo consumer moves to SDK 58 (React Native 0.88, RNTL 14), and an SDK 57 consumer stays alongside it. The SDK 58 consumer also checks that the presets provide every `expo-linking` and `expo-constants` member expo-router's build uses, and that loading `expo` and `expo-router` leaves Node's timers and `Promise` in place.
|
|
100
|
+
|
|
101
|
+
- 13f79b0: Under the native engine, an Expo module whose package ships a mock of its native module (`mocks/<Name>.ts`, generated by Expo for `expo-crypto`, `expo-file-system`, `expo-clipboard`, `expo-localization` and others) gets that mock as its native module, as under jest-expo. Its functions are `vi.fn`s that return the mock's values and reset between test files, classes keep their prototype, and members the mock leaves out are `undefined`. Before, every native module was a generic stub, so a package that read a value as it loaded failed: importing `expo-file-system/legacy` threw `p.replace is not a function`. Native modules without a package mock keep the generic stub.
|
|
102
|
+
|
|
51
103
|
- f107c6a: A `unistyles` preset for `react-native-unistyles` 3, which resolves styles in native code and could not load in tests. It is auto-detected when the package is installed. It covers everything Unistyles' own Jest mock does (themes from `StyleSheet.configure`, `StyleSheet.create`, `useUnistyles`, `withUnistyles`, `UnistylesRuntime`), and it follows the library's source where that mock does less:
|
|
52
104
|
|
|
53
105
|
- styles resolve as the device parses them: breakpoint values and `mq` keys against the screen, `_web` styles dropped;
|
|
@@ -178,6 +230,22 @@
|
|
|
178
230
|
|
|
179
231
|
### Patch Changes
|
|
180
232
|
|
|
233
|
+
- 1785957: `hotRuntime` stays `false` by default, as in 0.13.0: under the native engine each test file runs in a fresh worker. The hot runtime, which reuses workers across files and is faster on most suites, is available with `hotRuntime: 'auto'`; four known differences from per-file isolation are listed in the troubleshooting guide. Release candidates 0.14.0-rc.1 to rc.8 defaulted to `'auto'`, so a project that relied on that sets `hotRuntime: 'auto'` to keep it.
|
|
234
|
+
|
|
235
|
+
- ff23fde: The hot runtime no longer drops test files from a run. When a test file `jest.mock`ed a module that the per-file reset restores through Node, such as `jest.mock('react-native/Libraries/Utilities/Appearance', () => null)`, the reset for the next file threw before that file was collected. The file then had no result in any reporter, and the JSON report did not show it at all. With one worker, every later file of the run was lost the same way. On react-native-paper this dropped one file per run with four workers and 19 of 52 files with one. The `jest.mock` registrations are now cleared before the React Native state is restored. A reset that fails now fails the file it was for, with the error. A file that never runs because its worker's task broke is now reported as failed by name, and the run fails.
|
|
236
|
+
|
|
237
|
+
- cbade8c: The native engine runs its ESM loader in-thread (`module.registerHooks`) only on Node 22.22.3 and later on Node 22, 24.12 and later on Node 24, and Node 26 on; other Node versions use the threaded loader (`module.register`), as Node 22.13 always has. On the earlier releases that have `registerHooks`, the in-thread hooks broke the engine: expo-router failed to load its navigation elements ("request for 'node:module' is from a module not been linked") through Node 22.22.2 and 24.11, and the hot runtime's module reset did not behave as on other versions. `VITEST_NATIVE_LOADER_THREAD=1` still forces the threaded loader anywhere.
|
|
238
|
+
|
|
239
|
+
- 0c45e87: The native engine no longer reads every `require()` as an `import` on Node 22.15–22.18 and early Node 24 releases (24.3 and 24.4 measured), which 0.14.0's supported range now leaves out. Its in-thread loader hooks tell a `require()` from an `import` by the conditions Node passes them, and on those versions a `require()` reports its conditions as an empty object instead of a list. Every `require()` was read as an `import` and reached the engine's loader, which compiled Babel's own files as Babel loaded them, so every test failed with "Reentrant preset detected". Node 22.19 and 24.6 onwards list them and were unaffected, and so was Node 22.13, which uses the threaded loader.
|
|
240
|
+
|
|
241
|
+
- ce3be7a: Under the native engine, a test that imports `expo` or `expo-router` from Expo SDK 58 (React Native 0.88) no longer hangs. Expo's runtime requires `react-native/setup-env`, which replaced Node's timers with React Native's native-driven ones, so the first awaited timer never fired. That entry is now skipped, as `InitializeCore` already was. The `expo-linking` preset also adds `getLinkingURL`, `openURL` and `unwrapDevLaunchURL`, which expo-router 58 calls while rendering a route tree.
|
|
242
|
+
|
|
243
|
+
- 2ede5df: In an Expo project, the native engine installs Expo's runtime globals (`URL`, `structuredClone`, `DOMException` and the rest) before the project's setup files run, in every test file, as jest-expo does, instead of at a test's first `expo` import. A file that never imports Expo now sees Expo's polyfills for those globals, as under jest-expo. A `fetch` mocked in a setup file is no longer replaced once a test imports Expo. Global `fetch` stays Node's, so MSW, nock and undici's `MockAgent` keep intercepting, where Expo's native-driven `fetch` failed with `request.start is not a function`. Node's `FormData` also keeps working after Expo loads: Expo's patch for React Native's FormData made `append()` and `set()` throw.
|
|
244
|
+
|
|
245
|
+
- 2ac4de3: The native engine runs in an Expo project without `@react-native/babel-preset`. From SDK 56, `babel-preset-expo` carries React Native's Babel plugins itself and no longer depends on that preset, so a project created from the SDK 56, 57 or 58 template has none installed, and `reactNative()` fell back to the mock engine, where Expo modules failed to load. When `@react-native/babel-preset` does not resolve, the engine now compiles with Expo's preset (`expo/internal/babel-preset`), which Expo's Metro and jest-expo use in a project without a Babel config. A project that has `@react-native/babel-preset` keeps using it.
|
|
246
|
+
|
|
247
|
+
- 306b27a: Under the native engine, `expo-image` can be imported. `globalThis.expo.modules` answered every native module name, so a package probing for an optional module with `requireOptionalNativeModule` called into a stub instead of taking its fallback: expo-image found expo-observe's `ExpoObserve` and failed with `Cannot read properties of undefined (reading 'expo-image')`. A module that an installed package only probes for, and that no installed or local Expo module defines in its native sources, now reads as absent, as on a device. Every other module stays present, so a module that exists cannot read as missing. The scan is cached until the install changes.
|
|
248
|
+
|
|
181
249
|
- 61ae436: Preset mocks keep their behaviour through `vi.resetAllMocks()` and `mockReset: true`. A gesture-handler gesture built before a reset, such as `Gesture.Pan()` at module scope, keeps chaining. In the mock engine, `Platform.select()` follows `Platform.OS` after a reset, so a setup file's `setPlatform('android')` is no longer undone for `select()` while `Platform.OS` stays `"android"`. `Platform.select()` also picks by key presence, as React Native does, so an explicit `ios: undefined` selects `undefined`.
|
|
182
250
|
|
|
183
251
|
- de438fc: The reanimated preset's animation builders keep chaining after `vi.resetAllMocks()` or `mockReset: true`, so `LinearTransition.springify().damping(20)` and `SharedTransition.duration(300).custom(...)` no longer throw.
|
package/README.md
CHANGED
|
@@ -4,8 +4,8 @@
|
|
|
4
4
|
|
|
5
5
|
Run your React Native tests under Vitest, against **real React Native** — the same JavaScript that ships in your app, with only the native-module boundary mocked. That is the default and the point of the project. A lightweight pure-JS mock engine is available as an opt-in for fast, RN-free unit tests.
|
|
6
6
|
|
|
7
|
-
> **Beta.** The release-supported native engine is validated across React Native 0.81–0.
|
|
8
|
-
> Vite 6–8, Vitest 4–5, RNTL 12–14, bare apps, Expo SDK 57 (including expo-router's own testing
|
|
7
|
+
> **Beta.** The release-supported native engine is validated across React Native 0.81–0.88,
|
|
8
|
+
> Vite 6–8, Vitest 4–5, RNTL 12–14, bare apps, Expo SDK 58 and 57 (including expo-router's own testing
|
|
9
9
|
> library), and hoisted monorepos. The hot
|
|
10
10
|
> runtime (on by default where it can be bounded) is marked experimental because it uses Vitest's
|
|
11
11
|
> experimental custom-pool APIs.
|
|
@@ -72,7 +72,9 @@ pnpm add -D vitest-native
|
|
|
72
72
|
```
|
|
73
73
|
|
|
74
74
|
A real React Native project already provides what the native engine needs —
|
|
75
|
-
`react-native`, `@react-native/babel-preset`, and `@babel/core`.
|
|
75
|
+
`react-native`, `@react-native/babel-preset`, and `@babel/core`. From Expo SDK 56,
|
|
76
|
+
`babel-preset-expo` no longer depends on `@react-native/babel-preset`, and the engine compiles
|
|
77
|
+
with Expo's own preset instead, as Metro does. Add
|
|
76
78
|
`@testing-library/react-native` if you don't have it yet (the examples below use it):
|
|
77
79
|
|
|
78
80
|
```bash
|
|
@@ -148,7 +150,7 @@ export default defineConfig({
|
|
|
148
150
|
diagnostics: false, // Enable verbose logging
|
|
149
151
|
assetExts: [".lottie"], // Additional asset extensions to stub
|
|
150
152
|
transform: [], // Extra native-engine packages to Flow/TS transform
|
|
151
|
-
hotRuntime:
|
|
153
|
+
hotRuntime: false, // false (default) | 'auto' | true | HotRuntimeOptions
|
|
152
154
|
}),
|
|
153
155
|
],
|
|
154
156
|
});
|
|
@@ -163,7 +165,7 @@ export default defineConfig({
|
|
|
163
165
|
| `diagnostics` | `boolean` | `false` | Log plugin activity to the console for debugging. |
|
|
164
166
|
| `assetExts` | `string[]` | `[]` | Additional file extensions to stub as asset imports (beyond the built-in set). |
|
|
165
167
|
| `transform` | `string[]` | `[]` | **`engine: 'native'` only.** Extra `node_modules` packages whose source the native engine should transform (Flow/TS/JSX stripped) as it loads them — for third-party RN libraries that ship untranspiled source (e.g. `react-native-reanimated`). Analogous to Jest's `transformIgnorePatterns` allowlist. |
|
|
166
|
-
| `hotRuntime` | `boolean \| 'auto' \| HotRuntimeOptions` | `
|
|
168
|
+
| `hotRuntime` | `boolean \| 'auto' \| HotRuntimeOptions` | `false` | `engine: 'native'` only. Reuse workers while keeping app/test modules isolated per file. `false` (the default) gives each file a fresh worker; `'auto'` opts in where the run can be bounded and recycled, and keeps per-file isolation otherwise. See [Hot runtime](#hot-runtime). |
|
|
167
169
|
|
|
168
170
|
### Experimental Metro configuration
|
|
169
171
|
|
|
@@ -202,13 +204,13 @@ Choose how React Native is provided to your tests:
|
|
|
202
204
|
requires a device. Jest's `react-native` preset replaces many of these modules with
|
|
203
205
|
stubs, so the native engine exercises behavior Jest's mocks skip (see [Fidelity](#fidelity)
|
|
204
206
|
below). Best for components, integration, RNTL, virtualized lists, and anywhere a false
|
|
205
|
-
pass is costly. Requires `@react-native/babel-preset`
|
|
206
|
-
default in React Native apps
|
|
207
|
+
pass is costly. Requires `@react-native/babel-preset` (or, from Expo SDK 56, Expo's
|
|
208
|
+
preset) and `@babel/core`, present by default in React Native and Expo apps.
|
|
207
209
|
- `'mock'` — a lightweight, pure-JS reimplementation of React Native with **zero extra
|
|
208
210
|
dependencies**. Best for pure-logic/unit tests, maximum determinism, or when you can't
|
|
209
211
|
add the babel deps. Like Jest's preset, it is a simplification — see [Fidelity](#fidelity).
|
|
210
|
-
- `'auto'` _(default)_ — picks automatically, and **resolves to `'native'`** whenever
|
|
211
|
-
|
|
212
|
+
- `'auto'` _(default)_ — picks automatically, and **resolves to `'native'`** whenever a React
|
|
213
|
+
Native Babel preset and `@babel/core` are present (i.e. in any real RN or Expo app). It
|
|
212
214
|
falls back to `'mock'` only when those deps are absent, printing one line to explain why.
|
|
213
215
|
So `reactNative()` with no options runs real React Native. Set `engine: 'mock'` to opt out.
|
|
214
216
|
|
|
@@ -240,9 +242,11 @@ the cross-check/fidelity harnesses in the repository's `bench/` directory.
|
|
|
240
242
|
|
|
241
243
|
#### Hot runtime
|
|
242
244
|
|
|
243
|
-
Vitest's default isolation gives each test file a fresh worker, so React Native
|
|
244
|
-
|
|
245
|
-
modules per file whenever that can be done safely
|
|
245
|
+
Vitest's default isolation gives each test file a fresh worker, so React Native reloads for every
|
|
246
|
+
file; that is the default (`hotRuntime: false`), as in 0.13.0. With `hotRuntime: 'auto'` the native
|
|
247
|
+
engine instead reuses workers and resets modules per file whenever that can be done safely. It has
|
|
248
|
+
known differences from per-file isolation, listed under "A test passes on its own but fails when
|
|
249
|
+
run with other files" in the troubleshooting guide.
|
|
246
250
|
|
|
247
251
|
`'auto'` selects persistent workers when the current scheduler provides recyclable task boundaries,
|
|
248
252
|
the host/container memory plan admits at least two workers, no other pool was explicitly
|
|
@@ -257,8 +261,8 @@ jest-compat surface — `jest.mock` in its forms, runtime mocks, spies, timers,
|
|
|
257
261
|
Library cleanup — has its own cross-file isolation gate under the hot runtime. The decision runs
|
|
258
262
|
after other Vite config hooks, so a pool contributed by a later plugin is included rather than
|
|
259
263
|
producing a mixed runtime. When it falls
|
|
260
|
-
back to per-file isolation it
|
|
261
|
-
explicitly
|
|
264
|
+
back to per-file isolation it prints the reason. Per-file isolation, the default, can also be set
|
|
265
|
+
explicitly:
|
|
262
266
|
|
|
263
267
|
```ts
|
|
264
268
|
reactNative({
|
|
@@ -564,10 +568,10 @@ renders through real React Native).
|
|
|
564
568
|
|
|
565
569
|
### Expo
|
|
566
570
|
|
|
567
|
-
Expo apps need no Expo-specific package.
|
|
568
|
-
|
|
569
|
-
`expo-
|
|
570
|
-
expo
|
|
571
|
+
Expo apps need no Expo-specific package. Under the native engine every Expo package's own
|
|
572
|
+
JavaScript runs for real — `expo` itself, expo-router, React Navigation and Expo modules such as
|
|
573
|
+
`expo-constants` or `expo-splash-screen` — and only their native modules are mocked, the way
|
|
574
|
+
`jest-expo` runs them. (The mock engine replaces the common Expo modules with the `expo` preset.)
|
|
571
575
|
|
|
572
576
|
- **Coming from jest-expo:** `npx vitest-native migrate --write` translates the `jest-expo`
|
|
573
577
|
presets (`jest-expo/android` → `platform: 'android'`) and, because jest-expo does not mock React
|
|
@@ -575,14 +579,17 @@ expo-router and React Navigation — runs for real under the native engine.
|
|
|
575
579
|
- **expo-router screens:** `expo-router/testing-library` (`renderRouter`, `testRouter`,
|
|
576
580
|
`toHavePathname`) runs as written with the jest-compat layer. From SDK 57 expo-router bundles its
|
|
577
581
|
own React Navigation; before SDK 57, also set `presets: { navigation: false }`.
|
|
578
|
-
- **Expo modules
|
|
579
|
-
|
|
582
|
+
- **Expo modules** run their real JavaScript, and their native modules answer as under
|
|
583
|
+
jest-expo: from the package's own `mocks/<Name>.ts` where it ships one, else from Expo's table
|
|
584
|
+
of the native modules (`Device.modelName` is `'mock'`). An optional native module a package
|
|
585
|
+
probes for, and that no installed package defines, is absent, as on a device.
|
|
580
586
|
- **Expo SDK trails React Native.** Pin your `react-native` to the version your Expo SDK supports
|
|
581
587
|
(SDK 54 and later are within this plugin's validated range), not the newest RN release.
|
|
582
588
|
|
|
583
|
-
|
|
584
|
-
auto-detection and rendering, expo-router's testing library against file-based `app/`
|
|
585
|
-
|
|
589
|
+
Packed Expo SDK 58 and SDK 57 apps are installed from the release tarball and tested in CI: Expo
|
|
590
|
+
module auto-detection and rendering, and expo-router's testing library against file-based `app/`
|
|
591
|
+
routes. The SDK 58 app also runs those routes under the configuration `migrate` generates from a
|
|
592
|
+
jest-expo setup. See the
|
|
586
593
|
[Expo guide](https://danfry1.github.io/vitest-native/guide/expo).
|
|
587
594
|
|
|
588
595
|
---
|
|
@@ -645,7 +652,8 @@ Upgrade npm (`npm install --global npm@11`), or use pnpm, Yarn or Bun.
|
|
|
645
652
|
|
|
646
653
|
**`@react-native/babel-preset not found — using the mock engine`**
|
|
647
654
|
You asked for the default (`auto`) engine but the native babel deps aren't installed, so it
|
|
648
|
-
fell back to the mock engine.
|
|
655
|
+
fell back to the mock engine. An Expo project from SDK 56 needs nothing extra: the engine uses
|
|
656
|
+
Expo's preset, and `expo` brings `@babel/core`. Otherwise, to run real React Native, install them:
|
|
649
657
|
|
|
650
658
|
```bash
|
|
651
659
|
npm i -D @react-native/babel-preset @babel/core
|
|
@@ -965,15 +973,15 @@ that API.
|
|
|
965
973
|
|
|
966
974
|
Every release must pass:
|
|
967
975
|
|
|
968
|
-
- Linux on Node
|
|
976
|
+
- Linux on Node 22.13 (with RNTL 12, 13 and 14) and 24, plus macOS and Windows on Node 22.13.
|
|
969
977
|
- The mock, native iOS, native Android, hot-runtime, isolation, and 100-file soak suites.
|
|
970
|
-
- React Native 0.81–0.
|
|
971
|
-
on 0.81 and 0.
|
|
978
|
+
- React Native 0.81–0.88 against both locked and newest-supported Vitest, plus the Vitest 4 floor
|
|
979
|
+
on 0.81 and 0.88.
|
|
972
980
|
- Vitest's own behaviour under the defaults, on Vitest 5 and the Vitest 4 floor: config and CLI
|
|
973
981
|
flags, projects, watch mode, the jsdom and happy-dom environments, `--typecheck`, `vitest bench`,
|
|
974
982
|
and the HTML reporter.
|
|
975
|
-
- Packed consumers: bare RN 0.83/RNTL 12, a Jest-migration project, Expo SDK
|
|
976
|
-
expo-router and a `migrate`-generated jest-expo config), a mock-engine RNTL 14 project, npm- and
|
|
983
|
+
- Packed consumers: bare RN 0.83/RNTL 12, a Jest-migration project, Expo SDK 58/RNTL 14 (with
|
|
984
|
+
expo-router and a `migrate`-generated jest-expo config), Expo SDK 57/RNTL 13 (with expo-router), a mock-engine RNTL 14 project, npm- and
|
|
977
985
|
pnpm-workspace monorepos on Vite 8, and an RN 0.86 Android project.
|
|
978
986
|
- Packed V8 and Istanbul coverage maps/counts matching default isolation exactly under hot workers.
|
|
979
987
|
- Mock-versus-real-RN behavioral cross-checks, example-app tests, typecheck, lint, formatting, and
|
|
@@ -995,14 +1003,15 @@ see [versioning and stability](docs/versioning.md).
|
|
|
995
1003
|
| `react` | >= 18; use RN's matching React version |
|
|
996
1004
|
| `vite` | ^6.4.2, ^7.3.2, or ^8.0.5 |
|
|
997
1005
|
| `vitest` | 4.x or 5.x |
|
|
998
|
-
| `node` |
|
|
999
|
-
| `react-native` (native engine) | 0.81–0.
|
|
1006
|
+
| `node` | 22.13+ on Node 22, or 24.3+ |
|
|
1007
|
+
| `react-native` (native engine) | 0.81–0.88 validated |
|
|
1000
1008
|
| `@react-native/babel-preset` (native engine) | Match the installed React Native minor |
|
|
1001
1009
|
| `@testing-library/react-native` (optional) | 12.x, 13.x, or 14.x |
|
|
1002
1010
|
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1011
|
+
Node 20 reached end of life in April 2026. Node 22.13 is the first Node 22 that both RNTL 14 and the
|
|
1012
|
+
engine's CommonJS entry points (`require(esm)`) support. On Node 24.0–24.2, `jest.mock`,
|
|
1013
|
+
`jest.isolateModules` and `jest.resetModules` do not reach modules Node loads, with either loader.
|
|
1014
|
+
Node 23 is past its end of life. RNTL 14 uses async rendering APIs.
|
|
1006
1015
|
|
|
1007
1016
|
---
|
|
1008
1017
|
|
package/dist/cli.cjs
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
3
|
const require_rolldown_runtime = require("./rolldown-runtime-C0BPl7ul.cjs");
|
|
4
|
-
const require_ecosystem = require("./ecosystem-
|
|
5
|
-
const require_preset_map = require("./preset-map-
|
|
4
|
+
const require_ecosystem = require("./ecosystem-MFwkbnaC.cjs");
|
|
5
|
+
const require_preset_map = require("./preset-map-jSFsNy1Q.cjs");
|
|
6
6
|
const require_memory = require("./memory-6EPHrJA1.cjs");
|
|
7
7
|
let node_fs = require("node:fs");
|
|
8
8
|
node_fs = require_rolldown_runtime.__toESM(node_fs, 1);
|
|
@@ -65,12 +65,13 @@ function installedTestsItself(root, pkg) {
|
|
|
65
65
|
/**
|
|
66
66
|
* The presets a run in this project enables, decided as the plugin decides it: a
|
|
67
67
|
* preset is active when one of its packages is installed and does not test itself,
|
|
68
|
-
* and the user has not switched it
|
|
68
|
+
* the engine applies it (autoDetectedPresetApplies), and the user has not switched it
|
|
69
|
+
* off.
|
|
69
70
|
*/
|
|
70
|
-
function activePresets(root, disabled = []) {
|
|
71
|
+
function activePresets(root, disabled = [], engine = "native") {
|
|
71
72
|
const active = /* @__PURE__ */ new Set();
|
|
72
73
|
for (const [pkg, preset] of Object.entries(require_preset_map.AUTO_DETECT_PRESETS)) {
|
|
73
|
-
if (disabled.includes(preset)) continue;
|
|
74
|
+
if (disabled.includes(preset) || !require_preset_map.autoDetectedPresetApplies(preset, engine)) continue;
|
|
74
75
|
if (installedManifest(root, pkg) && !installedTestsItself(root, pkg)) active.add(preset);
|
|
75
76
|
}
|
|
76
77
|
return [...active];
|
|
@@ -349,20 +350,49 @@ function packageVersion(root, name) {
|
|
|
349
350
|
}
|
|
350
351
|
}
|
|
351
352
|
/**
|
|
352
|
-
* The supported Node
|
|
353
|
-
*
|
|
354
|
-
*
|
|
353
|
+
* The supported Node versions, as this package's own `engines.node` states them.
|
|
354
|
+
* Single source: the manifest is what a package manager enforces at install time, so a
|
|
355
|
+
* diagnostic must not carry its own copy of the range.
|
|
355
356
|
*/
|
|
356
|
-
function
|
|
357
|
-
const fallback =
|
|
357
|
+
function nodeRange() {
|
|
358
|
+
const fallback = ">=22.13.0 <23 || >=24.3.0";
|
|
358
359
|
try {
|
|
359
|
-
|
|
360
|
-
const match = /(\d+)\.(\d+)/.exec(manifest.engines?.node ?? "");
|
|
361
|
-
return match ? [Number(match[1]), Number(match[2])] : fallback;
|
|
360
|
+
return JSON.parse(node_fs.default.readFileSync(new URL("../../package.json", require("url").pathToFileURL(__filename).href), "utf8")).engines?.node?.trim() || fallback;
|
|
362
361
|
} catch {
|
|
363
362
|
return fallback;
|
|
364
363
|
}
|
|
365
364
|
}
|
|
365
|
+
const versionParts = (version) => {
|
|
366
|
+
const [major = 0, minor = 0, patch = 0] = version.replace(/^v/, "").split(/[.-]/).map((part) => Number.parseInt(part, 10) || 0);
|
|
367
|
+
return [
|
|
368
|
+
major,
|
|
369
|
+
minor,
|
|
370
|
+
patch
|
|
371
|
+
];
|
|
372
|
+
};
|
|
373
|
+
const compareVersions = (a, b) => {
|
|
374
|
+
const [x, y] = [versionParts(a), versionParts(b)];
|
|
375
|
+
return x[0] - y[0] || x[1] - y[1] || x[2] - y[2];
|
|
376
|
+
};
|
|
377
|
+
/**
|
|
378
|
+
* Whether `version` is in `range`: `||`-separated sets of space-separated comparators
|
|
379
|
+
* (`>=`, `>`, `<=`, `<`, `=`), the forms `engines.node` uses. A version missing parts
|
|
380
|
+
* reads them as 0 (`<23` is `<23.0.0`).
|
|
381
|
+
*/
|
|
382
|
+
function satisfiesNodeRange(version, range) {
|
|
383
|
+
return range.split("||").some((set) => set.trim().split(/\s+/).filter(Boolean).every((comparator) => {
|
|
384
|
+
const match = /^(>=|<=|>|<|=)?\s*v?(\d[\w.-]*)$/.exec(comparator);
|
|
385
|
+
if (!match) return false;
|
|
386
|
+
const order = compareVersions(version, match[2]);
|
|
387
|
+
switch (match[1] ?? "=") {
|
|
388
|
+
case ">=": return order >= 0;
|
|
389
|
+
case ">": return order > 0;
|
|
390
|
+
case "<=": return order <= 0;
|
|
391
|
+
case "<": return order < 0;
|
|
392
|
+
default: return order === 0;
|
|
393
|
+
}
|
|
394
|
+
}));
|
|
395
|
+
}
|
|
366
396
|
/**
|
|
367
397
|
* In Vitest's own precedence order: a `vitest.config.*` wins, and `vite.config.*`
|
|
368
398
|
* is used when there is none.
|
|
@@ -506,11 +536,9 @@ function runDoctor(root, nodeVersion = process.versions.node) {
|
|
|
506
536
|
const rootFor = (name) => resolvesHere(name) || configRoot === root ? root : configRoot;
|
|
507
537
|
lines.push(`vitest-native doctor — ${root}`);
|
|
508
538
|
lines.push("", "Runtime");
|
|
509
|
-
const
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
if (nodeMajorMinor[0] > floorMajor || nodeMajorMinor[0] === floorMajor && nodeMajorMinor[1] >= floorMinor) pass(`Node ${nodeVersion} (floor: ${floorText})`);
|
|
513
|
-
else fail(`Node ${nodeVersion} — vitest-native requires Node >= ${floorText}.`);
|
|
539
|
+
const range = nodeRange();
|
|
540
|
+
if (satisfiesNodeRange(nodeVersion, range)) pass(`Node ${nodeVersion} (supported: ${range})`);
|
|
541
|
+
else fail(`Node ${nodeVersion} — vitest-native supports Node ${range}.`);
|
|
514
542
|
lines.push("", "Peer dependencies");
|
|
515
543
|
for (const { name, minimum, maximumMajor, minimumByMajor, optional } of require_ecosystem.PEER_REQUIREMENTS) {
|
|
516
544
|
if (optional) continue;
|
|
@@ -525,12 +553,14 @@ function runDoctor(root, nodeVersion = process.versions.node) {
|
|
|
525
553
|
lines.push("", "Engine");
|
|
526
554
|
const rnVersion = packageVersion(rootFor("react-native"), "react-native");
|
|
527
555
|
const decision = require_ecosystem.detectEngine("auto", rootFor("@react-native/babel-preset"));
|
|
528
|
-
|
|
529
|
-
|
|
556
|
+
const transformPreset = require_ecosystem.resolveTransformPreset(rootFor("@react-native/babel-preset"));
|
|
557
|
+
const presetLabel = transformPreset ? `${transformPreset.name} ${transformPreset.version}` : "a React Native Babel preset";
|
|
558
|
+
if (decision.engine === "native") pass(`engine 'auto' resolves to NATIVE — real React Native${rnVersion ? ` ${rnVersion}` : ""} with ${presetLabel} + @babel/core present.`);
|
|
559
|
+
else if (rnVersion) warn(`engine 'auto' resolves to MOCK: react-native ${rnVersion} is installed but no React Native Babel preset (@react-native/babel-preset, or Expo's from SDK 56) and/or @babel/core resolve. Install both as devDependencies to run the real-RN native engine.`);
|
|
530
560
|
else warn("engine 'auto' resolves to MOCK: react-native is not installed. That is fine for pure-logic suites; install react-native (+ its babel preset) for the native engine.");
|
|
531
561
|
if (decision.engine === "native") {
|
|
532
562
|
const inferredRoot = configRoot;
|
|
533
|
-
const inferredEcosystem = require_ecosystem.detectEcosystemPackages([.../* @__PURE__ */ new Set([root, configRoot])], [], root === configRoot ? [] : [root], [], activePresets(root));
|
|
563
|
+
const inferredEcosystem = require_ecosystem.detectEcosystemPackages([.../* @__PURE__ */ new Set([root, configRoot])], [], root === configRoot ? [] : [root], [], activePresets(root, [], decision.engine));
|
|
534
564
|
const inferredOwnership = require_ecosystem.createNativeOwnershipPolicy({
|
|
535
565
|
projectRoot: inferredRoot,
|
|
536
566
|
ecosystemPackages: inferredEcosystem,
|
|
@@ -556,28 +586,31 @@ function runDoctor(root, nodeVersion = process.versions.node) {
|
|
|
556
586
|
const rntlReq = require_ecosystem.PEER_REQUIREMENTS.find((r) => r.name === "@testing-library/react-native");
|
|
557
587
|
const rntlError = rntlReq && require_ecosystem.validatePeerDependency(rntlReq.name, rntlReq.minimum, root, rntlReq.maximumMajor, rntlReq.minimumByMajor);
|
|
558
588
|
if (rntlError) warn(rntlError);
|
|
559
|
-
else if (rntlMajor >= 14 && (
|
|
589
|
+
else if (rntlMajor >= 14 && !satisfiesNodeRange(nodeVersion, ">=22.13.0")) fail(`@testing-library/react-native ${rntl} requires Node >= 22.13, but this is Node ${nodeVersion}. Upgrade Node or pin @testing-library/react-native@13.`);
|
|
560
590
|
else if (rntlMajor >= 14 && !packageVersion(rootFor("test-renderer"), "test-renderer")) fail(`@testing-library/react-native ${rntl} requires the 'test-renderer' package, which is not installed. Every render() will fail with "Cannot find module 'test-renderer'". Install it:\n\n npm install -D test-renderer\n`);
|
|
561
591
|
else pass(`@testing-library/react-native ${rntl}${rntlMajor >= 14 ? " (14 is async: await render/fireEvent)" : ""}`);
|
|
562
592
|
}
|
|
563
593
|
lines.push("", "Auto-detected presets");
|
|
564
594
|
const detected = [];
|
|
595
|
+
let installedAny = false;
|
|
565
596
|
for (const [pkg, preset] of Object.entries(require_preset_map.AUTO_DETECT_PRESETS)) {
|
|
566
597
|
if (!installedManifest(root, pkg)) continue;
|
|
598
|
+
installedAny = true;
|
|
567
599
|
if (installedTestsItself(root, pkg)) lines.push(` · ${pkg} ${installedMajor(root, pkg)} runs its own test mode under Vitest, so no preset replaces it`);
|
|
600
|
+
else if (!require_preset_map.autoDetectedPresetApplies(preset, decision.engine)) lines.push(` · ${pkg} runs as itself under the native engine, on its native-module mocks; the ${preset} preset applies under the mock engine or with \`presets: { ${preset}: true }\``);
|
|
568
601
|
else detected.push(`${pkg} → ${preset}`);
|
|
569
602
|
}
|
|
570
603
|
if (detected.length) for (const d of detected) pass(d);
|
|
571
|
-
else lines.push(" (none — no preset-covered packages installed)");
|
|
604
|
+
else if (!installedAny) lines.push(" (none — no preset-covered packages installed)");
|
|
572
605
|
const expo = packageVersion(rootFor("expo"), "expo");
|
|
573
606
|
if (expo) {
|
|
574
607
|
lines.push("", "Expo");
|
|
575
|
-
pass(`expo ${expo} detected.
|
|
608
|
+
pass((decision.engine === "native" ? `expo ${expo} detected. Under the native engine Expo modules run their real JavaScript on native-module mocks, as under jest-expo (unless the config sets \`engine: 'mock'\` or \`presets: { expo: true }\`, where the expo preset shadows ${require_preset_map.PRESET_MODULES.expo.join(", ")}). ` : `expo ${expo} detected. Under the mock engine the expo preset shadows ${require_preset_map.PRESET_MODULES.expo.join(", ")}; other Expo modules load their real JavaScript. `) + `Coming from jest-expo, run \`vitest-native migrate\`. See https://danfry1.github.io/vitest-native/guide/expo`);
|
|
576
609
|
}
|
|
577
610
|
const babel = readBabelConfig(root);
|
|
578
611
|
if (babel.source) {
|
|
579
612
|
lines.push("", "Babel");
|
|
580
|
-
const classified = classifyBabelPlugins(babel, root, activePresets(root));
|
|
613
|
+
const classified = classifyBabelPlugins(babel, root, activePresets(root, [], decision.engine));
|
|
581
614
|
const required = classified.filter((p) => p.verdict === "required");
|
|
582
615
|
for (const p of classified) if (p.verdict === "required") warn(`${p.reason} Required: ${babelRecipe(viteMajor(rootFor("vite")), required)}.`);
|
|
583
616
|
else if (p.verdict === "alias") warn(`${p.reason} \`vitest-native migrate\` writes them; otherwise add them to resolve.alias.`);
|
|
@@ -1409,11 +1442,13 @@ function list(items) {
|
|
|
1409
1442
|
return items.length <= 1 ? items[0] ?? "" : `${items.slice(0, -1).join(", ")} and ${items[items.length - 1]}`;
|
|
1410
1443
|
}
|
|
1411
1444
|
/**
|
|
1412
|
-
*
|
|
1413
|
-
*
|
|
1445
|
+
* How Expo modules run after migrating. The generated config uses the native engine,
|
|
1446
|
+
* where Expo modules run their own JavaScript on native-module mocks, as jest-expo
|
|
1447
|
+
* runs them; the expo preset applies to the mock engine only (preset-map's
|
|
1448
|
+
* NATIVE_ENGINE_RUNS_PACKAGES).
|
|
1414
1449
|
*/
|
|
1415
1450
|
function expoPresetCoverage() {
|
|
1416
|
-
return
|
|
1451
|
+
return "under the native engine, which the suggested config resolves to wherever React Native's Babel toolchain is installed, Expo modules run their own JavaScript on native-module mocks, as jest-expo runs them: each package's own mocks/ where it ships one, else jest-expo's table of the native modules; check tests that mock an Expo module's native side by hand";
|
|
1417
1452
|
}
|
|
1418
1453
|
/** Escape a literal for a JavaScript regex literal (including `/`). */
|
|
1419
1454
|
function regexLiteral(literal) {
|