Skip to content

Commit 232e0a3

Browse files
committed
doc, test: add throwIfNoEntry docs and test
1 parent 3f567d4 commit 232e0a3

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

doc/api/fs.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4786,6 +4786,9 @@ The `atime` and `mtime` arguments follow these rules:
47864786
<!-- YAML
47874787
added: v0.5.10
47884788
changes:
4789+
- version: REPLACEME
4790+
pr-url: https://github.com/nodejs/node/pull/61870
4791+
description: Added `throwIfNoEntry` option.
47894792
- version: v19.1.0
47904793
pr-url: https://github.com/nodejs/node/pull/45098
47914794
description: Added recursive support for Linux, AIX and IBMi.
@@ -4814,6 +4817,8 @@ changes:
48144817
* `encoding` {string} Specifies the character encoding to be used for the
48154818
filename passed to the listener. **Default:** `'utf8'`.
48164819
* `signal` {AbortSignal} allows closing the watcher with an AbortSignal.
4820+
* `throwIfNoEntry` {boolean} Indicates whether an exception should be thrown when the
4821+
path does not exist. **Default:** `true`.
48174822
* `ignore` {string|RegExp|Function|Array} Pattern(s) to ignore. Strings are
48184823
glob patterns (using [`minimatch`][]), RegExp patterns are tested against
48194824
the filename, and functions receive the filename and return `true` to

test/parallel/test-fs-watch-enoent.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,29 @@ tmpdir.refresh();
4343
);
4444
}
4545

46+
{
47+
assert.throws(
48+
() => fs.watch(nonexistentFile, { throwIfNoEntry: true }, common.mustNotCall()),
49+
(err) => {
50+
assert.strictEqual(err.path, nonexistentFile);
51+
assert.strictEqual(err.filename, nonexistentFile);
52+
return err.code === 'ENOENT' || err.code === 'ENODEV';
53+
},
54+
);
55+
}
56+
57+
{
58+
if (common.isAIX) {
59+
assert.throws(
60+
() => fs.watch(nonexistentFile, { throwIfNoEntry: false }, common.mustNotCall()),
61+
(err) => err.code === 'ENODEV',
62+
);
63+
} else {
64+
const watcher = fs.watch(nonexistentFile, { throwIfNoEntry: false }, common.mustNotCall());
65+
watcher.close();
66+
}
67+
}
68+
4669
{
4770
if (common.isMacOS || common.isWindows) {
4871
const file = tmpdir.resolve('file-to-watch');

0 commit comments

Comments
 (0)