Skip to content

Instantly share code, notes, and snippets.

@johanneslumpe
Forked from cgmartin/gulpfile.js
Created October 14, 2015 13:57
Show Gist options
  • Save johanneslumpe/6370a3225c2f8d599acf to your computer and use it in GitHub Desktop.
Save johanneslumpe/6370a3225c2f8d599acf to your computer and use it in GitHub Desktop.
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;
gulp.src(paths.server.scripts)
.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'}))
.pipe(istanbul.writeReports({
dir: coverageDir,
reportOpts: {dir: coverageDir},
reporters: ['text', 'text-summary', 'json', 'html']
}))
.pipe(coverageEnforcer({
thresholds: {
statements: 80,
branches: 50,
lines: 80,
functions: 50
},
coverageDirectory: coverageDir,
rootDirectory : ''
}))
.on('end', cb);
});
});
@newbreedofgeek
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