vitest-native 0.14.0-rc.6 → 0.14.0-rc.8
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 +52 -0
- package/README.md +28 -22
- package/dist/cli.cjs +22 -14
- package/dist/cli.mjs +22 -14
- package/dist/{ecosystem-BzWGVo_T.mjs → ecosystem-D6e1OVOg.mjs} +54 -5
- package/dist/{ecosystem-DTozsAyV.cjs → ecosystem-MFwkbnaC.cjs} +59 -4
- package/dist/index.mjs +10 -7
- 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 +74 -16
- package/dist/native/registry.mjs +4 -1
- package/dist/native/setup.mjs +12 -1
- package/dist/native/transform.mjs +51 -28
- 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.mjs +1 -1
- package/dist/setup.mjs +2 -2
- package/docs/migrating-from-vitest-react-native.md +1 -1
- package/docs/release-readiness.md +5 -3
- package/package.json +4 -4
package/CHANGELOG.md
CHANGED
|
@@ -45,9 +45,53 @@
|
|
|
45
45
|
- **Presets of your own are listed by path.** A preset object of a project's own passed to `presets`
|
|
46
46
|
used to shadow its packages with undefined exports; it is now refused at startup. List the module that
|
|
47
47
|
exports it instead: `presets: { './test/presets/my-lib.ts': true }`.
|
|
48
|
+
- **Expo SDK 56–58 projects run real React Native with nothing extra installed.** When
|
|
49
|
+
`@react-native/babel-preset` does not resolve (from SDK 56, `babel-preset-expo` no longer depends on
|
|
50
|
+
it), the native engine compiles with Expo's preset, as Metro does. `reactNative()` used the mock
|
|
51
|
+
engine there before.
|
|
52
|
+
- **Expo's globals are installed before your setup files, and `fetch` stays Node's.** A `fetch` mocked
|
|
53
|
+
in a setup file, an MSW server, nock and undici's `MockAgent` keep working whether or not a test
|
|
54
|
+
imports `expo`. Every test file in an Expo project now sees Expo's `URL`, `structuredClone` and
|
|
55
|
+
`DOMException` polyfills, as under jest-expo.
|
|
56
|
+
- **Expo modules' own native-module mocks are served.** Values that were `undefined` are the mock's
|
|
57
|
+
(`digestStringAsync` resolves `""`), and a member a mock leaves out is `undefined` where the generic
|
|
58
|
+
stub gave a function.
|
|
59
|
+
- **An optional native module that is not installed reads as absent.** `requireOptionalNativeModule`
|
|
60
|
+
returns `null` for a module a package only probes for and no installed package defines, as on a
|
|
61
|
+
device.
|
|
62
|
+
- **Expo modules run as their installed packages.** Under the native engine, the `expo` preset no
|
|
63
|
+
longer replaces `expo-constants`, `expo-status-bar`, `expo-font`, `expo-asset`, `expo-splash-screen`
|
|
64
|
+
and `expo-linking`, so their whole API is the installed SDK's (`hide()`, `setOptions()`,
|
|
65
|
+
`useAssets` …) and their values are jest-expo's: `Constants.expoConfig` is `{}`,
|
|
66
|
+
`Linking.createURL()` needs a scheme mocked into `expo-constants`, and `Font.isLoaded()` is `false`
|
|
67
|
+
until a font loads. The Minor Changes entry lists each value; `presets: { expo: true }` keeps the
|
|
68
|
+
preset while a suite moves off it.
|
|
48
69
|
|
|
49
70
|
### Minor Changes
|
|
50
71
|
|
|
72
|
+
- 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.
|
|
73
|
+
|
|
74
|
+
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.
|
|
75
|
+
|
|
76
|
+
What a suite that relied on the preset sees instead, each as under jest-expo:
|
|
77
|
+
|
|
78
|
+
- `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`.
|
|
79
|
+
- `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).
|
|
80
|
+
- `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.
|
|
81
|
+
- `preventAutoHideAsync()` and `hideAsync()` resolve `undefined` (were `true`).
|
|
82
|
+
|
|
83
|
+
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()`.
|
|
84
|
+
|
|
85
|
+
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.
|
|
86
|
+
|
|
87
|
+
- 7b9b795: React Native 0.88 and Expo SDK 58 join the supported matrix
|
|
88
|
+
|
|
89
|
+
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.
|
|
90
|
+
|
|
91
|
+
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.
|
|
92
|
+
|
|
93
|
+
- 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.
|
|
94
|
+
|
|
51
95
|
- 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
96
|
|
|
53
97
|
- styles resolve as the device parses them: breakpoint values and `mq` keys against the screen, `_web` styles dropped;
|
|
@@ -178,6 +222,14 @@
|
|
|
178
222
|
|
|
179
223
|
### Patch Changes
|
|
180
224
|
|
|
225
|
+
- 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.
|
|
226
|
+
|
|
227
|
+
- 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.
|
|
228
|
+
|
|
229
|
+
- 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.
|
|
230
|
+
|
|
231
|
+
- 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.
|
|
232
|
+
|
|
181
233
|
- 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
234
|
|
|
183
235
|
- 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
|
|
@@ -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
|
|
|
@@ -564,10 +566,10 @@ renders through real React Native).
|
|
|
564
566
|
|
|
565
567
|
### Expo
|
|
566
568
|
|
|
567
|
-
Expo apps need no Expo-specific package.
|
|
568
|
-
|
|
569
|
-
`expo-
|
|
570
|
-
expo
|
|
569
|
+
Expo apps need no Expo-specific package. Under the native engine every Expo package's own
|
|
570
|
+
JavaScript runs for real — `expo` itself, expo-router, React Navigation and Expo modules such as
|
|
571
|
+
`expo-constants` or `expo-splash-screen` — and only their native modules are mocked, the way
|
|
572
|
+
`jest-expo` runs them. (The mock engine replaces the common Expo modules with the `expo` preset.)
|
|
571
573
|
|
|
572
574
|
- **Coming from jest-expo:** `npx vitest-native migrate --write` translates the `jest-expo`
|
|
573
575
|
presets (`jest-expo/android` → `platform: 'android'`) and, because jest-expo does not mock React
|
|
@@ -575,14 +577,17 @@ expo-router and React Navigation — runs for real under the native engine.
|
|
|
575
577
|
- **expo-router screens:** `expo-router/testing-library` (`renderRouter`, `testRouter`,
|
|
576
578
|
`toHavePathname`) runs as written with the jest-compat layer. From SDK 57 expo-router bundles its
|
|
577
579
|
own React Navigation; before SDK 57, also set `presets: { navigation: false }`.
|
|
578
|
-
- **Expo modules
|
|
579
|
-
|
|
580
|
+
- **Expo modules** run their real JavaScript, and their native modules answer as under
|
|
581
|
+
jest-expo: from the package's own `mocks/<Name>.ts` where it ships one, else from Expo's table
|
|
582
|
+
of the native modules (`Device.modelName` is `'mock'`). An optional native module a package
|
|
583
|
+
probes for, and that no installed package defines, is absent, as on a device.
|
|
580
584
|
- **Expo SDK trails React Native.** Pin your `react-native` to the version your Expo SDK supports
|
|
581
585
|
(SDK 54 and later are within this plugin's validated range), not the newest RN release.
|
|
582
586
|
|
|
583
|
-
|
|
584
|
-
auto-detection and rendering, expo-router's testing library against file-based `app/`
|
|
585
|
-
|
|
587
|
+
Packed Expo SDK 58 and SDK 57 apps are installed from the release tarball and tested in CI: Expo
|
|
588
|
+
module auto-detection and rendering, and expo-router's testing library against file-based `app/`
|
|
589
|
+
routes. The SDK 58 app also runs those routes under the configuration `migrate` generates from a
|
|
590
|
+
jest-expo setup. See the
|
|
586
591
|
[Expo guide](https://danfry1.github.io/vitest-native/guide/expo).
|
|
587
592
|
|
|
588
593
|
---
|
|
@@ -645,7 +650,8 @@ Upgrade npm (`npm install --global npm@11`), or use pnpm, Yarn or Bun.
|
|
|
645
650
|
|
|
646
651
|
**`@react-native/babel-preset not found — using the mock engine`**
|
|
647
652
|
You asked for the default (`auto`) engine but the native babel deps aren't installed, so it
|
|
648
|
-
fell back to the mock engine.
|
|
653
|
+
fell back to the mock engine. An Expo project from SDK 56 needs nothing extra: the engine uses
|
|
654
|
+
Expo's preset, and `expo` brings `@babel/core`. Otherwise, to run real React Native, install them:
|
|
649
655
|
|
|
650
656
|
```bash
|
|
651
657
|
npm i -D @react-native/babel-preset @babel/core
|
|
@@ -967,13 +973,13 @@ Every release must pass:
|
|
|
967
973
|
|
|
968
974
|
- Linux on Node 20.19, 22.13, and 24, plus macOS and Windows on Node 22.13.
|
|
969
975
|
- 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.
|
|
976
|
+
- React Native 0.81–0.88 against both locked and newest-supported Vitest, plus the Vitest 4 floor
|
|
977
|
+
on 0.81 and 0.88.
|
|
972
978
|
- Vitest's own behaviour under the defaults, on Vitest 5 and the Vitest 4 floor: config and CLI
|
|
973
979
|
flags, projects, watch mode, the jsdom and happy-dom environments, `--typecheck`, `vitest bench`,
|
|
974
980
|
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
|
|
981
|
+
- Packed consumers: bare RN 0.83/RNTL 12, a Jest-migration project, Expo SDK 58/RNTL 14 (with
|
|
982
|
+
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
983
|
pnpm-workspace monorepos on Vite 8, and an RN 0.86 Android project.
|
|
978
984
|
- Packed V8 and Istanbul coverage maps/counts matching default isolation exactly under hot workers.
|
|
979
985
|
- Mock-versus-real-RN behavioral cross-checks, example-app tests, typecheck, lint, formatting, and
|
|
@@ -996,7 +1002,7 @@ see [versioning and stability](docs/versioning.md).
|
|
|
996
1002
|
| `vite` | ^6.4.2, ^7.3.2, or ^8.0.5 |
|
|
997
1003
|
| `vitest` | 4.x or 5.x |
|
|
998
1004
|
| `node` | >= 20.19; RN/RNTL may impose a higher floor |
|
|
999
|
-
| `react-native` (native engine) | 0.81–0.
|
|
1005
|
+
| `react-native` (native engine) | 0.81–0.88 validated |
|
|
1000
1006
|
| `@react-native/babel-preset` (native engine) | Match the installed React Native minor |
|
|
1001
1007
|
| `@testing-library/react-native` (optional) | 12.x, 13.x, or 14.x |
|
|
1002
1008
|
|
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];
|
|
@@ -525,12 +526,14 @@ function runDoctor(root, nodeVersion = process.versions.node) {
|
|
|
525
526
|
lines.push("", "Engine");
|
|
526
527
|
const rnVersion = packageVersion(rootFor("react-native"), "react-native");
|
|
527
528
|
const decision = require_ecosystem.detectEngine("auto", rootFor("@react-native/babel-preset"));
|
|
528
|
-
|
|
529
|
-
|
|
529
|
+
const transformPreset = require_ecosystem.resolveTransformPreset(rootFor("@react-native/babel-preset"));
|
|
530
|
+
const presetLabel = transformPreset ? `${transformPreset.name} ${transformPreset.version}` : "a React Native Babel preset";
|
|
531
|
+
if (decision.engine === "native") pass(`engine 'auto' resolves to NATIVE — real React Native${rnVersion ? ` ${rnVersion}` : ""} with ${presetLabel} + @babel/core present.`);
|
|
532
|
+
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
533
|
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
534
|
if (decision.engine === "native") {
|
|
532
535
|
const inferredRoot = configRoot;
|
|
533
|
-
const inferredEcosystem = require_ecosystem.detectEcosystemPackages([.../* @__PURE__ */ new Set([root, configRoot])], [], root === configRoot ? [] : [root], [], activePresets(root));
|
|
536
|
+
const inferredEcosystem = require_ecosystem.detectEcosystemPackages([.../* @__PURE__ */ new Set([root, configRoot])], [], root === configRoot ? [] : [root], [], activePresets(root, [], decision.engine));
|
|
534
537
|
const inferredOwnership = require_ecosystem.createNativeOwnershipPolicy({
|
|
535
538
|
projectRoot: inferredRoot,
|
|
536
539
|
ecosystemPackages: inferredEcosystem,
|
|
@@ -562,22 +565,25 @@ function runDoctor(root, nodeVersion = process.versions.node) {
|
|
|
562
565
|
}
|
|
563
566
|
lines.push("", "Auto-detected presets");
|
|
564
567
|
const detected = [];
|
|
568
|
+
let installedAny = false;
|
|
565
569
|
for (const [pkg, preset] of Object.entries(require_preset_map.AUTO_DETECT_PRESETS)) {
|
|
566
570
|
if (!installedManifest(root, pkg)) continue;
|
|
571
|
+
installedAny = true;
|
|
567
572
|
if (installedTestsItself(root, pkg)) lines.push(` · ${pkg} ${installedMajor(root, pkg)} runs its own test mode under Vitest, so no preset replaces it`);
|
|
573
|
+
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
574
|
else detected.push(`${pkg} → ${preset}`);
|
|
569
575
|
}
|
|
570
576
|
if (detected.length) for (const d of detected) pass(d);
|
|
571
|
-
else lines.push(" (none — no preset-covered packages installed)");
|
|
577
|
+
else if (!installedAny) lines.push(" (none — no preset-covered packages installed)");
|
|
572
578
|
const expo = packageVersion(rootFor("expo"), "expo");
|
|
573
579
|
if (expo) {
|
|
574
580
|
lines.push("", "Expo");
|
|
575
|
-
pass(`expo ${expo} detected.
|
|
581
|
+
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
582
|
}
|
|
577
583
|
const babel = readBabelConfig(root);
|
|
578
584
|
if (babel.source) {
|
|
579
585
|
lines.push("", "Babel");
|
|
580
|
-
const classified = classifyBabelPlugins(babel, root, activePresets(root));
|
|
586
|
+
const classified = classifyBabelPlugins(babel, root, activePresets(root, [], decision.engine));
|
|
581
587
|
const required = classified.filter((p) => p.verdict === "required");
|
|
582
588
|
for (const p of classified) if (p.verdict === "required") warn(`${p.reason} Required: ${babelRecipe(viteMajor(rootFor("vite")), required)}.`);
|
|
583
589
|
else if (p.verdict === "alias") warn(`${p.reason} \`vitest-native migrate\` writes them; otherwise add them to resolve.alias.`);
|
|
@@ -1409,11 +1415,13 @@ function list(items) {
|
|
|
1409
1415
|
return items.length <= 1 ? items[0] ?? "" : `${items.slice(0, -1).join(", ")} and ${items[items.length - 1]}`;
|
|
1410
1416
|
}
|
|
1411
1417
|
/**
|
|
1412
|
-
*
|
|
1413
|
-
*
|
|
1418
|
+
* How Expo modules run after migrating. The generated config uses the native engine,
|
|
1419
|
+
* where Expo modules run their own JavaScript on native-module mocks, as jest-expo
|
|
1420
|
+
* runs them; the expo preset applies to the mock engine only (preset-map's
|
|
1421
|
+
* NATIVE_ENGINE_RUNS_PACKAGES).
|
|
1414
1422
|
*/
|
|
1415
1423
|
function expoPresetCoverage() {
|
|
1416
|
-
return
|
|
1424
|
+
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
1425
|
}
|
|
1418
1426
|
/** Escape a literal for a JavaScript regex literal (including `/`). */
|
|
1419
1427
|
function regexLiteral(literal) {
|
package/dist/cli.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
2
|
+
import { f as validatePeerDependency, i as createNativeOwnershipPolicy, n as detectEngine, r as resolveTransformPreset, s as formatNativeOwnershipManifest, t as detectEcosystemPackages, u as PEER_REQUIREMENTS } from "./ecosystem-D6e1OVOg.mjs";
|
|
3
|
+
import { i as autoDetectedPresetApplies, n as DEFAULT_ASSET_EXTS, o as presetShadowing, r as PRESET_MODULES, s as testsItself, t as AUTO_DETECT_PRESETS } from "./preset-map-BlBriTA0.mjs";
|
|
4
4
|
import { n as formatHotMemoryPlan, t as createHotMemoryPlan } from "./memory-FYbP0_gg.mjs";
|
|
5
5
|
import { createRequire } from "node:module";
|
|
6
6
|
import fs from "node:fs";
|
|
@@ -61,12 +61,13 @@ function installedTestsItself(root, pkg) {
|
|
|
61
61
|
/**
|
|
62
62
|
* The presets a run in this project enables, decided as the plugin decides it: a
|
|
63
63
|
* preset is active when one of its packages is installed and does not test itself,
|
|
64
|
-
* and the user has not switched it
|
|
64
|
+
* the engine applies it (autoDetectedPresetApplies), and the user has not switched it
|
|
65
|
+
* off.
|
|
65
66
|
*/
|
|
66
|
-
function activePresets(root, disabled = []) {
|
|
67
|
+
function activePresets(root, disabled = [], engine = "native") {
|
|
67
68
|
const active = /* @__PURE__ */ new Set();
|
|
68
69
|
for (const [pkg, preset] of Object.entries(AUTO_DETECT_PRESETS)) {
|
|
69
|
-
if (disabled.includes(preset)) continue;
|
|
70
|
+
if (disabled.includes(preset) || !autoDetectedPresetApplies(preset, engine)) continue;
|
|
70
71
|
if (installedManifest(root, pkg) && !installedTestsItself(root, pkg)) active.add(preset);
|
|
71
72
|
}
|
|
72
73
|
return [...active];
|
|
@@ -521,12 +522,14 @@ function runDoctor(root, nodeVersion = process.versions.node) {
|
|
|
521
522
|
lines.push("", "Engine");
|
|
522
523
|
const rnVersion = packageVersion(rootFor("react-native"), "react-native");
|
|
523
524
|
const decision = detectEngine("auto", rootFor("@react-native/babel-preset"));
|
|
524
|
-
|
|
525
|
-
|
|
525
|
+
const transformPreset = resolveTransformPreset(rootFor("@react-native/babel-preset"));
|
|
526
|
+
const presetLabel = transformPreset ? `${transformPreset.name} ${transformPreset.version}` : "a React Native Babel preset";
|
|
527
|
+
if (decision.engine === "native") pass(`engine 'auto' resolves to NATIVE — real React Native${rnVersion ? ` ${rnVersion}` : ""} with ${presetLabel} + @babel/core present.`);
|
|
528
|
+
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.`);
|
|
526
529
|
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.");
|
|
527
530
|
if (decision.engine === "native") {
|
|
528
531
|
const inferredRoot = configRoot;
|
|
529
|
-
const inferredEcosystem = detectEcosystemPackages([.../* @__PURE__ */ new Set([root, configRoot])], [], root === configRoot ? [] : [root], [], activePresets(root));
|
|
532
|
+
const inferredEcosystem = detectEcosystemPackages([.../* @__PURE__ */ new Set([root, configRoot])], [], root === configRoot ? [] : [root], [], activePresets(root, [], decision.engine));
|
|
530
533
|
const inferredOwnership = createNativeOwnershipPolicy({
|
|
531
534
|
projectRoot: inferredRoot,
|
|
532
535
|
ecosystemPackages: inferredEcosystem,
|
|
@@ -558,22 +561,25 @@ function runDoctor(root, nodeVersion = process.versions.node) {
|
|
|
558
561
|
}
|
|
559
562
|
lines.push("", "Auto-detected presets");
|
|
560
563
|
const detected = [];
|
|
564
|
+
let installedAny = false;
|
|
561
565
|
for (const [pkg, preset] of Object.entries(AUTO_DETECT_PRESETS)) {
|
|
562
566
|
if (!installedManifest(root, pkg)) continue;
|
|
567
|
+
installedAny = true;
|
|
563
568
|
if (installedTestsItself(root, pkg)) lines.push(` · ${pkg} ${installedMajor(root, pkg)} runs its own test mode under Vitest, so no preset replaces it`);
|
|
569
|
+
else if (!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 }\``);
|
|
564
570
|
else detected.push(`${pkg} → ${preset}`);
|
|
565
571
|
}
|
|
566
572
|
if (detected.length) for (const d of detected) pass(d);
|
|
567
|
-
else lines.push(" (none — no preset-covered packages installed)");
|
|
573
|
+
else if (!installedAny) lines.push(" (none — no preset-covered packages installed)");
|
|
568
574
|
const expo = packageVersion(rootFor("expo"), "expo");
|
|
569
575
|
if (expo) {
|
|
570
576
|
lines.push("", "Expo");
|
|
571
|
-
pass(`expo ${expo} detected.
|
|
577
|
+
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 ${PRESET_MODULES.expo.join(", ")}). ` : `expo ${expo} detected. Under the mock engine the expo preset shadows ${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`);
|
|
572
578
|
}
|
|
573
579
|
const babel = readBabelConfig(root);
|
|
574
580
|
if (babel.source) {
|
|
575
581
|
lines.push("", "Babel");
|
|
576
|
-
const classified = classifyBabelPlugins(babel, root, activePresets(root));
|
|
582
|
+
const classified = classifyBabelPlugins(babel, root, activePresets(root, [], decision.engine));
|
|
577
583
|
const required = classified.filter((p) => p.verdict === "required");
|
|
578
584
|
for (const p of classified) if (p.verdict === "required") warn(`${p.reason} Required: ${babelRecipe(viteMajor(rootFor("vite")), required)}.`);
|
|
579
585
|
else if (p.verdict === "alias") warn(`${p.reason} \`vitest-native migrate\` writes them; otherwise add them to resolve.alias.`);
|
|
@@ -1405,11 +1411,13 @@ function list(items) {
|
|
|
1405
1411
|
return items.length <= 1 ? items[0] ?? "" : `${items.slice(0, -1).join(", ")} and ${items[items.length - 1]}`;
|
|
1406
1412
|
}
|
|
1407
1413
|
/**
|
|
1408
|
-
*
|
|
1409
|
-
*
|
|
1414
|
+
* How Expo modules run after migrating. The generated config uses the native engine,
|
|
1415
|
+
* where Expo modules run their own JavaScript on native-module mocks, as jest-expo
|
|
1416
|
+
* runs them; the expo preset applies to the mock engine only (preset-map's
|
|
1417
|
+
* NATIVE_ENGINE_RUNS_PACKAGES).
|
|
1410
1418
|
*/
|
|
1411
1419
|
function expoPresetCoverage() {
|
|
1412
|
-
return
|
|
1420
|
+
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";
|
|
1413
1421
|
}
|
|
1414
1422
|
/** Escape a literal for a JavaScript regex literal (including `/`). */
|
|
1415
1423
|
function regexLiteral(literal) {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { n as VitestNativeTypeError } from "./errors-CxoBUfVJ.mjs";
|
|
2
|
-
import { t as AUTO_DETECT_PRESETS } from "./preset-map-
|
|
2
|
+
import { t as AUTO_DETECT_PRESETS } from "./preset-map-BlBriTA0.mjs";
|
|
3
3
|
import { createRequire } from "node:module";
|
|
4
4
|
import fs from "node:fs";
|
|
5
5
|
import path from "node:path";
|
|
@@ -626,6 +626,54 @@ function formatNativeOwnershipManifest(input) {
|
|
|
626
626
|
if (manifest.enforcement === "overridden-by-inline-all") lines.push("WARNING: server.deps.inline=true takes precedence over Node ownership; graph uniqueness is not guaranteed");
|
|
627
627
|
return lines;
|
|
628
628
|
}
|
|
629
|
+
//#endregion
|
|
630
|
+
//#region src/native/babel-preset.mjs
|
|
631
|
+
/**
|
|
632
|
+
* The Babel preset the native engine compiles React Native and node_modules with,
|
|
633
|
+
* resolved from the project: the preset the project's Metro applies when the project
|
|
634
|
+
* has no Babel config of its own.
|
|
635
|
+
*
|
|
636
|
+
* - `@react-native/babel-preset`: React Native CLI projects, and Expo before SDK 56,
|
|
637
|
+
* whose babel-preset-expo depends on it.
|
|
638
|
+
* - `expo/internal/babel-preset` (babel-preset-expo): Expo from SDK 56. Its
|
|
639
|
+
* babel-preset-expo carries React Native's plugins itself and no longer depends on
|
|
640
|
+
* @react-native/babel-preset, so a project created from an SDK 56+ template has none
|
|
641
|
+
* installed. Expo's Metro (@expo/metro-config, loadBabelConfig) and jest-expo
|
|
642
|
+
* (src/resolveBabelOptions.js) load this preset in a project without a Babel config.
|
|
643
|
+
*
|
|
644
|
+
* The React Native preset is tried first, so a project that has it keeps compiling
|
|
645
|
+
* exactly as before. Null when neither resolves.
|
|
646
|
+
*
|
|
647
|
+
* @param {string} projectRoot
|
|
648
|
+
* @returns {{ name: string, file: string, version: string, packageDir: string } | null}
|
|
649
|
+
*/
|
|
650
|
+
function resolveTransformPreset(projectRoot) {
|
|
651
|
+
const req = createRequire(path.join(projectRoot, "package.json"));
|
|
652
|
+
try {
|
|
653
|
+
const manifest = req.resolve("@react-native/babel-preset/package.json");
|
|
654
|
+
return {
|
|
655
|
+
name: "@react-native/babel-preset",
|
|
656
|
+
file: path.dirname(manifest),
|
|
657
|
+
version: readVersion(manifest),
|
|
658
|
+
packageDir: path.dirname(manifest)
|
|
659
|
+
};
|
|
660
|
+
} catch {}
|
|
661
|
+
try {
|
|
662
|
+
const file = req.resolve("expo/internal/babel-preset");
|
|
663
|
+
const manifest = createRequire(file).resolve("babel-preset-expo/package.json");
|
|
664
|
+
return {
|
|
665
|
+
name: "babel-preset-expo",
|
|
666
|
+
file,
|
|
667
|
+
version: readVersion(manifest),
|
|
668
|
+
packageDir: path.dirname(manifest)
|
|
669
|
+
};
|
|
670
|
+
} catch {
|
|
671
|
+
return null;
|
|
672
|
+
}
|
|
673
|
+
}
|
|
674
|
+
function readVersion(manifest) {
|
|
675
|
+
return JSON.parse(fs.readFileSync(manifest, "utf8")).version;
|
|
676
|
+
}
|
|
629
677
|
/**
|
|
630
678
|
* The native engine's dependencies that do NOT resolve from the project root.
|
|
631
679
|
*
|
|
@@ -641,10 +689,11 @@ function missingNativeDeps(projectRoot) {
|
|
|
641
689
|
const req = createRequire(path.join(projectRoot, "package.json"));
|
|
642
690
|
const missing = [];
|
|
643
691
|
if (!reactNativeInstalledNear(projectRoot)) missing.push("react-native");
|
|
644
|
-
|
|
645
|
-
|
|
692
|
+
if (resolveTransformPreset(projectRoot) === null) missing.push("@react-native/babel-preset");
|
|
693
|
+
try {
|
|
694
|
+
req.resolve("@babel/core");
|
|
646
695
|
} catch {
|
|
647
|
-
missing.push(
|
|
696
|
+
missing.push("@babel/core");
|
|
648
697
|
}
|
|
649
698
|
return missing;
|
|
650
699
|
}
|
|
@@ -967,4 +1016,4 @@ function detectEcosystemPackages(projectRoot, explicit = [], testRoots = [], nev
|
|
|
967
1016
|
return [...inClosure].sort();
|
|
968
1017
|
}
|
|
969
1018
|
//#endregion
|
|
970
|
-
export {
|
|
1019
|
+
export { findNativeInlineConflicts as a, containsPath as c, validateOptions as d, validatePeerDependency as f, createNativeOwnershipPolicy as i, packageDirOf as l, detectEngine as n, findNativeOwnershipConflict as o, warnUnknownOptions as p, resolveTransformPreset as r, formatNativeOwnershipManifest as s, detectEcosystemPackages as t, PEER_REQUIREMENTS as u };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
const require_rolldown_runtime = require("./rolldown-runtime-C0BPl7ul.cjs");
|
|
2
2
|
const require_errors = require("./errors-B3lJK46O.cjs");
|
|
3
|
-
const require_preset_map = require("./preset-map-
|
|
3
|
+
const require_preset_map = require("./preset-map-jSFsNy1Q.cjs");
|
|
4
4
|
let node_fs = require("node:fs");
|
|
5
5
|
node_fs = require_rolldown_runtime.__toESM(node_fs, 1);
|
|
6
6
|
let node_path = require("node:path");
|
|
@@ -629,6 +629,54 @@ function formatNativeOwnershipManifest(input) {
|
|
|
629
629
|
if (manifest.enforcement === "overridden-by-inline-all") lines.push("WARNING: server.deps.inline=true takes precedence over Node ownership; graph uniqueness is not guaranteed");
|
|
630
630
|
return lines;
|
|
631
631
|
}
|
|
632
|
+
//#endregion
|
|
633
|
+
//#region src/native/babel-preset.mjs
|
|
634
|
+
/**
|
|
635
|
+
* The Babel preset the native engine compiles React Native and node_modules with,
|
|
636
|
+
* resolved from the project: the preset the project's Metro applies when the project
|
|
637
|
+
* has no Babel config of its own.
|
|
638
|
+
*
|
|
639
|
+
* - `@react-native/babel-preset`: React Native CLI projects, and Expo before SDK 56,
|
|
640
|
+
* whose babel-preset-expo depends on it.
|
|
641
|
+
* - `expo/internal/babel-preset` (babel-preset-expo): Expo from SDK 56. Its
|
|
642
|
+
* babel-preset-expo carries React Native's plugins itself and no longer depends on
|
|
643
|
+
* @react-native/babel-preset, so a project created from an SDK 56+ template has none
|
|
644
|
+
* installed. Expo's Metro (@expo/metro-config, loadBabelConfig) and jest-expo
|
|
645
|
+
* (src/resolveBabelOptions.js) load this preset in a project without a Babel config.
|
|
646
|
+
*
|
|
647
|
+
* The React Native preset is tried first, so a project that has it keeps compiling
|
|
648
|
+
* exactly as before. Null when neither resolves.
|
|
649
|
+
*
|
|
650
|
+
* @param {string} projectRoot
|
|
651
|
+
* @returns {{ name: string, file: string, version: string, packageDir: string } | null}
|
|
652
|
+
*/
|
|
653
|
+
function resolveTransformPreset(projectRoot) {
|
|
654
|
+
const req = (0, node_module.createRequire)(node_path.default.join(projectRoot, "package.json"));
|
|
655
|
+
try {
|
|
656
|
+
const manifest = req.resolve("@react-native/babel-preset/package.json");
|
|
657
|
+
return {
|
|
658
|
+
name: "@react-native/babel-preset",
|
|
659
|
+
file: node_path.default.dirname(manifest),
|
|
660
|
+
version: readVersion(manifest),
|
|
661
|
+
packageDir: node_path.default.dirname(manifest)
|
|
662
|
+
};
|
|
663
|
+
} catch {}
|
|
664
|
+
try {
|
|
665
|
+
const file = req.resolve("expo/internal/babel-preset");
|
|
666
|
+
const manifest = (0, node_module.createRequire)(file).resolve("babel-preset-expo/package.json");
|
|
667
|
+
return {
|
|
668
|
+
name: "babel-preset-expo",
|
|
669
|
+
file,
|
|
670
|
+
version: readVersion(manifest),
|
|
671
|
+
packageDir: node_path.default.dirname(manifest)
|
|
672
|
+
};
|
|
673
|
+
} catch {
|
|
674
|
+
return null;
|
|
675
|
+
}
|
|
676
|
+
}
|
|
677
|
+
function readVersion(manifest) {
|
|
678
|
+
return JSON.parse(node_fs.default.readFileSync(manifest, "utf8")).version;
|
|
679
|
+
}
|
|
632
680
|
/**
|
|
633
681
|
* The native engine's dependencies that do NOT resolve from the project root.
|
|
634
682
|
*
|
|
@@ -644,10 +692,11 @@ function missingNativeDeps(projectRoot) {
|
|
|
644
692
|
const req = (0, node_module.createRequire)(node_path.default.join(projectRoot, "package.json"));
|
|
645
693
|
const missing = [];
|
|
646
694
|
if (!reactNativeInstalledNear(projectRoot)) missing.push("react-native");
|
|
647
|
-
|
|
648
|
-
|
|
695
|
+
if (resolveTransformPreset(projectRoot) === null) missing.push("@react-native/babel-preset");
|
|
696
|
+
try {
|
|
697
|
+
req.resolve("@babel/core");
|
|
649
698
|
} catch {
|
|
650
|
-
missing.push(
|
|
699
|
+
missing.push("@babel/core");
|
|
651
700
|
}
|
|
652
701
|
return missing;
|
|
653
702
|
}
|
|
@@ -1024,6 +1073,12 @@ Object.defineProperty(exports, "packageDirOf", {
|
|
|
1024
1073
|
return packageDirOf;
|
|
1025
1074
|
}
|
|
1026
1075
|
});
|
|
1076
|
+
Object.defineProperty(exports, "resolveTransformPreset", {
|
|
1077
|
+
enumerable: true,
|
|
1078
|
+
get: function() {
|
|
1079
|
+
return resolveTransformPreset;
|
|
1080
|
+
}
|
|
1081
|
+
});
|
|
1027
1082
|
Object.defineProperty(exports, "validateOptions", {
|
|
1028
1083
|
enumerable: true,
|
|
1029
1084
|
get: function() {
|
package/dist/index.mjs
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { n as VitestNativeTypeError, t as VitestNativeError } from "./errors-CxoBUfVJ.mjs";
|
|
2
|
-
import { a as
|
|
2
|
+
import { a as findNativeInlineConflicts, c as containsPath, d as validateOptions, f as validatePeerDependency, i as createNativeOwnershipPolicy, l as packageDirOf, n as detectEngine, o as findNativeOwnershipConflict, p as warnUnknownOptions, s as formatNativeOwnershipManifest, t as detectEcosystemPackages, u as PEER_REQUIREMENTS } from "./ecosystem-D6e1OVOg.mjs";
|
|
3
3
|
import { n as presetFromModule } from "./preset-modules-CG8-G82P.mjs";
|
|
4
|
-
import { M as BUILT_IN_PRESET, t as presets_exports } from "./presets
|
|
5
|
-
import {
|
|
4
|
+
import { M as BUILT_IN_PRESET, t as presets_exports } from "./presets--zrEWQC2.mjs";
|
|
5
|
+
import { a as presetForInstalled, i as autoDetectedPresetApplies, n as DEFAULT_ASSET_EXTS, r as PRESET_MODULES, t as AUTO_DETECT_PRESETS } from "./preset-map-BlBriTA0.mjs";
|
|
6
6
|
import { t as workerVitestMismatch } from "./worker-vitest-BGPo0ek6.mjs";
|
|
7
7
|
import { createRequire } from "node:module";
|
|
8
8
|
import fs from "node:fs";
|
|
@@ -848,7 +848,7 @@ async function resolveOptions(options = {}, projectRoot, resolution) {
|
|
|
848
848
|
else {
|
|
849
849
|
const detected = await autoDetectPresets(diagnostics, root);
|
|
850
850
|
const disabled = disabledPresetNames(options.presets);
|
|
851
|
-
builtIn =
|
|
851
|
+
builtIn = detected.filter((p) => !disabled.has(p.name) && autoDetectedPresetApplies(p.name, engine, options.presets));
|
|
852
852
|
}
|
|
853
853
|
const presets = [...builtIn, ...await loadPresetModules(modulePaths, root)];
|
|
854
854
|
return {
|
|
@@ -1537,7 +1537,7 @@ function reactNative(options) {
|
|
|
1537
1537
|
const jsxTransform = getJsxTransformConfig(resolvedRoot);
|
|
1538
1538
|
const decision = detectEngine(requestedEngine, resolvedRoot);
|
|
1539
1539
|
engine = decision.engine;
|
|
1540
|
-
if (engine === "native" && !decision.nativeAvailable) throw new VitestNativeError("ENGINE_REQUIRES_BABEL", `engine:'native' requires react-native, '@react-native/babel-preset', and '@babel/core' to resolve from ${resolvedRoot} — missing: ${decision.missing.join(", ")}. React Native projects ship all three by default. Install what's missing (react-native as a dependency, the toolchain as devDependencies), or set engine:'mock' to run without a React Native install.`);
|
|
1540
|
+
if (engine === "native" && !decision.nativeAvailable) throw new VitestNativeError("ENGINE_REQUIRES_BABEL", `engine:'native' requires react-native, a React Native Babel preset ('@react-native/babel-preset', or Expo's from SDK 56), and '@babel/core' to resolve from ${resolvedRoot} — missing: ${decision.missing.join(", ")}. React Native and Expo projects ship all three by default. Install what's missing (react-native as a dependency, the toolchain as devDependencies), or set engine:'mock' to run without a React Native install.`);
|
|
1541
1541
|
if (decision.notice) console.warn(decision.notice);
|
|
1542
1542
|
if (engine !== "native") printEngineBanner(engine, platform, resolvedRoot);
|
|
1543
1543
|
const env = {
|
|
@@ -1566,7 +1566,7 @@ function reactNative(options) {
|
|
|
1566
1566
|
if (options?.mocks && Object.keys(options.mocks).length > 0) throw new VitestNativeError("MOCKS_REQUIRE_MOCK_ENGINE", "The \"mocks\" option is only supported by engine:'mock'. The native engine runs the real react-native module and cannot safely merge arbitrary exports into it. Use vi.mock() in a setup file, mockNativeModule() for native modules, or set engine:'mock'.");
|
|
1567
1567
|
const disabledNative = disabledPresetNames(options?.presets);
|
|
1568
1568
|
const selection = selectPresets(options?.presets, resolvedRoot);
|
|
1569
|
-
const nativePresetNames = selection.listed ? selection.listed.map((p) => p.name) : autoDetectPresetNames(resolvedRoot, diagnostics).filter((n) => !disabledNative.has(n));
|
|
1569
|
+
const nativePresetNames = selection.listed ? selection.listed.map((p) => p.name) : autoDetectPresetNames(resolvedRoot, diagnostics).filter((n) => !disabledNative.has(n) && autoDetectedPresetApplies(n, "native", options?.presets));
|
|
1570
1570
|
if (nativePresetNames.length > 0) env.VITEST_NATIVE_PRESET_NAMES = JSON.stringify(nativePresetNames);
|
|
1571
1571
|
if (selection.modulePaths.length > 0) env.VITEST_NATIVE_PRESET_MODULES = JSON.stringify(selection.modulePaths);
|
|
1572
1572
|
if (selection.listed) {
|
|
@@ -1730,7 +1730,10 @@ function reactNative(options) {
|
|
|
1730
1730
|
const error = validatePeerDependency(name, minimum, config.root, maximumMajor, minimumByMajor);
|
|
1731
1731
|
if (error && !error.includes("not found")) console.warn(`[vitest-native] ${error}`);
|
|
1732
1732
|
}
|
|
1733
|
-
resolved = await resolveOptions(
|
|
1733
|
+
resolved = await resolveOptions({
|
|
1734
|
+
...options,
|
|
1735
|
+
engine
|
|
1736
|
+
}, config.root, {
|
|
1734
1737
|
extensions,
|
|
1735
1738
|
assetExts: assetExtList
|
|
1736
1739
|
});
|