vitest-native 0.14.0-rc.10 → 0.14.0-rc.12
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/README.md +3 -2
- package/dist/cli.mjs +77 -5
- package/dist/helpers.cjs +53 -2
- package/dist/{host-DCPzgC3D.mjs → host-B4fG_RZ8.mjs} +377 -57
- package/dist/index.mjs +125 -110
- package/dist/jest-compat/node-registry.mjs +154 -34
- package/dist/jest-compat/setup.mjs +7 -3
- package/dist/jest-compat.cjs +222 -47
- package/dist/jest-compat.mjs +198 -47
- package/dist/native/assets.d.mts +2 -0
- package/dist/native/assets.mjs +34 -0
- package/dist/native/babel-toolchain.mjs +64 -0
- package/dist/native/babel-worker.mjs +53 -0
- package/dist/native/boundary.mjs +22 -5
- package/dist/native/esm-interop.mjs +216 -0
- package/dist/native/expo-native-modules.mjs +7 -1
- package/dist/native/globals.mjs +20 -2
- package/dist/native/hooks.mjs +11 -14
- package/dist/native/match.d.mts +18 -2
- package/dist/native/match.mjs +90 -12
- package/dist/native/metro-profile-compiler.mjs +2 -31
- package/dist/native/native-modules.d.mts +2 -0
- package/dist/native/native-modules.mjs +18 -0
- package/dist/native/ownership.d.mts +9 -0
- package/dist/native/ownership.mjs +82 -9
- package/dist/native/registry-compiler.mjs +6 -0
- package/dist/native/registry.mjs +63 -75
- package/dist/native/resolve.d.mts +6 -0
- package/dist/native/resolve.mjs +100 -9
- package/dist/native/setup.mjs +2 -2
- package/dist/native/transform.mjs +290 -59
- package/dist/{preset-map-BlBriTA0.mjs → preset-map-L1-vD19T.mjs} +34 -16
- package/dist/setup.mjs +28 -23
- package/docs/migrating-from-jest.md +10 -2
- package/package.json +20 -18
- package/CHANGELOG.md +0 -2617
- package/dist/cli.cjs +0 -1993
- package/dist/cli.d.cts +0 -3
- package/dist/errors-B3lJK46O.cjs +0 -75
- package/dist/host-D3wzmsw8.cjs +0 -1296
- package/dist/index-D5cOy_iY.d.cts +0 -487
- package/dist/memory-bBnzadf6.cjs +0 -155
- package/dist/pool-DaTJRKJb.cjs +0 -127
- package/dist/preset-map-jSFsNy1Q.cjs +0 -241
- package/dist/preset-modules-C7gu3bPn.cjs +0 -48
- package/dist/presets-DH7fC0YV.cjs +0 -3944
- package/dist/rolldown-runtime-C0BPl7ul.cjs +0 -43
- package/dist/worker-vitest-BfiQB8ND.cjs +0 -62
- package/docs/hot-default-design.md +0 -222
package/README.md
CHANGED
|
@@ -589,8 +589,9 @@ JavaScript runs for real — `expo` itself, expo-router, React Navigation and Ex
|
|
|
589
589
|
jest-expo: from the package's own `mocks/<Name>.ts` where it ships one, else from Expo's table
|
|
590
590
|
of the native modules (`Device.modelName` is `'mock'`). An optional native module a package
|
|
591
591
|
probes for, and that no installed package defines, is absent, as on a device.
|
|
592
|
-
- **Expo SDK
|
|
593
|
-
|
|
592
|
+
- **Expo SDK 57 and 58 are supported.** Earlier SDKs are not: the plugin and `doctor` warn about
|
|
593
|
+
one, so upgrade to SDK 57 or 58. Pin your `react-native` to the version your Expo SDK
|
|
594
|
+
supports, not the newest RN release.
|
|
594
595
|
|
|
595
596
|
Packed Expo SDK 58 and SDK 57 apps are installed from the release tarball and tested in CI: Expo
|
|
596
597
|
module auto-detection and rendering, and expo-router's testing library against file-based `app/`
|
package/dist/cli.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import {
|
|
3
|
-
import { i as autoDetectedPresetApplies, n as DEFAULT_ASSET_EXTS, o as presetShadowing, r as PRESET_MODULES, s as testsItself, t as AUTO_DETECT_PRESETS } from "./preset-map-
|
|
2
|
+
import { C as unsupportedExpoSdkMessage, S as installedExpoVersion, T as validatePeerDependency, c as detectEngine, i as ownVitestPackage, l as resolveTransformPreset, o as usesVitePlus, p as formatNativeOwnershipManifest, r as installedViteVersion, s as detectEcosystemPackages, u as createNativeOwnershipPolicy, x as PEER_REQUIREMENTS, y as fsModuleCacheOnByDefault } from "./host-B4fG_RZ8.mjs";
|
|
3
|
+
import { i as autoDetectedPresetApplies, n as DEFAULT_ASSET_EXTS, o as presetShadowing, r as PRESET_MODULES, s as testsItself, t as AUTO_DETECT_PRESETS } from "./preset-map-L1-vD19T.mjs";
|
|
4
4
|
import { n as formatHotMemoryPlan, t as createHotMemoryPlan } from "./memory-BFxB285Z.mjs";
|
|
5
5
|
import { createRequire } from "node:module";
|
|
6
6
|
import fs from "node:fs";
|
|
@@ -422,6 +422,67 @@ function findConfigFile(root) {
|
|
|
422
422
|
function withoutComments(source) {
|
|
423
423
|
return source.replace(/\/\*[\s\S]*?\*\//g, " ").replace(/(^|[^:])\/\/[^\n]*/g, "$1");
|
|
424
424
|
}
|
|
425
|
+
const settingOf = (value) => value === void 0 ? null : value === "false" ? "off" : "set";
|
|
426
|
+
/**
|
|
427
|
+
* How a config sets Vitest's `fsModuleCache`, read as text, in each spelling: inside
|
|
428
|
+
* `experimental: { ... }` (Vitest 4.0.11 and later) and anywhere else (the top-level
|
|
429
|
+
* option, Vitest 5). `off` for a literal `false`, `set` for any other value, null when
|
|
430
|
+
* that spelling is absent.
|
|
431
|
+
*/
|
|
432
|
+
function fsModuleCacheSetting(source) {
|
|
433
|
+
const code = withoutComments(source);
|
|
434
|
+
const nested = /\bexperimental\s*:\s*\{[^{}]*?\bfsModuleCache\s*:\s*([^,}\s]*)/.exec(code);
|
|
435
|
+
const rest = nested ? code.replace(nested[0], " ") : code;
|
|
436
|
+
const top = /\bfsModuleCache\s*:\s*([^,}\s]*)/.exec(rest);
|
|
437
|
+
return {
|
|
438
|
+
experimental: settingOf(nested?.[1]),
|
|
439
|
+
topLevel: settingOf(top?.[1])
|
|
440
|
+
};
|
|
441
|
+
}
|
|
442
|
+
/** Whether `version` is at or above `[major, minor, patch]`. */
|
|
443
|
+
function versionAtLeast(version, floor) {
|
|
444
|
+
const parts = version.replace(/^[^0-9]*/, "").split(/[.-]/).slice(0, 3).map(Number);
|
|
445
|
+
for (let i = 0; i < 3; i++) {
|
|
446
|
+
const part = parts[i] ?? 0;
|
|
447
|
+
if (part !== floor[i]) return part > floor[i];
|
|
448
|
+
}
|
|
449
|
+
return true;
|
|
450
|
+
}
|
|
451
|
+
/** The first Vitest with `experimental.fsModuleCache`. */
|
|
452
|
+
const EXPERIMENTAL_FS_MODULE_CACHE_FROM = [
|
|
453
|
+
4,
|
|
454
|
+
0,
|
|
455
|
+
11
|
|
456
|
+
];
|
|
457
|
+
const TROUBLESHOOTING_STALE_IMPORT = "https://danfry1.github.io/vitest-native/guide/troubleshooting#cannot-find-module-keeps-failing-after-the-missing-file-exists";
|
|
458
|
+
/**
|
|
459
|
+
* The transform-cache note for a Vitest the plugin does not turn the cache on for.
|
|
460
|
+
* Empty where it does (fsModuleCacheOnByDefault, which the plugin reads too), and where
|
|
461
|
+
* the config turns the cache off on purpose.
|
|
462
|
+
*/
|
|
463
|
+
function transformCacheAdvice(vitestVersion, configSource) {
|
|
464
|
+
const major = Number(vitestVersion?.replace(/^[^0-9]*/, "").split(".")[0]);
|
|
465
|
+
if (!vitestVersion || !(major >= 4) || fsModuleCacheOnByDefault(major)) return [];
|
|
466
|
+
const setting = configSource === null ? {
|
|
467
|
+
experimental: null,
|
|
468
|
+
topLevel: null
|
|
469
|
+
} : fsModuleCacheSetting(configSource);
|
|
470
|
+
if (setting.experimental === "off") return [];
|
|
471
|
+
const hasOption = versionAtLeast(vitestVersion, EXPERIMENTAL_FS_MODULE_CACHE_FROM);
|
|
472
|
+
const caveat = `A Vitest bug can keep a "Cannot find module" failure cached after the file exists (reproduced on Vitest 5.0.5, unverified on 4); ${TROUBLESHOOTING_STALE_IMPORT} lists when it happens and how to recover.`;
|
|
473
|
+
if (setting.experimental === "set" && hasOption) return [`Vitest ${vitestVersion}: the config sets \`experimental.fsModuleCache\`; while it is on, transformed modules are kept on disk between runs. ${caveat}`];
|
|
474
|
+
const lines = [`Vitest ${vitestVersion} re-transforms every imported module on each run, about half a second per thousand imported modules on one benchmark. Vitest 5 keeps transformed modules on disk between runs, and vitest-native turns that on.`];
|
|
475
|
+
if (setting.topLevel !== null) lines.push("The config sets `test.fsModuleCache`, the Vitest 5 spelling, which has no effect on Vitest 4.");
|
|
476
|
+
lines.push(hasOption ? `To keep them on disk on Vitest 4, set \`test.experimental.fsModuleCache: true\`. ${caveat}` : `Vitest 4.0.11 adds \`test.experimental.fsModuleCache\` to keep them on disk.`);
|
|
477
|
+
return lines;
|
|
478
|
+
}
|
|
479
|
+
/**
|
|
480
|
+
* The Vitest that runs here, as the peer check reports it: the project's own, or under
|
|
481
|
+
* Vite+ the copy this package loads.
|
|
482
|
+
*/
|
|
483
|
+
function runningVitestVersion(from) {
|
|
484
|
+
return packageVersion(from, "vitest") ?? (usesVitePlus(from) ? ownVitestPackage()?.version ?? null : null);
|
|
485
|
+
}
|
|
425
486
|
/**
|
|
426
487
|
* Whether a config is built on one imported from elsewhere — a shared preset in a
|
|
427
488
|
* workspace, typically. Such a file legitimately never mentions vitest-native, and
|
|
@@ -540,7 +601,7 @@ function runDoctor(root, nodeVersion = process.versions.node) {
|
|
|
540
601
|
for (const { name, minimum, maximumMajor, minimumByMajor, optional } of PEER_REQUIREMENTS) {
|
|
541
602
|
if (optional) continue;
|
|
542
603
|
const from = rootFor(name);
|
|
543
|
-
const running = name === "vite" ? installedViteVersion(from) : name === "vitest" ?
|
|
604
|
+
const running = name === "vite" ? installedViteVersion(from) : name === "vitest" ? runningVitestVersion(from) : null;
|
|
544
605
|
const error = validatePeerDependency(name, minimum, from, maximumMajor, minimumByMajor, running);
|
|
545
606
|
if (error) fail(error);
|
|
546
607
|
else {
|
|
@@ -600,8 +661,12 @@ function runDoctor(root, nodeVersion = process.versions.node) {
|
|
|
600
661
|
}
|
|
601
662
|
if (detected.length) for (const d of detected) pass(d);
|
|
602
663
|
else if (!installedAny) lines.push(" (none — no preset-covered packages installed)");
|
|
603
|
-
const expo =
|
|
604
|
-
|
|
664
|
+
const expo = installedExpoVersion(root) ?? (configRoot === root ? null : installedExpoVersion(configRoot));
|
|
665
|
+
const unsupported = expo && unsupportedExpoSdkMessage(expo);
|
|
666
|
+
if (unsupported) {
|
|
667
|
+
lines.push("", "Expo");
|
|
668
|
+
warn(unsupported);
|
|
669
|
+
} else if (expo) {
|
|
605
670
|
lines.push("", "Expo");
|
|
606
671
|
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 https://danfry1.github.io/vitest-native/guide/expo`);
|
|
607
672
|
}
|
|
@@ -619,15 +684,22 @@ function runDoctor(root, nodeVersion = process.versions.node) {
|
|
|
619
684
|
}
|
|
620
685
|
lines.push("", "Config");
|
|
621
686
|
const configFile = findConfigFile(configRoot);
|
|
687
|
+
let configSource = null;
|
|
622
688
|
if (!configFile) warn("no vitest.config.* found — run `vitest-native init` to create one.");
|
|
623
689
|
else {
|
|
624
690
|
const content = fs.readFileSync(path.join(configRoot, configFile), "utf8");
|
|
691
|
+
configSource = content;
|
|
625
692
|
const usage = analyzeConfigUsage(content);
|
|
626
693
|
if (usage.imports && usage.invokes) pass(`${configFile} uses vitest-native.`);
|
|
627
694
|
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.`);
|
|
628
695
|
else if (extendsSharedConfig(content)) lines.push(` · ${configFile} builds on a shared config, so this cannot tell from here whether the plugin is wired up. Check the config it extends.`);
|
|
629
696
|
else warn(`${configFile} exists but does not import vitest-native` + (content.includes("vitest-native") ? " (it is only mentioned in a comment)" : "") + " — add `reactNative()` to `plugins: [...]`, or run `vitest-native init`.");
|
|
630
697
|
}
|
|
698
|
+
const advice = transformCacheAdvice(runningVitestVersion(rootFor("vitest")), configSource);
|
|
699
|
+
if (advice.length) {
|
|
700
|
+
lines.push("", "Transform cache");
|
|
701
|
+
for (const line of advice) lines.push(` · ${line}`);
|
|
702
|
+
}
|
|
631
703
|
lines.push("", ok ? "✓ No blocking problems found." : "✗ Blocking problems found (see ✗ above).");
|
|
632
704
|
return {
|
|
633
705
|
lines,
|
package/dist/helpers.cjs
CHANGED
|
@@ -1,5 +1,56 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
|
|
2
|
+
//#region src/errors.mjs
|
|
3
|
+
/**
|
|
4
|
+
* The error types this package throws.
|
|
5
|
+
*
|
|
6
|
+
* Plain .mjs on purpose. The shipped native and jest-compat runtimes are copied to dist
|
|
7
|
+
* verbatim and import this by relative path, and the test suite loads those same files
|
|
8
|
+
* from src — so the module has to resolve identically in both trees. A .ts source would
|
|
9
|
+
* only exist in one of them.
|
|
10
|
+
*
|
|
11
|
+
* WHAT SURVIVES WHERE, measured rather than assumed:
|
|
12
|
+
*
|
|
13
|
+
* - In the main process, and in a user's own try/catch inside a test, everything is
|
|
14
|
+
* intact.
|
|
15
|
+
* - Across the worker/reporter boundary Vitest keeps only `name`, `message` and
|
|
16
|
+
* `stack`. `code` and every other own property is dropped.
|
|
17
|
+
*
|
|
18
|
+
* So the message must stay self-sufficient: nothing may move out of it into a field on
|
|
19
|
+
* the assumption a reader will see it.
|
|
20
|
+
*
|
|
21
|
+
* `isVitestNativeError` deliberately checks SHAPE rather than `instanceof`. Bundled
|
|
22
|
+
* entries and the verbatim .mjs runtimes can hold separate copies of this module, and a
|
|
23
|
+
* prototype check would quietly fail across that seam. Shape does not care.
|
|
24
|
+
*/
|
|
25
|
+
const PREFIX = "[vitest-native]";
|
|
26
|
+
/** Guarantees the prefix exactly once, however the caller wrote the message. */
|
|
27
|
+
function withPrefix(message) {
|
|
28
|
+
return message.startsWith(PREFIX) ? message : `${PREFIX} ${message}`;
|
|
29
|
+
}
|
|
30
|
+
function buildMessage(message, options) {
|
|
31
|
+
const base = withPrefix(message);
|
|
32
|
+
return options?.docs ? `${base}\nSee ${options.docs}` : base;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Error options, omitted entirely when there is no cause.
|
|
36
|
+
*
|
|
37
|
+
* `new Error(msg, { cause: undefined })` installs an own `cause` property set to
|
|
38
|
+
* undefined, which a plain `new Error(msg)` does not — enough to make some reporters
|
|
39
|
+
* print an empty cause and to make these errors shaped differently from every other
|
|
40
|
+
* error in the process. Passing nothing keeps them identical.
|
|
41
|
+
*/
|
|
42
|
+
function errorOptions(options) {
|
|
43
|
+
return options && "cause" in options && options.cause !== void 0 ? { cause: options.cause } : void 0;
|
|
44
|
+
}
|
|
45
|
+
/** A failure originating in vitest-native. */
|
|
46
|
+
var VitestNativeError = class extends Error {
|
|
47
|
+
constructor(code, message, options) {
|
|
48
|
+
super(buildMessage(message, options), errorOptions(options));
|
|
49
|
+
this.name = "VitestNativeError";
|
|
50
|
+
this.code = code;
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
//#endregion
|
|
3
54
|
//#region src/helpers.ts
|
|
4
55
|
/**
|
|
5
56
|
* Test helpers for vitest-native.
|
|
@@ -9,7 +60,7 @@ const require_errors = require("./errors-B3lJK46O.cjs");
|
|
|
9
60
|
*/
|
|
10
61
|
function getMock() {
|
|
11
62
|
const mock = globalThis.__vitest_native_mock;
|
|
12
|
-
if (!mock) throw new
|
|
63
|
+
if (!mock) throw new VitestNativeError("HELPERS_BEFORE_SETUP", "helpers were called before setup ran. Ensure the vitest-native plugin is configured.");
|
|
13
64
|
return mock;
|
|
14
65
|
}
|
|
15
66
|
function getNativeControl() {
|