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

Change tests option from --watch to --live to avoid node conflict #317

Merged
merged 1 commit into from May 16, 2023

Conversation

lyzadanger
Copy link
Contributor

@lyzadanger lyzadanger commented May 15, 2023

Node 18.11 introduced a core --watch flag. This creates a conflict with using a --watch option in the tests task module. For now, change the name of the task's option to --live to avoid this conflict.

Updated usage:

gulp test --live

Testing this change

  • In the main branch of the client, with a local node version of >=18.11, try running gulp test --watch. It should fail.
  • Check out this branch of frontend-build. Run yalc publish
  • In the client directory, run yalc add @hypothesis/frontend-build
  • In the client, run gulp test --live. It should work: tests should run and then run again on input/source file changes

Node 18.11 introduced a core `--watch` flag. This creates a conflict
with using a `--watch` option in the `test` task. For now, change the
name of the task's option to `--live` to avoid this conflict.

Updated usage:

`gulp test --live`
@lyzadanger
Copy link
Contributor Author

In the course of poking at this, I noticed that https://h.readthedocs.io/projects/client/en/latest/developers/developing.html 's section on testing is fairly egregiously out-of-date. We should update that documentation after we sort this.

@lyzadanger lyzadanger requested a review from acelaya May 15, 2023 14:29
Copy link
Contributor

@acelaya acelaya left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍🏼

@robertknight
Copy link
Member

robertknight commented May 16, 2023

After doing some digging, it looks like the issue is that the --watch flag matches a V8 flag which is detected by the flagged-respawn package that Gulp uses internally. According to the npm README, flagged-respawn respects a --no-respawning flag to disable its behavior. This almost works:

gulp test --watch --no-respawning

Except that the runTests function in @hypothesis/frontend-build complains about not understanding the --no-respawning flag. With a slight modification to the CLI arg parsing, the above command works:

  // Parse command-line options for test execution.
  program
    .option(
      '--grep <pattern>',
      'Run only tests where filename matches a regex pattern'
    )
    .option('--watch', 'Continuously run tests (default: false)', false)
    .parse(process.argv.filter(a => a !== '--no-respawning'));

This is why various other tools that have a --watch flag continue to work in the latest version of Node: they don't use gulp. Normally the Node-specific (as opposed to tool-specific) --watch flag would only be handled when the flag comes before the script name in the command:

node --watch path/to/tool --watch

In the above the first --watch is for Node, the second --watch is for the tool.

Copy link
Member

@robertknight robertknight left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To recap, the issue here is that Gulp is detecting any Node or V8 flag names in the CLI args and doing unwanted things if it sees them. The problem arose after a Node update because --watch is now a recognized Node/V8 flag name, according to the v8flags package. There is a way to turn this behavior off, but it is cumbersome.

I would prefer to use --watch as a more obvious name than --live, but as long as we're still using gulp, then the dumb approach of avoiding flag names that conflict with Node/V8 flags is the easiest thing to do. If we migrate away from gulp in future, we can revert the name to --watch.

@lyzadanger lyzadanger merged commit 3aa4e5e into main May 16, 2023
2 checks passed
@lyzadanger lyzadanger deleted the fix-test-watch branch May 16, 2023 12:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants