vitest-native 0.13.0 → 0.14.0-rc.10

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 (117) hide show
  1. package/CHANGELOG.md +746 -0
  2. package/README.md +205 -88
  3. package/dist/cli.cjs +1478 -145
  4. package/dist/cli.d.cts +2 -3
  5. package/dist/cli.d.mts +2 -3
  6. package/dist/cli.mjs +1475 -142
  7. package/dist/context.d.mts +40 -0
  8. package/dist/context.mjs +238 -0
  9. package/dist/errors.d.mts +19 -0
  10. package/dist/helpers.cjs +6 -9
  11. package/dist/helpers.d.cts +8 -9
  12. package/dist/helpers.d.mts +8 -9
  13. package/dist/helpers.mjs +6 -9
  14. package/dist/host-D3wzmsw8.cjs +1296 -0
  15. package/dist/host-DCPzgC3D.mjs +1180 -0
  16. package/dist/{index-CPGq6p95.d.cts → index-CPEAYjaQ.d.mts} +88 -19
  17. package/dist/{index-CmETArCM.d.mts → index-D5cOy_iY.d.cts} +89 -18
  18. package/dist/index.d.mts +4 -4
  19. package/dist/index.mjs +1366 -210
  20. package/dist/jest-compat/aliases.d.mts +5 -0
  21. package/dist/jest-compat/aliases.mjs +65 -0
  22. package/dist/jest-compat/caller.mjs +53 -0
  23. package/dist/jest-compat/error-equality.mjs +127 -0
  24. package/dist/jest-compat/interop.mjs +78 -4
  25. package/dist/jest-compat/jest-globals.mjs +5 -2
  26. package/dist/jest-compat/jest-object.mjs +348 -0
  27. package/dist/jest-compat/node-registry.mjs +489 -0
  28. package/dist/jest-compat/setup.mjs +167 -66
  29. package/dist/jest-compat.cjs +35 -5
  30. package/dist/jest-compat.d.cts +9 -5
  31. package/dist/jest-compat.d.mts +9 -5
  32. package/dist/jest-compat.mjs +35 -3
  33. package/dist/matchers.d.cts +9 -8
  34. package/dist/matchers.d.mts +9 -8
  35. package/dist/memory-BFxB285Z.mjs +137 -0
  36. package/dist/memory-bBnzadf6.cjs +155 -0
  37. package/dist/native/assets.d.mts +39 -0
  38. package/dist/native/assets.mjs +431 -0
  39. package/dist/native/babel-preset.d.mts +14 -0
  40. package/dist/native/babel-preset.mjs +56 -0
  41. package/dist/native/boundary.mjs +71 -8
  42. package/dist/native/bounded-process.mjs +165 -0
  43. package/dist/native/compile-cache.mjs +21 -9
  44. package/dist/native/expo-module-mocks.mjs +432 -0
  45. package/dist/native/expo-module-table-57.mjs +1925 -0
  46. package/dist/native/expo-module-table-58.mjs +2045 -0
  47. package/dist/native/expo-module-tables.mjs +6 -0
  48. package/dist/native/expo-native-modules.mjs +66 -0
  49. package/dist/native/export-condition-recovery-preload.mjs +5 -0
  50. package/dist/native/export-condition-recovery.mjs +195 -0
  51. package/dist/native/globals.mjs +289 -9
  52. package/dist/native/hooks.mjs +392 -114
  53. package/dist/native/loader.mjs +346 -75
  54. package/dist/native/match.d.mts +13 -0
  55. package/dist/native/match.mjs +127 -2
  56. package/dist/native/metro-profile-compiler.mjs +234 -0
  57. package/dist/native/metro-profile.mjs +115 -0
  58. package/dist/native/module-reset.mjs +172 -6
  59. package/dist/native/native-modules.d.mts +15 -0
  60. package/dist/native/native-modules.mjs +228 -0
  61. package/dist/native/nitro.mjs +60 -0
  62. package/dist/native/ownership.d.mts +105 -0
  63. package/dist/native/ownership.mjs +474 -0
  64. package/dist/native/registry-compiler.mjs +43 -0
  65. package/dist/native/registry-process.mjs +124 -0
  66. package/dist/native/registry.mjs +197 -39
  67. package/dist/native/reset.mjs +334 -135
  68. package/dist/native/resolve.d.mts +20 -3
  69. package/dist/native/resolve.mjs +103 -17
  70. package/dist/native/rntl-hooks.mjs +227 -0
  71. package/dist/native/rntl-text-host.mjs +64 -0
  72. package/dist/native/runner.mjs +33 -1
  73. package/dist/native/setup.mjs +284 -96
  74. package/dist/native/state-manifest.d.mts +22 -0
  75. package/dist/native/state-manifest.mjs +138 -0
  76. package/dist/native/transform.d.mts +2 -0
  77. package/dist/native/transform.mjs +270 -47
  78. package/dist/native/tsconfig-paths.d.mts +5 -0
  79. package/dist/native/tsconfig-paths.mjs +163 -0
  80. package/dist/native/worker.mjs +151 -40
  81. package/dist/pool-DUOe-n1k.mjs +125 -0
  82. package/dist/pool-DaTJRKJb.cjs +127 -0
  83. package/dist/preset-map-BlBriTA0.mjs +197 -0
  84. package/dist/preset-map-jSFsNy1Q.cjs +241 -0
  85. package/dist/preset-modules-Bt6k_Wdw.mjs +31 -0
  86. package/dist/preset-modules-C7gu3bPn.cjs +48 -0
  87. package/dist/preset-modules.d.mts +16 -0
  88. package/dist/preset-modules.mjs +92 -0
  89. package/dist/preset-ready.mjs +9 -0
  90. package/dist/{presets-CoNf4ByH.cjs → presets-DH7fC0YV.cjs} +1125 -102
  91. package/dist/{presets-DGProTaA.mjs → presets-DuXiUNAx.mjs} +1107 -103
  92. package/dist/presets.d.mts +2 -2
  93. package/dist/presets.mjs +1 -2
  94. package/dist/report-error.d.mts +20 -0
  95. package/dist/report-error.mjs +145 -0
  96. package/dist/rntl-matchers.d.ts +58 -12
  97. package/dist/rntl-support.d.mts +12 -0
  98. package/dist/rntl-support.mjs +189 -0
  99. package/dist/serializer.cjs +4 -2
  100. package/dist/serializer.d.cts +3 -4
  101. package/dist/serializer.d.mts +3 -4
  102. package/dist/serializer.mjs +4 -2
  103. package/dist/setup.mjs +463 -97
  104. package/dist/worker-vitest-BGPo0ek6.mjs +49 -0
  105. package/dist/worker-vitest-BfiQB8ND.cjs +62 -0
  106. package/docs/hot-default-design.md +181 -88
  107. package/docs/migrating-from-jest.md +74 -16
  108. package/docs/migrating-from-vitest-react-native.md +5 -5
  109. package/docs/release-readiness.md +55 -15
  110. package/docs/versioning.md +31 -22
  111. package/package.json +122 -98
  112. package/dist/ecosystem-CEIF_-jq.cjs +0 -659
  113. package/dist/ecosystem-Duw40-mO.mjs +0 -597
  114. package/dist/pool-BU-1ecIF.cjs +0 -122
  115. package/dist/pool-Bcxn9a3I.mjs +0 -118
  116. package/dist/preset-map-BoG19dLa.cjs +0 -35
  117. package/dist/preset-map-DuX0ocdn.mjs +0 -30
@@ -0,0 +1,197 @@
1
+ import fs from "node:fs";
2
+ import path from "node:path";
3
+ //#region src/preset-map.ts
4
+ /**
5
+ * Map of npm package names to their built-in preset export names.
6
+ * Shared between plugin.ts (Vite main process) and setup.ts (Vitest workers).
7
+ */
8
+ const AUTO_DETECT_PRESETS = {
9
+ "react-native-reanimated": "reanimated",
10
+ "react-native-worklets": "worklets",
11
+ "react-native-gesture-handler": "gestureHandler",
12
+ "react-native-safe-area-context": "safeAreaContext",
13
+ "@react-navigation/native": "navigation",
14
+ "@react-navigation/native-stack": "navigation",
15
+ "@react-navigation/bottom-tabs": "navigation",
16
+ "@react-navigation/elements": "navigation",
17
+ "@react-navigation/drawer": "navigation",
18
+ "@react-native-async-storage/async-storage": "asyncStorage",
19
+ "react-native-screens": "screens",
20
+ "expo-constants": "expo",
21
+ "react-native-device-info": "deviceInfo",
22
+ "react-native-mmkv": "mmkv",
23
+ "@react-native-community/netinfo": "netInfo",
24
+ "react-native-svg": "svg",
25
+ "react-native-webview": "webview",
26
+ "@react-native-vector-icons/common": "vectorIcons",
27
+ "@shopify/flash-list": "flashList",
28
+ "@gorhom/bottom-sheet": "bottomSheet",
29
+ "react-native-keyboard-controller": "keyboardController",
30
+ "react-native-unistyles": "unistyles",
31
+ "react-native-skia": "skia",
32
+ "@shopify/react-native-skia": "skia"
33
+ };
34
+ /**
35
+ * Packages whose own JavaScript switches to a built-in in-memory implementation under
36
+ * Vitest, from the given major on. Their preset would replace the real library with a
37
+ * hand-written approximation, so it steps aside and the library tests itself:
38
+ * - react-native-mmkv 3+: `isTest()` checks `VITEST_WORKER_ID` (and Jest's
39
+ * `JEST_WORKER_ID`), and `createMMKV` then returns `createMockMMKV()` — the real
40
+ * API (v4's `remove`, change listeners) with no native module. v4 imports
41
+ * react-native-nitro-modules at load time, which the native engine's Nitro boundary
42
+ * satisfies (see native/boundary.mjs). Before v3 there was no Vitest check.
43
+ */
44
+ const SELF_TESTING_FROM_MAJOR = { "react-native-mmkv": 3 };
45
+ /**
46
+ * Presets the native engine does not apply unless asked to, because the packages they
47
+ * cover run as themselves there. The native engine runs a package's own JavaScript and
48
+ * substitutes only its native module, the way jest-expo runs Expo packages: the real
49
+ * code is the whole API, current with every SDK, where a replacement covers only what
50
+ * was written into it.
51
+ *
52
+ * - expo: expo-constants, expo-font, expo-asset, expo-splash-screen, expo-linking and
53
+ * expo-status-bar run against the engine's Expo runtime (native/globals.mjs) and
54
+ * their own native-module mocks (native/expo-module-mocks.mjs). Measured on an
55
+ * Expo SDK 58 app against jest-expo: 17 of 17 probes of these packages matched with
56
+ * the preset off, 4 with it on. The preset was missing API (`hide`, `setOptions`,
57
+ * `useAssets`, `canOpenURL` …) and answered with values jest-expo never gives
58
+ * (`Constants.expoConfig.name === 'test-app'`).
59
+ *
60
+ * The mock engine has no real React Native to run them on, so it keeps these presets.
61
+ * `presets: { expo: true }` applies one under the native engine too.
62
+ */
63
+ const NATIVE_ENGINE_RUNS_PACKAGES = ["expo"];
64
+ /**
65
+ * Whether an auto-detected preset applies under `engine`, given the `presets` option:
66
+ * every one under the mock engine, and under the native engine all but those in
67
+ * NATIVE_ENGINE_RUNS_PACKAGES, unless the option turns one on (`{ expo: true }`).
68
+ */
69
+ function autoDetectedPresetApplies(preset, engine, presetsOption) {
70
+ if (engine === "mock" || !NATIVE_ENGINE_RUNS_PACKAGES.includes(preset)) return true;
71
+ return presetsOption !== null && typeof presetsOption === "object" && !Array.isArray(presetsOption) && presetsOption[preset] === true;
72
+ }
73
+ /** Whether `pkgName` at `version` runs its own test mode (SELF_TESTING_FROM_MAJOR). */
74
+ function testsItself(pkgName, version) {
75
+ const floor = SELF_TESTING_FROM_MAJOR[pkgName];
76
+ if (floor === void 0 || typeof version !== "string") return false;
77
+ const major = Number.parseInt(version, 10);
78
+ return !Number.isNaN(major) && major >= floor;
79
+ }
80
+ /**
81
+ * The installed version, from the package's own manifest on disk. Not
82
+ * `require('<pkg>/package.json')`: a package whose `exports` map omits ./package.json
83
+ * throws there, and a gate that fails closed would put the preset back over a library
84
+ * that tests itself, silently.
85
+ */
86
+ function installedVersion(pkgName, req) {
87
+ let dir;
88
+ try {
89
+ dir = path.dirname(req.resolve(pkgName));
90
+ } catch {
91
+ return;
92
+ }
93
+ for (;;) {
94
+ const file = path.join(dir, "package.json");
95
+ if (fs.existsSync(file)) try {
96
+ const manifest = JSON.parse(fs.readFileSync(file, "utf8"));
97
+ if (manifest.name === pkgName) return manifest.version;
98
+ } catch {}
99
+ const up = path.dirname(dir);
100
+ if (up === dir) return void 0;
101
+ dir = up;
102
+ }
103
+ }
104
+ /**
105
+ * The preset that shadows `pkgName` in this project, or null when the package is not
106
+ * installed or tests itself (SELF_TESTING_FROM_MAJOR). Every place that decides which
107
+ * presets are active asks this, so the plugin, the worker setup and ecosystem
108
+ * detection cannot disagree about a package.
109
+ */
110
+ function presetForInstalled(pkgName, req) {
111
+ try {
112
+ req.resolve(pkgName);
113
+ } catch {
114
+ return null;
115
+ }
116
+ if (testsItself(pkgName, installedVersion(pkgName, req))) return null;
117
+ return AUTO_DETECT_PRESETS[pkgName] ?? null;
118
+ }
119
+ /**
120
+ * The module ids each preset shadows — `Object.keys(preset().modules)`, written out.
121
+ *
122
+ * The CLI states what a preset covers (`migrate`: "the expo preset shadows
123
+ * expo-constants, …"; "__mocks__/x — the y preset shadows it"), and a claim like that
124
+ * must come from the preset itself. The presets cannot be imported to ask: they load
125
+ * `vitest` and `react`, which the CLI must not require (doctor runs in projects where
126
+ * neither resolves yet). So the ids are listed here, and `tests/preset-map.test.ts`
127
+ * calls every preset factory and fails if a list and its preset disagree in either
128
+ * direction, so the two cannot drift without a red build.
129
+ */
130
+ const PRESET_MODULES = {
131
+ reanimated: ["react-native-reanimated"],
132
+ worklets: ["react-native-worklets"],
133
+ gestureHandler: ["react-native-gesture-handler"],
134
+ safeAreaContext: ["react-native-safe-area-context"],
135
+ navigation: [
136
+ "@react-navigation/native",
137
+ "@react-navigation/native-stack",
138
+ "@react-navigation/bottom-tabs",
139
+ "@react-navigation/drawer",
140
+ "@react-navigation/elements"
141
+ ],
142
+ asyncStorage: ["@react-native-async-storage/async-storage"],
143
+ screens: ["react-native-screens"],
144
+ expo: [
145
+ "expo-constants",
146
+ "expo-font",
147
+ "expo-asset",
148
+ "expo-splash-screen",
149
+ "expo-linking",
150
+ "expo-status-bar"
151
+ ],
152
+ deviceInfo: ["react-native-device-info"],
153
+ mmkv: ["react-native-mmkv"],
154
+ netInfo: ["@react-native-community/netinfo"],
155
+ svg: ["react-native-svg"],
156
+ webview: ["react-native-webview"],
157
+ vectorIcons: ["@react-native-vector-icons/common"],
158
+ flashList: ["@shopify/flash-list"],
159
+ bottomSheet: ["@gorhom/bottom-sheet"],
160
+ keyboardController: ["react-native-keyboard-controller"],
161
+ unistyles: ["react-native-unistyles", "react-native-unistyles/reanimated"],
162
+ skia: ["react-native-skia", "@shopify/react-native-skia"]
163
+ };
164
+ /** The preset that shadows `moduleId`, or undefined when none does. */
165
+ function presetShadowing(moduleId) {
166
+ for (const [preset, modules] of Object.entries(PRESET_MODULES)) if (modules.includes(moduleId)) return preset;
167
+ }
168
+ /**
169
+ * Asset extensions the plugin handles before any Metro profile or `assetExts` option
170
+ * adds more. Kept here, not in plugin.ts, so the CLI can say which of a Jest asset
171
+ * mapper's extensions are covered without loading the plugin.
172
+ */
173
+ const DEFAULT_ASSET_EXTS = [
174
+ "png",
175
+ "jpg",
176
+ "jpeg",
177
+ "gif",
178
+ "bmp",
179
+ "webp",
180
+ "svg",
181
+ "tiff",
182
+ "heic",
183
+ "heif",
184
+ "mp4",
185
+ "mp3",
186
+ "wav",
187
+ "aac",
188
+ "m4a",
189
+ "mov",
190
+ "webm",
191
+ "ttf",
192
+ "otf",
193
+ "woff",
194
+ "woff2"
195
+ ];
196
+ //#endregion
197
+ export { presetForInstalled as a, autoDetectedPresetApplies as i, DEFAULT_ASSET_EXTS as n, presetShadowing as o, PRESET_MODULES as r, testsItself as s, AUTO_DETECT_PRESETS as t };
@@ -0,0 +1,241 @@
1
+ const require_rolldown_runtime = require("./rolldown-runtime-C0BPl7ul.cjs");
2
+ let node_fs = require("node:fs");
3
+ node_fs = require_rolldown_runtime.__toESM(node_fs, 1);
4
+ let node_path = require("node:path");
5
+ node_path = require_rolldown_runtime.__toESM(node_path, 1);
6
+ //#region src/preset-map.ts
7
+ /**
8
+ * Map of npm package names to their built-in preset export names.
9
+ * Shared between plugin.ts (Vite main process) and setup.ts (Vitest workers).
10
+ */
11
+ const AUTO_DETECT_PRESETS = {
12
+ "react-native-reanimated": "reanimated",
13
+ "react-native-worklets": "worklets",
14
+ "react-native-gesture-handler": "gestureHandler",
15
+ "react-native-safe-area-context": "safeAreaContext",
16
+ "@react-navigation/native": "navigation",
17
+ "@react-navigation/native-stack": "navigation",
18
+ "@react-navigation/bottom-tabs": "navigation",
19
+ "@react-navigation/elements": "navigation",
20
+ "@react-navigation/drawer": "navigation",
21
+ "@react-native-async-storage/async-storage": "asyncStorage",
22
+ "react-native-screens": "screens",
23
+ "expo-constants": "expo",
24
+ "react-native-device-info": "deviceInfo",
25
+ "react-native-mmkv": "mmkv",
26
+ "@react-native-community/netinfo": "netInfo",
27
+ "react-native-svg": "svg",
28
+ "react-native-webview": "webview",
29
+ "@react-native-vector-icons/common": "vectorIcons",
30
+ "@shopify/flash-list": "flashList",
31
+ "@gorhom/bottom-sheet": "bottomSheet",
32
+ "react-native-keyboard-controller": "keyboardController",
33
+ "react-native-unistyles": "unistyles",
34
+ "react-native-skia": "skia",
35
+ "@shopify/react-native-skia": "skia"
36
+ };
37
+ /**
38
+ * Packages whose own JavaScript switches to a built-in in-memory implementation under
39
+ * Vitest, from the given major on. Their preset would replace the real library with a
40
+ * hand-written approximation, so it steps aside and the library tests itself:
41
+ * - react-native-mmkv 3+: `isTest()` checks `VITEST_WORKER_ID` (and Jest's
42
+ * `JEST_WORKER_ID`), and `createMMKV` then returns `createMockMMKV()` — the real
43
+ * API (v4's `remove`, change listeners) with no native module. v4 imports
44
+ * react-native-nitro-modules at load time, which the native engine's Nitro boundary
45
+ * satisfies (see native/boundary.mjs). Before v3 there was no Vitest check.
46
+ */
47
+ const SELF_TESTING_FROM_MAJOR = { "react-native-mmkv": 3 };
48
+ /**
49
+ * Presets the native engine does not apply unless asked to, because the packages they
50
+ * cover run as themselves there. The native engine runs a package's own JavaScript and
51
+ * substitutes only its native module, the way jest-expo runs Expo packages: the real
52
+ * code is the whole API, current with every SDK, where a replacement covers only what
53
+ * was written into it.
54
+ *
55
+ * - expo: expo-constants, expo-font, expo-asset, expo-splash-screen, expo-linking and
56
+ * expo-status-bar run against the engine's Expo runtime (native/globals.mjs) and
57
+ * their own native-module mocks (native/expo-module-mocks.mjs). Measured on an
58
+ * Expo SDK 58 app against jest-expo: 17 of 17 probes of these packages matched with
59
+ * the preset off, 4 with it on. The preset was missing API (`hide`, `setOptions`,
60
+ * `useAssets`, `canOpenURL` …) and answered with values jest-expo never gives
61
+ * (`Constants.expoConfig.name === 'test-app'`).
62
+ *
63
+ * The mock engine has no real React Native to run them on, so it keeps these presets.
64
+ * `presets: { expo: true }` applies one under the native engine too.
65
+ */
66
+ const NATIVE_ENGINE_RUNS_PACKAGES = ["expo"];
67
+ /**
68
+ * Whether an auto-detected preset applies under `engine`, given the `presets` option:
69
+ * every one under the mock engine, and under the native engine all but those in
70
+ * NATIVE_ENGINE_RUNS_PACKAGES, unless the option turns one on (`{ expo: true }`).
71
+ */
72
+ function autoDetectedPresetApplies(preset, engine, presetsOption) {
73
+ if (engine === "mock" || !NATIVE_ENGINE_RUNS_PACKAGES.includes(preset)) return true;
74
+ return presetsOption !== null && typeof presetsOption === "object" && !Array.isArray(presetsOption) && presetsOption[preset] === true;
75
+ }
76
+ /** Whether `pkgName` at `version` runs its own test mode (SELF_TESTING_FROM_MAJOR). */
77
+ function testsItself(pkgName, version) {
78
+ const floor = SELF_TESTING_FROM_MAJOR[pkgName];
79
+ if (floor === void 0 || typeof version !== "string") return false;
80
+ const major = Number.parseInt(version, 10);
81
+ return !Number.isNaN(major) && major >= floor;
82
+ }
83
+ /**
84
+ * The installed version, from the package's own manifest on disk. Not
85
+ * `require('<pkg>/package.json')`: a package whose `exports` map omits ./package.json
86
+ * throws there, and a gate that fails closed would put the preset back over a library
87
+ * that tests itself, silently.
88
+ */
89
+ function installedVersion(pkgName, req) {
90
+ let dir;
91
+ try {
92
+ dir = node_path.default.dirname(req.resolve(pkgName));
93
+ } catch {
94
+ return;
95
+ }
96
+ for (;;) {
97
+ const file = node_path.default.join(dir, "package.json");
98
+ if (node_fs.default.existsSync(file)) try {
99
+ const manifest = JSON.parse(node_fs.default.readFileSync(file, "utf8"));
100
+ if (manifest.name === pkgName) return manifest.version;
101
+ } catch {}
102
+ const up = node_path.default.dirname(dir);
103
+ if (up === dir) return void 0;
104
+ dir = up;
105
+ }
106
+ }
107
+ /**
108
+ * The preset that shadows `pkgName` in this project, or null when the package is not
109
+ * installed or tests itself (SELF_TESTING_FROM_MAJOR). Every place that decides which
110
+ * presets are active asks this, so the plugin, the worker setup and ecosystem
111
+ * detection cannot disagree about a package.
112
+ */
113
+ function presetForInstalled(pkgName, req) {
114
+ try {
115
+ req.resolve(pkgName);
116
+ } catch {
117
+ return null;
118
+ }
119
+ if (testsItself(pkgName, installedVersion(pkgName, req))) return null;
120
+ return AUTO_DETECT_PRESETS[pkgName] ?? null;
121
+ }
122
+ /**
123
+ * The module ids each preset shadows — `Object.keys(preset().modules)`, written out.
124
+ *
125
+ * The CLI states what a preset covers (`migrate`: "the expo preset shadows
126
+ * expo-constants, …"; "__mocks__/x — the y preset shadows it"), and a claim like that
127
+ * must come from the preset itself. The presets cannot be imported to ask: they load
128
+ * `vitest` and `react`, which the CLI must not require (doctor runs in projects where
129
+ * neither resolves yet). So the ids are listed here, and `tests/preset-map.test.ts`
130
+ * calls every preset factory and fails if a list and its preset disagree in either
131
+ * direction, so the two cannot drift without a red build.
132
+ */
133
+ const PRESET_MODULES = {
134
+ reanimated: ["react-native-reanimated"],
135
+ worklets: ["react-native-worklets"],
136
+ gestureHandler: ["react-native-gesture-handler"],
137
+ safeAreaContext: ["react-native-safe-area-context"],
138
+ navigation: [
139
+ "@react-navigation/native",
140
+ "@react-navigation/native-stack",
141
+ "@react-navigation/bottom-tabs",
142
+ "@react-navigation/drawer",
143
+ "@react-navigation/elements"
144
+ ],
145
+ asyncStorage: ["@react-native-async-storage/async-storage"],
146
+ screens: ["react-native-screens"],
147
+ expo: [
148
+ "expo-constants",
149
+ "expo-font",
150
+ "expo-asset",
151
+ "expo-splash-screen",
152
+ "expo-linking",
153
+ "expo-status-bar"
154
+ ],
155
+ deviceInfo: ["react-native-device-info"],
156
+ mmkv: ["react-native-mmkv"],
157
+ netInfo: ["@react-native-community/netinfo"],
158
+ svg: ["react-native-svg"],
159
+ webview: ["react-native-webview"],
160
+ vectorIcons: ["@react-native-vector-icons/common"],
161
+ flashList: ["@shopify/flash-list"],
162
+ bottomSheet: ["@gorhom/bottom-sheet"],
163
+ keyboardController: ["react-native-keyboard-controller"],
164
+ unistyles: ["react-native-unistyles", "react-native-unistyles/reanimated"],
165
+ skia: ["react-native-skia", "@shopify/react-native-skia"]
166
+ };
167
+ /** The preset that shadows `moduleId`, or undefined when none does. */
168
+ function presetShadowing(moduleId) {
169
+ for (const [preset, modules] of Object.entries(PRESET_MODULES)) if (modules.includes(moduleId)) return preset;
170
+ }
171
+ /**
172
+ * Asset extensions the plugin handles before any Metro profile or `assetExts` option
173
+ * adds more. Kept here, not in plugin.ts, so the CLI can say which of a Jest asset
174
+ * mapper's extensions are covered without loading the plugin.
175
+ */
176
+ const DEFAULT_ASSET_EXTS = [
177
+ "png",
178
+ "jpg",
179
+ "jpeg",
180
+ "gif",
181
+ "bmp",
182
+ "webp",
183
+ "svg",
184
+ "tiff",
185
+ "heic",
186
+ "heif",
187
+ "mp4",
188
+ "mp3",
189
+ "wav",
190
+ "aac",
191
+ "m4a",
192
+ "mov",
193
+ "webm",
194
+ "ttf",
195
+ "otf",
196
+ "woff",
197
+ "woff2"
198
+ ];
199
+ //#endregion
200
+ Object.defineProperty(exports, "AUTO_DETECT_PRESETS", {
201
+ enumerable: true,
202
+ get: function() {
203
+ return AUTO_DETECT_PRESETS;
204
+ }
205
+ });
206
+ Object.defineProperty(exports, "DEFAULT_ASSET_EXTS", {
207
+ enumerable: true,
208
+ get: function() {
209
+ return DEFAULT_ASSET_EXTS;
210
+ }
211
+ });
212
+ Object.defineProperty(exports, "PRESET_MODULES", {
213
+ enumerable: true,
214
+ get: function() {
215
+ return PRESET_MODULES;
216
+ }
217
+ });
218
+ Object.defineProperty(exports, "autoDetectedPresetApplies", {
219
+ enumerable: true,
220
+ get: function() {
221
+ return autoDetectedPresetApplies;
222
+ }
223
+ });
224
+ Object.defineProperty(exports, "presetForInstalled", {
225
+ enumerable: true,
226
+ get: function() {
227
+ return presetForInstalled;
228
+ }
229
+ });
230
+ Object.defineProperty(exports, "presetShadowing", {
231
+ enumerable: true,
232
+ get: function() {
233
+ return presetShadowing;
234
+ }
235
+ });
236
+ Object.defineProperty(exports, "testsItself", {
237
+ enumerable: true,
238
+ get: function() {
239
+ return testsItself;
240
+ }
241
+ });
@@ -0,0 +1,31 @@
1
+ import { n as VitestNativeTypeError } from "./errors-CxoBUfVJ.mjs";
2
+ import { projectContext } from "./context.mjs";
3
+ //#region src/preset-modules.mjs
4
+ const IDENTIFIER = /^[A-Za-z_$][\w$]*$/;
5
+ const RESERVED = new Set("await break case catch class const continue debugger default delete do else enum export extends false finally for function if implements import in instanceof interface let new null package private protected public return static super switch this throw true try typeof var void while with yield".split(" "));
6
+ /**
7
+ * The preset a preset module exports: its default export, either a preset or a
8
+ * function returning one (called with no arguments).
9
+ */
10
+ function presetFromModule(namespace, file) {
11
+ const exported = namespace?.default;
12
+ const preset = typeof exported === "function" ? exported() : exported;
13
+ const isObject = (value) => value !== null && typeof value === "object";
14
+ if (typeof preset?.then === "function") throw new VitestNativeTypeError("INVALID_OPTION", `The preset module ${file} default-exports an async function. The plugin reads the preset synchronously; put async work in the preset's prepare(), which the test workers await before any test file loads.`);
15
+ if (!isObject(preset) || typeof preset.name !== "string" || !preset.name || !isObject(preset.modules)) throw new VitestNativeTypeError("INVALID_OPTION", `The preset module ${file} must default-export a preset ({ name, modules }) or a function that returns one.`);
16
+ for (const [moduleName, presetModule] of Object.entries(preset.modules)) {
17
+ if (!isObject(presetModule) || typeof presetModule.factory !== "function" || !(Array.isArray(presetModule.exports) || typeof presetModule.exportsFor === "function")) throw new VitestNativeTypeError("INVALID_OPTION", `The preset module ${file} declares '${moduleName}' without a factory function and an exports array.`);
18
+ for (const name of presetModule.exports ?? []) if (typeof name !== "string" || !IDENTIFIER.test(name) || RESERVED.has(name)) throw new VitestNativeTypeError("INVALID_OPTION", `The preset module ${file} lists ${JSON.stringify(name)} among the exports of '${moduleName}'. Each must be a name a variable could have` + (name === "default" ? `; the default import is the whole module object the factory returns.` : `.`));
19
+ }
20
+ return preset;
21
+ }
22
+ /** The preset module paths the plugin passed this worker, absolute. */
23
+ function presetModulePaths() {
24
+ return [...projectContext()?.presetModules ?? []];
25
+ }
26
+ /** Imports a preset module in a test worker, through Vitest so TypeScript loads. */
27
+ async function importPresetModule(vi, file) {
28
+ return presetFromModule(await vi.importActual(file), file);
29
+ }
30
+ //#endregion
31
+ export { presetFromModule as n, presetModulePaths as r, importPresetModule as t };
@@ -0,0 +1,48 @@
1
+ const require_errors = require("./errors-B3lJK46O.cjs");
2
+ let src_context_mjs = require("./context.mjs");
3
+ //#region src/preset-modules.mjs
4
+ const IDENTIFIER = /^[A-Za-z_$][\w$]*$/;
5
+ const RESERVED = new Set("await break case catch class const continue debugger default delete do else enum export extends false finally for function if implements import in instanceof interface let new null package private protected public return static super switch this throw true try typeof var void while with yield".split(" "));
6
+ /**
7
+ * The preset a preset module exports: its default export, either a preset or a
8
+ * function returning one (called with no arguments).
9
+ */
10
+ function presetFromModule(namespace, file) {
11
+ const exported = namespace?.default;
12
+ const preset = typeof exported === "function" ? exported() : exported;
13
+ const isObject = (value) => value !== null && typeof value === "object";
14
+ if (typeof preset?.then === "function") throw new require_errors.VitestNativeTypeError("INVALID_OPTION", `The preset module ${file} default-exports an async function. The plugin reads the preset synchronously; put async work in the preset's prepare(), which the test workers await before any test file loads.`);
15
+ if (!isObject(preset) || typeof preset.name !== "string" || !preset.name || !isObject(preset.modules)) throw new require_errors.VitestNativeTypeError("INVALID_OPTION", `The preset module ${file} must default-export a preset ({ name, modules }) or a function that returns one.`);
16
+ for (const [moduleName, presetModule] of Object.entries(preset.modules)) {
17
+ if (!isObject(presetModule) || typeof presetModule.factory !== "function" || !(Array.isArray(presetModule.exports) || typeof presetModule.exportsFor === "function")) throw new require_errors.VitestNativeTypeError("INVALID_OPTION", `The preset module ${file} declares '${moduleName}' without a factory function and an exports array.`);
18
+ for (const name of presetModule.exports ?? []) if (typeof name !== "string" || !IDENTIFIER.test(name) || RESERVED.has(name)) throw new require_errors.VitestNativeTypeError("INVALID_OPTION", `The preset module ${file} lists ${JSON.stringify(name)} among the exports of '${moduleName}'. Each must be a name a variable could have` + (name === "default" ? `; the default import is the whole module object the factory returns.` : `.`));
19
+ }
20
+ return preset;
21
+ }
22
+ /** The preset module paths the plugin passed this worker, absolute. */
23
+ function presetModulePaths() {
24
+ return [...(0, src_context_mjs.projectContext)()?.presetModules ?? []];
25
+ }
26
+ /** Imports a preset module in a test worker, through Vitest so TypeScript loads. */
27
+ async function importPresetModule(vi, file) {
28
+ return presetFromModule(await vi.importActual(file), file);
29
+ }
30
+ //#endregion
31
+ Object.defineProperty(exports, "importPresetModule", {
32
+ enumerable: true,
33
+ get: function() {
34
+ return importPresetModule;
35
+ }
36
+ });
37
+ Object.defineProperty(exports, "presetFromModule", {
38
+ enumerable: true,
39
+ get: function() {
40
+ return presetFromModule;
41
+ }
42
+ });
43
+ Object.defineProperty(exports, "presetModulePaths", {
44
+ enumerable: true,
45
+ get: function() {
46
+ return presetModulePaths;
47
+ }
48
+ });
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Types for preset-modules.mjs (plain .mjs: see the comment there). Self-contained,
3
+ * since it ships beside the built files; callers narrow the result to their `Preset`.
4
+ */
5
+ export interface LoadedPreset {
6
+ name: string;
7
+ modules: Record<string, unknown>;
8
+ [key: string]: unknown;
9
+ }
10
+
11
+ export declare function presetFromModule(namespace: unknown, file: string): LoadedPreset;
12
+ export declare function presetModulePaths(): string[];
13
+ export declare function importPresetModule(
14
+ vi: { importActual: (path: string) => Promise<unknown> },
15
+ file: string,
16
+ ): Promise<LoadedPreset>;
@@ -0,0 +1,92 @@
1
+ // Presets given as module paths: `presets: ['./test/presets/my-lib.ts']`.
2
+ //
3
+ // A preset's module factories are functions, and a function in the user's Vitest
4
+ // config cannot reach a test worker: the plugin passes workers JSON (environment
5
+ // variables), and each worker rebuilds the built-in presets by name. A preset of the
6
+ // project's own is therefore named by the module that exports it. The plugin imports
7
+ // that module while it resolves its config (for the preset's name, modules and
8
+ // export names) and hands the path to the workers, which import it again and call
9
+ // its factories there.
10
+ //
11
+ // Plain .mjs, like errors.mjs: the native engine's setup file loads it as shipped, and
12
+ // the plugin and the mock engine's setup bundle it.
13
+ import { VitestNativeTypeError } from "./errors.mjs";
14
+ import { projectContext } from "./context.mjs";
15
+
16
+ // The plugin and the native loader generate `export const <name> = ...` for each named
17
+ // export, so each must be a name a binding can have. `default` is the module object.
18
+ const IDENTIFIER = /^[A-Za-z_$][\w$]*$/;
19
+ const RESERVED = new Set(
20
+ (
21
+ "await break case catch class const continue debugger default delete do else enum " +
22
+ "export extends false finally for function if implements import in instanceof " +
23
+ "interface let new null package private protected public return static super switch " +
24
+ "this throw true try typeof var void while with yield"
25
+ ).split(" "),
26
+ );
27
+
28
+ /**
29
+ * The preset a preset module exports: its default export, either a preset or a
30
+ * function returning one (called with no arguments).
31
+ */
32
+ export function presetFromModule(namespace, file) {
33
+ const exported = namespace?.default;
34
+ const preset = typeof exported === "function" ? exported() : exported;
35
+ const isObject = (value) => value !== null && typeof value === "object";
36
+ if (typeof preset?.then === "function") {
37
+ throw new VitestNativeTypeError(
38
+ "INVALID_OPTION",
39
+ `The preset module ${file} default-exports an async function. The plugin reads the ` +
40
+ `preset synchronously; put async work in the preset's prepare(), which the test ` +
41
+ `workers await before any test file loads.`,
42
+ );
43
+ }
44
+ if (
45
+ !isObject(preset) ||
46
+ typeof preset.name !== "string" ||
47
+ !preset.name ||
48
+ !isObject(preset.modules)
49
+ ) {
50
+ throw new VitestNativeTypeError(
51
+ "INVALID_OPTION",
52
+ `The preset module ${file} must default-export a preset ({ name, modules }) or a ` +
53
+ `function that returns one.`,
54
+ );
55
+ }
56
+ for (const [moduleName, presetModule] of Object.entries(preset.modules)) {
57
+ if (
58
+ !isObject(presetModule) ||
59
+ typeof presetModule.factory !== "function" ||
60
+ !(Array.isArray(presetModule.exports) || typeof presetModule.exportsFor === "function")
61
+ ) {
62
+ throw new VitestNativeTypeError(
63
+ "INVALID_OPTION",
64
+ `The preset module ${file} declares '${moduleName}' without a factory function and ` +
65
+ `an exports array.`,
66
+ );
67
+ }
68
+ for (const name of presetModule.exports ?? []) {
69
+ if (typeof name !== "string" || !IDENTIFIER.test(name) || RESERVED.has(name)) {
70
+ throw new VitestNativeTypeError(
71
+ "INVALID_OPTION",
72
+ `The preset module ${file} lists ${JSON.stringify(name)} among the exports of ` +
73
+ `'${moduleName}'. Each must be a name a variable could have` +
74
+ (name === "default"
75
+ ? `; the default import is the whole module object the factory returns.`
76
+ : `.`),
77
+ );
78
+ }
79
+ }
80
+ }
81
+ return preset;
82
+ }
83
+
84
+ /** The preset module paths the plugin passed this worker, absolute. */
85
+ export function presetModulePaths() {
86
+ return [...(projectContext()?.presetModules ?? [])];
87
+ }
88
+
89
+ /** Imports a preset module in a test worker, through Vitest so TypeScript loads. */
90
+ export async function importPresetModule(vi, file) {
91
+ return presetFromModule(await vi.importActual(file), file);
92
+ }
@@ -0,0 +1,9 @@
1
+ // The mock engine's second setup file, listed directly after setup.ts. setup.ts
2
+ // starts each preset's async preparation (the skia preset loads CanvasKit), but it
3
+ // cannot await it: it is bundled, and the bundler also emits it as CommonJS, where a
4
+ // top-level await does not compile. This file waits instead, so a preset's module is
5
+ // built before any user setup file or test file loads, including a CommonJS library
6
+ // that require()s the package at its top level. A preparation that failed throws
7
+ // here, failing the file with the preset's own error. Plain .mjs, shipped verbatim,
8
+ // with no imports, so it is the same file in src/ and dist/.
9
+ await globalThis.__vitest_native_presets_ready;