vitest 4.0.0-beta.1 → 4.0.0-beta.11
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 +83 -2
- package/dist/browser.d.ts +19 -16
- package/dist/browser.js +11 -7
- package/dist/chunks/{benchmark.CYdenmiT.js → benchmark.LXhJ0F0X.js} +7 -9
- package/dist/chunks/{benchmark.d.BwvBVTda.d.ts → benchmark.d.DAaHLpsq.d.ts} +4 -4
- package/dist/chunks/{browser.d.q8Z0P0q1.d.ts → browser.d.Dx7DO_Ce.d.ts} +5 -5
- package/dist/chunks/{cac.D3EzDDZd.js → cac.elvK37c9.js} +71 -153
- package/dist/chunks/{cli-api.Dn5gKePv.js → cli-api.C7plPyhs.js} +1376 -1693
- package/dist/chunks/{config.d.HJdfX-8k.d.ts → config.d.B_LthbQq.d.ts} +58 -63
- package/dist/chunks/{console.CtFJOzRO.js → console.CiTi59Jy.js} +35 -71
- package/dist/chunks/{constants.DnKduX2e.js → constants.D_Q9UYh-.js} +1 -9
- package/dist/chunks/{coverage.Cwa-XhJt.js → coverage.CG6Uhorw.js} +522 -792
- package/dist/chunks/{coverage.DVF1vEu8.js → coverage.D_JHT54q.js} +2 -2
- package/dist/chunks/{coverage.d.S9RMNXIe.d.ts → coverage.d.BZtK59WP.d.ts} +10 -8
- package/dist/chunks/{creator.GK6I-cL4.js → creator.08Gi-vCA.js} +93 -77
- package/dist/chunks/{date.Bq6ZW5rf.js → date.-jtEtIeV.js} +6 -17
- package/dist/chunks/{environment.d.CUq4cUgQ.d.ts → environment.d.BsToaxti.d.ts} +27 -6
- package/dist/chunks/{git.BVQ8w_Sw.js → git.BFNcloKD.js} +1 -2
- package/dist/chunks/{global.d.CVbXEflG.d.ts → global.d.BK3X7FW1.d.ts} +2 -5
- package/dist/chunks/{globals.Cxal6MLI.js → globals.BjvYA-AD.js} +11 -9
- package/dist/chunks/{index.BWf_gE5n.js → index.AZOjjqWP.js} +7 -6
- package/dist/chunks/{index.B521nVV-.js → index.Bgo3tNWt.js} +23 -4
- package/dist/chunks/{index.TfbsX-3I.js → index.BhY64fF0.js} +16 -26
- package/dist/chunks/{index.CZI_8rVt.js → index.BwBttQPf.js} +340 -663
- package/dist/chunks/{index.CmSc2RE5.js → index.DIWhzsUh.js} +72 -118
- package/dist/chunks/{inspector.C914Efll.js → inspector.CvQD-Nie.js} +10 -25
- package/dist/chunks/moduleRunner.d.BNa-CL9e.d.ts +201 -0
- package/dist/chunks/{node.fjCdwEIl.js → node.BsdMi6DV.js} +2 -2
- package/dist/chunks/{plugin.d.C2EcJUjo.d.ts → plugin.d.C5phQR6o.d.ts} +1 -1
- package/dist/chunks/{reporters.d.DxZg19fy.d.ts → reporters.d.CVzhsTvK.d.ts} +1233 -1293
- package/dist/chunks/resolveSnapshotEnvironment.DQVamkje.js +81 -0
- package/dist/chunks/rpc.jKGRSXIH.js +65 -0
- package/dist/chunks/{setup-common.D7ZqXFx-.js → setup-common.NAWRuMRP.js} +18 -30
- package/dist/chunks/startModuleRunner.oAuCu1yL.js +682 -0
- package/dist/chunks/{suite.d.FvehnV49.d.ts → suite.d.BJWk38HB.d.ts} +1 -1
- package/dist/chunks/test.KC5tH8hC.js +214 -0
- package/dist/chunks/typechecker.gXq-5P3n.js +1438 -0
- package/dist/chunks/{utils.XdZDrNZV.js → utils.DGKhod2J.js} +9 -28
- package/dist/chunks/{vi.bdSIJ99Y.js → vi.CiJ0Laa6.js} +159 -306
- package/dist/chunks/worker.d.B_Fd9M_w.d.ts +100 -0
- package/dist/chunks/worker.rPGLlbkW.js +200 -0
- package/dist/cli.js +8 -6
- package/dist/config.cjs +3 -9
- package/dist/config.d.ts +49 -54
- package/dist/config.js +1 -1
- package/dist/coverage.d.ts +27 -26
- package/dist/coverage.js +6 -8
- package/dist/environments.d.ts +9 -13
- package/dist/environments.js +1 -1
- package/dist/index.d.ts +38 -45
- package/dist/index.js +10 -10
- package/dist/module-evaluator.d.ts +13 -0
- package/dist/module-evaluator.js +276 -0
- package/dist/module-runner.js +15 -0
- package/dist/node.d.ts +44 -42
- package/dist/node.js +30 -36
- package/dist/reporters.d.ts +12 -13
- package/dist/reporters.js +7 -5
- package/dist/runners.d.ts +3 -3
- package/dist/runners.js +15 -232
- package/dist/snapshot.js +3 -3
- package/dist/suite.d.ts +2 -2
- package/dist/suite.js +4 -3
- package/dist/worker-base.js +203 -0
- package/dist/{chunks/vm.BThCzidc.js → worker-vm.js} +179 -228
- package/dist/workers/runVmTests.js +39 -56
- package/globals.d.ts +17 -17
- package/package.json +40 -38
- package/browser.d.ts +0 -1
- package/dist/chunks/base.Bj3pWTr1.js +0 -38
- package/dist/chunks/execute.B7h3T_Hc.js +0 -708
- package/dist/chunks/index.D-VkfKhf.js +0 -105
- package/dist/chunks/rpc.CsFtxqeq.js +0 -83
- package/dist/chunks/runBaseTests.BC7ZIH5L.js +0 -129
- package/dist/chunks/typechecker.CVytUJuF.js +0 -874
- package/dist/chunks/utils.CAioKnHs.js +0 -61
- package/dist/chunks/worker.d.CmvJfRGs.d.ts +0 -8
- package/dist/chunks/worker.d.DoNjFAiv.d.ts +0 -169
- package/dist/execute.d.ts +0 -148
- package/dist/execute.js +0 -13
- package/dist/worker.js +0 -124
- package/dist/workers/forks.js +0 -43
- package/dist/workers/threads.js +0 -31
- package/dist/workers/vmForks.js +0 -47
- package/dist/workers/vmThreads.js +0 -37
- package/dist/workers.d.ts +0 -37
- package/dist/workers.js +0 -30
- package/execute.d.ts +0 -1
- package/utils.d.ts +0 -1
- package/workers.d.ts +0 -1
|
@@ -29,10 +29,13 @@ function createBirpc(functions, options) {
|
|
|
29
29
|
return functions;
|
|
30
30
|
if (method === "$close")
|
|
31
31
|
return close;
|
|
32
|
+
if (method === "$rejectPendingCalls") {
|
|
33
|
+
return rejectPendingCalls;
|
|
34
|
+
}
|
|
32
35
|
if (method === "$closed")
|
|
33
36
|
return closed;
|
|
34
37
|
if (method === "then" && !eventNames.includes("then") && !("then" in functions))
|
|
35
|
-
return
|
|
38
|
+
return void 0;
|
|
36
39
|
const sendEvent = (...args) => {
|
|
37
40
|
post(serialize({ m: method, a: args, t: TYPE_REQUEST }));
|
|
38
41
|
};
|
|
@@ -47,7 +50,7 @@ function createBirpc(functions, options) {
|
|
|
47
50
|
try {
|
|
48
51
|
await _promise;
|
|
49
52
|
} finally {
|
|
50
|
-
_promise =
|
|
53
|
+
_promise = void 0;
|
|
51
54
|
}
|
|
52
55
|
}
|
|
53
56
|
return new Promise((resolve, reject) => {
|
|
@@ -75,14 +78,30 @@ function createBirpc(functions, options) {
|
|
|
75
78
|
return sendCall;
|
|
76
79
|
}
|
|
77
80
|
});
|
|
78
|
-
function close(
|
|
81
|
+
function close(customError) {
|
|
79
82
|
closed = true;
|
|
80
83
|
rpcPromiseMap.forEach(({ reject, method }) => {
|
|
81
|
-
|
|
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);
|
|
82
90
|
});
|
|
83
91
|
rpcPromiseMap.clear();
|
|
84
92
|
off(onMessage);
|
|
85
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
|
+
}
|
|
86
105
|
async function onMessage(data, ...extra) {
|
|
87
106
|
let msg;
|
|
88
107
|
try {
|
|
@@ -2,9 +2,9 @@ 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 } 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.BwBttQPf.js';
|
|
6
6
|
import { stripVTControlCharacters } from 'node:util';
|
|
7
|
-
import { notNullish } from '@vitest/utils';
|
|
7
|
+
import { notNullish } from '@vitest/utils/helpers';
|
|
8
8
|
|
|
9
9
|
function createBenchmarkJsonReport(files) {
|
|
10
10
|
const report = { files: [] };
|
|
@@ -98,19 +98,16 @@ function renderBenchmark(result, widths) {
|
|
|
98
98
|
].join(" ");
|
|
99
99
|
}
|
|
100
100
|
function renderTable(options) {
|
|
101
|
-
const output = [];
|
|
102
|
-
const benchMap = {};
|
|
101
|
+
const output = [], benchMap = {};
|
|
103
102
|
for (const task of options.tasks) if (task.meta.benchmark && task.result?.benchmark) benchMap[task.id] = {
|
|
104
103
|
current: task.result.benchmark,
|
|
105
104
|
baseline: options.compare?.[task.id]
|
|
106
105
|
};
|
|
107
|
-
const benchCount = Object.entries(benchMap).length;
|
|
108
|
-
const columnWidths = computeColumnWidths(Object.values(benchMap).flatMap((v) => [v.current, v.baseline]).filter(notNullish));
|
|
106
|
+
const benchCount = Object.entries(benchMap).length, columnWidths = computeColumnWidths(Object.values(benchMap).flatMap((v) => [v.current, v.baseline]).filter(notNullish));
|
|
109
107
|
let idx = 0;
|
|
110
108
|
const padding = " ".repeat(1 );
|
|
111
109
|
for (const task of options.tasks) {
|
|
112
|
-
const duration = task.result?.duration;
|
|
113
|
-
const bench = benchMap[task.id];
|
|
110
|
+
const duration = task.result?.duration, bench = benchMap[task.id];
|
|
114
111
|
let prefix = "";
|
|
115
112
|
if (idx === 0 && task.meta?.benchmark) prefix += `${renderTableHead(columnWidths)}\n${padding}`;
|
|
116
113
|
prefix += ` ${getStateSymbol(task)} `;
|
|
@@ -126,8 +123,7 @@ function renderTable(options) {
|
|
|
126
123
|
let body = renderBenchmark(bench.current, columnWidths);
|
|
127
124
|
if (options.compare && bench.baseline) {
|
|
128
125
|
if (bench.current.hz) {
|
|
129
|
-
const diff = bench.current.hz / bench.baseline.hz;
|
|
130
|
-
const diffFixed = diff.toFixed(2);
|
|
126
|
+
const diff = bench.current.hz / bench.baseline.hz, diffFixed = diff.toFixed(2);
|
|
131
127
|
if (diffFixed === "1.0.0") body += c.gray(` [${diffFixed}x]`);
|
|
132
128
|
if (diff > 1) body += c.blue(` [${diffFixed}x] ⇑`);
|
|
133
129
|
else body += c.red(` [${diffFixed}x] ⇓`);
|
|
@@ -144,8 +140,7 @@ function renderTable(options) {
|
|
|
144
140
|
if (task.result?.state !== "pass" && outputMap.get(task) != null) {
|
|
145
141
|
let data = outputMap.get(task);
|
|
146
142
|
if (typeof data === "string") {
|
|
147
|
-
data = stripVTControlCharacters(data.trim().split("\n").filter(Boolean).pop());
|
|
148
|
-
if (data === "") data = void 0;
|
|
143
|
+
if (data = stripVTControlCharacters(data.trim().split("\n").filter(Boolean).pop()), data === "") data = void 0;
|
|
149
144
|
}
|
|
150
145
|
if (data != null) {
|
|
151
146
|
const out = ` ${" ".repeat(options.level)}${F_RIGHT} ${data}`;
|
|
@@ -160,8 +155,7 @@ function renderTable(options) {
|
|
|
160
155
|
class BenchmarkReporter extends DefaultReporter {
|
|
161
156
|
compare;
|
|
162
157
|
async onInit(ctx) {
|
|
163
|
-
super.onInit(ctx)
|
|
164
|
-
if (this.ctx.config.benchmark?.compare) {
|
|
158
|
+
if (super.onInit(ctx), this.ctx.config.benchmark?.compare) {
|
|
165
159
|
const compareFile = pathe.resolve(this.ctx.config.root, this.ctx.config.benchmark?.compare);
|
|
166
160
|
try {
|
|
167
161
|
this.compare = flattenFormattedBenchmarkReport(JSON.parse(await fs.promises.readFile(compareFile, "utf-8")));
|
|
@@ -179,8 +173,7 @@ class BenchmarkReporter extends DefaultReporter {
|
|
|
179
173
|
}
|
|
180
174
|
}
|
|
181
175
|
onTestSuiteResult(testSuite) {
|
|
182
|
-
super.onTestSuiteResult(testSuite);
|
|
183
|
-
this.printSuiteTable(testSuite);
|
|
176
|
+
super.onTestSuiteResult(testSuite), this.printSuiteTable(testSuite);
|
|
184
177
|
}
|
|
185
178
|
printTestModule(testModule) {
|
|
186
179
|
this.printSuiteTable(testModule);
|
|
@@ -188,13 +181,11 @@ class BenchmarkReporter extends DefaultReporter {
|
|
|
188
181
|
printSuiteTable(testTask) {
|
|
189
182
|
const state = testTask.state();
|
|
190
183
|
if (state === "pending" || state === "queued") return;
|
|
191
|
-
const benches = testTask.task.tasks.filter((t) => t.meta.benchmark);
|
|
192
|
-
const duration = testTask.task.result?.duration || 0;
|
|
184
|
+
const benches = testTask.task.tasks.filter((t) => t.meta.benchmark), duration = testTask.task.result?.duration || 0;
|
|
193
185
|
if (benches.length > 0 && benches.every((t) => t.result?.state !== "run" && t.result?.state !== "queued")) {
|
|
194
|
-
let title = `\n ${getStateSymbol(testTask.task)} ${formatProjectName(testTask.project)}${getFullName(testTask.task,
|
|
186
|
+
let title = `\n ${getStateSymbol(testTask.task)} ${formatProjectName(testTask.project)}${getFullName(testTask.task, separator)}`;
|
|
195
187
|
if (duration != null && duration > this.ctx.config.slowTestThreshold) title += c.yellow(` ${Math.round(duration)}${c.dim("ms")}`);
|
|
196
|
-
this.log(title)
|
|
197
|
-
this.log(renderTable({
|
|
188
|
+
this.log(title), this.log(renderTable({
|
|
198
189
|
tasks: benches,
|
|
199
190
|
level: 1,
|
|
200
191
|
columns: this.ctx.logger.getColumns(),
|
|
@@ -204,17 +195,16 @@ class BenchmarkReporter extends DefaultReporter {
|
|
|
204
195
|
}));
|
|
205
196
|
}
|
|
206
197
|
}
|
|
207
|
-
async
|
|
208
|
-
super.
|
|
198
|
+
async onTestRunEnd(testModules, unhandledErrors, reason) {
|
|
199
|
+
super.onTestRunEnd(testModules, unhandledErrors, reason);
|
|
209
200
|
// write output for future comparison
|
|
210
201
|
let outputFile = this.ctx.config.benchmark?.outputJson;
|
|
211
202
|
if (outputFile) {
|
|
212
203
|
outputFile = pathe.resolve(this.ctx.config.root, outputFile);
|
|
213
204
|
const outputDirectory = pathe.dirname(outputFile);
|
|
214
205
|
if (!fs.existsSync(outputDirectory)) await fs.promises.mkdir(outputDirectory, { recursive: true });
|
|
215
|
-
const output = createBenchmarkJsonReport(files);
|
|
216
|
-
await fs.promises.writeFile(outputFile, JSON.stringify(output, null, 2));
|
|
217
|
-
this.log(`Benchmark report written to ${outputFile}`);
|
|
206
|
+
const files = testModules.map((t) => t.task.file), output = createBenchmarkJsonReport(files);
|
|
207
|
+
await fs.promises.writeFile(outputFile, JSON.stringify(output, null, 2)), this.log(`Benchmark report written to ${outputFile}`);
|
|
218
208
|
}
|
|
219
209
|
}
|
|
220
210
|
}
|