vitest-native 0.9.0 → 0.10.0
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/CHANGELOG.md +731 -0
- package/README.md +32 -1
- package/dist/cli.cjs +163 -27
- package/dist/cli.mjs +162 -26
- package/dist/{ecosystem-EFtHnKS9.mjs → ecosystem-CO5vqExO.mjs} +77 -15
- package/dist/{ecosystem-BIWaVwYL.cjs → ecosystem-IuZ-Gv0R.cjs} +78 -16
- package/dist/errors-Dm5yLNTF.mjs +64 -0
- package/dist/errors-flXDIeWk.cjs +75 -0
- package/dist/errors.d.mts +46 -0
- package/dist/errors.mjs +78 -0
- package/dist/helpers.cjs +6 -23
- package/dist/helpers.d.cts +0 -6
- package/dist/helpers.d.mts +0 -6
- package/dist/helpers.mjs +6 -23
- package/dist/{index-CEgRDdhd.d.cts → index-BJL4cQ-l.d.cts} +9 -4
- package/dist/{index-j-0tueBr.d.mts → index-CvCU0cLl.d.mts} +9 -4
- package/dist/index.d.mts +8 -6
- package/dist/index.mjs +245 -59
- package/dist/jest-compat/interop.mjs +15 -0
- package/dist/jest-compat/setup.mjs +102 -7
- package/dist/matchers.cjs +16 -7
- package/dist/matchers.mjs +16 -7
- package/dist/native/hooks.mjs +75 -1
- package/dist/native/loader.mjs +26 -6
- package/dist/native/module-reset.mjs +63 -0
- package/dist/native/registry.mjs +80 -11
- package/dist/native/resolve.d.mts +22 -0
- package/dist/native/resolve.mjs +21 -13
- package/dist/native/runner.mjs +21 -0
- package/dist/native/setup.mjs +4 -2
- package/dist/native/transform.mjs +108 -3
- package/dist/native/worker.mjs +59 -16
- package/dist/{pool-CJmjRgsB.mjs → pool-Bcxp4Qrg.mjs} +2 -1
- package/dist/{pool-DzsEo9vv.cjs → pool-CFND7plG.cjs} +2 -1
- package/dist/{preset-map-CNsZKfvu.mjs → preset-map-BpDG_D5m.mjs} +0 -1
- package/dist/{preset-map-CG4FMtsl.cjs → preset-map-DxilQ4pI.cjs} +0 -1
- package/dist/{presets-C4faM3ds.cjs → presets-BGTqVH6C.cjs} +94 -50
- package/dist/{presets-CuDrNA_W.mjs → presets-CK85x8ey.mjs} +94 -50
- package/dist/presets.d.mts +1 -1
- package/dist/presets.mjs +1 -1
- package/dist/rntl-matchers.d.ts +35 -0
- package/dist/serializer.cjs +33 -3
- package/dist/serializer.mjs +33 -3
- package/dist/setup.mjs +234 -71
- package/docs/release-readiness.md +22 -5
- package/docs/versioning.md +133 -0
- package/package.json +25 -35
- package/dist/index.cjs +0 -788
- package/dist/index.d.cts +0 -14
- package/dist/presets.cjs +0 -18
- package/dist/presets.d.cts +0 -2
- package/dist/setup.cjs +0 -2702
- package/dist/setup.d.cts +0 -1
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { n as VitestNativeTypeError } from "./errors-Dm5yLNTF.mjs";
|
|
2
|
+
import { t as AUTO_DETECT_PRESETS } from "./preset-map-BpDG_D5m.mjs";
|
|
2
3
|
import { createRequire } from "node:module";
|
|
3
|
-
import path from "node:path";
|
|
4
4
|
import fs from "node:fs";
|
|
5
|
+
import path from "node:path";
|
|
5
6
|
//#region src/validate.ts
|
|
6
7
|
const KNOWN_OPTIONS = [
|
|
7
8
|
"platform",
|
|
@@ -19,24 +20,29 @@ const KNOWN_HOT_RUNTIME_OPTIONS = [
|
|
|
19
20
|
"preserveGlobals"
|
|
20
21
|
];
|
|
21
22
|
function assertStringArray(value, option) {
|
|
22
|
-
if (!Array.isArray(value) || value.some((entry) => typeof entry !== "string" || entry.length === 0)) throw new
|
|
23
|
+
if (!Array.isArray(value) || value.some((entry) => typeof entry !== "string" || entry.length === 0)) throw new VitestNativeTypeError("INVALID_OPTION", `"${option}" must be an array of non-empty strings.`);
|
|
23
24
|
}
|
|
24
25
|
function assertNonNegativeInteger(value, option) {
|
|
25
|
-
if (typeof value !== "number" || !Number.isSafeInteger(value) || value < 0) throw new
|
|
26
|
+
if (typeof value !== "number" || !Number.isSafeInteger(value) || value < 0) throw new VitestNativeTypeError("INVALID_OPTION", `"${option}" must be a non-negative safe integer.`);
|
|
26
27
|
}
|
|
27
28
|
function validateOptions(options) {
|
|
28
|
-
if (options.engine !== void 0 && options.engine !== "auto" && options.engine !== "mock" && options.engine !== "native") throw new
|
|
29
|
-
if (options.platform !== void 0 && options.platform !== "ios" && options.platform !== "android") throw new
|
|
30
|
-
if (options.diagnostics !== void 0 && typeof options.diagnostics !== "boolean") throw new
|
|
29
|
+
if (options.engine !== void 0 && options.engine !== "auto" && options.engine !== "mock" && options.engine !== "native") throw new VitestNativeTypeError("INVALID_OPTION", `"engine" must be "auto", "mock", or "native".`);
|
|
30
|
+
if (options.platform !== void 0 && options.platform !== "ios" && options.platform !== "android") throw new VitestNativeTypeError("INVALID_OPTION", `"platform" must be "ios" or "android".`);
|
|
31
|
+
if (options.diagnostics !== void 0 && typeof options.diagnostics !== "boolean") throw new VitestNativeTypeError("INVALID_OPTION", `"diagnostics" must be a boolean.`);
|
|
31
32
|
if (options.assetExts !== void 0) assertStringArray(options.assetExts, "assetExts");
|
|
32
33
|
if (options.transform !== void 0) assertStringArray(options.transform, "transform");
|
|
33
|
-
if (options.presets !== void 0 && !Array.isArray(options.presets))
|
|
34
|
-
|
|
34
|
+
if (options.presets !== void 0 && !Array.isArray(options.presets)) {
|
|
35
|
+
if (!(options.presets !== null && typeof options.presets === "object" && Object.values(options.presets).every((v) => typeof v === "boolean"))) throw new VitestNativeTypeError("INVALID_OPTION", "\"presets\" must be an array of presets, or an object of booleans to switch auto-detected presets off (for example { navigation: false }).");
|
|
36
|
+
}
|
|
37
|
+
if (options.mocks !== void 0 && (options.mocks === null || Array.isArray(options.mocks) || typeof options.mocks !== "object")) throw new VitestNativeTypeError("INVALID_OPTION", `"mocks" must be a plain object.`);
|
|
35
38
|
const hotRuntime = options.hotRuntime;
|
|
36
39
|
if (hotRuntime === void 0 || typeof hotRuntime === "boolean") return;
|
|
37
|
-
if (hotRuntime === null || Array.isArray(hotRuntime) || typeof hotRuntime !== "object") throw new
|
|
40
|
+
if (hotRuntime === null || Array.isArray(hotRuntime) || typeof hotRuntime !== "object") throw new VitestNativeTypeError("INVALID_OPTION", `"hotRuntime" must be a boolean or an options object.`);
|
|
38
41
|
const hotOptions = hotRuntime;
|
|
39
|
-
for (const key of Object.keys(hotOptions)) if (!KNOWN_HOT_RUNTIME_OPTIONS.includes(key))
|
|
42
|
+
for (const key of Object.keys(hotOptions)) if (!KNOWN_HOT_RUNTIME_OPTIONS.includes(key)) {
|
|
43
|
+
const suggestion = findClosest(key, KNOWN_HOT_RUNTIME_OPTIONS);
|
|
44
|
+
throw new VitestNativeTypeError("UNKNOWN_OPTION", `Unknown hotRuntime option "${key}".` + (suggestion ? ` Did you mean '${suggestion}'?` : "") + ` Valid options: ${KNOWN_HOT_RUNTIME_OPTIONS.join(", ")}.`);
|
|
45
|
+
}
|
|
40
46
|
if (hotOptions.recycleAfterFiles !== void 0) assertNonNegativeInteger(hotOptions.recycleAfterFiles, "hotRuntime.recycleAfterFiles");
|
|
41
47
|
if (hotOptions.memoryLimit !== void 0) assertNonNegativeInteger(hotOptions.memoryLimit, "hotRuntime.memoryLimit");
|
|
42
48
|
if (hotOptions.preserveGlobals !== void 0) assertStringArray(hotOptions.preserveGlobals, "hotRuntime.preserveGlobals");
|
|
@@ -111,6 +117,12 @@ const PEER_REQUIREMENTS = [
|
|
|
111
117
|
{
|
|
112
118
|
name: "react",
|
|
113
119
|
minimum: "18.0.0"
|
|
120
|
+
},
|
|
121
|
+
{
|
|
122
|
+
name: "@testing-library/react-native",
|
|
123
|
+
minimum: "12.0.0",
|
|
124
|
+
maximumMajor: 15,
|
|
125
|
+
optional: true
|
|
114
126
|
}
|
|
115
127
|
];
|
|
116
128
|
/** Can this project run the native engine? (Both transform deps resolvable.) */
|
|
@@ -190,13 +202,60 @@ function dependsOnReactNative(manifest) {
|
|
|
190
202
|
* never imported costs nothing, because inlining only applies to files that are
|
|
191
203
|
* actually loaded.
|
|
192
204
|
*/
|
|
205
|
+
/**
|
|
206
|
+
* Directories of the workspace members a manifest declares, plus any listed in a
|
|
207
|
+
* sibling pnpm-workspace.yaml.
|
|
208
|
+
*
|
|
209
|
+
* Needed because `manifestsFrom` only walks UP. In a workspace the run root is
|
|
210
|
+
* frequently ABOVE the package under test — Nx invokes tasks from the workspace
|
|
211
|
+
* root, and Vitest's root defaults to the working directory — so the app's own
|
|
212
|
+
* dependencies are declared in a manifest that walking up never reaches. The
|
|
213
|
+
* package then misses auto-detection and stays in Vite's graph while Node loads it
|
|
214
|
+
* too, which is the dual-ownership failure reproducing from nothing but a different
|
|
215
|
+
* working directory.
|
|
216
|
+
*
|
|
217
|
+
* Only the two glob shapes workspace fields actually use are expanded (`dir/*` and a
|
|
218
|
+
* literal path). Over-collecting is safe here — an unimported package costs nothing —
|
|
219
|
+
* so a shape that is not understood is skipped rather than approximated.
|
|
220
|
+
*/
|
|
221
|
+
function workspaceMemberDirs(dir, manifest) {
|
|
222
|
+
const patterns = [];
|
|
223
|
+
const declared = manifest.workspaces;
|
|
224
|
+
if (Array.isArray(declared)) patterns.push(...declared.filter((p) => typeof p === "string"));
|
|
225
|
+
else if (declared && typeof declared === "object" && Array.isArray(declared.packages)) patterns.push(...declared.packages.filter((p) => typeof p === "string"));
|
|
226
|
+
try {
|
|
227
|
+
const yaml = fs.readFileSync(path.join(dir, "pnpm-workspace.yaml"), "utf8");
|
|
228
|
+
for (const line of yaml.split(/\r?\n/)) {
|
|
229
|
+
const entry = /^\s*-\s*["']?([^"'#]+?)["']?\s*$/.exec(line);
|
|
230
|
+
if (entry) patterns.push(entry[1]);
|
|
231
|
+
}
|
|
232
|
+
} catch {}
|
|
233
|
+
const dirs = [];
|
|
234
|
+
for (const pattern of patterns) if (pattern.endsWith("/*")) {
|
|
235
|
+
const parent = path.join(dir, pattern.slice(0, -2));
|
|
236
|
+
try {
|
|
237
|
+
for (const entry of fs.readdirSync(parent, { withFileTypes: true })) if (entry.isDirectory()) dirs.push(path.join(parent, entry.name));
|
|
238
|
+
} catch {}
|
|
239
|
+
} else if (!pattern.includes("*")) dirs.push(path.join(dir, pattern));
|
|
240
|
+
return dirs;
|
|
241
|
+
}
|
|
193
242
|
function manifestsFrom(projectRoot) {
|
|
194
243
|
const manifests = [];
|
|
195
244
|
let dir = path.resolve(projectRoot);
|
|
196
245
|
for (;;) {
|
|
197
246
|
try {
|
|
198
247
|
const raw = fs.readFileSync(path.join(dir, "package.json"), "utf8");
|
|
199
|
-
|
|
248
|
+
const manifest = JSON.parse(raw);
|
|
249
|
+
manifests.push({
|
|
250
|
+
dir,
|
|
251
|
+
manifest
|
|
252
|
+
});
|
|
253
|
+
for (const member of workspaceMemberDirs(dir, manifest)) try {
|
|
254
|
+
manifests.push({
|
|
255
|
+
dir: member,
|
|
256
|
+
manifest: JSON.parse(fs.readFileSync(path.join(member, "package.json"), "utf8"))
|
|
257
|
+
});
|
|
258
|
+
} catch {}
|
|
200
259
|
} catch {}
|
|
201
260
|
const parent = path.dirname(dir);
|
|
202
261
|
if (parent === dir) return manifests;
|
|
@@ -227,14 +286,16 @@ function manifestsFrom(projectRoot) {
|
|
|
227
286
|
* in `transform` — that option keeps its existing meaning and takes precedence.
|
|
228
287
|
*/
|
|
229
288
|
function detectEcosystemPackages(projectRoot, explicit = []) {
|
|
230
|
-
const
|
|
289
|
+
const roots = (Array.isArray(projectRoot) ? projectRoot : [projectRoot]).filter(Boolean);
|
|
231
290
|
const skip = new Set([
|
|
232
291
|
...NEVER_INLINE,
|
|
233
292
|
...Object.keys(AUTO_DETECT_PRESETS),
|
|
234
293
|
...explicit
|
|
235
294
|
]);
|
|
236
295
|
const candidates = /* @__PURE__ */ new Set();
|
|
237
|
-
|
|
296
|
+
const found = roots.flatMap((root) => manifestsFrom(root));
|
|
297
|
+
const requires = [...new Set(found.map((entry) => entry.dir))].map((dir) => createRequire(path.join(dir, "package.json")));
|
|
298
|
+
for (const { manifest } of found) for (const field of [
|
|
238
299
|
"dependencies",
|
|
239
300
|
"devDependencies",
|
|
240
301
|
"optionalDependencies"
|
|
@@ -246,8 +307,9 @@ function detectEcosystemPackages(projectRoot, explicit = []) {
|
|
|
246
307
|
const detected = [];
|
|
247
308
|
for (const name of candidates) {
|
|
248
309
|
if (skip.has(name) || name.startsWith("@react-native/")) continue;
|
|
249
|
-
try {
|
|
310
|
+
for (const req of requires) try {
|
|
250
311
|
if (dependsOnReactNative(req(`${name}/package.json`))) detected.push(name);
|
|
312
|
+
break;
|
|
251
313
|
} catch {}
|
|
252
314
|
}
|
|
253
315
|
return detected.sort();
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
const require_chunk = require("./chunk-CZWwpsFl.cjs");
|
|
2
|
-
const
|
|
3
|
-
|
|
4
|
-
node_path = require_chunk.__toESM(node_path, 1);
|
|
2
|
+
const require_errors = require("./errors-flXDIeWk.cjs");
|
|
3
|
+
const require_preset_map = require("./preset-map-DxilQ4pI.cjs");
|
|
5
4
|
let node_fs = require("node:fs");
|
|
6
5
|
node_fs = require_chunk.__toESM(node_fs, 1);
|
|
6
|
+
let node_path = require("node:path");
|
|
7
|
+
node_path = require_chunk.__toESM(node_path, 1);
|
|
7
8
|
let node_module = require("node:module");
|
|
8
9
|
//#region src/validate.ts
|
|
9
10
|
const KNOWN_OPTIONS = [
|
|
@@ -22,24 +23,29 @@ const KNOWN_HOT_RUNTIME_OPTIONS = [
|
|
|
22
23
|
"preserveGlobals"
|
|
23
24
|
];
|
|
24
25
|
function assertStringArray(value, option) {
|
|
25
|
-
if (!Array.isArray(value) || value.some((entry) => typeof entry !== "string" || entry.length === 0)) throw new
|
|
26
|
+
if (!Array.isArray(value) || value.some((entry) => typeof entry !== "string" || entry.length === 0)) throw new require_errors.VitestNativeTypeError("INVALID_OPTION", `"${option}" must be an array of non-empty strings.`);
|
|
26
27
|
}
|
|
27
28
|
function assertNonNegativeInteger(value, option) {
|
|
28
|
-
if (typeof value !== "number" || !Number.isSafeInteger(value) || value < 0) throw new
|
|
29
|
+
if (typeof value !== "number" || !Number.isSafeInteger(value) || value < 0) throw new require_errors.VitestNativeTypeError("INVALID_OPTION", `"${option}" must be a non-negative safe integer.`);
|
|
29
30
|
}
|
|
30
31
|
function validateOptions(options) {
|
|
31
|
-
if (options.engine !== void 0 && options.engine !== "auto" && options.engine !== "mock" && options.engine !== "native") throw new
|
|
32
|
-
if (options.platform !== void 0 && options.platform !== "ios" && options.platform !== "android") throw new
|
|
33
|
-
if (options.diagnostics !== void 0 && typeof options.diagnostics !== "boolean") throw new
|
|
32
|
+
if (options.engine !== void 0 && options.engine !== "auto" && options.engine !== "mock" && options.engine !== "native") throw new require_errors.VitestNativeTypeError("INVALID_OPTION", `"engine" must be "auto", "mock", or "native".`);
|
|
33
|
+
if (options.platform !== void 0 && options.platform !== "ios" && options.platform !== "android") throw new require_errors.VitestNativeTypeError("INVALID_OPTION", `"platform" must be "ios" or "android".`);
|
|
34
|
+
if (options.diagnostics !== void 0 && typeof options.diagnostics !== "boolean") throw new require_errors.VitestNativeTypeError("INVALID_OPTION", `"diagnostics" must be a boolean.`);
|
|
34
35
|
if (options.assetExts !== void 0) assertStringArray(options.assetExts, "assetExts");
|
|
35
36
|
if (options.transform !== void 0) assertStringArray(options.transform, "transform");
|
|
36
|
-
if (options.presets !== void 0 && !Array.isArray(options.presets))
|
|
37
|
-
|
|
37
|
+
if (options.presets !== void 0 && !Array.isArray(options.presets)) {
|
|
38
|
+
if (!(options.presets !== null && typeof options.presets === "object" && Object.values(options.presets).every((v) => typeof v === "boolean"))) throw new require_errors.VitestNativeTypeError("INVALID_OPTION", "\"presets\" must be an array of presets, or an object of booleans to switch auto-detected presets off (for example { navigation: false }).");
|
|
39
|
+
}
|
|
40
|
+
if (options.mocks !== void 0 && (options.mocks === null || Array.isArray(options.mocks) || typeof options.mocks !== "object")) throw new require_errors.VitestNativeTypeError("INVALID_OPTION", `"mocks" must be a plain object.`);
|
|
38
41
|
const hotRuntime = options.hotRuntime;
|
|
39
42
|
if (hotRuntime === void 0 || typeof hotRuntime === "boolean") return;
|
|
40
|
-
if (hotRuntime === null || Array.isArray(hotRuntime) || typeof hotRuntime !== "object") throw new
|
|
43
|
+
if (hotRuntime === null || Array.isArray(hotRuntime) || typeof hotRuntime !== "object") throw new require_errors.VitestNativeTypeError("INVALID_OPTION", `"hotRuntime" must be a boolean or an options object.`);
|
|
41
44
|
const hotOptions = hotRuntime;
|
|
42
|
-
for (const key of Object.keys(hotOptions)) if (!KNOWN_HOT_RUNTIME_OPTIONS.includes(key))
|
|
45
|
+
for (const key of Object.keys(hotOptions)) if (!KNOWN_HOT_RUNTIME_OPTIONS.includes(key)) {
|
|
46
|
+
const suggestion = findClosest(key, KNOWN_HOT_RUNTIME_OPTIONS);
|
|
47
|
+
throw new require_errors.VitestNativeTypeError("UNKNOWN_OPTION", `Unknown hotRuntime option "${key}".` + (suggestion ? ` Did you mean '${suggestion}'?` : "") + ` Valid options: ${KNOWN_HOT_RUNTIME_OPTIONS.join(", ")}.`);
|
|
48
|
+
}
|
|
43
49
|
if (hotOptions.recycleAfterFiles !== void 0) assertNonNegativeInteger(hotOptions.recycleAfterFiles, "hotRuntime.recycleAfterFiles");
|
|
44
50
|
if (hotOptions.memoryLimit !== void 0) assertNonNegativeInteger(hotOptions.memoryLimit, "hotRuntime.memoryLimit");
|
|
45
51
|
if (hotOptions.preserveGlobals !== void 0) assertStringArray(hotOptions.preserveGlobals, "hotRuntime.preserveGlobals");
|
|
@@ -114,6 +120,12 @@ const PEER_REQUIREMENTS = [
|
|
|
114
120
|
{
|
|
115
121
|
name: "react",
|
|
116
122
|
minimum: "18.0.0"
|
|
123
|
+
},
|
|
124
|
+
{
|
|
125
|
+
name: "@testing-library/react-native",
|
|
126
|
+
minimum: "12.0.0",
|
|
127
|
+
maximumMajor: 15,
|
|
128
|
+
optional: true
|
|
117
129
|
}
|
|
118
130
|
];
|
|
119
131
|
/** Can this project run the native engine? (Both transform deps resolvable.) */
|
|
@@ -193,13 +205,60 @@ function dependsOnReactNative(manifest) {
|
|
|
193
205
|
* never imported costs nothing, because inlining only applies to files that are
|
|
194
206
|
* actually loaded.
|
|
195
207
|
*/
|
|
208
|
+
/**
|
|
209
|
+
* Directories of the workspace members a manifest declares, plus any listed in a
|
|
210
|
+
* sibling pnpm-workspace.yaml.
|
|
211
|
+
*
|
|
212
|
+
* Needed because `manifestsFrom` only walks UP. In a workspace the run root is
|
|
213
|
+
* frequently ABOVE the package under test — Nx invokes tasks from the workspace
|
|
214
|
+
* root, and Vitest's root defaults to the working directory — so the app's own
|
|
215
|
+
* dependencies are declared in a manifest that walking up never reaches. The
|
|
216
|
+
* package then misses auto-detection and stays in Vite's graph while Node loads it
|
|
217
|
+
* too, which is the dual-ownership failure reproducing from nothing but a different
|
|
218
|
+
* working directory.
|
|
219
|
+
*
|
|
220
|
+
* Only the two glob shapes workspace fields actually use are expanded (`dir/*` and a
|
|
221
|
+
* literal path). Over-collecting is safe here — an unimported package costs nothing —
|
|
222
|
+
* so a shape that is not understood is skipped rather than approximated.
|
|
223
|
+
*/
|
|
224
|
+
function workspaceMemberDirs(dir, manifest) {
|
|
225
|
+
const patterns = [];
|
|
226
|
+
const declared = manifest.workspaces;
|
|
227
|
+
if (Array.isArray(declared)) patterns.push(...declared.filter((p) => typeof p === "string"));
|
|
228
|
+
else if (declared && typeof declared === "object" && Array.isArray(declared.packages)) patterns.push(...declared.packages.filter((p) => typeof p === "string"));
|
|
229
|
+
try {
|
|
230
|
+
const yaml = node_fs.default.readFileSync(node_path.default.join(dir, "pnpm-workspace.yaml"), "utf8");
|
|
231
|
+
for (const line of yaml.split(/\r?\n/)) {
|
|
232
|
+
const entry = /^\s*-\s*["']?([^"'#]+?)["']?\s*$/.exec(line);
|
|
233
|
+
if (entry) patterns.push(entry[1]);
|
|
234
|
+
}
|
|
235
|
+
} catch {}
|
|
236
|
+
const dirs = [];
|
|
237
|
+
for (const pattern of patterns) if (pattern.endsWith("/*")) {
|
|
238
|
+
const parent = node_path.default.join(dir, pattern.slice(0, -2));
|
|
239
|
+
try {
|
|
240
|
+
for (const entry of node_fs.default.readdirSync(parent, { withFileTypes: true })) if (entry.isDirectory()) dirs.push(node_path.default.join(parent, entry.name));
|
|
241
|
+
} catch {}
|
|
242
|
+
} else if (!pattern.includes("*")) dirs.push(node_path.default.join(dir, pattern));
|
|
243
|
+
return dirs;
|
|
244
|
+
}
|
|
196
245
|
function manifestsFrom(projectRoot) {
|
|
197
246
|
const manifests = [];
|
|
198
247
|
let dir = node_path.default.resolve(projectRoot);
|
|
199
248
|
for (;;) {
|
|
200
249
|
try {
|
|
201
250
|
const raw = node_fs.default.readFileSync(node_path.default.join(dir, "package.json"), "utf8");
|
|
202
|
-
|
|
251
|
+
const manifest = JSON.parse(raw);
|
|
252
|
+
manifests.push({
|
|
253
|
+
dir,
|
|
254
|
+
manifest
|
|
255
|
+
});
|
|
256
|
+
for (const member of workspaceMemberDirs(dir, manifest)) try {
|
|
257
|
+
manifests.push({
|
|
258
|
+
dir: member,
|
|
259
|
+
manifest: JSON.parse(node_fs.default.readFileSync(node_path.default.join(member, "package.json"), "utf8"))
|
|
260
|
+
});
|
|
261
|
+
} catch {}
|
|
203
262
|
} catch {}
|
|
204
263
|
const parent = node_path.default.dirname(dir);
|
|
205
264
|
if (parent === dir) return manifests;
|
|
@@ -230,14 +289,16 @@ function manifestsFrom(projectRoot) {
|
|
|
230
289
|
* in `transform` — that option keeps its existing meaning and takes precedence.
|
|
231
290
|
*/
|
|
232
291
|
function detectEcosystemPackages(projectRoot, explicit = []) {
|
|
233
|
-
const
|
|
292
|
+
const roots = (Array.isArray(projectRoot) ? projectRoot : [projectRoot]).filter(Boolean);
|
|
234
293
|
const skip = new Set([
|
|
235
294
|
...NEVER_INLINE,
|
|
236
295
|
...Object.keys(require_preset_map.AUTO_DETECT_PRESETS),
|
|
237
296
|
...explicit
|
|
238
297
|
]);
|
|
239
298
|
const candidates = /* @__PURE__ */ new Set();
|
|
240
|
-
|
|
299
|
+
const found = roots.flatMap((root) => manifestsFrom(root));
|
|
300
|
+
const requires = [...new Set(found.map((entry) => entry.dir))].map((dir) => (0, node_module.createRequire)(node_path.default.join(dir, "package.json")));
|
|
301
|
+
for (const { manifest } of found) for (const field of [
|
|
241
302
|
"dependencies",
|
|
242
303
|
"devDependencies",
|
|
243
304
|
"optionalDependencies"
|
|
@@ -249,8 +310,9 @@ function detectEcosystemPackages(projectRoot, explicit = []) {
|
|
|
249
310
|
const detected = [];
|
|
250
311
|
for (const name of candidates) {
|
|
251
312
|
if (skip.has(name) || name.startsWith("@react-native/")) continue;
|
|
252
|
-
try {
|
|
313
|
+
for (const req of requires) try {
|
|
253
314
|
if (dependsOnReactNative(req(`${name}/package.json`))) detected.push(name);
|
|
315
|
+
break;
|
|
254
316
|
} catch {}
|
|
255
317
|
}
|
|
256
318
|
return detected.sort();
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
//#region src/errors.mjs
|
|
2
|
+
/**
|
|
3
|
+
* The error types this package throws.
|
|
4
|
+
*
|
|
5
|
+
* Plain .mjs on purpose. The shipped native and jest-compat runtimes are copied to dist
|
|
6
|
+
* verbatim and import this by relative path, and the test suite loads those same files
|
|
7
|
+
* from src — so the module has to resolve identically in both trees. A .ts source would
|
|
8
|
+
* only exist in one of them.
|
|
9
|
+
*
|
|
10
|
+
* WHAT SURVIVES WHERE, measured rather than assumed:
|
|
11
|
+
*
|
|
12
|
+
* - In the main process, and in a user's own try/catch inside a test, everything is
|
|
13
|
+
* intact.
|
|
14
|
+
* - Across the worker/reporter boundary Vitest keeps only `name`, `message` and
|
|
15
|
+
* `stack`. `code` and every other own property is dropped.
|
|
16
|
+
*
|
|
17
|
+
* So the message must stay self-sufficient: nothing may move out of it into a field on
|
|
18
|
+
* the assumption a reader will see it.
|
|
19
|
+
*
|
|
20
|
+
* `isVitestNativeError` deliberately checks SHAPE rather than `instanceof`. Bundled
|
|
21
|
+
* entries and the verbatim .mjs runtimes can hold separate copies of this module, and a
|
|
22
|
+
* prototype check would quietly fail across that seam. Shape does not care.
|
|
23
|
+
*/
|
|
24
|
+
const PREFIX = "[vitest-native]";
|
|
25
|
+
/** Guarantees the prefix exactly once, however the caller wrote the message. */
|
|
26
|
+
function withPrefix(message) {
|
|
27
|
+
return message.startsWith(PREFIX) ? message : `${PREFIX} ${message}`;
|
|
28
|
+
}
|
|
29
|
+
function buildMessage(message, options) {
|
|
30
|
+
const base = withPrefix(message);
|
|
31
|
+
return options?.docs ? `${base}\nSee ${options.docs}` : base;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Error options, omitted entirely when there is no cause.
|
|
35
|
+
*
|
|
36
|
+
* `new Error(msg, { cause: undefined })` installs an own `cause` property set to
|
|
37
|
+
* undefined, which a plain `new Error(msg)` does not — enough to make some reporters
|
|
38
|
+
* print an empty cause and to make these errors shaped differently from every other
|
|
39
|
+
* error in the process. Passing nothing keeps them identical.
|
|
40
|
+
*/
|
|
41
|
+
function errorOptions(options) {
|
|
42
|
+
return options && "cause" in options && options.cause !== void 0 ? { cause: options.cause } : void 0;
|
|
43
|
+
}
|
|
44
|
+
/** A failure originating in vitest-native. */
|
|
45
|
+
var VitestNativeError = class extends Error {
|
|
46
|
+
constructor(code, message, options) {
|
|
47
|
+
super(buildMessage(message, options), errorOptions(options));
|
|
48
|
+
this.name = "VitestNativeError";
|
|
49
|
+
this.code = code;
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
/**
|
|
53
|
+
* A vitest-native failure that is also a type error — a badly typed option, say.
|
|
54
|
+
* Extends TypeError so `instanceof TypeError` keeps working for consumers.
|
|
55
|
+
*/
|
|
56
|
+
var VitestNativeTypeError = class extends TypeError {
|
|
57
|
+
constructor(code, message, options) {
|
|
58
|
+
super(buildMessage(message, options), errorOptions(options));
|
|
59
|
+
this.name = "VitestNativeTypeError";
|
|
60
|
+
this.code = code;
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
//#endregion
|
|
64
|
+
export { VitestNativeTypeError as n, VitestNativeError as t };
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
//#region src/errors.mjs
|
|
2
|
+
/**
|
|
3
|
+
* The error types this package throws.
|
|
4
|
+
*
|
|
5
|
+
* Plain .mjs on purpose. The shipped native and jest-compat runtimes are copied to dist
|
|
6
|
+
* verbatim and import this by relative path, and the test suite loads those same files
|
|
7
|
+
* from src — so the module has to resolve identically in both trees. A .ts source would
|
|
8
|
+
* only exist in one of them.
|
|
9
|
+
*
|
|
10
|
+
* WHAT SURVIVES WHERE, measured rather than assumed:
|
|
11
|
+
*
|
|
12
|
+
* - In the main process, and in a user's own try/catch inside a test, everything is
|
|
13
|
+
* intact.
|
|
14
|
+
* - Across the worker/reporter boundary Vitest keeps only `name`, `message` and
|
|
15
|
+
* `stack`. `code` and every other own property is dropped.
|
|
16
|
+
*
|
|
17
|
+
* So the message must stay self-sufficient: nothing may move out of it into a field on
|
|
18
|
+
* the assumption a reader will see it.
|
|
19
|
+
*
|
|
20
|
+
* `isVitestNativeError` deliberately checks SHAPE rather than `instanceof`. Bundled
|
|
21
|
+
* entries and the verbatim .mjs runtimes can hold separate copies of this module, and a
|
|
22
|
+
* prototype check would quietly fail across that seam. Shape does not care.
|
|
23
|
+
*/
|
|
24
|
+
const PREFIX = "[vitest-native]";
|
|
25
|
+
/** Guarantees the prefix exactly once, however the caller wrote the message. */
|
|
26
|
+
function withPrefix(message) {
|
|
27
|
+
return message.startsWith(PREFIX) ? message : `${PREFIX} ${message}`;
|
|
28
|
+
}
|
|
29
|
+
function buildMessage(message, options) {
|
|
30
|
+
const base = withPrefix(message);
|
|
31
|
+
return options?.docs ? `${base}\nSee ${options.docs}` : base;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Error options, omitted entirely when there is no cause.
|
|
35
|
+
*
|
|
36
|
+
* `new Error(msg, { cause: undefined })` installs an own `cause` property set to
|
|
37
|
+
* undefined, which a plain `new Error(msg)` does not — enough to make some reporters
|
|
38
|
+
* print an empty cause and to make these errors shaped differently from every other
|
|
39
|
+
* error in the process. Passing nothing keeps them identical.
|
|
40
|
+
*/
|
|
41
|
+
function errorOptions(options) {
|
|
42
|
+
return options && "cause" in options && options.cause !== void 0 ? { cause: options.cause } : void 0;
|
|
43
|
+
}
|
|
44
|
+
/** A failure originating in vitest-native. */
|
|
45
|
+
var VitestNativeError = class extends Error {
|
|
46
|
+
constructor(code, message, options) {
|
|
47
|
+
super(buildMessage(message, options), errorOptions(options));
|
|
48
|
+
this.name = "VitestNativeError";
|
|
49
|
+
this.code = code;
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
/**
|
|
53
|
+
* A vitest-native failure that is also a type error — a badly typed option, say.
|
|
54
|
+
* Extends TypeError so `instanceof TypeError` keeps working for consumers.
|
|
55
|
+
*/
|
|
56
|
+
var VitestNativeTypeError = class extends TypeError {
|
|
57
|
+
constructor(code, message, options) {
|
|
58
|
+
super(buildMessage(message, options), errorOptions(options));
|
|
59
|
+
this.name = "VitestNativeTypeError";
|
|
60
|
+
this.code = code;
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
//#endregion
|
|
64
|
+
Object.defineProperty(exports, "VitestNativeError", {
|
|
65
|
+
enumerable: true,
|
|
66
|
+
get: function() {
|
|
67
|
+
return VitestNativeError;
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
Object.defineProperty(exports, "VitestNativeTypeError", {
|
|
71
|
+
enumerable: true,
|
|
72
|
+
get: function() {
|
|
73
|
+
return VitestNativeTypeError;
|
|
74
|
+
}
|
|
75
|
+
});
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Types for errors.mjs. Hand-written because the implementation is plain .mjs — see the
|
|
3
|
+
* comment there for why it cannot be TypeScript.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Stable identifiers for the failures this package raises. They are part of the public
|
|
8
|
+
* surface: renaming one is a breaking change for anyone branching on it.
|
|
9
|
+
*/
|
|
10
|
+
export type VitestNativeErrorCode =
|
|
11
|
+
| "INVALID_OPTION"
|
|
12
|
+
| "UNKNOWN_OPTION"
|
|
13
|
+
| "UNSUPPORTED_PEER"
|
|
14
|
+
| "UNSUPPORTED_POOL"
|
|
15
|
+
| "ENGINE_REQUIRES_BABEL"
|
|
16
|
+
| "MOCKS_REQUIRE_MOCK_ENGINE"
|
|
17
|
+
| "TRANSFORM_FAILED"
|
|
18
|
+
| "UNTRANSPILED_PACKAGE"
|
|
19
|
+
| "HOT_WORKER_ENV"
|
|
20
|
+
| "HOT_WORKER_PRELOAD"
|
|
21
|
+
| "HOT_RUNTIME_UNAVAILABLE"
|
|
22
|
+
| "PRESET_UNAVAILABLE"
|
|
23
|
+
| "WRONG_ENGINE_FOR_HELPER"
|
|
24
|
+
| "HELPERS_BEFORE_SETUP"
|
|
25
|
+
| "JEST_API_UNSUPPORTED"
|
|
26
|
+
| "MATCHER_BAD_RECEIVER";
|
|
27
|
+
|
|
28
|
+
export interface VitestNativeErrorOptions {
|
|
29
|
+
cause?: unknown;
|
|
30
|
+
/** A docs URL appended to the message, since fields do not reach the reporter. */
|
|
31
|
+
docs?: string;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export declare class VitestNativeError extends Error {
|
|
35
|
+
readonly code: VitestNativeErrorCode;
|
|
36
|
+
constructor(code: VitestNativeErrorCode, message: string, options?: VitestNativeErrorOptions);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export declare class VitestNativeTypeError extends TypeError {
|
|
40
|
+
readonly code: VitestNativeErrorCode;
|
|
41
|
+
constructor(code: VitestNativeErrorCode, message: string, options?: VitestNativeErrorOptions);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export declare function isVitestNativeError(
|
|
45
|
+
error: unknown,
|
|
46
|
+
): error is VitestNativeError | VitestNativeTypeError;
|
package/dist/errors.mjs
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The error types this package throws.
|
|
3
|
+
*
|
|
4
|
+
* Plain .mjs on purpose. The shipped native and jest-compat runtimes are copied to dist
|
|
5
|
+
* verbatim and import this by relative path, and the test suite loads those same files
|
|
6
|
+
* from src — so the module has to resolve identically in both trees. A .ts source would
|
|
7
|
+
* only exist in one of them.
|
|
8
|
+
*
|
|
9
|
+
* WHAT SURVIVES WHERE, measured rather than assumed:
|
|
10
|
+
*
|
|
11
|
+
* - In the main process, and in a user's own try/catch inside a test, everything is
|
|
12
|
+
* intact.
|
|
13
|
+
* - Across the worker/reporter boundary Vitest keeps only `name`, `message` and
|
|
14
|
+
* `stack`. `code` and every other own property is dropped.
|
|
15
|
+
*
|
|
16
|
+
* So the message must stay self-sufficient: nothing may move out of it into a field on
|
|
17
|
+
* the assumption a reader will see it.
|
|
18
|
+
*
|
|
19
|
+
* `isVitestNativeError` deliberately checks SHAPE rather than `instanceof`. Bundled
|
|
20
|
+
* entries and the verbatim .mjs runtimes can hold separate copies of this module, and a
|
|
21
|
+
* prototype check would quietly fail across that seam. Shape does not care.
|
|
22
|
+
*/
|
|
23
|
+
|
|
24
|
+
const PREFIX = "[vitest-native]";
|
|
25
|
+
|
|
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
|
+
|
|
31
|
+
function buildMessage(message, options) {
|
|
32
|
+
const base = withPrefix(message);
|
|
33
|
+
return options?.docs ? `${base}\nSee ${options.docs}` : base;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Error options, omitted entirely when there is no cause.
|
|
38
|
+
*
|
|
39
|
+
* `new Error(msg, { cause: undefined })` installs an own `cause` property set to
|
|
40
|
+
* undefined, which a plain `new Error(msg)` does not — enough to make some reporters
|
|
41
|
+
* print an empty cause and to make these errors shaped differently from every other
|
|
42
|
+
* error in the process. Passing nothing keeps them identical.
|
|
43
|
+
*/
|
|
44
|
+
function errorOptions(options) {
|
|
45
|
+
return options && "cause" in options && options.cause !== undefined
|
|
46
|
+
? { cause: options.cause }
|
|
47
|
+
: undefined;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/** A failure originating in vitest-native. */
|
|
51
|
+
export class VitestNativeError extends Error {
|
|
52
|
+
constructor(code, message, options) {
|
|
53
|
+
super(buildMessage(message, options), errorOptions(options));
|
|
54
|
+
this.name = "VitestNativeError";
|
|
55
|
+
this.code = code;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* A vitest-native failure that is also a type error — a badly typed option, say.
|
|
61
|
+
* Extends TypeError so `instanceof TypeError` keeps working for consumers.
|
|
62
|
+
*/
|
|
63
|
+
export class VitestNativeTypeError extends TypeError {
|
|
64
|
+
constructor(code, message, options) {
|
|
65
|
+
super(buildMessage(message, options), errorOptions(options));
|
|
66
|
+
this.name = "VitestNativeTypeError";
|
|
67
|
+
this.code = code;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/** True for any error this package raised, whichever copy of this module created it. */
|
|
72
|
+
export function isVitestNativeError(error) {
|
|
73
|
+
return (
|
|
74
|
+
error instanceof Error &&
|
|
75
|
+
typeof (/** @type {{ code?: unknown }} */ (error).code) === "string" &&
|
|
76
|
+
(error.name === "VitestNativeError" || error.name === "VitestNativeTypeError")
|
|
77
|
+
);
|
|
78
|
+
}
|
package/dist/helpers.cjs
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_errors = require("./errors-flXDIeWk.cjs");
|
|
2
3
|
//#region src/helpers.ts
|
|
3
4
|
/**
|
|
4
5
|
* Test helpers for vitest-native.
|
|
@@ -8,7 +9,7 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
|
8
9
|
*/
|
|
9
10
|
function getMock() {
|
|
10
11
|
const mock = globalThis.__vitest_native_mock;
|
|
11
|
-
if (!mock) throw new
|
|
12
|
+
if (!mock) throw new require_errors.VitestNativeError("HELPERS_BEFORE_SETUP", "helpers were called before setup ran. Ensure the vitest-native plugin is configured.");
|
|
12
13
|
return mock;
|
|
13
14
|
}
|
|
14
15
|
function getNativeControl() {
|
|
@@ -81,21 +82,10 @@ function resetAllMocks() {
|
|
|
81
82
|
mock.Platform.select.mockImplementation((specifics) => {
|
|
82
83
|
return specifics.ios ?? specifics.default;
|
|
83
84
|
});
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
height: 844,
|
|
89
|
-
scale: 3,
|
|
90
|
-
fontScale: 1
|
|
91
|
-
},
|
|
92
|
-
screen: {
|
|
93
|
-
width: 390,
|
|
94
|
-
height: 844,
|
|
95
|
-
scale: 3,
|
|
96
|
-
fontScale: 1
|
|
97
|
-
}
|
|
98
|
-
});
|
|
85
|
+
for (const value of Object.values(mock)) {
|
|
86
|
+
const candidate = value;
|
|
87
|
+
if (candidate && typeof candidate === "object" && typeof candidate._reset === "function") candidate._reset();
|
|
88
|
+
}
|
|
99
89
|
if (mock.useWindowDimensions._resetDimensions) mock.useWindowDimensions._resetDimensions({
|
|
100
90
|
width: 390,
|
|
101
91
|
height: 844,
|
|
@@ -108,15 +98,8 @@ function resetAllMocks() {
|
|
|
108
98
|
scale: 3,
|
|
109
99
|
fontScale: 1
|
|
110
100
|
});
|
|
111
|
-
if (mock.Appearance._reset) mock.Appearance._reset();
|
|
112
|
-
else mock.Appearance.setColorScheme("light");
|
|
113
101
|
if (mock.useColorScheme._resetScheme) mock.useColorScheme._resetScheme("light");
|
|
114
102
|
else if (mock.useColorScheme._setScheme) mock.useColorScheme._setScheme("light");
|
|
115
|
-
if (mock.Keyboard._reset) mock.Keyboard._reset();
|
|
116
|
-
if (mock.AppState._reset) mock.AppState._reset();
|
|
117
|
-
if (mock.BackHandler._reset) mock.BackHandler._reset();
|
|
118
|
-
if (mock.I18nManager._reset) mock.I18nManager._reset();
|
|
119
|
-
if (mock.DeviceEventEmitter._reset) mock.DeviceEventEmitter._reset();
|
|
120
103
|
if (originalNativeModules !== null) {
|
|
121
104
|
mock.NativeModules = originalNativeModules;
|
|
122
105
|
originalNativeModules = null;
|
package/dist/helpers.d.cts
CHANGED
|
@@ -1,10 +1,4 @@
|
|
|
1
1
|
//#region src/helpers.d.ts
|
|
2
|
-
/**
|
|
3
|
-
* Test helpers for vitest-native.
|
|
4
|
-
*
|
|
5
|
-
* These functions mutate the live mock instances created by the setup file.
|
|
6
|
-
* Import from 'vitest-native/helpers' in your test files.
|
|
7
|
-
*/
|
|
8
2
|
declare function setPlatform(os: "ios" | "android"): void;
|
|
9
3
|
declare function setDimensions(dims: {
|
|
10
4
|
width: number;
|
package/dist/helpers.d.mts
CHANGED
|
@@ -1,10 +1,4 @@
|
|
|
1
1
|
//#region src/helpers.d.ts
|
|
2
|
-
/**
|
|
3
|
-
* Test helpers for vitest-native.
|
|
4
|
-
*
|
|
5
|
-
* These functions mutate the live mock instances created by the setup file.
|
|
6
|
-
* Import from 'vitest-native/helpers' in your test files.
|
|
7
|
-
*/
|
|
8
2
|
declare function setPlatform(os: "ios" | "android"): void;
|
|
9
3
|
declare function setDimensions(dims: {
|
|
10
4
|
width: number;
|