12

I'm trying to run an app in windows and this app has some mocha tests. I need make. I read this

Mocha requires make. Can't find a make.exe that works on Windows

and this

Node.js cannot find module - interfering with cygwin on Windows

I have the app in the Github directory (outside of cygwin directory structure ) and i installed the windows version of node.

I Tried using powershell and setting the alias as suggested but i always get

> module.js:340
>     throw err;
>           ^ Error: Cannot find module 'C:\cygdrive\c\Users\Nicola\AppData\Roaming\npm\node_modules\mocha\bin\mocha'
>     at Function.Module._resolveFilename (module.js:338:15)
>     at Function.Module._load (module.js:280:25)
>     at Module.runMain (module.js:487:10)
>     at process.startup.processNextTick.process._tickCallback (node.js:244:9) Makefile:5: recipe for target `test' failed make: ***
> [test] Error 1

and i have mocha installed in that directory ( BTW why doesn't he look for mocha in the node_modules subdir? ). The problems seems to be the C:\cygdrive\c\Users part how do i take that off?

I also tried copying the file to my home/ directory under cygwin but i got

./node_modules/.bin/mocha: line 1: ../mocha/bin/mocha: No such file or directory
Makefile:5: recipe for target `test' failed
make: *** [test] Error 127

what should i do?

Community
  • 1
  • 1
Nicola Peluchetti
  • 76,206
  • 31
  • 145
  • 192

4 Answers4

22

Best way I've been able to do it is to first install mocha in the directory as a dev dependency (i.e: npm install mocha --save-dev). Then in the npm test command inside package.json, use "test": "mocha". This way, you can easily run npm test in CLI for standardization. You can now either setup your tests in a test/ directory or have a simple test.js file in case you only have a few tests to run. Also, don't forget to have a mocha.opts file with your options. This should work, especially if you're using Git Bash (I tried on windows CMD and it works too!).

Bwaxxlo
  • 1,860
  • 13
  • 18
  • I found adding project-dir\node_module\.bin to the path makes things work as expected with the package_json entry for test as: "scripts": { "test": "mocha test -u bdd -R spec" } – Amitabh Oct 24 '15 at 06:56
  • @Amitabh I wouldn't recommend adding node modules as a PATH variable. YMMV but you will be tied down to one version of mocha for projects. – Bwaxxlo Oct 26 '15 at 10:46
  • after running `npm install mocha --save-dev`, a simple call to `npm init` created the `package.json` file for me. I created a simple Mocha test file `test.js` (see the [Getting Started section](https://mochajs.org/)) and ran it at the command line with `npm test`. Fantastic answer!! – Jonathan Benn Feb 22 '19 at 21:50
3

You can configure the npm test command inside the package.json file to run mocha using the syntax below.

  "scripts": {
      "test": "node node_modules/mocha/bin/mocha --recursive"
  },
2

My solution was run the command node ./node_modules/mocha/bin/mocha

It happened because mocha is not variable of environment of the Windows.

Breno Gomes
  • 105
  • 3
0

when you write "make test" and you receive this:

./node_modules/.bin/mocha: line 1: ../mocha/bin/mocha: No such file or directory
Makefile:5: recipe for target `test' failed
make: *** [test] Error 127

it means that you don't have Mocha installed in your project. Put mocha in your package.json and run 'npm install':

{
"name": "appName"
, "version": "0.0.1"
, "private": true
, "dependencies": {

  "mocha": "1.3.0"
, "should": "1.0.0"

}
}

after that i got my tests running on windows.

Ville
  • 464
  • 4
  • 14