vitest-native 0.14.0-rc.12 → 0.14.0-rc.13
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 +4 -0
- package/dist/cli.d.mts +1 -3
- package/dist/cli.mjs +15 -24
- package/dist/context.d.mts +5 -0
- package/dist/context.mjs +5 -0
- package/dist/{errors-CxoBUfVJ.mjs → errors-ijs8WAcX.mjs} +1 -2
- package/dist/errors.d.mts +1 -0
- package/dist/helpers.cjs +2 -4
- package/dist/helpers.d.cts +1 -3
- package/dist/helpers.d.mts +1 -3
- package/dist/helpers.mjs +2 -3
- package/dist/{host-B4fG_RZ8.mjs → host-CzQ2Jpia.mjs} +117 -20
- package/dist/{index-CPEAYjaQ.d.mts → index-DqU4YO3D.d.mts} +20 -46
- package/dist/index.d.mts +1 -3
- package/dist/index.mjs +83 -32
- package/dist/jest-compat.cjs +3 -6
- package/dist/jest-compat.d.cts +1 -5
- package/dist/jest-compat.d.mts +1 -5
- package/dist/jest-compat.mjs +2 -4
- package/dist/matchers.cjs +1 -2
- package/dist/matchers.d.cts +0 -2
- package/dist/matchers.d.mts +0 -2
- package/dist/matchers.mjs +1 -2
- package/dist/{memory-BFxB285Z.mjs → memory-B9IFtT_r.mjs} +2 -3
- package/dist/native/babel-toolchain.mjs +128 -2
- package/dist/native/coverage-v8.mjs +287 -0
- package/dist/native/globals.mjs +45 -2
- package/dist/native/hooks.mjs +108 -27
- package/dist/native/loader.mjs +356 -11
- package/dist/native/match.d.mts +6 -0
- package/dist/native/match.mjs +27 -0
- package/dist/native/ownership.d.mts +1 -0
- package/dist/native/ownership.mjs +14 -0
- package/dist/native/registry.mjs +66 -59
- package/dist/native/resident-health.mjs +133 -0
- package/dist/native/runner.mjs +73 -0
- package/dist/native/setup.mjs +11 -4
- package/dist/native/state-manifest.mjs +1 -0
- package/dist/native/transform.mjs +111 -17
- package/dist/native/worker.mjs +39 -6
- package/dist/{pool-DUOe-n1k.mjs → pool-DQ2EE9e6.mjs} +30 -10
- package/dist/{preset-map-L1-vD19T.mjs → preset-map-n08Oz-ZL.mjs} +2 -4
- package/dist/{preset-modules-Bt6k_Wdw.mjs → preset-modules-CNrYP5IR.mjs} +2 -3
- package/dist/{presets-DuXiUNAx.mjs → presets-tEIGoZMO.mjs} +54 -76
- package/dist/presets.d.mts +1 -1
- package/dist/presets.mjs +1 -1
- package/dist/{rolldown-runtime-BhDjJH2R.mjs → rolldown-runtime-D70C1uOS.mjs} +1 -2
- package/dist/serializer.cjs +1 -2
- package/dist/serializer.d.cts +1 -3
- package/dist/serializer.d.mts +1 -3
- package/dist/serializer.mjs +1 -2
- package/dist/setup.mjs +58 -112
- package/dist/{worker-vitest-BGPo0ek6.mjs → worker-vitest-xlSyOBxD.mjs} +2 -3
- package/docs/migrating-from-jest.md +7 -0
- package/package.json +17 -8
package/README.md
CHANGED
|
@@ -320,6 +320,10 @@ reactNative({
|
|
|
320
320
|
});
|
|
321
321
|
```
|
|
322
322
|
|
|
323
|
+
That object requires the hot runtime and fails where it cannot run. Add `mode: "auto"` to keep
|
|
324
|
+
these options and fall back to per-file isolation instead, as `'auto'` does:
|
|
325
|
+
`hotRuntime: { mode: "auto", memoryLimit: 2 * 1024 ** 3 }`.
|
|
326
|
+
|
|
323
327
|
Recycling is applied between Vitest scheduler tasks. Current Vitest batches every file into one
|
|
324
328
|
uninterruptible task at `maxWorkers: 1`, so `'auto'` keeps per-file isolation there and
|
|
325
329
|
`hotRuntime: true` fails that configuration rather than claim an inert memory bound. Use at least
|
package/dist/cli.d.mts
CHANGED
package/dist/cli.mjs
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
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-
|
|
4
|
-
import { n as formatHotMemoryPlan, t as createHotMemoryPlan } from "./memory-
|
|
2
|
+
import { D as validatePeerDependency, S as PEER_REQUIREMENTS, T as unsupportedExpoSdkMessage, b as fsModuleCacheOnByDefault, c as detectEngine, i as ownVitestPackage, l as resolveTransformPreset, o as usesVitePlus, p as formatNativeOwnershipManifest, r as installedViteVersion, s as detectEcosystemPackages, u as createNativeOwnershipPolicy, w as installedExpoVersion } from "./host-CzQ2Jpia.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-n08Oz-ZL.mjs";
|
|
4
|
+
import { n as formatHotMemoryPlan, t as createHotMemoryPlan } from "./memory-B9IFtT_r.mjs";
|
|
5
5
|
import { createRequire } from "node:module";
|
|
6
6
|
import fs from "node:fs";
|
|
7
7
|
import path from "node:path";
|
|
8
|
-
|
|
8
|
+
// src/native/state-manifest.mjs
|
|
9
9
|
const HOT_STATE_MANIFEST_ENTRIES = Object.freeze([
|
|
10
10
|
"vitest-runtime",
|
|
11
11
|
"native-boundary-mocks",
|
|
@@ -19,10 +19,10 @@ const HOT_STATE_MANIFEST_ENTRIES = Object.freeze([
|
|
|
19
19
|
"console.descriptors",
|
|
20
20
|
"react-native.error-utils",
|
|
21
21
|
"expo.runtime",
|
|
22
|
-
"jest-compat.node-mocks"
|
|
22
|
+
"jest-compat.node-mocks",
|
|
23
|
+
"expo.sdk-warnings"
|
|
23
24
|
]);
|
|
24
|
-
|
|
25
|
-
//#region src/cli/manifest.ts
|
|
25
|
+
// src/cli/manifest.ts
|
|
26
26
|
/**
|
|
27
27
|
* Installed-package facts for the CLI, read from disk.
|
|
28
28
|
*
|
|
@@ -72,8 +72,7 @@ function activePresets(root, disabled = [], engine = "native") {
|
|
|
72
72
|
}
|
|
73
73
|
return [...active];
|
|
74
74
|
}
|
|
75
|
-
|
|
76
|
-
//#region src/cli/babel-config.ts
|
|
75
|
+
// src/cli/babel-config.ts
|
|
77
76
|
/**
|
|
78
77
|
* The project's Babel configuration, as `migrate` and `doctor` need to see it.
|
|
79
78
|
*
|
|
@@ -332,8 +331,7 @@ function serializableOptions(entry) {
|
|
|
332
331
|
};
|
|
333
332
|
return entry.options === void 0 || plain(entry.options);
|
|
334
333
|
}
|
|
335
|
-
|
|
336
|
-
//#region src/cli/doctor.ts
|
|
334
|
+
// src/cli/doctor.ts
|
|
337
335
|
/**
|
|
338
336
|
* `vitest-native doctor` — diagnose the project's environment: peer versions,
|
|
339
337
|
* engine resolution (and why), detected presets, RNTL/Node compatibility, and
|
|
@@ -706,8 +704,7 @@ function runDoctor(root, nodeVersion = process.versions.node) {
|
|
|
706
704
|
ok
|
|
707
705
|
};
|
|
708
706
|
}
|
|
709
|
-
|
|
710
|
-
//#region src/cli/init.ts
|
|
707
|
+
// src/cli/init.ts
|
|
711
708
|
/**
|
|
712
709
|
* `vitest-native init` — write a ready-to-run Vitest config. Two shapes:
|
|
713
710
|
* the zero-config default, and the jest-compat variant (the exact block the
|
|
@@ -889,8 +886,7 @@ function tryExpand(source, literalDot) {
|
|
|
889
886
|
throw error;
|
|
890
887
|
}
|
|
891
888
|
}
|
|
892
|
-
|
|
893
|
-
//#region src/cli/allowlist.ts
|
|
889
|
+
// src/cli/allowlist.ts
|
|
894
890
|
/**
|
|
895
891
|
* Reading Jest's `transformIgnorePatterns` allowlist,
|
|
896
892
|
* `node_modules/(?!(a|b|@scope/c)/)`. Real ones nest — React Native's own preset
|
|
@@ -987,8 +983,7 @@ function allows(entry, pkg) {
|
|
|
987
983
|
if (entry.kind === "scope") return pkg.startsWith(`${entry.name}/`);
|
|
988
984
|
return pkg.startsWith(entry.name);
|
|
989
985
|
}
|
|
990
|
-
|
|
991
|
-
//#region src/cli/jest-discovery.ts
|
|
986
|
+
// src/cli/jest-discovery.ts
|
|
992
987
|
/**
|
|
993
988
|
* Which files Jest treats as tests, said to Vitest.
|
|
994
989
|
*
|
|
@@ -1351,8 +1346,7 @@ function booleanFlag(value) {
|
|
|
1351
1346
|
if (value === true || value === "true") return true;
|
|
1352
1347
|
if (value === "false") return false;
|
|
1353
1348
|
}
|
|
1354
|
-
|
|
1355
|
-
//#region src/cli/untranspiled.ts
|
|
1349
|
+
// src/cli/untranspiled.ts
|
|
1356
1350
|
/**
|
|
1357
1351
|
* Evidence that a package needs `transform`: a `.js` file under one of its entry
|
|
1358
1352
|
* points that is not standard JavaScript (JSX or Flow), which neither Node nor Vite
|
|
@@ -1460,8 +1454,7 @@ function untranspiledFile(root, pkg) {
|
|
|
1460
1454
|
}
|
|
1461
1455
|
return null;
|
|
1462
1456
|
}
|
|
1463
|
-
|
|
1464
|
-
//#region src/cli/migrate.ts
|
|
1457
|
+
// src/cli/migrate.ts
|
|
1465
1458
|
/**
|
|
1466
1459
|
* `vitest-native migrate` — analyze a project's Jest configuration and report,
|
|
1467
1460
|
* key by key, what maps automatically, what the presets already cover (delete
|
|
@@ -1982,8 +1975,7 @@ function renderMigrationReport(report) {
|
|
|
1982
1975
|
lines.push(report.vitePlus ? "Re-run with --write to save this config, then: npx vitest-native doctor && vp test" : "Re-run with --write to save this config, then: npx vitest-native doctor && npx vitest", "", ...HOT_RUNTIME_NOTE);
|
|
1983
1976
|
return lines;
|
|
1984
1977
|
}
|
|
1985
|
-
|
|
1986
|
-
//#region src/cli/index.ts
|
|
1978
|
+
// src/cli/index.ts
|
|
1987
1979
|
/**
|
|
1988
1980
|
* vitest-native CLI: `init` (write a ready config), `doctor` (diagnose the
|
|
1989
1981
|
* environment), `migrate` (analyze a Jest config and report the mapping).
|
|
@@ -2057,5 +2049,4 @@ function main(argv, log = console.log) {
|
|
|
2057
2049
|
}
|
|
2058
2050
|
const entry = process.argv[1] ? path.basename(process.argv[1]) : "";
|
|
2059
2051
|
if (entry === "cli.mjs" || entry === "cli.cjs" || entry === "vitest-native") process.exit(main(process.argv.slice(2)));
|
|
2060
|
-
//#endregion
|
|
2061
2052
|
export { main };
|
package/dist/context.d.mts
CHANGED
|
@@ -13,6 +13,9 @@ export interface ProjectContextFields {
|
|
|
13
13
|
assetExts?: string[];
|
|
14
14
|
hotPreserveGlobals?: string[];
|
|
15
15
|
hotEsmGeneration?: boolean;
|
|
16
|
+
/** Coverage is on: Node-compiled project source carries an inline source map. */
|
|
17
|
+
sourceMaps?: boolean;
|
|
18
|
+
hotReleaseGenerations?: boolean;
|
|
16
19
|
registry?: string;
|
|
17
20
|
ownership?: Record<string, unknown>;
|
|
18
21
|
projectDirs?: string[];
|
|
@@ -27,6 +30,8 @@ export interface ProjectContextFields {
|
|
|
27
30
|
knownNativeModules?: string[];
|
|
28
31
|
nativeModuleSpecs?: Record<string, string[]>;
|
|
29
32
|
nativeModules?: "permissive";
|
|
33
|
+
/** The supported Expo SDKs, `[minimum, maximum]` (checkLoadedExpoSdk). */
|
|
34
|
+
expoSdks?: [number, number];
|
|
30
35
|
}
|
|
31
36
|
|
|
32
37
|
export declare function writeProjectContext(
|
package/dist/context.mjs
CHANGED
|
@@ -35,6 +35,8 @@ const SCHEMA = {
|
|
|
35
35
|
assetExts: { valid: strings },
|
|
36
36
|
hotPreserveGlobals: { valid: strings },
|
|
37
37
|
hotEsmGeneration: { valid: (v) => typeof v === "boolean" },
|
|
38
|
+
sourceMaps: { valid: (v) => typeof v === "boolean" },
|
|
39
|
+
hotReleaseGenerations: { valid: (v) => typeof v === "boolean" },
|
|
38
40
|
registry: { valid: absolute },
|
|
39
41
|
ownership: { valid: object },
|
|
40
42
|
projectDirs: { valid: strings },
|
|
@@ -52,6 +54,9 @@ const SCHEMA = {
|
|
|
52
54
|
knownNativeModules: { valid: strings },
|
|
53
55
|
nativeModuleSpecs: { valid: object },
|
|
54
56
|
nativeModules: { valid: (v) => v === "permissive" },
|
|
57
|
+
expoSdks: {
|
|
58
|
+
valid: (v) => Array.isArray(v) && v.length === 2 && v.every((n) => Number.isInteger(n)),
|
|
59
|
+
},
|
|
55
60
|
};
|
|
56
61
|
|
|
57
62
|
function invalid(reason, field, detail, dir) {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
// src/errors.mjs
|
|
2
2
|
/**
|
|
3
3
|
* The error types this package throws.
|
|
4
4
|
*
|
|
@@ -60,5 +60,4 @@ var VitestNativeTypeError = class extends TypeError {
|
|
|
60
60
|
this.code = code;
|
|
61
61
|
}
|
|
62
62
|
};
|
|
63
|
-
//#endregion
|
|
64
63
|
export { VitestNativeTypeError as n, VitestNativeError as t };
|
package/dist/errors.d.mts
CHANGED
package/dist/helpers.cjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
|
|
2
|
+
// src/errors.mjs
|
|
3
3
|
/**
|
|
4
4
|
* The error types this package throws.
|
|
5
5
|
*
|
|
@@ -50,8 +50,7 @@ var VitestNativeError = class extends Error {
|
|
|
50
50
|
this.code = code;
|
|
51
51
|
}
|
|
52
52
|
};
|
|
53
|
-
|
|
54
|
-
//#region src/helpers.ts
|
|
53
|
+
// src/helpers.ts
|
|
55
54
|
/**
|
|
56
55
|
* Test helpers for vitest-native.
|
|
57
56
|
*
|
|
@@ -202,7 +201,6 @@ function resetAllMocks() {
|
|
|
202
201
|
}
|
|
203
202
|
}
|
|
204
203
|
}
|
|
205
|
-
//#endregion
|
|
206
204
|
exports.extendPresetMock = extendPresetMock;
|
|
207
205
|
exports.mockNativeModule = mockNativeModule;
|
|
208
206
|
exports.resetAllMocks = resetAllMocks;
|
package/dist/helpers.d.cts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
//#region src/helpers.d.ts
|
|
2
1
|
export declare function setPlatform(os: "ios" | "android"): void;
|
|
3
2
|
export declare function setDimensions(dims: {
|
|
4
3
|
width: number;
|
|
@@ -21,5 +20,4 @@ export declare function setInsets(insets: {
|
|
|
21
20
|
*/
|
|
22
21
|
export declare function extendPresetMock(pkg: string, overrides: Record<string, any>): boolean;
|
|
23
22
|
export declare function mockNativeModule(name: string, impl: Record<string, any>): void;
|
|
24
|
-
export declare function resetAllMocks(): void;
|
|
25
|
-
//#endregion
|
|
23
|
+
export declare function resetAllMocks(): void;
|
package/dist/helpers.d.mts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
//#region src/helpers.d.ts
|
|
2
1
|
export declare function setPlatform(os: "ios" | "android"): void;
|
|
3
2
|
export declare function setDimensions(dims: {
|
|
4
3
|
width: number;
|
|
@@ -21,5 +20,4 @@ export declare function setInsets(insets: {
|
|
|
21
20
|
*/
|
|
22
21
|
export declare function extendPresetMock(pkg: string, overrides: Record<string, any>): boolean;
|
|
23
22
|
export declare function mockNativeModule(name: string, impl: Record<string, any>): void;
|
|
24
|
-
export declare function resetAllMocks(): void;
|
|
25
|
-
//#endregion
|
|
23
|
+
export declare function resetAllMocks(): void;
|
package/dist/helpers.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { t as VitestNativeError } from "./errors-
|
|
2
|
-
|
|
1
|
+
import { t as VitestNativeError } from "./errors-ijs8WAcX.mjs";
|
|
2
|
+
// src/helpers.ts
|
|
3
3
|
/**
|
|
4
4
|
* Test helpers for vitest-native.
|
|
5
5
|
*
|
|
@@ -150,5 +150,4 @@ function resetAllMocks() {
|
|
|
150
150
|
}
|
|
151
151
|
}
|
|
152
152
|
}
|
|
153
|
-
//#endregion
|
|
154
153
|
export { extendPresetMock, mockNativeModule, resetAllMocks, setColorScheme, setDimensions, setInsets, setPlatform };
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { n as VitestNativeTypeError, t as VitestNativeError } from "./errors-
|
|
2
|
-
import { t as AUTO_DETECT_PRESETS } from "./preset-map-
|
|
1
|
+
import { n as VitestNativeTypeError, t as VitestNativeError } from "./errors-ijs8WAcX.mjs";
|
|
2
|
+
import { t as AUTO_DETECT_PRESETS } from "./preset-map-n08Oz-ZL.mjs";
|
|
3
3
|
import { createRequire } from "node:module";
|
|
4
4
|
import fs from "node:fs";
|
|
5
5
|
import path from "node:path";
|
|
6
6
|
import { createHash } from "node:crypto";
|
|
7
|
-
|
|
7
|
+
// src/validate.ts
|
|
8
8
|
const KNOWN_OPTIONS = [
|
|
9
9
|
"platform",
|
|
10
10
|
"presets",
|
|
@@ -18,6 +18,7 @@ const KNOWN_OPTIONS = [
|
|
|
18
18
|
"nativeModules"
|
|
19
19
|
];
|
|
20
20
|
const KNOWN_HOT_RUNTIME_OPTIONS = [
|
|
21
|
+
"mode",
|
|
21
22
|
"recycleAfterFiles",
|
|
22
23
|
"memoryLimit",
|
|
23
24
|
"allowUnboundedMemory",
|
|
@@ -66,6 +67,8 @@ function validateOptions(options) {
|
|
|
66
67
|
const suggestion = findClosest(key, KNOWN_HOT_RUNTIME_OPTIONS);
|
|
67
68
|
throw new VitestNativeTypeError("UNKNOWN_OPTION", `Unknown hotRuntime option "${key}".` + (suggestion ? ` Did you mean '${suggestion}'?` : "") + ` Valid options: ${KNOWN_HOT_RUNTIME_OPTIONS.join(", ")}.`);
|
|
68
69
|
}
|
|
70
|
+
if (hotOptions.mode !== void 0 && hotOptions.mode !== "auto") throw new VitestNativeTypeError("INVALID_OPTION", `"hotRuntime.mode" must be "auto", or left out to require the hot runtime.`);
|
|
71
|
+
if (hotOptions.mode === "auto" && hotOptions.allowUnboundedMemory === true) throw new VitestNativeTypeError("INVALID_OPTION", "\"hotRuntime.allowUnboundedMemory\" cannot be combined with mode: \"auto\", which keeps per-file isolation where memory cannot be bounded. Leave out mode to require the hot runtime with unbounded memory.");
|
|
69
72
|
if (hotOptions.recycleAfterFiles !== void 0) assertNonNegativeInteger(hotOptions.recycleAfterFiles, "hotRuntime.recycleAfterFiles");
|
|
70
73
|
if (hotOptions.memoryLimit !== void 0) assertNonNegativeInteger(hotOptions.memoryLimit, "hotRuntime.memoryLimit");
|
|
71
74
|
if (hotOptions.allowUnboundedMemory !== void 0 && typeof hotOptions.allowUnboundedMemory !== "boolean") throw new VitestNativeTypeError("INVALID_OPTION", `"hotRuntime.allowUnboundedMemory" must be a boolean.`);
|
|
@@ -121,8 +124,7 @@ function levenshtein(a, b) {
|
|
|
121
124
|
for (let i = 1; i <= m; i++) for (let j = 1; j <= n; j++) dp[i][j] = a[i - 1] === b[j - 1] ? dp[i - 1][j - 1] : 1 + Math.min(dp[i - 1][j], dp[i][j - 1], dp[i - 1][j - 1]);
|
|
122
125
|
return dp[m][n];
|
|
123
126
|
}
|
|
124
|
-
|
|
125
|
-
//#region src/peer-requirements.ts
|
|
127
|
+
// src/peer-requirements.ts
|
|
126
128
|
const PEER_REQUIREMENTS = [
|
|
127
129
|
{
|
|
128
130
|
name: "vitest",
|
|
@@ -210,8 +212,10 @@ function installedExpoVersion(root) {
|
|
|
210
212
|
if (!deps || typeof deps !== "object") continue;
|
|
211
213
|
for (const name of Object.keys(deps)) try {
|
|
212
214
|
const file = req.resolve(`${name}/package.json`);
|
|
213
|
-
const
|
|
215
|
+
const dep = JSON.parse(fs.readFileSync(file, "utf8"));
|
|
216
|
+
const peers = dep.peerDependencies;
|
|
214
217
|
if (!peers || typeof peers !== "object" || !("expo" in peers)) continue;
|
|
218
|
+
if (dep.peerDependenciesMeta?.expo?.optional === true) continue;
|
|
215
219
|
const version = expoVersionFrom(path.dirname(file));
|
|
216
220
|
if (version) return version;
|
|
217
221
|
} catch {}
|
|
@@ -232,8 +236,7 @@ function unsupportedExpoSdkMessage(expoVersion) {
|
|
|
232
236
|
const supported = `vitest-native supports Expo SDK ${expoSdkList("and")}`;
|
|
233
237
|
return sdk < minimum ? `Expo SDK ${sdk} (expo ${expoVersion}) is not supported: ${supported}. Upgrade to Expo SDK ${expoSdkList("or")}; on an older SDK, tests that load Expo modules can fail.` : `Expo SDK ${sdk} (expo ${expoVersion}) is newer than this release supports: ${supported}. Check for a newer vitest-native.`;
|
|
234
238
|
}
|
|
235
|
-
|
|
236
|
-
//#region src/fs-module-cache.ts
|
|
239
|
+
// src/fs-module-cache.ts
|
|
237
240
|
/**
|
|
238
241
|
* Vitest's persistent transform cache (`fsModuleCache`), keyed for what this plugin
|
|
239
242
|
* contributes.
|
|
@@ -309,8 +312,7 @@ function shouldDefaultFsModuleCache(vitestMajor, userTest) {
|
|
|
309
312
|
if (!fsModuleCacheOnByDefault(vitestMajor)) return false;
|
|
310
313
|
return userTest?.fsModuleCache === void 0 && userTest?.experimental?.fsModuleCache === void 0;
|
|
311
314
|
}
|
|
312
|
-
|
|
313
|
-
//#region src/native/match.mjs
|
|
315
|
+
// src/native/match.mjs
|
|
314
316
|
/**
|
|
315
317
|
* Which files belong to which package — the one place that decides it.
|
|
316
318
|
*
|
|
@@ -551,8 +553,107 @@ function buildPkgMatcher(pkgs, projectRoot, dirOf = packageDirOf) {
|
|
|
551
553
|
return patterns.some((re) => re.test(norm));
|
|
552
554
|
};
|
|
553
555
|
}
|
|
554
|
-
|
|
555
|
-
|
|
556
|
+
function packageNameOf(specifier) {
|
|
557
|
+
if (specifier.startsWith("@")) {
|
|
558
|
+
const [scope, name] = specifier.split("/");
|
|
559
|
+
return name ? `${scope}/${name}` : specifier;
|
|
560
|
+
}
|
|
561
|
+
return specifier.split("/")[0];
|
|
562
|
+
}
|
|
563
|
+
function presetPackageOfFile(file, parentFile, isPresetPackage) {
|
|
564
|
+
const norm = toPosix(file);
|
|
565
|
+
const at = norm.lastIndexOf("/node_modules/");
|
|
566
|
+
if (at === -1) return null;
|
|
567
|
+
const rest = norm.slice(at + 14);
|
|
568
|
+
const pkg = packageNameOf(rest);
|
|
569
|
+
if (pkg === rest || !isPresetPackage(pkg)) return null;
|
|
570
|
+
const pkgDir = norm.slice(0, at + 14) + pkg + "/";
|
|
571
|
+
if (parentFile && toPosix(parentFile).startsWith(pkgDir)) return null;
|
|
572
|
+
return {
|
|
573
|
+
pkg,
|
|
574
|
+
subpath: rest.slice(pkg.length + 1)
|
|
575
|
+
};
|
|
576
|
+
}
|
|
577
|
+
const stripDot = (p) => p.replace(/^\.\//, "");
|
|
578
|
+
const stripExt = (p) => p.replace(/\.(?:[cm]?[jt]sx?|json)$/, "");
|
|
579
|
+
/** The value every `*` in `target` stands for when it matches `subpath`, or null. */
|
|
580
|
+
function patternMatch(target, subpath) {
|
|
581
|
+
const parts = target.split("*");
|
|
582
|
+
if (parts.length < 2) return null;
|
|
583
|
+
const escape = (text) => text.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
584
|
+
const source = parts.map((part, i) => (i === 0 ? "" : i === 1 ? "(.+?)" : "\\1") + escape(part)).join("");
|
|
585
|
+
const match = new RegExp(`^${source}$`).exec(subpath);
|
|
586
|
+
return match ? match[1] : null;
|
|
587
|
+
}
|
|
588
|
+
/** Every file target in an `exports` value, whatever its condition nesting. */
|
|
589
|
+
function exportTargets(value) {
|
|
590
|
+
if (typeof value === "string") return [value];
|
|
591
|
+
if (Array.isArray(value)) return value.flatMap(exportTargets);
|
|
592
|
+
if (value && typeof value === "object") return Object.values(value).flatMap(exportTargets);
|
|
593
|
+
return [];
|
|
594
|
+
}
|
|
595
|
+
/**
|
|
596
|
+
* The request that reached a file inside a package, recovered from the package's own
|
|
597
|
+
* manifest when only the resolved file is known (see presetPackageOfFile): the
|
|
598
|
+
* `exports` subpath that serves it (`./jest-utils` → "pkg/jest-utils", `.` → "pkg"),
|
|
599
|
+
* else the package itself for its `main`/`module`/`react-native` entry, else the
|
|
600
|
+
* subpath with `index` files read as their directory, as Node and Metro resolve them.
|
|
601
|
+
* The redirect's exemptions (utility entries such as `plugin`, `mock`, `jest-utils`)
|
|
602
|
+
* then apply to the request a caller actually wrote, not to a file name like `index`.
|
|
603
|
+
*/
|
|
604
|
+
function requestForPackageFile(pkg, subpath, manifest) {
|
|
605
|
+
const sub = toPosix(subpath);
|
|
606
|
+
const exportsField = manifest?.exports;
|
|
607
|
+
if (exportsField && typeof exportsField === "object" && !Array.isArray(exportsField)) {
|
|
608
|
+
const entries = Object.keys(exportsField).some((k) => k.startsWith(".")) ? Object.entries(exportsField) : [[".", exportsField]];
|
|
609
|
+
for (const [key, value] of entries) for (const target of exportTargets(value)) {
|
|
610
|
+
const t = stripDot(target);
|
|
611
|
+
if (!key.includes("*")) {
|
|
612
|
+
if (t === sub) return key === "." ? pkg : `${pkg}/${stripDot(key)}`;
|
|
613
|
+
continue;
|
|
614
|
+
}
|
|
615
|
+
const star = patternMatch(t, sub);
|
|
616
|
+
if (star !== null) return `${pkg}/${stripDot(key).split("*").join(star)}`;
|
|
617
|
+
}
|
|
618
|
+
} else if (typeof exportsField === "string" && stripDot(exportsField) === sub) return pkg;
|
|
619
|
+
for (const field of [
|
|
620
|
+
"react-native",
|
|
621
|
+
"module",
|
|
622
|
+
"main"
|
|
623
|
+
]) {
|
|
624
|
+
const entry = manifest?.[field];
|
|
625
|
+
if (typeof entry === "string" && stripExt(stripDot(entry)) === stripExt(sub)) return pkg;
|
|
626
|
+
}
|
|
627
|
+
if (!manifest?.main && /^index\.[cm]?[jt]sx?$/.test(sub)) return pkg;
|
|
628
|
+
const withoutIndex = sub.replace(/\/index\.[cm]?[jt]sx?$/, "");
|
|
629
|
+
return `${pkg}/${withoutIndex === sub ? stripExt(sub) : withoutIndex}`;
|
|
630
|
+
}
|
|
631
|
+
/**
|
|
632
|
+
* Whether the resolved `file` is preset package `pkg`'s own entry: the file a bare
|
|
633
|
+
* `pkg` answers (requestForPackageFile), reached through a subpath such as
|
|
634
|
+
* `pkg/lib/commonjs/index` or `pkg/src`. That subpath is the package itself, so it gets
|
|
635
|
+
* the root mock on every route (the CommonJS hook, the ESM loader, the plugin).
|
|
636
|
+
*/
|
|
637
|
+
function isPackageEntryFile(pkg, file, parentFile) {
|
|
638
|
+
const hit = presetPackageOfFile(file, parentFile, (name) => name === pkg);
|
|
639
|
+
if (!hit) return false;
|
|
640
|
+
const pkgDir = toPosix(file).slice(0, -(hit.subpath.length + 1));
|
|
641
|
+
return requestForPackageFile(pkg, hit.subpath, entryManifest(pkgDir)) === pkg;
|
|
642
|
+
}
|
|
643
|
+
const entryManifests = /* @__PURE__ */ new Map();
|
|
644
|
+
function entryManifest(pkgDir) {
|
|
645
|
+
if (!entryManifests.has(pkgDir)) {
|
|
646
|
+
let manifest = null;
|
|
647
|
+
try {
|
|
648
|
+
manifest = JSON.parse(fs.readFileSync(path.join(pkgDir, "package.json"), "utf8"));
|
|
649
|
+
} catch {
|
|
650
|
+
manifest = null;
|
|
651
|
+
}
|
|
652
|
+
entryManifests.set(pkgDir, manifest);
|
|
653
|
+
}
|
|
654
|
+
return entryManifests.get(pkgDir);
|
|
655
|
+
}
|
|
656
|
+
// src/native/ownership.mjs
|
|
556
657
|
/**
|
|
557
658
|
* Project-scoped module ownership policy for the native engine.
|
|
558
659
|
*
|
|
@@ -882,8 +983,7 @@ function formatNativeOwnershipManifest(input) {
|
|
|
882
983
|
if (manifest.enforcement === "overridden-by-inline-all") lines.push("WARNING: server.deps.inline=true takes precedence over Node ownership; graph uniqueness is not guaranteed");
|
|
883
984
|
return lines;
|
|
884
985
|
}
|
|
885
|
-
|
|
886
|
-
//#region src/native/babel-preset.mjs
|
|
986
|
+
// src/native/babel-preset.mjs
|
|
887
987
|
/**
|
|
888
988
|
* The Babel preset the native engine compiles React Native and node_modules with,
|
|
889
989
|
* resolved from the project: the preset the project's Metro applies when the project
|
|
@@ -999,8 +1099,7 @@ function detectEngine(requested, projectRoot, opts) {
|
|
|
999
1099
|
notice: null
|
|
1000
1100
|
};
|
|
1001
1101
|
}
|
|
1002
|
-
|
|
1003
|
-
//#region src/native/ecosystem.ts
|
|
1102
|
+
// src/native/ecosystem.ts
|
|
1004
1103
|
/** A path inside a node_modules directory: an installed package's, not a workspace member's. */
|
|
1005
1104
|
const NODE_MODULES_DIR = /[\\/]node_modules[\\/]/;
|
|
1006
1105
|
/**
|
|
@@ -1364,8 +1463,7 @@ function detectEcosystemPackages(projectRoot, explicit = [], testRoots = [], nev
|
|
|
1364
1463
|
walk(true);
|
|
1365
1464
|
return [...inClosure].sort();
|
|
1366
1465
|
}
|
|
1367
|
-
|
|
1368
|
-
//#region src/host.ts
|
|
1466
|
+
// src/host.ts
|
|
1369
1467
|
/** The running Vite's version, and where it was read, for messages that name it. */
|
|
1370
1468
|
async function runningVite(context) {
|
|
1371
1469
|
const fromHost = context?.meta?.viteVersion;
|
|
@@ -1496,5 +1594,4 @@ function assertHotWorkerLoadsRunningVitest(running, workerEntry) {
|
|
|
1496
1594
|
version: running.version
|
|
1497
1595
|
}, loadedRoot, "the hot runtime's worker", " Or set `hotRuntime: false`: per-file isolation loads Vitest through Vitest's own resolver, which reaches the running copy.");
|
|
1498
1596
|
}
|
|
1499
|
-
|
|
1500
|
-
export { unsupportedExpoSdkMessage as C, warnUnknownOptions as E, installedExpoVersion as S, validatePeerDependency as T, packageDirOf as _, runningVite as a, shouldDefaultFsModuleCache as b, detectEngine as c, findNativeInlineConflicts as d, findNativeOwnershipConflict as f, memoizePackageDirOf as g, dependencyDirOf as h, ownVitestPackage as i, resolveTransformPreset as l, containsPath as m, assertHotWorkerLoadsRunningVitest as n, usesVitePlus as o, formatNativeOwnershipManifest as p, installedViteVersion as r, detectEcosystemPackages as s, assertHostResolvesRunningVitest as t, createNativeOwnershipPolicy as u, fsModuleCacheKey as v, validateOptions as w, PEER_REQUIREMENTS as x, fsModuleCacheOnByDefault as y };
|
|
1597
|
+
export { SUPPORTED_EXPO_SDKS as C, validatePeerDependency as D, validateOptions as E, warnUnknownOptions as O, PEER_REQUIREMENTS as S, unsupportedExpoSdkMessage as T, memoizePackageDirOf as _, runningVite as a, fsModuleCacheOnByDefault as b, detectEngine as c, findNativeInlineConflicts as d, findNativeOwnershipConflict as f, isPackageEntryFile as g, dependencyDirOf as h, ownVitestPackage as i, resolveTransformPreset as l, containsPath as m, assertHotWorkerLoadsRunningVitest as n, usesVitePlus as o, formatNativeOwnershipManifest as p, installedViteVersion as r, detectEcosystemPackages as s, assertHostResolvesRunningVitest as t, createNativeOwnershipPolicy as u, packageDirOf as v, installedExpoVersion as w, shouldDefaultFsModuleCache as x, fsModuleCacheKey as y };
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { Mock } from "vitest";
|
|
2
|
-
//#region src/types.d.ts
|
|
3
2
|
/** Static methods available on the Image component mock. */
|
|
4
3
|
interface ImageStatic {
|
|
5
4
|
getSize: Mock;
|
|
@@ -243,6 +242,13 @@ interface NavigationPresetOptions {
|
|
|
243
242
|
*/
|
|
244
243
|
defaultRouteParams?: Record<string, unknown>;
|
|
245
244
|
}
|
|
245
|
+
/** The `hotRuntime` object form's recycling options, shared by both of its modes. */
|
|
246
|
+
interface HotRuntimeRecycleOptions {
|
|
247
|
+
recycleAfterFiles?: number;
|
|
248
|
+
memoryLimit?: number;
|
|
249
|
+
preserveGlobals?: string[];
|
|
250
|
+
esmGeneration?: boolean;
|
|
251
|
+
}
|
|
246
252
|
interface VitestNativeOptions {
|
|
247
253
|
/** Target platform. Default: 'ios' */
|
|
248
254
|
platform?: "ios" | "android";
|
|
@@ -396,17 +402,24 @@ interface VitestNativeOptions {
|
|
|
396
402
|
* explicit custom pool; otherwise the run keeps per-file isolation and prints the
|
|
397
403
|
* reason for falling back.
|
|
398
404
|
*
|
|
405
|
+
* - `mode: 'auto'` in the object form selects the same way, with the object's
|
|
406
|
+
* recycling options applied when the hot runtime runs:
|
|
407
|
+
* `{ mode: 'auto', memoryLimit: 2 * 1024 ** 3 }`. Without `mode`, the object
|
|
408
|
+
* form requires the hot runtime, as `true` does. Cannot be combined with
|
|
409
|
+
* `allowUnboundedMemory: true`. Worker count and process-RSS limits still come
|
|
410
|
+
* from the memory plan; `memoryLimit: 0` turns the heap threshold off.
|
|
411
|
+
*
|
|
399
412
|
* Default: `false`, as in 0.13.0: each file runs in a fresh worker, with React
|
|
400
413
|
* Native reloaded per file. The hot runtime has known differences from per-file
|
|
401
414
|
* isolation, listed in the troubleshooting guide.
|
|
402
415
|
*/
|
|
403
|
-
hotRuntime?: boolean | "auto" | {
|
|
404
|
-
|
|
405
|
-
memoryLimit?: number;
|
|
416
|
+
hotRuntime?: boolean | "auto" | (HotRuntimeRecycleOptions & {
|
|
417
|
+
mode?: undefined;
|
|
406
418
|
allowUnboundedMemory?: boolean;
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
419
|
+
}) | (HotRuntimeRecycleOptions & {
|
|
420
|
+
mode: "auto";
|
|
421
|
+
allowUnboundedMemory?: false;
|
|
422
|
+
});
|
|
410
423
|
/**
|
|
411
424
|
* `engine: 'native'` only. How native module lookups answer.
|
|
412
425
|
*
|
|
@@ -422,65 +435,26 @@ interface VitestNativeOptions {
|
|
|
422
435
|
*/
|
|
423
436
|
nativeModules?: "device" | "permissive";
|
|
424
437
|
}
|
|
425
|
-
//#endregion
|
|
426
|
-
//#region src/presets/reanimated.d.ts
|
|
427
438
|
declare function reanimated(): Preset;
|
|
428
|
-
//#endregion
|
|
429
|
-
//#region src/presets/gesture-handler.d.ts
|
|
430
439
|
declare function gestureHandler(): Preset;
|
|
431
|
-
//#endregion
|
|
432
|
-
//#region src/presets/safe-area.d.ts
|
|
433
440
|
declare function safeAreaContext(): Preset;
|
|
434
|
-
//#endregion
|
|
435
|
-
//#region src/presets/navigation.d.ts
|
|
436
441
|
declare function navigation(presetOptions?: NavigationPresetOptions): Preset;
|
|
437
|
-
//#endregion
|
|
438
|
-
//#region src/presets/async-storage.d.ts
|
|
439
442
|
declare function asyncStorage(): Preset;
|
|
440
|
-
//#endregion
|
|
441
|
-
//#region src/presets/screens.d.ts
|
|
442
443
|
declare function screens(): Preset;
|
|
443
|
-
//#endregion
|
|
444
|
-
//#region src/presets/expo.d.ts
|
|
445
444
|
declare function expo(): Preset;
|
|
446
|
-
//#endregion
|
|
447
|
-
//#region src/presets/device-info.d.ts
|
|
448
445
|
declare function deviceInfo(): Preset;
|
|
449
|
-
//#endregion
|
|
450
|
-
//#region src/presets/mmkv.d.ts
|
|
451
446
|
declare function mmkv(): Preset;
|
|
452
|
-
//#endregion
|
|
453
|
-
//#region src/presets/netinfo.d.ts
|
|
454
447
|
declare function netInfo(): Preset;
|
|
455
|
-
//#endregion
|
|
456
|
-
//#region src/presets/svg.d.ts
|
|
457
448
|
declare function svg(): Preset;
|
|
458
|
-
//#endregion
|
|
459
|
-
//#region src/presets/webview.d.ts
|
|
460
449
|
declare function webview(): Preset;
|
|
461
|
-
//#endregion
|
|
462
|
-
//#region src/presets/vector-icons.d.ts
|
|
463
450
|
declare function vectorIcons(): Preset;
|
|
464
|
-
//#endregion
|
|
465
|
-
//#region src/presets/flash-list.d.ts
|
|
466
451
|
declare function flashList(): Preset;
|
|
467
|
-
//#endregion
|
|
468
|
-
//#region src/presets/bottom-sheet.d.ts
|
|
469
452
|
declare function bottomSheet(): Preset;
|
|
470
|
-
//#endregion
|
|
471
|
-
//#region src/presets/keyboard-controller.d.ts
|
|
472
453
|
declare function keyboardController(): Preset;
|
|
473
|
-
//#endregion
|
|
474
|
-
//#region src/presets/worklets.d.ts
|
|
475
454
|
declare function worklets(): Preset;
|
|
476
|
-
//#endregion
|
|
477
|
-
//#region src/presets/unistyles.d.ts
|
|
478
455
|
declare function unistyles(): Preset;
|
|
479
|
-
//#endregion
|
|
480
|
-
//#region src/presets/skia.d.ts
|
|
481
456
|
declare function skia(): Preset;
|
|
482
457
|
declare namespace index_d_exports {
|
|
483
458
|
export { asyncStorage, bottomSheet, deviceInfo, expo, flashList, gestureHandler, keyboardController, mmkv, navigation, netInfo, reanimated, safeAreaContext, screens, skia, svg, unistyles, vectorIcons, webview, worklets };
|
|
484
459
|
}
|
|
485
|
-
//#endregion
|
|
486
460
|
export { VitestNativeOptions as C, ReactNativeMock as S, navigation as _, keyboardController as a, reanimated as b, vectorIcons as c, netInfo as d, mmkv as f, asyncStorage as g, screens as h, worklets as i, webview as l, expo as m, skia as n, bottomSheet as o, deviceInfo as p, unistyles as r, flashList as s, index_d_exports as t, svg as u, safeAreaContext as v, Preset as x, gestureHandler as y };
|
package/dist/index.d.mts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import { C as VitestNativeOptions, S as ReactNativeMock, t as index_d_exports, x as Preset } from "./index-
|
|
1
|
+
import { C as VitestNativeOptions, S as ReactNativeMock, t as index_d_exports, x as Preset } from "./index-DqU4YO3D.mjs";
|
|
2
2
|
import { Plugin } from "vite";
|
|
3
|
-
//#region src/plugin.d.ts
|
|
4
3
|
/**
|
|
5
4
|
* Preset names switched off by the object form of the `presets` option.
|
|
6
5
|
*
|
|
@@ -11,5 +10,4 @@ import { Plugin } from "vite";
|
|
|
11
10
|
*/
|
|
12
11
|
export declare function disabledPresetNames(presets: unknown): Set<string>;
|
|
13
12
|
export declare function reactNative(options?: VitestNativeOptions): Plugin;
|
|
14
|
-
//#endregion
|
|
15
13
|
export { type Preset, type ReactNativeMock, type VitestNativeOptions, index_d_exports as presets };
|