File tree Expand file tree Collapse file tree 2 files changed +11
-3
lines changed
Expand file tree Collapse file tree 2 files changed +11
-3
lines changed Original file line number Diff line number Diff line change @@ -30,9 +30,7 @@ export class Watcher {
3030 this . mode = opts . mode
3131
3232 this . chokidar = chokidarWatch ( watchPath , { ignoreInitial : true } )
33- . on ( 'all' , ( event , path ) =>
34- debugWatcher ( 'Chokidar event: [%s] %s' , event , path )
35- )
33+ . on ( 'all' , ( event , path ) => this . log ( event , path ) )
3634 . on ( 'change' , ( f ) => this . convert ( f ) )
3735 . on ( 'add' , ( f ) => this . convert ( f ) )
3836 . on ( 'unlink' , ( f ) => this . delete ( f ) )
@@ -42,6 +40,10 @@ export class Watcher {
4240 notifier . start ( )
4341 }
4442
43+ private log ( event : string , path : string ) {
44+ debugWatcher ( 'Chokidar event: [%s] %s' , event , path )
45+ }
46+
4547 private async convert ( filename : string ) {
4648 const resolvedFn = path . resolve ( filename )
4749 const mdFiles = ( await this . finder ( ) ) . filter (
Original file line number Diff line number Diff line change @@ -68,19 +68,25 @@ describe('Watcher', () => {
6868 // Chokidar events
6969 const on = watcher . chokidar . on as jest . Mock
7070
71+ expect ( on ) . toHaveBeenCalledWith ( 'all' , expect . any ( Function ) )
7172 expect ( on ) . toHaveBeenCalledWith ( 'change' , expect . any ( Function ) )
7273 expect ( on ) . toHaveBeenCalledWith ( 'add' , expect . any ( Function ) )
7374 expect ( on ) . toHaveBeenCalledWith ( 'unlink' , expect . any ( Function ) )
7475
76+ const onAll = on . mock . calls . find ( ( [ e ] ) => e === 'all' ) [ 1 ]
7577 const onChange = on . mock . calls . find ( ( [ e ] ) => e === 'change' ) [ 1 ]
7678 const onAdd = on . mock . calls . find ( ( [ e ] ) => e === 'add' ) [ 1 ]
7779 const onUnlink = on . mock . calls . find ( ( [ e ] ) => e === 'unlink' ) [ 1 ]
7880
7981 // Callbacks
82+ const log = jest . spyOn ( watcher as any , 'log' ) . mockImplementation ( )
8083 const conv = jest . spyOn ( watcher as any , 'convert' ) . mockImplementation ( )
8184 const del = jest . spyOn ( watcher as any , 'delete' ) . mockImplementation ( )
8285
8386 try {
87+ onAll ( 'event' , 'path' )
88+ expect ( log ) . toHaveBeenCalledWith ( 'event' , 'path' )
89+
8490 onChange ( 'change' )
8591 expect ( conv ) . toHaveBeenCalledWith ( 'change' )
8692
You can’t perform that action at this time.
0 commit comments