Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: add block-scoping to test-fs-watch-encoding #25532

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 37 additions & 28 deletions test/parallel/test-fs-watch-encoding.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,36 +42,45 @@ function unregisterWatcher(watcher) {
}
}

const watcher1 = fs.watch(
tmpdir.path,
{ encoding: 'hex' },
(event, filename) => {
if (['e696b0e5bbbae69687e5a4b9e4bbb62e747874', null].includes(filename))
done(watcher1);
}
);
registerWatcher(watcher1);
{
// Test that using the `encoding` option has the expected result.
const watcher = fs.watch(
tmpdir.path,
{ encoding: 'hex' },
(event, filename) => {
if (['e696b0e5bbbae69687e5a4b9e4bbb62e747874', null].includes(filename))
done(watcher);
}
);
registerWatcher(watcher);
}

const watcher2 = fs.watch(
tmpdir.path,
(event, filename) => {
if ([fn, null].includes(filename))
done(watcher2);
}
);
registerWatcher(watcher2);
{
// Test that in absence of `encoding` option has the expected result.
const watcher = fs.watch(
tmpdir.path,
(event, filename) => {
if ([fn, null].includes(filename))
done(watcher);
}
);
registerWatcher(watcher);
}

const watcher3 = fs.watch(
tmpdir.path,
{ encoding: 'buffer' },
(event, filename) => {
if (filename instanceof Buffer && filename.toString('utf8') === fn)
done(watcher3);
else if (filename === null)
done(watcher3);
}
);
registerWatcher(watcher3);
{
// Test that using the `encoding` option has the expected result.
const watcher = fs.watch(
tmpdir.path,
{ encoding: 'buffer' },
(event, filename) => {
if (filename instanceof Buffer && filename.toString('utf8') === fn)
done(watcher);
else if (filename === null)
done(watcher);
}
);
registerWatcher(watcher);
}

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

Expand Down