vitest 4.0.16 → 4.1.0-beta.1
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/dist/browser.d.ts +2 -1
- package/dist/browser.js +2 -1
- package/dist/chunks/{base.Bin-9uYm.js → base.CBRNZa3k.js} +8 -7
- package/dist/chunks/{browser.d.Bz3lxTX-.d.ts → browser.d.8hOapKZr.d.ts} +5 -1
- package/dist/chunks/{cac.BGonGPac.js → cac.B1v3xxoC.js} +26 -8
- package/dist/chunks/{cli-api.BKg19Fvw.js → cli-api.B4CqEpI6.js} +225 -110
- package/dist/chunks/{config.d.CzIjkicf.d.ts → config.d.idH22YSr.d.ts} +13 -11
- package/dist/chunks/{console.Cf-YriPC.js → console.uGgdMhyZ.js} +2 -1
- package/dist/chunks/{coverage.BuJUwVtg.js → coverage.BMlOMIWl.js} +18 -4
- package/dist/chunks/{creator.DAmOKTvJ.js → creator.C7WwjkuR.js} +32 -1
- package/dist/chunks/{globals.DOayXfHP.js → globals.DjuGMoMc.js} +10 -9
- package/dist/chunks/{index.Z5E_ObnR.js → index.BEFi2-_3.js} +3 -1
- package/dist/chunks/{index.6Qv1eEA6.js → index.BiOAd_ki.js} +16 -4
- package/dist/chunks/{index.BspFP3mn.js → index.CyBMJtT7.js} +1 -1
- package/dist/chunks/{index.456_DGfR.js → index.Dm4xqZ0s.js} +28 -4
- package/dist/chunks/{index.Drsj_6e7.js → index.DyBZXrH3.js} +1 -1
- package/dist/chunks/{init-forks.v9UONQS6.js → init-forks.CHeQ9Moq.js} +1 -1
- package/dist/chunks/{init-threads.DqYg3Trk.js → init-threads.uZiNAuPk.js} +1 -1
- package/dist/chunks/{init.KmQZdqFg.js → init.DVtKdFty.js} +24 -11
- package/dist/chunks/{plugin.d.v1sC_bv1.d.ts → plugin.d.D8KU2PY_.d.ts} +1 -1
- package/dist/chunks/{reporters.d.Rsi0PyxX.d.ts → reporters.d.Db3MiIWX.d.ts} +51 -22
- package/dist/chunks/rpc.HLmECnw_.js +148 -0
- package/dist/chunks/{setup-common.Cm-kSBVi.js → setup-common.BcqLPsn5.js} +1 -1
- package/dist/chunks/{startModuleRunner.DpqpB8k3.js → startModuleRunner.C5CcWyXW.js} +23 -23
- package/dist/chunks/{vi.2VT5v0um.js → test.prxIahgM.js} +500 -119
- package/dist/chunks/{traces.U4xDYhzZ.js → traces.CCmnQaNT.js} +46 -1
- package/dist/chunks/{vm.qFl6P1nF.js → vm.CrifS09m.js} +5 -8
- package/dist/chunks/{worker.d.5JNaocaN.d.ts → worker.d.Bji1eq5g.d.ts} +2 -1
- package/dist/cli.js +2 -2
- package/dist/config.d.ts +9 -9
- package/dist/coverage.d.ts +8 -8
- package/dist/coverage.js +3 -1
- package/dist/environments.js +3 -1
- package/dist/index.d.ts +22 -10
- package/dist/index.js +8 -7
- package/dist/module-evaluator.js +2 -6
- package/dist/node.d.ts +14 -11
- package/dist/node.js +20 -20
- package/dist/reporters.d.ts +7 -7
- package/dist/reporters.js +4 -2
- package/dist/runners.d.ts +23 -4
- package/dist/runners.js +4 -4
- package/dist/runtime.d.ts +6 -0
- package/dist/runtime.js +36 -0
- package/dist/snapshot.js +2 -0
- package/dist/suite.js +2 -0
- package/dist/worker.d.ts +4 -3
- package/dist/worker.js +10 -12
- package/dist/workers/forks.js +11 -13
- package/dist/workers/runVmTests.js +10 -12
- package/dist/workers/threads.js +11 -13
- package/dist/workers/vmForks.js +8 -9
- package/dist/workers/vmThreads.js +8 -9
- package/package.json +23 -27
- package/dist/chunks/date.Bq6ZW5rf.js +0 -73
- package/dist/chunks/rpc.BoxB0q7B.js +0 -76
- package/dist/chunks/test.B8ej_ZHS.js +0 -254
- package/dist/mocker.d.ts +0 -1
- package/dist/mocker.js +0 -1
- package/dist/module-runner.js +0 -17
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
/* Ported from https://github.com/boblauer/MockDate/blob/master/src/mockdate.ts */
|
|
2
|
-
/*
|
|
3
|
-
The MIT License (MIT)
|
|
4
|
-
|
|
5
|
-
Copyright (c) 2014 Bob Lauer
|
|
6
|
-
|
|
7
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
8
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
9
|
-
in the Software without restriction, including without limitation the rights
|
|
10
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
11
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
12
|
-
furnished to do so, subject to the following conditions:
|
|
13
|
-
|
|
14
|
-
The above copyright notice and this permission notice shall be included in all
|
|
15
|
-
copies or substantial portions of the Software.
|
|
16
|
-
|
|
17
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
18
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
19
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
20
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
21
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
22
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
23
|
-
SOFTWARE.
|
|
24
|
-
*/
|
|
25
|
-
const RealDate = Date;
|
|
26
|
-
let now = null;
|
|
27
|
-
class MockDate extends RealDate {
|
|
28
|
-
constructor(y, m, d, h, M, s, ms) {
|
|
29
|
-
super();
|
|
30
|
-
let date;
|
|
31
|
-
switch (arguments.length) {
|
|
32
|
-
case 0:
|
|
33
|
-
if (now !== null) date = new RealDate(now.valueOf());
|
|
34
|
-
else date = new RealDate();
|
|
35
|
-
break;
|
|
36
|
-
case 1:
|
|
37
|
-
date = new RealDate(y);
|
|
38
|
-
break;
|
|
39
|
-
default:
|
|
40
|
-
d = typeof d === "undefined" ? 1 : d;
|
|
41
|
-
h = h || 0;
|
|
42
|
-
M = M || 0;
|
|
43
|
-
s = s || 0;
|
|
44
|
-
ms = ms || 0;
|
|
45
|
-
date = new RealDate(y, m, d, h, M, s, ms);
|
|
46
|
-
break;
|
|
47
|
-
}
|
|
48
|
-
Object.setPrototypeOf(date, MockDate.prototype);
|
|
49
|
-
return date;
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
MockDate.UTC = RealDate.UTC;
|
|
53
|
-
MockDate.now = function() {
|
|
54
|
-
return new MockDate().valueOf();
|
|
55
|
-
};
|
|
56
|
-
MockDate.parse = function(dateString) {
|
|
57
|
-
return RealDate.parse(dateString);
|
|
58
|
-
};
|
|
59
|
-
MockDate.toString = function() {
|
|
60
|
-
return RealDate.toString();
|
|
61
|
-
};
|
|
62
|
-
function mockDate(date) {
|
|
63
|
-
const dateObj = new RealDate(date.valueOf());
|
|
64
|
-
if (Number.isNaN(dateObj.getTime())) throw new TypeError(`mockdate: The time set is an invalid date: ${date}`);
|
|
65
|
-
// @ts-expect-error global
|
|
66
|
-
globalThis.Date = MockDate;
|
|
67
|
-
now = dateObj.valueOf();
|
|
68
|
-
}
|
|
69
|
-
function resetDate() {
|
|
70
|
-
globalThis.Date = RealDate;
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
export { RealDate as R, mockDate as m, resetDate as r };
|
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
import { getSafeTimers } from '@vitest/utils/timers';
|
|
2
|
-
import { c as createBirpc } from './index.Chj8NDwU.js';
|
|
3
|
-
import { g as getWorkerState } from './utils.DvEY5TfP.js';
|
|
4
|
-
|
|
5
|
-
const { get } = Reflect;
|
|
6
|
-
function withSafeTimers(fn) {
|
|
7
|
-
const { setTimeout, clearTimeout, nextTick, setImmediate, clearImmediate } = getSafeTimers();
|
|
8
|
-
const currentSetTimeout = globalThis.setTimeout;
|
|
9
|
-
const currentClearTimeout = globalThis.clearTimeout;
|
|
10
|
-
const currentSetImmediate = globalThis.setImmediate;
|
|
11
|
-
const currentClearImmediate = globalThis.clearImmediate;
|
|
12
|
-
const currentNextTick = globalThis.process?.nextTick;
|
|
13
|
-
try {
|
|
14
|
-
globalThis.setTimeout = setTimeout;
|
|
15
|
-
globalThis.clearTimeout = clearTimeout;
|
|
16
|
-
if (setImmediate) globalThis.setImmediate = setImmediate;
|
|
17
|
-
if (clearImmediate) globalThis.clearImmediate = clearImmediate;
|
|
18
|
-
if (globalThis.process && nextTick) globalThis.process.nextTick = nextTick;
|
|
19
|
-
return fn();
|
|
20
|
-
} finally {
|
|
21
|
-
globalThis.setTimeout = currentSetTimeout;
|
|
22
|
-
globalThis.clearTimeout = currentClearTimeout;
|
|
23
|
-
globalThis.setImmediate = currentSetImmediate;
|
|
24
|
-
globalThis.clearImmediate = currentClearImmediate;
|
|
25
|
-
if (globalThis.process && nextTick) nextTick(() => {
|
|
26
|
-
globalThis.process.nextTick = currentNextTick;
|
|
27
|
-
});
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
const promises = /* @__PURE__ */ new Set();
|
|
31
|
-
async function rpcDone() {
|
|
32
|
-
if (!promises.size) return;
|
|
33
|
-
const awaitable = Array.from(promises);
|
|
34
|
-
return Promise.all(awaitable);
|
|
35
|
-
}
|
|
36
|
-
const onCancelCallbacks = [];
|
|
37
|
-
function onCancel(callback) {
|
|
38
|
-
onCancelCallbacks.push(callback);
|
|
39
|
-
}
|
|
40
|
-
function createRuntimeRpc(options) {
|
|
41
|
-
return createSafeRpc(createBirpc({ async onCancel(reason) {
|
|
42
|
-
await Promise.all(onCancelCallbacks.map((fn) => fn(reason)));
|
|
43
|
-
} }, {
|
|
44
|
-
eventNames: [
|
|
45
|
-
"onUserConsoleLog",
|
|
46
|
-
"onCollected",
|
|
47
|
-
"onCancel"
|
|
48
|
-
],
|
|
49
|
-
timeout: -1,
|
|
50
|
-
...options
|
|
51
|
-
}));
|
|
52
|
-
}
|
|
53
|
-
function createSafeRpc(rpc) {
|
|
54
|
-
return new Proxy(rpc, { get(target, p, handler) {
|
|
55
|
-
// keep $rejectPendingCalls as sync function
|
|
56
|
-
if (p === "$rejectPendingCalls") return rpc.$rejectPendingCalls;
|
|
57
|
-
const sendCall = get(target, p, handler);
|
|
58
|
-
const safeSendCall = (...args) => withSafeTimers(async () => {
|
|
59
|
-
const result = sendCall(...args);
|
|
60
|
-
promises.add(result);
|
|
61
|
-
try {
|
|
62
|
-
return await result;
|
|
63
|
-
} finally {
|
|
64
|
-
promises.delete(result);
|
|
65
|
-
}
|
|
66
|
-
});
|
|
67
|
-
safeSendCall.asEvent = sendCall.asEvent;
|
|
68
|
-
return safeSendCall;
|
|
69
|
-
} });
|
|
70
|
-
}
|
|
71
|
-
function rpc() {
|
|
72
|
-
const { rpc } = getWorkerState();
|
|
73
|
-
return rpc;
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
export { rpcDone as a, createRuntimeRpc as c, onCancel as o, rpc as r };
|
|
@@ -1,254 +0,0 @@
|
|
|
1
|
-
import { updateTask } from '@vitest/runner';
|
|
2
|
-
import { createDefer } from '@vitest/utils/helpers';
|
|
3
|
-
import { getSafeTimers } from '@vitest/utils/timers';
|
|
4
|
-
import { a as getBenchOptions, g as getBenchFn } from './benchmark.B3N2zMcH.js';
|
|
5
|
-
import { g as getWorkerState } from './utils.DvEY5TfP.js';
|
|
6
|
-
import { setState, GLOBAL_EXPECT, getState } from '@vitest/expect';
|
|
7
|
-
import { getTests, getNames, getTestName } from '@vitest/runner/utils';
|
|
8
|
-
import { processError } from '@vitest/utils/error';
|
|
9
|
-
import { normalize } from 'pathe';
|
|
10
|
-
import { a as getSnapshotClient, i as inject, c as createExpect, v as vi } from './vi.2VT5v0um.js';
|
|
11
|
-
import { r as rpc } from './rpc.BoxB0q7B.js';
|
|
12
|
-
|
|
13
|
-
function createBenchmarkResult(name) {
|
|
14
|
-
return {
|
|
15
|
-
name,
|
|
16
|
-
rank: 0,
|
|
17
|
-
rme: 0,
|
|
18
|
-
samples: []
|
|
19
|
-
};
|
|
20
|
-
}
|
|
21
|
-
const benchmarkTasks = /* @__PURE__ */ new WeakMap();
|
|
22
|
-
async function runBenchmarkSuite(suite, runner) {
|
|
23
|
-
const { Task, Bench } = await runner.importTinybench();
|
|
24
|
-
const start = performance.now();
|
|
25
|
-
const benchmarkGroup = [];
|
|
26
|
-
const benchmarkSuiteGroup = [];
|
|
27
|
-
for (const task of suite.tasks) {
|
|
28
|
-
if (task.mode !== "run" && task.mode !== "queued") continue;
|
|
29
|
-
if (task.meta?.benchmark) benchmarkGroup.push(task);
|
|
30
|
-
else if (task.type === "suite") benchmarkSuiteGroup.push(task);
|
|
31
|
-
}
|
|
32
|
-
// run sub suites sequentially
|
|
33
|
-
for (const subSuite of benchmarkSuiteGroup) await runBenchmarkSuite(subSuite, runner);
|
|
34
|
-
if (benchmarkGroup.length) {
|
|
35
|
-
const defer = createDefer();
|
|
36
|
-
suite.result = {
|
|
37
|
-
state: "run",
|
|
38
|
-
startTime: start,
|
|
39
|
-
benchmark: createBenchmarkResult(suite.name)
|
|
40
|
-
};
|
|
41
|
-
updateTask$1("suite-prepare", suite);
|
|
42
|
-
const addBenchTaskListener = (task, benchmark) => {
|
|
43
|
-
task.addEventListener("complete", (e) => {
|
|
44
|
-
const taskRes = e.task.result;
|
|
45
|
-
const result = benchmark.result.benchmark;
|
|
46
|
-
benchmark.result.state = "pass";
|
|
47
|
-
Object.assign(result, taskRes);
|
|
48
|
-
// compute extra stats and free raw samples as early as possible
|
|
49
|
-
const samples = result.samples;
|
|
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;
|
|
53
|
-
updateTask$1("test-finished", benchmark);
|
|
54
|
-
}, { once: true });
|
|
55
|
-
task.addEventListener("error", (e) => {
|
|
56
|
-
const task = e.task;
|
|
57
|
-
defer.reject(benchmark ? task.result.error : e);
|
|
58
|
-
}, { once: true });
|
|
59
|
-
};
|
|
60
|
-
benchmarkGroup.forEach((benchmark) => {
|
|
61
|
-
const benchmarkInstance = new Bench(getBenchOptions(benchmark));
|
|
62
|
-
const benchmarkFn = getBenchFn(benchmark);
|
|
63
|
-
benchmark.result = {
|
|
64
|
-
state: "run",
|
|
65
|
-
startTime: start,
|
|
66
|
-
benchmark: createBenchmarkResult(benchmark.name)
|
|
67
|
-
};
|
|
68
|
-
const task = new Task(benchmarkInstance, benchmark.name, benchmarkFn);
|
|
69
|
-
benchmarkTasks.set(benchmark, task);
|
|
70
|
-
addBenchTaskListener(task, benchmark);
|
|
71
|
-
});
|
|
72
|
-
const { setTimeout } = getSafeTimers();
|
|
73
|
-
const tasks = [];
|
|
74
|
-
for (const benchmark of benchmarkGroup) {
|
|
75
|
-
const task = benchmarkTasks.get(benchmark);
|
|
76
|
-
updateTask$1("test-prepare", benchmark);
|
|
77
|
-
await task.warmup();
|
|
78
|
-
tasks.push([await new Promise((resolve) => setTimeout(async () => {
|
|
79
|
-
resolve(await task.run());
|
|
80
|
-
})), benchmark]);
|
|
81
|
-
}
|
|
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;
|
|
87
|
-
}
|
|
88
|
-
function updateTask$1(event, task) {
|
|
89
|
-
updateTask(event, task, runner);
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
class NodeBenchmarkRunner {
|
|
93
|
-
moduleRunner;
|
|
94
|
-
constructor(config) {
|
|
95
|
-
this.config = config;
|
|
96
|
-
}
|
|
97
|
-
async importTinybench() {
|
|
98
|
-
return await import('tinybench');
|
|
99
|
-
}
|
|
100
|
-
importFile(filepath, source) {
|
|
101
|
-
if (source === "setup") {
|
|
102
|
-
const moduleNode = getWorkerState().evaluatedModules.getModuleById(filepath);
|
|
103
|
-
if (moduleNode) getWorkerState().evaluatedModules.invalidateModule(moduleNode);
|
|
104
|
-
}
|
|
105
|
-
return this.moduleRunner.import(filepath);
|
|
106
|
-
}
|
|
107
|
-
async runSuite(suite) {
|
|
108
|
-
await runBenchmarkSuite(suite, this);
|
|
109
|
-
}
|
|
110
|
-
async runTask() {
|
|
111
|
-
throw new Error("`test()` and `it()` is only available in test mode.");
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
// worker context is shared between all tests
|
|
116
|
-
const workerContext = Object.create(null);
|
|
117
|
-
class VitestTestRunner {
|
|
118
|
-
snapshotClient = getSnapshotClient();
|
|
119
|
-
workerState = getWorkerState();
|
|
120
|
-
moduleRunner;
|
|
121
|
-
cancelRun = false;
|
|
122
|
-
assertionsErrors = /* @__PURE__ */ new WeakMap();
|
|
123
|
-
pool = this.workerState.ctx.pool;
|
|
124
|
-
_otel;
|
|
125
|
-
viteEnvironment;
|
|
126
|
-
constructor(config) {
|
|
127
|
-
this.config = config;
|
|
128
|
-
const environment = this.workerState.environment;
|
|
129
|
-
this.viteEnvironment = environment.viteEnvironment || environment.name;
|
|
130
|
-
}
|
|
131
|
-
importFile(filepath, source) {
|
|
132
|
-
if (source === "setup") {
|
|
133
|
-
const moduleNode = this.workerState.evaluatedModules.getModuleById(filepath);
|
|
134
|
-
if (moduleNode) this.workerState.evaluatedModules.invalidateModule(moduleNode);
|
|
135
|
-
}
|
|
136
|
-
return this._otel.$(`vitest.module.import_${source === "setup" ? "setup" : "spec"}`, { attributes: { "code.file.path": filepath } }, () => this.moduleRunner.import(filepath));
|
|
137
|
-
}
|
|
138
|
-
onCollectStart(file) {
|
|
139
|
-
this.workerState.current = file;
|
|
140
|
-
}
|
|
141
|
-
onCleanupWorkerContext(listener) {
|
|
142
|
-
this.workerState.onCleanup(listener);
|
|
143
|
-
}
|
|
144
|
-
onAfterRunFiles() {
|
|
145
|
-
this.snapshotClient.clear();
|
|
146
|
-
this.workerState.current = void 0;
|
|
147
|
-
}
|
|
148
|
-
getWorkerContext() {
|
|
149
|
-
return workerContext;
|
|
150
|
-
}
|
|
151
|
-
async onAfterRunSuite(suite) {
|
|
152
|
-
if (this.config.logHeapUsage && typeof process !== "undefined") suite.result.heap = process.memoryUsage().heapUsed;
|
|
153
|
-
if (suite.mode !== "skip" && "filepath" in suite) {
|
|
154
|
-
// mark snapshots in skipped tests as not obsolete
|
|
155
|
-
for (const test of getTests(suite)) if (test.mode === "skip") {
|
|
156
|
-
const name = getNames(test).slice(1).join(" > ");
|
|
157
|
-
this.snapshotClient.skipTest(suite.file.filepath, name);
|
|
158
|
-
}
|
|
159
|
-
const result = await this.snapshotClient.finish(suite.file.filepath);
|
|
160
|
-
if (this.workerState.config.snapshotOptions.updateSnapshot === "none" && result.unchecked) {
|
|
161
|
-
let message = `Obsolete snapshots found when no snapshot update is expected.\n`;
|
|
162
|
-
for (const key of result.uncheckedKeys) message += `· ${key}\n`;
|
|
163
|
-
suite.result.errors ??= [];
|
|
164
|
-
suite.result.errors.push(processError(new Error(message)));
|
|
165
|
-
suite.result.state = "fail";
|
|
166
|
-
}
|
|
167
|
-
await rpc().snapshotSaved(result);
|
|
168
|
-
}
|
|
169
|
-
this.workerState.current = suite.suite || suite.file;
|
|
170
|
-
}
|
|
171
|
-
onAfterRunTask(test) {
|
|
172
|
-
if (this.config.logHeapUsage && typeof process !== "undefined") test.result.heap = process.memoryUsage().heapUsed;
|
|
173
|
-
this.workerState.current = test.suite || test.file;
|
|
174
|
-
}
|
|
175
|
-
cancel(_reason) {
|
|
176
|
-
this.cancelRun = true;
|
|
177
|
-
}
|
|
178
|
-
injectValue(key) {
|
|
179
|
-
// inject has a very limiting type controlled by ProvidedContext
|
|
180
|
-
// some tests override it which causes the build to fail
|
|
181
|
-
return inject(key);
|
|
182
|
-
}
|
|
183
|
-
async onBeforeRunTask(test) {
|
|
184
|
-
if (this.cancelRun) test.mode = "skip";
|
|
185
|
-
if (test.mode !== "run" && test.mode !== "queued") return;
|
|
186
|
-
this.workerState.current = test;
|
|
187
|
-
}
|
|
188
|
-
async onBeforeRunSuite(suite) {
|
|
189
|
-
if (this.cancelRun) suite.mode = "skip";
|
|
190
|
-
// initialize snapshot state before running file suite
|
|
191
|
-
if (suite.mode !== "skip" && "filepath" in suite) await this.snapshotClient.setup(suite.file.filepath, this.workerState.config.snapshotOptions);
|
|
192
|
-
this.workerState.current = suite;
|
|
193
|
-
}
|
|
194
|
-
onBeforeTryTask(test) {
|
|
195
|
-
clearModuleMocks(this.config);
|
|
196
|
-
this.snapshotClient.clearTest(test.file.filepath, test.id);
|
|
197
|
-
setState({
|
|
198
|
-
assertionCalls: 0,
|
|
199
|
-
isExpectingAssertions: false,
|
|
200
|
-
isExpectingAssertionsError: null,
|
|
201
|
-
expectedAssertionsNumber: null,
|
|
202
|
-
expectedAssertionsNumberErrorGen: null,
|
|
203
|
-
currentTestName: getTestName(test),
|
|
204
|
-
snapshotState: this.snapshotClient.getSnapshotState(test.file.filepath)
|
|
205
|
-
}, globalThis[GLOBAL_EXPECT]);
|
|
206
|
-
}
|
|
207
|
-
onAfterTryTask(test) {
|
|
208
|
-
const { assertionCalls, expectedAssertionsNumber, expectedAssertionsNumberErrorGen, isExpectingAssertions, isExpectingAssertionsError } = test.context._local ? test.context.expect.getState() : getState(globalThis[GLOBAL_EXPECT]);
|
|
209
|
-
if (expectedAssertionsNumber !== null && assertionCalls !== expectedAssertionsNumber) throw expectedAssertionsNumberErrorGen();
|
|
210
|
-
if (isExpectingAssertions === true && assertionCalls === 0) throw isExpectingAssertionsError;
|
|
211
|
-
if (this.config.expect.requireAssertions && assertionCalls === 0) throw this.assertionsErrors.get(test);
|
|
212
|
-
}
|
|
213
|
-
extendTaskContext(context) {
|
|
214
|
-
// create error during the test initialization so we have a nice stack trace
|
|
215
|
-
if (this.config.expect.requireAssertions) this.assertionsErrors.set(context.task, /* @__PURE__ */ new Error("expected any number of assertion, but got none"));
|
|
216
|
-
let _expect;
|
|
217
|
-
Object.defineProperty(context, "expect", { get() {
|
|
218
|
-
if (!_expect) _expect = createExpect(context.task);
|
|
219
|
-
return _expect;
|
|
220
|
-
} });
|
|
221
|
-
Object.defineProperty(context, "_local", { get() {
|
|
222
|
-
return _expect != null;
|
|
223
|
-
} });
|
|
224
|
-
return context;
|
|
225
|
-
}
|
|
226
|
-
getImportDurations() {
|
|
227
|
-
const importDurations = {};
|
|
228
|
-
const entries = this.workerState.moduleExecutionInfo?.entries() || [];
|
|
229
|
-
for (const [filepath, { duration, selfTime, external, importer }] of entries) importDurations[normalize(filepath)] = {
|
|
230
|
-
selfTime,
|
|
231
|
-
totalTime: duration,
|
|
232
|
-
external,
|
|
233
|
-
importer
|
|
234
|
-
};
|
|
235
|
-
return importDurations;
|
|
236
|
-
}
|
|
237
|
-
trace = (name, attributes, cb) => {
|
|
238
|
-
const options = typeof attributes === "object" ? { attributes } : {};
|
|
239
|
-
return this._otel.$(`vitest.test.runner.${name}`, options, cb || attributes);
|
|
240
|
-
};
|
|
241
|
-
__setTraces(traces) {
|
|
242
|
-
this._otel = traces;
|
|
243
|
-
}
|
|
244
|
-
}
|
|
245
|
-
function clearModuleMocks(config) {
|
|
246
|
-
const { clearMocks, mockReset, restoreMocks, unstubEnvs, unstubGlobals } = config;
|
|
247
|
-
if (restoreMocks) vi.restoreAllMocks();
|
|
248
|
-
if (mockReset) vi.resetAllMocks();
|
|
249
|
-
if (clearMocks) vi.clearAllMocks();
|
|
250
|
-
if (unstubEnvs) vi.unstubAllEnvs();
|
|
251
|
-
if (unstubGlobals) vi.unstubAllGlobals();
|
|
252
|
-
}
|
|
253
|
-
|
|
254
|
-
export { NodeBenchmarkRunner as N, VitestTestRunner as V };
|
package/dist/mocker.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from '@vitest/mocker';
|
package/dist/mocker.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from '@vitest/mocker';
|
package/dist/module-runner.js
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
export { VitestModuleEvaluator } from './module-evaluator.js';
|
|
2
|
-
export { a as VITEST_VM_CONTEXT_SYMBOL, V as VitestModuleRunner, s as startVitestModuleRunner } from './chunks/startModuleRunner.DpqpB8k3.js';
|
|
3
|
-
export { g as getWorkerState } from './chunks/utils.DvEY5TfP.js';
|
|
4
|
-
import 'node:module';
|
|
5
|
-
import 'node:url';
|
|
6
|
-
import 'node:vm';
|
|
7
|
-
import 'pathe';
|
|
8
|
-
import 'vite/module-runner';
|
|
9
|
-
import './chunks/traces.U4xDYhzZ.js';
|
|
10
|
-
import 'node:fs';
|
|
11
|
-
import '@vitest/utils/helpers';
|
|
12
|
-
import './chunks/modules.BJuCwlRJ.js';
|
|
13
|
-
import './path.js';
|
|
14
|
-
import 'node:path';
|
|
15
|
-
import '@vitest/utils/serialize';
|
|
16
|
-
import '@vitest/mocker';
|
|
17
|
-
import '@vitest/utils/timers';
|