Skip to content

Instantly share code, notes, and snippets.

@cgmartin
Created February 8, 2015 21:03
Show Gist options
  • Save cgmartin/599fefffd6baa161c615 to your computer and use it in GitHub Desktop.
Save cgmartin/599fefffd6baa161c615 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);
});
});
@cgmartin
Copy link
Author

cgmartin commented Feb 8, 2015

node --harmony `which gulp` test-coverage-server

@jednano
Copy link

jednano commented Jul 26, 2015

Have you gotten this to work with a gulpfile.babel.js?

@klausbayrhammer
Copy link

I've tried to use your gist without using the --harmony flag but instead adding babel/register. Works quite nice as well.

@mambax
Copy link

mambax commented Dec 6, 2016

Hey, just found your snippet, awesome. Just one question: I get an Unexpected token at import express from 'express'; . Isn't that exactly what isparta should solve :S?

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