vitest 0.34.3 → 0.34.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 (35) hide show
  1. package/dist/browser.d.ts +28 -2
  2. package/dist/browser.js +11 -2
  3. package/dist/child.js +13 -8
  4. package/dist/{chunk-api-setup.3b016b1c.js → chunk-api-setup.d65b007d.js} +3 -3
  5. package/dist/{chunk-install-pkg.a036014e.js → chunk-install-pkg.e623b1bf.js} +3 -3
  6. package/dist/{chunk-integrations-globals.7f4b17bf.js → chunk-integrations-globals.5afac659.js} +2 -2
  7. package/dist/{chunk-node-git.c410fed8.js → chunk-node-git.36288174.js} +1 -1
  8. package/dist/cli-wrapper.js +1 -1
  9. package/dist/cli.js +4 -4
  10. package/dist/config.d.ts +1 -1
  11. package/dist/coverage.d.ts +1 -1
  12. package/dist/entry-vm.js +3 -3
  13. package/dist/entry.js +6 -3
  14. package/dist/environments.d.ts +1 -1
  15. package/dist/environments.js +3 -2
  16. package/dist/execute.d.ts +1 -1
  17. package/dist/execute.js +1 -1
  18. package/dist/index.d.ts +25 -2
  19. package/dist/index.js +3 -3
  20. package/dist/node.d.ts +2 -2
  21. package/dist/node.js +3 -3
  22. package/dist/{reporters-2ff87305.d.ts → reporters-5f784f42.d.ts} +23 -18
  23. package/dist/reporters.d.ts +1 -1
  24. package/dist/runners.d.ts +1 -1
  25. package/dist/runners.js +1 -1
  26. package/dist/{vendor-environments.8eb4d407.js → vendor-environments.b9b2f624.js} +26 -5
  27. package/dist/{vendor-execute.a63e187f.js → vendor-execute.07d1a420.js} +10 -3
  28. package/dist/{vendor-index.9378c9a4.js → vendor-index.3e351f42.js} +2 -0
  29. package/dist/{vendor-index.7178e7a2.js → vendor-index.7646b3af.js} +1 -1
  30. package/dist/{vendor-index.1f85e5f1.js → vendor-index.85fc950a.js} +2 -2
  31. package/dist/{vendor-node.5ce5f335.js → vendor-node.81dd929c.js} +123 -96
  32. package/dist/{vendor-vi.597d9e06.js → vendor-vi.6873a1c1.js} +149 -22
  33. package/dist/vm.js +11 -6
  34. package/dist/worker.js +13 -8
  35. package/package.json +8 -8
@@ -25,14 +25,15 @@ import { fork } from 'node:child_process';
25
25
  import { c as createBirpc } from './vendor-index.b271ebe4.js';
26
26
  import { g as groupBy, A as AggregateErrorPonyfill, s as slash$1, t as toArray, i as isPrimitive, d as deepMerge, n as noop$1, a as stdout } from './vendor-base.9c08bbd0.js';
27
27
  import { MessageChannel } from 'node:worker_threads';
28
- import { cpus, totalmem } from 'node:os';
28
+ import * as nodeos from 'node:os';
29
+ import { totalmem } from 'node:os';
29
30
  import Tinypool from 'tinypool';
30
31
  import { createDefer, shuffle, inspect, positionToOffset, lineSplitRE, notNullish } from '@vitest/utils';
31
32
  import { isPackageExists, resolveModule } from 'local-pkg';
32
33
  import { isCI } from 'std-env';
33
34
  import { R as ReportersMap, B as BenchmarkReportsMap, s as stringWidth, a as ansiStyles, b as stripAnsi, c as sliceAnsi, d as divider, F as F_POINTER, e as cliTruncate } from './vendor-reporters.f6975b8d.js';
34
- import { createHash } from 'node:crypto';
35
- import { o as onExit, e as execa } from './vendor-index.1f85e5f1.js';
35
+ import crypto, { createHash } from 'node:crypto';
36
+ import { o as onExit, e as execa } from './vendor-index.85fc950a.js';
36
37
  import { TraceMap, generatedPositionFor, parseErrorStacktrace } from '@vitest/utils/source-map';
37
38
  import { writeFile, rm } from 'node:fs/promises';
38
39
  import ue from 'module';
@@ -41,7 +42,7 @@ import { ancestor, simple, findNodeAround } from 'acorn-walk';
41
42
  import { generateHash, calculateSuiteHash, someTasksAreOnly, interpretTaskModes, getTasks, hasFailed } from '@vitest/runner/utils';
42
43
  import MagicString from 'magic-string';
43
44
  import { stripLiteral } from 'strip-literal';
44
- import { g as getEnvPackageName } from './vendor-environments.8eb4d407.js';
45
+ import { g as getEnvPackageName } from './vendor-environments.b9b2f624.js';
45
46
  import readline from 'node:readline';
46
47
  import require$$0$2 from 'readline';
47
48
 
@@ -60,7 +61,7 @@ function _mergeNamespaces(n, m) {
60
61
  return Object.freeze(n);
61
62
  }
62
63
 
63
- var version$1 = "0.34.3";
64
+ var version$1 = "0.34.5";
64
65
 
65
66
  const __dirname$1 = url.fileURLToPath(new URL(".", import.meta.url));
66
67
  async function ensurePackageInstalled(dependency, root) {
@@ -79,7 +80,7 @@ async function ensurePackageInstalled(dependency, root) {
79
80
  message: c.reset(`Do you want to install ${c.green(dependency)}?`)
80
81
  });
81
82
  if (install) {
82
- await (await import('./chunk-install-pkg.a036014e.js')).installPackage(dependency, { dev: true });
83
+ await (await import('./chunk-install-pkg.e623b1bf.js')).installPackage(dependency, { dev: true });
83
84
  process.stderr.write(c.yellow(`
84
85
  Package ${dependency} installed, re-run the command to start.
85
86
  `));
@@ -7286,7 +7287,8 @@ function createWorkerChannel$1(project) {
7286
7287
  return { workerPort, port };
7287
7288
  }
7288
7289
  function createThreadsPool(ctx, { execArgv, env }) {
7289
- const threadsCount = ctx.config.watch ? Math.max(Math.floor(cpus().length / 2), 1) : Math.max(cpus().length - 1, 1);
7290
+ const numCpus = typeof nodeos.availableParallelism === "function" ? nodeos.availableParallelism() : nodeos.cpus().length;
7291
+ const threadsCount = ctx.config.watch ? Math.max(Math.floor(numCpus / 2), 1) : Math.max(numCpus - 1, 1);
7290
7292
  const maxThreads = ctx.config.maxThreads ?? threadsCount;
7291
7293
  const minThreads = ctx.config.minThreads ?? threadsCount;
7292
7294
  const options = {
@@ -7503,7 +7505,8 @@ function createWorkerChannel(project) {
7503
7505
  return { workerPort, port };
7504
7506
  }
7505
7507
  function createVmThreadsPool(ctx, { execArgv, env }) {
7506
- const threadsCount = ctx.config.watch ? Math.max(Math.floor(cpus().length / 2), 1) : Math.max(cpus().length - 1, 1);
7508
+ const numCpus = typeof nodeos.availableParallelism === "function" ? nodeos.availableParallelism() : nodeos.cpus().length;
7509
+ const threadsCount = ctx.config.watch ? Math.max(Math.floor(numCpus / 2), 1) : Math.max(numCpus - 1, 1);
7507
7510
  const maxThreads = ctx.config.maxThreads ?? threadsCount;
7508
7511
  const minThreads = ctx.config.minThreads ?? threadsCount;
7509
7512
  const options = {
@@ -7967,7 +7970,8 @@ const config = {
7967
7970
  const configDefaults = Object.freeze(config);
7968
7971
 
7969
7972
  function getDefaultThreadsCount(config) {
7970
- return config.watch ? Math.max(Math.floor(cpus().length / 2), 1) : Math.max(cpus().length - 1, 1);
7973
+ const numCpus = typeof nodeos.availableParallelism === "function" ? nodeos.availableParallelism() : nodeos.cpus().length;
7974
+ return config.watch ? Math.max(Math.floor(numCpus / 2), 1) : Math.max(numCpus - 1, 1);
7971
7975
  }
7972
7976
  function getWorkerMemoryLimit(config) {
7973
7977
  if (config.experimentalVmWorkerMemoryLimit)
@@ -8130,18 +8134,20 @@ class VitestCache {
8130
8134
  getFileStats(key) {
8131
8135
  return this.stats.getStats(key);
8132
8136
  }
8133
- static resolveCacheDir(root, dir) {
8134
- return resolve(root, slash$1(dir || "node_modules/.vitest"));
8137
+ static resolveCacheDir(root, dir, projectName) {
8138
+ const baseDir = slash$1(dir || "node_modules/.vitest");
8139
+ return projectName ? resolve(root, baseDir, crypto.createHash("md5").update(projectName, "utf-8").digest("hex")) : resolve(root, baseDir);
8135
8140
  }
8136
8141
  static async clearCache(options) {
8137
- var _a, _b;
8142
+ var _a, _b, _c;
8138
8143
  const root = resolve(options.root || process.cwd());
8139
8144
  const configPath = options.config === false ? false : options.config ? resolve(root, options.config) : await findUp(configFiles, { cwd: root });
8140
8145
  const config = configPath ? (_a = await loadConfigFromFile({ command: "serve", mode: "test" }, configPath)) == null ? void 0 : _a.config : void 0;
8141
8146
  const cache = (_b = config == null ? void 0 : config.test) == null ? void 0 : _b.cache;
8147
+ const projectName = (_c = config == null ? void 0 : config.test) == null ? void 0 : _c.name;
8142
8148
  if (cache === false)
8143
8149
  throw new Error("Cache is disabled");
8144
- const cachePath = VitestCache.resolveCacheDir(root, cache == null ? void 0 : cache.dir);
8150
+ const cachePath = VitestCache.resolveCacheDir(root, cache == null ? void 0 : cache.dir, projectName);
8145
8151
  let cleared = false;
8146
8152
  if (fs$8.existsSync(cachePath)) {
8147
8153
  fs$8.rmSync(cachePath, { recursive: true, force: true });
@@ -8232,8 +8238,10 @@ function resolveApiServerConfig(options) {
8232
8238
  }
8233
8239
  }
8234
8240
  if (api) {
8235
- if (!api.port)
8241
+ if (!api.port && !api.middlewareMode)
8236
8242
  api.port = defaultPort;
8243
+ } else {
8244
+ api = { middlewareMode: true };
8237
8245
  }
8238
8246
  return api;
8239
8247
  }
@@ -8399,6 +8407,12 @@ function resolveConfig(mode, options, viteConfig) {
8399
8407
  ...resolved.forceRerunTriggers,
8400
8408
  ...resolved.setupFiles
8401
8409
  ];
8410
+ if (resolved.diff) {
8411
+ resolved.diff = normalize(
8412
+ resolveModule(resolved.diff, { paths: [resolved.root] }) ?? resolve(resolved.root, resolved.diff)
8413
+ );
8414
+ resolved.forceRerunTriggers.push(resolved.diff);
8415
+ }
8402
8416
  resolved.api = resolveApiServerConfig(options);
8403
8417
  if (options.related)
8404
8418
  resolved.related = toArray(options.related).map((file) => resolve(resolved.root, file));
@@ -8422,7 +8436,7 @@ function resolveConfig(mode, options, viteConfig) {
8422
8436
  }
8423
8437
  resolved.cache ?? (resolved.cache = { dir: "" });
8424
8438
  if (resolved.cache)
8425
- resolved.cache.dir = VitestCache.resolveCacheDir(resolved.root, resolved.cache.dir);
8439
+ resolved.cache.dir = VitestCache.resolveCacheDir(resolved.root, resolved.cache.dir, resolved.name);
8426
8440
  resolved.sequence ?? (resolved.sequence = {});
8427
8441
  if (!((_q = resolved.sequence) == null ? void 0 : _q.sequencer)) {
8428
8442
  resolved.sequence.sequencer = resolved.sequence.shuffle ? RandomSequencer : BaseSequencer;
@@ -9007,7 +9021,7 @@ createLogUpdate(process$1.stdout);
9007
9021
 
9008
9022
  createLogUpdate(process$1.stderr);
9009
9023
 
9010
- var version = "0.34.3";
9024
+ var version = "0.34.5";
9011
9025
 
9012
9026
  const A=r=>r!==null&&typeof r=="object",a=(r,t)=>Object.assign(new Error(`[${r}]: ${t}`),{code:r}),_$1="ERR_INVALID_PACKAGE_CONFIG",E="ERR_INVALID_PACKAGE_TARGET",I="ERR_PACKAGE_PATH_NOT_EXPORTED",R$1=/^\d+$/,O=/^(\.{1,2}|node_modules)$/i,w=/\/|\\/;var h=(r=>(r.Export="exports",r.Import="imports",r))(h||{});const f=(r,t,e,o,c)=>{if(t==null)return [];if(typeof t=="string"){const[n,...i]=t.split(w);if(n===".."||i.some(l=>O.test(l)))throw a(E,`Invalid "${r}" target "${t}" defined in the package config`);return [c?t.replace(/\*/g,c):t]}if(Array.isArray(t))return t.flatMap(n=>f(r,n,e,o,c));if(A(t)){for(const n of Object.keys(t)){if(R$1.test(n))throw a(_$1,"Cannot contain numeric property keys");if(n==="default"||o.includes(n))return f(r,t[n],e,o,c)}return []}throw a(E,`Invalid "${r}" target "${t}"`)},s="*",m=(r,t)=>{const e=r.indexOf(s),o=t.indexOf(s);return e===o?t.length>r.length:o>e};function d$1(r,t){if(!t.includes(s)&&r.hasOwnProperty(t))return [t];let e,o;for(const c of Object.keys(r))if(c.includes(s)){const[n,i,l]=c.split(s);if(l===void 0&&t.startsWith(n)&&t.endsWith(i)){const g=t.slice(n.length,-i.length||void 0);g&&(!e||m(e,c))&&(e=c,o=g);}}return [e,o]}const p=r=>Object.keys(r).reduce((t,e)=>{const o=e===""||e[0]!==".";if(t===void 0||t===o)return o;throw a(_$1,'"exports" cannot contain some keys starting with "." and some not')},void 0),u=/^\w+:/,v=(r,t,e)=>{if(!r)throw new Error('"exports" is required');t=t===""?".":`./${t}`,(typeof r=="string"||Array.isArray(r)||A(r)&&p(r))&&(r={".":r});const[o,c]=d$1(r,t),n=f(h.Export,r[o],t,e,c);if(n.length===0)throw a(I,t==="."?'No "exports" main defined':`Package subpath '${t}' is not defined by "exports"`);for(const i of n)if(!i.startsWith("./")&&!u.test(i))throw a(E,`Invalid "exports" target "${i}" defined in the package config`);return n};
9013
9027
 
@@ -9783,7 +9797,7 @@ No ${config.mode} files found, exiting with code 1`));
9783
9797
  }
9784
9798
  }
9785
9799
  printBanner() {
9786
- var _a, _b;
9800
+ var _a, _b, _c;
9787
9801
  this.log();
9788
9802
  const versionTest = this.ctx.config.watch ? c.blue(`v${version}`) : c.cyan(`v${version}`);
9789
9803
  const mode = this.ctx.config.watch ? c.blue(" DEV ") : c.cyan(" RUN ");
@@ -9800,8 +9814,8 @@ No ${config.mode} files found, exiting with code 1`));
9800
9814
  });
9801
9815
  if (this.ctx.config.ui)
9802
9816
  this.log(c.dim(c.green(` UI started at http://${((_a = this.ctx.config.api) == null ? void 0 : _a.host) || "localhost"}:${c.bold(`${this.ctx.server.config.server.port}`)}${this.ctx.config.uiBase}`)));
9803
- else if (this.ctx.config.api)
9804
- this.log(c.dim(c.green(` API started at http://${((_b = this.ctx.config.api) == null ? void 0 : _b.host) || "localhost"}:${c.bold(`${this.ctx.config.api.port}`)}`)));
9817
+ else if ((_b = this.ctx.config.api) == null ? void 0 : _b.port)
9818
+ this.log(c.dim(c.green(` API started at http://${((_c = this.ctx.config.api) == null ? void 0 : _c.host) || "localhost"}:${c.bold(`${this.ctx.config.api.port}`)}`)));
9805
9819
  if (this.ctx.coverageProvider)
9806
9820
  this.log(c.dim(" Coverage enabled with ") + c.yellow(this.ctx.coverageProvider.name));
9807
9821
  this.log();
@@ -10001,7 +10015,8 @@ function resolveOptimizerConfig(_testOptions, viteOptions, testConfig) {
10001
10015
  entries: []
10002
10016
  };
10003
10017
  } else {
10004
- const cacheDir = testConfig.cache !== false ? (_a = testConfig.cache) == null ? void 0 : _a.dir : null;
10018
+ const root = testConfig.root ?? process.cwd();
10019
+ const cacheDir = testConfig.cache !== false ? (_a = testConfig.cache) == null ? void 0 : _a.dir : void 0;
10005
10020
  const currentInclude = testOptions.include || (viteOptions == null ? void 0 : viteOptions.include) || [];
10006
10021
  const exclude = [
10007
10022
  "vitest",
@@ -10012,7 +10027,7 @@ function resolveOptimizerConfig(_testOptions, viteOptions, testConfig) {
10012
10027
  const runtime = currentInclude.filter((n) => n.endsWith("jsx-dev-runtime"));
10013
10028
  exclude.push(...runtime);
10014
10029
  const include = (testOptions.include || (viteOptions == null ? void 0 : viteOptions.include) || []).filter((n) => !exclude.includes(n));
10015
- newConfig.cacheDir = cacheDir ?? "node_modules/.vitest";
10030
+ newConfig.cacheDir = cacheDir ?? VitestCache.resolveCacheDir(root, cacheDir, testConfig.name);
10016
10031
  newConfig.optimizeDeps = {
10017
10032
  ...viteOptions,
10018
10033
  ...testOptions,
@@ -10071,10 +10086,10 @@ function resolveFsAllow(projectRoot, rootConfigFile) {
10071
10086
  return [dirname(rootConfigFile), searchForWorkspaceRoot(projectRoot)];
10072
10087
  }
10073
10088
 
10074
- async function createBrowserServer(project, options) {
10089
+ async function createBrowserServer(project, configFile) {
10075
10090
  const root = project.config.root;
10076
10091
  await ensurePackageInstalled("@vitest/browser", root);
10077
- const configPath = options.config === false ? false : options.config ? resolve(root, options.config) : await findUp(configFiles, { cwd: root });
10092
+ const configPath = typeof configFile === "string" ? configFile : false;
10078
10093
  const server = await createServer({
10079
10094
  logLevel: "error",
10080
10095
  mode: project.config.mode,
@@ -10097,6 +10112,7 @@ async function createBrowserServer(project, options) {
10097
10112
  const server2 = resolveApiServerConfig(((_a = config.test) == null ? void 0 : _a.browser) || {}) || {
10098
10113
  port: defaultBrowserPort
10099
10114
  };
10115
+ server2.middlewareMode = false;
10100
10116
  config.server = server2;
10101
10117
  (_b = config.server).fs ?? (_b.fs = {});
10102
10118
  config.server.fs.allow = config.server.fs.allow || [];
@@ -10118,7 +10134,7 @@ async function createBrowserServer(project, options) {
10118
10134
  });
10119
10135
  await server.listen();
10120
10136
  await server.watcher.close();
10121
- (await import('./chunk-api-setup.3b016b1c.js')).setup(project, server);
10137
+ (await import('./chunk-api-setup.d65b007d.js')).setup(project, server);
10122
10138
  return server;
10123
10139
  }
10124
10140
 
@@ -10452,9 +10468,8 @@ function VitestOptimizer() {
10452
10468
  const ssrOptimizer = resolveOptimizerConfig((_d = (_c = testConfig.deps) == null ? void 0 : _c.optimizer) == null ? void 0 : _d.ssr, (_e = viteConfig.ssr) == null ? void 0 : _e.optimizeDeps, testConfig);
10453
10469
  viteConfig.cacheDir = webOptimizer.cacheDir || ssrOptimizer.cacheDir || viteConfig.cacheDir;
10454
10470
  viteConfig.optimizeDeps = webOptimizer.optimizeDeps;
10455
- viteConfig.ssr = {
10456
- optimizeDeps: ssrOptimizer.optimizeDeps
10457
- };
10471
+ viteConfig.ssr ?? (viteConfig.ssr = {});
10472
+ viteConfig.ssr.optimizeDeps = ssrOptimizer.optimizeDeps;
10458
10473
  }
10459
10474
  }
10460
10475
  };
@@ -10470,7 +10485,7 @@ function WorkspaceVitestPlugin(project, options) {
10470
10485
  },
10471
10486
  config(viteConfig) {
10472
10487
  var _a, _b, _c;
10473
- const env = deleteDefineConfig(viteConfig);
10488
+ const defines = deleteDefineConfig(viteConfig);
10474
10489
  const testConfig = viteConfig.test || {};
10475
10490
  const root = testConfig.root || viteConfig.root || options.root;
10476
10491
  let name = testConfig.name;
@@ -10508,6 +10523,7 @@ function WorkspaceVitestPlugin(project, options) {
10508
10523
  open: false,
10509
10524
  hmr: false,
10510
10525
  preTransformRequests: false,
10526
+ middlewareMode: true,
10511
10527
  fs: {
10512
10528
  allow: resolveFsAllow(
10513
10529
  project.ctx.config.root,
@@ -10516,10 +10532,10 @@ function WorkspaceVitestPlugin(project, options) {
10516
10532
  }
10517
10533
  },
10518
10534
  test: {
10519
- env,
10520
10535
  name
10521
10536
  }
10522
10537
  };
10538
+ config.test.defines = defines;
10523
10539
  const classNameStrategy = typeof testConfig.css !== "boolean" && ((_b = (_a = testConfig.css) == null ? void 0 : _a.modules) == null ? void 0 : _b.classNameStrategy) || "stable";
10524
10540
  if (classNameStrategy !== "scoped") {
10525
10541
  config.css ?? (config.css = {});
@@ -10561,8 +10577,22 @@ function WorkspaceVitestPlugin(project, options) {
10561
10577
  ];
10562
10578
  }
10563
10579
 
10580
+ async function createViteServer(inlineConfig) {
10581
+ const error = console.error;
10582
+ console.error = (...args) => {
10583
+ if (typeof args[0] === "string" && args[0].includes("WebSocket server error:"))
10584
+ return;
10585
+ error(...args);
10586
+ };
10587
+ const server = await createServer({
10588
+ logLevel: "error",
10589
+ ...inlineConfig
10590
+ });
10591
+ console.error = error;
10592
+ return server;
10593
+ }
10594
+
10564
10595
  async function initializeProject(workspacePath, ctx, options) {
10565
- var _a, _b, _c, _d, _e, _f, _g;
10566
10596
  const project = new WorkspaceProject(workspacePath, ctx);
10567
10597
  const configFile = options.extends ? resolve(dirname(options.workspaceConfigPath), options.extends) : typeof workspacePath === "number" || workspacePath.endsWith("/") ? false : workspacePath;
10568
10598
  const root = options.root || (typeof workspacePath === "number" ? void 0 : dirname(workspacePath));
@@ -10578,11 +10608,7 @@ async function initializeProject(workspacePath, ctx, options) {
10578
10608
  WorkspaceVitestPlugin(project, { ...options, root, workspacePath })
10579
10609
  ]
10580
10610
  };
10581
- const server = await createServer(config);
10582
- if (((_a = ctx.config.api) == null ? void 0 : _a.port) || ((_d = (_c = (_b = project.config.deps) == null ? void 0 : _b.optimizer) == null ? void 0 : _c.web) == null ? void 0 : _d.enabled) || ((_g = (_f = (_e = project.config.deps) == null ? void 0 : _e.optimizer) == null ? void 0 : _f.ssr) == null ? void 0 : _g.enabled))
10583
- await server.listen();
10584
- else
10585
- await server.pluginContainer.buildStart({});
10611
+ await createViteServer(config);
10586
10612
  return project;
10587
10613
  }
10588
10614
  class WorkspaceProject {
@@ -10606,6 +10632,12 @@ class WorkspaceProject {
10606
10632
  isCore() {
10607
10633
  return this.ctx.getCoreWorkspaceProject() === this;
10608
10634
  }
10635
+ // it's possible that file path was imported with different queries (?raw, ?url, etc)
10636
+ getModulesByFilepath(file) {
10637
+ var _a;
10638
+ const set = this.server.moduleGraph.getModulesByFile(file) || ((_a = this.browser) == null ? void 0 : _a.moduleGraph.getModulesByFile(file));
10639
+ return set || /* @__PURE__ */ new Set();
10640
+ }
10609
10641
  getModuleById(id) {
10610
10642
  var _a;
10611
10643
  return this.server.moduleGraph.getModuleById(id) || ((_a = this.browser) == null ? void 0 : _a.moduleGraph.getModuleById(id));
@@ -10686,19 +10718,28 @@ class WorkspaceProject {
10686
10718
  }
10687
10719
  return testFiles;
10688
10720
  }
10689
- async initBrowserServer(options) {
10721
+ async initBrowserServer(configFile) {
10690
10722
  var _a;
10691
10723
  if (!this.isBrowserEnabled())
10692
10724
  return;
10693
10725
  await ((_a = this.browser) == null ? void 0 : _a.close());
10694
- this.browser = await createBrowserServer(this, options);
10695
- }
10696
- async setServer(options, server, params = {}) {
10726
+ this.browser = await createBrowserServer(this, configFile);
10727
+ }
10728
+ static async createCoreProject(ctx) {
10729
+ const project = new WorkspaceProject(ctx.config.name || ctx.config.root, ctx);
10730
+ project.vitenode = ctx.vitenode;
10731
+ project.server = ctx.server;
10732
+ project.runner = ctx.runner;
10733
+ project.config = ctx.config;
10734
+ await project.initBrowserServer(ctx.server.config.configFile);
10735
+ return project;
10736
+ }
10737
+ async setServer(options, server) {
10697
10738
  this.config = resolveConfig(this.ctx.mode, options, server.config);
10698
10739
  this.server = server;
10699
- this.vitenode = params.server ?? new ViteNodeServer(server, this.config);
10740
+ this.vitenode = new ViteNodeServer(server, this.config);
10700
10741
  const node = this.vitenode;
10701
- this.runner = params.runner ?? new ViteNodeRunner({
10742
+ this.runner = new ViteNodeRunner({
10702
10743
  root: server.config.root,
10703
10744
  base: server.config.base,
10704
10745
  fetchModule(id) {
@@ -10708,7 +10749,7 @@ class WorkspaceProject {
10708
10749
  return node.resolveId(id, importer);
10709
10750
  }
10710
10751
  });
10711
- await this.initBrowserServer(options);
10752
+ await this.initBrowserServer(this.server.config.configFile);
10712
10753
  }
10713
10754
  async report(name, ...args) {
10714
10755
  return this.ctx.report(name, ...args);
@@ -10925,18 +10966,13 @@ class Vitest {
10925
10966
  } catch {
10926
10967
  }
10927
10968
  await Promise.all(this._onSetServer.map((fn) => fn()));
10928
- this.projects = await this.resolveWorkspace(options, cliOptions);
10969
+ this.projects = await this.resolveWorkspace(cliOptions);
10929
10970
  if (this.config.testNamePattern)
10930
10971
  this.configOverride.testNamePattern = this.config.testNamePattern;
10931
10972
  }
10932
- async createCoreWorkspace(options) {
10933
- const coreWorkspace = new WorkspaceProject(this.config.root, this);
10934
- await coreWorkspace.setServer(options, this.server, {
10935
- runner: this.runner,
10936
- server: this.vitenode
10937
- });
10938
- this.coreWorkspaceProject = coreWorkspace;
10939
- return coreWorkspace;
10973
+ async createCoreProject() {
10974
+ this.coreWorkspaceProject = await WorkspaceProject.createCoreProject(this);
10975
+ return this.coreWorkspaceProject;
10940
10976
  }
10941
10977
  getCoreWorkspaceProject() {
10942
10978
  return this.coreWorkspaceProject || null;
@@ -10947,14 +10983,14 @@ class Vitest {
10947
10983
  const projectName = task.projectName || ((_a = task == null ? void 0 : task.file) == null ? void 0 : _a.projectName);
10948
10984
  return this.projects.find((p) => p.getName() === projectName) || this.getCoreWorkspaceProject() || this.projects[0];
10949
10985
  }
10950
- async resolveWorkspace(options, cliOptions) {
10986
+ async resolveWorkspace(cliOptions) {
10951
10987
  const configDir = this.server.config.configFile ? dirname(this.server.config.configFile) : this.config.root;
10952
10988
  const rootFiles = await promises.readdir(configDir);
10953
10989
  const workspaceConfigName = workspacesFiles.find((configFile) => {
10954
10990
  return rootFiles.includes(configFile);
10955
10991
  });
10956
10992
  if (!workspaceConfigName)
10957
- return [await this.createCoreWorkspace(options)];
10993
+ return [await this.createCoreProject()];
10958
10994
  const workspaceConfigPath = join(configDir, workspaceConfigName);
10959
10995
  const workspaceModule = await this.runner.executeFile(workspaceConfigPath);
10960
10996
  if (!workspaceModule.default || !Array.isArray(workspaceModule.default))
@@ -11023,14 +11059,14 @@ class Vitest {
11023
11059
  }, {});
11024
11060
  const projects = filteredWorkspaces.map(async (workspacePath) => {
11025
11061
  if (this.server.config.configFile === workspacePath)
11026
- return this.createCoreWorkspace(options);
11062
+ return this.createCoreProject();
11027
11063
  return initializeProject(workspacePath, this, { workspaceConfigPath, test: cliOverrides });
11028
11064
  });
11029
- projectsOptions.forEach((options2, index) => {
11030
- projects.push(initializeProject(index, this, mergeConfig(options2, { workspaceConfigPath, test: cliOverrides })));
11065
+ projectsOptions.forEach((options, index) => {
11066
+ projects.push(initializeProject(index, this, mergeConfig(options, { workspaceConfigPath, test: cliOverrides })));
11031
11067
  });
11032
11068
  if (!projects.length)
11033
- return [await this.createCoreWorkspace(options)];
11069
+ return [await this.createCoreProject()];
11034
11070
  const resolvedProjects = await Promise.all(projects);
11035
11071
  const names = /* @__PURE__ */ new Set();
11036
11072
  for (const project of resolvedProjects) {
@@ -11114,7 +11150,7 @@ class Vitest {
11114
11150
  }
11115
11151
  async filterTestsBySource(specs) {
11116
11152
  if (this.config.changed && !this.config.related) {
11117
- const { VitestGit } = await import('./chunk-node-git.c410fed8.js');
11153
+ const { VitestGit } = await import('./chunk-node-git.36288174.js');
11118
11154
  const vitestGit = new VitestGit(this.config.root);
11119
11155
  const related2 = await vitestGit.findChangedFiles({
11120
11156
  changedSince: this.config.changed
@@ -11267,7 +11303,7 @@ class Vitest {
11267
11303
  }
11268
11304
  getModuleProjects(id) {
11269
11305
  return this.projects.filter((project) => {
11270
- return project.getModuleById(id);
11306
+ return project.getModulesByFilepath(id).size;
11271
11307
  });
11272
11308
  }
11273
11309
  unregisterWatcher = noop$1;
@@ -11275,9 +11311,12 @@ class Vitest {
11275
11311
  const updateLastChanged = (id) => {
11276
11312
  const projects = this.getModuleProjects(id);
11277
11313
  projects.forEach(({ server, browser }) => {
11278
- const mod = server.moduleGraph.getModuleById(id) || (browser == null ? void 0 : browser.moduleGraph.getModuleById(id));
11279
- if (mod)
11280
- server.moduleGraph.invalidateModule(mod);
11314
+ const serverMods = server.moduleGraph.getModulesByFile(id);
11315
+ serverMods == null ? void 0 : serverMods.forEach((mod) => server.moduleGraph.invalidateModule(mod));
11316
+ if (browser) {
11317
+ const browserMods = browser.moduleGraph.getModulesByFile(id);
11318
+ browserMods == null ? void 0 : browserMods.forEach((mod) => browser.moduleGraph.invalidateModule(mod));
11319
+ }
11281
11320
  });
11282
11321
  };
11283
11322
  const onChange = (id) => {
@@ -11341,21 +11380,10 @@ class Vitest {
11341
11380
  return [];
11342
11381
  const files = [];
11343
11382
  for (const project of projects) {
11344
- const { server, browser } = project;
11345
- const mod = server.moduleGraph.getModuleById(id) || (browser == null ? void 0 : browser.moduleGraph.getModuleById(id));
11346
- if (!mod) {
11347
- const mods = browser == null ? void 0 : browser.moduleGraph.getModulesByFile(id);
11348
- if (!(mods == null ? void 0 : mods.size))
11349
- return [];
11350
- let rerun2 = false;
11351
- mods.forEach((m) => {
11352
- if (m.id && this.handleFileChanged(m.id))
11353
- rerun2 = true;
11354
- });
11355
- if (rerun2)
11356
- files.push(id);
11383
+ const { server } = project;
11384
+ const mods = project.getModulesByFilepath(id);
11385
+ if (!mods.size)
11357
11386
  continue;
11358
- }
11359
11387
  id = normalizeRequestId(id, server.config.base);
11360
11388
  this.invalidates.add(id);
11361
11389
  if (this.state.filesMap.has(id) || project.isTestFile(id)) {
@@ -11364,13 +11392,17 @@ class Vitest {
11364
11392
  continue;
11365
11393
  }
11366
11394
  let rerun = false;
11367
- mod.importers.forEach((i) => {
11368
- if (!i.id)
11369
- return;
11370
- const heedsRerun = this.handleFileChanged(i.id);
11371
- if (heedsRerun)
11372
- rerun = true;
11373
- });
11395
+ for (const mod of mods) {
11396
+ if (!mod.id)
11397
+ continue;
11398
+ mod.importers.forEach((i) => {
11399
+ if (!i.id)
11400
+ return;
11401
+ const heedsRerun = this.handleFileChanged(i.id);
11402
+ if (heedsRerun)
11403
+ rerun = true;
11404
+ });
11405
+ }
11374
11406
  if (rerun)
11375
11407
  files.push(id);
11376
11408
  }
@@ -11379,10 +11411,8 @@ class Vitest {
11379
11411
  async reportCoverage(allTestsRun) {
11380
11412
  if (!this.config.coverage.reportOnFailure && this.state.getCountOfFailedTests() > 0)
11381
11413
  return;
11382
- if (this.coverageProvider) {
11383
- this.logger.log(c.blue(" % ") + c.dim("Coverage report from ") + c.yellow(this.coverageProvider.name));
11414
+ if (this.coverageProvider)
11384
11415
  await this.coverageProvider.reportCoverage({ allTestsRun });
11385
- }
11386
11416
  }
11387
11417
  async close() {
11388
11418
  if (!this.closingPromise) {
@@ -11493,7 +11523,7 @@ async function VitestPlugin(options = {}, ctx = new Vitest("test")) {
11493
11523
  testConfig.api = resolveApiServerConfig(testConfig);
11494
11524
  const defines = deleteDefineConfig(viteConfig);
11495
11525
  options.defines = defines;
11496
- let open;
11526
+ let open = false;
11497
11527
  if (testConfig.ui && testConfig.open)
11498
11528
  open = testConfig.uiBase ?? "/__vitest__/";
11499
11529
  const config = {
@@ -11544,7 +11574,7 @@ async function VitestPlugin(options = {}, ctx = new Vitest("test")) {
11544
11574
  return config;
11545
11575
  },
11546
11576
  async configResolved(viteConfig) {
11547
- var _a, _b, _c, _d;
11577
+ var _a, _b, _c;
11548
11578
  const viteConfigTest = viteConfig.test || {};
11549
11579
  if (viteConfigTest.watch === false)
11550
11580
  viteConfigTest.run = true;
@@ -11560,9 +11590,8 @@ async function VitestPlugin(options = {}, ctx = new Vitest("test")) {
11560
11590
  const { PROD, DEV, ...envs } = viteConfig.env;
11561
11591
  (_a = process.env).PROD ?? (_a.PROD = PROD ? "1" : "");
11562
11592
  (_b = process.env).DEV ?? (_b.DEV = DEV ? "1" : "");
11563
- (_c = process.env).SSR ?? (_c.SSR = "1");
11564
11593
  for (const name in envs)
11565
- (_d = process.env)[name] ?? (_d[name] = envs[name]);
11594
+ (_c = process.env)[name] ?? (_c[name] = envs[name]);
11566
11595
  if (!options.watch) {
11567
11596
  viteConfig.server.watch = {
11568
11597
  persistent: false,
@@ -11581,7 +11610,7 @@ async function VitestPlugin(options = {}, ctx = new Vitest("test")) {
11581
11610
  try {
11582
11611
  await ctx.setServer(options, server, userConfig);
11583
11612
  if (options.api && options.watch)
11584
- (await import('./chunk-api-setup.3b016b1c.js')).setup(ctx);
11613
+ (await import('./chunk-api-setup.d65b007d.js')).setup(ctx);
11585
11614
  } catch (err) {
11586
11615
  await ctx.logger.printError(err, { fullStack: true });
11587
11616
  process.exit(1);
@@ -11602,7 +11631,7 @@ async function VitestPlugin(options = {}, ctx = new Vitest("test")) {
11602
11631
  }
11603
11632
 
11604
11633
  async function createVitest(mode, options, viteOverrides = {}) {
11605
- var _a, _b, _c, _d, _e, _f, _g;
11634
+ var _a;
11606
11635
  const ctx = new Vitest(mode);
11607
11636
  const root = resolve(options.root || process.cwd());
11608
11637
  const configPath = options.config === false ? false : options.config ? resolve(root, options.config) : await findUp(configFiles, { cwd: root });
@@ -11614,11 +11643,9 @@ async function createVitest(mode, options, viteOverrides = {}) {
11614
11643
  mode: options.mode || process.env.NODE_ENV || mode,
11615
11644
  plugins: await VitestPlugin(options, ctx)
11616
11645
  };
11617
- const server = await createServer(mergeConfig(config, mergeConfig(viteOverrides, { root: options.root })));
11618
- if (((_a = ctx.config.api) == null ? void 0 : _a.port) || ((_d = (_c = (_b = ctx.config.deps) == null ? void 0 : _b.optimizer) == null ? void 0 : _c.web) == null ? void 0 : _d.enabled) || ((_g = (_f = (_e = ctx.config.deps) == null ? void 0 : _e.optimizer) == null ? void 0 : _f.ssr) == null ? void 0 : _g.enabled))
11646
+ const server = await createViteServer(mergeConfig(config, mergeConfig(viteOverrides, { root: options.root })));
11647
+ if ((_a = ctx.config.api) == null ? void 0 : _a.port)
11619
11648
  await server.listen();
11620
- else
11621
- await server.pluginContainer.buildStart({});
11622
11649
  return ctx;
11623
11650
  }
11624
11651