vitest-native 0.15.0 → 0.16.0-rc.1
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/dist/cli.mjs +177 -31
- package/dist/context.d.mts +6 -0
- package/dist/context.mjs +5 -0
- package/dist/errors.d.mts +5 -0
- package/dist/hang-watch.d.mts +2 -0
- package/dist/hang-watch.mjs +60 -3
- package/dist/{host-TAGjG56H.mjs → host-X6VHF-a4.mjs} +456 -15
- package/dist/{index-BpZ0E2eJ.d.mts → index-X3wuvaqa.d.mts} +25 -13
- package/dist/index.d.mts +3 -3
- package/dist/index.mjs +220 -117
- package/dist/jest-compat/jest-object.mjs +62 -17
- package/dist/jest-compat/node-registry.mjs +496 -126
- package/dist/jest-compat/setup.mjs +32 -4
- package/dist/jest-compat.cjs +277 -33
- package/dist/jest-compat.d.cts +1 -1
- package/dist/jest-compat.d.mts +1 -1
- package/dist/jest-compat.mjs +257 -33
- package/dist/native/assets.mjs +41 -10
- package/dist/native/babel-worker.mjs +4 -2
- package/dist/native/boundary.mjs +52 -14
- package/dist/native/bounded-process.mjs +110 -27
- package/dist/native/explain.mjs +101 -5
- package/dist/native/expo-module-mocks.mjs +3 -0
- package/dist/native/gesture-handler-buttons.mjs +148 -0
- package/dist/native/hooks.mjs +8 -2
- package/dist/native/hot-diagnostic.mjs +7 -0
- package/dist/native/library-jest.mjs +16 -8
- package/dist/native/loader.mjs +159 -2
- package/dist/native/metro-profile-compiler.mjs +2 -1
- package/dist/native/metro-profile.mjs +2 -0
- package/dist/native/ownership-ledger.d.mts +2 -0
- package/dist/native/ownership-ledger.mjs +3 -2
- package/dist/native/react-dedupe.d.mts +7 -0
- package/dist/native/react-dedupe.mjs +191 -0
- package/dist/native/registry-compiler.mjs +3 -2
- package/dist/native/registry-process.mjs +90 -12
- package/dist/native/registry.mjs +9 -4
- package/dist/native/reset.mjs +51 -26
- package/dist/native/resolve.mjs +5 -1
- package/dist/native/setup.mjs +15 -7
- package/dist/native/state-manifest.mjs +2 -3
- package/dist/native/transform.mjs +125 -3
- package/dist/native/worker.mjs +3 -12
- package/dist/node-dispatch.mjs +2 -0
- package/dist/preset-react.d.mts +11 -0
- package/dist/preset-react.mjs +121 -0
- package/dist/{presets-DLH7uRGA.mjs → presets-Dw0Sz9O6.mjs} +1352 -567
- package/dist/presets.d.mts +1 -1
- package/dist/presets.mjs +1 -1
- package/dist/setup-files-C6-77IIs.mjs +22 -0
- package/dist/setup.mjs +15 -13
- package/package.json +15 -5
- package/dist/memory-Couw0Esx.mjs +0 -151
- package/dist/native/compile-cache.mjs +0 -57
package/dist/index.mjs
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
import { n as runSetupFilesInOrder, t as placeSetupFiles } from "./setup-files-C6-77IIs.mjs";
|
|
2
|
+
import { B as unsupportedReactNativeMessage, C as installedManifest, E as shouldDefaultFsModuleCache, F as SUPPORTED_EXPO_SDKS, I as belowRecommendedMessage, L as installedExpoVersion, M as validatePeerDependency, N as warnUnknownOptions, O as assertSupportedNode, P as PEER_REQUIREMENTS, R as isBelowSupportedReactNative, T as fsModuleCacheKey, _ as isProjectSourceFile, a as runningVite, d as aliasReachedPaths, f as detectEcosystemPackages, g as createProjectBabel, h as detectEngine, j as validateOptions, l as memoryLoweredWorkers, n as assertHotWorkerLoadsRunningVitest, t as assertHostResolvesRunningVitest, v as missingBabelCoreNotice, w as readProjectSource, z as unsupportedExpoSdkMessage } from "./host-X6VHF-a4.mjs";
|
|
3
|
+
import { N as BUILT_IN_PRESET, t as presets_exports } from "./presets-Dw0Sz9O6.mjs";
|
|
4
|
+
import { a as PRESET_MODULES, d as presetForInstalled, i as LIBRARY_SETUP_FILES, r as DEFAULT_ASSET_EXTS, s as autoDetectedPresetApplies, t as AUTO_DETECT_PRESETS, u as libraryRegistryEntries } from "./preset-map-DdAexIwz.mjs";
|
|
4
5
|
import { t as workerVitestMismatch } from "./worker-vitest-CILPFeRX.mjs";
|
|
5
6
|
import { createRequire } from "node:module";
|
|
6
7
|
import { extensionsFor, firstExact, platformSubpathFile } from "./native/resolve.mjs";
|
|
@@ -12,16 +13,17 @@ import flowRemoveTypes from "flow-remove-types";
|
|
|
12
13
|
import { VitestNativeError, VitestNativeTypeError } from "./errors.mjs";
|
|
13
14
|
import { docsUrl } from "./docs-url.mjs";
|
|
14
15
|
import { presetFromModule } from "./preset-modules.mjs";
|
|
15
|
-
import { CONTEXT_ENV, ensureProjectContext, projectContext, writeProjectContext } from "./context.mjs";
|
|
16
16
|
import { serializableAliases } from "./jest-compat/aliases.mjs";
|
|
17
17
|
import { tsconfigPathAliases } from "./native/tsconfig-paths.mjs";
|
|
18
18
|
import { aliasList, checkResolverInputs, conditionsIn, createSharedResolver, identityKey, nodeDefaultConditions, nodeOptionsList, ownershipShadowFile, resolverInputsHash, serializeResolutionAliases } from "./native/shared-resolver.mjs";
|
|
19
19
|
import { knownNativeModulesFor, nativeModuleSpecsFor } from "./native/native-modules.mjs";
|
|
20
20
|
import { createNativeOwnershipPolicy, findNativeInlineConflicts, findNativeOwnershipConflict, formatNativeOwnershipManifest } from "./native/ownership.mjs";
|
|
21
|
+
import { REACT_DEDUPE } from "./native/react-dedupe.mjs";
|
|
21
22
|
import { AsyncLocalStorage } from "node:async_hooks";
|
|
22
|
-
import { transformWithOxc } from "vite";
|
|
23
|
+
import { parseAst, transformWithOxc } from "vite";
|
|
23
24
|
import { containsPath, dependencyDirOf, isPackageEntryFile, memoizePackageDirOf, packageDirOf } from "./native/match.mjs";
|
|
24
|
-
import { OWNERSHIP_META_KEY, OWNERSHIP_ROUTES, viteMarkerFor } from "./native/ownership-ledger.mjs";
|
|
25
|
+
import { OWNERSHIP_META_KEY, OWNERSHIP_ROUTES, OWNERSHIP_VIA, viteMarkerFor } from "./native/ownership-ledger.mjs";
|
|
26
|
+
import { CONTEXT_ENV, ensureProjectContext, projectContext, writeProjectContext } from "./context.mjs";
|
|
25
27
|
import { cacheRootFor } from "./native/transform.mjs";
|
|
26
28
|
import { HangWatch, debugging, hangTimeoutFor } from "./hang-watch.mjs";
|
|
27
29
|
import inspector from "node:inspector";
|
|
@@ -42,53 +44,6 @@ function getPlatformExtensions(platform) {
|
|
|
42
44
|
function getConfiguredPlatformExtensions(platform, sourceExts) {
|
|
43
45
|
return extensionsFor(platform, sourceExts);
|
|
44
46
|
}
|
|
45
|
-
// src/fresh-runtime-presets.ts
|
|
46
|
-
/**
|
|
47
|
-
* The presets whose module, as served, uses React through vitest-native's own dist (a
|
|
48
|
-
* module-scope `import React`). The hot runtime keeps that dist resident, so under
|
|
49
|
-
* `hotRuntime.freshRuntime`, where React is evaluated again for each file, these modules
|
|
50
|
-
* keep the first file's React, and later files fail with "Invalid hook call" or read a
|
|
51
|
-
* default (#719). While one is active, freshRuntime declines and React stays resident.
|
|
52
|
-
*
|
|
53
|
-
* reanimated corrects even the library's own mock with React-using helpers, and
|
|
54
|
-
* bottomSheet serves the names the library's mock lacks from its built-in module, so
|
|
55
|
-
* both count whichever module they serve.
|
|
56
|
-
*
|
|
57
|
-
* Temporary: removed when the preset factories take React from the file's own require.
|
|
58
|
-
*/
|
|
59
|
-
const HOLD_REACT = /* @__PURE__ */ new Set([
|
|
60
|
-
"bottomSheet",
|
|
61
|
-
"expo",
|
|
62
|
-
"flashList",
|
|
63
|
-
"gestureHandler",
|
|
64
|
-
"keyboardController",
|
|
65
|
-
"mmkv",
|
|
66
|
-
"navigation",
|
|
67
|
-
"reanimated",
|
|
68
|
-
"safeAreaContext",
|
|
69
|
-
"screens",
|
|
70
|
-
"svg",
|
|
71
|
-
"unistyles",
|
|
72
|
-
"vectorIcons",
|
|
73
|
-
"webview"
|
|
74
|
-
]);
|
|
75
|
-
/** Presets that serve the library's own Jest mock, which does not use the preset's React, when it is installed. */
|
|
76
|
-
const NOT_WITH_OWN_MOCK = {
|
|
77
|
-
safeAreaContext: SAFE_AREA_MOCK,
|
|
78
|
-
keyboardController: KEYBOARD_CONTROLLER_MOCK
|
|
79
|
-
};
|
|
80
|
-
/** The active presets, by name, whose served module holds React per worker. */
|
|
81
|
-
function presetsHoldingReact(presetNames, projectRoot) {
|
|
82
|
-
return presetNames.filter((name) => {
|
|
83
|
-
if (!HOLD_REACT.has(name)) return false;
|
|
84
|
-
const mock = NOT_WITH_OWN_MOCK[name];
|
|
85
|
-
return mock === void 0 || libraryMockDir(mock, projectRoot) === null;
|
|
86
|
-
});
|
|
87
|
-
}
|
|
88
|
-
/** The one line printed when freshRuntime declines. */
|
|
89
|
-
function freshRuntimeDeclinedNotice(names) {
|
|
90
|
-
return `[vitest-native] hotRuntime.freshRuntime declined: ${names.join(", ")} ${names.length === 1 ? "holds" : "hold"} React per worker (#719). React stays resident, as without freshRuntime.`;
|
|
91
|
-
}
|
|
92
47
|
// src/native/apply.ts
|
|
93
48
|
/**
|
|
94
49
|
* Vite/Vitest config fragment for the native engine.
|
|
@@ -173,12 +128,7 @@ function nativeEngineConfig(setupFilePath, fields, extensions, transformPkgs = [
|
|
|
173
128
|
"jsnext"
|
|
174
129
|
],
|
|
175
130
|
extensions,
|
|
176
|
-
dedupe: [
|
|
177
|
-
"react",
|
|
178
|
-
"react-test-renderer",
|
|
179
|
-
"test-renderer",
|
|
180
|
-
"react-is"
|
|
181
|
-
]
|
|
131
|
+
dedupe: [...REACT_DEDUPE]
|
|
182
132
|
},
|
|
183
133
|
test: {
|
|
184
134
|
setupFiles: [setupFilePath],
|
|
@@ -213,7 +163,9 @@ function nativeEngineConfig(setupFilePath, fields, extensions, transformPkgs = [
|
|
|
213
163
|
* Vite's import analysis cannot parse.
|
|
214
164
|
*
|
|
215
165
|
* Only files outside `node_modules`: packages are compiled by their own path (the native
|
|
216
|
-
* engine's Babel transform, or the mock engine's Flow strip and Vite's pipeline).
|
|
166
|
+
* engine's Babel transform, or the mock engine's Flow strip and Vite's pipeline). The one
|
|
167
|
+
* exception is loadPackageJsx below: a package's `.js` file that Vite serves uncompiled and
|
|
168
|
+
* cannot parse.
|
|
217
169
|
*/
|
|
218
170
|
/** The Oxc options for a project `.js` file, or undefined when Oxc is turned off. */
|
|
219
171
|
function projectJsxOptions(oxc) {
|
|
@@ -271,6 +223,72 @@ async function loadProjectJsx(id, options, config, chain, log) {
|
|
|
271
223
|
map: result.map
|
|
272
224
|
};
|
|
273
225
|
}
|
|
226
|
+
/**
|
|
227
|
+
* A `.js` file inside `node_modules`: the plain file, no query. The native engine compiles
|
|
228
|
+
* the packages it detects in Node, so such a file reaching Vite's load belongs to a package
|
|
229
|
+
* nothing compiles.
|
|
230
|
+
*/
|
|
231
|
+
function isPackageJsFile(id) {
|
|
232
|
+
return id.endsWith(".js") && !id.includes("?") && path.isAbsolute(id) && NODE_MODULES.test(id);
|
|
233
|
+
}
|
|
234
|
+
/** The package a `node_modules` path belongs to, `@scope/name` or `name`, or null. */
|
|
235
|
+
function packageOfFile(id) {
|
|
236
|
+
const parts = id.split(/[\\/]/);
|
|
237
|
+
const at = parts.lastIndexOf("node_modules");
|
|
238
|
+
if (at < 0 || at + 1 >= parts.length) return null;
|
|
239
|
+
const first = parts[at + 1];
|
|
240
|
+
return first.startsWith("@") && at + 2 < parts.length ? `${first}/${parts[at + 2]}` : first;
|
|
241
|
+
}
|
|
242
|
+
/** Whether Vite's parser accepts the code: Vite's import analysis fails on what it rejects. */
|
|
243
|
+
function parses(code) {
|
|
244
|
+
try {
|
|
245
|
+
parseAst(code);
|
|
246
|
+
return true;
|
|
247
|
+
} catch {
|
|
248
|
+
return false;
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
const warnedPackages = /* @__PURE__ */ new Set();
|
|
252
|
+
/**
|
|
253
|
+
* A package's `.js` file with JSX that nothing compiles, compiled as JSX, or undefined to
|
|
254
|
+
* leave the file as it is (#763).
|
|
255
|
+
*
|
|
256
|
+
* Under the native engine a package the engine does not detect (one that declares no
|
|
257
|
+
* `react-native` dependency or peer, such as react-native-calendars, whose `main` is
|
|
258
|
+
* `src/index.ts`) can be served by Vite. Oxc compiles its `.ts` files and skips its `.js`
|
|
259
|
+
* ones, so JSX in a `.js` file failed Vite's import analysis. The file is compiled here
|
|
260
|
+
* exactly as a project `.js` file is, and stays in Vite: no package changes owner.
|
|
261
|
+
*
|
|
262
|
+
* Only a file Vite's parser rejects is touched, so every file that loads today loads the
|
|
263
|
+
* same. Another plugin's load still wins, as for project files, and later transforms still
|
|
264
|
+
* run on the result. When Oxc cannot compile it either (Flow, say), the file is served as
|
|
265
|
+
* it is, Vite reports its own parse error, and one warning names the package and the fix.
|
|
266
|
+
*/
|
|
267
|
+
async function loadPackageJsx(id, options, config, chain, log, warn = console.warn) {
|
|
268
|
+
if (!options || !isPackageJsFile(id) || asking.getStore() === id) return void 0;
|
|
269
|
+
const code = await readProjectSource(id);
|
|
270
|
+
if (code === null || !MAY_HAVE_JSX.test(code) || parses(code)) return void 0;
|
|
271
|
+
if (chain) {
|
|
272
|
+
const other = await asking.run(id, () => chain.load(id));
|
|
273
|
+
if (other != null) return other;
|
|
274
|
+
}
|
|
275
|
+
const pkg = packageOfFile(id) ?? id;
|
|
276
|
+
let result;
|
|
277
|
+
try {
|
|
278
|
+
result = await transformWithOxc(code, id, options, void 0, config);
|
|
279
|
+
} catch {
|
|
280
|
+
if (!warnedPackages.has(pkg)) {
|
|
281
|
+
warnedPackages.add(pkg);
|
|
282
|
+
warn(`[vitest-native] ${pkg} ships source Vite cannot parse (${id}), and nothing compiles the package. Add it to reactNative({ transform: ['${pkg}'] }). See https://github.com/danfry1/vitest-native/issues/763.`);
|
|
283
|
+
}
|
|
284
|
+
return;
|
|
285
|
+
}
|
|
286
|
+
log?.(`[vitest-native] compiled JSX in ${id}: ${pkg} is served by Vite uncompiled (#763).`);
|
|
287
|
+
return {
|
|
288
|
+
code: result.code,
|
|
289
|
+
map: result.map
|
|
290
|
+
};
|
|
291
|
+
}
|
|
274
292
|
// src/plugin.ts
|
|
275
293
|
function uniqueExtensions(values) {
|
|
276
294
|
const seen = /* @__PURE__ */ new Set();
|
|
@@ -637,7 +655,6 @@ async function startRegistryFor(options) {
|
|
|
637
655
|
}
|
|
638
656
|
/** Recommended-floor warnings already printed in this process. */
|
|
639
657
|
const warnedRecommended = /* @__PURE__ */ new Set();
|
|
640
|
-
const freshRuntimeNotices = /* @__PURE__ */ new Set();
|
|
641
658
|
/** Vitest instances whose close already settles the background registry builds. */
|
|
642
659
|
const registrySettlers = /* @__PURE__ */ new WeakSet();
|
|
643
660
|
/** Load declarative Metro data without retaining Metro/Expo in Vite's process. */
|
|
@@ -1210,25 +1227,22 @@ function pinInlineProjectRoots(test, declaringRoot) {
|
|
|
1210
1227
|
return pinned;
|
|
1211
1228
|
}
|
|
1212
1229
|
/**
|
|
1213
|
-
* Run React Native's setup before the user's own setup files.
|
|
1214
|
-
*
|
|
1215
|
-
*
|
|
1216
|
-
*
|
|
1217
|
-
*
|
|
1218
|
-
* `
|
|
1219
|
-
*
|
|
1220
|
-
* by installing the hooks at worker boot; every other run broke. Jest has the same
|
|
1221
|
-
* ordering contract: a preset's `setupFiles` run before the project's
|
|
1222
|
-
* `setupFilesAfterEnv`. Moving the entries into the user's list (and out of the merged
|
|
1223
|
-
* result) keeps a single copy of each at the front, in order.
|
|
1230
|
+
* Run React Native's setup before the user's own setup files (placeSetupFiles). A user
|
|
1231
|
+
* setup that imports `@testing-library/react-native` or `react-native` otherwise reached
|
|
1232
|
+
* Node before the require hooks existed and failed on React Native's Flow source
|
|
1233
|
+
* ("Unexpected token 'typeof'"). The hot runtime hid this by installing the hooks at
|
|
1234
|
+
* worker boot; every other run broke. Jest has the same ordering contract: a preset's
|
|
1235
|
+
* `setupFiles` run before the project's `setupFilesAfterEnv`. The entries move into the
|
|
1236
|
+
* user's list and out of the merged result, so a single copy of each runs, first.
|
|
1224
1237
|
*/
|
|
1225
1238
|
function prependSetupFile(userConfig, contributed) {
|
|
1226
|
-
const ours = contributed.setupFiles;
|
|
1227
1239
|
const userTest = userConfig.test ??= {};
|
|
1228
1240
|
const existing = userTest.setupFiles;
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1241
|
+
if (existing == null || Array.isArray(existing) && existing.length === 0) {
|
|
1242
|
+
runSetupFilesInOrder(userTest);
|
|
1243
|
+
return;
|
|
1244
|
+
}
|
|
1245
|
+
placeSetupFiles(userTest, contributed.setupFiles);
|
|
1232
1246
|
contributed.setupFiles = [];
|
|
1233
1247
|
}
|
|
1234
1248
|
function sameDirectory(a, b) {
|
|
@@ -1244,19 +1258,33 @@ function hasSetupFile(setupFiles, file) {
|
|
|
1244
1258
|
* Vitest schedules projects that share a `sequence.groupOrder` (0 unless set) as one
|
|
1245
1259
|
* group, and throws when they resolve to different `maxWorkers` ("Projects … have
|
|
1246
1260
|
* different 'maxWorkers' but same 'sequence.groupOrder'", groupSpecs in Vitest
|
|
1247
|
-
* 5). The hot runtime's memory plan caps workers (
|
|
1248
|
-
* count), while a project beside it gets Vitest's
|
|
1249
|
-
* so a native project next to a mock or
|
|
1250
|
-
*
|
|
1261
|
+
* 5). The hot runtime's memory plan caps workers (one per performance core up to six,
|
|
1262
|
+
* else four, unless the user set the count), while a project beside it gets Vitest's
|
|
1263
|
+
* default of one fewer than the CPUs, so a native project next to a mock or
|
|
1264
|
+
* non-React-Native project failed on any machine with more CPUs than the automatic
|
|
1265
|
+
* count plus one (more than five on a host without core classes). Mirrors Vitest's resolveMaxWorkers and its grouping,
|
|
1251
1266
|
* including the exemption for a single-worker isolated project in the default group.
|
|
1267
|
+
*
|
|
1268
|
+
* The remedy it names first is one worker count for the whole group: a separate
|
|
1269
|
+
* groupOrder also avoids the clash, but Vitest runs groups one after another (#911).
|
|
1270
|
+
* `lowered` is set when the hot project's memory plan held its count below the one
|
|
1271
|
+
* requested, which is how projects given the same count (or none) differ on a machine
|
|
1272
|
+
* with less memory; the message then names the admitted count. A count from
|
|
1273
|
+
* `--maxWorkers` or `VITEST_MAX_WORKERS` (`flag`) reaches every project already, so
|
|
1274
|
+
* there the remedy is a smaller value.
|
|
1252
1275
|
*/
|
|
1253
|
-
function sharedGroupConflict(self, others, root, cpus) {
|
|
1276
|
+
function sharedGroupConflict(self, others, root, cpus, lowered) {
|
|
1254
1277
|
const order = (p) => Number(p.config.sequence?.groupOrder ?? 0);
|
|
1255
1278
|
const workers = (p) => p.config.maxWorkers || root.maxWorkers || vitestMaxWorkers(void 0, root.watch === true, cpus);
|
|
1256
1279
|
const ownGroup = (p) => p.config.isolate === true && order(p) === 0 && p.config.maxWorkers === 1;
|
|
1257
1280
|
for (const other of others) {
|
|
1258
1281
|
if (other === self || ownGroup(other) || order(other) !== order(self)) continue;
|
|
1259
|
-
if (workers(other) !== workers(self))
|
|
1282
|
+
if (workers(other) !== workers(self)) {
|
|
1283
|
+
const name = String(other.name ?? other.config.name ?? "another project");
|
|
1284
|
+
const admits = lowered && `the memory plan admits ${lowered.admitted} of the ${lowered.requested} workers requested on this machine; `;
|
|
1285
|
+
const remedy = !lowered ? `give every project in the group the same test.maxWorkers` : lowered.flag ? `${admits}every project takes the --maxWorkers or VITEST_MAX_WORKERS count, so pass ${lowered.admitted} or fewer here` : `${admits}give every project in the group the same test.maxWorkers, one the smallest machine you run on admits`;
|
|
1286
|
+
return `the project '${name}' is in the same sequence.groupOrder (${order(self)}) with ${workers(other)} workers to this project's ${workers(self)}, which Vitest rejects (${remedy}. A distinct test.sequence.groupOrder also works, but Vitest runs the groups one after another. See ${docsUrl("/guide/hot-runtime#react-native-and-other-projects-in-one-run")})`;
|
|
1287
|
+
}
|
|
1260
1288
|
}
|
|
1261
1289
|
return null;
|
|
1262
1290
|
}
|
|
@@ -1266,6 +1294,10 @@ function isVmPool(pool) {
|
|
|
1266
1294
|
function vmPoolUnsupported(pool) {
|
|
1267
1295
|
return new VitestNativeError("UNSUPPORTED_POOL", `engine:'native' cannot run on the '${pool}' pool. React Native is loaded through Node's module hooks, which a VM pool's context does not use — React Native fails to resolve its platform files there. Use 'threads' (the default) or 'forks', or switch to engine:'mock', which needs no hooks.`);
|
|
1268
1296
|
}
|
|
1297
|
+
/** hotRuntime: true beside a project in its group with another worker count. */
|
|
1298
|
+
function hotRuntimeGroupConflict(conflict) {
|
|
1299
|
+
return new VitestNativeError("HOT_RUNTIME_OVERRIDDEN", `hotRuntime was requested, but ${conflict}.`);
|
|
1300
|
+
}
|
|
1269
1301
|
function hotRuntimeOverridden(reason) {
|
|
1270
1302
|
return new VitestNativeError("HOT_RUNTIME_OVERRIDDEN", `hotRuntime was requested, but ${reason}, which the hot runtime cannot honour. Remove that setting, or use hotRuntime:'auto' (or add mode:'auto' to the options object, keeping its recycling options) to fall back to it automatically, or hotRuntime:false.`);
|
|
1271
1303
|
}
|
|
@@ -1379,6 +1411,24 @@ function ownershipGuardConfig(options, root) {
|
|
|
1379
1411
|
};
|
|
1380
1412
|
}
|
|
1381
1413
|
/**
|
|
1414
|
+
* The installed package a file belongs to: the directory after its LAST `node_modules`
|
|
1415
|
+
* (pnpm's store nests the real one under node_modules/.pnpm/<id>/node_modules/), with a
|
|
1416
|
+
* scope when it has one. Null for a file outside node_modules (project or workspace source).
|
|
1417
|
+
*/
|
|
1418
|
+
function installedPackageOf(file) {
|
|
1419
|
+
const parts = file.split(/[\\/]/);
|
|
1420
|
+
const at = parts.lastIndexOf("node_modules");
|
|
1421
|
+
if (at < 0 || at + 1 >= parts.length) return null;
|
|
1422
|
+
const end = at + (parts[at + 1].startsWith("@") ? 3 : 2);
|
|
1423
|
+
if (end > parts.length - 1) return null;
|
|
1424
|
+
const name = parts.slice(at + 1, end).join("/");
|
|
1425
|
+
const sep = file.includes("\\") && !file.includes("/") ? "\\" : "/";
|
|
1426
|
+
return {
|
|
1427
|
+
name,
|
|
1428
|
+
dir: parts.slice(0, end).join(sep)
|
|
1429
|
+
};
|
|
1430
|
+
}
|
|
1431
|
+
/**
|
|
1382
1432
|
* Prints the ownership guard's findings at the end of the run, whatever the reporter:
|
|
1383
1433
|
* worker console output is dropped by `silent`, by reporters that print only failures,
|
|
1384
1434
|
* and by Vitest 5's agent reporter, and a warning nobody sees is no warning. Each test
|
|
@@ -1388,19 +1438,21 @@ function ownershipGuardConfig(options, root) {
|
|
|
1388
1438
|
var OwnershipSummaryReporter = class {
|
|
1389
1439
|
allow;
|
|
1390
1440
|
write;
|
|
1441
|
+
diagnostics;
|
|
1391
1442
|
found = /* @__PURE__ */ new Map();
|
|
1392
1443
|
used = /* @__PURE__ */ new Set();
|
|
1393
1444
|
mode = "warn";
|
|
1394
|
-
constructor(allow, write = (text) => process.stderr.write(text)) {
|
|
1445
|
+
constructor(allow, write = (text) => process.stderr.write(text), diagnostics = () => false) {
|
|
1395
1446
|
this.allow = allow;
|
|
1396
1447
|
this.write = write;
|
|
1448
|
+
this.diagnostics = diagnostics;
|
|
1397
1449
|
}
|
|
1398
1450
|
onTestRunStart() {
|
|
1399
1451
|
this.found.clear();
|
|
1400
1452
|
this.used.clear();
|
|
1401
1453
|
this.mode = "warn";
|
|
1402
1454
|
}
|
|
1403
|
-
add(route, origin, file, test) {
|
|
1455
|
+
add(route, origin, file, test, reached = { route }) {
|
|
1404
1456
|
const key = `${route}\0${origin}`;
|
|
1405
1457
|
let cause = this.found.get(key);
|
|
1406
1458
|
if (cause === void 0) {
|
|
@@ -1408,12 +1460,14 @@ var OwnershipSummaryReporter = class {
|
|
|
1408
1460
|
route,
|
|
1409
1461
|
origin,
|
|
1410
1462
|
files: /* @__PURE__ */ new Set(),
|
|
1411
|
-
tests: /* @__PURE__ */ new Set()
|
|
1463
|
+
tests: /* @__PURE__ */ new Set(),
|
|
1464
|
+
reached: /* @__PURE__ */ new Map()
|
|
1412
1465
|
};
|
|
1413
1466
|
this.found.set(key, cause);
|
|
1414
1467
|
}
|
|
1415
1468
|
cause.files.add(file);
|
|
1416
1469
|
cause.tests.add(test);
|
|
1470
|
+
if (!cause.reached.has(file)) cause.reached.set(file, reached);
|
|
1417
1471
|
}
|
|
1418
1472
|
onTestModuleEnd(testModule) {
|
|
1419
1473
|
const test = path.relative(process.cwd(), testModule.moduleId).split(path.sep).join("/");
|
|
@@ -1437,20 +1491,57 @@ var OwnershipSummaryReporter = class {
|
|
|
1437
1491
|
route: conflict.route,
|
|
1438
1492
|
file: conflict.file
|
|
1439
1493
|
};
|
|
1440
|
-
this.add(cause.route, cause.file, conflict.file, test
|
|
1494
|
+
this.add(cause.route, cause.file, conflict.file, test, {
|
|
1495
|
+
route: conflict.route,
|
|
1496
|
+
via: conflict.via
|
|
1497
|
+
});
|
|
1441
1498
|
}
|
|
1442
1499
|
}
|
|
1443
1500
|
onTestRunEnd() {
|
|
1444
1501
|
const lines = [];
|
|
1445
1502
|
if (this.found.size > 0) {
|
|
1446
1503
|
const files = new Set([...this.found.values()].flatMap((cause) => [...cause.files]));
|
|
1447
|
-
const rel = (file) => (path.relative(
|
|
1448
|
-
const some = (items) => [...items].slice(0, 3).join(", ") + (
|
|
1449
|
-
|
|
1450
|
-
|
|
1451
|
-
|
|
1452
|
-
const
|
|
1453
|
-
|
|
1504
|
+
const rel = (file, from = process.cwd()) => (path.relative(from, file) || file).split(path.sep).join("/");
|
|
1505
|
+
const some = (items, size) => [...items].slice(0, 3).join(", ") + (size > 3 ? `, +${size - 3} more` : "");
|
|
1506
|
+
const listAll = this.diagnostics();
|
|
1507
|
+
const groups = /* @__PURE__ */ new Map();
|
|
1508
|
+
for (const [key, cause] of this.found) {
|
|
1509
|
+
const pkg = installedPackageOf(cause.origin);
|
|
1510
|
+
const groupKey = pkg ? `${cause.route}\0package\0${pkg.dir}` : key;
|
|
1511
|
+
let group = groups.get(groupKey);
|
|
1512
|
+
if (!group) {
|
|
1513
|
+
group = {
|
|
1514
|
+
route: cause.route,
|
|
1515
|
+
pkg,
|
|
1516
|
+
causes: []
|
|
1517
|
+
};
|
|
1518
|
+
groups.set(groupKey, group);
|
|
1519
|
+
}
|
|
1520
|
+
group.causes.push(cause);
|
|
1521
|
+
}
|
|
1522
|
+
lines.push(`[vitest-native] ownership: ${files.size} file(s) were evaluated by both Node and Vite (${this.mode === "error" ? "failed: ownership 'error'" : "warning; reactNative({ ownership: 'error' }) fails on it"}), from ${this.found.size} cause(s)` + (groups.size < this.found.size ? `, ${groups.size} after grouping by installed package:` : ":"));
|
|
1523
|
+
for (const group of groups.values()) {
|
|
1524
|
+
const known = OWNERSHIP_ROUTES[group.route];
|
|
1525
|
+
const via = known?.label ?? group.route;
|
|
1526
|
+
const reached = new Map(group.causes.flatMap((cause) => [...cause.reached]));
|
|
1527
|
+
const tests = new Set(group.causes.flatMap((cause) => [...cause.tests]));
|
|
1528
|
+
if (group.pkg && group.causes.length > 1) {
|
|
1529
|
+
lines.push(` ${group.pkg.name} (installed package, ${rel(group.pkg.dir)}), loaded by Node through ${via}: ${group.causes.length} cause(s), ${reached.size} file(s), in ${some(tests, tests.size)}`);
|
|
1530
|
+
if (!listAll) {
|
|
1531
|
+
const names = [...reached.keys()].map((file) => rel(file, group.pkg.dir));
|
|
1532
|
+
lines.push(` files: ${some(names, names.length)}` + (names.length > 3 ? " (reactNative({ diagnostics: true }) lists them all)" : ""));
|
|
1533
|
+
}
|
|
1534
|
+
} else {
|
|
1535
|
+
const cause = group.causes[0];
|
|
1536
|
+
const first = [...cause.files][0];
|
|
1537
|
+
lines.push(` ${rel(cause.origin)}, loaded by Node through ${via}: ${cause.files.size} file(s), in ${some(cause.tests, cause.tests.size)}`, ...cause.files.has(cause.origin) || listAll ? [] : [` first: ${rel(first)}`]);
|
|
1538
|
+
}
|
|
1539
|
+
if (listAll) for (const [file, how] of reached) {
|
|
1540
|
+
const label = OWNERSHIP_ROUTES[how.route]?.label ?? how.route;
|
|
1541
|
+
const loader = how.via ? OWNERSHIP_VIA[how.via] ?? how.via : null;
|
|
1542
|
+
lines.push(` file: ${rel(file)}, through ${label}${loader ? ` (${loader})` : ""}`);
|
|
1543
|
+
}
|
|
1544
|
+
if (known) lines.push(` fix: ${known.fix}`);
|
|
1454
1545
|
}
|
|
1455
1546
|
lines.push(` See ${docsUrl("/guide/errors#SOURCE_EVALUATED_TWICE")}.`);
|
|
1456
1547
|
}
|
|
@@ -1804,17 +1895,6 @@ function reactNative(options) {
|
|
|
1804
1895
|
const selection = selectPresets(options?.presets, resolvedRoot);
|
|
1805
1896
|
const nativePresetNames = selection.listed ? selection.listed.map((p) => p.name) : autoDetectPresetNames(resolvedRoot, diagnostics).filter((n) => !disabledNative.has(n) && autoDetectedPresetApplies(n, "native", options?.presets));
|
|
1806
1897
|
if (nativePresetNames.length > 0) fields.presetNames = nativePresetNames;
|
|
1807
|
-
if (fields.hotFreshRuntime === true) {
|
|
1808
|
-
const holding = presetsHoldingReact(nativePresetNames, resolvedRoot);
|
|
1809
|
-
if (holding.length > 0) {
|
|
1810
|
-
delete fields.hotFreshRuntime;
|
|
1811
|
-
const notice = freshRuntimeDeclinedNotice(holding);
|
|
1812
|
-
if (!freshRuntimeNotices.has(notice)) {
|
|
1813
|
-
freshRuntimeNotices.add(notice);
|
|
1814
|
-
console.warn(notice);
|
|
1815
|
-
}
|
|
1816
|
-
}
|
|
1817
|
-
}
|
|
1818
1898
|
if (options?.experimental?.nodeMocks === true || ownershipModel === "resolution") fields.nodeMocks = true;
|
|
1819
1899
|
let ownJestSupport = [];
|
|
1820
1900
|
if (!selection.listed) {
|
|
@@ -1835,6 +1915,7 @@ function reactNative(options) {
|
|
|
1835
1915
|
const userInline = userConfig.test?.server?.deps?.inline;
|
|
1836
1916
|
const userInlinesEverything = userInline === true;
|
|
1837
1917
|
const dirOf = memoizePackageDirOf();
|
|
1918
|
+
const scanFoundDependencies = [];
|
|
1838
1919
|
const ecosystem = detectEcosystemPackages([resolvedRoot, ...includeRoots], transformPkgs, includeRoots, neverTransform, nativePresetNames, memoizePackageDirOf(dependencyDirOf), {
|
|
1839
1920
|
compileReactNativeFieldSource: ownershipModel && engine === "native" ? {
|
|
1840
1921
|
platform,
|
|
@@ -1844,11 +1925,25 @@ function reactNative(options) {
|
|
|
1844
1925
|
reachedPaths: aliasTargets,
|
|
1845
1926
|
onReachedUndeclared: (name, dir) => {
|
|
1846
1927
|
if (diagnostics) console.log(`[vitest-native] ${name} (${dir}) is reached through an alias (resolve.alias or tsconfig paths) but is not a dependency of this package. Its installed React Native dependencies are compiled as if it were declared; declaring it makes the dependency explicit.`);
|
|
1928
|
+
},
|
|
1929
|
+
onImportedUndeclared: (importer, name, dir, listed) => {
|
|
1930
|
+
if (diagnostics) console.log(`[vitest-native] ${importer} imports ${name} (${dir}) and ${listed === "devDependency" ? `lists it only in devDependencies` : `does not list it in its dependencies`}. Node loads ${name} with ${importer}, so it is compiled for Node and the tests' imports share that copy; listing it in dependencies makes that explicit.`);
|
|
1931
|
+
},
|
|
1932
|
+
onScanFoundDependency: (dir, name, parent) => {
|
|
1933
|
+
scanFoundDependencies.push([
|
|
1934
|
+
dir,
|
|
1935
|
+
name,
|
|
1936
|
+
parent
|
|
1937
|
+
]);
|
|
1938
|
+
},
|
|
1939
|
+
onImportScanTruncated: (pkg, limit) => {
|
|
1940
|
+
if (diagnostics) console.log(`[vitest-native] ${pkg}: its imports were read from its first ${limit} files only. Workspace packages it imports from files past that, without listing them, are not compiled for Node.`);
|
|
1847
1941
|
}
|
|
1848
1942
|
});
|
|
1849
1943
|
const linkedDetectedDirs = ecosystem.map((name) => dirOf(name, resolvedRoot)).filter((dir) => dir !== null && !/[\\/]node_modules[\\/]/.test(dir));
|
|
1850
1944
|
const projectDirs = [...new Set([resolvedRoot, ...includeRoots].map((dir) => nearestPackageDir(dir)).filter((dir) => dir !== null))].filter((dir) => !linkedDetectedDirs.some((detected) => containsPath(dir, detected)));
|
|
1851
1945
|
if (projectDirs.length > 0) fields.projectDirs = projectDirs;
|
|
1946
|
+
if (scanFoundDependencies.length > 0) fields.scanFoundDependencies = scanFoundDependencies;
|
|
1852
1947
|
nativeOwnership = createNativeOwnershipPolicy({
|
|
1853
1948
|
projectRoot: resolvedRoot,
|
|
1854
1949
|
explicitTransforms: transformPkgs,
|
|
@@ -1867,7 +1962,7 @@ function reactNative(options) {
|
|
|
1867
1962
|
nativeRoots.add(vitestRootOf(userConfig));
|
|
1868
1963
|
let hotMemory;
|
|
1869
1964
|
if (hotRuntimeRequested) {
|
|
1870
|
-
const { createHotMemoryPlan, formatHotMemoryPlan, formatHotWorkerDecision, resolveRequestedWorkers } = await import("./
|
|
1965
|
+
const { createHotMemoryPlan, formatHotMemoryPlan, formatHotWorkerDecision, resolveRequestedWorkers } = await import("./host-X6VHF-a4.mjs").then((n) => n.u);
|
|
1871
1966
|
const requestedWorkers = resolveRequestedWorkers(userTest?.maxWorkers, { fileParallelism: userTest?.fileParallelism });
|
|
1872
1967
|
const plan = createHotMemoryPlan({
|
|
1873
1968
|
requestedWorkers,
|
|
@@ -1918,7 +2013,7 @@ function reactNative(options) {
|
|
|
1918
2013
|
if (registries?.libraryRegistry) fields.libraryRegistry = registries.libraryRegistry;
|
|
1919
2014
|
};
|
|
1920
2015
|
if (fields.ownershipModel) pendingRegistries.set(directoryKey(resolvedRoot), registryOptions);
|
|
1921
|
-
else if (hotMemory !== void 0 || options?.registryBuild
|
|
2016
|
+
else if (hotMemory !== void 0 || options?.registryBuild !== "background" || await loadRegistryProcess().then((rp) => rp.registryWaitForced() || rp.isCI())) useRegistries(await buildRegistryFor(registryOptions));
|
|
1922
2017
|
else {
|
|
1923
2018
|
const started = await startRegistryFor(registryOptions);
|
|
1924
2019
|
if (started.wait) useRegistries(await buildRegistryFor(registryOptions));
|
|
@@ -2000,12 +2095,7 @@ function reactNative(options) {
|
|
|
2000
2095
|
"jsnext:main",
|
|
2001
2096
|
"jsnext"
|
|
2002
2097
|
],
|
|
2003
|
-
dedupe: [
|
|
2004
|
-
"react",
|
|
2005
|
-
"react-test-renderer",
|
|
2006
|
-
"test-renderer",
|
|
2007
|
-
"react-is"
|
|
2008
|
-
]
|
|
2098
|
+
dedupe: [...REACT_DEDUPE]
|
|
2009
2099
|
},
|
|
2010
2100
|
test: {
|
|
2011
2101
|
setupFiles: [setupFilePath, presetReadyPath],
|
|
@@ -2161,6 +2251,7 @@ function reactNative(options) {
|
|
|
2161
2251
|
const projectBabel = projectBabelFor(this.environment?.config?.root);
|
|
2162
2252
|
if (projectBabel && isProjectSourceFile(id)) return projectBabel.load(id, chain).then((compiled) => compiled == null && projectJsx && isProjectJsFile(id) ? jsx() : compiled);
|
|
2163
2253
|
if (projectJsx && isProjectJsFile(id)) return jsx();
|
|
2254
|
+
if (engine === "native" && projectJsx && isPackageJsFile(id)) return loadPackageJsx(id, projectJsx, viteConfig, chain, diagnostics ? console.log : void 0);
|
|
2164
2255
|
if (id === "\0virtual:rn-facade" && rnFacadeExports !== null) {
|
|
2165
2256
|
const cached = virtualCodeCache.get(id);
|
|
2166
2257
|
if (cached) return cached;
|
|
@@ -2272,13 +2363,18 @@ function reactNative(options) {
|
|
|
2272
2363
|
let summary = ownershipSummaries.get(vitest);
|
|
2273
2364
|
if (!summary) {
|
|
2274
2365
|
const sources = /* @__PURE__ */ new Set();
|
|
2275
|
-
const
|
|
2276
|
-
|
|
2366
|
+
const state = {
|
|
2367
|
+
sources,
|
|
2368
|
+
diagnostics: false
|
|
2369
|
+
};
|
|
2370
|
+
const reporter = new OwnershipSummaryReporter(() => [...sources].flatMap((source) => [...source.values()].flat()), void 0, () => state.diagnostics);
|
|
2371
|
+
summary = state;
|
|
2277
2372
|
ownershipSummaries.set(vitest, summary);
|
|
2278
2373
|
if (Array.isArray(vitest.reporters) && vitest.reporters.length > 0) vitest.reporters.push(reporter);
|
|
2279
2374
|
else if (Array.isArray(vitest.config?.reporters)) vitest.config.reporters.push(reporter);
|
|
2280
2375
|
}
|
|
2281
2376
|
summary.sources.add(ownershipAllow);
|
|
2377
|
+
if (diagnostics) summary.diagnostics = true;
|
|
2282
2378
|
}
|
|
2283
2379
|
if (typeof vitest.version === "string") {
|
|
2284
2380
|
const vitestPeer = PEER_REQUIREMENTS.find((peer) => peer.name === "vitest");
|
|
@@ -2369,10 +2465,17 @@ function reactNative(options) {
|
|
|
2369
2465
|
const override = hotOverrideReason(projectConfig, cli, selection.pool, selection.singleWorkerAccepted);
|
|
2370
2466
|
const vitestWorkers = projectConfig.maxWorkers;
|
|
2371
2467
|
const replanned = override === null && selection.memory ? replanForVitestWorkers(selection.memory, projectConfig) : void 0;
|
|
2372
|
-
const
|
|
2468
|
+
const plan = replanned ?? selection.memory?.plan;
|
|
2469
|
+
const admitted = plan ? memoryLoweredWorkers(plan) : null;
|
|
2470
|
+
const conflict = override === null ? sharedGroupConflict(project, vitest.projects ?? [], {
|
|
2373
2471
|
maxWorkers: vitest.config?.maxWorkers,
|
|
2374
2472
|
watch: vitest.config?.watch
|
|
2375
|
-
}
|
|
2473
|
+
}, void 0, plan && admitted !== null ? {
|
|
2474
|
+
admitted,
|
|
2475
|
+
requested: plan.requestedWorkers,
|
|
2476
|
+
flag: cli.maxWorkers !== void 0 || Boolean(process.env.VITEST_MAX_WORKERS)
|
|
2477
|
+
} : void 0) : null;
|
|
2478
|
+
const reason = override ?? conflict;
|
|
2376
2479
|
if (reason === null) {
|
|
2377
2480
|
if (replanned && selection.memory) applyHotMemoryPlan(selection.memory, replanned, projectConfig, diagnostics);
|
|
2378
2481
|
else if (selection.memory?.capWarning) warnWorkersCapped(selection.memory.plan.requestedWorkers, selection.memory.plan);
|
|
@@ -2381,7 +2484,7 @@ function reactNative(options) {
|
|
|
2381
2484
|
return;
|
|
2382
2485
|
}
|
|
2383
2486
|
projectConfig.maxWorkers = vitestWorkers;
|
|
2384
|
-
if (!hotRuntimeAuto) throw hotRuntimeOverridden(reason);
|
|
2487
|
+
if (!hotRuntimeAuto) throw conflict !== null ? hotRuntimeGroupConflict(conflict) : hotRuntimeOverridden(reason);
|
|
2385
2488
|
projectConfig.pool = cli.pool ?? selection.userPool ?? "threads";
|
|
2386
2489
|
projectConfig.isolate = cli.isolate ?? true;
|
|
2387
2490
|
projectConfig.runner = selection.userRunner ?? testRunnerPath;
|