Skip to content

Commit

Permalink
fix: don't panic when coverage.reporter is a string
Browse files Browse the repository at this point in the history
  • Loading branch information
sheremet-va committed Aug 2, 2024
1 parent a7be50d commit 137c5d8
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
2 changes: 2 additions & 0 deletions packages/vitest/src/node/config/resolveConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
20 changes: 19 additions & 1 deletion test/coverage-test/test/reporters.test.ts
Original file line number Diff line number Diff line change
@@ -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'

Expand All @@ -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,
Expand Down

0 comments on commit 137c5d8

Please sign in to comment.