vitest-native 0.14.0-rc.4 → 0.14.0-rc.6

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.
Files changed (52) hide show
  1. package/CHANGELOG.md +116 -0
  2. package/README.md +14 -6
  3. package/dist/cli.cjs +31 -16
  4. package/dist/cli.mjs +31 -16
  5. package/dist/{ecosystem-CWnXwWCk.mjs → ecosystem-BzWGVo_T.mjs} +4 -2
  6. package/dist/{ecosystem-D18-tC1Z.cjs → ecosystem-DTozsAyV.cjs} +4 -2
  7. package/dist/errors.d.mts +4 -0
  8. package/dist/helpers.cjs +0 -6
  9. package/dist/helpers.mjs +0 -6
  10. package/dist/{index-BxzW2D7K.d.cts → index-BSyUeoga.d.mts} +49 -9
  11. package/dist/{index-CEbwa4QU.d.mts → index-bZ7AHqLc.d.cts} +50 -8
  12. package/dist/index.d.mts +1 -1
  13. package/dist/index.mjs +344 -26
  14. package/dist/jest-compat/jest-object.mjs +5 -3
  15. package/dist/jest-compat/node-registry.mjs +434 -0
  16. package/dist/jest-compat/setup.mjs +98 -73
  17. package/dist/jest-compat.cjs +34 -2
  18. package/dist/jest-compat.d.cts +5 -0
  19. package/dist/jest-compat.d.mts +5 -0
  20. package/dist/jest-compat.mjs +34 -2
  21. package/dist/matchers.d.cts +2 -1
  22. package/dist/matchers.d.mts +2 -1
  23. package/dist/native/assets.d.mts +39 -0
  24. package/dist/native/assets.mjs +431 -0
  25. package/dist/native/boundary.mjs +40 -4
  26. package/dist/native/hooks.mjs +46 -26
  27. package/dist/native/loader.mjs +19 -14
  28. package/dist/native/module-reset.mjs +29 -0
  29. package/dist/native/native-modules.d.mts +18 -0
  30. package/dist/native/native-modules.mjs +245 -0
  31. package/dist/native/registry.mjs +36 -12
  32. package/dist/native/reset.mjs +29 -0
  33. package/dist/native/resolve.mjs +74 -8
  34. package/dist/native/setup.mjs +78 -9
  35. package/dist/native/state-manifest.mjs +2 -0
  36. package/dist/native/transform.mjs +133 -15
  37. package/dist/native/worker.mjs +6 -10
  38. package/dist/{preset-map-CtNv1AGU.cjs → preset-map-B-T1CcPr.cjs} +8 -3
  39. package/dist/{preset-map-C9L_UtZa.mjs → preset-map-DO-dKDgr.mjs} +8 -3
  40. package/dist/preset-modules-BoLkaeEN.cjs +53 -0
  41. package/dist/preset-modules-CG8-G82P.mjs +36 -0
  42. package/dist/preset-modules.d.mts +16 -0
  43. package/dist/preset-modules.mjs +101 -0
  44. package/dist/preset-ready.mjs +9 -0
  45. package/dist/{presets-BYHmi7-W.cjs → presets-Bpy47wwV.cjs} +969 -78
  46. package/dist/{presets-DC-eM5IA.mjs → presets-C8vJ2Vnl.mjs} +951 -79
  47. package/dist/presets.d.mts +2 -2
  48. package/dist/presets.mjs +1 -2
  49. package/dist/setup.mjs +100 -17
  50. package/docs/migrating-from-jest.md +5 -3
  51. package/docs/versioning.md +14 -6
  52. package/package.json +29 -23
package/CHANGELOG.md CHANGED
@@ -26,9 +26,111 @@
26
26
  `process.env.JEST_WORKER_ID` is set, so code that checks for Jest takes its test branch.
27
27
  - **`hotRuntime: true` is stricter.** Combined with a configured pool, `test.isolate`, or a conflicting
28
28
  CLI flag, it now fails at startup with `HOT_RUNTIME_OVERRIDDEN` instead of warning and overriding.
29
+ - **Native modules answer as on a device.** Under the native engine, `NativeModules[name]` and
30
+ `TurboModuleRegistry.get(name)` are `undefined`/`null` for a module no app registers, and a React
31
+ Native module's stub has only the methods its codegen spec declares. Register a module a test needs
32
+ with `mockNativeModule(name, impl)`; `nativeModules: 'permissive'` restores the earlier behaviour.
33
+ - **Assets are registered ids.** `require('./logo.png')` evaluates to the number React Native's asset
34
+ registry assigned, as with Metro, instead of the file name. Snapshots that contained an asset's name
35
+ change; re-record them with `-u`.
36
+ - **`jest.mock` reaches `require()`.** With jest-compat, a `jest.mock` factory now applies to
37
+ `require()`, `jest.requireActual`'s dependencies and React Native's own requires of a mocked internal;
38
+ `jest.isolateModules` and `jest.isolateModulesAsync` work. TypeScript app files that Node loads are
39
+ compiled with the project's Babel config, as babel-jest compiles them.
40
+ - **Unistyles and Skia are mocked automatically.** The new `unistyles` and `skia` presets are
41
+ auto-detected. Remove Unistyles' `react-native-unistyles/mocks` setup file, whose `jest.mock()` calls
42
+ would replace the preset (`vitest-native migrate` removes it), and a hand-written Skia mock, which the
43
+ preset replaces. Skia's preset loads CanvasKit before each test file, about 20–30 ms;
44
+ `presets: { skia: false }` turns it off.
45
+ - **Presets of your own are listed by path.** A preset object of a project's own passed to `presets`
46
+ used to shadow its packages with undefined exports; it is now refused at startup. List the module that
47
+ exports it instead: `presets: { './test/presets/my-lib.ts': true }`.
29
48
 
30
49
  ### Minor Changes
31
50
 
51
+ - 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
+
53
+ - styles resolve as the device parses them: breakpoint values and `mq` keys against the screen, `_web` styles dropped;
54
+ - variants and compound variants apply by the device's rules, selected with `useVariants`;
55
+ - `StyleSheet.configure()` validates its input and picks the theme with the device runtime's messages; adaptive themes follow the colour scheme, and `setTheme`, `updateTheme` and `setAdaptiveThemes` take effect;
56
+ - `useUnistyles()`, `withUnistyles`, `Display`, `Hide` and `ScopedTheme` re-render on a theme or screen change;
57
+ - `ScopedTheme` scopes a theme to its children, and `withUnistyles` applies `uniProps`;
58
+ - `Display` and `Hide` follow `mq` against the screen size;
59
+ - `StyleSheet.flatten`, `compose`, `absoluteFill` and `hairlineWidth` are React Native's, as on a device;
60
+ - `resetAllMocks()` returns the theme to what `StyleSheet.configure()` set.
61
+
62
+ `vitest-native migrate` now deletes a library's own test setup file (such as `react-native-unistyles/mocks`) when a detected preset shadows that library, since its `jest.mock()` calls would replace the preset.
63
+
64
+ - 12a6dc5: A `skia` preset for Skia, which threw at import in tests ("Native Skia Module failed to correctly install JSI Bindings"). It covers both of Skia's package names, `react-native-skia` (2.15.0 and 3.x) and `@shopify/react-native-skia` (up to 2.14.0), shadows whichever is installed, and works under both engines.
65
+
66
+ - It loads CanvasKit, Skia compiled to WebAssembly, and serves Skia's own test mock over it, so the `Skia` API computes with real Skia, and `Canvas` and its drawing render as Views.
67
+ - Its named exports are read from the installed version's ESM build, since Skia's API changes between releases.
68
+ - It adds Skia's Reanimated helpers (`usePathValue`, `useTexture`, …), which the mock leaves out, and makes `matchFont` return a font.
69
+
70
+ The `Preset` type gains an optional async `prepare()`, which completes before any of the user's setup files or test files load, and `PresetModule` an optional `exportsFor()`, which reads the module's named exports from the installed package (or returns `null` when it is not installed, leaving it unshadowed). The skia preset uses both.
71
+
72
+ The project root given to test workers now follows `test.root` (or `--root`), as Vitest's does; a run started from a parent directory resolved packages from that directory in every worker.
73
+
74
+ - 51c351d: Presets of a project's own now work. A preset object passed to `presets: [...]` shadowed its packages with modules whose every export was undefined, under both engines: each test worker rebuilds the presets by name from vitest-native's own, and a preset's factories, being functions, cannot reach a worker from the config. A preset is now listed by the path of a module that default-exports it (or a function returning it): `presets: { './test/presets/my-lib.ts': true }` beside auto-detection, or `presets: ['./test/presets/my-lib.ts']` in a full list. The plugin reads its name and export names while loading the config, and each worker imports it, through Vitest so a TypeScript module loads. A preset object that is not exactly what one of vitest-native's factories returned, such as a built-in preset copied or extended, is refused at configuration time, naming the module form.
75
+
76
+ - 6724815: Native engine: native module lookups answer the way a device does
77
+
78
+ `NativeModules[name]` and `TurboModuleRegistry.get(name)` returned a stub for every name, so a module that no app registers looked present. Library feature detection then took the wrong branch: expo-constants checks `NativeModules.EXDevLauncher` and, finding it, threw at import while parsing the stub's `manifestString` as JSON.
79
+
80
+ React Native returns `undefined` from `NativeModules[name]` and `null` from `TurboModuleRegistry.get(name)` for an unregistered module, and Jest's React Native preset does the same. The native engine now does too:
81
+
82
+ - React Native's own native modules stay present for every lookup. The set is read from the installed `react-native`: every name its JavaScript passes to `TurboModuleRegistry.get` or `getEnforcing`, so it follows the project's React Native version.
83
+ - A React Native module's stub has only the members of its codegen spec, read from the same installed copy. Any other property is `undefined`, as on a device. A stub that answered every name with a function broke code that probes objects for optional properties: Node's `EventEmitter` read `captureRejections` from `NativeKeyboardObserver` when a test mocked `NativeEventEmitter` with it.
84
+ - `TurboModuleRegistry.getEnforcing(name)` still returns a stub for any name, where React Native would throw, so code that requires a native module keeps running without setup.
85
+ - A module registered with `mockNativeModule()` is present for all three lookups. Under the hot runtime, a registration a test file leaves behind is removed before the next file runs.
86
+
87
+ `nativeModules: 'permissive'` restores the earlier behaviour (every name present, every member a method) for a suite that depends on it.
88
+
89
+ If a test relied on an unregistered module being present through `NativeModules` or `TurboModuleRegistry.get`, or on a method a React Native module's spec does not declare, register it with `mockNativeModule(name, impl)` from `vitest-native/helpers`, in the test or a setup file.
90
+
91
+ - 3d20592: jest-compat: one module registry per test file, as in Jest. A `jest.mock(spec, factory)` (and `jest.doMock`, `jest.setMock`) now applies to `require()` from a test, to the modules `jest.requireActual` loads, and to React Native's own requires of a mocked internal such as `react-native/Libraries/AppState/AppState`, with the same mock instance the file's imports see. `jest.requireActual` unmocks only the module requested, `jest.requireMock` returns the registered mock instead of the real module, and `jest.resetModules()` gives `require()` fresh project modules and re-runs mock factories while React Native stays loaded. `jest.isolateModules` and `jest.isolateModulesAsync`, which previously threw, are implemented with Jest's semantics. A project module the test has imported is the instance `require()` returns. Registrations last for one test file, including in a reused worker. Factory-less mocks (automock and `__mocks__`) still apply to imports only.
92
+
93
+ TypeScript project files that Node loads are now compiled as babel-jest compiles them, with the options `@babel/core` loads for each file (any config format, `overrides`, and env- or caller-dependent configs). In a project with Expo, Babel sees jest-expo's Metro caller for the configured platform. The transform cache is keyed on those options, and a file the config ignores fails with "Babel ignores …", as under babel-jest. Relative requires from any file Node loads resolve as Metro resolves them: in its platform-extension order, with a trailing `/` naming the directory, and through a directory's `package.json` `react-native`, `browser` or `main` field. `jest.isolateModules` nesting throws Jest's exact error. Without `jestCompatSetup`, a `jest.mock` factory now fails with an error naming it (`JEST_COMPAT_SETUP_MISSING`).
94
+
95
+ - 12d413a: Asset imports and requires evaluate to what Metro gives an app: a registered asset id
96
+
97
+ `require('./logo.png')`, `import font from './Icon.ttf'` and every other asset now evaluate to a
98
+ number — the id React Native's asset registry assigned to the asset — instead of the file's name.
99
+ The module is the one Metro generates (`module.exports = require(assetRegistryPath).registerAsset({…})`),
100
+ with the descriptor Metro's `getAssetData` produces: `name`, `type`, `scales`, `hash`,
101
+ `httpServerLocation` and, for images, `width` and `height` in points. React Native code that consumes
102
+ assets therefore behaves as on device. `Image.resolveAssetSource(require('./splash.png'))` used to
103
+ return `null`, because a file name is not a registered id, so code such as
104
+ `Image.resolveAssetSource(source)!.uri` threw.
105
+
106
+ - **Native engine.** Assets register with React Native's own registry — the module Metro's
107
+ `assetRegistryPath` names (`react-native/asset-registry` on 0.87 and later,
108
+ `react-native/Libraries/Image/AssetRegistry` before) — on every load path: Vite-graph imports,
109
+ requires and imports through Node, and React Native's own image assets. `resolveAssetSource`,
110
+ `<Image source={require(…)}>` and `AssetRegistry.getAssetByID` resolve them.
111
+ - **Mock engine.** Assets register with the mock `AssetRegistry`, and the mock
112
+ `Image.resolveAssetSource` resolves a registered id as React Native does (the same URI the native
113
+ engine produces, on iOS and Android). The mock `AssetRegistry` now keeps its entries across
114
+ `resetAllMocks()`: React Native's registry has no reset, and an asset module's id must stay valid
115
+ for every test in the file.
116
+ - **Expo.** In a project `expo` resolves from, assets carry what Expo's bundler adds: `fileHashes`
117
+ and the Expo CLI dev server's asset location. expo-asset then resolves them through Expo, as in an
118
+ Expo app. The descriptor is checked against `getUniversalAssetData` from the installed Expo.
119
+ - **Scales and platforms.** `@2x`/`@3x` variants group as in Metro: `scales` lists them, the
120
+ dimensions are the smallest variant's divided by its scale, and resolution picks the variant for
121
+ the device's pixel ratio. A `.ios`/`.android` variant is preferred for the configured platform.
122
+ - **Dimensions** are read from PNG, JPEG, GIF, BMP and WebP headers, with no new dependency. SVG,
123
+ TIFF, PSD and KTX images, which Metro also measures, and files that are not valid images register
124
+ without `width` and `height`; Metro would fail the build on the latter.
125
+
126
+ ### Upgrading
127
+
128
+ Snapshots that contained an asset's file name now contain its registered id (a number), and under
129
+ the native engine a rendered `<Image source={require('./logo.png')} />` snapshots the resolved
130
+ source (`uri`, `width`, `height`, `scale`). Ids are assigned in registration order within a test
131
+ file, so they are stable for a given file. Update affected snapshots with `vitest -u`. Assertions
132
+ that compared an asset to its file name can compare `Image.resolveAssetSource(asset).uri` instead.
133
+
32
134
  - 52e80aa: Turn on Vitest 5's persistent transform cache, with a complete cache key
33
135
 
34
136
  On Vitest 5 the plugin turns on Vitest's persistent transform cache (`fsModuleCache`) unless the
@@ -76,6 +178,20 @@
76
178
 
77
179
  ### Patch Changes
78
180
 
181
+ - 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
+
183
+ - 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.
184
+
185
+ - df06716: Under the native engine, an imported BMP image's `width` and `height` are read as Metro 0.87.1 reads them. An OS/2 bitmap (12-byte header) now has its real dimensions instead of a misread width, and a file whose header size is not a bitmap's registers without dimensions, as other unreadable images do.
186
+
187
+ - dc2543b: `migrate` writes Jest's mock-clearing behaviour correctly:
188
+
189
+ - Jest's `resetMocks` becomes `test.mockReset`, Vitest's name for it. It was written as `test.resetMocks`, which Vitest ignores.
190
+ - When the Jest config does not set `clearMocks`, the generated config sets `clearMocks: false`, Jest's default. Vitest 5 defaults it to `true`, which clears calls mocks received while modules loaded before each test.
191
+
192
+ - b10cce3: `migrate` no longer says the test script's flags were "mapped above" when the script has no flags.
193
+ - 3d20592: Native engine: a module the require hooks resolve themselves (Metro's platform-extension scan, the project's aliases, React Native's deep paths) is now keyed by its real path, as Node keys its own resolutions. A file reached through a symlink, or on Windows an alias target written with `/`, loaded a second time and gave two instances of one module.
194
+
79
195
  - 041fd77: Fix native-engine gaps found running a production Expo app's existing suite
80
196
 
81
197
  - React Native's setup now runs before the project's own setup files. A setup file that imported `react-native` or `@testing-library/react-native` failed on React Native's Flow source whenever the hot runtime was not in use.
package/README.md CHANGED
@@ -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
- - [Asset Stubs](#asset-stubs)
34
+ - [Assets](#assets)
35
35
  - [Diagnostics](#diagnostics)
36
36
  - [Support Policy](#support-policy)
37
37
  - [Requirements](#requirements)
@@ -555,6 +555,8 @@ export default defineConfig({
555
555
  | `presets.flashList()` | `@shopify/flash-list` | `FlashList` rendering its data through `renderItem`, the ref surface, v2 recycler hooks |
556
556
  | `presets.bottomSheet()` | `@gorhom/bottom-sheet` | `BottomSheet`, `BottomSheetModal` + provider, sheet views, scroll/list variants, `BottomSheetTextInput`, backdrop, footer |
557
557
  | `presets.keyboardController()` | `react-native-keyboard-controller` | `KeyboardProvider`, `KeyboardAvoidingView`, `KeyboardAwareScrollView`, `KeyboardStickyView`, `KeyboardToolbar`; the imperative `KeyboardController` is inert |
558
+ | `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 |
559
+ | `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 |
558
560
 
559
561
  Presets apply under **both** engines: the mock engine and `engine: 'native'` (where they shadow each
560
562
  library's native runtime — worklets, native modules — exactly as Jest does, while the surrounding tree
@@ -914,15 +916,21 @@ falling back to the default (often web) file.
914
916
 
915
917
  ---
916
918
 
917
- ## Asset Stubs
919
+ ## Assets
918
920
 
919
- Image, font, video, and audio imports are automatically stubbed. The import resolves to the filename string, so code that passes asset paths through continues to work without errors.
921
+ 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:
920
922
 
921
- ```ts
922
- import logo from "./logo.png";
923
- // logo === 'logo.png'
923
+ ```tsx
924
+ const logo = require("./logo.png"); // a number
925
+ Image.resolveAssetSource(logo); // { uri, width, height, scale, __packager_asset: true }
926
+ <Image source={logo} />; // renders the resolved asset
924
927
  ```
925
928
 
929
+ - `@2x`/`@3x` variants are grouped as Metro groups them, and a `.ios`/`.android` variant is preferred for the configured platform.
930
+ - Dimensions are read from PNG, JPEG, GIF, BMP and WebP headers; other formats, and files that are not valid images, register without them.
931
+ - The native engine registers with React Native's real registry; the mock engine registers with the mock `AssetRegistry`, which its `Image.resolveAssetSource` reads.
932
+ - 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.
933
+
926
934
  Built-in extensions include common formats like `.png`, `.jpg`, `.gif`, `.svg`, `.mp4`, `.ttf`, `.otf`, and more. To add additional extensions:
927
935
 
928
936
  ```ts
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-D18-tC1Z.cjs");
5
- const require_preset_map = require("./preset-map-CtNv1AGU.cjs");
4
+ const require_ecosystem = require("./ecosystem-DTozsAyV.cjs");
5
+ const require_preset_map = require("./preset-map-B-T1CcPr.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);
@@ -13,6 +13,7 @@ let node_module = require("node:module");
13
13
  const HOT_STATE_MANIFEST_ENTRIES = Object.freeze([
14
14
  "vitest-runtime",
15
15
  "native-boundary-mocks",
16
+ "native-module-mocks",
16
17
  "react-native.dimensions",
17
18
  "react-native.appearance",
18
19
  "react-native.event-listeners",
@@ -21,7 +22,8 @@ const HOT_STATE_MANIFEST_ENTRIES = Object.freeze([
21
22
  "global.descriptors",
22
23
  "console.descriptors",
23
24
  "react-native.error-utils",
24
- "expo.runtime"
25
+ "expo.runtime",
26
+ "jest-compat.node-mocks"
25
27
  ]);
26
28
  //#endregion
27
29
  //#region src/cli/manifest.ts
@@ -1529,14 +1531,19 @@ function analyzeJestConfig(root) {
1529
1531
  for (const key of ["setupFiles", "setupFilesAfterEnv"]) {
1530
1532
  const files = take(key);
1531
1533
  if (!files?.length) continue;
1532
- for (const f of files) if (/react-native\/jest\/setup/.test(f)) presetCovered.push(`${key}: '${f}' — the plugin injects its own setup; delete.`);
1533
- else if (/jest-expo/.test(f)) attention.push(`${key}: '${f}' — ${expoPresetCoverage()}.`);
1534
- else if (f.startsWith("<rootDir>")) {
1535
- setupFiles.push(absolutePath(f.replace(/^<rootDir>\/?/, "./")));
1536
- automatic.push(`${key}: '${f}' → test.setupFiles (its jest.* calls run under the jest-compat shim).`);
1537
- } else {
1538
- setupFiles.push(JSON.stringify(f));
1539
- automatic.push(`${key}: '${f}' → test.setupFiles (its jest.* calls run under the jest-compat shim).`);
1534
+ for (const f of files) {
1535
+ const setupPackage = /^(@[^/]+\/[^/]+|[^@./][^/]*)\//.exec(f)?.[1];
1536
+ const setupPreset = setupPackage ? require_preset_map.presetShadowing(setupPackage) : void 0;
1537
+ if (/react-native\/jest\/setup/.test(f)) presetCovered.push(`${key}: '${f}' — the plugin injects its own setup; delete.`);
1538
+ else if (setupPreset && active.includes(setupPreset)) presetCovered.push(`${key}: '${f}' — ${setupPackage}'s own test setup; the auto-detected ${setupPreset} preset shadows ${setupPackage}, and this file's jest.mock() calls would replace it; delete.`);
1539
+ else if (/jest-expo/.test(f)) attention.push(`${key}: '${f}' — ${expoPresetCoverage()}.`);
1540
+ else if (f.startsWith("<rootDir>")) {
1541
+ setupFiles.push(absolutePath(f.replace(/^<rootDir>\/?/, "./")));
1542
+ automatic.push(`${key}: '${f}' → test.setupFiles (its jest.* calls run under the jest-compat shim).`);
1543
+ } else {
1544
+ setupFiles.push(JSON.stringify(f));
1545
+ automatic.push(`${key}: '${f}' → test.setupFiles (its jest.* calls run under the jest-compat shim).`);
1546
+ }
1540
1547
  }
1541
1548
  }
1542
1549
  const mapper = take("moduleNameMapper");
@@ -1546,10 +1553,10 @@ function analyzeJestConfig(root) {
1546
1553
  if (assetGroup) {
1547
1554
  const exts = assetGroup[1].toLowerCase().split("|");
1548
1555
  const missing = exts.filter((e) => !require_preset_map.DEFAULT_ASSET_EXTS.includes(e));
1549
- if (missing.length === 0) presetCovered.push(`moduleNameMapper '${pattern}' — the plugin stubs ${list(exts)} imports itself; delete.`);
1556
+ if (missing.length === 0) presetCovered.push(`moduleNameMapper '${pattern}' — the plugin handles ${list(exts)} imports itself; delete.`);
1550
1557
  else {
1551
1558
  pluginOptions.push(`assetExts: ${JSON.stringify(missing)}`);
1552
- automatic.push(`moduleNameMapper '${pattern}' — ${list(missing)} ${missing.length === 1 ? "is" : "are"} not among the extensions the plugin stubs by default → reactNative({ assetExts: ${JSON.stringify(missing)} }).`);
1559
+ automatic.push(`moduleNameMapper '${pattern}' — ${list(missing)} ${missing.length === 1 ? "is" : "are"} not among the extensions the plugin handles by default → reactNative({ assetExts: ${JSON.stringify(missing)} }).`);
1553
1560
  }
1554
1561
  } else if (/^\^?@\/|\^~\/|\^src\//.test(pattern)) {
1555
1562
  const aliasKey = pattern.replace(/[\^$]/g, "").replace(/\((\.\*|\.\+)\)\$?$/, "").replace(/\/$/, "");
@@ -1628,7 +1635,10 @@ function analyzeJestConfig(root) {
1628
1635
  } else attention.push(`scripts.test passes --${name}${value === true ? "" : `=${value}`} to Jest — no automatic mapping; pass the Vitest equivalent on the vitest command line if it still matters.`);
1629
1636
  }
1630
1637
  if (scriptFlags?.positional.length) attention.push(`scripts.test passes test path patterns ${JSON.stringify(scriptFlags.positional)} — pass them to \`vitest run\` as filters.`);
1631
- if (scriptFlags) attention.push("scripts.test runs Jest — point it at `vitest run` once the suite passes (its flags are mapped above).");
1638
+ if (scriptFlags) {
1639
+ const mapped = scriptFlags.flags.size > 0 ? " (its flags are mapped above)" : "";
1640
+ attention.push(`scripts.test runs Jest — point it at \`vitest run\` once the suite passes${mapped}.`);
1641
+ }
1632
1642
  if (otherJestScripts.length) attention.push(`${otherJestScripts.length === 1 ? "script" : "scripts"} ${list(otherJestScripts)} also ${otherJestScripts.length === 1 ? "runs" : "run"} Jest; only scripts.test was read for flags.`);
1633
1643
  const env = take("testEnvironment");
1634
1644
  if (env && env !== "node") attention.push(`testEnvironment: '${env}' — vitest-native suites run under 'node'; review.`);
@@ -1678,11 +1688,16 @@ function analyzeJestConfig(root) {
1678
1688
  handled.add(key);
1679
1689
  if (key === "transform") dropped.push(`transform — Babel/esbuild transforms are the plugin's job; dropped.`);
1680
1690
  else if (key === "clearMocks" || key === "resetMocks" || key === "restoreMocks") {
1681
- automatic.push(`${key} → test.${key} (same name in Vitest).`);
1682
- testEntries.push(`${key}: ${JSON.stringify(config[key])}`);
1691
+ const vitestKey = key === "resetMocks" ? "mockReset" : key;
1692
+ automatic.push(key === vitestKey ? `${key} → test.${key} (same name in Vitest).` : `${key} → test.${vitestKey} (Vitest's name for it).`);
1693
+ testEntries.push(`${vitestKey}: ${JSON.stringify(config[key])}`);
1683
1694
  } else if (key === "snapshotSerializers") attention.push(`snapshotSerializers — Vitest uses expect.addSnapshotSerializer; vitest-native ships one for RN trees.`);
1684
1695
  else dropped.push(`${key} — no vitest-native equivalent needed; dropped.`);
1685
1696
  }
1697
+ if (config.clearMocks === void 0) {
1698
+ testEntries.push(`clearMocks: false`);
1699
+ automatic.push("Jest keeps mock calls between tests unless clearMocks is set → test.clearMocks: false (Vitest 5 clears them before each test by default).");
1700
+ }
1686
1701
  for (const key of Object.keys(config)) if (!handled.has(key)) attention.push(`'${key}' — unrecognized Jest key; review manually.`);
1687
1702
  }
1688
1703
  const mocksDir = node_path.default.join(root, "__mocks__");
package/dist/cli.mjs CHANGED
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env node
2
- import { d as validatePeerDependency, l as PEER_REQUIREMENTS, n as detectEngine, o as formatNativeOwnershipManifest, r as createNativeOwnershipPolicy, t as detectEcosystemPackages } from "./ecosystem-CWnXwWCk.mjs";
3
- import { a as presetShadowing, n as DEFAULT_ASSET_EXTS, o as testsItself, r as PRESET_MODULES, t as AUTO_DETECT_PRESETS } from "./preset-map-C9L_UtZa.mjs";
2
+ import { d as validatePeerDependency, l as PEER_REQUIREMENTS, n as detectEngine, o as formatNativeOwnershipManifest, r as createNativeOwnershipPolicy, t as detectEcosystemPackages } from "./ecosystem-BzWGVo_T.mjs";
3
+ import { a as presetShadowing, n as DEFAULT_ASSET_EXTS, o as testsItself, r as PRESET_MODULES, t as AUTO_DETECT_PRESETS } from "./preset-map-DO-dKDgr.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";
@@ -9,6 +9,7 @@ import path from "node:path";
9
9
  const HOT_STATE_MANIFEST_ENTRIES = Object.freeze([
10
10
  "vitest-runtime",
11
11
  "native-boundary-mocks",
12
+ "native-module-mocks",
12
13
  "react-native.dimensions",
13
14
  "react-native.appearance",
14
15
  "react-native.event-listeners",
@@ -17,7 +18,8 @@ const HOT_STATE_MANIFEST_ENTRIES = Object.freeze([
17
18
  "global.descriptors",
18
19
  "console.descriptors",
19
20
  "react-native.error-utils",
20
- "expo.runtime"
21
+ "expo.runtime",
22
+ "jest-compat.node-mocks"
21
23
  ]);
22
24
  //#endregion
23
25
  //#region src/cli/manifest.ts
@@ -1525,14 +1527,19 @@ function analyzeJestConfig(root) {
1525
1527
  for (const key of ["setupFiles", "setupFilesAfterEnv"]) {
1526
1528
  const files = take(key);
1527
1529
  if (!files?.length) continue;
1528
- for (const f of files) if (/react-native\/jest\/setup/.test(f)) presetCovered.push(`${key}: '${f}' — the plugin injects its own setup; delete.`);
1529
- else if (/jest-expo/.test(f)) attention.push(`${key}: '${f}' — ${expoPresetCoverage()}.`);
1530
- else if (f.startsWith("<rootDir>")) {
1531
- setupFiles.push(absolutePath(f.replace(/^<rootDir>\/?/, "./")));
1532
- automatic.push(`${key}: '${f}' → test.setupFiles (its jest.* calls run under the jest-compat shim).`);
1533
- } else {
1534
- setupFiles.push(JSON.stringify(f));
1535
- automatic.push(`${key}: '${f}' → test.setupFiles (its jest.* calls run under the jest-compat shim).`);
1530
+ for (const f of files) {
1531
+ const setupPackage = /^(@[^/]+\/[^/]+|[^@./][^/]*)\//.exec(f)?.[1];
1532
+ const setupPreset = setupPackage ? presetShadowing(setupPackage) : void 0;
1533
+ if (/react-native\/jest\/setup/.test(f)) presetCovered.push(`${key}: '${f}' — the plugin injects its own setup; delete.`);
1534
+ else if (setupPreset && active.includes(setupPreset)) presetCovered.push(`${key}: '${f}' — ${setupPackage}'s own test setup; the auto-detected ${setupPreset} preset shadows ${setupPackage}, and this file's jest.mock() calls would replace it; delete.`);
1535
+ else if (/jest-expo/.test(f)) attention.push(`${key}: '${f}' — ${expoPresetCoverage()}.`);
1536
+ else if (f.startsWith("<rootDir>")) {
1537
+ setupFiles.push(absolutePath(f.replace(/^<rootDir>\/?/, "./")));
1538
+ automatic.push(`${key}: '${f}' → test.setupFiles (its jest.* calls run under the jest-compat shim).`);
1539
+ } else {
1540
+ setupFiles.push(JSON.stringify(f));
1541
+ automatic.push(`${key}: '${f}' → test.setupFiles (its jest.* calls run under the jest-compat shim).`);
1542
+ }
1536
1543
  }
1537
1544
  }
1538
1545
  const mapper = take("moduleNameMapper");
@@ -1542,10 +1549,10 @@ function analyzeJestConfig(root) {
1542
1549
  if (assetGroup) {
1543
1550
  const exts = assetGroup[1].toLowerCase().split("|");
1544
1551
  const missing = exts.filter((e) => !DEFAULT_ASSET_EXTS.includes(e));
1545
- if (missing.length === 0) presetCovered.push(`moduleNameMapper '${pattern}' — the plugin stubs ${list(exts)} imports itself; delete.`);
1552
+ if (missing.length === 0) presetCovered.push(`moduleNameMapper '${pattern}' — the plugin handles ${list(exts)} imports itself; delete.`);
1546
1553
  else {
1547
1554
  pluginOptions.push(`assetExts: ${JSON.stringify(missing)}`);
1548
- automatic.push(`moduleNameMapper '${pattern}' — ${list(missing)} ${missing.length === 1 ? "is" : "are"} not among the extensions the plugin stubs by default → reactNative({ assetExts: ${JSON.stringify(missing)} }).`);
1555
+ automatic.push(`moduleNameMapper '${pattern}' — ${list(missing)} ${missing.length === 1 ? "is" : "are"} not among the extensions the plugin handles by default → reactNative({ assetExts: ${JSON.stringify(missing)} }).`);
1549
1556
  }
1550
1557
  } else if (/^\^?@\/|\^~\/|\^src\//.test(pattern)) {
1551
1558
  const aliasKey = pattern.replace(/[\^$]/g, "").replace(/\((\.\*|\.\+)\)\$?$/, "").replace(/\/$/, "");
@@ -1624,7 +1631,10 @@ function analyzeJestConfig(root) {
1624
1631
  } else attention.push(`scripts.test passes --${name}${value === true ? "" : `=${value}`} to Jest — no automatic mapping; pass the Vitest equivalent on the vitest command line if it still matters.`);
1625
1632
  }
1626
1633
  if (scriptFlags?.positional.length) attention.push(`scripts.test passes test path patterns ${JSON.stringify(scriptFlags.positional)} — pass them to \`vitest run\` as filters.`);
1627
- if (scriptFlags) attention.push("scripts.test runs Jest — point it at `vitest run` once the suite passes (its flags are mapped above).");
1634
+ if (scriptFlags) {
1635
+ const mapped = scriptFlags.flags.size > 0 ? " (its flags are mapped above)" : "";
1636
+ attention.push(`scripts.test runs Jest — point it at \`vitest run\` once the suite passes${mapped}.`);
1637
+ }
1628
1638
  if (otherJestScripts.length) attention.push(`${otherJestScripts.length === 1 ? "script" : "scripts"} ${list(otherJestScripts)} also ${otherJestScripts.length === 1 ? "runs" : "run"} Jest; only scripts.test was read for flags.`);
1629
1639
  const env = take("testEnvironment");
1630
1640
  if (env && env !== "node") attention.push(`testEnvironment: '${env}' — vitest-native suites run under 'node'; review.`);
@@ -1674,11 +1684,16 @@ function analyzeJestConfig(root) {
1674
1684
  handled.add(key);
1675
1685
  if (key === "transform") dropped.push(`transform — Babel/esbuild transforms are the plugin's job; dropped.`);
1676
1686
  else if (key === "clearMocks" || key === "resetMocks" || key === "restoreMocks") {
1677
- automatic.push(`${key} → test.${key} (same name in Vitest).`);
1678
- testEntries.push(`${key}: ${JSON.stringify(config[key])}`);
1687
+ const vitestKey = key === "resetMocks" ? "mockReset" : key;
1688
+ automatic.push(key === vitestKey ? `${key} → test.${key} (same name in Vitest).` : `${key} → test.${vitestKey} (Vitest's name for it).`);
1689
+ testEntries.push(`${vitestKey}: ${JSON.stringify(config[key])}`);
1679
1690
  } else if (key === "snapshotSerializers") attention.push(`snapshotSerializers — Vitest uses expect.addSnapshotSerializer; vitest-native ships one for RN trees.`);
1680
1691
  else dropped.push(`${key} — no vitest-native equivalent needed; dropped.`);
1681
1692
  }
1693
+ if (config.clearMocks === void 0) {
1694
+ testEntries.push(`clearMocks: false`);
1695
+ automatic.push("Jest keeps mock calls between tests unless clearMocks is set → test.clearMocks: false (Vitest 5 clears them before each test by default).");
1696
+ }
1682
1697
  for (const key of Object.keys(config)) if (!handled.has(key)) attention.push(`'${key}' — unrecognized Jest key; review manually.`);
1683
1698
  }
1684
1699
  const mocksDir = path.join(root, "__mocks__");
@@ -1,5 +1,5 @@
1
1
  import { n as VitestNativeTypeError } from "./errors-CxoBUfVJ.mjs";
2
- import { t as AUTO_DETECT_PRESETS } from "./preset-map-C9L_UtZa.mjs";
2
+ import { t as AUTO_DETECT_PRESETS } from "./preset-map-DO-dKDgr.mjs";
3
3
  import { createRequire } from "node:module";
4
4
  import fs from "node:fs";
5
5
  import path from "node:path";
@@ -13,7 +13,8 @@ const KNOWN_OPTIONS = [
13
13
  "metroConfig",
14
14
  "engine",
15
15
  "transform",
16
- "hotRuntime"
16
+ "hotRuntime",
17
+ "nativeModules"
17
18
  ];
18
19
  const KNOWN_HOT_RUNTIME_OPTIONS = [
19
20
  "recycleAfterFiles",
@@ -32,6 +33,7 @@ function assertNonNegativeInteger(value, option) {
32
33
  function validateOptions(options) {
33
34
  if (options.engine !== void 0 && options.engine !== "auto" && options.engine !== "mock" && options.engine !== "native") throw new VitestNativeTypeError("INVALID_OPTION", `"engine" must be "auto", "mock", or "native".`);
34
35
  if (options.platform !== void 0 && options.platform !== "ios" && options.platform !== "android") throw new VitestNativeTypeError("INVALID_OPTION", `"platform" must be "ios" or "android".`);
36
+ if (options.nativeModules !== void 0 && options.nativeModules !== "device" && options.nativeModules !== "permissive") throw new VitestNativeTypeError("INVALID_OPTION", `"nativeModules" must be "device" or "permissive".`);
35
37
  if (options.diagnostics !== void 0 && typeof options.diagnostics !== "boolean") throw new VitestNativeTypeError("INVALID_OPTION", `"diagnostics" must be a boolean.`);
36
38
  if (options.assetExts !== void 0) assertStringArray(options.assetExts, "assetExts");
37
39
  if (options.metroConfig !== void 0 && typeof options.metroConfig !== "boolean") {
@@ -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-CtNv1AGU.cjs");
3
+ const require_preset_map = require("./preset-map-B-T1CcPr.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");
@@ -16,7 +16,8 @@ const KNOWN_OPTIONS = [
16
16
  "metroConfig",
17
17
  "engine",
18
18
  "transform",
19
- "hotRuntime"
19
+ "hotRuntime",
20
+ "nativeModules"
20
21
  ];
21
22
  const KNOWN_HOT_RUNTIME_OPTIONS = [
22
23
  "recycleAfterFiles",
@@ -35,6 +36,7 @@ function assertNonNegativeInteger(value, option) {
35
36
  function validateOptions(options) {
36
37
  if (options.engine !== void 0 && options.engine !== "auto" && options.engine !== "mock" && options.engine !== "native") throw new require_errors.VitestNativeTypeError("INVALID_OPTION", `"engine" must be "auto", "mock", or "native".`);
37
38
  if (options.platform !== void 0 && options.platform !== "ios" && options.platform !== "android") throw new require_errors.VitestNativeTypeError("INVALID_OPTION", `"platform" must be "ios" or "android".`);
39
+ if (options.nativeModules !== void 0 && options.nativeModules !== "device" && options.nativeModules !== "permissive") throw new require_errors.VitestNativeTypeError("INVALID_OPTION", `"nativeModules" must be "device" or "permissive".`);
38
40
  if (options.diagnostics !== void 0 && typeof options.diagnostics !== "boolean") throw new require_errors.VitestNativeTypeError("INVALID_OPTION", `"diagnostics" must be a boolean.`);
39
41
  if (options.assetExts !== void 0) assertStringArray(options.assetExts, "assetExts");
40
42
  if (options.metroConfig !== void 0 && typeof options.metroConfig !== "boolean") {
package/dist/errors.d.mts CHANGED
@@ -32,10 +32,14 @@ export type VitestNativeErrorCode =
32
32
  | "HOT_STATE_RESTORE_FAILED"
33
33
  | "HOT_CJS_CACHE_RESET"
34
34
  | "PRESET_UNAVAILABLE"
35
+ | "PRESET_NOT_PREPARED"
35
36
  | "WRONG_ENGINE_FOR_HELPER"
36
37
  | "HELPERS_BEFORE_SETUP"
37
38
  | "JEST_API_UNSUPPORTED"
38
39
  | "REQUIRE_ACTUAL_ALIAS_UNSUPPORTED"
40
+ | "JEST_MOCK_FACTORY_CYCLE"
41
+ | "JEST_COMPAT_SETUP_MISSING"
42
+ | "BABEL_IGNORES_FILE"
39
43
  | "MATCHER_BAD_RECEIVER";
40
44
 
41
45
  export interface VitestNativeErrorOptions {
package/dist/helpers.cjs CHANGED
@@ -23,9 +23,6 @@ function setPlatform(os) {
23
23
  const platform = getMock().Platform;
24
24
  platform.OS = os;
25
25
  platform.Version = os === "ios" ? "17.0" : 34;
26
- platform.select.mockImplementation((specifics) => {
27
- return specifics[os] ?? specifics.default;
28
- });
29
26
  }
30
27
  function setDimensions(dims) {
31
28
  const native = getNativeControl();
@@ -123,9 +120,6 @@ function resetAllMocks() {
123
120
  clearMockFns(mock);
124
121
  mock.Platform.OS = "ios";
125
122
  mock.Platform.Version = "17.0";
126
- mock.Platform.select.mockImplementation((specifics) => {
127
- return specifics.ios ?? specifics.default;
128
- });
129
123
  for (const value of Object.values(mock)) {
130
124
  const candidate = value;
131
125
  if (candidate && typeof candidate === "object" && typeof candidate._reset === "function") candidate._reset();
package/dist/helpers.mjs CHANGED
@@ -22,9 +22,6 @@ function setPlatform(os) {
22
22
  const platform = getMock().Platform;
23
23
  platform.OS = os;
24
24
  platform.Version = os === "ios" ? "17.0" : 34;
25
- platform.select.mockImplementation((specifics) => {
26
- return specifics[os] ?? specifics.default;
27
- });
28
25
  }
29
26
  function setDimensions(dims) {
30
27
  const native = getNativeControl();
@@ -122,9 +119,6 @@ function resetAllMocks() {
122
119
  clearMockFns(mock);
123
120
  mock.Platform.OS = "ios";
124
121
  mock.Platform.Version = "17.0";
125
- mock.Platform.select.mockImplementation((specifics) => {
126
- return specifics.ios ?? specifics.default;
127
- });
128
122
  for (const value of Object.values(mock)) {
129
123
  const candidate = value;
130
124
  if (candidate && typeof candidate === "object" && typeof candidate._reset === "function") candidate._reset();
@@ -1,5 +1,4 @@
1
1
  import { Mock } from "vitest";
2
- //#endregion
3
2
  //#region src/types.d.ts
4
3
  /** Static methods available on the Image component mock. */
5
4
  interface ImageStatic {
@@ -200,10 +199,26 @@ interface PresetModule {
200
199
  factory: () => Record<string, any>;
201
200
  /** Static list of named exports for virtual ESM module generation. Read at Vite config time (no vitest available). */
202
201
  exports: string[];
202
+ /**
203
+ * Named exports read from the installed package, for a package whose API changes
204
+ * between releases; replaces `exports` when present. Called once at Vite config time
205
+ * with the project root and platform. `null` means the package is not installed, so
206
+ * the module is not shadowed at all.
207
+ */
208
+ exportsFor?: (context: {
209
+ projectRoot: string;
210
+ platform: "ios" | "android";
211
+ }) => string[] | null;
203
212
  }
204
213
  interface Preset {
205
214
  name: string;
206
215
  modules: Record<string, PresetModule>;
216
+ /**
217
+ * Optional async work the setup file awaits before each test file, ahead of any
218
+ * `factory`. For a mock that needs something only an async API provides: the skia
219
+ * preset loads CanvasKit (Skia's WebAssembly build) here.
220
+ */
221
+ prepare?: () => Promise<void>;
207
222
  /**
208
223
  * Optional JSON-serializable configuration for the preset. Presets are rebuilt
209
224
  * inside Vitest worker processes from their `name`, so any options passed to a
@@ -251,17 +266,22 @@ interface VitestNativeOptions {
251
266
  * way. Listing every other detected preset back by hand just to drop one is
252
267
  * both tedious and a thing that silently rots as dependencies change.
253
268
  *
254
- * Only built-in presets are supported (reanimated, gestureHandler,
255
- * safeAreaContext, navigation, asyncStorage, screens, expo). For custom
256
- * module mocking, use vi.mock() in a setup file.
269
+ * Preset modules of your own are listed by path: a module whose default export is a
270
+ * `Preset` or a function returning one. In an array they sit beside vitest-native's
271
+ * presets (`presets.reanimated()`, ...); in the object form a path set to `true`
272
+ * adds one to the auto-detected presets. A preset object of your own cannot be
273
+ * listed directly, because its factories run in the test workers, which a function
274
+ * in the config cannot reach; the plugin imports the module there instead. A
275
+ * relative path resolves from the project root.
257
276
  *
258
277
  * @example
259
278
  * ```ts
260
279
  * import { reactNative, presets } from 'vitest-native';
261
- * reactNative({ presets: [presets.reanimated(), presets.navigation()] })
280
+ * reactNative({ presets: { navigation: false, './test/presets/my-lib.ts': true } })
281
+ * reactNative({ presets: [presets.reanimated(), './test/presets/my-lib.ts'] })
262
282
  * ```
263
283
  */
264
- presets?: Preset[] | Record<string, boolean>;
284
+ presets?: (Preset | string)[] | Record<string, boolean>;
265
285
  /**
266
286
  * `engine: 'mock'` only. Plain-data overrides merged into the react-native
267
287
  * module mock.
@@ -277,7 +297,7 @@ interface VitestNativeOptions {
277
297
  mocks?: Record<string, any>;
278
298
  /** Log plugin activity. Default: false */
279
299
  diagnostics?: boolean;
280
- /** Additional asset file extensions to stub (e.g. ['.lottie', '.m4b']) */
300
+ /** Additional asset file extensions, loaded as Metro loads assets (e.g. ['.lottie', '.m4b']) */
281
301
  assetExts?: string[];
282
302
  /**
283
303
  * Experimental. Read the project's declarative Metro resolution profile in a
@@ -382,6 +402,20 @@ interface VitestNativeOptions {
382
402
  preserveGlobals?: string[];
383
403
  esmGeneration?: boolean;
384
404
  };
405
+ /**
406
+ * `engine: 'native'` only. How native module lookups answer.
407
+ *
408
+ * - `'device'`: as on a device. `NativeModules[name]` and
409
+ * `TurboModuleRegistry.get(name)` find React Native's own modules and those
410
+ * registered with `mockNativeModule()`, and are `undefined`/`null` for any other
411
+ * name. A React Native module's stub has only the members of its codegen spec.
412
+ * - `'permissive'`: every name is present for every lookup, and every stub answers
413
+ * every property with a method. An escape hatch for suites written against that
414
+ * behaviour; prefer registering the modules a test needs with `mockNativeModule()`.
415
+ *
416
+ * Default: `'device'`.
417
+ */
418
+ nativeModules?: "device" | "permissive";
385
419
  }
386
420
  //#endregion
387
421
  //#region src/presets/reanimated.d.ts
@@ -434,8 +468,14 @@ declare function keyboardController(): Preset;
434
468
  //#endregion
435
469
  //#region src/presets/worklets.d.ts
436
470
  declare function worklets(): Preset;
471
+ //#endregion
472
+ //#region src/presets/unistyles.d.ts
473
+ declare function unistyles(): Preset;
474
+ //#endregion
475
+ //#region src/presets/skia.d.ts
476
+ declare function skia(): Preset;
437
477
  declare namespace index_d_exports {
438
- export { asyncStorage, bottomSheet, deviceInfo, expo, flashList, gestureHandler, keyboardController, mmkv, navigation, netInfo, reanimated, safeAreaContext, screens, svg, vectorIcons, webview, worklets };
478
+ export { asyncStorage, bottomSheet, deviceInfo, expo, flashList, gestureHandler, keyboardController, mmkv, navigation, netInfo, reanimated, safeAreaContext, screens, skia, svg, unistyles, vectorIcons, webview, worklets };
439
479
  }
440
480
  //#endregion
441
- export { gestureHandler as _, flashList as a, ReactNativeMock as b, svg as c, deviceInfo as d, expo as f, safeAreaContext as g, navigation as h, bottomSheet as i, netInfo as l, asyncStorage as m, worklets as n, vectorIcons as o, screens as p, keyboardController as r, webview as s, index_d_exports as t, mmkv as u, reanimated as v, VitestNativeOptions as x, Preset as y };
481
+ export { VitestNativeOptions as C, ReactNativeMock as S, navigation as _, keyboardController as a, reanimated as b, vectorIcons as c, netInfo as d, mmkv as f, asyncStorage as g, screens as h, worklets as i, webview as l, expo as m, skia as n, bottomSheet as o, deviceInfo as p, unistyles as r, flashList as s, index_d_exports as t, svg as u, safeAreaContext as v, Preset as x, gestureHandler as y };