test: tolerate duplicate watch change events

Allow test-watch-file-shared-dependency to observe multiple watcher
events while still asserting that the expected owner set is reached
exactly once.

Signed-off-by: Kamat, Trivikram <16024985+trivikr@users.noreply.github.com>
Assisted-by: openai:gpt-5.5
PR-URL: https://github.com/nodejs/node/pull/63937
Refs: https://github.com/nodejs/node/actions/runs/27462359210/job/81178399610
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Moshe Atlow <moshe@atlow.co.il>
This commit is contained in:
Trivikram Kamat authored and Antoine du Hamel committed 2026-07-30 13:51:40 +02:00
1 parent a124429b36
commit a56fbb2d36
1 file changed
+12 -5
@@ -34,15 +34,22 @@ describe('watch file with shared dependency', () => {
const controller = new AbortController();
const watcher = new FilesWatcher({ signal: controller.signal });
watcher.on('changed', common.mustCall(({ owners }) => {
if (owners.size !== 2) return;
// If this code is never reached the test times out.
const onExpectedOwners = common.mustCall(({ owners }) => {
assert.ok(owners.has(fixturePaths['test.js']));
assert.ok(owners.has(fixturePaths['test-2.js']));
controller.abort();
done();
}));
});
function onChanged({ owners }) {
if (owners.size !== 2) return;
// If this code is never reached the test times out.
watcher.removeListener('changed', onChanged);
onExpectedOwners({ owners });
}
watcher.on('changed', onChanged);
watcher.filterFile(fixturePaths['test.js']);
watcher.filterFile(fixturePaths['test-2.js']);
watcher.filterFile(fixturePaths['dependency.js'], fixturePaths['test.js']);