这个吞食任务挂在exec('node config/app')线上。第一个exec工作正常,但第二个只挂起。
gulp.task('test', function(cb) {
var exec = require('child_process').exec;
exec('echo 3', function(err, stdout) {
console.log(stdout);
});
exec('node config/app', function(err, stdout, stderr) {
console.log(stdout);
var testemOptions = {
file: 'testem.json'
};
var t = new testem();
return t.startCI(testemOptions, function() {
cb();
});
});
});我可以看到输出3,但是第二个console.log没有显示输出。
在使用testem运行测试之前,我试图运行我的服务器。
我尝试过类似的解决方案,但它不起作用:当尝试使用nodejs运行git短日志时,Exec不返回任何内容。
此外,我最近还问了一个悬挂式的茶具吞咽任务问题:完成后,Testem任务挂起。
编辑
我目前的解决办法是:
gulp.task('test', /*['build'],*/ function(cb) {
var spawn = require('child_process').spawn;
var proc = spawn('node', ['config/app']);
proc.stdout.on('readable', function() {
var output = proc.stdout.read();
if (output && output.toString().match('express listening')) {
var testemOptions = {
file: 'testem.json'
};
var t = new testem();
t.startCI(testemOptions, function() {
proc.kill();
cb();
});
}
});
});发布于 2014-08-24 09:06:53
如果您想使用testem测试“/app”服务器,则不能使用exec。
当命令完成时,Exec应该进行回调,因此在您的情况下,它将永远不会回调。
试着
gulp.task('test', function(cb) {
var spawn = require('child_process').spawn;
var proc = spawn('node', ['config/app']);
var testStarted = false;
proc.stdout.on('readable', function() {
if (testStarted) return;
testStarted = true;
var testemOptions = {
file: 'testem.json'
};
var t = new testem();
t.startCI(testemOptions, function() {
proc.kill()
cb();
});
}
});请注意,我没有测试这段代码,它可能不会处理您可能遇到的所有角落情况(例如,如果服务器意外停止)。
发布于 2014-09-14 13:41:10
在github上有ŧestem插件。
https://stackoverflow.com/questions/25469976
复制相似问题