Skip to content

Commit 1aa68f9

Browse files
Chris Youngjasnell
authored andcommitted
doc: list macOS as supporting filename argument
also added regression tests PR-URL: #13111Fixes: #13108 Reviewed-By: Refael Ackermann <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Alexey Orlenko <[email protected]>
1 parent 77d5e6f commit 1aa68f9

File tree

2 files changed

+22
-4
lines changed

2 files changed

+22
-4
lines changed

‎doc/api/fs.md‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2297,10 +2297,10 @@ this improves the usability of file watching. This is expected behavior.
22972297

22982298
<!--type=misc-->
22992299

2300-
Providing `filename` argument in the callback is only supported on Linux and
2301-
Windows. Even on supported platforms, `filename` is not always guaranteed to
2302-
be provided. Therefore, don't assume that `filename` argument is always
2303-
provided in the callback, and have some fallback logic if it is null.
2300+
Providing `filename` argument in the callback is only supported on Linux,
2301+
macOS, Windows, and AIX. Even on supported platforms, `filename` is not always
2302+
guaranteed to be provided. Therefore, don't assume that `filename` argument is
2303+
always provided in the callback, and have some fallback logic if it is null.
23042304

23052305
```js
23062306
fs.watch('somedir', (eventType, filename) =>{

‎test/parallel/test-fs-watchfile.js‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,3 +63,21 @@ fs.watchFile(enoentFile,{interval: 0}, common.mustCall(function(curr, prev){
6363
fs.unwatchFile(enoentFile);
6464
}
6565
},2));
66+
67+
// Watch events should callback with a filename on supported systems
68+
if(common.isLinux||common.isOSX||common.isWindows||common.isAix){
69+
constdir=common.tmpDir+'/watch';
70+
71+
fs.mkdir(dir,common.mustCall(function(err){
72+
if(err)assert.fail(err);
73+
74+
fs.watch(dir,common.mustCall(function(eventType,filename){
75+
this._handle.close();
76+
assert.strictEqual(filename,'foo.txt');
77+
}));
78+
79+
fs.writeFile(`${dir}/foo.txt`,'foo',common.mustCall(function(err){
80+
if(err)assert.fail(err);
81+
}));
82+
}));
83+
}

0 commit comments

Comments
(0)