Skip to content

Commit b44850e

Browse files
committed
fix(tests/serve): update tests for new watcher model
1 parent 12931ba commit b44850e

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

__tests__/commands.spec.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -502,8 +502,15 @@ describe('electron:serve', () => {
502502
'a-value'
503503
])
504504

505+
let exitCb
506+
mockExeca.on.mockImplementationOnce((eventName, cb) => {
507+
expect(eventName).toBe('exit')
508+
exitCb = cb
509+
})
505510
// Mock change of background file
506511
watchCb()
512+
// Call exit callback because app should have quit
513+
await exitCb()
507514
expect(mockExeca.removeListener.mock.calls[0][0]).toBe('exit')
508515

509516
expect(execa).toHaveBeenCalledTimes(2)
@@ -574,8 +581,15 @@ describe('electron:serve', () => {
574581
expect(webpack).toHaveBeenCalledTimes(1)
575582
expect(execa).toHaveBeenCalledTimes(1)
576583

584+
let exitCb
585+
mockExeca.on.mockImplementationOnce((eventName, cb) => {
586+
expect(eventName).toBe('exit')
587+
exitCb = cb
588+
})
577589
// Mock change of background file
578590
watchCb()
591+
// Call exit callback because app should have quit
592+
await exitCb()
579593
expect(mockExeca.removeListener.mock.calls[0][0]).toBe('exit')
580594
// Electron was killed and listeners removed
581595
if (isWin) {
@@ -627,8 +641,15 @@ describe('electron:serve', () => {
627641
expect(webpack).toHaveBeenCalledTimes(1)
628642
expect(execa).toHaveBeenCalledTimes(1)
629643

644+
let exitCb
645+
mockExeca.on.mockImplementationOnce((eventName, cb) => {
646+
expect(eventName).toBe('exit')
647+
exitCb = cb
648+
})
630649
// Mock change of listed file
631650
watchCb['projectPath/listFile']()
651+
// Call exit callback because app should have quit
652+
await exitCb()
632653
expect(mockExeca.removeListener.mock.calls[0][0]).toBe('exit')
633654
// Electron was killed and listeners removed
634655
if (isWin) {
@@ -645,8 +666,14 @@ describe('electron:serve', () => {
645666
// Electron was re-launched
646667
expect(execa).toHaveBeenCalledTimes(2)
647668

669+
mockExeca.on.mockImplementationOnce((eventName, cb) => {
670+
expect(eventName).toBe('exit')
671+
exitCb = cb
672+
})
648673
// Mock change of background file
649674
watchCb['projectPath/customBackground']()
675+
// Call exit callback because app should have quit
676+
await exitCb()
650677
expect(mockExeca.removeListener.mock.calls[0][0]).toBe('exit')
651678
// Electron was killed and listeners removed
652679
if (isWin) {

0 commit comments

Comments
 (0)