vitest 0.21.0 → 0.22.1

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 (45) hide show
  1. package/LICENSE.md +61 -4
  2. package/dist/browser.d.ts +4 -5
  3. package/dist/browser.mjs +9 -9
  4. package/dist/{chunk-api-setup.89eb0e7a.mjs → chunk-api-setup.377c28aa.mjs} +9 -9
  5. package/dist/chunk-constants.71e8a211.mjs +284 -0
  6. package/dist/{chunk-install-pkg.6c6dc0c2.mjs → chunk-install-pkg.3aa3eae6.mjs} +3 -2
  7. package/dist/{chunk-defaults.8390340d.mjs → chunk-integrations-coverage.d205bd87.mjs} +23 -152
  8. package/dist/{chunk-integrations-globals.a798d352.mjs → chunk-integrations-globals.60af7da3.mjs} +8 -8
  9. package/dist/{chunk-mock-date.ea3b3121.mjs → chunk-mock-date.304e29b1.mjs} +11 -255
  10. package/dist/chunk-node-git.9a7e3153.mjs +78 -0
  11. package/dist/{chunk-runtime-chain.44b4224d.mjs → chunk-runtime-chain.be610650.mjs} +4 -3
  12. package/dist/{chunk-runtime-error.95e53764.mjs → chunk-runtime-error.1104e45a.mjs} +13 -12
  13. package/dist/{chunk-runtime-hooks.291644ec.mjs → chunk-runtime-hooks.5d7073db.mjs} +3 -3
  14. package/dist/{chunk-runtime-mocker.6190d6a3.mjs → chunk-runtime-mocker.49d21aa6.mjs} +19 -5
  15. package/dist/{chunk-runtime-rpc.fc50dcc0.mjs → chunk-runtime-rpc.57586b73.mjs} +1 -1
  16. package/dist/{chunk-utils-source-map.d307e4ea.mjs → chunk-utils-source-map.bbf3ad19.mjs} +2 -1
  17. package/dist/{chunk-vite-node-client.b59ba135.mjs → chunk-vite-node-client.cddda63d.mjs} +49 -21
  18. package/dist/{chunk-vite-node-debug.dbce2e1f.mjs → chunk-vite-node-debug.536c4c5b.mjs} +3 -3
  19. package/dist/{chunk-vite-node-externalize.80bed9b3.mjs → chunk-vite-node-externalize.c843f497.mjs} +186 -50
  20. package/dist/chunk-vite-node-utils.b432150c.mjs +6921 -0
  21. package/dist/cli-wrapper.mjs +124 -0
  22. package/dist/cli.mjs +16 -15
  23. package/dist/config.cjs +3 -0
  24. package/dist/config.d.ts +6 -3
  25. package/dist/config.mjs +2 -1
  26. package/dist/entry.mjs +9 -9
  27. package/dist/{global-644546f7.d.ts → global-fe52f84b.d.ts} +512 -177
  28. package/dist/{index-3f764034.d.ts → index-ea17aa0c.d.ts} +4 -52
  29. package/dist/index.d.ts +5 -6
  30. package/dist/index.mjs +7 -5
  31. package/dist/loader.mjs +4 -3
  32. package/dist/node.d.ts +3 -3
  33. package/dist/node.mjs +16 -15
  34. package/dist/suite.mjs +6 -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.e0dc0a7e.mjs → vendor-index.fbec8a81.mjs} +5 -73
  40. package/dist/worker.mjs +9 -9
  41. package/package.json +9 -13
  42. package/vitest.mjs +1 -1
  43. package/dist/chunk-constants.9da1ef26.mjs +0 -38
  44. package/dist/chunk-vite-node-utils.96438e82.mjs +0 -1114
  45. package/dist/mocker-5e2a8e41.d.ts +0 -3
@@ -1,32 +1,33 @@
1
- import { y as resolve, j as join, z as basename, d as dirname, 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.ea3b3121.mjs';
2
- import { p as pLimit, c as configDefaults, r as resolveC8Options, a as cleanCoverage, b as reportCoverage, d as envPackageNames } from './chunk-defaults.8390340d.mjs';
3
- import { loadConfigFromFile, createServer, mergeConfig } from 'vite';
1
+ import { a as resolve, j as join, b as basename, d as dirname, c as distDir, e as rootDir, p as picocolors, i as isAbsolute, r as relative, f as configFiles, g as defaultPort, n as normalize, t as toNamespacedPath, E as EXIT_CODE_RESTART } from './chunk-constants.71e8a211.mjs';
2
+ import { p as pLimit, g as getCoverageProvider, a as envPackageNames, C as CoverageProviderMap } from './chunk-integrations-coverage.d205bd87.mjs';
3
+ import { A as AggregateErrorPonyfill, s as slash$2, j as isNode, k as relativePath, v as getTests, d as getFullName, u as hasFailed, w as hasFailedSnapshot, x as getSuites, o as shuffle, t as toArray$1, n as noop$1, y as deepMerge, g as getCallLastIndex, e as notNullish, z as ensurePackageInstalled, B as stdout } from './chunk-mock-date.304e29b1.mjs';
4
+ import { loadConfigFromFile, normalizePath, createServer, mergeConfig } from 'vite';
4
5
  import path$a from 'path';
5
- import _url, { fileURLToPath } from 'url';
6
+ import url, { fileURLToPath } from 'url';
6
7
  import process$1 from 'process';
7
8
  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.9da1ef26.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.b59ba135.mjs';
14
+ import { c as createBirpc, V as ViteNodeRunner } from './chunk-vite-node-client.cddda63d.mjs';
15
+ import { performance } from 'perf_hooks';
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.96438e82.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.b432150c.mjs';
17
18
  import { MessageChannel } from 'worker_threads';
18
19
  import { Tinypool } from 'tinypool';
19
- 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.d307e4ea.mjs';
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.bbf3ad19.mjs';
21
21
  import { b as safeSetInterval, c as safeClearInterval, s as safeSetTimeout, a as safeClearTimeout } from './chunk-utils-timers.b48455ed.mjs';
22
22
  import { resolveModule } from 'local-pkg';
23
23
  import { createHash } from 'crypto';
24
- import { o as onetime, s as signalExit } from './vendor-index.61438b77.mjs';
24
+ import { o as onetime } from './vendor-index.9d9196cc.mjs';
25
+ import { s as signalExit } from './vendor-index.29636037.mjs';
25
26
  import MagicString from './chunk-magic-string.efe26975.mjs';
26
27
  import require$$0$2 from 'readline';
27
- import { p as prompts } from './vendor-index.de788b6a.mjs';
28
+ import { p as prompts } from './vendor-index.ae96af6e.mjs';
28
29
 
29
- var version$1 = "0.21.0";
30
+ var version$1 = "0.22.1";
30
31
 
31
32
  class EndError extends Error {
32
33
  constructor(value) {
@@ -6850,7 +6851,7 @@ class ViteNodeServer {
6850
6851
  }, options.debug ?? {});
6851
6852
  }
6852
6853
  if (options.debug)
6853
- import('./chunk-vite-node-debug.dbce2e1f.mjs').then((r) => this.debugger = new r.Debugger(server.config.root, options.debug));
6854
+ import('./chunk-vite-node-debug.536c4c5b.mjs').then((r) => this.debugger = new r.Debugger(server.config.root, options.debug));
6854
6855
  }
6855
6856
  shouldExternalize(id) {
6856
6857
  return shouldExternalize(id, this.options.deps, this.externalizeCache);
@@ -6900,14 +6901,18 @@ class ViteNodeServer {
6900
6901
  if (timestamp && cache && cache.timestamp >= timestamp)
6901
6902
  return cache.result;
6902
6903
  const externalize = await this.shouldExternalize(filePath);
6904
+ let duration;
6903
6905
  if (externalize) {
6904
6906
  result = { externalize };
6905
6907
  (_a = this.debugger) == null ? void 0 : _a.recordExternalize(id, externalize);
6906
6908
  } else {
6909
+ const start = performance.now();
6907
6910
  const r = await this._transformRequest(id);
6911
+ duration = performance.now() - start;
6908
6912
  result = { code: r == null ? void 0 : r.code, map: r == null ? void 0 : r.map };
6909
6913
  }
6910
6914
  this.fetchCache.set(filePath, {
6915
+ duration,
6911
6916
  timestamp,
6912
6917
  result
6913
6918
  });
@@ -7000,11 +7005,11 @@ function addSnapshotResult(summary, result) {
7000
7005
  summary.total += result.added + result.matched + result.unmatched + result.updated;
7001
7006
  }
7002
7007
 
7003
- const workerPath = _url.pathToFileURL(resolve(distDir, "./worker.mjs")).href;
7004
- const loaderPath = _url.pathToFileURL(resolve(distDir, "./loader.mjs")).href;
7008
+ const workerPath = url.pathToFileURL(resolve(distDir, "./worker.mjs")).href;
7009
+ const loaderPath = url.pathToFileURL(resolve(distDir, "./loader.mjs")).href;
7005
7010
  const suppressLoaderWarningsPath = resolve(rootDir, "./suppress-warnings.cjs");
7006
7011
  function createPool(ctx) {
7007
- var _a, _b;
7012
+ var _a, _b, _c;
7008
7013
  const threadsCount = ctx.config.watch ? Math.max(Math.floor(cpus().length / 2), 1) : Math.max(cpus().length - 1, 1);
7009
7014
  const maxThreads = ctx.config.maxThreads ?? threadsCount;
7010
7015
  const minThreads = ctx.config.minThreads ?? threadsCount;
@@ -7031,8 +7036,7 @@ function createPool(ctx) {
7031
7036
  options.maxThreads = 1;
7032
7037
  options.minThreads = 1;
7033
7038
  }
7034
- if (ctx.config.coverage.enabled)
7035
- (_b = process.env).NODE_V8_COVERAGE || (_b.NODE_V8_COVERAGE = ctx.config.coverage.tempDirectory);
7039
+ (_c = (_b = ctx.coverageProvider) == null ? void 0 : _b.onBeforeFilesRun) == null ? void 0 : _c.call(_b);
7036
7040
  options.env = {
7037
7041
  TEST: "true",
7038
7042
  VITEST: "true",
@@ -7122,6 +7126,10 @@ function createChannel(ctx) {
7122
7126
  ctx.state.collectFiles(files);
7123
7127
  ctx.report("onCollected", files);
7124
7128
  },
7129
+ onAfterSuiteRun(meta) {
7130
+ var _a;
7131
+ (_a = ctx.coverageProvider) == null ? void 0 : _a.onAfterSuiteRun(meta);
7132
+ },
7125
7133
  onTaskUpdate(packs) {
7126
7134
  ctx.state.updateTasks(packs);
7127
7135
  ctx.report("onTaskUpdate", packs);
@@ -7450,8 +7458,8 @@ ${BADGE}${TRIGGER} ${picocolors.exports.blue(`x${rerun}`)}
7450
7458
  return shouldIgnore;
7451
7459
  return true;
7452
7460
  }
7453
- onServerRestart() {
7454
- this.ctx.logger.log(picocolors.exports.cyan("Restarted due to config changes..."));
7461
+ onServerRestart(reason) {
7462
+ this.ctx.logger.log(picocolors.exports.bold(picocolors.exports.magenta(reason === "config" ? "\nRestarting due to config changes..." : "\nRestarting Vitest...")));
7455
7463
  }
7456
7464
  async reportSummary(files) {
7457
7465
  const logger = this.ctx.logger;
@@ -7486,6 +7494,7 @@ ${BADGE}${TRIGGER} ${picocolors.exports.blue(`x${rerun}`)}
7486
7494
  var _a2;
7487
7495
  return acc + Math.max(0, ((_a2 = test.result) == null ? void 0 : _a2.duration) || 0);
7488
7496
  }, 0);
7497
+ const transformTime = Array.from(this.ctx.vitenode.fetchCache.values()).reduce((a, b) => a + ((b == null ? void 0 : b.duration) || 0), 0);
7489
7498
  const threadTime = collectTime + testsTime + setupTime;
7490
7499
  const padTitle = (str) => picocolors.exports.dim(`${str.padStart(10)} `);
7491
7500
  const time = (time2) => {
@@ -7505,7 +7514,7 @@ ${BADGE}${TRIGGER} ${picocolors.exports.blue(`x${rerun}`)}
7505
7514
  if (this.watchFilters)
7506
7515
  logger.log(padTitle("Duration"), time(threadTime));
7507
7516
  else
7508
- logger.log(padTitle("Duration"), time(executionTime) + picocolors.exports.gray(` (setup ${time(setupTime)}, collect ${time(collectTime)}, tests ${time(testsTime)})`));
7517
+ logger.log(padTitle("Duration"), time(executionTime) + picocolors.exports.dim(` (transform ${time(transformTime)}, setup ${time(setupTime)}, collect ${time(collectTime)}, tests ${time(testsTime)})`));
7509
7518
  logger.log();
7510
7519
  }
7511
7520
  async printTaskErrors(tasks, errorDivider) {
@@ -7977,7 +7986,7 @@ function tapString(str) {
7977
7986
  class TapReporter {
7978
7987
  onInit(ctx) {
7979
7988
  this.ctx = ctx;
7980
- this.logger = new IndentedLogger(this.ctx.logger.log.bind(this.ctx));
7989
+ this.logger = new IndentedLogger(ctx.logger.log.bind(ctx.logger));
7981
7990
  }
7982
7991
  static getComment(task) {
7983
7992
  var _a;
@@ -8065,7 +8074,8 @@ function escapeXML(value) {
8065
8074
  }
8066
8075
  function getDuration(task) {
8067
8076
  var _a;
8068
- return ((_a = task.result) == null ? void 0 : _a.duration) ? (task.result.duration / 1e3).toFixed(10) : void 0;
8077
+ const duration = ((_a = task.result) == null ? void 0 : _a.duration) ?? 0;
8078
+ return (duration / 1e3).toLocaleString(void 0, { useGrouping: false, maximumFractionDigits: 10 });
8069
8079
  }
8070
8080
  class JUnitReporter {
8071
8081
  async onInit(ctx) {
@@ -8349,6 +8359,85 @@ class StateManager {
8349
8359
  }
8350
8360
  }
8351
8361
 
8362
+ const defaultInclude = ["**/*.{test,spec}.{js,mjs,cjs,ts,mts,cts,jsx,tsx}"];
8363
+ const defaultExclude = ["**/node_modules/**", "**/dist/**", "**/cypress/**", "**/.{idea,git,cache,output,temp}/**"];
8364
+ const defaultCoverageExcludes = [
8365
+ "coverage/**",
8366
+ "dist/**",
8367
+ "packages/*/test{,s}/**",
8368
+ "**/*.d.ts",
8369
+ "cypress/**",
8370
+ "test{,s}/**",
8371
+ "test{,-*}.{js,cjs,mjs,ts,tsx,jsx}",
8372
+ "**/*{.,-}test.{js,cjs,mjs,ts,tsx,jsx}",
8373
+ "**/*{.,-}spec.{js,cjs,mjs,ts,tsx,jsx}",
8374
+ "**/__tests__/**",
8375
+ "**/{karma,rollup,webpack,vite,vitest,jest,ava,babel,nyc,cypress}.config.{js,cjs,mjs,ts}",
8376
+ "**/.{eslint,mocha,prettier}rc.{js,cjs,yml}"
8377
+ ];
8378
+ const coverageConfigDefaults = {
8379
+ provider: "c8",
8380
+ enabled: false,
8381
+ clean: true,
8382
+ cleanOnRerun: false,
8383
+ reportsDirectory: "./coverage",
8384
+ excludeNodeModules: true,
8385
+ exclude: defaultCoverageExcludes,
8386
+ reporter: ["text", "html", "clover"],
8387
+ allowExternal: false,
8388
+ extension: [".js", ".cjs", ".mjs", ".ts", ".tsx", ".jsx", ".vue", ".svelte"]
8389
+ };
8390
+ const fakeTimersDefaults = {
8391
+ loopLimit: 1e4,
8392
+ shouldClearNativeTimers: true,
8393
+ toFake: [
8394
+ "setTimeout",
8395
+ "clearTimeout",
8396
+ "setInterval",
8397
+ "clearInterval",
8398
+ "setImmediate",
8399
+ "clearImmediate",
8400
+ "Date"
8401
+ ]
8402
+ };
8403
+ const config = {
8404
+ allowOnly: !process.env.CI,
8405
+ watch: !process.env.CI,
8406
+ globals: false,
8407
+ environment: "node",
8408
+ threads: true,
8409
+ clearMocks: false,
8410
+ restoreMocks: false,
8411
+ mockReset: false,
8412
+ include: defaultInclude,
8413
+ exclude: defaultExclude,
8414
+ testTimeout: 5e3,
8415
+ hookTimeout: 1e4,
8416
+ teardownTimeout: 1e3,
8417
+ isolate: true,
8418
+ watchExclude: ["**/node_modules/**", "**/dist/**"],
8419
+ forceRerunTriggers: [
8420
+ "**/package.json/**",
8421
+ "**/vitest.config.*/**",
8422
+ "**/vite.config.*/**"
8423
+ ],
8424
+ update: false,
8425
+ reporters: [],
8426
+ silent: false,
8427
+ api: false,
8428
+ ui: false,
8429
+ uiBase: "/__vitest__/",
8430
+ open: true,
8431
+ css: {
8432
+ include: [/\.module\./]
8433
+ },
8434
+ coverage: coverageConfigDefaults,
8435
+ fakeTimers: fakeTimersDefaults,
8436
+ maxConcurrency: 5,
8437
+ dangerouslyIgnoreUnhandledErrors: false
8438
+ };
8439
+ const configDefaults = Object.freeze(config);
8440
+
8352
8441
  class FilesStatsCache {
8353
8442
  constructor() {
8354
8443
  this.cache = /* @__PURE__ */ new Map();
@@ -8557,7 +8646,6 @@ function resolveConfig(options, viteConfig) {
8557
8646
  };
8558
8647
  if (viteConfig.base !== "/")
8559
8648
  resolved.base = viteConfig.base;
8560
- resolved.coverage = resolveC8Options(options.coverage || {}, resolved.root);
8561
8649
  if (options.shard) {
8562
8650
  if (resolved.watch)
8563
8651
  throw new Error("You cannot use --shard option with enabled watch");
@@ -9106,7 +9194,7 @@ createLogUpdate(process$1.stdout);
9106
9194
 
9107
9195
  createLogUpdate(process$1.stderr);
9108
9196
 
9109
- var version = "0.21.0";
9197
+ var version = "0.22.1";
9110
9198
 
9111
9199
  function fileFromParsedStack(stack) {
9112
9200
  var _a, _b;
@@ -9349,12 +9437,14 @@ class Logger {
9349
9437
  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}`)));
9350
9438
  else if (this.ctx.config.api)
9351
9439
  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}`)}`)));
9440
+ if (this.ctx.coverageProvider)
9441
+ this.log(picocolors.exports.dim(" Coverage enabled with ") + picocolors.exports.yellow(this.ctx.coverageProvider.name));
9352
9442
  this.log();
9353
9443
  }
9354
9444
  async printUnhandledErrors(errors) {
9355
9445
  const errorMessage = picocolors.exports.red(picocolors.exports.bold(`
9356
- Vitest caught ${errors.length} unhandled error${errors.length > 1 ? "s" : ""} during the test run. This might cause false positive tests.
9357
- Please, resolve all the errors to make sure your tests are not affected.`));
9446
+ Vitest caught ${errors.length} unhandled error${errors.length > 1 ? "s" : ""} during the test run.
9447
+ This might cause false positive tests. Resolve unhandled errors to make sure your tests are not affected.`));
9358
9448
  this.log(picocolors.exports.red(divider(picocolors.exports.bold(picocolors.exports.inverse(" Unhandled Errors ")))));
9359
9449
  this.log(errorMessage);
9360
9450
  await Promise.all(errors.map(async (err) => {
@@ -9384,7 +9474,7 @@ class Vitest {
9384
9474
  this.logger = new Logger(this);
9385
9475
  }
9386
9476
  async setServer(options, server) {
9387
- var _a, _b;
9477
+ var _a, _b, _c;
9388
9478
  (_a = this.unregisterWatcher) == null ? void 0 : _a.call(this);
9389
9479
  safeClearTimeout(this._rerunTimer);
9390
9480
  this.restartsCount += 1;
@@ -9410,11 +9500,24 @@ class Vitest {
9410
9500
  return node.resolveId(id, importer);
9411
9501
  }
9412
9502
  });
9503
+ if (this.config.watch) {
9504
+ const serverRestart = server.restart;
9505
+ server.restart = async (...args) => {
9506
+ await Promise.all(this._onRestartListeners.map((fn) => fn()));
9507
+ return await serverRestart(...args);
9508
+ };
9509
+ server.watcher.on("change", async (file) => {
9510
+ file = normalizePath(file);
9511
+ const isConfig = file === server.config.configFile;
9512
+ if (isConfig) {
9513
+ await Promise.all(this._onRestartListeners.map((fn) => fn("config")));
9514
+ await serverRestart();
9515
+ }
9516
+ });
9517
+ }
9413
9518
  this.reporters = await createReporters(resolved.reporters, this.runner);
9414
9519
  this.runningPromise = void 0;
9415
- this._onRestartListeners.forEach((fn) => fn());
9416
- if (resolved.coverage.enabled)
9417
- await cleanCoverage(resolved.coverage, resolved.coverage.clean);
9520
+ await ((_c = this.coverageProvider) == null ? void 0 : _c.clean(this.config.coverage.clean));
9418
9521
  this.cache.results.setConfig(resolved.root, resolved.cache);
9419
9522
  try {
9420
9523
  await this.cache.results.readFromCache();
@@ -9422,6 +9525,16 @@ class Vitest {
9422
9525
  this.logger.error(`[vitest] Error, while trying to parse cache in ${this.cache.results.getCachePath()}:`, err);
9423
9526
  }
9424
9527
  }
9528
+ async initCoverageProvider() {
9529
+ if (this.coverageProvider !== void 0)
9530
+ return;
9531
+ this.coverageProvider = await getCoverageProvider(this.config.coverage);
9532
+ if (this.coverageProvider) {
9533
+ await this.coverageProvider.initialize(this);
9534
+ this.config.coverage = this.coverageProvider.resolveOptions();
9535
+ }
9536
+ return this.coverageProvider;
9537
+ }
9425
9538
  getSerializableConfig() {
9426
9539
  return deepMerge({
9427
9540
  ...this.config,
@@ -9438,6 +9551,12 @@ class Vitest {
9438
9551
  }, this.configOverride || {});
9439
9552
  }
9440
9553
  async start(filters) {
9554
+ try {
9555
+ await this.initCoverageProvider();
9556
+ } catch (e) {
9557
+ this.logger.error(e);
9558
+ process.exit(1);
9559
+ }
9441
9560
  await this.report("onInit", this);
9442
9561
  const files = await this.filterTestsBySource(await this.globTestFiles(filters));
9443
9562
  if (!files.length) {
@@ -9447,8 +9566,10 @@ class Vitest {
9447
9566
  }
9448
9567
  await Promise.all(files.map((file) => this.cache.stats.updateStats(file)));
9449
9568
  await this.runFiles(files);
9450
- if (this.config.coverage.enabled)
9451
- await reportCoverage(this);
9569
+ if (this.coverageProvider) {
9570
+ this.logger.log(picocolors.exports.blue(" % ") + picocolors.exports.dim("Coverage report from ") + picocolors.exports.yellow(this.coverageProvider.name));
9571
+ await this.coverageProvider.reportCoverage();
9572
+ }
9452
9573
  if (this.config.watch && !this.config.browser)
9453
9574
  await this.report("onWatcherStart");
9454
9575
  }
@@ -9473,7 +9594,7 @@ class Vitest {
9473
9594
  }
9474
9595
  async filterTestsBySource(tests) {
9475
9596
  if (this.config.changed && !this.config.related) {
9476
- const { VitestGit } = await import('./chunk-node-git.e0dc0a7e.mjs');
9597
+ const { VitestGit } = await import('./chunk-node-git.9a7e3153.mjs');
9477
9598
  const vitestGit = new VitestGit(this.config.root);
9478
9599
  const related2 = await vitestGit.findChangedFiles({
9479
9600
  changedSince: this.config.changed
@@ -9568,6 +9689,7 @@ class Vitest {
9568
9689
  if (this.restartsCount !== currentCount)
9569
9690
  return;
9570
9691
  this._rerunTimer = safeSetTimeout(async () => {
9692
+ var _a;
9571
9693
  if (this.changedTests.size === 0) {
9572
9694
  this.invalidates.clear();
9573
9695
  return;
@@ -9578,12 +9700,11 @@ class Vitest {
9578
9700
  this.snapshot.clear();
9579
9701
  const files = Array.from(this.changedTests);
9580
9702
  this.changedTests.clear();
9581
- if (this.config.coverage.enabled && this.config.coverage.cleanOnRerun)
9582
- await cleanCoverage(this.config.coverage);
9703
+ if (this.coverageProvider && this.config.coverage.cleanOnRerun)
9704
+ await this.coverageProvider.clean();
9583
9705
  await this.report("onWatcherRerun", files, triggerId);
9584
9706
  await this.runFiles(files);
9585
- if (this.config.coverage.enabled)
9586
- await reportCoverage(this);
9707
+ await ((_a = this.coverageProvider) == null ? void 0 : _a.reportCoverage());
9587
9708
  if (!this.config.browser)
9588
9709
  await this.report("onWatcherStart");
9589
9710
  }, WATCHER_DEBOUNCE);
@@ -9725,7 +9846,7 @@ class Vitest {
9725
9846
  isInSourceTestFile(code) {
9726
9847
  return code.includes("import.meta.vitest");
9727
9848
  }
9728
- onServerRestarted(fn) {
9849
+ onServerRestart(fn) {
9729
9850
  this._onRestartListeners.push(fn);
9730
9851
  }
9731
9852
  }
@@ -9959,8 +10080,17 @@ function CSSEnablerPlugin(ctx) {
9959
10080
  };
9960
10081
  }
9961
10082
 
10083
+ function CoverageTransform(ctx) {
10084
+ return {
10085
+ name: "vitest:coverage-transform",
10086
+ transform(srcCode, id) {
10087
+ var _a, _b;
10088
+ return (_b = (_a = ctx.coverageProvider) == null ? void 0 : _a.onFileTransform) == null ? void 0 : _b.call(_a, srcCode, id, this);
10089
+ }
10090
+ };
10091
+ }
10092
+
9962
10093
  async function VitestPlugin(options = {}, ctx = new Vitest()) {
9963
- let haveStarted = false;
9964
10094
  async function UIPlugin() {
9965
10095
  var _a;
9966
10096
  await ensurePackageInstalled("@vitest/ui", ((_a = ctx.config) == null ? void 0 : _a.root) || options.root || process.cwd());
@@ -10056,13 +10186,10 @@ async function VitestPlugin(options = {}, ctx = new Vitest()) {
10056
10186
  (_d = process.env)[name] ?? (_d[name] = envs[name]);
10057
10187
  },
10058
10188
  async configureServer(server) {
10059
- if (haveStarted)
10060
- await ctx.report("onServerRestart");
10061
10189
  try {
10062
10190
  await ctx.setServer(options, server);
10063
- haveStarted = true;
10064
10191
  if (options.api && options.watch)
10065
- (await import('./chunk-api-setup.89eb0e7a.mjs')).setup(ctx);
10192
+ (await import('./chunk-api-setup.377c28aa.mjs')).setup(ctx);
10066
10193
  } catch (err) {
10067
10194
  ctx.logger.printError(err, true);
10068
10195
  process.exit(1);
@@ -10076,6 +10203,7 @@ async function VitestPlugin(options = {}, ctx = new Vitest()) {
10076
10203
  GlobalSetupPlugin(ctx),
10077
10204
  ...options.browser ? await BrowserPlugin() : [],
10078
10205
  CSSEnablerPlugin(ctx),
10206
+ CoverageTransform(ctx),
10079
10207
  options.ui ? await UIPlugin() : null
10080
10208
  ].filter(notNullish);
10081
10209
  }
@@ -10124,7 +10252,7 @@ function registerConsoleShortcuts(ctx) {
10124
10252
  if (name === "u")
10125
10253
  return ctx.updateSnapshot();
10126
10254
  if (name === "a" || name === "return")
10127
- return ctx.rerunFiles(void 0);
10255
+ return ctx.changeNamePattern("");
10128
10256
  if (name === "f")
10129
10257
  return ctx.rerunFailed();
10130
10258
  if (name === "t")
@@ -10183,9 +10311,13 @@ async function startVitest(cliFilters, options, viteOverrides) {
10183
10311
  options.coverage = { enabled: options.coverage };
10184
10312
  const ctx = await createVitest(options, viteOverrides);
10185
10313
  if (ctx.config.coverage.enabled) {
10186
- if (!await ensurePackageInstalled("c8", root)) {
10187
- process.exitCode = 1;
10188
- return false;
10314
+ const provider = ctx.config.coverage.provider || "c8";
10315
+ if (typeof provider === "string") {
10316
+ const requiredPackages = CoverageProviderMap[provider];
10317
+ if (!await ensurePackageInstalled(requiredPackages, root)) {
10318
+ process.exitCode = 1;
10319
+ return false;
10320
+ }
10189
10321
  }
10190
10322
  }
10191
10323
  if (ctx.config.environment && ctx.config.environment !== "node") {
@@ -10197,8 +10329,12 @@ async function startVitest(cliFilters, options, viteOverrides) {
10197
10329
  }
10198
10330
  if (process.stdin.isTTY && ctx.config.watch)
10199
10331
  registerConsoleShortcuts(ctx);
10200
- ctx.onServerRestarted(() => {
10201
- ctx.start(cliFilters);
10332
+ ctx.onServerRestart((reason) => {
10333
+ ctx.report("onServerRestart", reason);
10334
+ if (process.env.VITEST_CLI_WRAPPER)
10335
+ process.exit(EXIT_CODE_RESTART);
10336
+ else
10337
+ ctx.start(cliFilters);
10202
10338
  });
10203
10339
  try {
10204
10340
  await ctx.start(cliFilters);