vitest-native 0.12.0 → 0.13.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,50 @@
1
1
  # vitest-native
2
2
 
3
+ ## 0.13.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 0c25e74: New helper `extendPresetMock(pkg, overrides)`: merge overrides into a preset's module mock (and its `default` export) — e.g. to give expo-constants a real `expoConfig` or add an export a library calls that the preset does not model. Undone by `resetAllMocks()`.
8
+ - 1283531: React Native 0.87 joins the supported matrix
9
+
10
+ The verified range is now 0.81–0.87: the CI matrix gains a 0.87 row (and the
11
+ Vitest 5 column moves its newest-RN cell up), the workspace pins 0.87, and the
12
+ published range statements follow. 0.87 removed InteractionManager, so its
13
+ cross-check probe is version-gated rather than deleted — the 0.81–0.86 legs
14
+ still compare it, and the published corpus count on the pinned version drops
15
+ from 85 to 84 with the retirement recorded deliberately via the report's
16
+ --allow-corpus-shrink flag.
17
+
18
+ ### Patch Changes
19
+
20
+ - 9f4fd3c: Complete the expo-linking preset mock: add `addEventListener`, `resolveScheme` and `getInitialURL`, which expo-router's linking layer calls at render time.
21
+ - 4216b1f: Fabricated native-module stubs follow Expo method conventions: unknown `*Async` properties resolve a Promise (fixes expo-notifications crashing at import), and unknown PascalCase properties are memoized classes extending `SharedObject` (fixes expo-file-system's `class File extends ExpoFileSystem.FileSystemFile`).
22
+ - 36a1625: Mock registries are null-prototype objects, so a module or package name of `__proto__` becomes an ordinary entry instead of re-prototyping the registry. Hardens the published `mockNativeModule()` surface against prototype-polluting names — the same class CodeQL flagged on `extendPresetMock()`.
23
+ - b127e6d: Resolve React Native 0.87's gated deep imports, and mock its new AssetRegistry export
24
+
25
+ React Native 0.87 ships an `exports` map whose deep-import surface sits behind
26
+ Metro's `react-native-legacy-deep-imports` condition — and its Babel preset now
27
+ compiles RN's own relative imports into bare deep specifiers
28
+ (`react-native/src/private/…`), so RN's compiled graph self-references through
29
+ paths plain Node refuses with `ERR_PACKAGE_PATH_NOT_EXPORTED`. Under the native
30
+ engine that failed almost every suite at collection. The engine now mirrors
31
+ Metro: when Node's resolver rejects a `react-native/*` or `@react-native/*` deep
32
+ specifier, the file is located by path from the package's real directory,
33
+ platform extensions included, in the require hook, the ESM loader, and the
34
+ precompiled registry's fall-through — where resolving by path keeps deep files
35
+ on the registry's instances instead of loading twins. Inert on 0.86 and earlier,
36
+ which have no exports map to reject anything.
37
+
38
+ The mock engine gains `AssetRegistry` (a top-level export since 0.87),
39
+ mirroring `@react-native/assets-registry/registry` down to its 1-based truthy
40
+ ids. The compatibility checker no longer misreads the bare `get() {` inside
41
+ 0.87's new `Object.defineProperty` export blocks as an export named `get`, and
42
+ the InteractionManager probe is version-gated: 0.87 removed the API outright,
43
+ so the matrix keeps running it on every version that ships it.
44
+
45
+ React Native 0.87 is not yet in the supported matrix — its release is inside
46
+ the dependency cooldown window; adoption follows separately.
47
+
3
48
  ## 0.12.0
4
49
 
5
50
  ### Minor Changes
package/dist/helpers.cjs CHANGED
@@ -49,6 +49,49 @@ function setInsets(insets) {
49
49
  const safeArea = globalThis.__vitest_native_preset_mocks?.["react-native-safe-area-context"];
50
50
  if (safeArea?._setInsets) safeArea._setInsets(insets);
51
51
  }
52
+ let presetMockOverrides = [];
53
+ /**
54
+ * Merge overrides into a preset's module mock (and its `default`, when that is
55
+ * an object) — e.g. to give expo-constants a real `expoConfig` or add an export
56
+ * a library calls that the preset does not model. Returns `false` when no
57
+ * preset mock exists for the package. Undone by `resetAllMocks()`.
58
+ */
59
+ function extendPresetMock(pkg, overrides) {
60
+ const mock = globalThis.__vitest_native_preset_mocks?.[pkg];
61
+ if (!mock) return false;
62
+ const targets = [mock];
63
+ if (mock.default && typeof mock.default === "object" && mock.default !== mock) targets.push(mock.default);
64
+ for (const target of targets) for (const [key, value] of Object.entries(overrides)) {
65
+ if (key === "__proto__" || key === "constructor" || key === "prototype") continue;
66
+ presetMockOverrides.push({
67
+ target,
68
+ key,
69
+ had: Object.prototype.hasOwnProperty.call(target, key),
70
+ previous: target[key]
71
+ });
72
+ Object.defineProperty(target, key, {
73
+ configurable: true,
74
+ enumerable: true,
75
+ writable: true,
76
+ value
77
+ });
78
+ }
79
+ return true;
80
+ }
81
+ function restorePresetMockOverrides() {
82
+ for (let i = presetMockOverrides.length - 1; i >= 0; i--) {
83
+ const { target, key, had, previous } = presetMockOverrides[i];
84
+ if (key === "__proto__" || key === "constructor" || key === "prototype") continue;
85
+ if (had) Object.defineProperty(target, key, {
86
+ configurable: true,
87
+ enumerable: true,
88
+ writable: true,
89
+ value: previous
90
+ });
91
+ else delete target[key];
92
+ }
93
+ presetMockOverrides = [];
94
+ }
52
95
  function mockNativeModule(name, impl) {
53
96
  const native = getNativeControl();
54
97
  if (native) return native.mockNativeModule(name, impl);
@@ -73,6 +116,7 @@ function clearMockFns(obj, visited = /* @__PURE__ */ new Set()) {
73
116
  }
74
117
  }
75
118
  function resetAllMocks() {
119
+ restorePresetMockOverrides();
76
120
  const native = getNativeControl();
77
121
  if (native) return native.resetAllMocks();
78
122
  const mock = getMock();
@@ -111,6 +155,7 @@ function resetAllMocks() {
111
155
  }
112
156
  }
113
157
  //#endregion
158
+ exports.extendPresetMock = extendPresetMock;
114
159
  exports.mockNativeModule = mockNativeModule;
115
160
  exports.resetAllMocks = resetAllMocks;
116
161
  exports.setColorScheme = setColorScheme;
@@ -13,7 +13,14 @@ declare function setInsets(insets: {
13
13
  bottom?: number;
14
14
  left?: number;
15
15
  }): void;
16
+ /**
17
+ * Merge overrides into a preset's module mock (and its `default`, when that is
18
+ * an object) — e.g. to give expo-constants a real `expoConfig` or add an export
19
+ * a library calls that the preset does not model. Returns `false` when no
20
+ * preset mock exists for the package. Undone by `resetAllMocks()`.
21
+ */
22
+ declare function extendPresetMock(pkg: string, overrides: Record<string, any>): boolean;
16
23
  declare function mockNativeModule(name: string, impl: Record<string, any>): void;
17
24
  declare function resetAllMocks(): void;
18
25
  //#endregion
19
- export { mockNativeModule, resetAllMocks, setColorScheme, setDimensions, setInsets, setPlatform };
26
+ export { extendPresetMock, mockNativeModule, resetAllMocks, setColorScheme, setDimensions, setInsets, setPlatform };
@@ -13,7 +13,14 @@ declare function setInsets(insets: {
13
13
  bottom?: number;
14
14
  left?: number;
15
15
  }): void;
16
+ /**
17
+ * Merge overrides into a preset's module mock (and its `default`, when that is
18
+ * an object) — e.g. to give expo-constants a real `expoConfig` or add an export
19
+ * a library calls that the preset does not model. Returns `false` when no
20
+ * preset mock exists for the package. Undone by `resetAllMocks()`.
21
+ */
22
+ declare function extendPresetMock(pkg: string, overrides: Record<string, any>): boolean;
16
23
  declare function mockNativeModule(name: string, impl: Record<string, any>): void;
17
24
  declare function resetAllMocks(): void;
18
25
  //#endregion
19
- export { mockNativeModule, resetAllMocks, setColorScheme, setDimensions, setInsets, setPlatform };
26
+ export { extendPresetMock, mockNativeModule, resetAllMocks, setColorScheme, setDimensions, setInsets, setPlatform };
package/dist/helpers.mjs CHANGED
@@ -48,6 +48,49 @@ function setInsets(insets) {
48
48
  const safeArea = globalThis.__vitest_native_preset_mocks?.["react-native-safe-area-context"];
49
49
  if (safeArea?._setInsets) safeArea._setInsets(insets);
50
50
  }
51
+ let presetMockOverrides = [];
52
+ /**
53
+ * Merge overrides into a preset's module mock (and its `default`, when that is
54
+ * an object) — e.g. to give expo-constants a real `expoConfig` or add an export
55
+ * a library calls that the preset does not model. Returns `false` when no
56
+ * preset mock exists for the package. Undone by `resetAllMocks()`.
57
+ */
58
+ function extendPresetMock(pkg, overrides) {
59
+ const mock = globalThis.__vitest_native_preset_mocks?.[pkg];
60
+ if (!mock) return false;
61
+ const targets = [mock];
62
+ if (mock.default && typeof mock.default === "object" && mock.default !== mock) targets.push(mock.default);
63
+ for (const target of targets) for (const [key, value] of Object.entries(overrides)) {
64
+ if (key === "__proto__" || key === "constructor" || key === "prototype") continue;
65
+ presetMockOverrides.push({
66
+ target,
67
+ key,
68
+ had: Object.prototype.hasOwnProperty.call(target, key),
69
+ previous: target[key]
70
+ });
71
+ Object.defineProperty(target, key, {
72
+ configurable: true,
73
+ enumerable: true,
74
+ writable: true,
75
+ value
76
+ });
77
+ }
78
+ return true;
79
+ }
80
+ function restorePresetMockOverrides() {
81
+ for (let i = presetMockOverrides.length - 1; i >= 0; i--) {
82
+ const { target, key, had, previous } = presetMockOverrides[i];
83
+ if (key === "__proto__" || key === "constructor" || key === "prototype") continue;
84
+ if (had) Object.defineProperty(target, key, {
85
+ configurable: true,
86
+ enumerable: true,
87
+ writable: true,
88
+ value: previous
89
+ });
90
+ else delete target[key];
91
+ }
92
+ presetMockOverrides = [];
93
+ }
51
94
  function mockNativeModule(name, impl) {
52
95
  const native = getNativeControl();
53
96
  if (native) return native.mockNativeModule(name, impl);
@@ -72,6 +115,7 @@ function clearMockFns(obj, visited = /* @__PURE__ */ new Set()) {
72
115
  }
73
116
  }
74
117
  function resetAllMocks() {
118
+ restorePresetMockOverrides();
75
119
  const native = getNativeControl();
76
120
  if (native) return native.resetAllMocks();
77
121
  const mock = getMock();
@@ -110,4 +154,4 @@ function resetAllMocks() {
110
154
  }
111
155
  }
112
156
  //#endregion
113
- export { mockNativeModule, resetAllMocks, setColorScheme, setDimensions, setInsets, setPlatform };
157
+ export { extendPresetMock, mockNativeModule, resetAllMocks, setColorScheme, setDimensions, setInsets, setPlatform };
package/dist/index.mjs CHANGED
@@ -1,7 +1,7 @@
1
1
  import { t as VitestNativeError } from "./errors-CxoBUfVJ.mjs";
2
2
  import { a as packageDirOf, c as validateOptions, i as containsPath, l as validatePeerDependency, n as detectEngine, o as packagePatterns, r as REACT_NATIVE_PATH, s as PEER_REQUIREMENTS, t as detectEcosystemPackages, u as warnUnknownOptions } from "./ecosystem-Duw40-mO.mjs";
3
3
  import { t as AUTO_DETECT_PRESETS } from "./preset-map-DuX0ocdn.mjs";
4
- import { t as presets_exports } from "./presets-IStcJEOa.mjs";
4
+ import { t as presets_exports } from "./presets-DGProTaA.mjs";
5
5
  import { createRequire } from "node:module";
6
6
  import fs from "node:fs";
7
7
  import path from "node:path";
@@ -427,6 +427,7 @@ const RN_EXPORT_NAMES = [
427
427
  "Alert",
428
428
  "Linking",
429
429
  "AppState",
430
+ "AssetRegistry",
430
431
  "Keyboard",
431
432
  "BackHandler",
432
433
  "Vibration",
@@ -21,7 +21,7 @@ export function installGlobals() {
21
21
  g.IS_REACT_ACT_ENVIRONMENT = true;
22
22
  g.IS_REACT_NATIVE_TEST_ENVIRONMENT = true;
23
23
  g.__fbBatchedBridgeConfig = { remoteModuleConfig: [], localModulesConfig: [] };
24
- g.__vitest_native_module_mocks = g.__vitest_native_module_mocks || {};
24
+ g.__vitest_native_module_mocks = g.__vitest_native_module_mocks || Object.create(null);
25
25
 
26
26
  installExpoGlobal(g);
27
27
  }
@@ -71,15 +71,34 @@ function installExpoGlobal(g) {
71
71
  // setUpJsLogger) call methods like `.addListener` on these, so return a
72
72
  // permissive NativeModule stub (EventEmitter methods + no-op for unknown native
73
73
  // methods) for any accessed module rather than crashing on `undefined`.
74
+ //
75
+ // Fabricated properties follow two Expo conventions instead of a blanket
76
+ // `() => undefined`:
77
+ // - `*Async` methods return Promises on device, and packages chain on them at
78
+ // import time (expo-notifications: `getRegistrationInfoAsync().then(...)`),
79
+ // so they resolve undefined — matching jest-expo's generated mocks.
80
+ // - PascalCase properties are native classes (SharedObjects) that package JS
81
+ // subclasses (expo-file-system: `class File extends ExpoFileSystem.FileSystemFile`),
82
+ // so they are memoized classes on SharedObject's prototype chain.
83
+ // Explicitly-set properties (spies, overrides) always win.
74
84
  const __moduleCache = new Map();
75
- const makeModuleStub = () =>
76
- new Proxy(new NativeModule(), {
85
+ const makeModuleStub = () => {
86
+ const fabricatedClasses = new Map();
87
+ return new Proxy(new NativeModule(), {
77
88
  get(target, prop) {
78
89
  if (prop in target) return target[prop];
79
90
  if (typeof prop === "symbol") return undefined;
91
+ if (prop.endsWith("Async")) return () => Promise.resolve(undefined);
92
+ if (/^[A-Z]/.test(prop)) {
93
+ if (!fabricatedClasses.has(prop)) {
94
+ fabricatedClasses.set(prop, class extends SharedObject {});
95
+ }
96
+ return fabricatedClasses.get(prop);
97
+ }
80
98
  return () => undefined;
81
99
  },
82
100
  });
101
+ };
83
102
  const modules = new Proxy(
84
103
  {},
85
104
  {
@@ -5,7 +5,7 @@ import path from "node:path";
5
5
  import fs from "node:fs";
6
6
  import { transformRN, isFlow, needsTransform } from "./transform.mjs";
7
7
  import { boundarySourceFor } from "./boundary.mjs";
8
- import { resolvePlatformFile } from "./resolve.mjs";
8
+ import { resolvePlatformFile, resolveDeepPackageFile } from "./resolve.mjs";
9
9
  import {
10
10
  NODE_MODULES_PATH,
11
11
  REACT_NATIVE_PATH,
@@ -292,7 +292,18 @@ export function installRequireHooks(
292
292
  );
293
293
  if (hit) return hit;
294
294
  }
295
- const resolved = origResolve.call(this, request, parent, ...rest);
295
+ let resolved;
296
+ try {
297
+ resolved = origResolve.call(this, request, parent, ...rest);
298
+ } catch (err) {
299
+ // RN 0.87's exports map rejects the deep self-references its own Babel
300
+ // preset emits (`react-native/src/private/…`); Metro resolves them via the
301
+ // `react-native-legacy-deep-imports` condition. Mirror Metro by path.
302
+ const fromDir = parent?.filename ? path.dirname(parent.filename) : projectRoot;
303
+ const deep = resolveDeepPackageFile(request, fromDir, platform);
304
+ if (deep === null) throw err;
305
+ resolved = deep;
306
+ }
296
307
  checkResolverAgreement(request, resolved);
297
308
  checkProjectSourceLoadedByNode(resolved, parent);
298
309
  return resolved;
@@ -5,7 +5,7 @@ import path from "node:path";
5
5
  import fs from "node:fs";
6
6
  import { transformRN, isFlow, cjsExportNames, needsTransform } from "./transform.mjs";
7
7
  import { boundarySourceFor } from "./boundary.mjs";
8
- import { resolvePlatformFile } from "./resolve.mjs";
8
+ import { resolvePlatformFile, resolveDeepPackageFile } from "./resolve.mjs";
9
9
  import {
10
10
  NODE_MODULES_PATH,
11
11
  REACT_NATIVE_PATH,
@@ -169,6 +169,17 @@ export async function resolve(specifier, context, nextResolve) {
169
169
  const hit = resolveExtensionless(path.resolve(path.dirname(parent), specifier));
170
170
  if (hit) resolved = { url: pathToFileURL(hit).href, shortCircuit: true };
171
171
  }
172
+ // RN 0.87's exports map rejects the deep self-references its own Babel
173
+ // preset emits (react-native/src/private/...); Metro resolves them via its
174
+ // legacy-deep-imports condition. Mirror Metro by path (see resolve.mjs).
175
+ if (!resolved) {
176
+ const deep = resolveDeepPackageFile(
177
+ specifier,
178
+ parent ? path.dirname(parent) : PROJECT_ROOT,
179
+ PLATFORM,
180
+ );
181
+ if (deep) resolved = { url: pathToFileURL(deep).href, shortCircuit: true };
182
+ }
172
183
  if (!resolved) throw err;
173
184
  }
174
185
 
@@ -34,7 +34,7 @@ import crypto from "node:crypto";
34
34
  import { transformRN, isFlow, cacheRootFor, TRANSFORM_CACHE_VERSION } from "./transform.mjs";
35
35
 
36
36
  import { boundarySourceFor, BOUNDARY_SOURCES } from "./boundary.mjs";
37
- import { resolvePlatformFile } from "./resolve.mjs";
37
+ import { resolvePlatformFile, resolveDeepPackageFile } from "./resolve.mjs";
38
38
 
39
39
  /**
40
40
  * Losing the registry is a silent performance cliff, not a correctness problem:
@@ -557,10 +557,22 @@ export function installRegistry(registryFile, projectRoot) {
557
557
  try {
558
558
  resolved = resolver.resolve(request);
559
559
  } catch {
560
- resolved = null;
560
+ // RN 0.87's exports map refuses the deep self-references its preset
561
+ // emits; resolve by path (Metro's behavior) so the file still lands on
562
+ // the registry's instance instead of loading a twin outside it.
563
+ resolved = resolveDeepPackageFile(
564
+ request,
565
+ parent?.filename ? path.dirname(parent.filename) : projectRoot,
566
+ process.env.VITEST_NATIVE_PLATFORM === "android" ? "android" : "ios",
567
+ );
561
568
  }
562
569
  const id = resolved === null ? undefined : idOf.get(resolved);
563
570
  if (id !== undefined) return registry.load(id);
571
+ // Resolved by path but not in the registry: forward the PATH — reloading
572
+ // the bare specifier would just hit the exports map again.
573
+ if (resolved !== null && path.isAbsolute(resolved)) {
574
+ return origLoad.call(this, resolved, parent, ...rest);
575
+ }
564
576
  }
565
577
  return origLoad.call(this, request, parent, ...rest);
566
578
  };
@@ -74,3 +74,46 @@ function scanPlatformFile(absBase, platform) {
74
74
  }
75
75
  return null;
76
76
  }
77
+
78
+ /**
79
+ * Resolve a deep package specifier by PATH when Node's exports-map enforcement
80
+ * rejects it.
81
+ *
82
+ * React Native 0.87 ships an `exports` map whose deep-import surface is gated
83
+ * behind Metro's `react-native-legacy-deep-imports` condition — and the 0.87
84
+ * Babel preset compiles RN's own relative imports into bare deep specifiers
85
+ * (`react-native/src/private/…`), so RN's compiled graph self-references through
86
+ * paths plain Node now refuses (`ERR_PACKAGE_PATH_NOT_EXPORTED`). Metro resolves
87
+ * them; this engine mirrors Metro: locate the package directory by walking
88
+ * node_modules from the requiring file and resolve the file directly, platform
89
+ * extensions included — path resolution is not subject to exports maps.
90
+ *
91
+ * Scoped to react-native and @react-native/* — the packages whose graphs the
92
+ * preset rewrites. Ordinary packages keep Node's exports enforcement.
93
+ */
94
+ export function resolveDeepPackageFile(request, fromDir, platform) {
95
+ const m = /^(react-native|@react-native\/[^/]+)\/(.+)$/.exec(request);
96
+ if (!m) return null;
97
+ const [, pkg, rest] = m;
98
+ const pkgDir = findPackageDir(fromDir, pkg);
99
+ if (!pkgDir) return null;
100
+ const base = path.join(pkgDir, rest);
101
+ try {
102
+ if (fs.statSync(base).isFile()) return base;
103
+ } catch {}
104
+ // `Foo.js` may exist only as a platform variant, and extensionless specifiers
105
+ // need the full Metro candidate list either way.
106
+ const stem = /\.[a-z0-9]+$/i.test(base) ? base.replace(/\.js$/, "") : base;
107
+ return resolvePlatformFile(stem, platform);
108
+ }
109
+
110
+ function findPackageDir(startDir, pkg) {
111
+ let dir = path.resolve(startDir);
112
+ for (;;) {
113
+ const candidate = path.join(dir, "node_modules", ...pkg.split("/"));
114
+ if (fs.existsSync(path.join(candidate, "package.json"))) return candidate;
115
+ const parent = path.dirname(dir);
116
+ if (parent === dir) return null;
117
+ dir = parent;
118
+ }
119
+ }
@@ -176,7 +176,7 @@ installRequireHooks(projectRoot, nodeTransformPkgs, platform, reactNativeVersion
176
176
  // Build the mock objects now that the require hooks are installed (preset
177
177
  // factories may lazily resolve react-native at render time).
178
178
  const g = globalThis;
179
- g.__vitest_native_preset_mocks = g.__vitest_native_preset_mocks || {};
179
+ g.__vitest_native_preset_mocks = g.__vitest_native_preset_mocks || Object.create(null);
180
180
  for (const { pkg, mod, presetName } of presetDefs) {
181
181
  g.__vitest_native_preset_mocks[pkg] = mod.factory();
182
182
  if (diagnostics) {
@@ -1474,7 +1474,10 @@ function expo() {
1474
1474
  exports: [
1475
1475
  "createURL",
1476
1476
  "parse",
1477
- "useURL"
1477
+ "useURL",
1478
+ "resolveScheme",
1479
+ "addEventListener",
1480
+ "getInitialURL"
1478
1481
  ],
1479
1482
  factory: () => {
1480
1483
  const exports = {
@@ -1485,7 +1488,10 @@ function expo() {
1485
1488
  path: url,
1486
1489
  queryParams: {}
1487
1490
  })),
1488
- useURL: vitest.vi.fn(() => null)
1491
+ useURL: vitest.vi.fn(() => null),
1492
+ resolveScheme: vitest.vi.fn(() => "exp"),
1493
+ addEventListener: vitest.vi.fn(() => ({ remove: () => {} })),
1494
+ getInitialURL: vitest.vi.fn(async () => null)
1489
1495
  };
1490
1496
  return {
1491
1497
  ...exports,
@@ -1472,7 +1472,10 @@ function expo() {
1472
1472
  exports: [
1473
1473
  "createURL",
1474
1474
  "parse",
1475
- "useURL"
1475
+ "useURL",
1476
+ "resolveScheme",
1477
+ "addEventListener",
1478
+ "getInitialURL"
1476
1479
  ],
1477
1480
  factory: () => {
1478
1481
  const exports = {
@@ -1483,7 +1486,10 @@ function expo() {
1483
1486
  path: url,
1484
1487
  queryParams: {}
1485
1488
  })),
1486
- useURL: vi.fn(() => null)
1489
+ useURL: vi.fn(() => null),
1490
+ resolveScheme: vi.fn(() => "exp"),
1491
+ addEventListener: vi.fn(() => ({ remove: () => {} })),
1492
+ getInitialURL: vi.fn(async () => null)
1487
1493
  };
1488
1494
  return {
1489
1495
  ...exports,
package/dist/presets.mjs CHANGED
@@ -1,2 +1,2 @@
1
- import { C as asyncStorage, E as gestureHandler, S as screens, T as safeAreaContext, _ as svg, a as bottomSheet, b as deviceInfo, g as webview, h as vectorIcons, k as reanimated, m as flashList, n as worklets, r as keyboardController, v as netInfo, w as navigation, x as expo, y as mmkv } from "./presets-IStcJEOa.mjs";
1
+ import { C as asyncStorage, E as gestureHandler, S as screens, T as safeAreaContext, _ as svg, a as bottomSheet, b as deviceInfo, g as webview, h as vectorIcons, k as reanimated, m as flashList, n as worklets, r as keyboardController, v as netInfo, w as navigation, x as expo, y as mmkv } from "./presets-DGProTaA.mjs";
2
2
  export { asyncStorage, bottomSheet, deviceInfo, expo, flashList, gestureHandler, keyboardController, mmkv, navigation, netInfo, reanimated, safeAreaContext, screens, svg, vectorIcons, webview, worklets };
package/dist/setup.mjs CHANGED
@@ -1,6 +1,6 @@
1
1
  import { n as __require } from "./rolldown-runtime-BhDjJH2R.mjs";
2
2
  import { t as AUTO_DETECT_PRESETS } from "./preset-map-DuX0ocdn.mjs";
3
- import { D as createPressableMock, O as buildPressableHostProps, c as createTouchableOpacityMock, d as createFlatListMock, f as createScrollViewMock, i as createViewMock, l as createVirtualizedListMock, o as createTouchableWithoutFeedbackMock, p as createTextInputMock, s as createTouchableHighlightMock, t as presets_exports, u as createSectionListMock } from "./presets-IStcJEOa.mjs";
3
+ import { D as createPressableMock, O as buildPressableHostProps, c as createTouchableOpacityMock, d as createFlatListMock, f as createScrollViewMock, i as createViewMock, l as createVirtualizedListMock, o as createTouchableWithoutFeedbackMock, p as createTextInputMock, s as createTouchableHighlightMock, t as presets_exports, u as createSectionListMock } from "./presets-DGProTaA.mjs";
4
4
  import { serializer } from "./serializer.mjs";
5
5
  import { animatedMatchers } from "./matchers.mjs";
6
6
  import { createRequire } from "node:module";
@@ -1759,6 +1759,29 @@ function createInteractionManagerMock() {
1759
1759
  };
1760
1760
  }
1761
1761
  //#endregion
1762
+ //#region src/mocks/apis/AssetRegistry.ts
1763
+ /**
1764
+ * AssetRegistry — a top-level export since React Native 0.87 (previously only
1765
+ * reachable via `@react-native/assets-registry/registry`). The real module is a
1766
+ * process-wide array: `registerAsset` pushes and returns the new length, so the
1767
+ * first asset gets id 1 (truthy), and `getAssetByID` reads `assets[id - 1]`.
1768
+ * Mirrored exactly, including the 1-based ids, so code that treats an id of 0
1769
+ * as "unregistered" behaves the same against the mock.
1770
+ */
1771
+ function createAssetRegistryMock() {
1772
+ const assets = [];
1773
+ const mock = {
1774
+ registerAsset: vi.fn((asset) => assets.push(asset)),
1775
+ getAssetByID: vi.fn((assetId) => assets[assetId - 1]),
1776
+ _reset: () => {
1777
+ assets.length = 0;
1778
+ mock.registerAsset.mockClear();
1779
+ mock.getAssetByID.mockClear();
1780
+ }
1781
+ };
1782
+ return mock;
1783
+ }
1784
+ //#endregion
1762
1785
  //#region src/mocks/apis/PanResponder.ts
1763
1786
  function createPanResponderMock() {
1764
1787
  return { create: vi.fn((config = {}) => ({ panHandlers: {
@@ -2430,6 +2453,7 @@ function buildReactNativeMock(platform = "ios") {
2430
2453
  Share: createShareMock(),
2431
2454
  AccessibilityInfo: createAccessibilityInfoMock(),
2432
2455
  InteractionManager: createInteractionManagerMock(),
2456
+ AssetRegistry: createAssetRegistryMock(),
2433
2457
  PanResponder: createPanResponderMock(),
2434
2458
  ToastAndroid: createToastAndroidMock(),
2435
2459
  ActionSheetIOS: createActionSheetIOSMock(),
@@ -2800,7 +2824,7 @@ function loadExplicitPresets(names) {
2800
2824
  return loaded;
2801
2825
  }
2802
2826
  const presets = explicitPresetNames ? loadExplicitPresets(explicitPresetNames) : autoDetectPresets().filter((p) => !disabledPresetNames.includes(p.name));
2803
- g.__vitest_native_preset_mocks = g.__vitest_native_preset_mocks || {};
2827
+ g.__vitest_native_preset_mocks = g.__vitest_native_preset_mocks || Object.create(null);
2804
2828
  for (const preset of presets) for (const [modName, presetModule] of Object.entries(preset.modules)) {
2805
2829
  const presetMock = presetModule.factory();
2806
2830
  installPresetCjsBridge(modName, presetMock);
@@ -28,7 +28,7 @@ npm i -D vitest-native @react-native/babel-preset @babel/core
28
28
 
29
29
  Keep your existing `vitest`, `vite`, `react`, `react-native`, and
30
30
  `@testing-library/react-native`. Requirements: **Vitest 4.x or 5.x, Vite ^6.4.2, ^7.3.2, or ^8.0.5, the React
31
- version required by your RN release, React Native 0.81–0.86 (validated), and
31
+ version required by your RN release, React Native 0.81–0.87 (validated), and
32
32
  RNTL 12–14.** RNTL 14 uses async rendering APIs and requires Node 22.13 or 24+.
33
33
 
34
34
  ## 2. Update `vitest.config`
@@ -23,7 +23,7 @@ and deep paths are not supported even when they happen to resolve.
23
23
  | Subpath | Covered exports |
24
24
  | --- | --- |
25
25
  | `vitest-native` | `reactNative`, `presets`, `disabledPresetNames` |
26
- | `vitest-native/helpers` | `setPlatform`, `setDimensions`, `setColorScheme`, `setInsets`, `mockNativeModule`, `resetAllMocks` |
26
+ | `vitest-native/helpers` | `setPlatform`, `setDimensions`, `setColorScheme`, `setInsets`, `mockNativeModule`, `extendPresetMock`, `resetAllMocks` |
27
27
  | `vitest-native/presets` | the 17 preset factories, by name |
28
28
  | `vitest-native/matchers` | `toHaveAnimatedStyle`, `toHaveAnimatedProps`, `animatedMatchers` |
29
29
  | `vitest-native/serializer` | `serializer` |
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vitest-native",
3
- "version": "0.12.0",
3
+ "version": "0.13.0",
4
4
  "type": "module",
5
5
  "description": "Run real React Native tests under Vitest. One install, zero config.",
6
6
  "license": "MIT",
@@ -138,7 +138,7 @@
138
138
  "@react-native-community/netinfo": "12.0.1",
139
139
  "@react-native-vector-icons/common": "13.0.1",
140
140
  "@react-native-vector-icons/material-icons": "13.1.2",
141
- "@react-native/babel-preset": "^0.86.2",
141
+ "@react-native/babel-preset": "0.87.0",
142
142
  "@react-navigation/native": "7.3.14",
143
143
  "@react-navigation/native-stack": "7.18.6",
144
144
  "@shopify/flash-list": "2.3.2",
@@ -153,7 +153,7 @@
153
153
  "generic-mainfield-lib": "file:./tests-native/fixtures/generic-mainfield-lib",
154
154
  "metro-resolver": "0.87.0",
155
155
  "react": "^19.2.8",
156
- "react-native": "^0.86.0",
156
+ "react-native": "0.87.0",
157
157
  "react-native-gesture-handler": "3.1.0",
158
158
  "react-native-keyboard-controller": "1.22.2",
159
159
  "react-native-reanimated": "4.5.3",