Navigation Menu

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

Vitest/C8 coverage includes the unit test files themselves #1612

Closed
6 tasks done
lloydjatkinson opened this issue Jul 7, 2022 · 5 comments
Closed
6 tasks done

Vitest/C8 coverage includes the unit test files themselves #1612

lloydjatkinson opened this issue Jul 7, 2022 · 5 comments
Labels
feat: coverage Issues and PRs related to the coverage feature

Comments

@lloydjatkinson
Copy link

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

@sheremet-va sheremet-va added bug feat: coverage Issues and PRs related to the coverage feature labels Jul 8, 2022
@pandyarudra
Copy link
Contributor

pandyarudra commented Jul 8, 2022

@lloydjatkinson Hey Lloyd, please try excluding the spec files in the coverage config options as follows:

// vite.config.js
export defineConfig({
  test: {
    coverage: {
      reporter: ['lcov', "html"],
      exclude: [
        '**/*.spec.ts',
      ],
    }
  }
});

All you need is the exclude config.

@sheremet-va
Copy link
Member

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.

@seivan
Copy link

seivan commented 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.

@pandyarudra
Copy link
Contributor

pandyarudra commented Jul 11, 2022

@sheremet-va PR is here: #1627

@antfu antfu closed this as completed in 21170ed Jul 14, 2022
@OmgImAlexis
Copy link

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

If this isn't fixed by #1627 I'd suggest making a new issue.

@github-actions github-actions bot locked and limited conversation to collaborators Jun 16, 2023
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
Projects
None yet
Development

No branches or pull requests

5 participants