@depup/vitest 4.1.1-depup.0 → 4.1.2-depup.0
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/README.md +4 -4
- package/changes.json +6 -6
- package/dist/browser.d.ts +1 -1
- package/dist/browser.js +1 -1
- package/dist/chunks/{base.C9_VThnT.js → base.BPik1OqN.js} +7 -7
- package/dist/chunks/{benchmark.D0SlKNbZ.js → benchmark.CX_oY03V.js} +1 -1
- package/dist/chunks/{browser.d.X3SXoOCV.d.ts → browser.d.BMOr_Kmk.d.ts} +1 -1
- package/dist/chunks/{cac.CHfKU_gf.js → cac.DRKYQDPl.js} +10 -8
- package/dist/chunks/{cli-api.BUXBO6jS.js → cli-api.Bxr1Nn49.js} +8 -6
- package/dist/chunks/{config.d.EJLVE3es.d.ts → config.d.Cz9kPrQs.d.ts} +1 -0
- package/dist/chunks/{coverage.CJ2HXVIG.js → coverage.kqM80boz.js} +12 -3
- package/dist/chunks/{defaults.CdU2lD-q.js → defaults.9aQKnqFk.js} +13 -5
- package/dist/chunks/{globals.8mibwXRO.js → globals.CVqIbOyt.js} +3 -3
- package/dist/chunks/{index.DXMFO5MJ.js → index.0GYC6HAu.js} +627 -586
- package/dist/chunks/{index.Dkvtd-Ku.js → index.DOa3dzoN.js} +2 -2
- package/dist/chunks/{index.6q6giCZO.js → index.nZ2xqFgD.js} +2 -2
- package/dist/chunks/{init-forks.B4YYSIj4.js → init-forks.UV3ZQGQH.js} +1 -1
- package/dist/chunks/{init-threads.Bd2Hsaex.js → init-threads.D3eCsY76.js} +1 -1
- package/dist/chunks/{init.BVxhC4nR.js → init.D98-gwRW.js} +3 -1
- package/dist/chunks/{nativeModuleMocker.Dd1Q1VIw.js → nativeModuleMocker.BRN2oBJd.js} +1 -1
- package/dist/chunks/{plugin.d.Dx0ozo6e.d.ts → plugin.d.BWbK_Jpw.d.ts} +1 -1
- package/dist/chunks/{reporters.d.CZ5E0GCT.d.ts → reporters.d.B0uk8id2.d.ts} +6 -8
- package/dist/chunks/{setup-common.CB31_KSV.js → setup-common.2wZXQUjS.js} +1 -1
- package/dist/chunks/{startVitestModuleRunner.C3FXk5Gv.js → startVitestModuleRunner.bRl2_oI_.js} +16 -2
- package/dist/chunks/{test.CBQUpOM3.js → test.p_J6dB8a.js} +1 -1
- package/dist/chunks/utils.DK8FXp4T.js +189 -0
- package/dist/chunks/{vm.DId8XBJa.js → vm.BvVhnZPV.js} +2 -2
- package/dist/chunks/{worker.d.B84sVRy0.d.ts → worker.d.BT5j8dyR.d.ts} +1 -1
- package/dist/cli.js +2 -20
- package/dist/config.cjs +13 -5
- package/dist/config.d.ts +8 -8
- package/dist/config.js +1 -1
- package/dist/coverage.d.ts +4 -4
- package/dist/coverage.js +2 -2
- package/dist/index.d.ts +6 -6
- package/dist/index.js +3 -3
- package/dist/node.d.ts +7 -7
- package/dist/node.js +8 -8
- package/dist/reporters.d.ts +4 -4
- package/dist/reporters.js +6 -6
- package/dist/runners.d.ts +1 -1
- package/dist/runners.js +2 -2
- package/dist/runtime.js +1 -1
- package/dist/suite.js +1 -1
- package/dist/worker.d.ts +2 -2
- package/dist/worker.js +9 -8
- package/dist/workers/forks.js +10 -9
- package/dist/workers/runVmTests.js +5 -5
- package/dist/workers/threads.js +10 -9
- package/dist/workers/vmForks.js +5 -5
- package/dist/workers/vmThreads.js +5 -5
- package/package.json +22 -22
- package/dist/chunks/index.CEzQDJGb.js +0 -231
|
@@ -1,231 +0,0 @@
|
|
|
1
|
-
import fs from 'node:fs';
|
|
2
|
-
import { getTasks, getFullName, getTests } from '@vitest/runner/utils';
|
|
3
|
-
import * as pathe from 'pathe';
|
|
4
|
-
import c from 'tinyrainbow';
|
|
5
|
-
import { g as getStateSymbol, t as truncateString, F as F_RIGHT, D as DefaultReporter, f as formatProjectName, s as separator } from './index.DXMFO5MJ.js';
|
|
6
|
-
import { stripVTControlCharacters } from 'node:util';
|
|
7
|
-
import { notNullish } from '@vitest/utils/helpers';
|
|
8
|
-
|
|
9
|
-
function createBenchmarkJsonReport(files) {
|
|
10
|
-
const report = { files: [] };
|
|
11
|
-
for (const file of files) {
|
|
12
|
-
const groups = [];
|
|
13
|
-
for (const task of getTasks(file)) if (task?.type === "suite") {
|
|
14
|
-
const benchmarks = [];
|
|
15
|
-
for (const t of task.tasks) {
|
|
16
|
-
const benchmark = t.meta.benchmark && t.result?.benchmark;
|
|
17
|
-
if (benchmark) benchmarks.push({
|
|
18
|
-
id: t.id,
|
|
19
|
-
...benchmark,
|
|
20
|
-
samples: []
|
|
21
|
-
});
|
|
22
|
-
}
|
|
23
|
-
if (benchmarks.length) groups.push({
|
|
24
|
-
fullName: getFullName(task, " > "),
|
|
25
|
-
benchmarks
|
|
26
|
-
});
|
|
27
|
-
}
|
|
28
|
-
report.files.push({
|
|
29
|
-
filepath: file.filepath,
|
|
30
|
-
groups
|
|
31
|
-
});
|
|
32
|
-
}
|
|
33
|
-
return report;
|
|
34
|
-
}
|
|
35
|
-
function flattenFormattedBenchmarkReport(report) {
|
|
36
|
-
const flat = {};
|
|
37
|
-
for (const file of report.files) for (const group of file.groups) for (const t of group.benchmarks) flat[t.id] = t;
|
|
38
|
-
return flat;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
const outputMap = /* @__PURE__ */ new WeakMap();
|
|
42
|
-
function formatNumber(number) {
|
|
43
|
-
const res = String(number.toFixed(number < 100 ? 4 : 2)).split(".");
|
|
44
|
-
return res[0].replace(/(?=(?:\d{3})+$)\B/g, ",") + (res[1] ? `.${res[1]}` : "");
|
|
45
|
-
}
|
|
46
|
-
const tableHead = [
|
|
47
|
-
"name",
|
|
48
|
-
"hz",
|
|
49
|
-
"min",
|
|
50
|
-
"max",
|
|
51
|
-
"mean",
|
|
52
|
-
"p75",
|
|
53
|
-
"p99",
|
|
54
|
-
"p995",
|
|
55
|
-
"p999",
|
|
56
|
-
"rme",
|
|
57
|
-
"samples"
|
|
58
|
-
];
|
|
59
|
-
function renderBenchmarkItems(result) {
|
|
60
|
-
return [
|
|
61
|
-
result.name,
|
|
62
|
-
formatNumber(result.hz || 0),
|
|
63
|
-
formatNumber(result.min || 0),
|
|
64
|
-
formatNumber(result.max || 0),
|
|
65
|
-
formatNumber(result.mean || 0),
|
|
66
|
-
formatNumber(result.p75 || 0),
|
|
67
|
-
formatNumber(result.p99 || 0),
|
|
68
|
-
formatNumber(result.p995 || 0),
|
|
69
|
-
formatNumber(result.p999 || 0),
|
|
70
|
-
`±${(result.rme || 0).toFixed(2)}%`,
|
|
71
|
-
(result.sampleCount || 0).toString()
|
|
72
|
-
];
|
|
73
|
-
}
|
|
74
|
-
function computeColumnWidths(results) {
|
|
75
|
-
const rows = [tableHead, ...results.map((v) => renderBenchmarkItems(v))];
|
|
76
|
-
return Array.from(tableHead, (_, i) => Math.max(...rows.map((row) => stripVTControlCharacters(row[i]).length)));
|
|
77
|
-
}
|
|
78
|
-
function padRow(row, widths) {
|
|
79
|
-
return row.map((v, i) => i ? v.padStart(widths[i], " ") : v.padEnd(widths[i], " "));
|
|
80
|
-
}
|
|
81
|
-
function renderTableHead(widths) {
|
|
82
|
-
return " ".repeat(3) + padRow(tableHead, widths).map(c.bold).join(" ");
|
|
83
|
-
}
|
|
84
|
-
function renderBenchmark(result, widths) {
|
|
85
|
-
const padded = padRow(renderBenchmarkItems(result), widths);
|
|
86
|
-
return [
|
|
87
|
-
padded[0],
|
|
88
|
-
c.blue(padded[1]),
|
|
89
|
-
c.cyan(padded[2]),
|
|
90
|
-
c.cyan(padded[3]),
|
|
91
|
-
c.cyan(padded[4]),
|
|
92
|
-
c.cyan(padded[5]),
|
|
93
|
-
c.cyan(padded[6]),
|
|
94
|
-
c.cyan(padded[7]),
|
|
95
|
-
c.cyan(padded[8]),
|
|
96
|
-
c.dim(padded[9]),
|
|
97
|
-
c.dim(padded[10])
|
|
98
|
-
].join(" ");
|
|
99
|
-
}
|
|
100
|
-
function renderTable(options) {
|
|
101
|
-
const output = [];
|
|
102
|
-
const benchMap = {};
|
|
103
|
-
for (const task of options.tasks) if (task.meta.benchmark && task.result?.benchmark) benchMap[task.id] = {
|
|
104
|
-
current: task.result.benchmark,
|
|
105
|
-
baseline: options.compare?.[task.id]
|
|
106
|
-
};
|
|
107
|
-
const benchCount = Object.entries(benchMap).length;
|
|
108
|
-
const columnWidths = computeColumnWidths(Object.values(benchMap).flatMap((v) => [v.current, v.baseline]).filter(notNullish));
|
|
109
|
-
let idx = 0;
|
|
110
|
-
const padding = " ".repeat(1 );
|
|
111
|
-
for (const task of options.tasks) {
|
|
112
|
-
const duration = task.result?.duration;
|
|
113
|
-
const bench = benchMap[task.id];
|
|
114
|
-
let prefix = "";
|
|
115
|
-
if (idx === 0 && task.meta?.benchmark) prefix += `${renderTableHead(columnWidths)}\n${padding}`;
|
|
116
|
-
prefix += ` ${getStateSymbol(task)} `;
|
|
117
|
-
let suffix = "";
|
|
118
|
-
if (task.type === "suite") suffix += c.dim(` (${getTests(task).length})`);
|
|
119
|
-
if (task.mode === "skip" || task.mode === "todo") suffix += c.dim(c.gray(" [skipped]"));
|
|
120
|
-
if (duration != null) {
|
|
121
|
-
const color = duration > options.slowTestThreshold ? c.yellow : c.green;
|
|
122
|
-
suffix += color(` ${Math.round(duration)}${c.dim("ms")}`);
|
|
123
|
-
}
|
|
124
|
-
if (options.showHeap && task.result?.heap != null) suffix += c.magenta(` ${Math.floor(task.result.heap / 1024 / 1024)} MB heap used`);
|
|
125
|
-
if (bench) {
|
|
126
|
-
let body = renderBenchmark(bench.current, columnWidths);
|
|
127
|
-
if (options.compare && bench.baseline) {
|
|
128
|
-
if (bench.current.hz) {
|
|
129
|
-
const diff = bench.current.hz / bench.baseline.hz;
|
|
130
|
-
const diffFixed = diff.toFixed(2);
|
|
131
|
-
if (diffFixed === "1.0.0") body += c.gray(` [${diffFixed}x]`);
|
|
132
|
-
if (diff > 1) body += c.blue(` [${diffFixed}x] ⇑`);
|
|
133
|
-
else body += c.red(` [${diffFixed}x] ⇓`);
|
|
134
|
-
}
|
|
135
|
-
output.push(padding + prefix + body + suffix);
|
|
136
|
-
const bodyBaseline = renderBenchmark(bench.baseline, columnWidths);
|
|
137
|
-
output.push(`${padding} ${bodyBaseline} ${c.dim("(baseline)")}`);
|
|
138
|
-
} else {
|
|
139
|
-
if (bench.current.rank === 1 && benchCount > 1) body += c.bold(c.green(" fastest"));
|
|
140
|
-
if (bench.current.rank === benchCount && benchCount > 2) body += c.bold(c.gray(" slowest"));
|
|
141
|
-
output.push(padding + prefix + body + suffix);
|
|
142
|
-
}
|
|
143
|
-
} else output.push(padding + prefix + task.name + suffix);
|
|
144
|
-
if (task.result?.state !== "pass" && outputMap.get(task) != null) {
|
|
145
|
-
let data = outputMap.get(task);
|
|
146
|
-
if (typeof data === "string") {
|
|
147
|
-
data = stripVTControlCharacters(data.trim().split("\n").filter(Boolean).pop());
|
|
148
|
-
if (data === "") data = void 0;
|
|
149
|
-
}
|
|
150
|
-
if (data != null) {
|
|
151
|
-
const out = ` ${" ".repeat(options.level)}${F_RIGHT} ${data}`;
|
|
152
|
-
output.push(c.gray(truncateString(out, options.columns)));
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
idx++;
|
|
156
|
-
}
|
|
157
|
-
return output.filter(Boolean).join("\n");
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
class BenchmarkReporter extends DefaultReporter {
|
|
161
|
-
compare;
|
|
162
|
-
async onInit(ctx) {
|
|
163
|
-
super.onInit(ctx);
|
|
164
|
-
if (this.ctx.config.benchmark?.compare) {
|
|
165
|
-
const compareFile = pathe.resolve(this.ctx.config.root, this.ctx.config.benchmark?.compare);
|
|
166
|
-
try {
|
|
167
|
-
this.compare = flattenFormattedBenchmarkReport(JSON.parse(await fs.promises.readFile(compareFile, "utf-8")));
|
|
168
|
-
} catch (e) {
|
|
169
|
-
this.error(`Failed to read '${compareFile}'`, e);
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
onTaskUpdate(packs) {
|
|
174
|
-
for (const pack of packs) {
|
|
175
|
-
const task = this.ctx.state.idMap.get(pack[0]);
|
|
176
|
-
if (task?.type === "suite" && task.result?.state !== "run") task.tasks.filter((task) => task.result?.benchmark).sort((benchA, benchB) => benchA.result.benchmark.mean - benchB.result.benchmark.mean).forEach((bench, idx) => {
|
|
177
|
-
bench.result.benchmark.rank = Number(idx) + 1;
|
|
178
|
-
});
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
|
-
onTestSuiteResult(testSuite) {
|
|
182
|
-
super.onTestSuiteResult(testSuite);
|
|
183
|
-
this.printSuiteTable(testSuite);
|
|
184
|
-
}
|
|
185
|
-
printTestModule(testModule) {
|
|
186
|
-
this.printSuiteTable(testModule);
|
|
187
|
-
}
|
|
188
|
-
printSuiteTable(testTask) {
|
|
189
|
-
const state = testTask.state();
|
|
190
|
-
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;
|
|
193
|
-
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, separator)}`;
|
|
195
|
-
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({
|
|
198
|
-
tasks: benches,
|
|
199
|
-
level: 1,
|
|
200
|
-
columns: this.ctx.logger.getColumns(),
|
|
201
|
-
compare: this.compare,
|
|
202
|
-
showHeap: this.ctx.config.logHeapUsage,
|
|
203
|
-
slowTestThreshold: this.ctx.config.slowTestThreshold
|
|
204
|
-
}));
|
|
205
|
-
}
|
|
206
|
-
}
|
|
207
|
-
async onTestRunEnd(testModules, unhandledErrors, reason) {
|
|
208
|
-
super.onTestRunEnd(testModules, unhandledErrors, reason);
|
|
209
|
-
// write output for future comparison
|
|
210
|
-
let outputFile = this.ctx.config.benchmark?.outputJson;
|
|
211
|
-
if (outputFile) {
|
|
212
|
-
outputFile = pathe.resolve(this.ctx.config.root, outputFile);
|
|
213
|
-
const outputDirectory = pathe.dirname(outputFile);
|
|
214
|
-
if (!fs.existsSync(outputDirectory)) await fs.promises.mkdir(outputDirectory, { recursive: true });
|
|
215
|
-
const output = createBenchmarkJsonReport(testModules.map((t) => t.task.file));
|
|
216
|
-
await fs.promises.writeFile(outputFile, JSON.stringify(output, null, 2));
|
|
217
|
-
this.log(`Benchmark report written to ${outputFile}`);
|
|
218
|
-
}
|
|
219
|
-
}
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
class VerboseBenchmarkReporter extends BenchmarkReporter {
|
|
223
|
-
verbose = true;
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
const BenchmarkReportsMap = {
|
|
227
|
-
default: BenchmarkReporter,
|
|
228
|
-
verbose: VerboseBenchmarkReporter
|
|
229
|
-
};
|
|
230
|
-
|
|
231
|
-
export { BenchmarkReporter as B, VerboseBenchmarkReporter as V, BenchmarkReportsMap as a };
|