From 1aa68f9a8dcf50d76399374ca3cccfa0888fdd4f Mon Sep 17 00:00:00 2001 From: Chris Young Date: Thu, 18 May 2017 22:07:52 -0400 Subject: [PATCH] doc: list macOS as supporting filename argument also added regression tests PR-URL: https://github.com/nodejs/node/pull/13111 Fixes: https://github.com/nodejs/node/issues/13108 Reviewed-By: Refael Ackermann Reviewed-By: Luigi Pinca Reviewed-By: James M Snell Reviewed-By: Alexey Orlenko --- doc/api/fs.md | 8 ++++---- test/parallel/test-fs-watchfile.js | 18 ++++++++++++++++++ 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/doc/api/fs.md b/doc/api/fs.md index a108e0aa7ecde9..e185bdc5cb7747 100644 --- a/doc/api/fs.md +++ b/doc/api/fs.md @@ -2297,10 +2297,10 @@ this improves the usability of file watching. This is expected behavior. -Providing `filename` argument in the callback is only supported on Linux and -Windows. Even on supported platforms, `filename` is not always guaranteed to -be provided. Therefore, don't assume that `filename` argument is always -provided in the callback, and have some fallback logic if it is null. +Providing `filename` argument in the callback is only supported on Linux, +macOS, Windows, and AIX. Even on supported platforms, `filename` is not always +guaranteed to be provided. Therefore, don't assume that `filename` argument is +always provided in the callback, and have some fallback logic if it is null. ```js fs.watch('somedir', (eventType, filename) => { diff --git a/test/parallel/test-fs-watchfile.js b/test/parallel/test-fs-watchfile.js index f583eb8989c06f..fe22f93a10e044 100644 --- a/test/parallel/test-fs-watchfile.js +++ b/test/parallel/test-fs-watchfile.js @@ -63,3 +63,21 @@ fs.watchFile(enoentFile, {interval: 0}, common.mustCall(function(curr, prev) { fs.unwatchFile(enoentFile); } }, 2)); + +// Watch events should callback with a filename on supported systems +if (common.isLinux || common.isOSX || common.isWindows || common.isAix) { + const dir = common.tmpDir + '/watch'; + + fs.mkdir(dir, common.mustCall(function(err) { + if (err) assert.fail(err); + + fs.watch(dir, common.mustCall(function(eventType, filename) { + this._handle.close(); + assert.strictEqual(filename, 'foo.txt'); + })); + + fs.writeFile(`${dir}/foo.txt`, 'foo', common.mustCall(function(err) { + if (err) assert.fail(err); + })); + })); +}