Skip to content

Commit a56fbb2

Browse files
trivikraduh95
authored andcommitted
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: #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>
1 parent a124429 commit a56fbb2

1 file changed

Lines changed: 12 additions & 5 deletions

File tree

‎test/parallel/test-watch-file-shared-dependency.mjs‎

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,22 @@ describe('watch file with shared dependency', () => {
3434
constcontroller=newAbortController();
3535
constwatcher=newFilesWatcher({signal: controller.signal});
3636

37-
watcher.on('changed',common.mustCall(({ owners })=>{
38-
if(owners.size!==2)return;
39-
40-
// If this code is never reached the test times out.
37+
constonExpectedOwners=common.mustCall(({ owners })=>{
4138
assert.ok(owners.has(fixturePaths['test.js']));
4239
assert.ok(owners.has(fixturePaths['test-2.js']));
4340
controller.abort();
4441
done();
45-
}));
42+
});
43+
44+
functiononChanged({ owners }){
45+
if(owners.size!==2)return;
46+
47+
// If this code is never reached the test times out.
48+
watcher.removeListener('changed',onChanged);
49+
onExpectedOwners({ owners });
50+
}
51+
52+
watcher.on('changed',onChanged);
4653
watcher.filterFile(fixturePaths['test.js']);
4754
watcher.filterFile(fixturePaths['test-2.js']);
4855
watcher.filterFile(fixturePaths['dependency.js'],fixturePaths['test.js']);

0 commit comments

Comments
 (0)