2017-10-09 74 views
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']); 

任何想法我可能會錯過?

回答

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']);