@@ -7,7 +7,7 @@ var path = require("path")
77 , testdir = __dirname
88 , fs = require ( "graceful-fs" )
99 , npmpkg = path . dirname ( testdir )
10- , npmcli = path . join ( __dirname , "bin" , "npm-cli.js" )
10+ , npmcli = path . resolve ( npmpkg , "bin" , "npm-cli.js" )
1111
1212var temp = process . env . TMPDIR
1313 || process . env . TMP
@@ -63,7 +63,7 @@ function prefix (content, pref) {
6363}
6464
6565var execCount = 0
66- function exec ( cmd , shouldFail , cb ) {
66+ function exec ( cmd , cwd , shouldFail , cb ) {
6767 if ( typeof shouldFail === "function" ) {
6868 cb = shouldFail , shouldFail = false
6969 }
@@ -81,7 +81,7 @@ function exec (cmd, shouldFail, cb) {
8181 cmd = cmd . replace ( / ^ n p m / , npmReplace + " " )
8282 cmd = cmd . replace ( / ^ n o d e / , nodeReplace + " " )
8383
84- child_process . exec ( cmd , { env : env } , function ( er , stdout , stderr ) {
84+ child_process . exec ( cmd , { cwd : cwd , env : env } , function ( er , stdout , stderr ) {
8585 if ( stdout ) {
8686 console . error ( prefix ( stdout , " 1> " ) )
8787 }
@@ -102,10 +102,8 @@ function exec (cmd, shouldFail, cb) {
102102}
103103
104104function execChain ( cmds , cb ) {
105- chain ( cmds . reduce ( function ( l , r ) {
106- return l . concat ( r )
107- } , [ ] ) . map ( function ( cmd ) {
108- return [ exec , cmd ]
105+ chain ( cmds . map ( function ( args ) {
106+ return [ exec ] . concat ( args )
109107 } ) , cb )
110108}
111109
@@ -118,9 +116,8 @@ function flatten (arr) {
118116function setup ( cb ) {
119117 cleanup ( function ( er ) {
120118 if ( er ) return cb ( er )
121- execChain ( [ "node \"" + path . resolve ( npmpkg , "bin" , "npm-cli.js" )
122- + "\" install \"" + npmpkg + "\""
123- , "npm config set package-config:foo boo"
119+ execChain ( [ [ "node \"" + npmcli + "\" install \"" + npmpkg + "\"" , root ] ,
120+ [ "npm config set package-config:foo boo" , root ]
124121 ] , cb )
125122 } )
126123}
@@ -134,6 +131,7 @@ function main (cb) {
134131 failures = 0
135132
136133 process . chdir ( testdir )
134+ var base = path . resolve ( root , path . join ( "lib" , "node_modules" ) )
137135
138136 // get the list of packages
139137 var packages = fs . readdirSync ( path . resolve ( testdir , "packages" ) )
@@ -150,17 +148,17 @@ function main (cb) {
150148 packagesToRm . push ( "npm" )
151149 }
152150
153- chain
154- ( [ setup
155- , [ exec , "npm install " + npmpkg ]
151+ chain (
152+ [ setup
153+ , [ exec , "npm install " + npmpkg , testdir ]
156154 , [ execChain , packages . map ( function ( p ) {
157- return "npm install packages/" + p
155+ return [ "npm install packages/" + p , testdir ]
158156 } ) ]
159157 , [ execChain , packages . map ( function ( p ) {
160- return "npm test " + p
158+ return [ "npm test" , path . resolve ( base , p ) ]
161159 } ) ]
162160 , [ execChain , packagesToRm . map ( function ( p ) {
163- return "npm rm " + p
161+ return [ "npm rm " + p , root ]
164162 } ) ]
165163 , installAndTestEach
166164 ]
@@ -171,15 +169,15 @@ function main (cb) {
171169 function installAndTestEach ( cb ) {
172170 var thingsToChain = [
173171 setup
174- , [ execChain , packages . map ( function ( p ) {
175- return [ "npm install packages/" + p
176- , "npm test " + p
177- , "npm rm " + p ]
178- } ) ]
172+ , [ execChain , flatten ( packages . map ( function ( p ) {
173+ return [ [ "npm install packages/" + p , testdir ]
174+ , [ "npm test" , path . resolve ( base , p ) ]
175+ , [ "npm rm " + p , root ] ]
176+ } ) ) ]
179177 ]
180178 if ( process . platform !== "win32" ) {
181179 // Windows can't handle npm rm npm due to file-in-use issues.
182- thingsToChain . push ( [ exec , "npm rm npm" ] )
180+ thingsToChain . push ( [ exec , "npm rm npm" , testdir ] )
183181 }
184182
185183 chain ( thingsToChain , cb )
0 commit comments