Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to run Mocha tests on windows node.js ( Error: Cannot find module 'C:\cygdrive\c\Users )

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?

like image 439
Nicola Peluchetti Avatar asked Jul 24 '12 16:07

Nicola Peluchetti


2 Answers

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"
  },
like image 121
Leonardo Nicolas Avatar answered Oct 12 '22 18:10

Leonardo Nicolas


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

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

like image 21
Breno Gomes Avatar answered Oct 12 '22 18:10

Breno Gomes