Skip to content
This repository has been archived by the owner on Aug 30, 2021. It is now read-only.

Commit

Permalink
Merge pull request #453 from reblace/#450
Browse files Browse the repository at this point in the history
Fix hanging gulp because mongoose connections are left open. Fixes #450.
  • Loading branch information
ilanbiala committed Mar 9, 2015
2 parents 61f1a22 + 6d0363f commit cabb4c4
Showing 1 changed file with 25 additions and 27 deletions.
52 changes: 25 additions & 27 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,29 +111,31 @@ gulp.task('less', function () {
.pipe(gulp.dest('./modules/'));
});

// Connect to MongoDB using the mongoose module
gulp.task('openMongoose', function (done) {
// Mocha tests task
gulp.task('mocha', function (done) {
// Open mongoose connections
var mongoose = require('./config/lib/mongoose.js');
var error;

// Connect mongoose
mongoose.connect(function() {
done();
// Run the tests
gulp.src(testAssets.tests.server)
.pipe(plugins.mocha({
reporter: 'spec'
}))
.on('error', function (err) {
// If an error occurs, save it
error = err;
})
.on('end', function() {
// When the tests are done, disconnect mongoose and pass the error state back to gulp
mongoose.disconnect(function() {
done(error);
});
});
});
});

gulp.task('closeMongoose', function (done) {
var mongoose = require('./config/lib/mongoose.js');

mongoose.disconnect(function(err) {
done(err);
});
});

// Mocha tests task
gulp.task('mocha', function () {
return gulp.src(testAssets.tests.server)
.pipe(plugins.mocha({
reporter: 'spec'
}));
});

// Karma test runner task
Expand All @@ -143,11 +145,7 @@ gulp.task('karma', function (done) {
configFile: 'karma.conf.js',
action: 'run',
singleRun: true
}))
.on('error', function (err) {
// Make sure failed tests cause gulp to exit non-zero
throw err;
});
}));
});

// Selenium standalone WebDriver update task
Expand All @@ -157,11 +155,11 @@ gulp.task('webdriver-update', plugins.protractor.webdriver_update);
gulp.task('protractor', function () {
gulp.src([])
.pipe(plugins.protractor.protractor({
configFile: "protractor.conf.js"
configFile: 'protractor.conf.js'
}))
.on('error', function (e) {
throw e
})
throw e;
});
});

// Lint CSS and JavaScript files.
Expand All @@ -176,7 +174,7 @@ gulp.task('build', function(done) {

// Run the project tests
gulp.task('test', function(done) {
runSequence('env:test', 'openMongoose', ['karma', 'mocha'], 'closeMongoose', done);
runSequence('env:test', ['karma', 'mocha'], done);
});

// Run the project in development mode
Expand Down

0 comments on commit cabb4c4

Please sign in to comment.