@@ -21,9 +21,13 @@ fs.writeFileSync(file2, 'bar');
2121const hooks = initHooks ( ) ;
2222hooks . enable ( ) ;
2323
24- function onchange ( ) { }
24+ function onchange1 ( curr , prev ) {
25+ console . log ( 'Watcher: w1' ) ;
26+ console . log ( 'current stat data:' , curr ) ;
27+ console . log ( 'previous stat data:' , prev ) ;
28+ }
2529// Install first file watcher
26- const w1 = fs . watchFile ( file1 , { interval : 10 } , onchange ) ;
30+ const w1 = fs . watchFile ( file1 , { interval : 10 } , onchange1 ) ;
2731
2832let as = hooks . activitiesOfTypes ( 'STATWATCHER' ) ;
2933assert . strictEqual ( as . length , 1 ) ;
@@ -35,8 +39,14 @@ assert.strictEqual(statwatcher1.triggerAsyncId, 1);
3539checkInvocations ( statwatcher1 , { init : 1 } ,
3640 'watcher1: when started to watch file' ) ;
3741
42+ function onchange2 ( curr , prev ) {
43+ console . log ( 'Watcher: w2' ) ;
44+ console . log ( 'current stat data:' , curr ) ;
45+ console . log ( 'previous stat data:' , prev ) ;
46+ }
47+
3848// Install second file watcher
39- const w2 = fs . watchFile ( file2 , { interval : 10 } , onchange ) ;
49+ const w2 = fs . watchFile ( file2 , { interval : 10 } , onchange2 ) ;
4050as = hooks . activitiesOfTypes ( 'STATWATCHER' ) ;
4151assert . strictEqual ( as . length , 2 ) ;
4252
@@ -51,7 +61,8 @@ checkInvocations(statwatcher2, { init: 1 },
5161
5262setTimeout ( ( ) => fs . writeFileSync ( file1 , 'foo++' ) ,
5363 common . platformTimeout ( 100 ) ) ;
54- w1 . once ( 'change' , common . mustCall ( ( ) => {
64+ w1 . once ( 'change' , common . mustCall ( ( curr , prev ) => {
65+ console . log ( 'w1 change' , curr , prev ) ;
5566 setImmediate ( ( ) => {
5667 checkInvocations ( statwatcher1 , { init : 1 , before : 1 , after : 1 } ,
5768 'watcher1: when unwatched first file' ) ;
@@ -60,7 +71,8 @@ w1.once('change', common.mustCall(() => {
6071
6172 setTimeout ( ( ) => fs . writeFileSync ( file2 , 'bar++' ) ,
6273 common . platformTimeout ( 100 ) ) ;
63- w2 . once ( 'change' , common . mustCall ( ( ) => {
74+ w2 . once ( 'change' , common . mustCall ( ( curr , prev ) => {
75+ console . log ( 'w2 change' , curr , prev ) ;
6476 setImmediate ( ( ) => {
6577 checkInvocations ( statwatcher1 , { init : 1 , before : 1 , after : 1 } ,
6678 'watcher1: when unwatched second file' ) ;
0 commit comments