@@ -5,10 +5,13 @@ describe("handleCliError", () => {
55 let exitSpy : ReturnType < typeof spyOn > ;
66 let errorSpy : ReturnType < typeof spyOn > ;
77 let originalIsTTY : boolean | undefined ;
8+ let lastExitCode : number | undefined ;
89
910 beforeEach ( ( ) => {
1011 originalIsTTY = process . stderr . isTTY ;
12+ lastExitCode = undefined ;
1113 exitSpy = spyOn ( process , "exit" ) . mockImplementation ( ( code ?: number ) => {
14+ lastExitCode = code ;
1215 // Bubble a sentinel error so tests can assert the exit while preventing the process from terminating.
1316 throw new Error ( "process.exit" ) ;
1417 } ) ;
@@ -24,6 +27,7 @@ describe("handleCliError", () => {
2427 test ( "prints json error when format is json" , ( ) => {
2528 expect ( ( ) => handleCliError ( new Error ( "boom" ) , "json" ) ) . toThrow ( "process.exit" ) ;
2629 expect ( exitSpy ) . toHaveBeenCalledWith ( 1 ) ;
30+ expect ( lastExitCode ) . toBe ( 1 ) ;
2731 expect ( errorSpy ) . toHaveBeenCalledWith ( JSON . stringify ( { error : { message : "boom" } } ) ) ;
2832 } ) ;
2933
@@ -32,6 +36,7 @@ describe("handleCliError", () => {
3236
3337 expect ( ( ) => handleCliError ( new Error ( "oops" ) , "tui" ) ) . toThrow ( "process.exit" ) ;
3438 expect ( exitSpy ) . toHaveBeenCalledWith ( 1 ) ;
39+ expect ( lastExitCode ) . toBe ( 1 ) ;
3540 expect ( errorSpy ) . toHaveBeenCalledWith ( "Error: oops" ) ;
3641 } ) ;
3742
@@ -40,6 +45,7 @@ describe("handleCliError", () => {
4045
4146 expect ( ( ) => handleCliError ( new Error ( "boxed" ) , "tui" ) ) . toThrow ( "process.exit" ) ;
4247 expect ( exitSpy ) . toHaveBeenCalledWith ( 1 ) ;
48+ expect ( lastExitCode ) . toBe ( 1 ) ;
4349 const output = errorSpy . mock . calls . map ( ( call ) => call [ 0 ] ) . join ( "" ) ;
4450 expect ( output ) . toContain ( "boxed" ) ;
4551 expect ( output ) . toContain ( "Error" ) ;
0 commit comments