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

How to include files completely missing tests from coverage reports? #4487

Open
2 tasks done
swantzter opened this issue Oct 9, 2024 · 2 comments
Open
2 tasks done
Labels

Comments

@swantzter
Copy link

Node.js Version

v22.9.0

NPM Version

v10.8.3

Operating System

Linux razz 5.15.153.1-microsoft-standard-WSL2 #1 SMP Fri Mar 29 23:14:13 UTC 2024 x86_64 x86_64 x86_64 GNU/Linux

Subsystem

Other

Description

If I have two files, add.js and subtract.js along with tests for just one of them add.test.js which imports add.js I would like the --experimental-test-coverage to report that I have only tested 50% of files.

I've tried using --test-coverage-include='*.js' but this does not seem to include the additional files, I've also tried changing the test pattern node --test *.js which does seem to sort-of work, but it adds extra processing for every file (~1s per file) and logs it as a test suite file in the console, which is undesirable.

Is there a way to make sure coverage reports across all files with a given pattern?

Minimal Reproduction

https://github.com/swantzter/poc-node-test-coverage

Output

Given the three files above, run node --test --experimental-test-coverage --test-coverage-include='*.js' --test-coverage-exclude='*.test.js'

This prints

[...]
# -------------------------------------------------------
# file   | line % | branch % | funcs % | uncovered lines
# -------------------------------------------------------
# add.js | 100.00 |   100.00 |  100.00 | 
# -------------------------------------------------------
# all f… | 100.00 |   100.00 |  100.00 |
# -------------------------------------------------------
# end of coverage report

I would expect, or am trying to find a way to make it print

[...]
# ------------------------------------------------------------
# file        | line % | branch % | funcs % | uncovered lines
# ------------------------------------------------------------
# add.js      | 100.00 |   100.00 |  100.00 |
# subtract.js |   0.00 |     0.00 |    0.00 | 1-3
# ------------------------------------------------------------
# all files   |  50.00 |    50.00 |   50.00 |
# ------------------------------------------------------------
# end of coverage report

Before You Submit

  • I have looked for issues that already exist before submitting this
  • My issue follows the guidelines in the README file, and follows the 'How to ask a good question' guide at https://stackoverflow.com/help/how-to-ask
@swantzter
Copy link
Author

Yes that does work but the runtime gets significantly worse and the logged output gets less useful

@nullswan
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants