0

Example: The following command is executed when I am trying to execute unit tests of an Angular app: npm run test -- --no-watch --browsers=ChromeHeadlessCI

I understood that the double dash (--) is needed to pass arguments into the npm script. but I don't understand what is the first '--' trying to do? because it does not have any argument behind it, does not like --no-watch or --browsers=ChromeHeadlessCI

the command example from: https://angular.io/guide/testing

Andreycw
  • 63
  • 1
  • 5
  • The npm v6.x [docs](https://docs.npmjs.com/cli/v6/commands/npm-run-script#description) provide the following description: _"As of npm@2.0.0, you can use custom arguments when executing scripts. The special option `--` is used by `getopt` to delimit the end of the options. npm will pass all the arguments after the `--` directly to your script"_. Essentially, the special `--` option demarcates the end of any option(s) belonging to the npm run command itself (e.g. `--silent`), and the beginning of the argument(s) that are to be passed to the end of the npm script. – RobC Sep 14 '21 at 07:58
  • Does this answer your question? [What does -- do when running an npm command?](https://stackoverflow.com/questions/43046885/what-does-do-when-running-an-npm-command) – RobC Sep 14 '21 at 14:15

1 Answers1

0

It is how npm parses the command. In your example:

npm run test -- --no-watch --browsers=ChromeHeadlessCI

The -- tells npm that any following arguments are for the test script, and not npm. Take this example: npm run test --workspace=a -- --no-watch --browsers=ChromeHeadlessCI

Workspaces are functionality of npm, not the test script.

https://docs.npmjs.com/cli/v7/commands/npm-run-script

John
  • 1,240
  • 9
  • 13