调用complete()后,Jake异步任务不会终止

时间:2014-05-09 04:40:14

标签: node.js testing mocha jake

我有这个jake任务来运行我的所有测试:

desc('Run all tests')
task('test', {async: true}, function(args) {
  process.env.NODE_ENV = 'test';
  var Mocha = require('mocha');
  var fs = require('fs'),  path = require('path');
  var mocha = new Mocha({reporter: 'spec', ui: 'bdd'});
  fs.readdirSync('test/unit').forEach(function(file) {
    mocha.addFile(path.join('test/unit', file));
  });
  fs.readdirSync('test/functional').forEach(function(file) {
    mocha.addFile(path.join('test/functional', file));
  });
  mocha.run(function(failures) {
    if (failures) {
      fail(failures);
    } else {
      complete();
    }
  });
});

但是当测试通过时,jake不会自动退出。我每次都要杀了它。我做错了吗?

1 个答案:

答案 0 :(得分:0)

只是一个猜测,但你需要添加一个监听器吗?

jake.addListener('complete', function () {
    console.log('_____finished_____')
    process.exit();
});