add option to show details of gas cost for each contract

This commit is contained in:
Jonathan Rainville 2018-06-28 15:48:57 -04:00
parent 18fa4307d7
commit 2648d0536e
3 changed files with 16 additions and 2 deletions

View File

@ -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});
});
}

View File

@ -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);
});

View File

@ -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);