From 5b912262c5d80e918c6a91fca662a5e608a654c3 Mon Sep 17 00:00:00 2001 From: Jonathan Rainville Date: Thu, 28 Jun 2018 15:18:28 -0400 Subject: [PATCH] log gas cost at the end of each suite --- lib/tests/reporter.js | 43 ++++++++++++++++++++++++++++++++++++++++-- lib/tests/run_tests.js | 1 + 2 files changed, 42 insertions(+), 2 deletions(-) diff --git a/lib/tests/reporter.js b/lib/tests/reporter.js index 91cfbfcc9..ef6c13334 100644 --- a/lib/tests/reporter.js +++ b/lib/tests/reporter.js @@ -9,10 +9,12 @@ class EmbarkSpec extends Base { self.embarkEvents = options.reporterOptions.events; let indents = 0; let n = 0; + self.stats.gasCost = 0; function onContractReceipt(receipt) { - console.log(receipt.className, receipt.gasUsed); + self.stats.gasCost += receipt.gasUsed; } + self.embarkEvents.on("deploy:contract:receipt", onContractReceipt); function indent() { @@ -62,11 +64,48 @@ class EmbarkSpec extends Base { console.log(indent() + color('fail', ' %d) %s'), ++n, test.title); }); - runner.once('end', function() { + runner.once('end', function () { + runner.removeAllListeners(); self.embarkEvents.removeListener("deploy:contract:receipt", onContractReceipt); 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; diff --git a/lib/tests/run_tests.js b/lib/tests/run_tests.js index 89fe40340..fd94307e9 100644 --- a/lib/tests/run_tests.js +++ b/lib/tests/run_tests.js @@ -114,6 +114,7 @@ module.exports = { mocha.run(function (fails) { failures += fails; + mocha.suite.removeAllListeners(); // Mocha prints the error already eachCb(); });