vitest 3.1.0-beta.1 → 3.1.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/dist/browser.js +4 -4
- package/dist/chunks/base.CylSMlTD.js +41 -0
- package/dist/chunks/benchmark.BKUatJGy.js +39 -0
- package/dist/chunks/cac.JtTXbKz0.js +1525 -0
- package/dist/chunks/{cli-api.BwkkJsRe.js → cli-api.BTtPTYMs.js} +4638 -5072
- package/dist/chunks/console.D6t261w0.js +173 -0
- package/dist/chunks/constants.BZZyIeIE.js +43 -0
- package/dist/chunks/coverage.0iPg4Wrz.js +33 -0
- package/dist/chunks/{coverage.gV8doR2Y.js → coverage.C2ohxaN0.js} +2216 -2479
- package/dist/chunks/creator.BEXek7yQ.js +640 -0
- package/dist/chunks/date.CDOsz-HY.js +53 -0
- package/dist/chunks/defaults.DmfNPoe5.js +114 -0
- package/dist/chunks/{env.D4Lgay0q.js → env.Dq0hM4Xv.js} +1 -1
- package/dist/chunks/execute.DZKwfrTs.js +791 -0
- package/dist/chunks/git.DXfdBEfR.js +74 -0
- package/dist/chunks/{globals.BEpDe-k3.js → globals.DCbUWjip.js} +10 -10
- package/dist/chunks/{index.D7Ny8f_s.js → index.BDobFbcz.js} +6 -7
- package/dist/chunks/index.DFXFpH3w.js +607 -0
- package/dist/chunks/index.VfYQ6MXY.js +104 -0
- package/dist/chunks/index.ZIOEXBQB.js +2382 -0
- package/dist/chunks/inspector.DbDkSkFn.js +54 -0
- package/dist/chunks/node.IqGoMrm4.js +15 -0
- package/dist/chunks/{reporters.d.r7poTZjA.d.ts → reporters.d.5g6jXhoW.d.ts} +14 -3
- package/dist/chunks/rpc.DGgL5dw7.js +92 -0
- package/dist/chunks/run-once.I7PpBOk1.js +47 -0
- package/dist/chunks/runBaseTests.CqmKSG99.js +134 -0
- package/dist/chunks/setup-common.DEGDGBiA.js +88 -0
- package/dist/chunks/{typechecker.BlF3eHsb.js → typechecker.C2IpOhid.js} +620 -622
- package/dist/chunks/utils.BfxieIyZ.js +66 -0
- package/dist/chunks/utils.CtocqOoE.js +72 -0
- package/dist/chunks/utils.OLmtDstN.js +194 -0
- package/dist/chunks/{vi.nSCvwQ7l.js → vi.B-PuvDzu.js} +878 -1019
- package/dist/chunks/vite.d.Dh1jE-_V.d.ts +23 -0
- package/dist/chunks/vm.BW5voG-u.js +789 -0
- package/dist/cli.js +2 -2
- package/dist/config.cjs +97 -103
- package/dist/config.d.ts +3 -3
- package/dist/config.js +6 -6
- package/dist/coverage.d.ts +1 -1
- package/dist/coverage.js +6 -6
- package/dist/environments.js +1 -1
- package/dist/execute.js +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.js +6 -6
- package/dist/node.d.ts +3 -3
- package/dist/node.js +36 -45
- package/dist/path.js +1 -4
- package/dist/reporters.d.ts +1 -1
- package/dist/reporters.js +4 -4
- package/dist/runners.js +231 -267
- package/dist/snapshot.js +2 -2
- package/dist/suite.js +2 -2
- package/dist/worker.js +98 -114
- package/dist/workers/forks.js +22 -22
- package/dist/workers/runVmTests.js +61 -66
- package/dist/workers/threads.js +13 -13
- package/dist/workers/vmForks.js +24 -24
- package/dist/workers/vmThreads.js +15 -15
- package/dist/workers.js +10 -10
- package/package.json +11 -11
- package/dist/chunks/base.DV59CbtV.js +0 -45
- package/dist/chunks/benchmark.DL72EVN-.js +0 -40
- package/dist/chunks/cac.BjmXy7OV.js +0 -1664
- package/dist/chunks/console.CN7AiMGV.js +0 -179
- package/dist/chunks/constants.DTYd6dNH.js +0 -46
- package/dist/chunks/coverage.A3sS5-Wm.js +0 -40
- package/dist/chunks/creator.BsBnpTzI.js +0 -670
- package/dist/chunks/date.W2xKR2qe.js +0 -53
- package/dist/chunks/defaults.C2Ndd9wx.js +0 -119
- package/dist/chunks/execute.eDH0aFFd.js +0 -839
- package/dist/chunks/git.B5SDxu-n.js +0 -69
- package/dist/chunks/index.DOyx6FYJ.js +0 -2551
- package/dist/chunks/index.K90BXFOx.js +0 -658
- package/dist/chunks/index.uXkkC4xl.js +0 -111
- package/dist/chunks/inspector.DKLceBVD.js +0 -54
- package/dist/chunks/node.AKq966Jp.js +0 -15
- package/dist/chunks/rpc.TVf73xOu.js +0 -102
- package/dist/chunks/run-once.2ogXb3JV.js +0 -28
- package/dist/chunks/runBaseTests.BVrL_ow3.js +0 -142
- package/dist/chunks/setup-common.CPvtqi8q.js +0 -96
- package/dist/chunks/utils.C8RiOc4B.js +0 -77
- package/dist/chunks/utils.Cn0zI1t3.js +0 -68
- package/dist/chunks/utils.bLM2atbD.js +0 -198
- package/dist/chunks/vite.d.Fvq-NZoa.d.ts +0 -11
- package/dist/chunks/vm.jEFQDlX_.js +0 -852
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
import { Console } from 'node:console';
|
|
2
|
+
import { relative } from 'node:path';
|
|
3
|
+
import { Writable } from 'node:stream';
|
|
4
|
+
import { getSafeTimers } from '@vitest/utils';
|
|
5
|
+
import c from 'tinyrainbow';
|
|
6
|
+
import { R as RealDate } from './date.CDOsz-HY.js';
|
|
7
|
+
import { g as getWorkerState } from './utils.CtocqOoE.js';
|
|
8
|
+
|
|
9
|
+
const UNKNOWN_TEST_ID = "__vitest__unknown_test__";
|
|
10
|
+
function getTaskIdByStack(root) {
|
|
11
|
+
const stack = new Error("STACK_TRACE_ERROR").stack?.split("\n");
|
|
12
|
+
if (!stack) {
|
|
13
|
+
return UNKNOWN_TEST_ID;
|
|
14
|
+
}
|
|
15
|
+
const index = stack.findIndex((line) => line.includes("at Console.value"));
|
|
16
|
+
const line = index === -1 ? null : stack[index + 2];
|
|
17
|
+
if (!line) {
|
|
18
|
+
return UNKNOWN_TEST_ID;
|
|
19
|
+
}
|
|
20
|
+
const filepath = line.match(/at\s(.*)\s?/)?.[1];
|
|
21
|
+
if (filepath) {
|
|
22
|
+
return relative(root, filepath);
|
|
23
|
+
}
|
|
24
|
+
return UNKNOWN_TEST_ID;
|
|
25
|
+
}
|
|
26
|
+
function createCustomConsole(defaultState) {
|
|
27
|
+
const stdoutBuffer = new Map();
|
|
28
|
+
const stderrBuffer = new Map();
|
|
29
|
+
const timers = new Map();
|
|
30
|
+
const { queueMicrotask } = getSafeTimers();
|
|
31
|
+
function queueCancelableMicrotask(callback) {
|
|
32
|
+
let canceled = false;
|
|
33
|
+
queueMicrotask(() => {
|
|
34
|
+
if (!canceled) {
|
|
35
|
+
callback();
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
return () => {
|
|
39
|
+
canceled = true;
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
const state = () => defaultState || getWorkerState();
|
|
43
|
+
function schedule(taskId) {
|
|
44
|
+
const timer = timers.get(taskId);
|
|
45
|
+
const { stdoutTime, stderrTime } = timer;
|
|
46
|
+
timer.cancel?.();
|
|
47
|
+
timer.cancel = queueCancelableMicrotask(() => {
|
|
48
|
+
if (stderrTime < stdoutTime) {
|
|
49
|
+
sendStderr(taskId);
|
|
50
|
+
sendStdout(taskId);
|
|
51
|
+
} else {
|
|
52
|
+
sendStdout(taskId);
|
|
53
|
+
sendStderr(taskId);
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
function sendStdout(taskId) {
|
|
58
|
+
sendBuffer("stdout", taskId);
|
|
59
|
+
}
|
|
60
|
+
function sendStderr(taskId) {
|
|
61
|
+
sendBuffer("stderr", taskId);
|
|
62
|
+
}
|
|
63
|
+
function sendBuffer(type, taskId) {
|
|
64
|
+
const buffers = type === "stdout" ? stdoutBuffer : stderrBuffer;
|
|
65
|
+
const buffer = buffers.get(taskId);
|
|
66
|
+
if (!buffer) {
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
if (state().config.printConsoleTrace) {
|
|
70
|
+
buffer.forEach(([buffer, origin]) => {
|
|
71
|
+
sendLog(type, taskId, String(buffer), buffer.length, origin);
|
|
72
|
+
});
|
|
73
|
+
} else {
|
|
74
|
+
const content = buffer.map((i) => String(i[0])).join("");
|
|
75
|
+
sendLog(type, taskId, content, buffer.length);
|
|
76
|
+
}
|
|
77
|
+
const timer = timers.get(taskId);
|
|
78
|
+
buffers.delete(taskId);
|
|
79
|
+
if (type === "stderr") {
|
|
80
|
+
timer.stderrTime = 0;
|
|
81
|
+
} else {
|
|
82
|
+
timer.stdoutTime = 0;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
function sendLog(type, taskId, content, size, origin) {
|
|
86
|
+
const timer = timers.get(taskId);
|
|
87
|
+
const time = type === "stderr" ? timer.stderrTime : timer.stdoutTime;
|
|
88
|
+
state().rpc.onUserConsoleLog({
|
|
89
|
+
type,
|
|
90
|
+
content: content || "<empty line>",
|
|
91
|
+
taskId,
|
|
92
|
+
time: time || RealDate.now(),
|
|
93
|
+
size,
|
|
94
|
+
origin
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
const stdout = new Writable({ write(data, encoding, callback) {
|
|
98
|
+
const s = state();
|
|
99
|
+
const id = s?.current?.id || s?.current?.suite?.id || s.current?.file.id || getTaskIdByStack(s.config.root);
|
|
100
|
+
let timer = timers.get(id);
|
|
101
|
+
if (timer) {
|
|
102
|
+
timer.stdoutTime = timer.stdoutTime || RealDate.now();
|
|
103
|
+
} else {
|
|
104
|
+
timer = {
|
|
105
|
+
stdoutTime: RealDate.now(),
|
|
106
|
+
stderrTime: RealDate.now()
|
|
107
|
+
};
|
|
108
|
+
timers.set(id, timer);
|
|
109
|
+
}
|
|
110
|
+
let buffer = stdoutBuffer.get(id);
|
|
111
|
+
if (!buffer) {
|
|
112
|
+
buffer = [];
|
|
113
|
+
stdoutBuffer.set(id, buffer);
|
|
114
|
+
}
|
|
115
|
+
if (state().config.printConsoleTrace) {
|
|
116
|
+
const limit = Error.stackTraceLimit;
|
|
117
|
+
Error.stackTraceLimit = limit + 6;
|
|
118
|
+
const stack = new Error("STACK_TRACE").stack;
|
|
119
|
+
const trace = stack?.split("\n").slice(7).join("\n");
|
|
120
|
+
Error.stackTraceLimit = limit;
|
|
121
|
+
buffer.push([data, trace]);
|
|
122
|
+
} else {
|
|
123
|
+
buffer.push([data, undefined]);
|
|
124
|
+
}
|
|
125
|
+
schedule(id);
|
|
126
|
+
callback();
|
|
127
|
+
} });
|
|
128
|
+
const stderr = new Writable({ write(data, encoding, callback) {
|
|
129
|
+
const s = state();
|
|
130
|
+
const id = s?.current?.id || s?.current?.suite?.id || s.current?.file.id || getTaskIdByStack(s.config.root);
|
|
131
|
+
let timer = timers.get(id);
|
|
132
|
+
if (timer) {
|
|
133
|
+
timer.stderrTime = timer.stderrTime || RealDate.now();
|
|
134
|
+
} else {
|
|
135
|
+
timer = {
|
|
136
|
+
stderrTime: RealDate.now(),
|
|
137
|
+
stdoutTime: RealDate.now()
|
|
138
|
+
};
|
|
139
|
+
timers.set(id, timer);
|
|
140
|
+
}
|
|
141
|
+
let buffer = stderrBuffer.get(id);
|
|
142
|
+
if (!buffer) {
|
|
143
|
+
buffer = [];
|
|
144
|
+
stderrBuffer.set(id, buffer);
|
|
145
|
+
}
|
|
146
|
+
if (state().config.printConsoleTrace) {
|
|
147
|
+
const limit = Error.stackTraceLimit;
|
|
148
|
+
Error.stackTraceLimit = limit + 6;
|
|
149
|
+
const stack = new Error("STACK_TRACE").stack?.split("\n");
|
|
150
|
+
Error.stackTraceLimit = limit;
|
|
151
|
+
const isTrace = stack?.some((line) => line.includes("at Console.trace"));
|
|
152
|
+
if (isTrace) {
|
|
153
|
+
buffer.push([data, undefined]);
|
|
154
|
+
} else {
|
|
155
|
+
const trace = stack?.slice(7).join("\n");
|
|
156
|
+
Error.stackTraceLimit = limit;
|
|
157
|
+
buffer.push([data, trace]);
|
|
158
|
+
}
|
|
159
|
+
} else {
|
|
160
|
+
buffer.push([data, undefined]);
|
|
161
|
+
}
|
|
162
|
+
schedule(id);
|
|
163
|
+
callback();
|
|
164
|
+
} });
|
|
165
|
+
return new Console({
|
|
166
|
+
stdout,
|
|
167
|
+
stderr,
|
|
168
|
+
colorMode: c.isColorSupported,
|
|
169
|
+
groupIndentation: 2
|
|
170
|
+
});
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
export { UNKNOWN_TEST_ID, createCustomConsole };
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
const defaultPort = 51204;
|
|
2
|
+
const defaultBrowserPort = 63315;
|
|
3
|
+
const defaultInspectPort = 9229;
|
|
4
|
+
const API_PATH = "/__vitest_api__";
|
|
5
|
+
const extraInlineDeps = [
|
|
6
|
+
/^(?!.*node_modules).*\.mjs$/,
|
|
7
|
+
/^(?!.*node_modules).*\.cjs\.js$/,
|
|
8
|
+
/vite\w*\/dist\/client\/env.mjs/
|
|
9
|
+
];
|
|
10
|
+
const CONFIG_NAMES = ["vitest.config", "vite.config"];
|
|
11
|
+
const WORKSPACES_NAMES = ["vitest.workspace", "vitest.projects"];
|
|
12
|
+
const CONFIG_EXTENSIONS = [
|
|
13
|
+
".ts",
|
|
14
|
+
".mts",
|
|
15
|
+
".cts",
|
|
16
|
+
".js",
|
|
17
|
+
".mjs",
|
|
18
|
+
".cjs"
|
|
19
|
+
];
|
|
20
|
+
const configFiles = CONFIG_NAMES.flatMap((name) => CONFIG_EXTENSIONS.map((ext) => name + ext));
|
|
21
|
+
const WORKSPACES_EXTENSIONS = [...CONFIG_EXTENSIONS, ".json"];
|
|
22
|
+
const workspacesFiles = WORKSPACES_NAMES.flatMap((name) => WORKSPACES_EXTENSIONS.map((ext) => name + ext));
|
|
23
|
+
const globalApis = [
|
|
24
|
+
"suite",
|
|
25
|
+
"test",
|
|
26
|
+
"describe",
|
|
27
|
+
"it",
|
|
28
|
+
"chai",
|
|
29
|
+
"expect",
|
|
30
|
+
"assert",
|
|
31
|
+
"expectTypeOf",
|
|
32
|
+
"assertType",
|
|
33
|
+
"vitest",
|
|
34
|
+
"vi",
|
|
35
|
+
"beforeAll",
|
|
36
|
+
"afterAll",
|
|
37
|
+
"beforeEach",
|
|
38
|
+
"afterEach",
|
|
39
|
+
"onTestFinished",
|
|
40
|
+
"onTestFailed"
|
|
41
|
+
];
|
|
42
|
+
|
|
43
|
+
export { API_PATH as A, defaultPort as a, defaultInspectPort as b, configFiles as c, defaultBrowserPort as d, extraInlineDeps as e, globalApis as g, workspacesFiles as w };
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
const CoverageProviderMap = {
|
|
2
|
+
v8: "@vitest/coverage-v8",
|
|
3
|
+
istanbul: "@vitest/coverage-istanbul"
|
|
4
|
+
};
|
|
5
|
+
async function resolveCoverageProviderModule(options, loader) {
|
|
6
|
+
if (!options?.enabled || !options.provider) {
|
|
7
|
+
return null;
|
|
8
|
+
}
|
|
9
|
+
const provider = options.provider;
|
|
10
|
+
if (provider === "v8" || provider === "istanbul") {
|
|
11
|
+
let builtInModule = CoverageProviderMap[provider];
|
|
12
|
+
if (provider === "v8" && loader.isBrowser) {
|
|
13
|
+
builtInModule += "/browser";
|
|
14
|
+
}
|
|
15
|
+
const { default: coverageModule } = await loader.executeId(builtInModule);
|
|
16
|
+
if (!coverageModule) {
|
|
17
|
+
throw new Error(`Failed to load ${CoverageProviderMap[provider]}. Default export is missing.`);
|
|
18
|
+
}
|
|
19
|
+
return coverageModule;
|
|
20
|
+
}
|
|
21
|
+
let customProviderModule;
|
|
22
|
+
try {
|
|
23
|
+
customProviderModule = await loader.executeId(options.customProviderModule);
|
|
24
|
+
} catch (error) {
|
|
25
|
+
throw new Error(`Failed to load custom CoverageProviderModule from ${options.customProviderModule}`, { cause: error });
|
|
26
|
+
}
|
|
27
|
+
if (customProviderModule.default == null) {
|
|
28
|
+
throw new Error(`Custom CoverageProviderModule loaded from ${options.customProviderModule} was not the default export`);
|
|
29
|
+
}
|
|
30
|
+
return customProviderModule.default;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export { CoverageProviderMap as C, resolveCoverageProviderModule as r };
|