question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Vitest/C8 coverage includes the unit test files themselves

See original GitHub issue

Describe the bug

As per the docs I have the following npm script to generate the coverage report:

"coverage": "vitest run --coverage"

However it includes the unit test files themselves which is not useful and also leads to incorrect coverage metrics. Please can this be addressed in Vite?

image image

Reproduction

Follow getting started guide and make a basic function and a unit test that imports that function. Have "coverage": "vitest run --coverage" in npm scrips and run it. Observe the reports in both the console and HTML istanbul report contain both SUT’s and the unit tests themselves.

System Info

Windows and Linux, Node 16.

Used Package Manager

npm

Validations

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

3reactions
sheremet-vacommented, Jul 8, 2022

All you need is the exclude config.

It should already be excluded. We have defaults.ts file with default coverage. We need to add spec alongside test there. PR welcome.

2reactions
seivancommented, Jul 8, 2022

Which begs the question, what happens if you do in-source testing? I love that feature, and I can’t leave it.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Coverage | Guide - Vitest
Vitest supports Native code coverage via c8 and instrumented code ... To configure it, set test.coverage options in your config file:.
Read more >
Should coverage.py present unit test code's coverage too?
The coverage report from coverage.py includes some coverage for actual unit tests code along "production" code and I think I'm doing ...
Read more >
Code coverage testing - Visual Studio (Windows)
To determine what proportion of your project's code is being tested by coded tests such as unit tests, you can use the code...
Read more >
Test coverage visualization - GitLab Docs
When submitting many files, it can take a few minutes for coverage to show on a merge request. The visualization only displays after...
Read more >
What is Unit Testing & Code Coverage and How to Use Them ...
So how exactly does Python know which unit tests are passing? The compiler will run each method in the unit test file. If...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found