vitest 4.0.7 → 4.0.9

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.
Files changed (65) hide show
  1. package/LICENSE.md +1 -1
  2. package/dist/browser.d.ts +2 -2
  3. package/dist/browser.js +2 -2
  4. package/dist/chunks/{base.D3GxgUMI.js → base.CiIV2DDC.js} +71 -36
  5. package/dist/chunks/{benchmark.DHKMYAts.js → benchmark.B3N2zMcH.js} +9 -4
  6. package/dist/chunks/{browser.d.-LKfRopd.d.ts → browser.d.DnU_kh8a.d.ts} +1 -1
  7. package/dist/chunks/{cac.G9DAn-c7.js → cac.B_NTJoIH.js} +115 -42
  8. package/dist/chunks/{cli-api.Csks4as1.js → cli-api.D48wY175.js} +1863 -845
  9. package/dist/chunks/console.Cf-YriPC.js +146 -0
  10. package/dist/chunks/{coverage.C2LA1DSL.js → coverage.BUlIqJrL.js} +284 -114
  11. package/dist/chunks/{creator.cqqifzG7.js → creator.BzqvXeRE.js} +75 -31
  12. package/dist/chunks/{date.-jtEtIeV.js → date.Bq6ZW5rf.js} +17 -6
  13. package/dist/chunks/{git.BFNcloKD.js → git.Bm2pzPAa.js} +3 -3
  14. package/dist/chunks/{global.d.DxtanrNO.d.ts → global.d.BQDgW9Pr.d.ts} +1 -1
  15. package/dist/chunks/{globals.BGT_RUsD.js → globals.DBrtKPdh.js} +5 -5
  16. package/dist/chunks/index.0kCJoeWi.js +220 -0
  17. package/dist/chunks/{index.CWIFvlX5.js → index.BfmpdV5p.js} +165 -54
  18. package/dist/chunks/{index.RwjEGCQ0.js → index.CGezRSGU.js} +2 -2
  19. package/dist/chunks/{index.DEPqWSIZ.js → index.CPA8jGhR.js} +33 -16
  20. package/dist/chunks/{index.CVpyv-Zg.js → index.kotH7DY7.js} +832 -373
  21. package/dist/chunks/{index.jMQYiEWE.js → index.op2Re5rn.js} +22 -12
  22. package/dist/chunks/{index.Dc3xnDvT.js → index.z7NPOg2E.js} +4 -4
  23. package/dist/chunks/{init-forks.IU-xQ2_X.js → init-forks.aqTzCSR2.js} +14 -4
  24. package/dist/chunks/{init-threads.C_NWvZkU.js → init-threads.C7T0-YMD.js} +1 -1
  25. package/dist/chunks/{init.fmH9J833.js → init.BQhNfT0h.js} +53 -30
  26. package/dist/chunks/{inspector.DLZxSeU3.js → inspector.CvyFGlXm.js} +25 -10
  27. package/dist/chunks/{moduleRunner.d.DEkTotCv.d.ts → moduleRunner.d.BxT-OjLR.d.ts} +1 -1
  28. package/dist/chunks/{node.BwAWWjHZ.js → node.Ce0vMQM7.js} +1 -1
  29. package/dist/chunks/{plugin.d.Cpes8Bt6.d.ts → plugin.d.DevON6kQ.d.ts} +1 -1
  30. package/dist/chunks/{reporters.d.CSNcMDxF.d.ts → reporters.d.BQ0wpUaj.d.ts} +6 -5
  31. package/dist/chunks/{rpc.D38ahn14.js → rpc.BytlcPfC.js} +20 -7
  32. package/dist/chunks/{setup-common.DR1sucx6.js → setup-common.Dw1XgX0v.js} +20 -8
  33. package/dist/chunks/{startModuleRunner.Cn7hCL7D.js → startModuleRunner.DLjmA_wU.js} +209 -86
  34. package/dist/chunks/{test.B6aJd6T3.js → test.w5HLbjmU.js} +48 -22
  35. package/dist/chunks/{utils.CG9h5ccR.js → utils.DvEY5TfP.js} +14 -5
  36. package/dist/chunks/{vi.BZvkKVkM.js → vi.CyIUVSoU.js} +267 -117
  37. package/dist/chunks/{vm.BL7_zzOr.js → vm.DXN8eCh2.js} +181 -75
  38. package/dist/chunks/{worker.d.D25zYZ7N.d.ts → worker.d.ZGohxCEd.d.ts} +74 -7
  39. package/dist/cli.js +2 -2
  40. package/dist/config.d.ts +5 -5
  41. package/dist/coverage.d.ts +3 -3
  42. package/dist/coverage.js +1 -1
  43. package/dist/environments.js +1 -1
  44. package/dist/index.d.ts +5 -5
  45. package/dist/index.js +5 -5
  46. package/dist/module-evaluator.d.ts +2 -2
  47. package/dist/module-evaluator.js +88 -38
  48. package/dist/module-runner.js +2 -2
  49. package/dist/node.d.ts +7 -7
  50. package/dist/node.js +17 -13
  51. package/dist/reporters.d.ts +3 -3
  52. package/dist/reporters.js +2 -2
  53. package/dist/runners.js +7 -7
  54. package/dist/snapshot.js +2 -2
  55. package/dist/suite.js +2 -2
  56. package/dist/worker.d.ts +1 -1
  57. package/dist/worker.js +15 -15
  58. package/dist/workers/forks.js +16 -16
  59. package/dist/workers/runVmTests.js +41 -22
  60. package/dist/workers/threads.js +16 -16
  61. package/dist/workers/vmForks.js +11 -11
  62. package/dist/workers/vmThreads.js +11 -11
  63. package/package.json +20 -20
  64. package/dist/chunks/console.CTJL2nuH.js +0 -115
  65. package/dist/chunks/index.Bgo3tNWt.js +0 -176
@@ -1,115 +0,0 @@
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.-jtEtIeV.js';
7
- import { g as getWorkerState } from './utils.CG9h5ccR.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")), line = index === -1 ? null : stack[index + 2];
14
- if (!line) return UNKNOWN_TEST_ID;
15
- const filepath = line.match(/at\s(.*)\s?/)?.[1];
16
- return filepath ? relative(root, filepath) : UNKNOWN_TEST_ID;
17
- }
18
- function createCustomConsole(defaultState) {
19
- const stdoutBuffer = /* @__PURE__ */ new Map(), stderrBuffer = /* @__PURE__ */ new Map(), timers = /* @__PURE__ */ new Map(), { queueMicrotask } = getSafeTimers();
20
- function queueCancelableMicrotask(callback) {
21
- let canceled = false;
22
- return queueMicrotask(() => {
23
- if (!canceled) callback();
24
- }), () => {
25
- canceled = true;
26
- };
27
- }
28
- const state = () => defaultState || getWorkerState();
29
- // group sync console.log calls with micro task
30
- function schedule(taskId) {
31
- const timer = timers.get(taskId), { stdoutTime, stderrTime } = timer;
32
- timer.cancel?.(), timer.cancel = queueCancelableMicrotask(() => {
33
- if (stderrTime < stdoutTime) sendStderr(taskId), sendStdout(taskId);
34
- else sendStdout(taskId), sendStderr(taskId);
35
- });
36
- }
37
- function sendStdout(taskId) {
38
- sendBuffer("stdout", taskId);
39
- }
40
- function sendStderr(taskId) {
41
- sendBuffer("stderr", taskId);
42
- }
43
- function sendBuffer(type, taskId) {
44
- const buffers = type === "stdout" ? stdoutBuffer : stderrBuffer, buffer = buffers.get(taskId);
45
- if (!buffer) return;
46
- if (state().config.printConsoleTrace) buffer.forEach(([buffer, origin]) => {
47
- sendLog(type, taskId, String(buffer), buffer.length, origin);
48
- });
49
- else {
50
- const content = buffer.map((i) => String(i[0])).join("");
51
- sendLog(type, taskId, content, buffer.length);
52
- }
53
- const timer = timers.get(taskId);
54
- if (buffers.delete(taskId), type === "stderr") timer.stderrTime = 0;
55
- else timer.stdoutTime = 0;
56
- }
57
- function sendLog(type, taskId, content, size, origin) {
58
- const timer = timers.get(taskId), time = type === "stderr" ? timer.stderrTime : timer.stdoutTime;
59
- state().rpc.onUserConsoleLog({
60
- type,
61
- content: content || "<empty line>",
62
- taskId,
63
- time: time || RealDate.now(),
64
- size,
65
- origin
66
- });
67
- }
68
- const stdout = new Writable({ write(data, encoding, callback) {
69
- const s = state(), id = s?.current?.id || s?.current?.suite?.id || s.current?.file.id || getTaskIdByStack(s.config.root);
70
- let timer = timers.get(id);
71
- if (timer) timer.stdoutTime = timer.stdoutTime || RealDate.now();
72
- else timer = {
73
- stdoutTime: RealDate.now(),
74
- stderrTime: RealDate.now()
75
- }, timers.set(id, timer);
76
- let buffer = stdoutBuffer.get(id);
77
- if (!buffer) buffer = [], stdoutBuffer.set(id, buffer);
78
- if (state().config.printConsoleTrace) {
79
- const limit = Error.stackTraceLimit;
80
- Error.stackTraceLimit = limit + 6;
81
- const trace = (/* @__PURE__ */ new Error("STACK_TRACE")).stack?.split("\n").slice(7).join("\n");
82
- Error.stackTraceLimit = limit, buffer.push([data, trace]);
83
- } else buffer.push([data, void 0]);
84
- schedule(id), callback();
85
- } }), stderr = new Writable({ write(data, encoding, callback) {
86
- const s = state(), id = s?.current?.id || s?.current?.suite?.id || s.current?.file.id || getTaskIdByStack(s.config.root);
87
- let timer = timers.get(id);
88
- if (timer) timer.stderrTime = timer.stderrTime || RealDate.now();
89
- else timer = {
90
- stderrTime: RealDate.now(),
91
- stdoutTime: RealDate.now()
92
- }, timers.set(id, timer);
93
- let buffer = stderrBuffer.get(id);
94
- if (!buffer) buffer = [], stderrBuffer.set(id, buffer);
95
- if (state().config.printConsoleTrace) {
96
- const limit = Error.stackTraceLimit;
97
- Error.stackTraceLimit = limit + 6;
98
- const stack = (/* @__PURE__ */ new Error("STACK_TRACE")).stack?.split("\n");
99
- if (Error.stackTraceLimit = limit, stack?.some((line) => line.includes("at Console.trace"))) buffer.push([data, void 0]);
100
- else {
101
- const trace = stack?.slice(7).join("\n");
102
- Error.stackTraceLimit = limit, buffer.push([data, trace]);
103
- }
104
- } else buffer.push([data, void 0]);
105
- schedule(id), callback();
106
- } });
107
- return new Console({
108
- stdout,
109
- stderr,
110
- colorMode: c.isColorSupported,
111
- groupIndentation: 2
112
- });
113
- }
114
-
115
- export { UNKNOWN_TEST_ID, createCustomConsole };
@@ -1,176 +0,0 @@
1
- const TYPE_REQUEST = "q";
2
- const TYPE_RESPONSE = "s";
3
- const DEFAULT_TIMEOUT = 6e4;
4
- function defaultSerialize(i) {
5
- return i;
6
- }
7
- const defaultDeserialize = defaultSerialize;
8
- const { clearTimeout, setTimeout } = globalThis;
9
- const random = Math.random.bind(Math);
10
- function createBirpc(functions, options) {
11
- const {
12
- post,
13
- on,
14
- off = () => {
15
- },
16
- eventNames = [],
17
- serialize = defaultSerialize,
18
- deserialize = defaultDeserialize,
19
- resolver,
20
- bind = "rpc",
21
- timeout = DEFAULT_TIMEOUT
22
- } = options;
23
- const rpcPromiseMap = /* @__PURE__ */ new Map();
24
- let _promise;
25
- let closed = false;
26
- const rpc = new Proxy({}, {
27
- get(_, method) {
28
- if (method === "$functions")
29
- return functions;
30
- if (method === "$close")
31
- return close;
32
- if (method === "$rejectPendingCalls") {
33
- return rejectPendingCalls;
34
- }
35
- if (method === "$closed")
36
- return closed;
37
- if (method === "then" && !eventNames.includes("then") && !("then" in functions))
38
- return void 0;
39
- const sendEvent = (...args) => {
40
- post(serialize({ m: method, a: args, t: TYPE_REQUEST }));
41
- };
42
- if (eventNames.includes(method)) {
43
- sendEvent.asEvent = sendEvent;
44
- return sendEvent;
45
- }
46
- const sendCall = async (...args) => {
47
- if (closed)
48
- throw new Error(`[birpc] rpc is closed, cannot call "${method}"`);
49
- if (_promise) {
50
- try {
51
- await _promise;
52
- } finally {
53
- _promise = void 0;
54
- }
55
- }
56
- return new Promise((resolve, reject) => {
57
- const id = nanoid();
58
- let timeoutId;
59
- if (timeout >= 0) {
60
- timeoutId = setTimeout(() => {
61
- try {
62
- const handleResult = options.onTimeoutError?.(method, args);
63
- if (handleResult !== true)
64
- throw new Error(`[birpc] timeout on calling "${method}"`);
65
- } catch (e) {
66
- reject(e);
67
- }
68
- rpcPromiseMap.delete(id);
69
- }, timeout);
70
- if (typeof timeoutId === "object")
71
- timeoutId = timeoutId.unref?.();
72
- }
73
- rpcPromiseMap.set(id, { resolve, reject, timeoutId, method });
74
- post(serialize({ m: method, a: args, i: id, t: "q" }));
75
- });
76
- };
77
- sendCall.asEvent = sendEvent;
78
- return sendCall;
79
- }
80
- });
81
- function close(customError) {
82
- closed = true;
83
- rpcPromiseMap.forEach(({ reject, method }) => {
84
- const error = new Error(`[birpc] rpc is closed, cannot call "${method}"`);
85
- if (customError) {
86
- customError.cause ??= error;
87
- return reject(customError);
88
- }
89
- reject(error);
90
- });
91
- rpcPromiseMap.clear();
92
- off(onMessage);
93
- }
94
- function rejectPendingCalls(handler) {
95
- const entries = Array.from(rpcPromiseMap.values());
96
- const handlerResults = entries.map(({ method, reject }) => {
97
- if (!handler) {
98
- return reject(new Error(`[birpc]: rejected pending call "${method}".`));
99
- }
100
- return handler({ method, reject });
101
- });
102
- rpcPromiseMap.clear();
103
- return handlerResults;
104
- }
105
- async function onMessage(data, ...extra) {
106
- let msg;
107
- try {
108
- msg = deserialize(data);
109
- } catch (e) {
110
- if (options.onGeneralError?.(e) !== true)
111
- throw e;
112
- return;
113
- }
114
- if (msg.t === TYPE_REQUEST) {
115
- const { m: method, a: args } = msg;
116
- let result, error;
117
- const fn = resolver ? resolver(method, functions[method]) : functions[method];
118
- if (!fn) {
119
- error = new Error(`[birpc] function "${method}" not found`);
120
- } else {
121
- try {
122
- result = await fn.apply(bind === "rpc" ? rpc : functions, args);
123
- } catch (e) {
124
- error = e;
125
- }
126
- }
127
- if (msg.i) {
128
- if (error && options.onError)
129
- options.onError(error, method, args);
130
- if (error && options.onFunctionError) {
131
- if (options.onFunctionError(error, method, args) === true)
132
- return;
133
- }
134
- if (!error) {
135
- try {
136
- post(serialize({ t: TYPE_RESPONSE, i: msg.i, r: result }), ...extra);
137
- return;
138
- } catch (e) {
139
- error = e;
140
- if (options.onGeneralError?.(e, method, args) !== true)
141
- throw e;
142
- }
143
- }
144
- try {
145
- post(serialize({ t: TYPE_RESPONSE, i: msg.i, e: error }), ...extra);
146
- } catch (e) {
147
- if (options.onGeneralError?.(e, method, args) !== true)
148
- throw e;
149
- }
150
- }
151
- } else {
152
- const { i: ack, r: result, e: error } = msg;
153
- const promise = rpcPromiseMap.get(ack);
154
- if (promise) {
155
- clearTimeout(promise.timeoutId);
156
- if (error)
157
- promise.reject(error);
158
- else
159
- promise.resolve(result);
160
- }
161
- rpcPromiseMap.delete(ack);
162
- }
163
- }
164
- _promise = on(onMessage);
165
- return rpc;
166
- }
167
- const urlAlphabet = "useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict";
168
- function nanoid(size = 21) {
169
- let id = "";
170
- let i = size;
171
- while (i--)
172
- id += urlAlphabet[random() * 64 | 0];
173
- return id;
174
- }
175
-
176
- export { createBirpc as c };