From 894f155af687f54447eb78066bbcc71cc0d5a695 Mon Sep 17 00:00:00 2001 From: mysteryven Date: Sun, 1 Jan 2023 22:37:50 +0800 Subject: [PATCH] fix(cli): allow overrides reporter via cli option (#2573) Co-authored-by: Vladimir fix https://github.com/vitest-dev/vitest/issues/2537 --- packages/vitest/src/node/config.ts | 8 +++----- test/reporters/tests/custom-reporter.spec.ts | 6 ++++++ 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/packages/vitest/src/node/config.ts b/packages/vitest/src/node/config.ts index cc57f4153a37..882299efd112 100644 --- a/packages/vitest/src/node/config.ts +++ b/packages/vitest/src/node/config.ts @@ -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) diff --git a/test/reporters/tests/custom-reporter.spec.ts b/test/reporters/tests/custom-reporter.spec.ts index 9524bf911726..e3598aa361b5 100644 --- a/test/reporters/tests/custom-reporter.spec.ts +++ b/test/reporters/tests/custom-reporter.spec.ts @@ -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) })