vitest 4.0.6 → 4.0.8

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 (65) hide show
  1. package/LICENSE.md +1 -1
  2. package/dist/browser.d.ts +2 -2
  3. package/dist/browser.js +2 -2
  4. package/dist/chunks/base.BgTO2qAg.js +156 -0
  5. package/dist/chunks/{benchmark.DHKMYAts.js → benchmark.B3N2zMcH.js} +9 -4
  6. package/dist/chunks/{browser.d.ScGeWTou.d.ts → browser.d.DTTM2PTh.d.ts} +1 -1
  7. package/dist/chunks/{cac.BBqWH4nd.js → cac.CfkWq8Qy.js} +117 -43
  8. package/dist/chunks/{cli-api.UL3SwFUb.js → cli-api.BQ-bjcRi.js} +1870 -847
  9. package/dist/chunks/console.Cf-YriPC.js +146 -0
  10. package/dist/chunks/{coverage.DuCn_Tmx.js → coverage.NVjCOln1.js} +281 -103
  11. package/dist/chunks/{creator.cqqifzG7.js → creator.fzVyoMf3.js} +74 -30
  12. package/dist/chunks/{date.-jtEtIeV.js → date.Bq6ZW5rf.js} +17 -6
  13. package/dist/chunks/{git.BFNcloKD.js → git.Bm2pzPAa.js} +3 -3
  14. package/dist/chunks/{global.d.DdOkMiVb.d.ts → global.d.DVdCfKp5.d.ts} +1 -1
  15. package/dist/chunks/{globals.BGT_RUsD.js → globals.DOh96BiR.js} +5 -5
  16. package/dist/chunks/{resolveSnapshotEnvironment.BZzLjzkh.js → index.BY4-tcno.js} +42 -25
  17. package/dist/chunks/{index.Bgo3tNWt.js → index.DAL392Ss.js} +40 -15
  18. package/dist/chunks/{index.RwjEGCQ0.js → index.DIFZf73e.js} +2 -2
  19. package/dist/chunks/{index.DV0mQLEO.js → index.DfKyPFVi.js} +195 -64
  20. package/dist/chunks/{index.BL8Hg4Uk.js → index.kotH7DY7.js} +837 -380
  21. package/dist/chunks/{index.CpdwpN7L.js → index.op2Re5rn.js} +22 -12
  22. package/dist/chunks/{init-forks.CSGFj9zN.js → init-forks.2hx7cf78.js} +16 -5
  23. package/dist/chunks/{init-threads.CIJLeFO8.js → init-threads.Cm4OCIWA.js} +3 -2
  24. package/dist/chunks/{init.DUeOfNO9.js → init.DMDG-idf.js} +124 -54
  25. package/dist/chunks/{inspector.DLZxSeU3.js → inspector.CvyFGlXm.js} +25 -10
  26. package/dist/chunks/{moduleRunner.d.TP-w6tIQ.d.ts → moduleRunner.d.CzOZ_4wC.d.ts} +1 -1
  27. package/dist/chunks/{node.BwAWWjHZ.js → node.Ce0vMQM7.js} +1 -1
  28. package/dist/chunks/{plugin.d.lctzD3Wk.d.ts → plugin.d.D4RrtywJ.d.ts} +1 -1
  29. package/dist/chunks/{reporters.d.PEs0tXod.d.ts → reporters.d.Da1D1VbQ.d.ts} +19 -9
  30. package/dist/chunks/rpc.BUV7uWKJ.js +76 -0
  31. package/dist/chunks/{setup-common.DR1sucx6.js → setup-common.LGjNSzXp.js} +20 -8
  32. package/dist/chunks/{startModuleRunner.Di-EZqh0.js → startModuleRunner.BOmUtLIO.js} +228 -105
  33. package/dist/chunks/{test.CnspO-X4.js → test.ClrAtjMv.js} +48 -22
  34. package/dist/chunks/{utils.CG9h5ccR.js → utils.DvEY5TfP.js} +14 -5
  35. package/dist/chunks/{vi.BZvkKVkM.js → vi.Bgcdy3bQ.js} +261 -111
  36. package/dist/chunks/{vm.Co_lR2NL.js → vm.BIkCDs68.js} +177 -70
  37. package/dist/chunks/{worker.d.B4Hthdvt.d.ts → worker.d.DadbA89M.d.ts} +52 -6
  38. package/dist/cli.js +2 -2
  39. package/dist/config.d.ts +5 -5
  40. package/dist/coverage.d.ts +3 -3
  41. package/dist/coverage.js +1 -1
  42. package/dist/environments.js +2 -1
  43. package/dist/index.d.ts +5 -5
  44. package/dist/index.js +5 -5
  45. package/dist/module-evaluator.d.ts +2 -2
  46. package/dist/module-evaluator.js +85 -35
  47. package/dist/module-runner.js +2 -2
  48. package/dist/node.d.ts +7 -7
  49. package/dist/node.js +16 -12
  50. package/dist/reporters.d.ts +3 -3
  51. package/dist/reporters.js +2 -2
  52. package/dist/runners.js +7 -7
  53. package/dist/snapshot.js +2 -2
  54. package/dist/suite.js +2 -2
  55. package/dist/worker.d.ts +2 -1
  56. package/dist/worker.js +27 -27
  57. package/dist/workers/forks.js +34 -31
  58. package/dist/workers/runVmTests.js +41 -22
  59. package/dist/workers/threads.js +34 -31
  60. package/dist/workers/vmForks.js +14 -14
  61. package/dist/workers/vmThreads.js +14 -14
  62. package/package.json +20 -20
  63. package/dist/chunks/base.BAf_bYeI.js +0 -128
  64. package/dist/chunks/console.CTJL2nuH.js +0 -115
  65. package/dist/chunks/rpc.Dv1Jt3i2.js +0 -66
@@ -1,14 +1,14 @@
1
1
  import { updateTask } from '@vitest/runner';
2
2
  import { createDefer } from '@vitest/utils/helpers';
3
3
  import { getSafeTimers } from '@vitest/utils/timers';
4
- import { a as getBenchOptions, g as getBenchFn } from './benchmark.DHKMYAts.js';
5
- import { g as getWorkerState } from './utils.CG9h5ccR.js';
4
+ import { a as getBenchOptions, g as getBenchFn } from './benchmark.B3N2zMcH.js';
5
+ import { g as getWorkerState } from './utils.DvEY5TfP.js';
6
6
  import { setState, GLOBAL_EXPECT, getState } from '@vitest/expect';
7
7
  import { getTests, getNames, getTestName } from '@vitest/runner/utils';
8
8
  import { processError } from '@vitest/utils/error';
9
9
  import { normalize } from 'pathe';
10
- import { a as getSnapshotClient, i as inject, c as createExpect, v as vi } from './vi.BZvkKVkM.js';
11
- import { r as rpc } from './rpc.Dv1Jt3i2.js';
10
+ import { a as getSnapshotClient, i as inject, c as createExpect, v as vi } from './vi.Bgcdy3bQ.js';
11
+ import { r as rpc } from './rpc.BUV7uWKJ.js';
12
12
 
13
13
  function createBenchmarkResult(name) {
14
14
  return {
@@ -20,7 +20,10 @@ function createBenchmarkResult(name) {
20
20
  }
21
21
  const benchmarkTasks = /* @__PURE__ */ new WeakMap();
22
22
  async function runBenchmarkSuite(suite, runner) {
23
- const { Task, Bench } = await runner.importTinybench(), start = performance.now(), benchmarkGroup = [], benchmarkSuiteGroup = [];
23
+ const { Task, Bench } = await runner.importTinybench();
24
+ const start = performance.now();
25
+ const benchmarkGroup = [];
26
+ const benchmarkSuiteGroup = [];
24
27
  for (const task of suite.tasks) {
25
28
  if (task.mode !== "run" && task.mode !== "queued") continue;
26
29
  if (task.meta?.benchmark) benchmarkGroup.push(task);
@@ -34,38 +37,53 @@ async function runBenchmarkSuite(suite, runner) {
34
37
  state: "run",
35
38
  startTime: start,
36
39
  benchmark: createBenchmarkResult(suite.name)
37
- }, updateTask$1("suite-prepare", suite);
40
+ };
41
+ updateTask$1("suite-prepare", suite);
38
42
  const addBenchTaskListener = (task, benchmark) => {
39
43
  task.addEventListener("complete", (e) => {
40
- const taskRes = e.task.result, result = benchmark.result.benchmark;
41
- benchmark.result.state = "pass", Object.assign(result, taskRes);
44
+ const taskRes = e.task.result;
45
+ const result = benchmark.result.benchmark;
46
+ benchmark.result.state = "pass";
47
+ Object.assign(result, taskRes);
42
48
  // compute extra stats and free raw samples as early as possible
43
49
  const samples = result.samples;
44
- if (result.sampleCount = samples.length, result.median = samples.length % 2 ? samples[Math.floor(samples.length / 2)] : (samples[samples.length / 2] + samples[samples.length / 2 - 1]) / 2, !runner.config.benchmark?.includeSamples) result.samples.length = 0;
50
+ result.sampleCount = samples.length;
51
+ result.median = samples.length % 2 ? samples[Math.floor(samples.length / 2)] : (samples[samples.length / 2] + samples[samples.length / 2 - 1]) / 2;
52
+ if (!runner.config.benchmark?.includeSamples) result.samples.length = 0;
45
53
  updateTask$1("test-finished", benchmark);
46
- }, { once: true }), task.addEventListener("error", (e) => {
54
+ }, { once: true });
55
+ task.addEventListener("error", (e) => {
47
56
  const task = e.task;
48
57
  defer.reject(benchmark ? task.result.error : e);
49
58
  }, { once: true });
50
59
  };
51
60
  benchmarkGroup.forEach((benchmark) => {
52
- const options = getBenchOptions(benchmark), benchmarkInstance = new Bench(options), benchmarkFn = getBenchFn(benchmark);
61
+ const benchmarkInstance = new Bench(getBenchOptions(benchmark));
62
+ const benchmarkFn = getBenchFn(benchmark);
53
63
  benchmark.result = {
54
64
  state: "run",
55
65
  startTime: start,
56
66
  benchmark: createBenchmarkResult(benchmark.name)
57
67
  };
58
68
  const task = new Task(benchmarkInstance, benchmark.name, benchmarkFn);
59
- benchmarkTasks.set(benchmark, task), addBenchTaskListener(task, benchmark);
69
+ benchmarkTasks.set(benchmark, task);
70
+ addBenchTaskListener(task, benchmark);
60
71
  });
61
- const { setTimeout } = getSafeTimers(), tasks = [];
72
+ const { setTimeout } = getSafeTimers();
73
+ const tasks = [];
62
74
  for (const benchmark of benchmarkGroup) {
63
75
  const task = benchmarkTasks.get(benchmark);
64
- updateTask$1("test-prepare", benchmark), await task.warmup(), tasks.push([await new Promise((resolve) => setTimeout(async () => {
76
+ updateTask$1("test-prepare", benchmark);
77
+ await task.warmup();
78
+ tasks.push([await new Promise((resolve) => setTimeout(async () => {
65
79
  resolve(await task.run());
66
80
  })), benchmark]);
67
81
  }
68
- suite.result.duration = performance.now() - start, suite.result.state = "pass", updateTask$1("suite-finished", suite), defer.resolve(null), await defer;
82
+ suite.result.duration = performance.now() - start;
83
+ suite.result.state = "pass";
84
+ updateTask$1("suite-finished", suite);
85
+ defer.resolve(null);
86
+ await defer;
69
87
  }
70
88
  function updateTask$1(event, task) {
71
89
  updateTask(event, task, runner);
@@ -120,7 +138,8 @@ class VitestTestRunner {
120
138
  this.workerState.onCleanup(listener);
121
139
  }
122
140
  onAfterRunFiles() {
123
- this.snapshotClient.clear(), this.workerState.current = void 0;
141
+ this.snapshotClient.clear();
142
+ this.workerState.current = void 0;
124
143
  }
125
144
  getWorkerContext() {
126
145
  return workerContext;
@@ -137,7 +156,9 @@ class VitestTestRunner {
137
156
  if (this.workerState.config.snapshotOptions.updateSnapshot === "none" && result.unchecked) {
138
157
  let message = `Obsolete snapshots found when no snapshot update is expected.\n`;
139
158
  for (const key of result.uncheckedKeys) message += `· ${key}\n`;
140
- suite.result.errors ??= [], suite.result.errors.push(processError(new Error(message))), suite.result.state = "fail";
159
+ suite.result.errors ??= [];
160
+ suite.result.errors.push(processError(new Error(message)));
161
+ suite.result.state = "fail";
141
162
  }
142
163
  await rpc().snapshotSaved(result);
143
164
  }
@@ -157,7 +178,8 @@ class VitestTestRunner {
157
178
  }
158
179
  async onBeforeRunTask(test) {
159
180
  if (this.cancelRun) test.mode = "skip";
160
- test.mode !== "run" && test.mode !== "queued" || (this.workerState.current = test);
181
+ if (test.mode !== "run" && test.mode !== "queued") return;
182
+ this.workerState.current = test;
161
183
  }
162
184
  async onBeforeRunSuite(suite) {
163
185
  if (this.cancelRun) suite.mode = "skip";
@@ -166,7 +188,9 @@ class VitestTestRunner {
166
188
  this.workerState.current = suite;
167
189
  }
168
190
  onBeforeTryTask(test) {
169
- clearModuleMocks(this.config), this.snapshotClient.clearTest(test.file.filepath, test.id), setState({
191
+ clearModuleMocks(this.config);
192
+ this.snapshotClient.clearTest(test.file.filepath, test.id);
193
+ setState({
170
194
  assertionCalls: 0,
171
195
  isExpectingAssertions: false,
172
196
  isExpectingAssertionsError: null,
@@ -186,12 +210,14 @@ class VitestTestRunner {
186
210
  // create error during the test initialization so we have a nice stack trace
187
211
  if (this.config.expect.requireAssertions) this.assertionsErrors.set(context.task, /* @__PURE__ */ new Error("expected any number of assertion, but got none"));
188
212
  let _expect;
189
- return Object.defineProperty(context, "expect", { get() {
213
+ Object.defineProperty(context, "expect", { get() {
190
214
  if (!_expect) _expect = createExpect(context.task);
191
215
  return _expect;
192
- } }), Object.defineProperty(context, "_local", { get() {
216
+ } });
217
+ Object.defineProperty(context, "_local", { get() {
193
218
  return _expect != null;
194
- } }), context;
219
+ } });
220
+ return context;
195
221
  }
196
222
  getImportDurations() {
197
223
  const entries = [...this.workerState.moduleExecutionInfo?.entries() ?? []];
@@ -8,12 +8,13 @@ function getWorkerState() {
8
8
  return workerState;
9
9
  }
10
10
  function provideWorkerState(context, state) {
11
- return Object.defineProperty(context, NAME_WORKER_STATE, {
11
+ Object.defineProperty(context, NAME_WORKER_STATE, {
12
12
  value: state,
13
13
  configurable: true,
14
14
  writable: true,
15
15
  enumerable: false
16
- }), state;
16
+ });
17
+ return state;
17
18
  }
18
19
  function isChildProcess() {
19
20
  return typeof process !== "undefined" && !!process.send;
@@ -26,7 +27,11 @@ function resetModules(modules, resetMocks = false) {
26
27
  ...!resetMocks ? [/^mock:/] : []
27
28
  ];
28
29
  modules.idToModuleMap.forEach((node, path) => {
29
- skipPaths.some((re) => re.test(path)) || (node.promise = void 0, node.exports = void 0, node.evaluated = false, node.importers.clear());
30
+ if (skipPaths.some((re) => re.test(path))) return;
31
+ node.promise = void 0;
32
+ node.exports = void 0;
33
+ node.evaluated = false;
34
+ node.importers.clear();
30
35
  });
31
36
  }
32
37
  function waitNextTick() {
@@ -35,9 +40,13 @@ function waitNextTick() {
35
40
  }
36
41
  async function waitForImportsToResolve() {
37
42
  await waitNextTick();
38
- const state = getWorkerState(), promises = [], resolvingCount = state.resolvingModules.size;
43
+ const state = getWorkerState();
44
+ const promises = [];
45
+ const resolvingCount = state.resolvingModules.size;
39
46
  for (const [_, mod] of state.evaluatedModules.idToModuleMap) if (mod.promise && !mod.evaluated) promises.push(mod.promise);
40
- !promises.length && !resolvingCount || (await Promise.allSettled(promises), await waitForImportsToResolve());
47
+ if (!promises.length && !resolvingCount) return;
48
+ await Promise.allSettled(promises);
49
+ await waitForImportsToResolve();
41
50
  }
42
51
 
43
52
  export { getWorkerState as g, isChildProcess as i, provideWorkerState as p, resetModules as r, waitForImportsToResolve as w };