vitest-native 0.14.0-rc.1 → 0.14.0-rc.11
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 +96 -68
- package/dist/cli.mjs +1502 -162
- package/dist/context.d.mts +40 -0
- package/dist/context.mjs +238 -0
- package/dist/errors.d.mts +7 -0
- package/dist/helpers.cjs +53 -8
- package/dist/helpers.mjs +0 -6
- package/dist/{ecosystem-DFbU_MPe.mjs → host-C3wt9zUE.mjs} +442 -43
- package/dist/{index-BxzW2D7K.d.cts → index-CPEAYjaQ.d.mts} +61 -16
- package/dist/index.d.mts +1 -1
- package/dist/index.mjs +971 -179
- package/dist/jest-compat/error-equality.mjs +127 -0
- package/dist/jest-compat/interop.mjs +78 -4
- package/dist/jest-compat/jest-globals.mjs +5 -2
- package/dist/jest-compat/jest-object.mjs +348 -0
- package/dist/jest-compat/node-registry.mjs +609 -0
- package/dist/jest-compat/setup.mjs +144 -75
- package/dist/jest-compat.cjs +231 -24
- package/dist/jest-compat.d.cts +5 -0
- package/dist/jest-compat.d.mts +5 -0
- package/dist/jest-compat.mjs +207 -24
- package/dist/matchers.d.cts +2 -1
- package/dist/matchers.d.mts +2 -1
- package/dist/{memory-FYbP0_gg.mjs → memory-BFxB285Z.mjs} +14 -3
- package/dist/native/assets.d.mts +41 -0
- package/dist/native/assets.mjs +465 -0
- package/dist/native/babel-preset.d.mts +14 -0
- package/dist/native/babel-preset.mjs +56 -0
- package/dist/native/babel-toolchain.mjs +64 -0
- package/dist/native/babel-worker.mjs +53 -0
- package/dist/native/boundary.mjs +58 -6
- package/dist/native/compile-cache.mjs +21 -9
- package/dist/native/esm-interop.mjs +216 -0
- 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 +157 -5
- package/dist/native/hooks.mjs +268 -59
- package/dist/native/loader.mjs +319 -61
- package/dist/native/match.d.mts +11 -1
- package/dist/native/match.mjs +106 -7
- package/dist/native/metro-profile-compiler.mjs +2 -31
- package/dist/native/module-reset.mjs +61 -0
- package/dist/native/native-modules.d.mts +15 -0
- package/dist/native/native-modules.mjs +228 -0
- package/dist/native/nitro.mjs +60 -0
- package/dist/native/registry-compiler.mjs +6 -0
- package/dist/native/registry.mjs +127 -88
- package/dist/native/reset.mjs +29 -0
- package/dist/native/resolve.d.mts +12 -0
- package/dist/native/resolve.mjs +185 -8
- package/dist/native/rntl-hooks.mjs +157 -6
- package/dist/native/rntl-text-host.mjs +64 -0
- package/dist/native/runner.mjs +33 -1
- package/dist/native/setup.mjs +211 -72
- package/dist/native/state-manifest.mjs +2 -0
- package/dist/native/transform.d.mts +2 -0
- package/dist/native/transform.mjs +482 -44
- package/dist/native/tsconfig-paths.d.mts +5 -0
- package/dist/native/tsconfig-paths.mjs +163 -0
- package/dist/native/worker.mjs +111 -48
- package/dist/{pool-DjpOjOf3.mjs → pool-DUOe-n1k.mjs} +7 -1
- package/dist/preset-map-L1-vD19T.mjs +215 -0
- package/dist/preset-modules-Bt6k_Wdw.mjs +31 -0
- package/dist/preset-modules.d.mts +16 -0
- package/dist/preset-modules.mjs +92 -0
- package/dist/preset-ready.mjs +9 -0
- package/dist/{presets-DC-eM5IA.mjs → presets-DuXiUNAx.mjs} +991 -86
- package/dist/presets.d.mts +2 -2
- package/dist/presets.mjs +1 -2
- 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/setup.mjs +419 -59
- package/docs/migrating-from-jest.md +74 -15
- package/docs/migrating-from-vitest-react-native.md +2 -2
- package/docs/release-readiness.md +21 -7
- package/docs/versioning.md +15 -7
- package/package.json +113 -101
- package/CHANGELOG.md +0 -2169
- package/dist/cli.cjs +0 -725
- package/dist/cli.d.cts +0 -3
- package/dist/ecosystem-DI1AhK_k.cjs +0 -1042
- package/dist/errors-B3lJK46O.cjs +0 -75
- package/dist/index-CEbwa4QU.d.mts +0 -440
- package/dist/memory-6EPHrJA1.cjs +0 -144
- package/dist/pool-B4yesGhI.cjs +0 -121
- package/dist/preset-map-BoG19dLa.cjs +0 -35
- package/dist/preset-map-DuX0ocdn.mjs +0 -30
- package/dist/presets-BYHmi7-W.cjs +0 -3020
- 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
|
@@ -4,10 +4,10 @@
|
|
|
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
|
-
> 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).
|
|
@@ -31,7 +31,7 @@ Run your React Native tests under Vitest, against **real React Native** — the
|
|
|
31
31
|
- [Animated Matchers (Reanimated)](#animated-matchers-reanimated)
|
|
32
32
|
- [Snapshot Serializer](#snapshot-serializer)
|
|
33
33
|
- [Platform Extensions](#platform-extensions)
|
|
34
|
-
- [
|
|
34
|
+
- [Assets](#assets)
|
|
35
35
|
- [Diagnostics](#diagnostics)
|
|
36
36
|
- [Support Policy](#support-policy)
|
|
37
37
|
- [Requirements](#requirements)
|
|
@@ -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
|
|
@@ -119,8 +121,14 @@ test("renders a greeting", async () => {
|
|
|
119
121
|
|
|
120
122
|
> Prefer Jest-style globals (`test`/`expect` without imports)? Set
|
|
121
123
|
> `test: { globals: true }` in your Vitest config. vitest-native does not enable the full
|
|
122
|
-
> globals mode; it only exposes `expect` when RNTL needs it to register matchers
|
|
123
|
-
>
|
|
124
|
+
> globals mode; it only exposes `expect` when RNTL needs it to register matchers, and
|
|
125
|
+
> registers RNTL's automatic cleanup after each test, which RNTL itself does only when
|
|
126
|
+
> `afterEach` is a global. That cleanup runs after the file's own `afterEach` hooks, as
|
|
127
|
+
> RNTL's does under Vitest with `globals: true` (Jest runs it first). Without the
|
|
128
|
+
> [jest-compat layer](https://danfry1.github.io/vitest-native/guide/jest-compat), RNTL cannot
|
|
129
|
+
> see `vi.useFakeTimers()`, so `waitFor` and `findBy*` do not advance the fake clock: use
|
|
130
|
+
> jest-compat, or advance it yourself (`await vi.advanceTimersByTimeAsync(ms)`). Awaiting
|
|
131
|
+
> `render` works with RNTL 12–13 and is required by RNTL 14.
|
|
124
132
|
|
|
125
133
|
Run it:
|
|
126
134
|
|
|
@@ -148,7 +156,7 @@ export default defineConfig({
|
|
|
148
156
|
diagnostics: false, // Enable verbose logging
|
|
149
157
|
assetExts: [".lottie"], // Additional asset extensions to stub
|
|
150
158
|
transform: [], // Extra native-engine packages to Flow/TS transform
|
|
151
|
-
hotRuntime:
|
|
159
|
+
hotRuntime: false, // false (default) | 'auto' | true | HotRuntimeOptions
|
|
152
160
|
}),
|
|
153
161
|
],
|
|
154
162
|
});
|
|
@@ -163,7 +171,7 @@ export default defineConfig({
|
|
|
163
171
|
| `diagnostics` | `boolean` | `false` | Log plugin activity to the console for debugging. |
|
|
164
172
|
| `assetExts` | `string[]` | `[]` | Additional file extensions to stub as asset imports (beyond the built-in set). |
|
|
165
173
|
| `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` | `
|
|
174
|
+
| `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
175
|
|
|
168
176
|
### Experimental Metro configuration
|
|
169
177
|
|
|
@@ -202,13 +210,13 @@ Choose how React Native is provided to your tests:
|
|
|
202
210
|
requires a device. Jest's `react-native` preset replaces many of these modules with
|
|
203
211
|
stubs, so the native engine exercises behavior Jest's mocks skip (see [Fidelity](#fidelity)
|
|
204
212
|
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
|
|
213
|
+
pass is costly. Requires `@react-native/babel-preset` (or, from Expo SDK 56, Expo's
|
|
214
|
+
preset) and `@babel/core`, present by default in React Native and Expo apps.
|
|
207
215
|
- `'mock'` — a lightweight, pure-JS reimplementation of React Native with **zero extra
|
|
208
216
|
dependencies**. Best for pure-logic/unit tests, maximum determinism, or when you can't
|
|
209
217
|
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
|
-
|
|
218
|
+
- `'auto'` _(default)_ — picks automatically, and **resolves to `'native'`** whenever a React
|
|
219
|
+
Native Babel preset and `@babel/core` are present (i.e. in any real RN or Expo app). It
|
|
212
220
|
falls back to `'mock'` only when those deps are absent, printing one line to explain why.
|
|
213
221
|
So `reactNative()` with no options runs real React Native. Set `engine: 'mock'` to opt out.
|
|
214
222
|
|
|
@@ -240,9 +248,11 @@ the cross-check/fidelity harnesses in the repository's `bench/` directory.
|
|
|
240
248
|
|
|
241
249
|
#### Hot runtime
|
|
242
250
|
|
|
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
|
|
251
|
+
Vitest's default isolation gives each test file a fresh worker, so React Native reloads for every
|
|
252
|
+
file; that is the default (`hotRuntime: false`), as in 0.13.0. With `hotRuntime: 'auto'` the native
|
|
253
|
+
engine instead reuses workers and resets modules per file whenever that can be done safely. It has
|
|
254
|
+
known differences from per-file isolation, listed under "A test passes on its own but fails when
|
|
255
|
+
run with other files" in the troubleshooting guide.
|
|
246
256
|
|
|
247
257
|
`'auto'` selects persistent workers when the current scheduler provides recyclable task boundaries,
|
|
248
258
|
the host/container memory plan admits at least two workers, no other pool was explicitly
|
|
@@ -257,8 +267,8 @@ jest-compat surface — `jest.mock` in its forms, runtime mocks, spies, timers,
|
|
|
257
267
|
Library cleanup — has its own cross-file isolation gate under the hot runtime. The decision runs
|
|
258
268
|
after other Vite config hooks, so a pool contributed by a later plugin is included rather than
|
|
259
269
|
producing a mixed runtime. When it falls
|
|
260
|
-
back to per-file isolation it
|
|
261
|
-
explicitly
|
|
270
|
+
back to per-file isolation it prints the reason. Per-file isolation, the default, can also be set
|
|
271
|
+
explicitly:
|
|
262
272
|
|
|
263
273
|
```ts
|
|
264
274
|
reactNative({
|
|
@@ -311,7 +321,7 @@ reactNative({
|
|
|
311
321
|
```
|
|
312
322
|
|
|
313
323
|
Recycling is applied between Vitest scheduler tasks. Current Vitest batches every file into one
|
|
314
|
-
uninterruptible task at `maxWorkers: 1`, so
|
|
324
|
+
uninterruptible task at `maxWorkers: 1`, so `'auto'` keeps per-file isolation there and
|
|
315
325
|
`hotRuntime: true` fails that configuration rather than claim an inert memory bound. Use at least
|
|
316
326
|
two workers for hot mode. If an external scheduler
|
|
317
327
|
already provides a hard boundary, you can deliberately accept the risk with
|
|
@@ -536,24 +546,27 @@ export default defineConfig({
|
|
|
536
546
|
|
|
537
547
|
### Available Presets
|
|
538
548
|
|
|
539
|
-
|
|
|
540
|
-
|
|
541
|
-
| `presets.reanimated()`
|
|
542
|
-
| `presets.
|
|
543
|
-
| `presets.
|
|
544
|
-
| `presets.
|
|
545
|
-
| `presets.
|
|
546
|
-
| `presets.screens()`
|
|
547
|
-
| `presets.
|
|
548
|
-
| `presets.
|
|
549
|
-
| `presets.
|
|
550
|
-
| `presets.
|
|
551
|
-
| `presets.
|
|
552
|
-
| `presets.
|
|
553
|
-
| `presets.
|
|
554
|
-
| `presets.
|
|
555
|
-
| `presets.
|
|
556
|
-
| `presets.
|
|
549
|
+
| Preset | Library | What's mocked |
|
|
550
|
+
|--------|---------|---------------|
|
|
551
|
+
| `presets.reanimated()` | `react-native-reanimated` | `useSharedValue`, `useAnimatedStyle`, `withTiming`, `withSpring`, `withDelay`, `withSequence`, `withRepeat`, layout animations (`FadeIn`, `FadeOut`, `SlideInRight`), `Easing`, `interpolate`, `createAnimatedComponent` |
|
|
552
|
+
| `presets.worklets()` | `react-native-worklets` | `runOnJS`, `runOnUI`, `scheduleOnRN`, `scheduleOnUI`, `createWorkletRuntime`, … run synchronously on the JS thread |
|
|
553
|
+
| `presets.gestureHandler()` | `react-native-gesture-handler` | `GestureHandlerRootView`, gesture handlers (Pan, Tap, LongPress, Pinch, Rotation, Fling), `Gesture` API (v2), `GestureDetector`, `Swipeable`, touchable wrappers, state constants |
|
|
554
|
+
| `presets.safeAreaContext()` | `react-native-safe-area-context` | `SafeAreaProvider`, `SafeAreaView`, `useSafeAreaInsets`, `useSafeAreaFrame`, `initialWindowMetrics`, `withSafeAreaInsets` |
|
|
555
|
+
| `presets.navigation()` | `@react-navigation/native`, `@react-navigation/native-stack`, `@react-navigation/bottom-tabs`, `@react-navigation/drawer`, `@react-navigation/elements` | `NavigationContainer`, `useNavigation`, `useRoute`, `useFocusEffect`, `useIsFocused`, `CommonActions`, `StackActions`, `TabActions`, `DrawerActions`, navigators |
|
|
556
|
+
| `presets.screens()` | `react-native-screens` | `enableScreens`, `Screen`, `ScreenContainer`, `ScreenStack` |
|
|
557
|
+
| `presets.asyncStorage()` | `@react-native-async-storage/async-storage` | in-memory store (`getItem`/`setItem`/`multiGet`/`mergeItem`/…) |
|
|
558
|
+
| `presets.expo()` | `expo-constants`, `expo-font`, `expo-asset`, `expo-splash-screen`, `expo-linking`, `expo-status-bar` | constants, fonts, assets, splash screen, linking, status bar |
|
|
559
|
+
| `presets.deviceInfo()` | `react-native-device-info` | string/bool/number getters with sync + async variants |
|
|
560
|
+
| `presets.mmkv()` | `react-native-mmkv` | in-memory `MMKV` + `useMMKV*` hooks, for mmkv 2 only: the library tests itself from v3 (its own in-memory backend under Vitest), so the preset steps aside |
|
|
561
|
+
| `presets.netInfo()` | `@react-native-community/netinfo` | connected-wifi state, `fetch`/`refresh`/`addEventListener`/`useNetInfo`, state-type enums |
|
|
562
|
+
| `presets.svg()` | `react-native-svg` | `Svg`, `Path`, `Circle`, `Rect`, `G`, … as host components |
|
|
563
|
+
| `presets.webview()` | `react-native-webview` | `WebView` (default + named) host component |
|
|
564
|
+
| `presets.vectorIcons()` | `@react-native-vector-icons/common` | `createIconSet` and the dynamic font loader shared by the v10+ scoped icon sets (not the legacy unscoped `react-native-vector-icons`) |
|
|
565
|
+
| `presets.flashList()` | `@shopify/flash-list` | `FlashList` rendering its data through `renderItem`, the ref surface, v2 recycler hooks |
|
|
566
|
+
| `presets.bottomSheet()` | `@gorhom/bottom-sheet` | `BottomSheet`, `BottomSheetModal` + provider, sheet views, scroll/list variants, `BottomSheetTextInput`, backdrop, footer |
|
|
567
|
+
| `presets.keyboardController()` | `react-native-keyboard-controller` | `KeyboardProvider`, `KeyboardAvoidingView`, `KeyboardAwareScrollView`, `KeyboardStickyView`, `KeyboardToolbar`; the imperative `KeyboardController` is inert |
|
|
568
|
+
| `presets.unistyles()` | `react-native-unistyles`, `react-native-unistyles/reanimated` | Unistyles 3: `StyleSheet.configure`/`create` with themes, variants and compound variants, `useUnistyles`, `withUnistyles`, `UnistylesRuntime` theme switching, `mq` with `Display`/`Hide`; matches the library's own Jest mock and follows its source where that mock does less |
|
|
569
|
+
| `presets.skia()` | `react-native-skia`, `@shopify/react-native-skia` | Skia's own test mock (`Mock(CanvasKit)`) over CanvasKit, Skia compiled to WebAssembly: the `Skia` API computes with real Skia, `Canvas` and its drawing render as Views; plus Skia's Reanimated helpers (`usePathValue`, `useTexture`, …) and a `matchFont` that returns a font |
|
|
557
570
|
|
|
558
571
|
Presets apply under **both** engines: the mock engine and `engine: 'native'` (where they shadow each
|
|
559
572
|
library's native runtime — worklets, native modules — exactly as Jest does, while the surrounding tree
|
|
@@ -561,10 +574,10 @@ renders through real React Native).
|
|
|
561
574
|
|
|
562
575
|
### Expo
|
|
563
576
|
|
|
564
|
-
Expo apps need no Expo-specific package.
|
|
565
|
-
|
|
566
|
-
`expo-
|
|
567
|
-
expo
|
|
577
|
+
Expo apps need no Expo-specific package. Under the native engine every Expo package's own
|
|
578
|
+
JavaScript runs for real — `expo` itself, expo-router, React Navigation and Expo modules such as
|
|
579
|
+
`expo-constants` or `expo-splash-screen` — and only their native modules are mocked, the way
|
|
580
|
+
`jest-expo` runs them. (The mock engine replaces the common Expo modules with the `expo` preset.)
|
|
568
581
|
|
|
569
582
|
- **Coming from jest-expo:** `npx vitest-native migrate --write` translates the `jest-expo`
|
|
570
583
|
presets (`jest-expo/android` → `platform: 'android'`) and, because jest-expo does not mock React
|
|
@@ -572,14 +585,18 @@ expo-router and React Navigation — runs for real under the native engine.
|
|
|
572
585
|
- **expo-router screens:** `expo-router/testing-library` (`renderRouter`, `testRouter`,
|
|
573
586
|
`toHavePathname`) runs as written with the jest-compat layer. From SDK 57 expo-router bundles its
|
|
574
587
|
own React Navigation; before SDK 57, also set `presets: { navigation: false }`.
|
|
575
|
-
- **Expo modules
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
588
|
+
- **Expo modules** run their real JavaScript, and their native modules answer as under
|
|
589
|
+
jest-expo: from the package's own `mocks/<Name>.ts` where it ships one, else from Expo's table
|
|
590
|
+
of the native modules (`Device.modelName` is `'mock'`). An optional native module a package
|
|
591
|
+
probes for, and that no installed package defines, is absent, as on a device.
|
|
592
|
+
- **Expo SDK 57 and 58 are supported.** Earlier SDKs are not: the plugin and `doctor` warn about
|
|
593
|
+
one, so upgrade to SDK 57 or 58. Pin your `react-native` to the version your Expo SDK
|
|
594
|
+
supports, not the newest RN release.
|
|
595
|
+
|
|
596
|
+
Packed Expo SDK 58 and SDK 57 apps are installed from the release tarball and tested in CI: Expo
|
|
597
|
+
module auto-detection and rendering, and expo-router's testing library against file-based `app/`
|
|
598
|
+
routes. The SDK 58 app also runs those routes under the configuration `migrate` generates from a
|
|
599
|
+
jest-expo setup. See the
|
|
583
600
|
[Expo guide](https://danfry1.github.io/vitest-native/guide/expo).
|
|
584
601
|
|
|
585
602
|
---
|
|
@@ -627,7 +644,7 @@ export default defineConfig({
|
|
|
627
644
|
```
|
|
628
645
|
|
|
629
646
|
This is **not** a turnkey drop-in — a real suite still needs a small per-suite cleanup (convert
|
|
630
|
-
top-level `jest.mock` → `vi.mock`, RNTL ≥ 12,
|
|
647
|
+
top-level `jest.mock` → `vi.mock`, RNTL ≥ 12, record snapshots for Vitest in their own directory). The full recipe,
|
|
631
648
|
with a worked real-app example, is in **[docs/migrating-from-jest.md](docs/migrating-from-jest.md)**.
|
|
632
649
|
|
|
633
650
|
---
|
|
@@ -642,7 +659,8 @@ Upgrade npm (`npm install --global npm@11`), or use pnpm, Yarn or Bun.
|
|
|
642
659
|
|
|
643
660
|
**`@react-native/babel-preset not found — using the mock engine`**
|
|
644
661
|
You asked for the default (`auto`) engine but the native babel deps aren't installed, so it
|
|
645
|
-
fell back to the mock engine.
|
|
662
|
+
fell back to the mock engine. An Expo project from SDK 56 needs nothing extra: the engine uses
|
|
663
|
+
Expo's preset, and `expo` brings `@babel/core`. Otherwise, to run real React Native, install them:
|
|
646
664
|
|
|
647
665
|
```bash
|
|
648
666
|
npm i -D @react-native/babel-preset @babel/core
|
|
@@ -673,7 +691,10 @@ preset.
|
|
|
673
691
|
|
|
674
692
|
**Snapshots differ after switching from Jest or the mock engine**
|
|
675
693
|
Real RN computes host props (e.g. `<Text>`'s `accessible`, `allowFontScaling`) that mocks omit, so
|
|
676
|
-
the tree is richer.
|
|
694
|
+
the tree is richer. Vitest also keys snapshots differently from Jest (`a > b 1`, not `a b 1`), so
|
|
695
|
+
it cannot check Jest's `.snap` files, and `vitest -u` rewrites them for Vitest. While both runners
|
|
696
|
+
run, give Vitest its own directory with `test.resolveSnapshotPath`; see
|
|
697
|
+
[docs/migrating-from-jest.md](docs/migrating-from-jest.md#2d-snapshots-keep-jests-and-vitests-apart-then-record-vitests).
|
|
677
698
|
|
|
678
699
|
**`Worker terminated due to reaching memory limit` / `JS heap out of memory` (large native suites)**
|
|
679
700
|
Every test file that renders real React Native loads a full renderer, so a large suite can grow a
|
|
@@ -687,7 +708,7 @@ export default defineConfig({
|
|
|
687
708
|
});
|
|
688
709
|
```
|
|
689
710
|
|
|
690
|
-
The hot runtime (
|
|
711
|
+
The hot runtime (`hotRuntime: 'auto'`, opt-in) also helps: it keeps React Native's precompiled
|
|
691
712
|
factory registry warm, resets its module instances from memory per file, and recycles workers on a
|
|
692
713
|
memory/file budget.
|
|
693
714
|
|
|
@@ -913,15 +934,21 @@ falling back to the default (often web) file.
|
|
|
913
934
|
|
|
914
935
|
---
|
|
915
936
|
|
|
916
|
-
##
|
|
937
|
+
## Assets
|
|
917
938
|
|
|
918
|
-
Image, font, video, and audio imports
|
|
939
|
+
Image, font, video, and audio imports evaluate to what Metro gives an app: a number, the id under which the asset is registered with React Native's asset registry. The registered descriptor is the one Metro builds — `name`, `type`, `scales`, `hash`, and for images `width` and `height` in points — so React Native's own asset handling works as on device:
|
|
919
940
|
|
|
920
|
-
```
|
|
921
|
-
|
|
922
|
-
//
|
|
941
|
+
```tsx
|
|
942
|
+
const logo = require("./logo.png"); // a number
|
|
943
|
+
Image.resolveAssetSource(logo); // { uri, width, height, scale, __packager_asset: true }
|
|
944
|
+
<Image source={logo} />; // renders the resolved asset
|
|
923
945
|
```
|
|
924
946
|
|
|
947
|
+
- `@2x`/`@3x` variants are grouped as Metro groups them, and a `.ios`/`.android` variant is preferred for the configured platform.
|
|
948
|
+
- Dimensions are read from PNG, JPEG, GIF, BMP and WebP headers; other formats, and files that are not valid images, register without them.
|
|
949
|
+
- The native engine registers with React Native's real registry; the mock engine registers with the mock `AssetRegistry`, which its `Image.resolveAssetSource` reads.
|
|
950
|
+
- A snapshot shows the id (a number) where it used to show the file name. Ids follow registration order within a test file, so they are stable for that file.
|
|
951
|
+
|
|
925
952
|
Built-in extensions include common formats like `.png`, `.jpg`, `.gif`, `.svg`, `.mp4`, `.ttf`, `.otf`, and more. To add additional extensions:
|
|
926
953
|
|
|
927
954
|
```ts
|
|
@@ -956,15 +983,15 @@ that API.
|
|
|
956
983
|
|
|
957
984
|
Every release must pass:
|
|
958
985
|
|
|
959
|
-
- Linux on Node
|
|
986
|
+
- Linux on Node 22.13 (with RNTL 12, 13 and 14) and 24, plus macOS and Windows on Node 22.13.
|
|
960
987
|
- The mock, native iOS, native Android, hot-runtime, isolation, and 100-file soak suites.
|
|
961
|
-
- React Native 0.81–0.
|
|
962
|
-
on 0.81 and 0.
|
|
988
|
+
- React Native 0.81–0.88 against both locked and newest-supported Vitest, plus the Vitest 4 floor
|
|
989
|
+
on 0.81 and 0.88.
|
|
963
990
|
- Vitest's own behaviour under the defaults, on Vitest 5 and the Vitest 4 floor: config and CLI
|
|
964
991
|
flags, projects, watch mode, the jsdom and happy-dom environments, `--typecheck`, `vitest bench`,
|
|
965
992
|
and the HTML reporter.
|
|
966
|
-
- Packed consumers: bare RN 0.83/RNTL 12, a Jest-migration project, Expo SDK
|
|
967
|
-
expo-router and a `migrate`-generated jest-expo config), a mock-engine RNTL 14 project, npm- and
|
|
993
|
+
- Packed consumers: bare RN 0.83/RNTL 12, a Jest-migration project, Expo SDK 58/RNTL 14 (with
|
|
994
|
+
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
|
|
968
995
|
pnpm-workspace monorepos on Vite 8, and an RN 0.86 Android project.
|
|
969
996
|
- Packed V8 and Istanbul coverage maps/counts matching default isolation exactly under hot workers.
|
|
970
997
|
- Mock-versus-real-RN behavioral cross-checks, example-app tests, typecheck, lint, formatting, and
|
|
@@ -986,14 +1013,15 @@ see [versioning and stability](docs/versioning.md).
|
|
|
986
1013
|
| `react` | >= 18; use RN's matching React version |
|
|
987
1014
|
| `vite` | ^6.4.2, ^7.3.2, or ^8.0.5 |
|
|
988
1015
|
| `vitest` | 4.x or 5.x |
|
|
989
|
-
| `node` |
|
|
990
|
-
| `react-native` (native engine) | 0.81–0.
|
|
1016
|
+
| `node` | 22.13+ on Node 22, or 24.3+ |
|
|
1017
|
+
| `react-native` (native engine) | 0.81–0.88 validated |
|
|
991
1018
|
| `@react-native/babel-preset` (native engine) | Match the installed React Native minor |
|
|
992
1019
|
| `@testing-library/react-native` (optional) | 12.x, 13.x, or 14.x |
|
|
993
1020
|
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
1021
|
+
Node 20 reached end of life in April 2026. Node 22.13 is the first Node 22 that both RNTL 14 and the
|
|
1022
|
+
engine's CommonJS entry points (`require(esm)`) support. On Node 24.0–24.2, `jest.mock`,
|
|
1023
|
+
`jest.isolateModules` and `jest.resetModules` do not reach modules Node loads, with either loader.
|
|
1024
|
+
Node 23 is past its end of life. RNTL 14 uses async rendering APIs.
|
|
997
1025
|
|
|
998
1026
|
---
|
|
999
1027
|
|