11const t = require ( 'tap' )
22const { spawnSync } = require ( 'child_process' )
3- const { resolve, join, extname, basename } = require ( 'path' )
3+ const { resolve, join, extname, basename, sep } = require ( 'path' )
44const { readFileSync, chmodSync, readdirSync } = require ( 'fs' )
55const Diff = require ( 'diff' )
66const { sync : which } = require ( 'which' )
@@ -18,6 +18,12 @@ const SHIMS = readdirSync(BIN).reduce((acc, shim) => {
1818
1919const SHIM_EXTS = [ ...new Set ( Object . keys ( SHIMS ) . map ( p => extname ( p ) ) ) ]
2020
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+
2127t . test ( 'shim contents' , t => {
2228 // these scripts should be kept in sync so this tests the contents of each
2329 // and does a diff to ensure the only differences between them are necessary
@@ -49,6 +55,13 @@ t.test('shim contents', t => {
4955 t . strictSame ( [ ...letters ] , [ 'M' , 'X' ] , 'all other changes are m->x' )
5056 t . end ( )
5157 } )
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+ } )
5265} )
5366
5467t . test ( 'run shims' , t => {
@@ -197,6 +210,11 @@ t.test('run shims', t => {
197210 case 'bash.exe' :
198211 args . push ( bin )
199212 break
213+ case 'pwsh.exe' :
214+ cmd = quotePath ( cmd )
215+ args . push ( `${ bin } .ps1` )
216+ opts . shell = true
217+ break
200218 default :
201219 throw new Error ( 'unknown shell' )
202220 }
0 commit comments