vitest 2.1.0-beta.6 → 2.1.0

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 (56) hide show
  1. package/LICENSE.md +52 -342
  2. package/dist/browser.d.ts +4 -2
  3. package/dist/browser.js +1 -1
  4. package/dist/chunks/{RandomSequencer.CjkAy_bL.js → RandomSequencer.Bh5-tlNJ.js} +10 -37
  5. package/dist/chunks/{base.BH-FAiX7.js → base.BlXpj3e_.js} +1 -29
  6. package/dist/chunks/{base.B-9RAXb6.js → base.CsQmmYBA.js} +2 -4
  7. package/dist/chunks/{cac.BZlOqtiQ.js → cac.Ce8UWvQp.js} +25 -16
  8. package/dist/chunks/{cli-api.B-2f6g4d.js → cli-api.KmLFBnKP.js} +2778 -3488
  9. package/dist/chunks/{creator.D0TxjnLa.js → creator.zfBZSJzo.js} +8 -11
  10. package/dist/chunks/{execute.DT9BA6zp.js → execute._eQQfgI8.js} +322 -232
  11. package/dist/chunks/{git.ZtkbKc8u.js → git.B5SDxu-n.js} +5 -5
  12. package/dist/chunks/{globals.Br36EZIp.js → globals.C03P0O1a.js} +3 -3
  13. package/dist/chunks/{index.CM5UI-4O.js → index.Bn75ITYg.js} +3 -3
  14. package/dist/chunks/index.CPD77dLA.js +133 -0
  15. package/dist/chunks/{index.dWDhoZDV.js → index.DkN6V87F.js} +1 -1
  16. package/dist/chunks/{index.m3Xip5Zz.js → index.iyKRMe3s.js} +1 -1
  17. package/dist/chunks/{index.C4LZENmc.js → index.zPibhCkV.js} +43 -45
  18. package/dist/chunks/mocker.cRtM890J.d.ts +17 -0
  19. package/dist/chunks/{reporters.B0Ao6Zu1.d.ts → reporters.WnPwkmgA.d.ts} +30 -22
  20. package/dist/chunks/{resolveConfig.C0vpvVRF.js → resolveConfig.-K5hHm0S.js} +19 -6
  21. package/dist/chunks/{runBaseTests.Cf8lGnUq.js → runBaseTests.9YDrdSI4.js} +6 -6
  22. package/dist/chunks/{setup-common.B7uEQsGB.js → setup-common.DV1PI68g.js} +1 -1
  23. package/dist/chunks/{utils.C3_cBsyn.js → utils.Cn0zI1t3.js} +16 -3
  24. package/dist/chunks/{utils.DO38lwfj.js → utils.Dbnmsfq1.js} +1 -1
  25. package/dist/chunks/{vi.DBepMgvg.js → vi.D6IHiKAI.js} +40 -46
  26. package/dist/chunks/{vite.Bvz2vSw0.d.ts → vite.D2yAwzwa.d.ts} +1 -1
  27. package/dist/chunks/{vm.kl9T_5ai.js → vm.CPXwWp4C.js} +1 -2
  28. package/dist/chunks/{worker.DTM-0OlZ.d.ts → worker.Bws9Zuxu.d.ts} +1 -1
  29. package/dist/chunks/{worker.CTdJUeeB.d.ts → worker.CmPmTxgH.d.ts} +1 -14
  30. package/dist/cli.js +2 -2
  31. package/dist/config.d.ts +2 -2
  32. package/dist/coverage.d.ts +1 -1
  33. package/dist/coverage.js +4 -4
  34. package/dist/execute.d.ts +12 -13
  35. package/dist/execute.js +3 -2
  36. package/dist/index.d.ts +17 -15
  37. package/dist/index.js +4 -4
  38. package/dist/mocker.d.ts +1 -0
  39. package/dist/mocker.js +1 -0
  40. package/dist/node.d.ts +15 -7
  41. package/dist/node.js +18 -16
  42. package/dist/reporters.d.ts +1 -1
  43. package/dist/reporters.js +5 -5
  44. package/dist/runners.js +2 -2
  45. package/dist/utils.d.ts +1 -0
  46. package/dist/worker.js +3 -2
  47. package/dist/workers/forks.js +5 -4
  48. package/dist/workers/runVmTests.js +5 -5
  49. package/dist/workers/threads.js +5 -4
  50. package/dist/workers/vmForks.js +4 -4
  51. package/dist/workers/vmThreads.js +4 -4
  52. package/dist/workers.d.ts +2 -2
  53. package/dist/workers.js +6 -5
  54. package/mocker.d.ts +1 -0
  55. package/package.json +22 -17
  56. package/dist/chunks/index.CWhwfxXK.js +0 -835
@@ -1,5 +1,5 @@
1
1
  import { resolve } from 'pathe';
2
- import { execa } from 'execa';
2
+ import { x } from 'tinyexec';
3
3
 
4
4
  class VitestGit {
5
5
  constructor(cwd) {
@@ -9,7 +9,7 @@ class VitestGit {
9
9
  async resolveFilesWithGitCommand(args) {
10
10
  let result;
11
11
  try {
12
- result = await execa("git", args, { cwd: this.root });
12
+ result = await x("git", args, { nodeOptions: { cwd: this.root } });
13
13
  } catch (e) {
14
14
  e.message = e.stderr;
15
15
  throw e;
@@ -56,10 +56,10 @@ class VitestGit {
56
56
  ]);
57
57
  }
58
58
  async getRoot(cwd) {
59
- const options = ["rev-parse", "--show-cdup"];
59
+ const args = ["rev-parse", "--show-cdup"];
60
60
  try {
61
- const result = await execa("git", options, { cwd });
62
- return resolve(cwd, result.stdout);
61
+ const result = await x("git", args, { nodeOptions: { cwd } });
62
+ return resolve(cwd, result.stdout.trim());
63
63
  } catch {
64
64
  return null;
65
65
  }
@@ -1,5 +1,5 @@
1
1
  import { g as globalApis } from './constants.fzPh7AOq.js';
2
- import { V as VitestIndex } from './index.m3Xip5Zz.js';
2
+ import { V as VitestIndex } from './index.iyKRMe3s.js';
3
3
  import '@vitest/runner';
4
4
  import './benchmark.C8CRJYG4.js';
5
5
  import '@vitest/runner/utils';
@@ -10,7 +10,7 @@ import './utils.Ck2hJTRs.js';
10
10
  import './env.CmHVDJnw.js';
11
11
  import 'std-env';
12
12
  import './run-once.Sxe67Wng.js';
13
- import './vi.DBepMgvg.js';
13
+ import './vi.D6IHiKAI.js';
14
14
  import 'chai';
15
15
  import './_commonjsHelpers.BFTU3MAI.js';
16
16
  import '@vitest/expect';
@@ -18,7 +18,7 @@ import '@vitest/snapshot';
18
18
  import '@vitest/utils/error';
19
19
  import './tasks.BZnCS9aT.js';
20
20
  import '@vitest/utils/source-map';
21
- import './base.BH-FAiX7.js';
21
+ import './base.BlXpj3e_.js';
22
22
  import './date.W2xKR2qe.js';
23
23
  import '@vitest/spy';
24
24
 
@@ -4,7 +4,7 @@ import process$1 from 'node:process';
4
4
  import { promises } from 'node:fs';
5
5
  import { g as getDefaultExportFromCjs } from './_commonjsHelpers.BFTU3MAI.js';
6
6
  import require$$0 from 'readline';
7
- import require$$0$1 from 'events';
7
+ import require$$2 from 'events';
8
8
 
9
9
  function _mergeNamespaces(n, m) {
10
10
  m.forEach(function (e) {
@@ -795,7 +795,7 @@ function requirePrompt$1 () {
795
795
  const _require = requireUtil$1(),
796
796
  action = _require.action;
797
797
 
798
- const EventEmitter = require$$0$1;
798
+ const EventEmitter = require$$2;
799
799
 
800
800
  const _require2 = requireSrc(),
801
801
  beep = _require2.beep,
@@ -3957,7 +3957,7 @@ function requirePrompt () {
3957
3957
 
3958
3958
  const readline = require$$0;
3959
3959
  const { action } = requireUtil();
3960
- const EventEmitter = require$$0$1;
3960
+ const EventEmitter = require$$2;
3961
3961
  const { beep, cursor } = requireSrc();
3962
3962
  const color = requireKleur();
3963
3963
 
@@ -0,0 +1,133 @@
1
+ import process$1 from 'process';
2
+ import fs from 'node:fs';
3
+ import fsp from 'node:fs/promises';
4
+ import path from 'node:path';
5
+ import process from 'node:process';
6
+ import { existsSync } from 'fs';
7
+ import { resolve } from 'path';
8
+ import { x } from 'tinyexec';
9
+
10
+ const AGENTS = [
11
+ "npm",
12
+ "yarn",
13
+ "yarn@berry",
14
+ "pnpm",
15
+ "pnpm@6",
16
+ "bun"
17
+ ];
18
+ const LOCKS = {
19
+ "bun.lockb": "bun",
20
+ "pnpm-lock.yaml": "pnpm",
21
+ "yarn.lock": "yarn",
22
+ "package-lock.json": "npm",
23
+ "npm-shrinkwrap.json": "npm"
24
+ };
25
+
26
+ async function detect({ cwd, onUnknown } = {}) {
27
+ for (const directory of lookup(cwd)) {
28
+ for (const lock of Object.keys(LOCKS)) {
29
+ if (await fileExists(path.join(directory, lock))) {
30
+ const name = LOCKS[lock];
31
+ const result2 = await parsePackageJson(path.join(directory, "package.json"), onUnknown);
32
+ if (result2)
33
+ return result2;
34
+ else
35
+ return { name, agent: name };
36
+ }
37
+ }
38
+ const result = await parsePackageJson(path.join(directory, "package.json"), onUnknown);
39
+ if (result)
40
+ return result;
41
+ }
42
+ return null;
43
+ }
44
+ function* lookup(cwd = process.cwd()) {
45
+ let directory = path.resolve(cwd);
46
+ const { root } = path.parse(directory);
47
+ while (directory && directory !== root) {
48
+ yield directory;
49
+ directory = path.dirname(directory);
50
+ }
51
+ }
52
+ async function parsePackageJson(filepath, onUnknown) {
53
+ if (!filepath || !await fileExists(filepath))
54
+ return null;
55
+ try {
56
+ const pkg = JSON.parse(fs.readFileSync(filepath, "utf8"));
57
+ let agent;
58
+ if (typeof pkg.packageManager === "string") {
59
+ const [name, ver] = pkg.packageManager.replace(/^\^/, "").split("@");
60
+ let version = ver;
61
+ if (name === "yarn" && Number.parseInt(ver) > 1) {
62
+ agent = "yarn@berry";
63
+ version = "berry";
64
+ return { name, agent, version };
65
+ } else if (name === "pnpm" && Number.parseInt(ver) < 7) {
66
+ agent = "pnpm@6";
67
+ return { name, agent, version };
68
+ } else if (AGENTS.includes(name)) {
69
+ agent = name;
70
+ return { name, agent, version };
71
+ } else {
72
+ return onUnknown?.(pkg.packageManager) ?? null;
73
+ }
74
+ }
75
+ } catch {
76
+ }
77
+ return null;
78
+ }
79
+ async function fileExists(filePath) {
80
+ try {
81
+ const stats = await fsp.stat(filePath);
82
+ if (stats.isFile()) {
83
+ return true;
84
+ }
85
+ } catch {
86
+ }
87
+ return false;
88
+ }
89
+
90
+ // src/detect.ts
91
+ async function detectPackageManager(cwd = process$1.cwd()) {
92
+ const result = await detect({
93
+ cwd,
94
+ onUnknown(packageManager) {
95
+ console.warn("[@antfu/install-pkg] Unknown packageManager:", packageManager);
96
+ return void 0;
97
+ }
98
+ });
99
+ return result?.agent || null;
100
+ }
101
+ async function installPackage(names, options = {}) {
102
+ const detectedAgent = options.packageManager || await detectPackageManager(options.cwd) || "npm";
103
+ const [agent] = detectedAgent.split("@");
104
+ if (!Array.isArray(names))
105
+ names = [names];
106
+ const args = options.additionalArgs || [];
107
+ if (options.preferOffline) {
108
+ if (detectedAgent === "yarn@berry")
109
+ args.unshift("--cached");
110
+ else
111
+ args.unshift("--prefer-offline");
112
+ }
113
+ if (agent === "pnpm" && existsSync(resolve(options.cwd ?? process$1.cwd(), "pnpm-workspace.yaml")))
114
+ args.unshift("-w");
115
+ return x(
116
+ agent,
117
+ [
118
+ agent === "yarn" ? "add" : "install",
119
+ options.dev ? "-D" : "",
120
+ ...args,
121
+ ...names
122
+ ].filter(Boolean),
123
+ {
124
+ nodeOptions: {
125
+ stdio: options.silent ? "ignore" : "inherit",
126
+ cwd: options.cwd
127
+ },
128
+ throwOnError: true
129
+ }
130
+ );
131
+ }
132
+
133
+ export { detectPackageManager, installPackage };
@@ -4,7 +4,7 @@ import { distDir } from '../path.js';
4
4
  import { g as getWorkerState } from './utils.Ck2hJTRs.js';
5
5
  import { r as rpc } from './rpc.B7Mfb-Yf.js';
6
6
  import { t as takeCoverageInsideWorker } from './coverage.zlNdAMHK.js';
7
- import { l as loadDiffConfig, a as loadSnapshotSerializers } from './setup-common.B7uEQsGB.js';
7
+ import { l as loadDiffConfig, a as loadSnapshotSerializers } from './setup-common.DV1PI68g.js';
8
8
 
9
9
  function setupChaiConfig(config) {
10
10
  Object.assign(chai.config, config);
@@ -1,7 +1,7 @@
1
1
  import { afterAll, afterEach, beforeAll, beforeEach, describe, it, onTestFailed, onTestFinished, suite, test } from '@vitest/runner';
2
2
  import { b as bench } from './benchmark.C8CRJYG4.js';
3
3
  import { i as isFirstRun, a as runOnce } from './run-once.Sxe67Wng.js';
4
- import { c as createExpect, a as globalExpect, v as vi, b as vitest } from './vi.DBepMgvg.js';
4
+ import { c as createExpect, a as globalExpect, v as vi, b as vitest } from './vi.D6IHiKAI.js';
5
5
  import { g as getWorkerState } from './utils.Ck2hJTRs.js';
6
6
  import * as chai from 'chai';
7
7
  import { assert, should } from 'chai';
@@ -5,24 +5,23 @@ import { relative, resolve, dirname, extname, normalize } from 'pathe';
5
5
  import { g as getTestName, h as hasFailedSnapshot, a as getFullName } from './tasks.BZnCS9aT.js';
6
6
  import { notNullish, highlight, inspect, positionToOffset, lineSplitRE } from '@vitest/utils';
7
7
  import { a as isNode, b as isDeno } from './env.CmHVDJnw.js';
8
- import { g as getStateSymbol, f as formatProjectName, t as taskFail, F as F_RIGHT, a as F_POINTER, r as renderSnapshotSummary, b as getStateString, c as formatTimeString, d as countTestErrors, e as divider, s as stripAnsi, h as getCols, i as getHookStateSymbol } from './utils.DO38lwfj.js';
8
+ import { g as getStateSymbol, f as formatProjectName, t as taskFail, F as F_RIGHT, a as F_POINTER, r as renderSnapshotSummary, b as getStateString, c as formatTimeString, d as countTestErrors, e as divider, s as stripAnsi, h as getCols, i as getHookStateSymbol } from './utils.Dbnmsfq1.js';
9
9
  import { getTests, hasFailed, getSuites, getTasks } from '@vitest/runner/utils';
10
10
  import { performance } from 'node:perf_hooks';
11
11
  import { parseStacktrace, parseErrorStacktrace } from '@vitest/utils/source-map';
12
12
  import { r as relativePath } from './index.CxRxs566.js';
13
- import { t as toArray, c as isPrimitive } from './base.BH-FAiX7.js';
13
+ import { t as toArray, b as isPrimitive } from './base.BlXpj3e_.js';
14
14
  import { isCI } from 'std-env';
15
- import { g as getOutputFile, R as RandomSequencer, a as TypeCheckError } from './RandomSequencer.CjkAy_bL.js';
15
+ import { g as getOutputFile, R as RandomSequencer, a as TypeCheckError } from './RandomSequencer.Bh5-tlNJ.js';
16
16
  import { hostname } from 'node:os';
17
17
  import { Writable } from 'node:stream';
18
18
  import { Console } from 'node:console';
19
19
  import process$2 from 'node:process';
20
20
  import { g as getDefaultExportFromCjs, c as commonjsGlobal } from './_commonjsHelpers.BFTU3MAI.js';
21
- import require$$0$1 from 'assert';
22
- import require$$0 from 'events';
21
+ import require$$0 from 'assert';
22
+ import require$$2 from 'events';
23
23
  import { createRequire } from 'node:module';
24
24
  import { mkdir, writeFile, readdir, stat, readFile } from 'node:fs/promises';
25
- import { cleanUrl } from 'vite-node/utils';
26
25
 
27
26
  class TestProject {
28
27
  /**
@@ -811,13 +810,6 @@ ${log.content}`);
811
810
  0
812
811
  );
813
812
  const threadTime = collectTime + testsTime + setupTime;
814
- const padTitle = (str) => c.dim(`${str.padStart(11)} `);
815
- const time = (time2) => {
816
- if (time2 > 1e3) {
817
- return `${(time2 / 1e3).toFixed(2)}s`;
818
- }
819
- return `${Math.round(time2)}ms`;
820
- };
821
813
  const snapshotOutput = renderSnapshotSummary(
822
814
  this.ctx.config.root,
823
815
  this.ctx.snapshot.summary
@@ -1001,6 +993,15 @@ ${c.cyan(c.inverse(c.bold(" BENCH ")))} ${c.cyan("Summary")}
1001
993
  };
1002
994
  }
1003
995
  }
996
+ function padTitle(str) {
997
+ return c.dim(`${str.padStart(11)} `);
998
+ }
999
+ function time(time2) {
1000
+ if (time2 > 1e3) {
1001
+ return `${(time2 / 1e3).toFixed(2)}s`;
1002
+ }
1003
+ return `${Math.round(time2)}ms`;
1004
+ }
1004
1005
 
1005
1006
  class BasicReporter extends BaseReporter {
1006
1007
  constructor() {
@@ -2904,11 +2905,11 @@ if (!processOk(process$1)) {
2904
2905
  return function () {}
2905
2906
  };
2906
2907
  } else {
2907
- var assert = require$$0$1;
2908
+ var assert = require$$0;
2908
2909
  var signals = requireSignals();
2909
2910
  var isWin = /^win/i.test(process$1.platform);
2910
2911
 
2911
- var EE = require$$0;
2912
+ var EE = require$$2;
2912
2913
  /* istanbul ignore if */
2913
2914
  if (typeof EE !== 'function') {
2914
2915
  EE = EE.EventEmitter;
@@ -3979,10 +3980,12 @@ No ${config.mode} files found, exiting with code 1`)
3979
3980
  const output = project.isCore() ? "" : ` [${name}]`;
3980
3981
  const resolvedUrls = project.browser.vite.resolvedUrls;
3981
3982
  const origin = resolvedUrls?.local[0] ?? resolvedUrls?.network[0];
3983
+ const provider = project.browser.provider.name;
3984
+ const providerString = provider === "preview" ? "" : ` by ${provider}`;
3982
3985
  this.log(
3983
3986
  c.dim(
3984
3987
  c.green(
3985
- ` ${output} Browser runner started at ${new URL("/", origin)}`
3988
+ ` ${output} Browser runner started${providerString} at ${new URL("/", origin)}`
3986
3989
  )
3987
3990
  )
3988
3991
  );
@@ -4318,9 +4321,6 @@ function generateCodeFrame(source, indent = 0, loc, range = 2) {
4318
4321
  let count = 0;
4319
4322
  let res = [];
4320
4323
  const columns = process.stdout?.columns || 80;
4321
- function lineNo(no = "") {
4322
- return c.gray(`${String(no).padStart(3, " ")}| `);
4323
- }
4324
4324
  for (let i = 0; i < lines.length; i++) {
4325
4325
  count += lines[i].length + nl;
4326
4326
  if (count >= start) {
@@ -4358,6 +4358,9 @@ function generateCodeFrame(source, indent = 0, loc, range = 2) {
4358
4358
  }
4359
4359
  return res.join("\n");
4360
4360
  }
4361
+ function lineNo(no = "") {
4362
+ return c.gray(`${String(no).padStart(3, " ")}| `);
4363
+ }
4361
4364
 
4362
4365
  function flattenTasks$1(task, baseName = "") {
4363
4366
  const base = baseName ? `${baseName} > ` : "";
@@ -4736,11 +4739,16 @@ class BlobReporter {
4736
4739
  const shard = this.ctx.config.shard;
4737
4740
  outputFile = shard ? `.vitest-reports/blob-${shard.index}-${shard.count}.json` : ".vitest-reports/blob.json";
4738
4741
  }
4739
- const moduleKeys = this.ctx.projects.map(
4742
+ const modules = this.ctx.projects.map(
4740
4743
  (project) => {
4741
4744
  return [
4742
4745
  project.getName(),
4743
- [...project.server.moduleGraph.idToModuleMap.keys()]
4746
+ [...project.server.moduleGraph.idToModuleMap.entries()].map((mod) => {
4747
+ if (!mod[1].file) {
4748
+ return null;
4749
+ }
4750
+ return [mod[0], mod[1].file, mod[1].url];
4751
+ }).filter((x) => x != null)
4744
4752
  ];
4745
4753
  }
4746
4754
  );
@@ -4748,7 +4756,7 @@ class BlobReporter {
4748
4756
  this.ctx.version,
4749
4757
  files,
4750
4758
  errors,
4751
- moduleKeys,
4759
+ modules,
4752
4760
  coverage
4753
4761
  ]);
4754
4762
  const reportFile = resolve(this.ctx.config.root, outputFile);
@@ -4760,7 +4768,7 @@ class BlobReporter {
4760
4768
  this.ctx.logger.log("blob report written to", reportFile);
4761
4769
  }
4762
4770
  }
4763
- async function readBlobs(blobsDirectory, projectsArray) {
4771
+ async function readBlobs(currentVersion, blobsDirectory, projectsArray) {
4764
4772
  const resolvedDir = resolve(process.cwd(), blobsDirectory);
4765
4773
  const blobsFiles = await readdir(resolvedDir);
4766
4774
  const promises = blobsFiles.map(async (filename) => {
@@ -4796,6 +4804,11 @@ async function readBlobs(blobsDirectory, projectsArray) {
4796
4804
  ${blobs.map((b) => `- "${b.file}" uses v${b.version}`).join("\n")}`
4797
4805
  );
4798
4806
  }
4807
+ if (!versions.has(currentVersion)) {
4808
+ throw new Error(
4809
+ `the blobs in "${blobsDirectory}" were generated by a different version of Vitest. Expected v${currentVersion}, but received v${blobs[0].version}`
4810
+ );
4811
+ }
4799
4812
  const projects = Object.fromEntries(
4800
4813
  projectsArray.map((p) => [p.getName(), p])
4801
4814
  );
@@ -4805,26 +4818,11 @@ ${blobs.map((b) => `- "${b.file}" uses v${b.version}`).join("\n")}`
4805
4818
  if (!project) {
4806
4819
  return;
4807
4820
  }
4808
- moduleIds.forEach((moduleId) => {
4809
- project.server.moduleGraph.idToModuleMap.set(moduleId, {
4810
- id: moduleId,
4811
- url: moduleId,
4812
- file: cleanUrl(moduleId),
4813
- ssrTransformResult: null,
4814
- transformResult: null,
4815
- importedBindings: null,
4816
- importedModules: /* @__PURE__ */ new Set(),
4817
- importers: /* @__PURE__ */ new Set(),
4818
- type: "js",
4819
- clientImportedModules: /* @__PURE__ */ new Set(),
4820
- ssrError: null,
4821
- ssrImportedModules: /* @__PURE__ */ new Set(),
4822
- ssrModule: null,
4823
- acceptedHmrDeps: /* @__PURE__ */ new Set(),
4824
- acceptedHmrExports: null,
4825
- lastHMRTimestamp: 0,
4826
- lastInvalidationTimestamp: 0
4827
- });
4821
+ moduleIds.forEach(([moduleId, file, url]) => {
4822
+ const moduleNode = project.server.moduleGraph.createFileOnlyEntry(file);
4823
+ moduleNode.url = url;
4824
+ moduleNode.id = moduleId;
4825
+ project.server.moduleGraph.idToModuleMap.set(moduleId, moduleNode);
4828
4826
  });
4829
4827
  });
4830
4828
  });
@@ -4937,7 +4935,7 @@ function renderTree(tasks, options, level = 0, shallow = false) {
4937
4935
  if (baseline) {
4938
4936
  benchMap[t.id].baseline = {
4939
4937
  ...baseline,
4940
- samples: Array(baseline.sampleCount)
4938
+ samples: Array.from({ length: baseline.sampleCount })
4941
4939
  };
4942
4940
  }
4943
4941
  }
@@ -5241,4 +5239,4 @@ const ReportersMap = {
5241
5239
  "github-actions": GithubActionsReporter
5242
5240
  };
5243
5241
 
5244
- export { BasicReporter as B, DefaultReporter as D, GithubActionsReporter as G, HangingProcessReporter as H, JsonReporter as J, Logger as L, ReportersMap as R, TapReporter as T, VerboseReporter as V, DotReporter as a, JUnitReporter as b, TapFlatReporter as c, TestFile as d, TestCase as e, TestModule as f, TestSuite as g, BenchmarkReportsMap as h, TestProject as i, generateCodeFrame as j, highlightCode as k, BlobReporter as l, parse as p, readBlobs as r, stringify as s };
5242
+ export { BasicReporter as B, DefaultReporter as D, GithubActionsReporter as G, HangingProcessReporter as H, JsonReporter as J, Logger as L, ReportersMap as R, TapReporter as T, VerboseReporter as V, DotReporter as a, JUnitReporter as b, TapFlatReporter as c, TestFile as d, TestCase as e, TestModule as f, TestSuite as g, BenchmarkReportsMap as h, TestProject as i, generateCodeFrame as j, BlobReporter as k, parse as p, readBlobs as r, stringify as s };
@@ -0,0 +1,17 @@
1
+ import { MockedModuleType } from '@vitest/mocker';
2
+
3
+ type Promisable<T> = T | Promise<T>;
4
+ type MockFactoryWithHelper<M = unknown> = (importOriginal: <T extends M = M>() => Promise<T>) => Promisable<Partial<M>>;
5
+ type MockFactory = () => any;
6
+ interface MockOptions {
7
+ spy?: boolean;
8
+ }
9
+ interface PendingSuiteMock {
10
+ id: string;
11
+ importer: string;
12
+ action: 'mock' | 'unmock';
13
+ type?: MockedModuleType;
14
+ factory?: MockFactory;
15
+ }
16
+
17
+ export type { MockFactoryWithHelper as M, PendingSuiteMock as P, MockOptions as a, MockFactory as b };
@@ -379,7 +379,7 @@ interface BrowserProvider {
379
379
  beforeCommand?: (command: string, args: unknown[]) => Awaitable$1<void>;
380
380
  afterCommand?: (command: string, args: unknown[]) => Awaitable$1<void>;
381
381
  getCommandsContext: (contextId: string) => Record<string, unknown>;
382
- openPage: (contextId: string, url: string) => Promise<void>;
382
+ openPage: (contextId: string, url: string, beforeNavigate?: () => Promise<void>) => Promise<void>;
383
383
  getCDPSession?: (contextId: string) => Promise<CDPSession>;
384
384
  close: () => Awaitable$1<void>;
385
385
  initialize(ctx: WorkspaceProject, options: BrowserProviderInitializationOptions): Awaitable$1<void>;
@@ -681,17 +681,28 @@ declare class WorkspaceProject {
681
681
  initBrowserProvider(): Promise<void>;
682
682
  }
683
683
 
684
- declare class WorkspaceSpec$1 {
684
+ type SerializedTestSpecification = [
685
+ project: {
686
+ name: string | undefined;
687
+ root: string;
688
+ },
689
+ file: string,
690
+ options: {
691
+ pool: string;
692
+ }
693
+ ];
694
+
695
+ declare class TestSpecification {
685
696
  /**
686
- * @deprecated
697
+ * @deprecated use `project` instead
687
698
  */
688
699
  readonly 0: WorkspaceProject;
689
700
  /**
690
- * @deprecated
701
+ * @deprecated use `moduleId` instead
691
702
  */
692
703
  readonly 1: string;
693
704
  /**
694
- * @deprecated
705
+ * @deprecated use `pool` instead
695
706
  */
696
707
  readonly 2: {
697
708
  pool: Pool;
@@ -700,6 +711,7 @@ declare class WorkspaceSpec$1 {
700
711
  readonly moduleId: string;
701
712
  readonly pool: Pool;
702
713
  constructor(workspaceProject: WorkspaceProject, moduleId: string, pool: Pool);
714
+ toJSON(): SerializedTestSpecification;
703
715
  /**
704
716
  * for backwards compatibility
705
717
  * @deprecated
@@ -707,7 +719,10 @@ declare class WorkspaceSpec$1 {
707
719
  [Symbol.iterator](): Generator<string | WorkspaceProject, void, unknown>;
708
720
  }
709
721
 
710
- type WorkspaceSpec = WorkspaceSpec$1 & [
722
+ /**
723
+ * @deprecated use TestSpecification instead
724
+ */
725
+ type WorkspaceSpec = TestSpecification & [
711
726
  /**
712
727
  * @deprecated use spec.project instead
713
728
  */
@@ -1432,6 +1447,7 @@ declare class Vitest {
1432
1447
  tests: File[];
1433
1448
  errors: unknown[];
1434
1449
  }>;
1450
+ listFiles(filters?: string[]): Promise<WorkspaceSpec[]>;
1435
1451
  start(filters?: string[]): Promise<void>;
1436
1452
  init(): Promise<void>;
1437
1453
  private getTestDependencies;
@@ -1441,9 +1457,8 @@ declare class Vitest {
1441
1457
  */
1442
1458
  getProjectsByTestFile(file: string): WorkspaceSpec[];
1443
1459
  getFileWorkspaceSpecs(file: string): WorkspaceSpec[];
1444
- initializeGlobalSetup(paths: WorkspaceSpec[]): Promise<void>;
1445
- private initializeDistPath;
1446
- runFiles(specs: WorkspaceSpec[], allTestsRun: boolean): Promise<void>;
1460
+ initializeGlobalSetup(paths: TestSpecification[]): Promise<void>;
1461
+ runFiles(specs: TestSpecification[], allTestsRun: boolean): Promise<void>;
1447
1462
  collectFiles(specs: WorkspaceSpec[]): Promise<void>;
1448
1463
  cancelCurrentRun(reason: CancelReason): Promise<void>;
1449
1464
  rerunFiles(files?: string[], trigger?: string): Promise<void>;
@@ -1459,6 +1474,10 @@ declare class Vitest {
1459
1474
  * Watch only the specified tests. If no tests are provided, all tests will be watched.
1460
1475
  */
1461
1476
  watchTests(tests: string[]): void;
1477
+ private updateLastChanged;
1478
+ onChange: (id: string) => void;
1479
+ onUnlink: (id: string) => void;
1480
+ onAdd: (id: string) => Promise<void>;
1462
1481
  private unregisterWatcher;
1463
1482
  private registerWatcher;
1464
1483
  /**
@@ -1486,21 +1505,10 @@ declare class Vitest {
1486
1505
  onClose(fn: () => void): void;
1487
1506
  }
1488
1507
 
1489
- type SerializedSpec = [
1490
- project: {
1491
- name: string | undefined;
1492
- root: string;
1493
- },
1494
- file: string,
1495
- options: {
1496
- pool: string;
1497
- }
1498
- ];
1499
-
1500
1508
  interface Reporter {
1501
1509
  onInit?: (ctx: Vitest) => void;
1502
1510
  onPathsCollected?: (paths?: string[]) => Awaitable<void>;
1503
- onSpecsCollected?: (specs?: SerializedSpec[]) => Awaitable<void>;
1511
+ onSpecsCollected?: (specs?: SerializedTestSpecification[]) => Awaitable<void>;
1504
1512
  onCollected?: (files?: File[]) => Awaitable<void>;
1505
1513
  onFinished?: (files: File[], errors: unknown[], coverage?: unknown) => Awaitable<void>;
1506
1514
  onTaskUpdate?: (packs: TaskResultPack[]) => Awaitable<void>;
@@ -2731,4 +2739,4 @@ type WorkspaceProjectConfiguration = string | (UserProjectConfigExport & {
2731
2739
  extends?: string;
2732
2740
  });
2733
2741
 
2734
- export { type BrowserProvider as $, type ApiConfig as A, type BaseCoverageOptions as B, type CoverageProvider as C, type DepsOptimizationOptions as D, type ResolvedConfig as E, type ProjectConfig as F, type BenchmarkUserOptions as G, type VitestOptions as H, type InlineConfig as I, WorkspaceProject as J, type TestSequencer as K, Logger as L, type WorkspaceSpec as M, TestModule as N, type ModuleDiagnostic as O, type Pool as P, type ProcessPool as Q, type ResolvedCoverageOptions as R, type SerializedSpec as S, type TscErrorInfo as T, type UserWorkspaceConfig as U, Vitest as V, type WorkspaceProjectConfiguration as W, getFilePoolName as X, VitestPackageInstaller as Y, type TestSequencerConstructor as Z, type BrowserProviderInitializationOptions as _, type CoverageProviderModule as a, type CDPSession as a0, type BrowserProviderModule as a1, type ResolvedBrowserOptions as a2, type BrowserProviderOptions as a3, type BrowserBuiltinProvider as a4, type BrowserCommand as a5, type BrowserCommandContext as a6, type BrowserServer as a7, type BrowserServerState as a8, type BrowserServerStateContext as a9, TestFile as aA, type FileDiagnostic as aB, ReportersMap as aC, type BuiltinReporters as aD, type BuiltinReporterOptions as aE, type JsonAssertionResult as aF, type JsonTestResult as aG, type JsonTestResults as aH, BenchmarkReportsMap as aI, type BenchmarkBuiltinReporters as aJ, type BrowserOrchestrator as aa, type JsonOptions as ab, type JUnitOptions as ac, type HTMLOptions as ad, TestCase as ae, TestSuite as af, TestProject as ag, TestCollection as ah, type TaskOptions as ai, type TestDiagnostic as aj, type TestResult as ak, type TestResultPassed as al, type TestResultFailed as am, type TestResultSkipped as an, type ResolvedProjectConfig as ao, DefaultReporter as ap, BasicReporter as aq, DotReporter as ar, JsonReporter as as, VerboseReporter as at, TapReporter as au, JUnitReporter as av, TapFlatReporter as aw, HangingProcessReporter as ax, GithubActionsReporter as ay, BaseReporter as az, type CoverageV8Options as b, type UserProjectConfigFn as c, type UserProjectConfigExport as d, type VitestEnvironment as e, type RawErrsMap as f, type CollectLineNumbers as g, type CollectLines as h, type RootAndTarget as i, type Context as j, type ReportContext as k, type CoverageReporter as l, type CoverageProviderName as m, type CoverageOptions as n, type CoverageIstanbulOptions as o, type CustomProviderOptions as p, type Reporter as q, type BrowserScript as r, type BrowserConfigOptions as s, type BuiltinEnvironment as t, type PoolOptions as u, type CSSModuleScopeStrategy as v, type VitestRunMode as w, type TransformModePatterns as x, type TypecheckConfig as y, type UserConfig as z };
2742
+ export { type BrowserProviderInitializationOptions as $, type ApiConfig as A, type BaseCoverageOptions as B, type CoverageProvider as C, type DepsOptimizationOptions as D, type ResolvedConfig as E, type ProjectConfig as F, type BenchmarkUserOptions as G, type VitestOptions as H, type InlineConfig as I, WorkspaceProject as J, type TestSequencer as K, Logger as L, type WorkspaceSpec as M, TestModule as N, type ModuleDiagnostic as O, type Pool as P, type ProcessPool as Q, type ResolvedCoverageOptions as R, type SerializedTestSpecification as S, type TscErrorInfo as T, type UserWorkspaceConfig as U, Vitest as V, type WorkspaceProjectConfiguration as W, getFilePoolName as X, VitestPackageInstaller as Y, TestSpecification as Z, type TestSequencerConstructor as _, type CoverageProviderModule as a, type BrowserProvider as a0, type CDPSession as a1, type BrowserProviderModule as a2, type ResolvedBrowserOptions as a3, type BrowserProviderOptions as a4, type BrowserBuiltinProvider as a5, type BrowserCommand as a6, type BrowserCommandContext as a7, type BrowserServer as a8, type BrowserServerState as a9, BaseReporter as aA, TestFile as aB, type FileDiagnostic as aC, ReportersMap as aD, type BuiltinReporters as aE, type BuiltinReporterOptions as aF, type JsonAssertionResult as aG, type JsonTestResult as aH, type JsonTestResults as aI, BenchmarkReportsMap as aJ, type BenchmarkBuiltinReporters as aK, type BrowserServerStateContext as aa, type BrowserOrchestrator as ab, type JsonOptions as ac, type JUnitOptions as ad, type HTMLOptions as ae, TestCase as af, TestSuite as ag, TestProject as ah, TestCollection as ai, type TaskOptions as aj, type TestDiagnostic as ak, type TestResult as al, type TestResultPassed as am, type TestResultFailed as an, type TestResultSkipped as ao, type ResolvedProjectConfig as ap, DefaultReporter as aq, BasicReporter as ar, DotReporter as as, JsonReporter as at, VerboseReporter as au, TapReporter as av, JUnitReporter as aw, TapFlatReporter as ax, HangingProcessReporter as ay, GithubActionsReporter as az, type CoverageV8Options as b, type UserProjectConfigFn as c, type UserProjectConfigExport as d, type VitestEnvironment as e, type RawErrsMap as f, type CollectLineNumbers as g, type CollectLines as h, type RootAndTarget as i, type Context as j, type ReportContext as k, type CoverageReporter as l, type CoverageProviderName as m, type CoverageOptions as n, type CoverageIstanbulOptions as o, type CustomProviderOptions as p, type Reporter as q, type BrowserScript as r, type BrowserConfigOptions as s, type BuiltinEnvironment as t, type PoolOptions as u, type CSSModuleScopeStrategy as v, type VitestRunMode as w, type TransformModePatterns as x, type TypecheckConfig as y, type UserConfig as z };
@@ -15,10 +15,10 @@ import nodeos__default from 'node:os';
15
15
  import { i as isWindows } from './env.CmHVDJnw.js';
16
16
  import { isCI, provider } from 'std-env';
17
17
  import { hasFailed } from '@vitest/runner/utils';
18
- import { b as groupBy, A as AggregateErrorPonyfill, a as slash, t as toArray } from './base.BH-FAiX7.js';
18
+ import { g as groupBy, A as AggregateErrorPonyfill, a as slash, t as toArray } from './base.BlXpj3e_.js';
19
19
  import { createDefer } from '@vitest/utils';
20
20
  import crypto, { createHash } from 'node:crypto';
21
- import { w as wrapSerializableConfig, T as Typechecker, R as RandomSequencer, B as BaseSequencer } from './RandomSequencer.CjkAy_bL.js';
21
+ import { w as wrapSerializableConfig, T as Typechecker, R as RandomSequencer, B as BaseSequencer } from './RandomSequencer.Bh5-tlNJ.js';
22
22
  import { g as getDefaultExportFromCjs } from './_commonjsHelpers.BFTU3MAI.js';
23
23
  import require$$0 from 'util';
24
24
  import p from 'path';
@@ -7667,9 +7667,9 @@ function resolveConfig(mode, options, viteConfig, logger) {
7667
7667
  );
7668
7668
  }
7669
7669
  }
7670
- if (resolved.browser.enabled && resolved.coverage.enabled && resolved.coverage.provider === "v8") {
7671
- if (!(resolved.browser.provider === "playwright" && resolved.browser.name === "chromium")) {
7672
- const browserConfig = { browser: { provider: resolved.browser.provider, name: resolved.browser.name } };
7670
+ if (resolved.browser.enabled && !(resolved.browser.provider === "playwright" && resolved.browser.name === "chromium")) {
7671
+ const browserConfig = { browser: { provider: resolved.browser.provider, name: resolved.browser.name } };
7672
+ if (resolved.coverage.enabled && resolved.coverage.provider === "v8") {
7673
7673
  throw new Error(
7674
7674
  `@vitest/coverage-v8 does not work with
7675
7675
  ${JSON.stringify(browserConfig, null, 2)}
@@ -7679,6 +7679,19 @@ ${JSON.stringify({ browser: { provider: "playwright", name: "chromium" } }, null
7679
7679
 
7680
7680
  ...or change your coverage provider to:
7681
7681
  ${JSON.stringify({ coverage: { provider: "istanbul" } }, null, 2)}
7682
+ `
7683
+ );
7684
+ }
7685
+ if (resolved.inspect || resolved.inspectBrk) {
7686
+ const inspectOption = `--inspect${resolved.inspectBrk ? "-brk" : ""}`;
7687
+ throw new Error(
7688
+ `${inspectOption} does not work with
7689
+ ${JSON.stringify(browserConfig, null, 2)}
7690
+
7691
+ Use either:
7692
+ ${JSON.stringify({ browser: { provider: "playwright", name: "chromium" } }, null, 2)}
7693
+
7694
+ ...or disable ${inspectOption}
7682
7695
  `
7683
7696
  );
7684
7697
  }
@@ -8127,4 +8140,4 @@ function resolveCoverageReporters(configReporters) {
8127
8140
  return resolvedReporters;
8128
8141
  }
8129
8142
 
8130
- export { VitestCache as V, resolveApiServerConfig as a, resolveConfig as b, createMethodsRPC as c, braces_1 as d, configDefaults as e, isPackageExists as f, getFilePoolName as g, createPool as h, isBrowserEnabled as i, coverageConfigDefaults as j, mm as m, picomatch$1 as p, resolveCoverageReporters as r, utils$4 as u };
8143
+ export { VitestCache as V, resolveApiServerConfig as a, resolveConfig as b, createMethodsRPC as c, configDefaults as d, isPackageExists as e, createPool as f, getFilePoolName as g, coverageConfigDefaults as h, isBrowserEnabled as i, mm as m, resolveCoverageReporters as r };