我对节点很陌生,在任何类型的“适当”环境中都可以进行开发。我已经为我当前的项目安装了gulp,以及摩卡和其他一些模块。这是我的gulpfile.js:
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才能返回到命令提示符。我怎样才能把它做好呢?
发布于 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();});};
发布于 2016-06-07 10:03:30
发布于 2017-10-24 15:30:32
在升级到mocha 4之后,我通过将--exit传递给mocha来解决这个问题。
有关详细信息,请参阅https://boneskull.com/mocha-v4-nears-release/#mochawontforceexit。
当使用gulp时,将该选项添加为exit: true,如下所示:
gulp.task('test', function () {
return gulp.src(['tests/**/*.spec.js'], {read: false})
.pipe(mocha({ exit: true }));
});https://stackoverflow.com/questions/33191377
复制相似问题