摩卡需要制作.找不到适用于Windows的make.exe

tig*_*tig 13 windows mocha.js node.js

Mocha(Node.js的测试框架)使用make.

对于我的生活,我找不到兼容的make.exe for Windows.

我的Mac上一切正常.

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

它不仅仅是我

这是makefile:

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

.PHONY: test
Run Code Online (Sandbox Code Playgroud)

制作barfs.在PHONY中,即使我删除它,它也从不运行mocha命令(或者至少没有输出).

./node_modules/.bin/mocha -u -tdd -R spec直接跑步给我测试报告:

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)
Run Code Online (Sandbox Code Playgroud)

编辑3/25/12

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

Ric*_*ner 10

嘿,我觉得你;)我是一个忙着用节点建立新创业公司的团队的一员.我们的两个开发人员在OSX上,一个在Linux上.我在Windows上.

我下载并使用GNU的"Make for Windows",现在可以很高兴地制作我们的安装和测试套件.

此外,我强烈建议您使用PowerShell - 它有一堆别名的命令(例如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
Run Code Online (Sandbox Code Playgroud)

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

我从这篇文章中偷走了FixPath例程(感谢Paul :)).如果在Windows上运行,它将替换字符串的/ with.

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

也许我会绕过去分配Gnu Make,看看我是否可以在执行命令而不是NT命令行时将其发送到Powershell.这也将消除上面对FixPaths的需求;)

如果你遇到困扰我吧;)


shr*_*ing 5

您可以使用commander在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);
}
Run Code Online (Sandbox Code Playgroud)