Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(cli): allow overrides reporter via cli option #2573

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 3 additions & 5 deletions packages/vitest/src/node/config.ts
Expand Up @@ -198,11 +198,9 @@ export function resolveConfig(
resolved.related = toArray(options.related).map(file => resolve(resolved.root, file))

if (mode !== 'benchmark') {
resolved.reporters = Array.from(new Set([
...toArray(resolved.reporters),
// @ts-expect-error from CLI
...toArray(resolved.reporter),
])).filter(Boolean)
// @ts-expect-error from CLI
const reporters = resolved.reporter ?? resolved.reporters
resolved.reporters = Array.from(new Set(toArray(reporters))).filter(Boolean)
}

if (!resolved.reporters.length)
Expand Down
6 changes: 6 additions & 0 deletions test/reporters/tests/custom-reporter.spec.ts
Expand Up @@ -71,4 +71,10 @@ describe.concurrent('custom reporters', () => {
const stdout = await runWithRetry('--config', 'without-custom-reporter.vitest.config.ts', '--reporter', customJSReporterPath)
expect(stdout).includes('hello from custom reporter')
}, TIMEOUT)

test('overrides reporters by given a CLI argument --reporter works', async () => {
const stdout = await runWithRetry('--config', 'deps-reporter.vitest.config.ts', '--reporter', customJSReporterPath)
expect(stdout).not.includes('hello from package reporter')
expect(stdout).includes('hello from custom reporter')
}, TIMEOUT)
})