Skip to content

Commit 8eb0df9

Browse files
committed
test: deflake test-watch-file-shared-dependency
Delay dependency file modification on macOS. Refs: #51842
1 parent 48c75bc commit 8eb0df9

File tree

1 file changed

+21
-3
lines changed

1 file changed

+21
-3
lines changed

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

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,19 @@ Object.entries(fixtureContent)
3232
.forEach(([file, content]) => writeFileSync(fixturePaths[file], content));
3333

3434
describe('watch file with shared dependency', () => {
35-
it('should not remove shared dependencies when unfiltering an owner', () => {
35+
it('should not remove shared dependencies when unfiltering an owner', (t, done) => {
3636
const controller = new AbortController();
37-
const watcher = new FilesWatcher({ signal: controller.signal, debounce: 200 });
37+
const watcher = new FilesWatcher({
38+
signal: controller.signal,
39+
debounce: common.isMacOS ? common.platformTimeout(200) : 200
40+
});
3841

3942
watcher.on('changed', ({ owners }) => {
4043
assert.strictEqual(owners.size, 2);
4144
assert.ok(owners.has(fixturePaths['test.js']));
4245
assert.ok(owners.has(fixturePaths['test-2.js']));
4346
controller.abort();
47+
done();
4448
});
4549
watcher.filterFile(fixturePaths['test.js']);
4650
watcher.filterFile(fixturePaths['test-2.js']);
@@ -49,6 +53,20 @@ describe('watch file with shared dependency', () => {
4953
watcher.unfilterFilesOwnedBy([fixturePaths['test.js']]);
5054
watcher.filterFile(fixturePaths['test.js']);
5155
watcher.filterFile(fixturePaths['dependency.js'], fixturePaths['test.js']);
52-
writeFileSync(fixturePaths['dependency.js'], 'module.exports = { modified: true };');
56+
57+
if (common.isMacOS) {
58+
// Do the write with a delay to ensure that the OS is ready to notify us.
59+
setTimeout(() => {
60+
writeFileSync(
61+
fixturePaths['dependency.js'],
62+
'module.exports = { modified: true };'
63+
);
64+
}, common.platformTimeout(100));
65+
} else {
66+
writeFileSync(
67+
fixturePaths['dependency.js'],
68+
'module.exports = { modified: true };'
69+
);
70+
}
5371
});
5472
});

0 commit comments

Comments
 (0)