vitest 0.0.116 → 0.0.120

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.
package/dist/cli.js CHANGED
@@ -7,8 +7,8 @@ import process$1 from 'process';
7
7
  import { m as mergeStream, g as getStream, c as crossSpawn } from './index-6e709f57.js';
8
8
  import require$$0, { constants } from 'os';
9
9
  import { s as signalExit } from './index-648e7ab2.js';
10
- import { e as ensurePackageInstalled } from './index-bf29f0e6.js';
11
- import { c as createVitest } from './index-1af8810e.js';
10
+ import { e as ensurePackageInstalled } from './index-090545ef.js';
11
+ import { c as createVitest } from './index-df5396e4.js';
12
12
  import './_commonjsHelpers-c9e3b764.js';
13
13
  import 'fs';
14
14
  import 'stream';
@@ -18,10 +18,10 @@ import 'url';
18
18
  import 'tty';
19
19
  import 'local-pkg';
20
20
  import 'vite';
21
- import './constants-080f26e8.js';
21
+ import './constants-22bbd600.js';
22
22
  import './magic-string.es-94000aea.js';
23
23
  import 'perf_hooks';
24
- import './diff-80c47cfa.js';
24
+ import './diff-a295cb37.js';
25
25
  import 'module';
26
26
  import 'worker_threads';
27
27
  import 'tinypool';
@@ -1700,10 +1700,11 @@ function execa(file, args, options) {
1700
1700
  return mergePromise(spawned, handlePromiseOnce);
1701
1701
  }
1702
1702
 
1703
- var version = "0.0.116";
1703
+ var version = "0.0.120";
1704
1704
 
1705
+ const CLOSE_TIMEOUT = 1e3;
1705
1706
  const cli = cac("vitest");
1706
- cli.version(version).option("-r, --root <path>", "root path").option("-c, --config <path>", "path to config file").option("-u, --update", "update snapshot").option("-w, --watch", "watch mode").option("-o, --open", "open UI", { default: false }).option("--api", "listen to port and serve API").option("--threads", "enabled threads", { default: true }).option("--silent", "silent console output from tests").option("--reporter <name>", "reporter").option("--coverage", "use c8 for coverage").option("--run", "do not watch").option("--global", "inject apis globally").option("--dom", "mock browser api with happy-dom").option("--environment <env>", "runner environment", { default: "node" }).option("--passWithNoTests", "pass when no tests found").help();
1707
+ cli.version(version).option("-r, --root <path>", "root path").option("-c, --config <path>", "path to config file").option("-u, --update", "update snapshot").option("-w, --watch", "watch mode").option("-o, --open", "open UI", { default: false }).option("-t, --testNamePattern <pattern>", "run test names with the specified pattern").option("--api", "listen to port and serve API").option("--threads", "enabled threads", { default: true }).option("--silent", "silent console output from tests").option("--reporter <name>", "reporter").option("--coverage", "use c8 for coverage").option("--run", "do not watch").option("--global", "inject apis globally").option("--dom", "mock browser api with happy-dom").option("--environment <env>", "runner environment", { default: "node" }).option("--passWithNoTests", "pass when no tests found").help();
1707
1708
  cli.command("run [...filters]").action(run);
1708
1709
  cli.command("watch [...filters]").action(dev);
1709
1710
  cli.command("dev [...filters]").action(dev);
@@ -1750,18 +1751,36 @@ async function run(cliFilters, options) {
1750
1751
  if (!ctx.config.watch)
1751
1752
  await ctx.close();
1752
1753
  }
1753
- if (!ctx.config.watch)
1754
- process.exit();
1754
+ if (!ctx.config.watch) {
1755
+ setTimeout(() => process.exit(), CLOSE_TIMEOUT).unref();
1756
+ }
1757
+ }
1758
+ function closeServerAndExitProcess(ctx) {
1759
+ const closePromise = ctx.close();
1760
+ let timeout;
1761
+ const timeoutPromise = new Promise((resolve, reject) => {
1762
+ timeout = setTimeout(() => reject(new Error(`close timed out after ${CLOSE_TIMEOUT}ms`)), CLOSE_TIMEOUT);
1763
+ });
1764
+ Promise.race([closePromise, timeoutPromise]).then(() => {
1765
+ clearTimeout(timeout);
1766
+ process.exit(0);
1767
+ }, (err) => {
1768
+ clearTimeout(timeout);
1769
+ console.error("error during close", err);
1770
+ process.exit(1);
1771
+ });
1755
1772
  }
1756
1773
  function registerConsoleShortcuts(ctx) {
1757
1774
  require$$0$1.emitKeypressEvents(process.stdin);
1758
1775
  process.stdin.setRawMode(true);
1759
1776
  process.stdin.on("keypress", (str, key) => {
1760
- if (str === "" || str === "" || key && key.ctrl && key.name === "c")
1761
- process.exit();
1777
+ if (str === "" || str === "" || key && key.ctrl && key.name === "c") {
1778
+ closeServerAndExitProcess(ctx);
1779
+ return;
1780
+ }
1762
1781
  if (ctx.runningPromise)
1763
1782
  return;
1764
1783
  if (ctx.isFirstRun)
1765
- process.exit();
1784
+ closeServerAndExitProcess(ctx);
1766
1785
  });
1767
1786
  }
@@ -1,5 +1,5 @@
1
1
  import { fileURLToPath } from 'url';
2
- import { k as resolve } from './index-bf29f0e6.js';
2
+ import { k as resolve } from './index-090545ef.js';
3
3
 
4
4
  const distDir = resolve(fileURLToPath(import.meta.url), "../../dist");
5
5
  const defaultInclude = ["**/*.{test,spec}.{js,mjs,cjs,ts,mts,cts,jsx,tsx}"];
@@ -1,5 +1,5 @@
1
1
  import { existsSync, promises } from 'fs';
2
- import { o as notNullish, c, r as relative } from './index-bf29f0e6.js';
2
+ import { o as notNullish, c, r as relative } from './index-090545ef.js';
3
3
 
4
4
  function Diff() {}
5
5
  Diff.prototype = {
package/dist/entry.js CHANGED
@@ -1,17 +1,17 @@
1
1
  import fs, { promises } from 'fs';
2
- import { f as equals, h as iterableEquality, j as subsetEquality, k as isA, J as JestChaiExpect, l as clearContext, m as defaultSuite, n as setHooks, o as getHooks, p as context, s as setState, q as getFn, b as getState, e as vi } from './vi-b3412f83.js';
2
+ import { f as equals, h as iterableEquality, j as subsetEquality, k as isA, J as JestChaiExpect, l as clearContext, m as defaultSuite, n as setHooks, o as getHooks, p as context, s as setState, q as getFn, b as getState, e as vi } from './vi-67a5a3b3.js';
3
3
  import { Console } from 'console';
4
4
  import { Writable } from 'stream';
5
5
  import { importModule } from 'local-pkg';
6
6
  import chai$1, { expect, util } from 'chai';
7
7
  import { a as commonjsRequire, c as commonjsGlobal } from './_commonjsHelpers-c9e3b764.js';
8
- import { q as index, s as slash, u as getNames, c as c$1, t as toArray, r as relative, v as interpretOnlyMode, w as partitionSuiteChildren, x as hasTests, h as hasFailed } from './index-bf29f0e6.js';
8
+ import { u as index, s as slash, v as getNames, c as c$1, t as toArray, r as relative, w as partitionSuiteChildren, x as hasTests, h as hasFailed } from './index-090545ef.js';
9
9
  import { r as rpc } from './rpc-8c7cc374.js';
10
- import { l as getOriginalPos, m as posToNumber, n as parseStack, u as unifiedDiff } from './diff-80c47cfa.js';
10
+ import { l as getOriginalPos, m as posToNumber, n as parseStack, u as unifiedDiff } from './diff-a295cb37.js';
11
11
  import { performance } from 'perf_hooks';
12
12
  import { createHash } from 'crypto';
13
13
  import { format as format$1 } from 'util';
14
- import './jest-mock-4a754991.js';
14
+ import './jest-mock-038a01b3.js';
15
15
  import 'tinyspy';
16
16
  import 'url';
17
17
  import 'tty';
@@ -2907,7 +2907,7 @@ class SnapshotState {
2907
2907
  this._dirty = dirty;
2908
2908
  this._inlineSnapshots = [];
2909
2909
  this._uncheckedKeys = new Set(Object.keys(this._snapshotData));
2910
- this._counters = /* @__PURE__ */ new Map();
2910
+ this._counters = new Map();
2911
2911
  this._index = 0;
2912
2912
  this.expand = options.expand || false;
2913
2913
  this.added = 0;
@@ -2944,7 +2944,7 @@ class SnapshotState {
2944
2944
  }
2945
2945
  clear() {
2946
2946
  this._snapshotData = this._initialData;
2947
- this._counters = /* @__PURE__ */ new Map();
2947
+ this._counters = new Map();
2948
2948
  this._index = 0;
2949
2949
  this.added = 0;
2950
2950
  this.matched = 0;
@@ -3532,7 +3532,7 @@ async function setupGlobalEnv(config) {
3532
3532
  setupConsoleLogSpy();
3533
3533
  await setupChai();
3534
3534
  if (config.global)
3535
- (await import('./global-a73dfade.js')).registerApiGlobally();
3535
+ (await import('./global-9532b920.js')).registerApiGlobally();
3536
3536
  }
3537
3537
  function setupConsoleLogSpy() {
3538
3538
  const stdout = new Writable({
@@ -3580,7 +3580,7 @@ async function runSetupFiles(config) {
3580
3580
  }));
3581
3581
  }
3582
3582
 
3583
- function serializeError(val, seen = /* @__PURE__ */ new WeakSet()) {
3583
+ function serializeError(val, seen = new WeakSet()) {
3584
3584
  if (!val || typeof val === "string")
3585
3585
  return val;
3586
3586
  if (typeof val === "function")
@@ -3596,9 +3596,15 @@ function serializeError(val, seen = /* @__PURE__ */ new WeakSet()) {
3596
3596
  if (seen.has(val))
3597
3597
  return val;
3598
3598
  seen.add(val);
3599
- Object.keys(val).forEach((key) => {
3600
- val[key] = serializeError(val[key], seen);
3601
- });
3599
+ if (Array.isArray(val)) {
3600
+ val = val.map((e) => {
3601
+ return serializeError(e, seen);
3602
+ });
3603
+ } else {
3604
+ Object.keys(val).forEach((key) => {
3605
+ val[key] = serializeError(val[key], seen);
3606
+ });
3607
+ }
3602
3608
  return val;
3603
3609
  }
3604
3610
  function processError(err) {
@@ -3657,12 +3663,51 @@ async function collectTests(paths, config) {
3657
3663
  process.stdout.write("\0");
3658
3664
  }
3659
3665
  calculateHash(file);
3666
+ interpretTaskModes(file, config.testNamePattern);
3660
3667
  files.push(file);
3661
3668
  }
3662
- const tasks = files.reduce((tasks2, file) => tasks2.concat(file.tasks), []);
3663
- interpretOnlyMode(tasks);
3664
3669
  return files;
3665
3670
  }
3671
+ function interpretTaskModes(suite, namePattern, onlyMode) {
3672
+ if (onlyMode === void 0)
3673
+ onlyMode = someTasksAreOnly(suite);
3674
+ suite.tasks.forEach((t) => {
3675
+ if (onlyMode) {
3676
+ if (t.type === "suite" && someTasksAreOnly(t)) {
3677
+ if (t.mode === "only")
3678
+ t.mode = "run";
3679
+ interpretTaskModes(t, namePattern, onlyMode);
3680
+ } else if (t.mode === "run") {
3681
+ t.mode = "skip";
3682
+ } else if (t.mode === "only") {
3683
+ t.mode = "run";
3684
+ }
3685
+ }
3686
+ if (t.type === "test") {
3687
+ if (namePattern && !t.name.match(namePattern))
3688
+ t.mode = "skip";
3689
+ } else if (t.type === "suite") {
3690
+ if (t.mode === "skip")
3691
+ skipAllTasks(t);
3692
+ if (t.mode === "run") {
3693
+ if (t.tasks.every((i) => i.mode !== "run"))
3694
+ t.mode = "skip";
3695
+ }
3696
+ }
3697
+ });
3698
+ }
3699
+ function someTasksAreOnly(suite) {
3700
+ return suite.tasks.some((t) => t.mode === "only" || t.type === "suite" && someTasksAreOnly(t));
3701
+ }
3702
+ function skipAllTasks(suite) {
3703
+ suite.tasks.forEach((t) => {
3704
+ if (t.mode === "run") {
3705
+ t.mode = "skip";
3706
+ if (t.type === "suite")
3707
+ skipAllTasks(t);
3708
+ }
3709
+ });
3710
+ }
3666
3711
  function calculateHash(parent) {
3667
3712
  parent.tasks.forEach((t, idx) => {
3668
3713
  t.id = `${parent.id}_${idx}`;
@@ -1,13 +1,13 @@
1
- import { g as globalApis } from './constants-080f26e8.js';
2
- import { i as index } from './index-80d9a771.js';
1
+ import { g as globalApis } from './constants-22bbd600.js';
2
+ import { i as index } from './index-ea959009.js';
3
3
  import 'url';
4
- import './index-bf29f0e6.js';
4
+ import './index-090545ef.js';
5
5
  import 'tty';
6
6
  import 'local-pkg';
7
7
  import 'path';
8
- import './vi-b3412f83.js';
8
+ import './vi-67a5a3b3.js';
9
9
  import './_commonjsHelpers-c9e3b764.js';
10
- import './jest-mock-4a754991.js';
10
+ import './jest-mock-038a01b3.js';
11
11
  import 'chai';
12
12
  import 'tinyspy';
13
13
 
@@ -282,24 +282,6 @@ function partitionSuiteChildren(suite) {
282
282
  tasksGroups.push(tasksGroup);
283
283
  return tasksGroups;
284
284
  }
285
- function interpretOnlyMode(tasks) {
286
- if (tasks.some((t) => t.mode === "only")) {
287
- tasks.forEach((t) => {
288
- if (t.mode === "run")
289
- t.mode = "skip";
290
- else if (t.mode === "only")
291
- t.mode = "run";
292
- });
293
- }
294
- tasks.forEach((t) => {
295
- if (t.type === "suite") {
296
- if (t.mode === "skip")
297
- t.tasks.forEach((c2) => c2.mode === "run" && (c2.mode = "skip"));
298
- else
299
- interpretOnlyMode(t.tasks);
300
- }
301
- });
302
- }
303
285
  function getTests(suite) {
304
286
  return toArray(suite).flatMap((s) => s.type === "test" ? [s] : s.tasks.flatMap((c2) => c2.type === "test" ? [c2] : getTests(c2)));
305
287
  }
@@ -383,4 +365,4 @@ function toFilePath(id, root) {
383
365
  return isWindows && absolute.startsWith("/") ? fileURLToPath(pathToFileURL(absolute.slice(1)).href) : absolute;
384
366
  }
385
367
 
386
- export { isAbsolute as a, basename as b, c, dirname as d, ensurePackageInstalled as e, getSuites as f, getFullName as g, hasFailed as h, isObject as i, getTests as j, resolve as k, deepMerge as l, toFilePath as m, noop as n, notNullish as o, mergeSlashes as p, index as q, relative as r, slash as s, toArray as t, getNames as u, interpretOnlyMode as v, partitionSuiteChildren as w, hasTests as x, isWindows as y, getTasks as z };
368
+ export { isAbsolute as a, basename as b, c, dirname as d, ensurePackageInstalled as e, getSuites as f, getFullName as g, hasFailed as h, isObject as i, getTests as j, resolve as k, deepMerge as l, toFilePath as m, noop as n, notNullish as o, mergeSlashes as p, join as q, relative as r, slash as s, toArray as t, index as u, getNames as v, partitionSuiteChildren as w, hasTests as x, isWindows as y, getTasks as z };
@@ -1,4 +1,4 @@
1
- import { c, s as slash$1, a as isAbsolute, r as relative, d as dirname, b as basename, g as getFullName, h as hasFailed, f as getSuites, j as getTests, t as toArray, k as resolve, l as deepMerge, m as toFilePath, n as noop$1 } from './index-bf29f0e6.js';
1
+ import { c, s as slash$1, a as isAbsolute, r as relative, d as dirname, b as basename, g as getFullName, h as hasFailed, f as getSuites, j as getTests, t as toArray, k as resolve, l as deepMerge, m as toFilePath, n as noop$1 } from './index-090545ef.js';
2
2
  import { createServer, mergeConfig } from 'vite';
3
3
  import path$a from 'path';
4
4
  import process$1 from 'process';
@@ -7,10 +7,10 @@ import require$$0 from 'os';
7
7
  import require$$0$1 from 'util';
8
8
  import require$$0$2 from 'stream';
9
9
  import require$$2 from 'events';
10
- import { d as defaultInclude, a as defaultExclude, b as defaultPort, c as distDir, e as configFiles } from './constants-080f26e8.js';
10
+ import { d as defaultInclude, a as defaultExclude, b as defaultPort, c as distDir, e as configFiles } from './constants-22bbd600.js';
11
11
  import MagicString from './magic-string.es-94000aea.js';
12
12
  import { performance } from 'perf_hooks';
13
- import { F as F_POINTER, a as F_DOWN, s as stripAnsi, b as F_LONG_DASH, c as F_DOWN_RIGHT, d as F_DOT, e as F_CHECK, f as F_CROSS, g as F_RIGHT, p as printError, h as stringWidth, i as ansiStyles, j as sliceAnsi, k as cliTruncate } from './diff-80c47cfa.js';
13
+ import { F as F_POINTER, a as F_DOWN, s as stripAnsi, b as F_LONG_DASH, c as F_DOWN_RIGHT, d as F_DOT, e as F_CHECK, f as F_CROSS, g as F_RIGHT, p as printError, h as stringWidth, i as ansiStyles, j as sliceAnsi, k as cliTruncate } from './diff-a295cb37.js';
14
14
  import { o as onetime, s as signalExit } from './index-648e7ab2.js';
15
15
  import { createRequire } from 'module';
16
16
  import { pathToFileURL } from 'url';
@@ -6847,9 +6847,9 @@ const MocksPlugin = () => {
6847
6847
  };
6848
6848
  };
6849
6849
 
6850
- const spinnerMap = /* @__PURE__ */ new WeakMap();
6850
+ const spinnerMap = new WeakMap();
6851
6851
  const pointer = c.yellow(F_POINTER);
6852
- const skipped = c.yellow(F_DOWN);
6852
+ const skipped = c.dim(c.gray(F_DOWN));
6853
6853
  function getCols(delta = 0) {
6854
6854
  let length = process.stdout.columns;
6855
6855
  if (!length || isNaN(length))
@@ -6993,8 +6993,8 @@ ${c.inverse(c.bold(mode))} ${c.gray(this.ctx.config.root)}
6993
6993
  if (this.isTTY)
6994
6994
  return;
6995
6995
  for (const pack of packs) {
6996
- const task = this.ctx.state.idMap[pack[0]];
6997
- if (task.type === "test" && ((_a = task.result) == null ? void 0 : _a.state) && ((_b = task.result) == null ? void 0 : _b.state) !== "run") {
6996
+ const task = this.ctx.state.idMap.get(pack[0]);
6997
+ if (task && task.type === "test" && ((_a = task.result) == null ? void 0 : _a.state) && ((_b = task.result) == null ? void 0 : _b.state) !== "run") {
6998
6998
  this.ctx.log(` ${getStateSymbol(task)} ${getFullName(task)}`);
6999
6999
  if (task.result.state === "fail")
7000
7000
  this.ctx.log(c.red(` ${F_RIGHT} ${(_c = task.result.error) == null ? void 0 : _c.message}`));
@@ -7024,7 +7024,7 @@ ${c.bold(c.inverse(c.green(" PASS ")))}${c.green(" Waiting for file changes...")
7024
7024
  onUserConsoleLog(log) {
7025
7025
  if (this.ctx.config.silent)
7026
7026
  return;
7027
- const task = log.taskId ? this.ctx.state.idMap[log.taskId] : void 0;
7027
+ const task = log.taskId ? this.ctx.state.idMap.get(log.taskId) : void 0;
7028
7028
  this.ctx.log(c.gray(log.type + c.dim(` | ${task ? getFullName(task) : "unknown test"}`)));
7029
7029
  process[log.type].write(`${log.content}
7030
7030
  `);
@@ -7598,7 +7598,7 @@ createLogUpdate(process$1.stderr);
7598
7598
 
7599
7599
  const DURATION_LONG = 300;
7600
7600
  const MAX_HEIGHT = 20;
7601
- const outputMap = /* @__PURE__ */ new WeakMap();
7601
+ const outputMap = new WeakMap();
7602
7602
  function formatFilepath(path) {
7603
7603
  const lastSlash = Math.max(path.lastIndexOf("/") + 1, 0);
7604
7604
  const basename = path.slice(lastSlash);
@@ -7614,10 +7614,10 @@ function renderTree(tasks, options, level = 0) {
7614
7614
  for (const task of tasks) {
7615
7615
  let suffix = "";
7616
7616
  const prefix = ` ${getStateSymbol(task)} `;
7617
- if (task.mode === "skip" || task.mode === "todo")
7618
- suffix += ` ${c.dim("[skipped]")}`;
7619
7617
  if (task.type === "suite")
7620
7618
  suffix += c.dim(` (${getTests(task).length})`);
7619
+ if (task.mode === "skip" || task.mode === "todo")
7620
+ suffix += ` ${c.dim(c.gray("[skipped]"))}`;
7621
7621
  if ((_a = task.result) == null ? void 0 : _a.end) {
7622
7622
  const duration = task.result.end - task.result.start;
7623
7623
  if (duration > DURATION_LONG)
@@ -7707,9 +7707,8 @@ class DefaultReporter extends BaseReporter {
7707
7707
  }
7708
7708
  async stopListRender() {
7709
7709
  var _a;
7710
- (_a = this.renderer) == null ? void 0 : _a.stop();
7710
+ await ((_a = this.renderer) == null ? void 0 : _a.stop());
7711
7711
  this.renderer = void 0;
7712
- await new Promise((resolve) => setTimeout(resolve, 10));
7713
7712
  }
7714
7713
  async onWatcherRerun(files, trigger) {
7715
7714
  await this.stopListRender();
@@ -7864,7 +7863,7 @@ function resolveC8Options(options, root) {
7864
7863
  reportsDirectory: "./coverage",
7865
7864
  excludeNodeModules: true,
7866
7865
  exclude: defaultExcludes,
7867
- reporter: "text",
7866
+ reporter: ["text", "html"],
7868
7867
  allowExternal: false
7869
7868
  }, options);
7870
7869
  resolved.reporter = toArray(resolved.reporter);
@@ -7874,27 +7873,19 @@ function resolveC8Options(options, root) {
7874
7873
  }
7875
7874
  async function cleanCoverage(options, clean = true) {
7876
7875
  if (clean && existsSync(options.reportsDirectory))
7877
- await promises.rmdir(options.reportsDirectory, { recursive: true });
7876
+ await promises.rm(options.reportsDirectory, { recursive: true, force: true });
7878
7877
  if (!existsSync(options.tempDirectory))
7879
7878
  await promises.mkdir(options.tempDirectory, { recursive: true });
7880
7879
  }
7881
- async function prepareCoverage(options) {
7882
- if (options.enabled)
7883
- return false;
7884
- await cleanCoverage(options, options.clean);
7885
- }
7886
7880
  const require2 = createRequire(import.meta.url);
7887
7881
  async function reportCoverage(ctx) {
7888
7882
  const createReport = require2("c8/lib/report");
7889
7883
  const report = createReport(ctx.config.coverage);
7890
7884
  Array.from(ctx.visitedFilesMap.entries()).filter((i) => !i[0].includes("/node_modules/")).forEach(([file, map]) => {
7891
- if (!existsSync(file))
7892
- return;
7893
7885
  const url = pathToFileURL(file).href;
7886
+ const sources = map.sources.length ? map.sources.map((i) => pathToFileURL(i).href) : [url];
7894
7887
  report.sourceMapCache[url] = {
7895
- data: __spreadProps$1(__spreadValues$1({}, map), {
7896
- sources: map.sources.map((i) => pathToFileURL(i).href) || [url]
7897
- })
7888
+ data: __spreadProps$1(__spreadValues$1({}, map), { sources })
7898
7889
  };
7899
7890
  });
7900
7891
  await report.run();
@@ -7902,25 +7893,25 @@ async function reportCoverage(ctx) {
7902
7893
 
7903
7894
  class StateManager {
7904
7895
  constructor() {
7905
- this.filesMap = {};
7906
- this.idMap = {};
7907
- this.taskFileMap = /* @__PURE__ */ new WeakMap();
7896
+ this.filesMap = new Map();
7897
+ this.idMap = new Map();
7898
+ this.taskFileMap = new WeakMap();
7908
7899
  }
7909
7900
  getFiles(keys) {
7910
7901
  if (keys)
7911
- return keys.map((key) => this.filesMap[key]);
7912
- return Object.values(this.filesMap);
7902
+ return keys.map((key) => this.filesMap.get(key));
7903
+ return Array.from(this.filesMap.values());
7913
7904
  }
7914
7905
  collectFiles(files = []) {
7915
7906
  files.forEach((file) => {
7916
- this.filesMap[file.filepath] = file;
7907
+ this.filesMap.set(file.filepath, file);
7917
7908
  this.updateId(file);
7918
7909
  });
7919
7910
  }
7920
7911
  updateId(task) {
7921
- if (this.idMap[task.id] === task)
7912
+ if (this.idMap.get(task.id) === task)
7922
7913
  return;
7923
- this.idMap[task.id] = task;
7914
+ this.idMap.set(task.id, task);
7924
7915
  if (task.type === "suite") {
7925
7916
  task.tasks.forEach((task2) => {
7926
7917
  this.updateId(task2);
@@ -7929,8 +7920,8 @@ class StateManager {
7929
7920
  }
7930
7921
  updateTasks(packs) {
7931
7922
  for (const [id, result] of packs) {
7932
- if (this.idMap[id])
7933
- this.idMap[id].result = result;
7923
+ if (this.idMap.has(id))
7924
+ this.idMap.get(id).result = result;
7934
7925
  }
7935
7926
  }
7936
7927
  }
@@ -7975,6 +7966,7 @@ function resolveConfig(options, viteConfig) {
7975
7966
  resolved.testTimeout = resolved.testTimeout ?? 5e3;
7976
7967
  resolved.hookTimeout = resolved.hookTimeout ?? 1e4;
7977
7968
  resolved.isolate = resolved.isolate ?? true;
7969
+ resolved.testNamePattern = resolved.testNamePattern ? resolved.testNamePattern instanceof RegExp ? resolved.testNamePattern : new RegExp(resolved.testNamePattern) : void 0;
7978
7970
  resolved.watchIgnore = resolved.watchIgnore ?? [/\/node_modules\//, /\/dist\//];
7979
7971
  const CI = !!process.env.CI;
7980
7972
  const UPDATE_SNAPSHOT = resolved.update || process.env.UPDATE_SNAPSHOT;
@@ -7991,7 +7983,7 @@ function resolveConfig(options, viteConfig) {
7991
7983
  return resolved;
7992
7984
  }
7993
7985
 
7994
- const promiseMap = /* @__PURE__ */ new Map();
7986
+ const promiseMap = new Map();
7995
7987
  async function transformRequest(ctx, id) {
7996
7988
  if (!promiseMap.has(id)) {
7997
7989
  promiseMap.set(id, _transformRequest(ctx, id).then((r) => {
@@ -8010,11 +8002,10 @@ async function _transformRequest(ctx, id) {
8010
8002
  if (result)
8011
8003
  result = await ctx.server.ssrTransform(result.code, result.map, id);
8012
8004
  }
8013
- if (result && process.env.NODE_V8_COVERAGE) {
8005
+ if (result)
8014
8006
  withInlineSourcemap(result);
8015
- if (result.map)
8016
- ctx.visitedFilesMap.set(toFilePath(id, ctx.config.root), result.map);
8017
- }
8007
+ if ((result == null ? void 0 : result.map) && process.env.NODE_V8_COVERAGE)
8008
+ ctx.visitedFilesMap.set(toFilePath(id, ctx.config.root), result.map);
8018
8009
  return result;
8019
8010
  }
8020
8011
  let SOURCEMAPPING_URL = "sourceMa";
@@ -8093,7 +8084,8 @@ function createWorkerPool(ctx) {
8093
8084
  return {
8094
8085
  runTests: runWithFiles("run"),
8095
8086
  collectTests: runWithFiles("collect"),
8096
- close: () => pool.destroy()
8087
+ close: async () => {
8088
+ }
8097
8089
  };
8098
8090
  }
8099
8091
  function createChannel(ctx) {
@@ -8153,9 +8145,9 @@ class Vitest {
8153
8145
  this.reporters = void 0;
8154
8146
  this.outputStream = process.stdout;
8155
8147
  this.errorStream = process.stderr;
8156
- this.invalidates = /* @__PURE__ */ new Set();
8157
- this.changedTests = /* @__PURE__ */ new Set();
8158
- this.visitedFilesMap = /* @__PURE__ */ new Map();
8148
+ this.invalidates = new Set();
8149
+ this.changedTests = new Set();
8150
+ this.visitedFilesMap = new Map();
8159
8151
  this.isFirstRun = true;
8160
8152
  this.restartsCount = 0;
8161
8153
  this._onRestartListeners = [];
@@ -8190,7 +8182,7 @@ class Vitest {
8190
8182
  this.runningPromise = void 0;
8191
8183
  this._onRestartListeners.forEach((fn) => fn());
8192
8184
  if (resolved.coverage.enabled)
8193
- await prepareCoverage(resolved.coverage);
8185
+ await cleanCoverage(resolved.coverage, resolved.coverage.clean);
8194
8186
  }
8195
8187
  async start(filters) {
8196
8188
  this.report("onInit", this);
@@ -8268,8 +8260,8 @@ class Vitest {
8268
8260
  const onUnlink = (id) => {
8269
8261
  id = slash$1(id);
8270
8262
  this.invalidates.add(id);
8271
- if (id in this.state.filesMap) {
8272
- delete this.state.filesMap[id];
8263
+ if (this.state.filesMap.has(id)) {
8264
+ this.state.filesMap.delete(id);
8273
8265
  this.changedTests.delete(id);
8274
8266
  }
8275
8267
  };
@@ -8298,7 +8290,7 @@ class Vitest {
8298
8290
  if (!mod)
8299
8291
  return;
8300
8292
  this.invalidates.add(id);
8301
- if (id in this.state.filesMap) {
8293
+ if (this.state.filesMap.has(id)) {
8302
8294
  this.changedTests.add(id);
8303
8295
  return;
8304
8296
  }
@@ -8309,8 +8301,17 @@ class Vitest {
8309
8301
  }
8310
8302
  async close() {
8311
8303
  var _a;
8312
- await ((_a = this.pool) == null ? void 0 : _a.close());
8313
- await this.server.close();
8304
+ if (!this.closingPromise) {
8305
+ this.closingPromise = Promise.allSettled([
8306
+ (_a = this.pool) == null ? void 0 : _a.close(),
8307
+ this.server.close()
8308
+ ].filter(Boolean)).then((results) => {
8309
+ results.filter((r) => r.status === "rejected").forEach((err) => {
8310
+ this.error("error during close", err.reason);
8311
+ });
8312
+ });
8313
+ }
8314
+ return this.closingPromise;
8314
8315
  }
8315
8316
  async report(name, ...args) {
8316
8317
  await Promise.all(this.reporters.map((r) => {
@@ -8356,7 +8357,7 @@ async function createVitest(options, viteOverrides = {}) {
8356
8357
  await ctx.setServer(options, server2);
8357
8358
  haveStarted = true;
8358
8359
  if (options.api)
8359
- (await import('./setup-95b119ff.js')).setup(ctx);
8360
+ (await import('./setup-c9c7cb5b.js')).setup(ctx);
8360
8361
  }
8361
8362
  },
8362
8363
  MocksPlugin()
@@ -8365,6 +8366,9 @@ async function createVitest(options, viteOverrides = {}) {
8365
8366
  open: options.open,
8366
8367
  strictPort: true
8367
8368
  },
8369
+ build: {
8370
+ sourcemap: true
8371
+ },
8368
8372
  optimizeDeps: {
8369
8373
  exclude: [
8370
8374
  "vitest"
@@ -1,6 +1,6 @@
1
- import { g as getCurrentSuite, w as withTimeout, a as getDefaultHookTimeout, b as getState, s as setState, c as suite, t as test, d as describe, i as it, v as vitest, e as vi } from './vi-b3412f83.js';
1
+ import { g as getCurrentSuite, w as withTimeout, a as getDefaultHookTimeout, b as getState, s as setState, c as suite, t as test, d as describe, i as it, v as vitest, e as vi } from './vi-67a5a3b3.js';
2
2
  import chai, { assert, should } from 'chai';
3
- import { s as spies, a as spyOn, f as fn } from './jest-mock-4a754991.js';
3
+ import { s as spies, a as spyOn, f as fn } from './jest-mock-038a01b3.js';
4
4
 
5
5
  const beforeAll = (fn, timeout) => getCurrentSuite().on("beforeAll", withTimeout(fn, timeout ?? getDefaultHookTimeout()));
6
6
  const afterAll = (fn, timeout) => getCurrentSuite().on("afterAll", withTimeout(fn, timeout ?? getDefaultHookTimeout()));
package/dist/index.d.ts CHANGED
@@ -177,8 +177,8 @@ interface WorkerPool {
177
177
  }
178
178
 
179
179
  declare class StateManager {
180
- filesMap: Record<string, File>;
181
- idMap: Record<string, Task>;
180
+ filesMap: Map<string, File>;
181
+ idMap: Map<string, Task>;
182
182
  taskFileMap: WeakMap<Task, File>;
183
183
  getFiles(keys?: string[]): File[];
184
184
  collectFiles(files?: File[]): void;
@@ -204,6 +204,7 @@ declare class Vitest {
204
204
  changedTests: Set<string>;
205
205
  visitedFilesMap: Map<string, RawSourceMap>;
206
206
  runningPromise?: Promise<void>;
207
+ closingPromise?: Promise<void>;
207
208
  isFirstRun: boolean;
208
209
  restartsCount: number;
209
210
  private _onRestartListeners;
@@ -624,6 +625,10 @@ interface InlineConfig {
624
625
  * @internal WIP
625
626
  */
626
627
  open?: boolean;
628
+ /**
629
+ * run test names with the specified pattern
630
+ */
631
+ testNamePattern?: string | RegExp;
627
632
  /**
628
633
  * Listen to port and serve API
629
634
  *
@@ -673,9 +678,10 @@ interface UserConfig extends InlineConfig {
673
678
  */
674
679
  passWithNoTests?: boolean;
675
680
  }
676
- interface ResolvedConfig extends Omit<Required<UserConfig>, 'config' | 'filters' | 'coverage'> {
681
+ interface ResolvedConfig extends Omit<Required<UserConfig>, 'config' | 'filters' | 'coverage' | 'testNamePattern'> {
677
682
  config?: string;
678
683
  filters?: string[];
684
+ testNamePattern?: RegExp;
679
685
  depsInline: (string | RegExp)[];
680
686
  depsExternal: (string | RegExp)[];
681
687
  coverage: ResolvedC8Options;
@@ -866,6 +872,15 @@ declare class VitestUtils {
866
872
  declare const vitest: VitestUtils;
867
873
  declare const vi: VitestUtils;
868
874
 
875
+ interface WebSocketHandlers {
876
+ getFiles(): File[];
877
+ getConfig(): ResolvedConfig;
878
+ getSourceCode(id: string): Promise<string>;
879
+ rerun(files: string[]): Promise<void>;
880
+ }
881
+ interface WebSocketEvents extends Pick<Reporter, 'onCollected' | 'onTaskUpdate'> {
882
+ }
883
+
869
884
  declare type VitestInlineConfig = InlineConfig;
870
885
 
871
886
  declare module 'vite' {
@@ -941,4 +956,4 @@ declare global {
941
956
  }
942
957
  }
943
958
 
944
- export { ArgumentsOf, ArgumentsType, Arrayable, Awaitable, BuiltinEnvironment, ComputeMode, ConstructorArgumentsOf, DoneCallback, Environment, EnvironmentReturn, File, HookListener, InlineConfig, JestMockCompat, JestMockCompatContext, JestMockCompatFn, MaybeMocked, MaybeMockedConstructor, MaybeMockedDeep, MethodKeysOf, MockWithArgs, MockableFunction, MockedFunction, MockedFunctionDeep, MockedObject, MockedObjectDeep, ModuleCache, Nullable, ParsedStack, Position, PropertyKeysOf, Reporter, ResolvedConfig, RunMode, RuntimeContext, SnapshotData, SnapshotMatchOptions, SnapshotResult, SnapshotStateOptions, SnapshotSummary, SnapshotUpdateState, Suite, SuiteCollector, SuiteHooks, Task, TaskBase, TaskResult, TaskResultPack, TaskState, Test, TestCollector, TestFactory, TestFunction, UncheckedSnapshot, UserConfig, UserConsoleLog, WorkerContext, WorkerRPC, afterAll, afterEach, beforeAll, beforeEach, describe, expect, fn, it, spies, spyOn, suite, test, vi, vitest };
959
+ export { ArgumentsOf, ArgumentsType, Arrayable, Awaitable, BuiltinEnvironment, ComputeMode, ConstructorArgumentsOf, DoneCallback, Environment, EnvironmentReturn, File, HookListener, InlineConfig, JestMockCompat, JestMockCompatContext, JestMockCompatFn, MaybeMocked, MaybeMockedConstructor, MaybeMockedDeep, MethodKeysOf, MockWithArgs, MockableFunction, MockedFunction, MockedFunctionDeep, MockedObject, MockedObjectDeep, ModuleCache, Nullable, ParsedStack, Position, PropertyKeysOf, Reporter, ResolvedConfig, RunMode, RuntimeContext, SnapshotData, SnapshotMatchOptions, SnapshotResult, SnapshotStateOptions, SnapshotSummary, SnapshotUpdateState, Suite, SuiteCollector, SuiteHooks, Task, TaskBase, TaskResult, TaskResultPack, TaskState, Test, TestCollector, TestFactory, TestFunction, UncheckedSnapshot, UserConfig, UserConsoleLog, WebSocketEvents, WebSocketHandlers, WorkerContext, WorkerRPC, afterAll, afterEach, beforeAll, beforeEach, describe, expect, fn, it, spies, spyOn, suite, test, vi, vitest };
package/dist/index.js CHANGED
@@ -1,8 +1,8 @@
1
- export { d as describe, i as it, c as suite, t as test, e as vi, v as vitest } from './vi-b3412f83.js';
2
- export { a as afterAll, d as afterEach, b as beforeAll, c as beforeEach, e as expect } from './index-80d9a771.js';
3
- export { f as fn, s as spies, a as spyOn } from './jest-mock-4a754991.js';
1
+ export { d as describe, i as it, c as suite, t as test, e as vi, v as vitest } from './vi-67a5a3b3.js';
2
+ export { a as afterAll, d as afterEach, b as beforeAll, c as beforeEach, e as expect } from './index-ea959009.js';
3
+ export { f as fn, s as spies, a as spyOn } from './jest-mock-038a01b3.js';
4
4
  export { assert, default as chai, should } from 'chai';
5
- import './index-bf29f0e6.js';
5
+ import './index-090545ef.js';
6
6
  import 'url';
7
7
  import 'tty';
8
8
  import 'local-pkg';
@@ -1,7 +1,7 @@
1
1
  import { util } from 'chai';
2
2
  import * as tinyspy from 'tinyspy';
3
3
 
4
- const spies = /* @__PURE__ */ new Set();
4
+ const spies = new Set();
5
5
  function spyOn(obj, method, accessType) {
6
6
  const dictionary = {
7
7
  get: "getter",
package/dist/node.d.ts CHANGED
@@ -334,6 +334,10 @@ interface InlineConfig {
334
334
  * @internal WIP
335
335
  */
336
336
  open?: boolean;
337
+ /**
338
+ * run test names with the specified pattern
339
+ */
340
+ testNamePattern?: string | RegExp;
337
341
  /**
338
342
  * Listen to port and serve API
339
343
  *
@@ -383,9 +387,10 @@ interface UserConfig extends InlineConfig {
383
387
  */
384
388
  passWithNoTests?: boolean;
385
389
  }
386
- interface ResolvedConfig extends Omit<Required<UserConfig>, 'config' | 'filters' | 'coverage'> {
390
+ interface ResolvedConfig extends Omit<Required<UserConfig>, 'config' | 'filters' | 'coverage' | 'testNamePattern'> {
387
391
  config?: string;
388
392
  filters?: string[];
393
+ testNamePattern?: RegExp;
389
394
  depsInline: (string | RegExp)[];
390
395
  depsExternal: (string | RegExp)[];
391
396
  coverage: ResolvedC8Options;
@@ -408,8 +413,8 @@ interface WorkerPool {
408
413
  }
409
414
 
410
415
  declare class StateManager {
411
- filesMap: Record<string, File>;
412
- idMap: Record<string, Task>;
416
+ filesMap: Map<string, File>;
417
+ idMap: Map<string, Task>;
413
418
  taskFileMap: WeakMap<Task, File>;
414
419
  getFiles(keys?: string[]): File[];
415
420
  collectFiles(files?: File[]): void;
@@ -435,6 +440,7 @@ declare class Vitest {
435
440
  changedTests: Set<string>;
436
441
  visitedFilesMap: Map<string, RawSourceMap>;
437
442
  runningPromise?: Promise<void>;
443
+ closingPromise?: Promise<void>;
438
444
  isFirstRun: boolean;
439
445
  restartsCount: number;
440
446
  private _onRestartListeners;
package/dist/node.js CHANGED
@@ -1,5 +1,5 @@
1
- export { c as createVitest } from './index-1af8810e.js';
2
- import './index-bf29f0e6.js';
1
+ export { c as createVitest } from './index-df5396e4.js';
2
+ import './index-090545ef.js';
3
3
  import 'url';
4
4
  import 'tty';
5
5
  import 'local-pkg';
@@ -11,10 +11,10 @@ import 'os';
11
11
  import 'util';
12
12
  import 'stream';
13
13
  import 'events';
14
- import './constants-080f26e8.js';
14
+ import './constants-22bbd600.js';
15
15
  import './magic-string.es-94000aea.js';
16
16
  import 'perf_hooks';
17
- import './diff-80c47cfa.js';
17
+ import './diff-a295cb37.js';
18
18
  import './index-648e7ab2.js';
19
19
  import './_commonjsHelpers-c9e3b764.js';
20
20
  import 'assert';
@@ -9,8 +9,8 @@ import require$$2 from 'events';
9
9
  import require$$1 from 'https';
10
10
  import require$$2$1 from 'http';
11
11
  import require$$7 from 'url';
12
- import { A as API_PATH } from './constants-080f26e8.js';
13
- import './index-bf29f0e6.js';
12
+ import { A as API_PATH } from './constants-22bbd600.js';
13
+ import './index-090545ef.js';
14
14
  import 'tty';
15
15
  import 'local-pkg';
16
16
  import 'path';
@@ -4248,7 +4248,7 @@ function abortHandshake(socket, code, message, headers) {
4248
4248
  function setup(ctx) {
4249
4249
  var _a;
4250
4250
  const wss = new websocketServer({ noServer: true });
4251
- const clients = /* @__PURE__ */ new Map();
4251
+ const clients = new Map();
4252
4252
  (_a = ctx.server.httpServer) == null ? void 0 : _a.on("upgrade", (request, socket, head) => {
4253
4253
  if (!request.url)
4254
4254
  return;
package/dist/utils.js CHANGED
@@ -1,4 +1,4 @@
1
- export { l as deepMerge, e as ensurePackageInstalled, g as getFullName, u as getNames, f as getSuites, z as getTasks, j as getTests, h as hasFailed, x as hasTests, v as interpretOnlyMode, i as isObject, y as isWindows, p as mergeSlashes, n as noop, o as notNullish, w as partitionSuiteChildren, k as resolvePath, s as slash, t as toArray, m as toFilePath } from './index-bf29f0e6.js';
1
+ export { l as deepMerge, e as ensurePackageInstalled, g as getFullName, v as getNames, f as getSuites, z as getTasks, j as getTests, h as hasFailed, x as hasTests, i as isObject, y as isWindows, p as mergeSlashes, n as noop, o as notNullish, w as partitionSuiteChildren, k as resolvePath, s as slash, t as toArray, m as toFilePath } from './index-090545ef.js';
2
2
  import 'url';
3
3
  import 'tty';
4
4
  import 'local-pkg';
@@ -1,6 +1,6 @@
1
- import { n as noop, i as isObject } from './index-bf29f0e6.js';
1
+ import { n as noop, i as isObject } from './index-090545ef.js';
2
2
  import { c as commonjsGlobal, g as getDefaultExportFromCjs } from './_commonjsHelpers-c9e3b764.js';
3
- import { a as spyOn, f as fn, s as spies } from './jest-mock-4a754991.js';
3
+ import { a as spyOn, f as fn, s as spies } from './jest-mock-038a01b3.js';
4
4
 
5
5
  var __defProp = Object.defineProperty;
6
6
  var __defProps = Object.defineProperties;
@@ -86,8 +86,8 @@ function normalizeTest(fn, timeout) {
86
86
  return withTimeout(ensureAsyncTest(fn), timeout);
87
87
  }
88
88
 
89
- const fnMap = /* @__PURE__ */ new WeakMap();
90
- const hooksMap = /* @__PURE__ */ new WeakMap();
89
+ const fnMap = new WeakMap();
90
+ const hooksMap = new WeakMap();
91
91
  function setFn(key, fn) {
92
92
  fnMap.set(key, fn);
93
93
  }
@@ -206,7 +206,7 @@ function equals(a, b, customTesters, strictCheck) {
206
206
  function isAsymmetric(obj) {
207
207
  return !!obj && isA("Function", obj.asymmetricMatch);
208
208
  }
209
- function hasAsymmetric(obj, seen = /* @__PURE__ */ new Set()) {
209
+ function hasAsymmetric(obj, seen = new Set()) {
210
210
  if (seen.has(obj))
211
211
  return false;
212
212
  seen.add(obj);
@@ -410,7 +410,7 @@ const hasPropertyInObject = (object, key) => {
410
410
  };
411
411
  const isObjectWithKeys = (a) => isObject(a) && !(a instanceof Error) && !(a instanceof Array) && !(a instanceof Date);
412
412
  const subsetEquality = (object, subset) => {
413
- const subsetEqualityWithContext = (seenReferences = /* @__PURE__ */ new WeakMap()) => (object2, subset2) => {
413
+ const subsetEqualityWithContext = (seenReferences = new WeakMap()) => (object2, subset2) => {
414
414
  if (!isObjectWithKeys(subset2))
415
415
  return void 0;
416
416
  return Object.keys(subset2).every((key) => {
@@ -429,6 +429,31 @@ const subsetEquality = (object, subset) => {
429
429
  };
430
430
  return subsetEqualityWithContext()(object, subset);
431
431
  };
432
+ const typeEquality = (a, b) => {
433
+ if (a == null || b == null || a.constructor === b.constructor)
434
+ return void 0;
435
+ return false;
436
+ };
437
+ const arrayBufferEquality = (a, b) => {
438
+ if (!(a instanceof ArrayBuffer) || !(b instanceof ArrayBuffer))
439
+ return void 0;
440
+ const dataViewA = new DataView(a);
441
+ const dataViewB = new DataView(b);
442
+ if (dataViewA.byteLength !== dataViewB.byteLength)
443
+ return false;
444
+ for (let i = 0; i < dataViewA.byteLength; i++) {
445
+ if (dataViewA.getUint8(i) !== dataViewB.getUint8(i))
446
+ return false;
447
+ }
448
+ return true;
449
+ };
450
+ const sparseArrayEquality = (a, b) => {
451
+ if (!Array.isArray(a) || !Array.isArray(b))
452
+ return void 0;
453
+ const aKeys = Object.keys(a);
454
+ const bKeys = Object.keys(b);
455
+ return equals(a, b, [iterableEquality, typeEquality], true) && equals(aKeys, bKeys);
456
+ };
432
457
 
433
458
  const MATCHERS_OBJECT = Symbol.for("matchers-object");
434
459
  if (!Object.prototype.hasOwnProperty.call(global, MATCHERS_OBJECT)) {
@@ -487,7 +512,7 @@ const JestChaiExpect = (chai, utils) => {
487
512
  return this.eql(expected);
488
513
  });
489
514
  def("toStrictEqual", function(expected) {
490
- return this.chaiEqual(expected);
515
+ return iterableEquality(this, expected) ?? typeEquality(this, expected) ?? sparseArrayEquality(this, expected) ?? arrayBufferEquality(this, expected);
491
516
  });
492
517
  def("toBe", function(expected) {
493
518
  return this.equal(expected);
@@ -772,6 +797,12 @@ const originalSetInterval = global.setInterval;
772
797
  const originalClearTimeout = global.clearTimeout;
773
798
  const originalClearInterval = global.clearInterval;
774
799
  const MAX_LOOPS = 1e4;
800
+ var QueueTaskType;
801
+ (function(QueueTaskType2) {
802
+ QueueTaskType2["Interval"] = "interval";
803
+ QueueTaskType2["Timeout"] = "timeout";
804
+ QueueTaskType2["Immediate"] = "immediate";
805
+ })(QueueTaskType || (QueueTaskType = {}));
775
806
  const assertEvery = (assertions, message) => {
776
807
  if (assertions.some((a) => !a))
777
808
  throw new Error(message);
@@ -816,8 +847,8 @@ class FakeTimers {
816
847
  return resultBuilder(id, cb);
817
848
  };
818
849
  };
819
- this._setTimeout = spyOn(global, "setTimeout").mockImplementation(spyFactory("timeout" /* Timeout */, getNodeTimeout));
820
- this._setInterval = spyOn(global, "setInterval").mockImplementation(spyFactory("interval" /* Interval */, getNodeTimeout));
850
+ this._setTimeout = spyOn(global, "setTimeout").mockImplementation(spyFactory(QueueTaskType.Timeout, getNodeTimeout));
851
+ this._setInterval = spyOn(global, "setInterval").mockImplementation(spyFactory(QueueTaskType.Interval, getNodeTimeout));
821
852
  const clearTimerFactory = (spyType) => (id) => {
822
853
  if (id === void 0)
823
854
  return;
@@ -825,8 +856,8 @@ class FakeTimers {
825
856
  if (index !== -1)
826
857
  this._tasksQueue.splice(index, 1);
827
858
  };
828
- this._clearTimeout = spyOn(global, "clearTimeout").mockImplementation(clearTimerFactory("timeout" /* Timeout */));
829
- this._clearInterval = spyOn(global, "clearInterval").mockImplementation(clearTimerFactory("interval" /* Interval */));
859
+ this._clearTimeout = spyOn(global, "clearTimeout").mockImplementation(clearTimerFactory(QueueTaskType.Timeout));
860
+ this._clearInterval = spyOn(global, "clearInterval").mockImplementation(clearTimerFactory(QueueTaskType.Interval));
830
861
  }
831
862
  useRealTimers() {
832
863
  this._isMocked = false;
@@ -922,7 +953,7 @@ class FakeTimers {
922
953
  this._tasksQueue.sort((t1, t2) => {
923
954
  const diff = t1.call.nestedMs - t2.call.nestedMs;
924
955
  if (diff === 0) {
925
- if (t1.type === "immediate" /* Immediate */ && t2.type !== "immediate" /* Immediate */)
956
+ if (t1.type === QueueTaskType.Immediate && t2.type !== QueueTaskType.Immediate)
926
957
  return 1;
927
958
  return 0;
928
959
  }
package/dist/worker.js CHANGED
@@ -1,6 +1,6 @@
1
- import { k as resolve, d as dirname$2, b as basename$2, p as mergeSlashes, s as slash, m as toFilePath } from './index-bf29f0e6.js';
1
+ import { d as dirname$2, b as basename$2, k as resolve, p as mergeSlashes, q as join$2, s as slash, m as toFilePath } from './index-090545ef.js';
2
2
  import { c as createBirpc } from './index-e909c175.js';
3
- import { c as distDir } from './constants-080f26e8.js';
3
+ import { c as distDir } from './constants-22bbd600.js';
4
4
  import { builtinModules, createRequire } from 'module';
5
5
  import { pathToFileURL, fileURLToPath as fileURLToPath$2, URL as URL$1 } from 'url';
6
6
  import vm from 'vm';
@@ -8,7 +8,7 @@ import path from 'path';
8
8
  import fs, { promises, realpathSync, statSync, Stats, existsSync, readdirSync } from 'fs';
9
9
  import assert from 'assert';
10
10
  import { format as format$2, inspect } from 'util';
11
- import { a as spyOn, s as spies } from './jest-mock-4a754991.js';
11
+ import { a as spyOn, s as spies } from './jest-mock-038a01b3.js';
12
12
  import { r as rpc } from './rpc-8c7cc374.js';
13
13
  import 'tty';
14
14
  import 'local-pkg';
@@ -9218,13 +9218,15 @@ var __spreadValues = (a, b) => {
9218
9218
  };
9219
9219
  function resolveMockPath(mockPath, root, nmName) {
9220
9220
  if (nmName) {
9221
- const mockFolder = resolve(root, "__mocks__");
9221
+ const mockDirname = dirname$2(nmName);
9222
+ const baseFilename = basename$2(nmName);
9223
+ const mockFolder = resolve(root, "__mocks__", mockDirname);
9222
9224
  if (!existsSync(mockFolder))
9223
9225
  return null;
9224
9226
  const files = readdirSync(mockFolder);
9225
9227
  for (const file of files) {
9226
9228
  const [basename2] = file.split(".");
9227
- if (basename2 === nmName)
9229
+ if (basename2 === baseFilename)
9228
9230
  return resolve(mockFolder, file).replace(root, "");
9229
9231
  }
9230
9232
  return null;
@@ -9306,6 +9308,11 @@ function createMocker(root, mockMap) {
9306
9308
  s.mockClear();
9307
9309
  });
9308
9310
  }
9311
+ function resolveDependency(dep) {
9312
+ if (dep.startsWith("/node_modules/"))
9313
+ return mergeSlashes(`/@fs/${join$2(root, dep)}`);
9314
+ return dep;
9315
+ }
9309
9316
  return {
9310
9317
  mockPath,
9311
9318
  unmockPath,
@@ -9313,12 +9320,14 @@ function createMocker(root, mockMap) {
9313
9320
  getActualPath,
9314
9321
  mockObject,
9315
9322
  getSuiteFilepath,
9316
- resolveMockPath
9323
+ resolveMockPath,
9324
+ resolveDependency
9317
9325
  };
9318
9326
  }
9319
9327
 
9320
9328
  const defaultInline = [
9321
9329
  "vitest/dist",
9330
+ /vitest-virtual-\w+\/dist/,
9322
9331
  /virtual:/,
9323
9332
  /\.ts$/,
9324
9333
  /\/esm\/.*\.js$/,
@@ -9343,29 +9352,33 @@ const stubRequests = {
9343
9352
  }
9344
9353
  }
9345
9354
  };
9355
+ function hasNestedDefault(target) {
9356
+ return "__esModule" in target && target.__esModule && "default" in target.default;
9357
+ }
9358
+ function proxyMethod(name, isNested) {
9359
+ return function(target, key, ...args) {
9360
+ const result = Reflect[name](target, key, ...args);
9361
+ if (isNested && key === "default" || !result)
9362
+ return Reflect[name](target.default, key, ...args);
9363
+ return result;
9364
+ };
9365
+ }
9346
9366
  async function interpretedImport(path, interpretDefault) {
9347
9367
  const mod = await import(path);
9348
9368
  if (interpretDefault && "default" in mod) {
9369
+ const isNested = hasNestedDefault(mod);
9349
9370
  return new Proxy(mod, {
9350
- get(target, key, receiver) {
9351
- return Reflect.get(target, key, receiver) || Reflect.get(target.default, key, receiver);
9352
- },
9353
- set(target, key, value, receiver) {
9354
- return Reflect.set(target, key, value, receiver) || Reflect.set(target.default, key, value, receiver);
9355
- },
9356
- has(target, key) {
9357
- return Reflect.has(target, key) || Reflect.has(target.default, key);
9358
- },
9359
- deleteProperty(target, key) {
9360
- return Reflect.deleteProperty(target, key) || Reflect.deleteProperty(target.default, key);
9361
- }
9371
+ get: proxyMethod("get", isNested),
9372
+ set: proxyMethod("set", isNested),
9373
+ has: proxyMethod("has", isNested),
9374
+ deleteProperty: proxyMethod("deleteProperty", isNested)
9362
9375
  });
9363
9376
  }
9364
9377
  return mod;
9365
9378
  }
9366
9379
  async function executeInViteNode(options) {
9367
9380
  const { moduleCache, root, files, fetch, mockMap } = options;
9368
- const externalCache = /* @__PURE__ */ new Map();
9381
+ const externalCache = new Map();
9369
9382
  builtinModules.forEach((m) => externalCache.set(m, true));
9370
9383
  const {
9371
9384
  getActualPath,
@@ -9374,7 +9387,8 @@ async function executeInViteNode(options) {
9374
9387
  mockPath,
9375
9388
  clearMocks,
9376
9389
  unmockPath,
9377
- resolveMockPath
9390
+ resolveMockPath,
9391
+ resolveDependency
9378
9392
  } = createMocker(root, mockMap);
9379
9393
  const result = [];
9380
9394
  for (const file of files)
@@ -9397,7 +9411,7 @@ async function executeInViteNode(options) {
9397
9411
  var _a;
9398
9412
  if (canMock) {
9399
9413
  const mocks2 = mockMap[suite || ""] || {};
9400
- const mock = mocks2[dep];
9414
+ const mock = mocks2[resolveDependency(dep)];
9401
9415
  if (typeof mock === "function")
9402
9416
  return callFunctionMock(dep, mock);
9403
9417
  if (typeof mock === "string")
@@ -9554,7 +9568,7 @@ function patchWindowsImportPath(path) {
9554
9568
  }
9555
9569
 
9556
9570
  let _viteNode;
9557
- const moduleCache = /* @__PURE__ */ new Map();
9571
+ const moduleCache = new Map();
9558
9572
  const mockMap = {};
9559
9573
  async function startViteNode(ctx) {
9560
9574
  if (_viteNode)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vitest",
3
- "version": "0.0.116",
3
+ "version": "0.0.120",
4
4
  "description": "A blazing fast unit test framework powered by Vite",
5
5
  "keywords": [
6
6
  "vite",
@@ -60,7 +60,7 @@
60
60
  "@types/jsdom": "^16.2.14",
61
61
  "@types/micromatch": "^4.0.2",
62
62
  "@types/natural-compare": "^1.4.1",
63
- "@types/node": "^17.0.4",
63
+ "@types/node": "^17.0.5",
64
64
  "@types/prompts": "^2.4.0",
65
65
  "birpc": "^0.0.2",
66
66
  "c8": "^7.10.0",