@@ -58,7 +58,7 @@ class App {
5858 * Generates a copy of the target project configured for solidity-coverage and saves to
5959 * the coverage environment folder. Process exits(1) if try fails
6060 */
61- generateCoverageEnvironment ( ) {
61+ async generateCoverageEnvironment ( ) {
6262 this . log ( 'Generating coverage environment' ) ;
6363
6464 try {
@@ -118,7 +118,7 @@ class App {
118118 shell . rm ( '-Rf' , `${ this . coverageDir } /build/contracts` )
119119 }
120120
121- this . runCompileCommand ( ) ;
121+ await this . runCompileCommand ( ) ;
122122 this . originalArtifacts = this . loadArtifacts ( ) ;
123123 shell . rm ( '-Rf' , `${ this . coverageDir } /build/contracts` ) ;
124124
@@ -136,7 +136,7 @@ class App {
136136 * + Save instrumented contract in the coverage environment folder where covered tests will run
137137 * + Add instrumentation info to the coverage map
138138 */
139- instrumentTarget ( ) {
139+ async instrumentTarget ( ) {
140140 this . skipFiles = this . skipFiles . map ( contract => `${ this . coverageDir } /contracts/${ contract } ` ) ;
141141 this . skipFiles . push ( `${ this . coverageDir } /contracts/Migrations.sol` ) ;
142142
@@ -162,7 +162,7 @@ class App {
162162 const msg = `There was a problem instrumenting ${ currentFile } : ` ;
163163 this . cleanUp ( msg + err ) ;
164164 }
165- this . postProcessPure ( this . coverageDir ) ;
165+ await this . postProcessPure ( this . coverageDir ) ;
166166 }
167167
168168 /**
@@ -191,32 +191,24 @@ class App {
191191 * Also reads the 'allFiredEvents' log.
192192 */
193193 async runTestCommand ( ) {
194-
195- let testCommand = require ( "truffle-core/lib/commands/test" ) ;
196- let options = { logger : console , network : 'coverage' , _ : [ ] } ;
197194
198- shell . cd ( this . coverageDir ) ;
195+ try {
196+ this . log ( `Running: truffle compile\n(this can take a few seconds)...` ) ;
199197
200- await new Promise ( ( resolve , reject ) => {
201- testCommand . run ( options , ( err , res ) => {
202- if ( err ) {
203- reject ( err ) ;
204- }
205- resolve ( res ) ;
206- } ) ;
207- } ) ;
198+ shell . cd ( this . coverageDir ) ;
208199
209- shell . cd ( './..' ) ;
200+ let testCommand = require ( "truffle-core/lib/commands/test" ) ;
201+ let options = { logger : console , network : 'coverage' , _ : [ ] } ;
210202
211- return ;
203+ await new Promise ( ( resolve , reject ) => {
204+ testCommand . run ( options , ( err , res ) => {
205+ if ( err ) {
206+ reject ( err ) ;
207+ }
208+ resolve ( res ) ;
209+ } ) ;
210+ } ) ;
212211
213- try {
214- const defaultCommand = `truffle test ${ this . network } ${ this . silence } ` ;
215- const command = this . testCommand || defaultCommand ;
216- this . log ( `Running: ${ command } \n(this can take a few seconds)...` ) ;
217- shell . cd ( this . coverageDir ) ;
218- shell . exec ( command ) ;
219- this . testsErrored = shell . error ( ) ;
220212 shell . cd ( './..' ) ;
221213 } catch ( err ) {
222214 const msg =
@@ -235,14 +227,25 @@ class App {
235227 * coverage environment folder. Shell cd command needs to be invoked
236228 * as its own statement for command line options to work, apparently.
237229 */
238- runCompileCommand ( ) {
230+ async runCompileCommand ( ) {
231+
239232 try {
240- const defaultCommand = `truffle compile ${ this . network } ${ this . silence } ` ;
241- const command = this . compileCommand || defaultCommand ;
242- this . log ( `Running: ${ command } \n(this can take a few seconds)...` ) ;
233+ // const defaultCommand = `truffle compile ${this.network} ${this.silence}`;
234+ // const command = this.compileCommand || defaultCommand;
235+ // this.log(`Running: ${command}\n(this can take a few seconds)...`);
243236 shell . cd ( this . coverageDir ) ;
244- shell . exec ( command ) ;
245- this . testsErrored = shell . error ( ) ;
237+
238+ let Config = require ( "truffle-config" ) ;
239+ let Contracts = require ( "truffle-workflow-compile" ) ;
240+ let config = Config . detect ( {
241+ logger : console ,
242+ network : 'coverage'
243+ } ) ;
244+ await new Promise ( resolve => Contracts . compile ( config , resolve ) ) ;
245+
246+ //shell.exec(command);
247+ //this.testsErrored = shell.error();
248+
246249 shell . cd ( './..' ) ;
247250 } catch ( err ) {
248251 const msg =
@@ -388,7 +391,7 @@ class App {
388391 * in the coverageEnv before the `contracts` folder is instrumented.
389392 * @param {String } env 'coverageEnv' presumably
390393 */
391- postProcessPure ( env ) {
394+ async postProcessPure ( env ) {
392395 shell . ls ( `${ env } /**/*.sol` ) . forEach ( file => {
393396 const contractPath = this . platformNeutralPath ( file ) ;
394397 const contract = fs . readFileSync ( contractPath ) . toString ( ) ;
@@ -403,7 +406,7 @@ class App {
403406 } ) ;
404407
405408 // First, compile the instrumented contracts
406- this . runCompileCommand ( ) ;
409+ await this . runCompileCommand ( ) ;
407410
408411 // Now swap the original abis into the instrumented artifacts so that truffle etc uses 'call'
409412 // on them.
0 commit comments