vitest 2.1.4 → 2.2.0-beta.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 (46) hide show
  1. package/dist/browser.d.ts +11 -11
  2. package/dist/browser.js +1 -1
  3. package/dist/chunks/{base.C3xNdjV6.js → base.BS0HhLXd.js} +1 -1
  4. package/dist/chunks/{cac.DrfPaMvZ.js → cac.Z91LBqmg.js} +56 -7
  5. package/dist/chunks/{cli-api.CKrRYkw8.js → cli-api.DVJJMJHj.js} +123 -80
  6. package/dist/chunks/{config.Crbj2GAb.d.ts → config.CPguQ7J1.d.ts} +2 -2
  7. package/dist/chunks/{environment.LoooBwUu.d.ts → environment.CT0jpO-1.d.ts} +2 -1
  8. package/dist/chunks/{globals.Bp645TTJ.js → globals.BCGEw6ON.js} +2 -2
  9. package/dist/chunks/{index.D3d79vc8.js → index.BjjsHdBb.js} +1 -1
  10. package/dist/chunks/{index.Dqe5k2Rk.js → index.DD5eTY2y.js} +2 -8
  11. package/dist/chunks/{index.Bn81VaWg.js → index.DLRzErGF.js} +240 -318
  12. package/dist/chunks/{index.BMoXz_-n.js → index.K90BXFOx.js} +1 -1
  13. package/dist/chunks/{reporters.anwo7Y6a.d.ts → reporters.B_9uUTGW.d.ts} +148 -22
  14. package/dist/chunks/{resolveConfig.DPmbhVlP.js → resolveConfig.CQIc6fe7.js} +8 -4
  15. package/dist/chunks/{runBaseTests.Dm-659zB.js → runBaseTests.B7hcVT-s.js} +4 -4
  16. package/dist/chunks/{setup-common.DDmVKp6O.js → setup-common.BfGt8K-K.js} +4 -1
  17. package/dist/chunks/{utils.BB4zjzR8.js → utils.DNoFbBUZ.js} +6 -2
  18. package/dist/chunks/{vi.JMQoNY_Z.js → vi.BlPttogV.js} +91 -4
  19. package/dist/chunks/{vite.BdBj-UWY.d.ts → vite.Bvms8Xir.d.ts} +1 -1
  20. package/dist/chunks/{vm.jpyrB0xy.js → vm.Zr4qWzDJ.js} +3 -0
  21. package/dist/chunks/{worker.BAlI9hII.d.ts → worker.9VY11NZs.d.ts} +3 -2
  22. package/dist/chunks/{worker.DHnGaO2M.d.ts → worker.Qz1UB4Fv.d.ts} +1 -1
  23. package/dist/cli.js +1 -1
  24. package/dist/config.d.ts +10 -9
  25. package/dist/coverage.d.ts +9 -112
  26. package/dist/coverage.js +1 -1
  27. package/dist/environments.d.ts +2 -2
  28. package/dist/environments.js +1 -1
  29. package/dist/execute.d.ts +4 -3
  30. package/dist/index.d.ts +39 -10
  31. package/dist/index.js +2 -2
  32. package/dist/node.d.ts +13 -11
  33. package/dist/node.js +7 -7
  34. package/dist/reporters.d.ts +10 -9
  35. package/dist/reporters.js +2 -2
  36. package/dist/runners.d.ts +3 -1
  37. package/dist/runners.js +4 -1
  38. package/dist/worker.js +6 -2
  39. package/dist/workers/forks.js +1 -1
  40. package/dist/workers/runVmTests.js +4 -4
  41. package/dist/workers/threads.js +1 -1
  42. package/dist/workers/vmForks.js +1 -1
  43. package/dist/workers/vmThreads.js +1 -1
  44. package/dist/workers.d.ts +5 -4
  45. package/dist/workers.js +4 -3
  46. package/package.json +15 -15
@@ -1,5 +1,5 @@
1
1
  import { existsSync, promises, readFileSync, mkdirSync, writeFileSync } from 'node:fs';
2
- import { createFileTask, getTasks, hasFailed, getTests, getNames } from '@vitest/runner/utils';
2
+ import { createFileTask, limitConcurrency, getTasks, hasFailed, getTests, getNames } from '@vitest/runner/utils';
3
3
  import { normalize, relative, dirname, resolve, join, basename, isAbsolute } from 'pathe';
4
4
  import { g as getCoverageProvider, C as CoverageProviderMap } from './coverage.BoMDb1ip.js';
5
5
  import a, { resolve as resolve$1 } from 'node:path';
@@ -8,12 +8,12 @@ import { f as findUp, p as prompt } from './index.BJDntFik.js';
8
8
  import { searchForWorkspaceRoot, version, createServer, mergeConfig } from 'vite';
9
9
  import { A as API_PATH, c as configFiles, a as defaultBrowserPort, w as workspacesFiles, d as defaultPort } from './constants.fzPh7AOq.js';
10
10
  import { SnapshotManager } from '@vitest/snapshot/manager';
11
- import { i as isPackageExists, e as requireMicromatch, V as VitestCache, f as configDefaults, m as mm, b as resolveConfig, h as isBrowserEnabled, w as wildcardPatternToRegExp, g as getFilePoolName, j as createPool, a as resolveApiServerConfig, c as coverageConfigDefaults, s as stdout } from './resolveConfig.DPmbhVlP.js';
11
+ import { i as isPackageExists, e as requireMicromatch, V as VitestCache, f as configDefaults, m as mm, b as resolveConfig, h as isBrowserEnabled, w as wildcardPatternToRegExp, g as getFilePoolName, j as createPool, a as resolveApiServerConfig, c as coverageConfigDefaults, s as stdout } from './resolveConfig.CQIc6fe7.js';
12
12
  import { ViteNodeRunner } from 'vite-node/client';
13
13
  import { ViteNodeServer } from 'vite-node/server';
14
- import { v as version$1 } from './cac.DrfPaMvZ.js';
14
+ import { v as version$1 } from './cac.Z91LBqmg.js';
15
15
  import { c as createBirpc } from './index.68735LiX.js';
16
- import { s as stringify, p as parse, R as ReportersMap, h as BenchmarkReportsMap, f as TestModule, g as TestSuite, e as TestCase, j as generateCodeFrame, i as TestProject, L as Logger, k as BlobReporter, r as readBlobs } from './index.Bn81VaWg.js';
16
+ import { s as stringify, p as parse, R as ReportersMap, h as BenchmarkReportsMap, f as TestModule, g as TestSuite, e as TestCase, j as generateCodeFrame, i as TestProject, L as Logger, k as BlobReporter, r as readBlobs } from './index.DLRzErGF.js';
17
17
  import require$$0$2 from 'stream';
18
18
  import require$$0 from 'zlib';
19
19
  import require$$0$1 from 'buffer';
@@ -33,14 +33,13 @@ import c from 'tinyrainbow';
33
33
  import { h as hash, i as isWindows } from './RandomSequencer.CMRlh2v4.js';
34
34
  import { isCI } from 'std-env';
35
35
  import { rm } from 'node:fs/promises';
36
- import { tmpdir } from 'node:os';
36
+ import nodeos__default, { tmpdir } from 'node:os';
37
37
  import require$$0$4 from 'os';
38
38
  import require$$0$5 from 'path';
39
39
  import require$$0$6 from 'fs';
40
40
  import { normalizeRequestId, cleanUrl } from 'vite-node/utils';
41
41
  import { hoistMocksPlugin, automockPlugin } from '@vitest/mocker/node';
42
42
  import MagicString from 'magic-string';
43
- import { isMainThread } from 'node:worker_threads';
44
43
  import readline from 'node:readline';
45
44
  import { stripVTControlCharacters } from 'node:util';
46
45
 
@@ -5220,6 +5219,7 @@ class StateManager {
5220
5219
  task.mode = "skip";
5221
5220
  task.result ??= { state: "skip" };
5222
5221
  task.result.state = "skip";
5222
+ task.result.note = _err.note;
5223
5223
  }
5224
5224
  return;
5225
5225
  }
@@ -8560,6 +8560,7 @@ function serializeConfig(config, coreConfig, viteConfig) {
8560
8560
  pool: config.pool,
8561
8561
  expect: config.expect,
8562
8562
  snapshotSerializers: config.snapshotSerializers,
8563
+ // TODO: non serializable function?
8563
8564
  diff: config.diff,
8564
8565
  retry: config.retry,
8565
8566
  disableConsoleIntercept: config.disableConsoleIntercept,
@@ -9705,6 +9706,18 @@ function WorkspaceVitestPlugin(project, options) {
9705
9706
  )
9706
9707
  }
9707
9708
  },
9709
+ // eslint-disable-next-line ts/ban-ts-comment
9710
+ // @ts-ignore Vite 6 compat
9711
+ environments: {
9712
+ ssr: {
9713
+ resolve: {
9714
+ // by default Vite resolves `module` field, which not always a native ESM module
9715
+ // setting this option can bypass that and fallback to cjs version
9716
+ mainFields: [],
9717
+ conditions: ["node"]
9718
+ }
9719
+ }
9720
+ },
9708
9721
  test: {
9709
9722
  name
9710
9723
  }
@@ -9894,7 +9907,8 @@ class WorkspaceProject {
9894
9907
  for (const globalSetupFile of this._globalSetups) {
9895
9908
  const teardown = await globalSetupFile.setup?.({
9896
9909
  provide: (key, value) => this.provide(key, value),
9897
- config: this.config
9910
+ config: this.config,
9911
+ onTestsRerun: (cb) => this.ctx.onTestsRerun(cb)
9898
9912
  });
9899
9913
  if (teardown == null || !!globalSetupFile.teardown) {
9900
9914
  continue;
@@ -10028,16 +10042,15 @@ class WorkspaceProject {
10028
10042
  }
10029
10043
  return testFiles;
10030
10044
  }
10031
- async initBrowserServer(configFile) {
10032
- if (!this.isBrowserEnabled()) {
10045
+ async initBrowserServer() {
10046
+ if (!this.isBrowserEnabled() || this.browser) {
10033
10047
  return;
10034
10048
  }
10035
10049
  await this.ctx.packageInstaller.ensureInstalled("@vitest/browser", this.config.root, this.ctx.version);
10036
10050
  const { createBrowserServer, distRoot } = await import('@vitest/browser');
10037
- await this.browser?.close();
10038
10051
  const browser = await createBrowserServer(
10039
10052
  this,
10040
- configFile,
10053
+ this.server.config.configFile,
10041
10054
  [
10042
10055
  ...MocksPlugins({
10043
10056
  filter(id) {
@@ -10075,9 +10088,7 @@ class WorkspaceProject {
10075
10088
  return project;
10076
10089
  }
10077
10090
  static async createCoreProject(ctx) {
10078
- const project = WorkspaceProject.createBasicProject(ctx);
10079
- await project.initBrowserServer(ctx.server.config.configFile);
10080
- return project;
10091
+ return WorkspaceProject.createBasicProject(ctx);
10081
10092
  }
10082
10093
  async setServer(options, server) {
10083
10094
  this.config = resolveConfig(
@@ -10096,6 +10107,7 @@ class WorkspaceProject {
10096
10107
  this.config.provide[providedKey]
10097
10108
  );
10098
10109
  }
10110
+ this.closingPromise = void 0;
10099
10111
  this.testProject = new TestProject(this);
10100
10112
  this.server = server;
10101
10113
  this.vitenode = new ViteNodeServer(server, this.config.server);
@@ -10110,7 +10122,6 @@ class WorkspaceProject {
10110
10122
  return node.resolveId(id, importer);
10111
10123
  }
10112
10124
  });
10113
- await this.initBrowserServer(this.server.config.configFile);
10114
10125
  }
10115
10126
  isBrowserEnabled() {
10116
10127
  return isBrowserEnabled(this.config);
@@ -10133,7 +10144,7 @@ class WorkspaceProject {
10133
10144
  if (!this.closingPromise) {
10134
10145
  this.closingPromise = Promise.all(
10135
10146
  [
10136
- this.server.close(),
10147
+ this.server?.close(),
10137
10148
  this.typechecker?.stop(),
10138
10149
  this.browser?.close(),
10139
10150
  this.clearTmpDir()
@@ -10149,9 +10160,12 @@ class WorkspaceProject {
10149
10160
  }
10150
10161
  }
10151
10162
  async initBrowserProvider() {
10152
- if (!this.isBrowserEnabled()) {
10163
+ if (!this.isBrowserEnabled() || this.browser?.provider) {
10153
10164
  return;
10154
10165
  }
10166
+ if (!this.browser) {
10167
+ await this.initBrowserServer();
10168
+ }
10155
10169
  await this.browser?.initBrowserProvider();
10156
10170
  }
10157
10171
  }
@@ -10222,48 +10236,33 @@ async function resolveWorkspace(vitest, cliOptions, workspaceConfigPath, workspa
10222
10236
  }
10223
10237
  return acc;
10224
10238
  }, {});
10225
- const cwd = process.cwd();
10226
- const projects = [];
10239
+ const projectPromises = [];
10227
10240
  const fileProjects = [...configFiles, ...nonConfigDirectories];
10228
- try {
10229
- for (const filepath of fileProjects) {
10230
- if (vitest.server.config.configFile === filepath) {
10231
- const project = await vitest._createCoreProject();
10232
- projects.push(project);
10233
- continue;
10234
- }
10235
- const directory = filepath.endsWith("/") ? filepath.slice(0, -1) : dirname(filepath);
10236
- if (isMainThread) {
10237
- process.chdir(directory);
10238
- }
10239
- projects.push(
10240
- await initializeProject(
10241
- filepath,
10242
- vitest,
10243
- { workspaceConfigPath, test: cliOverrides }
10244
- )
10245
- );
10246
- }
10247
- } finally {
10248
- if (isMainThread) {
10249
- process.chdir(cwd);
10241
+ const concurrent = limitConcurrency(nodeos__default.availableParallelism?.() || nodeos__default.cpus().length || 5);
10242
+ for (const filepath of fileProjects) {
10243
+ if (vitest.server.config.configFile === filepath) {
10244
+ projectPromises.push(concurrent(() => vitest._createCoreProject()));
10245
+ continue;
10250
10246
  }
10247
+ projectPromises.push(
10248
+ concurrent(() => initializeProject(
10249
+ filepath,
10250
+ vitest,
10251
+ { workspaceConfigPath, test: cliOverrides }
10252
+ ))
10253
+ );
10251
10254
  }
10252
- const projectPromises = [];
10253
10255
  projectConfigs.forEach((options, index) => {
10254
- projectPromises.push(initializeProject(
10256
+ projectPromises.push(concurrent(() => initializeProject(
10255
10257
  index,
10256
10258
  vitest,
10257
10259
  mergeConfig(options, { workspaceConfigPath, test: cliOverrides })
10258
- ));
10260
+ )));
10259
10261
  });
10260
- if (!projects.length && !projectPromises.length) {
10262
+ if (!projectPromises.length) {
10261
10263
  return [await vitest._createCoreProject()];
10262
10264
  }
10263
- const resolvedProjects = await Promise.all([
10264
- ...projects,
10265
- ...projectPromises
10266
- ]);
10265
+ const resolvedProjects = await Promise.all(projectPromises);
10267
10266
  const names = /* @__PURE__ */ new Set();
10268
10267
  for (const project of resolvedProjects) {
10269
10268
  const name = project.getName();
@@ -10407,10 +10406,12 @@ class Vitest {
10407
10406
  runner = void 0;
10408
10407
  packageInstaller;
10409
10408
  coreWorkspaceProject;
10409
+ /** @private */
10410
10410
  resolvedProjects = [];
10411
10411
  projects = [];
10412
10412
  distPath = distDir;
10413
10413
  _cachedSpecs = /* @__PURE__ */ new Map();
10414
+ _workspaceConfigPath;
10414
10415
  /** @deprecated use `_cachedSpecs` */
10415
10416
  projectTestFiles = this._cachedSpecs;
10416
10417
  /** @private */
@@ -10419,6 +10420,7 @@ class Vitest {
10419
10420
  _onClose = [];
10420
10421
  _onSetServer = [];
10421
10422
  _onCancelListeners = [];
10423
+ _onUserTestsRerun = [];
10422
10424
  async setServer(options, server, cliOptions) {
10423
10425
  this.unregisterWatcher?.();
10424
10426
  clearTimeout(this._rerunTimer);
@@ -10426,9 +10428,14 @@ class Vitest {
10426
10428
  this._browserLastPort = defaultBrowserPort;
10427
10429
  this.pool?.close?.();
10428
10430
  this.pool = void 0;
10431
+ this.closingPromise = void 0;
10432
+ this.projects = [];
10433
+ this.resolvedProjects = [];
10434
+ this._workspaceConfigPath = void 0;
10429
10435
  this.coverageProvider = void 0;
10430
10436
  this.runningPromise = void 0;
10431
10437
  this._cachedSpecs.clear();
10438
+ this._onUserTestsRerun = [];
10432
10439
  const resolved = resolveConfig(this.mode, options, server.config, this.logger);
10433
10440
  this.server = server;
10434
10441
  this.config = resolved;
@@ -10454,18 +10461,18 @@ class Vitest {
10454
10461
  const serverRestart = server.restart;
10455
10462
  server.restart = async (...args) => {
10456
10463
  await Promise.all(this._onRestartListeners.map((fn) => fn()));
10464
+ this.report("onServerRestart");
10465
+ await this.close();
10457
10466
  await serverRestart(...args);
10458
- this.unregisterWatcher();
10459
- this.registerWatcher();
10460
10467
  };
10461
10468
  server.watcher.on("change", async (file) => {
10462
10469
  file = normalize(file);
10463
- const isConfig = file === server.config.configFile;
10470
+ const isConfig = file === server.config.configFile || this.resolvedProjects.some((p) => p.server.config.configFile === file) || file === this._workspaceConfigPath;
10464
10471
  if (isConfig) {
10465
10472
  await Promise.all(this._onRestartListeners.map((fn) => fn("config")));
10473
+ this.report("onServerRestart", "config");
10474
+ await this.close();
10466
10475
  await serverRestart();
10467
- this.unregisterWatcher();
10468
- this.registerWatcher();
10469
10476
  }
10470
10477
  });
10471
10478
  }
@@ -10475,7 +10482,6 @@ class Vitest {
10475
10482
  await this.cache.results.readFromCache();
10476
10483
  } catch {
10477
10484
  }
10478
- await Promise.all(this._onSetServer.map((fn) => fn()));
10479
10485
  const projects = await this.resolveWorkspace(cliOptions);
10480
10486
  this.resolvedProjects = projects;
10481
10487
  this.projects = projects;
@@ -10491,6 +10497,7 @@ class Vitest {
10491
10497
  if (this.config.testNamePattern) {
10492
10498
  this.configOverride.testNamePattern = this.config.testNamePattern;
10493
10499
  }
10500
+ await Promise.all(this._onSetServer.map((fn) => fn()));
10494
10501
  }
10495
10502
  provide(key, value) {
10496
10503
  this.getCoreWorkspaceProject().provide(key, value);
@@ -10532,12 +10539,13 @@ class Vitest {
10532
10539
  return rootFiles.includes(configFile);
10533
10540
  });
10534
10541
  if (!workspaceConfigName) {
10535
- return null;
10542
+ return void 0;
10536
10543
  }
10537
10544
  return join(configDir, workspaceConfigName);
10538
10545
  }
10539
10546
  async resolveWorkspace(cliOptions) {
10540
10547
  const workspaceConfigPath = await this.getWorkspaceConfigPath();
10548
+ this._workspaceConfigPath = workspaceConfigPath;
10541
10549
  if (!workspaceConfigPath) {
10542
10550
  return [await this._createCoreProject()];
10543
10551
  }
@@ -10566,9 +10574,6 @@ class Vitest {
10566
10574
  }
10567
10575
  return this.coverageProvider;
10568
10576
  }
10569
- async initBrowserProviders() {
10570
- return Promise.all(this.projects.map((w) => w.initBrowserProvider()));
10571
- }
10572
10577
  async mergeReports() {
10573
10578
  if (this.reporters.some((r) => r instanceof BlobReporter)) {
10574
10579
  throw new Error("Cannot merge reports when `--reporter=blob` is used. Remove blob reporter from the config first.");
@@ -10611,13 +10616,13 @@ class Vitest {
10611
10616
  if (hasFailed(files)) {
10612
10617
  process.exitCode = 1;
10613
10618
  }
10619
+ this.checkUnhandledErrors(errors);
10614
10620
  await this.report("onFinished", files, errors);
10615
10621
  await this.initCoverageProvider();
10616
10622
  await this.coverageProvider?.mergeReports?.(coverages);
10617
10623
  }
10618
10624
  async collect(filters) {
10619
10625
  this._onClose = [];
10620
- await this.initBrowserProviders();
10621
10626
  const files = await this.filterTestsBySource(
10622
10627
  await this.globTestFiles(filters)
10623
10628
  );
@@ -10641,7 +10646,6 @@ class Vitest {
10641
10646
  try {
10642
10647
  await this.initCoverageProvider();
10643
10648
  await this.coverageProvider?.clean(this.config.coverage.clean);
10644
- await this.initBrowserProviders();
10645
10649
  } finally {
10646
10650
  await this.report("onInit", this);
10647
10651
  }
@@ -10671,7 +10675,6 @@ class Vitest {
10671
10675
  try {
10672
10676
  await this.initCoverageProvider();
10673
10677
  await this.coverageProvider?.clean(this.config.coverage.clean);
10674
- await this.initBrowserProviders();
10675
10678
  } finally {
10676
10679
  await this.report("onInit", this);
10677
10680
  }
@@ -10809,8 +10812,10 @@ class Vitest {
10809
10812
  await this.cache.results.writeToCache();
10810
10813
  })().finally(async () => {
10811
10814
  const files = Array.from(new Set(specs.map((spec) => spec.moduleId)));
10815
+ const errors = this.state.getUnhandledErrors();
10812
10816
  const coverage = await this.coverageProvider?.generateCoverage({ allTestsRun });
10813
- await this.report("onFinished", this.state.getFiles(files), this.state.getUnhandledErrors(), coverage);
10817
+ this.checkUnhandledErrors(errors);
10818
+ await this.report("onFinished", this.state.getFiles(files), errors, coverage);
10814
10819
  await this.reportCoverage(coverage, allTestsRun);
10815
10820
  this.runningPromise = void 0;
10816
10821
  this.isFirstRun = false;
@@ -10854,13 +10859,19 @@ class Vitest {
10854
10859
  this.isCancelling = true;
10855
10860
  await Promise.all(this._onCancelListeners.splice(0).map((listener) => listener(reason)));
10856
10861
  }
10857
- async rerunFiles(files = this.state.getFilepaths(), trigger) {
10862
+ async initBrowserServers() {
10863
+ await Promise.all(this.projects.map((p) => p.initBrowserServer()));
10864
+ }
10865
+ async rerunFiles(files = this.state.getFilepaths(), trigger, allTestsRun = true) {
10858
10866
  if (this.filenamePattern) {
10859
10867
  const filteredFiles = await this.globTestFiles([this.filenamePattern]);
10860
10868
  files = files.filter((file) => filteredFiles.some((f) => f[1] === file));
10861
10869
  }
10862
- await this.report("onWatcherRerun", files, trigger);
10863
- await this.runFiles(files.flatMap((file) => this.getProjectsByTestFile(file)), !trigger);
10870
+ await Promise.all([
10871
+ this.report("onWatcherRerun", files, trigger),
10872
+ ...this._onUserTestsRerun.map((fn) => fn(files))
10873
+ ]);
10874
+ await this.runFiles(files.flatMap((file) => this.getProjectsByTestFile(file)), allTestsRun);
10864
10875
  await this.report("onWatcherStart", this.state.getFiles(files));
10865
10876
  }
10866
10877
  async changeProjectName(pattern) {
@@ -10871,7 +10882,7 @@ class Vitest {
10871
10882
  }
10872
10883
  this.projects = this.resolvedProjects.filter((p) => p.getName() === pattern);
10873
10884
  const files = (await this.globTestSpecs()).map((spec) => spec.moduleId);
10874
- await this.rerunFiles(files, "change project filter");
10885
+ await this.rerunFiles(files, "change project filter", pattern === "");
10875
10886
  }
10876
10887
  async changeNamePattern(pattern, files = this.state.getFilepaths(), trigger) {
10877
10888
  if (pattern === "") {
@@ -10888,15 +10899,15 @@ class Vitest {
10888
10899
  });
10889
10900
  });
10890
10901
  }
10891
- await this.rerunFiles(files, trigger);
10902
+ await this.rerunFiles(files, trigger, pattern === "");
10892
10903
  }
10893
10904
  async changeFilenamePattern(pattern, files = this.state.getFilepaths()) {
10894
10905
  this.filenamePattern = pattern;
10895
10906
  const trigger = this.filenamePattern ? "change filename pattern" : "reset filename pattern";
10896
- await this.rerunFiles(files, trigger);
10907
+ await this.rerunFiles(files, trigger, pattern === "");
10897
10908
  }
10898
10909
  async rerunFailed() {
10899
- await this.rerunFiles(this.state.getFailedFilepaths(), "rerun failed");
10910
+ await this.rerunFiles(this.state.getFailedFilepaths(), "rerun failed", false);
10900
10911
  }
10901
10912
  async updateSnapshot(files) {
10902
10913
  files = files || [
@@ -10909,7 +10920,7 @@ class Vitest {
10909
10920
  snapshotEnvironment: null
10910
10921
  };
10911
10922
  try {
10912
- await this.rerunFiles(files, "update snapshot");
10923
+ await this.rerunFiles(files, "update snapshot", false);
10913
10924
  } finally {
10914
10925
  delete this.configOverride.snapshotOptions;
10915
10926
  }
@@ -10951,7 +10962,10 @@ class Vitest {
10951
10962
  this.changedTests.clear();
10952
10963
  const triggerIds = new Set(triggerId.map((id) => relative(this.config.root, id)));
10953
10964
  const triggerLabel = Array.from(triggerIds).join(", ");
10954
- await this.report("onWatcherRerun", files, triggerLabel);
10965
+ await Promise.all([
10966
+ this.report("onWatcherRerun", files, triggerLabel),
10967
+ ...this._onUserTestsRerun.map((fn) => fn(files))
10968
+ ]);
10955
10969
  await this.runFiles(files.flatMap((file) => this.getProjectsByTestFile(file)), false);
10956
10970
  await this.report("onWatcherStart", this.state.getFiles(files));
10957
10971
  }, WATCHER_DEBOUNCE);
@@ -11021,6 +11035,11 @@ class Vitest {
11021
11035
  }
11022
11036
  }
11023
11037
  };
11038
+ checkUnhandledErrors(errors) {
11039
+ if (errors.length && !this.config.dangerouslyIgnoreUnhandledErrors) {
11040
+ process.exitCode = 1;
11041
+ }
11042
+ }
11024
11043
  unregisterWatcher = noop;
11025
11044
  registerWatcher() {
11026
11045
  const watcher = this.server.watcher;
@@ -11219,6 +11238,9 @@ class Vitest {
11219
11238
  onClose(fn) {
11220
11239
  this._onClose.push(fn);
11221
11240
  }
11241
+ onTestsRerun(fn) {
11242
+ this._onUserTestsRerun.push(fn);
11243
+ }
11222
11244
  }
11223
11245
 
11224
11246
  async function VitestPlugin(options = {}, ctx = new Vitest("test")) {
@@ -11287,6 +11309,18 @@ async function VitestPlugin(options = {}, ctx = new Vitest("test")) {
11287
11309
  // https://github.com/vitejs/vite/pull/16453
11288
11310
  emptyOutDir: false
11289
11311
  },
11312
+ // eslint-disable-next-line ts/ban-ts-comment
11313
+ // @ts-ignore Vite 6 compat
11314
+ environments: {
11315
+ ssr: {
11316
+ resolve: {
11317
+ // by default Vite resolves `module` field, which not always a native ESM module
11318
+ // setting this option can bypass that and fallback to cjs version
11319
+ mainFields: [],
11320
+ conditions: ["node"]
11321
+ }
11322
+ }
11323
+ },
11290
11324
  test: {
11291
11325
  poolOptions: {
11292
11326
  threads: {
@@ -11477,9 +11511,9 @@ class WatchFilter {
11477
11511
  break;
11478
11512
  case (key?.ctrl && key?.name === "c"):
11479
11513
  case key?.name === "escape":
11480
- this.cancel();
11514
+ this.write(`${ESC}1G${ESC}0J`);
11481
11515
  onSubmit(void 0);
11482
- break;
11516
+ return;
11483
11517
  case key?.name === "enter":
11484
11518
  case key?.name === "return":
11485
11519
  onSubmit(
@@ -11583,9 +11617,6 @@ ${resultBody}`;
11583
11617
  const cursortPos = this.keywordOffset() + (this.currentKeyword?.length || 0);
11584
11618
  this.write(`${ESC}${cursortPos}G`);
11585
11619
  }
11586
- cancel() {
11587
- this.write(`${ESC}J`);
11588
- }
11589
11620
  write(data) {
11590
11621
  this.stdout.write(data);
11591
11622
  }
@@ -11602,6 +11633,7 @@ const keys = [
11602
11633
  ["p", "filter by a filename"],
11603
11634
  ["t", "filter by a test name regex pattern"],
11604
11635
  ["w", "filter by a project name"],
11636
+ ["b", "start the browser server if not started yet"],
11605
11637
  ["q", "quit"]
11606
11638
  ];
11607
11639
  const cancelKeys = ["space", "c", "h", ...keys.map((key) => key[0]).flat()];
@@ -11670,6 +11702,14 @@ function registerConsoleShortcuts(ctx, stdin = process.stdin, stdout2) {
11670
11702
  if (name === "p") {
11671
11703
  return inputFilePattern();
11672
11704
  }
11705
+ if (name === "b") {
11706
+ await ctx.initBrowserServers();
11707
+ ctx.projects.forEach((project) => {
11708
+ ctx.logger.log();
11709
+ ctx.logger.printBrowserBanner(project);
11710
+ });
11711
+ return null;
11712
+ }
11673
11713
  }
11674
11714
  async function keypressHandler(str, key) {
11675
11715
  await _keypressHandler(str, key);
@@ -11692,6 +11732,9 @@ function registerConsoleShortcuts(ctx, stdin = process.stdin, stdout2) {
11692
11732
  }
11693
11733
  });
11694
11734
  on();
11735
+ if (typeof filter === "undefined") {
11736
+ return;
11737
+ }
11695
11738
  const files = ctx.state.getFilepaths();
11696
11739
  const cliFiles = ctx.config.standalone && !files.length ? await ctx.getTestFilepaths() : void 0;
11697
11740
  await ctx.changeNamePattern(
@@ -11725,6 +11768,9 @@ function registerConsoleShortcuts(ctx, stdin = process.stdin, stdout2) {
11725
11768
  return files.map((file) => relative(ctx.config.root, file[1]));
11726
11769
  });
11727
11770
  on();
11771
+ if (typeof filter === "undefined") {
11772
+ return;
11773
+ }
11728
11774
  latestFilename = filter?.trim() || "";
11729
11775
  const lastResults = watchFilter.getLastResults();
11730
11776
  await ctx.changeFilenamePattern(
@@ -11780,9 +11826,6 @@ async function startVitest(mode, cliFilters = [], options = {}, viteOverrides, v
11780
11826
  if (stdin.isTTY && ctx.config.watch) {
11781
11827
  stdinCleanup = registerConsoleShortcuts(ctx, stdin, stdout);
11782
11828
  }
11783
- ctx.onServerRestart((reason) => {
11784
- ctx.report("onServerRestart", reason);
11785
- });
11786
11829
  ctx.onAfterSetServer(() => {
11787
11830
  if (ctx.config.standalone) {
11788
11831
  ctx.init();
@@ -2,6 +2,7 @@ import { PrettyFormatOptions } from '@vitest/pretty-format';
2
2
  import { SequenceHooks, SequenceSetupFiles } from '@vitest/runner';
3
3
  import { SnapshotUpdateState } from '@vitest/snapshot';
4
4
  import { SnapshotEnvironment } from '@vitest/snapshot/environment';
5
+ import { SerializedDiffOptions } from '@vitest/utils/diff';
5
6
 
6
7
  /**
7
8
  * Names of clock methods that may be faked by install.
@@ -154,7 +155,7 @@ interface SerializedConfig {
154
155
  showDiff?: boolean;
155
156
  truncateThreshold?: number;
156
157
  } | undefined;
157
- diff: string | undefined;
158
+ diff: string | SerializedDiffOptions | undefined;
158
159
  retry: number;
159
160
  includeTaskLocation: boolean | undefined;
160
161
  inspect: boolean | string | undefined;
@@ -200,7 +201,6 @@ interface SerializedCoverageConfig {
200
201
  }
201
202
  type RuntimeConfig = Pick<SerializedConfig, 'allowOnly' | 'testTimeout' | 'hookTimeout' | 'clearMocks' | 'mockReset' | 'restoreMocks' | 'fakeTimers' | 'maxConcurrency' | 'expect' | 'printConsoleTrace'> & {
202
203
  sequence?: {
203
- concurrent?: boolean;
204
204
  hooks?: SequenceHooks;
205
205
  };
206
206
  };
@@ -36,6 +36,7 @@ interface ModuleGraphData {
36
36
  inlined: string[];
37
37
  }
38
38
  type OnServerRestartHandler = (reason?: string) => Promise<void> | void;
39
+ type OnTestsRerunHandler = (testFiles: string[]) => Promise<void> | void;
39
40
  interface ProvidedContext {
40
41
  }
41
42
 
@@ -171,4 +172,4 @@ interface ResolvedTestEnvironment {
171
172
  options: Record<string, any> | null;
172
173
  }
173
174
 
174
- export type { AfterSuiteRunMeta as A, Constructable as C, Environment as E, HappyDOMOptions as H, JSDOMOptions as J, ModuleGraphData as M, Nullable as N, OnServerRestartHandler as O, ProvidedContext as P, ResolvedTestEnvironment as R, TransformMode as T, UserConsoleLog as U, VmEnvironmentReturn as V, EnvironmentReturn as a, Awaitable as b, Arrayable as c, ArgumentsType as d, MutableArray as e, EnvironmentOptions as f, ModuleCache as g };
175
+ export type { AfterSuiteRunMeta as A, Constructable as C, Environment as E, HappyDOMOptions as H, JSDOMOptions as J, ModuleGraphData as M, Nullable as N, OnServerRestartHandler as O, ProvidedContext as P, ResolvedTestEnvironment as R, TransformMode as T, UserConsoleLog as U, VmEnvironmentReturn as V, EnvironmentReturn as a, Awaitable as b, Arrayable as c, ArgumentsType as d, MutableArray as e, EnvironmentOptions as f, ModuleCache as g, OnTestsRerunHandler as h };
@@ -1,6 +1,6 @@
1
1
  import { g as globalApis } from './constants.fzPh7AOq.js';
2
- import { V as VitestIndex } from './index.Dqe5k2Rk.js';
3
- import './vi.JMQoNY_Z.js';
2
+ import { V as VitestIndex } from './index.DD5eTY2y.js';
3
+ import './vi.BlPttogV.js';
4
4
  import '@vitest/expect';
5
5
  import '@vitest/runner';
6
6
  import '@vitest/runner/utils';
@@ -3,7 +3,7 @@ import { resolve } from 'node:path';
3
3
  import { t as takeCoverageInsideWorker } from './coverage.BoMDb1ip.js';
4
4
  import { distDir } from '../path.js';
5
5
  import { r as rpc } from './rpc.C3q9uwRX.js';
6
- import { l as loadDiffConfig, a as loadSnapshotSerializers } from './setup-common.DDmVKp6O.js';
6
+ import { l as loadDiffConfig, a as loadSnapshotSerializers } from './setup-common.BfGt8K-K.js';
7
7
  import { g as getWorkerState } from './utils.C8RiOc4B.js';
8
8
 
9
9
  function setupChaiConfig(config) {
@@ -1,5 +1,4 @@
1
- import { c as createExpect, a as globalExpect, v as vi, b as vitest } from './vi.JMQoNY_Z.js';
2
- import { g as getWorkerState } from './utils.C8RiOc4B.js';
1
+ import { c as createExpect, a as globalExpect, i as inject, v as vi, b as vitest } from './vi.BlPttogV.js';
3
2
  import { i as isFirstRun, a as runOnce } from './run-once.2ogXb3JV.js';
4
3
  import { b as bench } from './benchmark.Cdu9hjj4.js';
5
4
  import { expectTypeOf } from 'expect-type';
@@ -7,11 +6,6 @@ import { afterAll, afterEach, beforeAll, beforeEach, describe, it, onTestFailed,
7
6
  import * as chai from 'chai';
8
7
  import { assert, should } from 'chai';
9
8
 
10
- function inject(key) {
11
- const workerState = getWorkerState();
12
- return workerState.providedContext[key];
13
- }
14
-
15
9
  function getRunningMode() {
16
10
  return process.env.VITEST_MODE === "WATCH" ? "watch" : "run";
17
11
  }
@@ -51,4 +45,4 @@ var VitestIndex = /*#__PURE__*/Object.freeze({
51
45
  vitest: vitest
52
46
  });
53
47
 
54
- export { VitestIndex as V, isWatchMode as a, assertType as b, getRunningMode as g, inject as i };
48
+ export { VitestIndex as V, assertType as a, getRunningMode as g, isWatchMode as i };