vitest-native 0.14.1 → 0.15.0-rc.2

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 (89) hide show
  1. package/README.md +11 -10
  2. package/dist/cli.d.mts +9 -1
  3. package/dist/cli.mjs +2609 -361
  4. package/dist/context.d.mts +19 -0
  5. package/dist/context.mjs +47 -1
  6. package/dist/docs-url.d.mts +4 -0
  7. package/dist/docs-url.mjs +9 -0
  8. package/dist/errors.d.mts +21 -1
  9. package/dist/hang-watch-setup.mjs +55 -0
  10. package/dist/hang-watch.d.mts +56 -0
  11. package/dist/hang-watch.mjs +343 -0
  12. package/dist/helpers.cjs +24 -53
  13. package/dist/helpers.mjs +22 -1
  14. package/dist/host-D0r3P_T1.mjs +1985 -0
  15. package/dist/{index-aNBCTfA5.d.mts → index-JOR602XU.d.mts} +105 -2
  16. package/dist/index.d.mts +2 -1
  17. package/dist/index.mjs +723 -149
  18. package/dist/jest-compat/aliases.d.mts +1 -0
  19. package/dist/jest-compat/aliases.mjs +11 -0
  20. package/dist/jest-compat/interop.mjs +1 -1
  21. package/dist/jest-compat/jest-object.mjs +23 -5
  22. package/dist/jest-compat/node-registry.mjs +836 -68
  23. package/dist/jest-compat/setup.mjs +205 -12
  24. package/dist/jest-compat.cjs +383 -47
  25. package/dist/jest-compat.d.cts +19 -2
  26. package/dist/jest-compat.d.mts +19 -2
  27. package/dist/jest-compat.mjs +232 -47
  28. package/dist/matchers.d.cts +0 -1
  29. package/dist/matchers.d.mts +0 -1
  30. package/dist/native/assets.mjs +3 -1
  31. package/dist/native/babel-caller.d.mts +13 -0
  32. package/dist/native/babel-caller.mjs +24 -0
  33. package/dist/native/babel-toolchain.mjs +27 -3
  34. package/dist/native/boundary.mjs +45 -8
  35. package/dist/native/bounded-process.mjs +63 -5
  36. package/dist/native/bridge-client.mjs +133 -0
  37. package/dist/native/bridge-server.mjs +215 -0
  38. package/dist/native/bridge-thread.mjs +79 -0
  39. package/dist/native/bridge.mjs +512 -0
  40. package/dist/native/compile-error.mjs +120 -0
  41. package/dist/native/explain.mjs +3 -2
  42. package/dist/native/expo-module-mocks.mjs +2 -0
  43. package/dist/native/export-condition-recovery.mjs +20 -99
  44. package/dist/native/hooks.mjs +256 -133
  45. package/dist/native/jest-resolvers.mjs +94 -0
  46. package/dist/native/library-jest.mjs +352 -0
  47. package/dist/native/loader.mjs +167 -73
  48. package/dist/native/match.mjs +67 -7
  49. package/dist/native/module-reset.mjs +44 -49
  50. package/dist/native/ownership-ledger.d.mts +87 -0
  51. package/dist/native/ownership-ledger.mjs +524 -0
  52. package/dist/native/ownership.d.mts +20 -0
  53. package/dist/native/ownership.mjs +114 -0
  54. package/dist/native/registry-compiler.mjs +39 -5
  55. package/dist/native/registry-process.mjs +327 -28
  56. package/dist/native/registry.mjs +752 -200
  57. package/dist/native/resident-health.mjs +1 -0
  58. package/dist/native/resolve.d.mts +7 -0
  59. package/dist/native/resolve.mjs +119 -4
  60. package/dist/native/rntl-hooks.mjs +9 -5
  61. package/dist/native/rntl-text-host.mjs +5 -15
  62. package/dist/native/root-spelling.d.mts +6 -0
  63. package/dist/native/root-spelling.mjs +77 -0
  64. package/dist/native/runner.mjs +2 -19
  65. package/dist/native/setup.mjs +119 -38
  66. package/dist/native/shared-resolver.d.mts +141 -0
  67. package/dist/native/shared-resolver.mjs +719 -0
  68. package/dist/native/test-runner.mjs +26 -0
  69. package/dist/native/transform.mjs +18 -22
  70. package/dist/native/worker.mjs +9 -4
  71. package/dist/node-dispatch.mjs +293 -0
  72. package/dist/{preset-map-CogjYmSw.mjs → preset-map-DdAexIwz.mjs} +113 -2
  73. package/dist/{presets-CXDyg51l.mjs → presets-_EaSw29m.mjs} +710 -130
  74. package/dist/presets.d.mts +1 -1
  75. package/dist/presets.mjs +1 -1
  76. package/dist/rntl-matchers.d.ts +11 -15
  77. package/dist/rntl-support.mjs +28 -13
  78. package/dist/root-mocks-BNXeosbR.mjs +155 -0
  79. package/dist/serializer.cjs +7 -5
  80. package/dist/serializer.d.cts +7 -5
  81. package/dist/serializer.d.mts +7 -5
  82. package/dist/serializer.mjs +7 -5
  83. package/dist/setup.mjs +26 -27
  84. package/docs/migrating-from-jest.md +9 -232
  85. package/docs/migrating-from-vitest-react-native.md +4 -4
  86. package/docs/release-readiness.md +9 -11
  87. package/docs/versioning.md +38 -9
  88. package/package.json +59 -33
  89. package/dist/host-BAAAlSkO.mjs +0 -1028
@@ -1,2 +1,2 @@
1
- import { _ as navigation, a as keyboardController, b as reanimated, c as vectorIcons, d as netInfo, f as mmkv, g as asyncStorage, h as screens, i as worklets, l as webview, m as expo, n as skia, o as bottomSheet, p as deviceInfo, r as unistyles, s as flashList, u as svg, v as safeAreaContext, y as gestureHandler } from "./index-aNBCTfA5.mjs";
1
+ import { _ as navigation, a as keyboardController, b as reanimated, c as vectorIcons, d as netInfo, f as mmkv, g as asyncStorage, h as screens, i as worklets, l as webview, m as expo, n as skia, o as bottomSheet, p as deviceInfo, r as unistyles, s as flashList, u as svg, v as safeAreaContext, y as gestureHandler } from "./index-JOR602XU.mjs";
2
2
  export { asyncStorage, bottomSheet, deviceInfo, expo, flashList, gestureHandler, keyboardController, mmkv, navigation, netInfo, reanimated, safeAreaContext, screens, skia, svg, unistyles, vectorIcons, webview, worklets };
package/dist/presets.mjs CHANGED
@@ -1 +1 @@
1
- export { T as asyncStorage, s as bottomSheet, S as deviceInfo, C as expo, g as flashList, O as gestureHandler, a as keyboardController, x as mmkv, E as navigation, b as netInfo, j as reanimated, D as safeAreaContext, w as screens, n as skia, y as svg, r as unistyles, _ as vectorIcons, v as webview, i as worklets } from "./presets-CXDyg51l.mjs";
1
+ export { T as asyncStorage, s as bottomSheet, S as deviceInfo, C as expo, g as flashList, O as gestureHandler, a as keyboardController, x as mmkv, E as navigation, b as netInfo, j as reanimated, D as safeAreaContext, w as screens, n as skia, y as svg, r as unistyles, _ as vectorIcons, v as webview, i as worklets } from "./presets-_EaSw29m.mjs";
@@ -5,8 +5,9 @@
5
5
  * RNTL's matchers work at runtime under this plugin, but RNTL declares their types for
6
6
  * Jest. Before RNTL 14 nothing reached Vitest's `Assertion`, so `toHaveTextContent`,
7
7
  * `toHaveStyle`, `toBeVisible` and the rest were `Property 'x' does not exist on type
8
- * 'Assertion<...>'` for anyone who typechecks. RNTL 14 also augments the global
9
- * `jest.Matchers<R>`, which Vitest 4's `JestAssertion<T>` extends as `Matchers<void, T>`.
8
+ * 'Assertion<...>'` for anyone who typechecks. RNTL 14 augments the global
9
+ * `jest.Matchers<R>`, which Vitest 5's `Assertion` does not inherit: its `JestAssertion`
10
+ * extends `CustomMatcher<R>`.
10
11
  *
11
12
  * Reference it once, anywhere in the project:
12
13
  *
@@ -22,13 +23,11 @@
22
23
  * this shape. @testing-library/jest-dom ships its `/vitest` entry for the same reason.
23
24
  *
24
25
  * The matcher interface is declared here rather than imported: RNTL does not export it
25
- * from its entry point, and its internal location differs by major (`build/` in 12 and
26
- * 13, `dist/` in 14), so a deep import typed the matchers on one major and silently
27
- * dropped them on the others. Only the element type is version-specific
28
- * (`ReactTestInstance` before 14, `TestInstance` from 14); it is read from RNTL's public
29
- * `screen` API, so it is identical to the type RNTL's own global augmentation uses. A
30
- * different type declares `toContainElement` twice on Vitest 4, which TypeScript 7
31
- * reports as TS2320 under `skipLibCheck: false`.
26
+ * from its entry point, and its internal location differs by major (`build/` in 13,
27
+ * `dist/` in 14), so a deep import typed the matchers on one major and silently dropped
28
+ * them on the other. Only the element type is version-specific (`ReactTestInstance` in
29
+ * 13, `TestInstance` from 14); it is read from RNTL's public `screen` API, so it is
30
+ * identical to the type RNTL's own global augmentation uses.
32
31
  * tests/rntl-matchers-types.test.ts compares these members with the installed RNTL's.
33
32
  */
34
33
  import type { screen } from "@testing-library/react-native";
@@ -65,12 +64,9 @@ interface RNTLMatchers<R> {
65
64
  }
66
65
 
67
66
  declare module "vitest" {
68
- // `void`, the same instantiation Vitest 4's JestAssertion inherits from RNTL 14's global
69
- // augmentation. Any other argument declares every matcher twice with different return
70
- // types, which TypeScript 7 rejects (TS2320) for RNTL 14 users; Vitest's own matchers
71
- // return void as well. The type parameters follow Vitest 5's `Assertion<R, T>`; on
72
- // Vitest 4 with `skipLibCheck: false` that is reported as TS2428, and the matchers
73
- // stay typed.
67
+ // `void`: the matchers return void, as Vitest's own do and as RNTL 14's global
68
+ // augmentation declares them. The type parameters follow Vitest 5's `Assertion<R, T>`,
69
+ // which interface declarations must agree on.
74
70
  // eslint-disable-next-line @typescript-eslint/no-empty-object-type
75
71
  interface Assertion<
76
72
  R extends void | Promise<void> = void,
@@ -7,10 +7,19 @@ import fs from "node:fs";
7
7
  import Module from "node:module";
8
8
  import { setImmediate as realSetImmediate } from "node:timers";
9
9
 
10
- /** RNTL's package entry: `build/index.js` (12, 13) or `dist/index.js` (14). */
10
+ /** RNTL's package entry: `build/index.js` (13) or `dist/index.js` (14). */
11
11
  export const RNTL_ENTRY =
12
12
  /[\\/]node_modules[\\/]@testing-library[\\/]react-native[\\/](?:build|dist)[\\/]index\.js$/;
13
13
 
14
+ /**
15
+ * RNTL's `dont-cleanup-after-each` module, at the package root in 13 and 14: one line,
16
+ * `process.env.RNTL_SKIP_AUTO_CLEANUP = true`. A file that imports it opts out of cleanup.
17
+ */
18
+ export const RNTL_DONT_CLEANUP =
19
+ /[\\/]node_modules[\\/]@testing-library[\\/]react-native[\\/]dont-cleanup-after-each\.js$/;
20
+
21
+ const isRntlFile = (file) => RNTL_ENTRY.test(file) || RNTL_DONT_CLEANUP.test(file);
22
+
14
23
  // Per-file auto-cleanup state, created by installRntlAutoCleanup. When files share a
15
24
  // worker, native/rntl-hooks.mjs and native/hooks.mjs add the RNTL entries a file loads
16
25
  // to `imported`.
@@ -20,6 +29,7 @@ const AUTO_CLEANUP = Symbol.for("vitest-native.rntl-auto-cleanup");
20
29
  function cacheKeyOf(file) {
21
30
  if (Module._cache[file]) return file;
22
31
  try {
32
+ // Node's spelling (fs.realpathSync): the key Module._cache holds the file under.
23
33
  const real = fs.realpathSync(file);
24
34
  return Module._cache[real] ? real : null;
25
35
  } catch {
@@ -28,7 +38,8 @@ function cacheKeyOf(file) {
28
38
  }
29
39
 
30
40
  /**
31
- * The RNTL entries the running test file's own module graph imports, read from
41
+ * The RNTL entries, and RNTL's dont-cleanup-after-each module, that the running test
42
+ * file's own module graph imports, read from
32
43
  * Vitest's evaluated-module graph: the modules Vite evaluates, and for each module it
33
44
  * externalizes to Node, that module and the modules it required directly (a shared
34
45
  * test-utils that re-exports RNTL). With `isolate: false` and no hot runtime both the
@@ -52,9 +63,9 @@ function rntlEntriesInFileGraph() {
52
63
  if (typeof external === "string") {
53
64
  const key = cacheKeyOf(external);
54
65
  if (!key) continue;
55
- if (RNTL_ENTRY.test(key)) found.push(key);
66
+ if (isRntlFile(key)) found.push(key);
56
67
  for (const child of Module._cache[key].children ?? []) {
57
- if (RNTL_ENTRY.test(child.id)) found.push(child.id);
68
+ if (isRntlFile(child.id)) found.push(child.id);
58
69
  }
59
70
  continue;
60
71
  }
@@ -66,8 +77,8 @@ function rntlEntriesInFileGraph() {
66
77
  /**
67
78
  * Register RNTL's automatic cleanup through Vitest's `afterEach` when RNTL cannot.
68
79
  *
69
- * RNTL's entry registers it only if `afterEach` is a global (12.9 build/index.js:25,
70
- * 13.3 build/index.js:27, 14.1 dist/index.js:26: `if (typeof afterEach === 'function')`).
80
+ * RNTL's entry registers it only if `afterEach` is a global (13.3 build/index.js:27,
81
+ * 14.1 dist/index.js:26: `if (typeof afterEach === 'function')`).
71
82
  * Vitest defines its globals only with `test.globals: true`, so with Vitest's default
72
83
  * every rendered tree stayed mounted for the rest of the file: `screen` and later
73
84
  * queries saw earlier tests' screens, and their effects kept running. With globals on,
@@ -78,15 +89,15 @@ function rntlEntriesInFileGraph() {
78
89
  * `@testing-library/react-native/pure` is RNTL's documented opt-out, so the setup
79
90
  * files never load the entry themselves and it is detected lazily, when the hook runs;
80
91
  * - not when RNTL_SKIP_AUTO_CLEANUP is set, tested by truthiness as RNTL does
81
- * (12.9 build/index.js:19, 13.3 :21, 14.1 dist/index.js:20); its
82
- * `dont-cleanup-after-each` module sets it;
83
- * - the cleanup each version's own hook calls: 12's synchronous `cleanup`
84
- * (12.9 build/index.js:29), 13's `cleanupAsync` (13.3 build/index.js:30; its
92
+ * (13.3 build/index.js:21, 14.1 dist/index.js:20); its
93
+ * `dont-cleanup-after-each` module sets it. When files share a worker, also not when
94
+ * this file imports that module, whose side effect ran in an earlier file only;
95
+ * - the cleanup each version's own hook calls: 13's `cleanupAsync` (13.3 build/index.js:30; its
85
96
  * `cleanup` is the synchronous one), and 14's `cleanup`, which is async and has no
86
97
  * `cleanupAsync` (14.1 dist/index.js:29, dist/cleanup.js:11);
87
98
  * - after one macrotask turn, as RNTL's `flushMicroTasks` (13.3/14.1
88
- * flush-micro-tasks.js:9) or 12's `flushMicroTasksLegacy` (12.9 :27) wait. RNTL uses
89
- * the `setImmediate` it captured when it loaded (12.9/13.3 build/helpers/timers.js:67,
99
+ * flush-micro-tasks.js:9) waits. RNTL uses
100
+ * the `setImmediate` it captured when it loaded (13.3 build/helpers/timers.js:67,
90
101
  * 14.1 dist/helpers/timers.js:74), not the current one, so a test that ends with fake
91
102
  * timers still installed does not hang its cleanup. This hook's own wait uses
92
103
  * `node:timers`' `setImmediate`, which Vitest's fake timers never replace: a capture
@@ -103,7 +114,7 @@ function rntlEntriesInFileGraph() {
103
114
  * expects the tree to be unmounted already sees it still mounted here.
104
115
  *
105
116
  * RNTL's entry also pairs `beforeAll`/`afterAll` to set React's act environment for the
106
- * file (12.9 build/index.js:32). Both engines set IS_REACT_ACT_ENVIRONMENT for every
117
+ * file. Both engines set IS_REACT_ACT_ENVIRONMENT for every
107
118
  * file already, so that pair is not reproduced.
108
119
  *
109
120
  * @param {(fn: () => Promise<void>) => void} afterEach Vitest's `afterEach`.
@@ -130,6 +141,10 @@ export function installRntlAutoCleanup(afterEach, { trackImports = false } = {})
130
141
  const files = state.imported
131
142
  ? new Set([...state.imported, ...rntlEntriesInFileGraph()])
132
143
  : Object.keys(Module._cache);
144
+ // When files share a worker, `dont-cleanup-after-each` stays loaded, so its variable is
145
+ // set only by the first file that imports it, and the worker's environment is restored
146
+ // between files. The file's own imports say whether it opted out (#527).
147
+ if (state.imported && [...files].some((file) => RNTL_DONT_CLEANUP.test(file))) return;
133
148
  for (const file of files) {
134
149
  if (!file.endsWith("index.js") || !RNTL_ENTRY.test(file)) continue;
135
150
  const rntl = Module._cache[file]?.exports;
@@ -0,0 +1,155 @@
1
+ import { isBuiltin } from "node:module";
2
+ import path from "node:path";
3
+ import fs from "node:fs";
4
+ // src/jest-compat/root-mocks.ts
5
+ /**
6
+ * Jest's automatic manual mocks for node_modules packages, registered as Jest 29.7
7
+ * registers them:
8
+ *
9
+ * - jest-haste-map crawls every root (`roots`, default `<rootDir>`), skipping
10
+ * node_modules and `modulePathIgnorePatterns`, and records each file whose path
11
+ * contains `/__mocks__/`, at any depth, under the path after the first `/__mocks__/`
12
+ * without its extension (getMockName): `src/__mocks__/moti.ts` and
13
+ * `__mocks__/moti.js` are both `moti`, `__mocks__/@scope/pkg.js` is `@scope/pkg`.
14
+ * A second file with the same name logs "duplicate manual mock found", and the file
15
+ * recorded later replaces the earlier one (`mocks.set`).
16
+ * - jest-runtime's `requireModule` then loads that file for a request of the same
17
+ * name, `name` or else `name/index` (ModuleMap.getMockModule), with no `jest.mock()`
18
+ * call. A Node core module stays real, and an explicit `jest.mock(name, factory)` or
19
+ * `jest.unmock(name)` is decided first (`_explicitShouldMock`).
20
+ *
21
+ * Vitest applies such a file only through `vi.mock()`, so a suite that relied on it ran
22
+ * the real package. jestMockTransform() mocks what this finds, ahead of the project's
23
+ * setup files, and `vitest-native migrate` lists the same files.
24
+ */
25
+ /** Jest's default moduleFileExtensions, less `node` (a binary addon is no mock source). */
26
+ const MOCK_FILE = /\.(?:[cm]?js|jsx|ts|tsx|json)$/;
27
+ const MOCKS_SEGMENT = `${path.sep}__mocks__${path.sep}`;
28
+ /**
29
+ * Never crawled: node_modules and git's own data, as Jest skips them, and the build and
30
+ * native folders an app tree holds, where a manual mock never lives and which are large
31
+ * (CocoaPods alone made one app's crawl 167 ms). Jest crawls the latter unless
32
+ * `modulePathIgnorePatterns` names them; skipping them by default changes which mocks
33
+ * apply only for a mock kept inside a build output, which no project does on purpose.
34
+ */
35
+ const SKIPPED = /* @__PURE__ */ new Set([
36
+ "node_modules",
37
+ ".git",
38
+ "ios",
39
+ "android",
40
+ "Pods",
41
+ "build",
42
+ ".expo",
43
+ ".tmp",
44
+ "dist"
45
+ ]);
46
+ /** The package a request names: `@scope/pkg` for `@scope/pkg/sub`, `pkg` for `pkg/sub`. */
47
+ function packageOfRequest(spec) {
48
+ const parts = spec.split("/");
49
+ return spec.startsWith("@") ? parts.slice(0, 2).join("/") : parts[0];
50
+ }
51
+ /** Whether `pkg` is installed for `root`: its manifest, found walking node_modules upward. */
52
+ function installed(root, pkg) {
53
+ for (let dir = path.resolve(root);; dir = path.dirname(dir)) {
54
+ if (fs.existsSync(path.join(dir, "node_modules", pkg, "package.json"))) return true;
55
+ if (path.dirname(dir) === dir) return false;
56
+ }
57
+ }
58
+ function readable(dir) {
59
+ try {
60
+ return fs.readdirSync(dir, { withFileTypes: true });
61
+ } catch {
62
+ return [];
63
+ }
64
+ }
65
+ /** Every file under `dir` below a `__mocks__` folder, in a fixed (sorted) order. */
66
+ function crawl(dir, ignore, out) {
67
+ const entries = readable(dir);
68
+ entries.sort((a, b) => a.name < b.name ? -1 : a.name > b.name ? 1 : 0);
69
+ for (const entry of entries) {
70
+ if (SKIPPED.has(entry.name)) continue;
71
+ const full = path.join(dir, entry.name);
72
+ if (ignore.some((pattern) => pattern.test(full))) continue;
73
+ if (entry.isDirectory()) crawl(full, ignore, out);
74
+ else if (entry.isFile() && full.includes(MOCKS_SEGMENT) && MOCK_FILE.test(entry.name)) out.push(full);
75
+ }
76
+ }
77
+ /** Jest's getMockName: the path after the first `/__mocks__/`, without its extension. */
78
+ function mockName(file) {
79
+ const inside = file.split(MOCKS_SEGMENT)[1];
80
+ return inside.slice(0, inside.length - path.extname(inside).length).split(path.sep).join("/");
81
+ }
82
+ /**
83
+ * Jest's `modulePathIgnorePatterns` entry as a regular expression, with `<rootDir>` replaced
84
+ * by the project root as literal text: a root's own characters (`.`, `+`, Windows' `\`)
85
+ * are not pattern syntax. Null for a pattern that is not a valid regular expression, which
86
+ * then ignores nothing.
87
+ */
88
+ function ignorePattern(pattern, root) {
89
+ const literalRoot = root.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
90
+ try {
91
+ return new RegExp(pattern.replaceAll("<rootDir>", literalRoot));
92
+ } catch {
93
+ return null;
94
+ }
95
+ }
96
+ /**
97
+ * The manual mocks Jest would apply to node_modules requests in this project: every
98
+ * `__mocks__` file under `roots`, by name, kept when the name is not a Node core module
99
+ * and its package is installed. `ignore` is Jest's `modulePathIgnorePatterns`, tested
100
+ * against absolute paths as Jest tests them.
101
+ */
102
+ const crawls = /* @__PURE__ */ new Map();
103
+ function findNodeModuleMocks(roots, projectRoot, ignore = []) {
104
+ const key = JSON.stringify([
105
+ roots,
106
+ projectRoot,
107
+ ignore.map(String)
108
+ ]);
109
+ let found = crawls.get(key);
110
+ if (!found) crawls.set(key, found = findUncached(roots, projectRoot, ignore));
111
+ return found;
112
+ }
113
+ function findUncached(roots, projectRoot, ignore) {
114
+ const files = [];
115
+ const seen = /* @__PURE__ */ new Set();
116
+ for (const root of roots) {
117
+ const crawled = [];
118
+ crawl(path.resolve(root), [...ignore], crawled);
119
+ for (const file of crawled) {
120
+ if (seen.has(file)) continue;
121
+ seen.add(file);
122
+ files.push(file);
123
+ }
124
+ }
125
+ const byName = /* @__PURE__ */ new Map();
126
+ const collisions = /* @__PURE__ */ new Map();
127
+ for (const file of files) {
128
+ const name = mockName(file);
129
+ const earlier = byName.get(name);
130
+ if (earlier) collisions.set(name, [...collisions.get(name) ?? [earlier], file]);
131
+ byName.set(name, file);
132
+ }
133
+ const mocks = [];
134
+ const add = (spec, file, viaIndex) => {
135
+ if (isBuiltin(spec) || !installed(projectRoot, packageOfRequest(spec))) return;
136
+ mocks.push({
137
+ spec,
138
+ file,
139
+ viaIndex
140
+ });
141
+ };
142
+ for (const [name, file] of byName) {
143
+ add(name, file, false);
144
+ const base = name.endsWith("/index") ? name.slice(0, -6) : null;
145
+ if (base && !byName.has(base)) add(base, file, true);
146
+ }
147
+ return {
148
+ mocks,
149
+ duplicates: [...collisions].map(([name, list]) => ({
150
+ name,
151
+ files: list
152
+ }))
153
+ };
154
+ }
155
+ export { ignorePattern as n, findNodeModuleMocks as t };
@@ -1,12 +1,13 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
2
  // src/serializer.ts
3
3
  /**
4
- * Vitest snapshot serializer for React Native components.
4
+ * vitest-native's earlier snapshot format for React Native trees: props as inline JSON,
5
+ * `undefined` as `"[undefined]"`.
5
6
  *
6
- * Produces clean JSX-like output from React test renderer instances
7
- * instead of raw createElement objects.
8
- *
9
- * Usage: expect.addSnapshotSerializer(serializer)
7
+ * @deprecated No longer registered: snapshots print with pretty-format's
8
+ * ReactTestComponent plugin, as Jest and Vitest print React trees. Kept for one release
9
+ * for a suite that wants the earlier format: `expect.addSnapshotSerializer(serializer)`
10
+ * in a setup file. It will be removed in the release after.
10
11
  */
11
12
  /** Props that are React internals and should be omitted from snapshot output. */
12
13
  const INTERNAL_PROPS = /* @__PURE__ */ new Set([
@@ -98,6 +99,7 @@ function isReactTestInstance(val) {
98
99
  if (obj.$$typeof && "type" in obj && "props" in obj) return true;
99
100
  return false;
100
101
  }
102
+ /** @deprecated See the module comment: snapshots now print in Jest's format. */
101
103
  const serializer = {
102
104
  test(val) {
103
105
  return isReactTestInstance(val);
@@ -1,13 +1,15 @@
1
1
  /**
2
- * Vitest snapshot serializer for React Native components.
2
+ * vitest-native's earlier snapshot format for React Native trees: props as inline JSON,
3
+ * `undefined` as `"[undefined]"`.
3
4
  *
4
- * Produces clean JSX-like output from React test renderer instances
5
- * instead of raw createElement objects.
6
- *
7
- * Usage: expect.addSnapshotSerializer(serializer)
5
+ * @deprecated No longer registered: snapshots print with pretty-format's
6
+ * ReactTestComponent plugin, as Jest and Vitest print React trees. Kept for one release
7
+ * for a suite that wants the earlier format: `expect.addSnapshotSerializer(serializer)`
8
+ * in a setup file. It will be removed in the release after.
8
9
  */
9
10
  export interface SnapshotSerializer {
10
11
  serialize(val: any, config: any, indentation: string, depth: number, refs: any[], printer: Function): string;
11
12
  test(val: any): boolean;
12
13
  }
14
+ /** @deprecated See the module comment: snapshots now print in Jest's format. */
13
15
  export declare const serializer: SnapshotSerializer;
@@ -1,13 +1,15 @@
1
1
  /**
2
- * Vitest snapshot serializer for React Native components.
2
+ * vitest-native's earlier snapshot format for React Native trees: props as inline JSON,
3
+ * `undefined` as `"[undefined]"`.
3
4
  *
4
- * Produces clean JSX-like output from React test renderer instances
5
- * instead of raw createElement objects.
6
- *
7
- * Usage: expect.addSnapshotSerializer(serializer)
5
+ * @deprecated No longer registered: snapshots print with pretty-format's
6
+ * ReactTestComponent plugin, as Jest and Vitest print React trees. Kept for one release
7
+ * for a suite that wants the earlier format: `expect.addSnapshotSerializer(serializer)`
8
+ * in a setup file. It will be removed in the release after.
8
9
  */
9
10
  export interface SnapshotSerializer {
10
11
  serialize(val: any, config: any, indentation: string, depth: number, refs: any[], printer: Function): string;
11
12
  test(val: any): boolean;
12
13
  }
14
+ /** @deprecated See the module comment: snapshots now print in Jest's format. */
13
15
  export declare const serializer: SnapshotSerializer;
@@ -1,11 +1,12 @@
1
1
  // src/serializer.ts
2
2
  /**
3
- * Vitest snapshot serializer for React Native components.
3
+ * vitest-native's earlier snapshot format for React Native trees: props as inline JSON,
4
+ * `undefined` as `"[undefined]"`.
4
5
  *
5
- * Produces clean JSX-like output from React test renderer instances
6
- * instead of raw createElement objects.
7
- *
8
- * Usage: expect.addSnapshotSerializer(serializer)
6
+ * @deprecated No longer registered: snapshots print with pretty-format's
7
+ * ReactTestComponent plugin, as Jest and Vitest print React trees. Kept for one release
8
+ * for a suite that wants the earlier format: `expect.addSnapshotSerializer(serializer)`
9
+ * in a setup file. It will be removed in the release after.
9
10
  */
10
11
  /** Props that are React internals and should be omitted from snapshot output. */
11
12
  const INTERNAL_PROPS = /* @__PURE__ */ new Set([
@@ -97,6 +98,7 @@ function isReactTestInstance(val) {
97
98
  if (obj.$$typeof && "type" in obj && "props" in obj) return true;
98
99
  return false;
99
100
  }
101
+ /** @deprecated See the module comment: snapshots now print in Jest's format. */
100
102
  const serializer = {
101
103
  test(val) {
102
104
  return isReactTestInstance(val);
package/dist/setup.mjs CHANGED
@@ -1,9 +1,8 @@
1
1
  import { n as __require } from "./rolldown-runtime-D70C1uOS.mjs";
2
- import { A as buildPressableHostProps, c as createTouchableWithoutFeedbackMock, d as createVirtualizedListMock, f as createSectionListMock, h as createTextInputMock, k as createPressableMock, l as createTouchableHighlightMock, m as createScrollViewMock, o as createViewMock, p as createFlatListMock, t as presets_exports, u as createTouchableOpacityMock } from "./presets-CXDyg51l.mjs";
3
- import { a as presetForInstalled, t as AUTO_DETECT_PRESETS } from "./preset-map-CogjYmSw.mjs";
4
- import { serializer } from "./serializer.mjs";
2
+ import { A as buildPressableHostProps, M as hostComponent, c as createTouchableWithoutFeedbackMock, d as createVirtualizedListMock, f as createSectionListMock, h as createTextInputMock, k as createPressableMock, l as createTouchableHighlightMock, m as createScrollViewMock, o as createViewMock, p as createFlatListMock, t as presets_exports, u as createTouchableOpacityMock } from "./presets-_EaSw29m.mjs";
3
+ import { d as presetForInstalled, t as AUTO_DETECT_PRESETS } from "./preset-map-DdAexIwz.mjs";
5
4
  import { animatedMatchers } from "./matchers.mjs";
6
- import Module, { createRequire } from "node:module";
5
+ import Module$1, { createRequire } from "node:module";
7
6
  import path from "node:path";
8
7
  import { importPresetModule, presetModulePaths } from "./preset-modules.mjs";
9
8
  import { projectContext } from "./context.mjs";
@@ -16,7 +15,7 @@ function createTextMock() {
16
15
  const Text = React.forwardRef((props, ref) => {
17
16
  const { onPress, onLongPress, disabled, accessibilityRole, ...rest } = props;
18
17
  const resolvedRole = accessibilityRole ?? (!disabled && (onPress || onLongPress) ? "link" : void 0);
19
- return React.createElement("Text", {
18
+ return React.createElement(hostComponent("Text"), {
20
19
  accessible: true,
21
20
  ...rest,
22
21
  ...onPress ? { onPress } : {},
@@ -81,7 +80,7 @@ function resolveRegistered(asset, deviceScale, os) {
81
80
  }
82
81
  function createImageMock(context = () => ({})) {
83
82
  const Image = React.forwardRef((props, ref) => {
84
- return React.createElement("Image", {
83
+ return React.createElement(hostComponent("Image"), {
85
84
  ...props,
86
85
  ref
87
86
  });
@@ -113,7 +112,7 @@ function createModalMock() {
113
112
  const Modal = React.forwardRef((props, ref) => {
114
113
  const { visible = true, children, ...rest } = props;
115
114
  if (!visible) return null;
116
- return React.createElement("Modal", {
115
+ return React.createElement(hostComponent("Modal"), {
117
116
  ...rest,
118
117
  visible,
119
118
  ref
@@ -136,7 +135,7 @@ function createTouchableNativeFeedbackMock() {
136
135
  delete rest.onPressOut;
137
136
  delete rest.onLongPress;
138
137
  }
139
- return React.createElement("TouchableNativeFeedback", {
138
+ return React.createElement(hostComponent("TouchableNativeFeedback"), {
140
139
  accessible: true,
141
140
  ...disabled ? { pointerEvents: "none" } : {},
142
141
  ...rest,
@@ -150,7 +149,7 @@ function createTouchableNativeFeedbackMock() {
150
149
  // src/mocks/components/ActivityIndicator.ts
151
150
  function createActivityIndicatorMock() {
152
151
  const ActivityIndicator = React.forwardRef((props, ref) => {
153
- return React.createElement("ActivityIndicator", {
152
+ return React.createElement(hostComponent("ActivityIndicator"), {
154
153
  ...props,
155
154
  ref
156
155
  });
@@ -170,7 +169,7 @@ function createButtonMock() {
170
169
  accessibilityLabel: accessibilityLabel || title,
171
170
  accessibilityRole: "button"
172
171
  }, void 0);
173
- return React.createElement("View", hostProps, React.createElement("Text", {
172
+ return React.createElement(hostComponent("View"), hostProps, React.createElement("Text", {
174
173
  style: color ? { color } : void 0,
175
174
  disabled
176
175
  }, title));
@@ -181,7 +180,7 @@ function createButtonMock() {
181
180
  // src/mocks/components/Switch.ts
182
181
  function createSwitchMock() {
183
182
  const Switch = React.forwardRef((props, ref) => {
184
- return React.createElement("RCTSwitch", {
183
+ return React.createElement(hostComponent("RCTSwitch"), {
185
184
  accessibilityRole: "switch",
186
185
  ...props,
187
186
  ref
@@ -193,7 +192,7 @@ function createSwitchMock() {
193
192
  // src/mocks/components/RefreshControl.ts
194
193
  function createRefreshControlMock() {
195
194
  const RefreshControl = React.forwardRef((props, ref) => {
196
- return React.createElement("RefreshControl", {
195
+ return React.createElement(hostComponent("RefreshControl"), {
197
196
  ...props,
198
197
  ref
199
198
  });
@@ -231,7 +230,7 @@ function createStatusBarMock() {
231
230
  // src/mocks/components/SafeAreaView.ts
232
231
  function createSafeAreaViewMock() {
233
232
  const SafeAreaView = React.forwardRef((props, ref) => {
234
- return React.createElement("SafeAreaView", {
233
+ return React.createElement(hostComponent("SafeAreaView"), {
235
234
  ...props,
236
235
  ref
237
236
  });
@@ -242,7 +241,7 @@ function createSafeAreaViewMock() {
242
241
  // src/mocks/components/KeyboardAvoidingView.ts
243
242
  function createKeyboardAvoidingViewMock() {
244
243
  const KeyboardAvoidingView = React.forwardRef((props, ref) => {
245
- return React.createElement("KeyboardAvoidingView", {
244
+ return React.createElement(hostComponent("KeyboardAvoidingView"), {
246
245
  ...props,
247
246
  ref
248
247
  });
@@ -254,7 +253,7 @@ function createKeyboardAvoidingViewMock() {
254
253
  function createImageBackgroundMock() {
255
254
  const ImageBackground = React.forwardRef((props, ref) => {
256
255
  const { children, style, imageStyle, source, ...rest } = props;
257
- return React.createElement("ImageBackground", {
256
+ return React.createElement(hostComponent("ImageBackground"), {
258
257
  ...rest,
259
258
  ref,
260
259
  style
@@ -269,7 +268,7 @@ function createImageBackgroundMock() {
269
268
  // src/mocks/components/InputAccessoryView.ts
270
269
  function createInputAccessoryViewMock() {
271
270
  const InputAccessoryView = React.forwardRef((props, ref) => {
272
- return React.createElement("InputAccessoryView", {
271
+ return React.createElement(hostComponent("InputAccessoryView"), {
273
272
  ...props,
274
273
  ref
275
274
  });
@@ -281,7 +280,7 @@ function createInputAccessoryViewMock() {
281
280
  function createDrawerLayoutAndroidMock() {
282
281
  const DrawerLayoutAndroid = React.forwardRef((props, ref) => {
283
282
  const { children, ...rest } = props;
284
- return React.createElement("DrawerLayoutAndroid", {
283
+ return React.createElement(hostComponent("DrawerLayoutAndroid"), {
285
284
  ...rest,
286
285
  ref
287
286
  }, children);
@@ -1147,13 +1146,13 @@ function createAnimatedWrapper(displayName) {
1147
1146
  useAnimatedStyleSubscription(props?.style);
1148
1147
  if (props && props.style !== void 0) {
1149
1148
  const { style, ...rest } = props;
1150
- return React.createElement(hostName, {
1149
+ return React.createElement(hostComponent(hostName), {
1151
1150
  ...rest,
1152
1151
  style: resolveAnimatedStyle(style),
1153
1152
  ref
1154
1153
  });
1155
1154
  }
1156
- return React.createElement(hostName, {
1155
+ return React.createElement(hostComponent(hostName), {
1157
1156
  ...props,
1158
1157
  ref
1159
1158
  });
@@ -1405,7 +1404,8 @@ function createAnimatedMock() {
1405
1404
  };
1406
1405
  }),
1407
1406
  unforkEvent: mockFn(),
1408
- createAnimatedComponent: vi.fn((component) => {
1407
+ createAnimatedComponent: vi.fn((given) => {
1408
+ const component = typeof given === "string" ? hostComponent(given) : given;
1409
1409
  const Wrapper = React.forwardRef((props, ref) => {
1410
1410
  useAnimatedStyleSubscription(props?.style);
1411
1411
  if (props && props.style !== void 0) {
@@ -2217,7 +2217,7 @@ function createNativeComponentRegistryMock() {
2217
2217
  return {
2218
2218
  get(name) {
2219
2219
  const Component = React.forwardRef((props, ref) => {
2220
- return React.createElement(name, {
2220
+ return React.createElement(hostComponent(name), {
2221
2221
  ...props,
2222
2222
  ref
2223
2223
  });
@@ -2234,7 +2234,7 @@ function createNativeComponentRegistryMock() {
2234
2234
  function createRequireNativeComponentMock() {
2235
2235
  return function requireNativeComponent(viewName) {
2236
2236
  const Component = React.forwardRef((props, ref) => {
2237
- return React.createElement(viewName, {
2237
+ return React.createElement(hostComponent(viewName), {
2238
2238
  ...props,
2239
2239
  ref
2240
2240
  });
@@ -2401,7 +2401,7 @@ function createVirtualizedSectionListMock() {
2401
2401
  })));
2402
2402
  });
2403
2403
  });
2404
- return React.createElement("VirtualizedSectionList", {
2404
+ return React.createElement(hostComponent("VirtualizedSectionList"), {
2405
2405
  ...rest,
2406
2406
  ref
2407
2407
  }, ...children);
@@ -2544,7 +2544,7 @@ function buildReactNativeMock(platform = "ios") {
2544
2544
  NBSP: "\xA0"
2545
2545
  },
2546
2546
  ProgressBarAndroid: (() => {
2547
- const C = React.forwardRef((props, ref) => React.createElement("ProgressBarAndroid", {
2547
+ const C = React.forwardRef((props, ref) => React.createElement(hostComponent("ProgressBarAndroid"), {
2548
2548
  ...props,
2549
2549
  ref
2550
2550
  }));
@@ -2745,7 +2745,7 @@ function installPresetCjsBridge(moduleName, mockObject) {
2745
2745
  * 4. Auto-detects and installs preset mocks
2746
2746
  * 5. Configures @testing-library/react-native host component names
2747
2747
  * 6. Auto-registers RNTL matchers
2748
- * 7. Registers snapshot serializer
2748
+ * 7. Leaves snapshots to Vitest's own printer (see below)
2749
2749
  *
2750
2750
  * Options are received through the project context, which the plugin's config() hook
2751
2751
  * writes and names in test.env. This is necessary because the plugin runs in Vite's main
@@ -2801,7 +2801,7 @@ if (typeof g.expect === "undefined") Object.defineProperty(g, "expect", {
2801
2801
  });
2802
2802
  g.IS_REACT_ACT_ENVIRONMENT = true;
2803
2803
  g.IS_REACT_NATIVE_TEST_ENVIRONMENT = true;
2804
- installRendererReportError(Module, g);
2804
+ installRendererReportError(Module$1, g);
2805
2805
  const rnMock = buildReactNativeMock(platform);
2806
2806
  if (Object.keys(customMocks).length > 0) Object.assign(rnMock, customMocks);
2807
2807
  g.__vitest_native_mock = rnMock;
@@ -2914,7 +2914,6 @@ try {
2914
2914
  }
2915
2915
  expect.extend(animatedMatchers);
2916
2916
  if (diagnostics) console.log(`[vitest-native] Registered ${Object.keys(animatedMatchers).length} animated matchers: ${Object.keys(animatedMatchers).join(", ")}`);
2917
- expect.addSnapshotSerializer(serializer);
2918
2917
  afterAll(() => {
2919
2918
  uninstallCjsBridge();
2920
2919
  });