mirror of https://github.com/embarklabs/embark.git
add option to show details of gas cost for each contract
This commit is contained in:
parent
18fa4307d7
commit
2648d0536e
|
@ -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});
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
});
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue