mirror of https://github.com/embarklabs/embark.git
feat(test/reporter): only show tx details on option
This commit is contained in:
parent
87d92b6091
commit
217357640a
|
@ -239,9 +239,10 @@ class Cmd {
|
|||
' vm - ' + __('start and use an Ethereum simulator (ganache)') + '\n' +
|
||||
' embark - ' + __('use the node of a running embark process') + '\n' +
|
||||
' <endpoint> - ' + __('connect to and use the specified node'))
|
||||
.option('-d , --gasDetails', __('print the gas cost for each contract deployment when running the tests'))
|
||||
.option('--gasDetails', __('print the gas cost for each contract deployment when running the tests. Deprecated: Please use --gas-details'))
|
||||
.option('-d , --gas-details', __('print the gas cost for each contract deployment when running the tests'))
|
||||
.option('-t , --tx-details', __('print the details of the transactions that happen during tests'))
|
||||
.option('-c , --coverage', __('generate a coverage report after running the tests (vm only)'))
|
||||
.option('--nobrowser', __('do not start browser after coverage report is generated'))
|
||||
.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')
|
||||
.option('--solc', __('run only solidity tests'))
|
||||
|
@ -261,8 +262,16 @@ class Cmd {
|
|||
process.exit(1);
|
||||
}
|
||||
i18n.setOrDetectLocale(options.locale);
|
||||
embark.runTests({file, solc:options.solc, logLevel: options.loglevel, gasDetails: options.gasDetails,
|
||||
node: options.node, coverage: options.coverage, noBrowser: options.nobrowser, env: options.env || 'development'});
|
||||
embark.runTests({
|
||||
file,
|
||||
solc: options.solc,
|
||||
logLevel: options.loglevel,
|
||||
gasDetails: options.gasDetails,
|
||||
txDetails: options.txDetails,
|
||||
node: options.node,
|
||||
coverage: options.coverage,
|
||||
env: options.env || 'development'
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -194,6 +194,7 @@ class TestRunner {
|
|||
mocha.reporter(reporter, {
|
||||
events: self.events,
|
||||
gasDetails: options.gasDetails,
|
||||
txDetails: options.txDetails,
|
||||
gasLimit
|
||||
});
|
||||
|
||||
|
|
|
@ -22,10 +22,12 @@ class EmbarkApiSpec extends Base {
|
|||
};
|
||||
};
|
||||
|
||||
runner.on('start', () => { this.embark.events.request('tests:results:reset'); });
|
||||
runner.on('pass', test => { this.embark.events.request('tests:results:report', formatTest(test)); });
|
||||
runner.on('fail', test => { this.embark.events.request('tests:results:report', formatTest(test)); });
|
||||
runner.on('suite', suite => { if(suite.title !== '') suiteStack.push(suite.title); });
|
||||
runner.on('start', () => this.embark.events.request('tests:results:reset'));
|
||||
runner.on('pass', test => this.embark.events.request('tests:results:report', formatTest(test)));
|
||||
runner.on('fail', test => this.embark.events.request('tests:results:report', formatTest(test)));
|
||||
runner.on('suite', suite => {
|
||||
if (suite.title !== '') suiteStack.push(suite.title);
|
||||
});
|
||||
runner.on('suite end', () => suiteStack.pop());
|
||||
}
|
||||
}
|
||||
|
@ -38,6 +40,7 @@ class EmbarkSpec extends Base {
|
|||
self.listenForGas = true;
|
||||
self.embarkEvents = options.reporterOptions.events;
|
||||
self.gasDetails = options.reporterOptions.gasDetails;
|
||||
self.txDetails = options.reporterOptions.txDetails;
|
||||
self.gasLimit = options.reporterOptions.gasLimit;
|
||||
let indents = 0;
|
||||
let n = 0;
|
||||
|
@ -49,12 +52,14 @@ class EmbarkSpec extends Base {
|
|||
self.txLogs = [];
|
||||
|
||||
function onContractReceipt(receipt) {
|
||||
self.embarkEvents.request('contracts:contract', receipt.className, (contract) => {
|
||||
if (contract) {
|
||||
self.contracts.push(contract);
|
||||
self.addressToContract = getAddressToContract(self.contracts, self.addressToContract);
|
||||
}
|
||||
});
|
||||
if (self.txDetails) {
|
||||
self.embarkEvents.request('contracts:contract', receipt.className, (contract) => {
|
||||
if (contract) {
|
||||
self.contracts.push(contract);
|
||||
self.addressToContract = getAddressToContract(self.contracts, self.addressToContract);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
if (self.gasDetails) {
|
||||
const fmt = color('bright pass', ' ') +
|
||||
|
@ -68,12 +73,15 @@ class EmbarkSpec extends Base {
|
|||
}
|
||||
|
||||
async function onBlockHeader(blockHeader) {
|
||||
if(!self.listenForGas) {
|
||||
if (!self.listenForGas) {
|
||||
return;
|
||||
}
|
||||
self.stats.totalGasCost += blockHeader.gasUsed;
|
||||
self.stats.test.gasUsed += blockHeader.gasUsed;
|
||||
|
||||
if (!self.txDetails) {
|
||||
return;
|
||||
}
|
||||
self.embarkEvents.request("blockchain:block:byNumber", blockHeader.number, (err, block) => {
|
||||
if (err) {
|
||||
return this.logger.error('Error getting block header', err.message || err);
|
||||
|
@ -110,11 +118,11 @@ class EmbarkSpec extends Base {
|
|||
return Array(indents).join(' ');
|
||||
}
|
||||
|
||||
runner.on('start', function () {
|
||||
runner.on('start', function() {
|
||||
console.log();
|
||||
});
|
||||
|
||||
runner.on('suite', function (suite) {
|
||||
runner.on('suite', function(suite) {
|
||||
++indents;
|
||||
if (self.gasDetails) {
|
||||
console.log();
|
||||
|
@ -122,25 +130,25 @@ class EmbarkSpec extends Base {
|
|||
console.log(color('suite', '%s%s'), indent(), suite.title);
|
||||
});
|
||||
|
||||
runner.on('suite end', function () {
|
||||
runner.on('suite end', function() {
|
||||
--indents;
|
||||
if (indents === 1) {
|
||||
console.log();
|
||||
}
|
||||
});
|
||||
|
||||
runner.on('pending', function (test) {
|
||||
runner.on('pending', function(test) {
|
||||
const fmt = indent() + color('pending', ' - %s');
|
||||
console.log(fmt, test.title);
|
||||
});
|
||||
|
||||
|
||||
runner.on('test', function () {
|
||||
runner.on('test', function() {
|
||||
self.stats.test.gasUsed = 0;
|
||||
self.contracts = [];
|
||||
});
|
||||
|
||||
runner.on('pass', function (test) {
|
||||
runner.on('pass', function(test) {
|
||||
let fmt =
|
||||
indent() +
|
||||
color('checkmark', ' ' + Base.symbols.ok) +
|
||||
|
@ -153,14 +161,14 @@ class EmbarkSpec extends Base {
|
|||
self.txLogs = [];
|
||||
});
|
||||
|
||||
runner.on('fail', function (test) {
|
||||
runner.on('fail', function(test) {
|
||||
console.log(indent() + color('fail', ' %d) %s') + ' - ' + color(self.getGasColor(self.stats.test.gasUsed), '[%d gas]'),
|
||||
++n, test.title, self.stats.test.gasUsed);
|
||||
self.txLogs.forEach(log => console.log(log));
|
||||
self.txLogs = [];
|
||||
});
|
||||
|
||||
runner.once('end', function () {
|
||||
runner.once('end', function() {
|
||||
runner.removeAllListeners();
|
||||
self.embarkEvents.removeListener("deploy:contract:receipt", onContractReceipt);
|
||||
self.embarkEvents.removeListener("block:header", onBlockHeader);
|
||||
|
|
Loading…
Reference in New Issue