vitest 3.0.9 → 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.
Files changed (85) hide show
  1. package/dist/browser.js +4 -4
  2. package/dist/chunks/base.CylSMlTD.js +41 -0
  3. package/dist/chunks/benchmark.BKUatJGy.js +39 -0
  4. package/dist/chunks/cac.JtTXbKz0.js +1525 -0
  5. package/dist/chunks/{cli-api.Ckwz_xSb.js → cli-api.BTtPTYMs.js} +4638 -5072
  6. package/dist/chunks/console.D6t261w0.js +173 -0
  7. package/dist/chunks/constants.BZZyIeIE.js +43 -0
  8. package/dist/chunks/coverage.0iPg4Wrz.js +33 -0
  9. package/dist/chunks/{coverage.gV8doR2Y.js → coverage.C2ohxaN0.js} +2216 -2479
  10. package/dist/chunks/creator.BEXek7yQ.js +640 -0
  11. package/dist/chunks/date.CDOsz-HY.js +53 -0
  12. package/dist/chunks/defaults.DmfNPoe5.js +114 -0
  13. package/dist/chunks/{env.D4Lgay0q.js → env.Dq0hM4Xv.js} +1 -1
  14. package/dist/chunks/execute.DZKwfrTs.js +791 -0
  15. package/dist/chunks/git.DXfdBEfR.js +74 -0
  16. package/dist/chunks/{globals.BEpDe-k3.js → globals.DCbUWjip.js} +10 -10
  17. package/dist/chunks/{index.D7Ny8f_s.js → index.BDobFbcz.js} +6 -7
  18. package/dist/chunks/index.DFXFpH3w.js +607 -0
  19. package/dist/chunks/index.VfYQ6MXY.js +104 -0
  20. package/dist/chunks/index.ZIOEXBQB.js +2382 -0
  21. package/dist/chunks/inspector.DbDkSkFn.js +54 -0
  22. package/dist/chunks/node.IqGoMrm4.js +15 -0
  23. package/dist/chunks/{reporters.d.CqBhtcTq.d.ts → reporters.d.5g6jXhoW.d.ts} +25 -8
  24. package/dist/chunks/rpc.DGgL5dw7.js +92 -0
  25. package/dist/chunks/run-once.I7PpBOk1.js +47 -0
  26. package/dist/chunks/runBaseTests.CqmKSG99.js +134 -0
  27. package/dist/chunks/setup-common.DEGDGBiA.js +88 -0
  28. package/dist/chunks/{typechecker.BlF3eHsb.js → typechecker.C2IpOhid.js} +620 -622
  29. package/dist/chunks/utils.BfxieIyZ.js +66 -0
  30. package/dist/chunks/utils.CtocqOoE.js +72 -0
  31. package/dist/chunks/utils.OLmtDstN.js +194 -0
  32. package/dist/chunks/{vi.nSCvwQ7l.js → vi.B-PuvDzu.js} +878 -1019
  33. package/dist/chunks/vite.d.Dh1jE-_V.d.ts +23 -0
  34. package/dist/chunks/vm.BW5voG-u.js +789 -0
  35. package/dist/cli.js +2 -2
  36. package/dist/config.cjs +97 -103
  37. package/dist/config.d.ts +3 -3
  38. package/dist/config.js +6 -6
  39. package/dist/coverage.d.ts +1 -1
  40. package/dist/coverage.js +6 -6
  41. package/dist/environments.js +1 -1
  42. package/dist/execute.js +1 -1
  43. package/dist/index.d.ts +2 -2
  44. package/dist/index.js +6 -6
  45. package/dist/node.d.ts +3 -3
  46. package/dist/node.js +36 -45
  47. package/dist/path.js +1 -4
  48. package/dist/reporters.d.ts +1 -1
  49. package/dist/reporters.js +4 -4
  50. package/dist/runners.js +231 -267
  51. package/dist/snapshot.js +2 -2
  52. package/dist/suite.js +2 -2
  53. package/dist/worker.js +98 -114
  54. package/dist/workers/forks.js +22 -22
  55. package/dist/workers/runVmTests.js +61 -66
  56. package/dist/workers/threads.js +13 -13
  57. package/dist/workers/vmForks.js +24 -24
  58. package/dist/workers/vmThreads.js +15 -15
  59. package/dist/workers.js +10 -10
  60. package/package.json +11 -11
  61. package/dist/chunks/base.DV59CbtV.js +0 -45
  62. package/dist/chunks/benchmark.DL72EVN-.js +0 -40
  63. package/dist/chunks/cac.CeVHgzve.js +0 -1659
  64. package/dist/chunks/console.CN7AiMGV.js +0 -179
  65. package/dist/chunks/constants.DTYd6dNH.js +0 -46
  66. package/dist/chunks/coverage.A3sS5-Wm.js +0 -40
  67. package/dist/chunks/creator.BsBnpTzI.js +0 -670
  68. package/dist/chunks/date.W2xKR2qe.js +0 -53
  69. package/dist/chunks/defaults.C2Ndd9wx.js +0 -119
  70. package/dist/chunks/execute.eDH0aFFd.js +0 -839
  71. package/dist/chunks/git.B5SDxu-n.js +0 -69
  72. package/dist/chunks/index.B8tIoLPT.js +0 -2526
  73. package/dist/chunks/index.K90BXFOx.js +0 -658
  74. package/dist/chunks/index.uXkkC4xl.js +0 -111
  75. package/dist/chunks/inspector.DKLceBVD.js +0 -54
  76. package/dist/chunks/node.AKq966Jp.js +0 -15
  77. package/dist/chunks/rpc.TVf73xOu.js +0 -102
  78. package/dist/chunks/run-once.2ogXb3JV.js +0 -28
  79. package/dist/chunks/runBaseTests.BVrL_ow3.js +0 -142
  80. package/dist/chunks/setup-common.CPvtqi8q.js +0 -96
  81. package/dist/chunks/utils.C8RiOc4B.js +0 -77
  82. package/dist/chunks/utils.Cn0zI1t3.js +0 -68
  83. package/dist/chunks/utils.bLM2atbD.js +0 -198
  84. package/dist/chunks/vite.d.BUZTGxQ3.d.ts +0 -11
  85. package/dist/chunks/vm.jEFQDlX_.js +0 -852
@@ -0,0 +1,66 @@
1
+ import { parseRegexp } from '@vitest/utils';
2
+
3
+ const REGEXP_WRAP_PREFIX = "$$vitest:";
4
+ const processSend = process.send?.bind(process);
5
+ const processOn = process.on?.bind(process);
6
+ const processOff = process.off?.bind(process);
7
+ const dispose = [];
8
+ function createThreadsRpcOptions({ port }) {
9
+ return {
10
+ post: (v) => {
11
+ port.postMessage(v);
12
+ },
13
+ on: (fn) => {
14
+ port.addListener("message", fn);
15
+ }
16
+ };
17
+ }
18
+ function disposeInternalListeners() {
19
+ for (const fn of dispose) {
20
+ try {
21
+ fn();
22
+ } catch {}
23
+ }
24
+ dispose.length = 0;
25
+ }
26
+ function createForksRpcOptions(nodeV8) {
27
+ return {
28
+ serialize: nodeV8.serialize,
29
+ deserialize: (v) => nodeV8.deserialize(Buffer.from(v)),
30
+ post(v) {
31
+ processSend(v);
32
+ },
33
+ on(fn) {
34
+ const handler = (message, ...extras) => {
35
+ if (message?.__tinypool_worker_message__) {
36
+ return;
37
+ }
38
+ return fn(message, ...extras);
39
+ };
40
+ processOn("message", handler);
41
+ dispose.push(() => processOff("message", handler));
42
+ }
43
+ };
44
+ }
45
+ /**
46
+ * Reverts the wrapping done by `utils/config-helpers.ts`'s `wrapSerializableConfig`
47
+ */
48
+ function unwrapSerializableConfig(config) {
49
+ if (config.testNamePattern && typeof config.testNamePattern === "string") {
50
+ const testNamePattern = config.testNamePattern;
51
+ if (testNamePattern.startsWith(REGEXP_WRAP_PREFIX)) {
52
+ config.testNamePattern = parseRegexp(testNamePattern.slice(REGEXP_WRAP_PREFIX.length));
53
+ }
54
+ }
55
+ if (config.defines && Array.isArray(config.defines.keys) && config.defines.original) {
56
+ const { keys, original } = config.defines;
57
+ const defines = {};
58
+ for (const key of keys) {
59
+ defines[key] = original[key];
60
+ }
61
+ config.defines = defines;
62
+ }
63
+ return config;
64
+ }
65
+
66
+ export { createThreadsRpcOptions as a, createForksRpcOptions as c, disposeInternalListeners as d, unwrapSerializableConfig as u };
@@ -0,0 +1,72 @@
1
+ import { getSafeTimers } from '@vitest/utils';
2
+
3
+ const NAME_WORKER_STATE = "__vitest_worker__";
4
+ function getWorkerState() {
5
+ const workerState = globalThis[NAME_WORKER_STATE];
6
+ if (!workerState) {
7
+ const errorMsg = "Vitest failed to access its internal state." + "\n\nOne of the following is possible:" + "\n- \"vitest\" is imported directly without running \"vitest\" command" + "\n- \"vitest\" is imported inside \"globalSetup\" (to fix this, use \"setupFiles\" instead, because \"globalSetup\" runs in a different context)" + "\n- Otherwise, it might be a Vitest bug. Please report it to https://github.com/vitest-dev/vitest/issues\n";
8
+ throw new Error(errorMsg);
9
+ }
10
+ return workerState;
11
+ }
12
+ function provideWorkerState(context, state) {
13
+ Object.defineProperty(context, NAME_WORKER_STATE, {
14
+ value: state,
15
+ configurable: true,
16
+ writable: true,
17
+ enumerable: false
18
+ });
19
+ return state;
20
+ }
21
+ function getCurrentEnvironment() {
22
+ const state = getWorkerState();
23
+ return state?.environment.name;
24
+ }
25
+ function isChildProcess() {
26
+ return typeof process !== "undefined" && !!process.send;
27
+ }
28
+ function setProcessTitle(title) {
29
+ try {
30
+ process.title = `node (${title})`;
31
+ } catch {}
32
+ }
33
+ function resetModules(modules, resetMocks = false) {
34
+ const skipPaths = [
35
+ /\/vitest\/dist\//,
36
+ /\/vite-node\/dist\//,
37
+ /vitest-virtual-\w+\/dist/,
38
+ /@vitest\/dist/,
39
+ ...!resetMocks ? [/^mock:/] : []
40
+ ];
41
+ modules.forEach((mod, path) => {
42
+ if (skipPaths.some((re) => re.test(path))) {
43
+ return;
44
+ }
45
+ modules.invalidateModule(mod);
46
+ });
47
+ }
48
+ function waitNextTick() {
49
+ const { setTimeout } = getSafeTimers();
50
+ return new Promise((resolve) => setTimeout(resolve, 0));
51
+ }
52
+ async function waitForImportsToResolve() {
53
+ await waitNextTick();
54
+ const state = getWorkerState();
55
+ const promises = [];
56
+ let resolvingCount = 0;
57
+ for (const mod of state.moduleCache.values()) {
58
+ if (mod.promise && !mod.evaluated) {
59
+ promises.push(mod.promise);
60
+ }
61
+ if (mod.resolving) {
62
+ resolvingCount++;
63
+ }
64
+ }
65
+ if (!promises.length && !resolvingCount) {
66
+ return;
67
+ }
68
+ await Promise.allSettled(promises);
69
+ await waitForImportsToResolve();
70
+ }
71
+
72
+ export { getCurrentEnvironment as a, getWorkerState as g, isChildProcess as i, provideWorkerState as p, resetModules as r, setProcessTitle as s, waitForImportsToResolve as w };
@@ -0,0 +1,194 @@
1
+ import { stripVTControlCharacters } from 'node:util';
2
+ import { slash } from '@vitest/utils';
3
+ import { isAbsolute, relative, dirname, basename } from 'pathe';
4
+ import c from 'tinyrainbow';
5
+
6
+ const F_RIGHT = "→";
7
+ const F_DOWN = "↓";
8
+ const F_DOWN_RIGHT = "↳";
9
+ const F_POINTER = "❯";
10
+ const F_DOT = "·";
11
+ const F_CHECK = "✓";
12
+ const F_CROSS = "×";
13
+ const F_LONG_DASH = "⎯";
14
+ const F_TREE_NODE_MIDDLE = "├──";
15
+ const F_TREE_NODE_END = "└──";
16
+
17
+ const pointer = c.yellow(F_POINTER);
18
+ const skipped = c.dim(c.gray(F_DOWN));
19
+ const benchmarkPass = c.green(F_DOT);
20
+ const testPass = c.green(F_CHECK);
21
+ const taskFail = c.red(F_CROSS);
22
+ const suiteFail = c.red(F_POINTER);
23
+ const pending = c.gray("·");
24
+ function getCols(delta = 0) {
25
+ let length = process.stdout?.columns;
26
+ if (!length || Number.isNaN(length)) {
27
+ length = 30;
28
+ }
29
+ return Math.max(length + delta, 0);
30
+ }
31
+ function divider(text, left, right) {
32
+ const cols = getCols();
33
+ if (text) {
34
+ const textLength = stripVTControlCharacters(text).length;
35
+ if (left == null && right != null) {
36
+ left = cols - textLength - right;
37
+ } else {
38
+ left = left ?? Math.floor((cols - textLength) / 2);
39
+ right = cols - textLength - left;
40
+ }
41
+ left = Math.max(0, left);
42
+ right = Math.max(0, right);
43
+ return `${F_LONG_DASH.repeat(left)}${text}${F_LONG_DASH.repeat(right)}`;
44
+ }
45
+ return F_LONG_DASH.repeat(cols);
46
+ }
47
+ function formatTestPath(root, path) {
48
+ if (isAbsolute(path)) {
49
+ path = relative(root, path);
50
+ }
51
+ const dir = dirname(path);
52
+ const ext = path.match(/(\.(spec|test)\.[cm]?[tj]sx?)$/)?.[0] || "";
53
+ const base = basename(path, ext);
54
+ return slash(c.dim(`${dir}/`) + c.bold(base)) + c.dim(ext);
55
+ }
56
+ function renderSnapshotSummary(rootDir, snapshots) {
57
+ const summary = [];
58
+ if (snapshots.added) {
59
+ summary.push(c.bold(c.green(`${snapshots.added} written`)));
60
+ }
61
+ if (snapshots.unmatched) {
62
+ summary.push(c.bold(c.red(`${snapshots.unmatched} failed`)));
63
+ }
64
+ if (snapshots.updated) {
65
+ summary.push(c.bold(c.green(`${snapshots.updated} updated `)));
66
+ }
67
+ if (snapshots.filesRemoved) {
68
+ if (snapshots.didUpdate) {
69
+ summary.push(c.bold(c.green(`${snapshots.filesRemoved} files removed `)));
70
+ } else {
71
+ summary.push(c.bold(c.yellow(`${snapshots.filesRemoved} files obsolete `)));
72
+ }
73
+ }
74
+ if (snapshots.filesRemovedList && snapshots.filesRemovedList.length) {
75
+ const [head, ...tail] = snapshots.filesRemovedList;
76
+ summary.push(`${c.gray(F_DOWN_RIGHT)} ${formatTestPath(rootDir, head)}`);
77
+ tail.forEach((key) => {
78
+ summary.push(` ${c.gray(F_DOT)} ${formatTestPath(rootDir, key)}`);
79
+ });
80
+ }
81
+ if (snapshots.unchecked) {
82
+ if (snapshots.didUpdate) {
83
+ summary.push(c.bold(c.green(`${snapshots.unchecked} removed`)));
84
+ } else {
85
+ summary.push(c.bold(c.yellow(`${snapshots.unchecked} obsolete`)));
86
+ }
87
+ snapshots.uncheckedKeysByFile.forEach((uncheckedFile) => {
88
+ summary.push(`${c.gray(F_DOWN_RIGHT)} ${formatTestPath(rootDir, uncheckedFile.filePath)}`);
89
+ uncheckedFile.keys.forEach((key) => summary.push(` ${c.gray(F_DOT)} ${key}`));
90
+ });
91
+ }
92
+ return summary;
93
+ }
94
+ function countTestErrors(tasks) {
95
+ return tasks.reduce((c, i) => c + (i.result?.errors?.length || 0), 0);
96
+ }
97
+ function getStateString(tasks, name = "tests", showTotal = true) {
98
+ if (tasks.length === 0) {
99
+ return c.dim(`no ${name}`);
100
+ }
101
+ const passed = tasks.filter((i) => i.result?.state === "pass");
102
+ const failed = tasks.filter((i) => i.result?.state === "fail");
103
+ const skipped = tasks.filter((i) => i.mode === "skip");
104
+ const todo = tasks.filter((i) => i.mode === "todo");
105
+ return [
106
+ failed.length ? c.bold(c.red(`${failed.length} failed`)) : null,
107
+ passed.length ? c.bold(c.green(`${passed.length} passed`)) : null,
108
+ skipped.length ? c.yellow(`${skipped.length} skipped`) : null,
109
+ todo.length ? c.gray(`${todo.length} todo`) : null
110
+ ].filter(Boolean).join(c.dim(" | ")) + (showTotal ? c.gray(` (${tasks.length})`) : "");
111
+ }
112
+ function getStateSymbol(task) {
113
+ if (task.mode === "skip" || task.mode === "todo") {
114
+ return skipped;
115
+ }
116
+ if (!task.result) {
117
+ return pending;
118
+ }
119
+ if (task.result.state === "run" || task.result.state === "queued") {
120
+ if (task.type === "suite") {
121
+ return pointer;
122
+ }
123
+ }
124
+ if (task.result.state === "pass") {
125
+ return task.meta?.benchmark ? benchmarkPass : testPass;
126
+ }
127
+ if (task.result.state === "fail") {
128
+ return task.type === "suite" ? suiteFail : taskFail;
129
+ }
130
+ return " ";
131
+ }
132
+ function formatTimeString(date) {
133
+ return date.toTimeString().split(" ")[0];
134
+ }
135
+ function formatTime(time) {
136
+ if (time > 1e3) {
137
+ return `${(time / 1e3).toFixed(2)}s`;
138
+ }
139
+ return `${Math.round(time)}ms`;
140
+ }
141
+ function formatProjectName(name, suffix = " ") {
142
+ if (!name) {
143
+ return "";
144
+ }
145
+ if (!c.isColorSupported) {
146
+ return `|${name}|${suffix}`;
147
+ }
148
+ const index = name.split("").reduce((acc, v, idx) => acc + v.charCodeAt(0) + idx, 0);
149
+ const colors = [
150
+ c.bgYellow,
151
+ c.bgCyan,
152
+ c.bgGreen,
153
+ c.bgMagenta
154
+ ];
155
+ return c.black(colors[index % colors.length](` ${name} `)) + suffix;
156
+ }
157
+ function withLabel(color, label, message) {
158
+ return `${c.bold(c.inverse(c[color](` ${label} `)))} ${message ? c[color](message) : ""}`;
159
+ }
160
+ function padSummaryTitle(str) {
161
+ return c.dim(`${str.padStart(11)} `);
162
+ }
163
+ function truncateString(text, maxLength) {
164
+ const plainText = stripVTControlCharacters(text);
165
+ if (plainText.length <= maxLength) {
166
+ return text;
167
+ }
168
+ return `${plainText.slice(0, maxLength - 1)}…`;
169
+ }
170
+
171
+ var utils = /*#__PURE__*/Object.freeze({
172
+ __proto__: null,
173
+ benchmarkPass: benchmarkPass,
174
+ countTestErrors: countTestErrors,
175
+ divider: divider,
176
+ formatProjectName: formatProjectName,
177
+ formatTestPath: formatTestPath,
178
+ formatTime: formatTime,
179
+ formatTimeString: formatTimeString,
180
+ getStateString: getStateString,
181
+ getStateSymbol: getStateSymbol,
182
+ padSummaryTitle: padSummaryTitle,
183
+ pending: pending,
184
+ pointer: pointer,
185
+ renderSnapshotSummary: renderSnapshotSummary,
186
+ skipped: skipped,
187
+ suiteFail: suiteFail,
188
+ taskFail: taskFail,
189
+ testPass: testPass,
190
+ truncateString: truncateString,
191
+ withLabel: withLabel
192
+ });
193
+
194
+ export { F_POINTER as F, formatProjectName as a, taskFail as b, F_CHECK as c, divider as d, F_RIGHT as e, formatTimeString as f, getStateSymbol as g, getStateString as h, formatTime as i, countTestErrors as j, F_TREE_NODE_END as k, F_TREE_NODE_MIDDLE as l, padSummaryTitle as p, renderSnapshotSummary as r, truncateString as t, utils as u, withLabel as w };