@@ -70,6 +70,29 @@ describe('watch mode file watcher', () => {
70
70
assert . ok ( changesCount < 5 ) ;
71
71
} ) ;
72
72
73
+ it ( 'should debounce changes on multiple files' , async ( ) => {
74
+ const files = [ ]
75
+ for ( let i = 0 ; i < 10 ; i ++ ) {
76
+ const file = tmpdir . resolve ( `file-debounced-${ i } ` ) ;
77
+ writeFileSync ( file , 'written' ) ;
78
+ watcher . filterFile ( file ) ;
79
+ files . push ( file ) ;
80
+ }
81
+
82
+ files . forEach ( ( file ) => writeFileSync ( file , '1' ) ) ;
83
+ files . forEach ( ( file ) => writeFileSync ( file , '2' ) ) ;
84
+ files . forEach ( ( file ) => writeFileSync ( file , '3' ) ) ;
85
+ files . forEach ( ( file ) => writeFileSync ( file , '4' ) ) ;
86
+
87
+ await setTimeout ( 200 ) ; // debounce * 2
88
+ files . forEach ( ( file ) => writeFileSync ( file , '5' ) ) ;
89
+ const changed = once ( watcher , 'changed' ) ;
90
+ files . forEach ( ( file ) => writeFileSync ( file , 'after' ) ) ;
91
+ await changed ;
92
+ // Unfortunately testing that changesCount === 2 is flaky
93
+ assert . ok ( changesCount < 5 ) ;
94
+ } ) ;
95
+
73
96
it ( 'should ignore files in watched directory if they are not filtered' ,
74
97
{ skip : ! supportsRecursiveWatching } , async ( ) => {
75
98
watcher . on ( 'changed' , common . mustNotCall ( ) ) ;
0 commit comments