2012-07-24 66 views
8

我试图在Windows中运行应用程序,此应用程序有一些摩卡测试。我需要制造。我读这如何在windows node.js上运行Mocha测试(错误:无法找到模块'C: cygdrive c Users)

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

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

我在Github上目录中的应用(外cygwin目录结构)和i节点安装的Windows版本。

我尝试使用PowerShell和设置别名的建议,但我总是得到

> 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 

和我已经安装在该目录摩卡(顺便说一句他为什么不去找在node_modules子目录摩卡?)。问题似乎是C:\cygdrive\c\Users部分我该如何解决这个问题?

我也试过在Cygwin的文件复制到我家/目录,但我得到了

./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 

我应该怎么办?

回答

1

您应该使用msysgit - 它带有make。

+5

我会接受你的答案,最后它是如此麻烦,我只是搬到了Ubuntu的 – 2012-07-24 22:34:15

+0

我经历了和你一样的挫折感,最终做了同样的事情 - 它只是比方式更好在Windows上开发:) – 2012-07-25 01:52:51

0

当你写“做试验”,您会收到这样的:

./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 

这意味着你没有安装在你的项目做摩卡。把摩卡咖啡在你的package.json和运行“故宫安装”:

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

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

} 
} 

后,我得到了在Windows上运行我的测试。

13

我已经能够做到的最好方法是首先在目录中安装摩卡作为开发依赖(例如:npm install mocha --save-dev)。然后在npm test命令里面package.json,使用"test": "mocha"。这样,您就可以在CLI中轻松运行npm test进行标准化。您现在可以在test/目录中设置您的测试,或者在您只有几个测试运行时使用简单的test.js文件。另外,请不要忘记在options上有一个mocha.opts文件。这应该工作,特别是如果你使用Git Bash(我在Windows CMD上尝试过,它也能工作!)。

+0

我发现在路径中添加project-dir \ node_module \ .bin可以像预期的那样使用package_json条目进行测试:“scripts”:{0} {0} R spec“} – Amitabh 2015-10-24 06:56:26

+0

@Amitabh我不建议添加节点模块作为PATH变量。 YMMV,但你会被绑定到一个项目的摩卡版本。 – Bwaxxlo 2015-10-26 10:46:43

相关问题