Ooberdan Ooberdan - 8 months ago 81
Node.js Question

Gulp hangs after "Finishing"

I'm new to node and developing in any sort of "proper" environment. I've installed gulp for my current project, along with mocha and a few other modules. Here is my 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.
// eslint.format() outputs the lint results to the console.
// Alternatively use eslint.formatEach() (see Docs).
// To have the process exit with an error code (1) on
// lint error, return the stream and pipe to failOnError last.

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...

When I run 'gulp', it appears to complete all its tasks, but hangs. I have to ctrl+c to get back to the command prompt. How do I get it to finish properly?


Apologies, folks! Turns out that this is addressed in the gulp-mocha FAQ. To quote:

Test suite not exiting

If your test suite is not exiting it might be because you still have a lingering callback, most often caused by an open database connection. You should close this connection or do the following:

gulp.task('default', function () {
    return gulp.src('test.js')
        .once('error', function () {
        .once('end', function () {