Skip to content

Commit 3afe68f

Browse files
authoredFeb 9, 2024
fix(vitest): support more array cli options (#5162)
1 parent ef0440c commit 3afe68f

File tree

2 files changed

+41
-1
lines changed

2 files changed

+41
-1
lines changed
 

‎packages/vitest/src/node/cli/cli-config.ts

+3
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ export const cliOptionsConfig: VitestCLIOptions = {
140140
description: 'Specify reporters',
141141
argument: '<name>',
142142
subcommands: null, // don't support custom objects
143+
array: true,
143144
},
144145
outputFile: {
145146
argument: '<filename/-s>',
@@ -175,6 +176,7 @@ export const cliOptionsConfig: VitestCLIOptions = {
175176
extension: {
176177
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"])',
177178
argument: '<extension>',
179+
array: true,
178180
},
179181
clean: {
180182
description: 'Clean coverage results before running tests (default: true)',
@@ -191,6 +193,7 @@ export const cliOptionsConfig: VitestCLIOptions = {
191193
description: 'Coverage reporters to use. Visit https://vitest.dev/config/#coverage-reporter for more information (default: ["text", "html", "clover", "json"])',
192194
argument: '<name>',
193195
subcommands: null, // don't support custom objects
196+
array: true,
194197
},
195198
reportOnFailure: {
196199
description: 'Generate coverage report even when tests fail (default: false)',

‎test/core/test/cli-test.test.ts

+38-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ test('nested coverage options have correct types', async () => {
6464
--coverage.thresholds.branches 25
6565
`).coverage).toEqual({
6666
enabled: true,
67-
reporter: 'text',
67+
reporter: ['text'],
6868
all: true,
6969
provider: 'v8',
7070
clean: false,
@@ -119,3 +119,40 @@ test('even if coverage is boolean, don\'t fail', () => {
119119
provider: 'v8',
120120
})
121121
})
122+
123+
test('array options', () => {
124+
expect(parseArguments('--reporter json --coverage.reporter=html --coverage.extension ts')).toMatchInlineSnapshot(`
125+
{
126+
"coverage": {
127+
"extension": [
128+
"ts",
129+
],
130+
"reporter": [
131+
"html",
132+
],
133+
},
134+
"reporter": [
135+
"json",
136+
],
137+
}
138+
`)
139+
140+
expect(parseArguments('--reporter json --reporter=default --coverage.reporter=json --coverage.reporter html --coverage.extension=ts --coverage.extension=tsx')).toMatchInlineSnapshot(`
141+
{
142+
"coverage": {
143+
"extension": [
144+
"ts",
145+
"tsx",
146+
],
147+
"reporter": [
148+
"json",
149+
"html",
150+
],
151+
},
152+
"reporter": [
153+
"json",
154+
"default",
155+
],
156+
}
157+
`)
158+
})

0 commit comments

Comments
 (0)
Please sign in to comment.