Search code examples
node.jsunit-testingnpmmocha.jsnyc

Passing options to mocha when running from npm


I am setting up nyc/mocha for my project. I want to pass --exit option to mocha when running mocha with/without nyc.

Here's my packages.json:

"scripts": {
    "start": "node ./app",
    "test": "./node_modules/.bin/mocha --exit",
    "test-with-coverage": "nyc --reporter=html mocha --reporter mochawesome --exit",
    "apidoc": "apidoc -i routes/ -o apidocs/"
  }

But this throws invalid option error when I run npm test or npm run test-with-coverage.

How do you pass any options to mocha from npm?


Solution

  • The only reason I can see for having the problem with the code you show is that --exit was added in Mocha 4.0.0 and you happen to be using an older version.