@@ -2,6 +2,7 @@ const shell = require('shelljs');
2
2
const fs = require ( 'fs' ) ;
3
3
const path = require ( 'path' ) ;
4
4
const childprocess = require ( 'child_process' ) ;
5
+ const readline = require ( 'readline' ) ;
5
6
const reqCwd = require ( 'req-cwd' ) ;
6
7
const istanbul = require ( 'istanbul' ) ;
7
8
const getInstrumentedVersion = require ( './instrumentSolidity.js' ) ;
@@ -184,14 +185,6 @@ class App {
184
185
shell . exec ( command ) ;
185
186
this . testsErrored = shell . error ( ) ;
186
187
shell . cd ( './..' ) ;
187
- } catch ( err ) {
188
- this . cleanUp ( err ) ;
189
- }
190
-
191
- // Get events fired during instrumented contracts execution.
192
- try {
193
- this . events = fs . readFileSync ( './allFiredEvents' ) . toString ( ) . split ( '\n' ) ;
194
- this . events . pop ( ) ;
195
188
} catch ( err ) {
196
189
const msg =
197
190
`
@@ -212,25 +205,39 @@ class App {
212
205
const reporter = new istanbul . Reporter ( ) ;
213
206
214
207
return new Promise ( ( resolve , reject ) => {
215
- try {
216
- this . coverage . generate ( this . events , `${ this . workingDir } /contracts` ) ;
217
-
218
- const json = JSON . stringify ( this . coverage . coverage ) ;
219
- fs . writeFileSync ( './coverage.json' , json ) ;
220
-
221
- collector . add ( this . coverage . coverage ) ;
222
- reporter . add ( 'html' ) ;
223
- reporter . add ( 'lcov' ) ;
224
- reporter . add ( 'text' ) ;
225
- reporter . write ( collector , true , ( ) => {
226
- this . log ( 'Istanbul coverage reports generated' ) ;
227
- this . cleanUp ( ) ;
228
- resolve ( ) ;
208
+ // Get events fired during instrumented contracts execution.
209
+ const stream = fs . createReadStream ( `./allFiredEvents` ) ;
210
+ stream . on ( 'error' , err => this . cleanUp ( 'Event trace could not be read.\n' + err ) ) ;
211
+ const reader = readline . createInterface ( {
212
+ input : stream ,
213
+ } ) ;
214
+ this . events = [ ] ;
215
+ reader
216
+ . on ( 'line' , line => this . events . push ( line ) )
217
+ . on ( 'close' , ( ) => {
218
+ // Generate Istanbul report
219
+ try {
220
+ // console.log(`got ${this.events.length} events`);
221
+ this . coverage . generate ( this . events , `${ this . workingDir } /contracts` ) ;
222
+
223
+ const json = JSON . stringify ( this . coverage . coverage ) ;
224
+ fs . writeFileSync ( './coverage.json' , json ) ;
225
+
226
+ collector . add ( this . coverage . coverage ) ;
227
+ reporter . add ( 'html' ) ;
228
+ reporter . add ( 'lcov' ) ;
229
+ reporter . add ( 'text' ) ;
230
+ reporter . write ( collector , true , ( ) => {
231
+ this . log ( 'Istanbul coverage reports generated' ) ;
232
+ this . cleanUp ( ) ;
233
+ resolve ( ) ;
234
+ } ) ;
235
+ } catch ( err ) {
236
+ const msg = 'There was a problem generating the coverage map / running Istanbul.\n' ;
237
+ console . log ( err . stack ) ;
238
+ this . cleanUp ( msg + err ) ;
239
+ }
229
240
} ) ;
230
- } catch ( err ) {
231
- const msg = 'There was a problem generating the coverage map / running Istanbul.\n' ;
232
- this . cleanUp ( msg + err ) ;
233
- }
234
241
} ) ;
235
242
}
236
243
0 commit comments