Skip to content

Commit

Permalink
watch: fix watch path with equals
Browse files Browse the repository at this point in the history
  • Loading branch information
MoLow committed Apr 2, 2023
1 parent 85705a4 commit 5c04888
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
5 changes: 4 additions & 1 deletion lib/internal/main/watch_mode.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const {
ArrayPrototypeMap,
ArrayPrototypePushApply,
ArrayPrototypeSlice,
StringPrototypeStartsWith,
} = primordials;

const {
Expand Down Expand Up @@ -38,7 +39,9 @@ const kPreserveOutput = getOptionValue('--watch-preserve-output');
const kCommand = ArrayPrototypeSlice(process.argv, 1);
const kCommandStr = inspect(ArrayPrototypeJoin(kCommand, ' '));
const args = ArrayPrototypeFilter(process.execArgv, (arg, i, arr) =>
arg !== '--watch-path' && arr[i - 1] !== '--watch-path' && arg !== '--watch' && arg !== '--watch-preserve-output');
!StringPrototypeStartsWith(arg, '--watch-path') &&
(!arr[i - 1] || !StringPrototypeStartsWith(arr[i - 1], '--watch-path')) &&
arg !== '--watch' && arg !== '--watch-preserve-output');
ArrayPrototypePushApply(args, kCommand);

const watcher = new FilesWatcher({ throttle: 500, mode: kShouldFilterModules ? 'filter' : 'all' });
Expand Down
18 changes: 18 additions & 0 deletions test/sequential/test-watch-mode.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,24 @@ describe('watch mode', { concurrency: false, timeout: 60_000 }, () => {
});
});

it('should watch when running an non-existing file - when specified under --watch-path with equals', {
skip: !supportsRecursive
}, async () => {
const file = fixtures.path('watch-mode/subdir/non-existing.js');
const watchedFile = fixtures.path('watch-mode/subdir/file.js');
const { stderr, stdout } = await spawnWithRestarts({
file,
watchedFile,
args: [`--watch-path=${fixtures.path('./watch-mode/subdir/')}`, file],
});

assert.strictEqual(stderr, '');
assertRestartedCorrectly({
stdout,
messages: { completed: `Failed running ${inspect(file)}`, restarted: `Restarting ${inspect(file)}` },
});
});

it('should watch changes to a file - event loop blocked', async () => {
const file = fixtures.path('watch-mode/event_loop_blocked.js');
const { stderr, stdout } = await spawnWithRestarts({
Expand Down

0 comments on commit 5c04888

Please sign in to comment.