vitest 1.5.0 → 1.5.2

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 (36) hide show
  1. package/dist/browser.d.ts +2 -1
  2. package/dist/browser.js +1 -1
  3. package/dist/chunks/{integrations-globals.2J_Aii2q.js → integrations-globals.k0N5-dd1.js} +2 -2
  4. package/dist/chunks/{runtime-runBaseTests.3fVSWBsC.js → runtime-runBaseTests.-x-nNuJ_.js} +4 -4
  5. package/dist/cli.js +2 -60
  6. package/dist/config.d.ts +2 -1
  7. package/dist/coverage.d.ts +4 -2
  8. package/dist/coverage.js +2 -2
  9. package/dist/environments.d.ts +2 -1
  10. package/dist/execute.d.ts +2 -1
  11. package/dist/index.d.ts +5 -4
  12. package/dist/index.js +3 -3
  13. package/dist/node.d.ts +26 -4
  14. package/dist/node.js +11 -9
  15. package/dist/{reporters-LqC_WI4d.d.ts → reporters-xEmem8D4.d.ts} +88 -41
  16. package/dist/reporters.d.ts +2 -1
  17. package/dist/reporters.js +3 -2
  18. package/dist/runners.d.ts +2 -1
  19. package/dist/runners.js +1 -1
  20. package/dist/{suite-ynYMzeLu.d.ts → suite-HPAKvIxA.d.ts} +1 -1
  21. package/dist/suite.d.ts +3 -2
  22. package/dist/vendor/{base.BjeeYg4o.js → base.gAwDs8Jc.js} +1 -1
  23. package/dist/vendor/cac.8mXc9Oj6.js +1406 -0
  24. package/dist/vendor/{cac.qnW6GNL2.js → cli-api._n4_Wp_j.js} +139 -1542
  25. package/dist/vendor/{index.12jbrDSD.js → index.0RrMQKD8.js} +1 -1
  26. package/dist/vendor/{index.kSaPvGW6.js → index.GlXSU9xI.js} +21 -208
  27. package/dist/vendor/{index.-ITFwqG_.js → index.gHZzsRJQ.js} +1 -1
  28. package/dist/vendor/{setup-common.A1De6efh.js → setup-common.7SXMSI--.js} +5 -2
  29. package/dist/vendor/utils.VYmeMh-u.js +217 -0
  30. package/dist/vendor/{vi.Fxjax7rQ.js → vi.Y_w82WR8.js} +5 -1
  31. package/dist/workers/forks.js +1 -1
  32. package/dist/workers/runVmTests.js +4 -4
  33. package/dist/workers/threads.js +1 -1
  34. package/dist/workers.d.ts +2 -1
  35. package/dist/workers.js +1 -1
  36. package/package.json +9 -9
@@ -1,12 +1,8 @@
1
1
  import { dirname, resolve, relative, normalize, join, basename, toNamespacedPath, isAbsolute } from 'pathe';
2
- import require$$0$3, { EventEmitter as EventEmitter$2 } from 'events';
3
- import c from 'picocolors';
4
- import { b as removeUndefinedValues, c as isWindows } from './index.ir9i0ywP.js';
5
- import { w as wrapSerializableConfig, f as Typechecker, R as ReportersMap, e as BenchmarkReportsMap, g as RandomSequencer, B as BaseSequencer, h as generateCodeFrame, i as highlightCode, j as divider, L as Logger, s as stripAnsi } from './index.kSaPvGW6.js';
6
- import { A as API_PATH, c as configFiles, d as defaultPort, e as extraInlineDeps, a as defaultBrowserPort, b as defaultInspectPort, E as EXIT_CODE_RESTART, w as workspacesFiles, C as CONFIG_NAMES } from './constants.5J7I254_.js';
2
+ import { A as API_PATH, d as defaultPort, e as extraInlineDeps, a as defaultBrowserPort, b as defaultInspectPort, E as EXIT_CODE_RESTART, w as workspacesFiles, C as CONFIG_NAMES, c as configFiles } from './constants.5J7I254_.js';
7
3
  import { g as getCoverageProvider, C as CoverageProviderMap } from './coverage.E7sG1b3r.js';
8
4
  import { g as getEnvPackageName } from './index.GVFv9dZ0.js';
9
- import { isFileServingAllowed, loadConfigFromFile, searchForWorkspaceRoot, version as version$1, createServer, mergeConfig } from 'vite';
5
+ import { isFileServingAllowed, searchForWorkspaceRoot, version as version$1, createServer, mergeConfig } from 'vite';
10
6
  import path$8 from 'node:path';
11
7
  import url, { fileURLToPath } from 'node:url';
12
8
  import process$1 from 'node:process';
@@ -17,10 +13,13 @@ import require$$0 from 'os';
17
13
  import p from 'path';
18
14
  import { a as micromatch_1, m as mm } from './index.xL8XjTLv.js';
19
15
  import require$$0$1 from 'stream';
16
+ import require$$0$3 from 'events';
20
17
  import require$$0$2 from 'fs';
18
+ import c from 'picocolors';
21
19
  import { ViteNodeRunner } from 'vite-node/client';
22
20
  import { SnapshotManager } from '@vitest/snapshot/manager';
23
21
  import { ViteNodeServer } from 'vite-node/server';
22
+ import { b as removeUndefinedValues, c as isWindows } from './index.ir9i0ywP.js';
24
23
  import { rootDir } from '../path.js';
25
24
  import { c as createBirpc } from './index.8bPxjt7g.js';
26
25
  import require$$0$4 from 'zlib';
@@ -37,17 +36,20 @@ import { n as noop$2, b as isPrimitive, c as groupBy, A as AggregateErrorPonyfil
37
36
  import v8 from 'node:v8';
38
37
  import * as nodeos from 'node:os';
39
38
  import nodeos__default from 'node:os';
40
- import EventEmitter$3 from 'node:events';
39
+ import EventEmitter$2 from 'node:events';
41
40
  import Tinypool$1, { Tinypool } from 'tinypool';
41
+ import { w as wrapSerializableConfig, f as Typechecker, R as ReportersMap, e as BenchmarkReportsMap, g as RandomSequencer, B as BaseSequencer, h as generateCodeFrame, i as highlightCode, L as Logger } from './index.GlXSU9xI.js';
42
42
  import { hasFailed, getTests } from '@vitest/runner/utils';
43
43
  import { resolveModule, isPackageExists } from 'local-pkg';
44
44
  import { isCI, provider as provider$1 } from 'std-env';
45
45
  import crypto, { createHash as createHash$2 } from 'node:crypto';
46
+ import { v as version } from './cac.8mXc9Oj6.js';
46
47
  import { normalizeRequestId, cleanUrl } from 'vite-node/utils';
47
48
  import MagicString from 'magic-string';
48
49
  import { findNodeAround } from 'acorn-walk';
49
50
  import { esmWalker } from '@vitest/utils/ast';
50
51
  import { stripLiteral } from 'strip-literal';
52
+ import { d as divider, s as stripAnsi } from './utils.VYmeMh-u.js';
51
53
  import { createRequire } from 'node:module';
52
54
  import readline from 'node:readline';
53
55
  import require$$0$6 from 'readline';
@@ -114,622 +116,6 @@ function stringifyReplace(key, value) {
114
116
  return value;
115
117
  }
116
118
 
117
- function toArr(any) {
118
- return any == null ? [] : Array.isArray(any) ? any : [any];
119
- }
120
-
121
- function toVal(out, key, val, opts) {
122
- var x, old=out[key], nxt=(
123
- !!~opts.string.indexOf(key) ? (val == null || val === true ? '' : String(val))
124
- : typeof val === 'boolean' ? val
125
- : !!~opts.boolean.indexOf(key) ? (val === 'false' ? false : val === 'true' || (out._.push((x = +val,x * 0 === 0) ? x : val),!!val))
126
- : (x = +val,x * 0 === 0) ? x : val
127
- );
128
- out[key] = old == null ? nxt : (Array.isArray(old) ? old.concat(nxt) : [old, nxt]);
129
- }
130
-
131
- function mri2 (args, opts) {
132
- args = args || [];
133
- opts = opts || {};
134
-
135
- var k, arr, arg, name, val, out={ _:[] };
136
- var i=0, j=0, idx=0, len=args.length;
137
-
138
- const alibi = opts.alias !== void 0;
139
- const strict = opts.unknown !== void 0;
140
- const defaults = opts.default !== void 0;
141
-
142
- opts.alias = opts.alias || {};
143
- opts.string = toArr(opts.string);
144
- opts.boolean = toArr(opts.boolean);
145
-
146
- if (alibi) {
147
- for (k in opts.alias) {
148
- arr = opts.alias[k] = toArr(opts.alias[k]);
149
- for (i=0; i < arr.length; i++) {
150
- (opts.alias[arr[i]] = arr.concat(k)).splice(i, 1);
151
- }
152
- }
153
- }
154
-
155
- for (i=opts.boolean.length; i-- > 0;) {
156
- arr = opts.alias[opts.boolean[i]] || [];
157
- for (j=arr.length; j-- > 0;) opts.boolean.push(arr[j]);
158
- }
159
-
160
- for (i=opts.string.length; i-- > 0;) {
161
- arr = opts.alias[opts.string[i]] || [];
162
- for (j=arr.length; j-- > 0;) opts.string.push(arr[j]);
163
- }
164
-
165
- if (defaults) {
166
- for (k in opts.default) {
167
- name = typeof opts.default[k];
168
- arr = opts.alias[k] = opts.alias[k] || [];
169
- if (opts[name] !== void 0) {
170
- opts[name].push(k);
171
- for (i=0; i < arr.length; i++) {
172
- opts[name].push(arr[i]);
173
- }
174
- }
175
- }
176
- }
177
-
178
- const keys = strict ? Object.keys(opts.alias) : [];
179
-
180
- for (i=0; i < len; i++) {
181
- arg = args[i];
182
-
183
- if (arg === '--') {
184
- out._ = out._.concat(args.slice(++i));
185
- break;
186
- }
187
-
188
- for (j=0; j < arg.length; j++) {
189
- if (arg.charCodeAt(j) !== 45) break; // "-"
190
- }
191
-
192
- if (j === 0) {
193
- out._.push(arg);
194
- } else if (arg.substring(j, j + 3) === 'no-') {
195
- name = arg.substring(j + 3);
196
- if (strict && !~keys.indexOf(name)) {
197
- return opts.unknown(arg);
198
- }
199
- out[name] = false;
200
- } else {
201
- for (idx=j+1; idx < arg.length; idx++) {
202
- if (arg.charCodeAt(idx) === 61) break; // "="
203
- }
204
-
205
- name = arg.substring(j, idx);
206
- val = arg.substring(++idx) || (i+1 === len || (''+args[i+1]).charCodeAt(0) === 45 || args[++i]);
207
- arr = (j === 2 ? [name] : name);
208
-
209
- for (idx=0; idx < arr.length; idx++) {
210
- name = arr[idx];
211
- if (strict && !~keys.indexOf(name)) return opts.unknown('-'.repeat(j) + name);
212
- toVal(out, name, (idx + 1 < arr.length) || val, opts);
213
- }
214
- }
215
- }
216
-
217
- if (defaults) {
218
- for (k in opts.default) {
219
- if (out[k] === void 0) {
220
- out[k] = opts.default[k];
221
- }
222
- }
223
- }
224
-
225
- if (alibi) {
226
- for (k in out) {
227
- arr = opts.alias[k] || [];
228
- while (arr.length > 0) {
229
- out[arr.shift()] = out[k];
230
- }
231
- }
232
- }
233
-
234
- return out;
235
- }
236
-
237
- const removeBrackets = (v) => v.replace(/[<[].+/, "").trim();
238
- const findAllBrackets = (v) => {
239
- const ANGLED_BRACKET_RE_GLOBAL = /<([^>]+)>/g;
240
- const SQUARE_BRACKET_RE_GLOBAL = /\[([^\]]+)\]/g;
241
- const res = [];
242
- const parse = (match) => {
243
- let variadic = false;
244
- let value = match[1];
245
- if (value.startsWith("...")) {
246
- value = value.slice(3);
247
- variadic = true;
248
- }
249
- return {
250
- required: match[0].startsWith("<"),
251
- value,
252
- variadic
253
- };
254
- };
255
- let angledMatch;
256
- while (angledMatch = ANGLED_BRACKET_RE_GLOBAL.exec(v)) {
257
- res.push(parse(angledMatch));
258
- }
259
- let squareMatch;
260
- while (squareMatch = SQUARE_BRACKET_RE_GLOBAL.exec(v)) {
261
- res.push(parse(squareMatch));
262
- }
263
- return res;
264
- };
265
- const getMriOptions = (options) => {
266
- const result = {alias: {}, boolean: []};
267
- for (const [index, option] of options.entries()) {
268
- if (option.names.length > 1) {
269
- result.alias[option.names[0]] = option.names.slice(1);
270
- }
271
- if (option.isBoolean) {
272
- if (option.negated) {
273
- const hasStringTypeOption = options.some((o, i) => {
274
- return i !== index && o.names.some((name) => option.names.includes(name)) && typeof o.required === "boolean";
275
- });
276
- if (!hasStringTypeOption) {
277
- result.boolean.push(option.names[0]);
278
- }
279
- } else {
280
- result.boolean.push(option.names[0]);
281
- }
282
- }
283
- }
284
- return result;
285
- };
286
- const findLongest = (arr) => {
287
- return arr.sort((a, b) => {
288
- return a.length > b.length ? -1 : 1;
289
- })[0];
290
- };
291
- const padRight = (str, length) => {
292
- return str.length >= length ? str : `${str}${" ".repeat(length - str.length)}`;
293
- };
294
- const camelcase = (input) => {
295
- return input.replace(/([a-z])-([a-z])/g, (_, p1, p2) => {
296
- return p1 + p2.toUpperCase();
297
- });
298
- };
299
- const setDotProp = (obj, keys, val, transforms) => {
300
- let i = 0;
301
- let length = keys.length;
302
- let t = obj;
303
- let x;
304
- let convertKey = (i) => {
305
- let key = keys[i];
306
- i--;
307
- while(i >= 0) {
308
- key = keys[i] + '.' + key;
309
- i--;
310
- }
311
- return key
312
- };
313
- for (; i < length; ++i) {
314
- x = t[keys[i]];
315
- const transform = transforms[convertKey(i)] || ((v) => v);
316
- t = t[keys[i]] = transform(i === length - 1 ? val : x != null ? x : !!~keys[i + 1].indexOf(".") || !(+keys[i + 1] > -1) ? {} : []);
317
- }
318
- };
319
- const getFileName = (input) => {
320
- const m = /([^\\\/]+)$/.exec(input);
321
- return m ? m[1] : "";
322
- };
323
- const camelcaseOptionName = (name) => {
324
- return name.split(".").map((v, i) => {
325
- return i === 0 ? camelcase(v) : v;
326
- }).join(".");
327
- };
328
- class CACError extends Error {
329
- constructor(message) {
330
- super(message);
331
- this.name = this.constructor.name;
332
- if (typeof Error.captureStackTrace === "function") {
333
- Error.captureStackTrace(this, this.constructor);
334
- } else {
335
- this.stack = new Error(message).stack;
336
- }
337
- }
338
- }
339
-
340
- class Option {
341
- constructor(rawName, description, config) {
342
- this.rawName = rawName;
343
- this.description = description;
344
- this.config = Object.assign({}, config);
345
- rawName = rawName.replace(/\.\*/g, "");
346
- this.negated = false;
347
- this.names = removeBrackets(rawName).split(",").map((v) => {
348
- let name = v.trim().replace(/^-{1,2}/, "");
349
- if (name.startsWith("no-")) {
350
- this.negated = true;
351
- name = name.replace(/^no-/, "");
352
- }
353
- return camelcaseOptionName(name);
354
- }).sort((a, b) => a.length > b.length ? 1 : -1);
355
- this.name = this.names[this.names.length - 1];
356
- if (this.negated && this.config.default == null) {
357
- this.config.default = true;
358
- }
359
- if (rawName.includes("<")) {
360
- this.required = true;
361
- } else if (rawName.includes("[")) {
362
- this.required = false;
363
- } else {
364
- this.isBoolean = true;
365
- }
366
- }
367
- }
368
-
369
- const processArgs = process.argv;
370
- const platformInfo = `${process.platform}-${process.arch} node-${process.version}`;
371
-
372
- class Command {
373
- constructor(rawName, description, config = {}, cli) {
374
- this.rawName = rawName;
375
- this.description = description;
376
- this.config = config;
377
- this.cli = cli;
378
- this.options = [];
379
- this.aliasNames = [];
380
- this.name = removeBrackets(rawName);
381
- this.args = findAllBrackets(rawName);
382
- this.examples = [];
383
- }
384
- usage(text) {
385
- this.usageText = text;
386
- return this;
387
- }
388
- allowUnknownOptions() {
389
- this.config.allowUnknownOptions = true;
390
- return this;
391
- }
392
- ignoreOptionDefaultValue() {
393
- this.config.ignoreOptionDefaultValue = true;
394
- return this;
395
- }
396
- version(version, customFlags = "-v, --version") {
397
- this.versionNumber = version;
398
- this.option(customFlags, "Display version number");
399
- return this;
400
- }
401
- example(example) {
402
- this.examples.push(example);
403
- return this;
404
- }
405
- option(rawName, description, config) {
406
- const option = new Option(rawName, description, config);
407
- this.options.push(option);
408
- return this;
409
- }
410
- alias(name) {
411
- this.aliasNames.push(name);
412
- return this;
413
- }
414
- action(callback) {
415
- this.commandAction = callback;
416
- return this;
417
- }
418
- isMatched(name) {
419
- return this.name === name || this.aliasNames.includes(name);
420
- }
421
- get isDefaultCommand() {
422
- return this.name === "" || this.aliasNames.includes("!");
423
- }
424
- get isGlobalCommand() {
425
- return this instanceof GlobalCommand;
426
- }
427
- hasOption(name) {
428
- name = name.split(".")[0];
429
- return this.options.find((option) => {
430
- return option.names.includes(name);
431
- });
432
- }
433
- outputHelp() {
434
- const {name, commands} = this.cli;
435
- const {
436
- versionNumber,
437
- options: globalOptions,
438
- helpCallback
439
- } = this.cli.globalCommand;
440
- let sections = [
441
- {
442
- body: `${name}${versionNumber ? `/${versionNumber}` : ""}`
443
- }
444
- ];
445
- sections.push({
446
- title: "Usage",
447
- body: ` $ ${name} ${this.usageText || this.rawName}`
448
- });
449
- const showCommands = (this.isGlobalCommand || this.isDefaultCommand) && commands.length > 0;
450
- if (showCommands) {
451
- const longestCommandName = findLongest(commands.map((command) => command.rawName));
452
- sections.push({
453
- title: "Commands",
454
- body: commands.map((command) => {
455
- return ` ${padRight(command.rawName, longestCommandName.length)} ${command.description}`;
456
- }).join("\n")
457
- });
458
- sections.push({
459
- title: `For more info, run any command with the \`--help\` flag`,
460
- body: commands.map((command) => ` $ ${name}${command.name === "" ? "" : ` ${command.name}`} --help`).join("\n")
461
- });
462
- }
463
- let options = this.isGlobalCommand ? globalOptions : [...this.options, ...globalOptions || []];
464
- if (!this.isGlobalCommand && !this.isDefaultCommand) {
465
- options = options.filter((option) => option.name !== "version");
466
- }
467
- if (options.length > 0) {
468
- const longestOptionName = findLongest(options.map((option) => option.rawName));
469
- sections.push({
470
- title: "Options",
471
- body: options.map((option) => {
472
- return ` ${padRight(option.rawName, longestOptionName.length)} ${option.description} ${option.config.default === void 0 ? "" : `(default: ${option.config.default})`}`;
473
- }).join("\n")
474
- });
475
- }
476
- if (this.examples.length > 0) {
477
- sections.push({
478
- title: "Examples",
479
- body: this.examples.map((example) => {
480
- if (typeof example === "function") {
481
- return example(name);
482
- }
483
- return example;
484
- }).join("\n")
485
- });
486
- }
487
- if (helpCallback) {
488
- sections = helpCallback(sections) || sections;
489
- }
490
- console.log(sections.map((section) => {
491
- return section.title ? `${section.title}:
492
- ${section.body}` : section.body;
493
- }).join("\n\n"));
494
- }
495
- outputVersion() {
496
- const {name} = this.cli;
497
- const {versionNumber} = this.cli.globalCommand;
498
- if (versionNumber) {
499
- console.log(`${name}/${versionNumber} ${platformInfo}`);
500
- }
501
- }
502
- checkRequiredArgs() {
503
- const minimalArgsCount = this.args.filter((arg) => arg.required).length;
504
- if (this.cli.args.length < minimalArgsCount) {
505
- throw new CACError(`missing required args for command \`${this.rawName}\``);
506
- }
507
- }
508
- checkUnknownOptions() {
509
- const {options, globalCommand} = this.cli;
510
- if (!this.config.allowUnknownOptions) {
511
- for (const name of Object.keys(options)) {
512
- if (name !== "--" && !this.hasOption(name) && !globalCommand.hasOption(name)) {
513
- throw new CACError(`Unknown option \`${name.length > 1 ? `--${name}` : `-${name}`}\``);
514
- }
515
- }
516
- }
517
- }
518
- checkOptionValue() {
519
- const {options: parsedOptions, globalCommand} = this.cli;
520
- const options = [...globalCommand.options, ...this.options];
521
- for (const option of options) {
522
- // skip dot names because only top level options are required
523
- if (option.name.includes('.')) {
524
- continue;
525
- }
526
- const value = parsedOptions[option.name];
527
- if (option.required) {
528
- const hasNegated = options.some((o) => o.negated && o.names.includes(option.name));
529
- if (value === true || value === false && !hasNegated) {
530
- throw new CACError(`option \`${option.rawName}\` value is missing`);
531
- }
532
- }
533
- }
534
- }
535
- }
536
- class GlobalCommand extends Command {
537
- constructor(cli) {
538
- super("@@global@@", "", {}, cli);
539
- }
540
- }
541
-
542
- var __assign = Object.assign;
543
- class CAC extends EventEmitter$2 {
544
- constructor(name = "") {
545
- super();
546
- this.name = name;
547
- this.commands = [];
548
- this.rawArgs = [];
549
- this.args = [];
550
- this.options = {};
551
- this.globalCommand = new GlobalCommand(this);
552
- this.globalCommand.usage("<command> [options]");
553
- }
554
- usage(text) {
555
- this.globalCommand.usage(text);
556
- return this;
557
- }
558
- command(rawName, description, config) {
559
- const command = new Command(rawName, description || "", config, this);
560
- command.globalCommand = this.globalCommand;
561
- this.commands.push(command);
562
- return command;
563
- }
564
- option(rawName, description, config) {
565
- this.globalCommand.option(rawName, description, config);
566
- return this;
567
- }
568
- help(callback) {
569
- this.globalCommand.option("-h, --help", "Display this message");
570
- this.globalCommand.helpCallback = callback;
571
- this.showHelpOnExit = true;
572
- return this;
573
- }
574
- version(version, customFlags = "-v, --version") {
575
- this.globalCommand.version(version, customFlags);
576
- this.showVersionOnExit = true;
577
- return this;
578
- }
579
- example(example) {
580
- this.globalCommand.example(example);
581
- return this;
582
- }
583
- outputHelp() {
584
- if (this.matchedCommand) {
585
- this.matchedCommand.outputHelp();
586
- } else {
587
- this.globalCommand.outputHelp();
588
- }
589
- }
590
- outputVersion() {
591
- this.globalCommand.outputVersion();
592
- }
593
- setParsedInfo({args, options}, matchedCommand, matchedCommandName) {
594
- this.args = args;
595
- this.options = options;
596
- if (matchedCommand) {
597
- this.matchedCommand = matchedCommand;
598
- }
599
- if (matchedCommandName) {
600
- this.matchedCommandName = matchedCommandName;
601
- }
602
- return this;
603
- }
604
- unsetMatchedCommand() {
605
- this.matchedCommand = void 0;
606
- this.matchedCommandName = void 0;
607
- }
608
- parse(argv = processArgs, {
609
- run = true
610
- } = {}) {
611
- this.rawArgs = argv;
612
- if (!this.name) {
613
- this.name = argv[1] ? getFileName(argv[1]) : "cli";
614
- }
615
- let shouldParse = true;
616
- for (const command of this.commands) {
617
- const parsed = this.mri(argv.slice(2), command);
618
- const commandName = parsed.args[0];
619
- if (command.isMatched(commandName)) {
620
- shouldParse = false;
621
- const parsedInfo = __assign(__assign({}, parsed), {
622
- args: parsed.args.slice(1)
623
- });
624
- this.setParsedInfo(parsedInfo, command, commandName);
625
- this.emit(`command:${commandName}`, command);
626
- }
627
- }
628
- if (shouldParse) {
629
- for (const command of this.commands) {
630
- if (command.name === "") {
631
- shouldParse = false;
632
- const parsed = this.mri(argv.slice(2), command);
633
- this.setParsedInfo(parsed, command);
634
- this.emit(`command:!`, command);
635
- }
636
- }
637
- }
638
- if (shouldParse) {
639
- const parsed = this.mri(argv.slice(2));
640
- this.setParsedInfo(parsed);
641
- }
642
- if (this.options.help && this.showHelpOnExit) {
643
- this.outputHelp();
644
- run = false;
645
- this.unsetMatchedCommand();
646
- }
647
- if (this.options.version && this.showVersionOnExit && this.matchedCommandName == null) {
648
- this.outputVersion();
649
- run = false;
650
- this.unsetMatchedCommand();
651
- }
652
- const parsedArgv = {args: this.args, options: this.options};
653
- if (run) {
654
- this.runMatchedCommand();
655
- }
656
- if (!this.matchedCommand && this.args[0]) {
657
- this.emit("command:*");
658
- }
659
- return parsedArgv;
660
- }
661
- mri(argv, command) {
662
- const cliOptions = [
663
- ...this.globalCommand.options,
664
- ...command ? command.options : []
665
- ];
666
- const mriOptions = getMriOptions(cliOptions);
667
- let argsAfterDoubleDashes = [];
668
- const doubleDashesIndex = argv.indexOf("--");
669
- if (doubleDashesIndex > -1) {
670
- argsAfterDoubleDashes = argv.slice(doubleDashesIndex + 1);
671
- argv = argv.slice(0, doubleDashesIndex);
672
- }
673
- let parsed = mri2(argv, mriOptions);
674
- parsed = Object.keys(parsed).reduce((res, name) => {
675
- return __assign(__assign({}, res), {
676
- [camelcaseOptionName(name)]: parsed[name]
677
- });
678
- }, {_: []});
679
- const args = parsed._;
680
- const options = {
681
- "--": argsAfterDoubleDashes
682
- };
683
- const ignoreDefault = command && command.config.ignoreOptionDefaultValue ? command.config.ignoreOptionDefaultValue : this.globalCommand.config.ignoreOptionDefaultValue;
684
- let transforms = Object.create(null);
685
- for (const cliOption of cliOptions) {
686
- if (!ignoreDefault && cliOption.config.default !== void 0) {
687
- for (const name of cliOption.names) {
688
- options[name] = cliOption.config.default;
689
- }
690
- }
691
- if (cliOption.config.type != null) {
692
- if (transforms[cliOption.name] === void 0) {
693
- transforms[cliOption.name] = cliOption.config.type;
694
- }
695
- }
696
- }
697
- for (const key of Object.keys(parsed)) {
698
- if (key !== "_") {
699
- const keys = key.split(".");
700
- setDotProp(options, keys, parsed[key], transforms);
701
- // setByType(options, transforms);
702
- }
703
- }
704
- return {
705
- args,
706
- options
707
- };
708
- }
709
- runMatchedCommand() {
710
- const {args, options, matchedCommand: command} = this;
711
- if (!command || !command.commandAction)
712
- return;
713
- command.checkUnknownOptions();
714
- command.checkOptionValue();
715
- command.checkRequiredArgs();
716
- const actionArgs = [];
717
- command.args.forEach((arg, index) => {
718
- if (arg.variadic) {
719
- actionArgs.push(args.slice(index));
720
- } else {
721
- actionArgs.push(args[index]);
722
- }
723
- });
724
- actionArgs.push(options);
725
- return command.commandAction.apply(this, actionArgs);
726
- }
727
- }
728
-
729
- const cac = (name = "") => new CAC(name);
730
-
731
- var version = "1.5.0";
732
-
733
119
  /*
734
120
  How it works:
735
121
  `this.#head` is an instance of `Node` which keeps track of its current value and nests another instance of `Node` that keeps the value that comes after it. When a value is provided to `.enqueue()`, the code needs to iterate through `this.#head`, going deeper and deeper to find the last value. However, iterating through every single item is slow. This problem is solved by saving a reference to the last value as `this.#tail` so that it can reference it to add a new value.
@@ -8566,7 +7952,7 @@ function createMethodsRPC(project) {
8566
7952
  }
8567
7953
 
8568
7954
  function createChildProcessChannel$1(project) {
8569
- const emitter = new EventEmitter$3();
7955
+ const emitter = new EventEmitter$2();
8570
7956
  const cleanup = () => emitter.removeAllListeners();
8571
7957
  const events = { message: "message", response: "response" };
8572
7958
  const channel = {
@@ -9213,7 +8599,7 @@ function createTypecheckPool(ctx) {
9213
8599
 
9214
8600
  const suppressWarningsPath = resolve(rootDir, "./suppress-warnings.cjs");
9215
8601
  function createChildProcessChannel(project) {
9216
- const emitter = new EventEmitter$3();
8602
+ const emitter = new EventEmitter$2();
9217
8603
  const cleanup = () => emitter.removeAllListeners();
9218
8604
  const events = { message: "message", response: "response" };
9219
8605
  const channel = {
@@ -9864,23 +9250,6 @@ class VitestCache {
9864
9250
  const baseDir = slash$1(dir || "node_modules/.vite/vitest");
9865
9251
  return projectName ? resolve(root, baseDir, crypto.createHash("md5").update(projectName, "utf-8").digest("hex")) : resolve(root, baseDir);
9866
9252
  }
9867
- static async clearCache(options) {
9868
- var _a, _b, _c;
9869
- const root = resolve(options.root || process.cwd());
9870
- const configPath = options.config === false ? false : options.config ? resolve(root, options.config) : await findUp(configFiles, { cwd: root });
9871
- const config = configPath ? (_a = await loadConfigFromFile({ command: "serve", mode: "test" }, configPath)) == null ? void 0 : _a.config : void 0;
9872
- const cache = (_b = config == null ? void 0 : config.test) == null ? void 0 : _b.cache;
9873
- const projectName = (_c = config == null ? void 0 : config.test) == null ? void 0 : _c.name;
9874
- if (cache === false)
9875
- throw new Error("Cache is disabled");
9876
- const cachePath = VitestCache.resolveCacheDir(root, cache == null ? void 0 : cache.dir, projectName);
9877
- let cleared = false;
9878
- if (fs$8.existsSync(cachePath)) {
9879
- fs$8.rmSync(cachePath, { recursive: true, force: true });
9880
- cleared = true;
9881
- }
9882
- return { dir: cachePath, cleared };
9883
- }
9884
9253
  }
9885
9254
 
9886
9255
  function resolvePath(path, root) {
@@ -9928,11 +9297,11 @@ function resolveApiServerConfig(options) {
9928
9297
  }
9929
9298
  return api;
9930
9299
  }
9931
- function resolveConfig(mode, options, viteConfig) {
9932
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _A, _B, _C, _D, _E, _F, _G, _H, _I, _J, _K, _L;
9300
+ function resolveConfig(mode, options, viteConfig, logger) {
9301
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _A, _B, _C, _D, _E, _F, _G, _H, _I, _J, _K, _L, _M;
9933
9302
  if (options.dom) {
9934
9303
  if (((_a = viteConfig.test) == null ? void 0 : _a.environment) != null && viteConfig.test.environment !== "happy-dom") {
9935
- console.warn(
9304
+ logger.console.warn(
9936
9305
  c.yellow(
9937
9306
  `${c.inverse(c.yellow(" Vitest "))} Your config.test.environment ("${viteConfig.test.environment}") conflicts with --dom flag ("happy-dom"), ignoring "${viteConfig.test.environment}"`
9938
9307
  )
@@ -9972,14 +9341,16 @@ function resolveConfig(mode, options, viteConfig) {
9972
9341
  resolved.maxWorkers = Number(resolved.maxWorkers);
9973
9342
  if (resolved.minWorkers)
9974
9343
  resolved.minWorkers = Number(resolved.minWorkers);
9344
+ resolved.browser ?? (resolved.browser = {});
9345
+ (_c = resolved.browser).fileParallelism ?? (_c.fileParallelism = resolved.fileParallelism ?? false);
9975
9346
  resolved.fileParallelism ?? (resolved.fileParallelism = mode !== "benchmark");
9976
9347
  if (!resolved.fileParallelism) {
9977
9348
  resolved.maxWorkers = 1;
9978
9349
  resolved.minWorkers = 1;
9979
9350
  }
9980
9351
  if (resolved.inspect || resolved.inspectBrk) {
9981
- const isSingleThread = resolved.pool === "threads" && ((_d = (_c = resolved.poolOptions) == null ? void 0 : _c.threads) == null ? void 0 : _d.singleThread);
9982
- const isSingleFork = resolved.pool === "forks" && ((_f = (_e = resolved.poolOptions) == null ? void 0 : _e.forks) == null ? void 0 : _f.singleFork);
9352
+ const isSingleThread = resolved.pool === "threads" && ((_e = (_d = resolved.poolOptions) == null ? void 0 : _d.threads) == null ? void 0 : _e.singleThread);
9353
+ const isSingleFork = resolved.pool === "forks" && ((_g = (_f = resolved.poolOptions) == null ? void 0 : _f.forks) == null ? void 0 : _g.singleFork);
9983
9354
  if (resolved.fileParallelism && !isSingleThread && !isSingleFork) {
9984
9355
  const inspectOption = `--inspect${resolved.inspectBrk ? "-brk" : ""}`;
9985
9356
  throw new Error(`You cannot use ${inspectOption} without "--no-file-parallelism", "poolOptions.threads.singleThread" or "poolOptions.forks.singleFork"`);
@@ -9995,7 +9366,7 @@ function resolveConfig(mode, options, viteConfig) {
9995
9366
  throw new Error(`You cannot set "coverage.reportsDirectory" as ${reportsDirectory}. Vitest needs to be able to remove this directory before test run`);
9996
9367
  }
9997
9368
  resolved.deps ?? (resolved.deps = {});
9998
- (_g = resolved.deps).moduleDirectories ?? (_g.moduleDirectories = []);
9369
+ (_h = resolved.deps).moduleDirectories ?? (_h.moduleDirectories = []);
9999
9370
  resolved.deps.moduleDirectories = resolved.deps.moduleDirectories.map((dir) => {
10000
9371
  if (!dir.startsWith("/"))
10001
9372
  dir = `/${dir}`;
@@ -10005,26 +9376,26 @@ function resolveConfig(mode, options, viteConfig) {
10005
9376
  });
10006
9377
  if (!resolved.deps.moduleDirectories.includes("/node_modules/"))
10007
9378
  resolved.deps.moduleDirectories.push("/node_modules/");
10008
- (_h = resolved.deps).optimizer ?? (_h.optimizer = {});
10009
- (_i = resolved.deps.optimizer).ssr ?? (_i.ssr = {});
10010
- (_j = resolved.deps.optimizer.ssr).enabled ?? (_j.enabled = true);
10011
- (_k = resolved.deps.optimizer).web ?? (_k.web = {});
10012
- (_l = resolved.deps.optimizer.web).enabled ?? (_l.enabled = true);
10013
- (_m = resolved.deps).web ?? (_m.web = {});
10014
- (_n = resolved.deps.web).transformAssets ?? (_n.transformAssets = true);
10015
- (_o = resolved.deps.web).transformCss ?? (_o.transformCss = true);
10016
- (_p = resolved.deps.web).transformGlobPattern ?? (_p.transformGlobPattern = []);
9379
+ (_i = resolved.deps).optimizer ?? (_i.optimizer = {});
9380
+ (_j = resolved.deps.optimizer).ssr ?? (_j.ssr = {});
9381
+ (_k = resolved.deps.optimizer.ssr).enabled ?? (_k.enabled = true);
9382
+ (_l = resolved.deps.optimizer).web ?? (_l.web = {});
9383
+ (_m = resolved.deps.optimizer.web).enabled ?? (_m.enabled = true);
9384
+ (_n = resolved.deps).web ?? (_n.web = {});
9385
+ (_o = resolved.deps.web).transformAssets ?? (_o.transformAssets = true);
9386
+ (_p = resolved.deps.web).transformCss ?? (_p.transformCss = true);
9387
+ (_q = resolved.deps.web).transformGlobPattern ?? (_q.transformGlobPattern = []);
10017
9388
  resolved.server ?? (resolved.server = {});
10018
- (_q = resolved.server).deps ?? (_q.deps = {});
9389
+ (_r = resolved.server).deps ?? (_r.deps = {});
10019
9390
  const deprecatedDepsOptions = ["inline", "external", "fallbackCJS"];
10020
9391
  deprecatedDepsOptions.forEach((option) => {
10021
9392
  if (resolved.deps[option] === void 0)
10022
9393
  return;
10023
9394
  if (option === "fallbackCJS") {
10024
- console.warn(c.yellow(`${c.inverse(c.yellow(" Vitest "))} "deps.${option}" is deprecated. Use "server.deps.${option}" instead`));
9395
+ logger.console.warn(c.yellow(`${c.inverse(c.yellow(" Vitest "))} "deps.${option}" is deprecated. Use "server.deps.${option}" instead`));
10025
9396
  } else {
10026
9397
  const transformMode = resolved.environment === "happy-dom" || resolved.environment === "jsdom" ? "web" : "ssr";
10027
- console.warn(
9398
+ logger.console.warn(
10028
9399
  c.yellow(
10029
9400
  `${c.inverse(c.yellow(" Vitest "))} "deps.${option}" is deprecated. If you rely on vite-node directly, use "server.deps.${option}" instead. Otherwise, consider using "deps.optimizer.${transformMode}.${option === "external" ? "exclude" : "include"}"`
10030
9401
  )
@@ -10040,11 +9411,11 @@ function resolveConfig(mode, options, viteConfig) {
10040
9411
  if ((ssrOptions == null ? void 0 : ssrOptions.noExternal) === true && resolved.server.deps.inline == null) {
10041
9412
  resolved.server.deps.inline = true;
10042
9413
  } else {
10043
- (_r = resolved.server.deps).inline ?? (_r.inline = []);
9414
+ (_s = resolved.server.deps).inline ?? (_s.inline = []);
10044
9415
  resolved.server.deps.inline.push(...extraInlineDeps);
10045
9416
  }
10046
9417
  }
10047
- (_s = resolved.server.deps).moduleDirectories ?? (_s.moduleDirectories = []);
9418
+ (_t = resolved.server.deps).moduleDirectories ?? (_t.moduleDirectories = []);
10048
9419
  resolved.server.deps.moduleDirectories.push(...resolved.deps.moduleDirectories);
10049
9420
  if (resolved.runner)
10050
9421
  resolved.runner = resolvePath(resolved.runner, resolved.root);
@@ -10072,11 +9443,11 @@ function resolveConfig(mode, options, viteConfig) {
10072
9443
  resolved.poolOptions = {
10073
9444
  ...resolved.poolOptions,
10074
9445
  threads: {
10075
- ...(_t = resolved.poolOptions) == null ? void 0 : _t.threads,
9446
+ ...(_u = resolved.poolOptions) == null ? void 0 : _u.threads,
10076
9447
  maxThreads: Number.parseInt(process.env.VITEST_MAX_THREADS)
10077
9448
  },
10078
9449
  vmThreads: {
10079
- ...(_u = resolved.poolOptions) == null ? void 0 : _u.vmThreads,
9450
+ ...(_v = resolved.poolOptions) == null ? void 0 : _v.vmThreads,
10080
9451
  maxThreads: Number.parseInt(process.env.VITEST_MAX_THREADS)
10081
9452
  }
10082
9453
  };
@@ -10085,11 +9456,11 @@ function resolveConfig(mode, options, viteConfig) {
10085
9456
  resolved.poolOptions = {
10086
9457
  ...resolved.poolOptions,
10087
9458
  threads: {
10088
- ...(_v = resolved.poolOptions) == null ? void 0 : _v.threads,
9459
+ ...(_w = resolved.poolOptions) == null ? void 0 : _w.threads,
10089
9460
  minThreads: Number.parseInt(process.env.VITEST_MIN_THREADS)
10090
9461
  },
10091
9462
  vmThreads: {
10092
- ...(_w = resolved.poolOptions) == null ? void 0 : _w.vmThreads,
9463
+ ...(_x = resolved.poolOptions) == null ? void 0 : _x.vmThreads,
10093
9464
  minThreads: Number.parseInt(process.env.VITEST_MIN_THREADS)
10094
9465
  }
10095
9466
  };
@@ -10098,11 +9469,11 @@ function resolveConfig(mode, options, viteConfig) {
10098
9469
  resolved.poolOptions = {
10099
9470
  ...resolved.poolOptions,
10100
9471
  forks: {
10101
- ...(_x = resolved.poolOptions) == null ? void 0 : _x.forks,
9472
+ ...(_y = resolved.poolOptions) == null ? void 0 : _y.forks,
10102
9473
  maxForks: Number.parseInt(process.env.VITEST_MAX_FORKS)
10103
9474
  },
10104
9475
  vmForks: {
10105
- ...(_y = resolved.poolOptions) == null ? void 0 : _y.vmForks,
9476
+ ...(_z = resolved.poolOptions) == null ? void 0 : _z.vmForks,
10106
9477
  maxForks: Number.parseInt(process.env.VITEST_MAX_FORKS)
10107
9478
  }
10108
9479
  };
@@ -10111,11 +9482,11 @@ function resolveConfig(mode, options, viteConfig) {
10111
9482
  resolved.poolOptions = {
10112
9483
  ...resolved.poolOptions,
10113
9484
  forks: {
10114
- ...(_z = resolved.poolOptions) == null ? void 0 : _z.forks,
9485
+ ...(_A = resolved.poolOptions) == null ? void 0 : _A.forks,
10115
9486
  minForks: Number.parseInt(process.env.VITEST_MIN_FORKS)
10116
9487
  },
10117
9488
  vmForks: {
10118
- ...(_A = resolved.poolOptions) == null ? void 0 : _A.vmForks,
9489
+ ...(_B = resolved.poolOptions) == null ? void 0 : _B.vmForks,
10119
9490
  minForks: Number.parseInt(process.env.VITEST_MIN_FORKS)
10120
9491
  }
10121
9492
  };
@@ -10207,13 +9578,13 @@ function resolveConfig(mode, options, viteConfig) {
10207
9578
  resolved.passWithNoTests ?? (resolved.passWithNoTests = true);
10208
9579
  resolved.css ?? (resolved.css = {});
10209
9580
  if (typeof resolved.css === "object") {
10210
- (_B = resolved.css).modules ?? (_B.modules = {});
10211
- (_C = resolved.css.modules).classNameStrategy ?? (_C.classNameStrategy = "stable");
9581
+ (_C = resolved.css).modules ?? (_C.modules = {});
9582
+ (_D = resolved.css.modules).classNameStrategy ?? (_D.classNameStrategy = "stable");
10212
9583
  }
10213
9584
  if (resolved.cache !== false) {
10214
9585
  let cacheDir = VitestCache.resolveCacheDir("", resolve(viteConfig.cacheDir, "vitest"), resolved.name);
10215
9586
  if (resolved.cache && resolved.cache.dir) {
10216
- console.warn(
9587
+ logger.console.warn(
10217
9588
  c.yellow(
10218
9589
  `${c.inverse(c.yellow(" Vitest "))} "cache.dir" is deprecated, use Vite's "cacheDir" instead if you want to change the cache director. Note caches will be written to "cacheDir/vitest"`
10219
9590
  )
@@ -10225,29 +9596,29 @@ function resolveConfig(mode, options, viteConfig) {
10225
9596
  resolved.sequence ?? (resolved.sequence = {});
10226
9597
  if (resolved.sequence.shuffle && typeof resolved.sequence.shuffle === "object") {
10227
9598
  const { files, tests } = resolved.sequence.shuffle;
10228
- (_D = resolved.sequence).sequencer ?? (_D.sequencer = files ? RandomSequencer : BaseSequencer);
9599
+ (_E = resolved.sequence).sequencer ?? (_E.sequencer = files ? RandomSequencer : BaseSequencer);
10229
9600
  resolved.sequence.shuffle = tests;
10230
9601
  }
10231
- if (!((_E = resolved.sequence) == null ? void 0 : _E.sequencer)) {
9602
+ if (!((_F = resolved.sequence) == null ? void 0 : _F.sequencer)) {
10232
9603
  resolved.sequence.sequencer = resolved.sequence.shuffle ? RandomSequencer : BaseSequencer;
10233
9604
  }
10234
- (_F = resolved.sequence).hooks ?? (_F.hooks = "parallel");
9605
+ (_G = resolved.sequence).hooks ?? (_G.hooks = "parallel");
10235
9606
  if (resolved.sequence.sequencer === RandomSequencer)
10236
- (_G = resolved.sequence).seed ?? (_G.seed = Date.now());
9607
+ (_H = resolved.sequence).seed ?? (_H.seed = Date.now());
10237
9608
  resolved.typecheck = {
10238
9609
  ...configDefaults.typecheck,
10239
9610
  ...resolved.typecheck
10240
9611
  };
10241
9612
  resolved.environmentMatchGlobs = (resolved.environmentMatchGlobs || []).map((i) => [resolve(resolved.root, i[0]), i[1]]);
10242
9613
  resolved.typecheck ?? (resolved.typecheck = {});
10243
- (_H = resolved.typecheck).enabled ?? (_H.enabled = false);
9614
+ (_I = resolved.typecheck).enabled ?? (_I.enabled = false);
10244
9615
  if (resolved.typecheck.enabled)
10245
- console.warn(c.yellow("Testing types with tsc and vue-tsc is an experimental feature.\nBreaking changes might not follow SemVer, please pin Vitest's version when using it."));
9616
+ logger.console.warn(c.yellow("Testing types with tsc and vue-tsc is an experimental feature.\nBreaking changes might not follow SemVer, please pin Vitest's version when using it."));
10246
9617
  resolved.browser ?? (resolved.browser = {});
10247
- (_I = resolved.browser).enabled ?? (_I.enabled = false);
10248
- (_J = resolved.browser).headless ?? (_J.headless = isCI);
10249
- (_K = resolved.browser).slowHijackESM ?? (_K.slowHijackESM = false);
10250
- (_L = resolved.browser).isolate ?? (_L.isolate = true);
9618
+ (_J = resolved.browser).enabled ?? (_J.enabled = false);
9619
+ (_K = resolved.browser).headless ?? (_K.headless = isCI);
9620
+ (_L = resolved.browser).slowHijackESM ?? (_L.slowHijackESM = false);
9621
+ (_M = resolved.browser).isolate ?? (_M.isolate = true);
10251
9622
  if (resolved.browser.enabled && provider$1 === "stackblitz")
10252
9623
  resolved.browser.provider = "none";
10253
9624
  resolved.browser.api = resolveApiServerConfig(resolved.browser) || {
@@ -11001,40 +10372,24 @@ async function loadGlobalSetupFile(file, runner) {
11001
10372
  }
11002
10373
 
11003
10374
  async function initializeProject(workspacePath, ctx, options) {
10375
+ var _a;
11004
10376
  const project = new WorkspaceProject(workspacePath, ctx, options);
11005
10377
  const configFile = options.extends ? resolve(dirname(options.workspaceConfigPath), options.extends) : typeof workspacePath === "number" || workspacePath.endsWith("/") ? false : workspacePath;
11006
10378
  const root = options.root || (typeof workspacePath === "number" ? void 0 : workspacePath.endsWith("/") ? workspacePath : dirname(workspacePath));
11007
- return new Promise((resolve2, reject) => {
11008
- var _a;
11009
- const resolution = createDefer();
11010
- let configResolved = false;
11011
- const config = {
11012
- ...options,
11013
- root,
11014
- logLevel: "error",
11015
- configFile,
11016
- // this will make "mode": "test" | "benchmark" inside defineConfig
11017
- mode: ((_a = options.test) == null ? void 0 : _a.mode) || options.mode || ctx.config.mode,
11018
- plugins: [
11019
- {
11020
- name: "vitest:workspace:resolve",
11021
- configResolved() {
11022
- configResolved = true;
11023
- resolve2(() => resolution);
11024
- }
11025
- },
11026
- ...options.plugins || [],
11027
- WorkspaceVitestPlugin(project, { ...options, root, workspacePath })
11028
- ]
11029
- };
11030
- createViteServer(config).then(() => resolution.resolve(project)).catch((err) => {
11031
- if (configResolved)
11032
- resolution.reject(err);
11033
- else
11034
- reject(err);
11035
- });
11036
- return project;
11037
- });
10379
+ const config = {
10380
+ ...options,
10381
+ root,
10382
+ logLevel: "error",
10383
+ configFile,
10384
+ // this will make "mode": "test" | "benchmark" inside defineConfig
10385
+ mode: ((_a = options.test) == null ? void 0 : _a.mode) || options.mode || ctx.config.mode,
10386
+ plugins: [
10387
+ ...options.plugins || [],
10388
+ WorkspaceVitestPlugin(project, { ...options, root, workspacePath })
10389
+ ]
10390
+ };
10391
+ await createViteServer(config);
10392
+ return project;
11038
10393
  }
11039
10394
  class WorkspaceProject {
11040
10395
  constructor(path, ctx, options) {
@@ -11203,11 +10558,9 @@ ${c.red(divider(c.bold(c.inverse(" Error during global setup "))))}`);
11203
10558
  return testFiles.filter((t) => {
11204
10559
  const testFile = relative(dir, t).toLocaleLowerCase();
11205
10560
  return filters.some((f) => {
10561
+ if (isAbsolute(f) && t.startsWith(f))
10562
+ return true;
11206
10563
  const relativePath = f.endsWith("/") ? join(relative(dir, f), "/") : relative(dir, f);
11207
- if (isAbsolute(f)) {
11208
- if (relativePath === ".." || relativePath === "../" || relativePath.startsWith("../.."))
11209
- return true;
11210
- }
11211
10564
  return testFile.includes(f.toLocaleLowerCase()) || testFile.includes(relativePath.toLocaleLowerCase());
11212
10565
  });
11213
10566
  });
@@ -11241,7 +10594,8 @@ ${c.red(divider(c.bold(c.inverse(" Error during global setup "))))}`);
11241
10594
  ...options,
11242
10595
  coverage: this.ctx.config.coverage
11243
10596
  },
11244
- server.config
10597
+ server.config,
10598
+ this.ctx.logger
11245
10599
  );
11246
10600
  this.server = server;
11247
10601
  this.vitenode = new ViteNodeServer(server, this.config.server);
@@ -11391,7 +10745,7 @@ const WATCHER_DEBOUNCE = 100;
11391
10745
  class Vitest {
11392
10746
  constructor(mode, options = {}) {
11393
10747
  this.mode = mode;
11394
- this.logger = new Logger(this);
10748
+ this.logger = new Logger(this, options.stdout, options.stderr);
11395
10749
  this.packageInstaller = options.packageInstaller || new VitestPackageInstaller();
11396
10750
  }
11397
10751
  config = void 0;
@@ -11435,7 +10789,7 @@ class Vitest {
11435
10789
  this.coverageProvider = void 0;
11436
10790
  this.runningPromise = void 0;
11437
10791
  this.projectsTestFiles.clear();
11438
- const resolved = resolveConfig(this.mode, options, server.config);
10792
+ const resolved = resolveConfig(this.mode, options, server.config, this.logger);
11439
10793
  this.server = server;
11440
10794
  this.config = resolved;
11441
10795
  this.state = new StateManager();
@@ -11611,13 +10965,15 @@ class Vitest {
11611
10965
  for (const filepath of filteredWorkspaces) {
11612
10966
  if (this.server.config.configFile === filepath) {
11613
10967
  const project = await this.createCoreProject();
11614
- projects.push(() => Promise.resolve(project));
10968
+ projects.push(project);
11615
10969
  continue;
11616
10970
  }
11617
10971
  const dir = filepath.endsWith("/") ? filepath.slice(0, -1) : dirname(filepath);
11618
10972
  if (isMainThread)
11619
10973
  process.chdir(dir);
11620
- projects.push(await initializeProject(filepath, this, { workspaceConfigPath, test: cliOverrides }));
10974
+ projects.push(
10975
+ await initializeProject(filepath, this, { workspaceConfigPath, test: cliOverrides })
10976
+ );
11621
10977
  }
11622
10978
  } finally {
11623
10979
  if (isMainThread)
@@ -11629,13 +10985,10 @@ class Vitest {
11629
10985
  });
11630
10986
  if (!projects.length && !projectPromises.length)
11631
10987
  return [await this.createCoreProject()];
11632
- const resolvedProjectsReceivers = [
10988
+ const resolvedProjects = await Promise.all([
11633
10989
  ...projects,
11634
10990
  ...await Promise.all(projectPromises)
11635
- ];
11636
- const resolvedProjects = await Promise.all(
11637
- resolvedProjectsReceivers.map((receiver) => receiver())
11638
- );
10991
+ ]);
11639
10992
  const names = /* @__PURE__ */ new Set();
11640
10993
  for (const project of resolvedProjects) {
11641
10994
  const name = project.getName();
@@ -12026,8 +11379,8 @@ class Vitest {
12026
11379
  teardownProjects.push(this.coreWorkspaceProject);
12027
11380
  for await (const project of teardownProjects.reverse())
12028
11381
  await project.teardownGlobalSetup();
12029
- const closePromises = this.projects.map((w) => w.close().then(() => w.server = void 0));
12030
- if (!this.projects.includes(this.coreWorkspaceProject))
11382
+ const closePromises = this.resolvedProjects.map((w) => w.close().then(() => w.server = void 0));
11383
+ if (!this.resolvedProjects.includes(this.coreWorkspaceProject))
12031
11384
  closePromises.push(this.coreWorkspaceProject.close().then(() => this.server = void 0));
12032
11385
  if (this.pool) {
12033
11386
  closePromises.push((async () => {
@@ -12056,7 +11409,7 @@ class Vitest {
12056
11409
  console.warn(`close timed out after ${this.config.teardownTimeout}ms`);
12057
11410
  this.state.getProcessTimeoutCauses().forEach((cause) => console.warn(cause));
12058
11411
  if (!this.pool) {
12059
- const runningServers = [this.server, ...this.projects.map((p) => p.server)].filter(Boolean).length;
11412
+ const runningServers = [this.server, ...this.resolvedProjects.map((p) => p.server)].filter(Boolean).length;
12060
11413
  if (runningServers === 1)
12061
11414
  console.warn("Tests closed successfully but something prevents Vite server from exiting");
12062
11415
  else if (runningServers > 1)
@@ -12173,6 +11526,15 @@ async function VitestPlugin(options = {}, ctx = new Vitest("test")) {
12173
11526
  allow: resolveFsAllow(getRoot(), testConfig.config)
12174
11527
  }
12175
11528
  },
11529
+ build: {
11530
+ // Vitest doesn't use outputDir, but this value affects what folders are watched
11531
+ // https://github.com/vitest-dev/vitest/issues/5429
11532
+ // This works for Vite <5.2.10
11533
+ outDir: "dummy-non-existing-folder",
11534
+ // This works for Vite >=5.2.10
11535
+ // https://github.com/vitejs/vite/pull/16453
11536
+ emptyOutDir: false
11537
+ },
12176
11538
  test: {
12177
11539
  poolOptions: {
12178
11540
  threads: {
@@ -18569,20 +17931,24 @@ class WatchFilter {
18569
17931
  results = [];
18570
17932
  selectionIndex = -1;
18571
17933
  onKeyPress;
18572
- constructor(message) {
17934
+ stdin;
17935
+ stdout;
17936
+ constructor(message, stdin = process.stdin, stdout$1 = stdout()) {
18573
17937
  this.message = message;
18574
- this.filterRL = readline.createInterface({ input: process.stdin, escapeCodeTimeout: 50 });
18575
- readline.emitKeypressEvents(process.stdin, this.filterRL);
18576
- if (process.stdin.isTTY)
18577
- process.stdin.setRawMode(true);
17938
+ this.stdin = stdin;
17939
+ this.stdout = stdout$1;
17940
+ this.filterRL = readline.createInterface({ input: this.stdin, escapeCodeTimeout: 50 });
17941
+ readline.emitKeypressEvents(this.stdin, this.filterRL);
17942
+ if (this.stdin.isTTY)
17943
+ this.stdin.setRawMode(true);
18578
17944
  }
18579
17945
  async filter(filterFunc) {
18580
- stdout().write(this.promptLine());
17946
+ this.write(this.promptLine());
18581
17947
  const resultPromise = createDefer();
18582
17948
  this.onKeyPress = this.filterHandler(filterFunc, (result) => {
18583
17949
  resultPromise.resolve(result);
18584
17950
  });
18585
- process.stdin.on("keypress", this.onKeyPress);
17951
+ this.stdin.on("keypress", this.onKeyPress);
18586
17952
  try {
18587
17953
  return await resultPromise;
18588
17954
  } finally {
@@ -18669,27 +18035,32 @@ ${resultBody}`;
18669
18035
  eraseAndPrint(str) {
18670
18036
  let rows = 0;
18671
18037
  const lines = str.split(/\r?\n/);
18672
- for (const line of lines)
18673
- rows += 1 + Math.floor(Math.max(stripAnsi(line).length - 1, 0) / stdout().columns);
18674
- stdout().write(`${ESC}1G`);
18675
- stdout().write(`${ESC}J`);
18676
- stdout().write(str);
18677
- stdout().write(`${ESC}${rows - 1}A`);
18038
+ for (const line of lines) {
18039
+ const columns = "columns" in this.stdout ? this.stdout.columns : 80;
18040
+ rows += 1 + Math.floor(Math.max(stripAnsi(line).length - 1, 0) / columns);
18041
+ }
18042
+ this.write(`${ESC}1G`);
18043
+ this.write(`${ESC}J`);
18044
+ this.write(str);
18045
+ this.write(`${ESC}${rows - 1}A`);
18678
18046
  }
18679
18047
  close() {
18680
18048
  this.filterRL.close();
18681
18049
  if (this.onKeyPress)
18682
- process.stdin.removeListener("keypress", this.onKeyPress);
18683
- if (process.stdin.isTTY)
18684
- process.stdin.setRawMode(false);
18050
+ this.stdin.removeListener("keypress", this.onKeyPress);
18051
+ if (this.stdin.isTTY)
18052
+ this.stdin.setRawMode(false);
18685
18053
  }
18686
18054
  restoreCursor() {
18687
18055
  var _a;
18688
18056
  const cursortPos = this.keywordOffset() + (((_a = this.currentKeyword) == null ? void 0 : _a.length) || 0);
18689
- stdout().write(`${ESC}${cursortPos}G`);
18057
+ this.write(`${ESC}${cursortPos}G`);
18690
18058
  }
18691
18059
  cancel() {
18692
- stdout().write(`${ESC}J`);
18060
+ this.write(`${ESC}J`);
18061
+ }
18062
+ write(data) {
18063
+ this.stdout.write(data);
18693
18064
  }
18694
18065
  }
18695
18066
 
@@ -18712,7 +18083,7 @@ ${keys.map((i) => c.dim(" press ") + c.reset([i[0]].flat().map(c.bold).join(",
18712
18083
  `
18713
18084
  );
18714
18085
  }
18715
- function registerConsoleShortcuts(ctx) {
18086
+ function registerConsoleShortcuts(ctx, stdin = process.stdin, stdout2) {
18716
18087
  let latestFilename = "";
18717
18088
  async function _keypressHandler(str, key) {
18718
18089
  if (str === "" || str === "\x1B" || key && key.ctrl && key.name === "c") {
@@ -18760,7 +18131,7 @@ function registerConsoleShortcuts(ctx) {
18760
18131
  }
18761
18132
  async function inputNamePattern() {
18762
18133
  off();
18763
- const watchFilter = new WatchFilter("Input test name pattern (RegExp)");
18134
+ const watchFilter = new WatchFilter("Input test name pattern (RegExp)", stdin, stdout2);
18764
18135
  const filter = await watchFilter.filter((str) => {
18765
18136
  const files = ctx.state.getFiles();
18766
18137
  const tests = getTests(files);
@@ -18787,7 +18158,7 @@ function registerConsoleShortcuts(ctx) {
18787
18158
  }
18788
18159
  async function inputFilePattern() {
18789
18160
  off();
18790
- const watchFilter = new WatchFilter("Input filename pattern");
18161
+ const watchFilter = new WatchFilter("Input filename pattern", stdin, stdout2);
18791
18162
  const filter = await watchFilter.filter(async (str) => {
18792
18163
  const files = await ctx.globTestFiles([str]);
18793
18164
  return files.map(
@@ -18801,18 +18172,18 @@ function registerConsoleShortcuts(ctx) {
18801
18172
  let rl;
18802
18173
  function on() {
18803
18174
  off();
18804
- rl = readline.createInterface({ input: process.stdin, escapeCodeTimeout: 50 });
18805
- readline.emitKeypressEvents(process.stdin, rl);
18806
- if (process.stdin.isTTY)
18807
- process.stdin.setRawMode(true);
18808
- process.stdin.on("keypress", keypressHandler);
18175
+ rl = readline.createInterface({ input: stdin, escapeCodeTimeout: 50 });
18176
+ readline.emitKeypressEvents(stdin, rl);
18177
+ if (stdin.isTTY)
18178
+ stdin.setRawMode(true);
18179
+ stdin.on("keypress", keypressHandler);
18809
18180
  }
18810
18181
  function off() {
18811
18182
  rl == null ? void 0 : rl.close();
18812
18183
  rl = void 0;
18813
- process.stdin.removeListener("keypress", keypressHandler);
18814
- if (process.stdin.isTTY)
18815
- process.stdin.setRawMode(false);
18184
+ stdin.removeListener("keypress", keypressHandler);
18185
+ if (stdin.isTTY)
18186
+ stdin.setRawMode(false);
18816
18187
  }
18817
18188
  on();
18818
18189
  return function cleanup() {
@@ -18848,9 +18219,11 @@ async function startVitest(mode, cliFilters = [], options = {}, viteOverrides, v
18848
18219
  process.exitCode = 1;
18849
18220
  return ctx;
18850
18221
  }
18222
+ const stdin = (vitestOptions == null ? void 0 : vitestOptions.stdin) || process.stdin;
18223
+ const stdout = (vitestOptions == null ? void 0 : vitestOptions.stdout) || process.stdout;
18851
18224
  let stdinCleanup;
18852
- if (process.stdin.isTTY && ctx.config.watch)
18853
- stdinCleanup = registerConsoleShortcuts(ctx);
18225
+ if (stdin.isTTY && ctx.config.watch)
18226
+ stdinCleanup = registerConsoleShortcuts(ctx, stdin, stdout);
18854
18227
  ctx.onServerRestart((reason) => {
18855
18228
  ctx.report("onServerRestart", reason);
18856
18229
  if (process.env.VITEST_CLI_WRAPPER)
@@ -18874,785 +18247,9 @@ async function startVitest(mode, cliFilters = [], options = {}, viteOverrides, v
18874
18247
  return ctx;
18875
18248
  }
18876
18249
 
18877
- const apiConfig = (port) => ({
18878
- port: {
18879
- 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}`,
18880
- argument: "[port]"
18881
- },
18882
- host: {
18883
- 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",
18884
- argument: "[host]"
18885
- },
18886
- strictPort: {
18887
- description: "Set to true to exit if port is already in use, instead of automatically trying the next available port"
18888
- },
18889
- middlewareMode: null
18250
+ var cliApi = /*#__PURE__*/Object.freeze({
18251
+ __proto__: null,
18252
+ startVitest: startVitest
18890
18253
  });
18891
- const poolThreadsCommands = {
18892
- isolate: {
18893
- description: "Isolate tests in threads pool (default: true)"
18894
- },
18895
- singleThread: {
18896
- description: "Run tests inside a single thread (default: false)"
18897
- },
18898
- maxThreads: {
18899
- description: "Maximum number of threads to run tests in",
18900
- argument: "<workers>"
18901
- },
18902
- minThreads: {
18903
- description: "Minimum number of threads to run tests in",
18904
- argument: "<workers>"
18905
- },
18906
- useAtomics: {
18907
- description: "Use Atomics to synchronize threads. This can improve performance in some cases, but might cause segfault in older Node versions (default: false)"
18908
- },
18909
- execArgv: null
18910
- };
18911
- const poolForksCommands = {
18912
- isolate: {
18913
- description: "Isolate tests in threads pool (default: true)"
18914
- },
18915
- singleFork: {
18916
- description: "Run tests inside a single child_process (default: false)"
18917
- },
18918
- maxForks: {
18919
- description: "Maximum number of processes to run tests in",
18920
- argument: "<workers>"
18921
- },
18922
- minForks: {
18923
- description: "Minimum number of processes to run tests in",
18924
- argument: "<workers>"
18925
- },
18926
- execArgv: null
18927
- };
18928
- function watermarkTransform(value) {
18929
- if (typeof value === "string")
18930
- return value.split(",").map(Number);
18931
- return value;
18932
- }
18933
- function transformNestedBoolean(value) {
18934
- if (typeof value === "boolean")
18935
- return { enabled: value };
18936
- return value;
18937
- }
18938
- const cliOptionsConfig = {
18939
- root: {
18940
- description: "Root path",
18941
- shorthand: "r",
18942
- argument: "<path>",
18943
- normalize: true
18944
- },
18945
- config: {
18946
- shorthand: "c",
18947
- description: "Path to config file",
18948
- argument: "<path>",
18949
- normalize: true
18950
- },
18951
- update: {
18952
- shorthand: "u",
18953
- description: "Update snapshot"
18954
- },
18955
- watch: {
18956
- shorthand: "w",
18957
- description: "Enable watch mode"
18958
- },
18959
- testNamePattern: {
18960
- description: "Run tests with full names matching the specified regexp pattern",
18961
- argument: "<pattern>",
18962
- shorthand: "t"
18963
- },
18964
- dir: {
18965
- description: "Base directory to scan for the test files",
18966
- argument: "<path>",
18967
- normalize: true
18968
- },
18969
- ui: {
18970
- description: "Enable UI"
18971
- },
18972
- open: {
18973
- description: "Open UI automatically (default: !process.env.CI)"
18974
- },
18975
- api: {
18976
- argument: "[port]",
18977
- 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}`,
18978
- subcommands: apiConfig(defaultPort)
18979
- },
18980
- silent: {
18981
- description: "Silent console output from tests"
18982
- },
18983
- hideSkippedTests: {
18984
- description: "Hide logs for skipped tests"
18985
- },
18986
- reporters: {
18987
- alias: "reporter",
18988
- description: "Specify reporters",
18989
- argument: "<name>",
18990
- subcommands: null,
18991
- // don't support custom objects
18992
- array: true
18993
- },
18994
- outputFile: {
18995
- argument: "<filename/-s>",
18996
- 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)",
18997
- subcommands: null
18998
- },
18999
- coverage: {
19000
- description: "Enable coverage report",
19001
- argument: "",
19002
- // empty string means boolean
19003
- transform: transformNestedBoolean,
19004
- subcommands: {
19005
- all: {
19006
- description: "Whether to include all files, including the untested ones into report",
19007
- default: true
19008
- },
19009
- provider: {
19010
- description: 'Select the tool for coverage collection, available values are: "v8", "istanbul" and "custom"',
19011
- argument: "<name>"
19012
- },
19013
- enabled: {
19014
- description: "Enables coverage collection. Can be overridden using the --coverage CLI option (default: false)"
19015
- },
19016
- include: {
19017
- description: "Files included in coverage as glob patterns. May be specified more than once when using multiple patterns (default: **)",
19018
- argument: "<pattern>",
19019
- array: true
19020
- },
19021
- exclude: {
19022
- description: "Files to be excluded in coverage. May be specified more than once when using multiple extensions (default: Visit https://vitest.dev/config/#coverage-exclude)",
19023
- argument: "<pattern>",
19024
- array: true
19025
- },
19026
- extension: {
19027
- description: 'Extension to be included in coverage. May be specified more than once when using multiple extensions (default: [".js", ".cjs", ".mjs", ".ts", ".mts", ".cts", ".tsx", ".jsx", ".vue", ".svelte"])',
19028
- argument: "<extension>",
19029
- array: true
19030
- },
19031
- clean: {
19032
- description: "Clean coverage results before running tests (default: true)"
19033
- },
19034
- cleanOnRerun: {
19035
- description: "Clean coverage report on watch rerun (default: true)"
19036
- },
19037
- reportsDirectory: {
19038
- description: "Directory to write coverage report to (default: ./coverage)",
19039
- argument: "<path>",
19040
- normalize: true
19041
- },
19042
- reporter: {
19043
- description: 'Coverage reporters to use. Visit https://vitest.dev/config/#coverage-reporter for more information (default: ["text", "html", "clover", "json"])',
19044
- argument: "<name>",
19045
- subcommands: null,
19046
- // don't support custom objects
19047
- array: true
19048
- },
19049
- reportOnFailure: {
19050
- description: "Generate coverage report even when tests fail (default: false)"
19051
- },
19052
- allowExternal: {
19053
- description: "Collect coverage of files outside the project root (default: false)"
19054
- },
19055
- skipFull: {
19056
- description: "Do not show files with 100% statement, branch, and function coverage (default: false)"
19057
- },
19058
- thresholds: {
19059
- description: null,
19060
- argument: "",
19061
- // no displayed
19062
- subcommands: {
19063
- perFile: {
19064
- 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)"
19065
- },
19066
- autoUpdate: {
19067
- description: 'Update threshold values: "lines", "functions", "branches" and "statements" to configuration file when current coverage is above the configured thresholds (default: false)'
19068
- },
19069
- lines: {
19070
- description: "Threshold for lines. Visit https://github.com/istanbuljs/nyc#coverage-thresholds for more information. This option is not available for custom providers",
19071
- argument: "<number>"
19072
- },
19073
- functions: {
19074
- description: "Threshold for functions. Visit https://github.com/istanbuljs/nyc#coverage-thresholds for more information. This option is not available for custom providers",
19075
- argument: "<number>"
19076
- },
19077
- branches: {
19078
- description: "Threshold for branches. Visit https://github.com/istanbuljs/nyc#coverage-thresholds for more information. This option is not available for custom providers",
19079
- argument: "<number>"
19080
- },
19081
- statements: {
19082
- description: "Threshold for statements. Visit https://github.com/istanbuljs/nyc#coverage-thresholds for more information. This option is not available for custom providers",
19083
- argument: "<number>"
19084
- },
19085
- 100: {
19086
- description: "Shortcut to set all coverage thresholds to 100 (default: false)"
19087
- }
19088
- }
19089
- },
19090
- ignoreClassMethods: {
19091
- description: "Array of class method names to ignore for coverage. Visit https://github.com/istanbuljs/nyc#ignoring-methods for more information. This option is only available for the istanbul providers (default: [])",
19092
- argument: "<name>",
19093
- array: true
19094
- },
19095
- processingConcurrency: {
19096
- description: "Concurrency limit used when processing the coverage results. (default min between 20 and the number of CPUs)",
19097
- argument: "<number>"
19098
- },
19099
- customProviderModule: {
19100
- description: "Specifies the module name or path for the custom coverage provider module. Visit https://vitest.dev/guide/coverage.html#custom-coverage-provider for more information. This option is only available for custom providers",
19101
- argument: "<path>",
19102
- normalize: true
19103
- },
19104
- watermarks: {
19105
- description: null,
19106
- argument: "",
19107
- // no displayed
19108
- subcommands: {
19109
- statements: {
19110
- description: "High and low watermarks for statements in the format of <high>,<low>",
19111
- argument: "<watermarks>",
19112
- transform: watermarkTransform
19113
- },
19114
- lines: {
19115
- description: "High and low watermarks for lines in the format of <high>,<low>",
19116
- argument: "<watermarks>",
19117
- transform: watermarkTransform
19118
- },
19119
- branches: {
19120
- description: "High and low watermarks for branches in the format of <high>,<low>",
19121
- argument: "<watermarks>",
19122
- transform: watermarkTransform
19123
- },
19124
- functions: {
19125
- description: "High and low watermarks for functions in the format of <high>,<low>",
19126
- argument: "<watermarks>",
19127
- transform: watermarkTransform
19128
- }
19129
- }
19130
- }
19131
- }
19132
- },
19133
- mode: {
19134
- description: "Override Vite mode (default: test or benchmark)",
19135
- argument: "<name>"
19136
- },
19137
- workspace: {
19138
- description: "Path to a workspace configuration file",
19139
- argument: "<path>",
19140
- normalize: true
19141
- },
19142
- isolate: {
19143
- description: "Run every test file in isolation. To disable isolation, use --no-isolate (default: true)"
19144
- },
19145
- globals: {
19146
- description: "Inject apis globally"
19147
- },
19148
- dom: {
19149
- description: "Mock browser API with happy-dom"
19150
- },
19151
- browser: {
19152
- description: "Run tests in the browser. Equivalent to --browser.enabled (default: false)",
19153
- argument: "<name>",
19154
- transform(browser) {
19155
- if (typeof browser === "boolean")
19156
- return { enabled: browser };
19157
- if (browser === "true" || browser === "false")
19158
- return { enabled: browser === "true" };
19159
- if (browser === "yes" || browser === "no")
19160
- return { enabled: browser === "yes" };
19161
- if (typeof browser === "string")
19162
- return { enabled: true, name: browser };
19163
- return browser;
19164
- },
19165
- subcommands: {
19166
- enabled: {
19167
- description: "Run tests in the browser. Equivalent to --browser.enabled (default: false)"
19168
- },
19169
- name: {
19170
- description: "Run all tests in a specific browser. Some browsers are only available for specific providers (see --browser.provider). Visit https://vitest.dev/config/#browser-name for more information",
19171
- argument: "<name>"
19172
- },
19173
- headless: {
19174
- 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)"
19175
- },
19176
- api: {
19177
- description: "Specify options for the browser API server. Does not affect the --api option",
19178
- argument: "[port]",
19179
- subcommands: apiConfig(defaultBrowserPort)
19180
- },
19181
- provider: {
19182
- description: 'Provider used to run browser tests. Some browsers are only available for specific providers. Can be "webdriverio", "playwright", or the path to a custom provider. Visit https://vitest.dev/config/#browser-provider for more information (default: "webdriverio")',
19183
- argument: "<name>",
19184
- subcommands: null
19185
- // don't support custom objects
19186
- },
19187
- providerOptions: {
19188
- description: "Options that are passed down to a browser provider. Visit https://vitest.dev/config/#browser-provideroptions-1-0-0 for more information",
19189
- argument: "<options>",
19190
- subcommands: null
19191
- // don't support custom objects
19192
- },
19193
- slowHijackESM: {
19194
- description: "Let Vitest use its own module resolution on the browser to enable APIs such as vi.mock and vi.spyOn. Visit https://vitest.dev/config/#browser-slowhijackesm for more information (default: false)"
19195
- },
19196
- isolate: {
19197
- description: "Run every browser test file in isolation. To disable isolation, use --browser.isolate=false (default: true)"
19198
- },
19199
- fileParallelism: {
19200
- description: "Should all test files run in parallel. Use --browser.file-parallelism=false to disable (default: same as --file-parallelism)"
19201
- }
19202
- }
19203
- },
19204
- pool: {
19205
- description: "Specify pool, if not running in the browser (default: threads)",
19206
- argument: "<pool>",
19207
- subcommands: null
19208
- // don't support custom objects
19209
- },
19210
- poolOptions: {
19211
- description: "Specify pool options",
19212
- argument: "<options>",
19213
- // we use casting here because TypeScript (for some reason) makes this into CLIOption<unknown>
19214
- // even when using casting, these types fail if the new option is added which is good
19215
- subcommands: {
19216
- threads: {
19217
- description: "Specify threads pool options",
19218
- argument: "<options>",
19219
- subcommands: poolThreadsCommands
19220
- },
19221
- vmThreads: {
19222
- description: "Specify VM threads pool options",
19223
- argument: "<options>",
19224
- subcommands: {
19225
- ...poolThreadsCommands,
19226
- memoryLimit: {
19227
- description: "Memory limit for VM threads pool. If you see memory leaks, try to tinker this value.",
19228
- argument: "<limit>"
19229
- }
19230
- }
19231
- },
19232
- forks: {
19233
- description: "Specify forks pool options",
19234
- argument: "<options>",
19235
- subcommands: poolForksCommands
19236
- },
19237
- vmForks: {
19238
- description: "Specify VM forks pool options",
19239
- argument: "<options>",
19240
- subcommands: {
19241
- ...poolForksCommands,
19242
- memoryLimit: {
19243
- description: "Memory limit for VM forks pool. If you see memory leaks, try to tinker this value.",
19244
- argument: "<limit>"
19245
- }
19246
- }
19247
- }
19248
- }
19249
- },
19250
- fileParallelism: {
19251
- description: "Should all test files run in parallel. Use --no-file-parallelism to disable (default: true)"
19252
- },
19253
- maxWorkers: {
19254
- description: "Maximum number of workers to run tests in",
19255
- argument: "<workers>"
19256
- },
19257
- minWorkers: {
19258
- description: "Minimum number of workers to run tests in",
19259
- argument: "<workers>"
19260
- },
19261
- environment: {
19262
- description: "Specify runner environment, if not running in the browser (default: node)",
19263
- argument: "<name>",
19264
- subcommands: null
19265
- // don't support custom objects
19266
- },
19267
- passWithNoTests: {
19268
- description: "Pass when no tests are found"
19269
- },
19270
- logHeapUsage: {
19271
- description: "Show the size of heap for each test when running in node"
19272
- },
19273
- allowOnly: {
19274
- description: "Allow tests and suites that are marked as only (default: !process.env.CI)"
19275
- },
19276
- dangerouslyIgnoreUnhandledErrors: {
19277
- description: "Ignore any unhandled errors that occur"
19278
- },
19279
- shard: {
19280
- description: "Test suite shard to execute in a format of <index>/<count>",
19281
- argument: "<shards>"
19282
- },
19283
- changed: {
19284
- description: "Run tests that are affected by the changed files (default: false)",
19285
- argument: "[since]"
19286
- },
19287
- sequence: {
19288
- description: "Options for how tests should be sorted",
19289
- argument: "<options>",
19290
- subcommands: {
19291
- shuffle: {
19292
- 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)",
19293
- argument: "",
19294
- subcommands: {
19295
- files: {
19296
- description: "Run files in a random order. Long running tests will not start earlier if you enable this option. (default: false)"
19297
- },
19298
- tests: {
19299
- description: "Run tests in a random oder (default: false)"
19300
- }
19301
- }
19302
- },
19303
- concurrent: {
19304
- description: "Make tests run in parallel (default: false)"
19305
- },
19306
- seed: {
19307
- description: "Set the randomization seed. This option will have no effect if --sequence.shuffle is falsy. Visit https://en.wikipedia.org/wiki/Random_seed for more information",
19308
- argument: "<seed>"
19309
- },
19310
- hooks: {
19311
- description: 'Changes the order in which hooks are executed. Accepted values are: "stack", "list" and "parallel". Visit https://vitest.dev/config/#sequence-hooks for more information (default: "parallel")',
19312
- argument: "<order>"
19313
- },
19314
- setupFiles: {
19315
- 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")',
19316
- argument: "<order>"
19317
- }
19318
- }
19319
- },
19320
- inspect: {
19321
- description: "Enable Node.js inspector (default: 127.0.0.1:9229)",
19322
- argument: "[[host:]port]",
19323
- transform(portOrEnabled) {
19324
- if (portOrEnabled === 0 || portOrEnabled === "true" || portOrEnabled === "yes")
19325
- return true;
19326
- if (portOrEnabled === "false" || portOrEnabled === "no")
19327
- return false;
19328
- return portOrEnabled;
19329
- }
19330
- },
19331
- inspectBrk: {
19332
- description: "Enable Node.js inspector and break before the test starts",
19333
- argument: "[[host:]port]",
19334
- transform(portOrEnabled) {
19335
- if (portOrEnabled === 0 || portOrEnabled === "true" || portOrEnabled === "yes")
19336
- return true;
19337
- if (portOrEnabled === "false" || portOrEnabled === "no")
19338
- return false;
19339
- return portOrEnabled;
19340
- }
19341
- },
19342
- inspector: null,
19343
- testTimeout: {
19344
- description: "Default timeout of a test in milliseconds (default: 5000)",
19345
- argument: "<timeout>"
19346
- },
19347
- hookTimeout: {
19348
- description: "Default hook timeout in milliseconds (default: 10000)",
19349
- argument: "<timeout>"
19350
- },
19351
- bail: {
19352
- description: "Stop test execution when given number of tests have failed (default: 0)",
19353
- argument: "<number>"
19354
- },
19355
- retry: {
19356
- description: "Retry the test specific number of times if it fails (default: 0)",
19357
- argument: "<times>"
19358
- },
19359
- diff: {
19360
- description: "Path to a diff config that will be used to generate diff interface",
19361
- argument: "<path>",
19362
- normalize: true
19363
- },
19364
- exclude: {
19365
- description: "Additional file globs to be excluded from test",
19366
- argument: "<glob>"
19367
- },
19368
- expandSnapshotDiff: {
19369
- description: "Show full diff when snapshot fails"
19370
- },
19371
- disableConsoleIntercept: {
19372
- description: "Disable automatic interception of console logging (default: false)"
19373
- },
19374
- typecheck: {
19375
- description: "Enable typechecking alongside tests (default: false)",
19376
- argument: "",
19377
- // allow boolean
19378
- transform: transformNestedBoolean,
19379
- subcommands: {
19380
- enabled: {
19381
- description: "Enable typechecking alongside tests (default: false)"
19382
- },
19383
- only: {
19384
- description: "Run only typecheck tests. This automatically enables typecheck (default: false)"
19385
- },
19386
- checker: {
19387
- description: 'Specify the typechecker to use. Available values are: "tcs" and "vue-tsc" and a path to an executable (default: "tsc")',
19388
- argument: "<name>",
19389
- subcommands: null
19390
- },
19391
- allowJs: {
19392
- description: "Allow JavaScript files to be typechecked. By default takes the value from tsconfig.json"
19393
- },
19394
- ignoreSourceErrors: {
19395
- description: "Ignore type errors from source files"
19396
- },
19397
- tsconfig: {
19398
- description: "Path to a custom tsconfig file",
19399
- argument: "<path>",
19400
- normalize: true
19401
- },
19402
- include: null,
19403
- exclude: null
19404
- }
19405
- },
19406
- project: {
19407
- 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*",
19408
- argument: "<name>",
19409
- array: true
19410
- },
19411
- slowTestThreshold: {
19412
- description: "Threshold in milliseconds for a test to be considered slow (default: 300)",
19413
- argument: "<threshold>"
19414
- },
19415
- teardownTimeout: {
19416
- description: "Default timeout of a teardown function in milliseconds (default: 10000)",
19417
- argument: "<timeout>"
19418
- },
19419
- cache: {
19420
- description: "Enable cache",
19421
- argument: "",
19422
- // allow only boolean
19423
- subcommands: {
19424
- dir: null
19425
- },
19426
- default: true,
19427
- // cache can only be "false" or an object
19428
- transform(cache) {
19429
- if (typeof cache !== "boolean" && cache)
19430
- throw new Error("--cache.dir is deprecated");
19431
- if (cache)
19432
- return {};
19433
- return cache;
19434
- }
19435
- },
19436
- maxConcurrency: {
19437
- description: "Maximum number of concurrent tests in a suite (default: 5)",
19438
- argument: "<number>"
19439
- },
19440
- // CLI only options
19441
- run: {
19442
- description: "Disable watch mode"
19443
- },
19444
- segfaultRetry: {
19445
- description: "Retry the test suite if it crashes due to a segfault (default: true)",
19446
- argument: "<times>",
19447
- default: 0
19448
- },
19449
- color: {
19450
- description: "Removes colors from the console output",
19451
- alias: "no-color"
19452
- },
19453
- clearScreen: {
19454
- description: "Clear terminal screen when re-running tests during watch mode (default: true)"
19455
- },
19456
- // disable CLI options
19457
- cliExclude: null,
19458
- server: null,
19459
- setupFiles: null,
19460
- globalSetup: null,
19461
- snapshotFormat: null,
19462
- snapshotSerializers: null,
19463
- includeSource: null,
19464
- watchExclude: null,
19465
- alias: null,
19466
- env: null,
19467
- environmentMatchGlobs: null,
19468
- environmentOptions: null,
19469
- unstubEnvs: null,
19470
- related: null,
19471
- restoreMocks: null,
19472
- runner: null,
19473
- mockReset: null,
19474
- forceRerunTriggers: null,
19475
- unstubGlobals: null,
19476
- uiBase: null,
19477
- benchmark: null,
19478
- include: null,
19479
- testTransformMode: null,
19480
- fakeTimers: null,
19481
- chaiConfig: null,
19482
- clearMocks: null,
19483
- css: null,
19484
- poolMatchGlobs: null,
19485
- deps: null,
19486
- name: null,
19487
- includeTaskLocation: null
19488
- };
19489
-
19490
- function addCommand(cli, name, option) {
19491
- const commandName = option.alias || name;
19492
- let command = option.shorthand ? `-${option.shorthand}, --${commandName}` : `--${commandName}`;
19493
- if ("argument" in option)
19494
- command += ` ${option.argument}`;
19495
- function transform(value) {
19496
- if (!option.array && Array.isArray(value)) {
19497
- const received = value.map((s) => typeof s === "string" ? `"${s}"` : s).join(", ");
19498
- throw new Error(
19499
- `Expected a single value for option "${command}", received [${received}]`
19500
- );
19501
- }
19502
- if (option.transform)
19503
- return option.transform(value);
19504
- if (option.array)
19505
- return toArray(value);
19506
- if (option.normalize)
19507
- return normalize(String(value));
19508
- return value;
19509
- }
19510
- const hasSubcommands = "subcommands" in option && option.subcommands;
19511
- if (option.description) {
19512
- let description = option.description;
19513
- if (hasSubcommands)
19514
- description += `. Use '--help --${commandName}' for more info.`;
19515
- cli.option(command, description, {
19516
- type: transform
19517
- });
19518
- }
19519
- if (hasSubcommands) {
19520
- for (const commandName2 in option.subcommands) {
19521
- const subcommand = option.subcommands[commandName2];
19522
- if (subcommand)
19523
- addCommand(cli, `${name}.${commandName2}`, subcommand);
19524
- }
19525
- }
19526
- }
19527
- function createCLI(options = {}) {
19528
- const cli = cac("vitest");
19529
- cli.version(version);
19530
- for (const optionName in cliOptionsConfig) {
19531
- const option = cliOptionsConfig[optionName];
19532
- if (option)
19533
- addCommand(cli, optionName, option);
19534
- }
19535
- cli.help((info) => {
19536
- const helpSection = info.find((current) => {
19537
- var _a;
19538
- return (_a = current.title) == null ? void 0 : _a.startsWith("For more info, run any command");
19539
- });
19540
- if (helpSection)
19541
- helpSection.body += "\n $ vitest --help --expand-help";
19542
- const options2 = info.find((current) => current.title === "Options");
19543
- if (typeof options2 !== "object")
19544
- return info;
19545
- const helpIndex = process.argv.findIndex((arg) => arg === "--help");
19546
- const subcommands = process.argv.slice(helpIndex + 1);
19547
- const defaultOutput = options2.body.split("\n").filter((line) => /^\s+--\S+\./.test(line) === false).join("\n");
19548
- if (subcommands.length === 0) {
19549
- options2.body = defaultOutput;
19550
- return info;
19551
- }
19552
- if (subcommands.length === 1 && (subcommands[0] === "--expand-help" || subcommands[0] === "--expandHelp"))
19553
- return info;
19554
- const subcommandMarker = "$SUB_COMMAND_MARKER$";
19555
- const banner = info.find((current) => /^vitest\/[0-9]+\.[0-9]+\.[0-9]+$/.test(current.body));
19556
- function addBannerWarning(warning) {
19557
- if (typeof (banner == null ? void 0 : banner.body) === "string") {
19558
- if (banner == null ? void 0 : banner.body.includes(warning))
19559
- return;
19560
- banner.body = `${banner.body}
19561
- WARN: ${warning}`;
19562
- }
19563
- }
19564
- for (let i = 0; i < subcommands.length; i++) {
19565
- const subcommand = subcommands[i];
19566
- if (subcommand === "--expand-help" || subcommand === "--expandHelp") {
19567
- addBannerWarning("--expand-help subcommand ignored because, when used with --help, it must be the only subcommand");
19568
- continue;
19569
- }
19570
- if (subcommand.startsWith("--")) {
19571
- options2.body = options2.body.split("\n").map((line) => line.trim().startsWith(subcommand) ? `${subcommandMarker}${line}` : line).join("\n");
19572
- }
19573
- }
19574
- options2.body = options2.body.split("\n").map((line) => line.startsWith(subcommandMarker) ? line.split(subcommandMarker)[1] : "").filter((line) => line.length !== 0).join("\n");
19575
- if (!options2.body) {
19576
- addBannerWarning("no options were found for your subcommands so we printed the whole output");
19577
- options2.body = defaultOutput;
19578
- }
19579
- return info;
19580
- });
19581
- cli.command("run [...filters]", void 0, options).action(run);
19582
- cli.command("related [...filters]", void 0, options).action(runRelated);
19583
- cli.command("watch [...filters]", void 0, options).action(watch);
19584
- cli.command("dev [...filters]", void 0, options).action(watch);
19585
- cli.command("bench [...filters]", void 0, options).action(benchmark);
19586
- cli.command("typecheck [...filters]").action(() => {
19587
- throw new Error(`Running typecheck via "typecheck" command is removed. Please use "--typecheck" to run your regular tests alongside typechecking, or "--typecheck.only" to run only typecheck tests.`);
19588
- });
19589
- cli.command("[...filters]", void 0, options).action((filters, options2) => start("test", filters, options2));
19590
- return cli;
19591
- }
19592
- function parseCLI(argv, config = {}) {
19593
- const arrayArgs = typeof argv === "string" ? argv.split(" ") : argv;
19594
- if (arrayArgs[0] !== "vitest")
19595
- throw new Error(`Expected "vitest" as the first argument, received "${arrayArgs[0]}"`);
19596
- arrayArgs[0] = "/index.js";
19597
- arrayArgs.unshift("node");
19598
- let { args, options } = createCLI(config).parse(arrayArgs, {
19599
- run: false
19600
- });
19601
- if (arrayArgs[2] === "watch" || arrayArgs[2] === "dev")
19602
- options.watch = true;
19603
- if (arrayArgs[2] === "run")
19604
- options.run = true;
19605
- if (arrayArgs[2] === "related") {
19606
- options.related = args;
19607
- options.passWithNoTests ?? (options.passWithNoTests = true);
19608
- args = [];
19609
- }
19610
- return {
19611
- filter: args,
19612
- options
19613
- };
19614
- }
19615
- async function runRelated(relatedFiles, argv) {
19616
- argv.related = relatedFiles;
19617
- argv.passWithNoTests ?? (argv.passWithNoTests = true);
19618
- await start("test", [], argv);
19619
- }
19620
- async function watch(cliFilters, options) {
19621
- options.watch = true;
19622
- await start("test", cliFilters, options);
19623
- }
19624
- async function run(cliFilters, options) {
19625
- options.run = true;
19626
- await start("test", cliFilters, options);
19627
- }
19628
- async function benchmark(cliFilters, options) {
19629
- console.warn(c.yellow("Benchmarking is an experimental feature.\nBreaking changes might not follow SemVer, please pin Vitest's version when using it."));
19630
- await start("benchmark", cliFilters, options);
19631
- }
19632
- function normalizeCliOptions(argv) {
19633
- if (argv.exclude) {
19634
- argv.cliExclude = toArray(argv.exclude);
19635
- delete argv.exclude;
19636
- }
19637
- return argv;
19638
- }
19639
- async function start(mode, cliFilters, options) {
19640
- try {
19641
- process.title = "node (vitest)";
19642
- } catch {
19643
- }
19644
- try {
19645
- const ctx = await startVitest(mode, cliFilters.map(normalize), normalizeCliOptions(options));
19646
- if (!(ctx == null ? void 0 : ctx.shouldKeepServer()))
19647
- await (ctx == null ? void 0 : ctx.exit());
19648
- return ctx;
19649
- } catch (e) {
19650
- console.error(`
19651
- ${c.red(divider(c.bold(c.inverse(" Unhandled Error "))))}`);
19652
- console.error(e);
19653
- console.error("\n\n");
19654
- process.exit(1);
19655
- }
19656
- }
19657
18254
 
19658
- export { VitestPlugin as V, createMethodsRPC as a, VitestPackageInstaller as b, createVitest as c, createCLI as d, parseCLI as p, registerConsoleShortcuts as r, startVitest as s };
18255
+ export { VitestPlugin as V, createMethodsRPC as a, VitestPackageInstaller as b, createVitest as c, cliApi as d, registerConsoleShortcuts as r, startVitest as s };