Commit ee27943b authored by Dan Schultzer's avatar Dan Schultzer

Add istanbul coverage

parent c292ff8f
......@@ -12,3 +12,5 @@ Thumbs.db
/app/**/*.map
/dist
/coverage
......@@ -31,6 +31,7 @@
"start": "gulp start",
"pretest": "gulp build-unit --env=test",
"test": "electron-mocha app/specs.js.autogenerated --renderer --require source-map-support/register",
"coverage": "npm test -- -R scripts/istanbul-reporter",
"pree2e": "gulp build-e2e --env=test",
"e2e": "mocha app/e2e.js.autogenerated --require source-map-support/register"
},
......@@ -46,8 +47,10 @@
"gulp-plumber": "^1.1.0",
"gulp-util": "^3.0.6",
"gulp-watch": "^4.3.5",
"istanbul": "^0.4.3",
"mocha": "^3.0.2",
"rollup": "^0.34.7",
"rollup-plugin-istanbul": "^1.1.0",
"source-map-support": "^0.4.2",
"spectron": "^3.3.0",
"yargs": "^4.2.0"
......
var istanbul = require('istanbul'),
/**
* Expose `Istanbul`.
*/
exports = module.exports = Istanbul;
/**
* Initialize a new Istanbul reporter.
*
* @param {Runner} runner
* @param {Object} options
* @public
*/
function Istanbul(runner, options) {
mocha.reporters.Base.call(this, runner);
var reporterOpts = { dir: 'coverage' },
reporters = ['text-summary', 'html'];
options = options || {};
if (options.reporters) reporters = options.reporters.split(',');
if (process.env.ISTANBUL_REPORTERS) reporters = process.env.ISTANBUL_REPORTERS.split(',');
if (options.reportDir) reporterOpts.dir = options.reportDir;
if (process.env.ISTANBUL_REPORT_DIR) reporterOpts.dir = process.env.ISTANBUL_REPORT_DIR;
runner.on('end', function(){
var cov = global.__coverage__ || {},
collector = new istanbul.Collector();
collector.add(cov);
reporters.forEach(function(reporter) {
istanbul.Report.create(reporter, reporterOpts).writeReport(collector, true);
});
});
}
......@@ -3,6 +3,7 @@
var gulp = require('gulp');
var jetpack = require('fs-jetpack');
var bundle = require('./bundle');
var istanbul = require('rollup-plugin-istanbul');
// Spec files are scattered through the whole project. Here we're searching
// for them and generate one entry file which will run all the tests.
......@@ -28,7 +29,14 @@ gulp.task('build-unit', ['environment'], function () {
return generateEntryFile(srcDir, 'specs.js.autogenerated', '*.spec.js')
.then(function (entryFilePath) {
return bundle(entryFilePath, destDir.path('specs.js.autogenerated'));
return bundle(entryFilePath, destDir.path('specs.js.autogenerated'), {
rollupPlugins: [
istanbul({
exclude: ['**/*.spec.js', '**/specs.js.autogenerated'],
sourceMap: true
})
]
});
});
});
......
......@@ -23,11 +23,14 @@ var generateExternalModulesList = function () {
var cached = {};
module.exports = function (src, dest) {
module.exports = function (src, dest, opts) {
opts = opts || {};
opts.rollupPlugins = opts.rollupPlugins || [];
return rollup({
entry: src,
external: generateExternalModulesList(),
cache: cached[src],
plugins: opts.rollupPlugins,
})
.then(function (bundle) {
cached[src] = bundle;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment