@@ -41,7 +41,7 @@ test('when subcommand executable not executable (EACCES) then throw custom messa
41
41
spawnSpy . mockRestore ( ) ;
42
42
} ) ;
43
43
44
- test ( 'when subcommand executable fails with other error then return in custom wrapper' , ( ) => {
44
+ test ( 'when subcommand executable fails with other error and exitOverride then return in custom wrapper' , ( ) => {
45
45
// The existing behaviour is to just silently fail for unexpected errors, as it is happening
46
46
// asynchronously in spawned process and client can not catch errors.
47
47
const mockProcess = new EventEmitter ( ) ;
@@ -62,3 +62,18 @@ test('when subcommand executable fails with other error then return in custom wr
62
62
expect ( caughtErr . nestedError . code ) . toEqual ( 'OTHER' ) ;
63
63
spawnSpy . mockRestore ( ) ;
64
64
} ) ;
65
+
66
+ test ( 'when subcommand executable fails with other error then exit' , ( ) => {
67
+ // The existing behaviour is to just silently fail for unexpected errors, as it is happening
68
+ // asynchronously in spawned process and client can not catch errors.
69
+ const mockProcess = new EventEmitter ( ) ;
70
+ const spawnSpy = jest . spyOn ( childProcess , 'spawn' ) . mockImplementation ( ( ) => { return mockProcess ; } ) ;
71
+ const exitSpy = jest . spyOn ( process , 'exit' ) . mockImplementation ( ( ) => { } ) ;
72
+ const program = new commander . Command ( ) ;
73
+ program . command ( 'executable' , 'executable description' ) ;
74
+ program . parse ( [ 'executable' ] , { from : 'user' } ) ;
75
+ mockProcess . emit ( 'error' , makeSystemError ( 'OTHER' ) ) ;
76
+ expect ( exitSpy ) . toHaveBeenCalledWith ( 1 ) ;
77
+ exitSpy . mockRestore ( ) ;
78
+ spawnSpy . mockRestore ( ) ;
79
+ } ) ;
0 commit comments