vitest 3.2.2 → 3.2.3

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.
@@ -619,7 +619,7 @@ class CAC extends EventEmitter {
619
619
 
620
620
  const cac = (name = "") => new CAC(name);
621
621
 
622
- var version = "3.2.2";
622
+ var version = "3.2.3";
623
623
 
624
624
  const apiConfig = (port) => ({
625
625
  port: {
@@ -1407,7 +1407,7 @@ async function start(mode, cliFilters, options) {
1407
1407
  process.title = "node (vitest)";
1408
1408
  } catch {}
1409
1409
  try {
1410
- const { startVitest } = await import('./cli-api.DYcKW0ri.js').then(function (n) { return n.f; });
1410
+ const { startVitest } = await import('./cli-api.C37Ou0i1.js').then(function (n) { return n.f; });
1411
1411
  const ctx = await startVitest(mode, cliFilters.map(normalize), normalizeCliOptions(cliFilters, options));
1412
1412
  if (!ctx.shouldKeepServer()) await ctx.exit();
1413
1413
  } catch (e) {
@@ -1432,7 +1432,7 @@ async function collect(mode, cliFilters, options) {
1432
1432
  process.title = "node (vitest)";
1433
1433
  } catch {}
1434
1434
  try {
1435
- const { prepareVitest, processCollected, outputFileList } = await import('./cli-api.DYcKW0ri.js').then(function (n) { return n.f; });
1435
+ const { prepareVitest, processCollected, outputFileList } = await import('./cli-api.C37Ou0i1.js').then(function (n) { return n.f; });
1436
1436
  const ctx = await prepareVitest(mode, {
1437
1437
  ...normalizeCliOptions(cliFilters, options),
1438
1438
  watch: false,
@@ -11,7 +11,7 @@ import { generateFileHash, limitConcurrency, createFileTask, hasFailed, getTasks
11
11
  import { SnapshotManager } from '@vitest/snapshot/manager';
12
12
  import { ViteNodeRunner } from 'vite-node/client';
13
13
  import { ViteNodeServer } from 'vite-node/server';
14
- import { v as version$1 } from './cac.DId3f5oR.js';
14
+ import { v as version$1 } from './cac.Cs_fZ7zn.js';
15
15
  import { c as createBirpc } from './index.CJ0plNrh.js';
16
16
  import { p as parse, s as stringify, d as printError, f as formatProjectName, w as withLabel, e as errorBanner, h as divider, i as generateCodeFrame, R as ReportersMap, j as BlobReporter, r as readBlobs, H as HangingProcessReporter } from './index.CX5aIIXH.js';
17
17
  import require$$0$3 from 'events';
@@ -28,7 +28,7 @@ import { g as getDefaultExportFromCjs } from './_commonjsHelpers.BFTU3MAI.js';
28
28
  import { parseErrorStacktrace } from '@vitest/utils/source-map';
29
29
  import crypto, { createHash } from 'node:crypto';
30
30
  import { distDir, rootDir } from '../path.js';
31
- import { h as hash, R as RandomSequencer, i as isPackageExists, g as getFilePoolName, d as isBrowserEnabled, r as resolveConfig, e as groupBy, f as getCoverageProvider, j as createPool, w as wildcardPatternToRegExp, a as resolveApiServerConfig, s as stdout } from './coverage.ChgzEmIc.js';
31
+ import { h as hash, R as RandomSequencer, i as isPackageExists, g as getFilePoolName, d as isBrowserEnabled, r as resolveConfig, e as groupBy, f as getCoverageProvider, j as createPool, w as wildcardPatternToRegExp, a as resolveApiServerConfig, s as stdout } from './coverage.D1a3dTnj.js';
32
32
  import { c as convertTasksToEvents } from './typechecker.DRKU1-1g.js';
33
33
  import { Console } from 'node:console';
34
34
  import c from 'tinyrainbow';
@@ -5572,7 +5572,7 @@ class Logger {
5572
5572
  const output = project.isRootProject() ? "" : formatProjectName(project);
5573
5573
  const provider = project.browser.provider.name;
5574
5574
  const providerString = provider === "preview" ? "" : ` by ${c.reset(c.bold(provider))}`;
5575
- this.log(c.dim(`${output}Browser runner started${providerString} ${c.dim("at")} ${c.blue(new URL("/", origin))}\n`));
5575
+ this.log(c.dim(`${output}Browser runner started${providerString} ${c.dim("at")} ${c.blue(new URL("/__vitest_test__/", origin))}\n`));
5576
5576
  }
5577
5577
  printUnhandledErrors(errors) {
5578
5578
  const errorMessage = c.red(c.bold(`\nVitest caught ${errors.length} unhandled error${errors.length > 1 ? "s" : ""} during the test run.
@@ -6709,15 +6709,10 @@ function VitestCoreResolver(ctx) {
6709
6709
  function WorkspaceVitestPlugin(project, options) {
6710
6710
  return [
6711
6711
  {
6712
- name: "vitest:project",
6712
+ name: "vitest:project:name",
6713
6713
  enforce: "post",
6714
- options() {
6715
- this.meta.watchMode = false;
6716
- },
6717
6714
  config(viteConfig) {
6718
- const defines = deleteDefineConfig(viteConfig);
6719
6715
  const testConfig = viteConfig.test || {};
6720
- const root = testConfig.root || viteConfig.root || options.root;
6721
6716
  let { label: name, color } = typeof testConfig.name === "string" ? { label: testConfig.name } : {
6722
6717
  label: "",
6723
6718
  ...testConfig.name
@@ -6729,6 +6724,45 @@ function WorkspaceVitestPlugin(project, options) {
6729
6724
  if (existsSync(pkgJsonPath)) name = JSON.parse(readFileSync(pkgJsonPath, "utf-8")).name;
6730
6725
  if (typeof name !== "string" || !name) name = basename(dir);
6731
6726
  } else name = options.workspacePath.toString();
6727
+ const isUserBrowserEnabled = viteConfig.test?.browser?.enabled;
6728
+ const isBrowserEnabled = isUserBrowserEnabled ?? (viteConfig.test?.browser && project.vitest._cliOptions.browser?.enabled);
6729
+ // keep project names to potentially filter it out
6730
+ const workspaceNames = [name];
6731
+ const browser = viteConfig.test.browser || {};
6732
+ if (isBrowserEnabled && browser.name && !browser.instances?.length)
6733
+ // vitest injects `instances` in this case later on
6734
+ workspaceNames.push(name ? `${name} (${browser.name})` : browser.name);
6735
+ viteConfig.test?.browser?.instances?.forEach((instance) => {
6736
+ // every instance is a potential project
6737
+ instance.name ??= name ? `${name} (${instance.browser})` : instance.browser;
6738
+ if (isBrowserEnabled) workspaceNames.push(instance.name);
6739
+ });
6740
+ const filters = project.vitest.config.project;
6741
+ // if there is `--project=...` filter, check if any of the potential projects match
6742
+ // if projects don't match, we ignore the test project altogether
6743
+ // if some of them match, they will later be filtered again by `resolveWorkspace`
6744
+ if (filters.length) {
6745
+ const hasProject = workspaceNames.some((name) => {
6746
+ return project.vitest.matchesProjectFilter(name);
6747
+ });
6748
+ if (!hasProject) throw new VitestFilteredOutProjectError();
6749
+ }
6750
+ return { test: { name: {
6751
+ label: name,
6752
+ color
6753
+ } } };
6754
+ }
6755
+ },
6756
+ {
6757
+ name: "vitest:project",
6758
+ enforce: "pre",
6759
+ options() {
6760
+ this.meta.watchMode = false;
6761
+ },
6762
+ config(viteConfig) {
6763
+ const defines = deleteDefineConfig(viteConfig);
6764
+ const testConfig = viteConfig.test || {};
6765
+ const root = testConfig.root || viteConfig.root || options.root;
6732
6766
  const resolveOptions = getDefaultResolveOptions();
6733
6767
  const config = {
6734
6768
  root,
@@ -6752,35 +6786,9 @@ function WorkspaceVitestPlugin(project, options) {
6752
6786
  fs: { allow: resolveFsAllow(project.vitest.config.root, project.vitest.vite.config.configFile) }
6753
6787
  },
6754
6788
  environments: { ssr: { resolve: resolveOptions } },
6755
- test: { name: {
6756
- label: name,
6757
- color
6758
- } }
6789
+ test: {}
6759
6790
  };
6760
6791
  config.test.defines = defines;
6761
- const isUserBrowserEnabled = viteConfig.test?.browser?.enabled;
6762
- const isBrowserEnabled = isUserBrowserEnabled ?? (viteConfig.test?.browser && project.vitest._cliOptions.browser?.enabled);
6763
- // keep project names to potentially filter it out
6764
- const workspaceNames = [name];
6765
- const browser = viteConfig.test.browser || {};
6766
- if (isBrowserEnabled && browser.name && !browser.instances?.length)
6767
- // vitest injects `instances` in this case later on
6768
- workspaceNames.push(name ? `${name} (${browser.name})` : browser.name);
6769
- viteConfig.test?.browser?.instances?.forEach((instance) => {
6770
- // every instance is a potential project
6771
- instance.name ??= name ? `${name} (${instance.browser})` : instance.browser;
6772
- if (isBrowserEnabled) workspaceNames.push(instance.name);
6773
- });
6774
- const filters = project.vitest.config.project;
6775
- // if there is `--project=...` filter, check if any of the potential projects match
6776
- // if projects don't match, we ignore the test project altogether
6777
- // if some of them match, they will later be filtered again by `resolveWorkspace`
6778
- if (filters.length) {
6779
- const hasProject = workspaceNames.some((name) => {
6780
- return project.vitest.matchesProjectFilter(name);
6781
- });
6782
- if (!hasProject) throw new VitestFilteredOutProjectError();
6783
- }
6784
6792
  const classNameStrategy = typeof testConfig.css !== "boolean" && testConfig.css?.modules?.classNameStrategy || "stable";
6785
6793
  if (classNameStrategy !== "scoped") {
6786
6794
  config.css ??= {};
@@ -6793,7 +6801,11 @@ function WorkspaceVitestPlugin(project, options) {
6793
6801
  config.customLogger = createViteLogger(project.vitest.logger, viteConfig.logLevel || "warn", { allowClearScreen: false });
6794
6802
  config.customLogger = silenceImportViteIgnoreWarning(config.customLogger);
6795
6803
  return config;
6796
- },
6804
+ }
6805
+ },
6806
+ {
6807
+ name: "vitest:project:server",
6808
+ enforce: "post",
6797
6809
  async configureServer(server) {
6798
6810
  const options = deepMerge({}, configDefaults, server.config.test || {});
6799
6811
  await project._configureServer(options, server);
@@ -9053,6 +9065,21 @@ class VitestWatcher {
9053
9065
  if (needsRerun) this.scheduleRerun(id);
9054
9066
  }
9055
9067
  };
9068
+ handleSetupFile(filepath) {
9069
+ let isSetupFile = false;
9070
+ this.vitest.projects.forEach((project) => {
9071
+ if (!project.config.setupFiles.includes(filepath)) return;
9072
+ this.vitest.state.filesMap.forEach((files) => {
9073
+ files.forEach((file) => {
9074
+ if (file.projectName === project.name) {
9075
+ isSetupFile = true;
9076
+ this.changedTests.add(file.filepath);
9077
+ }
9078
+ });
9079
+ });
9080
+ });
9081
+ return isSetupFile;
9082
+ }
9056
9083
  /**
9057
9084
  * @returns A value indicating whether rerun is needed (changedTests was mutated)
9058
9085
  */
@@ -9062,6 +9089,7 @@ class VitestWatcher {
9062
9089
  this.vitest.state.getFilepaths().forEach((file) => this.changedTests.add(file));
9063
9090
  return true;
9064
9091
  }
9092
+ if (this.handleSetupFile(filepath)) return true;
9065
9093
  const projects = this.vitest.projects.filter((project) => {
9066
9094
  const moduleGraph = project.browser?.vite.moduleGraph || project.vite.moduleGraph;
9067
9095
  return moduleGraph.getModulesByFile(filepath)?.size;
@@ -2581,7 +2581,17 @@ function createChildProcessChannel$1(project, collect = false) {
2581
2581
  }), {
2582
2582
  eventNames: ["onCancel"],
2583
2583
  serialize: v8.serialize,
2584
- deserialize: (v) => v8.deserialize(Buffer.from(v)),
2584
+ deserialize: (v) => {
2585
+ try {
2586
+ return v8.deserialize(Buffer.from(v));
2587
+ } catch (error) {
2588
+ let stringified = "";
2589
+ try {
2590
+ stringified = `\nReceived value: ${JSON.stringify(v)}`;
2591
+ } catch {}
2592
+ throw new Error(`[vitest-pool]: Unexpected call to process.send(). Make sure your test cases are not interfering with process's channel.${stringified}`, { cause: error });
2593
+ }
2594
+ },
2585
2595
  post(v) {
2586
2596
  emitter.emit(events.message, v);
2587
2597
  },
@@ -3032,7 +3042,17 @@ function createChildProcessChannel(project, collect) {
3032
3042
  }), {
3033
3043
  eventNames: ["onCancel"],
3034
3044
  serialize: v8.serialize,
3035
- deserialize: (v) => v8.deserialize(Buffer.from(v)),
3045
+ deserialize: (v) => {
3046
+ try {
3047
+ return v8.deserialize(Buffer.from(v));
3048
+ } catch (error) {
3049
+ let stringified = "";
3050
+ try {
3051
+ stringified = `\nReceived value: ${JSON.stringify(v)}`;
3052
+ } catch {}
3053
+ throw new Error(`[vitest-pool]: Unexpected call to process.send(). Make sure your test cases are not interfering with process's channel.${stringified}`, { cause: error });
3054
+ }
3055
+ },
3036
3056
  post(v) {
3037
3057
  emitter.emit(events.message, v);
3038
3058
  },
package/dist/cli.js CHANGED
@@ -1,4 +1,4 @@
1
- import { c as createCLI } from './chunks/cac.DId3f5oR.js';
1
+ import { c as createCLI } from './chunks/cac.Cs_fZ7zn.js';
2
2
  import '@vitest/utils';
3
3
  import 'events';
4
4
  import 'pathe';
package/dist/coverage.js CHANGED
@@ -1,4 +1,4 @@
1
- export { B as BaseCoverageProvider } from './chunks/coverage.ChgzEmIc.js';
1
+ export { B as BaseCoverageProvider } from './chunks/coverage.D1a3dTnj.js';
2
2
  import 'node:fs';
3
3
  import 'pathe';
4
4
  import 'picomatch';
package/dist/node.js CHANGED
@@ -1,11 +1,11 @@
1
1
  import * as vite from 'vite';
2
2
  import { resolveConfig as resolveConfig$1, mergeConfig } from 'vite';
3
3
  export { esbuildVersion, isFileServingAllowed, parseAst, parseAstAsync, rollupVersion, version as viteVersion } from 'vite';
4
- import { V as Vitest, a as VitestPlugin, T as TestModule } from './chunks/cli-api.DYcKW0ri.js';
5
- export { G as GitNotFoundError, F as TestsNotFoundError, b as VitestPackageInstaller, e as createViteLogger, c as createVitest, i as isValidApiRequest, d as registerConsoleShortcuts, r as resolveFsAllow, s as startVitest } from './chunks/cli-api.DYcKW0ri.js';
6
- export { p as parseCLI } from './chunks/cac.DId3f5oR.js';
7
- import { r as resolveConfig$2 } from './chunks/coverage.ChgzEmIc.js';
8
- export { b as BaseSequencer, c as createMethodsRPC, g as getFilePoolName, a as resolveApiServerConfig } from './chunks/coverage.ChgzEmIc.js';
4
+ import { V as Vitest, a as VitestPlugin, T as TestModule } from './chunks/cli-api.C37Ou0i1.js';
5
+ export { G as GitNotFoundError, F as TestsNotFoundError, b as VitestPackageInstaller, e as createViteLogger, c as createVitest, i as isValidApiRequest, d as registerConsoleShortcuts, r as resolveFsAllow, s as startVitest } from './chunks/cli-api.C37Ou0i1.js';
6
+ export { p as parseCLI } from './chunks/cac.Cs_fZ7zn.js';
7
+ import { r as resolveConfig$2 } from './chunks/coverage.D1a3dTnj.js';
8
+ export { b as BaseSequencer, c as createMethodsRPC, g as getFilePoolName, a as resolveApiServerConfig } from './chunks/coverage.D1a3dTnj.js';
9
9
  import { slash, deepClone } from '@vitest/utils';
10
10
  import { f as findUp } from './chunks/index.X0nbfr6-.js';
11
11
  import { resolve } from 'pathe';
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "vitest",
3
3
  "type": "module",
4
- "version": "3.2.2",
4
+ "version": "3.2.3",
5
5
  "description": "Next generation testing framework powered by Vite",
6
6
  "author": "Anthony Fu <anthonyfu117@hotmail.com>",
7
7
  "license": "MIT",
@@ -119,8 +119,8 @@
119
119
  "@types/node": "^18.0.0 || ^20.0.0 || >=22.0.0",
120
120
  "happy-dom": "*",
121
121
  "jsdom": "*",
122
- "@vitest/browser": "3.2.2",
123
- "@vitest/ui": "3.2.2"
122
+ "@vitest/browser": "3.2.3",
123
+ "@vitest/ui": "3.2.3"
124
124
  },
125
125
  "peerDependenciesMeta": {
126
126
  "@edge-runtime/vm": {
@@ -161,14 +161,14 @@
161
161
  "tinyrainbow": "^2.0.0",
162
162
  "vite": "^5.0.0 || ^6.0.0 || ^7.0.0-0",
163
163
  "why-is-node-running": "^2.3.0",
164
- "@vitest/pretty-format": "^3.2.2",
165
- "@vitest/snapshot": "3.2.2",
166
- "@vitest/runner": "3.2.2",
167
- "@vitest/spy": "3.2.2",
168
- "@vitest/utils": "3.2.2",
169
- "@vitest/expect": "3.2.2",
170
- "@vitest/mocker": "3.2.2",
171
- "vite-node": "3.2.2"
164
+ "@vitest/expect": "3.2.3",
165
+ "@vitest/pretty-format": "^3.2.3",
166
+ "@vitest/runner": "3.2.3",
167
+ "@vitest/spy": "3.2.3",
168
+ "@vitest/snapshot": "3.2.3",
169
+ "@vitest/mocker": "3.2.3",
170
+ "@vitest/utils": "3.2.3",
171
+ "vite-node": "3.2.3"
172
172
  },
173
173
  "devDependencies": {
174
174
  "@ampproject/remapping": "^2.3.0",