vitest 3.2.4 → 4.0.0-beta.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 +2 -2
- package/dist/browser.d.ts +13 -16
- package/dist/browser.js +6 -5
- package/dist/chunks/base.Cjha6usc.js +129 -0
- package/dist/chunks/{benchmark.CYdenmiT.js → benchmark.CJUa-Hsa.js} +6 -8
- package/dist/chunks/{benchmark.d.BwvBVTda.d.ts → benchmark.d.DAaHLpsq.d.ts} +4 -4
- package/dist/chunks/browser.d.yFAklsD1.d.ts +18 -0
- package/dist/chunks/{cac.Cb-PYCCB.js → cac.DCxo_nSu.js} +72 -163
- package/dist/chunks/{cli-api.BkDphVBG.js → cli-api.BJJXh9BV.js} +1331 -1678
- package/dist/chunks/{config.d.D2ROskhv.d.ts → config.d.B_LthbQq.d.ts} +59 -65
- package/dist/chunks/{console.CtFJOzRO.js → console.7h5kHUIf.js} +34 -70
- package/dist/chunks/{constants.DnKduX2e.js → constants.D_Q9UYh-.js} +1 -9
- package/dist/chunks/{coverage.DL5VHqXY.js → coverage.BCU-r2QL.js} +538 -765
- 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/{defaults.B7q_naMc.js → defaults.CXFFjsi8.js} +2 -42
- package/dist/chunks/environment.d.BsToaxti.d.ts +65 -0
- package/dist/chunks/{git.BVQ8w_Sw.js → git.BFNcloKD.js} +1 -2
- package/dist/chunks/{global.d.MAmajcmJ.d.ts → global.d.BK3X7FW1.d.ts} +7 -32
- package/dist/chunks/{globals.DEHgCU4V.js → globals.DG-S3xFe.js} +8 -8
- package/dist/chunks/{index.VByaPkjc.js → index.BIP7prJq.js} +472 -803
- package/dist/chunks/{index.B521nVV-.js → index.Bgo3tNWt.js} +23 -4
- package/dist/chunks/{index.BCWujgDG.js → index.BjKEiSn0.js} +14 -24
- package/dist/chunks/{index.CdQS2e2Q.js → index.CMfqw92x.js} +7 -8
- 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.D9nBoC4p.d.ts +201 -0
- package/dist/chunks/moduleTransport.I-bgQy0S.js +19 -0
- package/dist/chunks/{node.fjCdwEIl.js → node.CyipiPvJ.js} +1 -1
- package/dist/chunks/plugin.d.BMVSnsGV.d.ts +9 -0
- package/dist/chunks/{reporters.d.BFLkQcL6.d.ts → reporters.d.BUWjmRYq.d.ts} +2086 -2146
- package/dist/chunks/resolveSnapshotEnvironment.Bkht6Yor.js +81 -0
- package/dist/chunks/resolver.Bx6lE0iq.js +119 -0
- package/dist/chunks/rpc.BKr6mtxz.js +65 -0
- package/dist/chunks/{setup-common.Dd054P77.js → setup-common.uiMcU3cv.js} +17 -29
- package/dist/chunks/startModuleRunner.p67gbNo9.js +665 -0
- package/dist/chunks/{suite.d.FvehnV49.d.ts → suite.d.BJWk38HB.d.ts} +1 -1
- package/dist/chunks/test.BiqSKISg.js +214 -0
- package/dist/chunks/{typechecker.DRKU1-1g.js → typechecker.DB-fIMaH.js} +165 -234
- package/dist/chunks/{utils.CAioKnHs.js → utils.C2YI6McM.js} +5 -14
- package/dist/chunks/{utils.XdZDrNZV.js → utils.D2R2NiOH.js} +8 -27
- package/dist/chunks/{vi.bdSIJ99Y.js → vi.ZPgvtBao.js} +156 -305
- package/dist/chunks/{vm.BThCzidc.js → vm.Ca0Y0W5f.js} +116 -226
- package/dist/chunks/{worker.d.1GmBbd7G.d.ts → worker.d.BDsXGkwh.d.ts} +31 -32
- package/dist/chunks/{worker.d.CKwWzBSj.d.ts → worker.d.BNcX_2mH.d.ts} +1 -1
- package/dist/cli.js +10 -10
- package/dist/config.cjs +5 -58
- package/dist/config.d.ts +72 -71
- package/dist/config.js +3 -9
- package/dist/coverage.d.ts +31 -24
- package/dist/coverage.js +9 -9
- package/dist/environments.d.ts +9 -14
- package/dist/environments.js +1 -1
- package/dist/index.d.ts +52 -213
- package/dist/index.js +7 -9
- 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 +62 -51
- package/dist/node.js +26 -42
- package/dist/reporters.d.ts +11 -12
- package/dist/reporters.js +12 -12
- package/dist/runners.d.ts +3 -4
- package/dist/runners.js +13 -231
- package/dist/snapshot.js +2 -2
- package/dist/suite.d.ts +2 -2
- package/dist/suite.js +2 -2
- package/dist/worker.js +90 -47
- package/dist/workers/forks.js +34 -10
- package/dist/workers/runVmTests.js +36 -56
- package/dist/workers/threads.js +34 -10
- package/dist/workers/vmForks.js +11 -10
- package/dist/workers/vmThreads.js +11 -10
- package/dist/workers.d.ts +5 -7
- package/dist/workers.js +35 -17
- package/globals.d.ts +17 -17
- package/package.json +32 -31
- package/dist/chunks/base.DfmxU-tU.js +0 -38
- package/dist/chunks/environment.d.cL3nLXbE.d.ts +0 -119
- package/dist/chunks/execute.B7h3T_Hc.js +0 -708
- package/dist/chunks/index.CwejwG0H.js +0 -105
- package/dist/chunks/rpc.-pEldfrD.js +0 -83
- package/dist/chunks/runBaseTests.9Ij9_de-.js +0 -129
- package/dist/chunks/vite.d.CMLlLIFP.d.ts +0 -25
- package/dist/execute.d.ts +0 -150
- package/dist/execute.js +0 -13
package/dist/reporters.js
CHANGED
|
@@ -1,23 +1,23 @@
|
|
|
1
|
-
export {
|
|
2
|
-
export { B as BenchmarkReporter, a as BenchmarkReportsMap, V as VerboseBenchmarkReporter } from './chunks/index.
|
|
3
|
-
import 'node:
|
|
4
|
-
import '
|
|
5
|
-
import '@vitest/utils';
|
|
6
|
-
import '@vitest/utils/source-map';
|
|
1
|
+
export { D as DefaultReporter, a as DotReporter, G as GithubActionsReporter, H as HangingProcessReporter, b as JUnitReporter, J as JsonReporter, R as ReportersMap, T as TapFlatReporter, c as TapReporter, V as VerboseReporter } from './chunks/index.BIP7prJq.js';
|
|
2
|
+
export { B as BenchmarkReporter, a as BenchmarkReportsMap, V as VerboseBenchmarkReporter } from './chunks/index.BjKEiSn0.js';
|
|
3
|
+
import 'node:fs';
|
|
4
|
+
import 'node:fs/promises';
|
|
7
5
|
import 'pathe';
|
|
8
|
-
import '
|
|
9
|
-
import './chunks/env.D4Lgay0q.js';
|
|
10
|
-
import 'std-env';
|
|
11
|
-
import './chunks/typechecker.DRKU1-1g.js';
|
|
6
|
+
import './chunks/typechecker.DB-fIMaH.js';
|
|
12
7
|
import 'node:os';
|
|
8
|
+
import 'node:perf_hooks';
|
|
9
|
+
import '@vitest/utils/source-map';
|
|
13
10
|
import 'tinyexec';
|
|
14
11
|
import './path.js';
|
|
15
12
|
import 'node:path';
|
|
16
13
|
import 'node:url';
|
|
14
|
+
import '@vitest/runner/utils';
|
|
15
|
+
import '@vitest/utils';
|
|
17
16
|
import 'vite';
|
|
17
|
+
import 'tinyrainbow';
|
|
18
|
+
import './chunks/env.D4Lgay0q.js';
|
|
19
|
+
import 'std-env';
|
|
18
20
|
import 'node:util';
|
|
19
|
-
import 'node:fs';
|
|
20
|
-
import 'node:fs/promises';
|
|
21
21
|
import 'node:console';
|
|
22
22
|
import 'node:stream';
|
|
23
23
|
import 'node:module';
|
package/dist/runners.d.ts
CHANGED
|
@@ -1,15 +1,14 @@
|
|
|
1
1
|
import * as tinybench from 'tinybench';
|
|
2
2
|
import { VitestRunner, VitestRunnerImportSource, Suite, File, Task, CancelReason, Test, TestContext, ImportDuration } from '@vitest/runner';
|
|
3
3
|
export { VitestRunner } from '@vitest/runner';
|
|
4
|
-
import { a as SerializedConfig } from './chunks/config.d.
|
|
4
|
+
import { a as SerializedConfig } from './chunks/config.d.B_LthbQq.js';
|
|
5
5
|
import '@vitest/pretty-format';
|
|
6
6
|
import '@vitest/snapshot';
|
|
7
|
-
import '@vitest/snapshot/environment';
|
|
8
7
|
import '@vitest/utils/diff';
|
|
9
8
|
|
|
10
9
|
declare class NodeBenchmarkRunner implements VitestRunner {
|
|
11
10
|
config: SerializedConfig;
|
|
12
|
-
private
|
|
11
|
+
private moduleRunner;
|
|
13
12
|
constructor(config: SerializedConfig);
|
|
14
13
|
importTinybench(): Promise<typeof tinybench>;
|
|
15
14
|
importFile(filepath: string, source: VitestRunnerImportSource): unknown;
|
|
@@ -21,7 +20,7 @@ declare class VitestTestRunner implements VitestRunner {
|
|
|
21
20
|
config: SerializedConfig;
|
|
22
21
|
private snapshotClient;
|
|
23
22
|
private workerState;
|
|
24
|
-
private
|
|
23
|
+
private moduleRunner;
|
|
25
24
|
private cancelRun;
|
|
26
25
|
private assertionsErrors;
|
|
27
26
|
pool: string;
|
package/dist/runners.js
CHANGED
|
@@ -1,235 +1,17 @@
|
|
|
1
|
-
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
import
|
|
7
|
-
import
|
|
8
|
-
import
|
|
9
|
-
import
|
|
10
|
-
import '
|
|
1
|
+
export { N as NodeBenchmarkRunner, V as VitestTestRunner } from './chunks/test.BiqSKISg.js';
|
|
2
|
+
import '@vitest/runner';
|
|
3
|
+
import '@vitest/utils';
|
|
4
|
+
import './chunks/benchmark.CJUa-Hsa.js';
|
|
5
|
+
import '@vitest/runner/utils';
|
|
6
|
+
import './chunks/utils.D2R2NiOH.js';
|
|
7
|
+
import '@vitest/expect';
|
|
8
|
+
import '@vitest/utils/error';
|
|
9
|
+
import 'pathe';
|
|
10
|
+
import './chunks/vi.ZPgvtBao.js';
|
|
11
11
|
import './chunks/_commonjsHelpers.BFTU3MAI.js';
|
|
12
12
|
import '@vitest/snapshot';
|
|
13
|
-
import '@vitest/utils/error';
|
|
14
13
|
import '@vitest/spy';
|
|
15
14
|
import '@vitest/utils/source-map';
|
|
16
|
-
import './chunks/date.
|
|
17
|
-
import './chunks/
|
|
18
|
-
|
|
19
|
-
function createBenchmarkResult(name) {
|
|
20
|
-
return {
|
|
21
|
-
name,
|
|
22
|
-
rank: 0,
|
|
23
|
-
rme: 0,
|
|
24
|
-
samples: []
|
|
25
|
-
};
|
|
26
|
-
}
|
|
27
|
-
const benchmarkTasks = /* @__PURE__ */ new WeakMap();
|
|
28
|
-
async function runBenchmarkSuite(suite, runner) {
|
|
29
|
-
const { Task, Bench } = await runner.importTinybench();
|
|
30
|
-
const start = performance.now();
|
|
31
|
-
const benchmarkGroup = [];
|
|
32
|
-
const benchmarkSuiteGroup = [];
|
|
33
|
-
for (const task of suite.tasks) {
|
|
34
|
-
if (task.mode !== "run" && task.mode !== "queued") continue;
|
|
35
|
-
if (task.meta?.benchmark) benchmarkGroup.push(task);
|
|
36
|
-
else if (task.type === "suite") benchmarkSuiteGroup.push(task);
|
|
37
|
-
}
|
|
38
|
-
// run sub suites sequentially
|
|
39
|
-
for (const subSuite of benchmarkSuiteGroup) await runBenchmarkSuite(subSuite, runner);
|
|
40
|
-
if (benchmarkGroup.length) {
|
|
41
|
-
const defer = createDefer();
|
|
42
|
-
suite.result = {
|
|
43
|
-
state: "run",
|
|
44
|
-
startTime: start,
|
|
45
|
-
benchmark: createBenchmarkResult(suite.name)
|
|
46
|
-
};
|
|
47
|
-
updateTask$1("suite-prepare", suite);
|
|
48
|
-
const addBenchTaskListener = (task, benchmark) => {
|
|
49
|
-
task.addEventListener("complete", (e) => {
|
|
50
|
-
const task = e.task;
|
|
51
|
-
const taskRes = task.result;
|
|
52
|
-
const result = benchmark.result.benchmark;
|
|
53
|
-
benchmark.result.state = "pass";
|
|
54
|
-
Object.assign(result, taskRes);
|
|
55
|
-
// compute extra stats and free raw samples as early as possible
|
|
56
|
-
const samples = result.samples;
|
|
57
|
-
result.sampleCount = samples.length;
|
|
58
|
-
result.median = samples.length % 2 ? samples[Math.floor(samples.length / 2)] : (samples[samples.length / 2] + samples[samples.length / 2 - 1]) / 2;
|
|
59
|
-
if (!runner.config.benchmark?.includeSamples) result.samples.length = 0;
|
|
60
|
-
updateTask$1("test-finished", benchmark);
|
|
61
|
-
}, { once: true });
|
|
62
|
-
task.addEventListener("error", (e) => {
|
|
63
|
-
const task = e.task;
|
|
64
|
-
defer.reject(benchmark ? task.result.error : e);
|
|
65
|
-
}, { once: true });
|
|
66
|
-
};
|
|
67
|
-
benchmarkGroup.forEach((benchmark) => {
|
|
68
|
-
const options = getBenchOptions(benchmark);
|
|
69
|
-
const benchmarkInstance = new Bench(options);
|
|
70
|
-
const benchmarkFn = getBenchFn(benchmark);
|
|
71
|
-
benchmark.result = {
|
|
72
|
-
state: "run",
|
|
73
|
-
startTime: start,
|
|
74
|
-
benchmark: createBenchmarkResult(benchmark.name)
|
|
75
|
-
};
|
|
76
|
-
const task = new Task(benchmarkInstance, benchmark.name, benchmarkFn);
|
|
77
|
-
benchmarkTasks.set(benchmark, task);
|
|
78
|
-
addBenchTaskListener(task, benchmark);
|
|
79
|
-
});
|
|
80
|
-
const { setTimeout } = getSafeTimers();
|
|
81
|
-
const tasks = [];
|
|
82
|
-
for (const benchmark of benchmarkGroup) {
|
|
83
|
-
const task = benchmarkTasks.get(benchmark);
|
|
84
|
-
updateTask$1("test-prepare", benchmark);
|
|
85
|
-
await task.warmup();
|
|
86
|
-
tasks.push([await new Promise((resolve) => setTimeout(async () => {
|
|
87
|
-
resolve(await task.run());
|
|
88
|
-
})), benchmark]);
|
|
89
|
-
}
|
|
90
|
-
suite.result.duration = performance.now() - start;
|
|
91
|
-
suite.result.state = "pass";
|
|
92
|
-
updateTask$1("suite-finished", suite);
|
|
93
|
-
defer.resolve(null);
|
|
94
|
-
await defer;
|
|
95
|
-
}
|
|
96
|
-
function updateTask$1(event, task) {
|
|
97
|
-
updateTask(event, task, runner);
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
class NodeBenchmarkRunner {
|
|
101
|
-
__vitest_executor;
|
|
102
|
-
constructor(config) {
|
|
103
|
-
this.config = config;
|
|
104
|
-
}
|
|
105
|
-
async importTinybench() {
|
|
106
|
-
return await import('tinybench');
|
|
107
|
-
}
|
|
108
|
-
importFile(filepath, source) {
|
|
109
|
-
if (source === "setup") getWorkerState().moduleCache.delete(filepath);
|
|
110
|
-
return this.__vitest_executor.executeId(filepath);
|
|
111
|
-
}
|
|
112
|
-
async runSuite(suite) {
|
|
113
|
-
await runBenchmarkSuite(suite, this);
|
|
114
|
-
}
|
|
115
|
-
async runTask() {
|
|
116
|
-
throw new Error("`test()` and `it()` is only available in test mode.");
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
// worker context is shared between all tests
|
|
121
|
-
const workerContext = Object.create(null);
|
|
122
|
-
class VitestTestRunner {
|
|
123
|
-
snapshotClient = getSnapshotClient();
|
|
124
|
-
workerState = getWorkerState();
|
|
125
|
-
__vitest_executor;
|
|
126
|
-
cancelRun = false;
|
|
127
|
-
assertionsErrors = /* @__PURE__ */ new WeakMap();
|
|
128
|
-
pool = this.workerState.ctx.pool;
|
|
129
|
-
constructor(config) {
|
|
130
|
-
this.config = config;
|
|
131
|
-
}
|
|
132
|
-
importFile(filepath, source) {
|
|
133
|
-
if (source === "setup") this.workerState.moduleCache.delete(filepath);
|
|
134
|
-
return this.__vitest_executor.executeId(filepath);
|
|
135
|
-
}
|
|
136
|
-
onCollectStart(file) {
|
|
137
|
-
this.workerState.current = file;
|
|
138
|
-
}
|
|
139
|
-
onCleanupWorkerContext(listener) {
|
|
140
|
-
this.workerState.onCleanup(listener);
|
|
141
|
-
}
|
|
142
|
-
onAfterRunFiles() {
|
|
143
|
-
this.snapshotClient.clear();
|
|
144
|
-
this.workerState.current = void 0;
|
|
145
|
-
}
|
|
146
|
-
getWorkerContext() {
|
|
147
|
-
return workerContext;
|
|
148
|
-
}
|
|
149
|
-
async onAfterRunSuite(suite) {
|
|
150
|
-
if (this.config.logHeapUsage && typeof process !== "undefined") suite.result.heap = process.memoryUsage().heapUsed;
|
|
151
|
-
if (suite.mode !== "skip" && "filepath" in suite) {
|
|
152
|
-
// mark snapshots in skipped tests as not obsolete
|
|
153
|
-
for (const test of getTests(suite)) if (test.mode === "skip") {
|
|
154
|
-
const name = getNames(test).slice(1).join(" > ");
|
|
155
|
-
this.snapshotClient.skipTest(suite.file.filepath, name);
|
|
156
|
-
}
|
|
157
|
-
const result = await this.snapshotClient.finish(suite.file.filepath);
|
|
158
|
-
await rpc().snapshotSaved(result);
|
|
159
|
-
}
|
|
160
|
-
this.workerState.current = suite.suite || suite.file;
|
|
161
|
-
}
|
|
162
|
-
onAfterRunTask(test) {
|
|
163
|
-
if (this.config.logHeapUsage && typeof process !== "undefined") test.result.heap = process.memoryUsage().heapUsed;
|
|
164
|
-
this.workerState.current = test.suite || test.file;
|
|
165
|
-
}
|
|
166
|
-
cancel(_reason) {
|
|
167
|
-
this.cancelRun = true;
|
|
168
|
-
}
|
|
169
|
-
injectValue(key) {
|
|
170
|
-
// inject has a very limiting type controlled by ProvidedContext
|
|
171
|
-
// some tests override it which causes the build to fail
|
|
172
|
-
return inject(key);
|
|
173
|
-
}
|
|
174
|
-
async onBeforeRunTask(test) {
|
|
175
|
-
if (this.cancelRun) test.mode = "skip";
|
|
176
|
-
if (test.mode !== "run" && test.mode !== "queued") return;
|
|
177
|
-
this.workerState.current = test;
|
|
178
|
-
}
|
|
179
|
-
async onBeforeRunSuite(suite) {
|
|
180
|
-
if (this.cancelRun) suite.mode = "skip";
|
|
181
|
-
// initialize snapshot state before running file suite
|
|
182
|
-
if (suite.mode !== "skip" && "filepath" in suite) await this.snapshotClient.setup(suite.file.filepath, this.workerState.config.snapshotOptions);
|
|
183
|
-
this.workerState.current = suite;
|
|
184
|
-
}
|
|
185
|
-
onBeforeTryTask(test) {
|
|
186
|
-
clearModuleMocks(this.config);
|
|
187
|
-
this.snapshotClient.clearTest(test.file.filepath, test.id);
|
|
188
|
-
setState({
|
|
189
|
-
assertionCalls: 0,
|
|
190
|
-
isExpectingAssertions: false,
|
|
191
|
-
isExpectingAssertionsError: null,
|
|
192
|
-
expectedAssertionsNumber: null,
|
|
193
|
-
expectedAssertionsNumberErrorGen: null,
|
|
194
|
-
currentTestName: getTestName(test),
|
|
195
|
-
snapshotState: this.snapshotClient.getSnapshotState(test.file.filepath)
|
|
196
|
-
}, globalThis[GLOBAL_EXPECT]);
|
|
197
|
-
}
|
|
198
|
-
onAfterTryTask(test) {
|
|
199
|
-
const { assertionCalls, expectedAssertionsNumber, expectedAssertionsNumberErrorGen, isExpectingAssertions, isExpectingAssertionsError } = test.context._local ? test.context.expect.getState() : getState(globalThis[GLOBAL_EXPECT]);
|
|
200
|
-
if (expectedAssertionsNumber !== null && assertionCalls !== expectedAssertionsNumber) throw expectedAssertionsNumberErrorGen();
|
|
201
|
-
if (isExpectingAssertions === true && assertionCalls === 0) throw isExpectingAssertionsError;
|
|
202
|
-
if (this.config.expect.requireAssertions && assertionCalls === 0) throw this.assertionsErrors.get(test);
|
|
203
|
-
}
|
|
204
|
-
extendTaskContext(context) {
|
|
205
|
-
// create error during the test initialization so we have a nice stack trace
|
|
206
|
-
if (this.config.expect.requireAssertions) this.assertionsErrors.set(context.task, new Error("expected any number of assertion, but got none"));
|
|
207
|
-
let _expect;
|
|
208
|
-
Object.defineProperty(context, "expect", { get() {
|
|
209
|
-
if (!_expect) _expect = createExpect(context.task);
|
|
210
|
-
return _expect;
|
|
211
|
-
} });
|
|
212
|
-
Object.defineProperty(context, "_local", { get() {
|
|
213
|
-
return _expect != null;
|
|
214
|
-
} });
|
|
215
|
-
return context;
|
|
216
|
-
}
|
|
217
|
-
getImportDurations() {
|
|
218
|
-
const entries = [...this.workerState.moduleExecutionInfo?.entries() ?? []];
|
|
219
|
-
return Object.fromEntries(entries.map(([filepath, { duration, selfTime }]) => [normalize(filepath), {
|
|
220
|
-
selfTime,
|
|
221
|
-
totalTime: duration
|
|
222
|
-
}]));
|
|
223
|
-
}
|
|
224
|
-
}
|
|
225
|
-
function clearModuleMocks(config) {
|
|
226
|
-
const { clearMocks, mockReset, restoreMocks, unstubEnvs, unstubGlobals } = config;
|
|
227
|
-
// since each function calls another, we can just call one
|
|
228
|
-
if (restoreMocks) vi.restoreAllMocks();
|
|
229
|
-
else if (mockReset) vi.resetAllMocks();
|
|
230
|
-
else if (clearMocks) vi.clearAllMocks();
|
|
231
|
-
if (unstubEnvs) vi.unstubAllEnvs();
|
|
232
|
-
if (unstubGlobals) vi.unstubAllGlobals();
|
|
233
|
-
}
|
|
234
|
-
|
|
235
|
-
export { NodeBenchmarkRunner, VitestTestRunner };
|
|
15
|
+
import './chunks/date.-jtEtIeV.js';
|
|
16
|
+
import './chunks/rpc.BKr6mtxz.js';
|
|
17
|
+
import './chunks/index.Bgo3tNWt.js';
|
package/dist/snapshot.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { VitestNodeSnapshotEnvironment as VitestSnapshotEnvironment } from './chunks/node.
|
|
1
|
+
export { VitestNodeSnapshotEnvironment as VitestSnapshotEnvironment } from './chunks/node.CyipiPvJ.js';
|
|
2
2
|
import '@vitest/snapshot/environment';
|
|
3
|
-
import './chunks/utils.
|
|
3
|
+
import './chunks/utils.D2R2NiOH.js';
|
|
4
4
|
import '@vitest/utils';
|
package/dist/suite.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export { g as getBenchFn, a as getBenchOptions } from './chunks/suite.d.
|
|
1
|
+
export { g as getBenchFn, a as getBenchOptions } from './chunks/suite.d.BJWk38HB.js';
|
|
2
2
|
export { VitestRunner, VitestRunnerConfig, createTaskCollector, getCurrentSuite, getCurrentTest, getFn, getHooks, setFn, setHooks } from '@vitest/runner';
|
|
3
3
|
export { createChainable } from '@vitest/runner/utils';
|
|
4
|
-
import './chunks/benchmark.d.
|
|
4
|
+
import './chunks/benchmark.d.DAaHLpsq.js';
|
|
5
5
|
import 'tinybench';
|
package/dist/suite.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export { g as getBenchFn, a as getBenchOptions } from './chunks/benchmark.
|
|
1
|
+
export { g as getBenchFn, a as getBenchOptions } from './chunks/benchmark.CJUa-Hsa.js';
|
|
2
2
|
export { createTaskCollector, getCurrentSuite, getCurrentTest, getFn, getHooks, setFn, setHooks } from '@vitest/runner';
|
|
3
3
|
export { createChainable } from '@vitest/runner/utils';
|
|
4
4
|
import '@vitest/utils';
|
|
5
|
-
import './chunks/utils.
|
|
5
|
+
import './chunks/utils.D2R2NiOH.js';
|
package/dist/worker.js
CHANGED
|
@@ -1,50 +1,69 @@
|
|
|
1
1
|
import { pathToFileURL } from 'node:url';
|
|
2
2
|
import { createStackString, parseStacktrace } from '@vitest/utils/source-map';
|
|
3
|
-
import {
|
|
4
|
-
import { ViteNodeRunner, ModuleCacheMap } from 'vite-node/client';
|
|
3
|
+
import { ModuleRunner, EvaluatedModules } from 'vite/module-runner';
|
|
5
4
|
import { readFileSync } from 'node:fs';
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
5
|
+
import { isBuiltin } from 'node:module';
|
|
6
|
+
import { resolve } from 'pathe';
|
|
7
|
+
import { V as VitestTransport } from './chunks/moduleTransport.I-bgQy0S.js';
|
|
8
|
+
import { e as environments } from './chunks/index.DIWhzsUh.js';
|
|
9
|
+
import { s as setupInspect } from './chunks/inspector.CvQD-Nie.js';
|
|
10
|
+
import { c as createRuntimeRpc, a as rpcDone } from './chunks/rpc.BKr6mtxz.js';
|
|
11
|
+
import { i as isChildProcess } from './chunks/utils.D2R2NiOH.js';
|
|
12
|
+
import { d as disposeInternalListeners } from './chunks/utils.C2YI6McM.js';
|
|
12
13
|
import 'node:console';
|
|
13
|
-
import 'node:module';
|
|
14
14
|
import '@vitest/utils';
|
|
15
|
-
import './chunks/index.
|
|
15
|
+
import './chunks/index.Bgo3tNWt.js';
|
|
16
16
|
|
|
17
17
|
function isBuiltinEnvironment(env) {
|
|
18
18
|
return env in environments;
|
|
19
19
|
}
|
|
20
|
-
const _loaders = /* @__PURE__ */ new Map();
|
|
21
|
-
async function createEnvironmentLoader(
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
20
|
+
const isWindows = process.platform === "win32", _loaders = /* @__PURE__ */ new Map();
|
|
21
|
+
async function createEnvironmentLoader(root, rpc) {
|
|
22
|
+
const cachedLoader = _loaders.get(root);
|
|
23
|
+
if (!cachedLoader || cachedLoader.isClosed()) {
|
|
24
|
+
_loaders.delete(root);
|
|
25
|
+
const moduleRunner = new ModuleRunner({
|
|
26
|
+
hmr: false,
|
|
27
|
+
sourcemapInterceptor: "prepareStackTrace",
|
|
28
|
+
transport: new VitestTransport({
|
|
29
|
+
async fetchModule(id, importer, options) {
|
|
30
|
+
const result = await rpc.fetch(id, importer, "__vitest__", options);
|
|
31
|
+
if ("cached" in result) {
|
|
32
|
+
const code = readFileSync(result.tmp, "utf-8");
|
|
33
|
+
return {
|
|
34
|
+
code,
|
|
35
|
+
...result
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
if (isWindows && "externalize" in result)
|
|
39
|
+
// TODO: vitest returns paths for external modules, but Vite returns file://
|
|
40
|
+
// https://github.com/vitejs/vite/pull/20449
|
|
41
|
+
result.externalize = isBuiltin(id) || /^(?:node:|data:|http:|https:|file:)/.test(id) ? result.externalize : pathToFileURL(result.externalize).toString();
|
|
42
|
+
return result;
|
|
43
|
+
},
|
|
44
|
+
async resolveId(id, importer) {
|
|
45
|
+
return rpc.resolve(id, importer, "__vitest__");
|
|
46
|
+
}
|
|
47
|
+
})
|
|
48
|
+
});
|
|
49
|
+
_loaders.set(root, moduleRunner), await moduleRunner.import("/@vite/env");
|
|
26
50
|
}
|
|
27
|
-
return _loaders.get(
|
|
51
|
+
return _loaders.get(root);
|
|
28
52
|
}
|
|
29
53
|
async function loadEnvironment(ctx, rpc) {
|
|
30
54
|
const name = ctx.environment.name;
|
|
31
|
-
if (isBuiltinEnvironment(name)) return environments[name];
|
|
32
|
-
const loader = await createEnvironmentLoader({
|
|
33
|
-
root: ctx.config.root,
|
|
34
|
-
fetchModule: async (id) => {
|
|
35
|
-
const result = await rpc.fetch(id, "ssr");
|
|
36
|
-
if (result.id) return { code: readFileSync(result.id, "utf-8") };
|
|
37
|
-
return result;
|
|
38
|
-
},
|
|
39
|
-
resolveId: (id, importer) => rpc.resolveId(id, importer, "ssr")
|
|
40
|
-
});
|
|
41
|
-
const root = loader.root;
|
|
42
|
-
const packageId = name[0] === "." || name[0] === "/" ? resolve(root, name) : (await rpc.resolveId(`vitest-environment-${name}`, void 0, "ssr"))?.id ?? resolve(root, name);
|
|
43
|
-
const pkg = await loader.executeId(normalize(packageId));
|
|
55
|
+
if (isBuiltinEnvironment(name)) return { environment: environments[name] };
|
|
56
|
+
const root = ctx.config.root, loader = await createEnvironmentLoader(root, rpc), packageId = name[0] === "." || name[0] === "/" ? resolve(root, name) : (await rpc.resolve(`vitest-environment-${name}`, void 0, "__vitest__"))?.id ?? resolve(root, name), pkg = await loader.import(packageId);
|
|
44
57
|
if (!pkg || !pkg.default || typeof pkg.default !== "object") throw new TypeError(`Environment "${name}" is not a valid environment. Path "${packageId}" should export default object with a "setup" or/and "setupVM" method.`);
|
|
45
58
|
const environment = pkg.default;
|
|
46
|
-
if (environment.transformMode !== "web" && environment.transformMode !== "ssr") throw new TypeError(`Environment "${name}" is not a valid environment. Path "${packageId}" should export default object with a "transformMode" method equal to "ssr" or "web".`);
|
|
47
|
-
|
|
59
|
+
if (environment.transformMode != null && environment.transformMode !== "web" && environment.transformMode !== "ssr") throw new TypeError(`Environment "${name}" is not a valid environment. Path "${packageId}" should export default object with a "transformMode" method equal to "ssr" or "web", received "${environment.transformMode}".`);
|
|
60
|
+
if (environment.transformMode)
|
|
61
|
+
// keep for backwards compat
|
|
62
|
+
console.warn(`The Vitest environment ${environment.name} defines the "transformMode". This options was deprecated in Vitest 4 and will be removed in the next major version. Please, use "viteEnvironment" instead.`), environment.viteEnvironment ??= environment.transformMode === "ssr" ? "ssr" : "client";
|
|
63
|
+
return {
|
|
64
|
+
environment,
|
|
65
|
+
loader
|
|
66
|
+
};
|
|
48
67
|
}
|
|
49
68
|
|
|
50
69
|
const listeners = /* @__PURE__ */ new Set();
|
|
@@ -57,7 +76,6 @@ async function cleanup() {
|
|
|
57
76
|
}
|
|
58
77
|
|
|
59
78
|
if (isChildProcess()) {
|
|
60
|
-
setProcessTitle(`vitest ${workerId}`);
|
|
61
79
|
const isProfiling = process.execArgv.some((execArg) => execArg.startsWith("--prof") || execArg.startsWith("--cpu-prof") || execArg.startsWith("--heap-prof") || execArg.startsWith("--diagnostic-dir"));
|
|
62
80
|
if (isProfiling)
|
|
63
81
|
// Work-around for nodejs/node#55094
|
|
@@ -65,29 +83,36 @@ if (isChildProcess()) {
|
|
|
65
83
|
process.exit();
|
|
66
84
|
});
|
|
67
85
|
}
|
|
86
|
+
const resolvingModules = /* @__PURE__ */ new Set();
|
|
68
87
|
// this is what every pool executes when running tests
|
|
69
88
|
async function execute(method, ctx) {
|
|
70
89
|
disposeInternalListeners();
|
|
71
|
-
const prepareStart = performance.now();
|
|
72
|
-
const inspectorCleanup = setupInspect(ctx);
|
|
90
|
+
const prepareStart = performance.now(), cleanups = [setupInspect(ctx)];
|
|
73
91
|
process.env.VITEST_WORKER_ID = String(ctx.workerId);
|
|
74
|
-
|
|
92
|
+
const poolId = process.__tinypool_state__?.workerId;
|
|
93
|
+
process.env.VITEST_POOL_ID = String(poolId);
|
|
94
|
+
let environmentLoader;
|
|
75
95
|
try {
|
|
76
96
|
// worker is a filepath or URL to a file that exposes a default export with "getRpcOptions" and "runTests" methods
|
|
77
97
|
if (ctx.worker[0] === ".") throw new Error(`Path to the test runner cannot be relative, received "${ctx.worker}"`);
|
|
78
|
-
const file = ctx.worker.startsWith("file:") ? ctx.worker : pathToFileURL(ctx.worker).toString();
|
|
79
|
-
const testRunnerModule = await import(file);
|
|
98
|
+
const file = ctx.worker.startsWith("file:") ? ctx.worker : pathToFileURL(ctx.worker).toString(), testRunnerModule = await import(file);
|
|
80
99
|
if (!testRunnerModule.default || typeof testRunnerModule.default !== "object") throw new TypeError(`Test worker object should be exposed as a default export. Received "${typeof testRunnerModule.default}"`);
|
|
81
100
|
const worker = testRunnerModule.default;
|
|
82
101
|
if (!worker.getRpcOptions || typeof worker.getRpcOptions !== "function") throw new TypeError(`Test worker should expose "getRpcOptions" method. Received "${typeof worker.getRpcOptions}".`);
|
|
83
102
|
// RPC is used to communicate between worker (be it a thread worker or child process or a custom implementation) and the main thread
|
|
84
103
|
const { rpc, onCancel } = createRuntimeRpc(worker.getRpcOptions(ctx));
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
104
|
+
// do not close the RPC channel so that we can get the error messages sent to the main thread
|
|
105
|
+
cleanups.push(async () => {
|
|
106
|
+
await Promise.all(rpc.$rejectPendingCalls(({ method, reject }) => {
|
|
107
|
+
reject(/* @__PURE__ */ new Error(`[vitest-worker]: Closing rpc while "${method}" was pending`));
|
|
108
|
+
}));
|
|
109
|
+
});
|
|
110
|
+
const beforeEnvironmentTime = performance.now(), { environment, loader } = await loadEnvironment(ctx, rpc);
|
|
111
|
+
environmentLoader = loader;
|
|
88
112
|
const state = {
|
|
89
113
|
ctx,
|
|
90
|
-
|
|
114
|
+
evaluatedModules: new EvaluatedModules(),
|
|
115
|
+
resolvingModules,
|
|
91
116
|
moduleExecutionInfo: /* @__PURE__ */ new Map(),
|
|
92
117
|
config: ctx.config,
|
|
93
118
|
onCancel,
|
|
@@ -101,14 +126,13 @@ async function execute(method, ctx) {
|
|
|
101
126
|
providedContext: ctx.providedContext,
|
|
102
127
|
onFilterStackTrace(stack) {
|
|
103
128
|
return createStackString(parseStacktrace(stack));
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
|
|
129
|
+
},
|
|
130
|
+
metaEnv: createImportMetaEnvProxy()
|
|
131
|
+
}, methodName = method === "collect" ? "collectTests" : "runTests";
|
|
107
132
|
if (!worker[methodName] || typeof worker[methodName] !== "function") throw new TypeError(`Test worker should expose "runTests" method. Received "${typeof worker.runTests}".`);
|
|
108
133
|
await worker[methodName](state);
|
|
109
134
|
} finally {
|
|
110
|
-
await rpcDone().catch(() => {});
|
|
111
|
-
inspectorCleanup();
|
|
135
|
+
await Promise.all(cleanups.map((fn) => fn())), await rpcDone().catch(() => {}), environmentLoader?.close();
|
|
112
136
|
}
|
|
113
137
|
}
|
|
114
138
|
function run(ctx) {
|
|
@@ -120,5 +144,24 @@ function collect(ctx) {
|
|
|
120
144
|
async function teardown() {
|
|
121
145
|
return cleanup();
|
|
122
146
|
}
|
|
147
|
+
function createImportMetaEnvProxy() {
|
|
148
|
+
// packages/vitest/src/node/plugins/index.ts:146
|
|
149
|
+
const booleanKeys = [
|
|
150
|
+
"DEV",
|
|
151
|
+
"PROD",
|
|
152
|
+
"SSR"
|
|
153
|
+
];
|
|
154
|
+
return new Proxy(process.env, {
|
|
155
|
+
get(_, key) {
|
|
156
|
+
return typeof key === "string" ? booleanKeys.includes(key) ? !!process.env[key] : process.env[key] : void 0;
|
|
157
|
+
},
|
|
158
|
+
set(_, key, value) {
|
|
159
|
+
if (typeof key !== "string") return true;
|
|
160
|
+
if (booleanKeys.includes(key)) process.env[key] = value ? "1" : "";
|
|
161
|
+
else process.env[key] = value;
|
|
162
|
+
return true;
|
|
163
|
+
}
|
|
164
|
+
});
|
|
165
|
+
}
|
|
123
166
|
|
|
124
167
|
export { collect, run, teardown };
|
package/dist/workers/forks.js
CHANGED
|
@@ -1,20 +1,44 @@
|
|
|
1
1
|
import v8 from 'node:v8';
|
|
2
|
-
import { r as runBaseTests } from '../chunks/base.
|
|
3
|
-
import { c as createForksRpcOptions, u as unwrapSerializableConfig } from '../chunks/utils.
|
|
4
|
-
import '
|
|
5
|
-
import '
|
|
2
|
+
import { r as runBaseTests } from '../chunks/base.Cjha6usc.js';
|
|
3
|
+
import { c as createForksRpcOptions, u as unwrapSerializableConfig } from '../chunks/utils.C2YI6McM.js';
|
|
4
|
+
import 'node:vm';
|
|
5
|
+
import '@vitest/spy';
|
|
6
|
+
import 'vite/module-runner';
|
|
7
|
+
import '../chunks/startModuleRunner.p67gbNo9.js';
|
|
6
8
|
import 'node:fs';
|
|
9
|
+
import 'node:module';
|
|
10
|
+
import '@vitest/utils';
|
|
7
11
|
import 'node:url';
|
|
8
|
-
import 'node:vm';
|
|
9
|
-
import '@vitest/utils/error';
|
|
10
12
|
import 'pathe';
|
|
11
|
-
import 'vite-node/utils';
|
|
12
13
|
import '../path.js';
|
|
13
14
|
import 'node:path';
|
|
15
|
+
import '@vitest/utils/error';
|
|
16
|
+
import '../module-evaluator.js';
|
|
14
17
|
import '@vitest/mocker';
|
|
15
|
-
import '
|
|
16
|
-
import '
|
|
17
|
-
import '
|
|
18
|
+
import '../chunks/moduleTransport.I-bgQy0S.js';
|
|
19
|
+
import 'node:perf_hooks';
|
|
20
|
+
import '@vitest/runner';
|
|
21
|
+
import '../chunks/resolveSnapshotEnvironment.Bkht6Yor.js';
|
|
22
|
+
import '@vitest/expect';
|
|
23
|
+
import '../chunks/setup-common.uiMcU3cv.js';
|
|
24
|
+
import '../chunks/coverage.D_JHT54q.js';
|
|
25
|
+
import '@vitest/snapshot';
|
|
26
|
+
import '../chunks/utils.D2R2NiOH.js';
|
|
27
|
+
import '../chunks/rpc.BKr6mtxz.js';
|
|
28
|
+
import '../chunks/index.Bgo3tNWt.js';
|
|
29
|
+
import '../chunks/test.BiqSKISg.js';
|
|
30
|
+
import '../chunks/benchmark.CJUa-Hsa.js';
|
|
31
|
+
import '@vitest/runner/utils';
|
|
32
|
+
import '../chunks/vi.ZPgvtBao.js';
|
|
33
|
+
import '../chunks/_commonjsHelpers.BFTU3MAI.js';
|
|
34
|
+
import '@vitest/utils/source-map';
|
|
35
|
+
import '../chunks/date.-jtEtIeV.js';
|
|
36
|
+
import '../chunks/inspector.CvQD-Nie.js';
|
|
37
|
+
import 'node:timers';
|
|
38
|
+
import 'node:timers/promises';
|
|
39
|
+
import 'node:util';
|
|
40
|
+
import '../chunks/index.CMfqw92x.js';
|
|
41
|
+
import 'expect-type';
|
|
18
42
|
|
|
19
43
|
class ForksBaseWorker {
|
|
20
44
|
getRpcOptions() {
|