mocha-annotated
Version:
Mocha but with tasks and feedback built into it!
47 lines (34 loc) • 970 B
JavaScript
;
var Base = require('mocha/lib/reporters/base');
var _require = require('./helpers'),
clean = _require.clean;
/**
* Initialize a new `AnnotatedList` test reporter.
*
* @api public
* @param {Runner} runner
*/
function AnnotatedList(runner) {
var _this = this;
Base.call(this, runner);
this.total = runner.total;
runner.on('start', function () {
console.log(JSON.stringify(['start', { total: _this.total }]));
});
runner.on('pass', function (test) {
console.log(JSON.stringify(['pass', clean(test)]));
});
runner.on('fail', function (test, err) {
// eslint-disable-next-line no-param-reassign
test.err = test.err !== undefined ? test.err : err;
var result = clean(test);
console.log(JSON.stringify(['fail', result]));
});
runner.once('end', function () {
process.stdout.write(JSON.stringify(['end', _this.stats]));
});
}
/**
* Expose `AnnotatedList`.
*/
module.exports = AnnotatedList;