【问题标题】:Gulp: Wait for express server to start before running testsGulp:在运行测试之前等待快速服务器启动
【发布时间】:2015-11-03 06:16:10
【问题描述】:

我对节点很陌生。我构建了一个示例 express 应用程序并使用 cucumber.js 为其编写了一些 BDD 测试。我想使用 gulp 自动化测试,这样当我运行我的测试时,它将首先启动 express 应用程序,一旦服务器启动,运行测试。但是,目前测试在服务器启动之前运行,因此都失败了。有没有办法等待(使用 gulp)服务器启动,然后才运行测试?

我在这里使用 gulp-cucumber 和 gulp-express(有些被 gulp-load-plugins 隐藏)。

我的 gulpfile(部分):

var gulp = require('gulp'),
  plugins = require('gulp-load-plugins')();

gulp.task('server', function () {
  plugins.express.run(['bin/www']);
});

gulp.task('cucumber', ['server'], function() {
  return gulp.src('features/*').pipe(plugins.cucumber({
    'steps': 'features/steps/*.steps.js',
    'support': 'features/support/*.js'
  }));
});

gulp.task('test', ['server', 'cucumber']);

【问题讨论】:

    标签: node.js express gulp cucumberjs


    【解决方案1】:

    我必须使用这个解决方案 - https://www.npmjs.com/package/run-sequence

    var gulp = require('gulp'),
      plugins = require('gulp-load-plugins')(),
      runSequence = require('run-sequence');
    
    gulp.task('server', function () {
      plugins.express.run(['bin/www']);
    });
    
    gulp.task('cucumber', function() {
      return gulp.src('features/*').pipe(plugins.cucumber({
        'steps': 'features/steps/*.steps.js',
        'support': 'features/support/*.js'
      }));
    });
    
    gulp.task('test',  function(){
         runSequence('server', 'cucumber');
    });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-01-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-07-24
      • 2016-03-24
      • 2022-11-30
      • 1970-01-01
      相关资源
      最近更新 更多