gotwarlost / istanbul

Yet another JS code coverage tool that computes statement, line, function and branch coverage with module loader hooks to transparently add coverage when running tests. Supports all JS coverage use cases including unit tests, server side functional tests and browser tests. Built for scale.
Other
8.7k stars 788 forks source link

es6 imports & branch coverage with babel #397

Open MIJOTHY opened 9 years ago

MIJOTHY commented 9 years ago

This babel-generated line is throwing up an uncovered branch for me when using import blah from "blah".

function _interopRequireWildcard(obj) { Eif (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj["default"] = obj; return newObj; } }

I've seen a similar issue here but it's closed for that module. I'm wondering if I'm missing something that can help with this?

Using istanbul 0.3.17 & babel 5.4.7.

MIJOTHY commented 9 years ago

Just noticed - this only applies to the HTML reporting and not the lcov

cpinnix commented 9 years ago

Running into this same problem

Istanbul 0.3.17 Babel 5.8.21

karma.conf.js here: https://gist.github.com/cpinnix/a632946266571a6dff19

kpdecker commented 9 years ago

I can't speak to how Istanbul might formally support this but there are two options provided by outside projects today:

  1. Using the auxiliaryCommentBefore: 'istanbul ignore next' option in babel Ex: https://github.com/wycats/handlebars.js/blob/master/Gruntfile.js#L49
  2. Use the https://github.com/douglasduteil/isparta istanbul fork.

Pros and cons to each but I've been able to get to 100% coverage for projects using both techniques.

JoelOtter commented 8 years ago

I get the same issue with isparta, but using the auxiliaryCommentBefore worked nicely. Thanks @kpdecker 👍

jethrolarson commented 7 years ago

Doesn't seem to work anymore https://github.com/babel/babel/issues/3844