Skip to content

Simplify coverage.exclude patterns, remove coverage.all #6956

@AriPerkkio

Description

@AriPerkkio

Clear and concise description of the problem

Setting good defaults for coverage.exclude is difficult. The coverage.include is even more difficult. By default coverage.include is ['*'] as we don't know where users' source code are.

Currently we have listed complex coverage.exclude pattern that includes all kinds of framework and tool specific patterns that aren't really Vitest related. We constantly get new requests to add there more tool specific files, like MSW, postcss, tailwind, etc. This is not maintainable in long run.

What (most) users don't realize is that they shouldn't be using coverage.exclude in the first place. Instead of defining every single *.config.* file of your project's root, you should be defining coverage.include.

├── vitest.config.js
├── tailwind.config.js
├── postcss.config.js
|
├── public
|  └── mockServiceWorker.js
|
├── src
|  ├── math.js
|  └── utils
|     └── geometry.js
└── test
   └── math.test.js

Here users shouldn't do coverage.exclude: ['tailwind.config.js', 'postcss.config.js, 'public/mockServiceWorker.js']. They should do just coverage.include: ['src']

Suggested solution

#6956 (comment)

We could do similar option as Jest has: https://jestjs.io/docs/configuration#collectcoveragefrom-array

Their option forces users to define coverage.include, as by default they have coverage.all: false. By default Jest shows only files that were imported by test files. Users have to define uncovered files in collectCoverageFrom.

💡 We could remove coverage.all and by default only show files that were imported by tests. Then if coverage.includes is defined, show all covered+uncovered files that match those.

Additional context

No response

Validations

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    Status

    Approved

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions