Skip to content

Commit de587ba

Browse files
LakshmiSwethaGaddaleax
authored andcommitted
test: refactor to block-scope
PR-URL: #25532 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
1 parent fb83f84 commit de587ba

File tree

1 file changed

+37
-28
lines changed

1 file changed

+37
-28
lines changed

test/parallel/test-fs-watch-encoding.js

+37-28
Original file line numberDiff line numberDiff line change
@@ -42,36 +42,45 @@ function unregisterWatcher(watcher) {
4242
}
4343
}
4444

45-
const watcher1 = fs.watch(
46-
tmpdir.path,
47-
{ encoding: 'hex' },
48-
(event, filename) => {
49-
if (['e696b0e5bbbae69687e5a4b9e4bbb62e747874', null].includes(filename))
50-
done(watcher1);
51-
}
52-
);
53-
registerWatcher(watcher1);
45+
{
46+
// Test that using the `encoding` option has the expected result.
47+
const watcher = fs.watch(
48+
tmpdir.path,
49+
{ encoding: 'hex' },
50+
(event, filename) => {
51+
if (['e696b0e5bbbae69687e5a4b9e4bbb62e747874', null].includes(filename))
52+
done(watcher);
53+
}
54+
);
55+
registerWatcher(watcher);
56+
}
5457

55-
const watcher2 = fs.watch(
56-
tmpdir.path,
57-
(event, filename) => {
58-
if ([fn, null].includes(filename))
59-
done(watcher2);
60-
}
61-
);
62-
registerWatcher(watcher2);
58+
{
59+
// Test that in absence of `encoding` option has the expected result.
60+
const watcher = fs.watch(
61+
tmpdir.path,
62+
(event, filename) => {
63+
if ([fn, null].includes(filename))
64+
done(watcher);
65+
}
66+
);
67+
registerWatcher(watcher);
68+
}
6369

64-
const watcher3 = fs.watch(
65-
tmpdir.path,
66-
{ encoding: 'buffer' },
67-
(event, filename) => {
68-
if (filename instanceof Buffer && filename.toString('utf8') === fn)
69-
done(watcher3);
70-
else if (filename === null)
71-
done(watcher3);
72-
}
73-
);
74-
registerWatcher(watcher3);
70+
{
71+
// Test that using the `encoding` option has the expected result.
72+
const watcher = fs.watch(
73+
tmpdir.path,
74+
{ encoding: 'buffer' },
75+
(event, filename) => {
76+
if (filename instanceof Buffer && filename.toString('utf8') === fn)
77+
done(watcher);
78+
else if (filename === null)
79+
done(watcher);
80+
}
81+
);
82+
registerWatcher(watcher);
83+
}
7584

7685
const done = common.mustCall(unregisterWatcher, watchers.size);
7786

0 commit comments

Comments
 (0)