@@ -14,6 +14,7 @@ jest.useFakeTimers();
1414( global as any ) . nova = Object . assign ( nova , {
1515 commands : {
1616 register : jest . fn ( ) ,
17+ invoke : jest . fn ( ) ,
1718 } ,
1819 workspace : {
1920 path : "/workspace" ,
@@ -71,6 +72,7 @@ describe("test suite", () => {
7172 LanguageClientMock . mockReset ( ) . mockImplementation ( ( ) => ( {
7273 onRequest : jest . fn ( ) ,
7374 onNotification : jest . fn ( ) ,
75+ onDidStop : jest . fn ( ) ,
7476 start : jest . fn ( ) ,
7577 stop : jest . fn ( ) ,
7678 } ) ) ;
@@ -230,6 +232,50 @@ describe("test suite", () => {
230232 ) ;
231233 } ) ;
232234
235+ it ( "handles unexpected crashes" , async ( ) => {
236+ resetMocks ( ) ;
237+ nova . workspace . showActionPanel = jest . fn ( ) ;
238+
239+ await activate ( ) ;
240+
241+ const languageClient : LanguageClient =
242+ LanguageClientMock . mock . results [ 0 ] . value ;
243+ const stopCallback = ( languageClient . onDidStop as jest . Mock ) . mock
244+ . calls [ 0 ] [ 0 ] ;
245+
246+ stopCallback ( new Error ( "Mock language server crash" ) ) ;
247+
248+ expect ( nova . workspace . showActionPanel ) . toBeCalledTimes ( 1 ) ;
249+ const actionPanelCall = ( nova . workspace . showActionPanel as jest . Mock ) . mock
250+ . calls [ 0 ] ;
251+ expect ( actionPanelCall [ 0 ] ) . toMatchInlineSnapshot ( `
252+ "TypeScript Language Server stopped unexpectedly:
253+
254+ Error: Mock language server crash
255+
256+ Please report this, along with any output in the Extension Console."
257+ ` ) ;
258+ expect ( actionPanelCall [ 1 ] . buttons ) . toHaveLength ( 2 ) ;
259+
260+ const informationView = ( informationViewModule . InformationView as jest . Mock <
261+ informationViewModule . InformationView
262+ > ) . mock . instances [ 0 ] ;
263+ expect ( informationView . status ) . toBe ( "Stopped" ) ;
264+
265+ const actionCallback = actionPanelCall [ 2 ] ;
266+
267+ // reload
268+ expect ( nova . commands . invoke ) . not . toBeCalled ( ) ;
269+ actionCallback ( 0 ) ;
270+ expect ( nova . commands . invoke ) . toBeCalledTimes ( 1 ) ;
271+ expect ( nova . commands . invoke ) . toBeCalledWith (
272+ "apexskier.typescript.reload"
273+ ) ;
274+
275+ // ignore
276+ actionCallback ( 1 ) ;
277+ } ) ;
278+
233279 test ( "reload" , async ( ) => {
234280 resetMocks ( ) ;
235281
0 commit comments