Skip to content

Commit a0719b8

Browse files
committed
doc, test: update --watch for linux recursive watch
1 parent 1d5ed72 commit a0719b8

File tree

5 files changed

+75
-107
lines changed

5 files changed

+75
-107
lines changed

doc/api/cli.md

-4
Original file line numberDiff line numberDiff line change
@@ -2854,10 +2854,6 @@ This flag cannot be combined with
28542854
node --watch-path=./src --watch-path=./tests index.js
28552855
```
28562856

2857-
This option is only supported on macOS and Windows.
2858-
An `ERR_FEATURE_UNAVAILABLE_ON_PLATFORM` exception will be thrown
2859-
when the option is used on a platform that does not support it.
2860-
28612857
### `--watch-preserve-output`
28622858

28632859
<!-- YAML

doc/api/errors.md

+12-11
Original file line numberDiff line numberDiff line change
@@ -1252,17 +1252,6 @@ for the JS engine are not set up properly.
12521252
A `Promise` that was callbackified via `util.callbackify()` was rejected with a
12531253
falsy value.
12541254

1255-
<a id="ERR_FEATURE_UNAVAILABLE_ON_PLATFORM"></a>
1256-
1257-
### `ERR_FEATURE_UNAVAILABLE_ON_PLATFORM`
1258-
1259-
<!-- YAML
1260-
added: v14.0.0
1261-
-->
1262-
1263-
Used when a feature that is not available
1264-
to the current platform which is running Node.js is used.
1265-
12661255
<a id="ERR_FS_CP_DIR_TO_NON_DIR"></a>
12671256

12681257
### `ERR_FS_CP_DIR_TO_NON_DIR`
@@ -3299,6 +3288,18 @@ An incompatible combination of options was passed to [`crypto.scrypt()`][] or
32993288
[`crypto.scryptSync()`][]. New versions of Node.js use the error code
33003289
[`ERR_INCOMPATIBLE_OPTION_PAIR`][] instead, which is consistent with other APIs.
33013290

3291+
<a id="ERR_FEATURE_UNAVAILABLE_ON_PLATFORM"></a>
3292+
3293+
### `ERR_FEATURE_UNAVAILABLE_ON_PLATFORM`
3294+
3295+
<!-- YAML
3296+
added: v14.0.0
3297+
removed: v19.1.0
3298+
-->
3299+
3300+
Used when a feature that is not available
3301+
to the current platform which is running Node.js is used.
3302+
33023303
<a id="ERR_FS_INVALID_SYMLINK_TYPE"></a>
33033304

33043305
### `ERR_FS_INVALID_SYMLINK_TYPE`

lib/internal/errors.js

-4
Original file line numberDiff line numberDiff line change
@@ -1202,10 +1202,6 @@ E('ERR_FALSY_VALUE_REJECTION', function(reason) {
12021202
this.reason = reason;
12031203
return 'Promise was rejected with falsy value';
12041204
}, Error, HideStackFramesError);
1205-
E('ERR_FEATURE_UNAVAILABLE_ON_PLATFORM',
1206-
'The feature %s is unavailable on the current platform' +
1207-
', which is being used to run Node.js',
1208-
TypeError);
12091205
E('ERR_FS_CP_DIR_TO_NON_DIR',
12101206
'Cannot overwrite non-directory with directory', SystemError);
12111207
E('ERR_FS_CP_EEXIST', 'Target already exists', SystemError);

test/parallel/test-watch-mode-files_watcher.mjs

+54-60
Original file line numberDiff line numberDiff line change
@@ -93,14 +93,13 @@ describe('watch mode file watcher', () => {
9393
assert.ok(changesCount < 5);
9494
});
9595

96-
it('should ignore files in watched directory if they are not filtered',
97-
{ skip: !supportsRecursiveWatching }, async () => {
98-
watcher.on('changed', common.mustNotCall());
99-
watcher.watchPath(tmpdir.path);
100-
writeFileSync(tmpdir.resolve('file3'), '1');
101-
// Wait for this long to make sure changes are not triggered
102-
await setTimeout(1000);
103-
});
96+
it('should ignore files in watched directory if they are not filtered', async () => {
97+
watcher.on('changed', common.mustNotCall());
98+
watcher.watchPath(tmpdir.path);
99+
writeFileSync(tmpdir.resolve('file3'), '1');
100+
// Wait for this long to make sure changes are not triggered
101+
await setTimeout(1000);
102+
});
104103

105104
it('should allow clearing filters', async () => {
106105
const file = tmpdir.resolve('file4');
@@ -118,58 +117,53 @@ describe('watch mode file watcher', () => {
118117
assert.strictEqual(changesCount, 1);
119118
});
120119

121-
it('should watch all files in watched path when in "all" mode',
122-
{ skip: !supportsRecursiveWatching }, async () => {
123-
watcher = new FilesWatcher({ debounce: 100, mode: 'all' });
124-
watcher.on('changed', () => changesCount++);
125-
126-
const file = tmpdir.resolve('file5');
127-
watcher.watchPath(tmpdir.path);
128-
129-
const changed = once(watcher, 'changed');
130-
await setTimeout(common.platformTimeout(100)); // avoid throttling
131-
writeFileSync(file, 'changed');
132-
await changed;
133-
assert.strictEqual(changesCount, 1);
134-
});
135-
136-
it('should ruse existing watcher if it exists',
137-
{ skip: !supportsRecursiveWatching }, () => {
138-
assert.deepStrictEqual(watcher.watchedPaths, []);
139-
watcher.watchPath(tmpdir.path);
140-
assert.deepStrictEqual(watcher.watchedPaths, [tmpdir.path]);
141-
watcher.watchPath(tmpdir.path);
142-
assert.deepStrictEqual(watcher.watchedPaths, [tmpdir.path]);
143-
});
144-
145-
it('should ruse existing watcher of a parent directory',
146-
{ skip: !supportsRecursiveWatching }, () => {
147-
assert.deepStrictEqual(watcher.watchedPaths, []);
148-
watcher.watchPath(tmpdir.path);
149-
assert.deepStrictEqual(watcher.watchedPaths, [tmpdir.path]);
150-
watcher.watchPath(tmpdir.resolve('subdirectory'));
151-
assert.deepStrictEqual(watcher.watchedPaths, [tmpdir.path]);
152-
});
153-
154-
it('should remove existing watcher if adding a parent directory watcher',
155-
{ skip: !supportsRecursiveWatching }, () => {
156-
assert.deepStrictEqual(watcher.watchedPaths, []);
157-
const subdirectory = tmpdir.resolve('subdirectory');
158-
mkdirSync(subdirectory);
159-
watcher.watchPath(subdirectory);
160-
assert.deepStrictEqual(watcher.watchedPaths, [subdirectory]);
161-
watcher.watchPath(tmpdir.path);
162-
assert.deepStrictEqual(watcher.watchedPaths, [tmpdir.path]);
163-
});
164-
165-
it('should clear all watchers when calling clear',
166-
{ skip: !supportsRecursiveWatching }, () => {
167-
assert.deepStrictEqual(watcher.watchedPaths, []);
168-
watcher.watchPath(tmpdir.path);
169-
assert.deepStrictEqual(watcher.watchedPaths, [tmpdir.path]);
170-
watcher.clear();
171-
assert.deepStrictEqual(watcher.watchedPaths, []);
172-
});
120+
it('should watch all files in watched path when in "all" mode', async () => {
121+
watcher = new FilesWatcher({ debounce: 100, mode: 'all' });
122+
watcher.on('changed', () => changesCount++);
123+
124+
const file = tmpdir.resolve('file5');
125+
watcher.watchPath(tmpdir.path);
126+
127+
const changed = once(watcher, 'changed');
128+
await setTimeout(common.platformTimeout(100)); // avoid throttling
129+
writeFileSync(file, 'changed');
130+
await changed;
131+
assert.strictEqual(changesCount, 1);
132+
});
133+
134+
it('should ruse existing watcher if it exists', () => {
135+
assert.deepStrictEqual(watcher.watchedPaths, []);
136+
watcher.watchPath(tmpdir.path);
137+
assert.deepStrictEqual(watcher.watchedPaths, [tmpdir.path]);
138+
watcher.watchPath(tmpdir.path);
139+
assert.deepStrictEqual(watcher.watchedPaths, [tmpdir.path]);
140+
});
141+
142+
it('should ruse existing watcher of a parent directory', () => {
143+
assert.deepStrictEqual(watcher.watchedPaths, []);
144+
watcher.watchPath(tmpdir.path);
145+
assert.deepStrictEqual(watcher.watchedPaths, [tmpdir.path]);
146+
watcher.watchPath(tmpdir.resolve('subdirectory'));
147+
assert.deepStrictEqual(watcher.watchedPaths, [tmpdir.path]);
148+
});
149+
150+
it('should remove existing watcher if adding a parent directory watcher', () => {
151+
assert.deepStrictEqual(watcher.watchedPaths, []);
152+
const subdirectory = tmpdir.resolve('subdirectory');
153+
mkdirSync(subdirectory);
154+
watcher.watchPath(subdirectory);
155+
assert.deepStrictEqual(watcher.watchedPaths, [subdirectory]);
156+
watcher.watchPath(tmpdir.path);
157+
assert.deepStrictEqual(watcher.watchedPaths, [tmpdir.path]);
158+
});
159+
160+
it('should clear all watchers when calling clear', () => {
161+
assert.deepStrictEqual(watcher.watchedPaths, []);
162+
watcher.watchPath(tmpdir.path);
163+
assert.deepStrictEqual(watcher.watchedPaths, [tmpdir.path]);
164+
watcher.clear();
165+
assert.deepStrictEqual(watcher.watchedPaths, []);
166+
});
173167

174168
it('should watch files from subprocess IPC events', async () => {
175169
const file = fixtures.path('watch-mode/ipc.js');

test/sequential/test-watch-mode.mjs

+9-28
Original file line numberDiff line numberDiff line change
@@ -259,9 +259,7 @@ describe('watch mode', { concurrency: !process.env.TEST_PARALLEL, timeout: 60_00
259259
]);
260260
});
261261

262-
it('should watch changes to a file with watch-path', {
263-
skip: !supportsRecursive,
264-
}, async () => {
262+
it('should watch changes to a file with watch-path', async () => {
265263
const dir = tmpdir.resolve('subdir1');
266264
mkdirSync(dir);
267265
const file = createTmpFile();
@@ -280,9 +278,7 @@ describe('watch mode', { concurrency: !process.env.TEST_PARALLEL, timeout: 60_00
280278
assert.strictEqual(stderr, '');
281279
});
282280

283-
it('should watch when running an non-existing file - when specified under --watch-path', {
284-
skip: !supportsRecursive
285-
}, async () => {
281+
it('should watch when running an non-existing file - when specified under --watch-path', async () => {
286282
const dir = tmpdir.resolve('subdir2');
287283
mkdirSync(dir);
288284
const file = path.join(dir, 'non-existing.js');
@@ -304,9 +300,7 @@ describe('watch mode', { concurrency: !process.env.TEST_PARALLEL, timeout: 60_00
304300
]);
305301
});
306302

307-
it('should watch when running an non-existing file - when specified under --watch-path with equals', {
308-
skip: !supportsRecursive
309-
}, async () => {
303+
it('should watch when running an non-existing file - when specified under --watch-path with equals', async () => {
310304
const dir = tmpdir.resolve('subdir3');
311305
mkdirSync(dir);
312306
const file = path.join(dir, 'non-existing.js');
@@ -453,17 +447,12 @@ console.log(values.random);
453447
]);
454448
});
455449

456-
// TODO: Remove skip after https://github.com/nodejs/node/pull/45271 lands
457-
it('should not watch when running an missing file', {
458-
skip: !supportsRecursive
459-
}, async () => {
450+
it('should not watch when running an missing file', async () => {
460451
const nonExistingfile = tmpdir.resolve(`${tmpFiles++}.js`);
461452
await failWriteSucceed({ file: nonExistingfile, watchedFile: nonExistingfile });
462453
});
463454

464-
it('should not watch when running an missing mjs file', {
465-
skip: !supportsRecursive
466-
}, async () => {
455+
it('should not watch when running an missing mjs file', async () => {
467456
const nonExistingfile = tmpdir.resolve(`${tmpFiles++}.mjs`);
468457
await failWriteSucceed({ file: nonExistingfile, watchedFile: nonExistingfile });
469458
});
@@ -517,9 +506,7 @@ console.log(values.random);
517506
]);
518507
});
519508

520-
it('should run when `--watch-path=./foo --require ./bar.js`', {
521-
skip: !supportsRecursive,
522-
}, async () => {
509+
it('should run when `--watch-path=./foo --require ./bar.js`', async () => {
523510
const projectDir = tmpdir.resolve('project2');
524511
mkdirSync(projectDir);
525512

@@ -549,9 +536,7 @@ console.log(values.random);
549536
]);
550537
});
551538

552-
it('should run when `--watch-path=./foo --require=./bar.js`', {
553-
skip: !supportsRecursive,
554-
}, async () => {
539+
it('should run when `--watch-path=./foo --require=./bar.js`', async () => {
555540
const projectDir = tmpdir.resolve('project3');
556541
mkdirSync(projectDir);
557542

@@ -581,9 +566,7 @@ console.log(values.random);
581566
]);
582567
});
583568

584-
it('should run when `--watch-path ./foo --require ./bar.js`', {
585-
skip: !supportsRecursive,
586-
}, async () => {
569+
it('should run when `--watch-path ./foo --require ./bar.js`', async () => {
587570
const projectDir = tmpdir.resolve('project5');
588571
mkdirSync(projectDir);
589572

@@ -613,9 +596,7 @@ console.log(values.random);
613596
]);
614597
});
615598

616-
it('should run when `--watch-path=./foo --require=./bar.js`', {
617-
skip: !supportsRecursive,
618-
}, async () => {
599+
it('should run when `--watch-path=./foo --require=./bar.js`', async () => {
619600
const projectDir = tmpdir.resolve('project6');
620601
mkdirSync(projectDir);
621602

0 commit comments

Comments
 (0)