Skip to content
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

Merged
merged 2 commits into from
Apr 5, 2023

Conversation

MoLow
Copy link
Member

@MoLow MoLow commented Apr 2, 2023

Fixes: #47296

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

@nodejs-github-bot nodejs-github-bot added the needs-ci PRs that need a full CI run. label Apr 2, 2023
@MoLow MoLow added the watch-mode Issues and PRs related to watch mode label Apr 2, 2023
Copy link
Member

@debadree25 debadree25 left a 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

@MoLow
Copy link
Member Author

MoLow commented Apr 2, 2023

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

@debadree25
Copy link
Member

debadree25 commented Apr 2, 2023

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:

it('should watch when running an non-existing file - when specified under --watch-path with equals', {

it('should watch when running an non-existing file - when specified under --watch-path', {

both of which mention watching non-existing case

@debadree25
Copy link
Member

debadree25 commented Apr 2, 2023

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
Member

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

@debadree25
Copy link
Member

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
Copy link
Member Author

MoLow commented Apr 2, 2023

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

@debadree25
Copy link
Member

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

@debadree25 debadree25 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-actions github-actions bot removed the request-ci Add this label to start a Jenkins CI on a PR. label Apr 2, 2023
@nodejs-github-bot
Copy link
Collaborator

Copy link
Member

@tniessen tniessen left a 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.

@debadree25
Copy link
Member

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

@nodejs-github-bot
Copy link
Collaborator

@nodejs-github-bot
Copy link
Collaborator

@MoLow MoLow added the commit-queue Add this label to land a pull request using GitHub Actions. label Apr 5, 2023
@nodejs-github-bot 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 nodejs-github-bot merged commit 25858e3 into nodejs:main Apr 5, 2023
@nodejs-github-bot
Copy link
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 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 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 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>
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 pending requests for changes, 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