vitest 4.0.6 → 4.0.8
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 +1 -1
- package/dist/browser.d.ts +2 -2
- package/dist/browser.js +2 -2
- package/dist/chunks/base.BgTO2qAg.js +156 -0
- package/dist/chunks/{benchmark.DHKMYAts.js → benchmark.B3N2zMcH.js} +9 -4
- package/dist/chunks/{browser.d.ScGeWTou.d.ts → browser.d.DTTM2PTh.d.ts} +1 -1
- package/dist/chunks/{cac.BBqWH4nd.js → cac.CfkWq8Qy.js} +117 -43
- package/dist/chunks/{cli-api.UL3SwFUb.js → cli-api.BQ-bjcRi.js} +1870 -847
- package/dist/chunks/console.Cf-YriPC.js +146 -0
- package/dist/chunks/{coverage.DuCn_Tmx.js → coverage.NVjCOln1.js} +281 -103
- package/dist/chunks/{creator.cqqifzG7.js → creator.fzVyoMf3.js} +74 -30
- package/dist/chunks/{date.-jtEtIeV.js → date.Bq6ZW5rf.js} +17 -6
- package/dist/chunks/{git.BFNcloKD.js → git.Bm2pzPAa.js} +3 -3
- package/dist/chunks/{global.d.DdOkMiVb.d.ts → global.d.DVdCfKp5.d.ts} +1 -1
- package/dist/chunks/{globals.BGT_RUsD.js → globals.DOh96BiR.js} +5 -5
- package/dist/chunks/{resolveSnapshotEnvironment.BZzLjzkh.js → index.BY4-tcno.js} +42 -25
- package/dist/chunks/{index.Bgo3tNWt.js → index.DAL392Ss.js} +40 -15
- package/dist/chunks/{index.RwjEGCQ0.js → index.DIFZf73e.js} +2 -2
- package/dist/chunks/{index.DV0mQLEO.js → index.DfKyPFVi.js} +195 -64
- package/dist/chunks/{index.BL8Hg4Uk.js → index.kotH7DY7.js} +837 -380
- package/dist/chunks/{index.CpdwpN7L.js → index.op2Re5rn.js} +22 -12
- package/dist/chunks/{init-forks.CSGFj9zN.js → init-forks.2hx7cf78.js} +16 -5
- package/dist/chunks/{init-threads.CIJLeFO8.js → init-threads.Cm4OCIWA.js} +3 -2
- package/dist/chunks/{init.DUeOfNO9.js → init.DMDG-idf.js} +124 -54
- package/dist/chunks/{inspector.DLZxSeU3.js → inspector.CvyFGlXm.js} +25 -10
- package/dist/chunks/{moduleRunner.d.TP-w6tIQ.d.ts → moduleRunner.d.CzOZ_4wC.d.ts} +1 -1
- package/dist/chunks/{node.BwAWWjHZ.js → node.Ce0vMQM7.js} +1 -1
- package/dist/chunks/{plugin.d.lctzD3Wk.d.ts → plugin.d.D4RrtywJ.d.ts} +1 -1
- package/dist/chunks/{reporters.d.PEs0tXod.d.ts → reporters.d.Da1D1VbQ.d.ts} +19 -9
- package/dist/chunks/rpc.BUV7uWKJ.js +76 -0
- package/dist/chunks/{setup-common.DR1sucx6.js → setup-common.LGjNSzXp.js} +20 -8
- package/dist/chunks/{startModuleRunner.Di-EZqh0.js → startModuleRunner.BOmUtLIO.js} +228 -105
- package/dist/chunks/{test.CnspO-X4.js → test.ClrAtjMv.js} +48 -22
- package/dist/chunks/{utils.CG9h5ccR.js → utils.DvEY5TfP.js} +14 -5
- package/dist/chunks/{vi.BZvkKVkM.js → vi.Bgcdy3bQ.js} +261 -111
- package/dist/chunks/{vm.Co_lR2NL.js → vm.BIkCDs68.js} +177 -70
- package/dist/chunks/{worker.d.B4Hthdvt.d.ts → worker.d.DadbA89M.d.ts} +52 -6
- package/dist/cli.js +2 -2
- package/dist/config.d.ts +5 -5
- package/dist/coverage.d.ts +3 -3
- package/dist/coverage.js +1 -1
- package/dist/environments.js +2 -1
- package/dist/index.d.ts +5 -5
- package/dist/index.js +5 -5
- package/dist/module-evaluator.d.ts +2 -2
- package/dist/module-evaluator.js +85 -35
- package/dist/module-runner.js +2 -2
- package/dist/node.d.ts +7 -7
- package/dist/node.js +16 -12
- package/dist/reporters.d.ts +3 -3
- package/dist/reporters.js +2 -2
- package/dist/runners.js +7 -7
- package/dist/snapshot.js +2 -2
- package/dist/suite.js +2 -2
- package/dist/worker.d.ts +2 -1
- package/dist/worker.js +27 -27
- package/dist/workers/forks.js +34 -31
- package/dist/workers/runVmTests.js +41 -22
- package/dist/workers/threads.js +34 -31
- package/dist/workers/vmForks.js +14 -14
- package/dist/workers/vmThreads.js +14 -14
- package/package.json +20 -20
- package/dist/chunks/base.BAf_bYeI.js +0 -128
- package/dist/chunks/console.CTJL2nuH.js +0 -115
- package/dist/chunks/rpc.Dv1Jt3i2.js +0 -66
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
import { Console } from 'node:console';
|
|
2
|
+
import { relative } from 'node:path';
|
|
3
|
+
import { Writable } from 'node:stream';
|
|
4
|
+
import { getSafeTimers } from '@vitest/utils/timers';
|
|
5
|
+
import c from 'tinyrainbow';
|
|
6
|
+
import { R as RealDate } from './date.Bq6ZW5rf.js';
|
|
7
|
+
import { g as getWorkerState } from './utils.DvEY5TfP.js';
|
|
8
|
+
|
|
9
|
+
const UNKNOWN_TEST_ID = "__vitest__unknown_test__";
|
|
10
|
+
function getTaskIdByStack(root) {
|
|
11
|
+
const stack = (/* @__PURE__ */ new Error("STACK_TRACE_ERROR")).stack?.split("\n");
|
|
12
|
+
if (!stack) return UNKNOWN_TEST_ID;
|
|
13
|
+
const index = stack.findIndex((line) => line.includes("at Console.value"));
|
|
14
|
+
const line = index === -1 ? null : stack[index + 2];
|
|
15
|
+
if (!line) return UNKNOWN_TEST_ID;
|
|
16
|
+
const filepath = line.match(/at\s(.*)\s?/)?.[1];
|
|
17
|
+
if (filepath) return relative(root, filepath);
|
|
18
|
+
return UNKNOWN_TEST_ID;
|
|
19
|
+
}
|
|
20
|
+
function createCustomConsole(defaultState) {
|
|
21
|
+
const stdoutBuffer = /* @__PURE__ */ new Map();
|
|
22
|
+
const stderrBuffer = /* @__PURE__ */ new Map();
|
|
23
|
+
const timers = /* @__PURE__ */ new Map();
|
|
24
|
+
const { queueMicrotask } = getSafeTimers();
|
|
25
|
+
function queueCancelableMicrotask(callback) {
|
|
26
|
+
let canceled = false;
|
|
27
|
+
queueMicrotask(() => {
|
|
28
|
+
if (!canceled) callback();
|
|
29
|
+
});
|
|
30
|
+
return () => {
|
|
31
|
+
canceled = true;
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
const state = () => defaultState || getWorkerState();
|
|
35
|
+
// group sync console.log calls with micro task
|
|
36
|
+
function schedule(taskId) {
|
|
37
|
+
const timer = timers.get(taskId);
|
|
38
|
+
const { stdoutTime, stderrTime } = timer;
|
|
39
|
+
timer.cancel?.();
|
|
40
|
+
timer.cancel = queueCancelableMicrotask(() => {
|
|
41
|
+
if (stderrTime < stdoutTime) {
|
|
42
|
+
sendStderr(taskId);
|
|
43
|
+
sendStdout(taskId);
|
|
44
|
+
} else {
|
|
45
|
+
sendStdout(taskId);
|
|
46
|
+
sendStderr(taskId);
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
function sendStdout(taskId) {
|
|
51
|
+
sendBuffer("stdout", taskId);
|
|
52
|
+
}
|
|
53
|
+
function sendStderr(taskId) {
|
|
54
|
+
sendBuffer("stderr", taskId);
|
|
55
|
+
}
|
|
56
|
+
function sendBuffer(type, taskId) {
|
|
57
|
+
const buffers = type === "stdout" ? stdoutBuffer : stderrBuffer;
|
|
58
|
+
const buffer = buffers.get(taskId);
|
|
59
|
+
if (!buffer) return;
|
|
60
|
+
if (state().config.printConsoleTrace) buffer.forEach(([buffer, origin]) => {
|
|
61
|
+
sendLog(type, taskId, String(buffer), buffer.length, origin);
|
|
62
|
+
});
|
|
63
|
+
else sendLog(type, taskId, buffer.map((i) => String(i[0])).join(""), buffer.length);
|
|
64
|
+
const timer = timers.get(taskId);
|
|
65
|
+
buffers.delete(taskId);
|
|
66
|
+
if (type === "stderr") timer.stderrTime = 0;
|
|
67
|
+
else timer.stdoutTime = 0;
|
|
68
|
+
}
|
|
69
|
+
function sendLog(type, taskId, content, size, origin) {
|
|
70
|
+
const timer = timers.get(taskId);
|
|
71
|
+
const time = type === "stderr" ? timer.stderrTime : timer.stdoutTime;
|
|
72
|
+
state().rpc.onUserConsoleLog({
|
|
73
|
+
type,
|
|
74
|
+
content: content || "<empty line>",
|
|
75
|
+
taskId,
|
|
76
|
+
time: time || RealDate.now(),
|
|
77
|
+
size,
|
|
78
|
+
origin
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
return new Console({
|
|
82
|
+
stdout: new Writable({ write(data, encoding, callback) {
|
|
83
|
+
const s = state();
|
|
84
|
+
const id = s?.current?.id || s?.current?.suite?.id || s.current?.file.id || getTaskIdByStack(s.config.root);
|
|
85
|
+
let timer = timers.get(id);
|
|
86
|
+
if (timer) timer.stdoutTime = timer.stdoutTime || RealDate.now();
|
|
87
|
+
else {
|
|
88
|
+
timer = {
|
|
89
|
+
stdoutTime: RealDate.now(),
|
|
90
|
+
stderrTime: RealDate.now()
|
|
91
|
+
};
|
|
92
|
+
timers.set(id, timer);
|
|
93
|
+
}
|
|
94
|
+
let buffer = stdoutBuffer.get(id);
|
|
95
|
+
if (!buffer) {
|
|
96
|
+
buffer = [];
|
|
97
|
+
stdoutBuffer.set(id, buffer);
|
|
98
|
+
}
|
|
99
|
+
if (state().config.printConsoleTrace) {
|
|
100
|
+
const limit = Error.stackTraceLimit;
|
|
101
|
+
Error.stackTraceLimit = limit + 6;
|
|
102
|
+
const trace = (/* @__PURE__ */ new Error("STACK_TRACE")).stack?.split("\n").slice(7).join("\n");
|
|
103
|
+
Error.stackTraceLimit = limit;
|
|
104
|
+
buffer.push([data, trace]);
|
|
105
|
+
} else buffer.push([data, void 0]);
|
|
106
|
+
schedule(id);
|
|
107
|
+
callback();
|
|
108
|
+
} }),
|
|
109
|
+
stderr: new Writable({ write(data, encoding, callback) {
|
|
110
|
+
const s = state();
|
|
111
|
+
const id = s?.current?.id || s?.current?.suite?.id || s.current?.file.id || getTaskIdByStack(s.config.root);
|
|
112
|
+
let timer = timers.get(id);
|
|
113
|
+
if (timer) timer.stderrTime = timer.stderrTime || RealDate.now();
|
|
114
|
+
else {
|
|
115
|
+
timer = {
|
|
116
|
+
stderrTime: RealDate.now(),
|
|
117
|
+
stdoutTime: RealDate.now()
|
|
118
|
+
};
|
|
119
|
+
timers.set(id, timer);
|
|
120
|
+
}
|
|
121
|
+
let buffer = stderrBuffer.get(id);
|
|
122
|
+
if (!buffer) {
|
|
123
|
+
buffer = [];
|
|
124
|
+
stderrBuffer.set(id, buffer);
|
|
125
|
+
}
|
|
126
|
+
if (state().config.printConsoleTrace) {
|
|
127
|
+
const limit = Error.stackTraceLimit;
|
|
128
|
+
Error.stackTraceLimit = limit + 6;
|
|
129
|
+
const stack = (/* @__PURE__ */ new Error("STACK_TRACE")).stack?.split("\n");
|
|
130
|
+
Error.stackTraceLimit = limit;
|
|
131
|
+
if (stack?.some((line) => line.includes("at Console.trace"))) buffer.push([data, void 0]);
|
|
132
|
+
else {
|
|
133
|
+
const trace = stack?.slice(7).join("\n");
|
|
134
|
+
Error.stackTraceLimit = limit;
|
|
135
|
+
buffer.push([data, trace]);
|
|
136
|
+
}
|
|
137
|
+
} else buffer.push([data, void 0]);
|
|
138
|
+
schedule(id);
|
|
139
|
+
callback();
|
|
140
|
+
} }),
|
|
141
|
+
colorMode: c.isColorSupported,
|
|
142
|
+
groupIndentation: 2
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
export { UNKNOWN_TEST_ID, createCustomConsole };
|