[READ-ONLY] Mirror of https://github.com/vitest-dev/vitest. Next generation testing framework powered by Vite. vitest.dev
test testing-tools vite
12

Configure Feed

Select the types of activity you want to include in your feed.

docs: generate CLI table automatically (#5588)

authored by

Vladimir and committed by
GitHub
(Apr 23, 2024, 10:55 AM +0200) 597e0c20 4da88045

+245 -125
+2 -1
docs/package.json
··· 4 4 "private": true, 5 5 "scripts": { 6 6 "dev": "vitepress --port 3333 --open", 7 - "build": "nr prefetch && vitepress build", 7 + "build": "nr cli-table && nr prefetch && vitepress build", 8 + "cli-table": "tsx .vitepress/scripts/cli-generator.ts", 8 9 "build-no-prefetch": "vitepress build", 9 10 "serve": "vitepress serve", 10 11 "preview-https": "pnpm run build && serve .vitepress/dist",
+121
docs/guide/cli-table.md
··· 1 + | Options | | 2 + | ------------- | ------------- | 3 + | `-r, --root <path>` | Root path | 4 + | `-c, --config <path>` | Path to config file | 5 + | `-u, --update` | Update snapshot | 6 + | `-w, --watch` | Enable watch mode | 7 + | `-t, --testNamePattern <pattern>` | Run tests with full names matching the specified regexp pattern | 8 + | `--dir <path>` | Base directory to scan for the test files | 9 + | `--ui` | Enable UI | 10 + | `--open` | Open UI automatically (default: `!process.env.CI`) | 11 + | `--port [port]` | 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 `51204` | 12 + | `--host [host]` | 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 | 13 + | `--strictPort` | Set to true to exit if port is already in use, instead of automatically trying the next available port | 14 + | `--silent` | Silent console output from tests | 15 + | `--hideSkippedTests` | Hide logs for skipped tests | 16 + | `--reporter <name>` | Specify reporters | 17 + | `--outputFile <filename/-s>` | 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) | 18 + | `--all` | Whether to include all files, including the untested ones into report | 19 + | `--provider <name>` | Select the tool for coverage collection, available values are: "v8", "istanbul" and "custom" | 20 + | `--enabled` | Enables coverage collection. Can be overridden using the `--coverage` CLI option (default: `false`) | 21 + | `--include <pattern>` | Files included in coverage as glob patterns. May be specified more than once when using multiple patterns (default: `**`) | 22 + | `--exclude <pattern>` | Files to be excluded in coverage. May be specified more than once when using multiple extensions (default: Visit [`coverage.exclude`](https://vitest.dev/config/#coverage-exclude)) | 23 + | `--extension <extension>` | 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"]`) | 24 + | `--clean` | Clean coverage results before running tests (default: true) | 25 + | `--cleanOnRerun` | Clean coverage report on watch rerun (default: true) | 26 + | `--reportsDirectory <path>` | Directory to write coverage report to (default: ./coverage) | 27 + | `--reporter <name>` | Coverage reporters to use. Visit [`coverage.reporter`](https://vitest.dev/config/#coverage-reporter) for more information (default: `["text", "html", "clover", "json"]`) | 28 + | `--reportOnFailure` | Generate coverage report even when tests fail (default: false) | 29 + | `--allowExternal` | Collect coverage of files outside the project root (default: false) | 30 + | `--skipFull` | Do not show files with 100% statement, branch, and function coverage (default: false) | 31 + | `--100` | Shortcut to set all coverage thresholds to 100 (default: `false`) | 32 + | `--perFile` | Check thresholds per file. See `--coverage.thresholds.lines`, `--coverage.thresholds.functions`, `--coverage.thresholds.branches` and `--coverage.thresholds.statements` for the actual thresholds (default: `false`) | 33 + | `--autoUpdate` | Update threshold values: "lines", "functions", "branches" and "statements" to configuration file when current coverage is above the configured thresholds (default: `false`) | 34 + | `--lines <number>` | Threshold for lines. Visit [istanbuljs](https://github.com/istanbuljs/nyc#coverage-thresholds) for more information. This option is not available for custom providers | 35 + | `--functions <number>` | Threshold for functions. Visit [istanbuljs](https://github.com/istanbuljs/nyc#coverage-thresholds) for more information. This option is not available for custom providers | 36 + | `--branches <number>` | Threshold for branches. Visit [istanbuljs](https://github.com/istanbuljs/nyc#coverage-thresholds) for more information. This option is not available for custom providers | 37 + | `--statements <number>` | Threshold for statements. Visit [istanbuljs](https://github.com/istanbuljs/nyc#coverage-thresholds) for more information. This option is not available for custom providers | 38 + | `--ignoreClassMethods <name>` | Array of class method names to ignore for coverage. Visit [istanbuljs](https://github.com/istanbuljs/nyc#ignoring-methods) for more information. This option is only available for the istanbul providers (default: `[]`) | 39 + | `--processingConcurrency <number>` | Concurrency limit used when processing the coverage results. (default min between 20 and the number of CPUs) | 40 + | `--customProviderModule <path>` | Specifies the module name or path for the custom coverage provider module. Visit [Custom Coverage Provider](https://vitest.dev/guide/coverage#custom-coverage-provider) for more information. This option is only available for custom providers | 41 + | `--statements <watermarks>` | High and low watermarks for statements in the format of `<high>,<low>` | 42 + | `--lines <watermarks>` | High and low watermarks for lines in the format of `<high>,<low>` | 43 + | `--branches <watermarks>` | High and low watermarks for branches in the format of `<high>,<low>` | 44 + | `--functions <watermarks>` | High and low watermarks for functions in the format of `<high>,<low>` | 45 + | `--mode <name>` | Override Vite mode (default: `test` or `benchmark`) | 46 + | `--workspace <path>` | Path to a workspace configuration file | 47 + | `--isolate` | Run every test file in isolation. To disable isolation, use `--no-isolate` (default: `true`) | 48 + | `--globals` | Inject apis globally | 49 + | `--dom` | Mock browser API with happy-dom | 50 + | `--enabled` | Run tests in the browser. Equivalent to `--browser.enabled` (default: `false`) | 51 + | `--name <name>` | Run all tests in a specific browser. Some browsers are only available for specific providers (see `--browser.provider`). Visit [`browser.name`](https://vitest.dev/config/#browser-name) for more information | 52 + | `--headless` | 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`) | 53 + | `--port [port]` | 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 `63315` | 54 + | `--host [host]` | 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 | 55 + | `--strictPort` | Set to true to exit if port is already in use, instead of automatically trying the next available port | 56 + | `--provider <name>` | 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 [`browser.provider`](https://vitest.dev/config/#browser-provider) for more information (default: `"webdriverio"`) | 57 + | `--providerOptions <options>` | Options that are passed down to a browser provider. Visit [`browser.providerOptions`](https://vitest.dev/config/#browser-provideroptions) for more information | 58 + | `--slowHijackESM` | Let Vitest use its own module resolution on the browser to enable APIs such as vi.mock and vi.spyOn. Visit [`browser.slowHijackESM`](https://vitest.dev/config/#browser-slowhijackesm) for more information (default: `false`) | 59 + | `--isolate` | Run every browser test file in isolation. To disable isolation, use `--browser.isolate=false` (default: `true`) | 60 + | `--fileParallelism` | Should all test files run in parallel. Use `--browser.file-parallelism=false` to disable (default: same as `--file-parallelism`) | 61 + | `--pool <pool>` | Specify pool, if not running in the browser (default: `threads`) | 62 + | `--isolate` | Isolate tests in threads pool (default: `true`) | 63 + | `--singleThread` | Run tests inside a single thread (default: `false`) | 64 + | `--maxThreads <workers>` | Maximum number of threads to run tests in | 65 + | `--minThreads <workers>` | Minimum number of threads to run tests in | 66 + | `--useAtomics` | Use Atomics to synchronize threads. This can improve performance in some cases, but might cause segfault in older Node versions (default: `false`) | 67 + | `--isolate` | Isolate tests in threads pool (default: `true`) | 68 + | `--singleThread` | Run tests inside a single thread (default: `false`) | 69 + | `--maxThreads <workers>` | Maximum number of threads to run tests in | 70 + | `--minThreads <workers>` | Minimum number of threads to run tests in | 71 + | `--useAtomics` | Use Atomics to synchronize threads. This can improve performance in some cases, but might cause segfault in older Node versions (default: `false`) | 72 + | `--memoryLimit <limit>` | Memory limit for VM threads pool. If you see memory leaks, try to tinker this value. | 73 + | `--isolate` | Isolate tests in threads pool (default: `true`) | 74 + | `--singleFork` | Run tests inside a single child_process (default: `false`) | 75 + | `--maxForks <workers>` | Maximum number of processes to run tests in | 76 + | `--minForks <workers>` | Minimum number of processes to run tests in | 77 + | `--isolate` | Isolate tests in threads pool (default: `true`) | 78 + | `--singleFork` | Run tests inside a single child_process (default: `false`) | 79 + | `--maxForks <workers>` | Maximum number of processes to run tests in | 80 + | `--minForks <workers>` | Minimum number of processes to run tests in | 81 + | `--memoryLimit <limit>` | Memory limit for VM forks pool. If you see memory leaks, try to tinker this value. | 82 + | `--fileParallelism` | Should all test files run in parallel. Use `--no-file-parallelism` to disable (default: `true`) | 83 + | `--maxWorkers <workers>` | Maximum number of workers to run tests in | 84 + | `--minWorkers <workers>` | Minimum number of workers to run tests in | 85 + | `--environment <name>` | Specify runner environment, if not running in the browser (default: `node`) | 86 + | `--passWithNoTests` | Pass when no tests are found | 87 + | `--logHeapUsage` | Show the size of heap for each test when running in node | 88 + | `--allowOnly` | Allow tests and suites that are marked as only (default: `!process.env.CI`) | 89 + | `--dangerouslyIgnoreUnhandledErrors` | Ignore any unhandled errors that occur | 90 + | `--shard <shards>` | Test suite shard to execute in a format of `<index>/<count>` | 91 + | `--changed [since]` | Run tests that are affected by the changed files (default: `false`) | 92 + | `--files` | Run files in a random order. Long running tests will not start earlier if you enable this option. (default: `false`) | 93 + | `--tests` | Run tests in a random oder (default: `false`) | 94 + | `--concurrent` | Make tests run in parallel (default: `false`) | 95 + | `--seed <seed>` | Set the randomization seed. This option will have no effect if --sequence.shuffle is falsy. Visit ["Random Seed" page](https://en.wikipedia.org/wiki/Random_seed) for more information | 96 + | `--hooks <order>` | Changes the order in which hooks are executed. Accepted values are: "stack", "list" and "parallel". Visit [`sequence.hooks`](https://vitest.dev/config/#sequence-hooks) for more information (default: `"parallel"`) | 97 + | `--setupFiles <order>` | 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"`) | 98 + | `--inspect [[host:]port]` | Enable Node.js inspector (default: `127.0.0.1:9229`) | 99 + | `--inspectBrk [[host:]port]` | Enable Node.js inspector and break before the test starts | 100 + | `--testTimeout <timeout>` | Default timeout of a test in milliseconds (default: `5000`) | 101 + | `--hookTimeout <timeout>` | Default hook timeout in milliseconds (default: `10000`) | 102 + | `--bail <number>` | Stop test execution when given number of tests have failed (default: `0`) | 103 + | `--retry <times>` | Retry the test specific number of times if it fails (default: `0`) | 104 + | `--diff <path>` | Path to a diff config that will be used to generate diff interface | 105 + | `--exclude <glob>` | Additional file globs to be excluded from test | 106 + | `--expandSnapshotDiff` | Show full diff when snapshot fails | 107 + | `--disableConsoleIntercept` | Disable automatic interception of console logging (default: `false`) | 108 + | `--enabled` | Enable typechecking alongside tests (default: `false`) | 109 + | `--only` | Run only typecheck tests. This automatically enables typecheck (default: `false`) | 110 + | `--checker <name>` | Specify the typechecker to use. Available values are: "tcs" and "vue-tsc" and a path to an executable (default: `"tsc"`) | 111 + | `--allowJs` | Allow JavaScript files to be typechecked. By default takes the value from tsconfig.json | 112 + | `--ignoreSourceErrors` | Ignore type errors from source files | 113 + | `--tsconfig <path>` | Path to a custom tsconfig file | 114 + | `--project <name>` | 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*` | 115 + | `--slowTestThreshold <threshold>` | Threshold in milliseconds for a test to be considered slow (default: `300`) | 116 + | `--teardownTimeout <timeout>` | Default timeout of a teardown function in milliseconds (default: `10000`) | 117 + | `--maxConcurrency <number>` | Maximum number of concurrent tests in a suite (default: `5`) | 118 + | `--run` | Disable watch mode | 119 + | `--segfaultRetry <times>` | Retry the test suite if it crashes due to a segfault (default: `true`) | 120 + | `--no-color` | Removes colors from the console output | 121 + | `--clearScreen` | Clear terminal screen when re-running tests during watch mode (default: `true`) |
+1 -52
docs/guide/cli.md
··· 57 57 58 58 ## Options 59 59 60 - | Options | | 61 - | ------------- | ------------- | 62 - | `-v, --version` | Display version number | 63 - | `-r, --root <path>` | Define the project root | 64 - | `-c, --config <path>` | Path to config file | 65 - | `-u, --update` | Update snapshots | 66 - | `-w, --watch` | Smart & instant watch mode | 67 - | `-t, --testNamePattern <pattern>` | Run tests with full names matching the pattern | 68 - | `--dir <path>`| Base directory to scan for the test files | 69 - | `--ui` | Enable UI | 70 - | `--open` | Open the UI automatically if enabled (default: `true`) | 71 - | `--api [api]` | Serve API, available options: `--api.port <port>`, `--api.host [host]` and `--api.strictPort` | 72 - | `--pool <pool>` | Specify pool, if not running in the browser (default: `threads`) | 73 - | `--poolOptions <options>` | Specify pool options | 74 - | `--poolOptions.threads.isolate` | Isolate tests in threads pool (default: `true`) | 75 - | `--poolOptions.forks.isolate` | Isolate tests in forks pool (default: `true`) | 76 - | `--fileParallelism` | Should all test files run in parallel. Use --no-file-parallelism to disable (default: true) | 77 - | `--maxWorkers <workers>` | Maximum number of workers to run tests in | 78 - | `--minWorkers <workers>` | Minimum number of workers to run tests in | 79 - | `--silent` | Silent console output from tests | 80 - | `--reporter <name>` | Select reporter: `default`, `verbose`, `dot`, `junit`, `json`, or a path to a custom reporter | 81 - | `--outputFile <filename/-s>` | Write test results to a file when the `--reporter=json` or `--reporter=junit` option is also specified <br /> Via [cac's dot notation] you can specify individual outputs for multiple reporters | 82 - | `--coverage` | Enable coverage report | 83 - | `--run` | Do not watch | 84 - | `--isolate` | Run every test file in isolation. To disable isolation, use --no-isolate (default: `true`) | 85 - | `--mode <name>` | Override Vite mode (default: `test`) | 86 - | `--workspace <path>` | Path to a workspace configuration file | 87 - | `--globals` | Inject APIs globally | 88 - | `--dom` | Mock browser API with happy-dom | 89 - | `--browser [options]` | Run tests in [the browser](/guide/browser) (default: `false`) | 90 - | `--environment <env>` | Runner environment (default: `node`) | 91 - | `--passWithNoTests` | Pass when no tests found | 92 - | `--logHeapUsage` | Show the size of heap for each test | 93 - | `--allowOnly` | Allow tests and suites that are marked as `only` (default: false in CI, true otherwise) | 94 - | `--dangerouslyIgnoreUnhandledErrors` | Ignore any unhandled errors that occur | 95 - | `--changed [since]` | Run tests that are affected by the changed files (default: false). See [docs](#changed) | 96 - | `--shard <shard>` | Execute tests in a specified shard | 97 - | `--sequence` | Define in what order to run tests. Use [cac's dot notation] to specify options (for example, use `--sequence.shuffle` to run tests in random order or `--sequence.shuffle --sequence.seed SEED_ID` to run a specific order) | 98 - | `--no-color` | Removes colors from the console output | 99 - | `--inspect [[host:]port]` | Enable Node.js inspector (default: 127.0.0.1:9229) | 100 - | `--inspect-brk [[host:]port]` | Enables Node.js inspector and break before the test starts | 101 - | `--bail <number>` | Stop test execution when given number of tests have failed | 102 - | `--retry <times>` | Retry the test specific number of times if it fails | 103 - | `--exclude <glob>` | Additional file globs to be excluded from test | 104 - | `--expand-snapshot-diff` | Show full diff when snapshot fails | 105 - | `--disable-console-intercept` | Disable automatic interception of console logging (default: `false`) | 106 - | `--clearScreen` | Clear terminal screen when re-running tests during watch mode (default: `true`) | 107 - | `--typecheck [options]` | Custom options for typecheck pool. If passed without options, enables typechecking | 108 - | `--typecheck.enabled` | Enable typechecking alongside tests (default: `false`) | 109 - | `--typecheck.only` | Run only typecheck tests. This automatically enables typecheck (default: `false`) | 110 - | `--project` | 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*` | 111 - | `-h, --help` | Display available CLI options | 60 + <!--@include: ./cli-table.md--> 112 61 113 62 ::: tip 114 63 Vitest supports both camel case and kebab case for CLI arguments. For example, `--passWithNoTests` and `--pass-with-no-tests` will both work (`--no-color` and `--inspect-brk` are the exceptions).
+49
docs/.vitepress/scripts/cli-generator.ts
··· 1 + import { writeFileSync } from 'node:fs' 2 + import { dirname, resolve } from 'node:path' 3 + import { fileURLToPath } from 'node:url' 4 + import type { CLIOption, CLIOptions } from '../../../packages/vitest/src/node/cli/cli-config' 5 + import { cliOptionsConfig } from '../../../packages/vitest/src/node/cli/cli-config' 6 + 7 + const docsDir = resolve(dirname(fileURLToPath(import.meta.url)), '../..') 8 + const cliTablePath = resolve(docsDir, './guide/cli-table.md') 9 + 10 + const nonNullable = <T>(value: T): value is NonNullable<T> => value !== null && value !== undefined 11 + 12 + function resolveOptions(options: CLIOptions<any>, parentName?: string) { 13 + return Object.entries(options).flatMap( 14 + ([subcommandName, subcommandConfig]) => resolveCommand( 15 + parentName ? `${parentName}.${subcommandName}` : subcommandName, 16 + subcommandConfig, 17 + ), 18 + ).filter(nonNullable) 19 + } 20 + 21 + function resolveCommand(name: string, config: CLIOption<any> | null): any { 22 + if (!config) 23 + return null 24 + 25 + let title = '`' 26 + if (config.shorthand) 27 + title += `-${config.shorthand}, ` 28 + title += `--${config.alias || name}` 29 + if ('argument' in config) 30 + title += ` ${config.argument}` 31 + title += '`' 32 + if ('subcommands' in config && config.subcommands) 33 + return resolveOptions(config.subcommands) 34 + 35 + return { 36 + title, 37 + description: config.description, 38 + } 39 + } 40 + 41 + const options = resolveOptions(cliOptionsConfig) 42 + 43 + const template = ` 44 + | Options | | 45 + | ------------- | ------------- | 46 + ${options.map(({ title, description }) => `| ${title} | ${description} |`).join('\n')} 47 + `.trimStart() 48 + 49 + writeFileSync(cliTablePath, template, 'utf-8')
+4 -4
packages/vitest/src/node/cli/cac.ts
··· 2 2 import cac, { type CAC } from 'cac' 3 3 import c from 'picocolors' 4 4 import { version } from '../../../package.json' 5 - import { toArray } from '../../utils' 5 + import { toArray } from '../../utils/base' 6 6 import type { Vitest, VitestRunMode } from '../../types' 7 - import { divider } from '../reporters/renderers/utils' 8 7 import type { CliOptions } from './cli-api' 9 - import { startVitest } from './cli-api' 10 8 import type { CLIOption } from './cli-config' 11 9 import { cliOptionsConfig } from './cli-config' 12 10 ··· 35 33 const hasSubcommands = 'subcommands' in option && option.subcommands 36 34 37 35 if (option.description) { 38 - let description = option.description 36 + let description = option.description.replace(/\[.*\]\((.*)\)/, '$1').replace(/`/g, '') 39 37 40 38 if (hasSubcommands) 41 39 description += `. Use '--help --${commandName}' for more info.` ··· 242 240 catch {} 243 241 244 242 try { 243 + const { startVitest } = await import('./cli-api') 245 244 const ctx = await startVitest(mode, cliFilters.map(normalize), normalizeCliOptions(options)) 246 245 if (!ctx?.shouldKeepServer()) 247 246 await ctx?.exit() 248 247 return ctx 249 248 } 250 249 catch (e) { 250 + const { divider } = await import('../reporters/renderers/utils') 251 251 console.error(`\n${c.red(divider(c.bold(c.inverse(' Unhandled Error '))))}`) 252 252 console.error(e) 253 253 console.error('\n\n')
+67 -67
packages/vitest/src/node/cli/cli-config.ts
··· 21 21 // require argument for non-boolean options 22 22 (NonNullable<Value> extends boolean ? {} : { argument: string }) 23 23 24 - type CLIOptions<Config extends {}> = { 24 + export type CLIOptions<Config extends {}> = { 25 25 [Key in keyof Config as NonNullable<Config[Key]> extends Function ? never : Key]-?: CLIOption<Config[Key]> | null 26 26 } 27 27 ··· 29 29 30 30 const apiConfig: (port: number) => CLIOptions<ApiConfig> = (port: number) => ({ 31 31 port: { 32 - 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}`, 32 + 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}\``, 33 33 argument: '[port]', 34 34 }, 35 35 host: { 36 - 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', 36 + 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', 37 37 argument: '[host]', 38 38 }, 39 39 strictPort: { ··· 44 44 45 45 const poolThreadsCommands: CLIOptions<ThreadsOptions & WorkerContextOptions> = { 46 46 isolate: { 47 - description: 'Isolate tests in threads pool (default: true)', 47 + description: 'Isolate tests in threads pool (default: `true`)', 48 48 }, 49 49 singleThread: { 50 - description: 'Run tests inside a single thread (default: false)', 50 + description: 'Run tests inside a single thread (default: `false`)', 51 51 }, 52 52 maxThreads: { 53 53 description: 'Maximum number of threads to run tests in', ··· 58 58 argument: '<workers>', 59 59 }, 60 60 useAtomics: { 61 - description: 'Use Atomics to synchronize threads. This can improve performance in some cases, but might cause segfault in older Node versions (default: false)', 61 + description: 'Use Atomics to synchronize threads. This can improve performance in some cases, but might cause segfault in older Node versions (default: `false`)', 62 62 }, 63 63 execArgv: null, 64 64 } 65 65 66 66 const poolForksCommands: CLIOptions<ForksOptions & WorkerContextOptions> = { 67 67 isolate: { 68 - description: 'Isolate tests in threads pool (default: true)', 68 + description: 'Isolate tests in threads pool (default: `true`)', 69 69 }, 70 70 singleFork: { 71 - description: 'Run tests inside a single child_process (default: false)', 71 + description: 'Run tests inside a single child_process (default: `false`)', 72 72 }, 73 73 maxForks: { 74 74 description: 'Maximum number of processes to run tests in', ··· 128 128 description: 'Enable UI', 129 129 }, 130 130 open: { 131 - description: 'Open UI automatically (default: !process.env.CI)', 131 + description: 'Open UI automatically (default: `!process.env.CI`)', 132 132 }, 133 133 api: { 134 134 argument: '[port]', ··· 167 167 argument: '<name>', 168 168 }, 169 169 enabled: { 170 - description: 'Enables coverage collection. Can be overridden using the --coverage CLI option (default: false)', 170 + description: 'Enables coverage collection. Can be overridden using the `--coverage` CLI option (default: `false`)', 171 171 }, 172 172 include: { 173 - description: 'Files included in coverage as glob patterns. May be specified more than once when using multiple patterns (default: **)', 173 + description: 'Files included in coverage as glob patterns. May be specified more than once when using multiple patterns (default: `**`)', 174 174 argument: '<pattern>', 175 175 array: true, 176 176 }, 177 177 exclude: { 178 - 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)', 178 + description: 'Files to be excluded in coverage. May be specified more than once when using multiple extensions (default: Visit [`coverage.exclude`](https://vitest.dev/config/#coverage-exclude))', 179 179 argument: '<pattern>', 180 180 array: true, 181 181 }, 182 182 extension: { 183 - 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"])', 183 + 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"]`)', 184 184 argument: '<extension>', 185 185 array: true, 186 186 }, ··· 196 196 normalize: true, 197 197 }, 198 198 reporter: { 199 - description: 'Coverage reporters to use. Visit https://vitest.dev/config/#coverage-reporter for more information (default: ["text", "html", "clover", "json"])', 199 + description: 'Coverage reporters to use. Visit [`coverage.reporter`](https://vitest.dev/config/#coverage-reporter) for more information (default: `["text", "html", "clover", "json"]`)', 200 200 argument: '<name>', 201 201 subcommands: null, // don't support custom objects 202 202 array: true, ··· 215 215 argument: '', // no displayed 216 216 subcommands: { 217 217 perFile: { 218 - 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)', 218 + 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`)', 219 219 }, 220 220 autoUpdate: { 221 - description: 'Update threshold values: "lines", "functions", "branches" and "statements" to configuration file when current coverage is above the configured thresholds (default: false)', 221 + description: 'Update threshold values: "lines", "functions", "branches" and "statements" to configuration file when current coverage is above the configured thresholds (default: `false`)', 222 222 }, 223 223 lines: { 224 - description: 'Threshold for lines. Visit https://github.com/istanbuljs/nyc#coverage-thresholds for more information. This option is not available for custom providers', 224 + description: 'Threshold for lines. Visit [istanbuljs](https://github.com/istanbuljs/nyc#coverage-thresholds) for more information. This option is not available for custom providers', 225 225 argument: '<number>', 226 226 }, 227 227 functions: { 228 - description: 'Threshold for functions. Visit https://github.com/istanbuljs/nyc#coverage-thresholds for more information. This option is not available for custom providers', 228 + description: 'Threshold for functions. Visit [istanbuljs](https://github.com/istanbuljs/nyc#coverage-thresholds) for more information. This option is not available for custom providers', 229 229 argument: '<number>', 230 230 }, 231 231 branches: { 232 - description: 'Threshold for branches. Visit https://github.com/istanbuljs/nyc#coverage-thresholds for more information. This option is not available for custom providers', 232 + description: 'Threshold for branches. Visit [istanbuljs](https://github.com/istanbuljs/nyc#coverage-thresholds) for more information. This option is not available for custom providers', 233 233 argument: '<number>', 234 234 }, 235 235 statements: { 236 - description: 'Threshold for statements. Visit https://github.com/istanbuljs/nyc#coverage-thresholds for more information. This option is not available for custom providers', 236 + description: 'Threshold for statements. Visit [istanbuljs](https://github.com/istanbuljs/nyc#coverage-thresholds) for more information. This option is not available for custom providers', 237 237 argument: '<number>', 238 238 }, 239 239 100: { 240 - description: 'Shortcut to set all coverage thresholds to 100 (default: false)', 240 + description: 'Shortcut to set all coverage thresholds to 100 (default: `false`)', 241 241 }, 242 242 }, 243 243 }, 244 244 ignoreClassMethods: { 245 - 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: [])', 245 + description: 'Array of class method names to ignore for coverage. Visit [istanbuljs](https://github.com/istanbuljs/nyc#ignoring-methods) for more information. This option is only available for the istanbul providers (default: `[]`)', 246 246 argument: '<name>', 247 247 array: true, 248 248 }, ··· 251 251 argument: '<number>', 252 252 }, 253 253 customProviderModule: { 254 - 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', 254 + description: 'Specifies the module name or path for the custom coverage provider module. Visit [Custom Coverage Provider](https://vitest.dev/guide/coverage#custom-coverage-provider) for more information. This option is only available for custom providers', 255 255 argument: '<path>', 256 256 normalize: true, 257 257 }, ··· 260 260 argument: '', // no displayed 261 261 subcommands: { 262 262 statements: { 263 - description: 'High and low watermarks for statements in the format of <high>,<low>', 263 + description: 'High and low watermarks for statements in the format of `<high>,<low>`', 264 264 argument: '<watermarks>', 265 265 transform: watermarkTransform, 266 266 }, 267 267 lines: { 268 - description: 'High and low watermarks for lines in the format of <high>,<low>', 268 + description: 'High and low watermarks for lines in the format of `<high>,<low>`', 269 269 argument: '<watermarks>', 270 270 transform: watermarkTransform, 271 271 }, 272 272 branches: { 273 - description: 'High and low watermarks for branches in the format of <high>,<low>', 273 + description: 'High and low watermarks for branches in the format of `<high>,<low>`', 274 274 argument: '<watermarks>', 275 275 transform: watermarkTransform, 276 276 }, 277 277 functions: { 278 - description: 'High and low watermarks for functions in the format of <high>,<low>', 278 + description: 'High and low watermarks for functions in the format of `<high>,<low>`', 279 279 argument: '<watermarks>', 280 280 transform: watermarkTransform, 281 281 }, ··· 284 284 }, 285 285 }, 286 286 mode: { 287 - description: 'Override Vite mode (default: test or benchmark)', 287 + description: 'Override Vite mode (default: `test` or `benchmark`)', 288 288 argument: '<name>', 289 289 }, 290 290 workspace: { ··· 293 293 normalize: true, 294 294 }, 295 295 isolate: { 296 - description: 'Run every test file in isolation. To disable isolation, use --no-isolate (default: true)', 296 + description: 'Run every test file in isolation. To disable isolation, use `--no-isolate` (default: `true`)', 297 297 }, 298 298 globals: { 299 299 description: 'Inject apis globally', ··· 302 302 description: 'Mock browser API with happy-dom', 303 303 }, 304 304 browser: { 305 - description: 'Run tests in the browser. Equivalent to --browser.enabled (default: false)', 305 + description: 'Run tests in the browser. Equivalent to `--browser.enabled` (default: `false`)', 306 306 argument: '<name>', 307 307 transform(browser) { 308 308 if (typeof browser === 'boolean') ··· 317 317 }, 318 318 subcommands: { 319 319 enabled: { 320 - description: 'Run tests in the browser. Equivalent to --browser.enabled (default: false)', 320 + description: 'Run tests in the browser. Equivalent to `--browser.enabled` (default: `false`)', 321 321 }, 322 322 name: { 323 - 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', 323 + description: 'Run all tests in a specific browser. Some browsers are only available for specific providers (see `--browser.provider`). Visit [`browser.name`](https://vitest.dev/config/#browser-name) for more information', 324 324 argument: '<name>', 325 325 }, 326 326 headless: { 327 - 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)', 327 + 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`)', 328 328 }, 329 329 api: { 330 330 description: 'Specify options for the browser API server. Does not affect the --api option', ··· 332 332 subcommands: apiConfig(defaultBrowserPort), 333 333 }, 334 334 provider: { 335 - 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")', 335 + 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 [`browser.provider`](https://vitest.dev/config/#browser-provider) for more information (default: `"webdriverio"`)', 336 336 argument: '<name>', 337 337 subcommands: null, // don't support custom objects 338 338 }, 339 339 providerOptions: { 340 - description: 'Options that are passed down to a browser provider. Visit https://vitest.dev/config/#browser-provideroptions-1-0-0 for more information', 340 + description: 'Options that are passed down to a browser provider. Visit [`browser.providerOptions`](https://vitest.dev/config/#browser-provideroptions) for more information', 341 341 argument: '<options>', 342 342 subcommands: null, // don't support custom objects 343 343 }, 344 344 slowHijackESM: { 345 - 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)', 345 + description: 'Let Vitest use its own module resolution on the browser to enable APIs such as vi.mock and vi.spyOn. Visit [`browser.slowHijackESM`](https://vitest.dev/config/#browser-slowhijackesm) for more information (default: `false`)', 346 346 }, 347 347 isolate: { 348 - description: 'Run every browser test file in isolation. To disable isolation, use --browser.isolate=false (default: true)', 348 + description: 'Run every browser test file in isolation. To disable isolation, use `--browser.isolate=false` (default: `true`)', 349 349 }, 350 350 fileParallelism: { 351 - description: 'Should all test files run in parallel. Use --browser.file-parallelism=false to disable (default: same as --file-parallelism)', 351 + description: 'Should all test files run in parallel. Use `--browser.file-parallelism=false` to disable (default: same as `--file-parallelism`)', 352 352 }, 353 353 }, 354 354 }, 355 355 pool: { 356 - description: 'Specify pool, if not running in the browser (default: threads)', 356 + description: 'Specify pool, if not running in the browser (default: `threads`)', 357 357 argument: '<pool>', 358 358 subcommands: null, // don't support custom objects 359 359 }, ··· 398 398 }, 399 399 }, 400 400 fileParallelism: { 401 - description: 'Should all test files run in parallel. Use --no-file-parallelism to disable (default: true)', 401 + description: 'Should all test files run in parallel. Use `--no-file-parallelism` to disable (default: `true`)', 402 402 }, 403 403 maxWorkers: { 404 404 description: 'Maximum number of workers to run tests in', ··· 409 409 argument: '<workers>', 410 410 }, 411 411 environment: { 412 - description: 'Specify runner environment, if not running in the browser (default: node)', 412 + description: 'Specify runner environment, if not running in the browser (default: `node`)', 413 413 argument: '<name>', 414 414 subcommands: null, // don't support custom objects 415 415 }, ··· 420 420 description: 'Show the size of heap for each test when running in node', 421 421 }, 422 422 allowOnly: { 423 - description: 'Allow tests and suites that are marked as only (default: !process.env.CI)', 423 + description: 'Allow tests and suites that are marked as only (default: `!process.env.CI`)', 424 424 }, 425 425 dangerouslyIgnoreUnhandledErrors: { 426 426 description: 'Ignore any unhandled errors that occur', 427 427 }, 428 428 shard: { 429 - description: 'Test suite shard to execute in a format of <index>/<count>', 429 + description: 'Test suite shard to execute in a format of `<index>/<count>`', 430 430 argument: '<shards>', 431 431 }, 432 432 changed: { 433 - description: 'Run tests that are affected by the changed files (default: false)', 433 + description: 'Run tests that are affected by the changed files (default: `false`)', 434 434 argument: '[since]', 435 435 }, 436 436 sequence: { ··· 438 438 argument: '<options>', 439 439 subcommands: { 440 440 shuffle: { 441 - 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)', 441 + 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`)', 442 442 argument: '', 443 443 subcommands: { 444 444 files: { 445 - description: 'Run files in a random order. Long running tests will not start earlier if you enable this option. (default: false)', 445 + description: 'Run files in a random order. Long running tests will not start earlier if you enable this option. (default: `false`)', 446 446 }, 447 447 tests: { 448 - description: 'Run tests in a random oder (default: false)', 448 + description: 'Run tests in a random oder (default: `false`)', 449 449 }, 450 450 }, 451 451 }, 452 452 concurrent: { 453 - description: 'Make tests run in parallel (default: false)', 453 + description: 'Make tests run in parallel (default: `false`)', 454 454 }, 455 455 seed: { 456 - 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', 456 + description: 'Set the randomization seed. This option will have no effect if --sequence.shuffle is falsy. Visit ["Random Seed" page](https://en.wikipedia.org/wiki/Random_seed) for more information', 457 457 argument: '<seed>', 458 458 }, 459 459 hooks: { 460 - 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")', 460 + description: 'Changes the order in which hooks are executed. Accepted values are: "stack", "list" and "parallel". Visit [`sequence.hooks`](https://vitest.dev/config/#sequence-hooks) for more information (default: `"parallel"`)', 461 461 argument: '<order>', 462 462 }, 463 463 setupFiles: { 464 - 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")', 464 + 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"`)', 465 465 argument: '<order>', 466 466 }, 467 467 }, 468 468 }, 469 469 inspect: { 470 - description: 'Enable Node.js inspector (default: 127.0.0.1:9229)', 470 + description: 'Enable Node.js inspector (default: `127.0.0.1:9229`)', 471 471 argument: '[[host:]port]', 472 472 transform(portOrEnabled) { 473 473 if (portOrEnabled === 0 || portOrEnabled === 'true' || portOrEnabled === 'yes') ··· 490 490 }, 491 491 inspector: null, 492 492 testTimeout: { 493 - description: 'Default timeout of a test in milliseconds (default: 5000)', 493 + description: 'Default timeout of a test in milliseconds (default: `5000`)', 494 494 argument: '<timeout>', 495 495 }, 496 496 hookTimeout: { 497 - description: 'Default hook timeout in milliseconds (default: 10000)', 497 + description: 'Default hook timeout in milliseconds (default: `10000`)', 498 498 argument: '<timeout>', 499 499 }, 500 500 bail: { 501 - description: 'Stop test execution when given number of tests have failed (default: 0)', 501 + description: 'Stop test execution when given number of tests have failed (default: `0`)', 502 502 argument: '<number>', 503 503 }, 504 504 retry: { 505 - description: 'Retry the test specific number of times if it fails (default: 0)', 505 + description: 'Retry the test specific number of times if it fails (default: `0`)', 506 506 argument: '<times>', 507 507 }, 508 508 diff: { ··· 518 518 description: 'Show full diff when snapshot fails', 519 519 }, 520 520 disableConsoleIntercept: { 521 - description: 'Disable automatic interception of console logging (default: false)', 521 + description: 'Disable automatic interception of console logging (default: `false`)', 522 522 }, 523 523 typecheck: { 524 - description: 'Enable typechecking alongside tests (default: false)', 524 + description: 'Enable typechecking alongside tests (default: `false`)', 525 525 argument: '', // allow boolean 526 526 transform: transformNestedBoolean, 527 527 subcommands: { 528 528 enabled: { 529 - description: 'Enable typechecking alongside tests (default: false)', 529 + description: 'Enable typechecking alongside tests (default: `false`)', 530 530 }, 531 531 only: { 532 - description: 'Run only typecheck tests. This automatically enables typecheck (default: false)', 532 + description: 'Run only typecheck tests. This automatically enables typecheck (default: `false`)', 533 533 }, 534 534 checker: { 535 - description: 'Specify the typechecker to use. Available values are: "tcs" and "vue-tsc" and a path to an executable (default: "tsc")', 535 + description: 'Specify the typechecker to use. Available values are: "tcs" and "vue-tsc" and a path to an executable (default: `"tsc"`)', 536 536 argument: '<name>', 537 537 subcommands: null, 538 538 }, ··· 552 552 }, 553 553 }, 554 554 project: { 555 - 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*', 555 + 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*`', 556 556 argument: '<name>', 557 557 array: true, 558 558 }, 559 559 slowTestThreshold: { 560 - description: 'Threshold in milliseconds for a test to be considered slow (default: 300)', 560 + description: 'Threshold in milliseconds for a test to be considered slow (default: `300`)', 561 561 argument: '<threshold>', 562 562 }, 563 563 teardownTimeout: { 564 - description: 'Default timeout of a teardown function in milliseconds (default: 10000)', 564 + description: 'Default timeout of a teardown function in milliseconds (default: `10000`)', 565 565 argument: '<timeout>', 566 566 }, 567 567 cache: { ··· 581 581 }, 582 582 }, 583 583 maxConcurrency: { 584 - description: 'Maximum number of concurrent tests in a suite (default: 5)', 584 + description: 'Maximum number of concurrent tests in a suite (default: `5`)', 585 585 argument: '<number>', 586 586 }, 587 587 ··· 590 590 description: 'Disable watch mode', 591 591 }, 592 592 segfaultRetry: { 593 - description: 'Retry the test suite if it crashes due to a segfault (default: true)', 593 + description: 'Retry the test suite if it crashes due to a segfault (default: `true`)', 594 594 argument: '<times>', 595 595 default: 0, 596 596 }, ··· 599 599 alias: 'no-color', 600 600 }, 601 601 clearScreen: { 602 - description: 'Clear terminal screen when re-running tests during watch mode (default: true)', 602 + description: 'Clear terminal screen when re-running tests during watch mode (default: `true`)', 603 603 }, 604 604 605 605 // disable CLI options
+1 -1
packages/vitest/src/node/reporters/renderers/utils.ts
··· 2 2 import c from 'picocolors' 3 3 import stripAnsi from 'strip-ansi' 4 4 import type { SnapshotSummary, Task } from '../../../types' 5 - import { slash } from '../../../utils' 5 + import { slash } from '../../../utils/base' 6 6 import { F_CHECK, F_CROSS, F_DOT, F_DOWN, F_DOWN_RIGHT, F_LONG_DASH, F_POINTER } from '../../../utils/figures' 7 7 import type { SuiteHooks } from './../../../types/tasks' 8 8