vitest 0.21.1 → 0.22.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 (43) hide show
  1. package/LICENSE.md +32 -4
  2. package/dist/browser.d.ts +4 -5
  3. package/dist/browser.mjs +8 -9
  4. package/dist/{chunk-api-setup.7a6ba7fb.mjs → chunk-api-setup.ecd02c18.mjs} +8 -7
  5. package/dist/{chunk-constants.26dc9f85.mjs → chunk-constants.d3f8437b.mjs} +4 -4
  6. package/dist/{chunk-install-pkg.6c6dc0c2.mjs → chunk-install-pkg.3aa3eae6.mjs} +3 -2
  7. package/dist/{chunk-defaults.02abff90.mjs → chunk-integrations-coverage.d205bd87.mjs} +23 -152
  8. package/dist/{chunk-integrations-globals.44a8f047.mjs → chunk-integrations-globals.e81d2091.mjs} +7 -6
  9. package/dist/{chunk-mock-date.bc81a3ac.mjs → chunk-mock-date.debe9954.mjs} +6 -67
  10. package/dist/chunk-node-git.71b74da4.mjs +80 -0
  11. package/dist/{chunk-runtime-chain.98d42d89.mjs → chunk-runtime-chain.6e363ba2.mjs} +4 -3
  12. package/dist/{chunk-runtime-error.87a2b5a2.mjs → chunk-runtime-error.975bd80a.mjs} +13 -12
  13. package/dist/{chunk-runtime-hooks.453f8858.mjs → chunk-runtime-hooks.4789e99d.mjs} +3 -3
  14. package/dist/{chunk-runtime-mocker.23b62bfa.mjs → chunk-runtime-mocker.c91d29ce.mjs} +5 -5
  15. package/dist/{chunk-runtime-rpc.b50ab560.mjs → chunk-runtime-rpc.29488183.mjs} +1 -1
  16. package/dist/{chunk-utils-source-map.94107ee8.mjs → chunk-utils-source-map.2a082ffd.mjs} +2 -1
  17. package/dist/{chunk-vite-node-client.fdd9592c.mjs → chunk-vite-node-client.d1ead698.mjs} +2 -2
  18. package/dist/{chunk-vite-node-debug.09afb76f.mjs → chunk-vite-node-debug.ff1d2a9f.mjs} +3 -2
  19. package/dist/{chunk-vite-node-externalize.27aee038.mjs → chunk-vite-node-externalize.3a38c8af.mjs} +153 -35
  20. package/dist/{chunk-vite-node-utils.f34df9d3.mjs → chunk-vite-node-utils.d8e5ff7b.mjs} +42 -8
  21. package/dist/cli-wrapper.mjs +107 -0
  22. package/dist/cli.mjs +15 -13
  23. package/dist/config.cjs +3 -0
  24. package/dist/config.d.ts +6 -3
  25. package/dist/config.mjs +2 -1
  26. package/dist/entry.mjs +8 -9
  27. package/dist/{global-60f880c6.d.ts → global-74489cc9.d.ts} +485 -166
  28. package/dist/{index-4a906fa4.d.ts → index-9eded9ec.d.ts} +2 -50
  29. package/dist/index.d.ts +5 -6
  30. package/dist/index.mjs +6 -5
  31. package/dist/loader.mjs +3 -2
  32. package/dist/node.d.ts +3 -3
  33. package/dist/node.mjs +14 -12
  34. package/dist/suite.mjs +5 -4
  35. package/dist/{vendor-index.61438b77.mjs → vendor-index.29636037.mjs} +1 -61
  36. package/dist/{vendor-index.62ce5c33.mjs → vendor-index.2ae8040a.mjs} +0 -0
  37. package/dist/vendor-index.9d9196cc.mjs +61 -0
  38. package/dist/{chunk-node-git.c2be9c49.mjs → vendor-index.fbec8a81.mjs} +5 -73
  39. package/dist/vendor-picocolors.807856aa.mjs +64 -0
  40. package/dist/worker.mjs +7 -6
  41. package/package.json +6 -10
  42. package/vitest.mjs +1 -1
  43. package/dist/mocker-5e2a8e41.d.ts +0 -3
@@ -0,0 +1,107 @@
1
+ import { fileURLToPath } from 'url';
2
+ import { p as picocolors } from './vendor-picocolors.807856aa.mjs';
3
+ import { e as execa } from './vendor-index.fbec8a81.mjs';
4
+ import 'tty';
5
+ import 'buffer';
6
+ import 'path';
7
+ import 'child_process';
8
+ import 'process';
9
+ import './vendor-index.2ae8040a.mjs';
10
+ import './vendor-_commonjsHelpers.4da45ef5.mjs';
11
+ import 'fs';
12
+ import 'stream';
13
+ import 'util';
14
+ import 'os';
15
+ import './vendor-index.29636037.mjs';
16
+ import 'assert';
17
+ import 'events';
18
+
19
+ const ENTRY = new URL("./cli.mjs", import.meta.url);
20
+ const NODE_ARGS = ["--inspect", "--inspect-brk", "--trace-deprecation"];
21
+ const ERRORS = [
22
+ {
23
+ trigger: "Check failed: result.second.",
24
+ url: "https://github.com/nodejs/node/issues/43617"
25
+ },
26
+ {
27
+ trigger: "FATAL ERROR: v8::FromJust Maybe value is Nothing.",
28
+ url: "https://github.com/vitest-dev/vitest/issues/1191"
29
+ },
30
+ {
31
+ trigger: "FATAL ERROR: v8::ToLocalChecked Empty MaybeLocal.",
32
+ url: "https://github.com/nodejs/node/issues/42407"
33
+ }
34
+ ];
35
+ async function main() {
36
+ var _a;
37
+ const exitCode = 100;
38
+ let retries = 0;
39
+ const args = process.argv.slice(2);
40
+ if (process.env.VITEST_SEGFAULT_RETRY) {
41
+ retries = +process.env.VITEST_SEGFAULT_RETRY;
42
+ } else {
43
+ for (let i = 0; i < args.length; i++) {
44
+ if (args[i].startsWith("--segfault-retry=")) {
45
+ retries = +args[i].split("=")[1];
46
+ break;
47
+ } else if (args[i] === "--segfault-retry" && ((_a = args[i + 1]) == null ? void 0 : _a.match(/^\d+$/))) {
48
+ retries = +args[i + 1];
49
+ break;
50
+ }
51
+ }
52
+ }
53
+ retries = Math.max(1, retries || 1);
54
+ for (let i = 1; i <= retries; i++) {
55
+ if (i !== 1)
56
+ console.log(`${picocolors.exports.inverse(picocolors.exports.bold(picocolors.exports.magenta(" Retrying ")))} vitest ${args.join(" ")} ${picocolors.exports.gray(`(${i} of ${retries})`)}`);
57
+ await start(args);
58
+ if (i === 1 && retries === 1) {
59
+ console.log(picocolors.exports.yellow(`It seems to be an upstream bug of Node.js. To improve the test stability,
60
+ 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
61
+ have Vitest auto retries on flaky segfaults.
62
+ `));
63
+ }
64
+ }
65
+ process.exit(exitCode);
66
+ }
67
+ main();
68
+ async function start(args) {
69
+ var _a;
70
+ const nodeArgs = [];
71
+ const vitestArgs = [];
72
+ for (let i = 0; i < args.length; i++) {
73
+ let matched = false;
74
+ for (const nodeArg of NODE_ARGS) {
75
+ if (args[i] === nodeArg || args[i].startsWith(`${nodeArg}=`)) {
76
+ matched = true;
77
+ nodeArgs.push(args[i]);
78
+ break;
79
+ }
80
+ }
81
+ if (!matched)
82
+ vitestArgs.push(args[i]);
83
+ }
84
+ const child = execa("node", [...nodeArgs, fileURLToPath(ENTRY), ...vitestArgs], {
85
+ reject: false,
86
+ stderr: "pipe",
87
+ stdout: "inherit",
88
+ stdin: "inherit"
89
+ });
90
+ (_a = child.stderr) == null ? void 0 : _a.pipe(process.stderr);
91
+ const { stderr = "" } = await child;
92
+ for (const error of ERRORS) {
93
+ if (stderr.includes(error.trigger)) {
94
+ if (process.env.GITHUB_ACTIONS)
95
+ console.log(`::warning:: Segmentfault Error Detected: ${error.trigger}
96
+ Refer to ${error.url}`);
97
+ const RED_BLOCK = picocolors.exports.inverse(picocolors.exports.red(" "));
98
+ console.log(`
99
+ ${picocolors.exports.inverse(picocolors.exports.bold(picocolors.exports.red(" Segmentfault Error Detected ")))}
100
+ ${RED_BLOCK} ${picocolors.exports.red(error.trigger)}
101
+ ${RED_BLOCK} ${picocolors.exports.red(`Refer to ${error.url}`)}
102
+ `);
103
+ return;
104
+ }
105
+ }
106
+ process.exit(child.exitCode);
107
+ }
package/dist/cli.mjs CHANGED
@@ -1,32 +1,34 @@
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 './vendor-picocolors.807856aa.mjs';
3
+ import { v as version, s as startVitest, d as divider } from './chunk-vite-node-externalize.3a38c8af.mjs';
5
4
  import 'tty';
5
+ import './chunk-mock-date.debe9954.mjs';
6
+ import 'path';
6
7
  import 'local-pkg';
7
- import './chunk-defaults.02abff90.mjs';
8
- import 'fs';
9
- import 'module';
10
- import 'url';
8
+ import './chunk-integrations-coverage.d205bd87.mjs';
11
9
  import 'vite';
10
+ import 'url';
12
11
  import 'process';
13
- import './chunk-constants.26dc9f85.mjs';
12
+ import 'fs';
13
+ import './chunk-constants.d3f8437b.mjs';
14
14
  import 'os';
15
15
  import 'util';
16
16
  import 'stream';
17
17
  import './vendor-_commonjsHelpers.4da45ef5.mjs';
18
- import './chunk-vite-node-client.fdd9592c.mjs';
18
+ import './chunk-vite-node-client.d1ead698.mjs';
19
+ import 'module';
19
20
  import 'vm';
20
- import './chunk-vite-node-utils.f34df9d3.mjs';
21
+ import './chunk-vite-node-utils.d8e5ff7b.mjs';
21
22
  import 'assert';
22
23
  import 'debug';
23
24
  import 'worker_threads';
24
25
  import 'tinypool';
25
26
  import 'perf_hooks';
26
- import './chunk-utils-source-map.94107ee8.mjs';
27
+ import './chunk-utils-source-map.2a082ffd.mjs';
27
28
  import './chunk-utils-timers.b48455ed.mjs';
28
29
  import 'crypto';
29
- import './vendor-index.61438b77.mjs';
30
+ import './vendor-index.9d9196cc.mjs';
31
+ import './vendor-index.29636037.mjs';
30
32
  import './chunk-magic-string.efe26975.mjs';
31
33
  import 'readline';
32
34
  import './vendor-index.ae96af6e.mjs';
@@ -645,7 +647,7 @@ class CAC extends EventEmitter {
645
647
  const cac = (name = "") => new CAC(name);
646
648
 
647
649
  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();
650
+ 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
651
  cli.command("run [...filters]").action(run);
650
652
  cli.command("related [...filters]").action(runRelated);
651
653
  cli.command("watch [...filters]").action(start);
package/dist/config.cjs CHANGED
@@ -19,6 +19,7 @@ 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,
@@ -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,11 @@
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, a8 as ResolvedCoverageOptions, F as FakeTimerInstallOpts } from './global-74489cc9.js';
4
+ import 'worker_threads';
4
5
  import 'fs';
5
6
 
7
+ declare const defaultInclude: string[];
8
+ declare const defaultExclude: string[];
6
9
  declare const config: {
7
10
  allowOnly: boolean;
8
11
  watch: boolean;
@@ -30,7 +33,7 @@ declare const config: {
30
33
  css: {
31
34
  include: RegExp[];
32
35
  };
33
- coverage: ResolvedC8Options;
36
+ coverage: ResolvedCoverageOptions;
34
37
  fakeTimers: FakeTimerInstallOpts;
35
38
  maxConcurrency: number;
36
39
  dangerouslyIgnoreUnhandledErrors: boolean;
@@ -45,4 +48,4 @@ declare type UserConfigFn = (env: ConfigEnv) => UserConfig | Promise<UserConfig>
45
48
  declare type UserConfigExport = UserConfig | Promise<UserConfig> | UserConfigFn;
46
49
  declare function defineConfig(config: UserConfigExport): UserConfigExport;
47
50
 
48
- export { UserConfig, UserConfigExport, UserConfigFn, configDefaults, defineConfig };
51
+ export { UserConfig, UserConfigExport, UserConfigFn, configDefaults, defaultExclude, defaultInclude, defineConfig };
package/dist/config.mjs CHANGED
@@ -15,6 +15,7 @@ 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,
@@ -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,20 @@
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';
2
+ import { a as resetModules } from './chunk-mock-date.debe9954.mjs';
3
+ import { b as envs } from './chunk-integrations-coverage.d205bd87.mjs';
4
+ import { a as setupGlobalEnv, s as startTests, w as withEnv } from './chunk-runtime-error.975bd80a.mjs';
5
5
  import { g as getWorkerState } from './chunk-utils-global.fa20c2f6.mjs';
6
6
  import 'path';
7
+ import './vendor-picocolors.807856aa.mjs';
7
8
  import 'tty';
8
9
  import 'local-pkg';
9
- import 'module';
10
- import 'url';
11
- import './chunk-runtime-hooks.453f8858.mjs';
12
- import './chunk-runtime-chain.98d42d89.mjs';
10
+ import './chunk-runtime-hooks.4789e99d.mjs';
11
+ import './chunk-runtime-chain.6e363ba2.mjs';
13
12
  import 'util';
14
13
  import 'chai';
15
14
  import './vendor-_commonjsHelpers.4da45ef5.mjs';
16
- import './chunk-runtime-rpc.b50ab560.mjs';
15
+ import './chunk-runtime-rpc.29488183.mjs';
17
16
  import './chunk-utils-timers.b48455ed.mjs';
18
- import './chunk-utils-source-map.94107ee8.mjs';
17
+ import './chunk-utils-source-map.2a082ffd.mjs';
19
18
  import './spy.mjs';
20
19
  import 'tinyspy';
21
20