vitest 3.1.0-beta.1 → 3.1.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 (88) hide show
  1. package/LICENSE.md +29 -0
  2. package/dist/browser.js +4 -4
  3. package/dist/chunks/base.bV8rwssx.js +41 -0
  4. package/dist/chunks/benchmark.BKUatJGy.js +39 -0
  5. package/dist/chunks/cac.1WcTh-zl.js +1529 -0
  6. package/dist/chunks/{cli-api.BwkkJsRe.js → cli-api.2yb7XCwB.js} +4640 -5072
  7. package/dist/chunks/console.D6t261w0.js +173 -0
  8. package/dist/chunks/constants.BZZyIeIE.js +43 -0
  9. package/dist/chunks/coverage.0iPg4Wrz.js +33 -0
  10. package/dist/chunks/{coverage.gV8doR2Y.js → coverage.SfnlalVs.js} +2424 -2482
  11. package/dist/chunks/creator.CuL7xDWI.js +705 -0
  12. package/dist/chunks/date.CDOsz-HY.js +53 -0
  13. package/dist/chunks/defaults.DmfNPoe5.js +114 -0
  14. package/dist/chunks/{env.D4Lgay0q.js → env.Dq0hM4Xv.js} +1 -1
  15. package/dist/chunks/execute.CwmnH2oH.js +791 -0
  16. package/dist/chunks/git.DXfdBEfR.js +74 -0
  17. package/dist/chunks/{globals.BEpDe-k3.js → globals.DCbUWjip.js} +10 -10
  18. package/dist/chunks/{index.D7Ny8f_s.js → index.BDobFbcz.js} +6 -7
  19. package/dist/chunks/index.CwHmn5H5.js +2422 -0
  20. package/dist/chunks/index.DFXFpH3w.js +607 -0
  21. package/dist/chunks/index.VfYQ6MXY.js +104 -0
  22. package/dist/chunks/inspector.DbDkSkFn.js +54 -0
  23. package/dist/chunks/node.IqGoMrm4.js +15 -0
  24. package/dist/chunks/{reporters.d.r7poTZjA.d.ts → reporters.d.CfRkRKN2.d.ts} +52 -20
  25. package/dist/chunks/rpc.DGgL5dw7.js +92 -0
  26. package/dist/chunks/run-once.I7PpBOk1.js +47 -0
  27. package/dist/chunks/runBaseTests.CqmKSG99.js +134 -0
  28. package/dist/chunks/setup-common.DEGDGBiA.js +88 -0
  29. package/dist/chunks/{typechecker.BlF3eHsb.js → typechecker.CG0zmr19.js} +620 -622
  30. package/dist/chunks/utils.BfxieIyZ.js +66 -0
  31. package/dist/chunks/utils.CtocqOoE.js +72 -0
  32. package/dist/chunks/utils.Lot3J_8U.js +194 -0
  33. package/dist/chunks/{vi.nSCvwQ7l.js → vi.B-PuvDzu.js} +878 -1019
  34. package/dist/chunks/vite.d.4pkSbgmp.d.ts +23 -0
  35. package/dist/chunks/vm.Lp7mPCVW.js +796 -0
  36. package/dist/cli.js +2 -2
  37. package/dist/config.cjs +97 -103
  38. package/dist/config.d.ts +6 -4
  39. package/dist/config.js +6 -6
  40. package/dist/coverage.d.ts +2 -1
  41. package/dist/coverage.js +7 -7
  42. package/dist/environments.js +1 -1
  43. package/dist/execute.d.ts +0 -2
  44. package/dist/execute.js +1 -1
  45. package/dist/index.d.ts +6 -5
  46. package/dist/index.js +6 -6
  47. package/dist/node.d.ts +17 -6
  48. package/dist/node.js +36 -45
  49. package/dist/path.js +1 -4
  50. package/dist/reporters.d.ts +2 -1
  51. package/dist/reporters.js +4 -4
  52. package/dist/runners.js +231 -267
  53. package/dist/snapshot.js +2 -2
  54. package/dist/suite.js +2 -2
  55. package/dist/worker.js +98 -114
  56. package/dist/workers/forks.js +22 -22
  57. package/dist/workers/runVmTests.js +61 -66
  58. package/dist/workers/threads.js +13 -13
  59. package/dist/workers/vmForks.js +24 -24
  60. package/dist/workers/vmThreads.js +15 -15
  61. package/dist/workers.d.ts +2 -1
  62. package/dist/workers.js +10 -10
  63. package/package.json +17 -17
  64. package/dist/chunks/base.DV59CbtV.js +0 -45
  65. package/dist/chunks/benchmark.DL72EVN-.js +0 -40
  66. package/dist/chunks/cac.BjmXy7OV.js +0 -1664
  67. package/dist/chunks/console.CN7AiMGV.js +0 -179
  68. package/dist/chunks/constants.DTYd6dNH.js +0 -46
  69. package/dist/chunks/coverage.A3sS5-Wm.js +0 -40
  70. package/dist/chunks/creator.BsBnpTzI.js +0 -670
  71. package/dist/chunks/date.W2xKR2qe.js +0 -53
  72. package/dist/chunks/defaults.C2Ndd9wx.js +0 -119
  73. package/dist/chunks/execute.eDH0aFFd.js +0 -839
  74. package/dist/chunks/git.B5SDxu-n.js +0 -69
  75. package/dist/chunks/index.DOyx6FYJ.js +0 -2551
  76. package/dist/chunks/index.K90BXFOx.js +0 -658
  77. package/dist/chunks/index.uXkkC4xl.js +0 -111
  78. package/dist/chunks/inspector.DKLceBVD.js +0 -54
  79. package/dist/chunks/node.AKq966Jp.js +0 -15
  80. package/dist/chunks/rpc.TVf73xOu.js +0 -102
  81. package/dist/chunks/run-once.2ogXb3JV.js +0 -28
  82. package/dist/chunks/runBaseTests.BVrL_ow3.js +0 -142
  83. package/dist/chunks/setup-common.CPvtqi8q.js +0 -96
  84. package/dist/chunks/utils.C8RiOc4B.js +0 -77
  85. package/dist/chunks/utils.Cn0zI1t3.js +0 -68
  86. package/dist/chunks/utils.bLM2atbD.js +0 -198
  87. package/dist/chunks/vite.d.Fvq-NZoa.d.ts +0 -11
  88. package/dist/chunks/vm.jEFQDlX_.js +0 -852
@@ -0,0 +1,1529 @@
1
+ import { toArray } from '@vitest/utils';
2
+ import { EventEmitter } from 'events';
3
+ import { normalize } from 'pathe';
4
+ import c from 'tinyrainbow';
5
+ import { a as defaultPort, d as defaultBrowserPort } from './constants.BZZyIeIE.js';
6
+
7
+ function toArr(any) {
8
+ return any == null ? [] : Array.isArray(any) ? any : [any];
9
+ }
10
+
11
+ function toVal(out, key, val, opts) {
12
+ var x, old=out[key], nxt=(
13
+ !!~opts.string.indexOf(key) ? (val == null || val === true ? '' : String(val))
14
+ : typeof val === 'boolean' ? val
15
+ : !!~opts.boolean.indexOf(key) ? (val === 'false' ? false : val === 'true' || (out._.push((x = +val,x * 0 === 0) ? x : val),!!val))
16
+ : (x = +val,x * 0 === 0) ? x : val
17
+ );
18
+ out[key] = old == null ? nxt : (Array.isArray(old) ? old.concat(nxt) : [old, nxt]);
19
+ }
20
+
21
+ function mri2 (args, opts) {
22
+ args = args || [];
23
+ opts = opts || {};
24
+
25
+ var k, arr, arg, name, val, out={ _:[] };
26
+ var i=0, j=0, idx=0, len=args.length;
27
+
28
+ const alibi = opts.alias !== void 0;
29
+ const strict = opts.unknown !== void 0;
30
+ const defaults = opts.default !== void 0;
31
+
32
+ opts.alias = opts.alias || {};
33
+ opts.string = toArr(opts.string);
34
+ opts.boolean = toArr(opts.boolean);
35
+
36
+ if (alibi) {
37
+ for (k in opts.alias) {
38
+ arr = opts.alias[k] = toArr(opts.alias[k]);
39
+ for (i=0; i < arr.length; i++) {
40
+ (opts.alias[arr[i]] = arr.concat(k)).splice(i, 1);
41
+ }
42
+ }
43
+ }
44
+
45
+ for (i=opts.boolean.length; i-- > 0;) {
46
+ arr = opts.alias[opts.boolean[i]] || [];
47
+ for (j=arr.length; j-- > 0;) opts.boolean.push(arr[j]);
48
+ }
49
+
50
+ for (i=opts.string.length; i-- > 0;) {
51
+ arr = opts.alias[opts.string[i]] || [];
52
+ for (j=arr.length; j-- > 0;) opts.string.push(arr[j]);
53
+ }
54
+
55
+ if (defaults) {
56
+ for (k in opts.default) {
57
+ name = typeof opts.default[k];
58
+ arr = opts.alias[k] = opts.alias[k] || [];
59
+ if (opts[name] !== void 0) {
60
+ opts[name].push(k);
61
+ for (i=0; i < arr.length; i++) {
62
+ opts[name].push(arr[i]);
63
+ }
64
+ }
65
+ }
66
+ }
67
+
68
+ const keys = strict ? Object.keys(opts.alias) : [];
69
+
70
+ for (i=0; i < len; i++) {
71
+ arg = args[i];
72
+
73
+ if (arg === '--') {
74
+ out._ = out._.concat(args.slice(++i));
75
+ break;
76
+ }
77
+
78
+ for (j=0; j < arg.length; j++) {
79
+ if (arg.charCodeAt(j) !== 45) break; // "-"
80
+ }
81
+
82
+ if (j === 0) {
83
+ out._.push(arg);
84
+ } else if (arg.substring(j, j + 3) === 'no-') {
85
+ name = arg.substring(j + 3);
86
+ if (strict && !~keys.indexOf(name)) {
87
+ return opts.unknown(arg);
88
+ }
89
+ out[name] = false;
90
+ } else {
91
+ for (idx=j+1; idx < arg.length; idx++) {
92
+ if (arg.charCodeAt(idx) === 61) break; // "="
93
+ }
94
+
95
+ name = arg.substring(j, idx);
96
+ val = arg.substring(++idx) || (i+1 === len || (''+args[i+1]).charCodeAt(0) === 45 || args[++i]);
97
+ arr = (j === 2 ? [name] : name);
98
+
99
+ for (idx=0; idx < arr.length; idx++) {
100
+ name = arr[idx];
101
+ if (strict && !~keys.indexOf(name)) return opts.unknown('-'.repeat(j) + name);
102
+ toVal(out, name, (idx + 1 < arr.length) || val, opts);
103
+ }
104
+ }
105
+ }
106
+
107
+ if (defaults) {
108
+ for (k in opts.default) {
109
+ if (out[k] === void 0) {
110
+ out[k] = opts.default[k];
111
+ }
112
+ }
113
+ }
114
+
115
+ if (alibi) {
116
+ for (k in out) {
117
+ arr = opts.alias[k] || [];
118
+ while (arr.length > 0) {
119
+ out[arr.shift()] = out[k];
120
+ }
121
+ }
122
+ }
123
+
124
+ return out;
125
+ }
126
+
127
+ const removeBrackets = (v) => v.replace(/[<[].+/, "").trim();
128
+ const findAllBrackets = (v) => {
129
+ const ANGLED_BRACKET_RE_GLOBAL = /<([^>]+)>/g;
130
+ const SQUARE_BRACKET_RE_GLOBAL = /\[([^\]]+)\]/g;
131
+ const res = [];
132
+ const parse = (match) => {
133
+ let variadic = false;
134
+ let value = match[1];
135
+ if (value.startsWith("...")) {
136
+ value = value.slice(3);
137
+ variadic = true;
138
+ }
139
+ return {
140
+ required: match[0].startsWith("<"),
141
+ value,
142
+ variadic
143
+ };
144
+ };
145
+ let angledMatch;
146
+ while (angledMatch = ANGLED_BRACKET_RE_GLOBAL.exec(v)) {
147
+ res.push(parse(angledMatch));
148
+ }
149
+ let squareMatch;
150
+ while (squareMatch = SQUARE_BRACKET_RE_GLOBAL.exec(v)) {
151
+ res.push(parse(squareMatch));
152
+ }
153
+ return res;
154
+ };
155
+ const getMriOptions = (options) => {
156
+ const result = {alias: {}, boolean: []};
157
+ for (const [index, option] of options.entries()) {
158
+ if (option.names.length > 1) {
159
+ result.alias[option.names[0]] = option.names.slice(1);
160
+ }
161
+ if (option.isBoolean) {
162
+ if (option.negated) {
163
+ const hasStringTypeOption = options.some((o, i) => {
164
+ return i !== index && o.names.some((name) => option.names.includes(name)) && typeof o.required === "boolean";
165
+ });
166
+ if (!hasStringTypeOption) {
167
+ result.boolean.push(option.names[0]);
168
+ }
169
+ } else {
170
+ result.boolean.push(option.names[0]);
171
+ }
172
+ }
173
+ }
174
+ return result;
175
+ };
176
+ const findLongest = (arr) => {
177
+ return arr.sort((a, b) => {
178
+ return a.length > b.length ? -1 : 1;
179
+ })[0];
180
+ };
181
+ const padRight = (str, length) => {
182
+ return str.length >= length ? str : `${str}${" ".repeat(length - str.length)}`;
183
+ };
184
+ const camelcase = (input) => {
185
+ return input.replace(/([a-z])-([a-z])/g, (_, p1, p2) => {
186
+ return p1 + p2.toUpperCase();
187
+ });
188
+ };
189
+ const setDotProp = (obj, keys, val, transforms) => {
190
+ let i = 0;
191
+ let length = keys.length;
192
+ let t = obj;
193
+ let x;
194
+ let convertKey = (i) => {
195
+ let key = keys[i];
196
+ i--;
197
+ while(i >= 0) {
198
+ key = keys[i] + '.' + key;
199
+ i--;
200
+ }
201
+ return key
202
+ };
203
+ for (; i < length; ++i) {
204
+ x = t[keys[i]];
205
+ const transform = transforms[convertKey(i)] || ((v) => v);
206
+ t = t[keys[i]] = transform(i === length - 1 ? val : x != null ? x : !!~keys[i + 1].indexOf(".") || !(+keys[i + 1] > -1) ? {} : []);
207
+ }
208
+ };
209
+ const getFileName = (input) => {
210
+ const m = /([^\\\/]+)$/.exec(input);
211
+ return m ? m[1] : "";
212
+ };
213
+ const camelcaseOptionName = (name) => {
214
+ return name.split(".").map((v, i) => {
215
+ return i === 0 ? camelcase(v) : v;
216
+ }).join(".");
217
+ };
218
+ class CACError extends Error {
219
+ constructor(message) {
220
+ super(message);
221
+ this.name = this.constructor.name;
222
+ if (typeof Error.captureStackTrace === "function") {
223
+ Error.captureStackTrace(this, this.constructor);
224
+ } else {
225
+ this.stack = new Error(message).stack;
226
+ }
227
+ }
228
+ }
229
+
230
+ class Option {
231
+ constructor(rawName, description, config) {
232
+ this.rawName = rawName;
233
+ this.description = description;
234
+ this.config = Object.assign({}, config);
235
+ rawName = rawName.replace(/\.\*/g, "");
236
+ this.negated = false;
237
+ this.names = removeBrackets(rawName).split(",").map((v) => {
238
+ let name = v.trim().replace(/^-{1,2}/, "");
239
+ if (name.startsWith("no-")) {
240
+ this.negated = true;
241
+ name = name.replace(/^no-/, "");
242
+ }
243
+ return camelcaseOptionName(name);
244
+ }).sort((a, b) => a.length > b.length ? 1 : -1);
245
+ this.name = this.names[this.names.length - 1];
246
+ if (this.negated && this.config.default == null) {
247
+ this.config.default = true;
248
+ }
249
+ if (rawName.includes("<")) {
250
+ this.required = true;
251
+ } else if (rawName.includes("[")) {
252
+ this.required = false;
253
+ } else {
254
+ this.isBoolean = true;
255
+ }
256
+ }
257
+ }
258
+
259
+ const processArgs = process.argv;
260
+ const platformInfo = `${process.platform}-${process.arch} node-${process.version}`;
261
+
262
+ class Command {
263
+ constructor(rawName, description, config = {}, cli) {
264
+ this.rawName = rawName;
265
+ this.description = description;
266
+ this.config = config;
267
+ this.cli = cli;
268
+ this.options = [];
269
+ this.aliasNames = [];
270
+ this.name = removeBrackets(rawName);
271
+ this.args = findAllBrackets(rawName);
272
+ this.examples = [];
273
+ }
274
+ usage(text) {
275
+ this.usageText = text;
276
+ return this;
277
+ }
278
+ allowUnknownOptions() {
279
+ this.config.allowUnknownOptions = true;
280
+ return this;
281
+ }
282
+ ignoreOptionDefaultValue() {
283
+ this.config.ignoreOptionDefaultValue = true;
284
+ return this;
285
+ }
286
+ version(version, customFlags = "-v, --version") {
287
+ this.versionNumber = version;
288
+ this.option(customFlags, "Display version number");
289
+ return this;
290
+ }
291
+ example(example) {
292
+ this.examples.push(example);
293
+ return this;
294
+ }
295
+ option(rawName, description, config) {
296
+ const option = new Option(rawName, description, config);
297
+ this.options.push(option);
298
+ return this;
299
+ }
300
+ alias(name) {
301
+ this.aliasNames.push(name);
302
+ return this;
303
+ }
304
+ action(callback) {
305
+ this.commandAction = callback;
306
+ return this;
307
+ }
308
+ isMatched(name) {
309
+ return this.name === name || this.aliasNames.includes(name);
310
+ }
311
+ get isDefaultCommand() {
312
+ return this.name === "" || this.aliasNames.includes("!");
313
+ }
314
+ get isGlobalCommand() {
315
+ return this instanceof GlobalCommand;
316
+ }
317
+ hasOption(name) {
318
+ name = name.split(".")[0];
319
+ return this.options.find((option) => {
320
+ return option.names.includes(name);
321
+ });
322
+ }
323
+ outputHelp() {
324
+ const {name, commands} = this.cli;
325
+ const {
326
+ versionNumber,
327
+ options: globalOptions,
328
+ helpCallback
329
+ } = this.cli.globalCommand;
330
+ let sections = [
331
+ {
332
+ body: `${name}${versionNumber ? `/${versionNumber}` : ""}`
333
+ }
334
+ ];
335
+ sections.push({
336
+ title: "Usage",
337
+ body: ` $ ${name} ${this.usageText || this.rawName}`
338
+ });
339
+ const showCommands = (this.isGlobalCommand || this.isDefaultCommand) && commands.length > 0;
340
+ if (showCommands) {
341
+ const longestCommandName = findLongest(commands.map((command) => command.rawName));
342
+ sections.push({
343
+ title: "Commands",
344
+ body: commands.map((command) => {
345
+ return ` ${padRight(command.rawName, longestCommandName.length)} ${command.description}`;
346
+ }).join("\n")
347
+ });
348
+ sections.push({
349
+ title: `For more info, run any command with the \`--help\` flag`,
350
+ body: commands.map((command) => ` $ ${name}${command.name === "" ? "" : ` ${command.name}`} --help`).join("\n")
351
+ });
352
+ }
353
+ let options = this.isGlobalCommand ? globalOptions : [...this.options, ...globalOptions || []];
354
+ if (!this.isGlobalCommand && !this.isDefaultCommand) {
355
+ options = options.filter((option) => option.name !== "version");
356
+ }
357
+ if (options.length > 0) {
358
+ const longestOptionName = findLongest(options.map((option) => option.rawName));
359
+ sections.push({
360
+ title: "Options",
361
+ body: options.map((option) => {
362
+ return ` ${padRight(option.rawName, longestOptionName.length)} ${option.description} ${option.config.default === void 0 ? "" : `(default: ${option.config.default})`}`;
363
+ }).join("\n")
364
+ });
365
+ }
366
+ if (this.examples.length > 0) {
367
+ sections.push({
368
+ title: "Examples",
369
+ body: this.examples.map((example) => {
370
+ if (typeof example === "function") {
371
+ return example(name);
372
+ }
373
+ return example;
374
+ }).join("\n")
375
+ });
376
+ }
377
+ if (helpCallback) {
378
+ sections = helpCallback(sections) || sections;
379
+ }
380
+ console.log(sections.map((section) => {
381
+ return section.title ? `${section.title}:
382
+ ${section.body}` : section.body;
383
+ }).join("\n\n"));
384
+ }
385
+ outputVersion() {
386
+ const {name} = this.cli;
387
+ const {versionNumber} = this.cli.globalCommand;
388
+ if (versionNumber) {
389
+ console.log(`${name}/${versionNumber} ${platformInfo}`);
390
+ }
391
+ }
392
+ checkRequiredArgs() {
393
+ const minimalArgsCount = this.args.filter((arg) => arg.required).length;
394
+ if (this.cli.args.length < minimalArgsCount) {
395
+ throw new CACError(`missing required args for command \`${this.rawName}\``);
396
+ }
397
+ }
398
+ checkUnknownOptions() {
399
+ const {options, globalCommand} = this.cli;
400
+ if (!this.config.allowUnknownOptions) {
401
+ for (const name of Object.keys(options)) {
402
+ if (name !== "--" && !this.hasOption(name) && !globalCommand.hasOption(name)) {
403
+ throw new CACError(`Unknown option \`${name.length > 1 ? `--${name}` : `-${name}`}\``);
404
+ }
405
+ }
406
+ }
407
+ }
408
+ checkOptionValue() {
409
+ const {options: parsedOptions, globalCommand} = this.cli;
410
+ const options = [...globalCommand.options, ...this.options];
411
+ for (const option of options) {
412
+ // skip dot names because only top level options are required
413
+ if (option.name.includes('.')) {
414
+ continue;
415
+ }
416
+ const value = parsedOptions[option.name];
417
+ if (option.required) {
418
+ const hasNegated = options.some((o) => o.negated && o.names.includes(option.name));
419
+ if (value === true || value === false && !hasNegated) {
420
+ throw new CACError(`option \`${option.rawName}\` value is missing`);
421
+ }
422
+ }
423
+ }
424
+ }
425
+ }
426
+ class GlobalCommand extends Command {
427
+ constructor(cli) {
428
+ super("@@global@@", "", {}, cli);
429
+ }
430
+ }
431
+
432
+ var __assign = Object.assign;
433
+ class CAC extends EventEmitter {
434
+ constructor(name = "") {
435
+ super();
436
+ this.name = name;
437
+ this.commands = [];
438
+ this.rawArgs = [];
439
+ this.args = [];
440
+ this.options = {};
441
+ this.globalCommand = new GlobalCommand(this);
442
+ this.globalCommand.usage("<command> [options]");
443
+ }
444
+ usage(text) {
445
+ this.globalCommand.usage(text);
446
+ return this;
447
+ }
448
+ command(rawName, description, config) {
449
+ const command = new Command(rawName, description || "", config, this);
450
+ command.globalCommand = this.globalCommand;
451
+ this.commands.push(command);
452
+ return command;
453
+ }
454
+ option(rawName, description, config) {
455
+ this.globalCommand.option(rawName, description, config);
456
+ return this;
457
+ }
458
+ help(callback) {
459
+ this.globalCommand.option("-h, --help", "Display this message");
460
+ this.globalCommand.helpCallback = callback;
461
+ this.showHelpOnExit = true;
462
+ return this;
463
+ }
464
+ version(version, customFlags = "-v, --version") {
465
+ this.globalCommand.version(version, customFlags);
466
+ this.showVersionOnExit = true;
467
+ return this;
468
+ }
469
+ example(example) {
470
+ this.globalCommand.example(example);
471
+ return this;
472
+ }
473
+ outputHelp() {
474
+ if (this.matchedCommand) {
475
+ this.matchedCommand.outputHelp();
476
+ } else {
477
+ this.globalCommand.outputHelp();
478
+ }
479
+ }
480
+ outputVersion() {
481
+ this.globalCommand.outputVersion();
482
+ }
483
+ setParsedInfo({args, options}, matchedCommand, matchedCommandName) {
484
+ this.args = args;
485
+ this.options = options;
486
+ if (matchedCommand) {
487
+ this.matchedCommand = matchedCommand;
488
+ }
489
+ if (matchedCommandName) {
490
+ this.matchedCommandName = matchedCommandName;
491
+ }
492
+ return this;
493
+ }
494
+ unsetMatchedCommand() {
495
+ this.matchedCommand = void 0;
496
+ this.matchedCommandName = void 0;
497
+ }
498
+ parse(argv = processArgs, {
499
+ run = true
500
+ } = {}) {
501
+ this.rawArgs = argv;
502
+ if (!this.name) {
503
+ this.name = argv[1] ? getFileName(argv[1]) : "cli";
504
+ }
505
+ let shouldParse = true;
506
+ for (const command of this.commands) {
507
+ const parsed = this.mri(argv.slice(2), command);
508
+ const commandName = parsed.args[0];
509
+ if (command.isMatched(commandName)) {
510
+ shouldParse = false;
511
+ const parsedInfo = __assign(__assign({}, parsed), {
512
+ args: parsed.args.slice(1)
513
+ });
514
+ this.setParsedInfo(parsedInfo, command, commandName);
515
+ this.emit(`command:${commandName}`, command);
516
+ }
517
+ }
518
+ if (shouldParse) {
519
+ for (const command of this.commands) {
520
+ if (command.name === "") {
521
+ shouldParse = false;
522
+ const parsed = this.mri(argv.slice(2), command);
523
+ this.setParsedInfo(parsed, command);
524
+ this.emit(`command:!`, command);
525
+ }
526
+ }
527
+ }
528
+ if (shouldParse) {
529
+ const parsed = this.mri(argv.slice(2));
530
+ this.setParsedInfo(parsed);
531
+ }
532
+ if (this.options.help && this.showHelpOnExit) {
533
+ this.outputHelp();
534
+ run = false;
535
+ this.unsetMatchedCommand();
536
+ }
537
+ if (this.options.version && this.showVersionOnExit && this.matchedCommandName == null) {
538
+ this.outputVersion();
539
+ run = false;
540
+ this.unsetMatchedCommand();
541
+ }
542
+ const parsedArgv = {args: this.args, options: this.options};
543
+ if (run) {
544
+ this.runMatchedCommand();
545
+ }
546
+ if (!this.matchedCommand && this.args[0]) {
547
+ this.emit("command:*");
548
+ }
549
+ return parsedArgv;
550
+ }
551
+ mri(argv, command) {
552
+ const cliOptions = [
553
+ ...this.globalCommand.options,
554
+ ...command ? command.options : []
555
+ ];
556
+ const mriOptions = getMriOptions(cliOptions);
557
+ let argsAfterDoubleDashes = [];
558
+ const doubleDashesIndex = argv.indexOf("--");
559
+ if (doubleDashesIndex > -1) {
560
+ argsAfterDoubleDashes = argv.slice(doubleDashesIndex + 1);
561
+ argv = argv.slice(0, doubleDashesIndex);
562
+ }
563
+ let parsed = mri2(argv, mriOptions);
564
+ parsed = Object.keys(parsed).reduce((res, name) => {
565
+ return __assign(__assign({}, res), {
566
+ [camelcaseOptionName(name)]: parsed[name]
567
+ });
568
+ }, {_: []});
569
+ const args = parsed._;
570
+ const options = {
571
+ "--": argsAfterDoubleDashes
572
+ };
573
+ const ignoreDefault = command && command.config.ignoreOptionDefaultValue ? command.config.ignoreOptionDefaultValue : this.globalCommand.config.ignoreOptionDefaultValue;
574
+ let transforms = Object.create(null);
575
+ for (const cliOption of cliOptions) {
576
+ if (!ignoreDefault && cliOption.config.default !== void 0) {
577
+ for (const name of cliOption.names) {
578
+ options[name] = cliOption.config.default;
579
+ }
580
+ }
581
+ if (cliOption.config.type != null) {
582
+ if (transforms[cliOption.name] === void 0) {
583
+ transforms[cliOption.name] = cliOption.config.type;
584
+ }
585
+ }
586
+ }
587
+ for (const key of Object.keys(parsed)) {
588
+ if (key !== "_") {
589
+ const keys = key.split(".");
590
+ setDotProp(options, keys, parsed[key], transforms);
591
+ // setByType(options, transforms);
592
+ }
593
+ }
594
+ return {
595
+ args,
596
+ options
597
+ };
598
+ }
599
+ runMatchedCommand() {
600
+ const {args, options, matchedCommand: command} = this;
601
+ if (!command || !command.commandAction)
602
+ return;
603
+ command.checkUnknownOptions();
604
+ command.checkOptionValue();
605
+ command.checkRequiredArgs();
606
+ const actionArgs = [];
607
+ command.args.forEach((arg, index) => {
608
+ if (arg.variadic) {
609
+ actionArgs.push(args.slice(index));
610
+ } else {
611
+ actionArgs.push(args[index]);
612
+ }
613
+ });
614
+ actionArgs.push(options);
615
+ return command.commandAction.apply(this, actionArgs);
616
+ }
617
+ }
618
+
619
+ const cac = (name = "") => new CAC(name);
620
+
621
+ var version = "3.1.0";
622
+
623
+ const apiConfig = (port) => ({
624
+ port: {
625
+ description: `Specify server port. Note if the port is already being used, Vite will automatically try the next available port so this may not be the actual port the server ends up listening on. If true will be set to \`${port}\``,
626
+ argument: "[port]"
627
+ },
628
+ host: {
629
+ description: "Specify which IP addresses the server should listen on. Set this to `0.0.0.0` or `true` to listen on all addresses, including LAN and public addresses",
630
+ argument: "[host]"
631
+ },
632
+ strictPort: { description: "Set to true to exit if port is already in use, instead of automatically trying the next available port" },
633
+ middlewareMode: null
634
+ });
635
+ const poolThreadsCommands = {
636
+ isolate: { description: "Isolate tests in threads pool (default: `true`)" },
637
+ singleThread: { description: "Run tests inside a single thread (default: `false`)" },
638
+ maxThreads: {
639
+ description: "Maximum number or percentage of threads to run tests in",
640
+ argument: "<workers>"
641
+ },
642
+ minThreads: {
643
+ description: "Minimum number or percentage of threads to run tests in",
644
+ argument: "<workers>"
645
+ },
646
+ useAtomics: { description: "Use Atomics to synchronize threads. This can improve performance in some cases, but might cause segfault in older Node versions (default: `false`)" },
647
+ execArgv: null
648
+ };
649
+ const poolForksCommands = {
650
+ isolate: { description: "Isolate tests in forks pool (default: `true`)" },
651
+ singleFork: { description: "Run tests inside a single child_process (default: `false`)" },
652
+ maxForks: {
653
+ description: "Maximum number or percentage of processes to run tests in",
654
+ argument: "<workers>"
655
+ },
656
+ minForks: {
657
+ description: "Minimum number or percentage of processes to run tests in",
658
+ argument: "<workers>"
659
+ },
660
+ execArgv: null
661
+ };
662
+ function watermarkTransform(value) {
663
+ if (typeof value === "string") {
664
+ return value.split(",").map(Number);
665
+ }
666
+ return value;
667
+ }
668
+ function transformNestedBoolean(value) {
669
+ if (typeof value === "boolean") {
670
+ return { enabled: value };
671
+ }
672
+ return value;
673
+ }
674
+ const cliOptionsConfig = {
675
+ root: {
676
+ description: "Root path",
677
+ shorthand: "r",
678
+ argument: "<path>",
679
+ normalize: true
680
+ },
681
+ config: {
682
+ shorthand: "c",
683
+ description: "Path to config file",
684
+ argument: "<path>",
685
+ normalize: true
686
+ },
687
+ update: {
688
+ shorthand: "u",
689
+ description: "Update snapshot"
690
+ },
691
+ watch: {
692
+ shorthand: "w",
693
+ description: "Enable watch mode"
694
+ },
695
+ testNamePattern: {
696
+ description: "Run tests with full names matching the specified regexp pattern",
697
+ argument: "<pattern>",
698
+ shorthand: "t"
699
+ },
700
+ dir: {
701
+ description: "Base directory to scan for the test files",
702
+ argument: "<path>",
703
+ normalize: true
704
+ },
705
+ ui: { description: "Enable UI" },
706
+ open: { description: "Open UI automatically (default: `!process.env.CI`)" },
707
+ api: {
708
+ argument: "[port]",
709
+ description: `Specify server port. Note if the port is already being used, Vite will automatically try the next available port so this may not be the actual port the server ends up listening on. If true will be set to ${defaultPort}`,
710
+ subcommands: apiConfig(defaultPort)
711
+ },
712
+ silent: {
713
+ description: "Silent console output from tests. Use `'passed-only'` to see logs from failing tests only.",
714
+ argument: "[value]"
715
+ },
716
+ hideSkippedTests: { description: "Hide logs for skipped tests" },
717
+ reporters: {
718
+ alias: "reporter",
719
+ description: "Specify reporters",
720
+ argument: "<name>",
721
+ subcommands: null,
722
+ array: true
723
+ },
724
+ outputFile: {
725
+ argument: "<filename/-s>",
726
+ description: "Write test results to a file when supporter reporter is also specified, use cac's dot notation for individual outputs of multiple reporters (example: `--outputFile.tap=./tap.txt`)",
727
+ subcommands: null
728
+ },
729
+ coverage: {
730
+ description: "Enable coverage report",
731
+ argument: "",
732
+ transform: transformNestedBoolean,
733
+ subcommands: {
734
+ all: {
735
+ description: "Whether to include all files, including the untested ones into report",
736
+ default: true
737
+ },
738
+ provider: {
739
+ description: "Select the tool for coverage collection, available values are: \"v8\", \"istanbul\" and \"custom\"",
740
+ argument: "<name>"
741
+ },
742
+ enabled: { description: "Enables coverage collection. Can be overridden using the `--coverage` CLI option (default: `false`)" },
743
+ include: {
744
+ description: "Files included in coverage as glob patterns. May be specified more than once when using multiple patterns (default: `**`)",
745
+ argument: "<pattern>",
746
+ array: true
747
+ },
748
+ exclude: {
749
+ description: "Files to be excluded in coverage. May be specified more than once when using multiple extensions (default: Visit [`coverage.exclude`](https://vitest.dev/config/#coverage-exclude))",
750
+ argument: "<pattern>",
751
+ array: true
752
+ },
753
+ extension: {
754
+ description: "Extension to be included in coverage. May be specified more than once when using multiple extensions (default: `[\".js\", \".cjs\", \".mjs\", \".ts\", \".mts\", \".tsx\", \".jsx\", \".vue\", \".svelte\"]`)",
755
+ argument: "<extension>",
756
+ array: true
757
+ },
758
+ clean: { description: "Clean coverage results before running tests (default: true)" },
759
+ cleanOnRerun: { description: "Clean coverage report on watch rerun (default: true)" },
760
+ reportsDirectory: {
761
+ description: "Directory to write coverage report to (default: ./coverage)",
762
+ argument: "<path>",
763
+ normalize: true
764
+ },
765
+ reporter: {
766
+ description: "Coverage reporters to use. Visit [`coverage.reporter`](https://vitest.dev/config/#coverage-reporter) for more information (default: `[\"text\", \"html\", \"clover\", \"json\"]`)",
767
+ argument: "<name>",
768
+ subcommands: null,
769
+ array: true
770
+ },
771
+ reportOnFailure: { description: "Generate coverage report even when tests fail (default: `false`)" },
772
+ allowExternal: { description: "Collect coverage of files outside the project root (default: `false`)" },
773
+ skipFull: { description: "Do not show files with 100% statement, branch, and function coverage (default: `false`)" },
774
+ thresholds: {
775
+ description: null,
776
+ argument: "",
777
+ subcommands: {
778
+ 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`)" },
779
+ autoUpdate: { description: "Update threshold values: \"lines\", \"functions\", \"branches\" and \"statements\" to configuration file when current coverage is above the configured thresholds (default: `false`)" },
780
+ lines: {
781
+ description: "Threshold for lines. Visit [istanbuljs](https://github.com/istanbuljs/nyc#coverage-thresholds) for more information. This option is not available for custom providers",
782
+ argument: "<number>"
783
+ },
784
+ functions: {
785
+ description: "Threshold for functions. Visit [istanbuljs](https://github.com/istanbuljs/nyc#coverage-thresholds) for more information. This option is not available for custom providers",
786
+ argument: "<number>"
787
+ },
788
+ branches: {
789
+ description: "Threshold for branches. Visit [istanbuljs](https://github.com/istanbuljs/nyc#coverage-thresholds) for more information. This option is not available for custom providers",
790
+ argument: "<number>"
791
+ },
792
+ statements: {
793
+ description: "Threshold for statements. Visit [istanbuljs](https://github.com/istanbuljs/nyc#coverage-thresholds) for more information. This option is not available for custom providers",
794
+ argument: "<number>"
795
+ },
796
+ 100: { description: "Shortcut to set all coverage thresholds to 100 (default: `false`)" }
797
+ }
798
+ },
799
+ ignoreClassMethods: {
800
+ description: "Array of class method names to ignore for coverage. Visit [istanbuljs](https://github.com/istanbuljs/nyc#ignoring-methods) for more information. This option is only available for the istanbul providers (default: `[]`)",
801
+ argument: "<name>",
802
+ array: true
803
+ },
804
+ processingConcurrency: {
805
+ description: "Concurrency limit used when processing the coverage results. (default min between 20 and the number of CPUs)",
806
+ argument: "<number>"
807
+ },
808
+ customProviderModule: {
809
+ description: "Specifies the module name or path for the custom coverage provider module. Visit [Custom Coverage Provider](https://vitest.dev/guide/coverage#custom-coverage-provider) for more information. This option is only available for custom providers",
810
+ argument: "<path>",
811
+ normalize: true
812
+ },
813
+ watermarks: {
814
+ description: null,
815
+ argument: "",
816
+ subcommands: {
817
+ statements: {
818
+ description: "High and low watermarks for statements in the format of `<high>,<low>`",
819
+ argument: "<watermarks>",
820
+ transform: watermarkTransform
821
+ },
822
+ lines: {
823
+ description: "High and low watermarks for lines in the format of `<high>,<low>`",
824
+ argument: "<watermarks>",
825
+ transform: watermarkTransform
826
+ },
827
+ branches: {
828
+ description: "High and low watermarks for branches in the format of `<high>,<low>`",
829
+ argument: "<watermarks>",
830
+ transform: watermarkTransform
831
+ },
832
+ functions: {
833
+ description: "High and low watermarks for functions in the format of `<high>,<low>`",
834
+ argument: "<watermarks>",
835
+ transform: watermarkTransform
836
+ }
837
+ }
838
+ }
839
+ }
840
+ },
841
+ mode: {
842
+ description: "Override Vite mode (default: `test` or `benchmark`)",
843
+ argument: "<name>"
844
+ },
845
+ workspace: {
846
+ description: "Path to a workspace configuration file",
847
+ argument: "<path>",
848
+ normalize: true
849
+ },
850
+ isolate: { description: "Run every test file in isolation. To disable isolation, use `--no-isolate` (default: `true`)" },
851
+ globals: { description: "Inject apis globally" },
852
+ dom: { description: "Mock browser API with happy-dom" },
853
+ browser: {
854
+ description: "Run tests in the browser. Equivalent to `--browser.enabled` (default: `false`)",
855
+ argument: "<name>",
856
+ transform(browser) {
857
+ if (typeof browser === "boolean") {
858
+ return { enabled: browser };
859
+ }
860
+ if (browser === "true" || browser === "false") {
861
+ return { enabled: browser === "true" };
862
+ }
863
+ if (browser === "yes" || browser === "no") {
864
+ return { enabled: browser === "yes" };
865
+ }
866
+ if (typeof browser === "string") {
867
+ return {
868
+ enabled: true,
869
+ name: browser
870
+ };
871
+ }
872
+ return browser;
873
+ },
874
+ subcommands: {
875
+ enabled: { description: "Run tests in the browser. Equivalent to `--browser.enabled` (default: `false`)" },
876
+ name: {
877
+ description: "Run all tests in a specific browser. Some browsers are only available for specific providers (see `--browser.provider`). Visit [`browser.name`](https://vitest.dev/guide/browser/config/#browser-name) for more information",
878
+ argument: "<name>"
879
+ },
880
+ 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`)" },
881
+ api: {
882
+ description: "Specify options for the browser API server. Does not affect the --api option",
883
+ argument: "[port]",
884
+ subcommands: apiConfig(defaultBrowserPort)
885
+ },
886
+ provider: {
887
+ 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 (default: `\"preview\"`)",
888
+ argument: "<name>",
889
+ subcommands: null
890
+ },
891
+ providerOptions: {
892
+ description: "Options that are passed down to a browser provider. Visit [`browser.providerOptions`](https://vitest.dev/config/#browser-provideroptions) for more information",
893
+ argument: "<options>",
894
+ subcommands: null
895
+ },
896
+ isolate: { description: "Run every browser test file in isolation. To disable isolation, use `--browser.isolate=false` (default: `true`)" },
897
+ ui: { description: "Show Vitest UI when running tests (default: `!process.env.CI`)" },
898
+ fileParallelism: { description: "Should browser test files run in parallel. Use `--browser.fileParallelism=false` to disable (default: `true`)" },
899
+ connectTimeout: {
900
+ description: "If connection to the browser takes longer, the test suite will fail (default: `60_000`)",
901
+ argument: "<timeout>"
902
+ },
903
+ orchestratorScripts: null,
904
+ testerScripts: null,
905
+ commands: null,
906
+ viewport: null,
907
+ screenshotDirectory: null,
908
+ screenshotFailures: null,
909
+ locators: null,
910
+ testerHtmlPath: null,
911
+ instances: null
912
+ }
913
+ },
914
+ pool: {
915
+ description: "Specify pool, if not running in the browser (default: `forks`)",
916
+ argument: "<pool>",
917
+ subcommands: null
918
+ },
919
+ poolOptions: {
920
+ description: "Specify pool options",
921
+ argument: "<options>",
922
+ subcommands: {
923
+ threads: {
924
+ description: "Specify threads pool options",
925
+ argument: "<options>",
926
+ subcommands: poolThreadsCommands
927
+ },
928
+ vmThreads: {
929
+ description: "Specify VM threads pool options",
930
+ argument: "<options>",
931
+ subcommands: {
932
+ ...poolThreadsCommands,
933
+ memoryLimit: {
934
+ description: "Memory limit for VM threads pool. If you see memory leaks, try to tinker this value.",
935
+ argument: "<limit>"
936
+ }
937
+ }
938
+ },
939
+ forks: {
940
+ description: "Specify forks pool options",
941
+ argument: "<options>",
942
+ subcommands: poolForksCommands
943
+ },
944
+ vmForks: {
945
+ description: "Specify VM forks pool options",
946
+ argument: "<options>",
947
+ subcommands: {
948
+ ...poolForksCommands,
949
+ memoryLimit: {
950
+ description: "Memory limit for VM forks pool. If you see memory leaks, try to tinker this value.",
951
+ argument: "<limit>"
952
+ }
953
+ }
954
+ }
955
+ }
956
+ },
957
+ fileParallelism: { description: "Should all test files run in parallel. Use `--no-file-parallelism` to disable (default: `true`)" },
958
+ maxWorkers: {
959
+ description: "Maximum number or percentage of workers to run tests in",
960
+ argument: "<workers>"
961
+ },
962
+ minWorkers: {
963
+ description: "Minimum number or percentage of workers to run tests in",
964
+ argument: "<workers>"
965
+ },
966
+ environment: {
967
+ description: "Specify runner environment, if not running in the browser (default: `node`)",
968
+ argument: "<name>",
969
+ subcommands: null
970
+ },
971
+ passWithNoTests: { description: "Pass when no tests are found" },
972
+ logHeapUsage: { description: "Show the size of heap for each test when running in node" },
973
+ allowOnly: { description: "Allow tests and suites that are marked as only (default: `!process.env.CI`)" },
974
+ dangerouslyIgnoreUnhandledErrors: { description: "Ignore any unhandled errors that occur" },
975
+ shard: {
976
+ description: "Test suite shard to execute in a format of `<index>/<count>`",
977
+ argument: "<shards>"
978
+ },
979
+ changed: {
980
+ description: "Run tests that are affected by the changed files (default: `false`)",
981
+ argument: "[since]"
982
+ },
983
+ sequence: {
984
+ description: "Options for how tests should be sorted",
985
+ argument: "<options>",
986
+ subcommands: {
987
+ shuffle: {
988
+ description: "Run files and tests in a random order. Enabling this option will impact Vitest's cache and have a performance impact. May be useful to find tests that accidentally depend on another run previously (default: `false`)",
989
+ argument: "",
990
+ subcommands: {
991
+ files: { description: "Run files in a random order. Long running tests will not start earlier if you enable this option. (default: `false`)" },
992
+ tests: { description: "Run tests in a random order (default: `false`)" }
993
+ }
994
+ },
995
+ concurrent: { description: "Make tests run in parallel (default: `false`)" },
996
+ seed: {
997
+ description: "Set the randomization seed. This option will have no effect if `--sequence.shuffle` is falsy. Visit [\"Random Seed\" page](https://en.wikipedia.org/wiki/Random_seed) for more information",
998
+ argument: "<seed>"
999
+ },
1000
+ hooks: {
1001
+ description: "Changes the order in which hooks are executed. Accepted values are: \"stack\", \"list\" and \"parallel\". Visit [`sequence.hooks`](https://vitest.dev/config/#sequence-hooks) for more information (default: `\"parallel\"`)",
1002
+ argument: "<order>"
1003
+ },
1004
+ setupFiles: {
1005
+ description: "Changes the order in which setup files are executed. Accepted values are: \"list\" and \"parallel\". If set to \"list\", will run setup files in the order they are defined. If set to \"parallel\", will run setup files in parallel (default: `\"parallel\"`)",
1006
+ argument: "<order>"
1007
+ }
1008
+ }
1009
+ },
1010
+ inspect: {
1011
+ description: "Enable Node.js inspector (default: `127.0.0.1:9229`)",
1012
+ argument: "[[host:]port]",
1013
+ transform(portOrEnabled) {
1014
+ if (portOrEnabled === 0 || portOrEnabled === "true" || portOrEnabled === "yes") {
1015
+ return true;
1016
+ }
1017
+ if (portOrEnabled === "false" || portOrEnabled === "no") {
1018
+ return false;
1019
+ }
1020
+ return portOrEnabled;
1021
+ }
1022
+ },
1023
+ inspectBrk: {
1024
+ description: "Enable Node.js inspector and break before the test starts",
1025
+ argument: "[[host:]port]",
1026
+ transform(portOrEnabled) {
1027
+ if (portOrEnabled === 0 || portOrEnabled === "true" || portOrEnabled === "yes") {
1028
+ return true;
1029
+ }
1030
+ if (portOrEnabled === "false" || portOrEnabled === "no") {
1031
+ return false;
1032
+ }
1033
+ return portOrEnabled;
1034
+ }
1035
+ },
1036
+ inspector: null,
1037
+ testTimeout: {
1038
+ description: "Default timeout of a test in milliseconds (default: `5000`). Use `0` to disable timeout completely.",
1039
+ argument: "<timeout>"
1040
+ },
1041
+ hookTimeout: {
1042
+ description: "Default hook timeout in milliseconds (default: `10000`). Use `0` to disable timeout completely.",
1043
+ argument: "<timeout>"
1044
+ },
1045
+ bail: {
1046
+ description: "Stop test execution when given number of tests have failed (default: `0`)",
1047
+ argument: "<number>"
1048
+ },
1049
+ retry: {
1050
+ description: "Retry the test specific number of times if it fails (default: `0`)",
1051
+ argument: "<times>"
1052
+ },
1053
+ diff: {
1054
+ description: "DiffOptions object or a path to a module which exports DiffOptions object",
1055
+ argument: "<path>",
1056
+ subcommands: {
1057
+ aAnnotation: {
1058
+ description: "Annotation for expected lines (default: `Expected`)",
1059
+ argument: "<annotation>"
1060
+ },
1061
+ aIndicator: {
1062
+ description: "Indicator for expected lines (default: `-`)",
1063
+ argument: "<indicator>"
1064
+ },
1065
+ bAnnotation: {
1066
+ description: "Annotation for received lines (default: `Received`)",
1067
+ argument: "<annotation>"
1068
+ },
1069
+ bIndicator: {
1070
+ description: "Indicator for received lines (default: `+`)",
1071
+ argument: "<indicator>"
1072
+ },
1073
+ commonIndicator: {
1074
+ description: "Indicator for common lines (default: ` `)",
1075
+ argument: "<indicator>"
1076
+ },
1077
+ contextLines: {
1078
+ description: "Number of lines of context to show around each change (default: `5`)",
1079
+ argument: "<lines>"
1080
+ },
1081
+ emptyFirstOrLastLinePlaceholder: {
1082
+ description: "Placeholder for an empty first or last line (default: `\"\"`)",
1083
+ argument: "<placeholder>"
1084
+ },
1085
+ expand: { description: "Expand all common lines (default: `true`)" },
1086
+ includeChangeCounts: { description: "Include comparison counts in diff output (default: `false`)" },
1087
+ omitAnnotationLines: { description: "Omit annotation lines from the output (default: `false`)" },
1088
+ printBasicPrototype: { description: "Print basic prototype Object and Array (default: `true`)" },
1089
+ maxDepth: {
1090
+ description: "Limit the depth to recurse when printing nested objects (default: `20`)",
1091
+ argument: "<maxDepth>"
1092
+ },
1093
+ truncateThreshold: {
1094
+ description: "Number of lines to show before and after each change (default: `0`)",
1095
+ argument: "<threshold>"
1096
+ },
1097
+ truncateAnnotation: {
1098
+ description: "Annotation for truncated lines (default: `... Diff result is truncated`)",
1099
+ argument: "<annotation>"
1100
+ }
1101
+ }
1102
+ },
1103
+ exclude: {
1104
+ description: "Additional file globs to be excluded from test",
1105
+ argument: "<glob>",
1106
+ array: true
1107
+ },
1108
+ expandSnapshotDiff: { description: "Show full diff when snapshot fails" },
1109
+ disableConsoleIntercept: { description: "Disable automatic interception of console logging (default: `false`)" },
1110
+ typecheck: {
1111
+ description: "Enable typechecking alongside tests (default: `false`)",
1112
+ argument: "",
1113
+ transform: transformNestedBoolean,
1114
+ subcommands: {
1115
+ enabled: { description: "Enable typechecking alongside tests (default: `false`)" },
1116
+ only: { description: "Run only typecheck tests. This automatically enables typecheck (default: `false`)" },
1117
+ checker: {
1118
+ description: "Specify the typechecker to use. Available values are: \"tsc\" and \"vue-tsc\" and a path to an executable (default: `\"tsc\"`)",
1119
+ argument: "<name>",
1120
+ subcommands: null
1121
+ },
1122
+ allowJs: { description: "Allow JavaScript files to be typechecked. By default takes the value from tsconfig.json" },
1123
+ ignoreSourceErrors: { description: "Ignore type errors from source files" },
1124
+ tsconfig: {
1125
+ description: "Path to a custom tsconfig file",
1126
+ argument: "<path>",
1127
+ normalize: true
1128
+ },
1129
+ include: null,
1130
+ exclude: null
1131
+ }
1132
+ },
1133
+ project: {
1134
+ description: "The name of the project to run if you are using Vitest workspace feature. This can be repeated for multiple projects: `--project=1 --project=2`. You can also filter projects using wildcards like `--project=packages*`, and exclude projects with `--project=!pattern`.",
1135
+ argument: "<name>",
1136
+ array: true
1137
+ },
1138
+ slowTestThreshold: {
1139
+ description: "Threshold in milliseconds for a test or suite to be considered slow (default: `300`)",
1140
+ argument: "<threshold>"
1141
+ },
1142
+ teardownTimeout: {
1143
+ description: "Default timeout of a teardown function in milliseconds (default: `10000`)",
1144
+ argument: "<timeout>"
1145
+ },
1146
+ cache: {
1147
+ description: "Enable cache",
1148
+ argument: "",
1149
+ subcommands: { dir: null },
1150
+ default: true,
1151
+ transform(cache) {
1152
+ if (typeof cache !== "boolean" && cache) {
1153
+ throw new Error("--cache.dir is deprecated");
1154
+ }
1155
+ if (cache) {
1156
+ return {};
1157
+ }
1158
+ return cache;
1159
+ }
1160
+ },
1161
+ maxConcurrency: {
1162
+ description: "Maximum number of concurrent tests in a suite (default: `5`)",
1163
+ argument: "<number>"
1164
+ },
1165
+ expect: {
1166
+ description: "Configuration options for `expect()` matches",
1167
+ argument: "",
1168
+ subcommands: {
1169
+ requireAssertions: { description: "Require that all tests have at least one assertion" },
1170
+ poll: {
1171
+ description: "Default options for `expect.poll()`",
1172
+ argument: "",
1173
+ subcommands: {
1174
+ interval: {
1175
+ description: "Poll interval in milliseconds for `expect.poll()` assertions (default: `50`)",
1176
+ argument: "<interval>"
1177
+ },
1178
+ timeout: {
1179
+ description: "Poll timeout in milliseconds for `expect.poll()` assertions (default: `1000`)",
1180
+ argument: "<timeout>"
1181
+ }
1182
+ },
1183
+ transform(value) {
1184
+ if (typeof value !== "object") {
1185
+ throw new TypeError(`Unexpected value for --expect.poll: ${value}. If you need to configure timeout, use --expect.poll.timeout=<timeout>`);
1186
+ }
1187
+ return value;
1188
+ }
1189
+ }
1190
+ },
1191
+ transform(value) {
1192
+ if (typeof value !== "object") {
1193
+ throw new TypeError(`Unexpected value for --expect: ${value}. If you need to configure expect options, use --expect.{name}=<value> syntax`);
1194
+ }
1195
+ return value;
1196
+ }
1197
+ },
1198
+ printConsoleTrace: { description: "Always print console stack traces" },
1199
+ includeTaskLocation: { description: "Collect test and suite locations in the `location` property" },
1200
+ run: { description: "Disable watch mode" },
1201
+ color: {
1202
+ description: "Removes colors from the console output",
1203
+ alias: "no-color"
1204
+ },
1205
+ clearScreen: { description: "Clear terminal screen when re-running tests during watch mode (default: `true`)" },
1206
+ configLoader: {
1207
+ 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`)",
1208
+ argument: "<loader>"
1209
+ },
1210
+ standalone: { description: "Start Vitest without running tests. File filters will be ignored, tests will be running only on change (default: `false`)" },
1211
+ mergeReports: {
1212
+ 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",
1213
+ argument: "[path]",
1214
+ transform(value) {
1215
+ if (!value || typeof value === "boolean") {
1216
+ return ".vitest-reports";
1217
+ }
1218
+ return value;
1219
+ }
1220
+ },
1221
+ cliExclude: null,
1222
+ server: null,
1223
+ setupFiles: null,
1224
+ globalSetup: null,
1225
+ snapshotFormat: null,
1226
+ snapshotSerializers: null,
1227
+ includeSource: null,
1228
+ alias: null,
1229
+ env: null,
1230
+ environmentMatchGlobs: null,
1231
+ environmentOptions: null,
1232
+ unstubEnvs: null,
1233
+ related: null,
1234
+ restoreMocks: null,
1235
+ runner: null,
1236
+ mockReset: null,
1237
+ forceRerunTriggers: null,
1238
+ unstubGlobals: null,
1239
+ uiBase: null,
1240
+ benchmark: null,
1241
+ include: null,
1242
+ testTransformMode: null,
1243
+ fakeTimers: null,
1244
+ chaiConfig: null,
1245
+ clearMocks: null,
1246
+ css: null,
1247
+ poolMatchGlobs: null,
1248
+ deps: null,
1249
+ name: null,
1250
+ snapshotEnvironment: null,
1251
+ compare: null,
1252
+ outputJson: null,
1253
+ json: null,
1254
+ provide: null,
1255
+ filesOnly: null
1256
+ };
1257
+ const benchCliOptionsConfig = {
1258
+ compare: {
1259
+ description: "Benchmark output file to compare against",
1260
+ argument: "<filename>"
1261
+ },
1262
+ outputJson: {
1263
+ description: "Benchmark output file",
1264
+ argument: "<filename>"
1265
+ }
1266
+ };
1267
+ const collectCliOptionsConfig = {
1268
+ json: {
1269
+ description: "Print collected tests as JSON or write to a file (Default: false)",
1270
+ argument: "[true/path]"
1271
+ },
1272
+ filesOnly: { description: "Print only test files with out the test cases" }
1273
+ };
1274
+
1275
+ function addCommand(cli, name, option) {
1276
+ const commandName = option.alias || name;
1277
+ let command = option.shorthand ? `-${option.shorthand}, --${commandName}` : `--${commandName}`;
1278
+ if ("argument" in option) {
1279
+ command += ` ${option.argument}`;
1280
+ }
1281
+ function transform(value) {
1282
+ if (!option.array && Array.isArray(value)) {
1283
+ const received = value.map((s) => typeof s === "string" ? `"${s}"` : s).join(", ");
1284
+ throw new Error(`Expected a single value for option "${command}", received [${received}]`);
1285
+ }
1286
+ value = removeQuotes(value);
1287
+ if (option.transform) {
1288
+ return option.transform(value);
1289
+ }
1290
+ if (option.array) {
1291
+ return toArray(value);
1292
+ }
1293
+ if (option.normalize) {
1294
+ return normalize(String(value));
1295
+ }
1296
+ return value;
1297
+ }
1298
+ const hasSubcommands = "subcommands" in option && option.subcommands;
1299
+ if (option.description) {
1300
+ let description = option.description.replace(/\[.*\]\((.*)\)/, "$1").replace(/`/g, "");
1301
+ if (hasSubcommands) {
1302
+ description += `. Use '--help --${commandName}' for more info.`;
1303
+ }
1304
+ cli.option(command, description, { type: transform });
1305
+ }
1306
+ if (hasSubcommands) {
1307
+ for (const commandName in option.subcommands) {
1308
+ const subcommand = option.subcommands[commandName];
1309
+ if (subcommand) {
1310
+ addCommand(cli, `${name}.${commandName}`, subcommand);
1311
+ }
1312
+ }
1313
+ }
1314
+ }
1315
+ function addCliOptions(cli, options) {
1316
+ for (const [optionName, option] of Object.entries(options)) {
1317
+ if (option) {
1318
+ addCommand(cli, optionName, option);
1319
+ }
1320
+ }
1321
+ }
1322
+ function createCLI(options = {}) {
1323
+ const cli = cac("vitest");
1324
+ cli.version(version);
1325
+ addCliOptions(cli, cliOptionsConfig);
1326
+ cli.help((info) => {
1327
+ const helpSection = info.find((current) => current.title?.startsWith("For more info, run any command"));
1328
+ if (helpSection) {
1329
+ helpSection.body += "\n $ vitest --help --expand-help";
1330
+ }
1331
+ const options = info.find((current) => current.title === "Options");
1332
+ if (typeof options !== "object") {
1333
+ return info;
1334
+ }
1335
+ const helpIndex = process.argv.findIndex((arg) => arg === "--help");
1336
+ const subcommands = process.argv.slice(helpIndex + 1);
1337
+ const defaultOutput = options.body.split("\n").filter((line) => /^\s+--\S+\./.test(line) === false).join("\n");
1338
+ if (subcommands.length === 0) {
1339
+ options.body = defaultOutput;
1340
+ return info;
1341
+ }
1342
+ if (subcommands.length === 1 && (subcommands[0] === "--expand-help" || subcommands[0] === "--expandHelp")) {
1343
+ return info;
1344
+ }
1345
+ const subcommandMarker = "$SUB_COMMAND_MARKER$";
1346
+ const banner = info.find((current) => /^vitest\/\d+\.\d+\.\d+$/.test(current.body));
1347
+ function addBannerWarning(warning) {
1348
+ if (typeof banner?.body === "string") {
1349
+ if (banner?.body.includes(warning)) {
1350
+ return;
1351
+ }
1352
+ banner.body = `${banner.body}\n WARN: ${warning}`;
1353
+ }
1354
+ }
1355
+ for (let i = 0; i < subcommands.length; i++) {
1356
+ const subcommand = subcommands[i];
1357
+ if (subcommand === "--expand-help" || subcommand === "--expandHelp") {
1358
+ addBannerWarning("--expand-help subcommand ignored because, when used with --help, it must be the only subcommand");
1359
+ continue;
1360
+ }
1361
+ if (subcommand.startsWith("--")) {
1362
+ options.body = options.body.split("\n").map((line) => line.trim().startsWith(subcommand) ? `${subcommandMarker}${line}` : line).join("\n");
1363
+ }
1364
+ }
1365
+ options.body = options.body.split("\n").map((line) => line.startsWith(subcommandMarker) ? line.split(subcommandMarker)[1] : "").filter((line) => line.length !== 0).join("\n");
1366
+ if (!options.body) {
1367
+ addBannerWarning("no options were found for your subcommands so we printed the whole output");
1368
+ options.body = defaultOutput;
1369
+ }
1370
+ return info;
1371
+ });
1372
+ cli.command("run [...filters]", undefined, options).action(run);
1373
+ cli.command("related [...filters]", undefined, options).action(runRelated);
1374
+ cli.command("watch [...filters]", undefined, options).action(watch);
1375
+ cli.command("dev [...filters]", undefined, options).action(watch);
1376
+ addCliOptions(cli.command("bench [...filters]", undefined, options).action(benchmark), benchCliOptionsConfig);
1377
+ cli.command("init <project>", undefined, options).action(init);
1378
+ addCliOptions(cli.command("list [...filters]", undefined, options).action((filters, options) => collect("test", filters, options)), collectCliOptionsConfig);
1379
+ cli.command("[...filters]", undefined, options).action((filters, options) => start("test", filters, options));
1380
+ return cli;
1381
+ }
1382
+ function removeQuotes(str) {
1383
+ if (typeof str !== "string") {
1384
+ if (Array.isArray(str)) {
1385
+ return str.map(removeQuotes);
1386
+ }
1387
+ return str;
1388
+ }
1389
+ if (str.startsWith("\"") && str.endsWith("\"")) {
1390
+ return str.slice(1, -1);
1391
+ }
1392
+ if (str.startsWith(`'`) && str.endsWith(`'`)) {
1393
+ return str.slice(1, -1);
1394
+ }
1395
+ return str;
1396
+ }
1397
+ function splitArgv(argv) {
1398
+ const reg = /(['"])(?:(?!\1).)+\1/g;
1399
+ argv = argv.replace(reg, (match) => match.replace(/\s/g, "\0"));
1400
+ return argv.split(" ").map((arg) => {
1401
+ arg = arg.replace(/\0/g, " ");
1402
+ return removeQuotes(arg);
1403
+ });
1404
+ }
1405
+ function parseCLI(argv, config = {}) {
1406
+ const arrayArgs = typeof argv === "string" ? splitArgv(argv) : argv;
1407
+ if (arrayArgs[0] !== "vitest") {
1408
+ throw new Error(`Expected "vitest" as the first argument, received "${arrayArgs[0]}"`);
1409
+ }
1410
+ arrayArgs[0] = "/index.js";
1411
+ arrayArgs.unshift("node");
1412
+ let { args, options } = createCLI(config).parse(arrayArgs, { run: false });
1413
+ if (arrayArgs[2] === "watch" || arrayArgs[2] === "dev") {
1414
+ options.watch = true;
1415
+ }
1416
+ if (arrayArgs[2] === "run") {
1417
+ options.run = true;
1418
+ }
1419
+ if (arrayArgs[2] === "related") {
1420
+ options.related = args;
1421
+ options.passWithNoTests ??= true;
1422
+ args = [];
1423
+ }
1424
+ return {
1425
+ filter: args,
1426
+ options
1427
+ };
1428
+ }
1429
+ async function runRelated(relatedFiles, argv) {
1430
+ argv.related = relatedFiles;
1431
+ argv.passWithNoTests ??= true;
1432
+ await start("test", [], argv);
1433
+ }
1434
+ async function watch(cliFilters, options) {
1435
+ options.watch = true;
1436
+ await start("test", cliFilters, options);
1437
+ }
1438
+ async function run(cliFilters, options) {
1439
+ options.run = true;
1440
+ await start("test", cliFilters, options);
1441
+ }
1442
+ async function benchmark(cliFilters, options) {
1443
+ console.warn(c.yellow("Benchmarking is an experimental feature.\nBreaking changes might not follow SemVer, please pin Vitest's version when using it."));
1444
+ await start("benchmark", cliFilters, options);
1445
+ }
1446
+ function normalizeCliOptions(cliFilters, argv) {
1447
+ if (argv.exclude) {
1448
+ argv.cliExclude = toArray(argv.exclude);
1449
+ delete argv.exclude;
1450
+ }
1451
+ if (cliFilters.some((filter) => filter.includes(":"))) {
1452
+ argv.includeTaskLocation ??= true;
1453
+ }
1454
+ if (typeof argv.browser === "object" && !("enabled" in argv.browser)) {
1455
+ argv.browser.enabled = true;
1456
+ }
1457
+ if (typeof argv.typecheck?.only === "boolean") {
1458
+ argv.typecheck.enabled ??= true;
1459
+ }
1460
+ return argv;
1461
+ }
1462
+ async function start(mode, cliFilters, options) {
1463
+ try {
1464
+ process.title = "node (vitest)";
1465
+ } catch {}
1466
+ try {
1467
+ const { startVitest } = await import('./cli-api.2yb7XCwB.js').then(function (n) { return n.f; });
1468
+ const ctx = await startVitest(mode, cliFilters.map(normalize), normalizeCliOptions(cliFilters, options));
1469
+ if (!ctx.shouldKeepServer()) {
1470
+ await ctx.exit();
1471
+ }
1472
+ } catch (e) {
1473
+ const { divider } = await import('./utils.Lot3J_8U.js').then(function (n) { return n.u; });
1474
+ console.error(`\n${c.red(divider(c.bold(c.inverse(" Startup Error "))))}`);
1475
+ console.error(e);
1476
+ console.error("\n\n");
1477
+ if (process.exitCode == null) {
1478
+ process.exitCode = 1;
1479
+ }
1480
+ process.exit();
1481
+ }
1482
+ }
1483
+ async function init(project) {
1484
+ if (project !== "browser") {
1485
+ console.error(new Error("Only the \"browser\" project is supported. Use \"vitest init browser\" to create a new project."));
1486
+ process.exit(1);
1487
+ }
1488
+ const { create } = await import('./creator.CuL7xDWI.js');
1489
+ await create();
1490
+ }
1491
+ async function collect(mode, cliFilters, options) {
1492
+ try {
1493
+ process.title = "node (vitest)";
1494
+ } catch {}
1495
+ try {
1496
+ const { prepareVitest, processCollected, outputFileList } = await import('./cli-api.2yb7XCwB.js').then(function (n) { return n.f; });
1497
+ const ctx = await prepareVitest(mode, {
1498
+ ...normalizeCliOptions(cliFilters, options),
1499
+ watch: false,
1500
+ run: true
1501
+ });
1502
+ if (!options.filesOnly) {
1503
+ const { testModules: tests, unhandledErrors: errors } = await ctx.collect(cliFilters.map(normalize));
1504
+ if (errors.length) {
1505
+ console.error("\nThere were unhandled errors during test collection");
1506
+ errors.forEach((e) => console.error(e));
1507
+ console.error("\n\n");
1508
+ await ctx.close();
1509
+ return;
1510
+ }
1511
+ processCollected(ctx, tests, options);
1512
+ } else {
1513
+ const files = await ctx.getRelevantTestSpecifications(cliFilters.map(normalize));
1514
+ outputFileList(files, options);
1515
+ }
1516
+ await ctx.close();
1517
+ } catch (e) {
1518
+ const { divider } = await import('./utils.Lot3J_8U.js').then(function (n) { return n.u; });
1519
+ console.error(`\n${c.red(divider(c.bold(c.inverse(" Collect Error "))))}`);
1520
+ console.error(e);
1521
+ console.error("\n\n");
1522
+ if (process.exitCode == null) {
1523
+ process.exitCode = 1;
1524
+ }
1525
+ process.exit();
1526
+ }
1527
+ }
1528
+
1529
+ export { createCLI as c, parseCLI as p, version as v };