/
cli-config.ts
615 lines (603 loc) · 22.3 KB
/
cli-config.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
import { defaultBrowserPort, defaultPort } from '../../constants'
import type { ApiConfig } from '../../types/config'
import type { ForksOptions, ThreadsOptions, VmOptions, WorkerContextOptions } from '../../types/pool-options'
import type { CliOptions } from './cli-api'
type NestedOption<T, V = Extract<T, Record<string, any>>> = V extends never | RegExp | unknown[]
? never
: V
export type CLIOption<Value> = {
description: string | null
alias?: string
shorthand?: string
default?: unknown
transform?: (value: unknown) => unknown
array?: boolean
normalize?: boolean
} &
// require subcommands for nested options
(NestedOption<Value> extends never ? {} : { subcommands: CLIOptions<NestedOption<Value>> | null }) &
// require argument for non-boolean options
(NonNullable<Value> extends boolean ? {} : { argument: string })
type CLIOptions<Config extends {}> = {
[Key in keyof Config as NonNullable<Config[Key]> extends Function ? never : Key]-?: CLIOption<Config[Key]> | null
}
type VitestCLIOptions = CLIOptions<CliOptions>
const apiConfig: (port: number) => CLIOptions<ApiConfig> = (port: number) => ({
port: {
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}`,
argument: '[port]',
},
host: {
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',
argument: '[host]',
},
strictPort: {
description: 'Set to true to exit if port is already in use, instead of automatically trying the next available port',
},
middlewareMode: null,
})
const poolThreadsCommands: CLIOptions<ThreadsOptions & WorkerContextOptions> = {
isolate: {
description: 'Isolate tests in threads pool (default: true)',
},
singleThread: {
description: 'Run tests inside a single thread (default: false)',
},
maxThreads: {
description: 'Maximum number of threads to run tests in',
argument: '<workers>',
},
minThreads: {
description: 'Minimum number of threads to run tests in',
argument: '<workers>',
},
useAtomics: {
description: 'Use Atomics to synchronize threads. This can improve performance in some cases, but might cause segfault in older Node versions (default: false)',
},
execArgv: null,
}
const poolForksCommands: CLIOptions<ForksOptions & WorkerContextOptions> = {
isolate: {
description: 'Isolate tests in threads pool (default: true)',
},
singleFork: {
description: 'Run tests inside a single child_process (default: false)',
},
maxForks: {
description: 'Maximum number of processes to run tests in',
argument: '<workers>',
},
minForks: {
description: 'Minimum number of processes to run tests in',
argument: '<workers>',
},
execArgv: null,
}
function watermarkTransform(value: unknown) {
if (typeof value === 'string')
return value.split(',').map(Number)
return value
}
function transformNestedBoolean(value: unknown) {
if (typeof value === 'boolean')
return { enabled: value }
return value
}
export const cliOptionsConfig: VitestCLIOptions = {
root: {
description: 'Root path',
shorthand: 'r',
argument: '<path>',
normalize: true,
},
config: {
shorthand: 'c',
description: 'Path to config file',
argument: '<path>',
normalize: true,
},
update: {
shorthand: 'u',
description: 'Update snapshot',
},
watch: {
shorthand: 'w',
description: 'Enable watch mode',
},
testNamePattern: {
description: 'Run tests with full names matching the specified regexp pattern',
argument: '<pattern>',
shorthand: 't',
},
dir: {
description: 'Base directory to scan for the test files',
argument: '<path>',
normalize: true,
},
ui: {
description: 'Enable UI',
},
open: {
description: 'Open UI automatically (default: !process.env.CI)',
},
api: {
argument: '[port]',
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}`,
subcommands: apiConfig(defaultPort),
},
silent: {
description: 'Silent console output from tests',
},
hideSkippedTests: {
description: 'Hide logs for skipped tests',
},
reporters: {
alias: 'reporter',
description: 'Specify reporters',
argument: '<name>',
subcommands: null, // don't support custom objects
array: true,
},
outputFile: {
argument: '<filename/-s>',
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)',
subcommands: null,
},
coverage: {
description: 'Enable coverage report',
argument: '', // empty string means boolean
transform: transformNestedBoolean,
subcommands: {
all: {
description: 'Whether to include all files, including the untested ones into report',
default: true,
},
provider: {
description: 'Select the tool for coverage collection, available values are: "v8", "istanbul" and "custom"',
argument: '<name>',
},
enabled: {
description: 'Enables coverage collection. Can be overridden using the --coverage CLI option (default: false)',
},
include: {
description: 'Files included in coverage as glob patterns. May be specified more than once when using multiple patterns (default: **)',
argument: '<pattern>',
array: true,
},
exclude: {
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)',
argument: '<pattern>',
array: true,
},
extension: {
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"])',
argument: '<extension>',
array: true,
},
clean: {
description: 'Clean coverage results before running tests (default: true)',
},
cleanOnRerun: {
description: 'Clean coverage report on watch rerun (default: true)',
},
reportsDirectory: {
description: 'Directory to write coverage report to (default: ./coverage)',
argument: '<path>',
normalize: true,
},
reporter: {
description: 'Coverage reporters to use. Visit https://vitest.dev/config/#coverage-reporter for more information (default: ["text", "html", "clover", "json"])',
argument: '<name>',
subcommands: null, // don't support custom objects
array: true,
},
reportOnFailure: {
description: 'Generate coverage report even when tests fail (default: false)',
},
allowExternal: {
description: 'Collect coverage of files outside the project root (default: false)',
},
skipFull: {
description: 'Do not show files with 100% statement, branch, and function coverage (default: false)',
},
thresholds: {
description: null,
argument: '', // no displayed
subcommands: {
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)',
},
autoUpdate: {
description: 'Update threshold values: "lines", "functions", "branches" and "statements" to configuration file when current coverage is above the configured thresholds (default: false)',
},
lines: {
description: 'Threshold for lines. Visit https://github.com/istanbuljs/nyc#coverage-thresholds for more information. This option is not available for custom providers',
argument: '<number>',
},
functions: {
description: 'Threshold for functions. Visit https://github.com/istanbuljs/nyc#coverage-thresholds for more information. This option is not available for custom providers',
argument: '<number>',
},
branches: {
description: 'Threshold for branches. Visit https://github.com/istanbuljs/nyc#coverage-thresholds for more information. This option is not available for custom providers',
argument: '<number>',
},
statements: {
description: 'Threshold for statements. Visit https://github.com/istanbuljs/nyc#coverage-thresholds for more information. This option is not available for custom providers',
argument: '<number>',
},
100: {
description: 'Shortcut to set all coverage thresholds to 100 (default: false)',
},
},
},
ignoreClassMethods: {
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: [])',
argument: '<name>',
array: true,
},
processingConcurrency: {
description: 'Concurrency limit used when processing the coverage results. (default min between 20 and the number of CPUs)',
argument: '<number>',
},
customProviderModule: {
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',
argument: '<path>',
normalize: true,
},
watermarks: {
description: null,
argument: '', // no displayed
subcommands: {
statements: {
description: 'High and low watermarks for statements in the format of <high>,<low>',
argument: '<watermarks>',
transform: watermarkTransform,
},
lines: {
description: 'High and low watermarks for lines in the format of <high>,<low>',
argument: '<watermarks>',
transform: watermarkTransform,
},
branches: {
description: 'High and low watermarks for branches in the format of <high>,<low>',
argument: '<watermarks>',
transform: watermarkTransform,
},
functions: {
description: 'High and low watermarks for functions in the format of <high>,<low>',
argument: '<watermarks>',
transform: watermarkTransform,
},
},
},
},
},
mode: {
description: 'Override Vite mode (default: test or benchmark)',
argument: '<name>',
},
workspace: {
description: 'Path to a workspace configuration file',
argument: '<path>',
normalize: true,
},
isolate: {
description: 'Run every test file in isolation. To disable isolation, use --no-isolate (default: true)',
},
globals: {
description: 'Inject apis globally',
},
dom: {
description: 'Mock browser API with happy-dom',
},
browser: {
description: 'Run tests in the browser. Equivalent to --browser.enabled (default: false)',
argument: '<name>',
transform(browser) {
if (typeof browser === 'boolean')
return { enabled: browser }
if (browser === 'true' || browser === 'false')
return { enabled: browser !== 'false' }
if (typeof browser === 'string')
return { enabled: true, name: browser }
return browser
},
subcommands: {
enabled: {
description: 'Run tests in the browser. Equivalent to --browser.enabled (default: false)',
},
name: {
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',
argument: '<name>',
},
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)',
},
api: {
description: 'Specify options for the browser API server. Does not affect the --api option',
argument: '[port]',
subcommands: apiConfig(defaultBrowserPort),
},
provider: {
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")',
argument: '<name>',
subcommands: null, // don't support custom objects
},
providerOptions: {
description: 'Options that are passed down to a browser provider. Visit https://vitest.dev/config/#browser-provideroptions-1-0-0 for more information',
argument: '<options>',
subcommands: null, // don't support custom objects
},
slowHijackESM: {
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)',
},
isolate: {
description: 'Run every browser test file in isolation. To disable isolation, use --browser.isolate=false (default: true)',
},
fileParallelism: {
description: 'Should all test files run in parallel. Use --browser.file-parallelism=false to disable (default: same as --file-parallelism)',
},
},
},
pool: {
description: 'Specify pool, if not running in the browser (default: threads)',
argument: '<pool>',
subcommands: null, // don't support custom objects
},
poolOptions: {
description: 'Specify pool options',
argument: '<options>',
// we use casting here because TypeScript (for some reason) makes this into CLIOption<unknown>
// even when using casting, these types fail if the new option is added which is good
subcommands: {
threads: {
description: 'Specify threads pool options',
argument: '<options>',
subcommands: poolThreadsCommands,
} as CLIOption<ThreadsOptions & WorkerContextOptions>,
vmThreads: {
description: 'Specify VM threads pool options',
argument: '<options>',
subcommands: {
...poolThreadsCommands,
memoryLimit: {
description: 'Memory limit for VM threads pool. If you see memory leaks, try to tinker this value.',
argument: '<limit>',
},
},
} as CLIOption<ThreadsOptions & VmOptions>,
forks: {
description: 'Specify forks pool options',
argument: '<options>',
subcommands: poolForksCommands,
} as CLIOption<ForksOptions & WorkerContextOptions>,
vmForks: {
description: 'Specify VM forks pool options',
argument: '<options>',
subcommands: {
...poolForksCommands,
memoryLimit: {
description: 'Memory limit for VM forks pool. If you see memory leaks, try to tinker this value.',
argument: '<limit>',
},
},
} as CLIOption<ForksOptions & VmOptions>,
},
},
fileParallelism: {
description: 'Should all test files run in parallel. Use --no-file-parallelism to disable (default: true)',
},
maxWorkers: {
description: 'Maximum number of workers to run tests in',
argument: '<workers>',
},
minWorkers: {
description: 'Minimum number of workers to run tests in',
argument: '<workers>',
},
environment: {
description: 'Specify runner environment, if not running in the browser (default: node)',
argument: '<name>',
subcommands: null, // don't support custom objects
},
passWithNoTests: {
description: 'Pass when no tests are found',
},
logHeapUsage: {
description: 'Show the size of heap for each test when running in node',
},
allowOnly: {
description: 'Allow tests and suites that are marked as only (default: !process.env.CI)',
},
dangerouslyIgnoreUnhandledErrors: {
description: 'Ignore any unhandled errors that occur',
},
shard: {
description: 'Test suite shard to execute in a format of <index>/<count>',
argument: '<shards>',
},
changed: {
description: 'Run tests that are affected by the changed files (default: false)',
argument: '[since]',
},
sequence: {
description: 'Options for how tests should be sorted',
argument: '<options>',
subcommands: {
shuffle: {
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)',
argument: '',
subcommands: {
files: {
description: 'Run files in a random order. Long running tests will not start earlier if you enable this option. (default: false)',
},
tests: {
description: 'Run tests in a random oder (default: false)',
},
},
},
concurrent: {
description: 'Make tests run in parallel (default: false)',
},
seed: {
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',
argument: '<seed>',
},
hooks: {
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")',
argument: '<order>',
},
setupFiles: {
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")',
argument: '<order>',
},
},
},
inspect: {
description: 'Enable Node.js inspector',
},
inspectBrk: {
description: 'Enable Node.js inspector with break',
},
testTimeout: {
description: 'Default timeout of a test in milliseconds (default: 5000)',
argument: '<timeout>',
},
hookTimeout: {
description: 'Default hook timeout in milliseconds (default: 10000)',
argument: '<timeout>',
},
bail: {
description: 'Stop test execution when given number of tests have failed (default: 0)',
argument: '<number>',
},
retry: {
description: 'Retry the test specific number of times if it fails (default: 0)',
argument: '<times>',
},
diff: {
description: 'Path to a diff config that will be used to generate diff interface',
argument: '<path>',
normalize: true,
},
exclude: {
description: 'Additional file globs to be excluded from test',
argument: '<glob>',
},
expandSnapshotDiff: {
description: 'Show full diff when snapshot fails',
},
disableConsoleIntercept: {
description: 'Disable automatic interception of console logging (default: false)',
},
typecheck: {
description: 'Enable typechecking alongside tests (default: false)',
argument: '', // allow boolean
transform: transformNestedBoolean,
subcommands: {
enabled: {
description: 'Enable typechecking alongside tests (default: false)',
},
only: {
description: 'Run only typecheck tests. This automatically enables typecheck (default: false)',
},
checker: {
description: 'Specify the typechecker to use. Available values are: "tcs" and "vue-tsc" and a path to an executable (default: "tsc")',
argument: '<name>',
subcommands: null,
},
allowJs: {
description: 'Allow JavaScript files to be typechecked. By default takes the value from tsconfig.json',
},
ignoreSourceErrors: {
description: 'Ignore type errors from source files',
},
tsconfig: {
description: 'Path to a custom tsconfig file',
argument: '<path>',
normalize: true,
},
include: null,
exclude: null,
},
},
project: {
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*',
argument: '<name>',
array: true,
},
slowTestThreshold: {
description: 'Threshold in milliseconds for a test to be considered slow (default: 300)',
argument: '<threshold>',
},
teardownTimeout: {
description: 'Default timeout of a teardown function in milliseconds (default: 10000)',
argument: '<timeout>',
},
cache: {
description: 'Enable cache',
argument: '', // allow only boolean
subcommands: {
dir: {
description: 'Path to the cache directory',
argument: '<path>',
normalize: true,
},
},
// cache can only be "false" or an object
transform(cache) {
if (cache)
return {}
return cache
},
},
maxConcurrency: {
description: 'Maximum number of concurrent tests in a suite (default: 5)',
argument: '<number>',
},
// CLI only options
run: {
description: 'Disable watch mode',
},
segfaultRetry: {
description: 'Retry the test suite if it crashes due to a segfault (default: true)',
argument: '<times>',
default: 0,
},
color: {
description: 'Removes colors from the console output',
alias: 'no-color',
},
// disable CLI options
cliExclude: null,
server: null,
setupFiles: null,
globalSetup: null,
snapshotFormat: null,
snapshotSerializers: null,
includeSource: null,
watchExclude: null,
alias: null,
env: null,
environmentMatchGlobs: null,
environmentOptions: null,
unstubEnvs: null,
related: null,
restoreMocks: null,
runner: null,
mockReset: null,
forceRerunTriggers: null,
unstubGlobals: null,
uiBase: null,
benchmark: null,
include: null,
testTransformMode: null,
fakeTimers: null,
chaiConfig: null,
clearMocks: null,
css: null,
poolMatchGlobs: null,
deps: null,
name: null,
}