douglasduteil / isparta

:skull: A code coverage tool for ES6 (babel/6to5)
Do What The F*ck You Want To Public License
642 stars 47 forks source link

Else path not taken #127

Open Gopikrishna19 opened 7 years ago

Gopikrishna19 commented 7 years ago

Hello

I ran into a weird issue: when I have the following setup,

if(!array.length) {
  return null;
}

return doSomething();

It reported that else path is not taken: epnt1

I am testing the else part too, by asserting doSomething is called. I refactored the code to the following:

if(!array.length) {
  return null;
} else {
  return doSomething();
}

which ended up with following report: epnt2

Once again I refactored the code:

let returnValue;

if(!array.length) {
  returnValue = null;
} else {
  returnValue = doSomething();
}

return returnValue;

which resulted in 100% coverage. Can I please know what is wrong with first or second code pattern? why would it say that the else path was not taken, even though there are 'hits' on those lines of code? is this a bug or by design? Though I can somewhat digest the first one, I would say the second one is a real bug!

(I have cut many things inside the braces in the images to simplify stuff, the code given is the (pseudo)real one)

rodoabad commented 7 years ago

Same thing happens in nyc which IIRC uses the same core.