我遇到了问题,甚至不确定从哪里开始进行故障排除。
我正在使用稍微修改过的 mocha-casperjs。CasperJS 是 PhantomJS 的包装器。我正在尝试在完成测试时集成 Growl 通知。
我可以在调用 mocha.run 之前成功执行通知,如下所示:
execFile("terminal-notifier", ["-message", "Tests Begin"], null, function (err, stdout, stderr) {
console.log("execFileSTDOUT:", JSON.stringify(stdout))
console.log("execFileSTDERR:", JSON.stringify(stderr))
})
// for convience, expose the current runner on the mocha global
mocha.runner = mocha.run(function() {
...
但是,这失败了:
// for convience, expose the current runner on the mocha global
mocha.runner = mocha.run(function() {
execFile("terminal-notifier", ["-message", "Tests Begin"], null, function (err, stdout, stderr) {
console.log("execFileSTDOUT:", JSON.stringify(stdout))
console.log("execFileSTDERR:", JSON.stringify(stderr))
})
...
我不太了解 Mocha 或 PhantomJS 的内容。Mocha 是否会吃掉标准输出或类似的东西,导致 execFile 调用失败?还有什么我没有得到的吗?
谢谢,凯文
- - 更新 - -
情节变厚了。仅仅包括 casper 对象就会杀死 execFile。
使用“casperjs test.js”运行以下代码成功输出 execFile。取消注释 casper 对象不会导致输出。
'use strict';
var process = require("child_process");
var spawn = process.spawn;
var execFile = process.execFile;
execFile("ls", ["-lF", "/usr"], null, function (err, stdout, stderr) {
console.log("execFileSTDOUT:", JSON.stringify(stdout));
console.log("execFileSTDERR:", JSON.stringify(stderr));
});
//var casper = require('casper').create();
//casper.exit();