首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >大口大口地喝和幻影

大口大口地喝和幻影
EN

Stack Overflow用户
提问于 2015-06-04 03:04:23
回答 1查看 1.2K关注 0票数 0

我正试着用吞咽的方式运行自动测试。一切正常,但我现在不知道如何关闭PhantomJS后,共骗已经完成。我的gulp.js文件如下所示

代码语言:javascript
复制
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的方法?

EN

回答 1

Stack Overflow用户

发布于 2015-07-25 02:38:01

在PhantomJS v2.0下,这对我很有效:

代码语言:javascript
复制
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();
    });
}
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/30628525

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档