vitest-native 0.15.0-rc.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.
- package/dist/cli.mjs +166 -145
- package/dist/context.d.mts +4 -0
- package/dist/context.mjs +8 -0
- package/dist/docs-url.d.mts +4 -0
- package/dist/docs-url.mjs +9 -0
- package/dist/errors.d.mts +1 -0
- package/dist/hang-watch-setup.mjs +55 -0
- package/dist/hang-watch.d.mts +56 -0
- package/dist/hang-watch.mjs +343 -0
- package/dist/helpers.cjs +2 -52
- package/dist/{host-BAMNg80P.mjs → host-D0r3P_T1.mjs} +883 -3
- package/dist/{index-CrCsGULN.d.mts → index-JOR602XU.d.mts} +29 -0
- package/dist/index.d.mts +1 -1
- package/dist/index.mjs +183 -88
- package/dist/jest-compat/aliases.d.mts +1 -0
- package/dist/jest-compat/aliases.mjs +11 -0
- package/dist/jest-compat/jest-object.mjs +20 -1
- package/dist/jest-compat/node-registry.mjs +48 -4
- package/dist/jest-compat/setup.mjs +203 -10
- package/dist/jest-compat.cjs +383 -47
- package/dist/jest-compat.d.cts +19 -2
- package/dist/jest-compat.d.mts +19 -2
- package/dist/jest-compat.mjs +232 -47
- package/dist/native/assets.mjs +3 -1
- package/dist/native/babel-caller.d.mts +13 -0
- package/dist/native/babel-caller.mjs +24 -0
- package/dist/native/babel-toolchain.mjs +27 -3
- package/dist/native/boundary.mjs +45 -8
- package/dist/native/compile-error.mjs +120 -0
- package/dist/native/explain.mjs +3 -1
- package/dist/native/expo-module-mocks.mjs +2 -0
- package/dist/native/hooks.mjs +4 -6
- package/dist/native/library-jest.mjs +7 -1
- package/dist/native/loader.mjs +12 -6
- package/dist/native/match.mjs +37 -6
- package/dist/native/ownership-ledger.d.mts +10 -0
- package/dist/native/ownership-ledger.mjs +64 -7
- package/dist/native/ownership.d.mts +15 -0
- package/dist/native/ownership.mjs +84 -0
- package/dist/native/registry.mjs +2 -0
- package/dist/native/resident-health.mjs +1 -0
- package/dist/native/resolve.d.mts +7 -0
- package/dist/native/resolve.mjs +28 -0
- package/dist/native/rntl-hooks.mjs +1 -0
- package/dist/native/root-spelling.d.mts +6 -0
- package/dist/native/root-spelling.mjs +77 -0
- package/dist/native/runner.mjs +2 -19
- package/dist/native/setup.mjs +3 -3
- package/dist/native/test-runner.mjs +26 -0
- package/dist/native/transform.mjs +14 -17
- package/dist/node-dispatch.mjs +2 -0
- package/dist/{presets-CsQynQ0A.mjs → presets-_EaSw29m.mjs} +92 -54
- package/dist/presets.d.mts +1 -1
- package/dist/presets.mjs +1 -1
- package/dist/rntl-support.mjs +1 -0
- package/dist/root-mocks-BNXeosbR.mjs +155 -0
- package/dist/serializer.cjs +7 -5
- package/dist/serializer.d.cts +7 -5
- package/dist/serializer.d.mts +7 -5
- package/dist/serializer.mjs +7 -5
- package/dist/setup.mjs +23 -24
- package/docs/versioning.md +1 -1
- package/package.json +39 -33
package/dist/cli.mjs
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import {
|
|
2
|
+
import { A as unsupportedExpoSdkMessage, E as PEER_REQUIREMENTS, N as validatePeerDependency, O as installedExpoVersion, S as SUPPORTED_NODE, T as unsupportedNodeMessage, _ as normalizeBabelName, c as detectEcosystemPackages, g as isKnownPlugin, h as classifyBabelPlugins, i as ownVitestPackage, j as unsupportedReactNativeMessage, k as isBelowSupportedReactNative, l as babelParser, m as projectBabelTrigger, o as usesVitePlus, r as installedViteVersion, u as isPlainJavaScript, v as installedManifest, w as satisfiesNodeRange, y as detectEngine } from "./host-D0r3P_T1.mjs";
|
|
3
3
|
import { a as PRESET_MODULES, f as presetShadowing, i as LIBRARY_SETUP_FILES, m as testsItself, r as DEFAULT_ASSET_EXTS, s as autoDetectedPresetApplies, t as AUTO_DETECT_PRESETS } from "./preset-map-DdAexIwz.mjs";
|
|
4
|
+
import { n as ignorePattern, t as findNodeModuleMocks } from "./root-mocks-BNXeosbR.mjs";
|
|
4
5
|
import { n as formatHotMemoryPlan, t as createHotMemoryPlan } from "./memory-Couw0Esx.mjs";
|
|
5
6
|
import { createRequire } from "node:module";
|
|
6
7
|
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
@@ -8,11 +9,13 @@ import path from "node:path";
|
|
|
8
9
|
import fs from "node:fs";
|
|
9
10
|
import os from "node:os";
|
|
10
11
|
import { VitestNativeError } from "./errors.mjs";
|
|
12
|
+
import { docsUrl } from "./docs-url.mjs";
|
|
11
13
|
import { createNativeOwnershipPolicy, formatNativeOwnershipManifest } from "./native/ownership.mjs";
|
|
12
14
|
import { resolveTransformPreset } from "./native/babel-preset.mjs";
|
|
13
15
|
import { HOT_STATE_MANIFEST_ENTRIES } from "./native/state-manifest.mjs";
|
|
14
16
|
import { isDeepStrictEqual } from "node:util";
|
|
15
17
|
import { spawn, spawnSync } from "node:child_process";
|
|
18
|
+
import { StringDecoder } from "node:string_decoder";
|
|
16
19
|
// src/cli/manifest.ts
|
|
17
20
|
/**
|
|
18
21
|
* Installed-package facts for the CLI, read from disk.
|
|
@@ -24,18 +27,6 @@ import { spawn, spawnSync } from "node:child_process";
|
|
|
24
27
|
* runtime) answers `require.resolve` for preset packages that are not installed.
|
|
25
28
|
* The manifest file itself is what a package manager writes, so look for it.
|
|
26
29
|
*/
|
|
27
|
-
/** A package's manifest, found by walking node_modules upward from root, or null. */
|
|
28
|
-
function installedManifest(root, pkg) {
|
|
29
|
-
for (let dir = path.resolve(root);; dir = path.dirname(dir)) {
|
|
30
|
-
const file = path.join(dir, "node_modules", pkg, "package.json");
|
|
31
|
-
if (fs.existsSync(file)) try {
|
|
32
|
-
return JSON.parse(fs.readFileSync(file, "utf8"));
|
|
33
|
-
} catch {
|
|
34
|
-
return null;
|
|
35
|
-
}
|
|
36
|
-
if (path.dirname(dir) === dir) return null;
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
30
|
/** The installed major version of `pkg`, or null when absent or unversioned. */
|
|
40
31
|
function installedMajor(root, pkg) {
|
|
41
32
|
const version = installedManifest(root, pkg)?.version;
|
|
@@ -88,20 +79,6 @@ const RELATIVE_FILES = [
|
|
|
88
79
|
".babelrc.mjs",
|
|
89
80
|
".babelrc.json"
|
|
90
81
|
];
|
|
91
|
-
/**
|
|
92
|
-
* @babel/core's `standardizeName` (lib/config/files/plugins.js), rule for rule except that a name
|
|
93
|
-
* starting with `.` is taken as a relative path: `foo` →
|
|
94
|
-
* `babel-plugin-foo`, `@babel/foo` → `@babel/plugin-foo` (`@babel/plugin-foo` unchanged),
|
|
95
|
-
* `@scope/foo` → `@scope/babel-plugin-foo`, `@scope` → `@scope/babel-plugin`, `module:foo` →
|
|
96
|
-
* `foo`. A relative or absolute path is returned as written.
|
|
97
|
-
*/
|
|
98
|
-
function normalizeBabelName(name, kind = "plugin") {
|
|
99
|
-
if (name.startsWith(".") || path.isAbsolute(name)) return name;
|
|
100
|
-
const prefix = new RegExp(`^(?!@|module:|[^/]+/|babel-${kind}-)`);
|
|
101
|
-
const babelOrg = new RegExp(`^(@babel/)(?!${kind}-|[^/]+/)`);
|
|
102
|
-
const otherOrg = new RegExp(`^(@(?!babel/)[^/]+/)(?![^/]*babel-${kind}(?:-|/|$)|[^/]+/)`);
|
|
103
|
-
return name.replace(prefix, `babel-${kind}-`).replace(babelOrg, `$1${kind}-`).replace(otherOrg, `$1babel-${kind}-`).replace(/^(@(?!babel$)[^/]+)$/, `$1/babel-${kind}`).replace(/^module:/, "");
|
|
104
|
-
}
|
|
105
82
|
function entryOf(item, kind) {
|
|
106
83
|
const [target, options] = Array.isArray(item) ? item : [item, void 0];
|
|
107
84
|
if (typeof target !== "string") return {
|
|
@@ -255,7 +232,7 @@ function readBabelConfig(root) {
|
|
|
255
232
|
lazyInText.push(...lazyImportSettingsInText(text));
|
|
256
233
|
for (const written of new Set([...text.matchAll(/["'`]([^"'`\s]+)["'`]/g)].map((m) => m[1]))) {
|
|
257
234
|
const name = normalizeBabelName(written);
|
|
258
|
-
if (
|
|
235
|
+
if (isKnownPlugin(name)) plugins.push({
|
|
259
236
|
written,
|
|
260
237
|
name
|
|
261
238
|
});
|
|
@@ -266,77 +243,10 @@ function readBabelConfig(root) {
|
|
|
266
243
|
evaluated,
|
|
267
244
|
plugins,
|
|
268
245
|
presets: presetEntries.map((p) => p.name),
|
|
246
|
+
presetEntries,
|
|
269
247
|
lazyImports: [.../* @__PURE__ */ new Set([...lazyImportSettings(presetEntries, plugins), ...lazyInText])]
|
|
270
248
|
};
|
|
271
249
|
}
|
|
272
|
-
/** Why a worklet plugin is not needed — only when the preset replacing its library is active. */
|
|
273
|
-
function workletReason(pkg, active, root) {
|
|
274
|
-
const preset = presetShadowing(pkg);
|
|
275
|
-
if (preset && active.includes(preset)) return `transforms worklets for ${pkg}; the active ${preset} preset (auto-detected from ${Object.entries(AUTO_DETECT_PRESETS).filter(([, name]) => name === preset).map(([detect]) => detect).join(", ")}) replaces ${pkg} with a mock, so no worklet runs.`;
|
|
276
|
-
if (!installedManifest(root, pkg)) return `transforms worklets for ${pkg}, which is not installed.`;
|
|
277
|
-
return null;
|
|
278
|
-
}
|
|
279
|
-
const KNOWN_PLUGINS = [
|
|
280
|
-
{
|
|
281
|
-
names: ["babel-plugin-macros", "@lingui/babel-plugin-lingui-macro"],
|
|
282
|
-
verdict: "required",
|
|
283
|
-
reason: (e) => `${e.written} compiles macro imports away at build time; without it the macro module is imported for real and fails (e.g. "Cannot find module 'babel-plugin-macros'").`
|
|
284
|
-
},
|
|
285
|
-
{
|
|
286
|
-
names: ["babel-plugin-module-resolver"],
|
|
287
|
-
verdict: "alias",
|
|
288
|
-
reason: () => `module-resolver rewrites import paths; its aliases map onto resolve.alias.`
|
|
289
|
-
},
|
|
290
|
-
{
|
|
291
|
-
names: ["react-native-worklets/plugin"],
|
|
292
|
-
verdict: "unneeded",
|
|
293
|
-
reason: () => ""
|
|
294
|
-
},
|
|
295
|
-
{
|
|
296
|
-
names: ["react-native-reanimated/plugin"],
|
|
297
|
-
verdict: "unneeded",
|
|
298
|
-
reason: () => ""
|
|
299
|
-
},
|
|
300
|
-
{
|
|
301
|
-
names: ["babel-plugin-react-compiler"],
|
|
302
|
-
verdict: "unneeded",
|
|
303
|
-
reason: () => "React Compiler only adds memoization to components that follow the Rules of React (react.dev/learn/react-compiler); they render the same without it."
|
|
304
|
-
}
|
|
305
|
-
];
|
|
306
|
-
const unknownReason = (e) => `${e.written} ran on every file under babel-jest and does not run under vitest-native; check whether tests depend on what it does.`;
|
|
307
|
-
function classifyBabelPlugins(report, root, active) {
|
|
308
|
-
return report.plugins.map((entry) => {
|
|
309
|
-
const worklets = /^(react-native-worklets|react-native-reanimated)\/plugin$/.exec(entry.name);
|
|
310
|
-
if (worklets) {
|
|
311
|
-
const reason = workletReason(worklets[1], active, root);
|
|
312
|
-
return reason ? {
|
|
313
|
-
...entry,
|
|
314
|
-
verdict: "unneeded",
|
|
315
|
-
reason
|
|
316
|
-
} : {
|
|
317
|
-
...entry,
|
|
318
|
-
verdict: "unknown",
|
|
319
|
-
reason: unknownReason(entry)
|
|
320
|
-
};
|
|
321
|
-
}
|
|
322
|
-
const known = KNOWN_PLUGINS.find((k) => k.names.includes(entry.name));
|
|
323
|
-
if (known) return {
|
|
324
|
-
...entry,
|
|
325
|
-
verdict: known.verdict,
|
|
326
|
-
reason: known.reason(entry, active)
|
|
327
|
-
};
|
|
328
|
-
if (/(^|[/-])macros?($|[/-])/.test(entry.name)) return {
|
|
329
|
-
...entry,
|
|
330
|
-
verdict: "required",
|
|
331
|
-
reason: `${entry.written} looks like a macro plugin; macros are compiled away at build time and fail when imported for real.`
|
|
332
|
-
};
|
|
333
|
-
return {
|
|
334
|
-
...entry,
|
|
335
|
-
verdict: "unknown",
|
|
336
|
-
reason: unknownReason(entry)
|
|
337
|
-
};
|
|
338
|
-
});
|
|
339
|
-
}
|
|
340
250
|
/** Whether `name` is installed where the project resolves it. */
|
|
341
251
|
function installed(root, name) {
|
|
342
252
|
return installedManifest(root, name) !== null;
|
|
@@ -536,7 +446,7 @@ function resolutionRoot(start, exists = fs.existsSync) {
|
|
|
536
446
|
}
|
|
537
447
|
}
|
|
538
448
|
/** doctor's warning for Node 24.13.0, which troubleshooting.md explains. */
|
|
539
|
-
const NODE_24_13_0_CRASH =
|
|
449
|
+
const NODE_24_13_0_CRASH = `Node 24.13.0 can crash a test run at startup with a segmentation fault (an intermittent V8 garbage-collection crash on worker threads). Use another Node 24 release, such as 24.14 or later. See ${docsUrl("/guide/troubleshooting#node-24-13-0-segmentation-fault-at-startup")}`;
|
|
540
450
|
function runDoctor(root, nodeVersion = process.versions.node) {
|
|
541
451
|
const lines = [];
|
|
542
452
|
let ok = true;
|
|
@@ -632,17 +542,37 @@ function runDoctor(root, nodeVersion = process.versions.node) {
|
|
|
632
542
|
warn(unsupported);
|
|
633
543
|
} else if (expo) {
|
|
634
544
|
lines.push("", "Expo");
|
|
635
|
-
pass((decision.engine === "native" ? `expo ${expo} detected. Under the native engine Expo modules run their real JavaScript on native-module mocks, as under jest-expo (unless the config sets \`engine: 'mock'\` or \`presets: { expo: true }\`, where the expo preset shadows ${PRESET_MODULES.expo.join(", ")}). ` : `expo ${expo} detected. Under the mock engine the expo preset shadows ${PRESET_MODULES.expo.join(", ")}; other Expo modules load their real JavaScript. `) + `Coming from jest-expo, run \`vitest-native migrate\`. See
|
|
545
|
+
pass((decision.engine === "native" ? `expo ${expo} detected. Under the native engine Expo modules run their real JavaScript on native-module mocks, as under jest-expo (unless the config sets \`engine: 'mock'\` or \`presets: { expo: true }\`, where the expo preset shadows ${PRESET_MODULES.expo.join(", ")}). ` : `expo ${expo} detected. Under the mock engine the expo preset shadows ${PRESET_MODULES.expo.join(", ")}; other Expo modules load their real JavaScript. `) + `Coming from jest-expo, run \`vitest-native migrate\`. See ${docsUrl("/guide/expo")}`);
|
|
636
546
|
}
|
|
637
547
|
const babel = readBabelConfig(root);
|
|
548
|
+
const engineAppliedPlugins = [];
|
|
638
549
|
if (babel.source) {
|
|
639
550
|
lines.push("", "Babel");
|
|
640
|
-
const
|
|
641
|
-
const
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
551
|
+
const active = activePresets(root, [], decision.engine);
|
|
552
|
+
const classified = classifyBabelPlugins(babel, root, active);
|
|
553
|
+
const byEngine = (name, kind, options) => projectBabelTrigger({
|
|
554
|
+
name,
|
|
555
|
+
kind,
|
|
556
|
+
options
|
|
557
|
+
}, root, active);
|
|
558
|
+
const babelCore = installedManifest(root, "@babel/core") !== null;
|
|
559
|
+
for (const p of babel.presetEntries ?? []) {
|
|
560
|
+
const reason = byEngine(p.name, "preset", p.options);
|
|
561
|
+
if (reason && !babelCore) warn(`preset ${p.name} needs projectBabel (${reason}), which needs @babel/core installed in the project.`);
|
|
562
|
+
else if (reason) lines.push(` · preset ${p.name}: applied by the engine where needed (${reason}).`);
|
|
563
|
+
}
|
|
564
|
+
const required = classified.filter((p) => p.verdict === "required" && !byEngine(p.name, "plugin", p.options));
|
|
565
|
+
for (const p of classified) {
|
|
566
|
+
const reason = byEngine(p.name, "plugin", p.options);
|
|
567
|
+
if (reason && !babelCore) warn(`${p.written} needs projectBabel (${reason}), which needs @babel/core installed in the project; it does not resolve from here. Add @babel/core as a devDependency.`);
|
|
568
|
+
else if (reason) {
|
|
569
|
+
lines.push(` · ${p.written}: applied by the engine where needed (${reason}).`);
|
|
570
|
+
engineAppliedPlugins.push(p.name);
|
|
571
|
+
} else if (p.verdict === "required") warn(`${p.reason} Required: ${babelRecipe(required)}.`);
|
|
572
|
+
else if (p.verdict === "alias") warn(`${p.reason} \`vitest-native migrate\` writes them; otherwise add them to resolve.alias.`);
|
|
573
|
+
else if (p.verdict === "unknown") warn(p.reason);
|
|
574
|
+
else lines.push(` · ${p.written}: ${p.reason}`);
|
|
575
|
+
}
|
|
646
576
|
if (!babel.evaluated) lines.push(` · ${babel.source} could not be evaluated; only plugins recognized by name are listed.`);
|
|
647
577
|
else if (classified.length === 0) lines.push(` · ${babel.source} declares no plugins.`);
|
|
648
578
|
}
|
|
@@ -652,11 +582,17 @@ function runDoctor(root, nodeVersion = process.versions.node) {
|
|
|
652
582
|
else {
|
|
653
583
|
const content = fs.readFileSync(path.join(configRoot, configFile), "utf8");
|
|
654
584
|
const usage = analyzeConfigUsage(content);
|
|
585
|
+
const code = withoutComments$1(content);
|
|
586
|
+
if (/@rolldown\/plugin-babel|vite-plugin-babel/.test(code)) {
|
|
587
|
+
const listed = new Set([...code.matchAll(/["'`]([^"'`\s]+)["'`]/g)].map((m) => normalizeBabelName(m[1])));
|
|
588
|
+
const repeated = engineAppliedPlugins.filter((name) => listed.has(name));
|
|
589
|
+
if (repeated.length) warn(`${configFile}'s babel() lists ${repeated.join(", ")}, which the engine already applies to the project source that needs it; the entry is redundant and can be removed.`);
|
|
590
|
+
}
|
|
655
591
|
if (usage.imports && usage.invokes) {
|
|
656
592
|
pass(`${configFile} uses vitest-native.`);
|
|
657
593
|
const model = /\bownershipModel\s*:\s*["'](resolver|resolution)["']/.exec(withoutComments$1(content))?.[1];
|
|
658
594
|
if (model) {
|
|
659
|
-
lines.push(` · experimental.ownershipModel: '${model}' is on: Vite and Node's loaders resolve bare imports through one shared resolver (
|
|
595
|
+
lines.push(` · experimental.ownershipModel: '${model}' is on: Vite and Node's loaders resolve bare imports through one shared resolver (${docsUrl("/guide/plugin-options#experimental")}).`);
|
|
660
596
|
if (model === "resolution") lines.push(" · 'resolution' turns on experimental.nodeMocks: a vi.mock also reaches the modules Node loads, and a mock Node cannot have synchronously fails as MOCK_NOT_SEEN_BY_NODE.");
|
|
661
597
|
}
|
|
662
598
|
} else if (usage.imports) warn(`${configFile} imports vitest-native but never calls reactNative() — the plugin is not in \`plugins: [...]\`, so React Native imports will not resolve.`);
|
|
@@ -683,7 +619,7 @@ const HOT_RUNTIME_NOTE = [
|
|
|
683
619
|
"Hot runtime: off by default. `hotRuntime: 'auto'` reuses workers across test files instead of",
|
|
684
620
|
"starting a fresh one per file. Whether that is faster depends on the suite, so measure it on yours.",
|
|
685
621
|
"It has known differences from per-file isolation:",
|
|
686
|
-
"
|
|
622
|
+
` ${docsUrl("/guide/troubleshooting#a-test-passes-on-its-own-but-fails-when-run-with-other-files")}`
|
|
687
623
|
];
|
|
688
624
|
const PLAIN_CONFIG = `import { defineConfig } from 'vitest/config'
|
|
689
625
|
import { reactNative } from 'vitest-native'
|
|
@@ -1909,6 +1845,9 @@ function analyzeJestConfig(root) {
|
|
|
1909
1845
|
const extraImports = [];
|
|
1910
1846
|
const extraPlugins = [];
|
|
1911
1847
|
let excludeGlobs = [];
|
|
1848
|
+
let jestRoots = null;
|
|
1849
|
+
let jestIgnorePatterns = null;
|
|
1850
|
+
let directories;
|
|
1912
1851
|
let needsUrlImport = false;
|
|
1913
1852
|
const pluginOptions = [];
|
|
1914
1853
|
const resolvedPreset = typeof projectConfig?.preset === "string" ? resolveJestPreset(root, projectConfig.preset) : void 0;
|
|
@@ -2104,7 +2043,8 @@ function analyzeJestConfig(root) {
|
|
|
2104
2043
|
const value = take(key);
|
|
2105
2044
|
if (value !== void 0) discoveryOptions[key] = value;
|
|
2106
2045
|
}
|
|
2107
|
-
|
|
2046
|
+
if (Array.isArray(discoveryOptions.modulePathIgnorePatterns)) jestIgnorePatterns = discoveryOptions.modulePathIgnorePatterns.filter((p) => typeof p === "string");
|
|
2047
|
+
if (Array.isArray(discoveryOptions.roots)) jestRoots = discoveryOptions.roots.filter((r) => typeof r === "string").map((r) => path.posix.normalize(r.replace(/^<rootDir>/, ".")).replace(/\/$/, "") || ".");
|
|
2108
2048
|
const discovery = translateDiscovery(discoveryOptions, presetConfig, jestMajor(root), () => directories ??= projectDirectories(root));
|
|
2109
2049
|
if (discovery.include) testEntries.push(`include: [${discovery.include.map((g) => JSON.stringify(g)).join(", ")}]`);
|
|
2110
2050
|
excludeGlobs = discovery.exclude;
|
|
@@ -2150,7 +2090,7 @@ function analyzeJestConfig(root) {
|
|
|
2150
2090
|
if (reanimatedActive && code !== null && stripsOnlyReanimatedProps(code)) presetCovered.push(`snapshotSerializers '${entry}' — strips the jest* props Reanimated's real components add under Jest; the Reanimated preset's components add none; delete.`);
|
|
2151
2091
|
else rest.push(String(entry));
|
|
2152
2092
|
}
|
|
2153
|
-
if (rest.length || !serializers.length) attention.push(`snapshotSerializers${rest.length ? ` ${rest.map((r) => `'${r}'`).join(", ")}` : ""} — Vitest
|
|
2093
|
+
if (rest.length || !serializers.length) attention.push(`snapshotSerializers${rest.length ? ` ${rest.map((r) => `'${r}'`).join(", ")}` : ""} — Vitest has no such key: register each with expect.addSnapshotSerializer() in a setup file. React trees need none: they print as under Jest.`);
|
|
2154
2094
|
} else if (key === "watchPathIgnorePatterns") dropped.push(`${key} — affects only Jest's watch mode; Vitest's watch mode reruns by the module graph (tune it with server.watch.ignored if needed); dropped.`);
|
|
2155
2095
|
else if (key === "workerIdleMemoryLimit") dropped.push(`${key} — Vitest recycles workers by memory only in its vm pools (test.vmMemoryLimit), which vitest-native does not use; dropped. Watch memory on the first full run.`);
|
|
2156
2096
|
else dropped.push(`${key} — no vitest-native equivalent needed; dropped.`);
|
|
@@ -2167,17 +2107,38 @@ function analyzeJestConfig(root) {
|
|
|
2167
2107
|
}
|
|
2168
2108
|
for (const key of Object.keys(config)) if (!handled.has(key)) attention.push(`'${key}' — unrecognized Jest key; review manually.`);
|
|
2169
2109
|
}
|
|
2170
|
-
const
|
|
2171
|
-
|
|
2172
|
-
|
|
2173
|
-
|
|
2174
|
-
|
|
2175
|
-
|
|
2176
|
-
if (preset && active.includes(preset)) presetCovered.push(`__mocks__/${candidate} — the auto-detected ${preset} preset shadows ${candidate}; delete the manual mock.`);
|
|
2177
|
-
else if (preset && runsWithOwnSetup(preset) && installedManifest(root, candidate)) presetCovered.push(`__mocks__/${candidate} — the native engine runs ${candidate} with its own Jest setup (${LIBRARY_SETUP_FILES[preset]}), which replaces its native layer; delete the manual mock.`);
|
|
2178
|
-
else if (installedManifest(root, candidate) && installedTestsItself(root, candidate)) attention.push(`__mocks__/${candidate} — ${candidate} ${installedMajor(root, candidate)} runs its own test mode under Vitest, so no preset replaces it, and Vitest applies a root __mocks__ file only through vi.mock; the library's test mode stands in for this mock.`);
|
|
2110
|
+
const snapshotFiles = (directories ??= projectDirectories(root)).filter((dir) => path.posix.basename(dir) === "__snapshots__").reduce((count, dir) => {
|
|
2111
|
+
let names = [];
|
|
2112
|
+
try {
|
|
2113
|
+
names = fs.readdirSync(path.join(root, dir));
|
|
2114
|
+
} catch {
|
|
2115
|
+
names = [];
|
|
2179
2116
|
}
|
|
2117
|
+
return count + names.filter((name) => name.endsWith(".snap")).length;
|
|
2118
|
+
}, 0);
|
|
2119
|
+
if (snapshotFiles > 0) attention.push(`${snapshotFiles} Jest snapshot file${snapshotFiles === 1 ? "" : "s"} (__snapshots__/*.snap) — most entries need one re-record. Vitest names a snapshot inside a describe 'group > test 1' where Jest wrote 'group test 1', and a snapshot of React Native components differs: Jest's preset renders stand-ins named View and Text with the props as given, and vitest-native renders React Native's own host components (RCTView, RCTText) with the props React Native passes them. Once the rest of the suite passes, re-record them once with \`vitest -u\` and review the diff. Vitest also rewrites each file's first line to its own header when it runs it.`);
|
|
2120
|
+
const mockRoots = jestRoots ?? ["."];
|
|
2121
|
+
const ignored = (jestIgnorePatterns ?? []).flatMap((pattern) => {
|
|
2122
|
+
const regex = ignorePattern(pattern, root);
|
|
2123
|
+
return regex ? [regex] : [];
|
|
2124
|
+
});
|
|
2125
|
+
const manualMocks = findNodeModuleMocks(mockRoots.map((r) => path.resolve(root, r)), root, ignored);
|
|
2126
|
+
const relative = (file) => path.relative(root, file).split(path.sep).join("/");
|
|
2127
|
+
const byFile = /* @__PURE__ */ new Map();
|
|
2128
|
+
for (const mock of manualMocks.mocks) byFile.set(mock.file, [...byFile.get(mock.file) ?? [], mock.spec]);
|
|
2129
|
+
for (const [file, specs] of byFile) {
|
|
2130
|
+
const shown = relative(file).replace(/\.[^./]+$/, "");
|
|
2131
|
+
const candidate = specs[specs.length - 1];
|
|
2132
|
+
const preset = presetShadowing(candidate);
|
|
2133
|
+
const applied = `${shown} → applied to ${specs.slice().reverse().join(" and ")} in every test by jestMockTransform(), with no jest.mock() call, as Jest applies it.`;
|
|
2134
|
+
if (preset && active.includes(preset)) presetCovered.push(`${shown} — the auto-detected ${preset} preset shadows ${candidate}; delete the manual mock.`);
|
|
2135
|
+
else if (preset && runsWithOwnSetup(preset)) presetCovered.push(`${shown} — the native engine runs ${candidate} with its own Jest setup (${LIBRARY_SETUP_FILES[preset]}), which replaces its native layer; delete the manual mock.`);
|
|
2136
|
+
else if (installedTestsItself(root, candidate)) automatic.push(`${applied} ${candidate} ${installedMajor(root, candidate)} also runs its own test mode under Vitest, which can stand in for this mock.`);
|
|
2137
|
+
else automatic.push(applied);
|
|
2180
2138
|
}
|
|
2139
|
+
for (const duplicate of manualMocks.duplicates) attention.push(`duplicate manual mock ${duplicate.name}: ${duplicate.files.map(relative).join(", ")} — Jest warns and uses one; jestMockTransform() uses the last listed. Delete the others.`);
|
|
2140
|
+
const transformOptions = [...jestRoots && jestRoots.some((r) => r !== ".") ? [`roots: [${jestRoots.map((r) => JSON.stringify(r)).join(", ")}]`] : [], ...manualMocks.mocks.length > 0 && jestIgnorePatterns?.length ? [`modulePathIgnorePatterns: [${jestIgnorePatterns.map((p) => JSON.stringify(p)).join(", ")}]`] : []];
|
|
2141
|
+
const transformCall = transformOptions.length ? `jestMockTransform({ ${transformOptions.join(", ")} })` : "jestMockTransform()";
|
|
2181
2142
|
if (navigationOff) {
|
|
2182
2143
|
pluginOptions.push(`presets: { navigation: false }`);
|
|
2183
2144
|
automatic.push("jest-expo renders the real React Navigation → presets: { navigation: false }, so screens keep running in real navigators.");
|
|
@@ -2185,7 +2146,34 @@ function analyzeJestConfig(root) {
|
|
|
2185
2146
|
const babel = readBabelConfig(root);
|
|
2186
2147
|
if (babel.source) {
|
|
2187
2148
|
const classified = classifyBabelPlugins(babel, root, active);
|
|
2188
|
-
const
|
|
2149
|
+
const engineApplied = /* @__PURE__ */ new Map();
|
|
2150
|
+
for (const p of classified) {
|
|
2151
|
+
const reason = projectBabelTrigger({
|
|
2152
|
+
name: p.name,
|
|
2153
|
+
kind: "plugin",
|
|
2154
|
+
options: p.options
|
|
2155
|
+
}, root, active);
|
|
2156
|
+
if (reason) engineApplied.set(`plugin:${p.name}`, reason);
|
|
2157
|
+
}
|
|
2158
|
+
for (const p of babel.presetEntries ?? []) {
|
|
2159
|
+
const reason = projectBabelTrigger({
|
|
2160
|
+
name: p.name,
|
|
2161
|
+
kind: "preset",
|
|
2162
|
+
options: p.options
|
|
2163
|
+
}, root, active);
|
|
2164
|
+
if (reason) engineApplied.set(`preset:${p.name}`, reason);
|
|
2165
|
+
}
|
|
2166
|
+
const babelCore = installed(root, "@babel/core");
|
|
2167
|
+
if (engineApplied.size && !babelCore) {
|
|
2168
|
+
const names = [...engineApplied.keys()].map((k) => k.slice(k.indexOf(":") + 1));
|
|
2169
|
+
attention.push(`${babel.source}: ${list(names)} must reach your own source, and the engine applies ${names.length === 1 ? "it" : "them"} with your Babel config (projectBabel 'auto'), which needs @babel/core installed in the project. It does not resolve from here (often it came only with babel-jest). Add @babel/core as a devDependency.`);
|
|
2170
|
+
}
|
|
2171
|
+
for (const [key, reason] of babelCore ? engineApplied : /* @__PURE__ */ new Map()) {
|
|
2172
|
+
const [kind, name] = [key.slice(0, key.indexOf(":")), key.slice(key.indexOf(":") + 1)];
|
|
2173
|
+
automatic.push(`${babel.source}: ${kind} ${name} → applied by the engine to the project source that needs it (projectBabel 'auto'; ${reason}); nothing to add.`);
|
|
2174
|
+
}
|
|
2175
|
+
const byEngine = (p) => engineApplied.has(`plugin:${p.name}`);
|
|
2176
|
+
const required = classified.filter((p) => p.verdict === "required" && !byEngine(p));
|
|
2189
2177
|
if (required.length) {
|
|
2190
2178
|
if (installed(root, "@rolldown/plugin-babel") && installed(root, "@babel/core") && required.every(serializableOptions)) {
|
|
2191
2179
|
extraImports.push(`import babel from '@rolldown/plugin-babel'`);
|
|
@@ -2205,7 +2193,7 @@ function analyzeJestConfig(root) {
|
|
|
2205
2193
|
if (options.root !== void 0) attention.push(`${babel.source}: module-resolver root ${JSON.stringify(options.root)} — bare imports resolved from those directories need resolve.alias entries by hand.`);
|
|
2206
2194
|
}
|
|
2207
2195
|
for (const p of classified.filter((c) => c.verdict === "unneeded")) dropped.push(`${babel.source}: ${p.written} — ${p.reason}`);
|
|
2208
|
-
for (const p of classified.filter((c) => c.verdict === "unknown")) attention.push(`${babel.source}: ${p.reason}`);
|
|
2196
|
+
for (const p of classified.filter((c) => c.verdict === "unknown" && !byEngine(c))) attention.push(`${babel.source}: ${p.reason}`);
|
|
2209
2197
|
if (babel.lazyImports.length) attention.push(`${babel.source}: ${babel.lazyImports.join(", ")} — under Jest a package import ran only when the test first used it; here every import runs when its file loads. A module a test never touched is now evaluated, so a partial jest.mock of something it needs can fail (e.g. "requireOptionalNativeModule is not a function"). Give such a mock the rest of the module: jest.mock('x', () => ({ ...jest.requireActual('x'), ... })).`);
|
|
2210
2198
|
if (!babel.evaluated) attention.push(`${babel.source} could not be evaluated, so only plugins recognized by name are listed; review it for others.`);
|
|
2211
2199
|
}
|
|
@@ -2230,7 +2218,7 @@ export default defineConfig({
|
|
|
2230
2218
|
plugins: [${[
|
|
2231
2219
|
transformLine,
|
|
2232
2220
|
...extraPlugins,
|
|
2233
|
-
|
|
2221
|
+
transformCall
|
|
2234
2222
|
].join(", ")}],
|
|
2235
2223
|
resolve: {
|
|
2236
2224
|
dedupe: ['react', 'react-test-renderer', 'react-is'],
|
|
@@ -2993,9 +2981,9 @@ function classify(jest, vitest, options = {}) {
|
|
|
2993
2981
|
};
|
|
2994
2982
|
}
|
|
2995
2983
|
const SNAPSHOT_HINTS = {
|
|
2996
|
-
"no-vitest-snapshot":
|
|
2997
|
-
"shared-snapshot-dir":
|
|
2998
|
-
"shared-snapshot-dir-nested":
|
|
2984
|
+
"no-vitest-snapshot": `no Vitest snapshot recorded. Give Vitest its own snapshot directory first (the resolveSnapshotPath recipe at ${docsUrl("/migration/from-jest#snapshots")}), so recording cannot rewrite Jest's .snap files; then run \`vitest run\` once and review the new files`,
|
|
2985
|
+
"shared-snapshot-dir": `your Vitest config resolves snapshots to Jest's .snap files. This snapshot's key is the same in both runners, but Vitest rewrites the header of a Jest .snap file it reads, so compare does not let it read Jest's. Give Vitest its own directory (the resolveSnapshotPath recipe at ${docsUrl("/migration/from-jest#snapshots")}) and record there`,
|
|
2986
|
+
"shared-snapshot-dir-nested": `your Vitest config resolves snapshots to Jest's .snap files. Vitest names this snapshot differently (\`a > b 1\`, where Jest writes \`a b 1\`), so it would not find Jest's entry, and it rewrites the header of a Jest .snap file it reads. Give Vitest its own directory (the resolveSnapshotPath recipe at ${docsUrl("/migration/from-jest#snapshots")}) and record there`
|
|
2999
2987
|
};
|
|
3000
2988
|
/** Entries grouped by the first line of the given side's message, largest group first. */
|
|
3001
2989
|
function clusters(entries, by) {
|
|
@@ -3353,9 +3341,9 @@ function parseCompareArgs(argv) {
|
|
|
3353
3341
|
const jestArgs = splitArgs(values.get("jest-args") ?? "");
|
|
3354
3342
|
const vitestArgs = splitArgs(values.get("vitest-args") ?? "");
|
|
3355
3343
|
const refusedJest = refusedArg(jestArgs, JEST_ARGS);
|
|
3356
|
-
if (refusedJest) return { error: `--jest-args may not contain ${refusedJest}: compare passes only arguments that cannot write snapshots or replace its reports (see
|
|
3344
|
+
if (refusedJest) return { error: `--jest-args may not contain ${refusedJest}: compare passes only arguments that cannot write snapshots or replace its reports (see ${docsUrl("/guide/cli#compare")}).` };
|
|
3357
3345
|
const refusedVitest = refusedArg(vitestArgs, VITEST_ARGS);
|
|
3358
|
-
if (refusedVitest) return { error: `--vitest-args may not contain ${refusedVitest}: compare passes only arguments that cannot write snapshots or replace its reports or config (name a config with --vitest-config; see
|
|
3346
|
+
if (refusedVitest) return { error: `--vitest-args may not contain ${refusedVitest}: compare passes only arguments that cannot write snapshots or replace its reports or config (name a config with --vitest-config; see ${docsUrl("/guide/cli#compare")}).` };
|
|
3359
3347
|
const top = Number(values.get("top") ?? 10);
|
|
3360
3348
|
const timeout = Number(values.get("timeout") ?? 1800);
|
|
3361
3349
|
if (!Number.isInteger(top) || top < 1) return { error: "--top needs a positive whole number." };
|
|
@@ -3471,6 +3459,39 @@ const SIGNALS = [
|
|
|
3471
3459
|
/** How long to wait for a runner's pipes after it exits: a test's own daemon can hold them. */
|
|
3472
3460
|
const DRAIN_MS = 2e3;
|
|
3473
3461
|
/**
|
|
3462
|
+
* Splits a child's stdout and stderr into lines, each stream on its own: the two pipes
|
|
3463
|
+
* deliver chunks in any order and a chunk can end mid-line or mid-character, so a shared
|
|
3464
|
+
* buffer would join half a stderr line to a stdout line and lose what it said.
|
|
3465
|
+
*/
|
|
3466
|
+
function outputLines(onLine) {
|
|
3467
|
+
const streams = {
|
|
3468
|
+
stdout: {
|
|
3469
|
+
decoder: new StringDecoder("utf8"),
|
|
3470
|
+
partial: ""
|
|
3471
|
+
},
|
|
3472
|
+
stderr: {
|
|
3473
|
+
decoder: new StringDecoder("utf8"),
|
|
3474
|
+
partial: ""
|
|
3475
|
+
}
|
|
3476
|
+
};
|
|
3477
|
+
return {
|
|
3478
|
+
push(stream, chunk) {
|
|
3479
|
+
const state = streams[stream];
|
|
3480
|
+
const parts = (state.partial + state.decoder.write(chunk)).split("\n");
|
|
3481
|
+
state.partial = parts.pop() ?? "";
|
|
3482
|
+
for (const line of parts) onLine(line, stream);
|
|
3483
|
+
},
|
|
3484
|
+
flush() {
|
|
3485
|
+
for (const stream of ["stdout", "stderr"]) {
|
|
3486
|
+
const state = streams[stream];
|
|
3487
|
+
const rest = state.partial + state.decoder.end();
|
|
3488
|
+
state.partial = "";
|
|
3489
|
+
if (rest) onLine(rest, stream);
|
|
3490
|
+
}
|
|
3491
|
+
}
|
|
3492
|
+
};
|
|
3493
|
+
}
|
|
3494
|
+
/**
|
|
3474
3495
|
* Run a runner (`node <args>`) under the watchdog, with a timeout. On POSIX the watchdog
|
|
3475
3496
|
* leads its own process group, so the whole group — the runner's workers included — can
|
|
3476
3497
|
* be signalled: on timeout, Ctrl-C, SIGTERM or SIGHUP it gets SIGTERM, then SIGKILL after
|
|
@@ -3499,17 +3520,17 @@ function runBounded(args, options) {
|
|
|
3499
3520
|
windowsHide: true
|
|
3500
3521
|
});
|
|
3501
3522
|
const tail = [];
|
|
3502
|
-
|
|
3503
|
-
|
|
3504
|
-
|
|
3505
|
-
const parts = (partial + chunk.toString()).split("\n");
|
|
3506
|
-
partial = parts.pop() ?? "";
|
|
3507
|
-
for (const line of parts) options.onLine?.(line);
|
|
3508
|
-
tail.push(...parts);
|
|
3523
|
+
const lines = outputLines((line, stream) => {
|
|
3524
|
+
options.onLine?.(line, stream);
|
|
3525
|
+
tail.push(line);
|
|
3509
3526
|
if (tail.length > 40) tail.splice(0, tail.length - 40);
|
|
3527
|
+
});
|
|
3528
|
+
const onData = (stream) => (chunk) => {
|
|
3529
|
+
if (options.showOutput) process.stderr.write(chunk);
|
|
3530
|
+
lines.push(stream, chunk);
|
|
3510
3531
|
};
|
|
3511
|
-
child.stdout?.on("data", onData);
|
|
3512
|
-
child.stderr?.on("data", onData);
|
|
3532
|
+
child.stdout?.on("data", onData("stdout"));
|
|
3533
|
+
child.stderr?.on("data", onData("stderr"));
|
|
3513
3534
|
const killTree = (signal) => {
|
|
3514
3535
|
if (child.pid === void 0) return;
|
|
3515
3536
|
if (posix) try {
|
|
@@ -3554,10 +3575,7 @@ function runBounded(args, options) {
|
|
|
3554
3575
|
clearTimeout(escalate);
|
|
3555
3576
|
clearTimeout(drain);
|
|
3556
3577
|
for (const s of signals) process.off(s, onSignal);
|
|
3557
|
-
|
|
3558
|
-
options.onLine?.(partial);
|
|
3559
|
-
tail.push(partial);
|
|
3560
|
-
}
|
|
3578
|
+
lines.flush();
|
|
3561
3579
|
if (child.connected) child.disconnect();
|
|
3562
3580
|
resolve({
|
|
3563
3581
|
code,
|
|
@@ -3901,25 +3919,28 @@ function seconds(since) {
|
|
|
3901
3919
|
function vitestOutputReader(sanitize) {
|
|
3902
3920
|
const errors = [];
|
|
3903
3921
|
let engine = null;
|
|
3904
|
-
|
|
3922
|
+
const pending = {
|
|
3923
|
+
stdout: null,
|
|
3924
|
+
stderr: null
|
|
3925
|
+
};
|
|
3905
3926
|
let running = false;
|
|
3906
3927
|
const plain = (line) => line.replace(/\u001b\[[0-9;?]*[ -/]*[@-~]/g, "");
|
|
3907
3928
|
return {
|
|
3908
3929
|
errors,
|
|
3909
3930
|
engine: () => engine,
|
|
3910
|
-
onLine(raw) {
|
|
3931
|
+
onLine(raw, stream = "stdout") {
|
|
3911
3932
|
const line = plain(raw);
|
|
3912
3933
|
if (/^\s*RUN\s+v\d/.test(line)) running = true;
|
|
3913
3934
|
const m = running ? null : /^\[vitest-native\] engine: (native|mock) — /.exec(line);
|
|
3914
3935
|
if (m) engine ??= m[1];
|
|
3915
3936
|
const header = /⎯+\s*(Unhandled (?:Rejection|Error)|Uncaught Exception)\s*⎯+/.exec(line);
|
|
3916
3937
|
if (header) {
|
|
3917
|
-
pending = header[1];
|
|
3938
|
+
pending[stream] = header[1];
|
|
3918
3939
|
return;
|
|
3919
3940
|
}
|
|
3920
|
-
if (pending && line.trim() !== "") {
|
|
3921
|
-
errors.push(`${pending}: ${sanitize(line.trim())}`);
|
|
3922
|
-
pending = null;
|
|
3941
|
+
if (pending[stream] && line.trim() !== "") {
|
|
3942
|
+
errors.push(`${pending[stream]}: ${sanitize(line.trim())}`);
|
|
3943
|
+
pending[stream] = null;
|
|
3923
3944
|
return;
|
|
3924
3945
|
}
|
|
3925
3946
|
const close = /^error during close (.*)$/.exec(line);
|
|
@@ -4277,7 +4298,7 @@ Options:
|
|
|
4277
4298
|
--root <dir> project root (default: cwd)
|
|
4278
4299
|
--help this text
|
|
4279
4300
|
|
|
4280
|
-
Docs:
|
|
4301
|
+
Docs: ${docsUrl("/")}`;
|
|
4281
4302
|
function main(argv, log = console.log) {
|
|
4282
4303
|
const args = argv.filter((a) => a !== "--");
|
|
4283
4304
|
const command = args.find((a, i) => !a.startsWith("-") && !COMPARE_VALUED_FLAGS.includes(args[i - 1]));
|
package/dist/context.d.mts
CHANGED
|
@@ -22,9 +22,13 @@ export interface ProjectContextFields {
|
|
|
22
22
|
/** The library registry layered on `registry` (registry.mjs, buildLibraryRegistry). */
|
|
23
23
|
libraryRegistry?: string;
|
|
24
24
|
ownership?: Record<string, unknown>;
|
|
25
|
+
/** Each Node-transformed package's directory, resolved from `root` at config time. */
|
|
26
|
+
packageDirs?: { root: string; dirs: Record<string, string | null> };
|
|
25
27
|
ownershipGuard?: { mode: "warn" | "error"; allow: { path: string; reason: string }[] };
|
|
26
28
|
projectDirs?: string[];
|
|
27
29
|
requireAliases?: [string, string][];
|
|
30
|
+
/** The project sets test.restoreMocks: jest-compat restores jest.replaceProperty() before each test. */
|
|
31
|
+
restoreMocks?: true;
|
|
28
32
|
requireAliasesSkipped?: string[];
|
|
29
33
|
presetNames?: string[];
|
|
30
34
|
/** experimental.nodeMocks: a `vi.mock` applies to the modules Node loads. */
|
package/dist/context.mjs
CHANGED
|
@@ -42,6 +42,13 @@ const SCHEMA = {
|
|
|
42
42
|
},
|
|
43
43
|
libraryRegistry: { valid: absolute },
|
|
44
44
|
ownership: { valid: object },
|
|
45
|
+
packageDirs: {
|
|
46
|
+
valid: (v) =>
|
|
47
|
+
object(v) &&
|
|
48
|
+
absolute(v.root) &&
|
|
49
|
+
object(v.dirs) &&
|
|
50
|
+
Object.values(v.dirs).every((dir) => dir === null || absolute(dir)),
|
|
51
|
+
},
|
|
45
52
|
ownershipGuard: { valid: object },
|
|
46
53
|
projectDirs: { valid: strings },
|
|
47
54
|
requireAliases: {
|
|
@@ -51,6 +58,7 @@ const SCHEMA = {
|
|
|
51
58
|
requireAliasesSkipped: { valid: strings },
|
|
52
59
|
presetNames: { valid: strings },
|
|
53
60
|
nodeMocks: { valid: (v) => v === true },
|
|
61
|
+
restoreMocks: { valid: (v) => v === true },
|
|
54
62
|
presetConfig: { valid: object },
|
|
55
63
|
presetExports: { valid: object },
|
|
56
64
|
presetModules: { valid: strings },
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
// The documentation site's address. Every link vitest-native prints, and the site's own
|
|
2
|
+
// config, read it from here, so the site can move by changing one line; the old address
|
|
3
|
+
// keeps redirecting, because released versions print it.
|
|
4
|
+
export const SITE_URL = "https://danfry1.github.io/vitest-native";
|
|
5
|
+
|
|
6
|
+
/** An absolute link to a page of the site, from its path: `docsUrl("/guide/errors#INVALID_OPTION")`. */
|
|
7
|
+
export function docsUrl(path) {
|
|
8
|
+
return `${SITE_URL}${path}`;
|
|
9
|
+
}
|
package/dist/errors.d.mts
CHANGED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
// hangTimeout, the worker side: before each test, record which test is starting and how
|
|
2
|
+
// long it may legitimately take, in a per-worker file the main process reads when it
|
|
3
|
+
// sees no progress (hang-watch.mjs).
|
|
4
|
+
//
|
|
5
|
+
// The record is written synchronously, before the test body runs. A worker reports a
|
|
6
|
+
// test's start to the main process in batches, asynchronously, so one that then sticks in
|
|
7
|
+
// synchronous code never sends it; this file is on disk regardless.
|
|
8
|
+
//
|
|
9
|
+
// The test's own limits come from the test itself: its `timeout` (an `it(name, fn, ms)`
|
|
10
|
+
// or `{ timeout }` option, or `vi.setConfig({ testTimeout })`), and the hook timeout for
|
|
11
|
+
// the hooks around it. Each retry runs this hook again, so each attempt gets its own record.
|
|
12
|
+
//
|
|
13
|
+
// Added to the run's setup files by the plugin only while the watch is on; the records
|
|
14
|
+
// directory and the hook timeout come from the plugin through Vitest's provide/inject.
|
|
15
|
+
import fs from "node:fs";
|
|
16
|
+
import inspector from "node:inspector";
|
|
17
|
+
import path from "node:path";
|
|
18
|
+
import { threadId } from "node:worker_threads";
|
|
19
|
+
import { beforeEach, inject } from "vitest";
|
|
20
|
+
|
|
21
|
+
const watch = inject("vitestNativeHangWatch");
|
|
22
|
+
|
|
23
|
+
/** "outer > inner > test", as Vitest's reporters name a test. */
|
|
24
|
+
function fullName(task) {
|
|
25
|
+
const names = [];
|
|
26
|
+
for (let at = task; at && at.type !== "file" && at.name !== undefined; at = at.suite) {
|
|
27
|
+
if (at.type === "suite" && at.suite === undefined) break; // the file's root suite
|
|
28
|
+
names.unshift(at.name);
|
|
29
|
+
}
|
|
30
|
+
return names.join(" > ");
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
if (watch?.dir) {
|
|
34
|
+
const file = path.join(watch.dir, `${process.pid}-${threadId}.json`);
|
|
35
|
+
beforeEach((context) => {
|
|
36
|
+
const task = context.task;
|
|
37
|
+
try {
|
|
38
|
+
fs.writeFileSync(
|
|
39
|
+
file,
|
|
40
|
+
JSON.stringify({
|
|
41
|
+
file: task.file?.filepath ?? null,
|
|
42
|
+
test: fullName(task),
|
|
43
|
+
at: Date.now(),
|
|
44
|
+
// The runner resolves it at collection: the test's own, its describe's, or testTimeout.
|
|
45
|
+
timeout: task.timeout ?? 5000,
|
|
46
|
+
hookTimeout: watch.hookTimeout,
|
|
47
|
+
debugger: Boolean(inspector.url()),
|
|
48
|
+
}),
|
|
49
|
+
);
|
|
50
|
+
} catch (error) {
|
|
51
|
+
// The watch then names the file only; the test itself is unaffected.
|
|
52
|
+
process.stderr.write(`[vitest-native] hangTimeout could not record a test start: ${error}\n`);
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
}
|