FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

watch: fix watch path with equals by MoLow · Pull Request #47369 · nodejs/node · GitHub

/ node Public

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

MoLow requested review from benjamingr and debadree25 April 2, 2023 06:57
nodejs-github-bot added the needs-ci PRs that need a full CI run. label Apr 2, 2023
MoLow added the watch-mode Issues and PRs related to watch mode label Apr 2, 2023
MoLow force-pushed the fix-watch-path-equals branch from 910d539 to 2d84c7b Compare April 2, 2023 07:34
Comment thread test/sequential/test-watch-mode.mjs Outdated

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

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 commented Apr 2, 2023

Copy link
Copy Markdown
Member Author

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 force-pushed the fix-watch-path-equals branch from 2d84c7b to 5c04888 Compare April 2, 2023 11:13

debadree25 commented Apr 2, 2023
edited
Loading

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 commented Apr 2, 2023
edited
Loading

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

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 () => {
    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)}` },
    });
  });

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 force-pushed the fix-watch-path-equals branch from 5c04888 to 1c4d92c Compare April 2, 2023 16:51

MoLow commented Apr 2, 2023

Copy link
Copy Markdown
Member Author

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

Copy link
Copy Markdown
Contributor

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

debadree25 added author ready PRs that have at least one approval, no outstanding review comments, 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-actions Bot removed the request-ci Add this label to start a Jenkins CI on a PR. label Apr 2, 2023

Copy link
Copy Markdown
Collaborator

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

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.

Copy link
Copy Markdown
Contributor

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

Copy link
Copy Markdown
Collaborator

Copy link
Copy Markdown
Collaborator

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

Copy link
Copy Markdown
Collaborator

Landed in 25858e3

RafaelGSS pushed a commit that referenced this pull request Apr 5, 2023
PR-URL: #47369
Fixes: #47296
Reviewed-By: Debadree Chatterjee <debadree333@gmail.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
RafaelGSS mentioned this pull request Apr 6, 2023
RafaelGSS pushed a commit that referenced this pull request Apr 6, 2023
PR-URL: #47369
Fixes: #47296
Reviewed-By: Debadree Chatterjee <debadree333@gmail.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
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: #47369
Fixes: #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: #47369
Fixes: #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: #47369
Fixes: #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: #47369
Fixes: #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#47369
Fixes: nodejs#47296
Reviewed-By: Debadree Chatterjee <debadree333@gmail.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

author ready PRs that have at least one approval, no outstanding review comments, and a CI started. commit-queue-squash Add this label to instruct the Commit Queue to squash all the PR commits into the first one. needs-ci PRs that need a full CI run. watch-mode Issues 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


Back | FazBrowse Home | New Git URL