vitest 2.1.4 → 2.1.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (44) hide show
  1. package/dist/browser.d.ts +9 -9
  2. package/dist/browser.js +1 -1
  3. package/dist/chunks/{base.C3xNdjV6.js → base.BZZh4cSm.js} +1 -1
  4. package/dist/chunks/{cac.DrfPaMvZ.js → cac.DWAW3Uh5.js} +5 -5
  5. package/dist/chunks/{cli-api.CKrRYkw8.js → cli-api.BtqJwSCh.js} +106 -77
  6. package/dist/chunks/{config.Crbj2GAb.d.ts → config.Cy0C388Z.d.ts} +0 -1
  7. package/dist/chunks/{globals.Bp645TTJ.js → globals.D8ZVAdXd.js} +2 -2
  8. package/dist/chunks/{index.Bn81VaWg.js → index.DsZFoqi9.js} +205 -303
  9. package/dist/chunks/{index.BMoXz_-n.js → index.K90BXFOx.js} +1 -1
  10. package/dist/chunks/{index.Dqe5k2Rk.js → index.ckWaX2gY.js} +1 -1
  11. package/dist/chunks/{index.D3d79vc8.js → index.nEwtF0bu.js} +1 -1
  12. package/dist/chunks/{reporters.anwo7Y6a.d.ts → reporters.D7Jzd9GS.d.ts} +26 -16
  13. package/dist/chunks/{resolveConfig.DPmbhVlP.js → resolveConfig.RxKrDli4.js} +4 -2
  14. package/dist/chunks/{runBaseTests.Dm-659zB.js → runBaseTests.3qpJUEJM.js} +4 -4
  15. package/dist/chunks/{setup-common.DDmVKp6O.js → setup-common.Dj6BZI3u.js} +1 -1
  16. package/dist/chunks/{utils.BB4zjzR8.js → utils.DNoFbBUZ.js} +6 -2
  17. package/dist/chunks/{vi.JMQoNY_Z.js → vi.DgezovHB.js} +85 -3
  18. package/dist/chunks/{vite.BdBj-UWY.d.ts → vite.C-N5BBZe.d.ts} +1 -1
  19. package/dist/chunks/{vm.jpyrB0xy.js → vm.Zr4qWzDJ.js} +3 -0
  20. package/dist/chunks/{worker.DHnGaO2M.d.ts → worker.B9FxPCaC.d.ts} +1 -1
  21. package/dist/chunks/{worker.BAlI9hII.d.ts → worker.tN5KGIih.d.ts} +2 -1
  22. package/dist/cli.js +1 -1
  23. package/dist/config.d.ts +9 -9
  24. package/dist/coverage.d.ts +7 -7
  25. package/dist/coverage.js +1 -1
  26. package/dist/environments.js +1 -1
  27. package/dist/execute.d.ts +2 -2
  28. package/dist/index.d.ts +37 -8
  29. package/dist/index.js +2 -2
  30. package/dist/node.d.ts +8 -8
  31. package/dist/node.js +7 -7
  32. package/dist/reporters.d.ts +9 -9
  33. package/dist/reporters.js +2 -2
  34. package/dist/runners.d.ts +1 -1
  35. package/dist/runners.js +1 -1
  36. package/dist/worker.js +6 -2
  37. package/dist/workers/forks.js +1 -1
  38. package/dist/workers/runVmTests.js +4 -4
  39. package/dist/workers/threads.js +1 -1
  40. package/dist/workers/vmForks.js +1 -1
  41. package/dist/workers/vmThreads.js +1 -1
  42. package/dist/workers.d.ts +3 -3
  43. package/dist/workers.js +4 -3
  44. package/package.json +15 -15
package/dist/browser.d.ts CHANGED
@@ -1,27 +1,27 @@
1
- import { C as CoverageProvider, b as CoverageProviderModule } from './chunks/reporters.anwo7Y6a.js';
2
- import { a as SerializedCoverageConfig, S as SerializedConfig } from './chunks/config.Crbj2GAb.js';
1
+ import { C as CoverageProvider, b as CoverageProviderModule } from './chunks/reporters.D7Jzd9GS.js';
2
+ import { a as SerializedCoverageConfig, S as SerializedConfig } from './chunks/config.Cy0C388Z.js';
3
3
  import * as spy$1 from '@vitest/spy';
4
4
  import { DiffOptions } from '@vitest/expect';
5
5
  import { VitestExecutor } from './execute.js';
6
6
  export { collectTests, processError, startTests } from '@vitest/runner';
7
+ import './chunks/environment.LoooBwUu.js';
8
+ import 'node:stream';
9
+ import 'vite';
10
+ import '@vitest/utils';
7
11
  import '@vitest/pretty-format';
8
12
  import '@vitest/snapshot';
9
- import 'vite';
10
13
  import 'vite-node';
11
14
  import 'chai';
12
- import './chunks/environment.LoooBwUu.js';
13
- import 'node:stream';
14
- import '@vitest/utils';
15
15
  import '@vitest/utils/source-map';
16
16
  import 'vite-node/client';
17
17
  import 'vite-node/server';
18
- import '@vitest/snapshot/manager';
19
- import 'node:fs';
20
18
  import './chunks/benchmark.geERunq4.js';
21
19
  import '@vitest/runner/utils';
22
20
  import 'tinybench';
21
+ import '@vitest/snapshot/manager';
22
+ import 'node:fs';
23
23
  import '@vitest/snapshot/environment';
24
- import './chunks/worker.BAlI9hII.js';
24
+ import './chunks/worker.tN5KGIih.js';
25
25
  import 'node:vm';
26
26
  import '@vitest/mocker';
27
27
  import './chunks/mocker.cRtM890J.js';
package/dist/browser.js CHANGED
@@ -1,6 +1,6 @@
1
1
  export { g as getCoverageProvider, s as startCoverageInsideWorker, a as stopCoverageInsideWorker, t as takeCoverageInsideWorker } from './chunks/coverage.BoMDb1ip.js';
2
2
  export { s as SpyModule } from './chunks/spy.Cf_4R5Oe.js';
3
- export { l as loadDiffConfig, a as loadSnapshotSerializers, s as setupCommonEnv } from './chunks/setup-common.DDmVKp6O.js';
3
+ export { l as loadDiffConfig, a as loadSnapshotSerializers, s as setupCommonEnv } from './chunks/setup-common.Dj6BZI3u.js';
4
4
  export { collectTests, processError, startTests } from '@vitest/runner';
5
5
  import '@vitest/spy';
6
6
  import '@vitest/snapshot';
@@ -24,7 +24,7 @@ async function runBaseTests(method, state) {
24
24
  ctx.files.forEach((i) => state.moduleCache.delete(i));
25
25
  const [executor, { run }] = await Promise.all([
26
26
  startViteNode({ state, requestStubs: getDefaultRequestStubs() }),
27
- import('./runBaseTests.Dm-659zB.js')
27
+ import('./runBaseTests.3qpJUEJM.js')
28
28
  ]);
29
29
  await run(
30
30
  method,
@@ -618,7 +618,7 @@ class CAC extends EventEmitter {
618
618
 
619
619
  const cac = (name = "") => new CAC(name);
620
620
 
621
- var version = "2.1.4";
621
+ var version = "2.1.5";
622
622
 
623
623
  const apiConfig = (port) => ({
624
624
  port: {
@@ -1502,13 +1502,13 @@ async function start(mode, cliFilters, options) {
1502
1502
  } catch {
1503
1503
  }
1504
1504
  try {
1505
- const { startVitest } = await import('./cli-api.CKrRYkw8.js').then(function (n) { return n.e; });
1505
+ const { startVitest } = await import('./cli-api.BtqJwSCh.js').then(function (n) { return n.e; });
1506
1506
  const ctx = await startVitest(mode, cliFilters.map(normalize), normalizeCliOptions(options));
1507
1507
  if (!ctx?.shouldKeepServer()) {
1508
1508
  await ctx?.exit();
1509
1509
  }
1510
1510
  } catch (e) {
1511
- const { divider } = await import('./utils.BB4zjzR8.js').then(function (n) { return n.u; });
1511
+ const { divider } = await import('./utils.DNoFbBUZ.js').then(function (n) { return n.u; });
1512
1512
  console.error(`
1513
1513
  ${c.red(divider(c.bold(c.inverse(" Startup Error "))))}`);
1514
1514
  console.error(e);
@@ -1533,7 +1533,7 @@ async function collect(mode, cliFilters, options) {
1533
1533
  } catch {
1534
1534
  }
1535
1535
  try {
1536
- const { prepareVitest, processCollected, outputFileList } = await import('./cli-api.CKrRYkw8.js').then(function (n) { return n.e; });
1536
+ const { prepareVitest, processCollected, outputFileList } = await import('./cli-api.BtqJwSCh.js').then(function (n) { return n.e; });
1537
1537
  const ctx = await prepareVitest(mode, {
1538
1538
  ...normalizeCliOptions(options),
1539
1539
  watch: false,
@@ -1555,7 +1555,7 @@ async function collect(mode, cliFilters, options) {
1555
1555
  }
1556
1556
  await ctx.close();
1557
1557
  } catch (e) {
1558
- const { divider } = await import('./utils.BB4zjzR8.js').then(function (n) { return n.u; });
1558
+ const { divider } = await import('./utils.DNoFbBUZ.js').then(function (n) { return n.u; });
1559
1559
  console.error(`
1560
1560
  ${c.red(divider(c.bold(c.inverse(" Collect Error "))))}`);
1561
1561
  console.error(e);
@@ -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.RxKrDli4.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.DWAW3Uh5.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.DsZFoqi9.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
 
@@ -9705,6 +9704,18 @@ function WorkspaceVitestPlugin(project, options) {
9705
9704
  )
9706
9705
  }
9707
9706
  },
9707
+ // eslint-disable-next-line ts/ban-ts-comment
9708
+ // @ts-ignore Vite 6 compat
9709
+ environments: {
9710
+ ssr: {
9711
+ resolve: {
9712
+ // by default Vite resolves `module` field, which not always a native ESM module
9713
+ // setting this option can bypass that and fallback to cjs version
9714
+ mainFields: [],
9715
+ conditions: ["node"]
9716
+ }
9717
+ }
9718
+ },
9708
9719
  test: {
9709
9720
  name
9710
9721
  }
@@ -10028,16 +10039,15 @@ class WorkspaceProject {
10028
10039
  }
10029
10040
  return testFiles;
10030
10041
  }
10031
- async initBrowserServer(configFile) {
10032
- if (!this.isBrowserEnabled()) {
10042
+ async initBrowserServer() {
10043
+ if (!this.isBrowserEnabled() || this.browser) {
10033
10044
  return;
10034
10045
  }
10035
10046
  await this.ctx.packageInstaller.ensureInstalled("@vitest/browser", this.config.root, this.ctx.version);
10036
10047
  const { createBrowserServer, distRoot } = await import('@vitest/browser');
10037
- await this.browser?.close();
10038
10048
  const browser = await createBrowserServer(
10039
10049
  this,
10040
- configFile,
10050
+ this.server.config.configFile,
10041
10051
  [
10042
10052
  ...MocksPlugins({
10043
10053
  filter(id) {
@@ -10075,9 +10085,7 @@ class WorkspaceProject {
10075
10085
  return project;
10076
10086
  }
10077
10087
  static async createCoreProject(ctx) {
10078
- const project = WorkspaceProject.createBasicProject(ctx);
10079
- await project.initBrowserServer(ctx.server.config.configFile);
10080
- return project;
10088
+ return WorkspaceProject.createBasicProject(ctx);
10081
10089
  }
10082
10090
  async setServer(options, server) {
10083
10091
  this.config = resolveConfig(
@@ -10096,6 +10104,7 @@ class WorkspaceProject {
10096
10104
  this.config.provide[providedKey]
10097
10105
  );
10098
10106
  }
10107
+ this.closingPromise = void 0;
10099
10108
  this.testProject = new TestProject(this);
10100
10109
  this.server = server;
10101
10110
  this.vitenode = new ViteNodeServer(server, this.config.server);
@@ -10110,7 +10119,6 @@ class WorkspaceProject {
10110
10119
  return node.resolveId(id, importer);
10111
10120
  }
10112
10121
  });
10113
- await this.initBrowserServer(this.server.config.configFile);
10114
10122
  }
10115
10123
  isBrowserEnabled() {
10116
10124
  return isBrowserEnabled(this.config);
@@ -10133,7 +10141,7 @@ class WorkspaceProject {
10133
10141
  if (!this.closingPromise) {
10134
10142
  this.closingPromise = Promise.all(
10135
10143
  [
10136
- this.server.close(),
10144
+ this.server?.close(),
10137
10145
  this.typechecker?.stop(),
10138
10146
  this.browser?.close(),
10139
10147
  this.clearTmpDir()
@@ -10149,9 +10157,12 @@ class WorkspaceProject {
10149
10157
  }
10150
10158
  }
10151
10159
  async initBrowserProvider() {
10152
- if (!this.isBrowserEnabled()) {
10160
+ if (!this.isBrowserEnabled() || this.browser?.provider) {
10153
10161
  return;
10154
10162
  }
10163
+ if (!this.browser) {
10164
+ await this.initBrowserServer();
10165
+ }
10155
10166
  await this.browser?.initBrowserProvider();
10156
10167
  }
10157
10168
  }
@@ -10222,48 +10233,33 @@ async function resolveWorkspace(vitest, cliOptions, workspaceConfigPath, workspa
10222
10233
  }
10223
10234
  return acc;
10224
10235
  }, {});
10225
- const cwd = process.cwd();
10226
- const projects = [];
10236
+ const projectPromises = [];
10227
10237
  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);
10238
+ const concurrent = limitConcurrency(nodeos__default.availableParallelism?.() || nodeos__default.cpus().length || 5);
10239
+ for (const filepath of fileProjects) {
10240
+ if (vitest.server.config.configFile === filepath) {
10241
+ projectPromises.push(concurrent(() => vitest._createCoreProject()));
10242
+ continue;
10250
10243
  }
10244
+ projectPromises.push(
10245
+ concurrent(() => initializeProject(
10246
+ filepath,
10247
+ vitest,
10248
+ { workspaceConfigPath, test: cliOverrides }
10249
+ ))
10250
+ );
10251
10251
  }
10252
- const projectPromises = [];
10253
10252
  projectConfigs.forEach((options, index) => {
10254
- projectPromises.push(initializeProject(
10253
+ projectPromises.push(concurrent(() => initializeProject(
10255
10254
  index,
10256
10255
  vitest,
10257
10256
  mergeConfig(options, { workspaceConfigPath, test: cliOverrides })
10258
- ));
10257
+ )));
10259
10258
  });
10260
- if (!projects.length && !projectPromises.length) {
10259
+ if (!projectPromises.length) {
10261
10260
  return [await vitest._createCoreProject()];
10262
10261
  }
10263
- const resolvedProjects = await Promise.all([
10264
- ...projects,
10265
- ...projectPromises
10266
- ]);
10262
+ const resolvedProjects = await Promise.all(projectPromises);
10267
10263
  const names = /* @__PURE__ */ new Set();
10268
10264
  for (const project of resolvedProjects) {
10269
10265
  const name = project.getName();
@@ -10407,10 +10403,12 @@ class Vitest {
10407
10403
  runner = void 0;
10408
10404
  packageInstaller;
10409
10405
  coreWorkspaceProject;
10406
+ /** @private */
10410
10407
  resolvedProjects = [];
10411
10408
  projects = [];
10412
10409
  distPath = distDir;
10413
10410
  _cachedSpecs = /* @__PURE__ */ new Map();
10411
+ _workspaceConfigPath;
10414
10412
  /** @deprecated use `_cachedSpecs` */
10415
10413
  projectTestFiles = this._cachedSpecs;
10416
10414
  /** @private */
@@ -10426,6 +10424,10 @@ class Vitest {
10426
10424
  this._browserLastPort = defaultBrowserPort;
10427
10425
  this.pool?.close?.();
10428
10426
  this.pool = void 0;
10427
+ this.closingPromise = void 0;
10428
+ this.projects = [];
10429
+ this.resolvedProjects = [];
10430
+ this._workspaceConfigPath = void 0;
10429
10431
  this.coverageProvider = void 0;
10430
10432
  this.runningPromise = void 0;
10431
10433
  this._cachedSpecs.clear();
@@ -10454,18 +10456,18 @@ class Vitest {
10454
10456
  const serverRestart = server.restart;
10455
10457
  server.restart = async (...args) => {
10456
10458
  await Promise.all(this._onRestartListeners.map((fn) => fn()));
10459
+ this.report("onServerRestart");
10460
+ await this.close();
10457
10461
  await serverRestart(...args);
10458
- this.unregisterWatcher();
10459
- this.registerWatcher();
10460
10462
  };
10461
10463
  server.watcher.on("change", async (file) => {
10462
10464
  file = normalize(file);
10463
- const isConfig = file === server.config.configFile;
10465
+ const isConfig = file === server.config.configFile || this.resolvedProjects.some((p) => p.server.config.configFile === file) || file === this._workspaceConfigPath;
10464
10466
  if (isConfig) {
10465
10467
  await Promise.all(this._onRestartListeners.map((fn) => fn("config")));
10468
+ this.report("onServerRestart", "config");
10469
+ await this.close();
10466
10470
  await serverRestart();
10467
- this.unregisterWatcher();
10468
- this.registerWatcher();
10469
10471
  }
10470
10472
  });
10471
10473
  }
@@ -10475,7 +10477,6 @@ class Vitest {
10475
10477
  await this.cache.results.readFromCache();
10476
10478
  } catch {
10477
10479
  }
10478
- await Promise.all(this._onSetServer.map((fn) => fn()));
10479
10480
  const projects = await this.resolveWorkspace(cliOptions);
10480
10481
  this.resolvedProjects = projects;
10481
10482
  this.projects = projects;
@@ -10491,6 +10492,7 @@ class Vitest {
10491
10492
  if (this.config.testNamePattern) {
10492
10493
  this.configOverride.testNamePattern = this.config.testNamePattern;
10493
10494
  }
10495
+ await Promise.all(this._onSetServer.map((fn) => fn()));
10494
10496
  }
10495
10497
  provide(key, value) {
10496
10498
  this.getCoreWorkspaceProject().provide(key, value);
@@ -10532,12 +10534,13 @@ class Vitest {
10532
10534
  return rootFiles.includes(configFile);
10533
10535
  });
10534
10536
  if (!workspaceConfigName) {
10535
- return null;
10537
+ return void 0;
10536
10538
  }
10537
10539
  return join(configDir, workspaceConfigName);
10538
10540
  }
10539
10541
  async resolveWorkspace(cliOptions) {
10540
10542
  const workspaceConfigPath = await this.getWorkspaceConfigPath();
10543
+ this._workspaceConfigPath = workspaceConfigPath;
10541
10544
  if (!workspaceConfigPath) {
10542
10545
  return [await this._createCoreProject()];
10543
10546
  }
@@ -10566,9 +10569,6 @@ class Vitest {
10566
10569
  }
10567
10570
  return this.coverageProvider;
10568
10571
  }
10569
- async initBrowserProviders() {
10570
- return Promise.all(this.projects.map((w) => w.initBrowserProvider()));
10571
- }
10572
10572
  async mergeReports() {
10573
10573
  if (this.reporters.some((r) => r instanceof BlobReporter)) {
10574
10574
  throw new Error("Cannot merge reports when `--reporter=blob` is used. Remove blob reporter from the config first.");
@@ -10611,13 +10611,13 @@ class Vitest {
10611
10611
  if (hasFailed(files)) {
10612
10612
  process.exitCode = 1;
10613
10613
  }
10614
+ this.checkUnhandledErrors(errors);
10614
10615
  await this.report("onFinished", files, errors);
10615
10616
  await this.initCoverageProvider();
10616
10617
  await this.coverageProvider?.mergeReports?.(coverages);
10617
10618
  }
10618
10619
  async collect(filters) {
10619
10620
  this._onClose = [];
10620
- await this.initBrowserProviders();
10621
10621
  const files = await this.filterTestsBySource(
10622
10622
  await this.globTestFiles(filters)
10623
10623
  );
@@ -10641,7 +10641,6 @@ class Vitest {
10641
10641
  try {
10642
10642
  await this.initCoverageProvider();
10643
10643
  await this.coverageProvider?.clean(this.config.coverage.clean);
10644
- await this.initBrowserProviders();
10645
10644
  } finally {
10646
10645
  await this.report("onInit", this);
10647
10646
  }
@@ -10671,7 +10670,6 @@ class Vitest {
10671
10670
  try {
10672
10671
  await this.initCoverageProvider();
10673
10672
  await this.coverageProvider?.clean(this.config.coverage.clean);
10674
- await this.initBrowserProviders();
10675
10673
  } finally {
10676
10674
  await this.report("onInit", this);
10677
10675
  }
@@ -10809,8 +10807,10 @@ class Vitest {
10809
10807
  await this.cache.results.writeToCache();
10810
10808
  })().finally(async () => {
10811
10809
  const files = Array.from(new Set(specs.map((spec) => spec.moduleId)));
10810
+ const errors = this.state.getUnhandledErrors();
10812
10811
  const coverage = await this.coverageProvider?.generateCoverage({ allTestsRun });
10813
- await this.report("onFinished", this.state.getFiles(files), this.state.getUnhandledErrors(), coverage);
10812
+ this.checkUnhandledErrors(errors);
10813
+ await this.report("onFinished", this.state.getFiles(files), errors, coverage);
10814
10814
  await this.reportCoverage(coverage, allTestsRun);
10815
10815
  this.runningPromise = void 0;
10816
10816
  this.isFirstRun = false;
@@ -10854,13 +10854,16 @@ class Vitest {
10854
10854
  this.isCancelling = true;
10855
10855
  await Promise.all(this._onCancelListeners.splice(0).map((listener) => listener(reason)));
10856
10856
  }
10857
- async rerunFiles(files = this.state.getFilepaths(), trigger) {
10857
+ async initBrowserServers() {
10858
+ await Promise.all(this.projects.map((p) => p.initBrowserServer()));
10859
+ }
10860
+ async rerunFiles(files = this.state.getFilepaths(), trigger, allTestsRun = true) {
10858
10861
  if (this.filenamePattern) {
10859
10862
  const filteredFiles = await this.globTestFiles([this.filenamePattern]);
10860
10863
  files = files.filter((file) => filteredFiles.some((f) => f[1] === file));
10861
10864
  }
10862
10865
  await this.report("onWatcherRerun", files, trigger);
10863
- await this.runFiles(files.flatMap((file) => this.getProjectsByTestFile(file)), !trigger);
10866
+ await this.runFiles(files.flatMap((file) => this.getProjectsByTestFile(file)), allTestsRun);
10864
10867
  await this.report("onWatcherStart", this.state.getFiles(files));
10865
10868
  }
10866
10869
  async changeProjectName(pattern) {
@@ -10871,7 +10874,7 @@ class Vitest {
10871
10874
  }
10872
10875
  this.projects = this.resolvedProjects.filter((p) => p.getName() === pattern);
10873
10876
  const files = (await this.globTestSpecs()).map((spec) => spec.moduleId);
10874
- await this.rerunFiles(files, "change project filter");
10877
+ await this.rerunFiles(files, "change project filter", pattern === "");
10875
10878
  }
10876
10879
  async changeNamePattern(pattern, files = this.state.getFilepaths(), trigger) {
10877
10880
  if (pattern === "") {
@@ -10888,15 +10891,15 @@ class Vitest {
10888
10891
  });
10889
10892
  });
10890
10893
  }
10891
- await this.rerunFiles(files, trigger);
10894
+ await this.rerunFiles(files, trigger, pattern === "");
10892
10895
  }
10893
10896
  async changeFilenamePattern(pattern, files = this.state.getFilepaths()) {
10894
10897
  this.filenamePattern = pattern;
10895
10898
  const trigger = this.filenamePattern ? "change filename pattern" : "reset filename pattern";
10896
- await this.rerunFiles(files, trigger);
10899
+ await this.rerunFiles(files, trigger, pattern === "");
10897
10900
  }
10898
10901
  async rerunFailed() {
10899
- await this.rerunFiles(this.state.getFailedFilepaths(), "rerun failed");
10902
+ await this.rerunFiles(this.state.getFailedFilepaths(), "rerun failed", false);
10900
10903
  }
10901
10904
  async updateSnapshot(files) {
10902
10905
  files = files || [
@@ -10909,7 +10912,7 @@ class Vitest {
10909
10912
  snapshotEnvironment: null
10910
10913
  };
10911
10914
  try {
10912
- await this.rerunFiles(files, "update snapshot");
10915
+ await this.rerunFiles(files, "update snapshot", false);
10913
10916
  } finally {
10914
10917
  delete this.configOverride.snapshotOptions;
10915
10918
  }
@@ -11021,6 +11024,11 @@ class Vitest {
11021
11024
  }
11022
11025
  }
11023
11026
  };
11027
+ checkUnhandledErrors(errors) {
11028
+ if (errors.length && !this.config.dangerouslyIgnoreUnhandledErrors) {
11029
+ process.exitCode = 1;
11030
+ }
11031
+ }
11024
11032
  unregisterWatcher = noop;
11025
11033
  registerWatcher() {
11026
11034
  const watcher = this.server.watcher;
@@ -11287,6 +11295,18 @@ async function VitestPlugin(options = {}, ctx = new Vitest("test")) {
11287
11295
  // https://github.com/vitejs/vite/pull/16453
11288
11296
  emptyOutDir: false
11289
11297
  },
11298
+ // eslint-disable-next-line ts/ban-ts-comment
11299
+ // @ts-ignore Vite 6 compat
11300
+ environments: {
11301
+ ssr: {
11302
+ resolve: {
11303
+ // by default Vite resolves `module` field, which not always a native ESM module
11304
+ // setting this option can bypass that and fallback to cjs version
11305
+ mainFields: [],
11306
+ conditions: ["node"]
11307
+ }
11308
+ }
11309
+ },
11290
11310
  test: {
11291
11311
  poolOptions: {
11292
11312
  threads: {
@@ -11477,9 +11497,9 @@ class WatchFilter {
11477
11497
  break;
11478
11498
  case (key?.ctrl && key?.name === "c"):
11479
11499
  case key?.name === "escape":
11480
- this.cancel();
11500
+ this.write(`${ESC}1G${ESC}0J`);
11481
11501
  onSubmit(void 0);
11482
- break;
11502
+ return;
11483
11503
  case key?.name === "enter":
11484
11504
  case key?.name === "return":
11485
11505
  onSubmit(
@@ -11583,9 +11603,6 @@ ${resultBody}`;
11583
11603
  const cursortPos = this.keywordOffset() + (this.currentKeyword?.length || 0);
11584
11604
  this.write(`${ESC}${cursortPos}G`);
11585
11605
  }
11586
- cancel() {
11587
- this.write(`${ESC}J`);
11588
- }
11589
11606
  write(data) {
11590
11607
  this.stdout.write(data);
11591
11608
  }
@@ -11602,6 +11619,7 @@ const keys = [
11602
11619
  ["p", "filter by a filename"],
11603
11620
  ["t", "filter by a test name regex pattern"],
11604
11621
  ["w", "filter by a project name"],
11622
+ ["b", "start the browser server if not started yet"],
11605
11623
  ["q", "quit"]
11606
11624
  ];
11607
11625
  const cancelKeys = ["space", "c", "h", ...keys.map((key) => key[0]).flat()];
@@ -11670,6 +11688,14 @@ function registerConsoleShortcuts(ctx, stdin = process.stdin, stdout2) {
11670
11688
  if (name === "p") {
11671
11689
  return inputFilePattern();
11672
11690
  }
11691
+ if (name === "b") {
11692
+ await ctx.initBrowserServers();
11693
+ ctx.projects.forEach((project) => {
11694
+ ctx.logger.log();
11695
+ ctx.logger.printBrowserBanner(project);
11696
+ });
11697
+ return null;
11698
+ }
11673
11699
  }
11674
11700
  async function keypressHandler(str, key) {
11675
11701
  await _keypressHandler(str, key);
@@ -11692,6 +11718,9 @@ function registerConsoleShortcuts(ctx, stdin = process.stdin, stdout2) {
11692
11718
  }
11693
11719
  });
11694
11720
  on();
11721
+ if (typeof filter === "undefined") {
11722
+ return;
11723
+ }
11695
11724
  const files = ctx.state.getFilepaths();
11696
11725
  const cliFiles = ctx.config.standalone && !files.length ? await ctx.getTestFilepaths() : void 0;
11697
11726
  await ctx.changeNamePattern(
@@ -11725,6 +11754,9 @@ function registerConsoleShortcuts(ctx, stdin = process.stdin, stdout2) {
11725
11754
  return files.map((file) => relative(ctx.config.root, file[1]));
11726
11755
  });
11727
11756
  on();
11757
+ if (typeof filter === "undefined") {
11758
+ return;
11759
+ }
11728
11760
  latestFilename = filter?.trim() || "";
11729
11761
  const lastResults = watchFilter.getLastResults();
11730
11762
  await ctx.changeFilenamePattern(
@@ -11780,9 +11812,6 @@ async function startVitest(mode, cliFilters = [], options = {}, viteOverrides, v
11780
11812
  if (stdin.isTTY && ctx.config.watch) {
11781
11813
  stdinCleanup = registerConsoleShortcuts(ctx, stdin, stdout);
11782
11814
  }
11783
- ctx.onServerRestart((reason) => {
11784
- ctx.report("onServerRestart", reason);
11785
- });
11786
11815
  ctx.onAfterSetServer(() => {
11787
11816
  if (ctx.config.standalone) {
11788
11817
  ctx.init();
@@ -200,7 +200,6 @@ interface SerializedCoverageConfig {
200
200
  }
201
201
  type RuntimeConfig = Pick<SerializedConfig, 'allowOnly' | 'testTimeout' | 'hookTimeout' | 'clearMocks' | 'mockReset' | 'restoreMocks' | 'fakeTimers' | 'maxConcurrency' | 'expect' | 'printConsoleTrace'> & {
202
202
  sequence?: {
203
- concurrent?: boolean;
204
203
  hooks?: SequenceHooks;
205
204
  };
206
205
  };
@@ -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.ckWaX2gY.js';
3
+ import './vi.DgezovHB.js';
4
4
  import '@vitest/expect';
5
5
  import '@vitest/runner';
6
6
  import '@vitest/runner/utils';