Skip to content

Commit ef6ef54

Browse files
authored
fix(cli): add built-in reporters list to --help output (#7955)
1 parent 27ea604 commit ef6ef54

File tree

4 files changed

+23
-3
lines changed

4 files changed

+23
-3
lines changed

docs/guide/cli-generated.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,9 @@ Hide logs for skipped tests
8989
- **CLI:** `--reporter <name>`
9090
- **Config:** [reporters](/config/#reporters)
9191

92-
Specify reporters
92+
Specify which reporter(s) to use. Available values:
93+
94+
`default`, `basic`, `blob`, `verbose`, `dot`, `json`, `tap`, `tap-flat`, `junit`, `hanging-process`, `github-actions`.
9395

9496
### outputFile
9597

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import type {
77
} from '../types/pool-options'
88
import type { CliOptions } from './cli-api'
99
import { defaultBrowserPort, defaultPort } from '../../constants'
10+
import { ReportersMap } from '../reporters'
1011

1112
type NestedOption<T, V = Extract<T, Record<string, any>>> = V extends
1213
| never
@@ -160,7 +161,7 @@ export const cliOptionsConfig: VitestCLIOptions = {
160161
},
161162
reporters: {
162163
alias: 'reporter',
163-
description: 'Specify reporters',
164+
description: `Specify reporters (${Object.keys(ReportersMap).join(', ')})`,
164165
argument: '<name>',
165166
subcommands: null, // don't support custom objects
166167
array: true,

packages/vitest/src/node/reporters/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ export {
3131
}
3232
export type { BaseReporter, Reporter, TestRunEndReason }
3333

34+
export type { BenchmarkBuiltinReporters } from './benchmark'
3435
export {
35-
BenchmarkBuiltinReporters,
3636
BenchmarkReporter,
3737
BenchmarkReportsMap,
3838
VerboseBenchmarkReporter,

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { resolveConfig as viteResolveConfig } from 'vite'
22
import { expect, test } from 'vitest'
3+
import { ReportersMap } from 'vitest/reporters'
34
import { createCLI, parseCLI } from '../../../packages/vitest/src/node/cli/cac.js'
45
import { resolveConfig } from '../../../packages/vitest/src/node/config/resolveConfig.js'
56

@@ -465,3 +466,19 @@ test('public parseCLI works correctly', () => {
465466
},
466467
})
467468
})
469+
470+
test('should include builtin reporters list', () => {
471+
let helpText = ''
472+
vitestCli.help((sections) => {
473+
for (const section of sections) {
474+
helpText += section.body
475+
}
476+
})
477+
vitestCli.parse(['node', '/index.js', '--help'], { run: false })
478+
const match = helpText.match(/--reporter[^(]*\(([^)]+)\)/)
479+
expect(match).not.toBeNull()
480+
481+
const listed = match![1].split(',').map(s => s.trim()).filter(Boolean)
482+
const expected = Object.keys(ReportersMap)
483+
expect(new Set(listed)).toEqual(new Set(expected))
484+
})

0 commit comments

Comments
 (0)