6

I am trying to understand what I am doing wrong in this instance. 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 are run correctly:

$ npm test (successful run) 

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

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

This errors with:

-sh: mocha: command not found 

I do not have mocha globally installed, I only have installed it via npm to this specific project.

If I install mocha globally then it works. Why doesn't it work when I have simply have mocha installed in the current directory's node_modules, yet it does with 'npm test'?

1 Answer 1

8

npm scripts automatically add mocha to the PATH:

If you depend on modules that define executable scripts, like test suites, then those executables will be added to the PATH for executing the scripts.

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

Sign up to request clarification or add additional context in comments.

1 Comment

FWIW, those scripts are usually located in ./node_modules/.bin, which you could add to the $PATH variable.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.