File tree 1 file changed +14
-4
lines changed
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'));
34
34
let changes = 0 ;
35
35
function watchFile ( ) {
36
36
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
+ }
37
41
changes ++ ;
38
- assert . notDeepStrictEqual ( curr . mtime , prev . mtime ) ;
39
42
fs . unwatchFile ( f ) ;
40
43
watchFile ( ) ;
41
44
fs . unwatchFile ( f ) ;
@@ -44,10 +47,17 @@ function watchFile() {
44
47
45
48
watchFile ( ) ;
46
49
50
+ function changeFile ( ) {
51
+ const fd = fs . openSync ( f , 'w+' ) ;
52
+ fs . writeSync ( fd , 'xyz\n' ) ;
53
+ fs . closeSync ( fd ) ;
54
+ }
47
55
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 ( ) ;
51
61
52
62
process . on ( 'exit' , function ( ) {
53
63
assert . ok ( changes > 0 ) ;
You can’t perform that action at this time.
0 commit comments