mirror of https://github.com/embarklabs/embark.git
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*/
|
||||
const process = require('process');
|
||||
|
||||
const fs = require('../../core/fs');
|
||||
const ContractSources = require('./contract_sources');
|
||||
|
||||
|
@ -20,16 +18,16 @@ 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([]);
|
||||
|
||||
var self = this;
|
||||
|
||||
process.on('exit', (_code) => {
|
||||
const coverageReportPath = fs.dappPath('.embark', 'coverage.json');
|
||||
fs.writeFileSync(coverageReportPath, JSON.stringify(self.coverageReport));
|
||||
});
|
||||
this.dotEmbarkPath = fs.dappPath('.embark');
|
||||
this.coverageReportPath = fs.dappPath('.embark', 'coverage.json');
|
||||
}
|
||||
|
||||
compileSolc(input) {
|
||||
|
@ -42,6 +40,12 @@ class CodeCoverage {
|
|||
this.contractSources.parseSolcOutput(output);
|
||||
}
|
||||
|
||||
updateCoverageReport(cb) {
|
||||
fs.mkdirp(this.dotEmbarkPath, () => {
|
||||
fs.writeFile(this.coverageReportPath, JSON.stringify(this.coverageReport), cb);
|
||||
});
|
||||
}
|
||||
|
||||
async runSolc(receipt) {
|
||||
let block = await web3.eth.getBlock(receipt.number);
|
||||
if(block.transactions.length == 0) return;
|
||||
|
|
|
@ -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) {
|
||||
|
|
Loading…
Reference in New Issue