0

I use browserify to bundle all our angular js code into one file. We use karma + jasmine to unit test this one file, app.js. As part of the bundling that browserify does, it injects a single line of code at the beginning of the file:

(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){

I tried putting a /*instanbul ignore next*/ above that line but causes the whole file to be ignored. this one line is killing my branch coverage numbers. is there anyway to ignore this generated code?

josh
  • 1,231
  • 1
  • 12
  • 28

1 Answers1

0

It is always preferred to write the unit test for each file,before the bundle process. If you have a number of files, will be difficult to mock the dependencies and keep track of them. And we have only a number of options available in istanbul. And what you want to do is to skip the function definition header. There is no possible way to ignore that particular line only. But you can solve this issue by separating the unit test's into different files. That is preferred and easy to test.

Aravind
  • 2,290
  • 1
  • 11
  • 21