vitest 4.0.0-beta.7 → 4.0.0-beta.8

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.
@@ -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.C3EbxYwt.js';
6
+ import { R as ReportersMap } from './index.AzwzFtyi.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.0-beta.7";
622
+ var version = "4.0.0-beta.8";
623
623
 
624
624
  const apiConfig = (port) => ({
625
625
  port: {
@@ -872,7 +872,6 @@ const cliOptionsConfig = {
872
872
  },
873
873
  trackUnhandledErrors: { description: "Control if Vitest catches uncaught exceptions so they can be reported (default: `true`)" },
874
874
  orchestratorScripts: null,
875
- testerScripts: null,
876
875
  commands: null,
877
876
  viewport: null,
878
877
  screenshotDirectory: null,
@@ -1336,10 +1335,10 @@ async function start(mode, cliFilters, options) {
1336
1335
  process.title = "node (vitest)";
1337
1336
  } catch {}
1338
1337
  try {
1339
- const { startVitest } = await import('./cli-api.DfGJyldU.js').then(function (n) { return n.j; }), ctx = await startVitest(mode, cliFilters.map(normalize), normalizeCliOptions(cliFilters, options));
1338
+ const { startVitest } = await import('./cli-api.C-JHgQgp.js').then(function (n) { return n.j; }), ctx = await startVitest(mode, cliFilters.map(normalize), normalizeCliOptions(cliFilters, options));
1340
1339
  if (!ctx.shouldKeepServer()) await ctx.exit();
1341
1340
  } catch (e) {
1342
- const { errorBanner } = await import('./index.C3EbxYwt.js').then(function (n) { return n.u; });
1341
+ const { errorBanner } = await import('./index.AzwzFtyi.js').then(function (n) { return n.u; });
1343
1342
  if (console.error(`\n${errorBanner("Startup Error")}`), console.error(e), console.error("\n\n"), process.exitCode == null) process.exitCode = 1;
1344
1343
  process.exit();
1345
1344
  }
@@ -1354,7 +1353,7 @@ async function collect(mode, cliFilters, options) {
1354
1353
  process.title = "node (vitest)";
1355
1354
  } catch {}
1356
1355
  try {
1357
- const { prepareVitest, processCollected, outputFileList } = await import('./cli-api.DfGJyldU.js').then(function (n) { return n.j; }), ctx = await prepareVitest(mode, {
1356
+ const { prepareVitest, processCollected, outputFileList } = await import('./cli-api.C-JHgQgp.js').then(function (n) { return n.j; }), ctx = await prepareVitest(mode, {
1358
1357
  ...normalizeCliOptions(cliFilters, options),
1359
1358
  watch: false,
1360
1359
  run: true
@@ -1372,7 +1371,7 @@ async function collect(mode, cliFilters, options) {
1372
1371
  }
1373
1372
  await ctx.close();
1374
1373
  } catch (e) {
1375
- const { errorBanner } = await import('./index.C3EbxYwt.js').then(function (n) { return n.u; });
1374
+ const { errorBanner } = await import('./index.AzwzFtyi.js').then(function (n) { return n.u; });
1376
1375
  if (console.error(`\n${errorBanner("Collect Error")}`), console.error(e), console.error("\n\n"), process.exitCode == null) process.exitCode = 1;
1377
1376
  process.exit();
1378
1377
  }
@@ -10,9 +10,9 @@ import { A as API_PATH, c as configFiles, d as defaultBrowserPort, a as defaultP
10
10
  import nodeos__default, { tmpdir } from 'node:os';
11
11
  import { generateHash as generateHash$1, calculateSuiteHash, someTasksAreOnly, interpretTaskModes, generateFileHash, limitConcurrency, createFileTask as createFileTask$1, hasFailed, getTasks, getTests } from '@vitest/runner/utils';
12
12
  import { SnapshotManager } from '@vitest/snapshot/manager';
13
- import { v as version$1 } from './cac.Dsn7ixFt.js';
13
+ import { v as version$1 } from './cac.By1HvRIk.js';
14
14
  import { c as createBirpc } from './index.Bgo3tNWt.js';
15
- import { p as parse, s as stringify, d as printError, f as formatProjectName, w as withLabel, e as errorBanner, h as divider, i as generateCodeFrame, R as ReportersMap, B as BlobReporter, r as readBlobs, H as HangingProcessReporter } from './index.C3EbxYwt.js';
15
+ import { p as parse, s as stringify, d as printError, f as formatProjectName, w as withLabel, e as errorBanner, h as divider, i as generateCodeFrame, R as ReportersMap, B as BlobReporter, r as readBlobs, H as HangingProcessReporter } from './index.AzwzFtyi.js';
16
16
  import require$$0$3 from 'events';
17
17
  import require$$1$1 from 'https';
18
18
  import require$$2 from 'http';
@@ -26,7 +26,7 @@ import require$$0$1 from 'buffer';
26
26
  import { g as getDefaultExportFromCjs } from './_commonjsHelpers.BFTU3MAI.js';
27
27
  import crypto, { createHash } from 'node:crypto';
28
28
  import { distDir, rootDir } from '../path.js';
29
- import { h as hash, d as createFetchModuleFunction, n as normalizeResolvedIdToUrl, R as RandomSequencer, i as isPackageExists, g as getFilePoolName, e as isBrowserEnabled, r as resolveConfig, f as groupBy, j as getCoverageProvider, k as createPool, w as wildcardPatternToRegExp, a as resolveApiServerConfig, s as stdout } from './coverage.Dvxug1RM.js';
29
+ import { h as hash, d as createFetchModuleFunction, n as normalizeResolvedIdToUrl, R as RandomSequencer, i as isPackageExists, g as getFilePoolName, e as isBrowserEnabled, r as resolveConfig, f as groupBy, j as getCoverageProvider, k as createPool, w as wildcardPatternToRegExp, a as resolveApiServerConfig, s as stdout } from './coverage.DarITf6U.js';
30
30
  import { b as ancestor, c as convertTasksToEvents } from './typechecker.DSo_maXz.js';
31
31
  import { TraceMap, originalPositionFor, parseErrorStacktrace } from '@vitest/utils/source-map';
32
32
  import createDebug from 'debug';
@@ -45,7 +45,7 @@ import { hoistMocksPlugin, automockPlugin } from '@vitest/mocker/node';
45
45
  import { c as configDefaults } from './defaults.CXFFjsi8.js';
46
46
  import { f as findNearestPackageData } from './resolver.Bx6lE0iq.js';
47
47
  import * as esModuleLexer from 'es-module-lexer';
48
- import { a as BenchmarkReportsMap } from './index.D2B6d2vv.js';
48
+ import { a as BenchmarkReportsMap } from './index.BuwjkI-q.js';
49
49
  import assert$1 from 'node:assert';
50
50
  import { serializeError as serializeError$1 } from '@vitest/utils/error';
51
51
  import readline from 'node:readline';
@@ -5081,7 +5081,7 @@ catch {}
5081
5081
  }
5082
5082
 
5083
5083
  function setup(ctx, _server) {
5084
- const wss = new WebSocketServer({ noServer: true }), clients = /* @__PURE__ */ new Map(), server = _server || ctx.server;
5084
+ const wss = new WebSocketServer({ noServer: true }), clients = /* @__PURE__ */ new Map(), server = _server || ctx.vite;
5085
5085
  server.httpServer?.on("upgrade", (request, socket, head) => {
5086
5086
  if (!request.url) return;
5087
5087
  const { pathname } = new URL(request.url, "http://localhost");
@@ -5326,7 +5326,7 @@ function createFailedFileTask(project, filepath, error) {
5326
5326
  tasks: [],
5327
5327
  start: 0,
5328
5328
  end: 0,
5329
- projectName: project.getName(),
5329
+ projectName: project.name,
5330
5330
  meta: {},
5331
5331
  pool: project.browser ? "browser" : project.config.pool,
5332
5332
  file: null,
@@ -5521,7 +5521,7 @@ class FilesStatsCache {
5521
5521
  }
5522
5522
  async populateStats(root, specs) {
5523
5523
  const promises = specs.map((spec) => {
5524
- const key = `${spec[0].name}:${relative(root, spec.moduleId)}`;
5524
+ const key = `${spec.project.name}:${relative(root, spec.moduleId)}`;
5525
5525
  return this.updateStats(spec.moduleId, key);
5526
5526
  });
5527
5527
  await Promise.all(promises);
@@ -5773,10 +5773,10 @@ class Logger {
5773
5773
  const color = this.ctx.config.watch ? "blue" : "cyan", mode = this.ctx.config.watch ? "DEV" : "RUN";
5774
5774
  if (this.log(withLabel(color, mode, `v${this.ctx.version} `) + c.gray(this.ctx.config.root)), this.ctx.config.sequence.sequencer === RandomSequencer) this.log(PAD + c.gray(`Running tests with seed "${this.ctx.config.sequence.seed}"`));
5775
5775
  if (this.ctx.config.ui) {
5776
- const host = this.ctx.config.api?.host || "localhost", port = this.ctx.server.config.server.port, base = this.ctx.config.uiBase;
5776
+ const host = this.ctx.config.api?.host || "localhost", port = this.ctx.vite.config.server.port, base = this.ctx.config.uiBase;
5777
5777
  this.log(PAD + c.dim(c.green(`UI started at http://${host}:${c.bold(port)}${base}`)));
5778
5778
  } else if (this.ctx.config.api?.port) {
5779
- const resolvedUrls = this.ctx.server.resolvedUrls, fallbackUrl = `http://${this.ctx.config.api.host || "localhost"}:${this.ctx.config.api.port}`, origin = resolvedUrls?.local[0] ?? resolvedUrls?.network[0] ?? fallbackUrl;
5779
+ const resolvedUrls = this.ctx.vite.resolvedUrls, fallbackUrl = `http://${this.ctx.config.api.host || "localhost"}:${this.ctx.config.api.port}`, origin = resolvedUrls?.local[0] ?? resolvedUrls?.network[0] ?? fallbackUrl;
5780
5780
  this.log(PAD + c.dim(c.green(`API started at ${new URL("/", origin)}`)));
5781
5781
  }
5782
5782
  if (this.ctx.coverageProvider) this.log(PAD + c.dim("Coverage enabled with ") + c.yellow(this.ctx.coverageProvider.name));
@@ -6840,7 +6840,7 @@ function VitestProjectResolver(ctx) {
6840
6840
  if (id === "vitest" || id.startsWith("@vitest/") || id.startsWith("vitest/")) {
6841
6841
  // always redirect the request to the root vitest plugin since
6842
6842
  // it will be the one used to run Vitest
6843
- const resolved = await ctx.server.pluginContainer.resolveId(id, void 0, {
6843
+ const resolved = await ctx.vite.pluginContainer.resolveId(id, void 0, {
6844
6844
  skip: new Set([plugin]),
6845
6845
  ssr
6846
6846
  });
@@ -7075,18 +7075,6 @@ function matchExternalizePattern(id, moduleDirectories, patterns) {
7075
7075
  }
7076
7076
 
7077
7077
  class TestSpecification {
7078
- /**
7079
- * @deprecated use `project` instead
7080
- */
7081
- 0;
7082
- /**
7083
- * @deprecated use `moduleId` instead
7084
- */
7085
- 1;
7086
- /**
7087
- * @deprecated use `pool` instead
7088
- */
7089
- 2;
7090
7078
  /**
7091
7079
  * The task ID associated with the test module.
7092
7080
  */
@@ -7109,7 +7097,6 @@ class TestSpecification {
7109
7097
  */
7110
7098
  testLines;
7111
7099
  constructor(project, moduleId, pool, testLines) {
7112
- this[0] = project, this[1] = moduleId, this[2] = { pool };
7113
7100
  const name = project.config.name, hashName = pool !== "typescript" ? name : name ? `${name}:__typecheck__` : "__typecheck__";
7114
7101
  this.taskId = generateFileHash(relative(project.config.root, moduleId), hashName), this.project = project, this.moduleId = moduleId, this.pool = pool, this.testLines = testLines;
7115
7102
  }
@@ -7133,13 +7120,6 @@ class TestSpecification {
7133
7120
  }
7134
7121
  ];
7135
7122
  }
7136
- /**
7137
- * for backwards compatibility
7138
- * @deprecated
7139
- */
7140
- *[Symbol.iterator]() {
7141
- yield this.project, yield this.moduleId, yield this.pool;
7142
- }
7143
7123
  }
7144
7124
 
7145
7125
  async function createViteServer(inlineConfig) {
@@ -7167,8 +7147,6 @@ class TestProject {
7167
7147
  * Browser instance if the browser is enabled. This is initialized when the tests run for the first time.
7168
7148
  */
7169
7149
  browser;
7170
- /** @deprecated use `vitest` instead */
7171
- ctx;
7172
7150
  /**
7173
7151
  * Temporary directory for the project. This is unique for each project. Vitest stores transformed content here.
7174
7152
  */
@@ -7184,8 +7162,8 @@ class TestProject {
7184
7162
  typecheckFilesList = null;
7185
7163
  _globalSetups;
7186
7164
  _provided = {};
7187
- constructor(path, vitest, options) {
7188
- this.path = path, this.options = options, this.vitest = vitest, this.ctx = vitest, this.globalConfig = vitest.config;
7165
+ constructor(vitest, options) {
7166
+ this.options = options, this.vitest = vitest, this.globalConfig = vitest.config;
7189
7167
  }
7190
7168
  /**
7191
7169
  * The unique hash of this project. This value is consistent between the reruns.
@@ -7277,28 +7255,12 @@ class TestProject {
7277
7255
  get serializedConfig() {
7278
7256
  return this._serializeOverriddenConfig();
7279
7257
  }
7280
- /** @deprecated use `vite` instead */
7281
- get server() {
7282
- return this._vite;
7283
- }
7284
7258
  /**
7285
7259
  * Check if this is the root project. The root project is the one that has the root config.
7286
7260
  */
7287
7261
  isRootProject() {
7288
7262
  return this.vitest.getRootProject() === this;
7289
7263
  }
7290
- /** @deprecated use `isRootProject` instead */
7291
- isCore() {
7292
- return this.isRootProject();
7293
- }
7294
- /** @deprecated use `createSpecification` instead */
7295
- createSpec(moduleId, pool) {
7296
- return new TestSpecification(this, moduleId, pool);
7297
- }
7298
- /** @deprecated */
7299
- initializeGlobalSetup() {
7300
- return this._initializeGlobalSetup();
7301
- }
7302
7264
  /** @internal */
7303
7265
  async _initializeGlobalSetup() {
7304
7266
  if (!this._globalSetups) {
@@ -7314,37 +7276,10 @@ class TestProject {
7314
7276
  onTestsRerun(cb) {
7315
7277
  this.vitest.onTestsRerun(cb);
7316
7278
  }
7317
- /** @deprecated */
7318
- teardownGlobalSetup() {
7319
- return this._teardownGlobalSetup();
7320
- }
7321
7279
  /** @internal */
7322
7280
  async _teardownGlobalSetup() {
7323
7281
  if (this._globalSetups) for (const globalSetupFile of [...this._globalSetups].reverse()) await globalSetupFile.teardown?.();
7324
7282
  }
7325
- /** @deprecated use `vitest.logger` instead */
7326
- get logger() {
7327
- return this.vitest.logger;
7328
- }
7329
- // it's possible that file path was imported with different queries (?raw, ?url, etc)
7330
- /** @deprecated use `.vite` or `.browser.vite` directly */
7331
- getModulesByFilepath(file) {
7332
- const set = this.server.moduleGraph.getModulesByFile(file) || this.browser?.vite.moduleGraph.getModulesByFile(file);
7333
- return set || /* @__PURE__ */ new Set();
7334
- }
7335
- /** @deprecated use `.vite` or `.browser.vite` directly */
7336
- getModuleById(id) {
7337
- return this.server.moduleGraph.getModuleById(id) || this.browser?.vite.moduleGraph.getModuleById(id);
7338
- }
7339
- /** @deprecated use `.vite` or `.browser.vite` directly */
7340
- getSourceMapModuleById(id) {
7341
- const mod = this.server.moduleGraph.getModuleById(id);
7342
- return mod?.ssrTransformResult?.map || mod?.transformResult?.map;
7343
- }
7344
- /** @deprecated use `vitest.reporters` instead */
7345
- get reporters() {
7346
- return this.ctx.reporters;
7347
- }
7348
7283
  /**
7349
7284
  * Get all files in the project that match the globs in the config and the filters.
7350
7285
  * @param filters String filters to match the test files.
@@ -7396,10 +7331,6 @@ class TestProject {
7396
7331
  _isCachedTypecheckFile(testPath) {
7397
7332
  return !!this.typecheckFilesList && this.typecheckFilesList.includes(testPath);
7398
7333
  }
7399
- /** @deprecated use `serializedConfig` instead */
7400
- getSerializableConfig() {
7401
- return this._serializeOverriddenConfig();
7402
- }
7403
7334
  /** @internal */
7404
7335
  async globFiles(include, exclude, cwd) {
7405
7336
  const globOptions = {
@@ -7427,10 +7358,6 @@ class TestProject {
7427
7358
  }
7428
7359
  return false;
7429
7360
  }
7430
- /** @deprecated use `matchesTestGlob` instead */
7431
- async isTargetFile(id, source) {
7432
- return this.matchesTestGlob(id, source ? () => source : void 0);
7433
- }
7434
7361
  isInSourceTestCode(code) {
7435
7362
  return code.includes("import.meta.vitest");
7436
7363
  }
@@ -7495,14 +7422,6 @@ class TestProject {
7495
7422
  import(moduleId) {
7496
7423
  return this.runner.import(moduleId);
7497
7424
  }
7498
- /** @deprecated use `name` instead */
7499
- getName() {
7500
- return this.config.name || "";
7501
- }
7502
- /** @deprecated internal */
7503
- setServer(options, server) {
7504
- return this._configureServer(options, server);
7505
- }
7506
7425
  _setHash() {
7507
7426
  this._hash = generateHash(this._config.root + this._config.name);
7508
7427
  }
@@ -7530,10 +7449,6 @@ class TestProject {
7530
7449
  await rm(this.tmpDir, { recursive: true });
7531
7450
  } catch {}
7532
7451
  }
7533
- /** @deprecated */
7534
- initBrowserProvider() {
7535
- return this._initBrowserProvider();
7536
- }
7537
7452
  /** @internal */
7538
7453
  _initBrowserProvider = deduped(async () => {
7539
7454
  if (!(!this.isBrowserEnabled() || this.browser?.provider)) {
@@ -7551,12 +7466,12 @@ class TestProject {
7551
7466
  }
7552
7467
  /** @internal */
7553
7468
  static _createBasicProject(vitest) {
7554
- const project = new TestProject(vitest.config.name || vitest.config.root, vitest);
7555
- return project.runner = vitest.runner, project._vite = vitest.server, project._config = vitest.config, project._resolver = vitest._resolver, project._setHash(), project._provideObject(vitest.config.provide), project;
7469
+ const project = new TestProject(vitest);
7470
+ return project.runner = vitest.runner, project._vite = vitest.vite, project._config = vitest.config, project._resolver = vitest._resolver, project._setHash(), project._provideObject(vitest.config.provide), project;
7556
7471
  }
7557
7472
  /** @internal */
7558
7473
  static _cloneBrowserProject(parent, config) {
7559
- const clone = new TestProject(parent.path, parent.vitest);
7474
+ const clone = new TestProject(parent.vitest);
7560
7475
  return clone.runner = parent.runner, clone._vite = parent._vite, clone._resolver = parent._resolver, clone._config = config, clone._setHash(), clone._parent = parent, clone._provideObject(config.provide), clone;
7561
7476
  }
7562
7477
  }
@@ -7570,7 +7485,7 @@ function deduped(cb) {
7570
7485
  });
7571
7486
  }
7572
7487
  async function initializeProject(workspacePath, ctx, options) {
7573
- const project = new TestProject(workspacePath, ctx, options), { configFile,...restOptions } = options, config = {
7488
+ const project = new TestProject(ctx, options), { configFile,...restOptions } = options, config = {
7574
7489
  ...restOptions,
7575
7490
  configFile,
7576
7491
  configLoader: ctx.vite.config.inlineConfig.configLoader,
@@ -9186,7 +9101,6 @@ class Vitest {
9186
9101
  */
9187
9102
  watcher;
9188
9103
  /** @internal */ configOverride = {};
9189
- /** @internal */ coverageProvider;
9190
9104
  /** @internal */ filenamePattern;
9191
9105
  /** @internal */ runningPromise;
9192
9106
  /** @internal */ closingPromise;
@@ -9207,6 +9121,7 @@ class Vitest {
9207
9121
  _state;
9208
9122
  _cache;
9209
9123
  _snapshot;
9124
+ _coverageProvider;
9210
9125
  constructor(mode, cliOptions, options = {}) {
9211
9126
  this.mode = mode, this._cliOptions = cliOptions, this.logger = new Logger(this, options.stdout, options.stderr), this.packageInstaller = options.packageInstaller || new VitestPackageInstaller(), this.specifications = new VitestSpecifications(this), this.watcher = new VitestWatcher(this).onWatcherRerun((file) => this.scheduleRerun(file));
9212
9127
  }
@@ -9216,24 +9131,12 @@ class Vitest {
9216
9131
  _onCancelListeners = [];
9217
9132
  _onUserTestsRerun = [];
9218
9133
  _onFilterWatchedSpecification = [];
9219
- /** @deprecated will be removed in 4.0, use `onFilterWatchedSpecification` instead */
9220
- get invalidates() {
9221
- return this.watcher.invalidates;
9222
- }
9223
- /** @deprecated will be removed in 4.0, use `onFilterWatchedSpecification` instead */
9224
- get changedTests() {
9225
- return this.watcher.changedTests;
9226
- }
9227
9134
  /**
9228
9135
  * The global config.
9229
9136
  */
9230
9137
  get config() {
9231
9138
  return assert(this._config, "config"), this._config;
9232
9139
  }
9233
- /** @deprecated use `vitest.vite` instead */
9234
- get server() {
9235
- return this._vite;
9236
- }
9237
9140
  /**
9238
9141
  * Global Vite's dev server instance.
9239
9142
  */
@@ -9259,13 +9162,9 @@ class Vitest {
9259
9162
  get cache() {
9260
9163
  return assert(this._cache, "cache"), this._cache;
9261
9164
  }
9262
- /** @deprecated internal */
9263
- setServer(options, server) {
9264
- return this._setServer(options, server);
9265
- }
9266
9165
  /** @internal */
9267
9166
  async _setServer(options, server) {
9268
- this.watcher.unregisterWatcher(), clearTimeout(this._rerunTimer), this.restartsCount += 1, this.pool?.close?.(), this.pool = void 0, this.closingPromise = void 0, this.projects = [], this.coverageProvider = void 0, this.runningPromise = void 0, this.coreWorkspaceProject = void 0, this.specifications.clearCache(), this._onUserTestsRerun = [], this._vite = server;
9167
+ this.watcher.unregisterWatcher(), clearTimeout(this._rerunTimer), this.restartsCount += 1, this.pool?.close?.(), this.pool = void 0, this.closingPromise = void 0, this.projects = [], this.runningPromise = void 0, this.coreWorkspaceProject = void 0, this.specifications.clearCache(), this._coverageProvider = void 0, this._onUserTestsRerun = [], this._vite = server;
9269
9168
  const resolved = resolveConfig(this, options, server.config);
9270
9169
  if (this._config = resolved, this._state = new StateManager({ onUnhandledError: resolved.onUnhandledError }), this._cache = new VitestCache(this.version), this._snapshot = new SnapshotManager({ ...resolved.snapshotOptions }), this._testRun = new TestRun(this), this.config.watch) this.watcher.registerWatcher();
9271
9170
  this._resolver = new VitestResolver(server.config.cacheDir, resolved);
@@ -9306,6 +9205,26 @@ class Vitest {
9306
9205
  if (this.config.testNamePattern) this.configOverride.testNamePattern = this.config.testNamePattern;
9307
9206
  this.reporters = resolved.mode === "benchmark" ? await createBenchmarkReporters(toArray(resolved.benchmark?.reporters), this.runner) : await createReporters(resolved.reporters, this), await Promise.all(this._onSetServer.map((fn) => fn()));
9308
9207
  }
9208
+ /** @internal */
9209
+ get coverageProvider() {
9210
+ return this.configOverride.coverage?.enabled === false ? null : this._coverageProvider;
9211
+ }
9212
+ async enableCoverage() {
9213
+ this.configOverride.coverage = {}, this.configOverride.coverage.enabled = true, await this.createCoverageProvider(), await this.coverageProvider?.onEnabled?.();
9214
+ }
9215
+ disableCoverage() {
9216
+ this.configOverride.coverage ??= {}, this.configOverride.coverage.enabled = false;
9217
+ }
9218
+ _coverageOverrideCache = /* @__PURE__ */ new WeakMap();
9219
+ /** @internal */
9220
+ get _coverageOptions() {
9221
+ if (!this.configOverride.coverage) return this.config.coverage;
9222
+ if (!this._coverageOverrideCache.has(this.configOverride.coverage)) {
9223
+ const coverage = deepClone(this.config.coverage), options = deepMerge(coverage, this.configOverride.coverage);
9224
+ this._coverageOverrideCache.set(this.configOverride.coverage, options);
9225
+ }
9226
+ return this._coverageOverrideCache.get(this.configOverride.coverage);
9227
+ }
9309
9228
  /**
9310
9229
  * Inject new test projects into the workspace.
9311
9230
  * @param config Glob, config path or a custom config options.
@@ -9331,10 +9250,6 @@ class Vitest {
9331
9250
  _ensureRootProject() {
9332
9251
  return this.coreWorkspaceProject ||= TestProject._createBasicProject(this), this.coreWorkspaceProject;
9333
9252
  }
9334
- /** @deprecated use `getRootProject` instead */
9335
- getCoreWorkspaceProject() {
9336
- return this.getRootProject();
9337
- }
9338
9253
  /**
9339
9254
  * Return project that has the root (or "global") config.
9340
9255
  */
@@ -9342,13 +9257,6 @@ class Vitest {
9342
9257
  if (!this.coreWorkspaceProject) throw new Error(`Root project is not initialized. This means that the Vite server was not established yet and the the workspace config is not resolved.`);
9343
9258
  return this.coreWorkspaceProject;
9344
9259
  }
9345
- /**
9346
- * @deprecated use Reported Task API instead
9347
- */
9348
- getProjectByTaskId(taskId) {
9349
- const task = this.state.idMap.get(taskId), projectName = task.projectName || task?.file?.projectName || "";
9350
- return this.getProjectByName(projectName);
9351
- }
9352
9260
  getProjectByName(name) {
9353
9261
  const project = this.projects.find((p) => p.name === name) || this.coreWorkspaceProject || this.projects[0];
9354
9262
  if (!project) throw new Error(`Project "${name}" was not found.`);
@@ -9365,9 +9273,9 @@ class Vitest {
9365
9273
  * Creates a coverage provider if `coverage` is enabled in the config.
9366
9274
  */
9367
9275
  async createCoverageProvider() {
9368
- if (this.coverageProvider) return this.coverageProvider;
9276
+ if (this._coverageProvider) return this._coverageProvider;
9369
9277
  const coverageProvider = await this.initCoverageProvider();
9370
- if (coverageProvider) await coverageProvider.clean(this.config.coverage.clean);
9278
+ if (coverageProvider) await coverageProvider.clean(this._coverageOptions.clean);
9371
9279
  return coverageProvider || null;
9372
9280
  }
9373
9281
  async resolveProjects(cliOptions) {
@@ -9387,10 +9295,10 @@ class Vitest {
9387
9295
  return this.specifications.globTestSpecifications(filters);
9388
9296
  }
9389
9297
  async initCoverageProvider() {
9390
- if (this.coverageProvider === void 0) {
9391
- if (this.coverageProvider = await getCoverageProvider(this.config.coverage, this.runner), this.coverageProvider) await this.coverageProvider.initialize(this), this.config.coverage = this.coverageProvider.resolveOptions();
9392
- return this.coverageProvider;
9393
- }
9298
+ if (this._coverageProvider != null) return;
9299
+ const coverageConfig = this.configOverride.coverage ? this.getRootProject().serializedConfig.coverage : this.config.coverage;
9300
+ if (this._coverageProvider = await getCoverageProvider(coverageConfig, this.runner), this._coverageProvider) await this._coverageProvider.initialize(this), this.config.coverage = this._coverageProvider.resolveOptions();
9301
+ return this._coverageProvider;
9394
9302
  }
9395
9303
  /**
9396
9304
  * Merge reports from multiple runs located in the specified directory (value from `--merge-reports` if not specified).
@@ -9434,10 +9342,6 @@ class Vitest {
9434
9342
  unhandledErrors: []
9435
9343
  };
9436
9344
  }
9437
- /** @deprecated use `getRelevantTestSpecifications` instead */
9438
- listFiles(filters) {
9439
- return this.getRelevantTestSpecifications(filters);
9440
- }
9441
9345
  /**
9442
9346
  * Returns the list of test files that match the config and filters.
9443
9347
  * @param filters String filters to match the test files
@@ -9455,7 +9359,7 @@ class Vitest {
9455
9359
  */
9456
9360
  async start(filters) {
9457
9361
  try {
9458
- await this.initCoverageProvider(), await this.coverageProvider?.clean(this.config.coverage.clean);
9362
+ await this.initCoverageProvider(), await this.coverageProvider?.clean(this._coverageOptions.clean);
9459
9363
  } finally {
9460
9364
  await this.report("onInit", this);
9461
9365
  }
@@ -9481,23 +9385,13 @@ class Vitest {
9481
9385
  */
9482
9386
  async init() {
9483
9387
  try {
9484
- await this.initCoverageProvider(), await this.coverageProvider?.clean(this.config.coverage.clean);
9388
+ await this.initCoverageProvider(), await this.coverageProvider?.clean(this._coverageOptions.clean);
9485
9389
  } finally {
9486
9390
  await this.report("onInit", this);
9487
9391
  }
9488
9392
  if (await this.globTestSpecifications(), this.config.watch) await this.report("onWatcherStart");
9489
9393
  }
9490
9394
  /**
9491
- * @deprecated remove when vscode extension supports "getModuleSpecifications"
9492
- */
9493
- getProjectsByTestFile(file) {
9494
- return this.getModuleSpecifications(file);
9495
- }
9496
- /** @deprecated */
9497
- getFileWorkspaceSpecs(file) {
9498
- return this.getModuleSpecifications(file);
9499
- }
9500
- /**
9501
9395
  * If there is a test run happening, returns a promise that will
9502
9396
  * resolve when the test run is finished.
9503
9397
  */
@@ -9535,7 +9429,6 @@ class Vitest {
9535
9429
  * @param allTestsRun Indicates whether all tests were run. This only matters for coverage.
9536
9430
  */
9537
9431
  async rerunTestSpecifications(specifications, allTestsRun = false) {
9538
- this.configOverride.testNamePattern = void 0;
9539
9432
  const files = specifications.map((spec) => spec.moduleId);
9540
9433
  await Promise.all([this.report("onWatcherRerun", files, "rerun test"), ...this._onUserTestsRerun.map((fn) => fn(specifications))]);
9541
9434
  const result = await this.runTestSpecifications(specifications, allTestsRun);
@@ -9546,7 +9439,7 @@ class Vitest {
9546
9439
  try {
9547
9440
  if (!this.pool) this.pool = createPool(this);
9548
9441
  const invalidates = Array.from(this.watcher.invalidates);
9549
- if (this.watcher.invalidates.clear(), this.snapshot.clear(), this.state.clearErrors(), !this.isFirstRun && this.config.coverage.cleanOnRerun) await this.coverageProvider?.clean();
9442
+ if (this.watcher.invalidates.clear(), this.snapshot.clear(), this.state.clearErrors(), !this.isFirstRun && this._coverageOptions.cleanOnRerun) await this.coverageProvider?.clean();
9550
9443
  await this.initializeGlobalSetup(specs);
9551
9444
  try {
9552
9445
  await this.pool.runTests(specs, invalidates);
@@ -9755,17 +9648,13 @@ class Vitest {
9755
9648
  });
9756
9649
  });
9757
9650
  }
9758
- /** @deprecated use `invalidateFile` */
9759
- updateLastChanged(filepath) {
9760
- this.invalidateFile(filepath);
9761
- }
9762
9651
  /** @internal */
9763
9652
  _checkUnhandledErrors(errors) {
9764
9653
  if (errors.length && !this.config.dangerouslyIgnoreUnhandledErrors) process.exitCode = 1;
9765
9654
  }
9766
9655
  async reportCoverage(coverage, allTestsRun) {
9767
9656
  if (this.state.getCountOfFailedTests() > 0) {
9768
- if (await this.coverageProvider?.onTestFailure?.(), !this.config.coverage.reportOnFailure) return;
9657
+ if (await this.coverageProvider?.onTestFailure?.(), !this._coverageOptions.reportOnFailure) return;
9769
9658
  }
9770
9659
  if (this.coverageProvider) {
9771
9660
  await this.coverageProvider.reportCoverage(coverage, { allTestsRun });
@@ -9829,25 +9718,6 @@ class Vitest {
9829
9718
  return Array.from(new Set(specifications.map((spec) => spec.moduleId)));
9830
9719
  }
9831
9720
  /**
9832
- * @deprecated use `globTestSpecifications` instead
9833
- */
9834
- async globTestSpecs(filters = []) {
9835
- return this.globTestSpecifications(filters);
9836
- }
9837
- /**
9838
- * @deprecated use `globTestSpecifications` instead
9839
- */
9840
- async globTestFiles(filters = []) {
9841
- return this.globTestSpecifications(filters);
9842
- }
9843
- /** @deprecated filter by `this.projects` yourself */
9844
- getModuleProjects(filepath) {
9845
- return this.projects.filter((project) => {
9846
- return project.getModulesByFilepath(filepath).size;
9847
- // TODO: reevaluate || project.browser?.moduleGraph.getModulesByFile(id)?.size
9848
- });
9849
- }
9850
- /**
9851
9721
  * Should the server be kept running after the tests are done.
9852
9722
  */
9853
9723
  shouldKeepServer() {
@@ -10264,8 +10134,8 @@ function registerConsoleShortcuts(ctx, stdin = process.stdin, stdout) {
10264
10134
  async function inputFilePattern() {
10265
10135
  off();
10266
10136
  const watchFilter = new WatchFilter("Input filename pattern", stdin, stdout), filter = await watchFilter.filter(async (str) => {
10267
- const files = await ctx.globTestFiles([str]);
10268
- return files.map((file) => relative(ctx.config.root, file[1])).filter((file, index, all) => all.indexOf(file) === index);
10137
+ const specifications = await ctx.globTestSpecifications([str]);
10138
+ return specifications.map((specification) => relative(ctx.config.root, specification.moduleId)).filter((file, index, all) => all.indexOf(file) === index);
10269
10139
  });
10270
10140
  if (on(), typeof filter === "undefined") return;
10271
10141
  latestFilename = filter?.trim() || "";
@@ -10295,8 +10165,8 @@ function registerConsoleShortcuts(ctx, stdin = process.stdin, stdout) {
10295
10165
  */
10296
10166
  async function startVitest(mode, cliFilters = [], options = {}, viteOverrides, vitestOptions) {
10297
10167
  const root = resolve(options.root || process.cwd()), ctx = await prepareVitest(mode, options, viteOverrides, vitestOptions, cliFilters);
10298
- if (mode === "test" && ctx.config.coverage.enabled) {
10299
- const provider = ctx.config.coverage.provider || "v8", requiredPackages = CoverageProviderMap[provider];
10168
+ if (mode === "test" && ctx._coverageOptions.enabled) {
10169
+ const provider = ctx._coverageOptions.provider || "v8", requiredPackages = CoverageProviderMap[provider];
10300
10170
  if (requiredPackages) {
10301
10171
  if (!await ctx.packageInstaller.ensureInstalled(requiredPackages, root, ctx.version)) return process.exitCode = 1, ctx;
10302
10172
  }
@@ -2732,7 +2732,7 @@ function createForksPool(vitest, { execArgv, env }) {
2732
2732
  vitest.onCancel(() => pool.cancelPendingTasks());
2733
2733
  const configs = /* @__PURE__ */ new WeakMap(), getConfig = (project) => {
2734
2734
  if (configs.has(project)) return configs.get(project);
2735
- const _config = project.getSerializableConfig(), config = wrapSerializableConfig(_config);
2735
+ const _config = project.serializedConfig, config = wrapSerializableConfig(_config);
2736
2736
  return configs.set(project, config), config;
2737
2737
  }, singleFork = specs.filter((spec) => spec.project.config.poolOptions?.forks?.singleFork), multipleForks = specs.filter((spec) => !spec.project.config.poolOptions?.forks?.singleFork);
2738
2738
  if (multipleForks.length) {
@@ -3301,7 +3301,7 @@ function createPool(ctx) {
3301
3301
  typescript: () => createTypecheckPool(ctx)
3302
3302
  };
3303
3303
  for (const spec of files) {
3304
- const group = spec[0].config.sequence.groupOrder ?? 0;
3304
+ const group = spec.project.config.sequence.groupOrder ?? 0;
3305
3305
  groups.add(group), groupedSpecifications[group] ??= [], groupedSpecifications[group].push(spec);
3306
3306
  }
3307
3307
  const Sequencer = ctx.config.sequence.sequencer, sequencer = new Sequencer(ctx);
@@ -3324,7 +3324,7 @@ function createPool(ctx) {
3324
3324
  typescript: []
3325
3325
  };
3326
3326
  specifications.forEach((specification) => {
3327
- const pool = specification[2].pool;
3327
+ const pool = specification.pool;
3328
3328
  filesByPool[pool] ??= [], filesByPool[pool].push(specification);
3329
3329
  }), await Promise.all(Object.entries(filesByPool).map(async (entry) => {
3330
3330
  const [pool, files] = entry;
@@ -3749,7 +3749,7 @@ class BaseCoverageProvider {
3749
3749
  if (this.ctx = ctx, ctx.version !== this.version) ctx.logger.warn(c.yellow(`Loaded ${c.inverse(c.yellow(` vitest@${ctx.version} `))} and ${c.inverse(c.yellow(` @vitest/coverage-${this.name}@${this.version} `))}.
3750
3750
  Running mixed versions is not supported and may lead into bugs
3751
3751
  Update your dependencies and make sure the versions match.`));
3752
- const config = ctx.config.coverage;
3752
+ const config = ctx._coverageOptions;
3753
3753
  this.options = {
3754
3754
  ...coverageConfigDefaults,
3755
3755
  ...config,
@@ -3872,8 +3872,8 @@ Update your dependencies and make sure the versions match.`));
3872
3872
  async reportThresholds(coverageMap, allTestsRun) {
3873
3873
  const resolvedThresholds = this.resolveThresholds(coverageMap);
3874
3874
  if (this.checkThresholds(resolvedThresholds), this.options.thresholds?.autoUpdate && allTestsRun) {
3875
- if (!this.ctx.server.config.configFile) throw new Error("Missing configurationFile. The \"coverage.thresholds.autoUpdate\" can only be enabled when configuration file is used.");
3876
- const configFilePath = this.ctx.server.config.configFile, configModule = await this.parseConfigModule(configFilePath);
3875
+ if (!this.ctx.vite.config.configFile) throw new Error("Missing configurationFile. The \"coverage.thresholds.autoUpdate\" can only be enabled when configuration file is used.");
3876
+ const configFilePath = this.ctx.vite.config.configFile, configModule = await this.parseConfigModule(configFilePath);
3877
3877
  await this.updateThresholds({
3878
3878
  thresholds: resolvedThresholds,
3879
3879
  configurationFile: configModule,
@@ -1156,9 +1156,13 @@ function printErrorInner(error, project, options) {
1156
1156
  return;
1157
1157
  }
1158
1158
  const stacks = options.parseErrorStacktrace(e), nearest = error instanceof TypeCheckError ? error.stacks[0] : stacks.find((stack) => {
1159
+ // we are checking that this module was processed by us at one point
1159
1160
  try {
1160
- const module = project._vite && project.getModuleById(stack.file);
1161
- return (module?.transformResult || module?.ssrTransformResult) && existsSync(stack.file);
1161
+ const environments = [...Object.values(project._vite?.environments || {}), ...Object.values(project.browser?.vite.environments || {})], hasResult = environments.some((environment) => {
1162
+ const modules = environment.moduleGraph.getModulesByFile(stack.file);
1163
+ return [...modules?.values() || []].some((module) => !!module.transformResult);
1164
+ });
1165
+ return hasResult && existsSync(stack.file);
1162
1166
  } catch {
1163
1167
  return false;
1164
1168
  }
@@ -2,7 +2,7 @@ import fs from 'node:fs';
2
2
  import { getTasks, getFullName, getTests } from '@vitest/runner/utils';
3
3
  import * as pathe from 'pathe';
4
4
  import c from 'tinyrainbow';
5
- import { g as getStateSymbol, t as truncateString, F as F_RIGHT, D as DefaultReporter, f as formatProjectName } from './index.C3EbxYwt.js';
5
+ import { g as getStateSymbol, t as truncateString, F as F_RIGHT, D as DefaultReporter, f as formatProjectName } from './index.AzwzFtyi.js';
6
6
  import { stripVTControlCharacters } from 'node:util';
7
7
  import { notNullish } from '@vitest/utils';
8
8
 
@@ -1,4 +1,4 @@
1
- import { V as Vitest, T as TestProject, a as TestProjectConfiguration } from './reporters.d.BC86JJdB.js';
1
+ import { V as Vitest, T as TestProject, a as TestProjectConfiguration } from './reporters.d.37tJQ2uV.js';
2
2
 
3
3
  interface VitestPluginContext {
4
4
  vitest: Vitest;