Last Updated: February 25, 2016
· 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(tap(function(f) {
            // Make sure all files are loaded to get accurate coverage data
        .on('end', function() {
                    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.

Say Thanks

1 Response
Add your response


The second answer here: discusses a newer includeUntested option that should make this easier (no more tap dancing).

over 1 year ago ·
Filed Under