diff --git a/lib/cmd.js b/lib/cmd.js index 419e194d5..7cccc16a2 100644 --- a/lib/cmd.js +++ b/lib/cmd.js @@ -188,12 +188,13 @@ class Cmd { test() { program .command('test [file]') + .option('-d , --gasDetails', __('When set, will print the gas cost for each contract')) .option('--locale [locale]', __('language to use (default: en)')) .option('--loglevel [loglevel]', __('level of logging to display') + ' ["error", "warn", "info", "debug", "trace"]', /^(error|warn|info|debug|trace)$/i, 'warn') .description(__('run tests')) .action(function (file, options) { i18n.setOrDetectLocale(options.locale); - embark.runTests({file, loglevel: options.loglevel}); + embark.runTests({file, loglevel: options.loglevel, gasDetails: options.gasDetails}); }); } diff --git a/lib/tests/reporter.js b/lib/tests/reporter.js index ef6c13334..cbd7a8cc4 100644 --- a/lib/tests/reporter.js +++ b/lib/tests/reporter.js @@ -7,12 +7,22 @@ class EmbarkSpec extends Base { const self = this; self.embarkEvents = options.reporterOptions.events; + self.gasDetails = options.reporterOptions.gasDetails; let indents = 0; let n = 0; self.stats.gasCost = 0; function onContractReceipt(receipt) { self.stats.gasCost += receipt.gasUsed; + if (self.gasDetails) { + const fmt = color('bright pass', ' ') + + color('green', ' %s') + + ' deployed for ' + + color('green', '%s') + + color('light', ' gas'); + + console.log(fmt, receipt.className, receipt.gasUsed); + } } self.embarkEvents.on("deploy:contract:receipt", onContractReceipt); @@ -27,6 +37,9 @@ class EmbarkSpec extends Base { runner.on('suite', function (suite) { ++indents; + if (self.gasDetails) { + console.log(); + } console.log(color('suite', '%s%s'), indent(), suite.title); }); diff --git a/lib/tests/run_tests.js b/lib/tests/run_tests.js index fd94307e9..ceaab2fae 100644 --- a/lib/tests/run_tests.js +++ b/lib/tests/run_tests.js @@ -101,7 +101,7 @@ module.exports = { function executeForAllFiles(files, next) { async.eachLimit(files, 1, (file, eachCb) => { const mocha = new Mocha(); - mocha.reporter(EmbarkSpec, {events: global.embark.engine.events}); + mocha.reporter(EmbarkSpec, {events: global.embark.engine.events, gasDetails: options.gasDetails}); mocha.addFile(file); mocha.suite.timeout(0);