@@ -9,6 +9,7 @@ const execa = require('execa')
9
9
const portfinder = require ( 'portfinder' )
10
10
const Application = require ( 'spectron' ) . Application
11
11
const { chainWebpack, getExternals } = require ( '../lib/webpackConfig' )
12
+ const chokidar = require ( 'chokidar' )
12
13
// #endregion
13
14
14
15
// #region Mocks
@@ -26,6 +27,7 @@ jest.mock('electron-builder/out/cli/install-app-deps.js', () => ({
26
27
installAppDeps : mockInstallAppDeps
27
28
} ) )
28
29
jest . mock ( '../lib/webpackConfig.js' )
30
+ jest . mock ( 'chokidar' )
29
31
const mockPipe = jest . fn ( )
30
32
const childEvents = { }
31
33
const mockExeca = {
@@ -66,6 +68,11 @@ console.log = jest.fn()
66
68
beforeEach ( ( ) => {
67
69
jest . clearAllMocks ( )
68
70
} )
71
+ chokidar . watch . mockImplementation ( ( file ) => {
72
+ return {
73
+ on : ( type , cb ) => { }
74
+ }
75
+ } )
69
76
// #endregion
70
77
71
78
// #region runCommand
@@ -449,9 +456,13 @@ describe('electron:serve', () => {
449
456
450
457
test ( 'Custom launch arguments is used if provided' , async ( ) => {
451
458
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
+ }
455
466
} )
456
467
await runCommand ( 'electron:serve' , {
457
468
pluginOptions : {
@@ -514,9 +525,13 @@ describe('electron:serve', () => {
514
525
// So we can make sure it wasn't called
515
526
jest . spyOn ( process , 'exit' )
516
527
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
+ }
520
535
} )
521
536
await runCommand ( 'electron:serve' , {
522
537
pluginOptions : {
@@ -528,7 +543,7 @@ describe('electron:serve', () => {
528
543
} )
529
544
530
545
// 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' )
532
547
// Child has not yet been killed or unwatched
533
548
expect ( mockExeca . send ) . not . toBeCalled ( )
534
549
expect ( mockExeca . kill ) . not . toBeCalled ( )
@@ -560,9 +575,13 @@ describe('electron:serve', () => {
560
575
// So we can make sure it wasn't called
561
576
jest . spyOn ( process , 'exit' )
562
577
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
+ }
566
585
} )
567
586
await runCommand ( 'electron:serve' , {
568
587
pluginOptions : {
@@ -576,8 +595,8 @@ describe('electron:serve', () => {
576
595
} )
577
596
578
597
// 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' )
581
600
// Child has not yet been killed or unwatched
582
601
expect ( mockExeca . send ) . not . toBeCalled ( )
583
602
expect ( mockExeca . kill ) . not . toBeCalled ( )
0 commit comments