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.
- package/LICENSE.md +1 -1
- package/dist/browser.d.ts +2 -2
- package/dist/browser.js +2 -2
- package/dist/chunks/{base.D3GxgUMI.js → base.CiIV2DDC.js} +71 -36
- package/dist/chunks/{benchmark.DHKMYAts.js → benchmark.B3N2zMcH.js} +9 -4
- package/dist/chunks/{browser.d.-LKfRopd.d.ts → browser.d.DnU_kh8a.d.ts} +1 -1
- package/dist/chunks/{cac.G9DAn-c7.js → cac.B_NTJoIH.js} +115 -42
- package/dist/chunks/{cli-api.Csks4as1.js → cli-api.D48wY175.js} +1863 -845
- package/dist/chunks/console.Cf-YriPC.js +146 -0
- package/dist/chunks/{coverage.C2LA1DSL.js → coverage.BUlIqJrL.js} +284 -114
- package/dist/chunks/{creator.cqqifzG7.js → creator.BzqvXeRE.js} +75 -31
- 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.DxtanrNO.d.ts → global.d.BQDgW9Pr.d.ts} +1 -1
- package/dist/chunks/{globals.BGT_RUsD.js → globals.DBrtKPdh.js} +5 -5
- package/dist/chunks/index.0kCJoeWi.js +220 -0
- package/dist/chunks/{index.CWIFvlX5.js → index.BfmpdV5p.js} +165 -54
- package/dist/chunks/{index.RwjEGCQ0.js → index.CGezRSGU.js} +2 -2
- package/dist/chunks/{index.DEPqWSIZ.js → index.CPA8jGhR.js} +33 -16
- package/dist/chunks/{index.CVpyv-Zg.js → index.kotH7DY7.js} +832 -373
- package/dist/chunks/{index.jMQYiEWE.js → index.op2Re5rn.js} +22 -12
- package/dist/chunks/{index.Dc3xnDvT.js → index.z7NPOg2E.js} +4 -4
- package/dist/chunks/{init-forks.IU-xQ2_X.js → init-forks.aqTzCSR2.js} +14 -4
- package/dist/chunks/{init-threads.C_NWvZkU.js → init-threads.C7T0-YMD.js} +1 -1
- package/dist/chunks/{init.fmH9J833.js → init.BQhNfT0h.js} +53 -30
- package/dist/chunks/{inspector.DLZxSeU3.js → inspector.CvyFGlXm.js} +25 -10
- package/dist/chunks/{moduleRunner.d.DEkTotCv.d.ts → moduleRunner.d.BxT-OjLR.d.ts} +1 -1
- package/dist/chunks/{node.BwAWWjHZ.js → node.Ce0vMQM7.js} +1 -1
- package/dist/chunks/{plugin.d.Cpes8Bt6.d.ts → plugin.d.DevON6kQ.d.ts} +1 -1
- package/dist/chunks/{reporters.d.CSNcMDxF.d.ts → reporters.d.BQ0wpUaj.d.ts} +6 -5
- package/dist/chunks/{rpc.D38ahn14.js → rpc.BytlcPfC.js} +20 -7
- package/dist/chunks/{setup-common.DR1sucx6.js → setup-common.Dw1XgX0v.js} +20 -8
- package/dist/chunks/{startModuleRunner.Cn7hCL7D.js → startModuleRunner.DLjmA_wU.js} +209 -86
- package/dist/chunks/{test.B6aJd6T3.js → test.w5HLbjmU.js} +48 -22
- package/dist/chunks/{utils.CG9h5ccR.js → utils.DvEY5TfP.js} +14 -5
- package/dist/chunks/{vi.BZvkKVkM.js → vi.CyIUVSoU.js} +267 -117
- package/dist/chunks/{vm.BL7_zzOr.js → vm.DXN8eCh2.js} +181 -75
- package/dist/chunks/{worker.d.D25zYZ7N.d.ts → worker.d.ZGohxCEd.d.ts} +74 -7
- 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 +1 -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 +88 -38
- package/dist/module-runner.js +2 -2
- package/dist/node.d.ts +7 -7
- package/dist/node.js +17 -13
- 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 +1 -1
- package/dist/worker.js +15 -15
- package/dist/workers/forks.js +16 -16
- package/dist/workers/runVmTests.js +41 -22
- package/dist/workers/threads.js +16 -16
- package/dist/workers/vmForks.js +11 -11
- package/dist/workers/vmThreads.js +11 -11
- package/package.json +20 -20
- package/dist/chunks/console.CTJL2nuH.js +0 -115
- package/dist/chunks/index.Bgo3tNWt.js +0 -176
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import { updateTask } from '@vitest/runner';
|
|
2
2
|
import { createDefer } from '@vitest/utils/helpers';
|
|
3
3
|
import { getSafeTimers } from '@vitest/utils/timers';
|
|
4
|
-
import { a as getBenchOptions, g as getBenchFn } from './benchmark.
|
|
5
|
-
import { g as getWorkerState } from './utils.
|
|
4
|
+
import { a as getBenchOptions, g as getBenchFn } from './benchmark.B3N2zMcH.js';
|
|
5
|
+
import { g as getWorkerState } from './utils.DvEY5TfP.js';
|
|
6
6
|
import { setState, GLOBAL_EXPECT, getState } from '@vitest/expect';
|
|
7
7
|
import { getTests, getNames, getTestName } from '@vitest/runner/utils';
|
|
8
8
|
import { processError } from '@vitest/utils/error';
|
|
9
9
|
import { normalize } from 'pathe';
|
|
10
|
-
import { a as getSnapshotClient, i as inject, c as createExpect, v as vi } from './vi.
|
|
11
|
-
import { r as rpc } from './rpc.
|
|
10
|
+
import { a as getSnapshotClient, i as inject, c as createExpect, v as vi } from './vi.CyIUVSoU.js';
|
|
11
|
+
import { r as rpc } from './rpc.BytlcPfC.js';
|
|
12
12
|
|
|
13
13
|
function createBenchmarkResult(name) {
|
|
14
14
|
return {
|
|
@@ -20,7 +20,10 @@ function createBenchmarkResult(name) {
|
|
|
20
20
|
}
|
|
21
21
|
const benchmarkTasks = /* @__PURE__ */ new WeakMap();
|
|
22
22
|
async function runBenchmarkSuite(suite, runner) {
|
|
23
|
-
const { Task, Bench } = await runner.importTinybench()
|
|
23
|
+
const { Task, Bench } = await runner.importTinybench();
|
|
24
|
+
const start = performance.now();
|
|
25
|
+
const benchmarkGroup = [];
|
|
26
|
+
const benchmarkSuiteGroup = [];
|
|
24
27
|
for (const task of suite.tasks) {
|
|
25
28
|
if (task.mode !== "run" && task.mode !== "queued") continue;
|
|
26
29
|
if (task.meta?.benchmark) benchmarkGroup.push(task);
|
|
@@ -34,38 +37,53 @@ async function runBenchmarkSuite(suite, runner) {
|
|
|
34
37
|
state: "run",
|
|
35
38
|
startTime: start,
|
|
36
39
|
benchmark: createBenchmarkResult(suite.name)
|
|
37
|
-
}
|
|
40
|
+
};
|
|
41
|
+
updateTask$1("suite-prepare", suite);
|
|
38
42
|
const addBenchTaskListener = (task, benchmark) => {
|
|
39
43
|
task.addEventListener("complete", (e) => {
|
|
40
|
-
const taskRes = e.task.result
|
|
41
|
-
|
|
44
|
+
const taskRes = e.task.result;
|
|
45
|
+
const result = benchmark.result.benchmark;
|
|
46
|
+
benchmark.result.state = "pass";
|
|
47
|
+
Object.assign(result, taskRes);
|
|
42
48
|
// compute extra stats and free raw samples as early as possible
|
|
43
49
|
const samples = result.samples;
|
|
44
|
-
|
|
50
|
+
result.sampleCount = samples.length;
|
|
51
|
+
result.median = samples.length % 2 ? samples[Math.floor(samples.length / 2)] : (samples[samples.length / 2] + samples[samples.length / 2 - 1]) / 2;
|
|
52
|
+
if (!runner.config.benchmark?.includeSamples) result.samples.length = 0;
|
|
45
53
|
updateTask$1("test-finished", benchmark);
|
|
46
|
-
}, { once: true })
|
|
54
|
+
}, { once: true });
|
|
55
|
+
task.addEventListener("error", (e) => {
|
|
47
56
|
const task = e.task;
|
|
48
57
|
defer.reject(benchmark ? task.result.error : e);
|
|
49
58
|
}, { once: true });
|
|
50
59
|
};
|
|
51
60
|
benchmarkGroup.forEach((benchmark) => {
|
|
52
|
-
const
|
|
61
|
+
const benchmarkInstance = new Bench(getBenchOptions(benchmark));
|
|
62
|
+
const benchmarkFn = getBenchFn(benchmark);
|
|
53
63
|
benchmark.result = {
|
|
54
64
|
state: "run",
|
|
55
65
|
startTime: start,
|
|
56
66
|
benchmark: createBenchmarkResult(benchmark.name)
|
|
57
67
|
};
|
|
58
68
|
const task = new Task(benchmarkInstance, benchmark.name, benchmarkFn);
|
|
59
|
-
benchmarkTasks.set(benchmark, task)
|
|
69
|
+
benchmarkTasks.set(benchmark, task);
|
|
70
|
+
addBenchTaskListener(task, benchmark);
|
|
60
71
|
});
|
|
61
|
-
const { setTimeout } = getSafeTimers()
|
|
72
|
+
const { setTimeout } = getSafeTimers();
|
|
73
|
+
const tasks = [];
|
|
62
74
|
for (const benchmark of benchmarkGroup) {
|
|
63
75
|
const task = benchmarkTasks.get(benchmark);
|
|
64
|
-
updateTask$1("test-prepare", benchmark)
|
|
76
|
+
updateTask$1("test-prepare", benchmark);
|
|
77
|
+
await task.warmup();
|
|
78
|
+
tasks.push([await new Promise((resolve) => setTimeout(async () => {
|
|
65
79
|
resolve(await task.run());
|
|
66
80
|
})), benchmark]);
|
|
67
81
|
}
|
|
68
|
-
suite.result.duration = performance.now() - start
|
|
82
|
+
suite.result.duration = performance.now() - start;
|
|
83
|
+
suite.result.state = "pass";
|
|
84
|
+
updateTask$1("suite-finished", suite);
|
|
85
|
+
defer.resolve(null);
|
|
86
|
+
await defer;
|
|
69
87
|
}
|
|
70
88
|
function updateTask$1(event, task) {
|
|
71
89
|
updateTask(event, task, runner);
|
|
@@ -120,7 +138,8 @@ class VitestTestRunner {
|
|
|
120
138
|
this.workerState.onCleanup(listener);
|
|
121
139
|
}
|
|
122
140
|
onAfterRunFiles() {
|
|
123
|
-
this.snapshotClient.clear()
|
|
141
|
+
this.snapshotClient.clear();
|
|
142
|
+
this.workerState.current = void 0;
|
|
124
143
|
}
|
|
125
144
|
getWorkerContext() {
|
|
126
145
|
return workerContext;
|
|
@@ -137,7 +156,9 @@ class VitestTestRunner {
|
|
|
137
156
|
if (this.workerState.config.snapshotOptions.updateSnapshot === "none" && result.unchecked) {
|
|
138
157
|
let message = `Obsolete snapshots found when no snapshot update is expected.\n`;
|
|
139
158
|
for (const key of result.uncheckedKeys) message += `· ${key}\n`;
|
|
140
|
-
suite.result.errors ??= []
|
|
159
|
+
suite.result.errors ??= [];
|
|
160
|
+
suite.result.errors.push(processError(new Error(message)));
|
|
161
|
+
suite.result.state = "fail";
|
|
141
162
|
}
|
|
142
163
|
await rpc().snapshotSaved(result);
|
|
143
164
|
}
|
|
@@ -157,7 +178,8 @@ class VitestTestRunner {
|
|
|
157
178
|
}
|
|
158
179
|
async onBeforeRunTask(test) {
|
|
159
180
|
if (this.cancelRun) test.mode = "skip";
|
|
160
|
-
test.mode !== "run" && test.mode !== "queued"
|
|
181
|
+
if (test.mode !== "run" && test.mode !== "queued") return;
|
|
182
|
+
this.workerState.current = test;
|
|
161
183
|
}
|
|
162
184
|
async onBeforeRunSuite(suite) {
|
|
163
185
|
if (this.cancelRun) suite.mode = "skip";
|
|
@@ -166,7 +188,9 @@ class VitestTestRunner {
|
|
|
166
188
|
this.workerState.current = suite;
|
|
167
189
|
}
|
|
168
190
|
onBeforeTryTask(test) {
|
|
169
|
-
clearModuleMocks(this.config)
|
|
191
|
+
clearModuleMocks(this.config);
|
|
192
|
+
this.snapshotClient.clearTest(test.file.filepath, test.id);
|
|
193
|
+
setState({
|
|
170
194
|
assertionCalls: 0,
|
|
171
195
|
isExpectingAssertions: false,
|
|
172
196
|
isExpectingAssertionsError: null,
|
|
@@ -186,12 +210,14 @@ class VitestTestRunner {
|
|
|
186
210
|
// create error during the test initialization so we have a nice stack trace
|
|
187
211
|
if (this.config.expect.requireAssertions) this.assertionsErrors.set(context.task, /* @__PURE__ */ new Error("expected any number of assertion, but got none"));
|
|
188
212
|
let _expect;
|
|
189
|
-
|
|
213
|
+
Object.defineProperty(context, "expect", { get() {
|
|
190
214
|
if (!_expect) _expect = createExpect(context.task);
|
|
191
215
|
return _expect;
|
|
192
|
-
} })
|
|
216
|
+
} });
|
|
217
|
+
Object.defineProperty(context, "_local", { get() {
|
|
193
218
|
return _expect != null;
|
|
194
|
-
} })
|
|
219
|
+
} });
|
|
220
|
+
return context;
|
|
195
221
|
}
|
|
196
222
|
getImportDurations() {
|
|
197
223
|
const entries = [...this.workerState.moduleExecutionInfo?.entries() ?? []];
|
|
@@ -8,12 +8,13 @@ function getWorkerState() {
|
|
|
8
8
|
return workerState;
|
|
9
9
|
}
|
|
10
10
|
function provideWorkerState(context, state) {
|
|
11
|
-
|
|
11
|
+
Object.defineProperty(context, NAME_WORKER_STATE, {
|
|
12
12
|
value: state,
|
|
13
13
|
configurable: true,
|
|
14
14
|
writable: true,
|
|
15
15
|
enumerable: false
|
|
16
|
-
})
|
|
16
|
+
});
|
|
17
|
+
return state;
|
|
17
18
|
}
|
|
18
19
|
function isChildProcess() {
|
|
19
20
|
return typeof process !== "undefined" && !!process.send;
|
|
@@ -26,7 +27,11 @@ function resetModules(modules, resetMocks = false) {
|
|
|
26
27
|
...!resetMocks ? [/^mock:/] : []
|
|
27
28
|
];
|
|
28
29
|
modules.idToModuleMap.forEach((node, path) => {
|
|
29
|
-
skipPaths.some((re) => re.test(path))
|
|
30
|
+
if (skipPaths.some((re) => re.test(path))) return;
|
|
31
|
+
node.promise = void 0;
|
|
32
|
+
node.exports = void 0;
|
|
33
|
+
node.evaluated = false;
|
|
34
|
+
node.importers.clear();
|
|
30
35
|
});
|
|
31
36
|
}
|
|
32
37
|
function waitNextTick() {
|
|
@@ -35,9 +40,13 @@ function waitNextTick() {
|
|
|
35
40
|
}
|
|
36
41
|
async function waitForImportsToResolve() {
|
|
37
42
|
await waitNextTick();
|
|
38
|
-
const state = getWorkerState()
|
|
43
|
+
const state = getWorkerState();
|
|
44
|
+
const promises = [];
|
|
45
|
+
const resolvingCount = state.resolvingModules.size;
|
|
39
46
|
for (const [_, mod] of state.evaluatedModules.idToModuleMap) if (mod.promise && !mod.evaluated) promises.push(mod.promise);
|
|
40
|
-
!promises.length && !resolvingCount
|
|
47
|
+
if (!promises.length && !resolvingCount) return;
|
|
48
|
+
await Promise.allSettled(promises);
|
|
49
|
+
await waitForImportsToResolve();
|
|
41
50
|
}
|
|
42
51
|
|
|
43
52
|
export { getWorkerState as g, isChildProcess as i, provideWorkerState as p, resetModules as r, waitForImportsToResolve as w };
|