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 generated uncovered lines for import and export rule #3087

Closed
6 tasks done
schirrel opened this issue Mar 27, 2023 · 7 comments
Closed
6 tasks done

Coverage generated uncovered lines for import and export rule #3087

schirrel opened this issue Mar 27, 2023 · 7 comments
Labels
feat: coverage Issues and PRs related to the coverage feature

Comments

@schirrel
Copy link

schirrel commented Mar 27, 2023

Describe the bug

Hi i am having trouxe with generating coverage using vitest, it shows that import and export lines ar uncovered.
I follow all the docs and all the tutorials i found that explained why it happens, but no success.

I am also having proble with vue SFC files that show no coverage for <template> and <style> also:
Captura de Tela 2023-03-27 às 13 31 03
Captura de Tela 2023-03-27 às 13 31 16

Even add a sample defaault spec for .vue files, it not cover 100% and show missing coverage for html things like closing </div>??
Captura de Tela 2023-03-27 às 13 58 23

Other vue files (helloword.vue) points no covered for import line, look https://sonarcloud.io/code?id=vue-vitest-ts&selected=vue-vitest-ts%3Asrc%2Fcomponents%2FHelloWorld.vue
Captura de Tela 2023-03-27 às 13 59 14

Reproduction

Repository https://github.com/schirrel/vue-vitest-ts-coverage-problems
Sonar Cloude project analysis https://sonarcloud.io/code?id=vue-vitest-ts

Now can be seen the export file being take in consideration https://sonarcloud.io/code?id=vue-vitest-ts&selected=vue-vitest-ts%3Asrc%2Fhelpers%2Findex.ts

System Info

System:
    OS: macOS 13.1
    CPU: (8) arm64 Apple M1
    Memory: 1.19 GB / 16.00 GB
    Shell: 5.8.1 - /bin/zsh
  Binaries:
    Node: 16.17.1 - ~/.nvm/versions/node/v16.17.1/bin/node
    Yarn: 1.22.19 - ~/.yarn/bin/yarn
    npm: 8.15.0 - ~/.nvm/versions/node/v16.17.1/bin/npm
  Browsers:
    Chrome: 111.0.5563.64
    Firefox: 111.0.1
    Safari: 16.2
  npmPackages:
    @vitest/coverage-c8: ^0.29.2 => 0.29.2 
    vitest: ^0.29.2 => 0.29.2

Used Package Manager

yarn

Validations

@sheremet-va sheremet-va added the feat: coverage Issues and PRs related to the coverage feature label Mar 27, 2023
@AriPerkkio
Copy link
Member

AriPerkkio commented Mar 28, 2023

@schirrel does the default branch in a5fa05bca49a3d14679335babdf593511b4dcf98 reproduce this?

In the HTML and lcov reports the lines of src/App.vue are covered. There are no uncovered import statements.

image

// coverage/lcov.info, used by Sonar
SF:src/App.vue
DA:1,1
DA:2,1
DA:3,1
DA:4,1
DA:5,1
DA:6,1
DA:7,1
DA:8,1
DA:9,1
DA:10,1
DA:11,1
DA:12,1
DA:13,1
DA:14,1
DA:15,1
DA:16,1
DA:17,1
DA:18,1
DA:19,1
DA:20,1
DA:21,1
DA:22,1
DA:23,1
DA:24,1

Could you write a step-by-step instructions how to reproduce this issue?

@schirrel
Copy link
Author

@AriPerkkio yes it does.
between the two images i've add:

Even add a sample defaault spec for .vue files, it not cover 100% and show missing coverage for html things like closing ??

So in fact i add a test and imports are covered, but other things dont like the closing of a div.

Also you can take a look at the HelloWord.vue (here on sonar) were the vue import is show as uncovered.

The lvoc for HelloWorld.vue):

SF:src/components/HelloWorld.vue
FNF:0
FNH:0
DA:1,1
DA:2,1
DA:3,1
DA:4,1
DA:5,1
DA:6,1
DA:7,1
DA:8,1
DA:9,1
DA:10,1
DA:11,1
DA:12,1
DA:13,1
DA:14,1
DA:15,1
DA:16,1
DA:17,1
DA:18,1
DA:19,1
DA:20,1
DA:21,1
DA:22,1
DA:23,1
DA:24,1
DA:25,1
DA:26,1
DA:27,1
DA:28,1
DA:29,1
DA:30,1
DA:31,1
DA:32,1
DA:33,1
DA:34,1
DA:35,1
DA:36,1
DA:37,1
DA:38,1
DA:39,1
DA:40,1
DA:41,1
DA:42,1
DA:43,1
DA:44,1
DA:45,1
DA:46,1
DA:47,1
DA:48,1
DA:49,1
DA:50,1
DA:51,1
DA:52,1
DA:53,1
DA:54,1
DA:55,1
DA:56,1
DA:57,1
DA:58,1
DA:59,1
DA:60,1
DA:61,1
DA:62,1
DA:63,1
DA:64,1
DA:65,1
DA:66,1
DA:67,1
DA:68,1
DA:69,1
DA:70,1
DA:71,1
DA:72,1
DA:73,1
DA:74,1
DA:75,1
DA:76,1
DA:77,1
DA:78,1
DA:79,1
DA:80,1
DA:81,1
DA:82,1
DA:83,1
DA:84,1
DA:85,1
DA:86,1
DA:87,1
DA:88,1
DA:89,1
DA:90,1
DA:91,1
DA:92,1
DA:93,1
DA:94,1
DA:95,1
DA:96,1
DA:97,1
DA:98,1
DA:99,1
DA:100,1
DA:101,1
DA:102,1
DA:103,1
DA:104,1
DA:105,1
DA:106,0
DA:107,1
DA:108,1
DA:109,1
DA:110,1
DA:111,1
DA:112,1
DA:113,1
DA:114,1
DA:115,1
DA:116,1
DA:117,1
DA:118,1
DA:119,1
DA:120,1
DA:121,1
DA:122,1
DA:123,1
DA:124,1
DA:125,1
DA:126,1
DA:127,1
DA:128,1
DA:129,1
DA:130,1
DA:131,1
DA:132,1
DA:133,1
DA:134,1
DA:135,1
DA:136,1
LF:136
LH:135
BRDA:106,0,0,0
BRF:1
BRH:0
end_of_record
TN:

Also you can look at src/main.ts that shows the import as uncovered https://sonarcloud.io/code?id=vue-vitest-ts&selected=vue-vitest-ts%3Asrc%2Fmain.ts

The steps are only:

  • fork
  • install
  • yarn test:unit
  • and the i send the coverage report to sonar

@AriPerkkio
Copy link
Member

Also you can look at src/main.ts that shows the import as uncovered https://sonarcloud.io/code?id=vue-vitest-ts&selected=vue-vitest-ts%3Asrc%2Fmain.ts

None of the tests load src/main.ts so it is included by the all: true option. The c8 will then mark all lines as uncovered as the whole file was not loaded. This is just how c8 / V8 coverage works. The @vitest/coverage-istanbul does not have this issue.

I can reproduce the src/components/HelloWorld.vue issue now and see the uncovered import statement there. Debugging the root cause of this is not easy task. It would help if you could try and update all your dependencies to latest versions - especially the vite-plugin-vue.

@schirrel
Copy link
Author

Thanks for the response @AriPerkkio

I can reproduce the src/components/HelloWorld.vue issue now and see the uncovered import statement there. Debugging the root cause of this is not easy task. It would help if you could try and update all your dependencies to latest versions - especially the vite-plugin-vue.

Only updating the dependencies causes no effects

About what you said here

None of the tests load src/main.ts so it is included by the all: true option. The c8 will then mark all lines as uncovered as the whole file was not loaded. This is just how c8 / V8 coverage works. The @vitest/coverage-istanbul does not have this issue.

i've using all: true because if i don't files that has no tests are being ignored and i want to force to validate to files have tests. Is there a other configuration? if i remove it i get more trouble, i mean this on my real project

For the record i've update dependencies, remove the all like you said @AriPerkkio, it stops to show import as uncoverage, but show a lot of closing htmls tags as uncoverage.
look https://sonarcloud.io/component_measures?metric=coverage&selected=vue-vitest-ts-update-without-all%3Asrc%2Fcomponents%2FHelloWorld.vue&view=list&id=vue-vitest-ts-update-without-all

@schirrel
Copy link
Author

@AriPerkkio indeed change from c8 to istanbul quite solve a bunch of problems, imports and html tags. Maybe is a problem with c8?

@AriPerkkio
Copy link
Member

Maybe is a problem with c8?

The "import statements marked as uncovered when all:true is used" is not really a problem - that's just the way it works. It's not a bug either. When all: true is enabled and an untested file is loaded, c8 will simply mark whole file as uncovered. It does not check what code each line contains. Even comments are marked uncovered. More similar issues of c8 are described here: #1252.

But the uncovered ending HTML tags of tested files sounds like a real issue in source maps. The Vue compiler has had these issues before - that's why I'm not really eager to start debugging vite-plugin-vue2 that is even marked as end-of-life at this point. Debugging source maps and coverage results is a slow task.

I would recommend to use the @vitest/coverage-istanbul when these kind of issues come up with c8.

@schirrel
Copy link
Author

Thanks a lot @AriPerkkio , yeah we still use the vite-plugin-vue2 th because our project is vue 2.6.
We are looking to migrate for 2.7 or 3 on next semester.
I hope this does the trick 🙏🏻
For now we gona change for @vitest/coverage-istanbul.
Thanks for all you time and patience ❤️

@github-actions github-actions bot locked and limited conversation to collaborators Jun 2, 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

3 participants