首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >从gulp获取mocha "end“事件

从gulp获取mocha "end“事件
EN

Stack Overflow用户
提问于 2016-01-16 23:38:43
回答 1查看 351关注 0票数 4

我正在使用gulp mocha和gulp,并且我试图在mocha测试完成时收到通知。

这是我的gulpfile.js

代码语言:javascript
复制
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'] );

我设法看到了"error“事件的通知,但我找不到一种方法来获取"end”事件。

有关于如何获得它的想法吗?

EN

回答 1

Stack Overflow用户

发布于 2017-10-23 14:48:30

gulp-notify适用于流(即pipe(notify...),请使用node-notifier

我是这样做的:

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

https://stackoverflow.com/questions/34828794

复制
相关文章

相似问题

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