vitest-native 0.14.0-rc.12 → 0.14.0-rc.14
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 +15 -0
- package/dist/cli.d.mts +1 -3
- package/dist/cli.mjs +27 -41
- package/dist/context.d.mts +5 -0
- package/dist/context.mjs +5 -0
- 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-5o48Ujzs.mjs} +75 -636
- package/dist/{index-CPEAYjaQ.d.mts → index-DqU4YO3D.d.mts} +20 -46
- package/dist/index.d.mts +1 -3
- package/dist/index.mjs +110 -468
- 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 +3 -5
- 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-Couw0Esx.mjs} +17 -3
- package/dist/native/babel-toolchain.mjs +128 -2
- package/dist/native/babel-worker.mjs +11 -17
- package/dist/native/coverage-v8.mjs +287 -0
- package/dist/native/globals.mjs +45 -2
- package/dist/native/hooks.mjs +119 -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 +14 -8
- package/dist/native/transform.mjs +207 -41
- package/dist/native/worker.mjs +44 -6
- package/dist/{pool-DUOe-n1k.mjs → pool-CFSpNfyw.mjs} +30 -10
- package/dist/{preset-map-L1-vD19T.mjs → preset-map-CogjYmSw.mjs} +3 -36
- package/dist/{presets-DuXiUNAx.mjs → presets-CXDyg51l.mjs} +55 -77
- 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 +60 -398
- package/dist/{worker-vitest-BGPo0ek6.mjs → worker-vitest-CILPFeRX.mjs} +2 -3
- package/docs/migrating-from-jest.md +7 -0
- package/package.json +17 -8
- package/dist/errors-CxoBUfVJ.mjs +0 -64
- package/dist/preset-modules-Bt6k_Wdw.mjs +0 -31
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
|
|
@@ -971,6 +975,17 @@ reactNative({
|
|
|
971
975
|
|
|
972
976
|
This prints details about which presets were detected, which modules are being mocked, and how imports are resolved. Useful for debugging unexpected behavior.
|
|
973
977
|
|
|
978
|
+
To turn it on for a single run, read an environment variable you choose, then run
|
|
979
|
+
`RN_TEST_DEBUG=1 vitest run`:
|
|
980
|
+
|
|
981
|
+
```ts
|
|
982
|
+
reactNative({ diagnostics: process.env.RN_TEST_DEBUG === "1" });
|
|
983
|
+
```
|
|
984
|
+
|
|
985
|
+
There is no `VITEST_NATIVE_DIAGNOSTICS` variable. Older releases' `VITEST_NATIVE_*` settings, such
|
|
986
|
+
as `VITEST_NATIVE_PLATFORM`, are no longer read; set the matching option. Startup warns when one
|
|
987
|
+
is set.
|
|
988
|
+
|
|
974
989
|
---
|
|
975
990
|
|
|
976
991
|
## Support Policy
|
package/dist/cli.d.mts
CHANGED
package/dist/cli.mjs
CHANGED
|
@@ -1,28 +1,15 @@
|
|
|
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 { c as detectEcosystemPackages, d as fsModuleCacheOnByDefault, g as unsupportedExpoSdkMessage, h as installedExpoVersion, i as ownVitestPackage, l as detectEngine, o as usesVitePlus, p as PEER_REQUIREMENTS, r as installedViteVersion, v as validatePeerDependency } from "./host-5o48Ujzs.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-CogjYmSw.mjs";
|
|
4
|
+
import { n as formatHotMemoryPlan, t as createHotMemoryPlan } from "./memory-Couw0Esx.mjs";
|
|
5
5
|
import { createRequire } from "node:module";
|
|
6
|
-
import
|
|
6
|
+
import { fileURLToPath } from "node:url";
|
|
7
7
|
import path from "node:path";
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
"react-native.dimensions",
|
|
14
|
-
"react-native.appearance",
|
|
15
|
-
"react-native.event-listeners",
|
|
16
|
-
"process.env",
|
|
17
|
-
"process.listeners",
|
|
18
|
-
"global.descriptors",
|
|
19
|
-
"console.descriptors",
|
|
20
|
-
"react-native.error-utils",
|
|
21
|
-
"expo.runtime",
|
|
22
|
-
"jest-compat.node-mocks"
|
|
23
|
-
]);
|
|
24
|
-
//#endregion
|
|
25
|
-
//#region src/cli/manifest.ts
|
|
8
|
+
import fs from "node:fs";
|
|
9
|
+
import { createNativeOwnershipPolicy, formatNativeOwnershipManifest } from "./native/ownership.mjs";
|
|
10
|
+
import { resolveTransformPreset } from "./native/babel-preset.mjs";
|
|
11
|
+
import { HOT_STATE_MANIFEST_ENTRIES } from "./native/state-manifest.mjs";
|
|
12
|
+
// src/cli/manifest.ts
|
|
26
13
|
/**
|
|
27
14
|
* Installed-package facts for the CLI, read from disk.
|
|
28
15
|
*
|
|
@@ -72,8 +59,7 @@ function activePresets(root, disabled = [], engine = "native") {
|
|
|
72
59
|
}
|
|
73
60
|
return [...active];
|
|
74
61
|
}
|
|
75
|
-
|
|
76
|
-
//#region src/cli/babel-config.ts
|
|
62
|
+
// src/cli/babel-config.ts
|
|
77
63
|
/**
|
|
78
64
|
* The project's Babel configuration, as `migrate` and `doctor` need to see it.
|
|
79
65
|
*
|
|
@@ -332,8 +318,7 @@ function serializableOptions(entry) {
|
|
|
332
318
|
};
|
|
333
319
|
return entry.options === void 0 || plain(entry.options);
|
|
334
320
|
}
|
|
335
|
-
|
|
336
|
-
//#region src/cli/doctor.ts
|
|
321
|
+
// src/cli/doctor.ts
|
|
337
322
|
/**
|
|
338
323
|
* `vitest-native doctor` — diagnose the project's environment: peer versions,
|
|
339
324
|
* engine resolution (and why), detected presets, RNTL/Node compatibility, and
|
|
@@ -353,10 +338,18 @@ function packageVersion(root, name) {
|
|
|
353
338
|
*/
|
|
354
339
|
function nodeRange() {
|
|
355
340
|
const fallback = ">=22.13.0 <23 || >=24.3.0";
|
|
341
|
+
for (let dir = path.dirname(fileURLToPath(import.meta.url));; dir = path.dirname(dir)) {
|
|
342
|
+
const manifest = readManifest(path.join(dir, "package.json"));
|
|
343
|
+
if (manifest?.name === "vitest-native") return manifest.engines?.node?.trim() || fallback;
|
|
344
|
+
if (path.dirname(dir) === dir) return fallback;
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
/** A package.json, or null where there is none or it does not parse. */
|
|
348
|
+
function readManifest(file) {
|
|
356
349
|
try {
|
|
357
|
-
return JSON.parse(fs.readFileSync(
|
|
350
|
+
return JSON.parse(fs.readFileSync(file, "utf8"));
|
|
358
351
|
} catch {
|
|
359
|
-
return
|
|
352
|
+
return null;
|
|
360
353
|
}
|
|
361
354
|
}
|
|
362
355
|
const versionParts = (version) => {
|
|
@@ -706,8 +699,7 @@ function runDoctor(root, nodeVersion = process.versions.node) {
|
|
|
706
699
|
ok
|
|
707
700
|
};
|
|
708
701
|
}
|
|
709
|
-
|
|
710
|
-
//#region src/cli/init.ts
|
|
702
|
+
// src/cli/init.ts
|
|
711
703
|
/**
|
|
712
704
|
* `vitest-native init` — write a ready-to-run Vitest config. Two shapes:
|
|
713
705
|
* the zero-config default, and the jest-compat variant (the exact block the
|
|
@@ -889,8 +881,7 @@ function tryExpand(source, literalDot) {
|
|
|
889
881
|
throw error;
|
|
890
882
|
}
|
|
891
883
|
}
|
|
892
|
-
|
|
893
|
-
//#region src/cli/allowlist.ts
|
|
884
|
+
// src/cli/allowlist.ts
|
|
894
885
|
/**
|
|
895
886
|
* Reading Jest's `transformIgnorePatterns` allowlist,
|
|
896
887
|
* `node_modules/(?!(a|b|@scope/c)/)`. Real ones nest — React Native's own preset
|
|
@@ -987,8 +978,7 @@ function allows(entry, pkg) {
|
|
|
987
978
|
if (entry.kind === "scope") return pkg.startsWith(`${entry.name}/`);
|
|
988
979
|
return pkg.startsWith(entry.name);
|
|
989
980
|
}
|
|
990
|
-
|
|
991
|
-
//#region src/cli/jest-discovery.ts
|
|
981
|
+
// src/cli/jest-discovery.ts
|
|
992
982
|
/**
|
|
993
983
|
* Which files Jest treats as tests, said to Vitest.
|
|
994
984
|
*
|
|
@@ -1351,8 +1341,7 @@ function booleanFlag(value) {
|
|
|
1351
1341
|
if (value === true || value === "true") return true;
|
|
1352
1342
|
if (value === "false") return false;
|
|
1353
1343
|
}
|
|
1354
|
-
|
|
1355
|
-
//#region src/cli/untranspiled.ts
|
|
1344
|
+
// src/cli/untranspiled.ts
|
|
1356
1345
|
/**
|
|
1357
1346
|
* Evidence that a package needs `transform`: a `.js` file under one of its entry
|
|
1358
1347
|
* points that is not standard JavaScript (JSX or Flow), which neither Node nor Vite
|
|
@@ -1460,8 +1449,7 @@ function untranspiledFile(root, pkg) {
|
|
|
1460
1449
|
}
|
|
1461
1450
|
return null;
|
|
1462
1451
|
}
|
|
1463
|
-
|
|
1464
|
-
//#region src/cli/migrate.ts
|
|
1452
|
+
// src/cli/migrate.ts
|
|
1465
1453
|
/**
|
|
1466
1454
|
* `vitest-native migrate` — analyze a project's Jest configuration and report,
|
|
1467
1455
|
* key by key, what maps automatically, what the presets already cover (delete
|
|
@@ -1982,8 +1970,7 @@ function renderMigrationReport(report) {
|
|
|
1982
1970
|
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
1971
|
return lines;
|
|
1984
1972
|
}
|
|
1985
|
-
|
|
1986
|
-
//#region src/cli/index.ts
|
|
1973
|
+
// src/cli/index.ts
|
|
1987
1974
|
/**
|
|
1988
1975
|
* vitest-native CLI: `init` (write a ready config), `doctor` (diagnose the
|
|
1989
1976
|
* environment), `migrate` (analyze a Jest config and report the mapping).
|
|
@@ -2057,5 +2044,4 @@ function main(argv, log = console.log) {
|
|
|
2057
2044
|
}
|
|
2058
2045
|
const entry = process.argv[1] ? path.basename(process.argv[1]) : "";
|
|
2059
2046
|
if (entry === "cli.mjs" || entry === "cli.cjs" || entry === "vitest-native") process.exit(main(process.argv.slice(2)));
|
|
2060
|
-
//#endregion
|
|
2061
2047
|
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) {
|
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 {
|
|
2
|
-
|
|
1
|
+
import { VitestNativeError } from "./errors.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 };
|