@@ -32,19 +32,32 @@ const testdirHelper = (obj) => {
3232}
3333
3434const getSpawnArgs = async ( ) => {
35- const cliBin = join ( 'bin' , 'npm-cli.js' )
35+ const cliBin = join ( 'bin' , 'npm' )
36+ const cliJsBin = join ( 'bin' , 'npm-cli.js' )
37+ const npmLinks = await which ( 'npm' , { all : true } )
38+ const npmPaths = await Promise . all ( npmLinks . map ( npm => fs . realpath ( npm ) ) )
39+
40+ const cleanNpmPaths = [ ...new Set ( [
41+ CLI_ROOT ,
42+ join ( CLI_ROOT , cliBin ) ,
43+ join ( CLI_ROOT , cliJsBin ) ,
44+ ...npmLinks ,
45+ ...npmPaths ,
46+ ...npmPaths . map ( n => n . replace ( sep + cliBin , '' ) ) ,
47+ ...npmPaths . map ( n => n . replace ( sep + cliJsBin , '' ) ) ,
48+ ] ) ]
3649
3750 if ( SMOKE_PUBLISH_NPM ) {
3851 return {
3952 command : [ 'npm' ] ,
40- NPM : await which ( 'npm' ) . then ( p => fs . realpath ( p ) . replace ( sep + cliBin ) ) ,
53+ NPM : cleanNpmPaths ,
4154 }
4255 }
4356
4457 return {
45- command : [ process . execPath , join ( CLI_ROOT , cliBin ) ] ,
58+ command : [ process . execPath , join ( CLI_ROOT , cliJsBin ) ] ,
4659 NODE : process . execPath ,
47- NPM : join ( CLI_ROOT , cliBin ) ,
60+ NPM : cleanNpmPaths ,
4861 }
4962}
5063
@@ -87,17 +100,24 @@ module.exports = async (t, { testdir = {}, debug } = {}) => {
87100 t . strictSame ( registry . nock . activeMocks ( ) , [ ] , 'no active mocks after each' )
88101 } )
89102
90- const { command, ...spawnPaths } = await getSpawnArgs ( )
91- const cleanPaths = Object . entries ( { ...spawnPaths , CWD : CLI_ROOT } )
103+ const debugLog = debug || CI ? ( ...a ) => console . error ( ...a ) : ( ) => { }
104+ const { command, ...spawnPaths } = await getSpawnArgs ( { log : debugLog } )
105+ const cleanPaths = Object . entries ( spawnPaths )
92106
93107 const cleanOutput = s => {
94108 // sometimes we print normalized paths in snapshots regardless of
95109 // platform so replace those first then replace platform style paths
96110 for ( const [ key , value ] of cleanPaths ) {
97- s = s . split ( normalizePath ( value ) ) . join ( `{${ key } }` )
111+ const values = [ ] . concat ( value )
112+ for ( const v of values ) {
113+ s = s . split ( normalizePath ( v ) ) . join ( `{${ key } }` )
114+ }
98115 }
99116 for ( const [ key , value ] of cleanPaths ) {
100- s = s . split ( value ) . join ( `{${ key } }` )
117+ const values = [ ] . concat ( value )
118+ for ( const v of values ) {
119+ s = s . split ( v ) . join ( `{${ key } }` )
120+ }
101121 }
102122 return s
103123 . split ( relative ( CLI_ROOT , t . testdirName ) ) . join ( '{TESTDIR}' )
@@ -110,7 +130,7 @@ module.exports = async (t, { testdir = {}, debug } = {}) => {
110130 . replace ( / ^ .* d e b u g - [ 0 - 9 ] + .l o g $ / gm, '' )
111131 . replace ( / i n \d + m s $ / gm, 'in {TIME}' )
112132 }
113- const log = debug || CI ? ( ...a ) => console . error ( cleanOutput ( a . join ( ' ' ) ) ) : ( ) => { }
133+ const log = ( ...a ) => debugLog ( cleanOutput ( a . join ( ' ' ) ) )
114134 t . cleanSnapshot = cleanOutput
115135
116136 const npm = async ( ...args ) => {
0 commit comments