diff --git a/lib/modules/coverage/index.js b/lib/modules/coverage/index.js index a9070a1d..a7dbbb7d 100644 --- a/lib/modules/coverage/index.js +++ b/lib/modules/coverage/index.js @@ -24,12 +24,8 @@ class CodeCoverage { 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 +38,11 @@ class CodeCoverage { this.contractSources.parseSolcOutput(output); } + updateCoverageReport() { + fs.mkdirpSync(this.dotEmbarkPath); + fs.writeFileSync(this.coverageReportPath, JSON.stringify(this.coverageReport)); + } + async runSolc(receipt) { let block = await web3.eth.getBlock(receipt.number); if(block.transactions.length == 0) return; @@ -61,6 +62,8 @@ class CodeCoverage { for(let i in traces) { this.coverageReport = this.contractSources.generateCodeCoverage(traces[i]); } + + this.updateCoverageReport(); } }