From a0719b83177eb5437386b2b6afcf3413a7f69bf5 Mon Sep 17 00:00:00 2001
From: RedYetiDev <38299977+RedYetiDev@users.noreply.github.com>
Date: Fri, 4 Oct 2024 14:30:35 -0400
Subject: [PATCH] doc, test: update --watch for linux recursive watch
---
doc/api/cli.md | 4 -
doc/api/errors.md | 23 ++--
lib/internal/errors.js | 4 -
.../test-watch-mode-files_watcher.mjs | 114 +++++++++---------
test/sequential/test-watch-mode.mjs | 37 ++----
5 files changed, 75 insertions(+), 107 deletions(-)
diff --git a/doc/api/cli.md b/doc/api/cli.md
index a79bfe2addce59..ce3b4519f4d76a 100644
--- a/doc/api/cli.md
+++ b/doc/api/cli.md
@@ -2854,10 +2854,6 @@ This flag cannot be combined with
node --watch-path=./src --watch-path=./tests index.js
```
-This option is only supported on macOS and Windows.
-An `ERR_FEATURE_UNAVAILABLE_ON_PLATFORM` exception will be thrown
-when the option is used on a platform that does not support it.
-
### `--watch-preserve-output`
-
-Used when a feature that is not available
-to the current platform which is running Node.js is used.
-
### `ERR_FS_CP_DIR_TO_NON_DIR`
@@ -3299,6 +3288,18 @@ An incompatible combination of options was passed to [`crypto.scrypt()`][] or
[`crypto.scryptSync()`][]. New versions of Node.js use the error code
[`ERR_INCOMPATIBLE_OPTION_PAIR`][] instead, which is consistent with other APIs.
+
+
+### `ERR_FEATURE_UNAVAILABLE_ON_PLATFORM`
+
+
+
+Used when a feature that is not available
+to the current platform which is running Node.js is used.
+
### `ERR_FS_INVALID_SYMLINK_TYPE`
diff --git a/lib/internal/errors.js b/lib/internal/errors.js
index c7cb7715dbcaef..483381d1ce6432 100644
--- a/lib/internal/errors.js
+++ b/lib/internal/errors.js
@@ -1202,10 +1202,6 @@ E('ERR_FALSY_VALUE_REJECTION', function(reason) {
this.reason = reason;
return 'Promise was rejected with falsy value';
}, Error, HideStackFramesError);
-E('ERR_FEATURE_UNAVAILABLE_ON_PLATFORM',
- 'The feature %s is unavailable on the current platform' +
- ', which is being used to run Node.js',
- TypeError);
E('ERR_FS_CP_DIR_TO_NON_DIR',
'Cannot overwrite non-directory with directory', SystemError);
E('ERR_FS_CP_EEXIST', 'Target already exists', SystemError);
diff --git a/test/parallel/test-watch-mode-files_watcher.mjs b/test/parallel/test-watch-mode-files_watcher.mjs
index 2192a198d9cbbb..7590df8b3d1dcd 100644
--- a/test/parallel/test-watch-mode-files_watcher.mjs
+++ b/test/parallel/test-watch-mode-files_watcher.mjs
@@ -93,14 +93,13 @@ describe('watch mode file watcher', () => {
assert.ok(changesCount < 5);
});
- it('should ignore files in watched directory if they are not filtered',
- { skip: !supportsRecursiveWatching }, async () => {
- watcher.on('changed', common.mustNotCall());
- watcher.watchPath(tmpdir.path);
- writeFileSync(tmpdir.resolve('file3'), '1');
- // Wait for this long to make sure changes are not triggered
- await setTimeout(1000);
- });
+ it('should ignore files in watched directory if they are not filtered', async () => {
+ watcher.on('changed', common.mustNotCall());
+ watcher.watchPath(tmpdir.path);
+ writeFileSync(tmpdir.resolve('file3'), '1');
+ // Wait for this long to make sure changes are not triggered
+ await setTimeout(1000);
+ });
it('should allow clearing filters', async () => {
const file = tmpdir.resolve('file4');
@@ -118,58 +117,53 @@ describe('watch mode file watcher', () => {
assert.strictEqual(changesCount, 1);
});
- it('should watch all files in watched path when in "all" mode',
- { skip: !supportsRecursiveWatching }, async () => {
- watcher = new FilesWatcher({ debounce: 100, mode: 'all' });
- watcher.on('changed', () => changesCount++);
-
- const file = tmpdir.resolve('file5');
- watcher.watchPath(tmpdir.path);
-
- const changed = once(watcher, 'changed');
- await setTimeout(common.platformTimeout(100)); // avoid throttling
- writeFileSync(file, 'changed');
- await changed;
- assert.strictEqual(changesCount, 1);
- });
-
- it('should ruse existing watcher if it exists',
- { skip: !supportsRecursiveWatching }, () => {
- assert.deepStrictEqual(watcher.watchedPaths, []);
- watcher.watchPath(tmpdir.path);
- assert.deepStrictEqual(watcher.watchedPaths, [tmpdir.path]);
- watcher.watchPath(tmpdir.path);
- assert.deepStrictEqual(watcher.watchedPaths, [tmpdir.path]);
- });
-
- it('should ruse existing watcher of a parent directory',
- { skip: !supportsRecursiveWatching }, () => {
- assert.deepStrictEqual(watcher.watchedPaths, []);
- watcher.watchPath(tmpdir.path);
- assert.deepStrictEqual(watcher.watchedPaths, [tmpdir.path]);
- watcher.watchPath(tmpdir.resolve('subdirectory'));
- assert.deepStrictEqual(watcher.watchedPaths, [tmpdir.path]);
- });
-
- it('should remove existing watcher if adding a parent directory watcher',
- { skip: !supportsRecursiveWatching }, () => {
- assert.deepStrictEqual(watcher.watchedPaths, []);
- const subdirectory = tmpdir.resolve('subdirectory');
- mkdirSync(subdirectory);
- watcher.watchPath(subdirectory);
- assert.deepStrictEqual(watcher.watchedPaths, [subdirectory]);
- watcher.watchPath(tmpdir.path);
- assert.deepStrictEqual(watcher.watchedPaths, [tmpdir.path]);
- });
-
- it('should clear all watchers when calling clear',
- { skip: !supportsRecursiveWatching }, () => {
- assert.deepStrictEqual(watcher.watchedPaths, []);
- watcher.watchPath(tmpdir.path);
- assert.deepStrictEqual(watcher.watchedPaths, [tmpdir.path]);
- watcher.clear();
- assert.deepStrictEqual(watcher.watchedPaths, []);
- });
+ it('should watch all files in watched path when in "all" mode', async () => {
+ watcher = new FilesWatcher({ debounce: 100, mode: 'all' });
+ watcher.on('changed', () => changesCount++);
+
+ const file = tmpdir.resolve('file5');
+ watcher.watchPath(tmpdir.path);
+
+ const changed = once(watcher, 'changed');
+ await setTimeout(common.platformTimeout(100)); // avoid throttling
+ writeFileSync(file, 'changed');
+ await changed;
+ assert.strictEqual(changesCount, 1);
+ });
+
+ it('should ruse existing watcher if it exists', () => {
+ assert.deepStrictEqual(watcher.watchedPaths, []);
+ watcher.watchPath(tmpdir.path);
+ assert.deepStrictEqual(watcher.watchedPaths, [tmpdir.path]);
+ watcher.watchPath(tmpdir.path);
+ assert.deepStrictEqual(watcher.watchedPaths, [tmpdir.path]);
+ });
+
+ it('should ruse existing watcher of a parent directory', () => {
+ assert.deepStrictEqual(watcher.watchedPaths, []);
+ watcher.watchPath(tmpdir.path);
+ assert.deepStrictEqual(watcher.watchedPaths, [tmpdir.path]);
+ watcher.watchPath(tmpdir.resolve('subdirectory'));
+ assert.deepStrictEqual(watcher.watchedPaths, [tmpdir.path]);
+ });
+
+ it('should remove existing watcher if adding a parent directory watcher', () => {
+ assert.deepStrictEqual(watcher.watchedPaths, []);
+ const subdirectory = tmpdir.resolve('subdirectory');
+ mkdirSync(subdirectory);
+ watcher.watchPath(subdirectory);
+ assert.deepStrictEqual(watcher.watchedPaths, [subdirectory]);
+ watcher.watchPath(tmpdir.path);
+ assert.deepStrictEqual(watcher.watchedPaths, [tmpdir.path]);
+ });
+
+ it('should clear all watchers when calling clear', () => {
+ assert.deepStrictEqual(watcher.watchedPaths, []);
+ watcher.watchPath(tmpdir.path);
+ assert.deepStrictEqual(watcher.watchedPaths, [tmpdir.path]);
+ watcher.clear();
+ assert.deepStrictEqual(watcher.watchedPaths, []);
+ });
it('should watch files from subprocess IPC events', async () => {
const file = fixtures.path('watch-mode/ipc.js');
diff --git a/test/sequential/test-watch-mode.mjs b/test/sequential/test-watch-mode.mjs
index 39bc7223dffdfc..00a2f46da3a3cd 100644
--- a/test/sequential/test-watch-mode.mjs
+++ b/test/sequential/test-watch-mode.mjs
@@ -259,9 +259,7 @@ describe('watch mode', { concurrency: !process.env.TEST_PARALLEL, timeout: 60_00
]);
});
- it('should watch changes to a file with watch-path', {
- skip: !supportsRecursive,
- }, async () => {
+ it('should watch changes to a file with watch-path', async () => {
const dir = tmpdir.resolve('subdir1');
mkdirSync(dir);
const file = createTmpFile();
@@ -280,9 +278,7 @@ describe('watch mode', { concurrency: !process.env.TEST_PARALLEL, timeout: 60_00
assert.strictEqual(stderr, '');
});
- it('should watch when running an non-existing file - when specified under --watch-path', {
- skip: !supportsRecursive
- }, async () => {
+ it('should watch when running an non-existing file - when specified under --watch-path', async () => {
const dir = tmpdir.resolve('subdir2');
mkdirSync(dir);
const file = path.join(dir, 'non-existing.js');
@@ -304,9 +300,7 @@ describe('watch mode', { concurrency: !process.env.TEST_PARALLEL, timeout: 60_00
]);
});
- it('should watch when running an non-existing file - when specified under --watch-path with equals', {
- skip: !supportsRecursive
- }, async () => {
+ it('should watch when running an non-existing file - when specified under --watch-path with equals', async () => {
const dir = tmpdir.resolve('subdir3');
mkdirSync(dir);
const file = path.join(dir, 'non-existing.js');
@@ -453,17 +447,12 @@ console.log(values.random);
]);
});
- // TODO: Remove skip after https://github.com/nodejs/node/pull/45271 lands
- it('should not watch when running an missing file', {
- skip: !supportsRecursive
- }, async () => {
+ it('should not watch when running an missing file', async () => {
const nonExistingfile = tmpdir.resolve(`${tmpFiles++}.js`);
await failWriteSucceed({ file: nonExistingfile, watchedFile: nonExistingfile });
});
- it('should not watch when running an missing mjs file', {
- skip: !supportsRecursive
- }, async () => {
+ it('should not watch when running an missing mjs file', async () => {
const nonExistingfile = tmpdir.resolve(`${tmpFiles++}.mjs`);
await failWriteSucceed({ file: nonExistingfile, watchedFile: nonExistingfile });
});
@@ -517,9 +506,7 @@ console.log(values.random);
]);
});
- it('should run when `--watch-path=./foo --require ./bar.js`', {
- skip: !supportsRecursive,
- }, async () => {
+ it('should run when `--watch-path=./foo --require ./bar.js`', async () => {
const projectDir = tmpdir.resolve('project2');
mkdirSync(projectDir);
@@ -549,9 +536,7 @@ console.log(values.random);
]);
});
- it('should run when `--watch-path=./foo --require=./bar.js`', {
- skip: !supportsRecursive,
- }, async () => {
+ it('should run when `--watch-path=./foo --require=./bar.js`', async () => {
const projectDir = tmpdir.resolve('project3');
mkdirSync(projectDir);
@@ -581,9 +566,7 @@ console.log(values.random);
]);
});
- it('should run when `--watch-path ./foo --require ./bar.js`', {
- skip: !supportsRecursive,
- }, async () => {
+ it('should run when `--watch-path ./foo --require ./bar.js`', async () => {
const projectDir = tmpdir.resolve('project5');
mkdirSync(projectDir);
@@ -613,9 +596,7 @@ console.log(values.random);
]);
});
- it('should run when `--watch-path=./foo --require=./bar.js`', {
- skip: !supportsRecursive,
- }, async () => {
+ it('should run when `--watch-path=./foo --require=./bar.js`', async () => {
const projectDir = tmpdir.resolve('project6');
mkdirSync(projectDir);