Skip to content

Commit

Permalink
fix(vitest): support more array cli options (#5162)
Browse files Browse the repository at this point in the history
  • Loading branch information
hi-ogawa authored Feb 9, 2024
1 parent ef0440c commit 3afe68f
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 1 deletion.
3 changes: 3 additions & 0 deletions packages/vitest/src/node/cli/cli-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ export const cliOptionsConfig: VitestCLIOptions = {
description: 'Specify reporters',
argument: '<name>',
subcommands: null, // don't support custom objects
array: true,
},
outputFile: {
argument: '<filename/-s>',
Expand Down Expand Up @@ -175,6 +176,7 @@ export const cliOptionsConfig: VitestCLIOptions = {
extension: {
description: 'Extension to be included in coverage. May be specified more than once when using multiple extensions (default: [".js", ".cjs", ".mjs", ".ts", ".mts", ".cts", ".tsx", ".jsx", ".vue", ".svelte"])',
argument: '<extension>',
array: true,
},
clean: {
description: 'Clean coverage results before running tests (default: true)',
Expand All @@ -191,6 +193,7 @@ export const cliOptionsConfig: VitestCLIOptions = {
description: 'Coverage reporters to use. Visit https://vitest.dev/config/#coverage-reporter for more information (default: ["text", "html", "clover", "json"])',
argument: '<name>',
subcommands: null, // don't support custom objects
array: true,
},
reportOnFailure: {
description: 'Generate coverage report even when tests fail (default: false)',
Expand Down
39 changes: 38 additions & 1 deletion test/core/test/cli-test.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ test('nested coverage options have correct types', async () => {
--coverage.thresholds.branches 25
`).coverage).toEqual({
enabled: true,
reporter: 'text',
reporter: ['text'],
all: true,
provider: 'v8',
clean: false,
Expand Down Expand Up @@ -119,3 +119,40 @@ test('even if coverage is boolean, don\'t fail', () => {
provider: 'v8',
})
})

test('array options', () => {
expect(parseArguments('--reporter json --coverage.reporter=html --coverage.extension ts')).toMatchInlineSnapshot(`
{
"coverage": {
"extension": [
"ts",
],
"reporter": [
"html",
],
},
"reporter": [
"json",
],
}
`)

expect(parseArguments('--reporter json --reporter=default --coverage.reporter=json --coverage.reporter html --coverage.extension=ts --coverage.extension=tsx')).toMatchInlineSnapshot(`
{
"coverage": {
"extension": [
"ts",
"tsx",
],
"reporter": [
"json",
"html",
],
},
"reporter": [
"json",
"default",
],
}
`)
})

0 comments on commit 3afe68f

Please sign in to comment.