vitest-native 0.10.0 → 0.11.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 +190 -0
- package/README.md +1 -0
- package/dist/cli.cjs +25 -7
- package/dist/cli.mjs +22 -4
- package/dist/{ecosystem-IuZ-Gv0R.cjs → ecosystem-BJzJU3Cf.cjs} +226 -14
- package/dist/{ecosystem-CO5vqExO.mjs → ecosystem-C4qT_vl3.mjs} +200 -12
- package/dist/helpers.cjs +1 -1
- package/dist/helpers.mjs +1 -1
- package/dist/{index-BJL4cQ-l.d.cts → index-CrMeE8rd.d.mts} +5 -5
- package/dist/{index-CvCU0cLl.d.mts → index-DIMbjH8R.d.cts} +6 -3
- package/dist/index.d.mts +1 -2
- package/dist/index.mjs +78 -48
- package/dist/jest-compat.cjs +4 -4
- package/dist/jest-compat.d.cts +0 -1
- package/dist/jest-compat.d.mts +0 -1
- package/dist/jest-compat.mjs +2 -2
- package/dist/native/hooks.mjs +77 -12
- package/dist/native/loader.mjs +10 -5
- package/dist/native/match.d.mts +33 -0
- package/dist/native/match.mjs +94 -22
- package/dist/native/registry.mjs +30 -2
- package/dist/{pool-CFND7plG.cjs → pool-BU-1ecIF.cjs} +6 -6
- package/dist/{pool-Bcxp4Qrg.mjs → pool-Bcxn9a3I.mjs} +3 -3
- package/dist/{preset-map-DxilQ4pI.cjs → preset-map-BoG19dLa.cjs} +1 -0
- package/dist/{preset-map-BpDG_D5m.mjs → preset-map-DuX0ocdn.mjs} +1 -0
- package/dist/{presets-BGTqVH6C.cjs → presets-CwO_c4aL.cjs} +131 -6
- package/dist/{presets-CK85x8ey.mjs → presets-IStcJEOa.mjs} +123 -4
- package/dist/presets.d.mts +2 -2
- package/dist/presets.mjs +2 -2
- package/dist/{chunk-CjcI7cDX.mjs → rolldown-runtime-BhDjJH2R.mjs} +1 -1
- package/dist/{chunk-CZWwpsFl.cjs → rolldown-runtime-C0BPl7ul.cjs} +1 -1
- package/dist/serializer.cjs +1 -1
- package/dist/serializer.mjs +1 -1
- package/dist/setup.d.mts +1 -1
- package/dist/setup.mjs +5 -5
- package/docs/versioning.md +1 -1
- package/package.json +17 -15
- /package/dist/{errors-flXDIeWk.cjs → errors-B3lJK46O.cjs} +0 -0
- /package/dist/{errors-Dm5yLNTF.mjs → errors-CxoBUfVJ.mjs} +0 -0
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { n as VitestNativeTypeError } from "./errors-
|
|
2
|
-
import { t as AUTO_DETECT_PRESETS } from "./preset-map-
|
|
1
|
+
import { n as VitestNativeTypeError } from "./errors-CxoBUfVJ.mjs";
|
|
2
|
+
import { t as AUTO_DETECT_PRESETS } from "./preset-map-DuX0ocdn.mjs";
|
|
3
3
|
import { createRequire } from "node:module";
|
|
4
4
|
import fs from "node:fs";
|
|
5
5
|
import path from "node:path";
|
|
@@ -125,6 +125,126 @@ const PEER_REQUIREMENTS = [
|
|
|
125
125
|
optional: true
|
|
126
126
|
}
|
|
127
127
|
];
|
|
128
|
+
//#endregion
|
|
129
|
+
//#region src/native/match.mjs
|
|
130
|
+
/**
|
|
131
|
+
* Which files belong to which package — the one place that decides it.
|
|
132
|
+
*
|
|
133
|
+
* The native engine splits the module graph between Vite and Node (the rule itself is
|
|
134
|
+
* written down in the header of apply.ts). Four places used to answer "does this file
|
|
135
|
+
* belong to a Node-owned package?" independently: the externalization patterns handed
|
|
136
|
+
* to Vitest, auto-detection, and the transform matchers in the require hook and the
|
|
137
|
+
* ESM loader. They agreed by construction rather than by structure, and three of the
|
|
138
|
+
* defects in this area were one of them disagreeing with the others — a directory
|
|
139
|
+
* anchor the transform side applied and the config side did not, a `node_modules`
|
|
140
|
+
* rule that also matched any folder sharing a package's name, and a separator
|
|
141
|
+
* mismatch that only appeared on Windows.
|
|
142
|
+
*
|
|
143
|
+
* Vitest's `server.deps.external` takes patterns rather than a predicate, so config
|
|
144
|
+
* time and run time cannot literally call the same function. They can be generated
|
|
145
|
+
* from the same rules, which is what `packagePatterns` is for: `buildPkgMatcher`
|
|
146
|
+
* tests exactly the patterns that were handed to Vitest.
|
|
147
|
+
*
|
|
148
|
+
* Everything here is pure. apply.ts bundles a copy into the plugin entry while the
|
|
149
|
+
* worker loads this file directly, so it must stay that way — module-level state
|
|
150
|
+
* would exist twice.
|
|
151
|
+
*/
|
|
152
|
+
/**
|
|
153
|
+
* React Native's own source, including the `@react-native/*` packages. Node owns
|
|
154
|
+
* these unconditionally: the Flow strip, the boundary mocks and the precompiled
|
|
155
|
+
* registry are all Node loader hooks.
|
|
156
|
+
*/
|
|
157
|
+
const REACT_NATIVE_PATH = /[\\/]node_modules[\\/](react-native|@react-native)[\\/]/;
|
|
158
|
+
/** Escape a string for literal use inside a RegExp. */
|
|
159
|
+
function escapeRe(value) {
|
|
160
|
+
return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
161
|
+
}
|
|
162
|
+
/** Forward slashes, the form Vitest presents module ids in. */
|
|
163
|
+
function toPosix(value) {
|
|
164
|
+
return value.replace(/\\/g, "/");
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
* Does `dir` contain `target` (or equal it)?
|
|
168
|
+
*
|
|
169
|
+
* Used to recognise the package the run lives in. A package directory containing the
|
|
170
|
+
* Vitest root is the project, not a dependency of it — externalizing it hands Vitest
|
|
171
|
+
* its own source and test files back through Node, where they are compiled to
|
|
172
|
+
* CommonJS.
|
|
173
|
+
*
|
|
174
|
+
* Compared case-insensitively on Windows: `require.resolve` reports the on-disk
|
|
175
|
+
* casing while a working directory carries whatever the shell supplied, and a
|
|
176
|
+
* drive-letter difference alone would silently defeat the check.
|
|
177
|
+
*/
|
|
178
|
+
function containsPath(dir, target) {
|
|
179
|
+
const normalize = (value) => {
|
|
180
|
+
const resolved = path.resolve(value);
|
|
181
|
+
return process.platform === "win32" ? resolved.toLowerCase() : resolved;
|
|
182
|
+
};
|
|
183
|
+
const outer = normalize(dir);
|
|
184
|
+
const inner = normalize(target);
|
|
185
|
+
return inner === outer || inner.startsWith(outer.endsWith(path.sep) ? outer : outer + path.sep);
|
|
186
|
+
}
|
|
187
|
+
/**
|
|
188
|
+
* The on-disk directory a package resolves to, or null.
|
|
189
|
+
*
|
|
190
|
+
* `pkg/package.json` is tried first because it names the package root exactly; some
|
|
191
|
+
* packages do not export it, so fall back to resolving the entry and walking up to
|
|
192
|
+
* the manifest that names them. Symlinked and workspace packages resolve to their
|
|
193
|
+
* real location, which is the whole point — see buildPkgMatcher.
|
|
194
|
+
*/
|
|
195
|
+
function packageDirOf(name, projectRoot) {
|
|
196
|
+
const req = createRequire(path.join(projectRoot, "package.json"));
|
|
197
|
+
try {
|
|
198
|
+
return path.dirname(req.resolve(`${name}/package.json`));
|
|
199
|
+
} catch {}
|
|
200
|
+
let dir;
|
|
201
|
+
try {
|
|
202
|
+
dir = path.dirname(req.resolve(name));
|
|
203
|
+
} catch {
|
|
204
|
+
return null;
|
|
205
|
+
}
|
|
206
|
+
for (;;) {
|
|
207
|
+
try {
|
|
208
|
+
if (createRequire(path.join(dir, "index.js"))("./package.json").name === name) return dir;
|
|
209
|
+
} catch {}
|
|
210
|
+
const parent = path.dirname(dir);
|
|
211
|
+
if (parent === dir) return null;
|
|
212
|
+
dir = parent;
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
/**
|
|
216
|
+
* The patterns identifying one package's files. THE rule; everything else composes it.
|
|
217
|
+
*
|
|
218
|
+
* A bare `[/\]name[/\]` test — what this used to be — also matches any DIRECTORY
|
|
219
|
+
* that happens to share a package's name. A project folder called `expo`, or a source
|
|
220
|
+
* directory named after the library it implements, made every file beneath it look
|
|
221
|
+
* like third-party source to be compiled. That mis-compiled unrelated files, this
|
|
222
|
+
* package's own runtime among them.
|
|
223
|
+
*
|
|
224
|
+
* Anchoring on `node_modules` alone would fix that and break linked packages: a
|
|
225
|
+
* workspace or `file:` dependency resolves to its real path, which has no
|
|
226
|
+
* `node_modules` segment at all. So a file matches if it is either
|
|
227
|
+
*
|
|
228
|
+
* - under `node_modules/<name>/` (covers additional copies of a package that a
|
|
229
|
+
* single resolution cannot see, and projects where resolution fails), or
|
|
230
|
+
* - inside the package's resolved directory (exact; covers workspace links, and
|
|
231
|
+
* stores like pnpm's and bun's).
|
|
232
|
+
*
|
|
233
|
+
* The resolved-directory anchor is dropped when that directory CONTAINS the project
|
|
234
|
+
* root, because then it is the project. Externalizing the project hands Vitest its
|
|
235
|
+
* own source and test files back through Node, which compiles them to CommonJS: a
|
|
236
|
+
* test file's `import { it } from 'vitest'` becomes `require('vitest')` and throws.
|
|
237
|
+
*
|
|
238
|
+
* `projectRoot` is optional; without it only the `node_modules` rule applies, since
|
|
239
|
+
* there is nothing to resolve against.
|
|
240
|
+
*/
|
|
241
|
+
function packagePatterns(name, projectRoot) {
|
|
242
|
+
const patterns = [new RegExp(`[\\\\/]node_modules[\\\\/]${escapeRe(name)}[\\\\/]`)];
|
|
243
|
+
if (!projectRoot) return patterns;
|
|
244
|
+
const dir = packageDirOf(name, projectRoot);
|
|
245
|
+
if (dir && !containsPath(dir, projectRoot)) patterns.push(new RegExp(`^${escapeRe(toPosix(dir).replace(/\/$/, ""))}[\\\\/]`));
|
|
246
|
+
return patterns;
|
|
247
|
+
}
|
|
128
248
|
/** Can this project run the native engine? (Both transform deps resolvable.) */
|
|
129
249
|
function isNativeCapable(projectRoot) {
|
|
130
250
|
try {
|
|
@@ -174,12 +294,18 @@ function detectEngine(requested, projectRoot, opts) {
|
|
|
174
294
|
* engine itself wires up; pulling a second copy of them into the module graph has
|
|
175
295
|
* corrupted rendering before, in ways that surface as unrelated act() and
|
|
176
296
|
* host-component failures.
|
|
297
|
+
*
|
|
298
|
+
* This list is one clause of the ownership rule; the whole of it is written down in
|
|
299
|
+
* the header of native/apply.ts, which is the file to read before changing what ends
|
|
300
|
+
* up in either graph.
|
|
177
301
|
*/
|
|
178
|
-
const NEVER_INLINE = new Set([
|
|
302
|
+
const NEVER_INLINE = /* @__PURE__ */ new Set([
|
|
179
303
|
"@testing-library/react-native",
|
|
180
304
|
"react-test-renderer",
|
|
181
305
|
"test-renderer",
|
|
182
|
-
"react-native"
|
|
306
|
+
"react-native",
|
|
307
|
+
"react",
|
|
308
|
+
"react-is"
|
|
183
309
|
]);
|
|
184
310
|
/** Manifest fields that make a package part of the React Native ecosystem. */
|
|
185
311
|
function dependsOnReactNative(manifest) {
|
|
@@ -285,9 +411,9 @@ function manifestsFrom(projectRoot) {
|
|
|
285
411
|
* test infrastructure in NEVER_INLINE, and anything the consumer listed explicitly
|
|
286
412
|
* in `transform` — that option keeps its existing meaning and takes precedence.
|
|
287
413
|
*/
|
|
288
|
-
function detectEcosystemPackages(projectRoot, explicit = []) {
|
|
414
|
+
function detectEcosystemPackages(projectRoot, explicit = [], testRoots = []) {
|
|
289
415
|
const roots = (Array.isArray(projectRoot) ? projectRoot : [projectRoot]).filter(Boolean);
|
|
290
|
-
const skip = new Set([
|
|
416
|
+
const skip = /* @__PURE__ */ new Set([
|
|
291
417
|
...NEVER_INLINE,
|
|
292
418
|
...Object.keys(AUTO_DETECT_PRESETS),
|
|
293
419
|
...explicit
|
|
@@ -304,15 +430,77 @@ function detectEcosystemPackages(projectRoot, explicit = []) {
|
|
|
304
430
|
if (deps && typeof deps === "object") for (const name of Object.keys(deps)) candidates.add(name);
|
|
305
431
|
}
|
|
306
432
|
if (candidates.size === 0) return [];
|
|
433
|
+
/** Resolve a package's manifest from whichever root can see it. */
|
|
434
|
+
const manifestOf = (name) => {
|
|
435
|
+
for (const req of requires) try {
|
|
436
|
+
return req(`${name}/package.json`);
|
|
437
|
+
} catch {}
|
|
438
|
+
return null;
|
|
439
|
+
};
|
|
440
|
+
/**
|
|
441
|
+
* The packages the run itself lives in — the project, in other words.
|
|
442
|
+
*
|
|
443
|
+
* In a workspace, the package under test is usually declared as a dependency by a
|
|
444
|
+
* sibling or by the repository root, so it appears in the candidate set like any
|
|
445
|
+
* third-party library — and it declares React Native, because it is React Native
|
|
446
|
+
* code. Detecting it would claim the project's own source: its directory becomes a
|
|
447
|
+
* `server.deps.external` pattern, so Vitest hands every file under it to Node,
|
|
448
|
+
* where the loader compiles it to CommonJS. A test file's own
|
|
449
|
+
* `import { it } from 'vitest'` becomes `require('vitest')`, which throws
|
|
450
|
+
* "Vitest cannot be imported in a CommonJS module using require()" — a failure that
|
|
451
|
+
* appears in one workspace package and not another for no visible reason.
|
|
452
|
+
*
|
|
453
|
+
* A package cannot be its own dependency, so a manifest whose directory contains a
|
|
454
|
+
* run root belongs to the project. Read straight off the manifests already walked,
|
|
455
|
+
* which is both cheaper than resolving each candidate and independent of how a
|
|
456
|
+
* package manager happens to lay out its store — under pnpm every workspace member
|
|
457
|
+
* is additionally linked into a hidden directory on NODE_PATH, so a package can
|
|
458
|
+
* resolve its own name from its own directory, but nothing here depends on that.
|
|
459
|
+
*
|
|
460
|
+
* Workspace libraries the project merely depends on sit beside a run root rather
|
|
461
|
+
* than above it and are unaffected — detecting those is the point of the
|
|
462
|
+
* workspace-member walk above.
|
|
463
|
+
*/
|
|
464
|
+
const ownerRoots = [...roots, ...testRoots];
|
|
465
|
+
const runOwners = new Set(found.filter(({ dir }) => ownerRoots.some((root) => containsPath(dir, root))).map(({ manifest }) => manifest.name).filter((name) => typeof name === "string"));
|
|
466
|
+
const ownsTheRun = (name) => runOwners.has(name);
|
|
307
467
|
const detected = [];
|
|
308
468
|
for (const name of candidates) {
|
|
309
469
|
if (skip.has(name) || name.startsWith("@react-native/")) continue;
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
470
|
+
const pkg = manifestOf(name);
|
|
471
|
+
if (pkg && dependsOnReactNative(pkg) && !ownsTheRun(name)) detected.push(name);
|
|
472
|
+
}
|
|
473
|
+
const rnOwned = new Set(Object.keys(manifestOf("react-native")?.dependencies ?? {}));
|
|
474
|
+
/** Every package reachable from `roots` through runtime dependencies. */
|
|
475
|
+
const closureOf = (starts) => {
|
|
476
|
+
const seen = /* @__PURE__ */ new Set();
|
|
477
|
+
const pending = [...starts];
|
|
478
|
+
while (pending.length > 0) {
|
|
479
|
+
const name = pending.pop();
|
|
480
|
+
if (seen.has(name)) continue;
|
|
481
|
+
seen.add(name);
|
|
482
|
+
const deps = manifestOf(name)?.dependencies;
|
|
483
|
+
if (deps && typeof deps === "object") pending.push(...Object.keys(deps));
|
|
484
|
+
}
|
|
485
|
+
return seen;
|
|
486
|
+
};
|
|
487
|
+
const toolchain = closureOf(["@babel/core", "@react-native/babel-preset"]);
|
|
488
|
+
const inClosure = new Set(detected);
|
|
489
|
+
const queue = [...detected];
|
|
490
|
+
while (queue.length > 0) {
|
|
491
|
+
const deps = manifestOf(queue.pop())?.dependencies;
|
|
492
|
+
if (!deps || typeof deps !== "object") continue;
|
|
493
|
+
for (const dep of Object.keys(deps)) {
|
|
494
|
+
if (inClosure.has(dep) || skip.has(dep) || dep.startsWith("@react-native/")) continue;
|
|
495
|
+
if (rnOwned.has(dep)) continue;
|
|
496
|
+
if (toolchain.has(dep)) continue;
|
|
497
|
+
if (ownsTheRun(dep)) continue;
|
|
498
|
+
if (!manifestOf(dep)) continue;
|
|
499
|
+
inClosure.add(dep);
|
|
500
|
+
queue.push(dep);
|
|
501
|
+
}
|
|
314
502
|
}
|
|
315
|
-
return
|
|
503
|
+
return [...inClosure].sort();
|
|
316
504
|
}
|
|
317
505
|
//#endregion
|
|
318
|
-
export {
|
|
506
|
+
export { packageDirOf as a, validateOptions as c, containsPath as i, validatePeerDependency as l, detectEngine as n, packagePatterns as o, REACT_NATIVE_PATH as r, PEER_REQUIREMENTS as s, detectEcosystemPackages as t, warnUnknownOptions as u };
|
package/dist/helpers.cjs
CHANGED
package/dist/helpers.mjs
CHANGED
|
@@ -1,7 +1,4 @@
|
|
|
1
1
|
import { Mock } from "vitest";
|
|
2
|
-
|
|
3
|
-
//#region \0rolldown/runtime.js
|
|
4
|
-
//#endregion
|
|
5
2
|
//#region src/types.d.ts
|
|
6
3
|
/** Static methods available on the Image component mock. */
|
|
7
4
|
interface ImageStatic {
|
|
@@ -354,6 +351,9 @@ declare function deviceInfo(): Preset;
|
|
|
354
351
|
//#region src/presets/mmkv.d.ts
|
|
355
352
|
declare function mmkv(): Preset;
|
|
356
353
|
//#endregion
|
|
354
|
+
//#region src/presets/netinfo.d.ts
|
|
355
|
+
declare function netInfo(): Preset;
|
|
356
|
+
//#endregion
|
|
357
357
|
//#region src/presets/svg.d.ts
|
|
358
358
|
declare function svg(): Preset;
|
|
359
359
|
//#endregion
|
|
@@ -375,7 +375,7 @@ declare function keyboardController(): Preset;
|
|
|
375
375
|
//#region src/presets/worklets.d.ts
|
|
376
376
|
declare function worklets(): Preset;
|
|
377
377
|
declare namespace index_d_exports {
|
|
378
|
-
export { asyncStorage, bottomSheet, deviceInfo, expo, flashList, gestureHandler, keyboardController, mmkv, navigation, reanimated, safeAreaContext, screens, svg, vectorIcons, webview, worklets };
|
|
378
|
+
export { asyncStorage, bottomSheet, deviceInfo, expo, flashList, gestureHandler, keyboardController, mmkv, navigation, netInfo, reanimated, safeAreaContext, screens, svg, vectorIcons, webview, worklets };
|
|
379
379
|
}
|
|
380
380
|
//#endregion
|
|
381
|
-
export {
|
|
381
|
+
export { gestureHandler as _, flashList as a, ReactNativeMock as b, svg as c, deviceInfo as d, expo as f, safeAreaContext as g, navigation as h, bottomSheet as i, netInfo as l, asyncStorage as m, worklets as n, vectorIcons as o, screens as p, keyboardController as r, webview as s, index_d_exports as t, mmkv as u, reanimated as v, VitestNativeOptions as x, Preset as y };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Mock } from "vitest";
|
|
2
|
-
|
|
2
|
+
//#endregion
|
|
3
3
|
//#region src/types.d.ts
|
|
4
4
|
/** Static methods available on the Image component mock. */
|
|
5
5
|
interface ImageStatic {
|
|
@@ -352,6 +352,9 @@ declare function deviceInfo(): Preset;
|
|
|
352
352
|
//#region src/presets/mmkv.d.ts
|
|
353
353
|
declare function mmkv(): Preset;
|
|
354
354
|
//#endregion
|
|
355
|
+
//#region src/presets/netinfo.d.ts
|
|
356
|
+
declare function netInfo(): Preset;
|
|
357
|
+
//#endregion
|
|
355
358
|
//#region src/presets/svg.d.ts
|
|
356
359
|
declare function svg(): Preset;
|
|
357
360
|
//#endregion
|
|
@@ -373,7 +376,7 @@ declare function keyboardController(): Preset;
|
|
|
373
376
|
//#region src/presets/worklets.d.ts
|
|
374
377
|
declare function worklets(): Preset;
|
|
375
378
|
declare namespace index_d_exports {
|
|
376
|
-
export { asyncStorage, bottomSheet, deviceInfo, expo, flashList, gestureHandler, keyboardController, mmkv, navigation, reanimated, safeAreaContext, screens, svg, vectorIcons, webview, worklets };
|
|
379
|
+
export { asyncStorage, bottomSheet, deviceInfo, expo, flashList, gestureHandler, keyboardController, mmkv, navigation, netInfo, reanimated, safeAreaContext, screens, svg, vectorIcons, webview, worklets };
|
|
377
380
|
}
|
|
378
381
|
//#endregion
|
|
379
|
-
export {
|
|
382
|
+
export { gestureHandler as _, flashList as a, ReactNativeMock as b, svg as c, deviceInfo as d, expo as f, safeAreaContext as g, navigation as h, bottomSheet as i, netInfo as l, asyncStorage as m, worklets as n, vectorIcons as o, screens as p, keyboardController as r, webview as s, index_d_exports as t, mmkv as u, reanimated as v, VitestNativeOptions as x, Preset as y };
|
package/dist/index.d.mts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import { b as
|
|
1
|
+
import { b as ReactNativeMock, t as index_d_exports, x as VitestNativeOptions, y as Preset } from "./index-CrMeE8rd.mjs";
|
|
2
2
|
import { Plugin } from "vite";
|
|
3
|
-
|
|
4
3
|
//#region src/plugin.d.ts
|
|
5
4
|
/**
|
|
6
5
|
* Preset names switched off by the object form of the `presets` option.
|
package/dist/index.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { t as VitestNativeError } from "./errors-
|
|
2
|
-
import { a as
|
|
3
|
-
import { t as AUTO_DETECT_PRESETS } from "./preset-map-
|
|
4
|
-
import { t as presets_exports } from "./presets-
|
|
1
|
+
import { t as VitestNativeError } from "./errors-CxoBUfVJ.mjs";
|
|
2
|
+
import { a as packageDirOf, c as validateOptions, i as containsPath, l as validatePeerDependency, n as detectEngine, o as packagePatterns, r as REACT_NATIVE_PATH, s as PEER_REQUIREMENTS, t as detectEcosystemPackages, u as warnUnknownOptions } from "./ecosystem-C4qT_vl3.mjs";
|
|
3
|
+
import { t as AUTO_DETECT_PRESETS } from "./preset-map-DuX0ocdn.mjs";
|
|
4
|
+
import { t as presets_exports } from "./presets-IStcJEOa.mjs";
|
|
5
5
|
import { createRequire } from "node:module";
|
|
6
6
|
import fs from "node:fs";
|
|
7
7
|
import path from "node:path";
|
|
@@ -55,41 +55,19 @@ function getPlatformExtensions(platform) {
|
|
|
55
55
|
//#endregion
|
|
56
56
|
//#region src/native/apply.ts
|
|
57
57
|
/**
|
|
58
|
-
*
|
|
59
|
-
*
|
|
60
|
-
*
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
return s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
65
|
-
}
|
|
66
|
-
/**
|
|
67
|
-
* The on-disk directory a package resolves to, or null. Used alongside the
|
|
68
|
-
* node_modules-anchored patterns so workspace and `file:` dependencies — which
|
|
69
|
-
* resolve to a real path with no node_modules segment — are matched too.
|
|
58
|
+
* Files outside any installed package that Vitest may be running as an ENTRY rather
|
|
59
|
+
* than importing as a module: the two naming conventions test runners use.
|
|
60
|
+
*
|
|
61
|
+
* Neither is exhaustive — a project can point `test.include` anywhere — but a file
|
|
62
|
+
* that matches one of these is a test by convention and never library source, which
|
|
63
|
+
* is what makes it safe to keep out of Node's graph unconditionally.
|
|
70
64
|
*/
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
function nativeEngineConfig(setupFilePath, env, extensions, transformPkgs = [], hot, jsxTransform = { esbuild: { jsx: "automatic" } }, userPool, inlinePkgs = [], projectRoot = process.cwd()) {
|
|
80
|
-
const extraExternal = transformPkgs.flatMap((p) => {
|
|
81
|
-
const patterns = [new RegExp(`[\\\\/]node_modules[\\\\/]${escapeRe(p)}[\\\\/]`)];
|
|
82
|
-
const dir = resolvePackageDir(p, projectRoot);
|
|
83
|
-
if (dir) patterns.push(new RegExp(`^${escapeRe(dir.replace(/\\/g, "/"))}[\\\\/]`));
|
|
84
|
-
return patterns;
|
|
85
|
-
});
|
|
86
|
-
const ecosystemExternal = inlinePkgs.flatMap((p) => {
|
|
87
|
-
const patterns = [new RegExp(`[\\\\/]node_modules[\\\\/]${escapeRe(p)}[\\\\/]`)];
|
|
88
|
-
const dir = resolvePackageDir(p, projectRoot);
|
|
89
|
-
if (dir) patterns.push(new RegExp(`^${escapeRe(dir.replace(/\\/g, "/"))}[\\\\/]`));
|
|
90
|
-
return patterns;
|
|
91
|
-
});
|
|
92
|
-
const nodeTransformed = [...new Set([...transformPkgs, ...inlinePkgs])];
|
|
65
|
+
const OUTSIDE_NODE_MODULES = String.raw`^(?!.*[\\/]node_modules[\\/])`;
|
|
66
|
+
const TEST_ENTRY_PATTERNS = [new RegExp(String.raw`${OUTSIDE_NODE_MODULES}.*\.(?:test|spec)\.[cm]?[jt]sx?$`), new RegExp(String.raw`${OUTSIDE_NODE_MODULES}.*[\\/]__tests__[\\/].*\.[cm]?[jt]sx?$`)];
|
|
67
|
+
function nativeEngineConfig(setupFilePath, env, extensions, transformPkgs = [], hot, jsxTransform = { esbuild: { jsx: "automatic" } }, userPool, inlinePkgs = [], projectRoot = process.cwd(), userInlinesEverything = false) {
|
|
68
|
+
const extraExternal = transformPkgs.flatMap((p) => packagePatterns(p, projectRoot));
|
|
69
|
+
const ecosystemExternal = inlinePkgs.flatMap((p) => packagePatterns(p, projectRoot));
|
|
70
|
+
const nodeTransformed = [.../* @__PURE__ */ new Set([...transformPkgs, ...inlinePkgs])];
|
|
93
71
|
const fullEnv = { ...env };
|
|
94
72
|
if (nodeTransformed.length > 0) fullEnv.VITEST_NATIVE_TRANSFORM = JSON.stringify(nodeTransformed);
|
|
95
73
|
return {
|
|
@@ -127,12 +105,14 @@ function nativeEngineConfig(setupFilePath, env, extensions, transformPkgs = [],
|
|
|
127
105
|
isolate: false,
|
|
128
106
|
runner: hot.runnerPath
|
|
129
107
|
} : { pool: userPool ?? "threads" },
|
|
130
|
-
server: { deps: {
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
108
|
+
server: { deps: {
|
|
109
|
+
...userInlinesEverything ? {} : { inline: TEST_ENTRY_PATTERNS },
|
|
110
|
+
external: [
|
|
111
|
+
REACT_NATIVE_PATH,
|
|
112
|
+
...extraExternal,
|
|
113
|
+
...ecosystemExternal
|
|
114
|
+
]
|
|
115
|
+
} }
|
|
136
116
|
}
|
|
137
117
|
};
|
|
138
118
|
}
|
|
@@ -188,6 +168,51 @@ async function autoDetectPresets(diagnostics, projectRoot) {
|
|
|
188
168
|
}
|
|
189
169
|
return detected;
|
|
190
170
|
}
|
|
171
|
+
/**
|
|
172
|
+
* The directories a set of `test.include` globs point into, resolved against the run
|
|
173
|
+
* root — the literal part of each pattern, up to its first wildcard.
|
|
174
|
+
*
|
|
175
|
+
* `packages/ui/src/**\/*.test.ts` names `packages/ui/src`, which is enough to know
|
|
176
|
+
* the run's tests live in that package. `**\/*.test.ts` names nothing above the root
|
|
177
|
+
* and is dropped: treating it as a hint would mark every workspace member as the
|
|
178
|
+
* project and undo their detection entirely.
|
|
179
|
+
*/
|
|
180
|
+
function testIncludeRoots(include, projectRoot) {
|
|
181
|
+
if (!Array.isArray(include)) return [];
|
|
182
|
+
const dirs = /* @__PURE__ */ new Set();
|
|
183
|
+
for (const pattern of include) {
|
|
184
|
+
if (typeof pattern !== "string" || pattern.startsWith("!")) continue;
|
|
185
|
+
const literal = pattern.slice(0, firstWildcard(pattern));
|
|
186
|
+
const slash = literal.replace(/\\/g, "/").lastIndexOf("/");
|
|
187
|
+
if (slash <= 0) continue;
|
|
188
|
+
dirs.add(path.resolve(projectRoot, literal.slice(0, slash)));
|
|
189
|
+
}
|
|
190
|
+
return [...dirs];
|
|
191
|
+
}
|
|
192
|
+
/**
|
|
193
|
+
* Where a glob stops being a literal path.
|
|
194
|
+
*
|
|
195
|
+
* `!`, `+` and `@` only introduce a pattern as part of an extglob — `@(a|b)` — and
|
|
196
|
+
* are ordinary characters otherwise. Treating them as wildcards on their own cut
|
|
197
|
+
* `packages/@scope/ui/**\/*.test.ts` down to `packages/`, which would have named the
|
|
198
|
+
* whole workspace as the project and switched detection off for every member of it.
|
|
199
|
+
*/
|
|
200
|
+
function firstWildcard(pattern) {
|
|
201
|
+
const plain = pattern.search(/[*?[{]/);
|
|
202
|
+
const extglob = pattern.search(/[!+@]\(/);
|
|
203
|
+
if (plain === -1) return extglob === -1 ? pattern.length : extglob;
|
|
204
|
+
return extglob === -1 ? plain : Math.min(plain, extglob);
|
|
205
|
+
}
|
|
206
|
+
/** The nearest directory at or above `from` holding a package.json, or null. */
|
|
207
|
+
function nearestPackageDir(from) {
|
|
208
|
+
let dir = path.resolve(from);
|
|
209
|
+
for (;;) {
|
|
210
|
+
if (fs.existsSync(path.join(dir, "package.json"))) return dir;
|
|
211
|
+
const parent = path.dirname(dir);
|
|
212
|
+
if (parent === dir) return null;
|
|
213
|
+
dir = parent;
|
|
214
|
+
}
|
|
215
|
+
}
|
|
191
216
|
function resolvePackageVersion(packageName, projectRoot) {
|
|
192
217
|
const req = createRequire(path.join(projectRoot, "package.json"));
|
|
193
218
|
try {
|
|
@@ -487,7 +512,7 @@ function subpathLeafOf(specifier) {
|
|
|
487
512
|
* be shadowed (test utilities and tooling entry points). Mirrors
|
|
488
513
|
* native/match.mjs.
|
|
489
514
|
*/
|
|
490
|
-
const UTILITY_SUBPATH_LEAVES = new Set([
|
|
515
|
+
const UTILITY_SUBPATH_LEAVES = /* @__PURE__ */ new Set([
|
|
491
516
|
"jest-utils",
|
|
492
517
|
"jestSetup",
|
|
493
518
|
"mock",
|
|
@@ -702,7 +727,11 @@ function reactNative(options) {
|
|
|
702
727
|
for (const p of options.presets) if (p.config && Object.keys(p.config).length > 0) presetConfig[p.name] = p.config;
|
|
703
728
|
if (Object.keys(presetConfig).length > 0) env.VITEST_NATIVE_PRESET_CONFIG = JSON.stringify(presetConfig);
|
|
704
729
|
}
|
|
705
|
-
const
|
|
730
|
+
const includeRoots = testIncludeRoots(userConfig.test?.include, resolvedRoot);
|
|
731
|
+
const ecosystem = detectEcosystemPackages([resolvedRoot, ...includeRoots], transformPkgs, includeRoots);
|
|
732
|
+
const linkedDetectedDirs = ecosystem.map((name) => packageDirOf(name, resolvedRoot)).filter((dir) => dir !== null && !/[\\/]node_modules[\\/]/.test(dir));
|
|
733
|
+
const projectDirs = [...new Set([resolvedRoot, ...includeRoots].map((dir) => nearestPackageDir(dir)).filter((dir) => dir !== null))].filter((dir) => !linkedDetectedDirs.some((detected) => containsPath(dir, detected)));
|
|
734
|
+
if (projectDirs.length > 0) env.VITEST_NATIVE_PROJECT_DIRS = JSON.stringify(projectDirs);
|
|
706
735
|
if (ecosystem.length > 0) {
|
|
707
736
|
ecosystemRoot = resolvedRoot;
|
|
708
737
|
ecosystemPattern = new RegExp(`[\\\\/]node_modules[\\\\/](?:${ecosystem.map((p) => p.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")).join("|")})[\\\\/]`);
|
|
@@ -718,7 +747,7 @@ function reactNative(options) {
|
|
|
718
747
|
if (registryFile) env.VITEST_NATIVE_RN_REGISTRY = registryFile;
|
|
719
748
|
let hot;
|
|
720
749
|
if (hotRuntime) {
|
|
721
|
-
const { nativePool, defaultHotMemoryLimit } = await import("./pool-
|
|
750
|
+
const { nativePool, defaultHotMemoryLimit } = await import("./pool-Bcxn9a3I.mjs");
|
|
722
751
|
const memoryLimit = hotRecycle.memoryLimit ?? (hotRecycle.recycleAfterFiles == null ? defaultHotMemoryLimit() : void 0);
|
|
723
752
|
hot = {
|
|
724
753
|
pool: nativePool({
|
|
@@ -732,9 +761,10 @@ function reactNative(options) {
|
|
|
732
761
|
};
|
|
733
762
|
}
|
|
734
763
|
const userPool = userConfig.test?.pool;
|
|
764
|
+
const userInlinesEverything = userConfig.test?.server?.deps?.inline === true;
|
|
735
765
|
if (userPool === "vmThreads" || userPool === "vmForks") throw new VitestNativeError("UNSUPPORTED_POOL", `engine:'native' cannot run on the '${userPool}' pool. React Native is loaded through Node's module hooks, which a VM pool's context does not use — React Native fails to resolve its platform files there. Use 'threads' (the default) or 'forks', or switch to engine:'mock', which needs no hooks.`);
|
|
736
766
|
if (hot && userPool) console.warn(`[vitest-native] 'hotRuntime' supplies its own pool, overriding the configured pool '${typeof userPool === "string" ? userPool : "(custom)"}'.`);
|
|
737
|
-
return asCompatibleViteConfig(nativeEngineConfig(nativeSetupPath, env, extensions, transformPkgs, hot, jsxTransform, userPool, ecosystem, resolvedRoot));
|
|
767
|
+
return asCompatibleViteConfig(nativeEngineConfig(nativeSetupPath, env, extensions, transformPkgs, hot, jsxTransform, userPool, ecosystem, resolvedRoot, userInlinesEverything));
|
|
738
768
|
}
|
|
739
769
|
if (hotRuntime) console.warn(`[vitest-native] 'hotRuntime' only applies to engine:'native' (resolved engine: '${engine}'); ignoring.`);
|
|
740
770
|
if (options?.mocks && Object.keys(options.mocks).length > 0) env.VITEST_NATIVE_MOCKS = JSON.stringify(options.mocks);
|
package/dist/jest-compat.cjs
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const
|
|
2
|
+
const require_rolldown_runtime = require("./rolldown-runtime-C0BPl7ul.cjs");
|
|
3
3
|
let magic_string = require("magic-string");
|
|
4
|
-
magic_string =
|
|
4
|
+
magic_string = require_rolldown_runtime.__toESM(magic_string, 1);
|
|
5
5
|
//#region src/jest-compat/transform.ts
|
|
6
|
-
const HOISTABLE = new Set([
|
|
6
|
+
const HOISTABLE = /* @__PURE__ */ new Set([
|
|
7
7
|
"mock",
|
|
8
8
|
"unmock",
|
|
9
9
|
"doMock",
|
|
10
10
|
"doUnmock"
|
|
11
11
|
]);
|
|
12
|
-
const WITH_FACTORY = new Set(["mock", "doMock"]);
|
|
12
|
+
const WITH_FACTORY = /* @__PURE__ */ new Set(["mock", "doMock"]);
|
|
13
13
|
const TRANSFORMABLE = /\.(?:[cm]?[jt]sx?)$/;
|
|
14
14
|
const HAS_JEST_MOCK = /\bjest\s*\.\s*(?:mock|unmock|doMock|doUnmock)\s*\(/;
|
|
15
15
|
/** Visit every node in an ESTree AST (depth-first), calling `fn` on each. */
|
package/dist/jest-compat.d.cts
CHANGED
package/dist/jest-compat.d.mts
CHANGED
package/dist/jest-compat.mjs
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import MagicString from "magic-string";
|
|
2
2
|
//#region src/jest-compat/transform.ts
|
|
3
|
-
const HOISTABLE = new Set([
|
|
3
|
+
const HOISTABLE = /* @__PURE__ */ new Set([
|
|
4
4
|
"mock",
|
|
5
5
|
"unmock",
|
|
6
6
|
"doMock",
|
|
7
7
|
"doUnmock"
|
|
8
8
|
]);
|
|
9
|
-
const WITH_FACTORY = new Set(["mock", "doMock"]);
|
|
9
|
+
const WITH_FACTORY = /* @__PURE__ */ new Set(["mock", "doMock"]);
|
|
10
10
|
const TRANSFORMABLE = /\.(?:[cm]?[jt]sx?)$/;
|
|
11
11
|
const HAS_JEST_MOCK = /\bjest\s*\.\s*(?:mock|unmock|doMock|doUnmock)\s*\(/;
|
|
12
12
|
/** Visit every node in an ESTree AST (depth-first), calling `fn` on each. */
|