From 1f2443355cc79480332ee994bce397fb5ae4c8fc Mon Sep 17 00:00:00 2001 From: Lorenzo Bloedow <108244120+LorenzoBloedow@users.noreply.github.com> Date: Fri, 18 Aug 2023 14:56:26 +0000 Subject: [PATCH 01/14] fix: thresholdAutoUpdate being passed as a string instead of as a boolean when using the CLI --- packages/vitest/src/node/cli.ts | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/packages/vitest/src/node/cli.ts b/packages/vitest/src/node/cli.ts index a03dfdba6557..dc6c89e2ce3a 100644 --- a/packages/vitest/src/node/cli.ts +++ b/packages/vitest/src/node/cli.ts @@ -182,6 +182,12 @@ function normalizeCliOptions(argv: CliOptions): CliOptions { if ((coverage as CoverageIstanbulOptions).ignoreClassMethods) (coverage as CoverageIstanbulOptions).ignoreClassMethods = toArray((coverage as CoverageIstanbulOptions).ignoreClassMethods) + + const thresholdAutoUpdate = (coverage as CoverageIstanbulOptions).thresholdAutoUpdate + if ((thresholdAutoUpdate as unknown as string) === 'true') + (coverage as CoverageIstanbulOptions).thresholdAutoUpdate = true + else if ((thresholdAutoUpdate as unknown as string) === 'false') + (coverage as CoverageIstanbulOptions).thresholdAutoUpdate = false } return argv } From 34db6b94a0f58231c129a10c70da6b2fa95fb1a6 Mon Sep 17 00:00:00 2001 From: Lorenzo Bloedow <108244120+LorenzoBloedow@users.noreply.github.com> Date: Mon, 21 Aug 2023 09:57:24 -0700 Subject: [PATCH 02/14] Improve readability of `thresholdAutoUpdate` code --- packages/vitest/src/node/cli.ts | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/packages/vitest/src/node/cli.ts b/packages/vitest/src/node/cli.ts index dc6c89e2ce3a..d20b9957ebc3 100644 --- a/packages/vitest/src/node/cli.ts +++ b/packages/vitest/src/node/cli.ts @@ -183,11 +183,18 @@ function normalizeCliOptions(argv: CliOptions): CliOptions { if ((coverage as CoverageIstanbulOptions).ignoreClassMethods) (coverage as CoverageIstanbulOptions).ignoreClassMethods = toArray((coverage as CoverageIstanbulOptions).ignoreClassMethods) - const thresholdAutoUpdate = (coverage as CoverageIstanbulOptions).thresholdAutoUpdate - if ((thresholdAutoUpdate as unknown as string) === 'true') - (coverage as CoverageIstanbulOptions).thresholdAutoUpdate = true - else if ((thresholdAutoUpdate as unknown as string) === 'false') - (coverage as CoverageIstanbulOptions).thresholdAutoUpdate = false + if ('thresholdAutoUpdate' in coverage) { + // Convert string values ('true'|'false') to boolean + if (typeof coverage.thresholdAutoUpdate === 'string') { + const value = coverage.thresholdAutoUpdate === 'false' + ? false + : coverage.thresholdAutoUpdate === 'true' + ? true + : coverage.thresholdAutoUpdate + + coverage.thresholdAutoUpdate = value + } + } } return argv } From bdf1afc3bdb7f35fc29798cd02d47e5100f2ab77 Mon Sep 17 00:00:00 2001 From: Lorenzo Bloedow Date: Mon, 21 Aug 2023 11:57:38 -0700 Subject: [PATCH 03/14] fix the thresholdAutoUpdate problem natively with cac --- packages/vitest/src/node/cli.ts | 14 +------------- 1 file changed, 1 insertion(+), 13 deletions(-) diff --git a/packages/vitest/src/node/cli.ts b/packages/vitest/src/node/cli.ts index d20b9957ebc3..646e5aad02b7 100644 --- a/packages/vitest/src/node/cli.ts +++ b/packages/vitest/src/node/cli.ts @@ -27,6 +27,7 @@ cli .option('--outputFile ', 'Write test results to a file when supporter reporter is also specified, use cac\'s dot notation for individual outputs of multiple reporters') .option('--coverage', 'Enable coverage report') .option('--coverage.all', 'Whether to include all files, including the untested ones into report', { default: true }) + .option('--coverage.thresholdAutoUpdate', 'Update threshold values: "lines", "functions", "branches" and "statements" to configuration file when current coverage is above the configured thresholds') .option('--run', 'Disable watch mode') .option('--mode ', 'Override Vite mode (default: test)') .option('--workspace ', 'Path to a workspace configuration file') @@ -182,19 +183,6 @@ function normalizeCliOptions(argv: CliOptions): CliOptions { if ((coverage as CoverageIstanbulOptions).ignoreClassMethods) (coverage as CoverageIstanbulOptions).ignoreClassMethods = toArray((coverage as CoverageIstanbulOptions).ignoreClassMethods) - - if ('thresholdAutoUpdate' in coverage) { - // Convert string values ('true'|'false') to boolean - if (typeof coverage.thresholdAutoUpdate === 'string') { - const value = coverage.thresholdAutoUpdate === 'false' - ? false - : coverage.thresholdAutoUpdate === 'true' - ? true - : coverage.thresholdAutoUpdate - - coverage.thresholdAutoUpdate = value - } - } } return argv } From aa731cf6d2a171e88f95979dc3b90f68d649b0d6 Mon Sep 17 00:00:00 2001 From: Lorenzo Bloedow Date: Fri, 25 Aug 2023 12:24:31 -0700 Subject: [PATCH 04/14] Add nested Vitest options to cac --- packages/vitest/src/node/cli.ts | 46 ++++++++++++++++++++++++++++++--- 1 file changed, 42 insertions(+), 4 deletions(-) diff --git a/packages/vitest/src/node/cli.ts b/packages/vitest/src/node/cli.ts index 646e5aad02b7..21bd97245c66 100644 --- a/packages/vitest/src/node/cli.ts +++ b/packages/vitest/src/node/cli.ts @@ -4,6 +4,7 @@ import c from 'picocolors' import { version } from '../../package.json' import { toArray } from '../utils' import type { BaseCoverageOptions, CoverageIstanbulOptions, Vitest, VitestRunMode } from '../types' +import { defaultBrowserPort, defaultPort } from '../constants' import type { CliOptions } from './cli-api' import { startVitest } from './cli-api' import { divider } from './reporters/renderers/utils' @@ -20,21 +21,54 @@ cli .option('--dir ', 'Base directory to scan for the test files') .option('--ui', 'Enable UI') .option('--open', 'Open UI automatically (default: !process.env.CI))') - .option('--api [api]', 'Serve API, available options: --api.port , --api.host [host] and --api.strictPort') + .option('--api [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 ${defaultPort}`) + .option('--api.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') + .option('--api.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') + .option('--api.strictPort', 'Set to true to exit if port is already in use, instead of automatically trying the next available port') .option('--silent', 'Silent console output from tests') .option('--hideSkippedTests', 'Hide logs for skipped tests') .option('--reporter ', 'Specify reporters') .option('--outputFile ', 'Write test results to a file when supporter reporter is also specified, use cac\'s dot notation for individual outputs of multiple reporters') .option('--coverage', 'Enable coverage report') .option('--coverage.all', 'Whether to include all files, including the untested ones into report', { default: true }) - .option('--coverage.thresholdAutoUpdate', 'Update threshold values: "lines", "functions", "branches" and "statements" to configuration file when current coverage is above the configured thresholds') + .option('--coverage.provider', 'Select the tool for coverage collection, available values are: "v8", "istanbul" and "custom"') + .option('--coverage.enabled', 'Enables coverage collection. Can be overridden using the --coverage CLI option. This option is not available for custom providers (default: false)') + .option('--coverage.include', 'Files included in coverage as glob patterns. May be specified more than once when using multiple patterns. This option is not available for custom providers (default: **)') + .option('--coverage.extension', 'Extension to be included in coverage. May be specified more than once when using multiple extensions. This option is not available for custom providers (default: [".js", ".cjs", ".mjs", ".ts", ".mts", ".cts", ".tsx", ".jsx", ".vue", ".svelte"])') + .option('--coverage.exclude', 'Files to be excluded in coverage. May be specified more than once when using multiple extensions. This option is not available for custom providers (default: Visit https://vitest.dev/config/#coverage-exclude)') + .option('--coverage.all', 'Whether to include all files, including the untested ones into report. This option is not available for custom providers (default: false)') + .option('--coverage.clean', 'Clean coverage results before running tests. This option is not available for custom providers (default: true)') + .option('--coverage.cleanOnRerun', 'Clean coverage report on watch rerun. This option is not available for custom providers (default: true)') + .option('--coverage.reportsDirectory', 'Directory to write coverage report to. This option is not available for custom providers (default: ./coverage)') + .option('--coverage.reporter', 'Coverage reporters to use. Visit https://vitest.dev/config/#coverage-reporter for more information. This option is not available for custom providers (default: ["text", "html", "clover", "json"])') + .option('--coverage.reportOnFailure', 'Generate coverage report even when tests fail. This option is not available for custom providers (default: false)') + .option('--coverage.allowExternal', 'Collect coverage of files outside the project root. This option is not available for custom providers (default: false)') + .option('--coverage.skipFull', 'Do not show files with 100% statement, branch, and function coverage. This option is not available for custom providers (default: false)') + .option('--coverage.perFile', 'Check thresholds per file. See --coverage.lines, --coverage.functions, --coverage.branches and --coverage.statements for the actual thresholds. This option is not available for custom providers (default: false)') + .option('--coverage.thresholdAutoUpdate', 'Update threshold values: "lines", "functions", "branches" and "statements" to configuration file when current coverage is above the configured thresholds. This option is not available for custom providers (default: false)') + .option('--coverage.lines', 'Threshold for lines. Visit https://github.com/istanbuljs/nyc#coverage-thresholds for more information. This option is not available for custom providers') + .option('--coverage.functions', 'Threshold for functions. Visit https://github.com/istanbuljs/nyc#coverage-thresholds for more information. This option is not available for custom providers') + .option('--coverage.branches', 'Threshold for branches. Visit https://github.com/istanbuljs/nyc#coverage-thresholds for more information. This option is not available for custom providers') + .option('--coverage.statements', 'Threshold for statements. Visit https://github.com/istanbuljs/nyc#coverage-thresholds for more information. This option is not available for custom providers') + .option('--coverage.100', 'Shortcut to set all coverage thresholds to 100. This option is only available for the v8 provider (default: false)') + .option('--coverage.ignoreClassMethods', '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: [])') + .option('--coverage.watermarks', 'Watermarks for statements, lines, branches and functions. Visit https://github.com/istanbuljs/nyc#high-and-low-watermarks for more information. This option is not available for custom providers (default: Visit https://vitest.dev/config/#coverage-watermarks)') + .option('--coverage.customProviderModule', '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') .option('--run', 'Disable watch mode') .option('--mode ', 'Override Vite mode (default: test)') .option('--workspace ', 'Path to a workspace configuration file') .option('--isolate', 'Run every test file in isolation. To disable isolation, use --no-isolate (default: true)') .option('--globals', 'Inject apis globally') .option('--dom', 'Mock browser API with happy-dom') - .option('--browser [options]', 'Run tests in the browser (default: false)') + .option('--browser', 'Run tests in the browser. Equivalent to --browser.enabled (default: false)') + .option('--browser.enabled', 'Run all tests inside a browser by default. Can be overriden with the poolMatchGlobs configuration file option (default: false)') + .option('--browser.name', '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') + .option('--browser.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)') + .option('--browser.api [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. Does not affect the --api option. If true will be set to ${defaultBrowserPort} (default: ${defaultBrowserPort})`) + .option('--browser.api.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. Does not affect the --api.port option') + .option('--browser.api.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. Does not affect the --api.host option') + .option('--browser.provider', '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")') + .option('--browser.slowHijackESM', '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: true)') .option('--pool ', 'Specify pool, if not running in the browser (default: threads)') .option('--poolOptions ', 'Specify pool options') .option('--poolOptions.threads.isolate', 'Isolate tests in threads pool (default: true)') @@ -49,7 +83,11 @@ cli .option('--dangerouslyIgnoreUnhandledErrors', 'Ignore any unhandled errors that occur') .option('--shard ', 'Test suite shard to execute in a format of /') .option('--changed [since]', 'Run tests that are affected by the changed files (default: false)') - .option('--sequence ', 'Define in what order to run tests (use --sequence.shuffle to run tests in random order, use --sequence.concurrent to run tests in parallel)') + .option('--sequence.shuffle [shuffle]', 'Run 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)') + .option('--sequence.concurrent [concurrent]', 'Make tests run in parallel (default: false)') + .option('--sequence.seed ', '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') + .option('--sequence.hooks ', '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")') + .option('--sequence.setupFiles ', '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")') .option('--segfaultRetry ', 'Return tests on segment fault (default: 0)', { default: 0 }) .option('--no-color', 'Removes colors from the console output') .option('--inspect', 'Enable Node.js inspector') From 85f747163fa4c972bcb2c37862c65d0ee78d2f02 Mon Sep 17 00:00:00 2001 From: Lorenzo Bloedow Date: Fri, 25 Aug 2023 13:24:33 -0700 Subject: [PATCH 05/14] Omit nested help options by default and enable them when using the VERBOSE environment variable --- packages/vitest/src/node/cli.ts | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/packages/vitest/src/node/cli.ts b/packages/vitest/src/node/cli.ts index 21bd97245c66..a9fa1551ad89 100644 --- a/packages/vitest/src/node/cli.ts +++ b/packages/vitest/src/node/cli.ts @@ -103,7 +103,20 @@ cli .option('--typecheck.enabled', 'Enable typechecking alongside tests (default: false)') .option('--typecheck.only', 'Run only typecheck tests. This automatically enables typecheck (default: false)') .option('--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') - .help() + .help((info) => { + if (process.env.VERBOSE === 'true') + return info + + const optionObj = info.find(current => current.title === 'Options') + if (typeof optionObj !== 'object') + return info + + const options = optionObj.body.split('\n') + const filteredOptions = options.filter(option => option.search(/\S+\.\S+/) === -1).join('\n') + optionObj.body = filteredOptions + + return info + }) cli .command('run [...filters]') From 34f9b926af977e9786ef956b2b944d2ad7051b6b Mon Sep 17 00:00:00 2001 From: Lorenzo Bloedow Date: Mon, 28 Aug 2023 13:16:00 -0700 Subject: [PATCH 06/14] Show nested options on an ad hoc basis by using sub-commands --- packages/vitest/src/node/cli.ts | 65 ++++++++++++++++++++++++++++++--- 1 file changed, 59 insertions(+), 6 deletions(-) diff --git a/packages/vitest/src/node/cli.ts b/packages/vitest/src/node/cli.ts index a9fa1551ad89..d270a98e1d04 100644 --- a/packages/vitest/src/node/cli.ts +++ b/packages/vitest/src/node/cli.ts @@ -104,16 +104,69 @@ cli .option('--typecheck.only', 'Run only typecheck tests. This automatically enables typecheck (default: false)') .option('--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') .help((info) => { - if (process.env.VERBOSE === 'true') + const options = info.find(current => current.title === 'Options') + if (typeof options !== 'object') return info - const optionObj = info.find(current => current.title === 'Options') - if (typeof optionObj !== 'object') + const helpIndex = process.argv.findIndex(arg => arg === '--help') + const subCommands = process.argv.slice(helpIndex + 1) + + const defaultOutput = options.body + .split('\n') + .filter(line => /--\S+\./.test(line) === false) + .join('\n') + + // Filter out options with dot-notation if --help is not called with a sub-command (default behavior) + if (subCommands.length === 0) { + options.body = defaultOutput + return info + } + + if (subCommands.length === 1 && subCommands[0] === '--verbose') return info - const options = optionObj.body.split('\n') - const filteredOptions = options.filter(option => option.search(/\S+\.\S+/) === -1).join('\n') - optionObj.body = filteredOptions + const subCommandMarker = '$SUB_COMMAND_MARKER$' + + const banner = info.find(current => /^vitest\/[0-9]+\.[0-9]+\.[0-9]+$/.test(current.body)) + function addBannerWarning(warning: string) { + if (typeof banner?.body === 'string') { + if (banner?.body.includes(warning)) + return + + banner.body = `${banner.body}\n WARN: ${warning}` + } + } + + // If other sub-command combinations are used, only show options for the sub-command + for (let i = 0; i < subCommands.length; i++) { + const subCommand = subCommands[i] + + // --help --verbose can't be called with multiple sub-commands and is handled above + if (subCommand === '--verbose') { + addBannerWarning('--verbose sub-command ignored because, when used with --help, it must be the only sub-command') + continue + } + + // Mark the help section for the sub-commands + if (subCommand.startsWith('--')) { + options.body = options.body + .split('\n') + .map(line => (line.trim().startsWith(subCommand)) ? `${subCommandMarker}${line}` : line) + .join('\n') + } + } + + // Filter based on the marked options to preserve the original sort order + options.body = options.body + .split('\n') + .map(line => line.startsWith(subCommandMarker) ? line.split(subCommandMarker)[1] : '') + .filter(line => line.length !== 0) + .join('\n') + + if (!options.body) { + addBannerWarning('no options were found for your sub-commands so we printed the whole output') + options.body = defaultOutput + } return info }) From bf656d7915047f7e363dffc60e6eac39942b47c5 Mon Sep 17 00:00:00 2001 From: Lorenzo Bloedow Date: Mon, 28 Aug 2023 13:26:49 -0700 Subject: [PATCH 07/14] Write subcommand without hyphen --- packages/vitest/src/node/cli.ts | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/packages/vitest/src/node/cli.ts b/packages/vitest/src/node/cli.ts index d270a98e1d04..71a6a6498a74 100644 --- a/packages/vitest/src/node/cli.ts +++ b/packages/vitest/src/node/cli.ts @@ -109,23 +109,23 @@ cli return info const helpIndex = process.argv.findIndex(arg => arg === '--help') - const subCommands = process.argv.slice(helpIndex + 1) + const subcommands = process.argv.slice(helpIndex + 1) const defaultOutput = options.body .split('\n') .filter(line => /--\S+\./.test(line) === false) .join('\n') - // Filter out options with dot-notation if --help is not called with a sub-command (default behavior) - if (subCommands.length === 0) { + // Filter out options with dot-notation if --help is not called with a subcommand (default behavior) + if (subcommands.length === 0) { options.body = defaultOutput return info } - if (subCommands.length === 1 && subCommands[0] === '--verbose') + if (subcommands.length === 1 && subcommands[0] === '--verbose') return info - const subCommandMarker = '$SUB_COMMAND_MARKER$' + const subcommandMarker = '$SUB_COMMAND_MARKER$' const banner = info.find(current => /^vitest\/[0-9]+\.[0-9]+\.[0-9]+$/.test(current.body)) function addBannerWarning(warning: string) { @@ -137,21 +137,21 @@ cli } } - // If other sub-command combinations are used, only show options for the sub-command - for (let i = 0; i < subCommands.length; i++) { - const subCommand = subCommands[i] + // If other subcommand combinations are used, only show options for the subcommand + for (let i = 0; i < subcommands.length; i++) { + const subcommand = subcommands[i] - // --help --verbose can't be called with multiple sub-commands and is handled above - if (subCommand === '--verbose') { - addBannerWarning('--verbose sub-command ignored because, when used with --help, it must be the only sub-command') + // --help --verbose can't be called with multiple subcommands and is handled above + if (subcommand === '--verbose') { + addBannerWarning('--verbose subcommand ignored because, when used with --help, it must be the only subcommand') continue } - // Mark the help section for the sub-commands - if (subCommand.startsWith('--')) { + // Mark the help section for the subcommands + if (subcommand.startsWith('--')) { options.body = options.body .split('\n') - .map(line => (line.trim().startsWith(subCommand)) ? `${subCommandMarker}${line}` : line) + .map(line => (line.trim().startsWith(subcommand)) ? `${subcommandMarker}${line}` : line) .join('\n') } } @@ -159,12 +159,12 @@ cli // Filter based on the marked options to preserve the original sort order options.body = options.body .split('\n') - .map(line => line.startsWith(subCommandMarker) ? line.split(subCommandMarker)[1] : '') + .map(line => line.startsWith(subcommandMarker) ? line.split(subcommandMarker)[1] : '') .filter(line => line.length !== 0) .join('\n') if (!options.body) { - addBannerWarning('no options were found for your sub-commands so we printed the whole output') + addBannerWarning('no options were found for your subcommands so we printed the whole output') options.body = defaultOutput } From 9b1067b3834129c95faab694400fdaaca828ca05 Mon Sep 17 00:00:00 2001 From: Lorenzo Bloedow Date: Tue, 19 Dec 2023 10:49:24 -0500 Subject: [PATCH 08/14] Change --verbose subcommand to --expand-help --- packages/vitest/src/node/cli.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/vitest/src/node/cli.ts b/packages/vitest/src/node/cli.ts index 71a6a6498a74..13ac6848307b 100644 --- a/packages/vitest/src/node/cli.ts +++ b/packages/vitest/src/node/cli.ts @@ -122,7 +122,7 @@ cli return info } - if (subcommands.length === 1 && subcommands[0] === '--verbose') + if (subcommands.length === 1 && subcommands[0] === '--expand-help') return info const subcommandMarker = '$SUB_COMMAND_MARKER$' @@ -141,9 +141,9 @@ cli for (let i = 0; i < subcommands.length; i++) { const subcommand = subcommands[i] - // --help --verbose can't be called with multiple subcommands and is handled above - if (subcommand === '--verbose') { - addBannerWarning('--verbose subcommand ignored because, when used with --help, it must be the only subcommand') + // --help --expand-help can't be called with multiple subcommands and is handled above + if (subcommand === '--expand-help') { + addBannerWarning('--expand-help subcommand ignored because, when used with --help, it must be the only subcommand') continue } From 31e302c3005f43be2953d5ed2a3083682c7707d5 Mon Sep 17 00:00:00 2001 From: Lorenzo Date: Sat, 13 Jan 2024 14:36:45 -0400 Subject: [PATCH 09/14] Fix wrong 'api' CLI option --- packages/vitest/src/node/cli.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/vitest/src/node/cli.ts b/packages/vitest/src/node/cli.ts index 13ac6848307b..85ae63de2198 100644 --- a/packages/vitest/src/node/cli.ts +++ b/packages/vitest/src/node/cli.ts @@ -22,7 +22,7 @@ cli .option('--ui', 'Enable UI') .option('--open', 'Open UI automatically (default: !process.env.CI))') .option('--api [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 ${defaultPort}`) - .option('--api.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') + .option('--api.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 ${defaultPort}`) .option('--api.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') .option('--api.strictPort', 'Set to true to exit if port is already in use, instead of automatically trying the next available port') .option('--silent', 'Silent console output from tests') From 330445e416b7b0e0f64941e8a6748169459064fb Mon Sep 17 00:00:00 2001 From: Lorenzo Date: Sat, 13 Jan 2024 15:46:04 -0400 Subject: [PATCH 10/14] Create tests for --help and --expand-help options --- test/cli/test/help.test.ts | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 test/cli/test/help.test.ts diff --git a/test/cli/test/help.test.ts b/test/cli/test/help.test.ts new file mode 100644 index 000000000000..be0bbbbac35e --- /dev/null +++ b/test/cli/test/help.test.ts @@ -0,0 +1,19 @@ +import { expect, test } from 'vitest' + +import { runVitestCli } from '../../test-utils' + +const nestedRegex = /--\w+\.\w+/ +test('should not show nested help options by default', async () => { + const { stdout } = await runVitestCli('--help') + expect(stdout).not.toMatch(nestedRegex) +}) + +test('should show nested help options when used with --expand-help', async () => { + const { stdout } = await runVitestCli('--help', '--expand-help') + expect(stdout).toMatch(nestedRegex) +}) + +test('should not show nested help options when used with --expand-help and another option', async () => { + const { stdout } = await runVitestCli('--help', '--expand-help', '--run') + expect(stdout).not.toMatch(nestedRegex) +}) From c6ce3210844b0cb14497bcb8033df8cf5588329c Mon Sep 17 00:00:00 2001 From: Lorenzo Date: Sat, 13 Jan 2024 16:17:15 -0400 Subject: [PATCH 11/14] Fix wrong CAC argument type for CLI option --- packages/vitest/src/node/cli.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/vitest/src/node/cli.ts b/packages/vitest/src/node/cli.ts index 85ae63de2198..4926b91c8303 100644 --- a/packages/vitest/src/node/cli.ts +++ b/packages/vitest/src/node/cli.ts @@ -62,7 +62,7 @@ cli .option('--dom', 'Mock browser API with happy-dom') .option('--browser', 'Run tests in the browser. Equivalent to --browser.enabled (default: false)') .option('--browser.enabled', 'Run all tests inside a browser by default. Can be overriden with the poolMatchGlobs configuration file option (default: false)') - .option('--browser.name', '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') + .option('--browser.name ', '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') .option('--browser.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)') .option('--browser.api [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. Does not affect the --api option. If true will be set to ${defaultBrowserPort} (default: ${defaultBrowserPort})`) .option('--browser.api.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. Does not affect the --api.port option') From b9c7514359a2d581ee8a35ef35fd9719e02a9f2a Mon Sep 17 00:00:00 2001 From: Lorenzo Date: Sat, 13 Jan 2024 16:56:30 -0400 Subject: [PATCH 12/14] Add nested options to the docs --- docs/guide/cli.md | 39 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) diff --git a/docs/guide/cli.md b/docs/guide/cli.md index 71d7b618c239..4bc8faa27b08 100644 --- a/docs/guide/cli.md +++ b/docs/guide/cli.md @@ -68,7 +68,9 @@ Run only [benchmark](https://vitest.dev/guide/features.html#benchmarking-experim | `--dir `| Base directory to scan for the test files | | `--ui` | Enable UI | | `--open` | Open the UI automatically if enabled (default: `true`) | -| `--api [api]` | Serve API, available options: `--api.port `, `--api.host [host]` and `--api.strictPort` | +| `--api [port], --api.port [port]` | Specify server port. Note if the port is already being used, Vite will automatically try the next available port | +| `--api.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 | +| `--api.strictPort` | Set to true to exit if port is already in use, instead of automatically trying the next available port | | `--pool ` | Specify pool, if not running in the browser (default: `threads`) | | `--poolOptions ` | Specify pool options | | `--poolOptions.threads.isolate` | Isolate tests in threads pool (default: `true`) | @@ -80,6 +82,29 @@ Run only [benchmark](https://vitest.dev/guide/features.html#benchmarking-experim | `--reporter ` | Select reporter: `default`, `verbose`, `dot`, `junit`, `json`, or a path to a custom reporter | | `--outputFile ` | Write test results to a file when the `--reporter=json` or `--reporter=junit` option is also specified
Via [cac's dot notation] you can specify individual outputs for multiple reporters | | `--coverage` | Enable coverage report | +| `--coverage.all` | Whether to include all files, including the untested ones into report | +| `--coverage.provider` | Select the tool for coverage collection, available values are: "v8", "istanbul" and "custom" | +| `--coverage.enabled` | Enables coverage collection. Can be overridden using the --coverage CLI option. This option is not available for custom providers (default: false) | +| `--coverage.include` | Files included in coverage as glob patterns. May be specified more than once when using multiple patterns. This option is not available for custom providers (default: **) | +| `--coverage.extension` | Extension to be included in coverage. May be specified more than once when using multiple extensions. This option is not available for custom providers (default: `[".js", ".cjs", ".mjs", ".ts", ".mts", ".cts", ".tsx", ".jsx", ".vue", ".svelte"]`) | +| `--coverage.exclude` | Files to be excluded in coverage. May be specified more than once when using multiple extensions. This option is not available for custom providers (default: Visit https://vitest.dev/config/#coverage-exclude) +| `--coverage.clean` | Clean coverage results before running tests. This option is not available for custom providers (default: true) | +| `coverage.cleanOnRerun` | Clean coverage report on watch rerun. This option is not available for custom providers (default: true) | +| `coverage.reportsDirectory` | Directory to write coverage report to. This option is not available for custom providers (default: ./coverage) | +| `--coverage.reporter` | Coverage reporters to use. Visit [https://vitest.dev/config/#coverage-reporter](https://vitest.dev/config/#coverage-reporter) for more information. This option is not available for custom providers (default: `["text", "html", "clover", "json"]`) | +| `--coverage.reportOnFailure` | Generate coverage report even when tests fail. This option is not available for custom providers (default: `false`) | +| `--coverage.allowExternal` | Collect coverage of files outside the project root. This option is not available for custom providers (default: `false`) | +| `--coverage.skipFull` | Do not show files with 100% statement, branch, and function coverage. This option is not available for custom providers (default: `false`) | +| `--coverage.perFile` | Check thresholds per file. See `--coverage.lines`, `--coverage.functions`, `--coverage.branches` and `--coverage.statements` for the actual thresholds. This option is not available for custom providers (default: `false`) | +| `--coverage.thresholdAutoUpdate` | Update threshold values: "lines", "functions", "branches" and "statements" to configuration file when current coverage is above the configured thresholds. This option is not available for custom providers (default: `false`) | +| `--coverage.lines` | Threshold for lines. Visit [https://github.com/istanbuljs/nyc#coverage-thresholds](https://github.com/istanbuljs/nyc#coverage-thresholds) for more information. This option is not available for custom providers | +| `--coverage.functions` | Threshold for functions. Visit [https://github.com/istanbuljs/nyc#coverage-thresholds](https://github.com/istanbuljs/nyc#coverage-thresholds) for more information. This option is not available for custom providers | +| `--coverage.branches` | Threshold for branches. Visit [https://github.com/istanbuljs/nyc#coverage-thresholds](https://github.com/istanbuljs/nyc#coverage-thresholds) for more information. This option is not available for custom providers | +| `--coverage.statements` | Threshold for statements. Visit [https://github.com/istanbuljs/nyc#coverage-thresholds](https://github.com/istanbuljs/nyc#coverage-thresholds) for more information. This option is not available for custom providers | +| `--coverage.100` | Shortcut to set all coverage thresholds to 100. This option is only available for the v8 provider (default: `false`) | +| `--coverage.ignoreClassMethods` | Array of class method names to ignore for coverage. Visit [https://github.com/istanbuljs/nyc#ignoring-methods](https://github.com/istanbuljs/nyc#ignoring-methods) for more information. This option is only available for the istanbul providers (default: `[]`) | +| `--coverage.watermarks` | Watermarks for statements, lines, branches and functions. Visit [https://github.com/istanbuljs/nyc#high-and-low-watermarks](https://github.com/istanbuljs/nyc#high-and-low-watermarks) for more information. This option is not available for custom providers (default: Visit [https://vitest.dev/config/#coverage-watermarks](https://vitest.dev/config/#coverage-watermarks)) | +| `--coverage.customProviderModule` | Specifies the module name or path for the custom coverage provider module. Visit [https://vitest.dev/guide/coverage.html#custom-coverage-provider](https://vitest.dev/guide/coverage.html#custom-coverage-provider) for more information. This option is only available for custom providers | | `--run` | Do not watch | | `--isolate` | Run every test file in isolation. To disable isolation, use --no-isolate (default: `true`) | | `--mode ` | Override Vite mode (default: `test`) | @@ -87,6 +112,14 @@ Run only [benchmark](https://vitest.dev/guide/features.html#benchmarking-experim | `--globals` | Inject APIs globally | | `--dom` | Mock browser API with happy-dom | | `--browser [options]` | Run tests in [the browser](/guide/browser) (default: `false`) | +| `--browser.enabled` | Run all tests inside a browser by default. Can be overriden with the poolMatchGlobs configuration file option (default: false) | +| `--browser.name ` | 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 | +| `--browser.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) | +| `--browser.api [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. Does not affect the --api option. If true will be set to ${defaultBrowserPort} (default: ${defaultBrowserPort}) | +| `--browser.api.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. Does not affect the --api.port option | +| `--browser.api.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. Does not affect the --api.host option | +| `--browser.provider` | 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") | +| `--browser.slowHijackESM` | 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: true) | | `--environment ` | Runner environment (default: `node`) | | `--passWithNoTests` | Pass when no tests found | | `--logHeapUsage` | Show the size of heap for each test | @@ -95,6 +128,10 @@ Run only [benchmark](https://vitest.dev/guide/features.html#benchmarking-experim | `--changed [since]` | Run tests that are affected by the changed files (default: false). See [docs](#changed) | | `--shard ` | Execute tests in a specified shard | | `--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) | +| `--sequence.concurrent [concurrent]` | Make tests run in parallel (default: false) | +| `--sequence.seed ` | 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 | +| `--sequence.hooks ` | 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") | +| `--sequence.setupFiles ` | 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") | | `--no-color` | Removes colors from the console output | | `--inspect` | Enables Node.js inspector | | `--inspect-brk` | Enables Node.js inspector with break | From 43b7768e0c41041827882b96c7297c5bbba779dc Mon Sep 17 00:00:00 2001 From: Lorenzo Date: Sun, 14 Jan 2024 15:03:28 -0400 Subject: [PATCH 13/14] Fix wrong coverage options --- docs/guide/cli.md | 16 ++++++++-------- packages/vitest/src/node/cli.ts | 15 +++++++-------- 2 files changed, 15 insertions(+), 16 deletions(-) diff --git a/docs/guide/cli.md b/docs/guide/cli.md index 4bc8faa27b08..ca7282243ffe 100644 --- a/docs/guide/cli.md +++ b/docs/guide/cli.md @@ -82,7 +82,7 @@ Run only [benchmark](https://vitest.dev/guide/features.html#benchmarking-experim | `--reporter ` | Select reporter: `default`, `verbose`, `dot`, `junit`, `json`, or a path to a custom reporter | | `--outputFile ` | Write test results to a file when the `--reporter=json` or `--reporter=junit` option is also specified
Via [cac's dot notation] you can specify individual outputs for multiple reporters | | `--coverage` | Enable coverage report | -| `--coverage.all` | Whether to include all files, including the untested ones into report | +| `--coverage.all` | Whether to include all files, including the untested ones into report (default: `true`) | | `--coverage.provider` | Select the tool for coverage collection, available values are: "v8", "istanbul" and "custom" | | `--coverage.enabled` | Enables coverage collection. Can be overridden using the --coverage CLI option. This option is not available for custom providers (default: false) | | `--coverage.include` | Files included in coverage as glob patterns. May be specified more than once when using multiple patterns. This option is not available for custom providers (default: **) | @@ -95,13 +95,13 @@ Run only [benchmark](https://vitest.dev/guide/features.html#benchmarking-experim | `--coverage.reportOnFailure` | Generate coverage report even when tests fail. This option is not available for custom providers (default: `false`) | | `--coverage.allowExternal` | Collect coverage of files outside the project root. This option is not available for custom providers (default: `false`) | | `--coverage.skipFull` | Do not show files with 100% statement, branch, and function coverage. This option is not available for custom providers (default: `false`) | -| `--coverage.perFile` | Check thresholds per file. See `--coverage.lines`, `--coverage.functions`, `--coverage.branches` and `--coverage.statements` for the actual thresholds. This option is not available for custom providers (default: `false`) | -| `--coverage.thresholdAutoUpdate` | Update threshold values: "lines", "functions", "branches" and "statements" to configuration file when current coverage is above the configured thresholds. This option is not available for custom providers (default: `false`) | -| `--coverage.lines` | Threshold for lines. Visit [https://github.com/istanbuljs/nyc#coverage-thresholds](https://github.com/istanbuljs/nyc#coverage-thresholds) for more information. This option is not available for custom providers | -| `--coverage.functions` | Threshold for functions. Visit [https://github.com/istanbuljs/nyc#coverage-thresholds](https://github.com/istanbuljs/nyc#coverage-thresholds) for more information. This option is not available for custom providers | -| `--coverage.branches` | Threshold for branches. Visit [https://github.com/istanbuljs/nyc#coverage-thresholds](https://github.com/istanbuljs/nyc#coverage-thresholds) for more information. This option is not available for custom providers | -| `--coverage.statements` | Threshold for statements. Visit [https://github.com/istanbuljs/nyc#coverage-thresholds](https://github.com/istanbuljs/nyc#coverage-thresholds) for more information. This option is not available for custom providers | -| `--coverage.100` | Shortcut to set all coverage thresholds to 100. This option is only available for the v8 provider (default: `false`) | +| `--coverage.thresholds.perFile` | Check thresholds per file. See `--coverage.thresholds.lines`, `--coverage.thresholds.functions`, `--coverage.thresholds.branches` and `--coverage.thresholds.statements` for the actual thresholds. This option is not available for custom providers (default: `false`) | +| `--coverage.thresholds.autoUpdate` | Update threshold values: "lines", "functions", "branches" and "statements" to configuration file when current coverage is above the configured thresholds. This option is not available for custom providers (default: `false`) | +| `--coverage.thresholds.lines` | Threshold for lines. Visit [https://github.com/istanbuljs/nyc#coverage-thresholds](https://github.com/istanbuljs/nyc#coverage-thresholds) for more information. This option is not available for custom providers | +| `--coverage.thresholds.functions` | Threshold for functions. Visit [https://github.com/istanbuljs/nyc#coverage-thresholds](https://github.com/istanbuljs/nyc#coverage-thresholds) for more information. This option is not available for custom providers | +| `--coverage.thresholds.branches` | Threshold for branches. Visit [https://github.com/istanbuljs/nyc#coverage-thresholds](https://github.com/istanbuljs/nyc#coverage-thresholds) for more information. This option is not available for custom providers | +| `--coverage.thresholds.statements` | Threshold for statements. Visit [https://github.com/istanbuljs/nyc#coverage-thresholds](https://github.com/istanbuljs/nyc#coverage-thresholds) for more information. This option is not available for custom providers | +| `--coverage.thresholds.100` | Shortcut to set all coverage thresholds to 100. This option is only available for the v8 provider (default: `false`) | | `--coverage.ignoreClassMethods` | Array of class method names to ignore for coverage. Visit [https://github.com/istanbuljs/nyc#ignoring-methods](https://github.com/istanbuljs/nyc#ignoring-methods) for more information. This option is only available for the istanbul providers (default: `[]`) | | `--coverage.watermarks` | Watermarks for statements, lines, branches and functions. Visit [https://github.com/istanbuljs/nyc#high-and-low-watermarks](https://github.com/istanbuljs/nyc#high-and-low-watermarks) for more information. This option is not available for custom providers (default: Visit [https://vitest.dev/config/#coverage-watermarks](https://vitest.dev/config/#coverage-watermarks)) | | `--coverage.customProviderModule` | Specifies the module name or path for the custom coverage provider module. Visit [https://vitest.dev/guide/coverage.html#custom-coverage-provider](https://vitest.dev/guide/coverage.html#custom-coverage-provider) for more information. This option is only available for custom providers | diff --git a/packages/vitest/src/node/cli.ts b/packages/vitest/src/node/cli.ts index 4926b91c8303..3fb2ff11474c 100644 --- a/packages/vitest/src/node/cli.ts +++ b/packages/vitest/src/node/cli.ts @@ -36,7 +36,6 @@ cli .option('--coverage.include', 'Files included in coverage as glob patterns. May be specified more than once when using multiple patterns. This option is not available for custom providers (default: **)') .option('--coverage.extension', 'Extension to be included in coverage. May be specified more than once when using multiple extensions. This option is not available for custom providers (default: [".js", ".cjs", ".mjs", ".ts", ".mts", ".cts", ".tsx", ".jsx", ".vue", ".svelte"])') .option('--coverage.exclude', 'Files to be excluded in coverage. May be specified more than once when using multiple extensions. This option is not available for custom providers (default: Visit https://vitest.dev/config/#coverage-exclude)') - .option('--coverage.all', 'Whether to include all files, including the untested ones into report. This option is not available for custom providers (default: false)') .option('--coverage.clean', 'Clean coverage results before running tests. This option is not available for custom providers (default: true)') .option('--coverage.cleanOnRerun', 'Clean coverage report on watch rerun. This option is not available for custom providers (default: true)') .option('--coverage.reportsDirectory', 'Directory to write coverage report to. This option is not available for custom providers (default: ./coverage)') @@ -44,13 +43,13 @@ cli .option('--coverage.reportOnFailure', 'Generate coverage report even when tests fail. This option is not available for custom providers (default: false)') .option('--coverage.allowExternal', 'Collect coverage of files outside the project root. This option is not available for custom providers (default: false)') .option('--coverage.skipFull', 'Do not show files with 100% statement, branch, and function coverage. This option is not available for custom providers (default: false)') - .option('--coverage.perFile', 'Check thresholds per file. See --coverage.lines, --coverage.functions, --coverage.branches and --coverage.statements for the actual thresholds. This option is not available for custom providers (default: false)') - .option('--coverage.thresholdAutoUpdate', 'Update threshold values: "lines", "functions", "branches" and "statements" to configuration file when current coverage is above the configured thresholds. This option is not available for custom providers (default: false)') - .option('--coverage.lines', 'Threshold for lines. Visit https://github.com/istanbuljs/nyc#coverage-thresholds for more information. This option is not available for custom providers') - .option('--coverage.functions', 'Threshold for functions. Visit https://github.com/istanbuljs/nyc#coverage-thresholds for more information. This option is not available for custom providers') - .option('--coverage.branches', 'Threshold for branches. Visit https://github.com/istanbuljs/nyc#coverage-thresholds for more information. This option is not available for custom providers') - .option('--coverage.statements', 'Threshold for statements. Visit https://github.com/istanbuljs/nyc#coverage-thresholds for more information. This option is not available for custom providers') - .option('--coverage.100', 'Shortcut to set all coverage thresholds to 100. This option is only available for the v8 provider (default: false)') + .option('--coverage.thresholds.perFile', 'Check thresholds per file. See --coverage.thresholds.lines, --coverage.thresholds.functions, --coverage.thresholds.branches and --coverage.thresholds.statements for the actual thresholds. This option is not available for custom providers (default: false)') + .option('--coverage.thresholds.autoUpdate', 'Update threshold values: "lines", "functions", "branches" and "statements" to configuration file when current coverage is above the configured thresholds. This option is not available for custom providers (default: false)') + .option('--coverage.thresholds.lines', 'Threshold for lines. Visit https://github.com/istanbuljs/nyc#coverage-thresholds for more information. This option is not available for custom providers') + .option('--coverage.thresholds.functions', 'Threshold for functions. Visit https://github.com/istanbuljs/nyc#coverage-thresholds for more information. This option is not available for custom providers') + .option('--coverage.thresholds.branches', 'Threshold for branches. Visit https://github.com/istanbuljs/nyc#coverage-thresholds for more information. This option is not available for custom providers') + .option('--coverage.thresholds.statements', 'Threshold for statements. Visit https://github.com/istanbuljs/nyc#coverage-thresholds for more information. This option is not available for custom providers') + .option('--coverage.thresholds.100', 'Shortcut to set all coverage thresholds to 100. This option is only available for the v8 provider (default: false)') .option('--coverage.ignoreClassMethods', '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: [])') .option('--coverage.watermarks', 'Watermarks for statements, lines, branches and functions. Visit https://github.com/istanbuljs/nyc#high-and-low-watermarks for more information. This option is not available for custom providers (default: Visit https://vitest.dev/config/#coverage-watermarks)') .option('--coverage.customProviderModule', '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') From 3c5acffa065cae5f45746da9551c139039718d56 Mon Sep 17 00:00:00 2001 From: Vladimir Sheremet Date: Tue, 6 Feb 2024 14:26:58 +0100 Subject: [PATCH 14/14] chore: fix issues --- docs/guide/cli.md | 12 ++++++++---- packages/vitest/src/node/cli.ts | 6 +++--- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/docs/guide/cli.md b/docs/guide/cli.md index ca7282243ffe..a21d1e642165 100644 --- a/docs/guide/cli.md +++ b/docs/guide/cli.md @@ -80,7 +80,7 @@ Run only [benchmark](https://vitest.dev/guide/features.html#benchmarking-experim | `--minWorkers ` | Minimum number of workers to run tests in | | `--silent` | Silent console output from tests | | `--reporter ` | Select reporter: `default`, `verbose`, `dot`, `junit`, `json`, or a path to a custom reporter | -| `--outputFile ` | Write test results to a file when the `--reporter=json` or `--reporter=junit` option is also specified
Via [cac's dot notation] you can specify individual outputs for multiple reporters | +| `--outputFile ` | Write test results to a file when the `--reporter=json` or `--reporter=junit` option is also specified
Via [cac's dot notation](https://github.com/cacjs/cac#dot-nested-options) you can specify individual outputs for multiple reporters | | `--coverage` | Enable coverage report | | `--coverage.all` | Whether to include all files, including the untested ones into report (default: `true`) | | `--coverage.provider` | Select the tool for coverage collection, available values are: "v8", "istanbul" and "custom" | @@ -127,7 +127,7 @@ Run only [benchmark](https://vitest.dev/guide/features.html#benchmarking-experim | `--dangerouslyIgnoreUnhandledErrors` | Ignore any unhandled errors that occur | | `--changed [since]` | Run tests that are affected by the changed files (default: false). See [docs](#changed) | | `--shard ` | Execute tests in a specified shard | -| `--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) | +| `--sequence` | Define in what order to run tests. Use [cac's dot notation](https://github.com/cacjs/cac#dot-nested-options) 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) | | `--sequence.concurrent [concurrent]` | Make tests run in parallel (default: false) | | `--sequence.seed ` | 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 | | `--sequence.hooks ` | 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") | @@ -163,6 +163,12 @@ Boolean options can be negated with `no-` prefix. Specifying the value as `false vitest --no-api vitest --api=false ``` + +By default, Vitest only prints non-nested commands. To see all possible options, use `--expand-help` when calling `--help`: + +``` +vitest --help --expand-help +``` ::: ### changed @@ -197,5 +203,3 @@ vitest --api=false :::warning You cannot use this option with `--watch` enabled (enabled in dev by default). ::: - -[cac's dot notation]: https://github.com/cacjs/cac#dot-nested-options diff --git a/packages/vitest/src/node/cli.ts b/packages/vitest/src/node/cli.ts index 3fb2ff11474c..88096dcd89e9 100644 --- a/packages/vitest/src/node/cli.ts +++ b/packages/vitest/src/node/cli.ts @@ -112,7 +112,7 @@ cli const defaultOutput = options.body .split('\n') - .filter(line => /--\S+\./.test(line) === false) + .filter(line => /^\s+--\S+\./.test(line) === false) .join('\n') // Filter out options with dot-notation if --help is not called with a subcommand (default behavior) @@ -121,7 +121,7 @@ cli return info } - if (subcommands.length === 1 && subcommands[0] === '--expand-help') + if (subcommands.length === 1 && (subcommands[0] === '--expand-help' || subcommands[0] === '--expandHelp')) return info const subcommandMarker = '$SUB_COMMAND_MARKER$' @@ -141,7 +141,7 @@ cli const subcommand = subcommands[i] // --help --expand-help can't be called with multiple subcommands and is handled above - if (subcommand === '--expand-help') { + if (subcommand === '--expand-help' || subcommand === '--expandHelp') { addBannerWarning('--expand-help subcommand ignored because, when used with --help, it must be the only subcommand') continue }