diff --git a/packages/vitest/src/node/config/serializeConfig.ts b/packages/vitest/src/node/config/serializeConfig.ts index 15d1a06103ea..005ccbfd8664 100644 --- a/packages/vitest/src/node/config/serializeConfig.ts +++ b/packages/vitest/src/node/config/serializeConfig.ts @@ -1,4 +1,5 @@ import type { ResolvedConfig as ViteConfig } from 'vite' +import { toArray } from '@vitest/utils' import type { ResolvedConfig, SerializedConfig } from '../types/config' export function serializeConfig( @@ -46,11 +47,12 @@ export function serializeConfig( snapshotEnvironment: config.snapshotEnvironment, passWithNoTests: config.passWithNoTests, coverage: ((coverage) => { - const htmlReporter = coverage.reporter.find(([reporterName]) => reporterName === 'html') as [ + const htmlReporter = toArray(coverage.reporter).find(([reporterName]) => reporterName === 'html') as [ 'html', { subdir?: string }, ] | undefined const subdir = htmlReporter && htmlReporter[1]?.subdir + return { reportsDirectory: coverage.reportsDirectory, provider: coverage.provider, diff --git a/test/coverage-test/test/reporters.test.ts b/test/coverage-test/test/reporters.test.ts index 518cd2c2b4cd..8b1deeb0692f 100644 --- a/test/coverage-test/test/reporters.test.ts +++ b/test/coverage-test/test/reporters.test.ts @@ -65,3 +65,22 @@ test('all reporter variants mixed', async () => { expect(files).toContain('lcov-report') expect(files).toContain('custom-text-report') }) + +test('reporter as string while coverage disabled', async () => { + await runVitest({ + include, + coverage: { + reporter: 'json', + enabled: false, + }, + }) +}) + +test('reporter as list of strings while coverage disabled', async () => { + await runVitest({ + include, + coverage: { + reporter: ['json', 'lcov'], + }, + }) +})