vitest-native 0.14.0-rc.8 → 0.14.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/README.md +91 -72
- package/dist/cli.d.mts +1 -3
- package/dist/cli.mjs +215 -76
- package/dist/context.d.mts +45 -0
- package/dist/context.mjs +243 -0
- package/dist/errors.d.mts +3 -0
- package/dist/helpers.cjs +53 -4
- package/dist/helpers.d.cts +1 -3
- package/dist/helpers.d.mts +1 -3
- package/dist/helpers.mjs +2 -3
- package/dist/host-5o48Ujzs.mjs +939 -0
- package/dist/{index-BSyUeoga.d.mts → index-DqU4YO3D.d.mts} +32 -53
- package/dist/index.d.mts +1 -3
- package/dist/index.mjs +464 -596
- package/dist/jest-compat/error-equality.mjs +127 -0
- package/dist/jest-compat/jest-object.mjs +149 -4
- package/dist/jest-compat/node-registry.mjs +233 -58
- package/dist/jest-compat/setup.mjs +34 -4
- package/dist/jest-compat.cjs +227 -52
- package/dist/jest-compat.d.cts +5 -6
- package/dist/jest-compat.d.mts +5 -6
- package/dist/jest-compat.mjs +204 -52
- package/dist/matchers.cjs +1 -2
- package/dist/matchers.d.cts +0 -2
- package/dist/matchers.d.mts +0 -2
- package/dist/matchers.mjs +1 -2
- package/dist/{memory-FYbP0_gg.mjs → memory-Couw0Esx.mjs} +31 -6
- package/dist/native/assets.d.mts +2 -0
- package/dist/native/assets.mjs +34 -0
- package/dist/native/babel-toolchain.mjs +190 -0
- package/dist/native/babel-worker.mjs +47 -0
- package/dist/native/boundary.mjs +23 -8
- package/dist/native/compile-cache.mjs +21 -9
- package/dist/native/coverage-v8.mjs +287 -0
- package/dist/native/esm-interop.mjs +216 -0
- package/dist/native/expo-native-modules.mjs +7 -1
- package/dist/native/globals.mjs +104 -6
- package/dist/native/hooks.mjs +271 -60
- package/dist/native/loader.mjs +409 -20
- package/dist/native/match.d.mts +24 -2
- package/dist/native/match.mjs +117 -12
- package/dist/native/metro-profile-compiler.mjs +2 -31
- package/dist/native/module-reset.mjs +37 -5
- package/dist/native/native-modules.d.mts +2 -3
- package/dist/native/native-modules.mjs +22 -21
- package/dist/native/ownership.d.mts +10 -0
- package/dist/native/ownership.mjs +96 -9
- package/dist/native/registry-compiler.mjs +6 -0
- package/dist/native/registry.mjs +138 -119
- package/dist/native/resident-health.mjs +133 -0
- package/dist/native/resolve.d.mts +6 -0
- package/dist/native/resolve.mjs +100 -9
- package/dist/native/rntl-hooks.mjs +157 -6
- package/dist/native/rntl-text-host.mjs +64 -0
- package/dist/native/runner.mjs +106 -1
- package/dist/native/setup.mjs +105 -77
- package/dist/native/state-manifest.mjs +14 -8
- package/dist/native/transform.d.mts +2 -0
- package/dist/native/transform.mjs +476 -59
- package/dist/native/worker.mjs +151 -46
- package/dist/{pool-DjpOjOf3.mjs → pool-CFSpNfyw.mjs} +37 -11
- package/dist/{preset-map-BlBriTA0.mjs → preset-map-CogjYmSw.mjs} +4 -19
- package/dist/preset-modules.mjs +2 -11
- package/dist/{presets--zrEWQC2.mjs → presets-CXDyg51l.mjs} +65 -82
- package/dist/presets.d.mts +1 -1
- package/dist/presets.mjs +1 -1
- package/dist/report-error.d.mts +20 -0
- package/dist/report-error.mjs +145 -0
- package/dist/rntl-support.d.mts +12 -0
- package/dist/rntl-support.mjs +189 -0
- package/dist/{rolldown-runtime-BhDjJH2R.mjs → rolldown-runtime-D70C1uOS.mjs} +1 -2
- package/dist/serializer.cjs +1 -2
- package/dist/serializer.d.cts +1 -3
- package/dist/serializer.d.mts +1 -3
- package/dist/serializer.mjs +1 -2
- package/dist/setup.mjs +95 -156
- package/dist/{worker-vitest-BGPo0ek6.mjs → worker-vitest-CILPFeRX.mjs} +2 -3
- package/docs/migrating-from-jest.md +76 -12
- package/docs/migrating-from-vitest-react-native.md +1 -1
- package/docs/release-readiness.md +6 -5
- package/docs/versioning.md +1 -1
- package/package.json +121 -103
- package/CHANGELOG.md +0 -2475
- package/dist/cli.cjs +0 -1924
- package/dist/cli.d.cts +0 -3
- package/dist/ecosystem-D6e1OVOg.mjs +0 -1019
- package/dist/ecosystem-MFwkbnaC.cjs +0 -1099
- package/dist/errors-B3lJK46O.cjs +0 -75
- package/dist/errors-CxoBUfVJ.mjs +0 -64
- package/dist/index-bZ7AHqLc.d.cts +0 -482
- package/dist/memory-6EPHrJA1.cjs +0 -144
- package/dist/pool-B4yesGhI.cjs +0 -121
- package/dist/preset-map-jSFsNy1Q.cjs +0 -241
- package/dist/preset-modules-BoLkaeEN.cjs +0 -53
- package/dist/preset-modules-CG8-G82P.mjs +0 -36
- package/dist/presets-9f83H0WW.cjs +0 -3939
- package/dist/rolldown-runtime-C0BPl7ul.cjs +0 -43
- package/dist/worker-vitest-BfiQB8ND.cjs +0 -62
- package/docs/hot-default-design.md +0 -216
package/README.md
CHANGED
|
@@ -7,7 +7,7 @@ Run your React Native tests under Vitest, against **real React Native** — the
|
|
|
7
7
|
> **Beta.** The release-supported native engine is validated across React Native 0.81–0.88,
|
|
8
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
|
-
> runtime (
|
|
10
|
+
> runtime (opt-in with `hotRuntime: 'auto'`) is marked experimental because it uses Vitest's
|
|
11
11
|
> experimental custom-pool APIs.
|
|
12
12
|
>
|
|
13
13
|
> Maintained successor to [`vitest-community/vitest-react-native`](https://github.com/vitest-community/vitest-react-native) — same core idea (externalize RN, run its real JS under Node), rebuilt for modern Vitest (4+). Coming from it? See [Migrating from `vitest-react-native`](#migrating-from-vitest-react-native).
|
|
@@ -59,27 +59,23 @@ Testing React Native code with Jest has traditionally required a patchwork of co
|
|
|
59
59
|
|
|
60
60
|
```bash
|
|
61
61
|
# bun
|
|
62
|
-
bun add -d vitest-native
|
|
62
|
+
bun add -d vitest vite vitest-native @testing-library/react-native
|
|
63
63
|
|
|
64
64
|
# npm
|
|
65
|
-
npm install -D vitest-native
|
|
65
|
+
npm install -D vitest vite vitest-native @testing-library/react-native
|
|
66
66
|
|
|
67
67
|
# yarn
|
|
68
|
-
yarn add -D vitest-native
|
|
68
|
+
yarn add -D vitest vite vitest-native @testing-library/react-native
|
|
69
69
|
|
|
70
70
|
# pnpm
|
|
71
|
-
pnpm add -D vitest-native
|
|
71
|
+
pnpm add -D vitest vite vitest-native @testing-library/react-native
|
|
72
72
|
```
|
|
73
73
|
|
|
74
|
-
|
|
74
|
+
`vitest` and `vite` are peer dependencies. `@testing-library/react-native` is optional, but the examples
|
|
75
|
+
below use it. A real React Native project already provides what the native engine needs —
|
|
75
76
|
`react-native`, `@react-native/babel-preset`, and `@babel/core`. From Expo SDK 56,
|
|
76
77
|
`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.
|
|
78
|
-
`@testing-library/react-native` if you don't have it yet (the examples below use it):
|
|
79
|
-
|
|
80
|
-
```bash
|
|
81
|
-
npm install -D @testing-library/react-native
|
|
82
|
-
```
|
|
78
|
+
with Expo's own preset instead, as Metro does.
|
|
83
79
|
|
|
84
80
|
See [Requirements](#requirements) for exact versions.
|
|
85
81
|
|
|
@@ -121,8 +117,15 @@ test("renders a greeting", async () => {
|
|
|
121
117
|
|
|
122
118
|
> Prefer Jest-style globals (`test`/`expect` without imports)? Set
|
|
123
119
|
> `test: { globals: true }` in your Vitest config. vitest-native does not enable the full
|
|
124
|
-
> globals mode; it only exposes `expect` when RNTL needs it to register matchers
|
|
125
|
-
>
|
|
120
|
+
> globals mode; it only exposes `expect` when RNTL needs it to register matchers, and
|
|
121
|
+
> registers RNTL's automatic cleanup after each test, which RNTL itself does only when
|
|
122
|
+
> `afterEach` is a global. That cleanup runs after the file's own `afterEach` hooks, as
|
|
123
|
+
> RNTL's does under Vitest with `globals: true` (Jest runs it first). Under the native engine,
|
|
124
|
+
> RNTL's `waitFor` and `findBy*` advance `vi.useFakeTimers()`'s clock with no extra setup. Under
|
|
125
|
+
> the mock engine they do so only with the
|
|
126
|
+
> [jest-compat layer](https://danfry1.github.io/vitest-native/guide/jest-compat); without it,
|
|
127
|
+
> advance the clock yourself (`await vi.advanceTimersByTimeAsync(ms)`). Awaiting
|
|
128
|
+
> `render` works with RNTL 12–13 and is required by RNTL 14.
|
|
126
129
|
|
|
127
130
|
Run it:
|
|
128
131
|
|
|
@@ -145,12 +148,12 @@ export default defineConfig({
|
|
|
145
148
|
reactNative({
|
|
146
149
|
engine: "auto", // 'auto' | 'mock' | 'native' — auto → native when RN's babel deps are present, else mock
|
|
147
150
|
platform: "ios", // 'ios' | 'android' (default: 'ios')
|
|
148
|
-
presets:
|
|
149
|
-
mocks: {}, //
|
|
151
|
+
// presets: omit to auto-detect; an array replaces auto-detection (`[]` means none)
|
|
152
|
+
mocks: {}, // engine: 'mock' only; non-empty under native is a config error
|
|
150
153
|
diagnostics: false, // Enable verbose logging
|
|
151
154
|
assetExts: [".lottie"], // Additional asset extensions to stub
|
|
152
155
|
transform: [], // Extra native-engine packages to Flow/TS transform
|
|
153
|
-
hotRuntime:
|
|
156
|
+
hotRuntime: false, // false (default) | 'auto' | true | HotRuntimeOptions
|
|
154
157
|
}),
|
|
155
158
|
],
|
|
156
159
|
});
|
|
@@ -160,12 +163,12 @@ export default defineConfig({
|
|
|
160
163
|
| ------------- | ------------------------------ | ----------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
161
164
|
| `engine` | `'auto' \| 'mock' \| 'native'` | `'auto'` | How React Native is provided to your tests. `auto` runs real RN (native) when available, else mock. See [`engine`](#engine) below. |
|
|
162
165
|
| `platform` | `'ios' \| 'android'` | `'ios'` | Target platform. Controls `Platform.OS`, version defaults, and file extension resolution. |
|
|
163
|
-
| `presets` | `Preset[]
|
|
166
|
+
| `presets` | `(Preset \| string)[] \| Record<string, boolean>` | auto-detect | Library presets. When omitted, installed packages are detected automatically. An array uses only the presets it lists, so `[]` disables all of them; an object keeps auto-detection and switches presets on or off (`{ navigation: false }`). A string is the path of a module that exports your own preset. |
|
|
164
167
|
| `mocks` | `Record<string, any>` | `{}` | **`engine: 'mock'` only.** JSON-serializable overrides merged into the `react-native` module mock. Function values are not supported; use `vi.mock()` in a setup file for function-based overrides. |
|
|
165
168
|
| `diagnostics` | `boolean` | `false` | Log plugin activity to the console for debugging. |
|
|
166
169
|
| `assetExts` | `string[]` | `[]` | Additional file extensions to stub as asset imports (beyond the built-in set). |
|
|
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
|
|
168
|
-
| `hotRuntime` | `boolean \| 'auto' \| HotRuntimeOptions` | `
|
|
170
|
+
| `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 packages that ship untranspiled source and are not detected automatically (packages your project depends on that declare `react-native` as a dependency or peer dependency, and their runtime dependencies, are compiled without being listed). Analogous to Jest's `transformIgnorePatterns` allowlist. |
|
|
171
|
+
| `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). |
|
|
169
172
|
|
|
170
173
|
### Experimental Metro configuration
|
|
171
174
|
|
|
@@ -193,7 +196,7 @@ main fields and conditions remain governed by the engine's ownership policy;
|
|
|
193
196
|
startup; changing it requires restarting the run.
|
|
194
197
|
|
|
195
198
|
Default: `false`. Findings and remaining gates are recorded in
|
|
196
|
-
[the investigation log](docs/metro-profile-investigation.md).
|
|
199
|
+
[the investigation log](https://github.com/danfry1/vitest-native/blob/main/packages/vitest-native/docs/metro-profile-investigation.md).
|
|
197
200
|
|
|
198
201
|
### `engine`
|
|
199
202
|
|
|
@@ -242,9 +245,11 @@ the cross-check/fidelity harnesses in the repository's `bench/` directory.
|
|
|
242
245
|
|
|
243
246
|
#### Hot runtime
|
|
244
247
|
|
|
245
|
-
Vitest's default isolation gives each test file a fresh worker, so React Native
|
|
246
|
-
|
|
247
|
-
modules per file whenever that can be done safely
|
|
248
|
+
Vitest's default isolation gives each test file a fresh worker, so React Native reloads for every
|
|
249
|
+
file; that is the default (`hotRuntime: false`), as in 0.13.0. With `hotRuntime: 'auto'` the native
|
|
250
|
+
engine instead reuses workers and resets modules per file whenever that can be done safely. It has
|
|
251
|
+
known differences from per-file isolation, listed under "A test passes on its own but fails when
|
|
252
|
+
run with other files" in the troubleshooting guide.
|
|
248
253
|
|
|
249
254
|
`'auto'` selects persistent workers when the current scheduler provides recyclable task boundaries,
|
|
250
255
|
the host/container memory plan admits at least two workers, no other pool was explicitly
|
|
@@ -259,8 +264,8 @@ jest-compat surface — `jest.mock` in its forms, runtime mocks, spies, timers,
|
|
|
259
264
|
Library cleanup — has its own cross-file isolation gate under the hot runtime. The decision runs
|
|
260
265
|
after other Vite config hooks, so a pool contributed by a later plugin is included rather than
|
|
261
266
|
producing a mixed runtime. When it falls
|
|
262
|
-
back to per-file isolation it
|
|
263
|
-
explicitly
|
|
267
|
+
back to per-file isolation it prints the reason. Per-file isolation, the default, can also be set
|
|
268
|
+
explicitly:
|
|
264
269
|
|
|
265
270
|
```ts
|
|
266
271
|
reactNative({
|
|
@@ -283,7 +288,7 @@ resetting the registry's module instances and the app/test module graph for ever
|
|
|
283
288
|
state manifest also restores and verifies timers/Vitest stubs, direct `process.env` changes,
|
|
284
289
|
process and RN listeners, complete global and console property descriptors, known RN state,
|
|
285
290
|
ErrorUtils, Expo runtime state, and plugin boundary mocks. A mutation gate removes each of its
|
|
286
|
-
|
|
291
|
+
restore actions in turn and requires the cross-file isolation suite to fail by name.
|
|
287
292
|
|
|
288
293
|
When hot is enabled, the plugin derives a worker-total memory plan from the lower of host and
|
|
289
294
|
container/cgroup memory. It reserves main-process and replacement headroom, caps automatic
|
|
@@ -312,8 +317,12 @@ reactNative({
|
|
|
312
317
|
});
|
|
313
318
|
```
|
|
314
319
|
|
|
320
|
+
That object requires the hot runtime and fails where it cannot run. Add `mode: "auto"` to keep
|
|
321
|
+
these options and fall back to per-file isolation instead, as `'auto'` does:
|
|
322
|
+
`hotRuntime: { mode: "auto", memoryLimit: 2 * 1024 ** 3 }`.
|
|
323
|
+
|
|
315
324
|
Recycling is applied between Vitest scheduler tasks. Current Vitest batches every file into one
|
|
316
|
-
uninterruptible task at `maxWorkers: 1`, so
|
|
325
|
+
uninterruptible task at `maxWorkers: 1`, so `'auto'` keeps per-file isolation there and
|
|
317
326
|
`hotRuntime: true` fails that configuration rather than claim an inert memory bound. Use at least
|
|
318
327
|
two workers for hot mode. If an external scheduler
|
|
319
328
|
already provides a hard boundary, you can deliberately accept the risk with
|
|
@@ -480,7 +489,7 @@ Register a custom native module mock. The module becomes available through both
|
|
|
480
489
|
```ts
|
|
481
490
|
import { mockNativeModule } from "vitest-native/helpers";
|
|
482
491
|
|
|
483
|
-
test("uses a custom native module", () => {
|
|
492
|
+
test("uses a custom native module", async () => {
|
|
484
493
|
mockNativeModule("MyBridge", {
|
|
485
494
|
getValue: vi.fn().mockResolvedValue(42),
|
|
486
495
|
});
|
|
@@ -581,8 +590,9 @@ JavaScript runs for real — `expo` itself, expo-router, React Navigation and Ex
|
|
|
581
590
|
jest-expo: from the package's own `mocks/<Name>.ts` where it ships one, else from Expo's table
|
|
582
591
|
of the native modules (`Device.modelName` is `'mock'`). An optional native module a package
|
|
583
592
|
probes for, and that no installed package defines, is absent, as on a device.
|
|
584
|
-
- **Expo SDK
|
|
585
|
-
|
|
593
|
+
- **Expo SDK 57 and 58 are supported.** Earlier SDKs are not: the plugin and `doctor` warn about
|
|
594
|
+
one, so upgrade to SDK 57 or 58. Pin your `react-native` to the version your Expo SDK
|
|
595
|
+
supports, not the newest RN release.
|
|
586
596
|
|
|
587
597
|
Packed Expo SDK 58 and SDK 57 apps are installed from the release tarball and tested in CI: Expo
|
|
588
598
|
module auto-detection and rendering, and expo-router's testing library against file-based `app/`
|
|
@@ -613,30 +623,30 @@ common case it's a config swap:
|
|
|
613
623
|
|
|
614
624
|
Named import, and drop `@vitejs/plugin-react` (vitest-native handles the JSX runtime itself). The
|
|
615
625
|
full walkthrough — install, gotchas, what's the same — is in
|
|
616
|
-
**[docs/migrating-from-vitest-react-native.md](docs/migrating-from-vitest-react-native.md)**.
|
|
626
|
+
**[docs/migrating-from-vitest-react-native.md](https://github.com/danfry1/vitest-native/blob/main/packages/vitest-native/docs/migrating-from-vitest-react-native.md)**.
|
|
617
627
|
|
|
618
628
|
---
|
|
619
629
|
|
|
620
630
|
## Migrating from Jest
|
|
621
631
|
|
|
622
632
|
vitest-native ships a small compat layer that clears the mechanical Jest-API coupling in an existing
|
|
623
|
-
suite (the `jest` global, `@jest/globals`, jest-native's extend-expect):
|
|
633
|
+
suite (the `jest` global, top-level `jest.mock`, `@jest/globals`, jest-native's extend-expect):
|
|
624
634
|
|
|
625
635
|
```ts
|
|
626
636
|
// vitest.config.mts
|
|
627
637
|
import { reactNative } from "vitest-native";
|
|
628
|
-
import { jestCompatAliases, jestCompatSetup } from "vitest-native/jest-compat";
|
|
638
|
+
import { jestCompatAliases, jestCompatSetup, jestMockTransform } from "vitest-native/jest-compat";
|
|
629
639
|
|
|
630
640
|
export default defineConfig({
|
|
631
|
-
plugins: [reactNative({ engine: "native" })],
|
|
641
|
+
plugins: [reactNative({ engine: "native" }), jestMockTransform()],
|
|
632
642
|
resolve: { alias: { ...jestCompatAliases() } },
|
|
633
643
|
test: { globals: true, setupFiles: [jestCompatSetup] },
|
|
634
644
|
});
|
|
635
645
|
```
|
|
636
646
|
|
|
637
|
-
This is **not** a turnkey drop-in — a real suite still needs a small per-suite cleanup (
|
|
638
|
-
|
|
639
|
-
with a worked real-app example, is in **[docs/migrating-from-jest.md](docs/migrating-from-jest.md)**.
|
|
647
|
+
This is **not** a turnkey drop-in — a real suite still needs a small per-suite cleanup (mocks for
|
|
648
|
+
native libraries with no preset, RNTL ≥ 12, record snapshots for Vitest in their own directory). The full recipe,
|
|
649
|
+
with a worked real-app example, is in **[docs/migrating-from-jest.md](https://github.com/danfry1/vitest-native/blob/main/packages/vitest-native/docs/migrating-from-jest.md)**.
|
|
640
650
|
|
|
641
651
|
---
|
|
642
652
|
|
|
@@ -660,45 +670,42 @@ npm i -D @react-native/babel-preset @babel/core
|
|
|
660
670
|
To silence the notice and stay on mock deliberately, set `reactNative({ engine: 'mock' })`.
|
|
661
671
|
|
|
662
672
|
**`vi.mock('some-rn-library')` doesn't take effect (native engine)**
|
|
663
|
-
Under `engine: 'native'`, React Native and
|
|
664
|
-
|
|
665
|
-
|
|
673
|
+
Under `engine: 'native'`, React Native and third-party RN packages load through Node. `vi.mock`
|
|
674
|
+
applies to what your test and app source import, but not to `require()` calls inside a
|
|
675
|
+
Node-loaded library: a library's own import of a mocked package still gets the real one. Options:
|
|
666
676
|
|
|
667
677
|
- Use a **[preset](#auto-detect-presets)** if one exists (it shadows the library the way Jest does).
|
|
668
|
-
- For a pure-JS library shipping untranspiled source, add it to the [`transform`](#plugin-options)
|
|
669
|
-
allowlist so the engine strips its Flow/TS as it loads.
|
|
670
678
|
- Or test that boundary on the **mock engine**, where `vi.mock` applies normally.
|
|
671
679
|
|
|
672
680
|
**`Unexpected token` / Flow syntax errors from a third-party library (native engine)**
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
681
|
+
Packages your project depends on that declare `react-native` as a dependency or peer dependency,
|
|
682
|
+
and their runtime dependencies, are compiled automatically. If another package ships untranspiled
|
|
683
|
+
Flow/TS/JSX, add it to the
|
|
684
|
+
[`transform`](#plugin-options) list.
|
|
676
685
|
|
|
677
686
|
**My `babel.config.js` plugin isn't running**
|
|
678
|
-
|
|
679
|
-
apply. Vite 6–7 use esbuild and Vite 8 uses Oxc; the plugin configures the
|
|
680
|
-
|
|
681
|
-
|
|
687
|
+
Files your tests `import` go through Vite's JSX transformer, not your Babel config, so custom Babel
|
|
688
|
+
plugins don't apply to them. Vite 6–7 use esbuild and Vite 8 uses Oxc; the plugin configures the
|
|
689
|
+
automatic JSX runtime for both. Project TypeScript files that Node loads (through `require()` or
|
|
690
|
+
`jest.requireActual`) are compiled with your Babel config, as babel-jest compiles them; plain `.js`
|
|
691
|
+
project files Node loads are not compiled.
|
|
692
|
+
`vitest-native doctor` lists the Babel plugins a run does not apply; one your tests depend on, such
|
|
693
|
+
as a macro plugin, runs through a Vite plugin that calls Babel
|
|
694
|
+
([recipe](https://danfry1.github.io/vitest-native/migration/from-jest#babel-plugins-your-jest-run-applied)).
|
|
682
695
|
|
|
683
696
|
**Snapshots differ after switching from Jest or the mock engine**
|
|
684
697
|
Real RN computes host props (e.g. `<Text>`'s `accessible`, `allowFontScaling`) that mocks omit, so
|
|
685
|
-
the tree is richer.
|
|
698
|
+
the tree is richer. Vitest also keys snapshots differently from Jest (`a > b 1`, not `a b 1`), so
|
|
699
|
+
it cannot check Jest's `.snap` files, and `vitest -u` rewrites them for Vitest. While both runners
|
|
700
|
+
run, give Vitest its own directory with `test.resolveSnapshotPath`; see
|
|
701
|
+
[docs/migrating-from-jest.md](https://github.com/danfry1/vitest-native/blob/main/packages/vitest-native/docs/migrating-from-jest.md#2d-snapshots-keep-jests-and-vitests-apart-then-record-vitests).
|
|
686
702
|
|
|
687
703
|
**`Worker terminated due to reaching memory limit` / `JS heap out of memory` (large native suites)**
|
|
688
|
-
Every test file that renders real React Native loads a full renderer
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
// vitest.config.ts
|
|
694
|
-
export default defineConfig({
|
|
695
|
-
test: { poolOptions: { threads: { memoryLimit: "512MB" } } },
|
|
696
|
-
});
|
|
697
|
-
```
|
|
698
|
-
|
|
699
|
-
The hot runtime (the default where it can be bounded) also helps: it keeps React Native's precompiled
|
|
700
|
-
factory registry warm, resets its module instances from memory per file, and recycles workers on a
|
|
701
|
-
memory/file budget.
|
|
704
|
+
Every test file that renders real React Native loads a full renderer. Under the default per-file
|
|
705
|
+
isolation each file starts in a fresh worker, so heap does not accumulate across files. Under the
|
|
706
|
+
hot runtime (`hotRuntime: 'auto'`), workers
|
|
707
|
+
are reused and recycled on a memory budget; set your own heap threshold with
|
|
708
|
+
`hotRuntime: { mode: "auto", memoryLimit }` (bytes; see [Hot runtime](#hot-runtime)).
|
|
702
709
|
|
|
703
710
|
**`Vitest caught N unhandled errors` in error-boundary tests**
|
|
704
711
|
A test that intentionally throws inside a component (to exercise an error boundary) makes React log
|
|
@@ -959,6 +966,17 @@ reactNative({
|
|
|
959
966
|
|
|
960
967
|
This prints details about which presets were detected, which modules are being mocked, and how imports are resolved. Useful for debugging unexpected behavior.
|
|
961
968
|
|
|
969
|
+
To turn it on for a single run, read an environment variable you choose, then run
|
|
970
|
+
`RN_TEST_DEBUG=1 vitest run`:
|
|
971
|
+
|
|
972
|
+
```ts
|
|
973
|
+
reactNative({ diagnostics: process.env.RN_TEST_DEBUG === "1" });
|
|
974
|
+
```
|
|
975
|
+
|
|
976
|
+
There is no `VITEST_NATIVE_DIAGNOSTICS` variable. Older releases' `VITEST_NATIVE_*` settings, such
|
|
977
|
+
as `VITEST_NATIVE_PLATFORM`, are no longer read; set the matching option. Startup warns when one
|
|
978
|
+
is set.
|
|
979
|
+
|
|
962
980
|
---
|
|
963
981
|
|
|
964
982
|
## Support Policy
|
|
@@ -971,7 +989,7 @@ that API.
|
|
|
971
989
|
|
|
972
990
|
Every release must pass:
|
|
973
991
|
|
|
974
|
-
- Linux on Node
|
|
992
|
+
- Linux on Node 22.13 (with RNTL 12, 13 and 14) and 24, plus macOS and Windows on Node 22.13.
|
|
975
993
|
- The mock, native iOS, native Android, hot-runtime, isolation, and 100-file soak suites.
|
|
976
994
|
- React Native 0.81–0.88 against both locked and newest-supported Vitest, plus the Vitest 4 floor
|
|
977
995
|
on 0.81 and 0.88.
|
|
@@ -986,11 +1004,11 @@ Every release must pass:
|
|
|
986
1004
|
package export analysis.
|
|
987
1005
|
|
|
988
1006
|
Current React Native edge releases are also tested weekly. See
|
|
989
|
-
[the release-readiness policy](docs/release-readiness.md) for the exact gates and stability labels.
|
|
1007
|
+
[the release-readiness policy](https://github.com/danfry1/vitest-native/blob/main/packages/vitest-native/docs/release-readiness.md) for the exact gates and stability labels.
|
|
990
1008
|
|
|
991
1009
|
For what is *promised* rather than what is tested — which exports and options are protected by
|
|
992
1010
|
semver, which are experimental, how the version ranges above may move, and what 1.0 will mean —
|
|
993
|
-
see [versioning and stability](docs/versioning.md).
|
|
1011
|
+
see [versioning and stability](https://github.com/danfry1/vitest-native/blob/main/packages/vitest-native/docs/versioning.md).
|
|
994
1012
|
|
|
995
1013
|
---
|
|
996
1014
|
|
|
@@ -1001,14 +1019,15 @@ see [versioning and stability](docs/versioning.md).
|
|
|
1001
1019
|
| `react` | >= 18; use RN's matching React version |
|
|
1002
1020
|
| `vite` | ^6.4.2, ^7.3.2, or ^8.0.5 |
|
|
1003
1021
|
| `vitest` | 4.x or 5.x |
|
|
1004
|
-
| `node` |
|
|
1022
|
+
| `node` | 22.13+ on Node 22, or 24.3+ |
|
|
1005
1023
|
| `react-native` (native engine) | 0.81–0.88 validated |
|
|
1006
1024
|
| `@react-native/babel-preset` (native engine) | Match the installed React Native minor |
|
|
1007
1025
|
| `@testing-library/react-native` (optional) | 12.x, 13.x, or 14.x |
|
|
1008
1026
|
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1027
|
+
Node 20 reached end of life in April 2026. Node 22.13 is the first Node 22 that both RNTL 14 and the
|
|
1028
|
+
engine's CommonJS entry points (`require(esm)`) support. On Node 24.0–24.2, `jest.mock`,
|
|
1029
|
+
`jest.isolateModules` and `jest.resetModules` do not reach modules Node loads, with either loader.
|
|
1030
|
+
Node 23 is past its end of life. RNTL 14 uses async rendering APIs.
|
|
1012
1031
|
|
|
1013
1032
|
---
|
|
1014
1033
|
|
package/dist/cli.d.mts
CHANGED