2

I am looking for away to do something like this:

package.json

...
"scripts":{

      "debug_mocha_test":"node-debug ./node_modules/mocha/bin/_mocha --grep ${names}"
  }
...

so then at the command line, I can then run something like:

npm run debug_mocha_test --names 'test1'

or whatever

does anyone know how to do this, or is there a better way than this?

For some context, the mocha testing library has a --grep function like so:

http://mochajs.org/

  • possible duplicate of [Sending command line arguments to npm script](http://stackoverflow.com/questions/11580961/sending-command-line-arguments-to-npm-script) – laggingreflex Jul 02 '15 at 06:36

1 Answers1

1

Since npm 2.0.0, it's possible to pass arguments to a script defined in the package.json file (https://github.com/npm/npm/pull/5518). The format is not as clean as one would expect, but it works.

To pass the "foo" parameter to the "start" script:

npm run-script start -- foo=1

So in your case, the script in package.json should be:

"debug_mocha_test":"node-debug ./node_modules/mocha/bin/_mocha --grep"

And you can run it using:

npm run debug_mocha_test -- test1
nacho_dh
  • 1,847
  • 3
  • 18
  • 27