vitest 4.0.9 → 4.0.11

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 +4 -3
  2. package/dist/browser.js +1 -1
  3. package/dist/chunks/_commonjsHelpers.D26ty3Ew.js +6 -0
  4. package/dist/chunks/{base.CiIV2DDC.js → base.DiCUKpyF.js} +47 -40
  5. package/dist/chunks/{browser.d.DnU_kh8a.d.ts → browser.d.D-d8eZY4.d.ts} +1 -1
  6. package/dist/chunks/{cac.B_NTJoIH.js → cac.aVhqBj0-.js} +21 -7
  7. package/dist/chunks/{cli-api.D48wY175.js → cli-api.-bIZD4XU.js} +960 -345
  8. package/dist/chunks/{coverage.BUlIqJrL.js → coverage.CtyeYmKM.js} +7 -1
  9. package/dist/chunks/{creator.BzqvXeRE.js → creator.DAmOKTvJ.js} +5 -5
  10. package/dist/chunks/{global.d.BQDgW9Pr.d.ts → global.d.uY4Q0M5z.d.ts} +1 -1
  11. package/dist/chunks/{globals.DBrtKPdh.js → globals.C0izxiX3.js} +3 -3
  12. package/dist/chunks/{index.op2Re5rn.js → index.CMvpbrsJ.js} +1 -1
  13. package/dist/chunks/{index.CPA8jGhR.js → index.CQwQ_SLL.js} +16 -4
  14. package/dist/chunks/{index.z7NPOg2E.js → index.D4KonVSU.js} +1 -1
  15. package/dist/chunks/{index.CGezRSGU.js → index.DBx1AtPJ.js} +3 -2
  16. package/dist/chunks/{index.kotH7DY7.js → index.DWDW6mLz.js} +15 -4
  17. package/dist/chunks/{index.BfmpdV5p.js → index.QWbK7rHY.js} +3 -3
  18. package/dist/chunks/init-forks.DIuGPyId.js +32 -0
  19. package/dist/chunks/{init-threads.C7T0-YMD.js → init-threads.jC_8JdoN.js} +3 -3
  20. package/dist/chunks/{init.BQhNfT0h.js → init.B3IeC_yW.js} +60 -22
  21. package/dist/chunks/{moduleRunner.d.BxT-OjLR.d.ts → moduleRunner.d.B5SW5pMI.d.ts} +9 -1
  22. package/dist/chunks/plugin.d.N8khPRFb.d.ts +38 -0
  23. package/dist/chunks/{reporters.d.BQ0wpUaj.d.ts → reporters.d.DgZLBdyd.d.ts} +109 -48
  24. package/dist/chunks/{setup-common.Dw1XgX0v.js → setup-common.DGHc_BUK.js} +2 -2
  25. package/dist/chunks/{startModuleRunner.DLjmA_wU.js → startModuleRunner.DaBMy1JT.js} +97 -49
  26. package/dist/chunks/{test.w5HLbjmU.js → test.DqQZzsWf.js} +15 -5
  27. package/dist/chunks/traces.BVPrsYso.js +151 -0
  28. package/dist/chunks/{config.d.BTfZNUu9.d.ts → traces.d.B8ukBJqA.d.ts} +36 -1
  29. package/dist/chunks/{vi.CyIUVSoU.js → vi.BiaV1qII.js} +2 -2
  30. package/dist/chunks/{vm.DXN8eCh2.js → vm.BKyGp1KW.js} +12 -8
  31. package/dist/chunks/{worker.d.ZGohxCEd.d.ts → worker.d.B_PZTrCQ.d.ts} +5 -4
  32. package/dist/cli.js +2 -2
  33. package/dist/config.d.ts +8 -7
  34. package/dist/coverage.d.ts +6 -5
  35. package/dist/coverage.js +2 -2
  36. package/dist/environments.js +1 -1
  37. package/dist/index.d.ts +14 -12
  38. package/dist/index.js +4 -4
  39. package/dist/module-evaluator.d.ts +7 -6
  40. package/dist/module-evaluator.js +14 -1
  41. package/dist/module-runner.js +2 -1
  42. package/dist/node.d.ts +11 -10
  43. package/dist/node.js +12 -11
  44. package/dist/reporters.d.ts +6 -5
  45. package/dist/reporters.js +2 -2
  46. package/dist/runners.d.ts +5 -1
  47. package/dist/runners.js +3 -3
  48. package/dist/worker.d.ts +8 -7
  49. package/dist/worker.js +11 -10
  50. package/dist/workers/forks.js +12 -12
  51. package/dist/workers/runVmTests.js +24 -22
  52. package/dist/workers/threads.js +12 -11
  53. package/dist/workers/vmForks.js +6 -6
  54. package/dist/workers/vmThreads.js +6 -5
  55. package/package.json +19 -14
  56. package/dist/chunks/_commonjsHelpers.BFTU3MAI.js +0 -7
  57. package/dist/chunks/init-forks.aqTzCSR2.js +0 -65
  58. package/dist/chunks/plugin.d.DevON6kQ.d.ts +0 -9
package/dist/browser.d.ts CHANGED
@@ -1,7 +1,7 @@
1
- import { a as SerializedCoverageConfig, S as SerializedConfig } from './chunks/config.d.BTfZNUu9.js';
1
+ import { a as SerializedCoverageConfig, S as SerializedConfig } from './chunks/traces.d.B8ukBJqA.js';
2
2
  import { R as RuntimeCoverageModuleLoader } from './chunks/coverage.d.BZtK59WP.js';
3
3
  import { SerializedDiffOptions } from '@vitest/utils/diff';
4
- import { V as VitestModuleRunner } from './chunks/moduleRunner.d.BxT-OjLR.js';
4
+ import { V as VitestModuleRunner } from './chunks/moduleRunner.d.B5SW5pMI.js';
5
5
  export { collectTests, startTests } from '@vitest/runner';
6
6
  import * as _vitest_spy from '@vitest/spy';
7
7
  export { _vitest_spy as SpyModule };
@@ -13,9 +13,10 @@ export { DecodedMap, getOriginalPosition } from '@vitest/utils/source-map';
13
13
  export { getSafeTimers, setSafeTimers } from '@vitest/utils/timers';
14
14
  import '@vitest/pretty-format';
15
15
  import '@vitest/snapshot';
16
+ import '@opentelemetry/api';
16
17
  import 'node:vm';
17
18
  import 'vite/module-runner';
18
- import './chunks/worker.d.ZGohxCEd.js';
19
+ import './chunks/worker.d.B_PZTrCQ.js';
19
20
  import './chunks/environment.d.CrsxCzP1.js';
20
21
  import '@vitest/mocker';
21
22
  import './chunks/mocker.d.BE_2ls6u.js';
package/dist/browser.js CHANGED
@@ -1,4 +1,4 @@
1
- export { l as loadDiffConfig, b as loadSnapshotSerializers, c as setupCommonEnv, s as startCoverageInsideWorker, a as stopCoverageInsideWorker, t as takeCoverageInsideWorker } from './chunks/setup-common.Dw1XgX0v.js';
1
+ export { l as loadDiffConfig, b as loadSnapshotSerializers, c as setupCommonEnv, s as startCoverageInsideWorker, a as stopCoverageInsideWorker, t as takeCoverageInsideWorker } from './chunks/setup-common.DGHc_BUK.js';
2
2
  export { collectTests, startTests } from '@vitest/runner';
3
3
  import * as spyModule from '@vitest/spy';
4
4
  export { spyModule as SpyModule };
@@ -0,0 +1,6 @@
1
+ var commonjsGlobal = typeof globalThis !== "undefined" ? globalThis : typeof window !== "undefined" ? window : typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : {};
2
+ function getDefaultExportFromCjs(x) {
3
+ return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, "default") ? x["default"] : x;
4
+ }
5
+
6
+ export { commonjsGlobal as c, getDefaultExportFromCjs as g };
@@ -1,20 +1,20 @@
1
1
  import { runInThisContext } from 'node:vm';
2
2
  import * as spyModule from '@vitest/spy';
3
- import { r as resolveTestRunner, a as resolveSnapshotEnvironment, s as setupChaiConfig } from './index.CPA8jGhR.js';
4
- import { l as loadEnvironment } from './init.BQhNfT0h.js';
3
+ import { r as resolveTestRunner, a as resolveSnapshotEnvironment, s as setupChaiConfig } from './index.CQwQ_SLL.js';
4
+ import { l as loadEnvironment } from './init.B3IeC_yW.js';
5
5
  import { V as VitestEvaluatedModules } from './evaluatedModules.Dg1zASAC.js';
6
- import { s as startVitestModuleRunner, c as createNodeImportMeta } from './startModuleRunner.DLjmA_wU.js';
6
+ import { s as startVitestModuleRunner, c as createNodeImportMeta } from './startModuleRunner.DaBMy1JT.js';
7
7
  import { performance as performance$1 } from 'node:perf_hooks';
8
8
  import { startTests, collectTests } from '@vitest/runner';
9
- import { c as setupCommonEnv, s as startCoverageInsideWorker, a as stopCoverageInsideWorker } from './setup-common.Dw1XgX0v.js';
10
- import { g as globalExpect, v as vi } from './vi.CyIUVSoU.js';
9
+ import { c as setupCommonEnv, s as startCoverageInsideWorker, a as stopCoverageInsideWorker } from './setup-common.DGHc_BUK.js';
10
+ import { g as globalExpect, v as vi } from './vi.BiaV1qII.js';
11
11
  import { c as closeInspector } from './inspector.CvyFGlXm.js';
12
12
  import { createRequire } from 'node:module';
13
13
  import timers from 'node:timers';
14
14
  import timersPromises from 'node:timers/promises';
15
15
  import util from 'node:util';
16
16
  import { KNOWN_ASSET_TYPES } from '@vitest/utils/constants';
17
- import { i as index } from './index.CGezRSGU.js';
17
+ import { i as index } from './index.DBx1AtPJ.js';
18
18
  import { g as getWorkerState, r as resetModules, p as provideWorkerState } from './utils.DvEY5TfP.js';
19
19
 
20
20
  // this should only be used in Node
@@ -61,35 +61,37 @@ async function setupConsoleLogSpy() {
61
61
  }
62
62
 
63
63
  // browser shouldn't call this!
64
- async function run(method, files, config, moduleRunner, environment) {
64
+ async function run(method, files, config, moduleRunner, environment, traces) {
65
65
  const workerState = getWorkerState();
66
66
  const [testRunner] = await Promise.all([
67
- resolveTestRunner(config, moduleRunner),
68
- setupGlobalEnv(config, environment),
69
- startCoverageInsideWorker(config.coverage, moduleRunner, { isolate: config.isolate }),
70
- (async () => {
67
+ traces.$("vitest.runtime.runner", () => resolveTestRunner(config, moduleRunner, traces)),
68
+ traces.$("vitest.runtime.global_env", () => setupGlobalEnv(config, environment)),
69
+ traces.$("vitest.runtime.coverage.start", () => startCoverageInsideWorker(config.coverage, moduleRunner, { isolate: config.isolate })),
70
+ traces.$("vitest.runtime.snapshot.environment", async () => {
71
71
  if (!workerState.config.snapshotOptions.snapshotEnvironment) workerState.config.snapshotOptions.snapshotEnvironment = await resolveSnapshotEnvironment(config, moduleRunner);
72
- })()
72
+ })
73
73
  ]);
74
74
  workerState.onCancel((reason) => {
75
75
  closeInspector(config);
76
76
  testRunner.cancel?.(reason);
77
77
  });
78
78
  workerState.durations.prepare = performance$1.now() - workerState.durations.prepare;
79
- for (const file of files) {
80
- if (config.isolate) {
81
- moduleRunner.mocker.reset();
82
- resetModules(workerState.evaluatedModules, true);
79
+ await traces.$(`vitest.test.runner.${method}`, async () => {
80
+ for (const file of files) {
81
+ if (config.isolate) {
82
+ moduleRunner.mocker.reset();
83
+ resetModules(workerState.evaluatedModules, true);
84
+ }
85
+ workerState.filepath = file.filepath;
86
+ if (method === "run") await traces.$(`vitest.test.runner.${method}.module`, { attributes: { "code.file.path": file.filepath } }, () => startTests([file], testRunner));
87
+ else await traces.$(`vitest.test.runner.${method}.module`, { attributes: { "code.file.path": file.filepath } }, () => collectTests([file], testRunner));
88
+ // reset after tests, because user might call `vi.setConfig` in setupFile
89
+ vi.resetConfig();
90
+ // mocks should not affect different files
91
+ vi.restoreAllMocks();
83
92
  }
84
- workerState.filepath = file.filepath;
85
- if (method === "run") await startTests([file], testRunner);
86
- else await collectTests([file], testRunner);
87
- // reset after tests, because user might call `vi.setConfig` in setupFile
88
- vi.resetConfig();
89
- // mocks should not affect different files
90
- vi.restoreAllMocks();
91
- }
92
- await stopCoverageInsideWorker(config.coverage, moduleRunner, { isolate: config.isolate });
93
+ });
94
+ await traces.$("vitest.runtime.coverage.stop", () => stopCoverageInsideWorker(config.coverage, moduleRunner, { isolate: config.isolate }));
93
95
  }
94
96
 
95
97
  let _moduleRunner;
@@ -105,18 +107,31 @@ let _environmentTime;
105
107
  async function setupEnvironment(context) {
106
108
  const startTime = performance.now();
107
109
  const { environment: { name: environmentName, options: environmentOptions }, rpc, config } = context;
108
- const { environment, loader } = await loadEnvironment(environmentName, config.root, rpc);
110
+ // we could load @vite/env, but it would take ~8ms, while this takes ~0,02ms
111
+ if (context.config.serializedDefines) try {
112
+ runInThisContext(`(() =>{\n${context.config.serializedDefines}})()`, {
113
+ lineOffset: 1,
114
+ filename: "virtual:load-defines.js"
115
+ });
116
+ } catch (error) {
117
+ throw new Error(`Failed to load custom "defines": ${error.message}`);
118
+ }
119
+ const otel = context.traces;
120
+ const { environment, loader } = await loadEnvironment(environmentName, config.root, rpc, otel);
109
121
  _currentEnvironment = environment;
110
- const env = await environment.setup(globalThis, environmentOptions || config.environmentOptions || {});
122
+ const env = await otel.$("vitest.runtime.environment.setup", { attributes: {
123
+ "vitest.environment": environment.name,
124
+ "vitest.environment.vite_environment": environment.viteEnvironment || environment.name
125
+ } }, () => environment.setup(globalThis, environmentOptions || config.environmentOptions || {}));
111
126
  _environmentTime = performance.now() - startTime;
112
127
  if (config.chaiConfig) setupChaiConfig(config.chaiConfig);
113
128
  return async () => {
114
- await env.teardown(globalThis);
129
+ await otel.$("vitest.runtime.environment.teardown", () => env.teardown(globalThis));
115
130
  await loader?.close();
116
131
  };
117
132
  }
118
133
  /** @experimental */
119
- async function runBaseTests(method, state) {
134
+ async function runBaseTests(method, state, traces) {
120
135
  const { ctx } = state;
121
136
  state.environment = _currentEnvironment;
122
137
  state.durations.environment = _environmentTime;
@@ -139,18 +154,10 @@ async function runBaseTests(method, state) {
139
154
  state,
140
155
  evaluatedModules: state.evaluatedModules,
141
156
  spyModule,
142
- createImportMeta: createNodeImportMeta
157
+ createImportMeta: createNodeImportMeta,
158
+ traces
143
159
  });
144
- // we could load @vite/env, but it would take ~8ms, while this takes ~0,02ms
145
- if (ctx.config.serializedDefines) try {
146
- runInThisContext(`(() =>{\n${ctx.config.serializedDefines}})()`, {
147
- lineOffset: 1,
148
- filename: "virtual:load-defines.js"
149
- });
150
- } catch (error) {
151
- throw new Error(`Failed to load custom "defines": ${error.message}`);
152
- }
153
- await run(method, ctx.files, ctx.config, moduleRunner, _currentEnvironment);
160
+ await run(method, ctx.files, ctx.config, moduleRunner, _currentEnvironment, traces);
154
161
  }
155
162
 
156
163
  export { runBaseTests as r, setupEnvironment as s };
@@ -1,5 +1,5 @@
1
1
  import { FileSpecification } from '@vitest/runner';
2
- import { T as TestExecutionMethod } from './worker.d.ZGohxCEd.js';
2
+ import { T as TestExecutionMethod } from './worker.d.B_PZTrCQ.js';
3
3
 
4
4
  type SerializedTestSpecification = [project: {
5
5
  name: string | undefined;
@@ -3,7 +3,7 @@ import { EventEmitter } from 'events';
3
3
  import { normalize } from 'pathe';
4
4
  import c from 'tinyrainbow';
5
5
  import { a as defaultPort, d as defaultBrowserPort } from './constants.D_Q9UYh-.js';
6
- import { R as ReportersMap } from './index.kotH7DY7.js';
6
+ import { R as ReportersMap } from './index.DWDW6mLz.js';
7
7
 
8
8
  function toArr(any) {
9
9
  return any == null ? [] : Array.isArray(any) ? any : [any];
@@ -619,7 +619,7 @@ class CAC extends EventEmitter {
619
619
 
620
620
  const cac = (name = "") => new CAC(name);
621
621
 
622
- var version = "4.0.9";
622
+ var version = "4.0.11";
623
623
 
624
624
  const apiConfig = (port) => ({
625
625
  port: {
@@ -1152,6 +1152,16 @@ const cliOptionsConfig = {
1152
1152
  return value;
1153
1153
  }
1154
1154
  },
1155
+ clearCache: { description: "Delete all Vitest caches, including `experimental.fsModuleCache`, without running any tests. This will reduce the performance in the subsequent test run." },
1156
+ experimental: {
1157
+ description: "Experimental features.",
1158
+ argument: "<features>",
1159
+ subcommands: {
1160
+ fsModuleCache: { description: "Enable caching of modules on the file system between reruns." },
1161
+ fsModuleCachePath: null,
1162
+ openTelemetry: null
1163
+ }
1164
+ },
1155
1165
  cliExclude: null,
1156
1166
  server: null,
1157
1167
  setupFiles: null,
@@ -1353,15 +1363,19 @@ function normalizeCliOptions(cliFilters, argv) {
1353
1363
  }
1354
1364
  if (cliFilters.some((filter) => filter.includes(":"))) argv.includeTaskLocation ??= true;
1355
1365
  if (typeof argv.typecheck?.only === "boolean") argv.typecheck.enabled ??= true;
1366
+ if (argv.clearCache) {
1367
+ argv.watch = false;
1368
+ argv.run = true;
1369
+ }
1356
1370
  return argv;
1357
1371
  }
1358
1372
  async function start(mode, cliFilters, options) {
1359
1373
  try {
1360
- const { startVitest } = await import('./cli-api.D48wY175.js').then(function (n) { return n.p; });
1374
+ const { startVitest } = await import('./cli-api.-bIZD4XU.js').then(function (n) { return n.p; });
1361
1375
  const ctx = await startVitest(mode, cliFilters.map(normalize), normalizeCliOptions(cliFilters, options));
1362
1376
  if (!ctx.shouldKeepServer()) await ctx.exit();
1363
1377
  } catch (e) {
1364
- const { errorBanner } = await import('./index.kotH7DY7.js').then(function (n) { return n.u; });
1378
+ const { errorBanner } = await import('./index.DWDW6mLz.js').then(function (n) { return n.u; });
1365
1379
  console.error(`\n${errorBanner("Startup Error")}`);
1366
1380
  console.error(e);
1367
1381
  console.error("\n\n");
@@ -1374,12 +1388,12 @@ async function init(project) {
1374
1388
  console.error(/* @__PURE__ */ new Error("Only the \"browser\" project is supported. Use \"vitest init browser\" to create a new project."));
1375
1389
  process.exit(1);
1376
1390
  }
1377
- const { create } = await import('./creator.BzqvXeRE.js');
1391
+ const { create } = await import('./creator.DAmOKTvJ.js');
1378
1392
  await create();
1379
1393
  }
1380
1394
  async function collect(mode, cliFilters, options) {
1381
1395
  try {
1382
- const { prepareVitest, processCollected, outputFileList } = await import('./cli-api.D48wY175.js').then(function (n) { return n.p; });
1396
+ const { prepareVitest, processCollected, outputFileList } = await import('./cli-api.-bIZD4XU.js').then(function (n) { return n.p; });
1383
1397
  const ctx = await prepareVitest(mode, {
1384
1398
  ...normalizeCliOptions(cliFilters, options),
1385
1399
  watch: false,
@@ -1398,7 +1412,7 @@ async function collect(mode, cliFilters, options) {
1398
1412
  } else outputFileList(await ctx.getRelevantTestSpecifications(cliFilters.map(normalize)), options);
1399
1413
  await ctx.close();
1400
1414
  } catch (e) {
1401
- const { errorBanner } = await import('./index.kotH7DY7.js').then(function (n) { return n.u; });
1415
+ const { errorBanner } = await import('./index.DWDW6mLz.js').then(function (n) { return n.u; });
1402
1416
  console.error(`\n${errorBanner("Collect Error")}`);
1403
1417
  console.error(e);
1404
1418
  console.error("\n\n");