摩卡要求make。 找不到在Windows上工作的make.exe

Mocha(Node.js的testing框架)使用make。

对于我来说,我无法find适用于Windows的make.exe。

一切工作正常在我的Mac上。

我试过使用VS的nmake.exe和make.exe,我发现它是从Unix移植过来的。 但是它们都是不相容的。

它不能只是我

这是makefile:

test: @./node_modules/.bin/mocha -u tdd -R spec .PHONY: test 

在上做吧。 在PHONY,即使我删除它,它从不运行摩卡命令(或至less没有输出)。

运行./node_modules/.bin/mocha -u -tdd -R spec直接给我我的testing报告:

 first suite - ? ten should always be equal to 9+1 ? zero is less all positive numbers ? There is no i in team ? 3 tests complete (8ms) 

编辑3/25/12

  • 最后,处理这个问题的最简单的方法是使用Cygwin,并确保Cygwin的开发包已经安装。 在PowerShell中,我做了Set-Alias make "c:\dev\utils\cygwin\bin\make.exe" ,现在在标准的Mocha Makefiles上make test

嘿,我感觉你;)我是一个忙于建立一个使用节点的新创业团队的一部分。 我们的两个开发人员在OSX上,一个在Linux上。 我在Windows上。

我下载并使用GNU的“Make for Windows” ,现在可以非常高兴地做我们的安装和测试套件。

另外,我强烈鼓励你使用PowerShell – 它有一堆命令别名到UNIX友好的命令(例如Get-ChildItem – > ls)。 这使我们的几个脚本可以在UNIX或Windows上工作,而无需更改。

所以,对于你的问题:

尝试用以下代码替换上面的makefile:

 # Detect if we're running Windows ifdef SystemRoot # If so, set the file & folder deletion commands: FixPath = $(subst /,\,$1) else # Otherwise, assume we're running *N*X: FixPath = $1 endif NODE_MODULES := ./node_modules/.bin/ test: $(call FixPath, NODE_MODULES)mocha -u tdd -R spec .PHONY: test 

注意:使用Makefiles时,目标中的任务必须使用制表符来缩进,而不是空格! 去搞清楚!!

我从这个帖子偷了FixPath例程(感谢Paul :))。 如果在Windows上运行,它将替换字符串的/。

在Windows上制作的一个问题是,为了执行每个任务,它会通过CreateProcess发送到NT的命令行界面。 这意味着当执行makefile时,Powershell将会处理的任何N个 X-isms(例如ls,cat等)将不起作用。 因此,建议用可重写的别名替换内联命令,您可以将其设置为一个NT命令,另一个替换为N X.

也许我会去分叉努力看看,如果我可以得到它执行命令而不是NT命令行的Powershell。 这也将消除上面FixPath的需要;)

如果你被卡住了,请给我打电话;)

你可以使用指挥官在node.js中实现你自己的版本! 尽管我在Mac上,我仍然使用它来做我的项目。 它可以在安装节点的任何地方工作。

以下脚本假定您的cli脚本位于/path/to/your/app/cli

node cli/test.js -u # runs unit tests in /path/to/your/app/tests/unit

node cli/test.js -f # runs functional tests in /path/to/your/app/tests/functional

test.js

 /* * CLI for execution of the mocha test suite. * * test.js --help for instructions. */ var program = require('commander'); program .version('1.0.0') .option('-u, --unit', 'Run unit tests.') .option('-f, --functional', 'Run functional tests.') .on('--help', function(){ console.log('Executes the mocha testsuite.'); console.log(''); }) .parse(process.argv) ; if(!program.unit && !program.functional) { console.log(); console.log('Specify if you want to run unit tests (-u) or functional tests (-f).'); console.log('Run help (-h) for detailed instructions.'); console.log(); } if(program.unit) { require('child_process').exec(__dirname + '/../node_modules/.bin/mocha -u tdd -R spec --recursive -c ' + __dirname + '/../tests/unit', standardOutput); } if(program.functional) { require('child_process').exec(__dirname + '/../node_modules/.bin/mocha -u bdd -R spec --recursive -c ' + __dirname + '/../tests/functional', standardOutput); } /** * Standard output. * * @method standardOutput * @param {Object} error * @param {String} stdout the cli standard output * @param {String} stderr output of errors */ function standardOutput(error, stdout, stderr) { console.log(stdout); console.log(stderr); } 

对于那些不想使用make的人来说,你也可以在全局安装mocha ,以便在普通的windows命令行中工作:

npm install -g mocha

然后用mocha path\to\test.js运行你的测试

如果您正在使用cygwin的make(cygwin / bin / make.exe),请注意它需要makefile中的制表符分隔符。 如果您的编辑器将制表符转换为空格,您将最终得到类似的错误

makefile:23: *缺少分隔符。 停止。

我读过GNU的Make for Windows,上面提到的,对于空格或制表符来说是可以的,但是我还没有尝试过。

有关更多详细信息,请参阅如何在Windows中使用Mocha进行节点测试 。