Skip to content

Commit 424d91a

Browse files
Trotttargos
authored andcommittedJul 2, 2019
test: add logging to statwatcher test
Refs: #21425 (comment) PR-URL: #28270 Reviewed-By: Ruben Bridgewater <[email protected]> Reviewed-By: Refael Ackermann (רפאל פלחי) <[email protected]> Reviewed-By: Anna Henningsen <[email protected]>
1 parent 359e20f commit 424d91a

File tree

1 file changed

+17
-5
lines changed

1 file changed

+17
-5
lines changed
 

‎test/async-hooks/test-statwatcher.js

+17-5
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,13 @@ fs.writeFileSync(file2, 'bar');
2121
const hooks = initHooks();
2222
hooks.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

2832
let as = hooks.activitiesOfTypes('STATWATCHER');
2933
assert.strictEqual(as.length, 1);
@@ -35,8 +39,14 @@ assert.strictEqual(statwatcher1.triggerAsyncId, 1);
3539
checkInvocations(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);
4050
as = hooks.activitiesOfTypes('STATWATCHER');
4151
assert.strictEqual(as.length, 2);
4252

@@ -51,7 +61,8 @@ checkInvocations(statwatcher2, { init: 1 },
5161

5262
setTimeout(() => 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

Comments
 (0)