vitest 3.0.0-beta.3 → 3.0.0-beta.4

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 (48) hide show
  1. package/LICENSE.md +1 -315
  2. package/config.d.ts +2 -0
  3. package/dist/browser.d.ts +3 -3
  4. package/dist/browser.js +1 -1
  5. package/dist/chunks/{RandomSequencer.C6x84bNN.js → RandomSequencer.DB__To1b.js} +35 -6
  6. package/dist/chunks/{base.CQ2VEtuH.js → base.BJ8KO-VX.js} +2 -2
  7. package/dist/chunks/{cac.e7qW4xLT.js → cac.BAYqQ2aM.js} +7 -7
  8. package/dist/chunks/{cli-api.CWDlED-m.js → cli-api.Dhl34Trr.js} +24 -24
  9. package/dist/chunks/{config.BTPBhmK5.d.ts → config.BRtC-JeT.d.ts} +6 -0
  10. package/dist/chunks/{console.BYGVloWk.js → console.CN7AiMGV.js} +16 -7
  11. package/dist/chunks/{execute.2pr0rHgK.js → execute.BMOaRArH.js} +27 -16
  12. package/dist/chunks/{globals.BFncSRNA.js → globals.C5RQxaV3.js} +2 -2
  13. package/dist/chunks/{index.BBoOXW-l.js → index.B2M9nD1V.js} +1 -1
  14. package/dist/chunks/{index.CkWmZCXU.js → index.BQbxGbG9.js} +1 -1
  15. package/dist/chunks/index.CAueP3cK.js +3205 -0
  16. package/dist/chunks/{reporters.DCiyjXOg.d.ts → reporters.Dcdq51WE.d.ts} +80 -155
  17. package/dist/chunks/{resolveConfig.C1d7TK-U.js → resolveConfig.kZFMjKCQ.js} +4 -4
  18. package/dist/chunks/{runBaseTests.qNWRkgHj.js → runBaseTests.URiUrnWK.js} +8 -6
  19. package/dist/chunks/{setup-common.Cp_bu5q3.js → setup-common.D0zLenuv.js} +1 -1
  20. package/dist/chunks/{utils.Coei4Wlj.js → utils.yHKcm4dz.js} +9 -20
  21. package/dist/chunks/{vi.S4Fq8wSo.js → vi.Da_PT3Vw.js} +554 -272
  22. package/dist/chunks/{vite.CRSMFy31.d.ts → vite.DzluO1Kj.d.ts} +1 -1
  23. package/dist/chunks/{vm.DGhTouO3.js → vm.DrFVeTXo.js} +4 -4
  24. package/dist/chunks/{worker.R-PA7DpW.d.ts → worker.BIVMnzXw.d.ts} +1 -1
  25. package/dist/chunks/{worker.XbtCXEXv.d.ts → worker.Hz_LAzfd.d.ts} +1 -1
  26. package/dist/cli.js +1 -1
  27. package/dist/config.d.ts +4 -4
  28. package/dist/coverage.d.ts +2 -2
  29. package/dist/coverage.js +2 -2
  30. package/dist/execute.d.ts +3 -3
  31. package/dist/execute.js +1 -1
  32. package/dist/index.d.ts +7 -7
  33. package/dist/index.js +2 -2
  34. package/dist/node.d.ts +5 -5
  35. package/dist/node.js +8 -9
  36. package/dist/reporters.d.ts +2 -2
  37. package/dist/reporters.js +3 -7
  38. package/dist/runners.d.ts +1 -1
  39. package/dist/runners.js +3 -10
  40. package/dist/workers/forks.js +2 -2
  41. package/dist/workers/runVmTests.js +7 -5
  42. package/dist/workers/threads.js +2 -2
  43. package/dist/workers/vmForks.js +3 -3
  44. package/dist/workers/vmThreads.js +3 -3
  45. package/dist/workers.d.ts +3 -3
  46. package/dist/workers.js +4 -4
  47. package/package.json +15 -17
  48. package/dist/chunks/index.CzkCSFCy.js +0 -5455
@@ -10,9 +10,9 @@ import { createFileTask, limitConcurrency, getTasks, hasFailed, getTests } from
10
10
  import { SnapshotManager } from '@vitest/snapshot/manager';
11
11
  import { ViteNodeRunner } from 'vite-node/client';
12
12
  import { ViteNodeServer } from 'vite-node/server';
13
- import { v as version$1 } from './cac.e7qW4xLT.js';
13
+ import { v as version$1 } from './cac.BAYqQ2aM.js';
14
14
  import { c as createBirpc } from './index.68735LiX.js';
15
- import { s as stringify, p as parse, i as generateCodeFrame, R as ReportersMap, h as BenchmarkReportsMap, f as TestModule, g as TestSuite, e as TestCase, L as Logger, j as BlobReporter, r as readBlobs } from './index.CzkCSFCy.js';
15
+ import { s as stringify, p as parse, i as generateCodeFrame, R as ReportersMap, h as BenchmarkReportsMap, f as TestModule, g as TestSuite, e as TestCase, L as Logger, j as BlobReporter, r as readBlobs } from './index.CAueP3cK.js';
16
16
  import require$$0$2 from 'stream';
17
17
  import require$$0 from 'zlib';
18
18
  import require$$0$1 from 'buffer';
@@ -26,11 +26,11 @@ import require$$7 from 'url';
26
26
  import { g as getDefaultExportFromCjs, c as commonjsGlobal } from './_commonjsHelpers.BFTU3MAI.js';
27
27
  import { parseErrorStacktrace } from '@vitest/utils/source-map';
28
28
  import { distDir, rootDir } from '../path.js';
29
- import { i as isPackageExists, e as requireMicromatch, V as VitestCache, f as configDefaults, g as getFilePoolName, h as isBrowserEnabled, m as mm, a as resolveConfig, j as groupBy, w as wildcardPatternToRegExp, k as createPool, b as resolveApiServerConfig, c as coverageConfigDefaults, s as stdout } from './resolveConfig.C1d7TK-U.js';
29
+ import { i as isPackageExists, e as requireMicromatch, V as VitestCache, f as configDefaults, g as getFilePoolName, h as isBrowserEnabled, m as mm, a as resolveConfig, j as groupBy, w as wildcardPatternToRegExp, k as createPool, b as resolveApiServerConfig, c as coverageConfigDefaults, s as stdout } from './resolveConfig.kZFMjKCQ.js';
30
30
  import { createRequire } from 'node:module';
31
31
  import url from 'node:url';
32
32
  import c from 'tinyrainbow';
33
- import { b as isTTY, h as hash, i as isWindows } from './RandomSequencer.C6x84bNN.js';
33
+ import { i as isTTY, h as hash, b as isWindows } from './RandomSequencer.DB__To1b.js';
34
34
  import { rm } from 'node:fs/promises';
35
35
  import nodeos__default, { tmpdir } from 'node:os';
36
36
  import require$$0$4 from 'os';
@@ -39,7 +39,7 @@ import require$$0$6 from 'fs';
39
39
  import { normalizeRequestId, cleanUrl } from 'vite-node/utils';
40
40
  import { hoistMocksPlugin, automockPlugin } from '@vitest/mocker/node';
41
41
  import MagicString from 'magic-string';
42
- import { w as withLabel } from './utils.Coei4Wlj.js';
42
+ import { w as withLabel } from './utils.yHKcm4dz.js';
43
43
  import readline from 'node:readline';
44
44
  import { stripVTControlCharacters } from 'node:util';
45
45
 
@@ -5109,7 +5109,7 @@ class LocationFilterFileNotFoundError extends Error {
5109
5109
  class IncludeTaskLocationDisabledError extends Error {
5110
5110
  code = "VITEST_INCLUDE_TASK_LOCATION_DISABLED";
5111
5111
  constructor() {
5112
- super("Recieved line number filters while `includeTaskLocation` option is disabled");
5112
+ super("Received line number filters while `includeTaskLocation` option is disabled");
5113
5113
  }
5114
5114
  }
5115
5115
  class RangeLocationFilterProvidedError extends Error {
@@ -8316,7 +8316,7 @@ function requireOut () {
8316
8316
  }
8317
8317
  win32.convertPathToPattern = convertPathToPattern;
8318
8318
  })(FastGlob.win32 || (FastGlob.win32 = {}));
8319
- })(FastGlob || (FastGlob = {}));
8319
+ })(FastGlob);
8320
8320
  function getWorks(source, _Provider, options) {
8321
8321
  const patterns = [].concat(source);
8322
8322
  const settings = new settings_1.default(options);
@@ -9770,7 +9770,7 @@ class TestProject {
9770
9770
  * Serialized project configuration. This is the config that tests receive.
9771
9771
  */
9772
9772
  get serializedConfig() {
9773
- return this._serializeOverridenConfig();
9773
+ return this._serializeOverriddenConfig();
9774
9774
  }
9775
9775
  /** @deprecated use `vite` instead */
9776
9776
  get server() {
@@ -9914,19 +9914,19 @@ class TestProject {
9914
9914
  * Returns if the file is a test file. Requires `.globTestFiles()` to be called first.
9915
9915
  * @internal
9916
9916
  */
9917
- isCachedTestFile(testPath) {
9917
+ _isCachedTestFile(testPath) {
9918
9918
  return !!this.testFilesList && this.testFilesList.includes(testPath);
9919
9919
  }
9920
9920
  /**
9921
9921
  * Returns if the file is a typecheck test file. Requires `.globTestFiles()` to be called first.
9922
9922
  * @internal
9923
9923
  */
9924
- isCachedTypecheckFile(testPath) {
9924
+ _isCachedTypecheckFile(testPath) {
9925
9925
  return !!this.typecheckFilesList && this.typecheckFilesList.includes(testPath);
9926
9926
  }
9927
9927
  /** @deprecated use `serializedConfig` instead */
9928
9928
  getSerializableConfig() {
9929
- return this._serializeOverridenConfig();
9929
+ return this._serializeOverriddenConfig();
9930
9930
  }
9931
9931
  /** @internal */
9932
9932
  async globFiles(include, exclude, cwd) {
@@ -9942,7 +9942,7 @@ class TestProject {
9942
9942
  * Test if a file matches the test globs. This does the actual glob matching if the test is not cached, unlike `isCachedTestFile`.
9943
9943
  */
9944
9944
  matchesTestGlob(moduleId, source) {
9945
- if (this.isCachedTestFile(moduleId)) {
9945
+ if (this._isCachedTestFile(moduleId)) {
9946
9946
  return true;
9947
9947
  }
9948
9948
  const relativeId = relative(this.config.dir || this.config.root, moduleId);
@@ -10097,7 +10097,7 @@ class TestProject {
10097
10097
  }
10098
10098
  });
10099
10099
  }
10100
- _serializeOverridenConfig() {
10100
+ _serializeOverriddenConfig() {
10101
10101
  const config = serializeConfig(
10102
10102
  this.config,
10103
10103
  this.vitest.config,
@@ -10310,10 +10310,10 @@ class VitestSpecifications {
10310
10310
  }
10311
10311
  const specs = [];
10312
10312
  for (const project of this.vitest.projects) {
10313
- if (project.isCachedTestFile(moduleId)) {
10313
+ if (project._isCachedTestFile(moduleId)) {
10314
10314
  specs.push(project.createSpecification(moduleId));
10315
10315
  }
10316
- if (project.isCachedTypecheckFile(moduleId)) {
10316
+ if (project._isCachedTypecheckFile(moduleId)) {
10317
10317
  specs.push(project.createSpecification(moduleId, [], "typescript"));
10318
10318
  }
10319
10319
  }
@@ -10730,7 +10730,7 @@ class VitestWatcher {
10730
10730
  return moduleGraph.getModulesByFile(filepath)?.size;
10731
10731
  });
10732
10732
  if (!projects.length) {
10733
- if (this.vitest.state.filesMap.has(filepath) || this.vitest.projects.some((project) => project.isCachedTestFile(filepath))) {
10733
+ if (this.vitest.state.filesMap.has(filepath) || this.vitest.projects.some((project) => project._isCachedTestFile(filepath))) {
10734
10734
  this.changedTests.add(filepath);
10735
10735
  return true;
10736
10736
  }
@@ -10743,7 +10743,7 @@ class VitestWatcher {
10743
10743
  continue;
10744
10744
  }
10745
10745
  this.invalidates.add(filepath);
10746
- if (this.vitest.state.filesMap.has(filepath) || project.isCachedTestFile(filepath)) {
10746
+ if (this.vitest.state.filesMap.has(filepath) || project._isCachedTestFile(filepath)) {
10747
10747
  this.changedTests.add(filepath);
10748
10748
  files.push(filepath);
10749
10749
  continue;
@@ -11029,8 +11029,8 @@ async function resolveTestProjectConfigs(vitest, workspaceConfigPath, workspaceD
11029
11029
  if (!isDynamicPattern(stringOption)) {
11030
11030
  const file = resolve(vitest.config.root, stringOption);
11031
11031
  if (!existsSync(file)) {
11032
- const relativeWorkpaceConfigPath = workspaceConfigPath ? relative(vitest.config.root, workspaceConfigPath) : void 0;
11033
- const note = workspaceConfigPath ? `Workspace config file "${relativeWorkpaceConfigPath}"` : "Inline workspace";
11032
+ const relativeWorkSpaceConfigPath = workspaceConfigPath ? relative(vitest.config.root, workspaceConfigPath) : void 0;
11033
+ const note = workspaceConfigPath ? `Workspace config file "${relativeWorkSpaceConfigPath}"` : "Inline workspace";
11034
11034
  throw new Error(`${note} references a non-existing file or a directory: ${file}`);
11035
11035
  }
11036
11036
  const stats = await promises.stat(file);
@@ -11587,7 +11587,7 @@ class Vitest {
11587
11587
  return this.getModuleSpecifications(file);
11588
11588
  }
11589
11589
  /**
11590
- * Get test specifications assosiated with the given module. If module is not a test file, an empty array is returned.
11590
+ * Get test specifications associated with the given module. If module is not a test file, an empty array is returned.
11591
11591
  *
11592
11592
  * **Note:** this method relies on a cache generated by `globTestSpecifications`. If the file was not processed yet, use `project.matchesGlobPattern` instead.
11593
11593
  * @param moduleId The module ID to get test specifications for.
@@ -11596,7 +11596,7 @@ class Vitest {
11596
11596
  return this.specifications.getModuleSpecifications(moduleId);
11597
11597
  }
11598
11598
  /**
11599
- * Vitest automatically caches test specifications for each file. This method clears the cache for the given file or the whole cache alltogether.
11599
+ * Vitest automatically caches test specifications for each file. This method clears the cache for the given file or the whole cache altogether.
11600
11600
  */
11601
11601
  clearSpecificationsCache(moduleId) {
11602
11602
  this.specifications.clearCache(moduleId);
@@ -11723,6 +11723,7 @@ class Vitest {
11723
11723
  async cancelCurrentRun(reason) {
11724
11724
  this.isCancelling = true;
11725
11725
  await Promise.all(this._onCancelListeners.splice(0).map((listener) => listener(reason)));
11726
+ await this.runningPromise;
11726
11727
  }
11727
11728
  /** @internal */
11728
11729
  async _initBrowserServers() {
@@ -11836,12 +11837,14 @@ class Vitest {
11836
11837
  // environment is resolved inside a worker thread
11837
11838
  snapshotEnvironment: null
11838
11839
  };
11840
+ this.snapshot.options.updateSnapshot = "all";
11839
11841
  }
11840
11842
  /**
11841
11843
  * Disable the mode that allows updating snapshots when running tests.
11842
11844
  */
11843
11845
  resetSnapshotUpdate() {
11844
11846
  delete this.configOverride.snapshotOptions;
11847
+ this.snapshot.options.updateSnapshot = this.config.snapshotOptions.updateSnapshot;
11845
11848
  }
11846
11849
  /**
11847
11850
  * Set the global test name pattern to a regexp.
@@ -11975,7 +11978,6 @@ class Vitest {
11975
11978
  this.logger.error("error during close", r.reason);
11976
11979
  }
11977
11980
  });
11978
- this.logger.logUpdate.done();
11979
11981
  });
11980
11982
  })();
11981
11983
  }
@@ -12504,13 +12506,11 @@ function registerConsoleShortcuts(ctx, stdin = process.stdin, stdout2) {
12504
12506
  async function _keypressHandler(str, key) {
12505
12507
  if (str === "" || str === "\x1B" || key && key.ctrl && key.name === "c") {
12506
12508
  if (!ctx.isCancelling) {
12507
- ctx.logger.logUpdate.clear();
12508
12509
  ctx.logger.log(
12509
12510
  c.red("Cancelling test run. Press CTRL+c again to exit forcefully.\n")
12510
12511
  );
12511
12512
  process.exitCode = 130;
12512
12513
  await ctx.cancelCurrentRun("keyboard-input");
12513
- await ctx.runningPromise;
12514
12514
  }
12515
12515
  return ctx.exit(true);
12516
12516
  }
@@ -60,6 +60,12 @@ interface FakeTimerInstallOpts {
60
60
  * @default true
61
61
  */
62
62
  shouldClearNativeTimers?: boolean | undefined;
63
+
64
+ /**
65
+ * Don't throw error when asked to fake timers that are not present.
66
+ * @default false
67
+ */
68
+ ignoreMissingTimers?: boolean | undefined;
63
69
  }
64
70
 
65
71
  /**
@@ -27,13 +27,24 @@ function createCustomConsole(defaultState) {
27
27
  const stdoutBuffer = /* @__PURE__ */ new Map();
28
28
  const stderrBuffer = /* @__PURE__ */ new Map();
29
29
  const timers = /* @__PURE__ */ new Map();
30
- const { setTimeout, clearTimeout } = getSafeTimers();
30
+ const { queueMicrotask } = getSafeTimers();
31
+ function queueCancelableMicrotask(callback) {
32
+ let canceled = false;
33
+ queueMicrotask(() => {
34
+ if (!canceled) {
35
+ callback();
36
+ }
37
+ });
38
+ return () => {
39
+ canceled = true;
40
+ };
41
+ }
31
42
  const state = () => defaultState || getWorkerState();
32
43
  function schedule(taskId) {
33
44
  const timer = timers.get(taskId);
34
45
  const { stdoutTime, stderrTime } = timer;
35
- clearTimeout(timer.timer);
36
- timer.timer = setTimeout(() => {
46
+ timer.cancel?.();
47
+ timer.cancel = queueCancelableMicrotask(() => {
37
48
  if (stderrTime < stdoutTime) {
38
49
  sendStderr(taskId);
39
50
  sendStdout(taskId);
@@ -93,8 +104,7 @@ function createCustomConsole(defaultState) {
93
104
  } else {
94
105
  timer = {
95
106
  stdoutTime: RealDate.now(),
96
- stderrTime: RealDate.now(),
97
- timer: 0
107
+ stderrTime: RealDate.now()
98
108
  };
99
109
  timers.set(id, timer);
100
110
  }
@@ -127,8 +137,7 @@ function createCustomConsole(defaultState) {
127
137
  } else {
128
138
  timer = {
129
139
  stderrTime: RealDate.now(),
130
- stdoutTime: RealDate.now(),
131
- timer: 0
140
+ stdoutTime: RealDate.now()
132
141
  };
133
142
  timers.set(id, timer);
134
143
  }
@@ -21,6 +21,8 @@ function normalizeWindowsPath(input = "") {
21
21
  const _UNC_REGEX = /^[/\\]{2}/;
22
22
  const _IS_ABSOLUTE_RE = /^[/\\](?![/\\])|^[/\\]{2}(?!\.)|^[A-Za-z]:[/\\]/;
23
23
  const _DRIVE_LETTER_RE = /^[A-Za-z]:$/;
24
+ const _EXTNAME_RE = /.(\.[^./]+)$/;
25
+ globalThis.process?.platform === "win32" ? ";" : ":";
24
26
  const normalize = function(path) {
25
27
  if (path.length === 0) {
26
28
  return ".";
@@ -50,24 +52,26 @@ const normalize = function(path) {
50
52
  }
51
53
  return isPathAbsolute && !isAbsolute(path) ? `/${path}` : path;
52
54
  };
53
- const join = function(...arguments_) {
54
- if (arguments_.length === 0) {
55
- return ".";
56
- }
57
- let joined;
58
- for (const argument of arguments_) {
59
- if (argument && argument.length > 0) {
60
- if (joined === void 0) {
61
- joined = argument;
55
+ const join = function(...segments) {
56
+ let path = "";
57
+ for (const seg of segments) {
58
+ if (!seg) {
59
+ continue;
60
+ }
61
+ if (path.length > 0) {
62
+ const pathTrailing = path[path.length - 1] === "/";
63
+ const segLeading = seg[0] === "/";
64
+ const both = pathTrailing && segLeading;
65
+ if (both) {
66
+ path += seg.slice(1);
62
67
  } else {
63
- joined += `/${argument}`;
68
+ path += pathTrailing || segLeading ? seg : `/${seg}`;
64
69
  }
70
+ } else {
71
+ path += seg;
65
72
  }
66
73
  }
67
- if (joined === void 0) {
68
- return ".";
69
- }
70
- return normalize(joined.replace(/\/\/+/g, "/"));
74
+ return normalize(path);
71
75
  };
72
76
  function cwd() {
73
77
  if (typeof process !== "undefined" && typeof process.cwd === "function") {
@@ -156,7 +160,6 @@ function normalizeString(path, allowAboveRoot) {
156
160
  const isAbsolute = function(p) {
157
161
  return _IS_ABSOLUTE_RE.test(p);
158
162
  };
159
- const _EXTNAME_RE = /.(\.[^./]+)$/;
160
163
  const extname = function(p) {
161
164
  const match = _EXTNAME_RE.exec(normalizeWindowsPath(p));
162
165
  return match && match[1] || "";
@@ -169,7 +172,15 @@ const dirname = function(p) {
169
172
  return segments.join("/") || (isAbsolute(p) ? "/" : ".");
170
173
  };
171
174
  const basename = function(p, extension) {
172
- const lastSegment = normalizeWindowsPath(p).split("/").pop();
175
+ const segments = normalizeWindowsPath(p).split("/");
176
+ let lastSegment = "";
177
+ for (let i = segments.length - 1; i >= 0; i--) {
178
+ const val = segments[i];
179
+ if (val) {
180
+ lastSegment = val;
181
+ break;
182
+ }
183
+ }
173
184
  return extension && lastSegment.endsWith(extension) ? lastSegment.slice(0, -extension.length) : lastSegment;
174
185
  };
175
186
 
@@ -1,6 +1,6 @@
1
1
  import { g as globalApis } from './constants.fzPh7AOq.js';
2
- import { V as VitestIndex } from './index.CkWmZCXU.js';
3
- import './vi.S4Fq8wSo.js';
2
+ import { V as VitestIndex } from './index.BQbxGbG9.js';
3
+ import './vi.Da_PT3Vw.js';
4
4
  import '@vitest/expect';
5
5
  import '@vitest/runner';
6
6
  import '@vitest/runner/utils';
@@ -3,7 +3,7 @@ import { resolve } from 'node:path';
3
3
  import { t as takeCoverageInsideWorker } from './coverage.BWeNbfBa.js';
4
4
  import { distDir } from '../path.js';
5
5
  import { r as rpc } from './rpc.C3q9uwRX.js';
6
- import { l as loadDiffConfig, a as loadSnapshotSerializers } from './setup-common.Cp_bu5q3.js';
6
+ import { l as loadDiffConfig, a as loadSnapshotSerializers } from './setup-common.D0zLenuv.js';
7
7
  import { g as getWorkerState } from './utils.C8RiOc4B.js';
8
8
 
9
9
  function setupChaiConfig(config) {
@@ -1,4 +1,4 @@
1
- import { c as createExpect, a as globalExpect, i as inject, v as vi, b as vitest } from './vi.S4Fq8wSo.js';
1
+ import { c as createExpect, a as globalExpect, i as inject, v as vi, b as vitest } from './vi.Da_PT3Vw.js';
2
2
  import { i as isFirstRun, a as runOnce } from './run-once.2ogXb3JV.js';
3
3
  import { b as bench } from './benchmark.Cdu9hjj4.js';
4
4
  import { expectTypeOf } from 'expect-type';