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

Incorrect coverage reported for ternaries in some situations #61

Closed
Trott opened this issue Feb 5, 2019 · 4 comments
Closed

Incorrect coverage reported for ternaries in some situations #61

Trott opened this issue Feb 5, 2019 · 4 comments

Comments

@Trott
Copy link
Contributor

Trott commented Feb 5, 2019

  • Version: 11.9.0
  • Platform: Darwin Fhqwhgads.local 17.7.0 Darwin Kernel Version 17.7.0: Thu Dec 20 21:47:19 PST 2018; root:xnu-4570.71.22~1/RELEASE_X86_64 x86_64

In file foo.js:

'use strict';

function testIt (a, b) {
 const thing = a && b;
 console.log(thing);
 return a && b;
}

if (testIt(true, false))
  console.log('foo');

I run this:

c8 node foo.js

I get this:

false
----------|----------|----------|----------|----------|-------------------|
File      |  % Stmts | % Branch |  % Funcs |  % Lines | Uncovered Line #s |
----------|----------|----------|----------|----------|-------------------|
All files |      100 |       60 |      100 |      100 |                   |
 foo.js   |      100 |       60 |      100 |      100 |              6,10 |
----------|----------|----------|----------|----------|-------------------|

I would have expected the coverage for line 4 (the assignment to thing) and line 6 (the return statement) to be the same. Instead, it is (correctly) reporting that 6 has some uncovered branches, but is omitting the same thing for line 4.

@Trott
Copy link
Contributor Author

Trott commented Feb 5, 2019

@bcoe

@JaKXz
Copy link

JaKXz commented Feb 5, 2019

Feel free to submit a failing test in a PR :)

@bcoe
Copy link
Owner

bcoe commented Feb 6, 2019

@Trott thanks for filing; @JaKXz for this sort of problem, we'll probably want to look first at the output from V8, and see if the offsets are actually wrong -- if they look right in V8, we know the problem is with our translation to line #s, if they are in fact wrong, we should create an upstream error report in https://bugs.chromium.org.

@bcoe
Copy link
Owner

bcoe commented Oct 24, 2019

did a little bit of testing with Node 13, and a slightly modified sample:

'use strict';

function testIt (a, b) {
 const thing = a || b;
 console.log(thing);
 return a && b;
}

if (testIt(true, true))
  console.log('foo');

The coverage seems to work as I'd expect now 👍

@bcoe bcoe closed this as completed Oct 24, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants