vitest-dev / vitest

Next generation testing framework powered by Vite.
https://vitest.dev
MIT License
12.67k stars 1.13k forks source link

Exclude all '*.config.*' files from coverage by default #6508

Open Thomasan1999 opened 4 days ago

Thomasan1999 commented 4 days ago

Clear and concise description of the problem

By default only a list of config files are excluded from coverage: https://github.com/vitest-dev/vitest/blob/5932a7f988fdb269ac1ae704172bc7cfbf6ed721/packages/vitest/src/defaults.ts#L18

This seems like an extra work to list all libraries which use configuration files and you still might miss some. In my case, the default config did not include postcss.config.js and tailwind.config.ts files.

Suggested solution

I would change the mentioned line to this:

'**/*.config.*'

It would be easier to maintain and I don't think that it happens usually that someone uses .config. in a file name for a file they want to test.

Alternative

Add tailwind and postcss to the list, this would resolve my use-case but not the problem in general. The code would look like this:

'**/{karma,rollup,webpack,vite,vitest,jest,ava,babel,nyc,cypress,tsup,build,eslint,prettier,postcss,tailwind}.config.*'

Additional context

No response

Validations

AriPerkkio commented 3 days ago

By default only a list of config files are excluded from coverage: https://github.com/vitest-dev/vitest/blob/5932a7f988fdb269ac1ae704172bc7cfbf6ed721/packages/vitest/src/defaults.ts#L18

That's test file exclusions. I wonder why that's even needed - doesn't make sense to have test file extensions in configuration files. 🤔

This seems like an extra work to list all libraries which use configuration files and you still might miss some.

Yep I agree, but adding **/*.config.* could cause unexpected results. I don't think we should add pattern that's this wide.

Instead of defining your postcss.config.js and tailwind.config.ts files in coverage.exclusion, I would rather recommend to specify coverage.include so that your configuration files wouldn't match it, e.g. coverage.include: 'src'.