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

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 (40) hide show
  1. package/CHANGELOG.md +77 -0
  2. package/README.md +12 -6
  3. package/dist/cli.cjs +18 -8
  4. package/dist/cli.mjs +18 -8
  5. package/dist/{ecosystem-D18-tC1Z.cjs → ecosystem-Bg7DgFeG.cjs} +4 -2
  6. package/dist/{ecosystem-CWnXwWCk.mjs → ecosystem-lBGWAeOw.mjs} +4 -2
  7. package/dist/errors.d.mts +3 -0
  8. package/dist/{index-BxzW2D7K.d.cts → index-B40lg28R.d.cts} +15 -1
  9. package/dist/{index-CEbwa4QU.d.mts → index-D7-7BtcM.d.mts} +15 -1
  10. package/dist/index.d.mts +1 -1
  11. package/dist/index.mjs +188 -5
  12. package/dist/jest-compat/jest-object.mjs +5 -3
  13. package/dist/jest-compat/node-registry.mjs +434 -0
  14. package/dist/jest-compat/setup.mjs +98 -73
  15. package/dist/jest-compat.cjs +34 -2
  16. package/dist/jest-compat.d.cts +5 -0
  17. package/dist/jest-compat.d.mts +5 -0
  18. package/dist/jest-compat.mjs +34 -2
  19. package/dist/native/assets.d.mts +39 -0
  20. package/dist/native/assets.mjs +424 -0
  21. package/dist/native/boundary.mjs +40 -4
  22. package/dist/native/hooks.mjs +46 -26
  23. package/dist/native/loader.mjs +14 -13
  24. package/dist/native/module-reset.mjs +29 -0
  25. package/dist/native/native-modules.d.mts +18 -0
  26. package/dist/native/native-modules.mjs +245 -0
  27. package/dist/native/registry.mjs +36 -12
  28. package/dist/native/reset.mjs +29 -0
  29. package/dist/native/resolve.mjs +74 -8
  30. package/dist/native/setup.mjs +4 -1
  31. package/dist/native/state-manifest.mjs +2 -0
  32. package/dist/native/transform.mjs +133 -15
  33. package/dist/native/worker.mjs +6 -10
  34. package/dist/{preset-map-C9L_UtZa.mjs → preset-map-mriqY254.mjs} +1 -1
  35. package/dist/{preset-map-CtNv1AGU.cjs → preset-map-mzfu_YUy.cjs} +1 -1
  36. package/dist/presets.d.mts +1 -1
  37. package/dist/setup.mjs +64 -6
  38. package/docs/migrating-from-jest.md +5 -3
  39. package/docs/versioning.md +1 -1
  40. package/package.json +3 -2
package/CHANGELOG.md CHANGED
@@ -26,9 +26,78 @@
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.
29
40
 
30
41
  ### Minor Changes
31
42
 
43
+ - 6724815: Native engine: native module lookups answer the way a device does
44
+
45
+ `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.
46
+
47
+ 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:
48
+
49
+ - 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.
50
+ - 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.
51
+ - `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.
52
+ - 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.
53
+
54
+ `nativeModules: 'permissive'` restores the earlier behaviour (every name present, every member a method) for a suite that depends on it.
55
+
56
+ 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.
57
+
58
+ - 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.
59
+
60
+ 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`).
61
+
62
+ - 12d413a: Asset imports and requires evaluate to what Metro gives an app: a registered asset id
63
+
64
+ `require('./logo.png')`, `import font from './Icon.ttf'` and every other asset now evaluate to a
65
+ number — the id React Native's asset registry assigned to the asset — instead of the file's name.
66
+ The module is the one Metro generates (`module.exports = require(assetRegistryPath).registerAsset({…})`),
67
+ with the descriptor Metro's `getAssetData` produces: `name`, `type`, `scales`, `hash`,
68
+ `httpServerLocation` and, for images, `width` and `height` in points. React Native code that consumes
69
+ assets therefore behaves as on device. `Image.resolveAssetSource(require('./splash.png'))` used to
70
+ return `null`, because a file name is not a registered id, so code such as
71
+ `Image.resolveAssetSource(source)!.uri` threw.
72
+
73
+ - **Native engine.** Assets register with React Native's own registry — the module Metro's
74
+ `assetRegistryPath` names (`react-native/asset-registry` on 0.87 and later,
75
+ `react-native/Libraries/Image/AssetRegistry` before) — on every load path: Vite-graph imports,
76
+ requires and imports through Node, and React Native's own image assets. `resolveAssetSource`,
77
+ `<Image source={require(…)}>` and `AssetRegistry.getAssetByID` resolve them.
78
+ - **Mock engine.** Assets register with the mock `AssetRegistry`, and the mock
79
+ `Image.resolveAssetSource` resolves a registered id as React Native does (the same URI the native
80
+ engine produces, on iOS and Android). The mock `AssetRegistry` now keeps its entries across
81
+ `resetAllMocks()`: React Native's registry has no reset, and an asset module's id must stay valid
82
+ for every test in the file.
83
+ - **Expo.** In a project `expo` resolves from, assets carry what Expo's bundler adds: `fileHashes`
84
+ and the Expo CLI dev server's asset location. expo-asset then resolves them through Expo, as in an
85
+ Expo app. The descriptor is checked against `getUniversalAssetData` from the installed Expo.
86
+ - **Scales and platforms.** `@2x`/`@3x` variants group as in Metro: `scales` lists them, the
87
+ dimensions are the smallest variant's divided by its scale, and resolution picks the variant for
88
+ the device's pixel ratio. A `.ios`/`.android` variant is preferred for the configured platform.
89
+ - **Dimensions** are read from PNG, JPEG, GIF, BMP and WebP headers, with no new dependency. SVG,
90
+ TIFF, PSD and KTX images, which Metro also measures, and files that are not valid images register
91
+ without `width` and `height`; Metro would fail the build on the latter.
92
+
93
+ ### Upgrading
94
+
95
+ Snapshots that contained an asset's file name now contain its registered id (a number), and under
96
+ the native engine a rendered `<Image source={require('./logo.png')} />` snapshots the resolved
97
+ source (`uri`, `width`, `height`, `scale`). Ids are assigned in registration order within a test
98
+ file, so they are stable for a given file. Update affected snapshots with `vitest -u`. Assertions
99
+ that compared an asset to its file name can compare `Image.resolveAssetSource(asset).uri` instead.
100
+
32
101
  - 52e80aa: Turn on Vitest 5's persistent transform cache, with a complete cache key
33
102
 
34
103
  On Vitest 5 the plugin turns on Vitest's persistent transform cache (`fsModuleCache`) unless the
@@ -76,6 +145,14 @@
76
145
 
77
146
  ### Patch Changes
78
147
 
148
+ - dc2543b: `migrate` writes Jest's mock-clearing behaviour correctly:
149
+
150
+ - Jest's `resetMocks` becomes `test.mockReset`, Vitest's name for it. It was written as `test.resetMocks`, which Vitest ignores.
151
+ - 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.
152
+
153
+ - b10cce3: `migrate` no longer says the test script's flags were "mapped above" when the script has no flags.
154
+ - 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.
155
+
79
156
  - 041fd77: Fix native-engine gaps found running a production Expo app's existing suite
80
157
 
81
158
  - 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)
@@ -914,15 +914,21 @@ falling back to the default (often web) file.
914
914
 
915
915
  ---
916
916
 
917
- ## Asset Stubs
917
+ ## Assets
918
918
 
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.
919
+ 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
920
 
921
- ```ts
922
- import logo from "./logo.png";
923
- // logo === 'logo.png'
921
+ ```tsx
922
+ const logo = require("./logo.png"); // a number
923
+ Image.resolveAssetSource(logo); // { uri, width, height, scale, __packager_asset: true }
924
+ <Image source={logo} />; // renders the resolved asset
924
925
  ```
925
926
 
927
+ - `@2x`/`@3x` variants are grouped as Metro groups them, and a `.ios`/`.android` variant is preferred for the configured platform.
928
+ - Dimensions are read from PNG, JPEG, GIF, BMP and WebP headers; other formats, and files that are not valid images, register without them.
929
+ - The native engine registers with React Native's real registry; the mock engine registers with the mock `AssetRegistry`, which its `Image.resolveAssetSource` reads.
930
+ - 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.
931
+
926
932
  Built-in extensions include common formats like `.png`, `.jpg`, `.gif`, `.svg`, `.mp4`, `.ttf`, `.otf`, and more. To add additional extensions:
927
933
 
928
934
  ```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-Bg7DgFeG.cjs");
5
+ const require_preset_map = require("./preset-map-mzfu_YUy.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
@@ -1546,10 +1548,10 @@ function analyzeJestConfig(root) {
1546
1548
  if (assetGroup) {
1547
1549
  const exts = assetGroup[1].toLowerCase().split("|");
1548
1550
  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.`);
1551
+ if (missing.length === 0) presetCovered.push(`moduleNameMapper '${pattern}' — the plugin handles ${list(exts)} imports itself; delete.`);
1550
1552
  else {
1551
1553
  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)} }).`);
1554
+ 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
1555
  }
1554
1556
  } else if (/^\^?@\/|\^~\/|\^src\//.test(pattern)) {
1555
1557
  const aliasKey = pattern.replace(/[\^$]/g, "").replace(/\((\.\*|\.\+)\)\$?$/, "").replace(/\/$/, "");
@@ -1628,7 +1630,10 @@ function analyzeJestConfig(root) {
1628
1630
  } 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
1631
  }
1630
1632
  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).");
1633
+ if (scriptFlags) {
1634
+ const mapped = scriptFlags.flags.size > 0 ? " (its flags are mapped above)" : "";
1635
+ attention.push(`scripts.test runs Jest — point it at \`vitest run\` once the suite passes${mapped}.`);
1636
+ }
1632
1637
  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
1638
  const env = take("testEnvironment");
1634
1639
  if (env && env !== "node") attention.push(`testEnvironment: '${env}' — vitest-native suites run under 'node'; review.`);
@@ -1678,11 +1683,16 @@ function analyzeJestConfig(root) {
1678
1683
  handled.add(key);
1679
1684
  if (key === "transform") dropped.push(`transform — Babel/esbuild transforms are the plugin's job; dropped.`);
1680
1685
  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])}`);
1686
+ const vitestKey = key === "resetMocks" ? "mockReset" : key;
1687
+ automatic.push(key === vitestKey ? `${key} → test.${key} (same name in Vitest).` : `${key} → test.${vitestKey} (Vitest's name for it).`);
1688
+ testEntries.push(`${vitestKey}: ${JSON.stringify(config[key])}`);
1683
1689
  } else if (key === "snapshotSerializers") attention.push(`snapshotSerializers — Vitest uses expect.addSnapshotSerializer; vitest-native ships one for RN trees.`);
1684
1690
  else dropped.push(`${key} — no vitest-native equivalent needed; dropped.`);
1685
1691
  }
1692
+ if (config.clearMocks === void 0) {
1693
+ testEntries.push(`clearMocks: false`);
1694
+ automatic.push("Jest keeps mock calls between tests unless clearMocks is set → test.clearMocks: false (Vitest 5 clears them before each test by default).");
1695
+ }
1686
1696
  for (const key of Object.keys(config)) if (!handled.has(key)) attention.push(`'${key}' — unrecognized Jest key; review manually.`);
1687
1697
  }
1688
1698
  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-lBGWAeOw.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-mriqY254.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
@@ -1542,10 +1544,10 @@ function analyzeJestConfig(root) {
1542
1544
  if (assetGroup) {
1543
1545
  const exts = assetGroup[1].toLowerCase().split("|");
1544
1546
  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.`);
1547
+ if (missing.length === 0) presetCovered.push(`moduleNameMapper '${pattern}' — the plugin handles ${list(exts)} imports itself; delete.`);
1546
1548
  else {
1547
1549
  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)} }).`);
1550
+ 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
1551
  }
1550
1552
  } else if (/^\^?@\/|\^~\/|\^src\//.test(pattern)) {
1551
1553
  const aliasKey = pattern.replace(/[\^$]/g, "").replace(/\((\.\*|\.\+)\)\$?$/, "").replace(/\/$/, "");
@@ -1624,7 +1626,10 @@ function analyzeJestConfig(root) {
1624
1626
  } 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
1627
  }
1626
1628
  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).");
1629
+ if (scriptFlags) {
1630
+ const mapped = scriptFlags.flags.size > 0 ? " (its flags are mapped above)" : "";
1631
+ attention.push(`scripts.test runs Jest — point it at \`vitest run\` once the suite passes${mapped}.`);
1632
+ }
1628
1633
  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
1634
  const env = take("testEnvironment");
1630
1635
  if (env && env !== "node") attention.push(`testEnvironment: '${env}' — vitest-native suites run under 'node'; review.`);
@@ -1674,11 +1679,16 @@ function analyzeJestConfig(root) {
1674
1679
  handled.add(key);
1675
1680
  if (key === "transform") dropped.push(`transform — Babel/esbuild transforms are the plugin's job; dropped.`);
1676
1681
  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])}`);
1682
+ const vitestKey = key === "resetMocks" ? "mockReset" : key;
1683
+ automatic.push(key === vitestKey ? `${key} → test.${key} (same name in Vitest).` : `${key} → test.${vitestKey} (Vitest's name for it).`);
1684
+ testEntries.push(`${vitestKey}: ${JSON.stringify(config[key])}`);
1679
1685
  } else if (key === "snapshotSerializers") attention.push(`snapshotSerializers — Vitest uses expect.addSnapshotSerializer; vitest-native ships one for RN trees.`);
1680
1686
  else dropped.push(`${key} — no vitest-native equivalent needed; dropped.`);
1681
1687
  }
1688
+ if (config.clearMocks === void 0) {
1689
+ testEntries.push(`clearMocks: false`);
1690
+ automatic.push("Jest keeps mock calls between tests unless clearMocks is set → test.clearMocks: false (Vitest 5 clears them before each test by default).");
1691
+ }
1682
1692
  for (const key of Object.keys(config)) if (!handled.has(key)) attention.push(`'${key}' — unrecognized Jest key; review manually.`);
1683
1693
  }
1684
1694
  const mocksDir = path.join(root, "__mocks__");
@@ -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-mzfu_YUy.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") {
@@ -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-mriqY254.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") {
package/dist/errors.d.mts CHANGED
@@ -36,6 +36,9 @@ export type VitestNativeErrorCode =
36
36
  | "HELPERS_BEFORE_SETUP"
37
37
  | "JEST_API_UNSUPPORTED"
38
38
  | "REQUIRE_ACTUAL_ALIAS_UNSUPPORTED"
39
+ | "JEST_MOCK_FACTORY_CYCLE"
40
+ | "JEST_COMPAT_SETUP_MISSING"
41
+ | "BABEL_IGNORES_FILE"
39
42
  | "MATCHER_BAD_RECEIVER";
40
43
 
41
44
  export interface VitestNativeErrorOptions {
@@ -277,7 +277,7 @@ interface VitestNativeOptions {
277
277
  mocks?: Record<string, any>;
278
278
  /** Log plugin activity. Default: false */
279
279
  diagnostics?: boolean;
280
- /** Additional asset file extensions to stub (e.g. ['.lottie', '.m4b']) */
280
+ /** Additional asset file extensions, loaded as Metro loads assets (e.g. ['.lottie', '.m4b']) */
281
281
  assetExts?: string[];
282
282
  /**
283
283
  * Experimental. Read the project's declarative Metro resolution profile in a
@@ -382,6 +382,20 @@ interface VitestNativeOptions {
382
382
  preserveGlobals?: string[];
383
383
  esmGeneration?: boolean;
384
384
  };
385
+ /**
386
+ * `engine: 'native'` only. How native module lookups answer.
387
+ *
388
+ * - `'device'`: as on a device. `NativeModules[name]` and
389
+ * `TurboModuleRegistry.get(name)` find React Native's own modules and those
390
+ * registered with `mockNativeModule()`, and are `undefined`/`null` for any other
391
+ * name. A React Native module's stub has only the members of its codegen spec.
392
+ * - `'permissive'`: every name is present for every lookup, and every stub answers
393
+ * every property with a method. An escape hatch for suites written against that
394
+ * behaviour; prefer registering the modules a test needs with `mockNativeModule()`.
395
+ *
396
+ * Default: `'device'`.
397
+ */
398
+ nativeModules?: "device" | "permissive";
385
399
  }
386
400
  //#endregion
387
401
  //#region src/presets/reanimated.d.ts
@@ -276,7 +276,7 @@ interface VitestNativeOptions {
276
276
  mocks?: Record<string, any>;
277
277
  /** Log plugin activity. Default: false */
278
278
  diagnostics?: boolean;
279
- /** Additional asset file extensions to stub (e.g. ['.lottie', '.m4b']) */
279
+ /** Additional asset file extensions, loaded as Metro loads assets (e.g. ['.lottie', '.m4b']) */
280
280
  assetExts?: string[];
281
281
  /**
282
282
  * Experimental. Read the project's declarative Metro resolution profile in a
@@ -381,6 +381,20 @@ interface VitestNativeOptions {
381
381
  preserveGlobals?: string[];
382
382
  esmGeneration?: boolean;
383
383
  };
384
+ /**
385
+ * `engine: 'native'` only. How native module lookups answer.
386
+ *
387
+ * - `'device'`: as on a device. `NativeModules[name]` and
388
+ * `TurboModuleRegistry.get(name)` find React Native's own modules and those
389
+ * registered with `mockNativeModule()`, and are `undefined`/`null` for any other
390
+ * name. A React Native module's stub has only the members of its codegen spec.
391
+ * - `'permissive'`: every name is present for every lookup, and every stub answers
392
+ * every property with a method. An escape hatch for suites written against that
393
+ * behaviour; prefer registering the modules a test needs with `mockNativeModule()`.
394
+ *
395
+ * Default: `'device'`.
396
+ */
397
+ nativeModules?: "device" | "permissive";
384
398
  }
385
399
  //#endregion
386
400
  //#region src/presets/reanimated.d.ts
package/dist/index.d.mts CHANGED
@@ -1,4 +1,4 @@
1
- import { b as ReactNativeMock, t as index_d_exports, x as VitestNativeOptions, y as Preset } from "./index-CEbwa4QU.mjs";
1
+ import { b as ReactNativeMock, t as index_d_exports, x as VitestNativeOptions, y as Preset } from "./index-D7-7BtcM.mjs";
2
2
  import { Plugin } from "vite";
3
3
  //#region src/plugin.d.ts
4
4
  /**