diff --git a/test/parallel/test-fs-watchfile.js b/test/parallel/test-fs-watchfile.js index fe22f93a10e044..270a281ce31189 100644 --- a/test/parallel/test-fs-watchfile.js +++ b/test/parallel/test-fs-watchfile.js @@ -72,12 +72,15 @@ if (common.isLinux || common.isOSX || common.isWindows || common.isAix) { if (err) assert.fail(err); fs.watch(dir, common.mustCall(function(eventType, filename) { + clearInterval(interval); this._handle.close(); assert.strictEqual(filename, 'foo.txt'); })); - fs.writeFile(`${dir}/foo.txt`, 'foo', common.mustCall(function(err) { - if (err) assert.fail(err); - })); + const interval = setInterval(() => { + fs.writeFile(`${dir}/foo.txt`, 'foo', common.mustCall(function(err) { + if (err) assert.fail(err); + })); + }, 1); })); }