@@ -3,6 +3,7 @@ const fs = require('fs');
33const shell = require ( 'shelljs' ) ;
44const mock = require ( '../util/integration.truffle' ) ;
55const plugin = require ( '../../dist/truffle.plugin' ) ;
6+ const path = require ( 'path' )
67const util = require ( 'util' )
78const opts = { compact : false , depth : 5 , breakLength : 80 } ;
89
@@ -16,18 +17,21 @@ function assertCleanInitialState(){
1617 assert ( pathExists ( './coverage.json' ) === false , 'should start without: coverage.json' ) ;
1718}
1819
19- function assertCoverageGenerated ( ) {
20+ function assertCoverageGenerate ( truffleConfig ) {
21+ const jsonPath = path . join ( truffleConfig . working_directory , "coverage.json" ) ;
2022 assert ( pathExists ( './coverage' ) === true , 'should gen coverage folder' ) ;
21- assert ( pathExists ( './coverage.json' ) === true , 'should gen coverage.json' ) ;
23+ assert ( pathExists ( jsonPath ) === true , 'should gen coverage.json' ) ;
2224}
2325
24- function assertCoverageNotGenerated ( ) {
26+ function assertCoverageNotGenerated ( truffleConfig ) {
27+ const jsonPath = path . join ( truffleConfig . working_directory , "coverage.json" ) ;
2528 assert ( pathExists ( './coverage' ) !== true , 'should NOT gen coverage folder' ) ;
26- assert ( pathExists ( './coverage.json' ) !== true , 'should NOT gen coverage.json' ) ;
29+ assert ( pathExists ( jsonPath ) !== true , 'should NOT gen coverage.json' ) ;
2730}
2831
29- function getOutput ( ) {
30- return JSON . parse ( fs . readFileSync ( './coverage.json' , 'utf8' ) ) ;
32+ function getOutput ( truffleConfig ) {
33+ const jsonPath = path . join ( truffleConfig . working_directory , "coverage.json" ) ;
34+ return JSON . parse ( fs . readFileSync ( jsonPath , 'utf8' ) ) ;
3135}
3236
3337// ========
@@ -54,9 +58,9 @@ describe('app', function() {
5458 mock . install ( 'Simple' , 'simple.js' , solcoverConfig ) ;
5559 await plugin ( truffleConfig ) ;
5660
57- assertCoverageGenerated ( ) ;
61+ assertCoverageGenerate ( truffleConfig ) ;
5862
59- const output = getOutput ( ) ;
63+ const output = getOutput ( truffleConfig ) ;
6064 const path = Object . keys ( output ) [ 0 ] ;
6165
6266 assert ( output [ path ] . fnMap [ '1' ] . name === 'test' , 'coverage.json missing "test"' ) ;
@@ -92,7 +96,7 @@ describe('app', function() {
9296 await plugin ( truffleConfig ) ;
9397 } ) ;
9498
95- it . skip ( 'project with node_modules packages and relative path solidity imports' , async function ( ) {
99+ it ( 'project with node_modules packages and relative path solidity imports' , async function ( ) {
96100 assertCleanInitialState ( ) ;
97101 mock . installFullProject ( 'import-paths' ) ;
98102 await plugin ( truffleConfig ) ;
@@ -105,9 +109,9 @@ describe('app', function() {
105109 mock . install ( 'OnlyCall' , 'only-call.js' , solcoverConfig ) ;
106110 await plugin ( truffleConfig ) ;
107111
108- assertCoverageGenerated ( ) ;
112+ assertCoverageGenerate ( truffleConfig ) ;
109113
110- const output = getOutput ( ) ;
114+ const output = getOutput ( truffleConfig ) ;
111115 const path = Object . keys ( output ) [ 0 ] ;
112116 assert ( output [ path ] . fnMap [ '1' ] . name === 'addTwo' , 'cov should map "addTwo"' ) ;
113117 } ) ;
@@ -118,9 +122,9 @@ describe('app', function() {
118122 mock . install ( 'Wallet' , 'wallet.js' , solcoverConfig ) ;
119123 await plugin ( truffleConfig ) ;
120124
121- assertCoverageGenerated ( ) ;
125+ assertCoverageGenerate ( truffleConfig ) ;
122126
123- const output = getOutput ( ) ;
127+ const output = getOutput ( truffleConfig ) ;
124128 const path = Object . keys ( output ) [ 0 ] ;
125129 assert ( output [ path ] . fnMap [ '1' ] . name === 'transferPayment' , 'cov should map "transferPayment"' ) ;
126130 } ) ;
@@ -133,9 +137,9 @@ describe('app', function() {
133137 mock . installDouble ( [ 'Proxy' , 'Owned' ] , 'inheritance.js' , solcoverConfig ) ;
134138 await plugin ( truffleConfig ) ;
135139
136- assertCoverageGenerated ( ) ;
140+ assertCoverageGenerate ( truffleConfig ) ;
137141
138- const output = getOutput ( ) ;
142+ const output = getOutput ( truffleConfig ) ;
139143 const firstKey = Object . keys ( output ) [ 0 ] ;
140144 assert ( Object . keys ( output ) . length === 1 , 'Wrong # of contracts covered' ) ;
141145 assert ( firstKey . substr ( firstKey . length - 9 ) === 'Proxy.sol' , 'Wrong contract covered' ) ;
@@ -147,9 +151,9 @@ describe('app', function() {
147151 mock . installDouble ( [ 'Proxy' , 'Owned' ] , 'inheritance.js' , solcoverConfig ) ;
148152 await plugin ( truffleConfig ) ;
149153
150- assertCoverageGenerated ( ) ;
154+ assertCoverageGenerate ( truffleConfig ) ;
151155
152- const output = getOutput ( ) ;
156+ const output = getOutput ( truffleConfig ) ;
153157 const ownedPath = Object . keys ( output ) [ 0 ] ;
154158 const proxyPath = Object . keys ( output ) [ 1 ] ;
155159 assert ( output [ ownedPath ] . fnMap [ '1' ] . name === 'constructor' , '"constructor" not covered' ) ;
@@ -169,9 +173,9 @@ describe('app', function() {
169173 assert ( err . message . includes ( 'failed under coverage' ) ) ;
170174 }
171175
172- assertCoverageGenerated ( ) ;
176+ assertCoverageGenerate ( truffleConfig ) ;
173177
174- const output = getOutput ( ) ;
178+ const output = getOutput ( truffleConfig ) ;
175179 const path = Object . keys ( output ) [ 0 ] ;
176180
177181 assert ( output [ path ] . fnMap [ '1' ] . name === 'test' , 'cov missing "test"' ) ;
@@ -210,7 +214,7 @@ describe('app', function() {
210214 assert ( err . message . includes ( 'Compilation failed' ) ) ;
211215 }
212216
213- assertCoverageNotGenerated ( ) ;
217+ assertCoverageNotGenerated ( truffleConfig ) ;
214218 } ) ;
215219
216220} ) ;
0 commit comments