1

gulp-notify用来获取通过和失败黄瓜步骤的通知。

问题是我只在失败时收到通知,而不是在测试通过时收到通知。

没有抛出错误,但终端显示通过测试,我没有收到任何通知。

这是我的 Gulpfile.js 的内容:

var gulp = require('gulp');
var cucumber = require('gulp-cucumber');
var notify = require('gulp-notify');

gulp.task('cucumber', function() {
    gulp.src('*features/*')
        .pipe(cucumber({
            'steps': '*features/step_definitions/*.js',
            'support': '*features/support/*.js'
        }))
        .on('error', notify.onError({
            title: 'Red',
            message: 'Your test(s) failed'
        }))
        .pipe(notify({
            title: 'Green',
            message: 'All tests passed (you can refactor)'
        }));

});

gulp.task('watch', function() {
    gulp.watch(['features/**/*.feature', 'features/**/*.js', 'script/**/*.js'], ['cucumber']);
});

gulp.task('default', ['watch']);

有什么想法我可能会错过吗?

4

1 回答 1

1

我通过直接调用来实现它cucumberjs,如下所示:

const gulp = require('gulp');
const notifier = require('node-notifier');
const path = require('path');

gulp.task('cucumber', function() {
  const { exec } = require('child_process');
  exec('clear && node_modules/.bin/cucumber-js', (error, stdout, stderr) => {
      if (error) {
          notifier.notify({
            title: 'Red',
            message: 'Your test(s) failed',
            icon: path.join(__dirname, 'failed.png')
          });
      } else {
          notifier.notify({
            title: 'Green',
            message: 'All tests passed (you can refactor)',
            icon: path.join(__dirname, 'passed.png')
          });
      }

      console.log(stdout);
      console.log(stderr);
  });
});

gulp.task('watch', function() {
  gulp.watch(['features/**/*.js', 'script/**/*.js'], ['cucumber']);
});

gulp.task('default', ['cucumber', 'watch']);
于 2017-10-10T09:45:51.337 回答