@@ -94,4 +94,47 @@ describe('installMainProcessFailureObservers', () => {
9494 await vi . waitFor ( ( ) => expect ( app . relaunch ) . toHaveBeenCalledOnce ( ) )
9595 expect ( app . exit ) . toHaveBeenCalledWith ( 1 )
9696 } )
97+
98+ function emitAppEvent ( event : string ) {
99+ const handler = vi . mocked ( app . on ) . mock . calls . find ( ( [ name ] ) => name === event ) ?. [ 1 ]
100+ if ( ! handler ) throw new Error ( `No ${ event } listener` )
101+ ; ( handler as ( ) => void ) ( )
102+ }
103+
104+ it ( 'exits without prompting when the failure arrives after quitting has begun' , ( ) => {
105+ const events = { filePath : '/tmp/events.log' , record : vi . fn ( ) }
106+ const { handlers, source } = createProcessSource ( )
107+ installMainProcessFailureObservers ( { events, getWindow : ( ) => null , processSource : source } )
108+
109+ emitAppEvent ( 'before-quit' )
110+ handlers . get ( 'uncaughtException' ) ?.( new Error ( 'during shutdown' ) as never )
111+
112+ expect ( events . record ) . toHaveBeenCalledWith ( 'main_uncaught_exception' , { valueType : 'Error' } )
113+ expect ( dialog . showMessageBox ) . not . toHaveBeenCalled ( )
114+ expect ( app . relaunch ) . not . toHaveBeenCalled ( )
115+ expect ( app . exit ) . toHaveBeenCalledWith ( 1 )
116+ } )
117+
118+ it ( 'answers an open recovery prompt as Quit when the app starts quitting' , async ( ) => {
119+ vi . mocked ( dialog . showMessageBox ) . mockImplementationOnce (
120+ ( options : { cancelId ?: number ; signal ?: AbortSignal } ) =>
121+ new Promise ( ( resolve ) => {
122+ options . signal ?. addEventListener ( 'abort' , ( ) =>
123+ resolve ( { response : options . cancelId ?? 0 , checkboxChecked : false } )
124+ )
125+ } )
126+ )
127+ const events = { filePath : '/tmp/events.log' , record : vi . fn ( ) }
128+ const { handlers, source } = createProcessSource ( )
129+ installMainProcessFailureObservers ( { events, getWindow : ( ) => null , processSource : source } )
130+
131+ handlers . get ( 'uncaughtException' ) ?.( new Error ( 'while running' ) as never )
132+ expect ( dialog . showMessageBox ) . toHaveBeenCalledOnce ( )
133+ expect ( app . exit ) . not . toHaveBeenCalled ( )
134+
135+ emitAppEvent ( 'will-quit' )
136+
137+ await vi . waitFor ( ( ) => expect ( app . exit ) . toHaveBeenCalledWith ( 1 ) )
138+ expect ( app . relaunch ) . not . toHaveBeenCalled ( )
139+ } )
97140} )
0 commit comments