reads trace file line by line

pull/122/head
Marcin Rudolf 7 years ago
parent dfd6742c69
commit f9ddd876e9
  1. 23
      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,7 +205,19 @@ class App {
const reporter = new istanbul.Reporter();
return new Promise((resolve, reject) => {
// 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);
@ -229,9 +234,11 @@ class App {
});
} catch (err) {
const msg = 'There was a problem generating the coverage map / running Istanbul.\n';
console.log(err.stack);
this.cleanUp(msg + err);
}
});
});
}
// ------------------------------------------ Utils ----------------------------------------------

Loading…
Cancel
Save