vitest 4.1.12 → 5.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 (121) hide show
  1. package/LICENSE.md +192 -10
  2. package/browser/context.d.ts +7 -1
  3. package/browser/context.js +5 -5
  4. package/config.d.ts +0 -2
  5. package/dist/browser.d.ts +52 -21
  6. package/dist/browser.js +12 -13
  7. package/dist/chunks/{acorn.B2iPLyUM.js → acorn.C1kjbUFw.js} +30 -30
  8. package/dist/chunks/{base.B6Opl8PE.js → base.Cof-UHJf.js} +81 -52
  9. package/dist/chunks/{browser.d.BcoexmFG.d.ts → browser.d.C7tWgUvw.d.ts} +17 -14
  10. package/dist/chunks/{cac.DzDtg8hz.js → cac.BYbt0aJp.js} +143 -87
  11. package/dist/chunks/{cli-api.B0Pz1_R7.js → cli-api.COfZo8lK.js} +7160 -7189
  12. package/dist/chunks/config.d.B3YV4t0O.d.ts +3873 -0
  13. package/dist/chunks/{console.3WNpx0tS.js → console.CQZ877Hi.js} +69 -63
  14. package/dist/chunks/{constants.CPYnjOGj.js → constants.DLYM6cZY.js} +2 -2
  15. package/dist/chunks/coverage.9iqXE2gN.js +26 -0
  16. package/dist/chunks/{coverage.CTzCuANN.js → coverage.jGCktcGP.js} +7 -2
  17. package/dist/chunks/{creator.DgVhQm5q.js → creator.DHWmytIK.js} +65 -28
  18. package/dist/chunks/{defaults.9aQKnqFk.js → defaults.B1FCaFfh.js} +16 -9
  19. package/dist/chunks/display.BlTmubjj.js +194 -0
  20. package/dist/chunks/doctor.B-oPbwps.js +465 -0
  21. package/dist/chunks/{env.D4Lgay0q.js → env.BKKtU2WC.js} +2 -1
  22. package/dist/chunks/{environment.d.CrsxCzP1.d.ts → environment.d.BFQtFKdZ.d.ts} +9 -1
  23. package/dist/chunks/globals.ZKtKSkEf.js +29 -0
  24. package/dist/chunks/index.Bi0NXYPf.js +1708 -0
  25. package/dist/chunks/{index.CMESou6r.js → index.BoyTG_B7.js} +82 -81
  26. package/dist/chunks/index.CZzC1gGg.js +8501 -0
  27. package/dist/chunks/index.D0heQG4v.js +1318 -0
  28. package/dist/chunks/index.Di8au7q4.js +15665 -0
  29. package/dist/chunks/{index.Chj8NDwU.js → index.DmDMHCg8.js} +6 -12
  30. package/dist/chunks/{index.DXx9Dtk7.js → index.w_oBZ9N8.js} +25 -12
  31. package/dist/chunks/{init-forks.H5ZuobOQ.js → init-forks.BaDXQSD8.js} +7 -10
  32. package/dist/chunks/{init-threads.6kl1khcL.js → init-threads.ZX_Vov0z.js} +1 -1
  33. package/dist/chunks/{init.k9zZ9sLh.js → init.CO4AB7HZ.js} +113 -38
  34. package/dist/chunks/module-dependencies._2Eei3FO.js +71 -0
  35. package/dist/chunks/{native.DPzPHdi5.js → native.upB-V0CK.js} +50 -37
  36. package/dist/chunks/{nativeModuleMocker.BkNfQMkH.js → nativeModuleMocker.Dh5azSB4.js} +48 -19
  37. package/dist/chunks/{index.BCY_7LL2.js → nativeModuleRunner.9xPIMzi7.js} +110 -42
  38. package/dist/chunks/node.B9mkVmLH.js +47 -0
  39. package/dist/chunks/offset.Dy-5Fdfn.js +24 -0
  40. package/dist/chunks/pathe.M-eThtNZ.zq3TM4NT.js +492 -0
  41. package/dist/chunks/{reporters.d.DtoKVV2s.d.ts → plugin.d.LRFSN46m.d.ts} +2573 -1453
  42. package/dist/chunks/plugins.DPQHVT0p.js +37 -0
  43. package/dist/chunks/rawSnapshot.DqSiqIEx.js +356 -0
  44. package/dist/chunks/resolver.BzpmeQeT.js +48 -0
  45. package/dist/chunks/rpc.Uhkwr2NM.js +93 -0
  46. package/dist/chunks/rpc.d.3FOhdFx8.d.ts +75 -0
  47. package/dist/chunks/run.CjdgFZiW.js +4231 -0
  48. package/dist/chunks/setup-common.CqAQCXzx.js +36 -0
  49. package/dist/chunks/source-map.DakdQc29.js +1788 -0
  50. package/dist/chunks/source-map.d.BkG8YK_3.d.ts +89 -0
  51. package/dist/chunks/spy.DDMXghXv.js +509 -0
  52. package/dist/chunks/task-utils.d.D-gFPNFi.d.ts +144 -0
  53. package/dist/chunks/tinyrainbow.Do8I1XRG.js +88 -0
  54. package/dist/chunks/{utils.BS4fH3nR.js → utils.BBk_icFG.js} +50 -52
  55. package/dist/chunks/{utils.BX5Fg8C4.js → utils.DYj33du9.js} +1 -17
  56. package/dist/chunks/vm.b4MbCAJQ.js +1329 -0
  57. package/dist/chunks/{worker.d.ZpHpO4yb.d.ts → worker.d.CyJRpyfZ.d.ts} +34 -19
  58. package/dist/cli.js +5 -6
  59. package/dist/config.cjs +9 -6
  60. package/dist/config.d.ts +27 -25
  61. package/dist/config.js +3 -3
  62. package/dist/index.d.ts +471 -38
  63. package/dist/index.js +18 -19
  64. package/dist/module-evaluator.d.ts +64 -5
  65. package/dist/module-evaluator.js +122 -62
  66. package/dist/node.d.ts +355 -87
  67. package/dist/node.js +49 -73
  68. package/dist/runtime.d.ts +43 -6
  69. package/dist/runtime.js +7 -9
  70. package/dist/spy.js +1 -1
  71. package/dist/task-utils.js +290 -0
  72. package/dist/{chunks/traces.DT5aQ62U.js → traces.js} +3 -2
  73. package/dist/worker.d.ts +8 -10
  74. package/dist/worker.js +33 -43
  75. package/dist/workers/forks.js +30 -40
  76. package/dist/workers/runVmTests.js +66 -43
  77. package/dist/workers/threads.js +30 -40
  78. package/dist/workers/vmForks.js +19 -20
  79. package/dist/workers/vmThreads.js +19 -20
  80. package/globals.d.ts +19 -19
  81. package/index.cjs +3 -3
  82. package/optional-runtime-types.d.ts +1 -1
  83. package/optional-types.d.ts +1 -1
  84. package/package.json +59 -74
  85. package/suppress-warnings.cjs +1 -1
  86. package/dist/chunks/_commonjsHelpers.D26ty3Ew.js +0 -6
  87. package/dist/chunks/benchmark.CX_oY03V.js +0 -40
  88. package/dist/chunks/benchmark.d.DAaHLpsq.d.ts +0 -24
  89. package/dist/chunks/config.d.A1h_Y6Jt.d.ts +0 -232
  90. package/dist/chunks/coverage.DM_a_rWm.js +0 -1087
  91. package/dist/chunks/coverage.d.BZtK59WP.d.ts +0 -37
  92. package/dist/chunks/evaluatedModules.Dg1zASAC.js +0 -17
  93. package/dist/chunks/global.d.DVsSRdQ5.d.ts +0 -100
  94. package/dist/chunks/globals.Dj1TGiMC.js +0 -31
  95. package/dist/chunks/index.DC7d2Pf8.js +0 -729
  96. package/dist/chunks/index.DdgEv5B1.js +0 -42
  97. package/dist/chunks/index.UpGiHP7g.js +0 -4255
  98. package/dist/chunks/index.og1WyBLx.js +0 -6358
  99. package/dist/chunks/nativeModuleRunner.BIakptoF.js +0 -36
  100. package/dist/chunks/node.COQbm6gK.js +0 -14
  101. package/dist/chunks/plugin.d.DwFIiJ7i.d.ts +0 -38
  102. package/dist/chunks/rpc.MzXet3jl.js +0 -144
  103. package/dist/chunks/rpc.d.B_8sPU0w.d.ts +0 -30
  104. package/dist/chunks/setup-common.DYx3LtFI.js +0 -60
  105. package/dist/chunks/startVitestModuleRunner.DB-7oCpn.js +0 -740
  106. package/dist/chunks/suite.d.udJtyAgw.d.ts +0 -10
  107. package/dist/chunks/test.DNmyFkvJ.js +0 -4430
  108. package/dist/chunks/traces.d.D2T_R8rx.d.ts +0 -60
  109. package/dist/chunks/vm.CXMd5FHa.js +0 -785
  110. package/dist/coverage.d.ts +0 -123
  111. package/dist/coverage.js +0 -27
  112. package/dist/environments.d.ts +0 -22
  113. package/dist/environments.js +0 -5
  114. package/dist/reporters.d.ts +0 -27
  115. package/dist/reporters.js +0 -26
  116. package/dist/runners.d.ts +0 -70
  117. package/dist/runners.js +0 -19
  118. package/dist/snapshot.d.ts +0 -9
  119. package/dist/snapshot.js +0 -6
  120. package/dist/suite.d.ts +0 -5
  121. package/dist/suite.js +0 -8
@@ -1,12 +1,13 @@
1
1
  import { Console } from 'node:console';
2
2
  import { relative } from 'node:path';
3
3
  import { Writable } from 'node:stream';
4
- import { getSafeTimers } from '@vitest/utils/timers';
5
- import c from 'tinyrainbow';
6
- import { R as RealDate } from './rpc.MzXet3jl.js';
7
- import { g as getWorkerState } from './utils.BX5Fg8C4.js';
8
- import './index.Chj8NDwU.js';
4
+ import { a as getSafeTimers } from './source-map.DakdQc29.js';
5
+ import { $ } from './tinyrainbow.Do8I1XRG.js';
6
+ import { g as getWorkerState, E as EnvironmentTeardownError } from './utils.DYj33du9.js';
7
+ import './index.D0heQG4v.js';
8
+ import './pathe.M-eThtNZ.zq3TM4NT.js';
9
9
 
10
+ const RealDate = globalThis.Date;
10
11
  const UNKNOWN_TEST_ID = "__vitest__unknown_test__";
11
12
  function getTaskIdByStack(root) {
12
13
  const stack = (/* @__PURE__ */ new Error("STACK_TRACE_ERROR")).stack?.split("\n");
@@ -77,71 +78,76 @@ function createCustomConsole(defaultState) {
77
78
  time: time || RealDate.now(),
78
79
  size,
79
80
  origin
81
+ }).catch((error) => {
82
+ // the log is already sent, the worker only closed before the reporter answered
83
+ if (!(error instanceof EnvironmentTeardownError)) throw error;
80
84
  });
81
85
  }
82
- return new Console({
83
- stdout: new Writable({ write(data, encoding, callback) {
84
- const s = state();
85
- const id = s?.current?.id || s?.current?.suite?.id || s.current?.file.id || getTaskIdByStack(s.config.root);
86
- let timer = timers.get(id);
87
- if (timer) timer.stdoutTime = timer.stdoutTime || RealDate.now();
86
+ const stdout = new Writable({ write(data, encoding, callback) {
87
+ const s = state();
88
+ const id = s?.current?.id || s?.current?.suite?.id || s.current?.file.id || getTaskIdByStack(s.config.root);
89
+ let timer = timers.get(id);
90
+ if (timer) timer.stdoutTime = timer.stdoutTime || RealDate.now();
91
+ else {
92
+ timer = {
93
+ stdoutTime: RealDate.now(),
94
+ stderrTime: 0
95
+ };
96
+ timers.set(id, timer);
97
+ }
98
+ let buffer = stdoutBuffer.get(id);
99
+ if (!buffer) {
100
+ buffer = [];
101
+ stdoutBuffer.set(id, buffer);
102
+ }
103
+ if (state().config.printConsoleTrace) {
104
+ const limit = Error.stackTraceLimit;
105
+ Error.stackTraceLimit = limit + 6;
106
+ const trace = (/* @__PURE__ */ new Error("STACK_TRACE")).stack?.split("\n").slice(7).join("\n");
107
+ Error.stackTraceLimit = limit;
108
+ buffer.push([data, trace]);
109
+ } else buffer.push([data, void 0]);
110
+ schedule(id);
111
+ callback();
112
+ } });
113
+ const stderr = new Writable({ write(data, encoding, callback) {
114
+ const s = state();
115
+ const id = s?.current?.id || s?.current?.suite?.id || s.current?.file.id || getTaskIdByStack(s.config.root);
116
+ let timer = timers.get(id);
117
+ if (timer) timer.stderrTime = timer.stderrTime || RealDate.now();
118
+ else {
119
+ timer = {
120
+ stderrTime: RealDate.now(),
121
+ stdoutTime: 0
122
+ };
123
+ timers.set(id, timer);
124
+ }
125
+ let buffer = stderrBuffer.get(id);
126
+ if (!buffer) {
127
+ buffer = [];
128
+ stderrBuffer.set(id, buffer);
129
+ }
130
+ if (state().config.printConsoleTrace) {
131
+ const limit = Error.stackTraceLimit;
132
+ Error.stackTraceLimit = limit + 6;
133
+ const stack = (/* @__PURE__ */ new Error("STACK_TRACE")).stack?.split("\n");
134
+ Error.stackTraceLimit = limit;
135
+ if (stack?.some((line) => line.includes("at Console.trace"))) buffer.push([data, void 0]);
88
136
  else {
89
- timer = {
90
- stdoutTime: RealDate.now(),
91
- stderrTime: RealDate.now()
92
- };
93
- timers.set(id, timer);
94
- }
95
- let buffer = stdoutBuffer.get(id);
96
- if (!buffer) {
97
- buffer = [];
98
- stdoutBuffer.set(id, buffer);
99
- }
100
- if (state().config.printConsoleTrace) {
101
- const limit = Error.stackTraceLimit;
102
- Error.stackTraceLimit = limit + 6;
103
- const trace = (/* @__PURE__ */ new Error("STACK_TRACE")).stack?.split("\n").slice(7).join("\n");
137
+ const trace = stack?.slice(7).join("\n");
104
138
  Error.stackTraceLimit = limit;
105
139
  buffer.push([data, trace]);
106
- } else buffer.push([data, void 0]);
107
- schedule(id);
108
- callback();
109
- } }),
110
- stderr: new Writable({ write(data, encoding, callback) {
111
- const s = state();
112
- const id = s?.current?.id || s?.current?.suite?.id || s.current?.file.id || getTaskIdByStack(s.config.root);
113
- let timer = timers.get(id);
114
- if (timer) timer.stderrTime = timer.stderrTime || RealDate.now();
115
- else {
116
- timer = {
117
- stderrTime: RealDate.now(),
118
- stdoutTime: RealDate.now()
119
- };
120
- timers.set(id, timer);
121
140
  }
122
- let buffer = stderrBuffer.get(id);
123
- if (!buffer) {
124
- buffer = [];
125
- stderrBuffer.set(id, buffer);
126
- }
127
- if (state().config.printConsoleTrace) {
128
- const limit = Error.stackTraceLimit;
129
- Error.stackTraceLimit = limit + 6;
130
- const stack = (/* @__PURE__ */ new Error("STACK_TRACE")).stack?.split("\n");
131
- Error.stackTraceLimit = limit;
132
- if (stack?.some((line) => line.includes("at Console.trace"))) buffer.push([data, void 0]);
133
- else {
134
- const trace = stack?.slice(7).join("\n");
135
- Error.stackTraceLimit = limit;
136
- buffer.push([data, trace]);
137
- }
138
- } else buffer.push([data, void 0]);
139
- schedule(id);
140
- callback();
141
- } }),
142
- colorMode: c.isColorSupported,
141
+ } else buffer.push([data, void 0]);
142
+ schedule(id);
143
+ callback();
144
+ } });
145
+ return new Console({
146
+ stdout,
147
+ stderr,
148
+ colorMode: $.isColorSupported,
143
149
  groupIndentation: 2
144
150
  });
145
151
  }
146
152
 
147
- export { UNKNOWN_TEST_ID, createCustomConsole };
153
+ export { createCustomConsole };
@@ -1,6 +1,6 @@
1
1
  // if changed, update also jsdocs and docs
2
2
  const defaultPort = 51204;
3
- const defaultBrowserPort = 63315;
3
+ const defaultBrowserPort = 23315;
4
4
  const defaultInspectPort = 9229;
5
5
  const API_PATH = "/__vitest_api__";
6
6
  const CONFIG_NAMES = ["vitest.config", "vite.config"];
@@ -35,4 +35,4 @@ const globalApis = [
35
35
  "aroundAll"
36
36
  ];
37
37
 
38
- export { API_PATH as A, defaultInspectPort as a, defaultPort as b, configFiles as c, defaultBrowserPort as d, globalApis as g };
38
+ export { API_PATH as A, defaultPort as a, defaultInspectPort as b, configFiles as c, defaultBrowserPort as d, globalApis as g };
@@ -0,0 +1,26 @@
1
+ import { r as resolveCoverageProviderModule } from './coverage.jGCktcGP.js';
2
+
3
+ async function startCoverageInsideWorker(options, loader, runtimeOptions) {
4
+ const coverageModule = await resolveCoverageProviderModule(options, loader);
5
+ if (coverageModule) return coverageModule.startCoverage?.({
6
+ ...runtimeOptions,
7
+ autoAttachSubprocess: options.autoAttachSubprocess,
8
+ reportsDirectory: options.reportsDirectory
9
+ });
10
+ return null;
11
+ }
12
+ async function takeCoverageInsideWorker(options, loader) {
13
+ const coverageModule = await resolveCoverageProviderModule(options, loader);
14
+ if (coverageModule) return coverageModule.takeCoverage?.({
15
+ moduleExecutionInfo: loader.moduleExecutionInfo,
16
+ coverageFilesDirectory: options.coverageFilesDirectory
17
+ });
18
+ return null;
19
+ }
20
+ async function stopCoverageInsideWorker(options, loader, runtimeOptions) {
21
+ const coverageModule = await resolveCoverageProviderModule(options, loader);
22
+ if (coverageModule) return coverageModule.stopCoverage?.(runtimeOptions);
23
+ return null;
24
+ }
25
+
26
+ export { stopCoverageInsideWorker as a, startCoverageInsideWorker as s, takeCoverageInsideWorker as t };
@@ -1,3 +1,8 @@
1
+ import { r as resolve } from './pathe.M-eThtNZ.zq3TM4NT.js';
2
+
3
+ function getCoverageFilesDirectory(reportsDirectory, shard) {
4
+ return resolve(reportsDirectory, `.tmp${shard ? `-${shard.index}-${shard.count}` : ""}`);
5
+ }
1
6
  const CoverageProviderMap = {
2
7
  v8: "@vitest/coverage-v8",
3
8
  istanbul: "@vitest/coverage-istanbul"
@@ -7,7 +12,7 @@ async function resolveCoverageProviderModule(options, loader) {
7
12
  const provider = options.provider;
8
13
  if (provider === "v8" || provider === "istanbul") {
9
14
  let builtInModule = CoverageProviderMap[provider];
10
- if (provider === "v8" && loader.isBrowser) builtInModule += "/browser";
15
+ if (loader.isBrowser) builtInModule += "/browser";
11
16
  const { default: coverageModule } = loader.isBrowser ? await loader.import(builtInModule) : await import(
12
17
  /* @vite-ignore */
13
18
  builtInModule
@@ -25,4 +30,4 @@ async function resolveCoverageProviderModule(options, loader) {
25
30
  return customProviderModule.default;
26
31
  }
27
32
 
28
- export { CoverageProviderMap as C, resolveCoverageProviderModule as r };
33
+ export { CoverageProviderMap as C, getCoverageFilesDirectory as g, resolveCoverageProviderModule as r };
@@ -1,17 +1,56 @@
1
1
  import { existsSync, writeFileSync, readFileSync } from 'node:fs';
2
2
  import { mkdir, writeFile } from 'node:fs/promises';
3
3
  import { resolve, dirname, relative } from 'node:path';
4
- import { detectPackageManager, installPackage } from './index.CMESou6r.js';
5
- import { p as prompt, a as any } from './index.og1WyBLx.js';
4
+ import { detectPackageManager, installPackage } from './index.BoyTG_B7.js';
5
+ import { p as prompt, n as findConfigFile } from './index.Di8au7q4.js';
6
6
  import { x } from 'tinyexec';
7
- import c from 'tinyrainbow';
8
- import { c as configFiles } from './constants.CPYnjOGj.js';
7
+ import { $ } from './tinyrainbow.Do8I1XRG.js';
9
8
  import 'node:process';
10
- import 'node:module';
11
9
  import 'node:url';
12
- import './_commonjsHelpers.D26ty3Ew.js';
13
- import 'readline';
10
+ import './pathe.M-eThtNZ.zq3TM4NT.js';
11
+ import './nativeModuleRunner.9xPIMzi7.js';
12
+ import 'node:module';
13
+ import 'node:assert';
14
+ import 'node:v8';
15
+ import 'node:util';
16
+ import 'vite/module-runner';
17
+ import 'tinyglobby';
18
+ import 'vite';
19
+ import './constants.DLYM6cZY.js';
20
+ import './defaults.B1FCaFfh.js';
21
+ import 'node:os';
22
+ import './env.BKKtU2WC.js';
23
+ import 'std-env';
24
+ import 'node:crypto';
25
+ import '../path.js';
26
+ import './modules.BJuCwlRJ.js';
27
+ import 'magic-string';
28
+ import '@vitest/mocker/node';
29
+ import 'node:console';
30
+ import 'node:stream';
31
+ import './display.BlTmubjj.js';
32
+ import './index.D0heQG4v.js';
33
+ import 'node:perf_hooks';
34
+ import './source-map.DakdQc29.js';
35
+ import './run.CjdgFZiW.js';
36
+ import '../task-utils.js';
37
+ import 'obug';
38
+ import './resolver.BzpmeQeT.js';
39
+ import 'es-module-lexer';
40
+ import './offset.Dy-5Fdfn.js';
41
+ import './utils.BBk_icFG.js';
42
+ import '#module-evaluator';
43
+ import 'picomatch';
44
+ import './module-dependencies._2Eei3FO.js';
45
+ import './coverage.jGCktcGP.js';
46
+ import 'node:tty';
47
+ import 'node:events';
48
+ import './index.DmDMHCg8.js';
49
+ import 'node:child_process';
50
+ import 'node:worker_threads';
51
+ import './cac.BYbt0aJp.js';
14
52
  import 'events';
53
+ import 'readline';
15
54
 
16
55
  const jsxExample = {
17
56
  name: "HelloWorld.jsx",
@@ -78,7 +117,7 @@ import { render } from 'vitest-browser-vue'
78
117
  import HelloWorld from './HelloWorld.vue'
79
118
 
80
119
  test('renders name', async () => {
81
- const { getByText } = render(HelloWorld, {
120
+ const { getByText } = await render(HelloWorld, {
82
121
  props: { name: 'Vitest' },
83
122
  })
84
123
  await expect.element(getByText('Hello Vitest!')).toBeInTheDocument()
@@ -107,7 +146,7 @@ import { render } from 'vitest-browser-svelte'
107
146
  import HelloWorld from './HelloWorld.svelte'
108
147
 
109
148
  test('renders name', async () => {
110
- const { getByText } = render(HelloWorld, { name: 'Vitest' })
149
+ const { getByText } = await render(HelloWorld, { name: 'Vitest' })
111
150
  await expect.element(getByText('Hello Vitest!')).toBeInTheDocument()
112
151
  })
113
152
  `
@@ -337,7 +376,7 @@ async function generateExampleFiles(framework, lang) {
337
376
  return testPath;
338
377
  }
339
378
 
340
- // eslint-disable-next-line no-console
379
+ // oxlint-disable-next-line no-console
341
380
  const log = console.log;
342
381
  function getProviderOptions() {
343
382
  return Object.entries({
@@ -460,11 +499,11 @@ function getLanguageOptions() {
460
499
  }
461
500
  async function installPackages(pkgManager, packages) {
462
501
  if (!packages.length) {
463
- log(c.green("✔"), c.bold("All packages are already installed."));
502
+ log($.green("✔"), $.bold("All packages are already installed."));
464
503
  return;
465
504
  }
466
- log(c.cyan("◼"), c.bold("Installing packages..."));
467
- log(c.cyan("◼"), packages.join(", "));
505
+ log($.cyan("◼"), $.bold("Installing packages..."));
506
+ log($.cyan("◼"), packages.join(", "));
468
507
  log();
469
508
  await installPackage(packages, {
470
509
  dev: true,
@@ -555,16 +594,14 @@ async function generateFrameworkConfigFile(options) {
555
594
  await writeFile(options.configPath, configContent);
556
595
  }
557
596
  async function updatePkgJsonScripts(pkgJsonPath, vitestScript) {
558
- if (!existsSync(pkgJsonPath)) {
559
- const pkg = { scripts: { "test:browser": vitestScript } };
560
- await writeFile(pkgJsonPath, `${JSON.stringify(pkg, null, 2)}\n`, "utf-8");
561
- } else {
597
+ if (!existsSync(pkgJsonPath)) await writeFile(pkgJsonPath, `${JSON.stringify({ scripts: { "test:browser": vitestScript } }, null, 2)}\n`, "utf-8");
598
+ else {
562
599
  const pkg = JSON.parse(readFileSync(pkgJsonPath, "utf-8"));
563
600
  pkg.scripts = pkg.scripts || {};
564
601
  pkg.scripts["test:browser"] = vitestScript;
565
602
  await writeFile(pkgJsonPath, `${JSON.stringify(pkg, null, 2)}\n`, "utf-8");
566
603
  }
567
- log(c.green("✔"), "Added \"test:browser\" script to your package.json.");
604
+ log($.green("✔"), "Added \"test:browser\" script to your package.json.");
568
605
  }
569
606
  function getRunScript(pkgManager) {
570
607
  switch (pkgManager) {
@@ -587,7 +624,7 @@ function getPlaywrightRunArgs(pkgManager) {
587
624
  }
588
625
  }
589
626
  async function create() {
590
- log(c.cyan("◼"), "This utility will help you set up a browser testing environment.\n");
627
+ log($.cyan("◼"), "This utility will help you set up a browser testing environment.\n");
591
628
  const pkgJsonPath = resolve(process.cwd(), "package.json");
592
629
  const pkg = readPkgJson(pkgJsonPath) || {};
593
630
  const dependencies = {
@@ -641,7 +678,7 @@ async function create() {
641
678
  const pkgManager = await detectPackageManager();
642
679
  log();
643
680
  await installPackages(pkgManager, dependenciesToInstall.filter((pkg) => !dependencies[pkg]));
644
- const rootConfig = any(configFiles, { cwd: process.cwd() });
681
+ const rootConfig = findConfigFile(process.cwd());
645
682
  let scriptCommand = "vitest";
646
683
  log();
647
684
  if (rootConfig) {
@@ -655,13 +692,13 @@ async function create() {
655
692
  browsers
656
693
  });
657
694
  log(
658
- c.green("✔"),
695
+ $.green("✔"),
659
696
  "Created a new config file for browser tests:",
660
- c.bold(relative(process.cwd(), configPath)),
697
+ $.bold(relative(process.cwd(), configPath)),
661
698
  // TODO: Can we modify the config ourselves?
662
699
  "\nSince you already have a Vitest config file, it is recommended to copy the contents of the new file ",
663
700
  "into your existing config located at ",
664
- c.bold(relative(process.cwd(), rootConfig))
701
+ $.bold(relative(process.cwd(), rootConfig))
665
702
  );
666
703
  } else {
667
704
  const configPath = resolve(process.cwd(), `vitest.config.${lang}`);
@@ -672,7 +709,7 @@ async function create() {
672
709
  provider,
673
710
  browsers
674
711
  });
675
- log(c.green("✔"), "Created a config file for browser tests:", c.bold(relative(process.cwd(), configPath)));
712
+ log($.green("✔"), "Created a config file for browser tests:", $.bold(relative(process.cwd(), configPath)));
676
713
  }
677
714
  log();
678
715
  await updatePkgJsonScripts(pkgJsonPath, scriptCommand);
@@ -685,7 +722,7 @@ async function create() {
685
722
  "install",
686
723
  "--with-deps"
687
724
  ];
688
- log(c.cyan("◼"), `Installing Playwright dependencies with \`${c.bold(command)} ${c.bold(allArgs.join(" "))}\`...`);
725
+ log($.cyan("◼"), `Installing Playwright dependencies with \`${$.bold(command)} ${$.bold(allArgs.join(" "))}\`...`);
689
726
  log();
690
727
  await x(command, allArgs, { nodeOptions: { stdio: [
691
728
  "pipe",
@@ -695,10 +732,10 @@ async function create() {
695
732
  }
696
733
  log();
697
734
  const exampleTestFile = await generateExampleFiles(framework, lang);
698
- log(c.green("✔"), "Created example test file in", c.bold(relative(process.cwd(), exampleTestFile)));
699
- log(c.dim(" You can safely delete this file once you have written your own tests."));
735
+ log($.green("✔"), "Created example test file in", $.bold(relative(process.cwd(), exampleTestFile)));
736
+ log($.dim(" You can safely delete this file once you have written your own tests."));
700
737
  log();
701
- log(c.cyan("◼"), "All done! Run your tests with", c.bold(getRunScript(pkgManager)));
738
+ log($.cyan("◼"), "All done! Run your tests with", $.bold(getRunScript(pkgManager)));
702
739
  }
703
740
 
704
741
  export { create };
@@ -1,15 +1,19 @@
1
- import nodeos__default from 'node:os';
2
- import './env.D4Lgay0q.js';
1
+ import os__default from 'node:os';
2
+ import './env.BKKtU2WC.js';
3
3
  import { isCI, isAgent } from 'std-env';
4
4
 
5
5
  const defaultInclude = ["**/*.{test,spec}.?(c|m)[jt]s?(x)"];
6
6
  const defaultExclude = ["**/node_modules/**", "**/.git/**"];
7
7
  const benchmarkConfigDefaults = {
8
+ enabled: false,
8
9
  include: ["**/*.{bench,benchmark}.?(c|m)[jt]s?(x)"],
9
10
  exclude: defaultExclude,
10
11
  includeSource: [],
11
- reporters: ["default"],
12
- includeSamples: false
12
+ retainSamples: false,
13
+ suppressExportGetterWarnings: false,
14
+ // Populated automatically when Vitest clones the parent project; the default
15
+ // here applies to the (unused) raw config that's never run as a benchmark.
16
+ projectName: ""
13
17
  };
14
18
  // These are the generic defaults for coverage. Providers may also set some provider specific defaults.
15
19
  const coverageConfigDefaults = {
@@ -28,7 +32,7 @@ const coverageConfigDefaults = {
28
32
  ],
29
33
  allowExternal: false,
30
34
  excludeAfterRemap: false,
31
- processingConcurrency: Math.min(20, nodeos__default.availableParallelism?.() ?? nodeos__default.cpus().length),
35
+ processingConcurrency: Math.min(20, os__default.availableParallelism()),
32
36
  ignoreClassMethods: [],
33
37
  skipFull: false,
34
38
  watermarks: {
@@ -36,7 +40,8 @@ const coverageConfigDefaults = {
36
40
  functions: [50, 80],
37
41
  branches: [50, 80],
38
42
  lines: [50, 80]
39
- }
43
+ },
44
+ autoAttachSubprocess: false
40
45
  };
41
46
  const fakeTimersDefaults = {
42
47
  loopLimit: 1e4,
@@ -47,8 +52,9 @@ const configDefaults = Object.freeze({
47
52
  isolate: true,
48
53
  watch: !isCI && process.stdin.isTTY && !isAgent,
49
54
  globals: false,
55
+ injectCjsGlobals: true,
50
56
  environment: "node",
51
- clearMocks: false,
57
+ clearMocks: true,
52
58
  restoreMocks: false,
53
59
  mockReset: false,
54
60
  unstubGlobals: false,
@@ -56,9 +62,9 @@ const configDefaults = Object.freeze({
56
62
  include: defaultInclude,
57
63
  exclude: defaultExclude,
58
64
  teardownTimeout: 1e4,
59
- forceRerunTriggers: ["**/package.json/**", "**/{vitest,vite}.config.*/**"],
65
+ forceRerunTriggers: ["**/package.json", "**/{vitest,vite}.config.*"],
60
66
  update: false,
61
- reporters: [],
67
+ reporters: [isAgent ? "minimal" : "default", ...process.env.GITHUB_ACTIONS === "true" ? ["github-actions"] : []],
62
68
  silent: false,
63
69
  hideSkippedTests: false,
64
70
  api: false,
@@ -76,6 +82,7 @@ const configDefaults = Object.freeze({
76
82
  exclude: defaultExclude
77
83
  },
78
84
  slowTestThreshold: 300,
85
+ taskTitleValueFormatTruncate: 40,
79
86
  disableConsoleIntercept: false,
80
87
  detectAsyncLeaks: false
81
88
  });
@@ -0,0 +1,194 @@
1
+ import { f as format$1, p as plugins, c as createDOMElementFilter } from './index.D0heQG4v.js';
2
+
3
+ const { AsymmetricMatcher, DOMCollection, DOMElement, Immutable, ReactElement, ReactTestComponent } = plugins;
4
+ const PLUGINS = [
5
+ ReactTestComponent,
6
+ ReactElement,
7
+ DOMElement,
8
+ DOMCollection,
9
+ Immutable,
10
+ AsymmetricMatcher
11
+ ];
12
+ function stringify(object, maxDepth = 10, { maxLength, filterNode, ...options } = {}) {
13
+ const MAX_LENGTH = maxLength ?? 1e4;
14
+ let result;
15
+ // Convert string selector to filter function
16
+ const filterFn = typeof filterNode === "string" ? createNodeFilterFromSelector(filterNode) : filterNode;
17
+ const plugins = filterFn ? [
18
+ ReactTestComponent,
19
+ ReactElement,
20
+ createDOMElementFilter(filterFn),
21
+ DOMCollection,
22
+ Immutable,
23
+ AsymmetricMatcher
24
+ ] : PLUGINS;
25
+ try {
26
+ result = format$1(object, {
27
+ maxDepth,
28
+ escapeString: false,
29
+ // min: true,
30
+ plugins,
31
+ ...options
32
+ });
33
+ } catch {
34
+ result = format$1(object, {
35
+ callToJSON: false,
36
+ maxDepth,
37
+ escapeString: false,
38
+ // min: true,
39
+ plugins,
40
+ ...options
41
+ });
42
+ }
43
+ // Prevents infinite loop https://github.com/vitest-dev/vitest/issues/7249
44
+ return result.length >= MAX_LENGTH && maxDepth > 1 ? stringify(object, Math.floor(Math.min(maxDepth, Number.MAX_SAFE_INTEGER) / 2), {
45
+ maxLength,
46
+ filterNode,
47
+ ...options
48
+ }) : result;
49
+ }
50
+ function createNodeFilterFromSelector(selector) {
51
+ const ELEMENT_NODE = 1;
52
+ const COMMENT_NODE = 8;
53
+ return (node) => {
54
+ // Filter out comments
55
+ if (node.nodeType === COMMENT_NODE) return false;
56
+ // Filter out elements matching the selector
57
+ if (node.nodeType === ELEMENT_NODE && node.matches) try {
58
+ return !node.matches(selector);
59
+ } catch {
60
+ return true;
61
+ }
62
+ return true;
63
+ };
64
+ }
65
+ const formatRegExp = /%[sdjifoOc%]/g;
66
+ function format(args, options = {}) {
67
+ const formatArg = (item) => inspect(item, options);
68
+ if (typeof args[0] !== "string") {
69
+ const objects = [];
70
+ for (let i = 0; i < args.length; i++) objects.push(formatArg(args[i]));
71
+ return objects.join(" ");
72
+ }
73
+ const len = args.length;
74
+ let i = 1;
75
+ const template = args[0];
76
+ let str = String(template).replace(formatRegExp, (x) => {
77
+ if (x === "%%") return "%";
78
+ if (i >= len) return x;
79
+ switch (x) {
80
+ case "%s": {
81
+ const value = args[i++];
82
+ if (typeof value === "bigint") return `${value.toString()}n`;
83
+ if (typeof value === "number" && value === 0 && 1 / value < 0) return "-0";
84
+ if (typeof value === "object" && value !== null) {
85
+ if (typeof value.toString === "function" && value.toString !== Object.prototype.toString) return value.toString();
86
+ return formatArg(value);
87
+ }
88
+ return String(value);
89
+ }
90
+ case "%d": {
91
+ const value = args[i++];
92
+ if (typeof value === "bigint") return `${value.toString()}n`;
93
+ if (typeof value === "symbol") return "NaN";
94
+ return Number(value).toString();
95
+ }
96
+ case "%i": {
97
+ const value = args[i++];
98
+ if (typeof value === "bigint") return `${value.toString()}n`;
99
+ return Number.parseInt(String(value)).toString();
100
+ }
101
+ case "%f": return Number.parseFloat(String(args[i++])).toString();
102
+ case "%o":
103
+ case "%O": return formatArg(args[i++]);
104
+ case "%c":
105
+ i++;
106
+ return "";
107
+ case "%j": try {
108
+ return JSON.stringify(args[i++]);
109
+ } catch (err) {
110
+ const m = err.message;
111
+ if (m.includes("circular structure") || m.includes("cyclic structures") || m.includes("cyclic object")) return "[Circular]";
112
+ throw err;
113
+ }
114
+ default: return x;
115
+ }
116
+ });
117
+ for (let x = args[i]; i < len; x = args[++i]) if (x === null || typeof x !== "object") str += ` ${typeof x === "symbol" ? x.toString() : x}`;
118
+ else str += ` ${formatArg(x)}`;
119
+ return str;
120
+ }
121
+ function inspect(obj, options) {
122
+ const { truncate, multiline, ...stringifyOptions } = options ?? {};
123
+ const prettyFormatOptions = {
124
+ singleQuote: true,
125
+ quoteKeys: false,
126
+ min: true,
127
+ spacingInner: " ",
128
+ spacingOuter: " ",
129
+ printBasicPrototype: false,
130
+ compareKeys: null,
131
+ ...multiline ? {
132
+ min: false,
133
+ spacingInner: void 0,
134
+ spacingOuter: void 0
135
+ } : {}
136
+ };
137
+ const threshold = truncate ?? 0;
138
+ const formatted = stringify(obj, void 0, {
139
+ ...prettyFormatOptions,
140
+ ...stringifyOptions,
141
+ maxLength: threshold || void 0
142
+ });
143
+ if (threshold === 0 || formatted.length <= threshold) return formatted;
144
+ // if stringify's adaptive maxDepth (down to 1) fails to truncate enough,
145
+ // - for known types (e.g. string, object, array, etc), apply best effort truncation.
146
+ // - for other values, fallback to maxDepth = 0 which should can show minimal output.
147
+ const type = Object.prototype.toString.call(obj);
148
+ if (typeof obj === "string") {
149
+ let end = threshold - 1;
150
+ if (end > 0 && isHighSurrogate(formatted[end - 1])) end = end - 1;
151
+ return `'${formatted.slice(1, end)}…'`;
152
+ }
153
+ if (type === "[object Array]" || type === "[object Object]" || type === "[object Set]" || type === "[object Map]") return stringifyByMaxWidth(obj, threshold, {
154
+ ...prettyFormatOptions,
155
+ ...stringifyOptions,
156
+ maxDepth: 1
157
+ });
158
+ return stringify(obj, void 0, {
159
+ ...prettyFormatOptions,
160
+ ...stringifyOptions,
161
+ maxDepth: 0
162
+ });
163
+ }
164
+ function truncateString(string, maxLength) {
165
+ if (string.length <= maxLength) return string;
166
+ let end = maxLength - 1;
167
+ if (isHighSurrogate(string[end - 1])) end = end - 1;
168
+ return `${string.slice(0, end)}…`;
169
+ }
170
+ function stringifyByMaxWidth(object, threshold, options) {
171
+ function evaluate(x) {
172
+ return stringify(object, void 0, {
173
+ ...options,
174
+ maxWidth: x
175
+ });
176
+ }
177
+ return evaluate(binarySearch(0, threshold, (x) => evaluate(x).length <= threshold));
178
+ }
179
+ // find max(x \in [x, y) | f(x) = true)
180
+ // if f(x0) is false, then returns x0.
181
+ function binarySearch(x0, x1, f) {
182
+ while (x0 + 1 < x1) {
183
+ const x = Math.floor((x0 + x1) / 2);
184
+ if (f(x)) x0 = x;
185
+ else x1 = x;
186
+ }
187
+ return x0;
188
+ }
189
+ // https://github.com/chaijs/loupe/pull/79
190
+ function isHighSurrogate(char) {
191
+ return char >= "\ud800" && char <= "\udbff";
192
+ }
193
+
194
+ export { formatRegExp as a, format as f, inspect as i, stringify as s, truncateString as t };