Skip to content

Instantly share code, notes, and snippets.

@barretts
Created January 17, 2017 17:28
Show Gist options
  • Save barretts/db9097d4a988a56b54a585e3085a7d06 to your computer and use it in GitHub Desktop.
Save barretts/db9097d4a988a56b54a585e3085a7d06 to your computer and use it in GitHub Desktop.
Code coverage sample files
var config = require('config.json');
var fs = require('fs');
var gulp = require('gulp');
var mochaPhantomJS = require('gulp-mocha-phantomjs');
var webpack = require('webpack');
var remapIstanbul = require('remap-istanbul/lib/gulpRemapIstanbul');
var coverageFile = './results/coverage/coverage.json';
gulp.task('webpack-coverage', function (cb) {
var webpackConfig = require('webpack-coverage.config');
webpack(webpackConfig, function (err) {
if (err) throw new Error('webpack', err);
cb();
});
});
gulp.task('coverage', ['webpack-coverage'], function () {
return gulp
.src(config.files.tests)
.pipe(mochaPhantomJS({
phantomjs: {
hooks: 'mocha-phantomjs-istanbul',
coverageFile,
ignoreResourceErrors: true,
},
reporter: 'dot',
}))
.on('finish', function () {
gulp.src(coverageFile)
.pipe(remapIstanbul({
reports: {
html: './results/coverage',
},
warn: () => {},
}));
});
});
var config = require('./webpack.config')[0]; // regular config for production and development builds
var path = require('path');
config.devtool = '#inline-source-map';
config.entry = './specs/testRunner.js';
config.output.filename = 'coverage.bundle.js';
config.resolve.root.push(path.join(__dirname, 'specs'));
config.module.loaders[config.module.loaders.length - 1] = {
exclude: /(node_modules)/,
loader: 'babel-loader',
test: /\.jsx?$/,
query: {
presets: ['es2015'],
plugins: [
['istanbul', {
exclude: [
'specs/**/*.js',
'dist/**/*.js',
'node_modules/**/*.js',
],
}],
],
},
};
module.exports = config;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment