vitest 0.21.1 → 0.23.0

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 (50) hide show
  1. package/LICENSE.md +61 -33
  2. package/dist/browser.d.ts +5 -5
  3. package/dist/browser.mjs +12 -10
  4. package/dist/{chunk-api-setup.7a6ba7fb.mjs → chunk-api-setup.5fc06d1d.mjs} +94 -91
  5. package/dist/chunk-constants.6196597b.mjs +284 -0
  6. package/dist/chunk-env-node.ceb43f1c.mjs +403 -0
  7. package/dist/{chunk-install-pkg.6c6dc0c2.mjs → chunk-install-pkg.e081fc1b.mjs} +2 -1
  8. package/dist/chunk-integrations-coverage.99c020eb.mjs +166 -0
  9. package/dist/{chunk-integrations-globals.44a8f047.mjs → chunk-integrations-globals.ef598c23.mjs} +8 -9
  10. package/dist/{chunk-magic-string.efe26975.mjs → chunk-magic-string.56b2b543.mjs} +30 -10
  11. package/dist/chunk-mock-date.0d86eaa5.mjs +332 -0
  12. package/dist/chunk-node-git.6f289b0a.mjs +84 -0
  13. package/dist/{chunk-runtime-chain.98d42d89.mjs → chunk-runtime-chain.2af36ddf.mjs} +507 -172
  14. package/dist/{chunk-runtime-error.87a2b5a2.mjs → chunk-runtime-error.ed9b4f70.mjs} +208 -76
  15. package/dist/{chunk-runtime-hooks.453f8858.mjs → chunk-runtime-hooks.75ce0575.mjs} +18 -12
  16. package/dist/{chunk-runtime-mocker.23b62bfa.mjs → chunk-runtime-mocker.fc76f21d.mjs} +18 -11
  17. package/dist/{chunk-runtime-rpc.b50ab560.mjs → chunk-runtime-rpc.3fe371e9.mjs} +1 -2
  18. package/dist/{chunk-utils-source-map.94107ee8.mjs → chunk-utils-source-map.70ee97e1.mjs} +11 -4
  19. package/dist/{chunk-vite-node-client.fdd9592c.mjs → chunk-vite-node-client.74ebe3d5.mjs} +97 -31
  20. package/dist/{chunk-vite-node-debug.09afb76f.mjs → chunk-vite-node-debug.2d8a1dc3.mjs} +3 -3
  21. package/dist/{chunk-vite-node-externalize.27aee038.mjs → chunk-vite-node-externalize.41bf722e.mjs} +644 -222
  22. package/dist/{chunk-vite-node-utils.f34df9d3.mjs → chunk-vite-node-utils.68573626.mjs} +60 -42
  23. package/dist/cli-wrapper.mjs +128 -0
  24. package/dist/cli.mjs +29 -20
  25. package/dist/config.cjs +5 -2
  26. package/dist/config.d.ts +8 -4
  27. package/dist/config.mjs +4 -3
  28. package/dist/entry.mjs +20 -15
  29. package/dist/environments.d.ts +23 -0
  30. package/dist/environments.mjs +3 -0
  31. package/dist/{global-60f880c6.d.ts → global-ea084c9f.d.ts} +627 -178
  32. package/dist/{index-4a906fa4.d.ts → index-5f09f4d0.d.ts} +3 -50
  33. package/dist/index.d.ts +6 -6
  34. package/dist/index.mjs +7 -6
  35. package/dist/loader.mjs +3 -3
  36. package/dist/node.d.ts +5 -4
  37. package/dist/node.mjs +19 -16
  38. package/dist/suite.mjs +6 -5
  39. package/dist/vendor-index.0557b03a.mjs +147 -0
  40. package/dist/vendor-index.13e3bda3.mjs +61 -0
  41. package/dist/{chunk-node-git.c2be9c49.mjs → vendor-index.4aeeb598.mjs} +4 -72
  42. package/dist/{vendor-index.61438b77.mjs → vendor-index.731a22f2.mjs} +1 -61
  43. package/dist/worker.mjs +20 -18
  44. package/package.json +19 -16
  45. package/vitest.mjs +1 -1
  46. package/dist/chunk-constants.26dc9f85.mjs +0 -38
  47. package/dist/chunk-defaults.02abff90.mjs +0 -680
  48. package/dist/chunk-mock-date.bc81a3ac.mjs +0 -555
  49. package/dist/chunk-utils-global.fa20c2f6.mjs +0 -5
  50. package/dist/mocker-5e2a8e41.d.ts +0 -3
@@ -4,7 +4,7 @@ import { pathToFileURL, fileURLToPath as fileURLToPath$1, URL as URL$1 } from 'u
4
4
  import path from 'path';
5
5
  import assert from 'assert';
6
6
  import { format, inspect } from 'util';
7
- import { y as resolve$1 } from './chunk-mock-date.bc81a3ac.mjs';
7
+ import { a as resolve$1 } from './chunk-constants.6196597b.mjs';
8
8
 
9
9
  // This file was generated. Do not modify manually!
10
10
  var astralIdentifierCodes = [509, 0, 227, 0, 150, 4, 294, 9, 1368, 2, 2, 1, 6, 3, 41, 2, 5, 0, 166, 1, 574, 3, 9, 9, 370, 1, 154, 10, 50, 3, 123, 2, 54, 14, 32, 10, 3, 1, 11, 3, 46, 10, 8, 0, 46, 9, 7, 2, 37, 13, 2, 9, 6, 1, 45, 0, 13, 2, 49, 13, 9, 3, 2, 11, 83, 11, 7, 0, 161, 11, 6, 9, 7, 3, 56, 1, 2, 6, 3, 1, 3, 2, 10, 0, 11, 1, 3, 6, 4, 4, 193, 17, 10, 9, 5, 0, 82, 19, 13, 9, 214, 6, 3, 8, 28, 1, 83, 16, 16, 9, 82, 12, 9, 9, 84, 14, 5, 9, 243, 14, 166, 9, 71, 5, 2, 1, 3, 3, 2, 0, 2, 1, 13, 9, 120, 6, 3, 6, 4, 0, 29, 9, 41, 6, 2, 3, 9, 0, 10, 10, 47, 15, 406, 7, 2, 7, 17, 9, 57, 21, 2, 13, 123, 5, 4, 0, 2, 1, 2, 6, 2, 0, 9, 9, 49, 4, 2, 1, 2, 4, 9, 9, 330, 3, 19306, 9, 87, 9, 39, 4, 60, 6, 26, 9, 1014, 0, 2, 54, 8, 3, 82, 0, 12, 1, 19628, 1, 4706, 45, 3, 22, 543, 4, 4, 5, 9, 7, 3, 6, 31, 3, 149, 2, 1418, 49, 513, 54, 5, 49, 9, 0, 15, 0, 23, 4, 2, 14, 1361, 6, 2, 16, 3, 6, 2, 1, 2, 4, 262, 6, 10, 9, 357, 0, 62, 13, 1495, 6, 110, 6, 6, 9, 4759, 9, 787719, 239];
@@ -5553,50 +5553,56 @@ Parser.acorn = {
5553
5553
  nonASCIIwhitespace: nonASCIIwhitespace
5554
5554
  };
5555
5555
 
5556
- function normalizeWindowsPath$1(input = "") {
5557
- if (!input.includes("\\")) {
5558
- return input;
5556
+ const TRAILING_SLASH_RE = /\/$|\/\?/;
5557
+ function hasTrailingSlash(input = "", queryParams = false) {
5558
+ if (!queryParams) {
5559
+ return input.endsWith("/");
5559
5560
  }
5560
- return input.replace(/\\/g, "/");
5561
+ return TRAILING_SLASH_RE.test(input);
5562
+ }
5563
+ function withTrailingSlash(input = "", queryParams = false) {
5564
+ if (!queryParams) {
5565
+ return input.endsWith("/") ? input : input + "/";
5566
+ }
5567
+ if (hasTrailingSlash(input, true)) {
5568
+ return input || "/";
5569
+ }
5570
+ const [s0, ...s] = input.split("?");
5571
+ return s0 + "/" + (s.length ? `?${s.join("?")}` : "");
5572
+ }
5573
+ function hasLeadingSlash(input = "") {
5574
+ return input.startsWith("/");
5575
+ }
5576
+ function withoutLeadingSlash(input = "") {
5577
+ return (hasLeadingSlash(input) ? input.substr(1) : input) || "/";
5578
+ }
5579
+ function isNonEmptyURL(url) {
5580
+ return url && url !== "/";
5581
+ }
5582
+ function joinURL(base, ...input) {
5583
+ let url = base || "";
5584
+ for (const i of input.filter(isNonEmptyURL)) {
5585
+ url = url ? withTrailingSlash(url) + withoutLeadingSlash(i) : i;
5586
+ }
5587
+ return url;
5561
5588
  }
5562
- const _IS_ABSOLUTE_RE$1 = /^\/|^\\|^[a-zA-Z]:[/\\]/;
5563
- const isAbsolute$1 = function(p) {
5564
- return _IS_ABSOLUTE_RE$1.test(p);
5565
- };
5566
- const _EXTNAME_RE = /(?<!^)\.[^/.]+$/;
5567
- const extname = function(p) {
5568
- const match = _EXTNAME_RE.exec(normalizeWindowsPath$1(p));
5569
- return match && match[0] || "";
5570
- };
5571
-
5572
- /*---------------------------------------------------------------------------------------------
5573
- * Copyright (c) Microsoft Corporation. All rights reserved.
5574
- * Licensed under the MIT License. See License.txt in the project root for license information.
5575
- *--------------------------------------------------------------------------------------------*/
5576
- var ParseOptions;
5577
- (function (ParseOptions) {
5578
- ParseOptions.DEFAULT = {
5579
- allowTrailingComma: false
5580
- };
5581
- })(ParseOptions || (ParseOptions = {}));
5582
5589
 
5583
5590
  function normalizeWindowsPath(input = "") {
5584
- if (!input.includes("\\")) {
5591
+ if (!input || !input.includes("\\")) {
5585
5592
  return input;
5586
5593
  }
5587
5594
  return input.replace(/\\/g, "/");
5588
5595
  }
5589
5596
 
5590
- const _UNC_REGEX = /^[/][/]/;
5591
- const _UNC_DRIVE_REGEX = /^[/][/]([.]{1,2}[/])?([a-zA-Z]):[/]/;
5592
- const _IS_ABSOLUTE_RE = /^\/|^\\|^[a-zA-Z]:[/\\]/;
5597
+ const _UNC_REGEX = /^[\\/]{2}/;
5598
+ const _IS_ABSOLUTE_RE = /^[\\/](?![\\/])|^[\\/]{2}(?!\.)|^[a-zA-Z]:[\\/]/;
5599
+ const _DRIVE_LETTER_RE = /^[a-zA-Z]:$/;
5593
5600
  const normalize = function(path) {
5594
5601
  if (path.length === 0) {
5595
5602
  return ".";
5596
5603
  }
5597
5604
  path = normalizeWindowsPath(path);
5598
5605
  const isUNCPath = path.match(_UNC_REGEX);
5599
- const hasUNCDrive = isUNCPath && path.match(_UNC_DRIVE_REGEX);
5600
5606
  const isPathAbsolute = isAbsolute(path);
5601
5607
  const trailingSeparator = path[path.length - 1] === "/";
5602
5608
  path = normalizeString(path, !isPathAbsolute);
@@ -5609,8 +5615,11 @@ const normalize = function(path) {
5609
5615
  if (trailingSeparator) {
5610
5616
  path += "/";
5611
5617
  }
5618
+ if (_DRIVE_LETTER_RE.test(path)) {
5619
+ path += "/";
5620
+ }
5612
5621
  if (isUNCPath) {
5613
- if (hasUNCDrive) {
5622
+ if (!isPathAbsolute) {
5614
5623
  return `//./${path}`;
5615
5624
  }
5616
5625
  return `//${path}`;
@@ -5624,7 +5633,7 @@ const join = function(...args) {
5624
5633
  let joined;
5625
5634
  for (let i = 0; i < args.length; ++i) {
5626
5635
  const arg = args[i];
5627
- if (arg.length > 0) {
5636
+ if (arg && arg.length > 0) {
5628
5637
  if (joined === void 0) {
5629
5638
  joined = arg;
5630
5639
  } else {
@@ -5642,8 +5651,8 @@ const resolve = function(...args) {
5642
5651
  let resolvedPath = "";
5643
5652
  let resolvedAbsolute = false;
5644
5653
  for (let i = args.length - 1; i >= -1 && !resolvedAbsolute; i--) {
5645
- const path = i >= 0 ? args[i] : process.cwd();
5646
- if (path.length === 0) {
5654
+ const path = i >= 0 ? args[i] : process.cwd().replace(/\\/g, "/");
5655
+ if (!path || path.length === 0) {
5647
5656
  continue;
5648
5657
  }
5649
5658
  resolvedPath = `${path}/${resolvedPath}`;
@@ -5717,6 +5726,11 @@ function normalizeString(path, allowAboveRoot) {
5717
5726
  const isAbsolute = function(p) {
5718
5727
  return _IS_ABSOLUTE_RE.test(p);
5719
5728
  };
5729
+ const _EXTNAME_RE = /.(\.[^/.]+)$/;
5730
+ const extname = function(p) {
5731
+ const match = _EXTNAME_RE.exec(normalizeWindowsPath(p));
5732
+ return match && match[1] || "";
5733
+ };
5720
5734
 
5721
5735
  const defaultFindOptions = {
5722
5736
  startingFrom: ".",
@@ -5740,8 +5754,9 @@ async function findNearestFile(filename, _options = {}) {
5740
5754
  segments[0] = "/" + segments[0];
5741
5755
  }
5742
5756
  let root = segments.findIndex((r) => r.match(options.rootPattern));
5743
- if (root === -1)
5757
+ if (root === -1) {
5744
5758
  root = 0;
5759
+ }
5745
5760
  for (let i = segments.length; i > root; i--) {
5746
5761
  const filePath = join(...segments.slice(0, i), filename);
5747
5762
  if (await options.test(filePath)) {
@@ -6710,7 +6725,7 @@ function normalizeid(id) {
6710
6725
  if (BUILTIN_MODULES.has(id)) {
6711
6726
  return "node:" + id;
6712
6727
  }
6713
- return "file://" + normalizeSlash(id);
6728
+ return "file://" + encodeURI(normalizeSlash(id));
6714
6729
  }
6715
6730
  function isNodeBuiltin(id = "") {
6716
6731
  id = id.replace(/^node:/, "").split("/")[0];
@@ -6743,7 +6758,7 @@ function _resolve(id, opts = {}) {
6743
6758
  if (BUILTIN_MODULES.has(id)) {
6744
6759
  return "node:" + id;
6745
6760
  }
6746
- if (isAbsolute$1(id) && existsSync(id)) {
6761
+ if (isAbsolute(id) && existsSync(id)) {
6747
6762
  const realPath2 = realpathSync(fileURLToPath(id));
6748
6763
  return pathToFileURL(realPath2).toString();
6749
6764
  }
@@ -6754,10 +6769,10 @@ function _resolve(id, opts = {}) {
6754
6769
  }
6755
6770
  const urls = [..._urls];
6756
6771
  for (const url of _urls) {
6757
- if (url.protocol === "file:" && !url.pathname.includes("node_modules")) {
6758
- const newURL = new URL(url);
6759
- newURL.pathname += "/node_modules";
6760
- urls.push(newURL);
6772
+ if (url.protocol === "file:") {
6773
+ urls.push(new URL("./", url));
6774
+ urls.push(new URL(joinURL(url.pathname, "_index.js"), url));
6775
+ urls.push(new URL("./node_modules", url));
6761
6776
  }
6762
6777
  }
6763
6778
  let resolved;
@@ -6843,6 +6858,9 @@ const isWindows = process.platform === "win32";
6843
6858
  function slash(str) {
6844
6859
  return str.replace(/\\/g, "/");
6845
6860
  }
6861
+ function getType(value) {
6862
+ return Object.prototype.toString.apply(value).slice(8, -1);
6863
+ }
6846
6864
  function mergeSlashes(str) {
6847
6865
  return str.replace(/\/\//g, "/");
6848
6866
  }
@@ -6884,4 +6902,4 @@ function toArray(array) {
6884
6902
  return [array];
6885
6903
  }
6886
6904
 
6887
- export { isValidNodeImport as a, toFilePath as b, isPrimitive as c, normalizeModuleId as d, hasCJSSyntax as h, isNodeBuiltin as i, mergeSlashes as m, normalizeRequestId as n, slash as s, toArray as t, withInlineSourcemap as w };
6905
+ export { isValidNodeImport as a, toFilePath as b, isPrimitive as c, normalizeModuleId as d, getType as g, hasCJSSyntax as h, isNodeBuiltin as i, mergeSlashes as m, normalizeRequestId as n, slash as s, toArray as t, withInlineSourcemap as w };
@@ -0,0 +1,128 @@
1
+ import { fileURLToPath } from 'url';
2
+ import { p as picocolors, E as EXIT_CODE_RESTART } from './chunk-constants.6196597b.mjs';
3
+ import { e as execa } from './vendor-index.4aeeb598.mjs';
4
+ import 'tty';
5
+ import 'path';
6
+ import 'buffer';
7
+ import 'child_process';
8
+ import 'process';
9
+ import './vendor-index.62ce5c33.mjs';
10
+ import './vendor-_commonjsHelpers.4da45ef5.mjs';
11
+ import 'fs';
12
+ import 'stream';
13
+ import 'util';
14
+ import 'os';
15
+ import './vendor-index.731a22f2.mjs';
16
+ import 'assert';
17
+ import 'events';
18
+
19
+ const ENTRY = new URL("./cli.mjs", import.meta.url);
20
+ const NODE_ARGS = [
21
+ "--inspect",
22
+ "--inspect-brk",
23
+ "--trace-deprecation"
24
+ ];
25
+ const SegfaultErrors = [
26
+ {
27
+ trigger: "Check failed: result.second.",
28
+ url: "https://github.com/nodejs/node/issues/43617"
29
+ },
30
+ {
31
+ trigger: "FATAL ERROR: v8::FromJust Maybe value is Nothing.",
32
+ url: "https://github.com/vitest-dev/vitest/issues/1191"
33
+ },
34
+ {
35
+ trigger: "FATAL ERROR: v8::ToLocalChecked Empty MaybeLocal.",
36
+ url: "https://github.com/nodejs/node/issues/42407"
37
+ }
38
+ ];
39
+ main();
40
+ async function main() {
41
+ var _a;
42
+ let retries = 0;
43
+ const args = process.argv.slice(2);
44
+ if (process.env.VITEST_SEGFAULT_RETRY) {
45
+ retries = +process.env.VITEST_SEGFAULT_RETRY;
46
+ } else {
47
+ for (let i = 0; i < args.length; i++) {
48
+ if (args[i].startsWith("--segfault-retry=")) {
49
+ retries = +args[i].split("=")[1];
50
+ break;
51
+ } else if (args[i] === "--segfault-retry" && ((_a = args[i + 1]) == null ? void 0 : _a.match(/^\d+$/))) {
52
+ retries = +args[i + 1];
53
+ break;
54
+ }
55
+ }
56
+ }
57
+ const nodeArgs = [];
58
+ const vitestArgs = [];
59
+ for (let i = 0; i < args.length; i++) {
60
+ let matched = false;
61
+ for (const nodeArg of NODE_ARGS) {
62
+ if (args[i] === nodeArg || args[i].startsWith(`${nodeArg}=`)) {
63
+ matched = true;
64
+ nodeArgs.push(args[i]);
65
+ break;
66
+ }
67
+ }
68
+ if (!matched)
69
+ vitestArgs.push(args[i]);
70
+ }
71
+ retries = Math.max(1, retries || 1);
72
+ for (let i = 1; i <= retries; i++) {
73
+ const result = await start(nodeArgs, vitestArgs);
74
+ if (result === "restart") {
75
+ i -= 1;
76
+ continue;
77
+ }
78
+ if (i === 1 && retries === 1) {
79
+ console.log(picocolors.exports.yellow(`It seems to be an upstream bug of Node.js. To improve the test stability,
80
+ you could pass ${picocolors.exports.bold(picocolors.exports.green("--segfault-retry=3"))} or set env ${picocolors.exports.bold(picocolors.exports.green("VITEST_SEGFAULT_RETRY=3"))} to
81
+ have Vitest auto retries on flaky segfaults.
82
+ `));
83
+ }
84
+ if (i !== retries)
85
+ console.log(`${picocolors.exports.inverse(picocolors.exports.bold(picocolors.exports.magenta(" Retrying ")))} vitest ${args.join(" ")} ${picocolors.exports.gray(`(${i + 1} of ${retries})`)}`);
86
+ }
87
+ process.exit(1);
88
+ }
89
+ async function start(preArgs, postArgs) {
90
+ var _a;
91
+ const child = execa(
92
+ "node",
93
+ [
94
+ ...preArgs,
95
+ fileURLToPath(ENTRY),
96
+ ...postArgs
97
+ ],
98
+ {
99
+ reject: false,
100
+ stderr: "pipe",
101
+ stdout: "inherit",
102
+ stdin: "inherit",
103
+ env: {
104
+ ...process.env,
105
+ VITEST_CLI_WRAPPER: "true"
106
+ }
107
+ }
108
+ );
109
+ (_a = child.stderr) == null ? void 0 : _a.pipe(process.stderr);
110
+ const { stderr = "" } = await child;
111
+ if (child.exitCode === EXIT_CODE_RESTART)
112
+ return "restart";
113
+ for (const error of SegfaultErrors) {
114
+ if (stderr.includes(error.trigger)) {
115
+ if (process.env.GITHUB_ACTIONS)
116
+ console.log(`::warning:: Segmentfault Error Detected: ${error.trigger}
117
+ Refer to ${error.url}`);
118
+ const RED_BLOCK = picocolors.exports.inverse(picocolors.exports.red(" "));
119
+ console.log(`
120
+ ${picocolors.exports.inverse(picocolors.exports.bold(picocolors.exports.red(" Segmentfault Error Detected ")))}
121
+ ${RED_BLOCK} ${picocolors.exports.red(error.trigger)}
122
+ ${RED_BLOCK} ${picocolors.exports.red(`Refer to ${error.url}`)}
123
+ `);
124
+ return "error";
125
+ }
126
+ }
127
+ process.exit(child.exitCode);
128
+ }
package/dist/cli.mjs CHANGED
@@ -1,33 +1,37 @@
1
1
  import { EventEmitter } from 'events';
2
- import { p as picocolors } from './chunk-mock-date.bc81a3ac.mjs';
3
- import { v as version, s as startVitest, d as divider } from './chunk-vite-node-externalize.27aee038.mjs';
4
- import 'path';
2
+ import { p as picocolors } from './chunk-constants.6196597b.mjs';
3
+ import { v as version, s as startVitest, d as divider } from './chunk-vite-node-externalize.41bf722e.mjs';
5
4
  import 'tty';
6
- import 'local-pkg';
7
- import './chunk-defaults.02abff90.mjs';
8
- import 'fs';
9
- import 'module';
10
5
  import 'url';
6
+ import 'path';
7
+ import './chunk-integrations-coverage.99c020eb.mjs';
8
+ import 'local-pkg';
9
+ import './chunk-env-node.ceb43f1c.mjs';
10
+ import 'console';
11
+ import './chunk-mock-date.0d86eaa5.mjs';
11
12
  import 'vite';
12
13
  import 'process';
13
- import './chunk-constants.26dc9f85.mjs';
14
+ import 'fs';
14
15
  import 'os';
15
16
  import 'util';
16
17
  import 'stream';
17
18
  import './vendor-_commonjsHelpers.4da45ef5.mjs';
18
- import './chunk-vite-node-client.fdd9592c.mjs';
19
+ import './chunk-vite-node-client.74ebe3d5.mjs';
20
+ import 'module';
19
21
  import 'vm';
20
- import './chunk-vite-node-utils.f34df9d3.mjs';
22
+ import './chunk-vite-node-utils.68573626.mjs';
21
23
  import 'assert';
22
24
  import 'debug';
25
+ import 'perf_hooks';
23
26
  import 'worker_threads';
24
27
  import 'tinypool';
25
- import 'perf_hooks';
26
- import './chunk-utils-source-map.94107ee8.mjs';
28
+ import './chunk-utils-source-map.70ee97e1.mjs';
27
29
  import './chunk-utils-timers.b48455ed.mjs';
28
30
  import 'crypto';
29
- import './vendor-index.61438b77.mjs';
30
- import './chunk-magic-string.efe26975.mjs';
31
+ import './vendor-index.13e3bda3.mjs';
32
+ import './vendor-index.731a22f2.mjs';
33
+ import './chunk-magic-string.56b2b543.mjs';
34
+ import 'strip-literal';
31
35
  import 'readline';
32
36
  import './vendor-index.ae96af6e.mjs';
33
37
 
@@ -645,25 +649,30 @@ class CAC extends EventEmitter {
645
649
  const cac = (name = "") => new CAC(name);
646
650
 
647
651
  const cli = cac("vitest");
648
- 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 mutliple reporters").option("--coverage", "use c8 for coverage").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)").help();
652
+ 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();
649
653
  cli.command("run [...filters]").action(run);
650
654
  cli.command("related [...filters]").action(runRelated);
651
655
  cli.command("watch [...filters]").action(start);
652
656
  cli.command("dev [...filters]").action(start);
653
- cli.command("[...filters]").action(start);
657
+ cli.command("bench [...filters]").action(benchmark);
658
+ cli.command("[...filters]").action((filter, options) => start("test", filter, options));
654
659
  cli.parse();
655
660
  async function runRelated(relatedFiles, argv) {
656
661
  argv.related = relatedFiles;
657
662
  argv.passWithNoTests ?? (argv.passWithNoTests = true);
658
- await start([], argv);
663
+ await start("test", [], argv);
659
664
  }
660
665
  async function run(cliFilters, options) {
661
666
  options.run = true;
662
- await start(cliFilters, options);
667
+ await start("test", cliFilters, options);
668
+ }
669
+ async function benchmark(cliFilters, options) {
670
+ console.warn(picocolors.exports.yellow("Benchmarking is an experimental feature. API might change in the future."));
671
+ await start("benchmark", cliFilters, options);
663
672
  }
664
- async function start(cliFilters, options) {
673
+ async function start(mode, cliFilters, options) {
665
674
  try {
666
- if (await startVitest(cliFilters, options) === false)
675
+ if (await startVitest(mode, cliFilters, options) === false)
667
676
  process.exit();
668
677
  } catch (e) {
669
678
  process.exitCode = 1;
package/dist/config.cjs CHANGED
@@ -19,13 +19,14 @@ const defaultCoverageExcludes = [
19
19
  "**/.{eslint,mocha,prettier}rc.{js,cjs,yml}"
20
20
  ];
21
21
  const coverageConfigDefaults = {
22
+ provider: "c8",
22
23
  enabled: false,
23
24
  clean: true,
24
25
  cleanOnRerun: false,
25
26
  reportsDirectory: "./coverage",
26
27
  excludeNodeModules: true,
27
28
  exclude: defaultCoverageExcludes,
28
- reporter: ["text", "html", "clover"],
29
+ reporter: ["text", "html", "clover", "json"],
29
30
  allowExternal: false,
30
31
  extension: [".js", ".cjs", ".mjs", ".ts", ".tsx", ".jsx", ".vue", ".svelte"]
31
32
  };
@@ -71,7 +72,7 @@ const config = {
71
72
  uiBase: "/__vitest__/",
72
73
  open: true,
73
74
  css: {
74
- include: [/\.module\./]
75
+ include: []
75
76
  },
76
77
  coverage: coverageConfigDefaults,
77
78
  fakeTimers: fakeTimersDefaults,
@@ -85,4 +86,6 @@ function defineConfig(config) {
85
86
  }
86
87
 
87
88
  exports.configDefaults = configDefaults;
89
+ exports.defaultExclude = defaultExclude;
90
+ exports.defaultInclude = defaultInclude;
88
91
  exports.defineConfig = defineConfig;
package/dist/config.d.ts CHANGED
@@ -1,8 +1,12 @@
1
1
  import { UserConfig as UserConfig$2, ConfigEnv } from 'vite';
2
2
  export { ConfigEnv } from 'vite';
3
- import { U as UserConfig$1, a1 as ResolvedC8Options, F as FakeTimerInstallOpts } from './global-60f880c6.js';
3
+ import { U as UserConfig$1, ad as ResolvedCoverageOptions, F as FakeTimerInstallOpts } from './global-ea084c9f.js';
4
+ import 'tinybench';
4
5
  import 'fs';
6
+ import 'worker_threads';
5
7
 
8
+ declare const defaultInclude: string[];
9
+ declare const defaultExclude: string[];
6
10
  declare const config: {
7
11
  allowOnly: boolean;
8
12
  watch: boolean;
@@ -28,9 +32,9 @@ declare const config: {
28
32
  uiBase: string;
29
33
  open: boolean;
30
34
  css: {
31
- include: RegExp[];
35
+ include: never[];
32
36
  };
33
- coverage: ResolvedC8Options;
37
+ coverage: ResolvedCoverageOptions;
34
38
  fakeTimers: FakeTimerInstallOpts;
35
39
  maxConcurrency: number;
36
40
  dangerouslyIgnoreUnhandledErrors: boolean;
@@ -45,4 +49,4 @@ declare type UserConfigFn = (env: ConfigEnv) => UserConfig | Promise<UserConfig>
45
49
  declare type UserConfigExport = UserConfig | Promise<UserConfig> | UserConfigFn;
46
50
  declare function defineConfig(config: UserConfigExport): UserConfigExport;
47
51
 
48
- export { UserConfig, UserConfigExport, UserConfigFn, configDefaults, defineConfig };
52
+ export { UserConfig, UserConfigExport, UserConfigFn, configDefaults, defaultExclude, defaultInclude, defineConfig };
package/dist/config.mjs CHANGED
@@ -15,13 +15,14 @@ const defaultCoverageExcludes = [
15
15
  "**/.{eslint,mocha,prettier}rc.{js,cjs,yml}"
16
16
  ];
17
17
  const coverageConfigDefaults = {
18
+ provider: "c8",
18
19
  enabled: false,
19
20
  clean: true,
20
21
  cleanOnRerun: false,
21
22
  reportsDirectory: "./coverage",
22
23
  excludeNodeModules: true,
23
24
  exclude: defaultCoverageExcludes,
24
- reporter: ["text", "html", "clover"],
25
+ reporter: ["text", "html", "clover", "json"],
25
26
  allowExternal: false,
26
27
  extension: [".js", ".cjs", ".mjs", ".ts", ".tsx", ".jsx", ".vue", ".svelte"]
27
28
  };
@@ -67,7 +68,7 @@ const config = {
67
68
  uiBase: "/__vitest__/",
68
69
  open: true,
69
70
  css: {
70
- include: [/\.module\./]
71
+ include: []
71
72
  },
72
73
  coverage: coverageConfigDefaults,
73
74
  fakeTimers: fakeTimersDefaults,
@@ -80,4 +81,4 @@ function defineConfig(config) {
80
81
  return config;
81
82
  }
82
83
 
83
- export { configDefaults, defineConfig };
84
+ export { configDefaults, defaultExclude, defaultInclude, defineConfig };
package/dist/entry.mjs CHANGED
@@ -1,21 +1,23 @@
1
1
  import { promises } from 'fs';
2
- import { a as resetModules } from './chunk-mock-date.bc81a3ac.mjs';
3
- import { f as envs } from './chunk-defaults.02abff90.mjs';
4
- import { a as setupGlobalEnv, s as startTests, w as withEnv } from './chunk-runtime-error.87a2b5a2.mjs';
5
- import { g as getWorkerState } from './chunk-utils-global.fa20c2f6.mjs';
2
+ import { g as getWorkerState, a as resetModules } from './chunk-mock-date.0d86eaa5.mjs';
3
+ import { a as envs } from './chunk-env-node.ceb43f1c.mjs';
4
+ import { a as setupGlobalEnv, s as startTests, w as withEnv } from './chunk-runtime-error.ed9b4f70.mjs';
6
5
  import 'path';
6
+ import './chunk-constants.6196597b.mjs';
7
7
  import 'tty';
8
- import 'local-pkg';
9
- import 'module';
10
8
  import 'url';
11
- import './chunk-runtime-hooks.453f8858.mjs';
12
- import './chunk-runtime-chain.98d42d89.mjs';
9
+ import 'local-pkg';
10
+ import 'console';
11
+ import 'perf_hooks';
12
+ import './chunk-integrations-coverage.99c020eb.mjs';
13
+ import './chunk-runtime-hooks.75ce0575.mjs';
14
+ import './chunk-runtime-chain.2af36ddf.mjs';
13
15
  import 'util';
14
16
  import 'chai';
15
17
  import './vendor-_commonjsHelpers.4da45ef5.mjs';
16
- import './chunk-runtime-rpc.b50ab560.mjs';
18
+ import './chunk-runtime-rpc.3fe371e9.mjs';
17
19
  import './chunk-utils-timers.b48455ed.mjs';
18
- import './chunk-utils-source-map.94107ee8.mjs';
20
+ import './chunk-utils-source-map.70ee97e1.mjs';
19
21
  import './spy.mjs';
20
22
  import 'tinyspy';
21
23
 
@@ -31,8 +33,6 @@ async function run(files, config) {
31
33
  var _a;
32
34
  const code = await promises.readFile(file, "utf-8");
33
35
  const env = ((_a = code.match(/@(?:vitest|jest)-environment\s+?([\w-]+)\b/)) == null ? void 0 : _a[1]) || config.environment || "node";
34
- if (!envs.includes(env))
35
- throw new Error(`Unsupported environment: "${env}" in ${file}`);
36
36
  return {
37
37
  file,
38
38
  env
@@ -43,15 +43,20 @@ async function run(files, config) {
43
43
  acc[env].push(file);
44
44
  return acc;
45
45
  }, {});
46
- for (const env of envs) {
46
+ const orderedEnvs = envs.concat(
47
+ Object.keys(filesByEnv).filter((env) => !envs.includes(env))
48
+ );
49
+ for (const env of orderedEnvs) {
47
50
  const environment = env;
48
51
  const files2 = filesByEnv[environment];
49
52
  if (!files2 || !files2.length)
50
53
  continue;
51
54
  await withEnv(environment, config.environmentOptions || {}, async () => {
52
55
  for (const file of files2) {
53
- workerState.mockMap.clear();
54
- resetModules(workerState.moduleCache, true);
56
+ if (config.isolate) {
57
+ workerState.mockMap.clear();
58
+ resetModules(workerState.moduleCache, true);
59
+ }
55
60
  workerState.filepath = file;
56
61
  await startTests([file], config);
57
62
  workerState.filepath = void 0;
@@ -0,0 +1,23 @@
1
+ import { a3 as Environment } from './global-ea084c9f.js';
2
+ import 'vite';
3
+ import 'tinybench';
4
+ import 'fs';
5
+ import 'worker_threads';
6
+
7
+ declare const environments: {
8
+ node: Environment;
9
+ jsdom: Environment;
10
+ 'happy-dom': Environment;
11
+ 'edge-runtime': Environment;
12
+ };
13
+
14
+ interface PopulateOptions {
15
+ bindFunctions?: boolean;
16
+ }
17
+ declare function populateGlobal(global: any, win: any, options?: PopulateOptions): {
18
+ keys: Set<string>;
19
+ skipKeys: string[];
20
+ originals: Map<string | symbol, any>;
21
+ };
22
+
23
+ export { environments as builtinEnvironments, populateGlobal };
@@ -0,0 +1,3 @@
1
+ export { e as builtinEnvironments, p as populateGlobal } from './chunk-env-node.ceb43f1c.mjs';
2
+ import 'console';
3
+ import 'local-pkg';