diff --git a/packages/vitest/src/node/config/resolveConfig.ts b/packages/vitest/src/node/config/resolveConfig.ts index c9745317388d..64318e82771b 100644 --- a/packages/vitest/src/node/config/resolveConfig.ts +++ b/packages/vitest/src/node/config/resolveConfig.ts @@ -229,6 +229,8 @@ export function resolveConfig( ) } + resolved.coverage.reporter = toArray(resolved.coverage.reporter) + if (resolved.coverage.enabled && resolved.coverage.reportsDirectory) { const reportsDirectory = resolve( resolved.root, diff --git a/test/coverage-test/test/reporters.test.ts b/test/coverage-test/test/reporters.test.ts index 518cd2c2b4cd..e93a3cd2f098 100644 --- a/test/coverage-test/test/reporters.test.ts +++ b/test/coverage-test/test/reporters.test.ts @@ -1,4 +1,5 @@ -import { readdirSync } from 'node:fs' +import { existsSync, readdirSync } from 'node:fs' +import { rm } from 'node:fs/promises' import { expect } from 'vitest' import { runVitest, test } from '../utils' @@ -17,6 +18,23 @@ test('reporter as string', async () => { expect(files).toContain('coverage-final.json') }) +test('reporter as string when coverage is disabled', async () => { + if (existsSync('./coverage')) { + await rm('./coverage', { recursive: true, force: true }) + } + + await runVitest({ + include, + coverage: { + enabled: false, + reporter: 'json', + all: false, + }, + }) + + expect(existsSync('./coverage')).toBe(false) +}) + test('reporter as list of strings', async () => { await runVitest({ include,