From a56fbb2d36b413f65261cd0a0714fe53f4186c27 Mon Sep 17 00:00:00 2001 From: Trivikram Kamat <16024985+trivikr@users.noreply.github.com> Date: Sun, 21 Jun 2026 01:47:04 -0700 Subject: [PATCH] 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 Reviewed-By: Moshe Atlow --- .../test-watch-file-shared-dependency.mjs | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/test/parallel/test-watch-file-shared-dependency.mjs b/test/parallel/test-watch-file-shared-dependency.mjs index 08fbf38177d..721220b254c 100644 --- a/test/parallel/test-watch-file-shared-dependency.mjs +++ b/test/parallel/test-watch-file-shared-dependency.mjs @@ -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']);