vitest 4.1.5 → 5.0.0-beta.2
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/LICENSE.md +7 -0
- package/dist/browser.d.ts +9 -9
- package/dist/browser.js +4 -4
- package/dist/chunks/{base.RR7zL1h0.js → base.Opc_YHkk.js} +10 -11
- package/dist/chunks/browser.d.BUhkKcDl.d.ts +899 -0
- package/dist/chunks/{cac.DJJmV0dT.js → cac.8N4bOkkB.js} +23 -11
- package/dist/chunks/{cli-api.Cjt90eJu.js → cli-api.B0RFke2g.js} +5799 -353
- package/dist/chunks/{config.d.A1h_Y6Jt.d.ts → config.d.D91DHYaD.d.ts} +11 -3
- package/dist/chunks/{console.3WNpx0tS.js → console.B3IRP8fX.js} +3 -1
- package/dist/chunks/{constants.CPYnjOGj.js → constants.-juJ8b_4.js} +1 -1
- package/dist/chunks/{coverage.d.BZtK59WP.d.ts → coverage.d.g2xbl2sP.d.ts} +4 -0
- package/dist/chunks/{creator.DgVhQm5q.js → creator.BqL2U_x4.js} +1 -1
- package/dist/chunks/{defaults.9aQKnqFk.js → defaults.szbHWQun.js} +4 -2
- package/dist/chunks/environment.d-DOJxxZV9.d.DOJxxZV9.d.ts +17 -0
- package/dist/chunks/general.d.DFAHgpC2.d.ts +247 -0
- package/dist/chunks/{global.d.DVsSRdQ5.d.ts → global.d.DhbKSQoV.d.ts} +4 -5
- package/dist/chunks/{globals.Dj1TGiMC.js → globals.EHmmu0nC.js} +15 -14
- package/dist/chunks/{index.DXx9Dtk7.js → index.CViWo__T.js} +5 -5
- package/dist/chunks/{startVitestModuleRunner.bRl2_oI_.js → index.CbgUM9E5.js} +731 -5
- package/dist/chunks/{test.DNmyFkvJ.js → index.D_7-4CaB.js} +2659 -14
- package/dist/chunks/{init-forks.UV3ZQGQH.js → init-forks.DMge3WTt.js} +1 -1
- package/dist/chunks/{init-threads.D3eCsY76.js → init-threads.eIoyCTon.js} +1 -1
- package/dist/chunks/{init.D98-gwRW.js → init.BVd7SaCA.js} +3 -5
- package/dist/chunks/{nativeModuleMocker.BRN2oBJd.js → nativeModuleMocker.DKpFw0pk.js} +3 -2
- package/dist/chunks/{index.BCY_7LL2.js → nativeModuleRunner.BOeMnHl4.js} +43 -12
- package/dist/chunks/node.CwFbQqI1.js +47 -0
- package/dist/chunks/{reporters.d.CEnv6XRv.d.ts → plugin.d.cIKZEZ16.d.ts} +306 -19
- package/dist/chunks/plugins.DrsmdUE2.js +37 -0
- package/dist/chunks/{rpc.MzXet3jl.js → rpc.DFRWVnRh.js} +16 -1
- package/dist/chunks/{rpc.d.B_8sPU0w.d.ts → rpc.d.7JZuxZ8u.d.ts} +19 -3
- package/dist/chunks/{setup-common.DYx3LtFI.js → setup-common.Hpq30zVk.js} +7 -3
- package/dist/chunks/{utils.BS4fH3nR.js → utils.DKODp04v.js} +3 -4
- package/dist/chunks/{vm.DVLYObm9.js → vm.2okbRRME.js} +6 -6
- package/dist/chunks/{worker.d.ZpHpO4yb.d.ts → worker.d.Bu1kXGw4.d.ts} +3 -3
- package/dist/cli.js +2 -2
- package/dist/config.cjs +4 -2
- package/dist/config.d.ts +21 -18
- package/dist/config.js +2 -2
- package/dist/index.d.ts +84 -22
- package/dist/index.js +15 -13
- package/dist/module-evaluator.d.ts +5 -3
- package/dist/module-evaluator.js +1 -1
- package/dist/node.d.ts +114 -19
- package/dist/node.js +21 -26
- package/dist/runtime.d.ts +40 -4
- package/dist/runtime.js +5 -6
- package/dist/{chunks/traces.DT5aQ62U.js → traces.js} +1 -1
- package/dist/worker.d.ts +5 -5
- package/dist/worker.js +21 -23
- package/dist/workers/forks.js +21 -23
- package/dist/workers/runVmTests.js +17 -16
- package/dist/workers/threads.js +21 -23
- package/dist/workers/vmForks.js +7 -9
- package/dist/workers/vmThreads.js +7 -9
- package/package.json +21 -38
- package/dist/chunks/benchmark.CX_oY03V.js +0 -40
- package/dist/chunks/benchmark.d.DAaHLpsq.d.ts +0 -24
- package/dist/chunks/browser.d.BcoexmFG.d.ts +0 -62
- package/dist/chunks/coverage.DM_a_rWm.js +0 -1087
- package/dist/chunks/evaluatedModules.Dg1zASAC.js +0 -17
- package/dist/chunks/index.DC7d2Pf8.js +0 -729
- package/dist/chunks/index.DdgEv5B1.js +0 -42
- package/dist/chunks/index.UpGiHP7g.js +0 -4255
- package/dist/chunks/nativeModuleRunner.BIakptoF.js +0 -36
- package/dist/chunks/node.COQbm6gK.js +0 -14
- package/dist/chunks/plugin.d.BM2TCi12.d.ts +0 -38
- package/dist/chunks/suite.d.udJtyAgw.d.ts +0 -10
- package/dist/chunks/traces.d.D2T_R8rx.d.ts +0 -60
- package/dist/coverage.d.ts +0 -123
- package/dist/coverage.js +0 -27
- package/dist/environments.d.ts +0 -22
- package/dist/environments.js +0 -5
- package/dist/reporters.d.ts +0 -27
- package/dist/reporters.js +0 -26
- package/dist/runners.d.ts +0 -70
- package/dist/runners.js +0 -19
- package/dist/snapshot.d.ts +0 -9
- package/dist/snapshot.js +0 -6
- package/dist/suite.d.ts +0 -5
- package/dist/suite.js +0 -8
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { isMainThread, parentPort } from 'node:worker_threads';
|
|
2
|
-
import { i as init } from './init.
|
|
2
|
+
import { i as init } from './init.BVd7SaCA.js';
|
|
3
3
|
|
|
4
4
|
if (isMainThread || !parentPort) throw new Error("Expected worker to be run in node:worker_threads");
|
|
5
5
|
function workerInit(options) {
|
|
@@ -3,16 +3,14 @@ import { isBuiltin } from 'node:module';
|
|
|
3
3
|
import { pathToFileURL } from 'node:url';
|
|
4
4
|
import { resolve } from 'pathe';
|
|
5
5
|
import { ModuleRunner, EvaluatedModules } from 'vite/module-runner';
|
|
6
|
-
import { b as VitestTransport } from './
|
|
7
|
-
import { e as environments } from './index.DC7d2Pf8.js';
|
|
6
|
+
import { e as environments, b as VitestTransport } from './index.CbgUM9E5.js';
|
|
8
7
|
import { serializeValue } from '@vitest/utils/serialize';
|
|
9
8
|
import { serializeError } from '@vitest/utils/error';
|
|
10
9
|
import { disableDefaultColors } from 'tinyrainbow';
|
|
11
|
-
import {
|
|
12
|
-
import { o as onCancel, a as rpcDone, c as createRuntimeRpc } from './rpc.
|
|
10
|
+
import { Traces } from '../traces.js';
|
|
11
|
+
import { o as onCancel, V as VitestEvaluatedModules, a as rpcDone, c as createRuntimeRpc } from './rpc.DFRWVnRh.js';
|
|
13
12
|
import { createStackString, parseStacktrace } from '@vitest/utils/source-map';
|
|
14
13
|
import { s as setupInspect } from './inspector.CvyFGlXm.js';
|
|
15
|
-
import { V as VitestEvaluatedModules } from './evaluatedModules.Dg1zASAC.js';
|
|
16
14
|
import { E as EnvironmentTeardownError } from './utils.BX5Fg8C4.js';
|
|
17
15
|
|
|
18
16
|
function isBuiltinEnvironment(env) {
|
|
@@ -5,7 +5,7 @@ import { cleanUrl, createDefer } from '@vitest/utils/helpers';
|
|
|
5
5
|
import { p as parse } from './acorn.B2iPLyUM.js';
|
|
6
6
|
import { isAbsolute } from 'pathe';
|
|
7
7
|
import { t as toBuiltin } from './modules.BJuCwlRJ.js';
|
|
8
|
-
import { B as BareModuleMocker, n as normalizeModuleId } from './
|
|
8
|
+
import { B as BareModuleMocker, n as normalizeModuleId } from './index.CbgUM9E5.js';
|
|
9
9
|
import 'node:fs';
|
|
10
10
|
import './utils.BX5Fg8C4.js';
|
|
11
11
|
import '@vitest/utils/timers';
|
|
@@ -14,9 +14,10 @@ import 'node:path';
|
|
|
14
14
|
import '../module-evaluator.js';
|
|
15
15
|
import 'node:vm';
|
|
16
16
|
import 'vite/module-runner';
|
|
17
|
-
import '
|
|
17
|
+
import '../traces.js';
|
|
18
18
|
import '@vitest/mocker';
|
|
19
19
|
import '@vitest/mocker/redirect';
|
|
20
|
+
import 'node:console';
|
|
20
21
|
|
|
21
22
|
class NativeModuleMocker extends BareModuleMocker {
|
|
22
23
|
wrapDynamicImport(moduleFactory) {
|
|
@@ -1,13 +1,14 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { fileURLToPath as fileURLToPath$1, pathToFileURL as pathToFileURL$1, URL as URL$1 } from 'node:url';
|
|
2
|
+
import fs__default, { statSync, realpathSync } from 'node:fs';
|
|
2
3
|
import { builtinModules, createRequire } from 'node:module';
|
|
3
4
|
import path, { win32, dirname, join } from 'node:path';
|
|
4
5
|
import process$1 from 'node:process';
|
|
5
|
-
import fs
|
|
6
|
-
import {
|
|
7
|
-
import { isAbsolute } from 'pathe';
|
|
6
|
+
import fs from 'node:fs/promises';
|
|
7
|
+
import { isAbsolute, resolve } from 'pathe';
|
|
8
8
|
import assert from 'node:assert';
|
|
9
9
|
import v8 from 'node:v8';
|
|
10
10
|
import { format, inspect } from 'node:util';
|
|
11
|
+
import { ModuleRunner } from 'vite/module-runner';
|
|
11
12
|
|
|
12
13
|
const JOIN_LEADING_SLASH_RE = /^\.?\//;
|
|
13
14
|
function withTrailingSlash(input = "", respectQueryAndFragment) {
|
|
@@ -561,7 +562,7 @@ function read(jsonPath, {base, specifier}) {
|
|
|
561
562
|
let string;
|
|
562
563
|
|
|
563
564
|
try {
|
|
564
|
-
string =
|
|
565
|
+
string = fs__default.readFileSync(path.toNamespacedPath(jsonPath), 'utf8');
|
|
565
566
|
} catch (error) {
|
|
566
567
|
const exception = /** @type {ErrnoException} */ (error);
|
|
567
568
|
|
|
@@ -2194,7 +2195,7 @@ async function findUp$1(name, {
|
|
|
2194
2195
|
while (directory) {
|
|
2195
2196
|
const filePath = isAbsoluteName ? name : path.join(directory, name);
|
|
2196
2197
|
try {
|
|
2197
|
-
const stats = await fs
|
|
2198
|
+
const stats = await fs.stat(filePath); // eslint-disable-line no-await-in-loop
|
|
2198
2199
|
if ((type === 'file' && stats.isFile()) || (type === 'directory' && stats.isDirectory())) {
|
|
2199
2200
|
return filePath;
|
|
2200
2201
|
}
|
|
@@ -2222,7 +2223,7 @@ function findUpSync(name, {
|
|
|
2222
2223
|
const filePath = isAbsoluteName ? name : path.join(directory, name);
|
|
2223
2224
|
|
|
2224
2225
|
try {
|
|
2225
|
-
const stats =
|
|
2226
|
+
const stats = fs__default.statSync(filePath, {throwIfNoEntry: false});
|
|
2226
2227
|
if ((type === 'file' && stats?.isFile()) || (type === 'directory' && stats?.isDirectory())) {
|
|
2227
2228
|
return filePath;
|
|
2228
2229
|
}
|
|
@@ -2273,8 +2274,8 @@ function getPackageJsonPath(name, options = {}) {
|
|
|
2273
2274
|
return searchPackageJSON(entry);
|
|
2274
2275
|
}
|
|
2275
2276
|
const readFile = quansync({
|
|
2276
|
-
async: (id) =>
|
|
2277
|
-
sync: (id) =>
|
|
2277
|
+
async: (id) => fs__default.promises.readFile(id, "utf8"),
|
|
2278
|
+
sync: (id) => fs__default.readFileSync(id, "utf8")
|
|
2278
2279
|
});
|
|
2279
2280
|
const getPackageInfo = quansync(function* (name, options = {}) {
|
|
2280
2281
|
const packageJsonPath = getPackageJsonPath(name, options);
|
|
@@ -2313,7 +2314,7 @@ function searchPackageJSON(dir) {
|
|
|
2313
2314
|
return;
|
|
2314
2315
|
dir = newDir;
|
|
2315
2316
|
packageJsonPath = join(dir, "package.json");
|
|
2316
|
-
if (
|
|
2317
|
+
if (fs__default.existsSync(packageJsonPath))
|
|
2317
2318
|
break;
|
|
2318
2319
|
}
|
|
2319
2320
|
return packageJsonPath;
|
|
@@ -2324,7 +2325,7 @@ const findUp = quansync({
|
|
|
2324
2325
|
});
|
|
2325
2326
|
const loadPackageJSON = quansync(function* (cwd = process$1.cwd()) {
|
|
2326
2327
|
const path = yield findUp("package.json", { cwd });
|
|
2327
|
-
if (!path || !
|
|
2328
|
+
if (!path || !fs__default.existsSync(path))
|
|
2328
2329
|
return null;
|
|
2329
2330
|
return JSON.parse(yield readFile(path));
|
|
2330
2331
|
});
|
|
@@ -2335,4 +2336,34 @@ const isPackageListed = quansync(function* (name, cwd) {
|
|
|
2335
2336
|
});
|
|
2336
2337
|
isPackageListed.sync;
|
|
2337
2338
|
|
|
2338
|
-
|
|
2339
|
+
class NativeModuleRunner extends ModuleRunner {
|
|
2340
|
+
/**
|
|
2341
|
+
* @internal
|
|
2342
|
+
*/
|
|
2343
|
+
mocker;
|
|
2344
|
+
constructor(root, mocker) {
|
|
2345
|
+
super({
|
|
2346
|
+
hmr: false,
|
|
2347
|
+
sourcemapInterceptor: false,
|
|
2348
|
+
transport: { invoke() {
|
|
2349
|
+
throw new Error("Unexpected `invoke`");
|
|
2350
|
+
} }
|
|
2351
|
+
});
|
|
2352
|
+
this.root = root;
|
|
2353
|
+
this.mocker = mocker;
|
|
2354
|
+
if (mocker) Object.defineProperty(globalThis, "__vitest_mocker__", {
|
|
2355
|
+
configurable: true,
|
|
2356
|
+
writable: true,
|
|
2357
|
+
value: mocker
|
|
2358
|
+
});
|
|
2359
|
+
}
|
|
2360
|
+
async import(moduleId) {
|
|
2361
|
+
const path = resolveModule(moduleId, { paths: [this.root] }) ?? resolve(this.root, moduleId);
|
|
2362
|
+
// resolveModule doesn't keep the query params, so we need to add them back
|
|
2363
|
+
let queryParams = "";
|
|
2364
|
+
if (moduleId.includes("?") && !path.includes("?")) queryParams = moduleId.slice(moduleId.indexOf("?"));
|
|
2365
|
+
return import(pathToFileURL$1(path + queryParams).toString());
|
|
2366
|
+
}
|
|
2367
|
+
}
|
|
2368
|
+
|
|
2369
|
+
export { NativeModuleRunner as N, isPackageExists as i, resolveModule as r };
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { g as getWorkerState } from './utils.BX5Fg8C4.js';
|
|
2
|
+
import { promises, existsSync } from 'node:fs';
|
|
3
|
+
import { isAbsolute, resolve, dirname, join, basename } from 'pathe';
|
|
4
|
+
import '@vitest/utils/timers';
|
|
5
|
+
|
|
6
|
+
class NodeSnapshotEnvironment {
|
|
7
|
+
constructor(options = {}) {
|
|
8
|
+
this.options = options;
|
|
9
|
+
}
|
|
10
|
+
getVersion() {
|
|
11
|
+
return "1";
|
|
12
|
+
}
|
|
13
|
+
getHeader() {
|
|
14
|
+
return `// Snapshot v${this.getVersion()}`;
|
|
15
|
+
}
|
|
16
|
+
async resolveRawPath(testPath, rawPath) {
|
|
17
|
+
return isAbsolute(rawPath) ? rawPath : resolve(dirname(testPath), rawPath);
|
|
18
|
+
}
|
|
19
|
+
async resolvePath(filepath) {
|
|
20
|
+
return join(join(dirname(filepath), this.options.snapshotsDirName ?? "__snapshots__"), `${basename(filepath)}.snap`);
|
|
21
|
+
}
|
|
22
|
+
async prepareDirectory(dirPath) {
|
|
23
|
+
await promises.mkdir(dirPath, { recursive: true });
|
|
24
|
+
}
|
|
25
|
+
async saveSnapshotFile(filepath, snapshot) {
|
|
26
|
+
await promises.mkdir(dirname(filepath), { recursive: true });
|
|
27
|
+
await promises.writeFile(filepath, snapshot, "utf-8");
|
|
28
|
+
}
|
|
29
|
+
async readSnapshotFile(filepath) {
|
|
30
|
+
if (!existsSync(filepath)) return null;
|
|
31
|
+
return promises.readFile(filepath, "utf-8");
|
|
32
|
+
}
|
|
33
|
+
async removeSnapshotFile(filepath) {
|
|
34
|
+
if (existsSync(filepath)) await promises.unlink(filepath);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
class VitestNodeSnapshotEnvironment extends NodeSnapshotEnvironment {
|
|
39
|
+
getHeader() {
|
|
40
|
+
return `// Vitest Snapshot v${this.getVersion()}, https://vitest.dev/guide/snapshot.html`;
|
|
41
|
+
}
|
|
42
|
+
resolvePath(filepath) {
|
|
43
|
+
return getWorkerState().rpc.resolveSnapshotPath(filepath);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export { VitestNodeSnapshotEnvironment };
|