From 8eb0df92960fbcdfccb9f670179db0b8a78c68be Mon Sep 17 00:00:00 2001 From: Luigi Pinca Date: Mon, 23 Dec 2024 09:23:25 +0100 Subject: [PATCH] test: deflake test-watch-file-shared-dependency Delay dependency file modification on macOS. Refs: https://github.com/nodejs/node/pull/51842 --- .../test-watch-file-shared-dependency.mjs | 24 ++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/test/parallel/test-watch-file-shared-dependency.mjs b/test/parallel/test-watch-file-shared-dependency.mjs index 37ac647f82310e0..3f112f08b8ab087 100644 --- a/test/parallel/test-watch-file-shared-dependency.mjs +++ b/test/parallel/test-watch-file-shared-dependency.mjs @@ -32,15 +32,19 @@ Object.entries(fixtureContent) .forEach(([file, content]) => writeFileSync(fixturePaths[file], content)); describe('watch file with shared dependency', () => { - it('should not remove shared dependencies when unfiltering an owner', () => { + it('should not remove shared dependencies when unfiltering an owner', (t, done) => { const controller = new AbortController(); - const watcher = new FilesWatcher({ signal: controller.signal, debounce: 200 }); + const watcher = new FilesWatcher({ + signal: controller.signal, + debounce: common.isMacOS ? common.platformTimeout(200) : 200 + }); watcher.on('changed', ({ owners }) => { assert.strictEqual(owners.size, 2); assert.ok(owners.has(fixturePaths['test.js'])); assert.ok(owners.has(fixturePaths['test-2.js'])); controller.abort(); + done(); }); watcher.filterFile(fixturePaths['test.js']); watcher.filterFile(fixturePaths['test-2.js']); @@ -49,6 +53,20 @@ describe('watch file with shared dependency', () => { watcher.unfilterFilesOwnedBy([fixturePaths['test.js']]); watcher.filterFile(fixturePaths['test.js']); watcher.filterFile(fixturePaths['dependency.js'], fixturePaths['test.js']); - writeFileSync(fixturePaths['dependency.js'], 'module.exports = { modified: true };'); + + if (common.isMacOS) { + // Do the write with a delay to ensure that the OS is ready to notify us. + setTimeout(() => { + writeFileSync( + fixturePaths['dependency.js'], + 'module.exports = { modified: true };' + ); + }, common.platformTimeout(100)); + } else { + writeFileSync( + fixturePaths['dependency.js'], + 'module.exports = { modified: true };' + ); + } }); });