@@ -32,7 +32,7 @@ run.methods.forEach((method) => {
3232 expect ( stdout . trim ( ) ) . toBe ( 'foo' ) ;
3333 } ) ;
3434
35- it ( 'should support shebang in executables with /usr/bin/env' , async ( ) => {
35+ it ( 'should support shebang in executables with ` /usr/bin/env` ' , async ( ) => {
3636 const { stdout : stdout1 } = await run ( method , `${ __dirname } /fixtures/shebang` ) ;
3737
3838 expect ( stdout1 ) . toBe ( 'shebang works!' ) ;
@@ -219,6 +219,26 @@ run.methods.forEach((method) => {
219219 expect ( stdout3 . trim ( ) ) . toBe ( 'foo' ) ;
220220 } ) ;
221221
222+ it ( 'should work with a relative posix path to a command with a custom `cwd`' , async ( ) => {
223+ const relativeTestPath = path . relative ( process . cwd ( ) , __dirname ) . replace ( / \\ / , '/' ) ;
224+
225+ const { stdout : stdout1 } = await run ( method , 'fixtures/say-foo' , { cwd : relativeTestPath } ) ;
226+
227+ expect ( stdout1 . trim ( ) ) . toBe ( 'foo' ) ;
228+
229+ const { stdout : stdout2 } = await run ( method , './fixtures/say-foo' , { cwd : `./${ relativeTestPath } ` } ) ;
230+
231+ expect ( stdout2 . trim ( ) ) . toBe ( 'foo' ) ;
232+
233+ if ( ! isWin ) {
234+ return ;
235+ }
236+
237+ const { stdout : stdout3 } = await run ( method , './fixtures/say-foo.bat' , { cwd : `./${ relativeTestPath } ` } ) ;
238+
239+ expect ( stdout3 . trim ( ) ) . toBe ( 'foo' ) ;
240+ } ) ;
241+
222242 {
223243 const assertError = ( err ) => {
224244 const syscall = run . isMethodSync ( method ) ? 'spawnSync' : 'spawn' ;
@@ -354,6 +374,45 @@ run.methods.forEach((method) => {
354374 } ) ;
355375 }
356376
377+ if ( run . isMethodSync ( method ) ) {
378+ it ( 'should fail with ENOENT a non-existing `cwd` was specified' , ( ) => {
379+ expect . assertions ( 1 ) ;
380+
381+ try {
382+ run ( method , 'fixtures/say-foo' , { cwd : 'somedirthatwillneverexist' } ) ;
383+ } catch ( err ) {
384+ expect ( err . code ) . toBe ( 'ENOENT' ) ;
385+ }
386+ } ) ;
387+ } else {
388+ it ( 'should emit `error` and `close` if a non-existing `cwd` was specified' , async ( ) => {
389+ expect . assertions ( 3 ) ;
390+
391+ await new Promise ( ( resolve , reject ) => {
392+ const promise = run ( method , 'somecommandthatwillneverexist' , [ 'foo' ] ) ;
393+ const { cp } = promise ;
394+
395+ promise . catch ( ( ) => { } ) ;
396+
397+ let timeout ;
398+
399+ cp
400+ . on ( 'error' , ( err ) => expect ( err . code ) . toBe ( 'ENOENT' ) )
401+ . on ( 'exit' , ( ) => {
402+ cp . removeAllListeners ( ) ;
403+ clearTimeout ( timeout ) ;
404+ reject ( new Error ( 'Should not emit exit' ) ) ;
405+ } )
406+ . on ( 'close' , ( code , signal ) => {
407+ expect ( code ) . not . toBe ( 0 ) ;
408+ expect ( signal ) . toBe ( null ) ;
409+
410+ timeout = setTimeout ( resolve , 1000 ) ;
411+ } ) ;
412+ } ) ;
413+ } ) ;
414+ }
415+
357416 if ( isWin ) {
358417 it ( 'should use nodejs\' spawn when options.shell is specified (windows)' , async ( ) => {
359418 const { stdout } = await run ( method , 'echo' , [ '%RANDOM%' ] , { shell : true } ) ;
0 commit comments