Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

mocha running with NPM test but not regular mocha CLI command

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'?

like image 972
Collin Estes Avatar asked Jun 29 '15 15:06

Collin Estes


1 Answers

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

like image 112
beautifulcoder Avatar answered Sep 29 '22 14:09

beautifulcoder