首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >咽喉挂在“结束”之后

咽喉挂在“结束”之后
EN

Stack Overflow用户
提问于 2015-10-17 20:41:02
回答 4查看 9.9K关注 0票数 11

我对节点很陌生,在任何类型的“适当”环境中都可以进行开发。我已经为我当前的项目安装了gulp,以及摩卡和其他一些模块。这是我的gulpfile.js:

代码语言:javascript
复制
var gulp = require('gulp');
var mocha = require('gulp-mocha');
var eslint = require('gulp-eslint');

gulp.task('lint', function () {
    return gulp.src(['js/**/*.js'])
        // eslint() attaches the lint output to the eslint property 
        // of the file object so it can be used by other modules. 
        .pipe(eslint())
        // eslint.format() outputs the lint results to the console. 
        // Alternatively use eslint.formatEach() (see Docs). 
        .pipe(eslint.format())
        // To have the process exit with an error code (1) on 
        // lint error, return the stream and pipe to failOnError last. 
        .pipe(eslint.failOnError());
});

gulp.task('test', function () {
    return gulp.src('tests/test.js', {read: false})
        // gulp-mocha needs filepaths so you can't have any plugins before it 
        .pipe(mocha({reporter: 'list'}));
});

gulp.task('default', ['lint','test'], function () {
    // This will only run if the lint task is successful...
});

当我运行“gulp”时,它似乎完成了所有的任务,但是挂起了。我必须使用ctrl+c才能返回到命令提示符。我怎样才能把它做好呢?

EN

回答 4

Stack Overflow用户

回答已采纳

发布于 2015-10-22 18:18:31

抱歉,伙计们!事实证明,这是在咽喉摩卡常见问题中解决的。引用如下:

测试套件不退出 如果您的测试套件没有退出,可能是因为您仍然有一个挥之不去的回调,通常是由打开的数据库连接造成的。您应该关闭此连接或执行以下操作: Gulp.task(默认),函数() {返回gulp.src('test.js') .pipe(mocha () .once('error',function () { process.exit(1);}) .once('end',function (){ process.exit();});};

票数 16
EN

Stack Overflow用户

发布于 2016-06-07 10:03:30

如果您没有在gulp-mocha之后运行任何内容,则接受的解决方案将适用于您。但是,如果您需要在gulp-mocha之后运行任务(例如,在部署构建之前运行mocha测试),下面的解决方案将防止gulp无限期挂起,同时仍然允许任务在gulp-mocha之后运行

代码语言:javascript
复制
gulp.on('stop', () => { process.exit(0); });
gulp.on('err', () => { process.exit(1); });

这是因为gulp 承继来自策划人,在所有任务运行到完成或错误之后,发布事件分别运行到完成或错误。

票数 3
EN

Stack Overflow用户

发布于 2017-10-24 15:30:32

在升级到mocha 4之后,我通过将--exit传递给mocha来解决这个问题。

有关详细信息,请参阅https://boneskull.com/mocha-v4-nears-release/#mochawontforceexit

当使用gulp时,将该选项添加为exit: true,如下所示:

代码语言:javascript
复制
gulp.task('test', function () {
  return gulp.src(['tests/**/*.spec.js'], {read: false})
  .pipe(mocha({ exit: true }));
});
票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/33191377

复制
相关文章

相似问题

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