Skip to content

Commit 4188ee0

Browse files
lpincaaduh95
authored andcommitted
test: deflake test-watch-file-shared-dependency
Delay dependency file modification on macOS. Refs: #51842 PR-URL: #56344 Reviewed-By: Michaël Zasso <[email protected]> Reviewed-By: Jake Yuesong Li <[email protected]>
1 parent 384ccba commit 4188ee0

File tree

1 file changed

+21
-6
lines changed

1 file changed

+21
-6
lines changed

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

+21-6
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@ if (common.isIBMi)
1212
if (common.isAIX)
1313
common.skip('folder watch capability is limited in AIX.');
1414

15-
tmpdir.refresh();
16-
1715
const { FilesWatcher } = watcher;
1816

1917
tmpdir.refresh();
@@ -32,15 +30,18 @@ Object.entries(fixtureContent)
3230
.forEach(([file, content]) => writeFileSync(fixturePaths[file], content));
3331

3432
describe('watch file with shared dependency', () => {
35-
it('should not remove shared dependencies when unfiltering an owner', () => {
33+
it('should not remove shared dependencies when unfiltering an owner', (t, done) => {
3634
const controller = new AbortController();
37-
const watcher = new FilesWatcher({ signal: controller.signal, debounce: 200 });
35+
const watcher = new FilesWatcher({ signal: controller.signal });
3836

3937
watcher.on('changed', ({ owners }) => {
40-
assert.strictEqual(owners.size, 2);
38+
if (owners.size !== 2) return;
39+
40+
// If this code is never reached the test times out.
4141
assert.ok(owners.has(fixturePaths['test.js']));
4242
assert.ok(owners.has(fixturePaths['test-2.js']));
4343
controller.abort();
44+
done();
4445
});
4546
watcher.filterFile(fixturePaths['test.js']);
4647
watcher.filterFile(fixturePaths['test-2.js']);
@@ -49,6 +50,20 @@ describe('watch file with shared dependency', () => {
4950
watcher.unfilterFilesOwnedBy([fixturePaths['test.js']]);
5051
watcher.filterFile(fixturePaths['test.js']);
5152
watcher.filterFile(fixturePaths['dependency.js'], fixturePaths['test.js']);
52-
writeFileSync(fixturePaths['dependency.js'], 'module.exports = { modified: true };');
53+
54+
if (common.isMacOS) {
55+
// Do the write with a delay to ensure that the OS is ready to notify us.
56+
setTimeout(() => {
57+
writeFileSync(
58+
fixturePaths['dependency.js'],
59+
'module.exports = { modified: true };'
60+
);
61+
}, common.platformTimeout(200));
62+
} else {
63+
writeFileSync(
64+
fixturePaths['dependency.js'],
65+
'module.exports = { modified: true };'
66+
);
67+
}
5368
});
5469
});

0 commit comments

Comments
 (0)