question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

reported uncovered lines that actually have been covered

See original GitHub issue

Link to bug demonstration repository

https://github.com/lichader/nyc-demo

Expected Behavior

Expected 100% coverage

Observed Behavior

Reporting Branch coverage as 50%.

I made a basic repo to show what the problem is. I have a simple js file here that just prints something in the log. From console output I pasted below, you can see that the code inside the if block is hit. But nyc reported lines 8-16 are uncovered, which is quite strange. Not sure where I did wrong or it is a bug.

This is the output here:

 π nyc-poc master ✗ ❯ npm run cover:unit

> unit@1.0.0 cover:unit /Users/me802707/work/rpeng/nyc-poc
> nyc --all npm run test


> unit@1.0.0 test /Users/me802707/work/rpeng/nyc-poc
> mocha tests/*.test.js --reporter mocha-junit-reporter --reporter-options mochaFile=./test-results/test-results.xml

found bar: user1
found bar: user2
bar is found
ERROR: Coverage for branches (50%) does not meet global threshold (90%)
----------|---------|----------|---------|---------|-------------------
File      | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s
----------|---------|----------|---------|---------|-------------------
All files |     100 |       50 |     100 |     100 |
 foo.js   |     100 |       50 |     100 |     100 | 8-16
----------|---------|----------|---------|---------|-------------------

Troubleshooting steps

run command: npm install && npm run cover:unit

Environment Information

  System:
    OS: macOS 11.2.1
    CPU: (12) x64 Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz
    Memory: 51.58 MB / 16.00 GB
  Binaries:
    Node: 14.15.4 - ~/.nvm/versions/node/v14.15.4/bin/node
    npm: 6.14.10 - ~/.nvm/versions/node/v14.15.4/bin/npm
  npmPackages:
    nyc: 15.1.0 => 15.1.0

Thank you

Issue Analytics

  • State:open
  • Created 3 years ago
  • Comments:7

github_iconTop GitHub Comments

3reactions
hedocodecommented, Jul 31, 2021

I have the same problem on if statements, however, I wrote console.log statements into these ifs and they are properly displayed in the console

0reactions
andrecadetecommented, May 12, 2022

Hi dhensby,

Makes sense for actual branches, but these are mocked Constructor arguments, how exactly does your example relate to that use-case?

Either way, once we cover the remaining branches I’ll let you know if that fixed it. But seems silly, it should instead state which lines are partially tested when less than 100% of branches were tested. There’s no way it can know which constructor arguments are used in untested branches without knowing which lines those are. So indicating those lines as untested or (a new feature) as partially tested would have actual use while indicating constructor arguments says very little.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Jest Uncovered Lines - How do I test these lines..?
If the 'uncovered lines' are in yellow, it means they're partially covered. You can find out what specific attributes are not covered by ......
Read more >
Why does JaCoCo report uncovered lines which are in fact ...
I created a project on GitHub [1] and integrated it with coveralls.io using the JaCoCo Maven plugin to generate the coverage report. The...
Read more >
How do I see what lines are not covered?
I have a simple trigger that works in the sandbox, does exactly what I want it to do. Cannot get code coverage above...
Read more >
Total coverage won't increase even after exclusions
What I have noticed after exclusions was, after exclusions the number of Lines to cover and Uncovered Lines both got reduced. So lo…...
Read more >
Read the coverage report | IntelliJ IDEA Documentation
The report shows the percentage of the code that has been executed or covered by tests. You can see the coverage result for...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found