From f9ddd876e91da271ef32dcb37627430a19640b2b Mon Sep 17 00:00:00 2001 From: Marcin Rudolf Date: Fri, 29 Sep 2017 16:54:36 +0200 Subject: [PATCH] reads trace file line by line --- lib/app.js | 59 ++++++++++++++++++++++++++++++------------------------ 1 file changed, 33 insertions(+), 26 deletions(-) diff --git a/lib/app.js b/lib/app.js index c467553..8ffdec1 100644 --- a/lib/app.js +++ b/lib/app.js @@ -2,6 +2,7 @@ const shell = require('shelljs'); const fs = require('fs'); const path = require('path'); const childprocess = require('child_process'); +const readline = require('readline'); const reqCwd = require('req-cwd'); const istanbul = require('istanbul'); const getInstrumentedVersion = require('./instrumentSolidity.js'); @@ -184,14 +185,6 @@ class App { shell.exec(command); this.testsErrored = shell.error(); shell.cd('./..'); - } catch (err) { - this.cleanUp(err); - } - - // Get events fired during instrumented contracts execution. - try { - this.events = fs.readFileSync('./allFiredEvents').toString().split('\n'); - this.events.pop(); } catch (err) { const msg = ` @@ -212,25 +205,39 @@ class App { const reporter = new istanbul.Reporter(); return new Promise((resolve, reject) => { - try { - this.coverage.generate(this.events, `${this.workingDir}/contracts`); - - const json = JSON.stringify(this.coverage.coverage); - fs.writeFileSync('./coverage.json', json); - - collector.add(this.coverage.coverage); - reporter.add('html'); - reporter.add('lcov'); - reporter.add('text'); - reporter.write(collector, true, () => { - this.log('Istanbul coverage reports generated'); - this.cleanUp(); - resolve(); + // Get events fired during instrumented contracts execution. + const stream = fs.createReadStream(`./allFiredEvents`); + stream.on('error', err => this.cleanUp('Event trace could not be read.\n' + err)); + const reader = readline.createInterface({ + input: stream, + }); + this.events = []; + reader + .on('line', line => this.events.push(line)) + .on('close', () => { + // Generate Istanbul report + try { + // console.log(`got ${this.events.length} events`); + this.coverage.generate(this.events, `${this.workingDir}/contracts`); + + const json = JSON.stringify(this.coverage.coverage); + fs.writeFileSync('./coverage.json', json); + + collector.add(this.coverage.coverage); + reporter.add('html'); + reporter.add('lcov'); + reporter.add('text'); + reporter.write(collector, true, () => { + this.log('Istanbul coverage reports generated'); + this.cleanUp(); + resolve(); + }); + } catch (err) { + const msg = 'There was a problem generating the coverage map / running Istanbul.\n'; + console.log(err.stack); + this.cleanUp(msg + err); + } }); - } catch (err) { - const msg = 'There was a problem generating the coverage map / running Istanbul.\n'; - this.cleanUp(msg + err); - } }); }