@@ -326,6 +326,57 @@ describe('serve:electron', () => {
326
326
// Electron was re-launched
327
327
expect ( execa ) . toHaveBeenCalledTimes ( 2 )
328
328
} )
329
+
330
+ test ( 'Main process is recompiled and Electron is relaunched when file in list change' , async ( ) => {
331
+ process . exit = jest . fn ( )
332
+ let watchCb = { }
333
+ fs . watchFile . mockImplementation ( ( file , cb ) => {
334
+ // Set callback to be called later
335
+ watchCb [ file ] = cb
336
+ } )
337
+ await runCommand ( 'serve:electron' , {
338
+ pluginOptions : {
339
+ electronBuilder : {
340
+ mainProcessFile : 'customBackground' ,
341
+ mainProcessWatch : [ 'listFile' ]
342
+ }
343
+ }
344
+ } )
345
+
346
+ // Proper file is watched
347
+ expect ( fs . watchFile . mock . calls [ 0 ] [ 0 ] ) . toBe ( 'projectPath/customBackground' )
348
+ expect ( fs . watchFile . mock . calls [ 1 ] [ 0 ] ) . toBe ( 'projectPath/listFile' )
349
+ // Child has not yet been killed or unwatched
350
+ expect ( mockExeca . kill ) . not . toBeCalled ( )
351
+ expect ( mockExeca . removeAllListeners ) . not . toBeCalled ( )
352
+ // Main process was bundled and Electron was launched initially
353
+ expect ( webpack ) . toHaveBeenCalledTimes ( 1 )
354
+ expect ( execa ) . toHaveBeenCalledTimes ( 1 )
355
+
356
+ // Mock change of listed file
357
+ watchCb [ 'projectPath/listFile' ] ( )
358
+ // Electron was killed and listeners removed
359
+ expect ( mockExeca . kill ) . toHaveBeenCalledTimes ( 1 )
360
+ expect ( mockExeca . removeAllListeners ) . toHaveBeenCalledTimes ( 1 )
361
+ // Process did not exit on Electron close
362
+ expect ( process . exit ) . not . toBeCalled ( )
363
+ // Main process file was recompiled
364
+ expect ( webpack ) . toHaveBeenCalledTimes ( 2 )
365
+ // Electron was re-launched
366
+ expect ( execa ) . toHaveBeenCalledTimes ( 2 )
367
+
368
+ // Mock change of background file
369
+ watchCb [ 'projectPath/customBackground' ] ( )
370
+ // Electron was killed and listeners removed
371
+ expect ( mockExeca . kill ) . toHaveBeenCalledTimes ( 2 )
372
+ expect ( mockExeca . removeAllListeners ) . toHaveBeenCalledTimes ( 2 )
373
+ // Process did not exit on Electron close
374
+ expect ( process . exit ) . not . toBeCalled ( )
375
+ // Main process file was recompiled
376
+ expect ( webpack ) . toHaveBeenCalledTimes ( 3 )
377
+ // Electron was re-launched
378
+ expect ( execa ) . toHaveBeenCalledTimes ( 3 )
379
+ } )
329
380
} )
330
381
331
382
describe ( 'testWithSpectron' , async ( ) => {
0 commit comments