douglasduteil / isparta

:skull: A code coverage tool for ES6 (babel/6to5)

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

coverage report looks not good

mariodu opened this issue · comments

image

It seems that can't deal with '||'.

I spent some time digging into this issue and this is what I found:

Isparta extends Istanbul's Instrumenter class and overrides the input code with babel generated code, and patches the generated metrics (statementMap, fnMap, branchMap) using the source map generated by Babel, mapping the generated positions back to the original positions in the source code. However, Babel's source map isn't detailed enough to return the precise end position for any expression. For example, it returns a column number of 0 for the end position of expressions that are part of:

  • a boolean expression, e.g. a || b
  • a ternary expression, e.g. a ? b : c

When Istanbul's HTML reporter is generating the HTML, it attempts to wrap the skipped branch, e.g. b with a <span>, however the end column is smaller than the starter column, so it fails to insert the closing </span>, causing the "skipped branch" span to include everything until the end of file.

I don't see a way to fix this other than asking Babel to provide source maps with better precision, but I also don't think it's going to be easy.