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.
Written by Joel Grenon
Related protips
1 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
·
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#