4

問題が発生しており、どこからトラブルシューティングを開始すればよいかさえよくわかりません。

少し変更した 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 が 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();
4

2 に答える 2

1

私は同じ問題に遭遇しました。 execFile非同期で実行されるため、実行する機会を与える必要があります。CasperJS をすぐに終了すると、ls が終了せず、コールバックが呼び出されなかったため、出力はありません。回避策の 1 つは、 を使用すること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-12-09T19:01:00.047 に答える