@@ -32,19 +32,32 @@ const testdirHelper = (obj) => {
32
32
}
33
33
34
34
const 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
+ ] ) ]
36
49
37
50
if ( SMOKE_PUBLISH_NPM ) {
38
51
return {
39
52
command : [ 'npm' ] ,
40
- NPM : await which ( 'npm' ) . then ( p => fs . realpath ( p ) . replace ( sep + cliBin ) ) ,
53
+ NPM : cleanNpmPaths ,
41
54
}
42
55
}
43
56
44
57
return {
45
- command : [ process . execPath , join ( CLI_ROOT , cliBin ) ] ,
58
+ command : [ process . execPath , join ( CLI_ROOT , cliJsBin ) ] ,
46
59
NODE : process . execPath ,
47
- NPM : join ( CLI_ROOT , cliBin ) ,
60
+ NPM : cleanNpmPaths ,
48
61
}
49
62
}
50
63
@@ -87,17 +100,24 @@ module.exports = async (t, { testdir = {}, debug } = {}) => {
87
100
t . strictSame ( registry . nock . activeMocks ( ) , [ ] , 'no active mocks after each' )
88
101
} )
89
102
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 )
92
106
93
107
const cleanOutput = s => {
94
108
// sometimes we print normalized paths in snapshots regardless of
95
109
// platform so replace those first then replace platform style paths
96
110
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
+ }
98
115
}
99
116
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
+ }
101
121
}
102
122
return s
103
123
. split ( relative ( CLI_ROOT , t . testdirName ) ) . join ( '{TESTDIR}' )
@@ -110,7 +130,7 @@ module.exports = async (t, { testdir = {}, debug } = {}) => {
110
130
. replace ( / ^ .* d e b u g - [ 0 - 9 ] + .l o g $ / gm, '' )
111
131
. replace ( / i n \d + m s $ / gm, 'in {TIME}' )
112
132
}
113
- const log = debug || CI ? ( ...a ) => console . error ( cleanOutput ( a . join ( ' ' ) ) ) : ( ) => { }
133
+ const log = ( ...a ) => debugLog ( cleanOutput ( a . join ( ' ' ) ) )
114
134
t . cleanSnapshot = cleanOutput
115
135
116
136
const npm = async ( ...args ) => {
0 commit comments