Search code examples
javascriptbrowserifybabeljsistanbulkarma-coverage

How to ignore function _interopRequireDefault in istanbul coverage report?


Babel compiles my modules to include the following line:

function _interopRequireDefault(obj) { 
    return obj && obj.__esModule ? obj : { default: obj }; 
}

Which, to my best understanding, is to deal with CommonJS imports.

How can I ignore this line from being covered in my coverage report? My branch coverage is usually affected by this line.

I wasn't able to add an inline ignore comment such as /* istanbul ignore next */, because I can't add it directly over this line. Adding the comment to the beginning of the file adds it before the class definition.

I also tried using Babel's auxiliaryCommentBefore option to add a comment before compiled lines, but it adds it almost everywhere in the code, so this can't be used.

Is there a way to ignore this line when analyzing the coverage?


Solution

  • We ended up using isparta in order for the coverage to use the ES6 code before the transpiling, which is actually more accurate (we wanted to check coverage against the code we actually wrote, not the code that's compiled). Thanks for the help. :)