【问题标题】:Get the mocha "end" event from gulp从 gulp 获取 mocha "end" 事件
【发布时间】:2016-01-16 15:38:43
【问题描述】:

我将 gulp-mocha 与 gulp 一起使用,并且我正在尝试在 mocha 测试完成时收到通知。

这是我的gulpfile.js

var gulp = require('gulp');
var mocha = require('gulp-mocha');
var notify = require("gulp-notify");
 
gulp.task('test', function () {
  return gulp.src(['test/**/*.js'], { read: false })
    .pipe( mocha({ reporter: 'nyan' }))
    .on("error", notify.onError({
      message: 'Error: <%= error.message %>'
    }))
    .on('end', function () {
      notify( "Tests passed" )
    });
});
 
gulp.task('watch-test', function () {
  gulp.watch(['./**'], ['test']);
});

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

我设法看到有关“错误”事件的通知,但找不到获取“结束”事件的方法。

知道如何获得它吗?

【问题讨论】:

  • 我遇到了类似的问题...您找到解决方案了吗?
  • 不@AdrianE,不幸的是我没有

标签: testing gulp mocha.js


【解决方案1】:

gulp-notify 与流一起使用(即pipe(notify...),使用node-notifier

我是这样做的:

let gulp     = require('gulp');
let gulpeach = require('gulp-foreach');
let mocha    = require('gulp-mocha');
let notifier = require('node-notifier');

// Run tests.
gulp.task('test', function () {
  gulp.src(['test/test-*.js'])
    .pipe(gulpeach(function (stream, file) {
      return stream
        .pipe(mocha())
        .on('error', (error) => {
          notifier.notify({
            message: ('Command: ' + error.cmd),
          })
        })
      ;
    }))
    .on('finish', () => notifier.notify('Tests completed'))
  ;
});

【讨论】:

    猜你喜欢
    • 2022-11-08
    • 2016-11-28
    • 2019-03-07
    • 1970-01-01
    • 2021-07-16
    • 2015-05-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多