Setup coverage to listen to the test embark events

This allows us to catch an event to know when the tests are done running. In turn, this will tell us when to save the coverage file and run the report.
This commit is contained in:
Andre Medeiros 2018-09-14 16:31:40 -04:00
parent d8becfe54f
commit a8a9f3e9a8
2 changed files with 20 additions and 15 deletions

View File

@ -18,6 +18,10 @@ class CodeCoverage {
embark.events.on('contracts:run:solc', this.runSolc.bind(this));
embark.events.on('block:header', this.runSolc.bind(this));
// These events are emitted from a test-specific Embark instance, so we need to
// pull it in from global.
global.embark.events.on('tests:finished', this.updateCoverageReport.bind(this));
this.seenTransactions = {};
this.coverageReport = {};
this.contractSources = new ContractSources([]);
@ -36,9 +40,10 @@ class CodeCoverage {
this.contractSources.parseSolcOutput(output);
}
updateCoverageReport() {
updateCoverageReport(cb) {
fs.mkdirpSync(this.dotEmbarkPath);
fs.writeFileSync(this.coverageReportPath, JSON.stringify(this.coverageReport));
cb();
}
async runSolc(receipt) {
@ -60,8 +65,6 @@ class CodeCoverage {
for(let i in traces) {
this.coverageReport = this.contractSources.generateCodeCoverage(traces[i]);
}
this.updateCoverageReport();
}
}

View File

@ -130,18 +130,20 @@ module.exports = {
return next();
}
runCmd(`${fs.embarkPath('node_modules/.bin/istanbul')} report --root .embark --format html`,
{silent: false, exitOnError: false}, (err) => {
if (err) {
return next(err);
}
console.log(`Coverage report created. You can find it here: ${fs.dappPath('coverage/index.html')}\n`);
const opn = require('opn');
const _next = () => { next(); };
opn(fs.dappPath('coverage/index.html'), {wait: false})
.then(() => new Promise(resolve => setTimeout(resolve, 1000)))
.then(_next, _next);
});
global.embark.events.emit('tests:finished', function() {
runCmd(`${fs.embarkPath('node_modules/.bin/istanbul')} report --root .embark --format html`,
{silent: false, exitOnError: false}, (err) => {
if (err) {
return next(err);
}
console.log(`Coverage report created. You can find it here: ${fs.dappPath('coverage/index.html')}\n`);
const opn = require('opn');
const _next = () => { next(); };
opn(fs.dappPath('coverage/index.html'), {wait: false})
.then(() => new Promise(resolve => setTimeout(resolve, 1000)))
.then(_next, _next);
});
});
}
], (err) => {
if (err) {