|
|
|
@ -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); |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|