@@ -9,6 +9,7 @@ const execa = require('execa')
99const portfinder = require ( 'portfinder' )
1010const Application = require ( 'spectron' ) . Application
1111const { chainWebpack, getExternals } = require ( '../lib/webpackConfig' )
12+ const chokidar = require ( 'chokidar' )
1213// #endregion
1314
1415// #region Mocks
@@ -26,6 +27,7 @@ jest.mock('electron-builder/out/cli/install-app-deps.js', () => ({
2627 installAppDeps : mockInstallAppDeps
2728} ) )
2829jest . mock ( '../lib/webpackConfig.js' )
30+ jest . mock ( 'chokidar' )
2931const mockPipe = jest . fn ( )
3032const childEvents = { }
3133const mockExeca = {
@@ -66,6 +68,11 @@ console.log = jest.fn()
6668beforeEach ( ( ) => {
6769 jest . clearAllMocks ( )
6870} )
71+ chokidar . watch . mockImplementation ( ( file ) => {
72+ return {
73+ on : ( type , cb ) => { }
74+ }
75+ } )
6976// #endregion
7077
7178// #region runCommand
@@ -449,9 +456,13 @@ describe('electron:serve', () => {
449456
450457 test ( 'Custom launch arguments is used if provided' , async ( ) => {
451458 let watchCb
452- fs . watchFile . mockImplementation ( ( file , cb ) => {
453- // Set callback to be called later
454- watchCb = cb
459+ chokidar . watch . mockImplementation ( ( file ) => {
460+ return {
461+ on : ( type , cb ) => {
462+ // Set callback to be called later
463+ watchCb = cb
464+ }
465+ }
455466 } )
456467 await runCommand ( 'electron:serve' , {
457468 pluginOptions : {
@@ -514,9 +525,13 @@ describe('electron:serve', () => {
514525 // So we can make sure it wasn't called
515526 jest . spyOn ( process , 'exit' )
516527 let watchCb
517- fs . watchFile . mockImplementation ( ( file , cb ) => {
518- // Set callback to be called later
519- watchCb = cb
528+ chokidar . watch . mockImplementation ( ( file ) => {
529+ return {
530+ on : ( type , cb ) => {
531+ // Set callback to be called later
532+ watchCb = cb
533+ }
534+ }
520535 } )
521536 await runCommand ( 'electron:serve' , {
522537 pluginOptions : {
@@ -528,7 +543,7 @@ describe('electron:serve', () => {
528543 } )
529544
530545 // Proper file is watched
531- expect ( fs . watchFile . mock . calls [ 0 ] [ 0 ] ) . toBe ( 'projectPath/customBackground' )
546+ expect ( chokidar . watch . mock . calls [ 0 ] [ 0 ] ) . toBe ( 'projectPath/customBackground' )
532547 // Child has not yet been killed or unwatched
533548 expect ( mockExeca . send ) . not . toBeCalled ( )
534549 expect ( mockExeca . kill ) . not . toBeCalled ( )
@@ -560,9 +575,13 @@ describe('electron:serve', () => {
560575 // So we can make sure it wasn't called
561576 jest . spyOn ( process , 'exit' )
562577 let watchCb = { }
563- fs . watchFile . mockImplementation ( ( file , cb ) => {
564- // Set callback to be called later
565- watchCb [ file ] = cb
578+ chokidar . watch . mockImplementation ( ( file ) => {
579+ return {
580+ on : ( type , cb ) => {
581+ // Set callback to be called later
582+ watchCb [ file ] = cb
583+ }
584+ }
566585 } )
567586 await runCommand ( 'electron:serve' , {
568587 pluginOptions : {
@@ -576,8 +595,8 @@ describe('electron:serve', () => {
576595 } )
577596
578597 // Proper file is watched
579- expect ( fs . watchFile . mock . calls [ 0 ] [ 0 ] ) . toBe ( 'projectPath/customBackground' )
580- expect ( fs . watchFile . mock . calls [ 1 ] [ 0 ] ) . toBe ( 'projectPath/listFile' )
598+ expect ( chokidar . watch . mock . calls [ 0 ] [ 0 ] ) . toBe ( 'projectPath/customBackground' )
599+ expect ( chokidar . watch . mock . calls [ 1 ] [ 0 ] ) . toBe ( 'projectPath/listFile' )
581600 // Child has not yet been killed or unwatched
582601 expect ( mockExeca . send ) . not . toBeCalled ( )
583602 expect ( mockExeca . kill ) . not . toBeCalled ( )
0 commit comments