File tree Expand file tree Collapse file tree 1 file changed +14
-4
lines changed Expand file tree Collapse file tree 1 file changed +14
-4
lines changed Original file line number Diff line number Diff line change @@ -34,8 +34,11 @@ fs.closeSync(fs.openSync(f, 'w'));
3434let changes = 0 ;
3535function watchFile ( ) {
3636 fs . watchFile ( f , ( curr , prev ) => {
37+ // Make sure there is at least one watch event that shows a changed mtime.
38+ if ( curr . mtime <= prev . mtime ) {
39+ return ;
40+ }
3741 changes ++ ;
38- assert . notDeepStrictEqual ( curr . mtime , prev . mtime ) ;
3942 fs . unwatchFile ( f ) ;
4043 watchFile ( ) ;
4144 fs . unwatchFile ( f ) ;
@@ -44,10 +47,17 @@ function watchFile() {
4447
4548watchFile ( ) ;
4649
50+ function changeFile ( ) {
51+ const fd = fs . openSync ( f , 'w+' ) ;
52+ fs . writeSync ( fd , 'xyz\n' ) ;
53+ fs . closeSync ( fd ) ;
54+ }
4755
48- const fd = fs . openSync ( f , 'w+' ) ;
49- fs . writeSync ( fd , 'xyz\n' ) ;
50- fs . closeSync ( fd ) ;
56+ changeFile ( ) ;
57+ const interval = setInterval ( changeFile , 1000 ) ;
58+ // Use unref() here so fs.watchFile() watcher is the only thing keeping the
59+ // event loop open.
60+ interval . unref ( ) ;
5161
5262process . on ( 'exit' , function ( ) {
5363 assert . ok ( changes > 0 ) ;
You can’t perform that action at this time.
0 commit comments