modernweb-dev / web

Guides, tools and libraries for modern web development.
https://modern-web.dev
MIT License
2.23k stars 297 forks source link

[test runner] code coverage does not include untested files #1880

Open jmcgavin opened 2 years ago

jmcgavin commented 2 years ago

The includes property of the coverageConfig object does not include untested files in the code coverage. Only files visited during tests are included in the coverage.

I think having the option to include the entire codebase in the code coverage output is a good idea. Either through the includes property or the addition of an all property like the --all flag that can be used with istanbul/nyc or c8.

jmcgavin commented 2 years ago

The @web/test-runner-coverage-v8 package uses the v8-to-istanbul lib which initializes all to false.

jmcgavin commented 2 years ago

Relates to #1873

u-b-i-p-i-x-e-l-s commented 2 years ago

@LarsDenBakker would love to have your feedback on this. 😃

LarsDenBakker commented 2 years ago

I'm not sure the "all" flag would change anything here. Did anyone test this? I think we need to see all the files in the browser to make them show up in the coverage.

electrovir commented 1 year ago

This may be overkill but here's a workaround:

  1. before running web-test-runner, run a new script that finds all your files
  2. using that script, generate a new TS/JS file that imports all the found file paths from step 1
  3. include that new file in the test files that web-test-runner executes
  4. now all your files are included in the coverage report because the browser imported them all!
mohamedmansour commented 7 months ago

This may be overkill but here's a workaround:

  1. before running web-test-runner, run a new script that finds all your files

  2. using that script, generate a new TS/JS file that imports all the found file paths from step 1

  3. include that new file in the test files that web-test-runner executes

  4. now all your files are included in the coverage report because the browser imported them all!

Another approach instead of creating a new test file is to add it to Istanbul reporter as 0 coverage for all files found then merge the coverage data found.