`coverage.reporter` with a single value causes error while running tests without coverage (v2.0.x)
Describe the bug
The documentation of coverage.reporter on both V2 and V1 say that we can use string as a valid value.
So a minimal vitest.config like this, should work
export default defineConfig({
test: {
coverage: {
reporter: 'json',
},
},
})
This works fine with 1.6, but not in 2.0.x.
Error printed while executing pnpm run test. The error is not present while running pnpm run test --coverage
Reproduction
A minimal reproduction case in this repository ildede/vitest-single-reporter-error
System Info
System:
OS: macOS 14.5
CPU: (8) arm64 Apple M1 Pro
Memory: 116.05 MB / 32.00 GB
Shell: 5.9 - /bin/zsh
Binaries:
Node: 20.9.0 - ~/Library/pnpm/node
npm: 10.1.0 - ~/Library/pnpm/npm
pnpm: 9.5.0 - ~/Library/pnpm/pnpm
Browsers:
Chrome: 127.0.6533.88
Safari: 17.5
npmPackages:
vitest: ^2.0.5 => 2.0.5
Used Package Manager
pnpm
Validations
- [X] Follow our Code of Conduct
- [X] Read the Contributing Guidelines.
- [X] Read the docs.
- [X] Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
- [X] Check that this is a concrete bug. For Q&A open a GitHub Discussion or join our Discord Chat Server.
- [X] The provided reproduction is a minimal reproducible example of the bug.
We have test case for all reporter option types but all those run with coverage: { enabled: true }. This error case seems to come up only when coverage is disabled.
https://github.com/vitest-dev/vitest/blob/a7be50dbceea31611403542caca7ebf44e4e014a/test/coverage-test/test/reporters.test.ts#L7-L18
This might have been caused by refactoring done during https://github.com/vitest-dev/vitest/pull/6205.
If anyone is wondering how to work around this (like me) until 2.1.x gets released, wrapping the reporter string in an array should do the trick. So from:
coverage: {
reporter: 'json',
}
to:
coverage: {
reporter: ['json'],
}