diff --git a/test/parallel/test-fs-watch-recursive-add-file-to-existing-subfolder.js b/test/parallel/test-fs-watch-recursive-add-file-to-existing-subfolder.js index 995c82743e49ea..628ca4b2fdf805 100644 --- a/test/parallel/test-fs-watch-recursive-add-file-to-existing-subfolder.js +++ b/test/parallel/test-fs-watch-recursive-add-file-to-existing-subfolder.js @@ -48,7 +48,10 @@ watcher.on('change', function(event, filename) { } }); -fs.writeFileSync(childrenAbsolutePath, 'world'); +// Do the write with a delay to ensure that the OS is ready to notify us. +setTimeout(() => { + fs.writeFileSync(childrenAbsolutePath, 'world'); +}, common.platformTimeout(200)); process.once('exit', function() { assert(watcherClosed, 'watcher Object was not closed'); diff --git a/test/parallel/test-fs-watch-recursive-add-file-to-new-folder.js b/test/parallel/test-fs-watch-recursive-add-file-to-new-folder.js index 1d5f0098428c03..2f91c968f78a1a 100644 --- a/test/parallel/test-fs-watch-recursive-add-file-to-new-folder.js +++ b/test/parallel/test-fs-watch-recursive-add-file-to-new-folder.js @@ -44,8 +44,11 @@ watcher.on('change', function(event, filename) { } }); -fs.mkdirSync(filePath); -fs.writeFileSync(childrenAbsolutePath, 'world'); +// Do the write with a delay to ensure that the OS is ready to notify us. +setTimeout(() => { + fs.mkdirSync(filePath); + fs.writeFileSync(childrenAbsolutePath, 'world'); +}, common.platformTimeout(200)); process.once('exit', function() { assert(watcherClosed, 'watcher Object was not closed'); diff --git a/test/parallel/test-fs-watch-recursive-add-file.js b/test/parallel/test-fs-watch-recursive-add-file.js index d03a4144ac81bb..27b933871cb403 100644 --- a/test/parallel/test-fs-watch-recursive-add-file.js +++ b/test/parallel/test-fs-watch-recursive-add-file.js @@ -39,7 +39,10 @@ watcher.on('change', function(event, filename) { } }); -fs.writeFileSync(testFile, 'world'); +// Do the write with a delay to ensure that the OS is ready to notify us. +setTimeout(() => { + fs.writeFileSync(testFile, 'world'); +}, common.platformTimeout(200)); process.once('exit', function() { assert(watcherClosed, 'watcher Object was not closed'); diff --git a/test/parallel/test-fs-watch-recursive-assert-leaks.js b/test/parallel/test-fs-watch-recursive-assert-leaks.js index 9d178fcfe8212b..f5950e38ce2201 100644 --- a/test/parallel/test-fs-watch-recursive-assert-leaks.js +++ b/test/parallel/test-fs-watch-recursive-assert-leaks.js @@ -42,4 +42,9 @@ watcher.on('change', common.mustCallAtLeast(async (event, filename) => { process.on('exit', function() { assert(watcherClosed, 'watcher Object was not closed'); }); -fs.writeFileSync(filePath, 'content'); + +// Do the write with a delay to ensure that the OS is ready to notify us. +(async () => { + await setTimeout(200); + fs.writeFileSync(filePath, 'content'); +})().then(common.mustCall()); diff --git a/test/parallel/test-fs-watch-recursive-sync-write.js b/test/parallel/test-fs-watch-recursive-sync-write.js index 38dce82fb115aa..ecc380d190eee7 100644 --- a/test/parallel/test-fs-watch-recursive-sync-write.js +++ b/test/parallel/test-fs-watch-recursive-sync-write.js @@ -32,4 +32,7 @@ const watcher = watch(tmpDir, { recursive: true }, common.mustCall((eventType, _ assert.strictEqual(join(tmpDir, _filename), filename); })); -writeFileSync(filename, 'foobar2'); +// Do the write with a delay to ensure that the OS is ready to notify us. +setTimeout(() => { + writeFileSync(filename, 'foobar2'); +}, common.platformTimeout(200)); diff --git a/test/parallel/test-fs-watch-recursive-update-file.js b/test/parallel/test-fs-watch-recursive-update-file.js index ee8e8fe52b4374..7100b015ab2567 100644 --- a/test/parallel/test-fs-watch-recursive-update-file.js +++ b/test/parallel/test-fs-watch-recursive-update-file.js @@ -39,4 +39,7 @@ watcher.on('change', common.mustCallAtLeast(function(event, filename) { } })); -fs.writeFileSync(testFile, 'hello'); +// Do the write with a delay to ensure that the OS is ready to notify us. +setTimeout(() => { + fs.writeFileSync(testFile, 'hello'); +}, common.platformTimeout(200));