vitest 0.25.8 → 0.26.1

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 (45) hide show
  1. package/LICENSE.md +0 -142
  2. package/browser.d.ts +1 -0
  3. package/dist/browser.d.ts +8 -5
  4. package/dist/browser.js +17 -16
  5. package/dist/{chunk-api-setup.dc71e384.js → chunk-api-setup.adeab271.js} +45 -46
  6. package/dist/{chunk-env-node.67948209.js → chunk-env-node.b3664da2.js} +1 -1
  7. package/dist/{chunk-install-pkg.579a5a27.js → chunk-install-pkg.6dd2bae6.js} +19 -19
  8. package/dist/chunk-integrations-globals.96914902.js +27 -0
  9. package/dist/{chunk-node-git.5a1b1656.js → chunk-node-git.a90c0582.js} +10 -6
  10. package/dist/{chunk-runtime-chain.f86e5250.js → chunk-runtime-chain.4cd984be.js} +8 -8
  11. package/dist/{chunk-runtime-error.616e92ca.js → chunk-runtime-error.f5c8aaf2.js} +10 -8
  12. package/dist/{chunk-runtime-mocker.99b910d0.js → chunk-runtime-mocker.3fa602ba.js} +73 -65
  13. package/dist/{chunk-runtime-rpc.42aebbb9.js → chunk-runtime-rpc.54d72169.js} +2 -2
  14. package/dist/{chunk-runtime-setup.5398e2c4.js → chunk-runtime-setup.9cdedce6.js} +21 -34
  15. package/dist/{chunk-vite-node-externalize.b9495318.js → chunk-snapshot-manager.e54d78b8.js} +82 -358
  16. package/dist/{chunk-typecheck-constants.ed987901.js → chunk-typecheck-constants.06e1fe5b.js} +8 -7
  17. package/dist/{chunk-utils-env.03f840f2.js → chunk-utils-env.3fdc1793.js} +8 -8
  18. package/dist/{chunk-runtime-test-state.3f86f48f.js → chunk-utils-import.afe2ffde.js} +50 -19
  19. package/dist/{chunk-utils-source-map.29ff1088.js → chunk-utils-source-map.59ba6b0a.js} +6 -4
  20. package/dist/{chunk-utils-timers.793fd179.js → chunk-utils-timers.715da787.js} +31 -15
  21. package/dist/cli-wrapper.js +10 -5
  22. package/dist/cli.js +30 -25
  23. package/dist/config.d.ts +6 -3
  24. package/dist/entry.js +18 -16
  25. package/dist/environments.d.ts +6 -3
  26. package/dist/environments.js +2 -2
  27. package/dist/{index-5aad25c1.d.ts → index-1e9f7f83.d.ts} +1 -1
  28. package/dist/index.d.ts +30 -12
  29. package/dist/index.js +12 -10
  30. package/dist/loader.js +12 -7
  31. package/dist/node.d.ts +21 -20
  32. package/dist/node.js +33 -25
  33. package/dist/suite.js +10 -8
  34. package/dist/{types-71ccd11d.d.ts → types-c41bae41.d.ts} +39 -279
  35. package/dist/vendor-index.2e96c50b.js +215 -0
  36. package/dist/vendor-index.783e7f3e.js +71 -0
  37. package/dist/{vendor-index.e1d4cf84.js → vendor-index.7a2cebfe.js} +16 -16
  38. package/dist/{vendor-index.737c3cff.js → vendor-index.b2fdde54.js} +9 -8
  39. package/dist/worker.js +21 -18
  40. package/environments.d.ts +1 -0
  41. package/package.json +4 -4
  42. package/dist/chunk-integrations-globals.4d261bb8.js +0 -25
  43. package/dist/chunk-vite-node-source-map.b4ea5792.js +0 -446
  44. package/dist/chunk-vite-node-utils.0e4a6a88.js +0 -1385
  45. package/dist/vendor-source-map-support.1ce17397.js +0 -707
@@ -1,5 +1,5 @@
1
- import { relative } from 'path';
2
- import { i as isNode, a as isBrowser, r as relative$1, p as picocolors, E as EXIT_CODE_RESTART } from './chunk-utils-env.03f840f2.js';
1
+ import { relative } from 'node:path';
2
+ import { i as isNode, a as isBrowser, r as relative$1, p as picocolors, E as EXIT_CODE_RESTART } from './chunk-utils-env.3fdc1793.js';
3
3
  import { isPackageExists } from 'local-pkg';
4
4
 
5
5
  const TYPECHECK_SUITE = Symbol("vitest:typecheck-suite");
@@ -81,9 +81,6 @@ function notNullish(v) {
81
81
  function slash(str) {
82
82
  return str.replace(/\\/g, "/");
83
83
  }
84
- function mergeSlashes(str) {
85
- return str.replace(/\/\//g, "/");
86
- }
87
84
  const noop = () => {
88
85
  };
89
86
  function getType(value) {
@@ -229,6 +226,9 @@ function getNames(task) {
229
226
  function getWorkerState() {
230
227
  return globalThis.__vitest_worker__;
231
228
  }
229
+ function getCurrentEnvironment() {
230
+ return globalThis.__vitest_environment__;
231
+ }
232
232
 
233
233
  const isWindows = isNode && process.platform === "win32";
234
234
  const getRunMode = () => getWorkerState().config.mode;
@@ -253,6 +253,7 @@ function partitionSuiteChildren(suite) {
253
253
  function resetModules(modules, resetMocks = false) {
254
254
  const skipPaths = [
255
255
  /\/vitest\/dist\//,
256
+ /\/vite-node\/dist\//,
256
257
  /vitest-virtual-\w+\/dist/,
257
258
  /@vitest\/dist/,
258
259
  ...!resetMocks ? [/^mock:/] : []
@@ -289,7 +290,7 @@ async function ensurePackageInstalled(dependency, root) {
289
290
  message: picocolors.exports.reset(`Do you want to install ${picocolors.exports.green(dependency)}?`)
290
291
  });
291
292
  if (install) {
292
- await (await import('./chunk-install-pkg.579a5a27.js')).installPackage(dependency, { dev: true });
293
+ await (await import('./chunk-install-pkg.6dd2bae6.js')).installPackage(dependency, { dev: true });
293
294
  process.stderr.write(picocolors.exports.yellow(`
294
295
  Package ${dependency} installed, re-run the command to start.
295
296
  `));
@@ -355,4 +356,4 @@ function objectAttr(source, path, defaultValue = void 0) {
355
356
  return result;
356
357
  }
357
358
 
358
- export { AggregateErrorPonyfill as A, hasFailedSnapshot as B, getTypecheckTests as C, getSuites as D, isTypecheckTest as E, deepMerge as F, removeUndefinedValues as G, isWindows as H, stdout as I, mergeSlashes as J, getAllMockableProperties as K, RealDate as R, TYPECHECK_SUITE as T, resetModules as a, getCallLastIndex as b, getNames as c, assertTypes as d, getFullName as e, isRunningInTest as f, getWorkerState as g, isRunningInBenchmark as h, isObject as i, notNullish as j, relativePath as k, shuffle as l, mockDate as m, noop as n, objectAttr as o, partitionSuiteChildren as p, hasTests as q, resetDate as r, slash as s, toArray as t, hasFailed as u, createDefer as v, deepClone as w, getType as x, ensurePackageInstalled as y, getTests as z };
359
+ export { AggregateErrorPonyfill as A, getTests as B, hasFailedSnapshot as C, getTypecheckTests as D, getSuites as E, isTypecheckTest as F, deepMerge as G, removeUndefinedValues as H, isWindows as I, stdout as J, getAllMockableProperties as K, RealDate as R, TYPECHECK_SUITE as T, resetModules as a, getCallLastIndex as b, getNames as c, assertTypes as d, getCurrentEnvironment as e, getFullName as f, getWorkerState as g, isRunningInTest as h, isObject as i, isRunningInBenchmark as j, notNullish as k, relativePath as l, mockDate as m, noop as n, objectAttr as o, partitionSuiteChildren as p, shuffle as q, resetDate as r, slash as s, toArray as t, hasTests as u, hasFailed as v, createDefer as w, deepClone as x, getType as y, ensurePackageInstalled as z };
@@ -1,6 +1,6 @@
1
1
  import require$$0 from 'tty';
2
- import url from 'url';
3
- import path from 'path';
2
+ import url from 'node:url';
3
+ import g from 'path';
4
4
 
5
5
  var picocolors = {exports: {}};
6
6
 
@@ -206,22 +206,22 @@ const toNamespacedPath = function(p) {
206
206
  return normalizeWindowsPath(p);
207
207
  };
208
208
  const extname = function(p) {
209
- return path.posix.extname(normalizeWindowsPath(p));
209
+ return g.posix.extname(normalizeWindowsPath(p));
210
210
  };
211
211
  const relative = function(from, to) {
212
- return path.posix.relative(normalizeWindowsPath(from), normalizeWindowsPath(to));
212
+ return g.posix.relative(normalizeWindowsPath(from), normalizeWindowsPath(to));
213
213
  };
214
214
  const dirname = function(p) {
215
- return path.posix.dirname(normalizeWindowsPath(p));
215
+ return g.posix.dirname(normalizeWindowsPath(p));
216
216
  };
217
217
  const format = function(p) {
218
- return normalizeWindowsPath(path.posix.format(p));
218
+ return normalizeWindowsPath(g.posix.format(p));
219
219
  };
220
220
  const basename = function(p, ext) {
221
- return path.posix.basename(normalizeWindowsPath(p), ext);
221
+ return g.posix.basename(normalizeWindowsPath(p), ext);
222
222
  };
223
223
  const parse = function(p) {
224
- return path.posix.parse(normalizeWindowsPath(p));
224
+ return g.posix.parse(normalizeWindowsPath(p));
225
225
  };
226
226
 
227
227
  const _path = /*#__PURE__*/Object.freeze({
@@ -1,13 +1,27 @@
1
- import { g as getCurrentSuite, w as withTimeout, a as getDefaultHookTimeout, s as suite, t as test, d as describe, i as it, b as bench, c as createExpect, e as globalExpect } from './chunk-runtime-chain.f86e5250.js';
2
- import { g as getWorkerState, R as RealDate, r as resetDate, m as mockDate, a as resetModules } from './chunk-typecheck-constants.ed987901.js';
3
- import { p as parseStacktrace } from './chunk-utils-source-map.29ff1088.js';
1
+ import { g as getCurrentSuite, w as withTimeout, a as getDefaultHookTimeout, s as suite, t as test, d as describe, i as it, b as bench, c as createExpect, e as globalExpect } from './chunk-runtime-chain.4cd984be.js';
2
+ import { g as getWorkerState, R as RealDate, r as resetDate, m as mockDate, a as resetModules } from './chunk-typecheck-constants.06e1fe5b.js';
3
+ import { p as parseStacktrace } from './chunk-utils-source-map.59ba6b0a.js';
4
4
  import { c as commonjsGlobal } from './vendor-_commonjsHelpers.addc3445.js';
5
5
  import util from 'util';
6
6
  import { spyOn, fn, isMockFunction, spies } from './spy.js';
7
- import { s as safeSetTimeout } from './chunk-utils-timers.793fd179.js';
7
+ import { s as safeSetTimeout } from './chunk-utils-timers.715da787.js';
8
8
  import * as chai from 'chai';
9
9
  import { assert, should } from 'chai';
10
10
 
11
+ async function waitForImportsToResolve(tries = 0) {
12
+ await new Promise((resolve) => safeSetTimeout(resolve, 0));
13
+ const state = getWorkerState();
14
+ const promises = [];
15
+ for (const mod of state.moduleCache.values()) {
16
+ if (mod.promise && !mod.evaluated)
17
+ promises.push(mod.promise);
18
+ }
19
+ if (!promises.length && tries >= 3)
20
+ return;
21
+ await Promise.allSettled(promises);
22
+ await new Promise((resolve) => safeSetTimeout(resolve, 1)).then(() => Promise.resolve()).then(() => waitForImportsToResolve(tries + 1));
23
+ }
24
+
11
25
  let _test;
12
26
  function setCurrentTest(test) {
13
27
  _test = test;
@@ -2720,6 +2734,8 @@ class VitestUtils {
2720
2734
  constructor() {
2721
2735
  this.spyOn = spyOn;
2722
2736
  this.fn = fn;
2737
+ this._stubsGlobal = /* @__PURE__ */ new Map();
2738
+ this._stubsEnv = /* @__PURE__ */ new Map();
2723
2739
  this._config = null;
2724
2740
  this._mocker = typeof __vitest_mocker__ !== "undefined" ? __vitest_mocker__ : null;
2725
2741
  this._mockedDate = null;
@@ -2829,11 +2845,35 @@ class VitestUtils {
2829
2845
  return this;
2830
2846
  }
2831
2847
  stubGlobal(name, value) {
2832
- if (globalThis.window) {
2833
- globalThis.window[name] = value;
2834
- } else {
2835
- globalThis[name] = value;
2836
- }
2848
+ if (!this._stubsGlobal.has(name))
2849
+ this._stubsGlobal.set(name, Object.getOwnPropertyDescriptor(globalThis, name));
2850
+ globalThis[name] = value;
2851
+ return this;
2852
+ }
2853
+ stubEnv(name, value) {
2854
+ if (!this._stubsEnv.has(name))
2855
+ this._stubsEnv.set(name, process.env[name]);
2856
+ process.env[name] = value;
2857
+ return this;
2858
+ }
2859
+ unstubAllGlobals() {
2860
+ this._stubsGlobal.forEach((original, name) => {
2861
+ if (!original)
2862
+ Reflect.deleteProperty(globalThis, name);
2863
+ else
2864
+ Object.defineProperty(globalThis, name, original);
2865
+ });
2866
+ this._stubsGlobal.clear();
2867
+ return this;
2868
+ }
2869
+ unstubAllEnvs() {
2870
+ this._stubsEnv.forEach((original, name) => {
2871
+ if (original === void 0)
2872
+ delete process.env[name];
2873
+ else
2874
+ process.env[name] = original;
2875
+ });
2876
+ this._stubsEnv.clear();
2837
2877
  return this;
2838
2878
  }
2839
2879
  resetModules() {
@@ -2842,16 +2882,7 @@ class VitestUtils {
2842
2882
  return this;
2843
2883
  }
2844
2884
  async dynamicImportSettled() {
2845
- const state = getWorkerState();
2846
- const promises = [];
2847
- for (const mod of state.moduleCache.values()) {
2848
- if (mod.promise && !mod.evaluated)
2849
- promises.push(mod.promise);
2850
- }
2851
- if (!promises.length)
2852
- return;
2853
- await Promise.allSettled(promises);
2854
- await new Promise((resolve) => safeSetTimeout(resolve, 1)).then(() => Promise.resolve()).then(() => this.dynamicImportSettled());
2885
+ return waitForImportsToResolve();
2855
2886
  }
2856
2887
  setConfig(config) {
2857
2888
  const state = getWorkerState();
@@ -1,12 +1,13 @@
1
- import { s as slash, j as notNullish } from './chunk-typecheck-constants.ed987901.js';
1
+ import { b as resolve } from './chunk-utils-env.3fdc1793.js';
2
+ import { k as notNullish } from './chunk-typecheck-constants.06e1fe5b.js';
2
3
 
3
4
  const lineSplitRE = /\r?\n/;
4
5
  const stackIgnorePatterns = [
5
6
  "node:internal",
6
7
  "/vitest/dist/",
7
- "/vite-node/dist",
8
- "/vite-node/src",
9
8
  "/vitest/src/",
9
+ "/vite-node/dist/",
10
+ "/vite-node/src/",
10
11
  "/node_modules/chai/",
11
12
  "/node_modules/tinypool/",
12
13
  "/node_modules/tinyspy/"
@@ -42,11 +43,12 @@ function parseStacktrace(e, full = false) {
42
43
  method = method.slice(6);
43
44
  if (file.startsWith("file://"))
44
45
  file = file.slice(7);
46
+ file = resolve(file);
45
47
  if (!full && stackIgnorePatterns.some((p) => file && file.includes(p)))
46
48
  return null;
47
49
  return {
48
50
  method,
49
- file: slash(file),
51
+ file,
50
52
  line: parseInt(lineNumber),
51
53
  column: parseInt(columnNumber)
52
54
  };
@@ -1,4 +1,4 @@
1
- import { p as picocolors } from './chunk-utils-env.03f840f2.js';
1
+ import { p as picocolors } from './chunk-utils-env.3fdc1793.js';
2
2
 
3
3
  const {
4
4
  setTimeout: safeSetTimeout,
@@ -3856,15 +3856,20 @@ function formatLine(line, outputTruncateLength) {
3856
3856
  function unifiedDiff(actual, expected, options = {}) {
3857
3857
  if (actual === expected)
3858
3858
  return "";
3859
- const { outputTruncateLength, outputDiffLines, showLegend = true } = options;
3859
+ const { outputTruncateLength, outputDiffLines, outputDiffMaxLines, noColor, showLegend = true } = options;
3860
3860
  const indent = " ";
3861
3861
  const diffLimit = outputDiffLines || 15;
3862
+ const diffMaxLines = outputDiffMaxLines || 50;
3862
3863
  const counts = {
3863
3864
  "+": 0,
3864
3865
  "-": 0
3865
3866
  };
3866
3867
  let previousState = null;
3867
3868
  let previousCount = 0;
3869
+ const str = (str2) => str2;
3870
+ const dim = noColor ? str : picocolors.exports.dim;
3871
+ const green = noColor ? str : picocolors.exports.green;
3872
+ const red = noColor ? str : picocolors.exports.red;
3868
3873
  function preprocess(line) {
3869
3874
  if (!line || line.match(/\\ No newline/))
3870
3875
  return;
@@ -3877,38 +3882,49 @@ function unifiedDiff(actual, expected, options = {}) {
3877
3882
  previousCount++;
3878
3883
  counts[char]++;
3879
3884
  if (previousCount === diffLimit)
3880
- return picocolors.exports.dim(`${char} ...`);
3885
+ return dim(`${char} ...`);
3881
3886
  else if (previousCount > diffLimit)
3882
3887
  return;
3883
3888
  }
3884
3889
  return line;
3885
3890
  }
3886
3891
  const msg = createPatch("string", expected, actual);
3887
- const lines = msg.split("\n").slice(5).map(preprocess).filter(Boolean);
3892
+ let lines = msg.split("\n").slice(5).map(preprocess).filter(Boolean);
3893
+ let moreLines = 0;
3888
3894
  const isCompact = counts["+"] === 1 && counts["-"] === 1 && lines.length === 2;
3895
+ if (lines.length > diffMaxLines) {
3896
+ const firstDiff = lines.findIndex((line) => line[0] === "-" || line[0] === "+");
3897
+ const displayLines = lines.slice(firstDiff - 2, diffMaxLines);
3898
+ const lastDisplayedIndex = firstDiff - 2 + diffMaxLines;
3899
+ if (lastDisplayedIndex < lines.length)
3900
+ moreLines = lines.length - lastDisplayedIndex;
3901
+ lines = displayLines;
3902
+ }
3889
3903
  let formatted = lines.map((line) => {
3890
3904
  line = line.replace(/\\"/g, '"');
3891
3905
  if (line[0] === "-") {
3892
3906
  line = formatLine(line.slice(1), outputTruncateLength);
3893
3907
  if (isCompact)
3894
- return picocolors.exports.green(line);
3895
- return picocolors.exports.green(`- ${formatLine(line, outputTruncateLength)}`);
3908
+ return green(line);
3909
+ return green(`- ${formatLine(line, outputTruncateLength)}`);
3896
3910
  }
3897
3911
  if (line[0] === "+") {
3898
3912
  line = formatLine(line.slice(1), outputTruncateLength);
3899
3913
  if (isCompact)
3900
- return picocolors.exports.red(line);
3901
- return picocolors.exports.red(`+ ${formatLine(line, outputTruncateLength)}`);
3914
+ return red(line);
3915
+ return red(`+ ${formatLine(line, outputTruncateLength)}`);
3902
3916
  }
3903
3917
  if (line.match(/@@/))
3904
3918
  return "--";
3905
3919
  return ` ${line}`;
3906
3920
  });
3921
+ if (moreLines)
3922
+ formatted.push(dim(`... ${moreLines} more lines`));
3907
3923
  if (showLegend) {
3908
3924
  if (isCompact) {
3909
3925
  formatted = [
3910
- `${picocolors.exports.green("- Expected")} ${formatted[0]}`,
3911
- `${picocolors.exports.red("+ Received")} ${formatted[1]}`
3926
+ `${green("- Expected")} ${formatted[0]}`,
3927
+ `${red("+ Received")} ${formatted[1]}`
3912
3928
  ];
3913
3929
  } else {
3914
3930
  if (formatted[0].includes('"'))
@@ -3917,13 +3933,13 @@ function unifiedDiff(actual, expected, options = {}) {
3917
3933
  if (formatted[last].endsWith('"'))
3918
3934
  formatted[last] = formatted[last].slice(0, formatted[last].length - 1);
3919
3935
  formatted.unshift(
3920
- picocolors.exports.green(`- Expected - ${counts["-"]}`),
3921
- picocolors.exports.red(`+ Received + ${counts["+"]}`),
3936
+ green(`- Expected - ${counts["-"]}`),
3937
+ red(`+ Received + ${counts["+"]}`),
3922
3938
  ""
3923
3939
  );
3924
3940
  }
3925
3941
  }
3926
- return formatted.map((i) => indent + i).join("\n");
3942
+ return formatted.map((i) => i ? indent + i : i).join("\n");
3927
3943
  }
3928
3944
 
3929
3945
  const EXPECTED_COLOR = picocolors.exports.green;
@@ -3994,8 +4010,8 @@ function matcherHint(matcherName, received = "received", expected = "expected",
3994
4010
  }
3995
4011
  const SPACE_SYMBOL = "\xB7";
3996
4012
  const replaceTrailingSpaces = (text) => text.replace(/\s+$/gm, (spaces) => SPACE_SYMBOL.repeat(spaces.length));
3997
- function stringify(object, maxDepth = 10, options) {
3998
- const MAX_LENGTH = 1e4;
4013
+ function stringify(object, maxDepth = 10, { maxLength, ...options } = {}) {
4014
+ const MAX_LENGTH = maxLength ?? 1e4;
3999
4015
  let result;
4000
4016
  try {
4001
4017
  result = format_1(object, {
@@ -1,19 +1,24 @@
1
1
  import { fileURLToPath } from 'url';
2
- import { p as picocolors, E as EXIT_CODE_RESTART } from './chunk-utils-env.03f840f2.js';
3
- import { e as execa } from './vendor-index.737c3cff.js';
2
+ import { p as picocolors, E as EXIT_CODE_RESTART } from './chunk-utils-env.3fdc1793.js';
3
+ import { e as execa } from './vendor-index.b2fdde54.js';
4
4
  import 'tty';
5
+ import 'node:url';
5
6
  import 'path';
6
- import 'buffer';
7
+ import 'node:buffer';
8
+ import 'node:path';
9
+ import 'node:child_process';
10
+ import 'node:process';
11
+ import './vendor-index.7a2cebfe.js';
7
12
  import 'child_process';
8
- import 'process';
9
- import './vendor-index.e1d4cf84.js';
10
13
  import './vendor-_commonjsHelpers.addc3445.js';
11
14
  import 'fs';
12
15
  import 'assert';
13
16
  import 'events';
17
+ import 'buffer';
14
18
  import 'stream';
15
19
  import 'util';
16
20
  import 'os';
21
+ import 'node:os';
17
22
 
18
23
  const ENTRY = new URL("./cli.js", import.meta.url);
19
24
  const NODE_ARGS = [
package/dist/cli.js CHANGED
@@ -1,43 +1,48 @@
1
- import { p as picocolors, n as normalize } from './chunk-utils-env.03f840f2.js';
1
+ import { p as picocolors, n as normalize } from './chunk-utils-env.3fdc1793.js';
2
2
  import { EventEmitter } from 'events';
3
- import { v as version, s as startVitest, d as divider } from './chunk-vite-node-externalize.b9495318.js';
3
+ import { v as version, s as startVitest, d as divider } from './chunk-snapshot-manager.e54d78b8.js';
4
4
  import 'tty';
5
- import 'url';
5
+ import 'node:url';
6
6
  import 'path';
7
7
  import './chunk-integrations-coverage.befed097.js';
8
8
  import 'local-pkg';
9
- import './chunk-env-node.67948209.js';
10
- import 'console';
11
- import './chunk-typecheck-constants.ed987901.js';
9
+ import './chunk-env-node.b3664da2.js';
10
+ import 'node:console';
11
+ import './chunk-typecheck-constants.06e1fe5b.js';
12
+ import 'node:path';
12
13
  import 'vite';
13
- import 'process';
14
- import 'fs';
14
+ import 'node:process';
15
+ import 'node:fs';
15
16
  import 'os';
16
17
  import 'util';
17
18
  import 'stream';
19
+ import 'fs';
18
20
  import './vendor-_commonjsHelpers.addc3445.js';
19
- import './chunk-vite-node-source-map.b4ea5792.js';
20
- import 'module';
21
- import 'vm';
22
- import './chunk-vite-node-utils.0e4a6a88.js';
23
- import 'acorn';
21
+ import 'vite-node/client';
22
+ import 'vite-node/server';
23
+ import 'node:fs/promises';
24
+ import './vendor-index.b2fdde54.js';
25
+ import 'node:buffer';
26
+ import 'node:child_process';
27
+ import './vendor-index.7a2cebfe.js';
28
+ import 'child_process';
24
29
  import 'assert';
25
- import 'debug';
26
- import './vendor-source-map-support.1ce17397.js';
27
- import 'source-map';
28
- import 'perf_hooks';
29
- import 'fs/promises';
30
- import './vendor-index.737c3cff.js';
31
30
  import 'buffer';
32
- import 'child_process';
33
- import './vendor-index.e1d4cf84.js';
31
+ import 'node:os';
32
+ import 'source-map';
33
+ import 'module';
34
+ import 'acorn';
34
35
  import 'acorn-walk';
35
- import 'worker_threads';
36
+ import 'node:worker_threads';
36
37
  import 'tinypool';
37
- import './chunk-utils-timers.793fd179.js';
38
- import './chunk-utils-source-map.29ff1088.js';
38
+ import './vendor-index.783e7f3e.js';
39
+ import 'perf_hooks';
40
+ import './chunk-utils-timers.715da787.js';
41
+ import './chunk-utils-source-map.59ba6b0a.js';
39
42
  import 'crypto';
43
+ import 'vite-node/utils';
40
44
  import './vendor-index.9c919048.js';
45
+ import 'node:crypto';
41
46
  import './chunk-magic-string.3a794426.js';
42
47
  import 'strip-literal';
43
48
  import 'readline';
@@ -657,7 +662,7 @@ class CAC extends EventEmitter {
657
662
  const cac = (name = "") => new CAC(name);
658
663
 
659
664
  const cli = cac("vitest");
660
- 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("-t, --testNamePattern <pattern>", "run tests with full names matching the specified pattern").option("--dir <path>", "base directory to scan for the test files").option("--ui", "enable UI").option("--open", "open UI automatically (default: !process.env.CI))").option("--api [api]", "serve API, available options: --api.port <port>, --api.host [host] and --api.strictPort").option("--threads", "enabled threads (default: true)").option("--silent", "silent console output from tests").option("--isolate", "isolate environment for each test file (default: true)").option("--reporter <name>", "reporter").option("--outputTruncateLength <length>", "diff output length (default: 80)").option("--outputDiffLines <lines>", "number of diff output lines (default: 15)").option("--outputFile <filename/-s>", "write test results to a file when the --reporter=json or --reporter=junit option is also specified, use cac's dot notation for individual outputs of multiple reporters").option("--coverage", "enable coverage report").option("--run", "do not watch").option("--mode <name>", "override Vite mode (default: test)").option("--globals", "inject apis globally").option("--dom", "mock browser api with happy-dom").option("--browser", "run tests in browser").option("--environment <env>", "runner environment (default: node)").option("--passWithNoTests", "pass when no tests found").option("--allowOnly", "Allow tests and suites that are marked as only (default: !process.env.CI)").option("--dangerouslyIgnoreUnhandledErrors", "Ignore any unhandled errors that occur").option("--shard <shard>", "Test suite shard to execute in a format of <index>/<count>").option("--changed [since]", "Run tests that are affected by the changed files (default: false)").option("--sequence <options>", "Define in what order to run tests (use --sequence.shuffle to run tests in random order)").option("--no-color", "Removes colors from the console output").option("--segfault-retry <times>", "Return tests on segment fault (default: 0)", { default: 0 }).option("--inspect", "Enable Node.js inspector").option("--inspect-brk", "Enable Node.js inspector with break").help();
665
+ 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("-t, --testNamePattern <pattern>", "run tests with full names matching the specified pattern").option("--dir <path>", "base directory to scan for the test files").option("--ui", "enable UI").option("--open", "open UI automatically (default: !process.env.CI))").option("--api [api]", "serve API, available options: --api.port <port>, --api.host [host] and --api.strictPort").option("--threads", "enabled threads (default: true)").option("--silent", "silent console output from tests").option("--isolate", "isolate environment for each test file (default: true)").option("--reporter <name>", "reporter").option("--outputDiffMaxSize <length>", "object diff output max size (default: 10000)").option("--outputDiffMaxLines <length>", "max lines in diff output window (default: 50)").option("--outputTruncateLength <length>", "diff output line length (default: 80)").option("--outputDiffLines <lines>", "number of lines in single diff (default: 15)").option("--outputFile <filename/-s>", "write test results to a file when the --reporter=json or --reporter=junit option is also specified, use cac's dot notation for individual outputs of multiple reporters").option("--coverage", "enable coverage report").option("--run", "do not watch").option("--mode <name>", "override Vite mode (default: test)").option("--globals", "inject apis globally").option("--dom", "mock browser api with happy-dom").option("--browser", "run tests in browser").option("--environment <env>", "runner environment (default: node)").option("--passWithNoTests", "pass when no tests found").option("--logHeapUsage", "show the size of heap for each test").option("--allowOnly", "Allow tests and suites that are marked as only (default: !process.env.CI)").option("--dangerouslyIgnoreUnhandledErrors", "Ignore any unhandled errors that occur").option("--shard <shard>", "Test suite shard to execute in a format of <index>/<count>").option("--changed [since]", "Run tests that are affected by the changed files (default: false)").option("--sequence <options>", "Define in what order to run tests (use --sequence.shuffle to run tests in random order)").option("--no-color", "Removes colors from the console output").option("--segfault-retry <times>", "Return tests on segment fault (default: 0)", { default: 0 }).option("--inspect", "Enable Node.js inspector").option("--inspect-brk", "Enable Node.js inspector with break").help();
661
666
  cli.command("run [...filters]").action(run);
662
667
  cli.command("related [...filters]").action(runRelated);
663
668
  cli.command("watch [...filters]").action(watch);
package/dist/config.d.ts CHANGED
@@ -1,9 +1,12 @@
1
1
  import { UserConfig as UserConfig$2, ConfigEnv } from 'vite';
2
2
  export { ConfigEnv } from 'vite';
3
- import { U as UserConfig$1, ao as ResolvedCoverageOptions, F as FakeTimerInstallOpts } from './types-71ccd11d.js';
3
+ import { U as UserConfig$1, ao as ResolvedCoverageOptions, F as FakeTimerInstallOpts } from './types-c41bae41.js';
4
4
  import 'tinybench';
5
- import 'fs';
6
- import 'worker_threads';
5
+ import 'vite-node/client';
6
+ import 'vite-node/server';
7
+ import 'vite-node';
8
+ import 'node:fs';
9
+ import 'node:worker_threads';
7
10
 
8
11
  declare const defaultInclude: string[];
9
12
  declare const defaultExclude: string[];
package/dist/entry.js CHANGED
@@ -1,28 +1,29 @@
1
- import { promises } from 'fs';
2
- import { g as getWorkerState, a as resetModules } from './chunk-typecheck-constants.ed987901.js';
3
- import { v as vi } from './chunk-runtime-test-state.3f86f48f.js';
4
- import { a as envs } from './chunk-env-node.67948209.js';
5
- import { a as setupGlobalEnv, s as startTests, w as withEnv } from './chunk-runtime-setup.5398e2c4.js';
6
- import 'path';
7
- import './chunk-utils-env.03f840f2.js';
1
+ import { promises } from 'node:fs';
2
+ import { g as getWorkerState, a as resetModules } from './chunk-typecheck-constants.06e1fe5b.js';
3
+ import { v as vi } from './chunk-utils-import.afe2ffde.js';
4
+ import { a as envs } from './chunk-env-node.b3664da2.js';
5
+ import { a as setupGlobalEnv, s as startTests, w as withEnv } from './chunk-runtime-setup.9cdedce6.js';
6
+ import 'node:path';
7
+ import './chunk-utils-env.3fdc1793.js';
8
8
  import 'tty';
9
- import 'url';
9
+ import 'node:url';
10
+ import 'path';
10
11
  import 'local-pkg';
11
- import './chunk-runtime-chain.f86e5250.js';
12
+ import './chunk-runtime-chain.4cd984be.js';
12
13
  import 'util';
13
14
  import 'chai';
14
15
  import './vendor-_commonjsHelpers.addc3445.js';
15
- import './chunk-runtime-rpc.42aebbb9.js';
16
- import './chunk-utils-timers.793fd179.js';
17
- import './chunk-utils-source-map.29ff1088.js';
16
+ import './chunk-runtime-rpc.54d72169.js';
17
+ import './chunk-utils-timers.715da787.js';
18
+ import './chunk-utils-source-map.59ba6b0a.js';
19
+ import 'fs';
18
20
  import './spy.js';
19
21
  import 'tinyspy';
20
- import 'console';
22
+ import 'node:console';
21
23
  import 'perf_hooks';
22
24
  import './chunk-integrations-coverage.befed097.js';
23
- import './chunk-runtime-error.616e92ca.js';
24
- import './vendor-source-map-support.1ce17397.js';
25
- import 'source-map';
25
+ import './chunk-runtime-error.f5c8aaf2.js';
26
+ import 'vite-node/source-map';
26
27
 
27
28
  function groupBy(collection, iteratee) {
28
29
  return collection.reduce((acc, item) => {
@@ -60,6 +61,7 @@ async function run(files, config) {
60
61
  const files2 = filesByEnv[environment];
61
62
  if (!files2 || !files2.length)
62
63
  continue;
64
+ globalThis.__vitest_environment__ = environment;
63
65
  const filesByOptions = groupBy(files2, ({ envOptions }) => JSON.stringify(envOptions));
64
66
  for (const options of Object.keys(filesByOptions)) {
65
67
  const files3 = filesByOptions[options];
@@ -1,8 +1,11 @@
1
- import { ae as Environment } from './types-71ccd11d.js';
1
+ import { ae as Environment } from './types-c41bae41.js';
2
2
  import 'vite';
3
3
  import 'tinybench';
4
- import 'fs';
5
- import 'worker_threads';
4
+ import 'vite-node/client';
5
+ import 'vite-node/server';
6
+ import 'vite-node';
7
+ import 'node:fs';
8
+ import 'node:worker_threads';
6
9
 
7
10
  declare const environments: {
8
11
  node: Environment;
@@ -1,3 +1,3 @@
1
- export { e as builtinEnvironments, p as populateGlobal } from './chunk-env-node.67948209.js';
2
- import 'console';
1
+ export { e as builtinEnvironments, p as populateGlobal } from './chunk-env-node.b3664da2.js';
2
+ import 'node:console';
3
3
  import 'local-pkg';
@@ -1,5 +1,5 @@
1
1
  import { SpyImpl } from 'tinyspy';
2
- import { w as SuiteAPI, v as TestAPI, aw as BenchmarkAPI, y as SuiteHooks, H as HookListener, L as TestContext, p as Suite, x as HookCleanupCallback, O as OnTestFailedHandler, q as Test } from './types-71ccd11d.js';
2
+ import { w as SuiteAPI, v as TestAPI, aw as BenchmarkAPI, y as SuiteHooks, H as HookListener, L as TestContext, p as Suite, x as HookCleanupCallback, O as OnTestFailedHandler, q as Test } from './types-c41bae41.js';
3
3
 
4
4
  declare type Not<T extends boolean> = T extends true ? false : true;
5
5
  declare type And<Types extends boolean[]> = Types[number] extends true ? true : false;
package/dist/index.d.ts CHANGED
@@ -1,15 +1,18 @@
1
- import { s as spyOn, f as fn, M as MaybeMockedDeep, a as MaybeMocked, b as MaybePartiallyMocked, c as MaybePartiallyMockedDeep, E as EnhancedSpy } from './index-5aad25c1.js';
2
- export { A as AssertType, E as EnhancedSpy, q as ExpectTypeOf, x as Mock, y as MockContext, w as MockInstance, z as Mocked, B as MockedClass, u as MockedFunction, v as MockedObject, S as SpyInstance, j as afterAll, l as afterEach, r as assertType, h as beforeAll, k as beforeEach, g as bench, n as createExpect, e as describe, m as expect, p as expectTypeOf, i as it, o as onTestFailed, d as suite, t as test } from './index-5aad25c1.js';
3
- import { D as DoneCallback, F as FakeTimerInstallOpts, R as RuntimeConfig, a as File, T as TaskResultPack, b as ResolvedConfig, M as ModuleGraphData, c as Reporter } from './types-71ccd11d.js';
4
- export { a1 as AfterSuiteRunMeta, A as ApiConfig, a7 as ArgumentsType, a6 as Arrayable, a4 as Awaitable, ap as BaseCoverageOptions, av as BenchFunction, at as Benchmark, aw as BenchmarkAPI, au as BenchmarkResult, as as BenchmarkUserOptions, B as BuiltinEnvironment, i as CSSModuleScopeStrategy, C as CollectLineNumbers, f as CollectLines, ab as Constructable, h as Context, ar as CoverageC8Options, aq as CoverageIstanbulOptions, an as CoverageOptions, ak as CoverageProvider, al as CoverageProviderModule, am as CoverageReporter, a9 as DeepMerge, D as DoneCallback, ae as Environment, E as EnvironmentOptions, ad as EnvironmentReturn, ai as ErrorWithDiff, a as File, x as HookCleanupCallback, H as HookListener, I as InlineConfig, J as JSDOMOptions, a8 as MergeInsertions, ac as ModuleCache, M as ModuleGraphData, aa as MutableArray, a5 as Nullable, aj as OnServerRestartHandler, O as OnTestFailedHandler, ah as ParsedStack, ag as Position, d as RawErrsMap, c as Reporter, a0 as ResolveIdFunction, b as ResolvedConfig, ao as ResolvedCoverageOptions, g as RootAndTarget, l as RunMode, R as RuntimeConfig, K as RuntimeContext, S as SequenceHooks, P as SnapshotData, X as SnapshotMatchOptions, Y as SnapshotResult, W as SnapshotStateOptions, _ as SnapshotSummary, Q as SnapshotUpdateState, p as Suite, w as SuiteAPI, z as SuiteCollector, G as SuiteFactory, y as SuiteHooks, s as Task, n as TaskBase, o as TaskResult, T as TaskResultPack, m as TaskState, q as Test, v as TestAPI, L as TestContext, t as TestFunction, u as TestOptions, e as TscErrorInfo, r as TypeCheck, k as TypecheckConfig, Z as UncheckedSnapshot, U as UserConfig, af as UserConsoleLog, N as Vitest, V as VitestEnvironment, j as VitestRunMode, $ as WorkerContext, a3 as WorkerGlobalState, a2 as WorkerRPC } from './types-71ccd11d.js';
1
+ import { s as spyOn, f as fn, M as MaybeMockedDeep, a as MaybeMocked, b as MaybePartiallyMocked, c as MaybePartiallyMockedDeep, E as EnhancedSpy } from './index-1e9f7f83.js';
2
+ export { A as AssertType, E as EnhancedSpy, q as ExpectTypeOf, x as Mock, y as MockContext, w as MockInstance, z as Mocked, B as MockedClass, u as MockedFunction, v as MockedObject, S as SpyInstance, j as afterAll, l as afterEach, r as assertType, h as beforeAll, k as beforeEach, g as bench, n as createExpect, e as describe, m as expect, p as expectTypeOf, i as it, o as onTestFailed, d as suite, t as test } from './index-1e9f7f83.js';
3
+ import { D as DoneCallback, F as FakeTimerInstallOpts, R as RuntimeConfig, a as File, T as TaskResultPack, b as ResolvedConfig, M as ModuleGraphData, c as Reporter } from './types-c41bae41.js';
4
+ export { a1 as AfterSuiteRunMeta, A as ApiConfig, a7 as ArgumentsType, a6 as Arrayable, a4 as Awaitable, ap as BaseCoverageOptions, av as BenchFunction, at as Benchmark, aw as BenchmarkAPI, au as BenchmarkResult, as as BenchmarkUserOptions, B as BuiltinEnvironment, i as CSSModuleScopeStrategy, C as CollectLineNumbers, f as CollectLines, ab as Constructable, h as Context, ar as CoverageC8Options, aq as CoverageIstanbulOptions, an as CoverageOptions, ak as CoverageProvider, al as CoverageProviderModule, am as CoverageReporter, a9 as DeepMerge, D as DoneCallback, ae as Environment, E as EnvironmentOptions, ad as EnvironmentReturn, ai as ErrorWithDiff, a as File, x as HookCleanupCallback, H as HookListener, I as InlineConfig, J as JSDOMOptions, a8 as MergeInsertions, ac as ModuleCache, M as ModuleGraphData, aa as MutableArray, a5 as Nullable, aj as OnServerRestartHandler, O as OnTestFailedHandler, ah as ParsedStack, ag as Position, d as RawErrsMap, c as Reporter, a0 as ResolveIdFunction, b as ResolvedConfig, ao as ResolvedCoverageOptions, g as RootAndTarget, l as RunMode, R as RuntimeConfig, K as RuntimeContext, S as SequenceHooks, P as SnapshotData, X as SnapshotMatchOptions, Y as SnapshotResult, W as SnapshotStateOptions, _ as SnapshotSummary, Q as SnapshotUpdateState, p as Suite, w as SuiteAPI, z as SuiteCollector, G as SuiteFactory, y as SuiteHooks, s as Task, n as TaskBase, o as TaskResult, T as TaskResultPack, m as TaskState, q as Test, v as TestAPI, L as TestContext, t as TestFunction, u as TestOptions, e as TscErrorInfo, r as TypeCheck, k as TypecheckConfig, Z as UncheckedSnapshot, U as UserConfig, af as UserConsoleLog, N as Vitest, V as VitestEnvironment, j as VitestRunMode, $ as WorkerContext, a3 as WorkerGlobalState, a2 as WorkerRPC } from './types-c41bae41.js';
5
5
  import { TransformResult } from 'vite';
6
6
  import * as chai from 'chai';
7
7
  export { chai };
8
8
  export { assert, should } from 'chai';
9
9
  export { Bench as BenchFactory, Options as BenchOptions, Task as BenchTask, TaskResult as BenchTaskResult } from 'tinybench';
10
10
  import 'tinyspy';
11
- import 'fs';
12
- import 'worker_threads';
11
+ import 'vite-node/client';
12
+ import 'vite-node/server';
13
+ import 'vite-node';
14
+ import 'node:fs';
15
+ import 'node:worker_threads';
13
16
 
14
17
  /**
15
18
  * A simple wrapper for converting callback style to promise
@@ -136,17 +139,32 @@ declare class VitestUtils {
136
139
  clearAllMocks(): this;
137
140
  resetAllMocks(): this;
138
141
  restoreAllMocks(): this;
142
+ private _stubsGlobal;
143
+ private _stubsEnv;
139
144
  /**
140
- * Will put a value on global scope. Useful, if you are
141
- * using jsdom/happy-dom and want to mock global variables, like
142
- * `IntersectionObserver`.
145
+ * Makes value available on global namespace.
146
+ * Useful, if you want to have global variables available, like `IntersectionObserver`.
147
+ * You can return it back to original value with `vi.unstubGlobals`, or by enabling `unstubGlobals` config option.
143
148
  */
144
149
  stubGlobal(name: string | symbol | number, value: any): this;
150
+ /**
151
+ * Changes the value of `import.meta.env` and `process.env`.
152
+ * You can return it back to original value with `vi.unstubEnvs`, or by enabling `unstubEnvs` config option.
153
+ */
154
+ stubEnv(name: string, value: string): this;
155
+ /**
156
+ * Reset the value to original value that was available before first `vi.stubGlobal` was called.
157
+ */
158
+ unstubAllGlobals(): this;
159
+ /**
160
+ * Reset enviromental variables to the ones that were available before first `vi.stubEnv` was called.
161
+ */
162
+ unstubAllEnvs(): this;
145
163
  resetModules(): this;
146
164
  /**
147
- * Wait for all imports to load.
148
- * Useful, if you have a synchronous call that starts
149
- * importing a module that you cannot wait otherwise.
165
+ * Wait for all imports to load. Useful, if you have a synchronous call that starts
166
+ * importing a module that you cannot await otherwise.
167
+ * Will also wait for new imports, started during the wait.
150
168
  */
151
169
  dynamicImportSettled(): Promise<void>;
152
170
  private _config;