mirror of https://github.com/embarklabs/embark.git
add reporter with event to get receipt
This commit is contained in:
parent
ff340fe88c
commit
bd369ec1a8
|
@ -248,6 +248,7 @@ class ContractDeployer {
|
|||
self.logger.info(contract.className.bold.cyan + " " + __("deployed at").green + " " + receipt.contractAddress.bold.cyan);
|
||||
contract.deployedAddress = receipt.contractAddress;
|
||||
contract.transactionHash = receipt.transactionHash;
|
||||
receipt.className = contract.className;
|
||||
self.events.emit("deploy:contract:receipt", receipt);
|
||||
self.events.emit("deploy:contract:deployed", contract);
|
||||
|
||||
|
|
|
@ -0,0 +1,72 @@
|
|||
const Base = require('mocha/lib/reporters/base');
|
||||
const color = Base.color;
|
||||
|
||||
class EmbarkSpec extends Base {
|
||||
constructor(runner, options) {
|
||||
super(runner, options);
|
||||
|
||||
const self = this;
|
||||
self.embarkEvents = options.reporterOptions.events;
|
||||
let indents = 0;
|
||||
let n = 0;
|
||||
|
||||
function onContractReceipt(receipt) {
|
||||
console.log(receipt.className, receipt.gasUsed);
|
||||
}
|
||||
self.embarkEvents.on("deploy:contract:receipt", onContractReceipt);
|
||||
|
||||
function indent() {
|
||||
return Array(indents).join(' ');
|
||||
}
|
||||
|
||||
runner.on('start', function () {
|
||||
console.log();
|
||||
});
|
||||
|
||||
runner.on('suite', function (suite) {
|
||||
++indents;
|
||||
console.log(color('suite', '%s%s'), indent(), suite.title);
|
||||
});
|
||||
|
||||
runner.on('suite end', function () {
|
||||
--indents;
|
||||
if (indents === 1) {
|
||||
console.log();
|
||||
}
|
||||
});
|
||||
|
||||
runner.on('pending', function (test) {
|
||||
const fmt = indent() + color('pending', ' - %s');
|
||||
console.log(fmt, test.title);
|
||||
});
|
||||
|
||||
runner.on('pass', function (test) {
|
||||
let fmt;
|
||||
if (test.speed === 'fast') {
|
||||
fmt =
|
||||
indent() +
|
||||
color('checkmark', ' ' + Base.symbols.ok) +
|
||||
color('pass', ' %s');
|
||||
console.log(fmt, test.title);
|
||||
} else {
|
||||
fmt =
|
||||
indent() +
|
||||
color('checkmark', ' ' + Base.symbols.ok) +
|
||||
color('pass', ' %s') +
|
||||
color(test.speed, ' (%dms)');
|
||||
console.log(fmt, test.title, test.duration);
|
||||
}
|
||||
});
|
||||
|
||||
runner.on('fail', function (test) {
|
||||
console.log(indent() + color('fail', ' %d) %s'), ++n, test.title);
|
||||
});
|
||||
|
||||
runner.once('end', function() {
|
||||
self.embarkEvents.removeListener("deploy:contract:receipt", onContractReceipt);
|
||||
self.epilogue();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = EmbarkSpec;
|
|
@ -4,6 +4,7 @@ const Mocha = require('mocha');
|
|||
const path = require('path');
|
||||
const assert = require('assert');
|
||||
const Test = require('./test');
|
||||
const EmbarkSpec = require('./reporter');
|
||||
|
||||
function getFilesFromDir(filePath, cb) {
|
||||
fs.readdir(filePath, (err, files) => {
|
||||
|
@ -100,6 +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.addFile(file);
|
||||
|
||||
mocha.suite.timeout(0);
|
||||
|
|
Loading…
Reference in New Issue