Skip to content

Commit 894f155

Browse files
authoredJan 1, 2023
fix(cli): allow overrides reporter via cli option (#2573)
Co-authored-by: Vladimir <sleuths.slews0s@icloud.com> fix #2537
1 parent 8d64790 commit 894f155

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed
 

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

+3-5
Original file line numberDiff line numberDiff line change
@@ -198,11 +198,9 @@ export function resolveConfig(
198198
resolved.related = toArray(options.related).map(file => resolve(resolved.root, file))
199199

200200
if (mode !== 'benchmark') {
201-
resolved.reporters = Array.from(new Set([
202-
...toArray(resolved.reporters),
203-
// @ts-expect-error from CLI
204-
...toArray(resolved.reporter),
205-
])).filter(Boolean)
201+
// @ts-expect-error from CLI
202+
const reporters = resolved.reporter ?? resolved.reporters
203+
resolved.reporters = Array.from(new Set(toArray(reporters))).filter(Boolean)
206204
}
207205

208206
if (!resolved.reporters.length)

‎test/reporters/tests/custom-reporter.spec.ts

+6
Original file line numberDiff line numberDiff line change
@@ -71,4 +71,10 @@ describe.concurrent('custom reporters', () => {
7171
const stdout = await runWithRetry('--config', 'without-custom-reporter.vitest.config.ts', '--reporter', customJSReporterPath)
7272
expect(stdout).includes('hello from custom reporter')
7373
}, TIMEOUT)
74+
75+
test('overrides reporters by given a CLI argument --reporter works', async () => {
76+
const stdout = await runWithRetry('--config', 'deps-reporter.vitest.config.ts', '--reporter', customJSReporterPath)
77+
expect(stdout).not.includes('hello from package reporter')
78+
expect(stdout).includes('hello from custom reporter')
79+
}, TIMEOUT)
7480
})

0 commit comments

Comments
 (0)
Please sign in to comment.