vitest 4.0.7 → 4.0.8
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.
- package/LICENSE.md +1 -1
- package/dist/browser.d.ts +2 -2
- package/dist/browser.js +2 -2
- package/dist/chunks/{base.D3GxgUMI.js → base.BgTO2qAg.js} +71 -36
- package/dist/chunks/{benchmark.DHKMYAts.js → benchmark.B3N2zMcH.js} +9 -4
- package/dist/chunks/{browser.d.-LKfRopd.d.ts → browser.d.DTTM2PTh.d.ts} +1 -1
- package/dist/chunks/{cac.G9DAn-c7.js → cac.CfkWq8Qy.js} +115 -42
- package/dist/chunks/{cli-api.Csks4as1.js → cli-api.BQ-bjcRi.js} +1857 -839
- package/dist/chunks/console.Cf-YriPC.js +146 -0
- package/dist/chunks/{coverage.C2LA1DSL.js → coverage.NVjCOln1.js} +273 -103
- package/dist/chunks/{creator.cqqifzG7.js → creator.fzVyoMf3.js} +74 -30
- package/dist/chunks/{date.-jtEtIeV.js → date.Bq6ZW5rf.js} +17 -6
- package/dist/chunks/{git.BFNcloKD.js → git.Bm2pzPAa.js} +3 -3
- package/dist/chunks/{global.d.DxtanrNO.d.ts → global.d.DVdCfKp5.d.ts} +1 -1
- package/dist/chunks/{globals.BGT_RUsD.js → globals.DOh96BiR.js} +5 -5
- package/dist/chunks/{index.DEPqWSIZ.js → index.BY4-tcno.js} +33 -16
- package/dist/chunks/{index.Bgo3tNWt.js → index.DAL392Ss.js} +40 -15
- package/dist/chunks/{index.RwjEGCQ0.js → index.DIFZf73e.js} +2 -2
- package/dist/chunks/{index.CWIFvlX5.js → index.DfKyPFVi.js} +159 -54
- package/dist/chunks/{index.CVpyv-Zg.js → index.kotH7DY7.js} +832 -373
- package/dist/chunks/{index.jMQYiEWE.js → index.op2Re5rn.js} +22 -12
- package/dist/chunks/{init-forks.IU-xQ2_X.js → init-forks.2hx7cf78.js} +14 -4
- package/dist/chunks/{init-threads.C_NWvZkU.js → init-threads.Cm4OCIWA.js} +1 -1
- package/dist/chunks/{init.fmH9J833.js → init.DMDG-idf.js} +53 -30
- package/dist/chunks/{inspector.DLZxSeU3.js → inspector.CvyFGlXm.js} +25 -10
- package/dist/chunks/{moduleRunner.d.DEkTotCv.d.ts → moduleRunner.d.CzOZ_4wC.d.ts} +1 -1
- package/dist/chunks/{node.BwAWWjHZ.js → node.Ce0vMQM7.js} +1 -1
- package/dist/chunks/{plugin.d.Cpes8Bt6.d.ts → plugin.d.D4RrtywJ.d.ts} +1 -1
- package/dist/chunks/{reporters.d.CSNcMDxF.d.ts → reporters.d.Da1D1VbQ.d.ts} +6 -5
- package/dist/chunks/{rpc.D38ahn14.js → rpc.BUV7uWKJ.js} +20 -7
- package/dist/chunks/{setup-common.DR1sucx6.js → setup-common.LGjNSzXp.js} +20 -8
- package/dist/chunks/{startModuleRunner.Cn7hCL7D.js → startModuleRunner.BOmUtLIO.js} +206 -83
- package/dist/chunks/{test.B6aJd6T3.js → test.ClrAtjMv.js} +48 -22
- package/dist/chunks/{utils.CG9h5ccR.js → utils.DvEY5TfP.js} +14 -5
- package/dist/chunks/{vi.BZvkKVkM.js → vi.Bgcdy3bQ.js} +261 -111
- package/dist/chunks/{vm.BL7_zzOr.js → vm.BIkCDs68.js} +177 -71
- package/dist/chunks/{worker.d.D25zYZ7N.d.ts → worker.d.DadbA89M.d.ts} +30 -2
- package/dist/cli.js +2 -2
- package/dist/config.d.ts +5 -5
- package/dist/coverage.d.ts +3 -3
- package/dist/coverage.js +1 -1
- package/dist/environments.js +1 -1
- package/dist/index.d.ts +5 -5
- package/dist/index.js +5 -5
- package/dist/module-evaluator.d.ts +2 -2
- package/dist/module-evaluator.js +85 -35
- package/dist/module-runner.js +2 -2
- package/dist/node.d.ts +7 -7
- package/dist/node.js +16 -12
- package/dist/reporters.d.ts +3 -3
- package/dist/reporters.js +2 -2
- package/dist/runners.js +7 -7
- package/dist/snapshot.js +2 -2
- package/dist/suite.js +2 -2
- package/dist/worker.d.ts +1 -1
- package/dist/worker.js +15 -15
- package/dist/workers/forks.js +16 -16
- package/dist/workers/runVmTests.js +41 -22
- package/dist/workers/threads.js +16 -16
- package/dist/workers/vmForks.js +11 -11
- package/dist/workers/vmThreads.js +11 -11
- package/package.json +20 -20
- package/dist/chunks/console.CTJL2nuH.js +0 -115
package/LICENSE.md
CHANGED
package/dist/browser.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { a as SerializedCoverageConfig, S as SerializedConfig } from './chunks/config.d.BTfZNUu9.js';
|
|
2
2
|
import { R as RuntimeCoverageModuleLoader } from './chunks/coverage.d.BZtK59WP.js';
|
|
3
3
|
import { SerializedDiffOptions } from '@vitest/utils/diff';
|
|
4
|
-
import { V as VitestModuleRunner } from './chunks/moduleRunner.d.
|
|
4
|
+
import { V as VitestModuleRunner } from './chunks/moduleRunner.d.CzOZ_4wC.js';
|
|
5
5
|
export { collectTests, startTests } from '@vitest/runner';
|
|
6
6
|
import * as _vitest_spy from '@vitest/spy';
|
|
7
7
|
export { _vitest_spy as SpyModule };
|
|
@@ -15,7 +15,7 @@ import '@vitest/pretty-format';
|
|
|
15
15
|
import '@vitest/snapshot';
|
|
16
16
|
import 'node:vm';
|
|
17
17
|
import 'vite/module-runner';
|
|
18
|
-
import './chunks/worker.d.
|
|
18
|
+
import './chunks/worker.d.DadbA89M.js';
|
|
19
19
|
import './chunks/environment.d.CrsxCzP1.js';
|
|
20
20
|
import '@vitest/mocker';
|
|
21
21
|
import './chunks/mocker.d.BE_2ls6u.js';
|
package/dist/browser.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { l as loadDiffConfig, b as loadSnapshotSerializers, c as setupCommonEnv, s as startCoverageInsideWorker, a as stopCoverageInsideWorker, t as takeCoverageInsideWorker } from './chunks/setup-common.
|
|
1
|
+
export { l as loadDiffConfig, b as loadSnapshotSerializers, c as setupCommonEnv, s as startCoverageInsideWorker, a as stopCoverageInsideWorker, t as takeCoverageInsideWorker } from './chunks/setup-common.LGjNSzXp.js';
|
|
2
2
|
export { collectTests, startTests } from '@vitest/runner';
|
|
3
3
|
import * as spyModule from '@vitest/spy';
|
|
4
4
|
export { spyModule as SpyModule };
|
|
@@ -9,7 +9,7 @@ export { DecodedMap, getOriginalPosition } from '@vitest/utils/source-map';
|
|
|
9
9
|
export { getSafeTimers, setSafeTimers } from '@vitest/utils/timers';
|
|
10
10
|
import './chunks/coverage.D_JHT54q.js';
|
|
11
11
|
import '@vitest/snapshot';
|
|
12
|
-
import './chunks/utils.
|
|
12
|
+
import './chunks/utils.DvEY5TfP.js';
|
|
13
13
|
|
|
14
14
|
/**
|
|
15
15
|
* @internal
|
|
@@ -1,41 +1,53 @@
|
|
|
1
1
|
import { runInThisContext } from 'node:vm';
|
|
2
2
|
import * as spyModule from '@vitest/spy';
|
|
3
|
-
import { r as resolveTestRunner, a as resolveSnapshotEnvironment, s as setupChaiConfig } from './index.
|
|
4
|
-
import { l as loadEnvironment } from './init.
|
|
3
|
+
import { r as resolveTestRunner, a as resolveSnapshotEnvironment, s as setupChaiConfig } from './index.BY4-tcno.js';
|
|
4
|
+
import { l as loadEnvironment } from './init.DMDG-idf.js';
|
|
5
5
|
import { V as VitestEvaluatedModules } from './evaluatedModules.Dg1zASAC.js';
|
|
6
|
-
import { s as startVitestModuleRunner, c as createNodeImportMeta } from './startModuleRunner.
|
|
6
|
+
import { s as startVitestModuleRunner, c as createNodeImportMeta } from './startModuleRunner.BOmUtLIO.js';
|
|
7
7
|
import { performance as performance$1 } from 'node:perf_hooks';
|
|
8
8
|
import { startTests, collectTests } from '@vitest/runner';
|
|
9
|
-
import { c as setupCommonEnv, s as startCoverageInsideWorker, a as stopCoverageInsideWorker } from './setup-common.
|
|
10
|
-
import { g as globalExpect, v as vi } from './vi.
|
|
11
|
-
import { c as closeInspector } from './inspector.
|
|
9
|
+
import { c as setupCommonEnv, s as startCoverageInsideWorker, a as stopCoverageInsideWorker } from './setup-common.LGjNSzXp.js';
|
|
10
|
+
import { g as globalExpect, v as vi } from './vi.Bgcdy3bQ.js';
|
|
11
|
+
import { c as closeInspector } from './inspector.CvyFGlXm.js';
|
|
12
12
|
import { createRequire } from 'node:module';
|
|
13
13
|
import timers from 'node:timers';
|
|
14
14
|
import timersPromises from 'node:timers/promises';
|
|
15
15
|
import util from 'node:util';
|
|
16
16
|
import { KNOWN_ASSET_TYPES } from '@vitest/utils/constants';
|
|
17
|
-
import { i as index } from './index.
|
|
18
|
-
import { g as getWorkerState, r as resetModules, p as provideWorkerState } from './utils.
|
|
17
|
+
import { i as index } from './index.DIFZf73e.js';
|
|
18
|
+
import { g as getWorkerState, r as resetModules, p as provideWorkerState } from './utils.DvEY5TfP.js';
|
|
19
19
|
|
|
20
20
|
// this should only be used in Node
|
|
21
21
|
let globalSetup = false;
|
|
22
22
|
async function setupGlobalEnv(config, environment) {
|
|
23
|
-
|
|
23
|
+
await setupCommonEnv(config);
|
|
24
|
+
Object.defineProperty(globalThis, "__vitest_index__", {
|
|
24
25
|
value: index,
|
|
25
26
|
enumerable: false
|
|
26
|
-
})
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
27
|
+
});
|
|
28
|
+
globalExpect.setState({ environment: environment.name });
|
|
29
|
+
if (globalSetup) return;
|
|
30
|
+
globalSetup = true;
|
|
31
|
+
if ((environment.viteEnvironment || environment.name) === "client") {
|
|
32
|
+
const _require = createRequire(import.meta.url);
|
|
33
|
+
// always mock "required" `css` files, because we cannot process them
|
|
34
|
+
_require.extensions[".css"] = resolveCss;
|
|
35
|
+
_require.extensions[".scss"] = resolveCss;
|
|
36
|
+
_require.extensions[".sass"] = resolveCss;
|
|
37
|
+
_require.extensions[".less"] = resolveCss;
|
|
38
|
+
// since we are using Vite, we can assume how these will be resolved
|
|
39
|
+
KNOWN_ASSET_TYPES.forEach((type) => {
|
|
40
|
+
_require.extensions[`.${type}`] = resolveAsset;
|
|
41
|
+
});
|
|
42
|
+
process.env.SSR = "";
|
|
43
|
+
} else process.env.SSR = "1";
|
|
44
|
+
// @ts-expect-error not typed global for patched timers
|
|
45
|
+
globalThis.__vitest_required__ = {
|
|
46
|
+
util,
|
|
47
|
+
timers,
|
|
48
|
+
timersPromises
|
|
49
|
+
};
|
|
50
|
+
if (!config.disableConsoleIntercept) await setupConsoleLogSpy();
|
|
39
51
|
}
|
|
40
52
|
function resolveCss(mod) {
|
|
41
53
|
mod.exports = "";
|
|
@@ -44,13 +56,14 @@ function resolveAsset(mod, url) {
|
|
|
44
56
|
mod.exports = url;
|
|
45
57
|
}
|
|
46
58
|
async function setupConsoleLogSpy() {
|
|
47
|
-
const { createCustomConsole } = await import('./console.
|
|
59
|
+
const { createCustomConsole } = await import('./console.Cf-YriPC.js');
|
|
48
60
|
globalThis.console = createCustomConsole();
|
|
49
61
|
}
|
|
50
62
|
|
|
51
63
|
// browser shouldn't call this!
|
|
52
64
|
async function run(method, files, config, moduleRunner, environment) {
|
|
53
|
-
const workerState = getWorkerState()
|
|
65
|
+
const workerState = getWorkerState();
|
|
66
|
+
const [testRunner] = await Promise.all([
|
|
54
67
|
resolveTestRunner(config, moduleRunner),
|
|
55
68
|
setupGlobalEnv(config, environment),
|
|
56
69
|
startCoverageInsideWorker(config.coverage, moduleRunner, { isolate: config.isolate }),
|
|
@@ -59,37 +72,59 @@ async function run(method, files, config, moduleRunner, environment) {
|
|
|
59
72
|
})()
|
|
60
73
|
]);
|
|
61
74
|
workerState.onCancel((reason) => {
|
|
62
|
-
closeInspector(config)
|
|
63
|
-
|
|
75
|
+
closeInspector(config);
|
|
76
|
+
testRunner.cancel?.(reason);
|
|
77
|
+
});
|
|
78
|
+
workerState.durations.prepare = performance$1.now() - workerState.durations.prepare;
|
|
64
79
|
for (const file of files) {
|
|
65
|
-
if (config.isolate)
|
|
66
|
-
|
|
80
|
+
if (config.isolate) {
|
|
81
|
+
moduleRunner.mocker.reset();
|
|
82
|
+
resetModules(workerState.evaluatedModules, true);
|
|
83
|
+
}
|
|
84
|
+
workerState.filepath = file.filepath;
|
|
85
|
+
if (method === "run") await startTests([file], testRunner);
|
|
67
86
|
else await collectTests([file], testRunner);
|
|
87
|
+
// reset after tests, because user might call `vi.setConfig` in setupFile
|
|
88
|
+
vi.resetConfig();
|
|
68
89
|
// mocks should not affect different files
|
|
69
|
-
vi.
|
|
90
|
+
vi.restoreAllMocks();
|
|
70
91
|
}
|
|
71
92
|
await stopCoverageInsideWorker(config.coverage, moduleRunner, { isolate: config.isolate });
|
|
72
93
|
}
|
|
73
94
|
|
|
74
95
|
let _moduleRunner;
|
|
75
|
-
const evaluatedModules = new VitestEvaluatedModules()
|
|
96
|
+
const evaluatedModules = new VitestEvaluatedModules();
|
|
97
|
+
const moduleExecutionInfo = /* @__PURE__ */ new Map();
|
|
76
98
|
function startModuleRunner(options) {
|
|
77
|
-
|
|
99
|
+
if (_moduleRunner) return _moduleRunner;
|
|
100
|
+
_moduleRunner = startVitestModuleRunner(options);
|
|
101
|
+
return _moduleRunner;
|
|
78
102
|
}
|
|
79
|
-
let _currentEnvironment
|
|
103
|
+
let _currentEnvironment;
|
|
104
|
+
let _environmentTime;
|
|
80
105
|
async function setupEnvironment(context) {
|
|
81
|
-
const startTime = performance.now()
|
|
106
|
+
const startTime = performance.now();
|
|
107
|
+
const { environment: { name: environmentName, options: environmentOptions }, rpc, config } = context;
|
|
108
|
+
const { environment, loader } = await loadEnvironment(environmentName, config.root, rpc);
|
|
82
109
|
_currentEnvironment = environment;
|
|
83
110
|
const env = await environment.setup(globalThis, environmentOptions || config.environmentOptions || {});
|
|
84
|
-
|
|
111
|
+
_environmentTime = performance.now() - startTime;
|
|
112
|
+
if (config.chaiConfig) setupChaiConfig(config.chaiConfig);
|
|
85
113
|
return async () => {
|
|
86
|
-
await env.teardown(globalThis)
|
|
114
|
+
await env.teardown(globalThis);
|
|
115
|
+
await loader?.close();
|
|
87
116
|
};
|
|
88
117
|
}
|
|
89
118
|
/** @experimental */
|
|
90
119
|
async function runBaseTests(method, state) {
|
|
91
120
|
const { ctx } = state;
|
|
92
|
-
|
|
121
|
+
state.environment = _currentEnvironment;
|
|
122
|
+
state.durations.environment = _environmentTime;
|
|
123
|
+
// state has new context, but we want to reuse existing ones
|
|
124
|
+
state.evaluatedModules = evaluatedModules;
|
|
125
|
+
state.moduleExecutionInfo = moduleExecutionInfo;
|
|
126
|
+
provideWorkerState(globalThis, state);
|
|
127
|
+
if (ctx.invalidates) ctx.invalidates.forEach((filepath) => {
|
|
93
128
|
(state.evaluatedModules.fileToModulesMap.get(filepath) || []).forEach((module) => {
|
|
94
129
|
state.evaluatedModules.invalidateModule(module);
|
|
95
130
|
});
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { getCurrentSuite } from '@vitest/runner';
|
|
2
2
|
import { createChainable } from '@vitest/runner/utils';
|
|
3
3
|
import { noop } from '@vitest/utils/helpers';
|
|
4
|
-
import { g as getWorkerState } from './utils.
|
|
4
|
+
import { g as getWorkerState } from './utils.DvEY5TfP.js';
|
|
5
5
|
|
|
6
|
-
const benchFns = /* @__PURE__ */ new WeakMap()
|
|
6
|
+
const benchFns = /* @__PURE__ */ new WeakMap();
|
|
7
|
+
const benchOptsMap = /* @__PURE__ */ new WeakMap();
|
|
7
8
|
function getBenchOptions(key) {
|
|
8
9
|
return benchOptsMap.get(key);
|
|
9
10
|
}
|
|
@@ -16,9 +17,11 @@ const bench = createBenchmark(function(name, fn = noop, options = {}) {
|
|
|
16
17
|
...this,
|
|
17
18
|
meta: { benchmark: true }
|
|
18
19
|
});
|
|
20
|
+
benchFns.set(task, fn);
|
|
21
|
+
benchOptsMap.set(task, options);
|
|
19
22
|
// vitest runner sets mode to `todo` if handler is not passed down
|
|
20
23
|
// but we store handler separetly
|
|
21
|
-
if (
|
|
24
|
+
if (!this.todo && task.mode === "todo") task.mode = "run";
|
|
22
25
|
});
|
|
23
26
|
function createBenchmark(fn) {
|
|
24
27
|
const benchmark = createChainable([
|
|
@@ -26,7 +29,9 @@ function createBenchmark(fn) {
|
|
|
26
29
|
"only",
|
|
27
30
|
"todo"
|
|
28
31
|
], fn);
|
|
29
|
-
|
|
32
|
+
benchmark.skipIf = (condition) => condition ? benchmark.skip : benchmark;
|
|
33
|
+
benchmark.runIf = (condition) => condition ? benchmark : benchmark.skip;
|
|
34
|
+
return benchmark;
|
|
30
35
|
}
|
|
31
36
|
function formatName(name) {
|
|
32
37
|
return typeof name === "string" ? name : typeof name === "function" ? name.name || "<anonymous>" : String(name);
|
|
@@ -3,7 +3,7 @@ import { EventEmitter } from 'events';
|
|
|
3
3
|
import { normalize } from 'pathe';
|
|
4
4
|
import c from 'tinyrainbow';
|
|
5
5
|
import { a as defaultPort, d as defaultBrowserPort } from './constants.D_Q9UYh-.js';
|
|
6
|
-
import { R as ReportersMap } from './index.
|
|
6
|
+
import { R as ReportersMap } from './index.kotH7DY7.js';
|
|
7
7
|
|
|
8
8
|
function toArr(any) {
|
|
9
9
|
return any == null ? [] : Array.isArray(any) ? any : [any];
|
|
@@ -619,7 +619,7 @@ class CAC extends EventEmitter {
|
|
|
619
619
|
|
|
620
620
|
const cac = (name = "") => new CAC(name);
|
|
621
621
|
|
|
622
|
-
var version = "4.0.
|
|
622
|
+
var version = "4.0.8";
|
|
623
623
|
|
|
624
624
|
const apiConfig = (port) => ({
|
|
625
625
|
port: {
|
|
@@ -634,10 +634,12 @@ const apiConfig = (port) => ({
|
|
|
634
634
|
middlewareMode: null
|
|
635
635
|
});
|
|
636
636
|
function watermarkTransform(value) {
|
|
637
|
-
|
|
637
|
+
if (typeof value === "string") return value.split(",").map(Number);
|
|
638
|
+
return value;
|
|
638
639
|
}
|
|
639
640
|
function transformNestedBoolean(value) {
|
|
640
|
-
|
|
641
|
+
if (typeof value === "boolean") return { enabled: value };
|
|
642
|
+
return value;
|
|
641
643
|
}
|
|
642
644
|
const cliOptionsConfig = {
|
|
643
645
|
root: {
|
|
@@ -746,7 +748,9 @@ const cliOptionsConfig = {
|
|
|
746
748
|
argument: "<boolean|function>",
|
|
747
749
|
subcommands: null,
|
|
748
750
|
transform(value) {
|
|
749
|
-
|
|
751
|
+
if (value === "true" || value === "yes" || value === true) return true;
|
|
752
|
+
if (value === "false" || value === "no" || value === false) return false;
|
|
753
|
+
return value;
|
|
750
754
|
}
|
|
751
755
|
},
|
|
752
756
|
lines: {
|
|
@@ -821,12 +825,16 @@ const cliOptionsConfig = {
|
|
|
821
825
|
description: "Run tests in the browser. Equivalent to `--browser.enabled` (default: `false`)",
|
|
822
826
|
argument: "<name>",
|
|
823
827
|
transform(browser) {
|
|
824
|
-
|
|
828
|
+
if (typeof browser === "boolean") return { enabled: browser };
|
|
829
|
+
if (browser === "true" || browser === "false") return { enabled: browser === "true" };
|
|
830
|
+
if (browser === "yes" || browser === "no") return { enabled: browser === "yes" };
|
|
831
|
+
if (typeof browser === "string") return { name: browser };
|
|
832
|
+
return browser;
|
|
825
833
|
},
|
|
826
834
|
subcommands: {
|
|
827
835
|
enabled: { description: "Run tests in the browser. Equivalent to `--browser.enabled` (default: `false`)" },
|
|
828
836
|
name: {
|
|
829
|
-
description: "Run all tests in a specific browser. Some browsers are only available for specific providers (see `--browser.provider`).
|
|
837
|
+
description: "Run all tests in a specific browser. Some browsers are only available for specific providers (see `--browser.provider`).",
|
|
830
838
|
argument: "<name>"
|
|
831
839
|
},
|
|
832
840
|
headless: { description: "Run the browser in headless mode (i.e. without opening the GUI (Graphical User Interface)). If you are running Vitest in CI, it will be enabled by default (default: `process.env.CI`)" },
|
|
@@ -836,7 +844,7 @@ const cliOptionsConfig = {
|
|
|
836
844
|
subcommands: apiConfig(defaultBrowserPort)
|
|
837
845
|
},
|
|
838
846
|
provider: {
|
|
839
|
-
description: "Provider used to run browser tests. Some browsers are only available for specific providers. Can be \"webdriverio\", \"playwright\", \"preview\", or the path to a custom provider. Visit [`browser.provider`](https://vitest.dev/
|
|
847
|
+
description: "Provider used to run browser tests. Some browsers are only available for specific providers. Can be \"webdriverio\", \"playwright\", \"preview\", or the path to a custom provider. Visit [`browser.provider`](https://vitest.dev/config/browser/provider) for more information",
|
|
840
848
|
argument: "<name>",
|
|
841
849
|
subcommands: null,
|
|
842
850
|
transform(value) {
|
|
@@ -947,14 +955,18 @@ const cliOptionsConfig = {
|
|
|
947
955
|
description: "Enable Node.js inspector (default: `127.0.0.1:9229`)",
|
|
948
956
|
argument: "[[host:]port]",
|
|
949
957
|
transform(portOrEnabled) {
|
|
950
|
-
|
|
958
|
+
if (portOrEnabled === 0 || portOrEnabled === "true" || portOrEnabled === "yes") return true;
|
|
959
|
+
if (portOrEnabled === "false" || portOrEnabled === "no") return false;
|
|
960
|
+
return portOrEnabled;
|
|
951
961
|
}
|
|
952
962
|
},
|
|
953
963
|
inspectBrk: {
|
|
954
964
|
description: "Enable Node.js inspector and break before the test starts",
|
|
955
965
|
argument: "[[host:]port]",
|
|
956
966
|
transform(portOrEnabled) {
|
|
957
|
-
|
|
967
|
+
if (portOrEnabled === 0 || portOrEnabled === "true" || portOrEnabled === "yes") return true;
|
|
968
|
+
if (portOrEnabled === "false" || portOrEnabled === "no") return false;
|
|
969
|
+
return portOrEnabled;
|
|
958
970
|
}
|
|
959
971
|
},
|
|
960
972
|
inspector: null,
|
|
@@ -1078,7 +1090,8 @@ const cliOptionsConfig = {
|
|
|
1078
1090
|
default: true,
|
|
1079
1091
|
transform(cache) {
|
|
1080
1092
|
if (typeof cache !== "boolean" && cache) throw new Error("--cache.dir is deprecated");
|
|
1081
|
-
|
|
1093
|
+
if (cache) return {};
|
|
1094
|
+
return cache;
|
|
1082
1095
|
}
|
|
1083
1096
|
},
|
|
1084
1097
|
maxConcurrency: {
|
|
@@ -1135,7 +1148,8 @@ const cliOptionsConfig = {
|
|
|
1135
1148
|
description: "Path to a blob reports directory. If this options is used, Vitest won't run any tests, it will only report previously recorded tests",
|
|
1136
1149
|
argument: "[path]",
|
|
1137
1150
|
transform(value) {
|
|
1138
|
-
|
|
1151
|
+
if (!value || typeof value === "boolean") return ".vitest-reports";
|
|
1152
|
+
return value;
|
|
1139
1153
|
}
|
|
1140
1154
|
},
|
|
1141
1155
|
cliExclude: null,
|
|
@@ -1205,7 +1219,11 @@ function addCommand(cli, name, option) {
|
|
|
1205
1219
|
const received = value.map((s) => typeof s === "string" ? `"${s}"` : s).join(", ");
|
|
1206
1220
|
throw new Error(`Expected a single value for option "${command}", received [${received}]`);
|
|
1207
1221
|
}
|
|
1208
|
-
|
|
1222
|
+
value = removeQuotes(value);
|
|
1223
|
+
if (option.transform) return option.transform(value);
|
|
1224
|
+
if (option.array) return toArray(value);
|
|
1225
|
+
if (option.normalize) return normalize(String(value));
|
|
1226
|
+
return value;
|
|
1209
1227
|
}
|
|
1210
1228
|
const hasSubcommands = "subcommands" in option && option.subcommands;
|
|
1211
1229
|
if (option.description) {
|
|
@@ -1223,16 +1241,24 @@ function addCliOptions(cli, options) {
|
|
|
1223
1241
|
}
|
|
1224
1242
|
function createCLI(options = {}) {
|
|
1225
1243
|
const cli = cac("vitest");
|
|
1226
|
-
|
|
1244
|
+
cli.version(version);
|
|
1245
|
+
addCliOptions(cli, cliOptionsConfig);
|
|
1246
|
+
cli.help((info) => {
|
|
1227
1247
|
const helpSection = info.find((current) => current.title?.startsWith("For more info, run any command"));
|
|
1228
1248
|
if (helpSection) helpSection.body += "\n $ vitest --help --expand-help";
|
|
1229
1249
|
const options = info.find((current) => current.title === "Options");
|
|
1230
1250
|
if (typeof options !== "object") return info;
|
|
1231
|
-
const helpIndex = process.argv.findIndex((arg) => arg === "--help")
|
|
1251
|
+
const helpIndex = process.argv.findIndex((arg) => arg === "--help");
|
|
1252
|
+
const subcommands = process.argv.slice(helpIndex + 1);
|
|
1253
|
+
const defaultOutput = options.body.split("\n").filter((line) => /^\s+--\S+\./.test(line) === false).join("\n");
|
|
1232
1254
|
// Filter out options with dot-notation if --help is not called with a subcommand (default behavior)
|
|
1233
|
-
if (subcommands.length === 0)
|
|
1255
|
+
if (subcommands.length === 0) {
|
|
1256
|
+
options.body = defaultOutput;
|
|
1257
|
+
return info;
|
|
1258
|
+
}
|
|
1234
1259
|
if (subcommands.length === 1 && (subcommands[0] === "--expand-help" || subcommands[0] === "--expandHelp")) return info;
|
|
1235
|
-
const subcommandMarker = "$SUB_COMMAND_MARKER$"
|
|
1260
|
+
const subcommandMarker = "$SUB_COMMAND_MARKER$";
|
|
1261
|
+
const banner = info.find((current) => /^vitest\/\d+\.\d+\.\d+$/.test(current.body));
|
|
1236
1262
|
function addBannerWarning(warning) {
|
|
1237
1263
|
if (typeof banner?.body === "string") {
|
|
1238
1264
|
if (banner?.body.includes(warning)) return;
|
|
@@ -1250,67 +1276,111 @@ function createCLI(options = {}) {
|
|
|
1250
1276
|
// Mark the help section for the subcommands
|
|
1251
1277
|
if (subcommand.startsWith("--")) options.body = options.body.split("\n").map((line) => line.trim().startsWith(subcommand) ? `${subcommandMarker}${line}` : line).join("\n");
|
|
1252
1278
|
}
|
|
1253
|
-
|
|
1279
|
+
// Filter based on the marked options to preserve the original sort order
|
|
1280
|
+
options.body = options.body.split("\n").map((line) => line.startsWith(subcommandMarker) ? line.split(subcommandMarker)[1] : "").filter((line) => line.length !== 0).join("\n");
|
|
1281
|
+
if (!options.body) {
|
|
1282
|
+
addBannerWarning("no options were found for your subcommands so we printed the whole output");
|
|
1283
|
+
options.body = defaultOutput;
|
|
1284
|
+
}
|
|
1254
1285
|
return info;
|
|
1255
|
-
})
|
|
1286
|
+
});
|
|
1287
|
+
cli.command("run [...filters]", void 0, options).action(run);
|
|
1288
|
+
cli.command("related [...filters]", void 0, options).action(runRelated);
|
|
1289
|
+
cli.command("watch [...filters]", void 0, options).action(watch);
|
|
1290
|
+
cli.command("dev [...filters]", void 0, options).action(watch);
|
|
1291
|
+
addCliOptions(cli.command("bench [...filters]", void 0, options).action(benchmark), benchCliOptionsConfig);
|
|
1292
|
+
cli.command("init <project>", void 0, options).action(init);
|
|
1293
|
+
addCliOptions(cli.command("list [...filters]", void 0, options).action((filters, options) => collect("test", filters, options)), collectCliOptionsConfig);
|
|
1294
|
+
cli.command("[...filters]", void 0, options).action((filters, options) => start("test", filters, options));
|
|
1295
|
+
return cli;
|
|
1256
1296
|
}
|
|
1257
1297
|
function removeQuotes(str) {
|
|
1258
|
-
|
|
1298
|
+
if (typeof str !== "string") {
|
|
1299
|
+
if (Array.isArray(str)) return str.map(removeQuotes);
|
|
1300
|
+
return str;
|
|
1301
|
+
}
|
|
1302
|
+
if (str[0] === "\"" && str.endsWith("\"")) return str.slice(1, -1);
|
|
1303
|
+
if (str.startsWith(`'`) && str.endsWith(`'`)) return str.slice(1, -1);
|
|
1304
|
+
return str;
|
|
1259
1305
|
}
|
|
1260
1306
|
function splitArgv(argv) {
|
|
1261
|
-
|
|
1262
|
-
|
|
1307
|
+
argv = argv.replace(/(['"])(?:(?!\1).)+\1/g, (match) => match.replace(/\s/g, "\0"));
|
|
1308
|
+
return argv.split(" ").map((arg) => {
|
|
1309
|
+
arg = arg.replace(/\0/g, " ");
|
|
1310
|
+
return removeQuotes(arg);
|
|
1263
1311
|
});
|
|
1264
1312
|
}
|
|
1265
1313
|
function parseCLI(argv, config = {}) {
|
|
1266
1314
|
const arrayArgs = typeof argv === "string" ? splitArgv(argv) : argv;
|
|
1267
1315
|
if (arrayArgs[0] !== "vitest") throw new Error(`Expected "vitest" as the first argument, received "${arrayArgs[0]}"`);
|
|
1268
|
-
arrayArgs[0] = "/index.js"
|
|
1316
|
+
arrayArgs[0] = "/index.js";
|
|
1317
|
+
arrayArgs.unshift("node");
|
|
1269
1318
|
let { args, options } = createCLI(config).parse(arrayArgs, { run: false });
|
|
1270
1319
|
if (arrayArgs[2] === "watch" || arrayArgs[2] === "dev") options.watch = true;
|
|
1271
1320
|
if (arrayArgs[2] === "run" && !options.watch) options.run = true;
|
|
1272
|
-
if (arrayArgs[2] === "related")
|
|
1321
|
+
if (arrayArgs[2] === "related") {
|
|
1322
|
+
options.related = args;
|
|
1323
|
+
options.passWithNoTests ??= true;
|
|
1324
|
+
args = [];
|
|
1325
|
+
}
|
|
1273
1326
|
return {
|
|
1274
1327
|
filter: args,
|
|
1275
1328
|
options
|
|
1276
1329
|
};
|
|
1277
1330
|
}
|
|
1278
1331
|
async function runRelated(relatedFiles, argv) {
|
|
1279
|
-
argv.related = relatedFiles
|
|
1332
|
+
argv.related = relatedFiles;
|
|
1333
|
+
argv.passWithNoTests ??= true;
|
|
1334
|
+
await start("test", [], argv);
|
|
1280
1335
|
}
|
|
1281
1336
|
async function watch(cliFilters, options) {
|
|
1282
|
-
options.watch = true
|
|
1337
|
+
options.watch = true;
|
|
1338
|
+
await start("test", cliFilters, options);
|
|
1283
1339
|
}
|
|
1284
1340
|
async function run(cliFilters, options) {
|
|
1285
|
-
|
|
1341
|
+
// "vitest run --watch" should still be watch mode
|
|
1342
|
+
options.run = !options.watch;
|
|
1343
|
+
await start("test", cliFilters, options);
|
|
1286
1344
|
}
|
|
1287
1345
|
async function benchmark(cliFilters, options) {
|
|
1288
|
-
console.warn(c.yellow("Benchmarking is an experimental feature.\nBreaking changes might not follow SemVer, please pin Vitest's version when using it."))
|
|
1346
|
+
console.warn(c.yellow("Benchmarking is an experimental feature.\nBreaking changes might not follow SemVer, please pin Vitest's version when using it."));
|
|
1347
|
+
await start("benchmark", cliFilters, options);
|
|
1289
1348
|
}
|
|
1290
1349
|
function normalizeCliOptions(cliFilters, argv) {
|
|
1291
|
-
if (argv.exclude)
|
|
1350
|
+
if (argv.exclude) {
|
|
1351
|
+
argv.cliExclude = toArray(argv.exclude);
|
|
1352
|
+
delete argv.exclude;
|
|
1353
|
+
}
|
|
1292
1354
|
if (cliFilters.some((filter) => filter.includes(":"))) argv.includeTaskLocation ??= true;
|
|
1293
1355
|
if (typeof argv.typecheck?.only === "boolean") argv.typecheck.enabled ??= true;
|
|
1294
1356
|
return argv;
|
|
1295
1357
|
}
|
|
1296
1358
|
async function start(mode, cliFilters, options) {
|
|
1297
1359
|
try {
|
|
1298
|
-
const { startVitest } = await import('./cli-api.
|
|
1360
|
+
const { startVitest } = await import('./cli-api.BQ-bjcRi.js').then(function (n) { return n.p; });
|
|
1361
|
+
const ctx = await startVitest(mode, cliFilters.map(normalize), normalizeCliOptions(cliFilters, options));
|
|
1299
1362
|
if (!ctx.shouldKeepServer()) await ctx.exit();
|
|
1300
1363
|
} catch (e) {
|
|
1301
|
-
const { errorBanner } = await import('./index.
|
|
1302
|
-
|
|
1364
|
+
const { errorBanner } = await import('./index.kotH7DY7.js').then(function (n) { return n.u; });
|
|
1365
|
+
console.error(`\n${errorBanner("Startup Error")}`);
|
|
1366
|
+
console.error(e);
|
|
1367
|
+
console.error("\n\n");
|
|
1368
|
+
if (process.exitCode == null) process.exitCode = 1;
|
|
1303
1369
|
process.exit();
|
|
1304
1370
|
}
|
|
1305
1371
|
}
|
|
1306
1372
|
async function init(project) {
|
|
1307
|
-
if (project !== "browser")
|
|
1308
|
-
|
|
1373
|
+
if (project !== "browser") {
|
|
1374
|
+
console.error(/* @__PURE__ */ new Error("Only the \"browser\" project is supported. Use \"vitest init browser\" to create a new project."));
|
|
1375
|
+
process.exit(1);
|
|
1376
|
+
}
|
|
1377
|
+
const { create } = await import('./creator.fzVyoMf3.js');
|
|
1309
1378
|
await create();
|
|
1310
1379
|
}
|
|
1311
1380
|
async function collect(mode, cliFilters, options) {
|
|
1312
1381
|
try {
|
|
1313
|
-
const { prepareVitest, processCollected, outputFileList } = await import('./cli-api.
|
|
1382
|
+
const { prepareVitest, processCollected, outputFileList } = await import('./cli-api.BQ-bjcRi.js').then(function (n) { return n.p; });
|
|
1383
|
+
const ctx = await prepareVitest(mode, {
|
|
1314
1384
|
...normalizeCliOptions(cliFilters, options),
|
|
1315
1385
|
watch: false,
|
|
1316
1386
|
run: true
|
|
@@ -1318,18 +1388,21 @@ async function collect(mode, cliFilters, options) {
|
|
|
1318
1388
|
if (!options.filesOnly) {
|
|
1319
1389
|
const { testModules: tests, unhandledErrors: errors } = await ctx.collect(cliFilters.map(normalize));
|
|
1320
1390
|
if (errors.length) {
|
|
1321
|
-
console.error("\nThere were unhandled errors during test collection")
|
|
1391
|
+
console.error("\nThere were unhandled errors during test collection");
|
|
1392
|
+
errors.forEach((e) => console.error(e));
|
|
1393
|
+
console.error("\n\n");
|
|
1394
|
+
await ctx.close();
|
|
1322
1395
|
return;
|
|
1323
1396
|
}
|
|
1324
1397
|
processCollected(ctx, tests, options);
|
|
1325
|
-
} else
|
|
1326
|
-
const files = await ctx.getRelevantTestSpecifications(cliFilters.map(normalize));
|
|
1327
|
-
outputFileList(files, options);
|
|
1328
|
-
}
|
|
1398
|
+
} else outputFileList(await ctx.getRelevantTestSpecifications(cliFilters.map(normalize)), options);
|
|
1329
1399
|
await ctx.close();
|
|
1330
1400
|
} catch (e) {
|
|
1331
|
-
const { errorBanner } = await import('./index.
|
|
1332
|
-
|
|
1401
|
+
const { errorBanner } = await import('./index.kotH7DY7.js').then(function (n) { return n.u; });
|
|
1402
|
+
console.error(`\n${errorBanner("Collect Error")}`);
|
|
1403
|
+
console.error(e);
|
|
1404
|
+
console.error("\n\n");
|
|
1405
|
+
if (process.exitCode == null) process.exitCode = 1;
|
|
1333
1406
|
process.exit();
|
|
1334
1407
|
}
|
|
1335
1408
|
}
|