1
1
const t = require ( 'tap' )
2
2
const { spawnSync } = require ( 'child_process' )
3
- const { resolve, join, extname, basename } = require ( 'path' )
3
+ const { resolve, join, extname, basename, sep } = require ( 'path' )
4
4
const { readFileSync, chmodSync, readdirSync } = require ( 'fs' )
5
5
const Diff = require ( 'diff' )
6
6
const { sync : which } = require ( 'which' )
@@ -18,6 +18,12 @@ const SHIMS = readdirSync(BIN).reduce((acc, shim) => {
18
18
19
19
const SHIM_EXTS = [ ...new Set ( Object . keys ( SHIMS ) . map ( p => extname ( p ) ) ) ]
20
20
21
+ // windows requires each segment of a command path to be quoted when using shell: true
22
+ const quotePath = ( cmd ) => cmd
23
+ . split ( sep )
24
+ . map ( p => p . includes ( ' ' ) ? `"${ p } "` : p )
25
+ . join ( sep )
26
+
21
27
t . test ( 'shim contents' , t => {
22
28
// these scripts should be kept in sync so this tests the contents of each
23
29
// and does a diff to ensure the only differences between them are necessary
@@ -49,6 +55,13 @@ t.test('shim contents', t => {
49
55
t . strictSame ( [ ...letters ] , [ 'M' , 'X' ] , 'all other changes are m->x' )
50
56
t . end ( )
51
57
} )
58
+
59
+ t . test ( 'pwsh' , t => {
60
+ const { diff, letters } = diffFiles ( SHIMS [ 'npm.ps1' ] , SHIMS [ 'npx.ps1' ] )
61
+ t . equal ( diff . length , 0 )
62
+ t . strictSame ( [ ...letters ] , [ 'M' , 'X' ] , 'all other changes are m->x' )
63
+ t . end ( )
64
+ } )
52
65
} )
53
66
54
67
t . test ( 'run shims' , t => {
@@ -133,6 +146,7 @@ t.test('run shims', t => {
133
146
134
147
const shells = Object . entries ( {
135
148
cmd : 'cmd' ,
149
+ pwsh : 'pwsh' ,
136
150
git : join ( ProgramFiles , 'Git' , 'bin' , 'bash.exe' ) ,
137
151
'user git' : join ( ProgramFiles , 'Git' , 'usr' , 'bin' , 'bash.exe' ) ,
138
152
wsl : join ( SystemRoot , 'System32' , 'bash.exe' ) ,
@@ -197,6 +211,11 @@ t.test('run shims', t => {
197
211
case 'bash.exe' :
198
212
args . push ( bin )
199
213
break
214
+ case 'pwsh.exe' :
215
+ cmd = quotePath ( cmd )
216
+ args . push ( `${ bin } .ps1` )
217
+ opts . shell = true
218
+ break
200
219
default :
201
220
throw new Error ( 'unknown shell' )
202
221
}
0 commit comments