-
Notifications
You must be signed in to change notification settings - Fork 29.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
watch: fix watch path with equals #47369
Conversation
910d539
to
2d84c7b
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there was no general test for —watch-path both the tests for checking for non-existing files, if there isn't i think we could add a test for —watch-path watching over a directory and executing a file like it is for the —watch tests
There is such a test. see |
2d84c7b
to
5c04888
Compare
could you point out which ones 😅😅 on node/test/sequential/test-watch-mode.mjs Line 158 in 5c04888
node/test/sequential/test-watch-mode.mjs Line 140 in 5c04888
both of which mention watching non-existing case |
I was basically talking of a test something like this it('should watch changes to a file with watch-path', {
skip: !supportsRecursive,
}, async () => {
const file = createTmpFile();
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: { inner: 'running', completed: `Completed running ${inspect(file)}`, restarted: `Restarting ${inspect(file)}` },
});
}); |
ok was able make the test case pass with the following changes: in --- a/lib/internal/main/watch_mode.js
+++ b/lib/internal/main/watch_mode.js
@@ -53,7 +53,7 @@ let exited;
function start() {
exited = false;
- const stdio = kShouldFilterModules ? ['inherit', 'inherit', 'inherit', 'ipc'] : undefined;
+ const stdio = kShouldFilterModules ? ['inherit', 'inherit', 'inherit', 'ipc'] : 'inherit';
child = spawn(process.execPath, args, { stdio, env: { ...process.env, WATCH_REPORT_DEPENDENCIES: '1' } });
watcher.watchChildProcessModules(child);
child.once('exit', (code) => { and updated the tests as follows: --- a/test/sequential/test-watch-mode.mjs
+++ b/test/sequential/test-watch-mode.mjs
@@ -148,7 +165,8 @@ describe('watch mode', { concurrency: false, timeout: 60_000 }, () => {
args: ['--watch-path', fixtures.path('./watch-mode/subdir/'), file],
});
- assert.strictEqual(stderr, '');
+ assert.match(stderr, /Error: Cannot find module/);
+ assert(stderr.match(/Error: Cannot find module/g).length >= 2);
assertRestartedCorrectly({
stdout,
messages: { completed: `Failed running ${inspect(file)}`, restarted: `Restarting ${inspect(file)}` },
@@ -166,7 +184,8 @@ describe('watch mode', { concurrency: false, timeout: 60_000 }, () => {
args: [`--watch-path=${fixtures.path('./watch-mode/subdir/')}`, file],
});
- assert.strictEqual(stderr, '');
+ assert.match(stderr, /Error: Cannot find module/);
+ assert(stderr.match(/Error: Cannot find module/g).length >= 2);
assertRestartedCorrectly({
stdout,
messages: { completed: `Failed running ${inspect(file)}`, restarted: `Restarting ${inspect(file)}` }, does this look ok? if yes could commit it to this branch @MoLow |
5c04888
to
1c4d92c
Compare
thanks @debadree25! |
just added the test for watch-path in the general case @MoLow |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FWIW it seems odd to implement this in JS, separate from the usual C++ argument parsing logic. I had similar concerns in the original PR.
Is there a similar example in present cpp where multiple options are parsed like this? |
Landed in 25858e3 |
PR-URL: nodejs#47369 Fixes: nodejs#47296 Reviewed-By: Debadree Chatterjee <debadree333@gmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Fixes: #47296
prior to this fix
node --watch-path path.js
worked butnode --watch-path=path.js
did not