log gas cost at the end of each suite

This commit is contained in:
Jonathan Rainville 2018-06-28 15:18:28 -04:00 committed by Iuri Matias
parent bd369ec1a8
commit 5b912262c5
2 changed files with 42 additions and 2 deletions

View File

@ -9,10 +9,12 @@ class EmbarkSpec extends Base {
self.embarkEvents = options.reporterOptions.events; self.embarkEvents = options.reporterOptions.events;
let indents = 0; let indents = 0;
let n = 0; let n = 0;
self.stats.gasCost = 0;
function onContractReceipt(receipt) { function onContractReceipt(receipt) {
console.log(receipt.className, receipt.gasUsed); self.stats.gasCost += receipt.gasUsed;
} }
self.embarkEvents.on("deploy:contract:receipt", onContractReceipt); self.embarkEvents.on("deploy:contract:receipt", onContractReceipt);
function indent() { function indent() {
@ -63,10 +65,47 @@ class EmbarkSpec extends Base {
}); });
runner.once('end', function () { runner.once('end', function () {
runner.removeAllListeners();
self.embarkEvents.removeListener("deploy:contract:receipt", onContractReceipt); self.embarkEvents.removeListener("deploy:contract:receipt", onContractReceipt);
self.epilogue(); self.epilogue();
}); });
} }
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();
}
} }
module.exports = EmbarkSpec; module.exports = EmbarkSpec;

View File

@ -114,6 +114,7 @@ module.exports = {
mocha.run(function (fails) { mocha.run(function (fails) {
failures += fails; failures += fails;
mocha.suite.removeAllListeners();
// Mocha prints the error already // Mocha prints the error already
eachCb(); eachCb();
}); });