0

This gulp task doesn't exit after finished, I have to manually press Ctrl-C to exit.

gulp.task('test', function(done) {
    var testem = require('testem');

    var testemOptions = {
        file: 'testem.json'
    };

    var t = new testem();

    t.startCI(testemOptions, done);
});

How can i make this task exit properly?

Note: Actually it exits itself, but it takes like 15 seconds after finished.

Output:

[15:49:59] Using gulpfile ~/gulpfile.js
[15:49:59] Starting 'test'...
ok 1 PhantomJS 1.9 - Integration Tests: Home Index Page

1..3
# tests 3
# pass  3
# fail  0

# ok
[15:50:00] Finished 'test' after 1.33 s
4

1 回答 1

1

设法使用 重现您的问题Chromium launcher,但它应该与PhantomJS. 15sec CPU在结束task和实际退出之间确实存在延迟process

> time gulp testem
Starting 'testem'...
ok 1 Chrome 32.0 - sass: link
ok 2 Chrome 32.0 - Unit - HomeRoute: exists
ok 3 Chrome 32.0 - Unit - HomeRoute: #model
ok 4 Chrome 32.0 - Unit - HomeRoute: redirect

1..4
# tests 4
# pass  4
# fail  0

# ok
Finished 'testem' after 938 ms
gulp testem  1.27s user 0.25s system 9% cpu 16.581 total

通过删除done callback您在任务上设置的并传递给startCI它,不要将此作为参数,

var testem = require('testem');

gulp.task('test', function () {

  var testemOptions = {
    file: 'testem.json'
  };

  var t = new testem();
  return t.startCI(testemOptions);

});

任务按预期运行并在完成时正确退出:

> time gulp testem
Starting 'testem'...
ok 1 Chrome 32.0 - sass: link
ok 2 Chrome 32.0 - Unit - HomeRoute: exists
ok 3 Chrome 32.0 - Unit - HomeRoute: #model
ok 4 Chrome 32.0 - Unit - HomeRoute: redirect

1..4
# tests 4
# pass  4
# fail  0

# ok
gulp testem  1.26s user 0.19s system 91% cpu 1.582 total

顺便说一句,不知道你能做到这一点,只需将一个带有file属性的对象传递给startCI,我认为你应该使用你在里面提供的配置参数读取配置文件fs.readFile并将其数据解析JSON为启动。testemtestem.json

还有一件事,有一个 gulp 插件gulp-testem我没有机会尝试,但它可能会有所帮助。

于 2014-08-01T22:39:57.433 回答