Skip to content

Commit

Permalink
fix(coverage): resolve string reporters correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
AriPerkkio committed Aug 1, 2024
1 parent a7be50d commit b1ad1e5
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
4 changes: 3 additions & 1 deletion packages/vitest/src/node/config/serializeConfig.ts
Original file line number Diff line number Diff line change
@@ -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(
Expand Down Expand Up @@ -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,
Expand Down
19 changes: 19 additions & 0 deletions test/coverage-test/test/reporters.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'],
},
})
})

0 comments on commit b1ad1e5

Please sign in to comment.