From 5fee2e89987a0e56230868b020cbd9c693e74fe6 Mon Sep 17 00:00:00 2001 From: Chris Young Date: Thu, 18 May 2017 19:07:52 -0700 Subject: [PATCH 1/3] doc: list macOS as supporting filename argument Fixes: https://github.com/nodejs/node/issues/13108 --- doc/api/fs.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/doc/api/fs.md b/doc/api/fs.md index e867e994349945..15723a2a288752 100644 --- a/doc/api/fs.md +++ b/doc/api/fs.md @@ -2405,10 +2405,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, 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. ```js fs.watch('somedir', (eventType, filename) => { From 9bd40124d7d7bf6f1ddb93ef9092fdfa49f83f95 Mon Sep 17 00:00:00 2001 From: Chris Young Date: Thu, 18 May 2017 23:00:03 -0700 Subject: [PATCH 2/3] test: check fs.watch filename on Linux and macOS Fixes: https://github.com/nodejs/node/issues/13108 --- test/parallel/test-fs-watchfile.js | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/test/parallel/test-fs-watchfile.js b/test/parallel/test-fs-watchfile.js index f583eb8989c06f..3e8f2e22a5904a 100644 --- a/test/parallel/test-fs-watchfile.js +++ b/test/parallel/test-fs-watchfile.js @@ -63,3 +63,25 @@ fs.watchFile(enoentFile, {interval: 0}, common.mustCall(function(curr, prev) { fs.unwatchFile(enoentFile); } }, 2)); + +// Watch events should callback with a filename +if (common.isLinux || common.isOSX) { + const dir = common.tmpDir + '/watch'; + + fs.mkdir(dir, common.mustCall(function(err) { + assert(!err); + + fs.watch(dir, common.mustCall(function(eventType, filename) { + this._handle.close(); + common.refreshTmpDir(); + assert.strictEqual(filename, 'foo.txt'); + })); + + fs.writeFile(`${dir}/foo.txt`, 'foo', common.mustCall((err) => { + if (err) { + common.refreshTmpDir(); + assert(!err); + } + })); + })); +} From 64884c2a5c1371a645215a0caec8fdcd39e994d2 Mon Sep 17 00:00:00 2001 From: Chris Young Date: Fri, 19 May 2017 12:49:46 -0700 Subject: [PATCH 3/3] test: fs.watch filename check for Windows & AIX Fixes: https://github.com/nodejs/node/issues/13108 --- doc/api/fs.md | 2 +- test/parallel/test-fs-watchfile.js | 14 +++++--------- 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/doc/api/fs.md b/doc/api/fs.md index 15723a2a288752..c8c1c19fee9004 100644 --- a/doc/api/fs.md +++ b/doc/api/fs.md @@ -2406,7 +2406,7 @@ this improves the usability of file watching. This is expected behavior. Providing `filename` argument in the callback is only supported on Linux, -macOS, and Windows. Even on supported platforms, `filename` is not always +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. diff --git a/test/parallel/test-fs-watchfile.js b/test/parallel/test-fs-watchfile.js index 3e8f2e22a5904a..fe22f93a10e044 100644 --- a/test/parallel/test-fs-watchfile.js +++ b/test/parallel/test-fs-watchfile.js @@ -64,24 +64,20 @@ fs.watchFile(enoentFile, {interval: 0}, common.mustCall(function(curr, prev) { } }, 2)); -// Watch events should callback with a filename -if (common.isLinux || common.isOSX) { +// 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) { - assert(!err); + if (err) assert.fail(err); fs.watch(dir, common.mustCall(function(eventType, filename) { this._handle.close(); - common.refreshTmpDir(); assert.strictEqual(filename, 'foo.txt'); })); - fs.writeFile(`${dir}/foo.txt`, 'foo', common.mustCall((err) => { - if (err) { - common.refreshTmpDir(); - assert(!err); - } + fs.writeFile(`${dir}/foo.txt`, 'foo', common.mustCall(function(err) { + if (err) assert.fail(err); })); })); }