我正试着用吞咽的方式运行自动测试。一切正常,但我现在不知道如何关闭PhantomJS后,共骗已经完成。我的gulp.js文件如下所示
var gulp = require('gulp');
var connect = require('gulp-connect-php');
var shell = require('gulp-shell');
var codecept = require('gulp-codeception');
gulp.task('webserver', function() {
connect.server({
base : './public'
});
});
gulp.task('phantom', shell.task(['phantomjs.exe --webdriver=4444']));
gulp.task('codecept', function() {
gulp.src('./tests/*.php').pipe(codecept());
});
gulp.task('tests', ['phantom', 'codecept']);有没有办法在所有测试完成后停止Phantom,或者更好的午餐Phantom的方法?
发布于 2015-07-25 02:38:01
在PhantomJS v2.0下,这对我很有效:
var gulp = require('gulp');
var gutil = require('gulp-util');
var codecept = require('gulp-codeception');
gulp.task('codecept', function(done) {
runInPhantomJs(function() {
return gulp.src('./tests/*.php').pipe(codecept());
}, done);
});
function runInPhantomJs(fn, done) {
var args = [ '--webdriver=4444' ],
phantomjsProcess = childProcess.spawn('phantomjs', args),
completed = false;
phantomjsProcess.stdout.on('data', function(data) {
if (data.toString().indexOf('running on port') >= 0) {
fn().on('end', function() {
completed = true;
phantomjsProcess.kill();
});
}
});
phantomjsProcess.stderr.on('data', function(data) {
gutil.log(gutil.colors.red(data));
});
phantomjsProcess.on('close', function(code) {
if (code && !completed) {
return done(new Error('phantomjs failed with code: ' + code + '\n' +
'Check that port 4444 is free and that there are no other ' +
'instances of phantomjs running.'));
}
done();
});
}https://stackoverflow.com/questions/30628525
复制相似问题