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

Coverage report does not include types-only TS files #6164

Closed
6 tasks done
igordanchenko opened this issue Jul 18, 2024 · 1 comment · Fixed by #6183
Closed
6 tasks done

Coverage report does not include types-only TS files #6164

igordanchenko opened this issue Jul 18, 2024 · 1 comment · Fixed by #6183
Labels
feat: coverage Issues and PRs related to the coverage feature p2-edge-case Bug, but has workaround or limited in scope (priority)

Comments

@igordanchenko
Copy link

Describe the bug

Discussed in #6158

In some cases, the coverage report does not include types-only .ts files. One particular case is when the tested file uses a types-only .ts file, but the types are not exported from the package barrel file. The file is not included in the report even with all: true in coverage settings.

Reproduction

  1. Open https://stackblitz.com/edit/vitest-v2-ts-coverage-bug-5s95pp?file=test%2Ffoo.test.ts
  2. Download the sandbox to run the test locally
  3. npm install
  4. npm run test:run

Observe coverage report:

 % Coverage report from v8
----------|---------|----------|---------|---------|-------------------
File      | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s 
----------|---------|----------|---------|---------|-------------------
All files |     100 |      100 |     100 |     100 |                   
 foo.ts   |     100 |      100 |     100 |     100 |                   
 index.ts |     100 |      100 |     100 |     100 |                   
----------|---------|----------|---------|---------|-------------------

System Info

System:
    OS: macOS 14.5
    CPU: (12) x64 Intel(R) Core(TM) i7-8850H CPU @ 2.60GHz
    Memory: 578.00 MB / 32.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 20.15.1 - ~/.nvm/versions/node/v20.15.1/bin/node
    npm: 10.7.0 - ~/.nvm/versions/node/v20.15.1/bin/npm
  Browsers:
    Chrome: 126.0.6478.182
    Safari: 17.5
  npmPackages:
    @vitest/coverage-v8: latest => 2.0.3 
    @vitest/ui: latest => 2.0.3 
    vite: latest => 5.3.4 
    vitest: latest => 2.0.3

Used Package Manager

npm

Validations

@AriPerkkio AriPerkkio added feat: coverage Issues and PRs related to the coverage feature p2-edge-case Bug, but has workaround or limited in scope (priority) and removed pending triage labels Jul 19, 2024
@AriPerkkio
Copy link
Member

AriPerkkio commented Jul 19, 2024

To summarize the bug here:

  • Empty files (no runtime code, e.g. type-only) are shown in report when they are imported by test files. ✅
  • Empty files are not shown in report when they are not imported by any test, picked by coverage.all

This behavior is inconsistent. During #5457 the changes of #5328 should have been reverted. The #5457 implements type-only file detection in proper way while #5328 was mostly a work-around since good solution was not available back then.

This line needs to be removed and we need to make sure that the type-only files are shown properly in coverage report when they are picked by coverage.all. These files should not be shown as uncovered like they used to before previous fixes.

// Ignore empty files, e.g. files that contain only typescript types and no runtime code
if (source && stripLiteral(source).trim() === '') {
return null
}

@github-actions github-actions bot locked and limited conversation to collaborators Aug 6, 2024
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 p2-edge-case Bug, but has workaround or limited in scope (priority)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants