vuejs / vue-jest

Jest Vue transformer
MIT License
748 stars 156 forks source link

Coverage showing Unknown% #487

Closed derHodrig closed 2 years ago

derHodrig commented 2 years ago

First of all, I'm new to this testing aspect but I really want to learn it. I, unfortunately, faced an Issue with the coverage. It does simply not work. The test and code around should be okay. Just to mention, it's a nuxt + typescript setup. But typescript is not actively, because I try to learn this in that repo too. I tried the app, should work fine, tests are running successful, linter also works fine. So I can assure you, it's not the code itself.

Repo

https://gitlab.com/skoenfeld/nuxt-monorepo/-/tree/coverage

used version

"jest": "^27.4.4",
"ts-jest": "^27.1.1",
"vue-jest": "^3.0.4"

pls, use the coverage branch.


install the dependencies and hit jest --coverage

Output should be

 PASS  test/JestTest.spec.js                                                                                                                                                                                                                                                                                            
  JestTest
    √ correct initial values (2 ms)                                                                                                                                                                                                                                                                                     
    √ correct mounted (36 ms)                                                                                                                                                                                                                                                                                           
    √ testing setWord (9 ms)                                                                                                                                                                                                                                                                                            
    √ testing button (9 ms)                                                                                                                                                                                                                                                                                             

=============================== Coverage summary ===============================                                                                                                                                                                                                                                        
Statements   : Unknown% ( 0/0 )
Branches     : Unknown% ( 0/0 )
Functions    : Unknown% ( 0/0 )
Lines        : Unknown% ( 0/0 )
================================================================================
Test Suites: 1 passed, 1 total
Tests:       4 passed, 4 total
Snapshots:   0 total
Time:        6.172 s
Ran all test suites.

Problem

I am getting into testing with vue / nuxt. After writing the first test I tried to show the coverage. The coverage is Unknown for all categories. The HTML in ./coverage/Icov-report shows also an empty table.

Tries

I tried already to lower the jest and vue-jest to v26 as I saw this on other issues. Not working at all. The configuration seems also fine in my opinion. So this might be a bug?

meufel commented 2 years ago

Hey @derHodrig,

I was able to reproduce your issue & didn't find a solution for the version of vue-jest you use. Since v3.0.4 is outdated I removed the vue-jest dependency & added "@vue/vue2-jest": "^27.0.0" to your project. After that the coverage was collected correctly.

Note that when replacing the dependency you have to update the vue transformer inside your jest.config.js to

'.*\\.(vue)$': '@vue/vue2-jest',
derHodrig commented 2 years ago

Thank you @meufel!