vitest 0.20.3 → 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 (44) hide show
  1. package/LICENSE.md +61 -4
  2. package/dist/browser.d.ts +8 -1902
  3. package/dist/browser.mjs +8 -9
  4. package/dist/{chunk-api-setup.9bff74bb.mjs → chunk-api-setup.ecd02c18.mjs} +8 -7
  5. package/dist/{chunk-constants.16825f0c.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.6698a2d3.mjs → chunk-integrations-coverage.d205bd87.mjs} +23 -152
  8. package/dist/{chunk-integrations-globals.c5b78414.mjs → chunk-integrations-globals.e81d2091.mjs} +7 -6
  9. package/dist/{chunk-mock-date.9160e13b.mjs → chunk-mock-date.debe9954.mjs} +16 -74
  10. package/dist/chunk-node-git.71b74da4.mjs +80 -0
  11. package/dist/{chunk-runtime-chain.b6c2cdbc.mjs → chunk-runtime-chain.6e363ba2.mjs} +31 -21
  12. package/dist/{chunk-runtime-error.034e03ba.mjs → chunk-runtime-error.975bd80a.mjs} +14 -12
  13. package/dist/{chunk-runtime-hooks.a8401528.mjs → chunk-runtime-hooks.4789e99d.mjs} +3 -3
  14. package/dist/{chunk-runtime-mocker.653847b2.mjs → chunk-runtime-mocker.c91d29ce.mjs} +34 -12
  15. package/dist/{chunk-runtime-rpc.dbf0b31d.mjs → chunk-runtime-rpc.29488183.mjs} +1 -1
  16. package/dist/{chunk-utils-source-map.8198ebd9.mjs → chunk-utils-source-map.2a082ffd.mjs} +2 -1
  17. package/dist/{chunk-vite-node-client.115caed2.mjs → chunk-vite-node-client.d1ead698.mjs} +7 -3
  18. package/dist/{chunk-vite-node-debug.c5887932.mjs → chunk-vite-node-debug.ff1d2a9f.mjs} +3 -2
  19. package/dist/{chunk-vite-node-externalize.91ae6e85.mjs → chunk-vite-node-externalize.3a38c8af.mjs} +167 -39
  20. package/dist/chunk-vite-node-utils.d8e5ff7b.mjs +6921 -0
  21. package/dist/cli-wrapper.mjs +107 -0
  22. package/dist/cli.mjs +16 -14
  23. package/dist/config.cjs +3 -0
  24. package/dist/config.d.ts +7 -69
  25. package/dist/config.mjs +2 -1
  26. package/dist/entry.mjs +8 -9
  27. package/dist/global-74489cc9.d.ts +2098 -0
  28. package/dist/index-9eded9ec.d.ts +116 -0
  29. package/dist/index.d.ts +9 -1928
  30. package/dist/index.mjs +6 -5
  31. package/dist/loader.mjs +74 -17
  32. package/dist/node.d.ts +7 -1682
  33. package/dist/node.mjs +15 -13
  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/{vendor-index.de788b6a.mjs → vendor-index.ae96af6e.mjs} +14 -14
  39. package/dist/{chunk-node-git.43dbdd42.mjs → vendor-index.fbec8a81.mjs} +5 -73
  40. package/dist/vendor-picocolors.807856aa.mjs +64 -0
  41. package/dist/worker.mjs +7 -6
  42. package/package.json +8 -12
  43. package/vitest.mjs +1 -1
  44. package/dist/chunk-vite-node-utils.7e46948f.mjs +0 -1114
@@ -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,35 +1,37 @@
1
1
  import { EventEmitter } from 'events';
2
- import { p as picocolors } from './chunk-mock-date.9160e13b.mjs';
3
- import { v as version, s as startVitest, d as divider } from './chunk-vite-node-externalize.91ae6e85.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.6698a2d3.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.16825f0c.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.115caed2.mjs';
18
+ import './chunk-vite-node-client.d1ead698.mjs';
19
+ import 'module';
19
20
  import 'vm';
20
- import './chunk-vite-node-utils.7e46948f.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.8198ebd9.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
- import './vendor-index.de788b6a.mjs';
34
+ import './vendor-index.ae96af6e.mjs';
33
35
 
34
36
  function toArr(any) {
35
37
  return any == null ? [] : Array.isArray(any) ? any : [any];
@@ -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,73 +1,11 @@
1
1
  import { UserConfig as UserConfig$2, ConfigEnv } from 'vite';
2
2
  export { ConfigEnv } from 'vite';
3
- import { UserConfig as UserConfig$1, ResolvedC8Options } from 'vitest';
4
-
5
- // Type definitions for @sinonjs/fake-timers 8.1
6
- // Project: https://github.com/sinonjs/fake-timers
7
- // Definitions by: Wim Looman <https://github.com/Nemo157>
8
- // Rogier Schouten <https://github.com/rogierschouten>
9
- // Yishai Zehavi <https://github.com/zyishai>
10
- // Remco Haszing <https://github.com/remcohaszing>
11
- // Jaden Simon <https://github.com/JadenSimon>
12
- // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
13
- // TypeScript Version: 2.3
14
-
15
- /**
16
- * Names of clock methods that may be faked by install.
17
- */
18
- type FakeMethod =
19
- | 'setTimeout'
20
- | 'clearTimeout'
21
- | 'setImmediate'
22
- | 'clearImmediate'
23
- | 'setInterval'
24
- | 'clearInterval'
25
- | 'Date'
26
- | 'nextTick'
27
- | 'hrtime'
28
- | 'requestAnimationFrame'
29
- | 'cancelAnimationFrame'
30
- | 'requestIdleCallback'
31
- | 'cancelIdleCallback'
32
- | 'performance'
33
- | 'queueMicrotask';
34
-
35
- interface FakeTimerInstallOpts {
36
- /**
37
- * Installs fake timers with the specified unix epoch (default: 0)
38
- */
39
- now?: number | Date | undefined;
40
-
41
- /**
42
- * An array with names of global methods and APIs to fake. By default, `@sinonjs/fake-timers` does not replace `nextTick()` and `queueMicrotask()`.
43
- * For instance, `FakeTimers.install({ toFake: ['setTimeout', 'nextTick'] })` will fake only `setTimeout()` and `nextTick()`
44
- */
45
- toFake?: FakeMethod[] | undefined;
46
-
47
- /**
48
- * The maximum number of timers that will be run when calling runAll() (default: 1000)
49
- */
50
- loopLimit?: number | undefined;
51
-
52
- /**
53
- * Tells @sinonjs/fake-timers to increment mocked time automatically based on the real system time shift (e.g. the mocked time will be incremented by
54
- * 20ms for every 20ms change in the real system time) (default: false)
55
- */
56
- shouldAdvanceTime?: boolean | undefined;
57
-
58
- /**
59
- * Relevant only when using with shouldAdvanceTime: true. increment mocked time by advanceTimeDelta ms every advanceTimeDelta ms change
60
- * in the real system time (default: 20)
61
- */
62
- advanceTimeDelta?: number | undefined;
63
-
64
- /**
65
- * Tells FakeTimers to clear 'native' (i.e. not fake) timers by delegating to their respective handlers. These are not cleared by
66
- * default, leading to potentially unexpected behavior if timers existed prior to installing FakeTimers. (default: false)
67
- */
68
- shouldClearNativeTimers?: boolean | undefined;
69
- }
3
+ import { U as UserConfig$1, a8 as ResolvedCoverageOptions, F as FakeTimerInstallOpts } from './global-74489cc9.js';
4
+ import 'worker_threads';
5
+ import 'fs';
70
6
 
7
+ declare const defaultInclude: string[];
8
+ declare const defaultExclude: string[];
71
9
  declare const config: {
72
10
  allowOnly: boolean;
73
11
  watch: boolean;
@@ -95,7 +33,7 @@ declare const config: {
95
33
  css: {
96
34
  include: RegExp[];
97
35
  };
98
- coverage: ResolvedC8Options;
36
+ coverage: ResolvedCoverageOptions;
99
37
  fakeTimers: FakeTimerInstallOpts;
100
38
  maxConcurrency: number;
101
39
  dangerouslyIgnoreUnhandledErrors: boolean;
@@ -110,4 +48,4 @@ declare type UserConfigFn = (env: ConfigEnv) => UserConfig | Promise<UserConfig>
110
48
  declare type UserConfigExport = UserConfig | Promise<UserConfig> | UserConfigFn;
111
49
  declare function defineConfig(config: UserConfigExport): UserConfigExport;
112
50
 
113
- 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.9160e13b.mjs';
3
- import { f as envs } from './chunk-defaults.6698a2d3.mjs';
4
- import { a as setupGlobalEnv, s as startTests, w as withEnv } from './chunk-runtime-error.034e03ba.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.a8401528.mjs';
12
- import './chunk-runtime-chain.b6c2cdbc.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.dbf0b31d.mjs';
15
+ import './chunk-runtime-rpc.29488183.mjs';
17
16
  import './chunk-utils-timers.b48455ed.mjs';
18
- import './chunk-utils-source-map.8198ebd9.mjs';
17
+ import './chunk-utils-source-map.2a082ffd.mjs';
19
18
  import './spy.mjs';
20
19
  import 'tinyspy';
21
20