Last Updated: February 25, 2016
·
8.215K
· jgrenon

Coverage report with gulp and istanbul

I spent a lot of time on this unit-test coverage task. To get the full coverage report, including files that aren't processed by unit-test (the most important ones actually!), you need to setup your task like that :

return gulp.src(['./build/target/**/*.js', '!./build/target/static/**'])
        .pipe(istanbul())
        .pipe(tap(function(f) {
            // Make sure all files are loaded to get accurate coverage data
            require(f.path);
        }))
        .on('end', function() {
            gulp.src(src)
                .pipe(jasmine())
                .pipe(istanbul.writeReports({
                    dir: './build/unit-test-coverage',
                    reporters: [ 'lcov' ],
                    reportOpts: { dir: './build/unit-test-coverage' }
                }));
        });

The key injecting a tap inside the pipeline to require all files AFTER instrumentation. This will add a reference of this file in istanbul and add it as an uncovered file in the final report. If you omit that, you only get files that have been touched by unit tests, which is not good.

1 Response
Add your response

The second answer here: http://stackoverflow.com/questions/22702578/full-gulp-istanbul-coverage-report discusses a newer includeUntested option that should make this easier (no more tap dancing).

over 1 year ago ·