Skip to content

Instantly share code, notes, and snippets.

Forked from cgmartin/gulpfile.js
Created October 14, 2015 13:57
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
Node ES6 istanbul, isparta, mocha-co gulpfile example
'use strict';
var gulp = require('gulp');
var del = require('del');
var mocha = require('gulp-mocha-co');
var istanbul = require('gulp-istanbul');
var isparta = require('isparta');
var coverageEnforcer = require('gulp-istanbul-enforcer');
var paths = {
server: {
scripts: ['server/src/**/*.js'],
tests: ['server/test/**/*.spec.js'],
coverage: 'coverage/server'
gulp.task('clean-coverage', function(cb) {
del(['coverage'], cb);
gulp.task('test-coverage-server', ['clean-coverage'], function(cb) {
var coverageDir = paths.server.coverage;
.pipe(istanbul({ // Covering files
instrumenter: isparta.Instrumenter,
includeUntested: true
.pipe(istanbul.hookRequire()) // Force `require` to return covered files
.on('finish', function() {
gulp.src(paths.server.tests, {read: false})
.pipe(mocha({reporter: 'spec'}))
dir: coverageDir,
reportOpts: {dir: coverageDir},
reporters: ['text', 'text-summary', 'json', 'html']
thresholds: {
statements: 80,
branches: 50,
lines: 80,
functions: 50
coverageDirectory: coverageDir,
rootDirectory : ''
.on('end', cb);
Copy link

Thanks! Finally got coverage working in my project tnx to this example. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment