vitest: Coverage report does not include .vue files

Describe the bug

The coverage seems to only cover .vue files that are currently tested, giving wrong coverage reports since files without tests are not covered. Possible related issues/PRs https://github.com/vitest-dev/vitest/issues/559 https://github.com/vitest-dev/vitest/pull/518

Reproduction

https://github.com/kouts/vitest-coverage

running npm run coverage gives us the following image while it should include the uncovered src/Hello.vue component

System Info

System:
    OS: macOS 11.6.2
    CPU: (12) x64 Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz
    Memory: 192.20 MB / 32.00 GB
    Shell: 5.8 - /bin/zsh
  Binaries:
    Node: 16.13.2 - ~/.nvm/versions/node/v16.13.2/bin/node
    Yarn: 1.22.17 - ~/.nvm/versions/node/v16.13.2/bin/yarn
    npm: 8.1.2 - ~/.nvm/versions/node/v16.13.2/bin/npm
  Browsers:
    Chrome: 98.0.4758.80
    Firefox: 96.0.2
    Firefox Developer Edition: 97.0
    Safari: 15.2
    Safari Technology Preview: 15.4
  npmPackages:
    @vitejs/plugin-vue: ^2.1.0 => 2.1.0 
    vitest: latest => 0.2.7

Used Package Manager

npm

Validations

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Reactions: 1
  • Comments: 21 (7 by maintainers)

Commits related to this issue

Most upvoted comments

https://github.com/bcoe/c8#checking-for-full-source-coverage-using---all

c8 by default only collects coverage for files that have been tested. You can pass all: true option to Vitest coverage config to report coverage for all files. You will probably need to adjust coverage.include option too, to not receive coverage for files that you don’t want.

export default defineConfig({
  test: {
    coverage: {
      all: true
    }
  },
})

@kouts is this issue still valid? The reproduction case seems to work as expected:

 ✓ test/async.test.ts (1)

 Test Files  1 passed (1)
      Tests  1 passed (1)
   Start at  14:30:29
   Duration  1.25s (transform 719ms, setup 0ms, collect 146ms, tests 9ms)

 % Coverage report from c8
------------------|---------|----------|---------|---------|-------------------
File              | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s 
------------------|---------|----------|---------|---------|-------------------
All files         |    57.5 |    66.66 |       0 |    57.5 |                   
 AsyncComp.vue    |     100 |      100 |     100 |     100 |                   
 AsyncWrapper.vue |     100 |      100 |     100 |     100 |                   
 Hello.vue        |       0 |        0 |       0 |       0 | 1-17              
------------------|---------|----------|---------|---------|-------------------

For me, the coverage of .vue files is also inaccurate. For some files it shows 100%,

@mahmost your reproduction case seems to work fine with changes of on-going PR #2591. It’s having the same issue as #2539.

------------------------|---------|----------|---------|---------|----------------------
File                    | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s    
------------------------|---------|----------|---------|---------|----------------------
All files               |   29.29 |     6.66 |       0 |   29.29 |                      
 src                    |       0 |        0 |       0 |       0 |                      
  App.vue               |       0 |        0 |       0 |       0 | 1-81                 
  main.js               |       0 |        0 |       0 |       0 | 1-4                  
 src/components         |   41.96 |     12.5 |       0 |   41.96 |                      
  HelloWorld.vue        |   94.81 |    16.66 |       0 |   94.81 | 20,38,43-44,56-57,59 
  TheWelcome.vue        |       0 |        0 |       0 |       0 | 1-84                 
  WelcomeItem.vue       |       0 |        0 |       0 |       0 | 1-86                 
 src/components/icons   |       0 |        0 |       0 |       0 |                      
  IconCommunity.vue     |       0 |        0 |       0 |       0 | 1-7                  
  IconDocumentation.vue |       0 |        0 |       0 |       0 | 1-7                  
  IconEcosystem.vue     |       0 |        0 |       0 |       0 | 1-7                  
  IconSupport.vue       |       0 |        0 |       0 |       0 | 1-7                  
  IconTooling.vue       |       0 |        0 |       0 |       0 | 1-19                 
------------------------|---------|----------|---------|---------|----------------------

Maybe it’s time to close this issue and open new ones if there are still existing problems.

I’m using vitest@0.12.6 and have c8@7.11.3 installed. It seems now that my coverage does show all of the .vue files that I don’t have tests for in the coverage report, but almost all are showing 100%. Weirdly there are a couple files that are still at zero.

We made some major App changes yesterday so maybe that’s affecting it, since I’m pretty sure yesterday we were seeing the files but they were listed at 0% covered. But… seems weird that today they would go to 100%, unless coverage just isn’t being calculated correctly in .vue files?

I’m kind of lost here, so I’m curious what others are seeing.

C8 already merged the PR that will make this possible.

Hi @AriPerkkio, unfortunately, i am still experiencing this issue and have opened a new issue here. i have tried using both c8 and istanbul and they both yield the same result.

Peeky had custom code before but it was too much work to implement istanbul and I just switched to c8 for the coverage report.