vitest 4.0.0-beta.1 → 4.0.0-beta.10
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 +2 -2
- package/dist/browser.d.ts +13 -14
- package/dist/browser.js +6 -5
- package/dist/chunks/base.Cjha6usc.js +129 -0
- package/dist/chunks/{benchmark.CYdenmiT.js → benchmark.CJUa-Hsa.js} +6 -8
- package/dist/chunks/{benchmark.d.BwvBVTda.d.ts → benchmark.d.DAaHLpsq.d.ts} +4 -4
- package/dist/chunks/{browser.d.q8Z0P0q1.d.ts → browser.d.yFAklsD1.d.ts} +5 -5
- package/dist/chunks/{cac.D3EzDDZd.js → cac.DCxo_nSu.js} +70 -152
- package/dist/chunks/{cli-api.Dn5gKePv.js → cli-api.BJJXh9BV.js} +1330 -1677
- package/dist/chunks/{config.d.HJdfX-8k.d.ts → config.d.B_LthbQq.d.ts} +58 -63
- package/dist/chunks/{console.CtFJOzRO.js → console.7h5kHUIf.js} +34 -70
- package/dist/chunks/{constants.DnKduX2e.js → constants.D_Q9UYh-.js} +1 -9
- package/dist/chunks/{coverage.Cwa-XhJt.js → coverage.BCU-r2QL.js} +515 -781
- package/dist/chunks/{coverage.DVF1vEu8.js → coverage.D_JHT54q.js} +2 -2
- package/dist/chunks/{coverage.d.S9RMNXIe.d.ts → coverage.d.BZtK59WP.d.ts} +10 -8
- package/dist/chunks/{creator.GK6I-cL4.js → creator.08Gi-vCA.js} +93 -77
- package/dist/chunks/{date.Bq6ZW5rf.js → date.-jtEtIeV.js} +6 -17
- package/dist/chunks/{environment.d.CUq4cUgQ.d.ts → environment.d.BsToaxti.d.ts} +27 -6
- package/dist/chunks/{git.BVQ8w_Sw.js → git.BFNcloKD.js} +1 -2
- package/dist/chunks/{global.d.CVbXEflG.d.ts → global.d.BK3X7FW1.d.ts} +2 -5
- package/dist/chunks/{globals.Cxal6MLI.js → globals.DG-S3xFe.js} +8 -8
- package/dist/chunks/{index.CZI_8rVt.js → index.BIP7prJq.js} +289 -608
- package/dist/chunks/{index.B521nVV-.js → index.Bgo3tNWt.js} +23 -4
- package/dist/chunks/{index.TfbsX-3I.js → index.BjKEiSn0.js} +14 -24
- package/dist/chunks/{index.BWf_gE5n.js → index.CMfqw92x.js} +7 -6
- package/dist/chunks/{index.CmSc2RE5.js → index.DIWhzsUh.js} +72 -118
- package/dist/chunks/{inspector.C914Efll.js → inspector.CvQD-Nie.js} +10 -25
- package/dist/chunks/moduleRunner.d.D9nBoC4p.d.ts +201 -0
- package/dist/chunks/moduleTransport.I-bgQy0S.js +19 -0
- package/dist/chunks/{node.fjCdwEIl.js → node.CyipiPvJ.js} +1 -1
- package/dist/chunks/{plugin.d.C2EcJUjo.d.ts → plugin.d.BMVSnsGV.d.ts} +1 -1
- package/dist/chunks/{reporters.d.DxZg19fy.d.ts → reporters.d.BUWjmRYq.d.ts} +1226 -1291
- package/dist/chunks/resolveSnapshotEnvironment.Bkht6Yor.js +81 -0
- package/dist/chunks/resolver.Bx6lE0iq.js +119 -0
- package/dist/chunks/rpc.BKr6mtxz.js +65 -0
- package/dist/chunks/{setup-common.D7ZqXFx-.js → setup-common.uiMcU3cv.js} +17 -29
- package/dist/chunks/startModuleRunner.p67gbNo9.js +665 -0
- package/dist/chunks/{suite.d.FvehnV49.d.ts → suite.d.BJWk38HB.d.ts} +1 -1
- package/dist/chunks/test.BiqSKISg.js +214 -0
- package/dist/chunks/{typechecker.CVytUJuF.js → typechecker.DB-fIMaH.js} +144 -213
- package/dist/chunks/{utils.CAioKnHs.js → utils.C2YI6McM.js} +5 -14
- package/dist/chunks/{utils.XdZDrNZV.js → utils.D2R2NiOH.js} +8 -27
- package/dist/chunks/{vi.bdSIJ99Y.js → vi.ZPgvtBao.js} +156 -305
- package/dist/chunks/{vm.BThCzidc.js → vm.Ca0Y0W5f.js} +116 -226
- package/dist/chunks/{worker.d.DoNjFAiv.d.ts → worker.d.BDsXGkwh.d.ts} +28 -22
- package/dist/chunks/{worker.d.CmvJfRGs.d.ts → worker.d.BNcX_2mH.d.ts} +1 -1
- package/dist/cli.js +4 -4
- package/dist/config.cjs +3 -9
- package/dist/config.d.ts +49 -54
- package/dist/config.js +1 -1
- package/dist/coverage.d.ts +27 -26
- package/dist/coverage.js +6 -7
- package/dist/environments.d.ts +9 -13
- package/dist/environments.js +1 -1
- package/dist/index.d.ts +38 -45
- package/dist/index.js +7 -9
- package/dist/module-evaluator.d.ts +13 -0
- package/dist/module-evaluator.js +276 -0
- package/dist/module-runner.js +15 -0
- package/dist/node.d.ts +40 -41
- package/dist/node.js +23 -33
- package/dist/reporters.d.ts +12 -13
- package/dist/reporters.js +3 -3
- package/dist/runners.d.ts +3 -3
- package/dist/runners.js +13 -232
- package/dist/snapshot.js +2 -2
- package/dist/suite.d.ts +2 -2
- package/dist/suite.js +2 -2
- package/dist/worker.js +90 -47
- package/dist/workers/forks.js +34 -10
- package/dist/workers/runVmTests.js +36 -56
- package/dist/workers/threads.js +34 -10
- package/dist/workers/vmForks.js +11 -10
- package/dist/workers/vmThreads.js +11 -10
- package/dist/workers.d.ts +5 -4
- package/dist/workers.js +35 -17
- package/globals.d.ts +17 -17
- package/package.json +32 -31
- package/dist/chunks/base.Bj3pWTr1.js +0 -38
- package/dist/chunks/execute.B7h3T_Hc.js +0 -708
- package/dist/chunks/index.D-VkfKhf.js +0 -105
- package/dist/chunks/rpc.CsFtxqeq.js +0 -83
- package/dist/chunks/runBaseTests.BC7ZIH5L.js +0 -129
- package/dist/execute.d.ts +0 -148
- package/dist/execute.js +0 -13
|
@@ -2,8 +2,8 @@ import { toArray } from '@vitest/utils';
|
|
|
2
2
|
import { EventEmitter } from 'events';
|
|
3
3
|
import { normalize } from 'pathe';
|
|
4
4
|
import c from 'tinyrainbow';
|
|
5
|
-
import { a as defaultPort, d as defaultBrowserPort } from './constants.
|
|
6
|
-
import { R as ReportersMap } from './index.
|
|
5
|
+
import { a as defaultPort, d as defaultBrowserPort } from './constants.D_Q9UYh-.js';
|
|
6
|
+
import { R as ReportersMap } from './index.BIP7prJq.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.0-beta.
|
|
622
|
+
var version = "4.0.0-beta.10";
|
|
623
623
|
|
|
624
624
|
const apiConfig = (port) => ({
|
|
625
625
|
port: {
|
|
@@ -632,41 +632,29 @@ const apiConfig = (port) => ({
|
|
|
632
632
|
},
|
|
633
633
|
strictPort: { description: "Set to true to exit if port is already in use, instead of automatically trying the next available port" },
|
|
634
634
|
middlewareMode: null
|
|
635
|
-
})
|
|
636
|
-
const poolThreadsCommands = {
|
|
635
|
+
}), poolThreadsCommands = {
|
|
637
636
|
isolate: { description: "Isolate tests in threads pool (default: `true`)" },
|
|
638
637
|
singleThread: { description: "Run tests inside a single thread (default: `false`)" },
|
|
639
638
|
maxThreads: {
|
|
640
639
|
description: "Maximum number or percentage of threads to run tests in",
|
|
641
640
|
argument: "<workers>"
|
|
642
641
|
},
|
|
643
|
-
minThreads: {
|
|
644
|
-
description: "Minimum number or percentage of threads to run tests in",
|
|
645
|
-
argument: "<workers>"
|
|
646
|
-
},
|
|
647
642
|
useAtomics: { description: "Use Atomics to synchronize threads. This can improve performance in some cases, but might cause segfault in older Node versions (default: `false`)" },
|
|
648
643
|
execArgv: null
|
|
649
|
-
}
|
|
650
|
-
const poolForksCommands = {
|
|
644
|
+
}, poolForksCommands = {
|
|
651
645
|
isolate: { description: "Isolate tests in forks pool (default: `true`)" },
|
|
652
646
|
singleFork: { description: "Run tests inside a single child_process (default: `false`)" },
|
|
653
647
|
maxForks: {
|
|
654
648
|
description: "Maximum number or percentage of processes to run tests in",
|
|
655
649
|
argument: "<workers>"
|
|
656
650
|
},
|
|
657
|
-
minForks: {
|
|
658
|
-
description: "Minimum number or percentage of processes to run tests in",
|
|
659
|
-
argument: "<workers>"
|
|
660
|
-
},
|
|
661
651
|
execArgv: null
|
|
662
652
|
};
|
|
663
653
|
function watermarkTransform(value) {
|
|
664
|
-
|
|
665
|
-
return value;
|
|
654
|
+
return typeof value === "string" ? value.split(",").map(Number) : value;
|
|
666
655
|
}
|
|
667
656
|
function transformNestedBoolean(value) {
|
|
668
|
-
|
|
669
|
-
return value;
|
|
657
|
+
return typeof value === "boolean" ? { enabled: value } : value;
|
|
670
658
|
}
|
|
671
659
|
const cliOptionsConfig = {
|
|
672
660
|
root: {
|
|
@@ -770,7 +758,14 @@ const cliOptionsConfig = {
|
|
|
770
758
|
argument: "",
|
|
771
759
|
subcommands: {
|
|
772
760
|
perFile: { description: "Check thresholds per file. See `--coverage.thresholds.lines`, `--coverage.thresholds.functions`, `--coverage.thresholds.branches` and `--coverage.thresholds.statements` for the actual thresholds (default: `false`)" },
|
|
773
|
-
autoUpdate: {
|
|
761
|
+
autoUpdate: {
|
|
762
|
+
description: "Update threshold values: \"lines\", \"functions\", \"branches\" and \"statements\" to configuration file when current coverage is above the configured thresholds (default: `false`)",
|
|
763
|
+
argument: "<boolean|function>",
|
|
764
|
+
subcommands: null,
|
|
765
|
+
transform(value) {
|
|
766
|
+
return value === "true" || value === "yes" || value === true ? true : value === "false" || value === "no" || value === false ? false : value;
|
|
767
|
+
}
|
|
768
|
+
},
|
|
774
769
|
lines: {
|
|
775
770
|
description: "Threshold for lines. Visit [istanbuljs](https://github.com/istanbuljs/nyc#coverage-thresholds) for more information. This option is not available for custom providers",
|
|
776
771
|
argument: "<number>"
|
|
@@ -836,11 +831,6 @@ const cliOptionsConfig = {
|
|
|
836
831
|
description: "Override Vite mode (default: `test` or `benchmark`)",
|
|
837
832
|
argument: "<name>"
|
|
838
833
|
},
|
|
839
|
-
workspace: {
|
|
840
|
-
description: "[deprecated] Path to a workspace configuration file",
|
|
841
|
-
argument: "<path>",
|
|
842
|
-
normalize: true
|
|
843
|
-
},
|
|
844
834
|
isolate: { description: "Run every test file in isolation. To disable isolation, use `--no-isolate` (default: `true`)" },
|
|
845
835
|
globals: { description: "Inject apis globally" },
|
|
846
836
|
dom: { description: "Mock browser API with happy-dom" },
|
|
@@ -848,11 +838,7 @@ const cliOptionsConfig = {
|
|
|
848
838
|
description: "Run tests in the browser. Equivalent to `--browser.enabled` (default: `false`)",
|
|
849
839
|
argument: "<name>",
|
|
850
840
|
transform(browser) {
|
|
851
|
-
|
|
852
|
-
if (browser === "true" || browser === "false") return { enabled: browser === "true" };
|
|
853
|
-
if (browser === "yes" || browser === "no") return { enabled: browser === "yes" };
|
|
854
|
-
if (typeof browser === "string") return { name: browser };
|
|
855
|
-
return browser;
|
|
841
|
+
return typeof browser === "boolean" ? { enabled: browser } : browser === "true" || browser === "false" ? { enabled: browser === "true" } : browser === "yes" || browser === "no" ? { enabled: browser === "yes" } : typeof browser === "string" ? { name: browser } : browser;
|
|
856
842
|
},
|
|
857
843
|
subcommands: {
|
|
858
844
|
enabled: { description: "Run tests in the browser. Equivalent to `--browser.enabled` (default: `false`)" },
|
|
@@ -869,12 +855,19 @@ const cliOptionsConfig = {
|
|
|
869
855
|
provider: {
|
|
870
856
|
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/guide/browser/config.html#browser-provider) for more information (default: `\"preview\"`)",
|
|
871
857
|
argument: "<name>",
|
|
872
|
-
subcommands: null
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
858
|
+
subcommands: null,
|
|
859
|
+
transform(value) {
|
|
860
|
+
const supported = [
|
|
861
|
+
"playwright",
|
|
862
|
+
"webdriverio",
|
|
863
|
+
"preview"
|
|
864
|
+
];
|
|
865
|
+
if (typeof value !== "string" || !supported.includes(value)) throw new Error(`Unsupported browser provider: ${value}. Supported providers are: ${supported.join(", ")}`);
|
|
866
|
+
return {
|
|
867
|
+
name: value,
|
|
868
|
+
_cli: true
|
|
869
|
+
};
|
|
870
|
+
}
|
|
878
871
|
},
|
|
879
872
|
isolate: { description: "Run every browser test file in isolation. To disable isolation, use `--browser.isolate=false` (default: `true`)" },
|
|
880
873
|
ui: { description: "Show Vitest UI when running tests (default: `!process.env.CI`)" },
|
|
@@ -883,15 +876,16 @@ const cliOptionsConfig = {
|
|
|
883
876
|
description: "If connection to the browser takes longer, the test suite will fail (default: `60_000`)",
|
|
884
877
|
argument: "<timeout>"
|
|
885
878
|
},
|
|
879
|
+
trackUnhandledErrors: { description: "Control if Vitest catches uncaught exceptions so they can be reported (default: `true`)" },
|
|
886
880
|
orchestratorScripts: null,
|
|
887
|
-
testerScripts: null,
|
|
888
881
|
commands: null,
|
|
889
882
|
viewport: null,
|
|
890
883
|
screenshotDirectory: null,
|
|
891
884
|
screenshotFailures: null,
|
|
892
885
|
locators: null,
|
|
893
886
|
testerHtmlPath: null,
|
|
894
|
-
instances: null
|
|
887
|
+
instances: null,
|
|
888
|
+
expect: null
|
|
895
889
|
}
|
|
896
890
|
},
|
|
897
891
|
pool: {
|
|
@@ -942,10 +936,6 @@ const cliOptionsConfig = {
|
|
|
942
936
|
description: "Maximum number or percentage of workers to run tests in",
|
|
943
937
|
argument: "<workers>"
|
|
944
938
|
},
|
|
945
|
-
minWorkers: {
|
|
946
|
-
description: "Minimum number or percentage of workers to run tests in",
|
|
947
|
-
argument: "<workers>"
|
|
948
|
-
},
|
|
949
939
|
environment: {
|
|
950
940
|
description: "Specify runner environment, if not running in the browser (default: `node`)",
|
|
951
941
|
argument: "<name>",
|
|
@@ -995,18 +985,14 @@ const cliOptionsConfig = {
|
|
|
995
985
|
description: "Enable Node.js inspector (default: `127.0.0.1:9229`)",
|
|
996
986
|
argument: "[[host:]port]",
|
|
997
987
|
transform(portOrEnabled) {
|
|
998
|
-
|
|
999
|
-
if (portOrEnabled === "false" || portOrEnabled === "no") return false;
|
|
1000
|
-
return portOrEnabled;
|
|
988
|
+
return portOrEnabled === 0 || portOrEnabled === "true" || portOrEnabled === "yes" ? true : portOrEnabled === "false" || portOrEnabled === "no" ? false : portOrEnabled;
|
|
1001
989
|
}
|
|
1002
990
|
},
|
|
1003
991
|
inspectBrk: {
|
|
1004
992
|
description: "Enable Node.js inspector and break before the test starts",
|
|
1005
993
|
argument: "[[host:]port]",
|
|
1006
994
|
transform(portOrEnabled) {
|
|
1007
|
-
|
|
1008
|
-
if (portOrEnabled === "false" || portOrEnabled === "no") return false;
|
|
1009
|
-
return portOrEnabled;
|
|
995
|
+
return portOrEnabled === 0 || portOrEnabled === "true" || portOrEnabled === "yes" ? true : portOrEnabled === "false" || portOrEnabled === "no" ? false : portOrEnabled;
|
|
1010
996
|
}
|
|
1011
997
|
},
|
|
1012
998
|
inspector: null,
|
|
@@ -1130,8 +1116,7 @@ const cliOptionsConfig = {
|
|
|
1130
1116
|
default: true,
|
|
1131
1117
|
transform(cache) {
|
|
1132
1118
|
if (typeof cache !== "boolean" && cache) throw new Error("--cache.dir is deprecated");
|
|
1133
|
-
|
|
1134
|
-
return cache;
|
|
1119
|
+
return cache && {};
|
|
1135
1120
|
}
|
|
1136
1121
|
},
|
|
1137
1122
|
maxConcurrency: {
|
|
@@ -1183,13 +1168,12 @@ const cliOptionsConfig = {
|
|
|
1183
1168
|
description: "Use `bundle` to bundle the config with esbuild or `runner` (experimental) to process it on the fly. This is only available in vite version 6.1.0 and above. (default: `bundle`)",
|
|
1184
1169
|
argument: "<loader>"
|
|
1185
1170
|
},
|
|
1186
|
-
standalone: { description: "Start Vitest without running tests.
|
|
1171
|
+
standalone: { description: "Start Vitest without running tests. Tests will be running only on change. This option is ignored when CLI file filters are passed. (default: `false`)" },
|
|
1187
1172
|
mergeReports: {
|
|
1188
1173
|
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",
|
|
1189
1174
|
argument: "[path]",
|
|
1190
1175
|
transform(value) {
|
|
1191
|
-
|
|
1192
|
-
return value;
|
|
1176
|
+
return !value || typeof value === "boolean" ? ".vitest-reports" : value;
|
|
1193
1177
|
}
|
|
1194
1178
|
},
|
|
1195
1179
|
cliExclude: null,
|
|
@@ -1201,7 +1185,6 @@ const cliOptionsConfig = {
|
|
|
1201
1185
|
includeSource: null,
|
|
1202
1186
|
alias: null,
|
|
1203
1187
|
env: null,
|
|
1204
|
-
environmentMatchGlobs: null,
|
|
1205
1188
|
environmentOptions: null,
|
|
1206
1189
|
unstubEnvs: null,
|
|
1207
1190
|
related: null,
|
|
@@ -1213,12 +1196,10 @@ const cliOptionsConfig = {
|
|
|
1213
1196
|
uiBase: null,
|
|
1214
1197
|
benchmark: null,
|
|
1215
1198
|
include: null,
|
|
1216
|
-
testTransformMode: null,
|
|
1217
1199
|
fakeTimers: null,
|
|
1218
1200
|
chaiConfig: null,
|
|
1219
1201
|
clearMocks: null,
|
|
1220
1202
|
css: null,
|
|
1221
|
-
poolMatchGlobs: null,
|
|
1222
1203
|
deps: null,
|
|
1223
1204
|
name: null,
|
|
1224
1205
|
snapshotEnvironment: null,
|
|
@@ -1241,11 +1222,16 @@ const benchCliOptionsConfig = {
|
|
|
1241
1222
|
}
|
|
1242
1223
|
};
|
|
1243
1224
|
const collectCliOptionsConfig = {
|
|
1225
|
+
...cliOptionsConfig,
|
|
1244
1226
|
json: {
|
|
1245
1227
|
description: "Print collected tests as JSON or write to a file (Default: false)",
|
|
1246
1228
|
argument: "[true/path]"
|
|
1247
1229
|
},
|
|
1248
|
-
filesOnly: { description: "Print only test files with out the test cases" }
|
|
1230
|
+
filesOnly: { description: "Print only test files with out the test cases" },
|
|
1231
|
+
changed: {
|
|
1232
|
+
description: "Print only tests that are affected by the changed files (default: `false`)",
|
|
1233
|
+
argument: "[since]"
|
|
1234
|
+
}
|
|
1249
1235
|
};
|
|
1250
1236
|
|
|
1251
1237
|
function addCommand(cli, name, option) {
|
|
@@ -1257,11 +1243,7 @@ function addCommand(cli, name, option) {
|
|
|
1257
1243
|
const received = value.map((s) => typeof s === "string" ? `"${s}"` : s).join(", ");
|
|
1258
1244
|
throw new Error(`Expected a single value for option "${command}", received [${received}]`);
|
|
1259
1245
|
}
|
|
1260
|
-
value = removeQuotes(value);
|
|
1261
|
-
if (option.transform) return option.transform(value);
|
|
1262
|
-
if (option.array) return toArray(value);
|
|
1263
|
-
if (option.normalize) return normalize(String(value));
|
|
1264
|
-
return value;
|
|
1246
|
+
return value = removeQuotes(value), option.transform ? option.transform(value) : option.array ? toArray(value) : option.normalize ? normalize(String(value)) : value;
|
|
1265
1247
|
}
|
|
1266
1248
|
const hasSubcommands = "subcommands" in option && option.subcommands;
|
|
1267
1249
|
if (option.description) {
|
|
@@ -1279,24 +1261,16 @@ function addCliOptions(cli, options) {
|
|
|
1279
1261
|
}
|
|
1280
1262
|
function createCLI(options = {}) {
|
|
1281
1263
|
const cli = cac("vitest");
|
|
1282
|
-
cli.version(version)
|
|
1283
|
-
addCliOptions(cli, cliOptionsConfig);
|
|
1284
|
-
cli.help((info) => {
|
|
1264
|
+
return cli.version(version), addCliOptions(cli, cliOptionsConfig), cli.help((info) => {
|
|
1285
1265
|
const helpSection = info.find((current) => current.title?.startsWith("For more info, run any command"));
|
|
1286
1266
|
if (helpSection) helpSection.body += "\n $ vitest --help --expand-help";
|
|
1287
1267
|
const options = info.find((current) => current.title === "Options");
|
|
1288
1268
|
if (typeof options !== "object") return info;
|
|
1289
|
-
const helpIndex = process.argv.findIndex((arg) => arg === "--help");
|
|
1290
|
-
const subcommands = process.argv.slice(helpIndex + 1);
|
|
1291
|
-
const defaultOutput = options.body.split("\n").filter((line) => /^\s+--\S+\./.test(line) === false).join("\n");
|
|
1269
|
+
const helpIndex = process.argv.findIndex((arg) => arg === "--help"), subcommands = process.argv.slice(helpIndex + 1), defaultOutput = options.body.split("\n").filter((line) => /^\s+--\S+\./.test(line) === false).join("\n");
|
|
1292
1270
|
// Filter out options with dot-notation if --help is not called with a subcommand (default behavior)
|
|
1293
|
-
if (subcommands.length === 0)
|
|
1294
|
-
options.body = defaultOutput;
|
|
1295
|
-
return info;
|
|
1296
|
-
}
|
|
1271
|
+
if (subcommands.length === 0) return options.body = defaultOutput, info;
|
|
1297
1272
|
if (subcommands.length === 1 && (subcommands[0] === "--expand-help" || subcommands[0] === "--expandHelp")) return info;
|
|
1298
|
-
const subcommandMarker = "$SUB_COMMAND_MARKER$";
|
|
1299
|
-
const banner = info.find((current) => /^vitest\/\d+\.\d+\.\d+$/.test(current.body));
|
|
1273
|
+
const subcommandMarker = "$SUB_COMMAND_MARKER$", banner = info.find((current) => /^vitest\/\d+\.\d+\.\d+$/.test(current.body));
|
|
1300
1274
|
function addBannerWarning(warning) {
|
|
1301
1275
|
if (typeof banner?.body === "string") {
|
|
1302
1276
|
if (banner?.body.includes(warning)) return;
|
|
@@ -1314,129 +1288,76 @@ function createCLI(options = {}) {
|
|
|
1314
1288
|
// Mark the help section for the subcommands
|
|
1315
1289
|
if (subcommand.startsWith("--")) options.body = options.body.split("\n").map((line) => line.trim().startsWith(subcommand) ? `${subcommandMarker}${line}` : line).join("\n");
|
|
1316
1290
|
}
|
|
1317
|
-
|
|
1318
|
-
options.body = options.body.split("\n").map((line) => line.startsWith(subcommandMarker) ? line.split(subcommandMarker)[1] : "").filter((line) => line.length !== 0).join("\n");
|
|
1319
|
-
if (!options.body) {
|
|
1320
|
-
addBannerWarning("no options were found for your subcommands so we printed the whole output");
|
|
1321
|
-
options.body = defaultOutput;
|
|
1322
|
-
}
|
|
1291
|
+
if (options.body = options.body.split("\n").map((line) => line.startsWith(subcommandMarker) ? line.split(subcommandMarker)[1] : "").filter((line) => line.length !== 0).join("\n"), !options.body) addBannerWarning("no options were found for your subcommands so we printed the whole output"), options.body = defaultOutput;
|
|
1323
1292
|
return info;
|
|
1324
|
-
});
|
|
1325
|
-
cli.command("run [...filters]", void 0, options).action(run);
|
|
1326
|
-
cli.command("related [...filters]", void 0, options).action(runRelated);
|
|
1327
|
-
cli.command("watch [...filters]", void 0, options).action(watch);
|
|
1328
|
-
cli.command("dev [...filters]", void 0, options).action(watch);
|
|
1329
|
-
addCliOptions(cli.command("bench [...filters]", void 0, options).action(benchmark), benchCliOptionsConfig);
|
|
1330
|
-
cli.command("init <project>", void 0, options).action(init);
|
|
1331
|
-
addCliOptions(cli.command("list [...filters]", void 0, options).action((filters, options) => collect("test", filters, options)), collectCliOptionsConfig);
|
|
1332
|
-
cli.command("[...filters]", void 0, options).action((filters, options) => start("test", filters, options));
|
|
1333
|
-
return cli;
|
|
1293
|
+
}), cli.command("run [...filters]", void 0, options).action(run), cli.command("related [...filters]", void 0, options).action(runRelated), cli.command("watch [...filters]", void 0, options).action(watch), cli.command("dev [...filters]", void 0, options).action(watch), addCliOptions(cli.command("bench [...filters]", void 0, options).action(benchmark), benchCliOptionsConfig), cli.command("init <project>", void 0, options).action(init), addCliOptions(cli.command("list [...filters]", void 0, options).action((filters, options) => collect("test", filters, options)), collectCliOptionsConfig), cli.command("[...filters]", void 0, options).action((filters, options) => start("test", filters, options)), cli;
|
|
1334
1294
|
}
|
|
1335
1295
|
function removeQuotes(str) {
|
|
1336
|
-
|
|
1337
|
-
if (Array.isArray(str)) return str.map(removeQuotes);
|
|
1338
|
-
return str;
|
|
1339
|
-
}
|
|
1340
|
-
if (str.startsWith("\"") && str.endsWith("\"")) return str.slice(1, -1);
|
|
1341
|
-
if (str.startsWith(`'`) && str.endsWith(`'`)) return str.slice(1, -1);
|
|
1342
|
-
return str;
|
|
1296
|
+
return typeof str === "string" ? str.startsWith("\"") && str.endsWith("\"") || str.startsWith(`'`) && str.endsWith(`'`) ? str.slice(1, -1) : str : Array.isArray(str) ? str.map(removeQuotes) : str;
|
|
1343
1297
|
}
|
|
1344
1298
|
function splitArgv(argv) {
|
|
1345
1299
|
const reg = /(['"])(?:(?!\1).)+\1/g;
|
|
1346
|
-
argv = argv.replace(reg, (match) => match.replace(/\s/g, "\0"))
|
|
1347
|
-
|
|
1348
|
-
arg = arg.replace(/\0/g, " ");
|
|
1349
|
-
return removeQuotes(arg);
|
|
1300
|
+
return argv = argv.replace(reg, (match) => match.replace(/\s/g, "\0")), argv.split(" ").map((arg) => {
|
|
1301
|
+
return arg = arg.replace(/\0/g, " "), removeQuotes(arg);
|
|
1350
1302
|
});
|
|
1351
1303
|
}
|
|
1352
1304
|
function parseCLI(argv, config = {}) {
|
|
1353
1305
|
const arrayArgs = typeof argv === "string" ? splitArgv(argv) : argv;
|
|
1354
1306
|
if (arrayArgs[0] !== "vitest") throw new Error(`Expected "vitest" as the first argument, received "${arrayArgs[0]}"`);
|
|
1355
|
-
arrayArgs[0] = "/index.js";
|
|
1356
|
-
arrayArgs.unshift("node");
|
|
1307
|
+
arrayArgs[0] = "/index.js", arrayArgs.unshift("node");
|
|
1357
1308
|
let { args, options } = createCLI(config).parse(arrayArgs, { run: false });
|
|
1358
1309
|
if (arrayArgs[2] === "watch" || arrayArgs[2] === "dev") options.watch = true;
|
|
1359
1310
|
if (arrayArgs[2] === "run" && !options.watch) options.run = true;
|
|
1360
|
-
if (arrayArgs[2] === "related")
|
|
1361
|
-
options.related = args;
|
|
1362
|
-
options.passWithNoTests ??= true;
|
|
1363
|
-
args = [];
|
|
1364
|
-
}
|
|
1311
|
+
if (arrayArgs[2] === "related") options.related = args, options.passWithNoTests ??= true, args = [];
|
|
1365
1312
|
return {
|
|
1366
1313
|
filter: args,
|
|
1367
1314
|
options
|
|
1368
1315
|
};
|
|
1369
1316
|
}
|
|
1370
1317
|
async function runRelated(relatedFiles, argv) {
|
|
1371
|
-
argv.related = relatedFiles;
|
|
1372
|
-
argv.passWithNoTests ??= true;
|
|
1373
|
-
await start("test", [], argv);
|
|
1318
|
+
argv.related = relatedFiles, argv.passWithNoTests ??= true, await start("test", [], argv);
|
|
1374
1319
|
}
|
|
1375
1320
|
async function watch(cliFilters, options) {
|
|
1376
|
-
options.watch = true;
|
|
1377
|
-
await start("test", cliFilters, options);
|
|
1321
|
+
options.watch = true, await start("test", cliFilters, options);
|
|
1378
1322
|
}
|
|
1379
1323
|
async function run(cliFilters, options) {
|
|
1380
|
-
|
|
1381
|
-
options.run = !options.watch;
|
|
1382
|
-
await start("test", cliFilters, options);
|
|
1324
|
+
options.run = !options.watch, await start("test", cliFilters, options);
|
|
1383
1325
|
}
|
|
1384
1326
|
async function benchmark(cliFilters, options) {
|
|
1385
|
-
console.warn(c.yellow("Benchmarking is an experimental feature.\nBreaking changes might not follow SemVer, please pin Vitest's version when using it."));
|
|
1386
|
-
await start("benchmark", cliFilters, options);
|
|
1327
|
+
console.warn(c.yellow("Benchmarking is an experimental feature.\nBreaking changes might not follow SemVer, please pin Vitest's version when using it.")), await start("benchmark", cliFilters, options);
|
|
1387
1328
|
}
|
|
1388
1329
|
function normalizeCliOptions(cliFilters, argv) {
|
|
1389
|
-
if (argv.exclude)
|
|
1390
|
-
argv.cliExclude = toArray(argv.exclude);
|
|
1391
|
-
delete argv.exclude;
|
|
1392
|
-
}
|
|
1330
|
+
if (argv.exclude) argv.cliExclude = toArray(argv.exclude), delete argv.exclude;
|
|
1393
1331
|
if (cliFilters.some((filter) => filter.includes(":"))) argv.includeTaskLocation ??= true;
|
|
1394
1332
|
if (typeof argv.typecheck?.only === "boolean") argv.typecheck.enabled ??= true;
|
|
1395
1333
|
return argv;
|
|
1396
1334
|
}
|
|
1397
1335
|
async function start(mode, cliFilters, options) {
|
|
1398
1336
|
try {
|
|
1399
|
-
|
|
1400
|
-
} catch {}
|
|
1401
|
-
try {
|
|
1402
|
-
const { startVitest } = await import('./cli-api.Dn5gKePv.js').then(function (n) { return n.f; });
|
|
1403
|
-
const ctx = await startVitest(mode, cliFilters.map(normalize), normalizeCliOptions(cliFilters, options));
|
|
1337
|
+
const { startVitest } = await import('./cli-api.BJJXh9BV.js').then(function (n) { return n.j; }), ctx = await startVitest(mode, cliFilters.map(normalize), normalizeCliOptions(cliFilters, options));
|
|
1404
1338
|
if (!ctx.shouldKeepServer()) await ctx.exit();
|
|
1405
1339
|
} catch (e) {
|
|
1406
|
-
const { errorBanner } = await import('./index.
|
|
1407
|
-
console.error(`\n${errorBanner("Startup Error")}`);
|
|
1408
|
-
console.error(e);
|
|
1409
|
-
console.error("\n\n");
|
|
1410
|
-
if (process.exitCode == null) process.exitCode = 1;
|
|
1340
|
+
const { errorBanner } = await import('./index.BIP7prJq.js').then(function (n) { return n.u; });
|
|
1341
|
+
if (console.error(`\n${errorBanner("Startup Error")}`), console.error(e), console.error("\n\n"), process.exitCode == null) process.exitCode = 1;
|
|
1411
1342
|
process.exit();
|
|
1412
1343
|
}
|
|
1413
1344
|
}
|
|
1414
1345
|
async function init(project) {
|
|
1415
|
-
if (project !== "browser")
|
|
1416
|
-
|
|
1417
|
-
process.exit(1);
|
|
1418
|
-
}
|
|
1419
|
-
const { create } = await import('./creator.GK6I-cL4.js');
|
|
1346
|
+
if (project !== "browser") console.error(/* @__PURE__ */ new Error("Only the \"browser\" project is supported. Use \"vitest init browser\" to create a new project.")), process.exit(1);
|
|
1347
|
+
const { create } = await import('./creator.08Gi-vCA.js');
|
|
1420
1348
|
await create();
|
|
1421
1349
|
}
|
|
1422
1350
|
async function collect(mode, cliFilters, options) {
|
|
1423
1351
|
try {
|
|
1424
|
-
|
|
1425
|
-
} catch {}
|
|
1426
|
-
try {
|
|
1427
|
-
const { prepareVitest, processCollected, outputFileList } = await import('./cli-api.Dn5gKePv.js').then(function (n) { return n.f; });
|
|
1428
|
-
const ctx = await prepareVitest(mode, {
|
|
1352
|
+
const { prepareVitest, processCollected, outputFileList } = await import('./cli-api.BJJXh9BV.js').then(function (n) { return n.j; }), ctx = await prepareVitest(mode, {
|
|
1429
1353
|
...normalizeCliOptions(cliFilters, options),
|
|
1430
1354
|
watch: false,
|
|
1431
1355
|
run: true
|
|
1432
|
-
});
|
|
1356
|
+
}, void 0, void 0, cliFilters);
|
|
1433
1357
|
if (!options.filesOnly) {
|
|
1434
1358
|
const { testModules: tests, unhandledErrors: errors } = await ctx.collect(cliFilters.map(normalize));
|
|
1435
1359
|
if (errors.length) {
|
|
1436
|
-
console.error("\nThere were unhandled errors during test collection");
|
|
1437
|
-
errors.forEach((e) => console.error(e));
|
|
1438
|
-
console.error("\n\n");
|
|
1439
|
-
await ctx.close();
|
|
1360
|
+
console.error("\nThere were unhandled errors during test collection"), errors.forEach((e) => console.error(e)), console.error("\n\n"), await ctx.close();
|
|
1440
1361
|
return;
|
|
1441
1362
|
}
|
|
1442
1363
|
processCollected(ctx, tests, options);
|
|
@@ -1446,11 +1367,8 @@ async function collect(mode, cliFilters, options) {
|
|
|
1446
1367
|
}
|
|
1447
1368
|
await ctx.close();
|
|
1448
1369
|
} catch (e) {
|
|
1449
|
-
const { errorBanner } = await import('./index.
|
|
1450
|
-
console.error(`\n${errorBanner("Collect Error")}`);
|
|
1451
|
-
console.error(e);
|
|
1452
|
-
console.error("\n\n");
|
|
1453
|
-
if (process.exitCode == null) process.exitCode = 1;
|
|
1370
|
+
const { errorBanner } = await import('./index.BIP7prJq.js').then(function (n) { return n.u; });
|
|
1371
|
+
if (console.error(`\n${errorBanner("Collect Error")}`), console.error(e), console.error("\n\n"), process.exitCode == null) process.exitCode = 1;
|
|
1454
1372
|
process.exit();
|
|
1455
1373
|
}
|
|
1456
1374
|
}
|