我尝试在 win 7 上将 mocha 与 webstorm 测试运行器一起使用。
我有这些配置参数:
Node 路径:
C:\Program Files (x86)\nodejs\node.exe
工作目录:
D:\creation\software developer\projects\dev\document root\
Node 应用js文件的路径:
C:\Users\inf3rno\node_modules\mocha\bin\_mocha
应用参数:
test
我在 webstorm 控制台中收到以下错误消息
✖ 1 of 1 test failed:
但没有关于哪个测试失败的信息。 :S
如何解决?
(在 git bash 中我得到了详细的错误信息,所以 mocha 安装好了)
尝试了不同的记者,但似乎没有一个有效。我认为问题出在 Error 对象上。其他一切都显示良好。
写了一个自定义报告器,发现堆栈是否显示在 webstorm 控制台上是完全随机的。最好的选择是用 process.stderr.write 打印它,用 console.log 或 process.stdout.write 什么都不显示。我不知道为什么会这样。也许是某种类型的超时,但我将超时设置为 9999999。:S :S :S 嗯,也许 webstorm runner 有超时,这取决于那个,而不是 mocha 超时设置...
与本记者一起测试:
exports = module.exports = WebStorm;
/**
* Initialize a new `WebStorm` test reporter.
*
* @param {Runner} runner
* @api public
*/
//decribe -> suite
//it -> test
function WebStorm(runner) {
var buffer = [];
var suites = [];
var fails = [];
runner.on("suite", function(suite){
suites.push(suite.title || "''");
});
runner.on("suite end", function(suite){
if (fails.length > 0)
buffer.push("describe "+suites.join(".")+"\n"+fails.join("\n"));
fails = [];
suites.pop();
});
runner.on("fail", function(test, err){
fails.push(" it fail "+test.fullTitle() + err.message);
});
runner.on("end", function (){
process.stderr.write(buffer.length+"\n");
//process.stderr.write(buffer.join("\n"));
});
}
我发现输出文本有多长并不重要,重要的是在显示它之前需要等待多长时间。所以我仍然认为这是一个超时问题,而不是标准输出错误。 webstorm 控制台返回:“Process finished with exit code 59”,意思是“发生意外的网络错误。”
更改为 jasmine-node,它正在工作。
编辑:
我换成jasmine2,在windows上也有同样的问题。最简单的解决方法是将 process.exit
延迟 1 毫秒。所以它不能在 stdout.write
结束之前退出。 (手动刷新 stdout 并仅在此之后调用 exit 可能也是一个可行的解决方案。)
最佳答案
虽然更大的权力是debating on the hows and the whys to fix this , 较小的凡人可以求助于此解决方法:
- 创建一个名为 testRunner.js(或其他名称)的文件
- 向其中添加以下代码行
- 修改每个项目的测试文件列表
- 在 webstorm 中,运行
testRunner.js
来运行你的测试
testRunner.js
var testFiles=["test/_helper.js","test/tests.js","test/tests.coffee"];
var Mocha = require('mocha');
var mocha = new Mocha;
mocha.reporter('spec').ui('bdd');
for (var i =0;i<testFiles.length;i++){
mocha.addFile(testFiles[i]);
}
var runner = mocha.run(function(){
console.log('finished');
});
礼貌:http://wuntusk.blogspot.com/2012/06/using-webstorm-or-phpstorm-and-mocha.html
关于windows - mocha + webstorm - 错误信息被破坏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13151940/