【问题标题】:Jake async tasks don't terminated after calling complete()调用 complete() 后,Jake 异步任务不会终止
【发布时间】:2014-05-09 04:40:13
【问题描述】:

我有这个 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 不会自动退出。我每次都要杀了它。我做错什么了吗?

【问题讨论】:

  • 我遇到了和你一样的问题,我认为 mocha 仍在后台做某事,因为在我的实例中 jake 触发了下一个任务但挂起。

标签: node.js testing mocha.js jake


【解决方案1】:

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-10-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-09-23
    • 1970-01-01
    • 2011-07-22
    相关资源
    最近更新 更多