41

非常に明白な何かを見落としている可能性がありますがgulp-mocha、エラーを検出することができずgulp watch、テストが失敗するたびにタスクが終了してしまいます。

セットアップは非常に簡単です。

gulp.task("watch", ["build"], function () {
  gulp.watch([paths.scripts, paths.tests], ["test"]);
});

gulp.task("test", function() {
  return gulp.src(paths.tests)
    .pipe(mocha({ reporter: "spec" }).on("error", gutil.log));
});

または、ハンドラーをストリーム全体に配置しても、同じ問題が発生します。

gulp.task("test", function() {
  return gulp.src(paths.tests)
    .pipe(mocha({ reporter: "spec" }))
    .on("error", gutil.log);
});

も使用してみましたが、plumber役に立たなかったので、些細なことを見落としていると思います。combinegulp-batch

要点: http://gist.github.com/RoyJacobs/b518ebac117e95ff1457

4

2 に答える 2

41

香川修平の答えを拡張..

発行終了は、キャッチされていないエラーが例外に変換されるため、gulp が終了するのを防ぎます。

監視変数を設定して、監視を介してテストを実行しているかどうかを追跡し、CI を開発しているか実行しているかに応じて終了するかどうかを確認します。

var watching = false;

function onError(err) {
  console.log(err.toString());
  if (watching) {
    this.emit('end');
  } else {
    // if you want to be really specific
    process.exit(1);
  }
}

gulp.task("test", function() {
  return gulp.src(paths.tests)
    .pipe(mocha({ reporter: "spec" }).on("error", onError));
});

gulp.task("watch", ["build"], function () {
  watching = true;
  gulp.watch([paths.tests], ["test"]);
});

これは、開発と CI に使用できます。

于 2014-02-12T17:24:13.030 に答える