@@ -21,9 +21,13 @@ fs.writeFileSync(file2, 'bar');
21
21
const hooks = initHooks ( ) ;
22
22
hooks . enable ( ) ;
23
23
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
+ }
25
29
// Install first file watcher
26
- const w1 = fs . watchFile ( file1 , { interval : 10 } , onchange ) ;
30
+ const w1 = fs . watchFile ( file1 , { interval : 10 } , onchange1 ) ;
27
31
28
32
let as = hooks . activitiesOfTypes ( 'STATWATCHER' ) ;
29
33
assert . strictEqual ( as . length , 1 ) ;
@@ -35,8 +39,14 @@ assert.strictEqual(statwatcher1.triggerAsyncId, 1);
35
39
checkInvocations ( statwatcher1 , { init : 1 } ,
36
40
'watcher1: when started to watch file' ) ;
37
41
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
+
38
48
// Install second file watcher
39
- const w2 = fs . watchFile ( file2 , { interval : 10 } , onchange ) ;
49
+ const w2 = fs . watchFile ( file2 , { interval : 10 } , onchange2 ) ;
40
50
as = hooks . activitiesOfTypes ( 'STATWATCHER' ) ;
41
51
assert . strictEqual ( as . length , 2 ) ;
42
52
@@ -51,7 +61,8 @@ checkInvocations(statwatcher2, { init: 1 },
51
61
52
62
setTimeout ( ( ) => fs . writeFileSync ( file1 , 'foo++' ) ,
53
63
common . platformTimeout ( 100 ) ) ;
54
- w1 . once ( 'change' , common . mustCall ( ( ) => {
64
+ w1 . once ( 'change' , common . mustCall ( ( curr , prev ) => {
65
+ console . log ( 'w1 change' , curr , prev ) ;
55
66
setImmediate ( ( ) => {
56
67
checkInvocations ( statwatcher1 , { init : 1 , before : 1 , after : 1 } ,
57
68
'watcher1: when unwatched first file' ) ;
@@ -60,7 +71,8 @@ w1.once('change', common.mustCall(() => {
60
71
61
72
setTimeout ( ( ) => fs . writeFileSync ( file2 , 'bar++' ) ,
62
73
common . platformTimeout ( 100 ) ) ;
63
- w2 . once ( 'change' , common . mustCall ( ( ) => {
74
+ w2 . once ( 'change' , common . mustCall ( ( curr , prev ) => {
75
+ console . log ( 'w2 change' , curr , prev ) ;
64
76
setImmediate ( ( ) => {
65
77
checkInvocations ( statwatcher1 , { init : 1 , before : 1 , after : 1 } ,
66
78
'watcher1: when unwatched second file' ) ;
0 commit comments