File tree 2 files changed +11
-3
lines changed
2 files changed +11
-3
lines changed Original file line number Diff line number Diff line change @@ -30,9 +30,7 @@ export class Watcher {
30
30
this . mode = opts . mode
31
31
32
32
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 ) )
36
34
. on ( 'change' , ( f ) => this . convert ( f ) )
37
35
. on ( 'add' , ( f ) => this . convert ( f ) )
38
36
. on ( 'unlink' , ( f ) => this . delete ( f ) )
@@ -42,6 +40,10 @@ export class Watcher {
42
40
notifier . start ( )
43
41
}
44
42
43
+ private log ( event : string , path : string ) {
44
+ debugWatcher ( 'Chokidar event: [%s] %s' , event , path )
45
+ }
46
+
45
47
private async convert ( filename : string ) {
46
48
const resolvedFn = path . resolve ( filename )
47
49
const mdFiles = ( await this . finder ( ) ) . filter (
Original file line number Diff line number Diff line change @@ -68,19 +68,25 @@ describe('Watcher', () => {
68
68
// Chokidar events
69
69
const on = watcher . chokidar . on as jest . Mock
70
70
71
+ expect ( on ) . toHaveBeenCalledWith ( 'all' , expect . any ( Function ) )
71
72
expect ( on ) . toHaveBeenCalledWith ( 'change' , expect . any ( Function ) )
72
73
expect ( on ) . toHaveBeenCalledWith ( 'add' , expect . any ( Function ) )
73
74
expect ( on ) . toHaveBeenCalledWith ( 'unlink' , expect . any ( Function ) )
74
75
76
+ const onAll = on . mock . calls . find ( ( [ e ] ) => e === 'all' ) [ 1 ]
75
77
const onChange = on . mock . calls . find ( ( [ e ] ) => e === 'change' ) [ 1 ]
76
78
const onAdd = on . mock . calls . find ( ( [ e ] ) => e === 'add' ) [ 1 ]
77
79
const onUnlink = on . mock . calls . find ( ( [ e ] ) => e === 'unlink' ) [ 1 ]
78
80
79
81
// Callbacks
82
+ const log = jest . spyOn ( watcher as any , 'log' ) . mockImplementation ( )
80
83
const conv = jest . spyOn ( watcher as any , 'convert' ) . mockImplementation ( )
81
84
const del = jest . spyOn ( watcher as any , 'delete' ) . mockImplementation ( )
82
85
83
86
try {
87
+ onAll ( 'event' , 'path' )
88
+ expect ( log ) . toHaveBeenCalledWith ( 'event' , 'path' )
89
+
84
90
onChange ( 'change' )
85
91
expect ( conv ) . toHaveBeenCalledWith ( 'change' )
86
92
You can’t perform that action at this time.
0 commit comments