Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
6 tasks done
ildede opened this issue Aug 1, 2024 · 2 comments · Fixed by #6267
Closed
6 tasks done
Labels
feat: coverage Issues and PRs related to the coverage feature p4-important Violate documented behavior or significantly improves performance (priority)

Comments

@ildede
Copy link

ildede commented Aug 1, 2024

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

@AriPerkkio
Copy link
Member

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.

test('reporter as string', async () => {
await runVitest({
include,
coverage: {
reporter: 'json',
all: false,
},
})
const files = readdirSync('./coverage')
expect(files).toContain('coverage-final.json')
})

This might have been caused by refactoring done during #6205.

@AriPerkkio AriPerkkio added feat: coverage Issues and PRs related to the coverage feature p4-important Violate documented behavior or significantly improves performance (priority) and removed pending triage labels Aug 1, 2024
@osmestad
Copy link

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

@github-actions github-actions bot locked and limited conversation to collaborators Aug 28, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
feat: coverage Issues and PRs related to the coverage feature p4-important Violate documented behavior or significantly improves performance (priority)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants