@@ -266,28 +266,25 @@ describe('cli', () => {
266
266
test ( 'executes a script from $PATH' , async ( ) => {
267
267
const isWindows = process . platform === 'win32'
268
268
const oldPath = process . env . PATH
269
-
270
- const envPathSeparator = isWindows ? ';' : ':'
271
- const dir = tmpdir ( )
272
- process . env . PATH += envPathSeparator + dir
273
-
274
269
const toPOSIXPath = ( _path ) => _path . split ( path . sep ) . join ( path . posix . sep )
275
270
276
271
const zxPath = path . resolve ( './build/cli.js' )
277
272
const zxLocation = isWindows ? toPOSIXPath ( zxPath ) : zxPath
278
- const scriptName = 'script-from-path'
279
273
const scriptCode = `#!/usr/bin/env ${ zxLocation } \nconsole.log('The script from path runs.')`
280
- const scriptPath = path . join ( dir , scriptName )
274
+ const scriptName = 'script-from-path'
275
+ const scriptFile = tmpfile ( scriptName , scriptCode )
276
+ const scriptDir = path . dirname ( scriptFile )
277
+ fs . chmodSync ( scriptFile , 0o744 )
278
+
279
+ const envPathSeparator = isWindows ? ';' : ':'
280
+ process . env . PATH += envPathSeparator + scriptDir
281
281
282
282
try {
283
283
await $ `chmod +x ${ zxLocation } `
284
- await $ `echo ${ scriptCode } ` . pipe (
285
- fs . createWriteStream ( scriptPath , { mode : 0o744 } )
286
- )
287
284
await $ `${ scriptName } `
288
285
} finally {
289
286
process . env . PATH = oldPath
290
- fs . rmSync ( scriptPath )
287
+ await fs . rm ( scriptFile )
291
288
}
292
289
} )
293
290
0 commit comments