0

In the initial state I have e.g. app.module.js with the following code of Angular application:

'use strict';

var app = angular.module('bumblebee', []);

In order to get test coverage for e2e protractor tests I apply the gulp-istanbul.

gulp.task('decorate:code:istanbul', function() {
    return gulp.src('./app/')
        .pipe(istanbul({
            includeUntested: true,
            coverageVariable: '__coverage__'
        }))
        .pipe(gulp.dest(./app/));
});

What this does is it digests all my files with istanbul so they will have code coverage decoration inside, like my file app.module.js:

"use strict";
var __cov_BJkerWMhn194664Vc2WfiA = (Function('return this'))();
if (!__cov_BJkerWMhn194664Vc2WfiA.__coverage__) {
    __cov_BJkerWMhn194664Vc2WfiA.__coverage__ = {};
}
__cov_BJkerWMhn194664Vc2WfiA = __cov_BJkerWMhn194664Vc2WfiA.__coverage__;
if (!(__cov_BJkerWMhn194664Vc2WfiA['c:\\project\\app.js'])) {
    __cov_BJkerWMhn194664Vc2WfiA['c:\\project\\app.js'] = {
        "path": "c:\\project\\app.js",
        "s": {"1": 0, "2": 0},
        "b": {},
        "f": {"1": 0},
        "fnMap": {
            "1": {
                "name": "(anonymous_1)",
                "line": 6,
                "loc": {"start": {"line": 6, "column": 9}, "end": {"line": 6, "column": 20}}
            }
        },
        "statementMap": {
            "1": {"start": {"line": 3, "column": 0}, "end": {"line": 3, "column": 171}}
        },
        "branchMap": {}
    };
}
__cov_BJkerWMhn194664Vc2WfiA = __cov_BJkerWMhn194664Vc2WfiA['c:\\project\\app.js'];
__cov_BJkerWMhn194664Vc2WfiA.s['1']++;
var app = angular.module('bumblebee', []);

Then after running the tests and getting the source code coverage I want to remove all this additional information from app.module.js. Is there a way to do this?

P.S. Currently I'm copying all source to new directory, instrument it with istanbul, run e2e tests for this instrumented code, get code coverage and use it as for original code. This is not very efficient in my opinion.

zmii
  • 4,123
  • 3
  • 40
  • 64

1 Answers1

1

Removing that instrumentation code is a nightmare. It would take you just as long to remove it as it did to instrument it, if not longer. Copying the code to be instrumented to a new folder, instrumenting it, and then using that code to determine coverage is a very common practice. Efficient or not, that is how getting coverage with Istanbul works best.

MBielski
  • 6,628
  • 3
  • 32
  • 43
  • but `karma-coverage` somehow does this for unit tests, right? – zmii Feb 12 '16 at 16:02
  • Yes, it does instrument the files, but the difference is that it then serves up the instrumented files. It doesn't remove the instrumenting code. – MBielski Feb 12 '16 at 19:54