Skip to content

Instantly share code, notes, and snippets.

@pulkitsinghal
Last active April 9, 2017 21:49
Show Gist options
  • Save pulkitsinghal/d53ad3538e153e6003a99139715beed3 to your computer and use it in GitHub Desktop.
Save pulkitsinghal/d53ad3538e153e6003a99139715beed3 to your computer and use it in GitHub Desktop.
How it all ties together: cli, npm, package.json, pretest, test, mocha

Both configurations of package.json hare equally valid:

  1. npm test will run linting and then testing:
"test": "jshint . && mocha",
  1. npm test will still run linting and then testing:
"pretest": "jshint",
"test": "mocha",

... BUT it is NOT possible to invoke npm pretest directly from the command line ... aha! But I recently read:

## All scripts under scripts can be executed with npm run-script [script name].

# Like this, to run our test command:
npm run-script pretest
npm run-script test

# `run` and `run-script` are aliased
npm run pretest
npm run test
  1. If you pass -- (there’s a space after the --, right there) you can pass argument through to the underlying command.
## http://www.marcusoft.net/2015/08/npm-scripting-configs-and-arguments.html#passing-through-command-line-argument

# So if you have:
# "scripts": { "test": "mocha" }
# then running:
npm run test -- --debug-brk

# is like running `mocha --debug-brk`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment