diff --git a/gulpfile.js b/gulpfile.js index 3abc1995f3..c9b0fe6c12 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -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 @@ -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 @@ -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. @@ -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