我遇到了一个问题,甚至不确定从哪里开始故障排除。
我用的是slightly modified mocha-casperjs。CasperJS是PhantomJS的包装器。我正在尝试集成完成测试时的咆哮通知。
在调用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是否正在吞噬stdout或类似的东西,从而导致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();发布于 2016-12-10 03:01:00
我遇到了同样的问题。execFile异步运行,所以您需要给它一个执行的机会。通过立即退出CasperJS,没有输出,因为ls没有完成,所以回调没有被调用。一种变通方法是使用setTimeout。下面是我在PhantomJS中做的事情。我假设这对CasperJS也是一样的。
'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));
});
setTimeout(function() { phantom.exit(0) },1000);发布于 2016-03-07 19:37:13
您可以尝试将日志行更改为以下行:
console.log("execFileSTDOUT:" + JSON.stringify(stdout));然后,您应该看到,如果调用execFile : execFileSTDOUT:"“
https://stackoverflow.com/questions/27495303
复制相似问题