reads trace file line by line

pull/122/head
Marcin Rudolf 7 years ago
parent dfd6742c69
commit f9ddd876e9
  1. 59
      lib/app.js

@ -2,6 +2,7 @@ const shell = require('shelljs');
const fs = require('fs'); const fs = require('fs');
const path = require('path'); const path = require('path');
const childprocess = require('child_process'); const childprocess = require('child_process');
const readline = require('readline');
const reqCwd = require('req-cwd'); const reqCwd = require('req-cwd');
const istanbul = require('istanbul'); const istanbul = require('istanbul');
const getInstrumentedVersion = require('./instrumentSolidity.js'); const getInstrumentedVersion = require('./instrumentSolidity.js');
@ -184,14 +185,6 @@ class App {
shell.exec(command); shell.exec(command);
this.testsErrored = shell.error(); this.testsErrored = shell.error();
shell.cd('./..'); 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) { } catch (err) {
const msg = const msg =
` `
@ -212,25 +205,39 @@ class App {
const reporter = new istanbul.Reporter(); const reporter = new istanbul.Reporter();
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
try { // Get events fired during instrumented contracts execution.
this.coverage.generate(this.events, `${this.workingDir}/contracts`); const stream = fs.createReadStream(`./allFiredEvents`);
stream.on('error', err => this.cleanUp('Event trace could not be read.\n' + err));
const json = JSON.stringify(this.coverage.coverage); const reader = readline.createInterface({
fs.writeFileSync('./coverage.json', json); input: stream,
});
collector.add(this.coverage.coverage); this.events = [];
reporter.add('html'); reader
reporter.add('lcov'); .on('line', line => this.events.push(line))
reporter.add('text'); .on('close', () => {
reporter.write(collector, true, () => { // Generate Istanbul report
this.log('Istanbul coverage reports generated'); try {
this.cleanUp(); // console.log(`got ${this.events.length} events`);
resolve(); 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);
}
}); });
} }

Loading…
Cancel
Save