Skip to content

watch: fix watch path with equals - #47369

Merged
nodejs-github-bot merged 2 commits into
nodejs:mainfrom
MoLow:fix-watch-path-equals
Apr 5, 2023
Merged

watch: fix watch path with equals#47369
nodejs-github-bot merged 2 commits into
nodejs:mainfrom
MoLow:fix-watch-path-equals

Conversation

@MoLow

@MoLowMoLow commented Apr 2, 2023

Copy link
Copy Markdown
Member

Fixes: #47296

prior to this fix node --watch-path path.js worked but node --watch-path=path.js did not

@nodejs-github-botnodejs-github-bot added the needs-ci PRs that need a full CI run. label Apr 2, 2023
@MoLowMoLow added the watch-mode Issues and PRs related to watch mode label Apr 2, 2023
@MoLow
MoLowforce-pushed the fix-watch-path-equals branch from 910d539 to 2d84c7bCompareApril 2, 2023 07:34
Comment threadtest/sequential/test-watch-mode.mjs Outdated

@debadree25debadree25 left a comment

Copy link
Copy Markdown
Contributor

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

@MoLow

MoLow commented Apr 2, 2023

Copy link
Copy Markdown
MemberAuthor

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 test/sequential/test-watch-mode.mjs

@MoLow
MoLowforce-pushed the fix-watch-path-equals branch from 2d84c7b to 5c04888CompareApril 2, 2023 11:13
@debadree25

debadree25 commented Apr 2, 2023

Copy link
Copy Markdown
Contributor

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 test/sequential/test-watch-mode.mjs

could you point out which ones 😅😅 on test/sequential/test-watch-mode.mjs was able to find two tests:

https://github.com/nodejs/node/blob/5c048889f7258a09d5f41860f34ae2ccd3604070/test/sequential/test-watch-mode.mjs#L158

https://github.com/nodejs/node/blob/5c048889f7258a09d5f41860f34ae2ccd3604070/test/sequential/test-watch-mode.mjs#L140

both of which mention watching non-existing case

@debadree25

debadree25 commented Apr 2, 2023

Copy link
Copy Markdown
Contributor

Also, I tried running to see if the console log not appearing issue is fixed for example I have a file test.mjs and test_dir/test.js, test.mjs has a statement console.log('hello world'); and running out/Release/node --watch-path=./test_dir test.mjs gave the following output, hello world not printed

Screenshot 2023-04-02 at 7 31 15 PM

@debadree25

Copy link
Copy Markdown
Contributor

I was basically talking of a test something like this

it('should watch changes to a file with watch-path',{skip: !supportsRecursive,},async()=>{constfile=createTmpFile();constwatchedFile=fixtures.path('watch-mode/subdir/file.js');const{ stderr, stdout }=awaitspawnWithRestarts({
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)}`},});});

@debadree25

Copy link
Copy Markdown
Contributor

ok was able make the test case pass with the following changes:

in lib/internal/main/watch_mode.js passing the 'inherit' option when using watch mode

--- 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

@MoLow
MoLowforce-pushed the fix-watch-path-equals branch from 5c04888 to 1c4d92cCompareApril 2, 2023 16:51
@MoLow

MoLow commented Apr 2, 2023

Copy link
Copy Markdown
MemberAuthor

thanks @debadree25!
feel free to commit to this branch if you find anything else

@debadree25

Copy link
Copy Markdown
Contributor

just added the test for watch-path in the general case @MoLow

@debadree25debadree25 added author ready PRs that have at least one approval, no pending requests for changes, and a CI started. request-ci Add this label to start a Jenkins CI on a PR. commit-queue-squash Add this label to instruct the Commit Queue to squash all the PR commits into the first one. labels Apr 2, 2023
@github-actionsgithub-actionsBot removed the request-ci Add this label to start a Jenkins CI on a PR. label Apr 2, 2023
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

@tniessentniessen left a comment

Copy link
Copy Markdown
Member

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.

@debadree25

Copy link
Copy Markdown
Contributor

Is there a similar example in present cpp where multiple options are parsed like this?

@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

@MoLowMoLow added the commit-queue Add this label to land a pull request using GitHub Actions. label Apr 5, 2023
@nodejs-github-botnodejs-github-bot removed the commit-queue Add this label to land a pull request using GitHub Actions. label Apr 5, 2023
@nodejs-github-bot
nodejs-github-bot merged commit 25858e3 into nodejs:mainApr 5, 2023
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

Landed in 25858e3

RafaelGSS pushed a commit that referenced this pull request Apr 5, 2023
PR-URL: #47369Fixes: #47296
Reviewed-By: Debadree Chatterjee <debadree333@gmail.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
@RafaelGSSRafaelGSS mentioned this pull request Apr 6, 2023
RafaelGSS pushed a commit that referenced this pull request Apr 6, 2023
PR-URL: #47369Fixes: #47296
Reviewed-By: Debadree Chatterjee <debadree333@gmail.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
@MoLow
MoLow deleted the fix-watch-path-equals branch April 6, 2023 18:15
RafaelGSS pushed a commit that referenced this pull request Apr 7, 2023
PR-URL: #47369Fixes: #47296
Reviewed-By: Debadree Chatterjee <debadree333@gmail.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
RafaelGSS pushed a commit that referenced this pull request Apr 8, 2023
PR-URL: #47369Fixes: #47296
Reviewed-By: Debadree Chatterjee <debadree333@gmail.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
RafaelGSS pushed a commit that referenced this pull request Apr 13, 2023
PR-URL: #47369Fixes: #47296
Reviewed-By: Debadree Chatterjee <debadree333@gmail.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
danielleadams pushed a commit that referenced this pull request Jul 6, 2023
PR-URL: #47369Fixes: #47296
Reviewed-By: Debadree Chatterjee <debadree333@gmail.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
MoLow added a commit to MoLow/node that referenced this pull request Jul 6, 2023
PR-URL: nodejs#47369Fixes: nodejs#47296
Reviewed-By: Debadree Chatterjee <debadree333@gmail.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

author readyPRs that have at least one approval, no pending requests for changes, and a CI started.commit-queue-squashAdd this label to instruct the Commit Queue to squash all the PR commits into the first one.needs-ciPRs that need a full CI run.watch-modeIssues and PRs related to watch mode

Projects

None yet

Development

Successfully merging this pull request may close these issues.

--watch-path doesn't run the JavaScript file

5 participants

@MoLow@debadree25@nodejs-github-bot@benjamingr@tniessen