Skip to content

🐛 Vitest plugin: @vitest/coverage-v8 reported as unused with vitest --coverage #1799

Description

@WooWan

Prerequisites

Reproduction url

https://github.com/WooWan/knip-vitest-coverage

Reproduction access

  • I've made sure the reproduction is publicly accessible

Description of the issue

@vitest/coverage-v8 is incorrectly reported as unused when tests run via
vitest --coverage.

The bare --coverage flag enables coverage with the default provider (v8), so
the package is actually used. But the Vitest plugin only registers the coverage
dependency when a provider is passed as an object (--coverage.provider=v8):

if (typeof parsed['coverage'] === 'object' && parsed['coverage'].provider) {
    inputs.push(toDependency(`@vitest/coverage-${parsed['coverage'].provider}`));
}

For a boolean --coverage, parsed.coverage is true, so it is skipped → false positive.

Expected

@vitest/coverage-v8 is recognized as used (default v8 provider).

Actual

Unused devDependencies (1)
@vitest/coverage-v8  package.json

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions