vitest 4.0.14 → 4.0.15
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/dist/browser.d.ts +1 -1
- package/dist/browser.js +1 -1
- package/dist/chunks/{base.BEv8sRbK.js → base.CTp-EStD.js} +6 -6
- package/dist/chunks/browser.d.DBzUq_Na.d.ts +57 -0
- package/dist/chunks/{cac.DnEx6DOX.js → cac.BNNpZQl7.js} +10 -25
- package/dist/chunks/{cli-api.CbjxIXjQ.js → cli-api.C7sYjHmQ.js} +423 -98
- package/dist/chunks/{config.d.g6OOauRt.d.ts → config.d.CzIjkicf.d.ts} +1 -0
- package/dist/chunks/evaluatedModules.d.BxJ5omdx.d.ts +7 -0
- package/dist/chunks/{globals.C0izxiX3.js → globals.DOayXfHP.js} +3 -3
- package/dist/chunks/{index.D6PC4Dpu.js → index.456_DGfR.js} +128 -18
- package/dist/chunks/{index.B88tjlE5.js → index.Drsj_6e7.js} +1 -1
- package/dist/chunks/{index.DBx1AtPJ.js → index.Z5E_ObnR.js} +1 -1
- package/dist/chunks/{index.CQwQ_SLL.js → index.bFLgAE-Z.js} +2 -2
- package/dist/chunks/{init-forks.DmvIFK4U.js → init-forks.CKEYp90N.js} +11 -2
- package/dist/chunks/{init-threads.De6b3S3g.js → init-threads.D8Ok07M7.js} +1 -1
- package/dist/chunks/{init.a5SCIJ0x.js → init.B04saIIg.js} +1 -1
- package/dist/chunks/modules.DJPjQW6m.js +35 -0
- package/dist/chunks/{plugin.d.B6hlg3fN.d.ts → plugin.d.CY7CUjf-.d.ts} +1 -1
- package/dist/chunks/{reporters.d.DeFcIuza.d.ts → reporters.d.OXEK7y4s.d.ts} +27 -4
- package/dist/chunks/{setup-common.DGHc_BUK.js → setup-common.Cm-kSBVi.js} +1 -1
- package/dist/chunks/{startModuleRunner.W28wBIgJ.js → startModuleRunner.Iz2V0ESw.js} +8 -9
- package/dist/chunks/{test.DqQZzsWf.js → test.BT8LKgU9.js} +8 -3
- package/dist/chunks/{vi.BiaV1qII.js → vi.2VT5v0um.js} +40 -30
- package/dist/chunks/{vm.BbVD4fJ5.js → vm.BwmD1Rql.js} +2 -2
- package/dist/chunks/{worker.d.DhEa3KzY.d.ts → worker.d.B4A26qg6.d.ts} +1 -1
- package/dist/cli.js +2 -2
- package/dist/config.d.ts +7 -7
- package/dist/coverage.d.ts +8 -8
- package/dist/index.d.ts +22 -14
- package/dist/index.js +3 -3
- package/dist/module-evaluator.d.ts +5 -0
- package/dist/module-evaluator.js +21 -6
- package/dist/module-runner.js +2 -1
- package/dist/node.d.ts +7 -7
- package/dist/node.js +6 -5
- package/dist/reporters.d.ts +7 -7
- package/dist/reporters.js +2 -2
- package/dist/runners.d.ts +2 -1
- package/dist/runners.js +2 -2
- package/dist/worker.d.ts +2 -2
- package/dist/worker.js +9 -8
- package/dist/workers/forks.js +10 -9
- package/dist/workers/runVmTests.js +5 -5
- package/dist/workers/threads.js +10 -9
- package/dist/workers/vmForks.js +5 -4
- package/dist/workers/vmThreads.js +5 -4
- package/package.json +14 -14
- package/dist/chunks/browser.d.F6jMf15V.d.ts +0 -18
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { g as globalApis } from './constants.D_Q9UYh-.js';
|
|
2
|
-
import { i as index } from './index.
|
|
3
|
-
import './vi.
|
|
2
|
+
import { i as index } from './index.Z5E_ObnR.js';
|
|
3
|
+
import './vi.2VT5v0um.js';
|
|
4
4
|
import '@vitest/expect';
|
|
5
5
|
import '@vitest/runner';
|
|
6
|
-
import '@vitest/runner/utils';
|
|
7
6
|
import './utils.DvEY5TfP.js';
|
|
8
7
|
import '@vitest/utils/timers';
|
|
8
|
+
import '@vitest/runner/utils';
|
|
9
9
|
import '@vitest/snapshot';
|
|
10
10
|
import '@vitest/utils/error';
|
|
11
11
|
import '@vitest/utils/helpers';
|
|
@@ -285,6 +285,62 @@ async function readBlobs(currentVersion, blobsDirectory, projectsArray) {
|
|
|
285
285
|
};
|
|
286
286
|
}
|
|
287
287
|
|
|
288
|
+
function groupBy(collection, iteratee) {
|
|
289
|
+
return collection.reduce((acc, item) => {
|
|
290
|
+
const key = iteratee(item);
|
|
291
|
+
acc[key] ||= [];
|
|
292
|
+
acc[key].push(item);
|
|
293
|
+
return acc;
|
|
294
|
+
}, {});
|
|
295
|
+
}
|
|
296
|
+
function stdout() {
|
|
297
|
+
// @ts-expect-error Node.js maps process.stdout to console._stdout
|
|
298
|
+
// eslint-disable-next-line no-console
|
|
299
|
+
return console._stdout || process.stdout;
|
|
300
|
+
}
|
|
301
|
+
function escapeRegExp(s) {
|
|
302
|
+
// From https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions#escaping
|
|
303
|
+
return s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
304
|
+
}
|
|
305
|
+
function wildcardPatternToRegExp(pattern) {
|
|
306
|
+
const negated = pattern[0] === "!";
|
|
307
|
+
if (negated) pattern = pattern.slice(1);
|
|
308
|
+
let regexp = `${pattern.split("*").map(escapeRegExp).join(".*")}$`;
|
|
309
|
+
if (negated) regexp = `(?!${regexp})`;
|
|
310
|
+
return new RegExp(`^${regexp}`, "i");
|
|
311
|
+
}
|
|
312
|
+
function createIndexLocationsMap(source) {
|
|
313
|
+
const map = /* @__PURE__ */ new Map();
|
|
314
|
+
let index = 0;
|
|
315
|
+
let line = 1;
|
|
316
|
+
let column = 1;
|
|
317
|
+
for (const char of source) {
|
|
318
|
+
map.set(index++, {
|
|
319
|
+
line,
|
|
320
|
+
column
|
|
321
|
+
});
|
|
322
|
+
if (char === "\n" || char === "\r\n") {
|
|
323
|
+
line++;
|
|
324
|
+
column = 0;
|
|
325
|
+
} else column++;
|
|
326
|
+
}
|
|
327
|
+
return map;
|
|
328
|
+
}
|
|
329
|
+
function createLocationsIndexMap(source) {
|
|
330
|
+
const map = /* @__PURE__ */ new Map();
|
|
331
|
+
let index = 0;
|
|
332
|
+
let line = 1;
|
|
333
|
+
let column = 1;
|
|
334
|
+
for (const char of source) {
|
|
335
|
+
map.set(`${line}:${column}`, index++);
|
|
336
|
+
if (char === "\n" || char === "\r\n") {
|
|
337
|
+
line++;
|
|
338
|
+
column = 0;
|
|
339
|
+
} else column++;
|
|
340
|
+
}
|
|
341
|
+
return map;
|
|
342
|
+
}
|
|
343
|
+
|
|
288
344
|
function hasFailedSnapshot(suite) {
|
|
289
345
|
return getTests(suite).some((s) => {
|
|
290
346
|
return s.result?.errors?.some((e) => typeof e?.message === "string" && e.message.match(/Snapshot .* mismatched/));
|
|
@@ -808,7 +864,76 @@ class BaseReporter {
|
|
|
808
864
|
this.log(padSummaryTitle("Duration"), formatTime(executionTime) + c.dim(` (${timers})`));
|
|
809
865
|
if (blobs?.executionTimes) this.log(padSummaryTitle("Per blob") + blobs.executionTimes.map((time) => ` ${formatTime(time)}`).join(""));
|
|
810
866
|
}
|
|
867
|
+
if (this.ctx.config.experimental.printImportBreakdown) this.printImportsBreakdown();
|
|
868
|
+
this.log();
|
|
869
|
+
}
|
|
870
|
+
printImportsBreakdown() {
|
|
871
|
+
const testModules = this.ctx.state.getTestModules();
|
|
872
|
+
const allImports = [];
|
|
873
|
+
for (const testModule of testModules) {
|
|
874
|
+
const importDurations = testModule.diagnostic().importDurations;
|
|
875
|
+
for (const filePath in importDurations) {
|
|
876
|
+
const duration = importDurations[filePath];
|
|
877
|
+
allImports.push({
|
|
878
|
+
importedModuleId: filePath,
|
|
879
|
+
testModule,
|
|
880
|
+
selfTime: duration.selfTime,
|
|
881
|
+
totalTime: duration.totalTime,
|
|
882
|
+
external: duration.external
|
|
883
|
+
});
|
|
884
|
+
}
|
|
885
|
+
}
|
|
886
|
+
if (allImports.length === 0) return;
|
|
887
|
+
const sortedImports = allImports.sort((a, b) => b.totalTime - a.totalTime);
|
|
888
|
+
const maxTotalTime = sortedImports[0].totalTime;
|
|
889
|
+
const topImports = sortedImports.slice(0, 10);
|
|
890
|
+
const totalSelfTime = allImports.reduce((sum, imp) => sum + imp.selfTime, 0);
|
|
891
|
+
const totalTotalTime = allImports.reduce((sum, imp) => sum + imp.totalTime, 0);
|
|
892
|
+
const slowestImport = sortedImports[0];
|
|
893
|
+
this.log();
|
|
894
|
+
this.log(c.bold("Import Duration Breakdown") + c.dim(" (ordered by Total Time) (Top 10)"));
|
|
895
|
+
// if there are multiple files, it's highly possible that some of them will import the same large file
|
|
896
|
+
// we group them to show the distinction between those files more easily
|
|
897
|
+
// Import Duration Breakdown (ordered by Total Time) (Top 10)
|
|
898
|
+
// .../fields/FieldFile/__tests__/FieldFile.spec.ts self: 7ms total: 1.01s ████████████████████
|
|
899
|
+
// ↳ tests/support/components/index.ts self: 0ms total: 861ms █████████████████░░░
|
|
900
|
+
// ↳ tests/support/components/renderComponent.ts self: 59ms total: 861ms █████████████████░░░
|
|
901
|
+
// ...s__/apps/desktop/form-updater.desktop.spec.ts self: 8ms total: 991ms ████████████████████
|
|
902
|
+
// ...sts__/apps/mobile/form-updater.mobile.spec.ts self: 11ms total: 990ms ████████████████████
|
|
903
|
+
// shared/components/Form/__tests__/Form.spec.ts self: 5ms total: 988ms ████████████████████
|
|
904
|
+
// ↳ tests/support/components/index.ts self: 0ms total: 935ms ███████████████████░
|
|
905
|
+
// ↳ tests/support/components/renderComponent.ts self: 61ms total: 935ms ███████████████████░
|
|
906
|
+
// ...ditor/features/link/__test__/LinkForm.spec.ts self: 7ms total: 972ms ███████████████████░
|
|
907
|
+
// ↳ tests/support/components/renderComponent.ts self: 56ms total: 936ms ███████████████████░
|
|
908
|
+
const groupedImports = Object.entries(
|
|
909
|
+
groupBy(topImports, (i) => i.testModule.id)
|
|
910
|
+
// the first one is always the highest because the modules are already sorted
|
|
911
|
+
).sort(([, imps1], [, imps2]) => imps2[0].totalTime - imps1[0].totalTime);
|
|
912
|
+
for (const [_, group] of groupedImports) group.forEach((imp, index) => {
|
|
913
|
+
const barWidth = 20;
|
|
914
|
+
const filledWidth = Math.round(imp.totalTime / maxTotalTime * barWidth);
|
|
915
|
+
const bar = c.cyan("█".repeat(filledWidth)) + c.dim("░".repeat(barWidth - filledWidth));
|
|
916
|
+
// only show the arrow if there is more than 1 group
|
|
917
|
+
const pathDisplay = this.ellipsisPath(imp.importedModuleId, imp.external, groupedImports.length > 1 && index > 0);
|
|
918
|
+
this.log(`${pathDisplay} ${c.dim("self:")} ${this.importDurationTime(imp.selfTime)} ${c.dim("total:")} ${this.importDurationTime(imp.totalTime)} ${bar}`);
|
|
919
|
+
});
|
|
811
920
|
this.log();
|
|
921
|
+
this.log(c.dim("Total imports: ") + allImports.length);
|
|
922
|
+
this.log(c.dim("Slowest import (total-time): ") + formatTime(slowestImport.totalTime));
|
|
923
|
+
this.log(c.dim("Total import time (self/total): ") + formatTime(totalSelfTime) + c.dim(" / ") + formatTime(totalTotalTime));
|
|
924
|
+
}
|
|
925
|
+
importDurationTime(duration) {
|
|
926
|
+
return (duration >= 500 ? c.red : duration >= 100 ? c.yellow : (c) => c)(formatTime(duration).padStart(6));
|
|
927
|
+
}
|
|
928
|
+
ellipsisPath(path, external, nested) {
|
|
929
|
+
const pathDisplay = this.relative(path);
|
|
930
|
+
const color = external ? c.magenta : (c) => c;
|
|
931
|
+
const slicedPath = pathDisplay.slice(-44);
|
|
932
|
+
let title = "";
|
|
933
|
+
if (pathDisplay.length > slicedPath.length) title += "...";
|
|
934
|
+
if (nested) title = ` ${F_DOWN_RIGHT} ${title}`;
|
|
935
|
+
title += slicedPath;
|
|
936
|
+
return color(title.padEnd(50));
|
|
812
937
|
}
|
|
813
938
|
printErrorsSummary(files, errors) {
|
|
814
939
|
const suites = getSuites(files);
|
|
@@ -2526,21 +2651,6 @@ async function getRawErrsMapFromTsCompile(tscErrorStdout) {
|
|
|
2526
2651
|
return rawErrsMap;
|
|
2527
2652
|
}
|
|
2528
2653
|
|
|
2529
|
-
function createIndexMap(source) {
|
|
2530
|
-
const map = /* @__PURE__ */ new Map();
|
|
2531
|
-
let index = 0;
|
|
2532
|
-
let line = 1;
|
|
2533
|
-
let column = 1;
|
|
2534
|
-
for (const char of source) {
|
|
2535
|
-
map.set(`${line}:${column}`, index++);
|
|
2536
|
-
if (char === "\n" || char === "\r\n") {
|
|
2537
|
-
line++;
|
|
2538
|
-
column = 0;
|
|
2539
|
-
} else column++;
|
|
2540
|
-
}
|
|
2541
|
-
return map;
|
|
2542
|
-
}
|
|
2543
|
-
|
|
2544
2654
|
class TypeCheckError extends Error {
|
|
2545
2655
|
name = "TypeCheckError";
|
|
2546
2656
|
constructor(message, stacks) {
|
|
@@ -2620,7 +2730,7 @@ class Typechecker {
|
|
|
2620
2730
|
const sortedDefinitions = [...definitions.sort((a, b) => b.start - a.start)];
|
|
2621
2731
|
// has no map for ".js" files that use // @ts-check
|
|
2622
2732
|
const traceMap = map && new TraceMap(map);
|
|
2623
|
-
const indexMap =
|
|
2733
|
+
const indexMap = createLocationsIndexMap(parsed);
|
|
2624
2734
|
const markState = (task, state) => {
|
|
2625
2735
|
task.result = { state: task.mode === "run" || task.mode === "only" ? state : task.mode };
|
|
2626
2736
|
if (task.suite) markState(task.suite, state);
|
|
@@ -3141,7 +3251,7 @@ class GithubActionsReporter {
|
|
|
3141
3251
|
const title = getFullName(task, " > ");
|
|
3142
3252
|
for (const error of task.result?.errors ?? []) projectErrors.push({
|
|
3143
3253
|
project,
|
|
3144
|
-
title,
|
|
3254
|
+
title: project.name ? `[${project.name}] ${title}` : title,
|
|
3145
3255
|
error,
|
|
3146
3256
|
file
|
|
3147
3257
|
});
|
|
@@ -3702,4 +3812,4 @@ const ReportersMap = {
|
|
|
3702
3812
|
"github-actions": GithubActionsReporter
|
|
3703
3813
|
};
|
|
3704
3814
|
|
|
3705
|
-
export { BlobReporter as B, DefaultReporter as D, F_RIGHT as F, GithubActionsReporter as G, HangingProcessReporter as H, JsonReporter as J, ReportersMap as R, TapFlatReporter as T, VerboseReporter as V, DotReporter as a, JUnitReporter as b, TapReporter as c, stringify as d,
|
|
3815
|
+
export { utils as A, BlobReporter as B, DefaultReporter as D, F_RIGHT as F, GithubActionsReporter as G, HangingProcessReporter as H, JsonReporter as J, ReportersMap as R, TapFlatReporter as T, VerboseReporter as V, DotReporter as a, JUnitReporter as b, TapReporter as c, stringify as d, createIndexLocationsMap as e, formatProjectName as f, getStateSymbol as g, TraceMap as h, ancestor as i, printError as j, errorBanner as k, divider as l, Typechecker as m, generateCodeFrame as n, originalPositionFor as o, parse$1 as p, escapeRegExp as q, createDefinesScript as r, separator as s, truncateString as t, groupBy as u, readBlobs as v, withLabel as w, convertTasksToEvents as x, wildcardPatternToRegExp as y, stdout as z };
|
|
@@ -2,7 +2,7 @@ import fs from 'node:fs';
|
|
|
2
2
|
import { getTasks, getFullName, getTests } from '@vitest/runner/utils';
|
|
3
3
|
import * as pathe from 'pathe';
|
|
4
4
|
import c from 'tinyrainbow';
|
|
5
|
-
import { g as getStateSymbol, t as truncateString, F as F_RIGHT, D as DefaultReporter, f as formatProjectName, s as separator } from './index.
|
|
5
|
+
import { g as getStateSymbol, t as truncateString, F as F_RIGHT, D as DefaultReporter, f as formatProjectName, s as separator } from './index.456_DGfR.js';
|
|
6
6
|
import { stripVTControlCharacters } from 'node:util';
|
|
7
7
|
import { notNullish } from '@vitest/utils/helpers';
|
|
8
8
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { b as assert, c as createExpect, g as globalExpect, i as inject, s as should, v as vi, d as vitest } from './vi.
|
|
1
|
+
import { b as assert, c as createExpect, g as globalExpect, i as inject, s as should, v as vi, d as vitest } from './vi.2VT5v0um.js';
|
|
2
2
|
import { b as bench } from './benchmark.B3N2zMcH.js';
|
|
3
3
|
import { V as VitestEvaluatedModules } from './evaluatedModules.Dg1zASAC.js';
|
|
4
4
|
import { expectTypeOf } from 'expect-type';
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { chai } from '@vitest/expect';
|
|
2
|
-
import { l as loadDiffConfig, b as loadSnapshotSerializers, t as takeCoverageInsideWorker } from './setup-common.
|
|
2
|
+
import { l as loadDiffConfig, b as loadSnapshotSerializers, t as takeCoverageInsideWorker } from './setup-common.Cm-kSBVi.js';
|
|
3
3
|
import { r as rpc } from './rpc.BytlcPfC.js';
|
|
4
4
|
import { g as getWorkerState } from './utils.DvEY5TfP.js';
|
|
5
|
-
import { V as VitestTestRunner, N as NodeBenchmarkRunner } from './test.
|
|
5
|
+
import { V as VitestTestRunner, N as NodeBenchmarkRunner } from './test.BT8LKgU9.js';
|
|
6
6
|
|
|
7
7
|
function setupChaiConfig(config) {
|
|
8
8
|
Object.assign(chai.config, config);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { i as init } from './init.
|
|
1
|
+
import { i as init } from './init.B04saIIg.js';
|
|
2
2
|
|
|
3
3
|
if (!process.send) throw new Error("Expected worker to be run in node:child_process");
|
|
4
4
|
// Store globals in case tests overwrite them
|
|
@@ -9,13 +9,17 @@ const processOff = process.off.bind(process);
|
|
|
9
9
|
const processRemoveAllListeners = process.removeAllListeners.bind(process);
|
|
10
10
|
// Work-around for nodejs/node#55094
|
|
11
11
|
if (process.execArgv.some((execArg) => execArg.startsWith("--prof") || execArg.startsWith("--cpu-prof") || execArg.startsWith("--heap-prof") || execArg.startsWith("--diagnostic-dir"))) processOn("SIGTERM", () => processExit());
|
|
12
|
+
processOn("error", onError);
|
|
12
13
|
function workerInit(options) {
|
|
13
14
|
const { runTests } = options;
|
|
14
15
|
init({
|
|
15
16
|
post: (v) => processSend(v),
|
|
16
17
|
on: (cb) => processOn("message", cb),
|
|
17
18
|
off: (cb) => processOff("message", cb),
|
|
18
|
-
teardown: () =>
|
|
19
|
+
teardown: () => {
|
|
20
|
+
processRemoveAllListeners("message");
|
|
21
|
+
processOff("error", onError);
|
|
22
|
+
},
|
|
19
23
|
runTests: (state, traces) => executeTests("run", state, traces),
|
|
20
24
|
collectTests: (state, traces) => executeTests("collect", state, traces),
|
|
21
25
|
setup: options.setup
|
|
@@ -28,5 +32,10 @@ function workerInit(options) {
|
|
|
28
32
|
}
|
|
29
33
|
}
|
|
30
34
|
}
|
|
35
|
+
// Prevent leaving worker in loops where it tries to send message to closed main
|
|
36
|
+
// thread, errors, and tries to send the error.
|
|
37
|
+
function onError(error) {
|
|
38
|
+
if (error?.code === "ERR_IPC_CHANNEL_CLOSED" || error?.code === "EPIPE") processExit(1);
|
|
39
|
+
}
|
|
31
40
|
|
|
32
41
|
export { workerInit as w };
|
|
@@ -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.B04saIIg.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,7 +3,7 @@ import { isBuiltin } from 'node:module';
|
|
|
3
3
|
import { pathToFileURL } from 'node:url';
|
|
4
4
|
import { resolve } from 'pathe';
|
|
5
5
|
import { ModuleRunner } from 'vite/module-runner';
|
|
6
|
-
import { b as VitestTransport } from './startModuleRunner.
|
|
6
|
+
import { b as VitestTransport } from './startModuleRunner.Iz2V0ESw.js';
|
|
7
7
|
import { e as environments } from './index.BspFP3mn.js';
|
|
8
8
|
import { serializeError } from '@vitest/utils/error';
|
|
9
9
|
import { T as Traces } from './traces.U4xDYhzZ.js';
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { builtinModules } from 'node:module';
|
|
2
|
+
|
|
3
|
+
// copied from vite
|
|
4
|
+
// https://github.com/vitejs/vite/blob/814120f2ad387ca3d1e16c7dd403b04ca4b97f75/packages/vite/src/node/utils.ts#L106
|
|
5
|
+
// Supported by Node, Deno, Bun
|
|
6
|
+
const NODE_BUILTIN_NAMESPACE = "node:";
|
|
7
|
+
// Supported by Deno
|
|
8
|
+
const NPM_BUILTIN_NAMESPACE = "npm:";
|
|
9
|
+
// Supported by Bun
|
|
10
|
+
const BUN_BUILTIN_NAMESPACE = "bun:";
|
|
11
|
+
// Some runtimes like Bun injects namespaced modules here, which is not a node builtin
|
|
12
|
+
const nodeBuiltins = builtinModules.filter((id) => !id.includes(":"));
|
|
13
|
+
// TODO: Use `isBuiltin` from `node:module`, but Deno doesn't support it
|
|
14
|
+
function isBuiltin(id) {
|
|
15
|
+
if (process.versions.deno && id.startsWith(NPM_BUILTIN_NAMESPACE)) return true;
|
|
16
|
+
if (process.versions.bun && id.startsWith(BUN_BUILTIN_NAMESPACE)) return true;
|
|
17
|
+
return isNodeBuiltin(id);
|
|
18
|
+
}
|
|
19
|
+
function isNodeBuiltin(id) {
|
|
20
|
+
if (id.startsWith(NODE_BUILTIN_NAMESPACE)) return true;
|
|
21
|
+
return nodeBuiltins.includes(id);
|
|
22
|
+
}
|
|
23
|
+
const browserExternalId = "__vite-browser-external";
|
|
24
|
+
const browserExternalLength = 24;
|
|
25
|
+
function isBrowserExternal(id) {
|
|
26
|
+
return id.startsWith(browserExternalId);
|
|
27
|
+
}
|
|
28
|
+
function toBuiltin(id) {
|
|
29
|
+
if (id.startsWith(browserExternalId)) id = id.slice(browserExternalLength);
|
|
30
|
+
if (id.startsWith(NPM_BUILTIN_NAMESPACE) || id.startsWith(BUN_BUILTIN_NAMESPACE) || id.startsWith(NODE_BUILTIN_NAMESPACE)) return id;
|
|
31
|
+
if (process.versions.deno || process.versions.bun) return id;
|
|
32
|
+
return `node:${id}`;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export { isBrowserExternal as a, isBuiltin as i, toBuiltin as t };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { DevEnvironment } from 'vite';
|
|
2
|
-
import { V as Vitest, T as TestProject, b as TestProjectConfiguration } from './reporters.d.
|
|
2
|
+
import { V as Vitest, T as TestProject, b as TestProjectConfiguration } from './reporters.d.OXEK7y4s.js';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Generate a unique cache identifier.
|
|
@@ -2,18 +2,18 @@ import { TaskMeta, Suite, File, TestAnnotation, TestArtifact, ImportDuration, Te
|
|
|
2
2
|
import { TestError, SerializedError, Arrayable, ParsedStack, Awaitable } from '@vitest/utils';
|
|
3
3
|
import { A as AfterSuiteRunMeta, U as UserConsoleLog, P as ProvidedContext, L as LabelColor } from './rpc.d.RH3apGEf.js';
|
|
4
4
|
import { Writable } from 'node:stream';
|
|
5
|
-
import { TransformResult as TransformResult$1, ViteDevServer, Plugin, UserConfig as UserConfig$1, DepOptimizationConfig, ServerOptions, ConfigEnv, AliasOptions } from 'vite';
|
|
5
|
+
import { DevEnvironment, TransformResult as TransformResult$1, ViteDevServer, Plugin, UserConfig as UserConfig$1, DepOptimizationConfig, ServerOptions, ConfigEnv, AliasOptions } from 'vite';
|
|
6
|
+
import { S as SerializedTestSpecification, c as SourceModuleDiagnostic, B as BrowserTesterOptions } from './browser.d.DBzUq_Na.js';
|
|
6
7
|
import { MockedModule } from '@vitest/mocker';
|
|
7
8
|
import { StackTraceParserOptions } from '@vitest/utils/source-map';
|
|
8
9
|
import { BrowserCommands } from 'vitest/browser';
|
|
9
|
-
import { B as BrowserTraceViewMode, S as SerializedConfig, F as FakeTimerInstallOpts } from './config.d.
|
|
10
|
-
import { S as SerializedTestSpecification, B as BrowserTesterOptions } from './browser.d.F6jMf15V.js';
|
|
10
|
+
import { B as BrowserTraceViewMode, S as SerializedConfig, F as FakeTimerInstallOpts } from './config.d.CzIjkicf.js';
|
|
11
11
|
import { PrettyFormatOptions } from '@vitest/pretty-format';
|
|
12
12
|
import { SnapshotSummary, SnapshotStateOptions } from '@vitest/snapshot';
|
|
13
13
|
import { SerializedDiffOptions } from '@vitest/utils/diff';
|
|
14
14
|
import { chai } from '@vitest/expect';
|
|
15
15
|
import { happyDomTypes, jsdomTypes } from 'vitest/optional-types.js';
|
|
16
|
-
import { c as ContextTestEnvironment, d as WorkerExecuteContext, e as WorkerTestEnvironment } from './worker.d.
|
|
16
|
+
import { c as ContextTestEnvironment, d as WorkerExecuteContext, e as WorkerTestEnvironment } from './worker.d.B4A26qg6.js';
|
|
17
17
|
import { O as OTELCarrier } from './traces.d.402V_yFI.js';
|
|
18
18
|
import { B as BenchmarkResult } from './benchmark.d.DAaHLpsq.js';
|
|
19
19
|
import { a as RuntimeCoverageProviderModule } from './coverage.d.BZtK59WP.js';
|
|
@@ -239,6 +239,12 @@ declare class TestModule extends SuiteImplementation {
|
|
|
239
239
|
readonly location: undefined;
|
|
240
240
|
readonly type = "module";
|
|
241
241
|
/**
|
|
242
|
+
* The Vite environment that processes files on the server.
|
|
243
|
+
*
|
|
244
|
+
* Can be empty if test module did not run yet.
|
|
245
|
+
*/
|
|
246
|
+
readonly viteEnvironment: DevEnvironment | undefined;
|
|
247
|
+
/**
|
|
242
248
|
* This is usually an absolute UNIX file path.
|
|
243
249
|
* It can be a virtual ID if the file is not on the disk.
|
|
244
250
|
* This value corresponds to the ID in the Vite's module graph.
|
|
@@ -1278,6 +1284,14 @@ declare class Vitest {
|
|
|
1278
1284
|
*/
|
|
1279
1285
|
rerunTestSpecifications(specifications: TestSpecification[], allTestsRun?: boolean): Promise<TestRunResult>;
|
|
1280
1286
|
private runFiles;
|
|
1287
|
+
/**
|
|
1288
|
+
* Returns module's diagnostic. If `testModule` is not provided, `selfTime` and `totalTime` will be aggregated across all tests.
|
|
1289
|
+
*
|
|
1290
|
+
* If the module was not transformed or executed, the diagnostic will be empty.
|
|
1291
|
+
* @experimental
|
|
1292
|
+
* @see {@link https://vitest.dev/api/advanced/vitest#getsourcemodulediagnostic}
|
|
1293
|
+
*/
|
|
1294
|
+
experimental_getSourceModuleDiagnostic(moduleId: string, testModule?: TestModule): Promise<SourceModuleDiagnostic>;
|
|
1281
1295
|
experimental_parseSpecifications(specifications: TestSpecification[], options?: {
|
|
1282
1296
|
/** @default os.availableParallelism() */
|
|
1283
1297
|
concurrency?: number;
|
|
@@ -2025,6 +2039,9 @@ declare abstract class BaseReporter implements Reporter {
|
|
|
2025
2039
|
onServerRestart(reason?: string): void;
|
|
2026
2040
|
reportSummary(files: File[], errors: unknown[]): void;
|
|
2027
2041
|
reportTestSummary(files: File[], errors: unknown[]): void;
|
|
2042
|
+
private printImportsBreakdown;
|
|
2043
|
+
private importDurationTime;
|
|
2044
|
+
private ellipsisPath;
|
|
2028
2045
|
private printErrorsSummary;
|
|
2029
2046
|
reportBenchmarkSummary(files: File[]): void;
|
|
2030
2047
|
private printTaskErrors;
|
|
@@ -3019,6 +3036,12 @@ interface InlineConfig {
|
|
|
3019
3036
|
enabled: boolean;
|
|
3020
3037
|
sdkPath?: string;
|
|
3021
3038
|
};
|
|
3039
|
+
/**
|
|
3040
|
+
* Show imports (top 10) that take a long time.
|
|
3041
|
+
*
|
|
3042
|
+
* Enabling this will also show a breakdown by default in UI, but you can always press a button to toggle it.
|
|
3043
|
+
*/
|
|
3044
|
+
printImportBreakdown?: boolean;
|
|
3022
3045
|
};
|
|
3023
3046
|
}
|
|
3024
3047
|
interface TypecheckConfig {
|
|
@@ -26,7 +26,7 @@ async function setupCommonEnv(config) {
|
|
|
26
26
|
if (globalSetup) return;
|
|
27
27
|
globalSetup = true;
|
|
28
28
|
setSafeTimers();
|
|
29
|
-
if (config.globals) (await import('./globals.
|
|
29
|
+
if (config.globals) (await import('./globals.DOayXfHP.js')).registerApiGlobally();
|
|
30
30
|
}
|
|
31
31
|
function setupDefines(config) {
|
|
32
32
|
for (const key in config.defines) globalThis[key] = config.defines[key];
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import fs from 'node:fs';
|
|
2
|
-
import nodeModule, { isBuiltin } from 'node:module';
|
|
3
2
|
import { isBareImport } from '@vitest/utils/helpers';
|
|
3
|
+
import { i as isBuiltin, a as isBrowserExternal, t as toBuiltin } from './modules.DJPjQW6m.js';
|
|
4
4
|
import { pathToFileURL } from 'node:url';
|
|
5
5
|
import { normalize as normalize$1, join as join$1 } from 'pathe';
|
|
6
6
|
import { distDir } from '../path.js';
|
|
@@ -9,6 +9,7 @@ import { VitestModuleEvaluator, unwrapId } from '../module-evaluator.js';
|
|
|
9
9
|
import { resolve as resolve$1, isAbsolute as isAbsolute$1 } from 'node:path';
|
|
10
10
|
import vm from 'node:vm';
|
|
11
11
|
import { MockerRegistry, mockObject, RedirectedModule, AutomockedModule } from '@vitest/mocker';
|
|
12
|
+
import nodeModule from 'node:module';
|
|
12
13
|
import * as viteModuleRunner from 'vite/module-runner';
|
|
13
14
|
import { T as Traces } from './traces.U4xDYhzZ.js';
|
|
14
15
|
|
|
@@ -754,8 +755,6 @@ function listenForErrors(state) {
|
|
|
754
755
|
}
|
|
755
756
|
|
|
756
757
|
const { readFileSync } = fs;
|
|
757
|
-
const browserExternalId = "__vite-browser-external";
|
|
758
|
-
const browserExternalLength = 24;
|
|
759
758
|
const VITEST_VM_CONTEXT_SYMBOL = "__vitest_vm_context__";
|
|
760
759
|
const cwd = process.cwd();
|
|
761
760
|
const isWindows = process.platform === "win32";
|
|
@@ -777,6 +776,7 @@ function startVitestModuleRunner(options) {
|
|
|
777
776
|
} : void 0;
|
|
778
777
|
const evaluator = options.evaluator || new VitestModuleEvaluator(vm, {
|
|
779
778
|
traces,
|
|
779
|
+
evaluatedModules: options.evaluatedModules,
|
|
780
780
|
get moduleExecutionInfo() {
|
|
781
781
|
return state().moduleExecutionInfo;
|
|
782
782
|
},
|
|
@@ -817,7 +817,11 @@ function startVitestModuleRunner(options) {
|
|
|
817
817
|
invalidate: false,
|
|
818
818
|
mockedModule: resolvedMock
|
|
819
819
|
};
|
|
820
|
-
if (isBuiltin(rawId)
|
|
820
|
+
if (isBuiltin(rawId)) return {
|
|
821
|
+
externalize: rawId,
|
|
822
|
+
type: "builtin"
|
|
823
|
+
};
|
|
824
|
+
if (isBrowserExternal(rawId)) return {
|
|
821
825
|
externalize: toBuiltin(rawId),
|
|
822
826
|
type: "builtin"
|
|
823
827
|
};
|
|
@@ -853,10 +857,5 @@ function startVitestModuleRunner(options) {
|
|
|
853
857
|
});
|
|
854
858
|
return moduleRunner;
|
|
855
859
|
}
|
|
856
|
-
function toBuiltin(id) {
|
|
857
|
-
if (id.startsWith(browserExternalId)) id = id.slice(browserExternalLength);
|
|
858
|
-
if (!id.startsWith("node:")) id = `node:${id}`;
|
|
859
|
-
return id;
|
|
860
|
-
}
|
|
861
860
|
|
|
862
861
|
export { VitestModuleRunner as V, VITEST_VM_CONTEXT_SYMBOL as a, VitestTransport as b, createNodeImportMeta as c, startVitestModuleRunner as s };
|
|
@@ -7,7 +7,7 @@ import { setState, GLOBAL_EXPECT, getState } from '@vitest/expect';
|
|
|
7
7
|
import { getTests, getNames, getTestName } from '@vitest/runner/utils';
|
|
8
8
|
import { processError } from '@vitest/utils/error';
|
|
9
9
|
import { normalize } from 'pathe';
|
|
10
|
-
import { a as getSnapshotClient, i as inject, c as createExpect, v as vi } from './vi.
|
|
10
|
+
import { a as getSnapshotClient, i as inject, c as createExpect, v as vi } from './vi.2VT5v0um.js';
|
|
11
11
|
import { r as rpc } from './rpc.BytlcPfC.js';
|
|
12
12
|
|
|
13
13
|
function createBenchmarkResult(name) {
|
|
@@ -122,8 +122,11 @@ class VitestTestRunner {
|
|
|
122
122
|
assertionsErrors = /* @__PURE__ */ new WeakMap();
|
|
123
123
|
pool = this.workerState.ctx.pool;
|
|
124
124
|
_otel;
|
|
125
|
+
viteEnvironment;
|
|
125
126
|
constructor(config) {
|
|
126
127
|
this.config = config;
|
|
128
|
+
const environment = this.workerState.environment;
|
|
129
|
+
this.viteEnvironment = environment.viteEnvironment || environment.name;
|
|
127
130
|
}
|
|
128
131
|
importFile(filepath, source) {
|
|
129
132
|
if (source === "setup") {
|
|
@@ -223,9 +226,11 @@ class VitestTestRunner {
|
|
|
223
226
|
getImportDurations() {
|
|
224
227
|
const importDurations = {};
|
|
225
228
|
const entries = this.workerState.moduleExecutionInfo?.entries() || [];
|
|
226
|
-
for (const [filepath, { duration, selfTime }] of entries) importDurations[normalize(filepath)] = {
|
|
229
|
+
for (const [filepath, { duration, selfTime, external, importer }] of entries) importDurations[normalize(filepath)] = {
|
|
227
230
|
selfTime,
|
|
228
|
-
totalTime: duration
|
|
231
|
+
totalTime: duration,
|
|
232
|
+
external,
|
|
233
|
+
importer
|
|
229
234
|
};
|
|
230
235
|
return importDurations;
|
|
231
236
|
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { chai, equals, iterableEquality, subsetEquality, JestExtend, JestChaiExpect, JestAsymmetricMatchers, GLOBAL_EXPECT, ASYMMETRIC_MATCHERS_OBJECT, getState, setState, addCustomEqualityTesters, customMatchers } from '@vitest/expect';
|
|
2
2
|
import { getCurrentTest } from '@vitest/runner';
|
|
3
|
-
import { getNames, getTestName } from '@vitest/runner/utils';
|
|
4
3
|
import { g as getWorkerState, i as isChildProcess, w as waitForImportsToResolve, r as resetModules } from './utils.DvEY5TfP.js';
|
|
5
|
-
import { getSafeTimers } from '@vitest/utils/timers';
|
|
4
|
+
import { getSafeTimers, delay } from '@vitest/utils/timers';
|
|
5
|
+
import { getNames } from '@vitest/runner/utils';
|
|
6
6
|
import { stripSnapshotIndentation, addSerializer, SnapshotClient } from '@vitest/snapshot';
|
|
7
7
|
import '@vitest/utils/error';
|
|
8
8
|
import { assertTypes, createSimpleStackTrace } from '@vitest/utils/helpers';
|
|
@@ -25,6 +25,18 @@ const unsupported = [
|
|
|
25
25
|
"toThrow",
|
|
26
26
|
"toThrowError"
|
|
27
27
|
];
|
|
28
|
+
/**
|
|
29
|
+
* Attaches a `cause` property to the error if missing, copies the stack trace from the source, and throws.
|
|
30
|
+
*
|
|
31
|
+
* @param error - The error to throw
|
|
32
|
+
* @param source - Error to copy the stack trace from
|
|
33
|
+
*
|
|
34
|
+
* @throws Always throws the provided error with an amended stack trace
|
|
35
|
+
*/
|
|
36
|
+
function throwWithCause(error, source) {
|
|
37
|
+
if (error.cause == null) error.cause = /* @__PURE__ */ new Error("Matcher did not succeed in time.");
|
|
38
|
+
throw copyStackTrace$1(error, source);
|
|
39
|
+
}
|
|
28
40
|
function createExpectPoll(expect) {
|
|
29
41
|
return function poll(fn, options = {}) {
|
|
30
42
|
const defaults = getWorkerState().config.expect?.poll ?? {};
|
|
@@ -41,35 +53,33 @@ function createExpectPoll(expect) {
|
|
|
41
53
|
if (typeof key === "string" && unsupported.includes(key)) throw new SyntaxError(`expect.poll() is not supported in combination with .${key}(). Use vi.waitFor() if your assertion condition is unstable.`);
|
|
42
54
|
return function(...args) {
|
|
43
55
|
const STACK_TRACE_ERROR = /* @__PURE__ */ new Error("STACK_TRACE_ERROR");
|
|
44
|
-
const promise =
|
|
45
|
-
let intervalId;
|
|
46
|
-
let timeoutId;
|
|
47
|
-
let lastError;
|
|
56
|
+
const promise = async () => {
|
|
48
57
|
const { setTimeout, clearTimeout } = getSafeTimers();
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
chai.util.flag(assertion, "object", obj);
|
|
54
|
-
resolve(await assertionFunction.call(assertion, ...args));
|
|
55
|
-
clearTimeout(intervalId);
|
|
56
|
-
clearTimeout(timeoutId);
|
|
57
|
-
} catch (err) {
|
|
58
|
-
lastError = err;
|
|
59
|
-
if (!chai.util.flag(assertion, "_isLastPollAttempt")) intervalId = setTimeout(check, interval);
|
|
60
|
-
}
|
|
61
|
-
};
|
|
62
|
-
timeoutId = setTimeout(() => {
|
|
63
|
-
clearTimeout(intervalId);
|
|
64
|
-
chai.util.flag(assertion, "_isLastPollAttempt", true);
|
|
65
|
-
const rejectWithCause = (error) => {
|
|
66
|
-
if (error.cause == null) error.cause = /* @__PURE__ */ new Error("Matcher did not succeed in time.");
|
|
67
|
-
reject(copyStackTrace$1(error, STACK_TRACE_ERROR));
|
|
68
|
-
};
|
|
69
|
-
check().then(() => rejectWithCause(lastError)).catch((e) => rejectWithCause(e));
|
|
58
|
+
let executionPhase = "fn";
|
|
59
|
+
let hasTimedOut = false;
|
|
60
|
+
const timerId = setTimeout(() => {
|
|
61
|
+
hasTimedOut = true;
|
|
70
62
|
}, timeout);
|
|
71
|
-
|
|
72
|
-
|
|
63
|
+
chai.util.flag(assertion, "_name", key);
|
|
64
|
+
try {
|
|
65
|
+
while (true) {
|
|
66
|
+
const isLastAttempt = hasTimedOut;
|
|
67
|
+
if (isLastAttempt) chai.util.flag(assertion, "_isLastPollAttempt", true);
|
|
68
|
+
try {
|
|
69
|
+
executionPhase = "fn";
|
|
70
|
+
const obj = await fn();
|
|
71
|
+
chai.util.flag(assertion, "object", obj);
|
|
72
|
+
executionPhase = "assertion";
|
|
73
|
+
return await assertionFunction.call(assertion, ...args);
|
|
74
|
+
} catch (err) {
|
|
75
|
+
if (isLastAttempt || executionPhase === "assertion" && chai.util.flag(assertion, "_poll.assert_once")) throwWithCause(err, STACK_TRACE_ERROR);
|
|
76
|
+
await delay(interval, setTimeout);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
} finally {
|
|
80
|
+
clearTimeout(timerId);
|
|
81
|
+
}
|
|
82
|
+
};
|
|
73
83
|
let awaited = false;
|
|
74
84
|
test.onFinished ??= [];
|
|
75
85
|
test.onFinished.push(() => {
|
|
@@ -315,7 +325,7 @@ function createExpect(test) {
|
|
|
315
325
|
get testPath() {
|
|
316
326
|
return getWorkerState().filepath;
|
|
317
327
|
},
|
|
318
|
-
currentTestName: test ?
|
|
328
|
+
currentTestName: test ? test.fullTestName ?? "" : globalState.currentTestName
|
|
319
329
|
}, expect);
|
|
320
330
|
expect.assert = chai.assert;
|
|
321
331
|
// @ts-expect-error untyped
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { fileURLToPath, pathToFileURL } from 'node:url';
|
|
2
2
|
import vm, { isContext, runInContext } from 'node:vm';
|
|
3
3
|
import { dirname, basename, extname, normalize, resolve } from 'pathe';
|
|
4
|
-
import { l as loadEnvironment } from './init.
|
|
4
|
+
import { l as loadEnvironment } from './init.B04saIIg.js';
|
|
5
5
|
import { distDir } from '../path.js';
|
|
6
6
|
import { createCustomConsole } from './console.Cf-YriPC.js';
|
|
7
7
|
import fs from 'node:fs';
|
|
@@ -11,7 +11,7 @@ import { findNearestPackageData } from '@vitest/utils/resolver';
|
|
|
11
11
|
import { dirname as dirname$1 } from 'node:path';
|
|
12
12
|
import { CSS_LANGS_RE, KNOWN_ASSET_RE } from '@vitest/utils/constants';
|
|
13
13
|
import { getDefaultRequestStubs } from '../module-evaluator.js';
|
|
14
|
-
import { s as startVitestModuleRunner, c as createNodeImportMeta, a as VITEST_VM_CONTEXT_SYMBOL } from './startModuleRunner.
|
|
14
|
+
import { s as startVitestModuleRunner, c as createNodeImportMeta, a as VITEST_VM_CONTEXT_SYMBOL } from './startModuleRunner.Iz2V0ESw.js';
|
|
15
15
|
import { p as provideWorkerState } from './utils.DvEY5TfP.js';
|
|
16
16
|
|
|
17
17
|
function interopCommonJsModule(interopDefault, mod) {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { FileSpecification, Task, CancelReason } from '@vitest/runner';
|
|
2
2
|
import { EvaluatedModules } from 'vite/module-runner';
|
|
3
|
-
import { S as SerializedConfig } from './config.d.
|
|
3
|
+
import { S as SerializedConfig } from './config.d.CzIjkicf.js';
|
|
4
4
|
import { E as Environment } from './environment.d.CrsxCzP1.js';
|
|
5
5
|
import { R as RuntimeRPC, a as RunnerRPC } from './rpc.d.RH3apGEf.js';
|
|
6
6
|
|