UNPKG

grunt-mocha-blanket

Version:

Headless Blanket.js code coverage and Mocha testing via PhantomJS

48 lines (38 loc) 1.06 kB
/** * Some helper functions when working with mocha */ 'use strict'; var exports = module.exports; /** * Take a collection of stats objects and reduce them * * @param stats {Array} Array of mocha test stats */ exports.reduceStats = function(stats) { var initial = { passes : 0, failures : 0, tests : 0, duration : 0 }; // console.log(testStats); var total = stats.reduce(function(prev, stats, i, list) { prev.passes += stats.passes; prev.failures += stats.failures; prev.tests += stats.tests; prev.duration += (stats.end - stats.start); return prev; }, initial); total.duration = this.formatMs(total.duration); return total; }; exports.formatMs = function(ms) { return (Math.ceil(ms * 100) / 100000).toFixed(2); } /* * Overriding XUnit reporter from mochajs. Due to bug described in: * https://github.com/mochajs/mocha/issues/2297 * https://github.com/kmiyashiro/grunt-mocha/issues/163 */ var reporters = require('mocha').reporters; reporters['XUnit'] = require('./xunit');