Merge pull request #835 from embark-framework/fix-coverage-timing
Update coverage report after suite
This commit is contained in:
commit
e3273b7867
|
@ -1,6 +1,4 @@
|
||||||
/*global web3*/
|
/*global web3*/
|
||||||
const process = require('process');
|
|
||||||
|
|
||||||
const fs = require('../../core/fs');
|
const fs = require('../../core/fs');
|
||||||
const ContractSources = require('./contract_sources');
|
const ContractSources = require('./contract_sources');
|
||||||
|
|
||||||
|
@ -20,16 +18,16 @@ class CodeCoverage {
|
||||||
embark.events.on('contracts:run:solc', this.runSolc.bind(this));
|
embark.events.on('contracts:run:solc', this.runSolc.bind(this));
|
||||||
embark.events.on('block:header', 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.seenTransactions = {};
|
||||||
this.coverageReport = {};
|
this.coverageReport = {};
|
||||||
this.contractSources = new ContractSources([]);
|
this.contractSources = new ContractSources([]);
|
||||||
|
|
||||||
var self = this;
|
this.dotEmbarkPath = fs.dappPath('.embark');
|
||||||
|
this.coverageReportPath = fs.dappPath('.embark', 'coverage.json');
|
||||||
process.on('exit', (_code) => {
|
|
||||||
const coverageReportPath = fs.dappPath('.embark', 'coverage.json');
|
|
||||||
fs.writeFileSync(coverageReportPath, JSON.stringify(self.coverageReport));
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
compileSolc(input) {
|
compileSolc(input) {
|
||||||
|
@ -42,6 +40,12 @@ class CodeCoverage {
|
||||||
this.contractSources.parseSolcOutput(output);
|
this.contractSources.parseSolcOutput(output);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
updateCoverageReport(cb) {
|
||||||
|
fs.mkdirp(this.dotEmbarkPath, () => {
|
||||||
|
fs.writeFile(this.coverageReportPath, JSON.stringify(this.coverageReport), cb);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
async runSolc(receipt) {
|
async runSolc(receipt) {
|
||||||
let block = await web3.eth.getBlock(receipt.number);
|
let block = await web3.eth.getBlock(receipt.number);
|
||||||
if(block.transactions.length == 0) return;
|
if(block.transactions.length == 0) return;
|
||||||
|
|
|
@ -130,18 +130,20 @@ module.exports = {
|
||||||
return next();
|
return next();
|
||||||
}
|
}
|
||||||
|
|
||||||
runCmd(`${fs.embarkPath('node_modules/.bin/istanbul')} report --root .embark --format html`,
|
global.embark.events.emit('tests:finished', function() {
|
||||||
{silent: false, exitOnError: false}, (err) => {
|
runCmd(`${fs.embarkPath('node_modules/.bin/istanbul')} report --root .embark --format html`,
|
||||||
if (err) {
|
{silent: false, exitOnError: false}, (err) => {
|
||||||
return next(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');
|
console.log(`Coverage report created. You can find it here: ${fs.dappPath('coverage/index.html')}\n`);
|
||||||
const _next = () => { next(); };
|
const opn = require('opn');
|
||||||
opn(fs.dappPath('coverage/index.html'), {wait: false})
|
const _next = () => { next(); };
|
||||||
.then(() => new Promise(resolve => setTimeout(resolve, 1000)))
|
opn(fs.dappPath('coverage/index.html'), {wait: false})
|
||||||
.then(_next, _next);
|
.then(() => new Promise(resolve => setTimeout(resolve, 1000)))
|
||||||
});
|
.then(_next, _next);
|
||||||
|
});
|
||||||
|
});
|
||||||
}
|
}
|
||||||
], (err) => {
|
], (err) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
|
|
Loading…
Reference in New Issue