vitest icon indicating copy to clipboard operation
vitest copied to clipboard

`coverage.reporter` with a single value causes error while running tests without coverage (v2.0.x)

Open ildede opened this issue 2 years ago • 2 comments

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

Screenshot 2024-08-01 at 18 22 23

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

ildede avatar Aug 01 '24 16:08 ildede

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.

AriPerkkio avatar Aug 01 '24 18:08 AriPerkkio

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'], 
}

osmestad avatar Aug 13 '24 15:08 osmestad