adgitg
Last Updated: February 25, 2016
·
6.356K
· jgrenon
877bde91169e48ce6f18cfb3bc557451

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.

Say Thanks
Respond

1 Response
Add your response

18470

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 ·
Filed Under