“整理”之后,
我是新来的节点,并在任何“适当”的环境中发展。 我已经为我目前的项目安装了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... });
当我运行'吞咽',似乎完成了所有的任务,但挂起。 我必须按Ctrl + C返回到命令提示符。 我如何才能正确完成?
道歉,伙计! 原来,这是在一揽子 – 摩卡常见问题解答 。 去引用:
testing套件不退出
如果你的testing套件没有退出,那么可能是因为你仍然有一个拖延的callback,通常是由一个开放的数据库连接引起的。 您应closures此连接或执行以下操作:
gulp.task('default', function () { return gulp.src('test.js') .pipe(mocha()) .once('error', function () { process.exit(1); }) .once('end', function () { process.exit(); }); });
如果你没有运行任何东西,接受的解决scheme将为你工作。 但是,如果您需要在gulp-mocha
之后运行任务(例如在部署构build之前运行mochatesting),则可以采用以下解决scheme来防止gulp
无限期挂起,同时允许任务在gulp-mocha
之后运行:
gulp.on('stop', () => { process.exit(0); }); gulp.on('err', () => { process.exit(1); });
这是gulp
,因为gulp
从orchestrator inheritance ,在所有任务运行完成或错误之后,它们会发出事件 。
在gulp任务中添加一个return语句。 或者运行callback。
gulp.task('default', ['lint','test'], function (next) { // This will only run if the lint task is successful... next(); });
升级到摩卡4后,我可以通过传递给摩卡来解决这个问题。
有关更多信息,请参阅https://boneskull.com/mocha-v4-nears-release/#mochawontforceexit 。
在使用gulp-mocha时,将该选项添加为exit: true
如下所示:
gulp.task('test', function () { return gulp.src(['tests/**/*.spec.js'], {read: false}) .pipe(mocha({ exit: true })); });
- Glob / minimatch:如何gulp.src()的一切,然后排除文件夹,但保留一个文件
- 如何处理非SPA使用的项目级捆绑?
- Gulp似乎在工作,但构build文件尚未处理
- Visual Studio 2013/2015 – 节点包构build错误(gulp_util)
- 启动Node.js服务器W / GULP“连接”rest实时刷新(Angular应用W / HTML5模式)
- gulp复制单个文件(srcpipe道dest)与通配目录
- 使用没有全局吞噬的gulp //编辑:并且不链接到bin js文件
- 在通过gulp-submodule注入依赖项的模块上运行gulp任务,通过gulp-submodule依次拥有自己的依赖项,失败
- 为什么Gulp随机失败ENOENT错误(或)无法生成输出(或意外删除)?