Skip to content

Commit 35a07c0

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

File tree

1 file changed

+21
-5
lines changed

1 file changed

+21
-5
lines changed

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

+21-5
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,19 @@ 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({
36+
signal: controller.signal,
37+
debounce: common.isMacOS ? common.platformTimeout(200) : 200
38+
});
3839

3940
watcher.on('changed', ({ owners }) => {
4041
assert.strictEqual(owners.size, 2);
4142
assert.ok(owners.has(fixturePaths['test.js']));
4243
assert.ok(owners.has(fixturePaths['test-2.js']));
4344
controller.abort();
45+
done();
4446
});
4547
watcher.filterFile(fixturePaths['test.js']);
4648
watcher.filterFile(fixturePaths['test-2.js']);
@@ -49,6 +51,20 @@ describe('watch file with shared dependency', () => {
4951
watcher.unfilterFilesOwnedBy([fixturePaths['test.js']]);
5052
watcher.filterFile(fixturePaths['test.js']);
5153
watcher.filterFile(fixturePaths['dependency.js'], fixturePaths['test.js']);
52-
writeFileSync(fixturePaths['dependency.js'], 'module.exports = { modified: true };');
54+
55+
if (common.isMacOS) {
56+
// Do the write with a delay to ensure that the OS is ready to notify us.
57+
setImmediate(() => {
58+
writeFileSync(
59+
fixturePaths['dependency.js'],
60+
'module.exports = { modified: true };'
61+
);
62+
}, common.platformTimeout(100));
63+
} else {
64+
writeFileSync(
65+
fixturePaths['dependency.js'],
66+
'module.exports = { modified: true };'
67+
);
68+
}
5369
});
5470
});

0 commit comments

Comments
 (0)