@voidzero-dev/vite-plus-test 0.1.8 → 0.1.10
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 +181 -1
- package/dist/@vitest/browser/client/.vite/manifest.json +6 -6
- package/dist/@vitest/browser/client/__vitest__/assets/index-Da0hb3oU.css +1 -0
- package/dist/@vitest/browser/client/__vitest__/assets/index-Di71CKDo.js +63 -0
- package/dist/@vitest/browser/client/__vitest__/favicon.ico +0 -0
- package/dist/@vitest/browser/client/__vitest__/favicon.svg +49 -4
- package/dist/@vitest/browser/client/__vitest__/index.html +2 -2
- package/dist/@vitest/browser/client/__vitest_browser__/{orchestrator-S_3e_uzt.js → orchestrator-CXs6qrFe.js} +70 -28
- package/dist/@vitest/browser/client/__vitest_browser__/{tester-k74mgIRa.js → tester-K5NNxh1O.js} +167 -58
- package/dist/@vitest/browser/client/__vitest_browser__/{utils-uxqdqUz8.js → utils-C2ISqq1C.js} +2 -2
- package/dist/@vitest/browser/client/favicon.svg +49 -4
- package/dist/@vitest/browser/client/orchestrator.html +2 -2
- package/dist/@vitest/browser/client/tester/tester.html +2 -2
- package/dist/@vitest/browser/client.js +20 -13
- package/dist/@vitest/browser/context.d.ts +160 -10
- package/dist/@vitest/browser/context.js +108 -22
- package/dist/@vitest/browser/expect-element.js +23 -28
- package/dist/@vitest/browser/index-5Pe7X7sp.js +7 -0
- package/dist/@vitest/browser/index.d.ts +20 -2
- package/dist/@vitest/browser/index.js +5706 -159
- package/dist/@vitest/browser/locators.d.ts +14 -3
- package/dist/@vitest/browser/locators.js +1 -1
- package/dist/@vitest/browser-playwright/index.d.ts +22 -5
- package/dist/@vitest/browser-playwright/index.js +169 -61
- package/dist/@vitest/browser-preview/index.d.ts +14 -1
- package/dist/@vitest/browser-preview/locators.js +31 -18
- package/dist/@vitest/browser-webdriverio/index.d.ts +17 -3
- package/dist/@vitest/browser-webdriverio/index.js +22 -2
- package/dist/@vitest/browser-webdriverio/locators.js +84 -7
- package/dist/@vitest/expect/index.d.ts +172 -54
- package/dist/@vitest/expect/index.js +124 -67
- package/dist/@vitest/mocker/auto-register.js +1 -0
- package/dist/@vitest/mocker/automock.d.ts +1 -0
- package/dist/@vitest/mocker/automock.js +5 -0
- package/dist/@vitest/mocker/browser.d.ts +4 -4
- package/dist/@vitest/mocker/browser.js +1 -0
- package/dist/@vitest/mocker/chunk-automock.js +182 -14
- package/dist/@vitest/mocker/chunk-helpers.js +44 -0
- package/dist/@vitest/mocker/chunk-hoistMocks.js +659 -0
- package/dist/@vitest/mocker/chunk-mocker.js +41 -30
- package/dist/@vitest/mocker/chunk-registry.js +21 -7
- package/dist/@vitest/mocker/chunk-utils.js +18 -7
- package/dist/@vitest/mocker/hoistMocks.d-w2ILr1dG.d.ts +739 -0
- package/dist/@vitest/mocker/{index.d-C-sLYZi-.d.ts → index.d-B41z0AuW.d.ts} +1 -1
- package/dist/@vitest/mocker/index.d.ts +2 -2
- package/dist/@vitest/mocker/index.js +18 -3
- package/dist/@vitest/mocker/{mocker.d-TnKRhz7N.d.ts → mocker.d-QEntlm6J.d.ts} +10 -5
- package/dist/@vitest/mocker/node.d.ts +5 -734
- package/dist/@vitest/mocker/node.js +29 -587
- package/dist/@vitest/mocker/redirect.js +4 -4
- package/dist/@vitest/mocker/register.d.ts +3 -3
- package/dist/@vitest/mocker/register.js +1 -0
- package/dist/@vitest/mocker/transforms.d.ts +6 -0
- package/dist/@vitest/mocker/transforms.js +8 -0
- package/dist/@vitest/mocker/{types.d-B8CCKmHt.d.ts → types.d-BjI5eAwu.d.ts} +23 -7
- package/dist/@vitest/pretty-format/index.d.ts +11 -1
- package/dist/@vitest/pretty-format/index.js +33 -4
- package/dist/@vitest/runner/chunk-tasks.js +305 -37
- package/dist/@vitest/runner/index.d.ts +5 -6
- package/dist/@vitest/runner/index.js +1146 -455
- package/dist/@vitest/runner/{tasks.d-C7UxawJ9.d.ts → tasks.d-D2GKpdwQ.d.ts} +726 -55
- package/dist/@vitest/runner/types.d.ts +2 -182
- package/dist/@vitest/runner/utils.d.ts +16 -8
- package/dist/@vitest/runner/utils.js +1 -1
- package/dist/@vitest/snapshot/{environment.d-DHdQ1Csl.d.ts → environment.d-DOJxxZV9.d.ts} +2 -7
- package/dist/@vitest/snapshot/environment.d.ts +2 -1
- package/dist/@vitest/snapshot/environment.js +1 -1
- package/dist/@vitest/snapshot/index.d.ts +4 -3
- package/dist/@vitest/snapshot/index.js +21 -550
- package/dist/@vitest/snapshot/manager.d.ts +3 -2
- package/dist/@vitest/snapshot/manager.js +1 -1
- package/dist/@vitest/snapshot/{rawSnapshot.d-lFsMJFUd.d.ts → rawSnapshot.d-U2kJUxDr.d.ts} +1 -1
- package/dist/@vitest/spy/index.d.ts +34 -4
- package/dist/@vitest/spy/index.js +69 -19
- package/dist/@vitest/utils/diff.js +11 -9
- package/dist/@vitest/utils/display.d.ts +2 -1
- package/dist/@vitest/utils/display.js +38 -5
- package/dist/@vitest/utils/error.d.ts +2 -1
- package/dist/@vitest/utils/error.js +1 -2
- package/dist/@vitest/utils/helpers.d.ts +4 -1
- package/dist/@vitest/utils/helpers.js +43 -1
- package/dist/@vitest/utils/resolver.js +1 -2
- package/dist/@vitest/utils/serialize.js +6 -6
- package/dist/@vitest/utils/source-map/node.d.ts +6 -0
- package/dist/@vitest/utils/source-map/node.js +23 -0
- package/dist/@vitest/utils/source-map.js +15 -5
- package/dist/browser.d.ts +3 -2
- package/dist/browser.js +2 -2
- package/dist/chunks/acorn.B2iPLyUM.js +5958 -0
- package/dist/chunks/{base.CJ0Y4ePK.js → base.DM0-RqVb.js} +54 -16
- package/dist/chunks/{benchmark.B3N2zMcH.js → benchmark.D0SlKNbZ.js} +1 -1
- package/dist/chunks/{browser.d.ChKACdzH.d.ts → browser.d.X3SXoOCV.d.ts} +4 -1
- package/dist/chunks/{cac.DVeoLl0M.js → cac.CWGDZnXT.js} +979 -20
- package/dist/chunks/{cli-api.B7PN_QUv.js → cli-api.DuT9iuvY.js} +8764 -7898
- package/dist/chunks/{config.d.Cy95HiCx.d.ts → config.d.EJLVE3es.d.ts} +30 -15
- package/dist/chunks/{console.Cf-YriPC.js → console.3WNpx0tS.js} +3 -2
- package/dist/chunks/{constants.D_Q9UYh-.js → constants.CPYnjOGj.js} +4 -2
- package/dist/chunks/coverage.Bri33R1t.js +1050 -0
- package/dist/chunks/{creator.DAmOKTvJ.js → creator.DgVhQm5q.js} +35 -4
- package/dist/chunks/{defaults.BOqNVLsY.js → defaults.CdU2lD-q.js} +4 -3
- package/dist/chunks/{global.d.B15mdLcR.d.ts → global.d.x-ILCfAE.d.ts} +1 -2
- package/dist/chunks/{globals.DOayXfHP.js → globals.BXNGLnTL.js} +11 -10
- package/dist/chunks/{coverage.AVPTjMgw.js → index.BCY_7LL2.js} +5 -959
- package/dist/chunks/{index.C5r1PdPD.js → index.CEzQDJGb.js} +1 -1
- package/dist/chunks/{index.D3XRDfWc.js → index.CMESou6r.js} +26 -1
- package/dist/chunks/{index.6Qv1eEA6.js → index.DGNSnENe.js} +95 -9
- package/dist/chunks/{index.M8mOzt4Y.js → index.DXMFO5MJ.js} +3279 -2914
- package/dist/chunks/{index.Z5E_ObnR.js → index.DlDSLQD3.js} +7 -3
- package/dist/chunks/{index.CyBMJtT7.js → index.EY6TCHpo.js} +10 -8
- package/dist/chunks/{index.D4KonVSU.js → index.og1WyBLx.js} +18 -3
- package/dist/chunks/{init-forks._y3TW739.js → init-forks.DeArv0jT.js} +1 -1
- package/dist/chunks/{init-threads.DBO2kn-p.js → init-threads.-2OUl4Nn.js} +1 -1
- package/dist/chunks/{init.B6MLFIaN.js → init.DICorXCo.js} +52 -13
- package/dist/chunks/native.DPzPHdi5.js +148 -0
- package/dist/chunks/nativeModuleMocker.DndvSdL6.js +206 -0
- package/dist/chunks/nativeModuleRunner.BIakptoF.js +36 -0
- package/dist/chunks/{node.Ce0vMQM7.js → node.COQbm6gK.js} +1 -1
- package/dist/chunks/{plugin.d.CtqpEehP.d.ts → plugin.d.BuW-flqo.d.ts} +1 -1
- package/dist/chunks/{reporters.d.CWXNI2jG.d.ts → reporters.d.DVUYHHhe.d.ts} +328 -79
- package/dist/chunks/rpc.MzXet3jl.js +144 -0
- package/dist/chunks/{rpc.d.RH3apGEf.d.ts → rpc.d.BFMWpdph.d.ts} +10 -2
- package/dist/chunks/{setup-common.Cm-kSBVi.js → setup-common.B41N_kPE.js} +3 -3
- package/dist/chunks/{startModuleRunner.DEj0jb3e.js → startVitestModuleRunner.C3ZR-4J3.js} +265 -405
- package/dist/chunks/{suite.d.BJWk38HB.d.ts → suite.d.udJtyAgw.d.ts} +1 -1
- package/dist/chunks/{vi.2VT5v0um.js → test.CTcmp4Su.js} +538 -181
- package/dist/chunks/{utils.DvEY5TfP.js → utils.BX5Fg8C4.js} +8 -1
- package/dist/chunks/{vm.D3epNOPZ.js → vm.Dh2rTtmP.js} +48 -8
- package/dist/chunks/{worker.d.Dyxm8DEL.d.ts → worker.d.B84sVRy0.d.ts} +2 -2
- package/dist/cli.js +6 -5
- package/dist/client/.vite/manifest.json +6 -6
- package/dist/client/__vitest__/assets/index-Da0hb3oU.css +1 -0
- package/dist/client/__vitest__/assets/index-Di71CKDo.js +63 -0
- package/dist/client/__vitest__/favicon.ico +0 -0
- package/dist/client/__vitest__/favicon.svg +49 -4
- package/dist/client/__vitest__/index.html +2 -2
- package/dist/client/__vitest_browser__/{orchestrator-S_3e_uzt.js → orchestrator-CXs6qrFe.js} +70 -28
- package/dist/client/__vitest_browser__/{tester-k74mgIRa.js → tester-K5NNxh1O.js} +167 -58
- package/dist/client/__vitest_browser__/{utils-uxqdqUz8.js → utils-C2ISqq1C.js} +2 -2
- package/dist/client/favicon.svg +49 -4
- package/dist/client/orchestrator.html +2 -2
- package/dist/client/tester/tester.html +2 -2
- package/dist/client.js +20 -13
- package/dist/config.cjs +3 -2
- package/dist/config.d.ts +13 -12
- package/dist/config.js +2 -2
- package/dist/context.js +108 -22
- package/dist/coverage.d.ts +12 -8
- package/dist/coverage.js +8 -5
- package/dist/environments.js +3 -1
- package/dist/expect-element.js +23 -23
- package/dist/index-5Pe7X7sp.js +7 -0
- package/dist/index.d.ts +66 -27
- package/dist/index.js +10 -9
- package/dist/locators.d.ts +14 -3
- package/dist/locators.js +1 -1
- package/dist/module-evaluator.d.ts +11 -1
- package/dist/module-evaluator.js +43 -26
- package/dist/node.d.ts +28 -14
- package/dist/node.js +42 -40
- package/dist/nodejs-worker-loader.js +41 -0
- package/dist/plugins/mocker-transforms.mjs +2 -0
- package/dist/plugins/utils-source-map-node.mjs +2 -0
- package/dist/reporters.d.ts +8 -8
- package/dist/reporters.js +7 -5
- package/dist/runners.d.ts +24 -5
- package/dist/runners.js +6 -6
- package/dist/runtime.d.ts +6 -0
- package/dist/runtime.js +35 -0
- package/dist/snapshot.js +4 -2
- package/dist/suite.d.ts +1 -1
- package/dist/suite.js +4 -2
- package/dist/vendor/blazediff_core.d.mts +1 -0
- package/dist/vendor/blazediff_core.mjs +117 -0
- package/dist/vendor/chai.mjs +4 -249
- package/dist/vendor/convert-source-map.d.mts +1 -0
- package/dist/vendor/convert-source-map.mjs +150 -0
- package/dist/vendor/expect-type.d.mts +14 -7
- package/dist/vendor/expect-type.mjs +5 -5
- package/dist/vendor/std-env.d.mts +131 -40
- package/dist/vendor/std-env.mjs +114 -117
- package/dist/worker.d.ts +6 -6
- package/dist/worker.js +27 -21
- package/dist/workers/forks.js +23 -17
- package/dist/workers/runVmTests.js +18 -16
- package/dist/workers/threads.js +23 -17
- package/dist/workers/vmForks.js +15 -12
- package/dist/workers/vmThreads.js +15 -12
- package/globals.d.ts +2 -0
- package/package.json +36 -27
- package/suppress-warnings.cjs +1 -0
- package/dist/@vitest/browser/client/__vitest__/assets/index-BUCFJtth.js +0 -57
- package/dist/@vitest/browser/client/__vitest__/assets/index-DlhE0rqZ.css +0 -1
- package/dist/@vitest/browser/index-D6m36C6U.js +0 -11
- package/dist/@vitest/utils/chunk-_commonjsHelpers.js +0 -5
- package/dist/@vitest/utils/highlight.d.ts +0 -9
- package/dist/@vitest/utils/highlight.js +0 -538
- 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/client/__vitest__/assets/index-BUCFJtth.js +0 -57
- package/dist/client/__vitest__/assets/index-DlhE0rqZ.css +0 -1
- package/dist/index-D6m36C6U.js +0 -6
- package/dist/mocker.d.ts +0 -1
- package/dist/mocker.js +0 -1
- package/dist/module-runner.js +0 -17
|
@@ -1,254 +0,0 @@
|
|
|
1
|
-
import { updateTask } from '../@vitest/runner/index.js';
|
|
2
|
-
import { createDefer } from '../@vitest/utils/helpers.js';
|
|
3
|
-
import { getSafeTimers } from '../@vitest/utils/timers.js';
|
|
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/index.js';
|
|
7
|
-
import { getTests, getNames, getTestName } from '../@vitest/runner/utils.js';
|
|
8
|
-
import { processError } from '../@vitest/utils/error.js';
|
|
9
|
-
import { normalize } from '../vendor/pathe.mjs';
|
|
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('../vendor/tinybench.mjs');
|
|
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 };
|