Mocha works with an NPM test but is not a regular mocha CLI team

I am trying to understand what I am doing wrong in this case. I have a Node.js project with the following in my package. Json

"scripts": { "test": "mocha --recursive ./src/setup/*.js ./test/**/*.js" }, "dependencies": { "mocha": "^2.2.5" } 

When I run "npm test", the mocha tests run correctly:

 $ npm test (successful run) 

However, when I try to just run the mocha command, I have it in my package. json

 $ mocha --recursive ./src/setup/*.js ./test/**/*.js" 

These errors are:

 -sh: mocha: command not found 

I don’t have mocha globally, I just installed it through npm for this particular project.

If I install mocha globally, then it works. Why doesn't it work when I only have mocha installed in the current node_modules directory, but it works with "npm test"?

+5
source share
1 answer

npm scripts automatically add mocha to PATH:

If you depend on modules that define executable scripts, such as test packages, these executable files will be added to the PATH to execute scripts.

https://docs.npmjs.com/misc/scripts#path

+7
source

All Articles