vitest 4.0.17 → 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.
Files changed (58) hide show
  1. package/dist/browser.d.ts +1 -1
  2. package/dist/browser.js +1 -1
  3. package/dist/chunks/{base.XJJQZiKB.js → base.CBRNZa3k.js} +8 -7
  4. package/dist/chunks/{browser.d.ChKACdzH.d.ts → browser.d.8hOapKZr.d.ts} +3 -1
  5. package/dist/chunks/{cac.jRCLJDDc.js → cac.B1v3xxoC.js} +26 -8
  6. package/dist/chunks/{cli-api.Cx2DW4Bc.js → cli-api.B4CqEpI6.js} +102 -54
  7. package/dist/chunks/{config.d.Cy95HiCx.d.ts → config.d.idH22YSr.d.ts} +8 -11
  8. package/dist/chunks/{console.Cf-YriPC.js → console.uGgdMhyZ.js} +2 -1
  9. package/dist/chunks/{coverage.AVPTjMgw.js → coverage.BMlOMIWl.js} +14 -4
  10. package/dist/chunks/{creator.DAmOKTvJ.js → creator.C7WwjkuR.js} +32 -1
  11. package/dist/chunks/{globals.DOayXfHP.js → globals.DjuGMoMc.js} +10 -9
  12. package/dist/chunks/{index.Z5E_ObnR.js → index.BEFi2-_3.js} +3 -1
  13. package/dist/chunks/{index.6Qv1eEA6.js → index.BiOAd_ki.js} +16 -4
  14. package/dist/chunks/{index.M8mOzt4Y.js → index.Dm4xqZ0s.js} +2 -2
  15. package/dist/chunks/{index.C5r1PdPD.js → index.DyBZXrH3.js} +1 -1
  16. package/dist/chunks/{init-forks.BC6ZwHQN.js → init-forks.CHeQ9Moq.js} +1 -1
  17. package/dist/chunks/{init-threads.CxSxLC0N.js → init-threads.uZiNAuPk.js} +1 -1
  18. package/dist/chunks/{init.C9kljSTm.js → init.DVtKdFty.js} +21 -6
  19. package/dist/chunks/{plugin.d.CtqpEehP.d.ts → plugin.d.D8KU2PY_.d.ts} +1 -1
  20. package/dist/chunks/{reporters.d.CWXNI2jG.d.ts → reporters.d.Db3MiIWX.d.ts} +48 -20
  21. package/dist/chunks/rpc.HLmECnw_.js +148 -0
  22. package/dist/chunks/{setup-common.Cm-kSBVi.js → setup-common.BcqLPsn5.js} +1 -1
  23. package/dist/chunks/{startModuleRunner.DEj0jb3e.js → startModuleRunner.C5CcWyXW.js} +22 -22
  24. package/dist/chunks/{vi.2VT5v0um.js → test.prxIahgM.js} +500 -119
  25. package/dist/chunks/{vm.CMjifoPa.js → vm.CrifS09m.js} +5 -8
  26. package/dist/chunks/{worker.d.Dyxm8DEL.d.ts → worker.d.Bji1eq5g.d.ts} +1 -1
  27. package/dist/cli.js +2 -2
  28. package/dist/config.d.ts +9 -9
  29. package/dist/coverage.d.ts +7 -7
  30. package/dist/coverage.js +3 -1
  31. package/dist/environments.js +2 -0
  32. package/dist/index.d.ts +21 -9
  33. package/dist/index.js +8 -7
  34. package/dist/module-evaluator.js +1 -5
  35. package/dist/node.d.ts +11 -10
  36. package/dist/node.js +19 -19
  37. package/dist/reporters.d.ts +7 -7
  38. package/dist/reporters.js +4 -2
  39. package/dist/runners.d.ts +23 -4
  40. package/dist/runners.js +4 -4
  41. package/dist/runtime.d.ts +6 -0
  42. package/dist/runtime.js +36 -0
  43. package/dist/snapshot.js +2 -0
  44. package/dist/suite.js +2 -0
  45. package/dist/worker.d.ts +4 -3
  46. package/dist/worker.js +8 -10
  47. package/dist/workers/forks.js +9 -11
  48. package/dist/workers/runVmTests.js +10 -12
  49. package/dist/workers/threads.js +9 -11
  50. package/dist/workers/vmForks.js +6 -7
  51. package/dist/workers/vmThreads.js +6 -7
  52. package/package.json +23 -27
  53. package/dist/chunks/date.Bq6ZW5rf.js +0 -73
  54. package/dist/chunks/rpc.BoxB0q7B.js +0 -76
  55. package/dist/chunks/test.B8ej_ZHS.js +0 -254
  56. package/dist/mocker.d.ts +0 -1
  57. package/dist/mocker.js +0 -1
  58. package/dist/module-runner.js +0 -17
@@ -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';
@@ -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.DEj0jb3e.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.CCmnQaNT.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';