vitest 0.20.3 → 0.22.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 (44) hide show
  1. package/LICENSE.md +61 -4
  2. package/dist/browser.d.ts +8 -1902
  3. package/dist/browser.mjs +8 -9
  4. package/dist/{chunk-api-setup.9bff74bb.mjs → chunk-api-setup.ecd02c18.mjs} +8 -7
  5. package/dist/{chunk-constants.16825f0c.mjs → chunk-constants.d3f8437b.mjs} +4 -4
  6. package/dist/{chunk-install-pkg.6c6dc0c2.mjs → chunk-install-pkg.3aa3eae6.mjs} +3 -2
  7. package/dist/{chunk-defaults.6698a2d3.mjs → chunk-integrations-coverage.d205bd87.mjs} +23 -152
  8. package/dist/{chunk-integrations-globals.c5b78414.mjs → chunk-integrations-globals.e81d2091.mjs} +7 -6
  9. package/dist/{chunk-mock-date.9160e13b.mjs → chunk-mock-date.debe9954.mjs} +16 -74
  10. package/dist/chunk-node-git.71b74da4.mjs +80 -0
  11. package/dist/{chunk-runtime-chain.b6c2cdbc.mjs → chunk-runtime-chain.6e363ba2.mjs} +31 -21
  12. package/dist/{chunk-runtime-error.034e03ba.mjs → chunk-runtime-error.975bd80a.mjs} +14 -12
  13. package/dist/{chunk-runtime-hooks.a8401528.mjs → chunk-runtime-hooks.4789e99d.mjs} +3 -3
  14. package/dist/{chunk-runtime-mocker.653847b2.mjs → chunk-runtime-mocker.c91d29ce.mjs} +34 -12
  15. package/dist/{chunk-runtime-rpc.dbf0b31d.mjs → chunk-runtime-rpc.29488183.mjs} +1 -1
  16. package/dist/{chunk-utils-source-map.8198ebd9.mjs → chunk-utils-source-map.2a082ffd.mjs} +2 -1
  17. package/dist/{chunk-vite-node-client.115caed2.mjs → chunk-vite-node-client.d1ead698.mjs} +7 -3
  18. package/dist/{chunk-vite-node-debug.c5887932.mjs → chunk-vite-node-debug.ff1d2a9f.mjs} +3 -2
  19. package/dist/{chunk-vite-node-externalize.91ae6e85.mjs → chunk-vite-node-externalize.3a38c8af.mjs} +167 -39
  20. package/dist/chunk-vite-node-utils.d8e5ff7b.mjs +6921 -0
  21. package/dist/cli-wrapper.mjs +107 -0
  22. package/dist/cli.mjs +16 -14
  23. package/dist/config.cjs +3 -0
  24. package/dist/config.d.ts +7 -69
  25. package/dist/config.mjs +2 -1
  26. package/dist/entry.mjs +8 -9
  27. package/dist/global-74489cc9.d.ts +2098 -0
  28. package/dist/index-9eded9ec.d.ts +116 -0
  29. package/dist/index.d.ts +9 -1928
  30. package/dist/index.mjs +6 -5
  31. package/dist/loader.mjs +74 -17
  32. package/dist/node.d.ts +7 -1682
  33. package/dist/node.mjs +15 -13
  34. package/dist/suite.mjs +5 -4
  35. package/dist/{vendor-index.61438b77.mjs → vendor-index.29636037.mjs} +1 -61
  36. package/dist/{vendor-index.62ce5c33.mjs → vendor-index.2ae8040a.mjs} +0 -0
  37. package/dist/vendor-index.9d9196cc.mjs +61 -0
  38. package/dist/{vendor-index.de788b6a.mjs → vendor-index.ae96af6e.mjs} +14 -14
  39. package/dist/{chunk-node-git.43dbdd42.mjs → vendor-index.fbec8a81.mjs} +5 -73
  40. package/dist/vendor-picocolors.807856aa.mjs +64 -0
  41. package/dist/worker.mjs +7 -6
  42. package/package.json +8 -12
  43. package/vitest.mjs +1 -1
  44. package/dist/chunk-vite-node-utils.7e46948f.mjs +0 -1114
@@ -1,11 +1,11 @@
1
- import { e as environments, t as takeCoverage, p as pLimit } from './chunk-defaults.6698a2d3.mjs';
2
- import { r as resetRunOnceCounter, i as index, v as vi } from './chunk-runtime-hooks.a8401528.mjs';
3
- import { h as deepClone, k as getType, l as isNode, R as RealDate, t as toArray, o as relativePath, q as isBrowser, u as partitionSuiteChildren, v as shuffle, w as hasTests, x as hasFailed, e as getFullName } from './chunk-mock-date.9160e13b.mjs';
4
- import { e as clearCollectorContext, f as defaultSuite, h as setHooks, j as getHooks, k as collectorContext, l as setState, G as GLOBAL_EXPECT, m as getFn, n as getState } from './chunk-runtime-chain.b6c2cdbc.mjs';
5
- import { r as rpc } from './chunk-runtime-rpc.dbf0b31d.mjs';
1
+ import { e as environments, t as takeCoverageInsideWorker, p as pLimit } from './chunk-integrations-coverage.d205bd87.mjs';
2
+ import { r as resetRunOnceCounter, i as index, v as vi } from './chunk-runtime-hooks.4789e99d.mjs';
3
+ import { h as deepClone, k as getType, l as isNode, R as RealDate, t as toArray, o as relativePath, p as isBrowser, q as partitionSuiteChildren, u as shuffle, v as hasTests, w as hasFailed, e as getFullName } from './chunk-mock-date.debe9954.mjs';
4
+ import { e as clearCollectorContext, f as defaultSuite, h as setHooks, j as getHooks, k as collectorContext, l as setState, G as GLOBAL_EXPECT, m as getFn, n as getState } from './chunk-runtime-chain.6e363ba2.mjs';
5
+ import { r as rpc } from './chunk-runtime-rpc.29488183.mjs';
6
6
  import util$1 from 'util';
7
7
  import { util } from 'chai';
8
- import { s as stringify } from './chunk-utils-source-map.8198ebd9.mjs';
8
+ import { s as stringify } from './chunk-utils-source-map.2a082ffd.mjs';
9
9
  import { g as getWorkerState } from './chunk-utils-global.fa20c2f6.mjs';
10
10
  import { a as safeClearTimeout, s as safeSetTimeout } from './chunk-utils-timers.b48455ed.mjs';
11
11
 
@@ -123,6 +123,7 @@ async function setupGlobalEnv(config) {
123
123
  value: index,
124
124
  enumerable: false
125
125
  });
126
+ Error.stackTraceLimit = 100;
126
127
  setupDefines(config.defines);
127
128
  if (globalSetup)
128
129
  return;
@@ -130,7 +131,7 @@ async function setupGlobalEnv(config) {
130
131
  if (isNode)
131
132
  await setupConsoleLogSpy();
132
133
  if (config.globals)
133
- (await import('./chunk-integrations-globals.c5b78414.mjs')).registerApiGlobally();
134
+ (await import('./chunk-integrations-globals.e81d2091.mjs')).registerApiGlobally();
134
135
  }
135
136
  function setupDefines(defines) {
136
137
  for (const key in defines)
@@ -441,7 +442,7 @@ async function sendTasksUpdate() {
441
442
  async function runTest(test) {
442
443
  var _a, _b;
443
444
  if (test.mode !== "run") {
444
- const { getSnapshotClient } = await import('./chunk-runtime-chain.b6c2cdbc.mjs').then(function (n) { return n.p; });
445
+ const { getSnapshotClient } = await import('./chunk-runtime-chain.6e363ba2.mjs').then(function (n) { return n.p; });
445
446
  getSnapshotClient().skipTestSnapshots(test);
446
447
  return;
447
448
  }
@@ -457,7 +458,7 @@ async function runTest(test) {
457
458
  updateTask(test);
458
459
  clearModuleMocks();
459
460
  if (isNode) {
460
- const { getSnapshotClient } = await import('./chunk-runtime-chain.b6c2cdbc.mjs').then(function (n) { return n.p; });
461
+ const { getSnapshotClient } = await import('./chunk-runtime-chain.6e363ba2.mjs').then(function (n) { return n.p; });
461
462
  await getSnapshotClient().setTest(test);
462
463
  }
463
464
  const workerState = getWorkerState();
@@ -510,7 +511,7 @@ async function runTest(test) {
510
511
  if (isBrowser && test.result.error)
511
512
  console.error(test.result.error.message, test.result.error.stackStr);
512
513
  if (isNode) {
513
- const { getSnapshotClient } = await import('./chunk-runtime-chain.b6c2cdbc.mjs').then(function (n) { return n.p; });
514
+ const { getSnapshotClient } = await import('./chunk-runtime-chain.6e363ba2.mjs').then(function (n) { return n.p; });
514
515
  getSnapshotClient().clearTest();
515
516
  }
516
517
  test.result.duration = now() - start;
@@ -622,10 +623,11 @@ async function startTestsBrowser(paths, config) {
622
623
  async function startTestsNode(paths, config) {
623
624
  const files = await collectTests(paths, config);
624
625
  rpc().onCollected(files);
625
- const { getSnapshotClient } = await import('./chunk-runtime-chain.b6c2cdbc.mjs').then(function (n) { return n.p; });
626
+ const { getSnapshotClient } = await import('./chunk-runtime-chain.6e363ba2.mjs').then(function (n) { return n.p; });
626
627
  getSnapshotClient().clear();
627
628
  await runFiles(files, config);
628
- takeCoverage();
629
+ const coverage = await takeCoverageInsideWorker(config.coverage);
630
+ rpc().onAfterSuiteRun({ coverage });
629
631
  await getSnapshotClient().saveCurrent();
630
632
  await sendTasksUpdate();
631
633
  }
@@ -1,7 +1,7 @@
1
- import { g as getCurrentSuite, w as withTimeout, a as getDefaultHookTimeout, s as suite, t as test, d as describe, i as it, c as createExpect, b as globalExpect } from './chunk-runtime-chain.b6c2cdbc.mjs';
2
- import { R as RealDate, r as resetDate, m as mockDate, a as resetModules } from './chunk-mock-date.9160e13b.mjs';
1
+ import { g as getCurrentSuite, w as withTimeout, a as getDefaultHookTimeout, s as suite, t as test, d as describe, i as it, c as createExpect, b as globalExpect } from './chunk-runtime-chain.6e363ba2.mjs';
2
+ import { R as RealDate, r as resetDate, m as mockDate, a as resetModules } from './chunk-mock-date.debe9954.mjs';
3
3
  import { g as getWorkerState } from './chunk-utils-global.fa20c2f6.mjs';
4
- import { p as parseStacktrace } from './chunk-utils-source-map.8198ebd9.mjs';
4
+ import { p as parseStacktrace } from './chunk-utils-source-map.2a082ffd.mjs';
5
5
  import { c as commonjsGlobal } from './vendor-_commonjsHelpers.4da45ef5.mjs';
6
6
  import util from 'util';
7
7
  import { spyOn, fn, isMockFunction, spies } from './spy.mjs';
@@ -1,9 +1,9 @@
1
- import { V as ViteNodeRunner } from './chunk-vite-node-client.115caed2.mjs';
1
+ import { V as ViteNodeRunner } from './chunk-vite-node-client.d1ead698.mjs';
2
2
  import { normalizePath } from 'vite';
3
- import { M as isWindows, N as mergeSlashes, d as dirname, j as join, z as basename, y as resolve, s as slash, k as getType, O as getAllProperties } from './chunk-mock-date.9160e13b.mjs';
3
+ import { L as isWindows, M as mergeSlashes, d as dirname, j as join, y as basename, x as resolve, s as slash, k as getType, N as getAllMockableProperties } from './chunk-mock-date.debe9954.mjs';
4
4
  import { existsSync, readdirSync } from 'fs';
5
- import { n as normalizeRequestId, i as isNodeBuiltin, b as toFilePath } from './chunk-vite-node-utils.7e46948f.mjs';
6
- import { d as distDir } from './chunk-constants.16825f0c.mjs';
5
+ import { n as normalizeRequestId, i as isNodeBuiltin, b as toFilePath } from './chunk-vite-node-utils.d8e5ff7b.mjs';
6
+ import { d as distDir } from './chunk-constants.d3f8437b.mjs';
7
7
  import { g as getWorkerState } from './chunk-utils-global.fa20c2f6.mjs';
8
8
 
9
9
  class RefTracker {
@@ -78,8 +78,22 @@ const _VitestMocker = class {
78
78
  if (cached)
79
79
  return cached;
80
80
  const exports = await mock();
81
+ if (exports === null || typeof exports !== "object")
82
+ throw new Error('[vitest] vi.mock(path: string, factory?: () => unknown) is not returning an object. Did you mean to return an object with a "default" key?');
81
83
  this.moduleCache.set(dep, { exports });
82
- return exports;
84
+ const exportHandler = {
85
+ get(target, prop) {
86
+ const val = target[prop];
87
+ if (prop === "then") {
88
+ if (target instanceof Promise)
89
+ return target.then.bind(target);
90
+ } else if (!(prop in target)) {
91
+ throw new Error(`[vitest] No "${prop}" export is defined on the "${dep}"`);
92
+ }
93
+ return val;
94
+ }
95
+ };
96
+ return new Proxy(exports, exportHandler);
83
97
  }
84
98
  getMockPath(dep) {
85
99
  return `mock:${dep}`;
@@ -123,13 +137,20 @@ const _VitestMocker = class {
123
137
  const spyModule = _VitestMocker.spyModule;
124
138
  const finalizers = new Array();
125
139
  const refs = new RefTracker();
140
+ const define = (container, key, value) => {
141
+ try {
142
+ container[key] = value;
143
+ return true;
144
+ } catch {
145
+ return false;
146
+ }
147
+ };
126
148
  const mockPropertiesOf = (container, newContainer) => {
127
149
  const containerType = getType(container);
128
150
  const isModule = containerType === "Module" || !!container.__esModule;
129
- for (const property of getAllProperties(container)) {
151
+ for (const { key: property, descriptor } of getAllMockableProperties(container)) {
130
152
  if (!isModule) {
131
- const descriptor = Object.getOwnPropertyDescriptor(container, property);
132
- if ((descriptor == null ? void 0 : descriptor.get) || (descriptor == null ? void 0 : descriptor.set))
153
+ if (descriptor.get || descriptor.set)
133
154
  continue;
134
155
  }
135
156
  if (isSpecialProp(property, containerType))
@@ -137,20 +158,21 @@ const _VitestMocker = class {
137
158
  const value = container[property];
138
159
  const refId = refs.getId(value);
139
160
  if (refId) {
140
- finalizers.push(() => newContainer[property] = refs.getMockedValue(refId));
161
+ finalizers.push(() => define(newContainer, property, refs.getMockedValue(refId)));
141
162
  continue;
142
163
  }
143
164
  const type = getType(value);
144
165
  if (Array.isArray(value)) {
145
- newContainer[property] = [];
166
+ define(newContainer, property, []);
146
167
  continue;
147
168
  }
148
169
  const isFunction = type.includes("Function") && typeof value === "function";
149
170
  if ((!isFunction || value.__isMockFunction) && type !== "Object" && type !== "Module") {
150
- newContainer[property] = value;
171
+ define(newContainer, property, value);
151
172
  continue;
152
173
  }
153
- newContainer[property] = isFunction ? value : {};
174
+ if (!define(newContainer, property, isFunction ? value : {}))
175
+ continue;
154
176
  if (isFunction) {
155
177
  spyModule.spyOn(newContainer, property).mockImplementation(() => void 0);
156
178
  Object.defineProperty(newContainer[property], "length", { value: 0 });
@@ -1,4 +1,4 @@
1
- import './chunk-mock-date.9160e13b.mjs';
1
+ import './chunk-mock-date.debe9954.mjs';
2
2
  import { g as getWorkerState } from './chunk-utils-global.fa20c2f6.mjs';
3
3
  import { w as withSafeTimers } from './chunk-utils-timers.b48455ed.mjs';
4
4
 
@@ -1,4 +1,5 @@
1
- import { s as slash, f as notNullish, p as picocolors } from './chunk-mock-date.9160e13b.mjs';
1
+ import { s as slash, f as notNullish } from './chunk-mock-date.debe9954.mjs';
2
+ import { p as picocolors } from './vendor-picocolors.807856aa.mjs';
2
3
 
3
4
  var build = {};
4
5
 
@@ -1,8 +1,8 @@
1
1
  import { createRequire } from 'module';
2
2
  import { pathToFileURL, fileURLToPath } from 'url';
3
3
  import vm from 'vm';
4
- import { y as resolve, d as dirname, B as isAbsolute, L as extname } from './chunk-mock-date.9160e13b.mjs';
5
- import { s as slash, n as normalizeRequestId, b as toFilePath, i as isNodeBuiltin, c as isPrimitive, d as normalizeModuleId, m as mergeSlashes } from './chunk-vite-node-utils.7e46948f.mjs';
4
+ import { x as resolve, d as dirname, z as isAbsolute, K as extname } from './chunk-mock-date.debe9954.mjs';
5
+ import { s as slash, n as normalizeRequestId, b as toFilePath, i as isNodeBuiltin, c as isPrimitive, d as normalizeModuleId, m as mergeSlashes } from './chunk-vite-node-utils.d8e5ff7b.mjs';
6
6
  import createDebug from 'debug';
7
7
 
8
8
  const debugExecute = createDebug("vite-node:client:execute");
@@ -141,7 +141,11 @@ ${getStack()}`), 2e3);
141
141
  const url = pathToFileURL(fsPath).href;
142
142
  const meta = { url };
143
143
  const exports = /* @__PURE__ */ Object.create(null);
144
- exports[Symbol.toStringTag] = "Module";
144
+ Object.defineProperty(exports, Symbol.toStringTag, {
145
+ value: "Module",
146
+ enumerable: false,
147
+ configurable: false
148
+ });
145
149
  this.moduleCache.set(fsPath, { code: transformed, exports });
146
150
  const __filename = fileURLToPath(url);
147
151
  const moduleProxy = {
@@ -1,8 +1,9 @@
1
1
  import { existsSync, promises } from 'fs';
2
- import { y as resolve, p as picocolors, j as join } from './chunk-mock-date.9160e13b.mjs';
2
+ import { x as resolve, j as join } from './chunk-mock-date.debe9954.mjs';
3
+ import { p as picocolors } from './vendor-picocolors.807856aa.mjs';
3
4
  import 'path';
4
- import 'tty';
5
5
  import 'local-pkg';
6
+ import 'tty';
6
7
 
7
8
  function hashCode(s) {
8
9
  return s.split("").reduce((a, b) => {
@@ -1,32 +1,34 @@
1
- import { j as join, z as basename, d as dirname, y as resolve, A as AggregateErrorPonyfill, p as picocolors, B as isAbsolute, C as relative, s as slash$2, l as isNode, o as relativePath, D as getTests, e as getFullName, x as hasFailed, E as hasFailedSnapshot, F as getSuites, v as shuffle, t as toArray$1, G as normalize, n as noop$1, H as deepMerge, I as toNamespacedPath, g as getCallLastIndex, f as notNullish, J as ensurePackageInstalled, K as stdout } from './chunk-mock-date.9160e13b.mjs';
2
- import { p as pLimit, c as configDefaults, r as resolveC8Options, a as cleanCoverage, b as reportCoverage, d as envPackageNames } from './chunk-defaults.6698a2d3.mjs';
1
+ import { x as resolve, j as join, y as basename, d as dirname, A as AggregateErrorPonyfill, z as isAbsolute, B as relative, s as slash$2, l as isNode, o as relativePath, C as getTests, e as getFullName, w as hasFailed, D as hasFailedSnapshot, E as getSuites, u as shuffle, t as toArray$1, F as normalize, n as noop$1, G as deepMerge, H as toNamespacedPath, g as getCallLastIndex, f as notNullish, I as ensurePackageInstalled, J as stdout } from './chunk-mock-date.debe9954.mjs';
2
+ import { p as pLimit, g as getCoverageProvider, a as envPackageNames, C as CoverageProviderMap } from './chunk-integrations-coverage.d205bd87.mjs';
3
3
  import { loadConfigFromFile, createServer, mergeConfig } from 'vite';
4
4
  import path$a from 'path';
5
- import _url, { fileURLToPath } from 'url';
5
+ import url, { fileURLToPath } from 'url';
6
6
  import process$1 from 'process';
7
7
  import fs$8, { promises, existsSync, readFileSync } from 'fs';
8
- import { d as distDir, r as rootDir, c as configFiles, a as defaultPort } from './chunk-constants.16825f0c.mjs';
8
+ import { d as distDir, r as rootDir, c as configFiles, a as defaultPort } from './chunk-constants.d3f8437b.mjs';
9
9
  import require$$0, { cpus, hostname } from 'os';
10
10
  import util$2 from 'util';
11
11
  import require$$0$1 from 'stream';
12
12
  import require$$2 from 'events';
13
13
  import { c as commonjsGlobal } from './vendor-_commonjsHelpers.4da45ef5.mjs';
14
- import { c as createBirpc, V as ViteNodeRunner } from './chunk-vite-node-client.115caed2.mjs';
14
+ import { p as picocolors } from './vendor-picocolors.807856aa.mjs';
15
+ import { c as createBirpc, V as ViteNodeRunner } from './chunk-vite-node-client.d1ead698.mjs';
15
16
  import createDebug from 'debug';
16
- import { i as isNodeBuiltin, a as isValidNodeImport, s as slash$1, t as toArray, b as toFilePath, w as withInlineSourcemap } from './chunk-vite-node-utils.7e46948f.mjs';
17
+ import { i as isNodeBuiltin, a as isValidNodeImport, s as slash$1, t as toArray, b as toFilePath, w as withInlineSourcemap } from './chunk-vite-node-utils.d8e5ff7b.mjs';
17
18
  import { MessageChannel } from 'worker_threads';
18
19
  import { Tinypool } from 'tinypool';
19
20
  import { performance } from 'perf_hooks';
20
- import { c as stripAnsi, d as cliTruncate, p as parseStacktrace, e as stringWidth, h as ansiStyles, i as sliceAnsi, j as interpretSourcePos, s as stringify$5, u as unifiedDiff, b as posToNumber, l as lineSplitRE } from './chunk-utils-source-map.8198ebd9.mjs';
21
+ import { c as stripAnsi, d as cliTruncate, p as parseStacktrace, e as stringWidth, h as ansiStyles, i as sliceAnsi, j as interpretSourcePos, s as stringify$5, u as unifiedDiff, b as posToNumber, l as lineSplitRE } from './chunk-utils-source-map.2a082ffd.mjs';
21
22
  import { b as safeSetInterval, c as safeClearInterval, s as safeSetTimeout, a as safeClearTimeout } from './chunk-utils-timers.b48455ed.mjs';
22
23
  import { resolveModule } from 'local-pkg';
23
24
  import { createHash } from 'crypto';
24
- import { o as onetime, s as signalExit } from './vendor-index.61438b77.mjs';
25
+ import { o as onetime } from './vendor-index.9d9196cc.mjs';
26
+ import { s as signalExit } from './vendor-index.29636037.mjs';
25
27
  import MagicString from './chunk-magic-string.efe26975.mjs';
26
28
  import require$$0$2 from 'readline';
27
- import { p as prompts } from './vendor-index.de788b6a.mjs';
29
+ import { p as prompts } from './vendor-index.ae96af6e.mjs';
28
30
 
29
- var version$1 = "0.20.3";
31
+ var version$1 = "0.22.0";
30
32
 
31
33
  class EndError extends Error {
32
34
  constructor(value) {
@@ -6850,14 +6852,14 @@ class ViteNodeServer {
6850
6852
  }, options.debug ?? {});
6851
6853
  }
6852
6854
  if (options.debug)
6853
- import('./chunk-vite-node-debug.c5887932.mjs').then((r) => this.debugger = new r.Debugger(server.config.root, options.debug));
6855
+ import('./chunk-vite-node-debug.ff1d2a9f.mjs').then((r) => this.debugger = new r.Debugger(server.config.root, options.debug));
6854
6856
  }
6855
6857
  shouldExternalize(id) {
6856
6858
  return shouldExternalize(id, this.options.deps, this.externalizeCache);
6857
6859
  }
6858
6860
  async resolveId(id, importer) {
6859
6861
  if (importer && !importer.startsWith(this.server.config.root))
6860
- importer = join(this.server.config.root, importer);
6862
+ importer = resolve(this.server.config.root, importer);
6861
6863
  const mode = importer && this.getTransformMode(importer) || "ssr";
6862
6864
  return this.server.pluginContainer.resolveId(id, importer, { ssr: mode === "ssr" });
6863
6865
  }
@@ -7000,11 +7002,11 @@ function addSnapshotResult(summary, result) {
7000
7002
  summary.total += result.added + result.matched + result.unmatched + result.updated;
7001
7003
  }
7002
7004
 
7003
- const workerPath = _url.pathToFileURL(resolve(distDir, "./worker.mjs")).href;
7004
- const loaderPath = _url.pathToFileURL(resolve(distDir, "./loader.mjs")).href;
7005
+ const workerPath = url.pathToFileURL(resolve(distDir, "./worker.mjs")).href;
7006
+ const loaderPath = url.pathToFileURL(resolve(distDir, "./loader.mjs")).href;
7005
7007
  const suppressLoaderWarningsPath = resolve(rootDir, "./suppress-warnings.cjs");
7006
7008
  function createPool(ctx) {
7007
- var _a, _b;
7009
+ var _a, _b, _c;
7008
7010
  const threadsCount = ctx.config.watch ? Math.max(Math.floor(cpus().length / 2), 1) : Math.max(cpus().length - 1, 1);
7009
7011
  const maxThreads = ctx.config.maxThreads ?? threadsCount;
7010
7012
  const minThreads = ctx.config.minThreads ?? threadsCount;
@@ -7031,8 +7033,7 @@ function createPool(ctx) {
7031
7033
  options.maxThreads = 1;
7032
7034
  options.minThreads = 1;
7033
7035
  }
7034
- if (ctx.config.coverage.enabled)
7035
- (_b = process.env).NODE_V8_COVERAGE || (_b.NODE_V8_COVERAGE = ctx.config.coverage.tempDirectory);
7036
+ (_c = (_b = ctx.coverageProvider) == null ? void 0 : _b.onBeforeFilesRun) == null ? void 0 : _c.call(_b);
7036
7037
  options.env = {
7037
7038
  TEST: "true",
7038
7039
  VITEST: "true",
@@ -7122,6 +7123,10 @@ function createChannel(ctx) {
7122
7123
  ctx.state.collectFiles(files);
7123
7124
  ctx.report("onCollected", files);
7124
7125
  },
7126
+ onAfterSuiteRun(meta) {
7127
+ var _a;
7128
+ (_a = ctx.coverageProvider) == null ? void 0 : _a.onAfterSuiteRun(meta);
7129
+ },
7125
7130
  onTaskUpdate(packs) {
7126
7131
  ctx.state.updateTasks(packs);
7127
7132
  ctx.report("onTaskUpdate", packs);
@@ -7977,7 +7982,7 @@ function tapString(str) {
7977
7982
  class TapReporter {
7978
7983
  onInit(ctx) {
7979
7984
  this.ctx = ctx;
7980
- this.logger = new IndentedLogger(this.ctx.logger.log.bind(this.ctx));
7985
+ this.logger = new IndentedLogger(ctx.logger.log.bind(ctx.logger));
7981
7986
  }
7982
7987
  static getComment(task) {
7983
7988
  var _a;
@@ -8065,7 +8070,8 @@ function escapeXML(value) {
8065
8070
  }
8066
8071
  function getDuration(task) {
8067
8072
  var _a;
8068
- return ((_a = task.result) == null ? void 0 : _a.duration) ? (task.result.duration / 1e3).toFixed(10) : void 0;
8073
+ const duration = ((_a = task.result) == null ? void 0 : _a.duration) ?? 0;
8074
+ return (duration / 1e3).toLocaleString(void 0, { useGrouping: false, maximumFractionDigits: 10 });
8069
8075
  }
8070
8076
  class JUnitReporter {
8071
8077
  async onInit(ctx) {
@@ -8250,6 +8256,11 @@ function createReporters(reporterReferences, runner) {
8250
8256
  return Promise.all(promisedReporters);
8251
8257
  }
8252
8258
 
8259
+ const isAggregateError = (err) => {
8260
+ if (typeof AggregateError !== "undefined" && err instanceof AggregateError)
8261
+ return true;
8262
+ return err instanceof Error && "errors" in err;
8263
+ };
8253
8264
  class StateManager {
8254
8265
  constructor() {
8255
8266
  this.filesMap = /* @__PURE__ */ new Map();
@@ -8260,6 +8271,8 @@ class StateManager {
8260
8271
  this.errorsSet = /* @__PURE__ */ new Set();
8261
8272
  }
8262
8273
  catchError(err, type) {
8274
+ if (isAggregateError(err))
8275
+ return err.errors.forEach((error) => this.catchError(error, type));
8263
8276
  err.type = type;
8264
8277
  this.errorsSet.add(err);
8265
8278
  }
@@ -8342,6 +8355,85 @@ class StateManager {
8342
8355
  }
8343
8356
  }
8344
8357
 
8358
+ const defaultInclude = ["**/*.{test,spec}.{js,mjs,cjs,ts,mts,cts,jsx,tsx}"];
8359
+ const defaultExclude = ["**/node_modules/**", "**/dist/**", "**/cypress/**", "**/.{idea,git,cache,output,temp}/**"];
8360
+ const defaultCoverageExcludes = [
8361
+ "coverage/**",
8362
+ "dist/**",
8363
+ "packages/*/test{,s}/**",
8364
+ "**/*.d.ts",
8365
+ "cypress/**",
8366
+ "test{,s}/**",
8367
+ "test{,-*}.{js,cjs,mjs,ts,tsx,jsx}",
8368
+ "**/*{.,-}test.{js,cjs,mjs,ts,tsx,jsx}",
8369
+ "**/*{.,-}spec.{js,cjs,mjs,ts,tsx,jsx}",
8370
+ "**/__tests__/**",
8371
+ "**/{karma,rollup,webpack,vite,vitest,jest,ava,babel,nyc,cypress}.config.{js,cjs,mjs,ts}",
8372
+ "**/.{eslint,mocha,prettier}rc.{js,cjs,yml}"
8373
+ ];
8374
+ const coverageConfigDefaults = {
8375
+ provider: "c8",
8376
+ enabled: false,
8377
+ clean: true,
8378
+ cleanOnRerun: false,
8379
+ reportsDirectory: "./coverage",
8380
+ excludeNodeModules: true,
8381
+ exclude: defaultCoverageExcludes,
8382
+ reporter: ["text", "html", "clover"],
8383
+ allowExternal: false,
8384
+ extension: [".js", ".cjs", ".mjs", ".ts", ".tsx", ".jsx", ".vue", ".svelte"]
8385
+ };
8386
+ const fakeTimersDefaults = {
8387
+ loopLimit: 1e4,
8388
+ shouldClearNativeTimers: true,
8389
+ toFake: [
8390
+ "setTimeout",
8391
+ "clearTimeout",
8392
+ "setInterval",
8393
+ "clearInterval",
8394
+ "setImmediate",
8395
+ "clearImmediate",
8396
+ "Date"
8397
+ ]
8398
+ };
8399
+ const config = {
8400
+ allowOnly: !process.env.CI,
8401
+ watch: !process.env.CI,
8402
+ globals: false,
8403
+ environment: "node",
8404
+ threads: true,
8405
+ clearMocks: false,
8406
+ restoreMocks: false,
8407
+ mockReset: false,
8408
+ include: defaultInclude,
8409
+ exclude: defaultExclude,
8410
+ testTimeout: 5e3,
8411
+ hookTimeout: 1e4,
8412
+ teardownTimeout: 1e3,
8413
+ isolate: true,
8414
+ watchExclude: ["**/node_modules/**", "**/dist/**"],
8415
+ forceRerunTriggers: [
8416
+ "**/package.json/**",
8417
+ "**/vitest.config.*/**",
8418
+ "**/vite.config.*/**"
8419
+ ],
8420
+ update: false,
8421
+ reporters: [],
8422
+ silent: false,
8423
+ api: false,
8424
+ ui: false,
8425
+ uiBase: "/__vitest__/",
8426
+ open: true,
8427
+ css: {
8428
+ include: [/\.module\./]
8429
+ },
8430
+ coverage: coverageConfigDefaults,
8431
+ fakeTimers: fakeTimersDefaults,
8432
+ maxConcurrency: 5,
8433
+ dangerouslyIgnoreUnhandledErrors: false
8434
+ };
8435
+ const configDefaults = Object.freeze(config);
8436
+
8345
8437
  class FilesStatsCache {
8346
8438
  constructor() {
8347
8439
  this.cache = /* @__PURE__ */ new Map();
@@ -8550,7 +8642,6 @@ function resolveConfig(options, viteConfig) {
8550
8642
  };
8551
8643
  if (viteConfig.base !== "/")
8552
8644
  resolved.base = viteConfig.base;
8553
- resolved.coverage = resolveC8Options(options.coverage || {}, resolved.root);
8554
8645
  if (options.shard) {
8555
8646
  if (resolved.watch)
8556
8647
  throw new Error("You cannot use --shard option with enabled watch");
@@ -8573,7 +8664,7 @@ function resolveConfig(options, viteConfig) {
8573
8664
  resolved.deps.inline.push(...extraInlineDeps);
8574
8665
  }
8575
8666
  }
8576
- (_c = resolved.deps).registerNodeLoader ?? (_c.registerNodeLoader = typeof process.versions.pnp === "undefined");
8667
+ (_c = resolved.deps).registerNodeLoader ?? (_c.registerNodeLoader = false);
8577
8668
  resolved.testNamePattern = resolved.testNamePattern ? resolved.testNamePattern instanceof RegExp ? resolved.testNamePattern : new RegExp(resolved.testNamePattern) : void 0;
8578
8669
  const CI = !!process.env.CI;
8579
8670
  const UPDATE_SNAPSHOT = resolved.update || process.env.UPDATE_SNAPSHOT;
@@ -9099,7 +9190,7 @@ createLogUpdate(process$1.stdout);
9099
9190
 
9100
9191
  createLogUpdate(process$1.stderr);
9101
9192
 
9102
- var version = "0.20.3";
9193
+ var version = "0.22.0";
9103
9194
 
9104
9195
  function fileFromParsedStack(stack) {
9105
9196
  var _a, _b;
@@ -9342,12 +9433,14 @@ class Logger {
9342
9433
  this.log(picocolors.exports.dim(picocolors.exports.green(` UI started at http://${((_b = this.ctx.config.api) == null ? void 0 : _b.host) || "localhost"}:${picocolors.exports.bold(`${this.ctx.server.config.server.port}`)}${this.ctx.config.uiBase}`)));
9343
9434
  else if (this.ctx.config.api)
9344
9435
  this.log(picocolors.exports.dim(picocolors.exports.green(` API started at http://${((_c = this.ctx.config.api) == null ? void 0 : _c.host) || "localhost"}:${picocolors.exports.bold(`${this.ctx.config.api.port}`)}`)));
9436
+ if (this.ctx.coverageProvider)
9437
+ this.log(picocolors.exports.dim(" Coverage enabled with ") + picocolors.exports.yellow(this.ctx.coverageProvider.name));
9345
9438
  this.log();
9346
9439
  }
9347
9440
  async printUnhandledErrors(errors) {
9348
9441
  const errorMessage = picocolors.exports.red(picocolors.exports.bold(`
9349
- Vitest caught ${errors.length} unhandled error${errors.length > 1 ? "s" : ""} during the test run. This might cause false positive tests.
9350
- Please, resolve all the errors to make sure your tests are not affected.`));
9442
+ Vitest caught ${errors.length} unhandled error${errors.length > 1 ? "s" : ""} during the test run.
9443
+ This might cause false positive tests. Resolve unhandled errors to make sure your tests are not affected.`));
9351
9444
  this.log(picocolors.exports.red(divider(picocolors.exports.bold(picocolors.exports.inverse(" Unhandled Errors ")))));
9352
9445
  this.log(errorMessage);
9353
9446
  await Promise.all(errors.map(async (err) => {
@@ -9377,7 +9470,7 @@ class Vitest {
9377
9470
  this.logger = new Logger(this);
9378
9471
  }
9379
9472
  async setServer(options, server) {
9380
- var _a, _b;
9473
+ var _a, _b, _c;
9381
9474
  (_a = this.unregisterWatcher) == null ? void 0 : _a.call(this);
9382
9475
  safeClearTimeout(this._rerunTimer);
9383
9476
  this.restartsCount += 1;
@@ -9406,8 +9499,7 @@ class Vitest {
9406
9499
  this.reporters = await createReporters(resolved.reporters, this.runner);
9407
9500
  this.runningPromise = void 0;
9408
9501
  this._onRestartListeners.forEach((fn) => fn());
9409
- if (resolved.coverage.enabled)
9410
- await cleanCoverage(resolved.coverage, resolved.coverage.clean);
9502
+ await ((_c = this.coverageProvider) == null ? void 0 : _c.clean(this.config.coverage.clean));
9411
9503
  this.cache.results.setConfig(resolved.root, resolved.cache);
9412
9504
  try {
9413
9505
  await this.cache.results.readFromCache();
@@ -9415,6 +9507,16 @@ class Vitest {
9415
9507
  this.logger.error(`[vitest] Error, while trying to parse cache in ${this.cache.results.getCachePath()}:`, err);
9416
9508
  }
9417
9509
  }
9510
+ async initCoverageProvider() {
9511
+ if (this.coverageProvider !== void 0)
9512
+ return;
9513
+ this.coverageProvider = await getCoverageProvider(this.config.coverage);
9514
+ if (this.coverageProvider) {
9515
+ await this.coverageProvider.initialize(this);
9516
+ this.config.coverage = this.coverageProvider.resolveOptions();
9517
+ }
9518
+ return this.coverageProvider;
9519
+ }
9418
9520
  getSerializableConfig() {
9419
9521
  return deepMerge({
9420
9522
  ...this.config,
@@ -9431,6 +9533,12 @@ class Vitest {
9431
9533
  }, this.configOverride || {});
9432
9534
  }
9433
9535
  async start(filters) {
9536
+ try {
9537
+ await this.initCoverageProvider();
9538
+ } catch (e) {
9539
+ this.logger.error(e);
9540
+ process.exit(1);
9541
+ }
9434
9542
  await this.report("onInit", this);
9435
9543
  const files = await this.filterTestsBySource(await this.globTestFiles(filters));
9436
9544
  if (!files.length) {
@@ -9440,8 +9548,10 @@ class Vitest {
9440
9548
  }
9441
9549
  await Promise.all(files.map((file) => this.cache.stats.updateStats(file)));
9442
9550
  await this.runFiles(files);
9443
- if (this.config.coverage.enabled)
9444
- await reportCoverage(this);
9551
+ if (this.coverageProvider) {
9552
+ this.logger.log(picocolors.exports.blue(" % ") + picocolors.exports.dim("Coverage report from ") + picocolors.exports.yellow(this.coverageProvider.name));
9553
+ await this.coverageProvider.reportCoverage();
9554
+ }
9445
9555
  if (this.config.watch && !this.config.browser)
9446
9556
  await this.report("onWatcherStart");
9447
9557
  }
@@ -9466,7 +9576,7 @@ class Vitest {
9466
9576
  }
9467
9577
  async filterTestsBySource(tests) {
9468
9578
  if (this.config.changed && !this.config.related) {
9469
- const { VitestGit } = await import('./chunk-node-git.43dbdd42.mjs');
9579
+ const { VitestGit } = await import('./chunk-node-git.71b74da4.mjs');
9470
9580
  const vitestGit = new VitestGit(this.config.root);
9471
9581
  const related2 = await vitestGit.findChangedFiles({
9472
9582
  changedSince: this.config.changed
@@ -9561,6 +9671,7 @@ class Vitest {
9561
9671
  if (this.restartsCount !== currentCount)
9562
9672
  return;
9563
9673
  this._rerunTimer = safeSetTimeout(async () => {
9674
+ var _a;
9564
9675
  if (this.changedTests.size === 0) {
9565
9676
  this.invalidates.clear();
9566
9677
  return;
@@ -9571,12 +9682,11 @@ class Vitest {
9571
9682
  this.snapshot.clear();
9572
9683
  const files = Array.from(this.changedTests);
9573
9684
  this.changedTests.clear();
9574
- if (this.config.coverage.enabled && this.config.coverage.cleanOnRerun)
9575
- await cleanCoverage(this.config.coverage);
9685
+ if (this.coverageProvider && this.config.coverage.cleanOnRerun)
9686
+ await this.coverageProvider.clean();
9576
9687
  await this.report("onWatcherRerun", files, triggerId);
9577
9688
  await this.runFiles(files);
9578
- if (this.config.coverage.enabled)
9579
- await reportCoverage(this);
9689
+ await ((_a = this.coverageProvider) == null ? void 0 : _a.reportCoverage());
9580
9690
  if (!this.config.browser)
9581
9691
  await this.report("onWatcherStart");
9582
9692
  }, WATCHER_DEBOUNCE);
@@ -9952,6 +10062,16 @@ function CSSEnablerPlugin(ctx) {
9952
10062
  };
9953
10063
  }
9954
10064
 
10065
+ function CoverageTransform(ctx) {
10066
+ return {
10067
+ name: "vitest:coverage-transform",
10068
+ transform(srcCode, id) {
10069
+ var _a, _b;
10070
+ return (_b = (_a = ctx.coverageProvider) == null ? void 0 : _a.onFileTransform) == null ? void 0 : _b.call(_a, srcCode, id, this);
10071
+ }
10072
+ };
10073
+ }
10074
+
9955
10075
  async function VitestPlugin(options = {}, ctx = new Vitest()) {
9956
10076
  let haveStarted = false;
9957
10077
  async function UIPlugin() {
@@ -9968,6 +10088,9 @@ async function VitestPlugin(options = {}, ctx = new Vitest()) {
9968
10088
  {
9969
10089
  name: "vitest",
9970
10090
  enforce: "pre",
10091
+ options() {
10092
+ this.meta.watchMode = false;
10093
+ },
9971
10094
  config(viteConfig) {
9972
10095
  const preOptions = deepMerge({}, configDefaults, options, viteConfig.test ?? {});
9973
10096
  preOptions.api = resolveApiConfig(preOptions);
@@ -10052,7 +10175,7 @@ async function VitestPlugin(options = {}, ctx = new Vitest()) {
10052
10175
  await ctx.setServer(options, server);
10053
10176
  haveStarted = true;
10054
10177
  if (options.api && options.watch)
10055
- (await import('./chunk-api-setup.9bff74bb.mjs')).setup(ctx);
10178
+ (await import('./chunk-api-setup.ecd02c18.mjs')).setup(ctx);
10056
10179
  } catch (err) {
10057
10180
  ctx.logger.printError(err, true);
10058
10181
  process.exit(1);
@@ -10066,6 +10189,7 @@ async function VitestPlugin(options = {}, ctx = new Vitest()) {
10066
10189
  GlobalSetupPlugin(ctx),
10067
10190
  ...options.browser ? await BrowserPlugin() : [],
10068
10191
  CSSEnablerPlugin(ctx),
10192
+ CoverageTransform(ctx),
10069
10193
  options.ui ? await UIPlugin() : null
10070
10194
  ].filter(notNullish);
10071
10195
  }
@@ -10114,7 +10238,7 @@ function registerConsoleShortcuts(ctx) {
10114
10238
  if (name === "u")
10115
10239
  return ctx.updateSnapshot();
10116
10240
  if (name === "a" || name === "return")
10117
- return ctx.rerunFiles(void 0);
10241
+ return ctx.changeNamePattern("");
10118
10242
  if (name === "f")
10119
10243
  return ctx.rerunFailed();
10120
10244
  if (name === "t")
@@ -10173,9 +10297,13 @@ async function startVitest(cliFilters, options, viteOverrides) {
10173
10297
  options.coverage = { enabled: options.coverage };
10174
10298
  const ctx = await createVitest(options, viteOverrides);
10175
10299
  if (ctx.config.coverage.enabled) {
10176
- if (!await ensurePackageInstalled("c8", root)) {
10177
- process.exitCode = 1;
10178
- return false;
10300
+ const provider = ctx.config.coverage.provider || "c8";
10301
+ if (typeof provider === "string") {
10302
+ const requiredPackages = CoverageProviderMap[provider];
10303
+ if (!await ensurePackageInstalled(requiredPackages, root)) {
10304
+ process.exitCode = 1;
10305
+ return false;
10306
+ }
10179
10307
  }
10180
10308
  }
10181
10309
  if (ctx.config.environment && ctx.config.environment !== "node") {