embark-area-51/lib/tests/reporter.js

112 lines
2.5 KiB
JavaScript
Raw Normal View History

2018-06-28 18:01:44 +00:00
const Base = require('mocha/lib/reporters/base');
const color = Base.color;
class EmbarkSpec extends Base {
constructor(runner, options) {
super(runner, options);
const self = this;
self.embarkEvents = options.reporterOptions.events;
let indents = 0;
let n = 0;
2018-06-28 19:18:28 +00:00
self.stats.gasCost = 0;
2018-06-28 18:01:44 +00:00
function onContractReceipt(receipt) {
2018-06-28 19:18:28 +00:00
self.stats.gasCost += receipt.gasUsed;
2018-06-28 18:01:44 +00:00
}
2018-06-28 19:18:28 +00:00
2018-06-28 18:01:44 +00:00
self.embarkEvents.on("deploy:contract:receipt", onContractReceipt);
function indent() {
return Array(indents).join(' ');
}
runner.on('start', function () {
console.log();
});
runner.on('suite', function (suite) {
++indents;
console.log(color('suite', '%s%s'), indent(), suite.title);
});
runner.on('suite end', function () {
--indents;
if (indents === 1) {
console.log();
}
});
runner.on('pending', function (test) {
const fmt = indent() + color('pending', ' - %s');
console.log(fmt, test.title);
});
runner.on('pass', function (test) {
let fmt;
if (test.speed === 'fast') {
fmt =
indent() +
color('checkmark', ' ' + Base.symbols.ok) +
color('pass', ' %s');
console.log(fmt, test.title);
} else {
fmt =
indent() +
color('checkmark', ' ' + Base.symbols.ok) +
color('pass', ' %s') +
color(test.speed, ' (%dms)');
console.log(fmt, test.title, test.duration);
}
});
runner.on('fail', function (test) {
console.log(indent() + color('fail', ' %d) %s'), ++n, test.title);
});
2018-06-28 19:18:28 +00:00
runner.once('end', function () {
runner.removeAllListeners();
2018-06-28 18:01:44 +00:00
self.embarkEvents.removeListener("deploy:contract:receipt", onContractReceipt);
self.epilogue();
});
}
2018-06-28 19:18:28 +00:00
epilogue() {
const stats = this.stats;
let fmt;
console.log();
// passes
fmt = color('bright pass', ' ') +
color('green', ' %d passing') +
color('light', ' (%s gas)');
console.log(fmt,
stats.passes || 0,
stats.gasCost);
// pending
if (stats.pending) {
fmt = color('pending', ' ') +
color('pending', ' %d pending');
console.log(fmt, stats.pending);
}
// failures
if (stats.failures) {
fmt = color('fail', ' %d failing');
console.log(fmt, stats.failures);
Base.list(this.failures);
console.log();
}
console.log();
}
2018-06-28 18:01:44 +00:00
}
module.exports = EmbarkSpec;