0

I am able to use Karma, Tape, and Istanbul (specifically, babel-istanbul) to get what look like correct coverage reports of my ES6 codebase, but the HTML report shows some covered lines in red, even as it shows in the margin that they have been covered some number of times in the test suite:

enter image description here

In particular, line 13 shows 4x coverage, which reflects the test I just wrote (which calls concat() four times).

Why is that line red?

Roni Choudhury
  • 486
  • 4
  • 15
  • hi, I have same issue, did you find the cause ? – egig Apr 06 '17 at 11:18
  • Unfortunately, I didn't really. Because things were so complicated with uncertain results, I backed away from doing automated coverage testing at the time. Things may be in a better situation now. – Roni Choudhury Apr 06 '17 at 15:26

2 Answers2

-1

Hi I think it's because in your mocha file you require from lib rather than src.

you should require the src code rather than the compiled code. and make sure in your package.json scripts you have something like

{
"compile": "babel src/ -d lib/ --presets es2015 --source-map both",
 "test": "npm run compile && mocha",
"test-cov": "npm run compile && istanbul cover _mocha -- --opts ./test/mocha.opts"
}

src is your source code lib is the compiled code --source-map both can help istanbul track the coverage of your source code

in mocha.opts

--require babel-polyfill
--compilers js:babel-register
Sabrina Luo
  • 3,810
  • 4
  • 16
  • 35
  • I'm not sure what you mean - I'm not using Mocha, and I am getting coverage for the correct lines in my ES6 code (via sourcemaps embedded in the compiled files). My question has to do with why lines are red, yet still (correctly) reported as being covered. – Roni Choudhury Apr 19 '16 at 19:52
  • you need to embedded source map, in both es6 code and compiled code. and if you are not using mocha, which testing framework do you use, can you specify? which file do you require in your test framework? es6 code or compiled code? try to require es6 code in your test framework – Sabrina Luo Apr 25 '16 at 07:47
  • My sourcemaps are embedded; that's why I get coverage results for ES6 code. My original question describes my setup: tape to write the tests, karma to run them, and babel-istanbul for coverage. – Roni Choudhury May 06 '16 at 13:28
  • can you please show your test file also??? IT IS NOT ONLY ABOUT THE SOURCE MAP, BUT ALSO RELATED TO THE FILE YOU REQUIRE IN YOUR TEST FILE! – Sabrina Luo May 09 '16 at 02:05
-1

I think what's happening is that the lines are being run the number of times listed in the margin, but they are red because some aspect of coverage hasn't been hit. Looking at my screenshot I'm not sure what that could be for line 13, for example, but hovering the mouse over a red line pops up a message explaining what was missed.

Roni Choudhury
  • 486
  • 4
  • 15