From 5f57f9d6f29c1d040d1e7b1bb35af0d326ce8505 Mon Sep 17 00:00:00 2001 From: reblace Date: Fri, 6 Mar 2015 14:18:33 -0500 Subject: [PATCH 1/4] #450 Now the mocha task synchronously calls mongoose connect and disconnect. --- gulpfile.js | 41 +++++++++++++++++------------------------ 1 file changed, 17 insertions(+), 24 deletions(-) diff --git a/gulpfile.js b/gulpfile.js index 3abc1995f3..8fb826c57f 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -111,29 +111,26 @@ 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; mongoose.connect(function() { - done(); + gulp.src(testAssets.tests.server) + .pipe(plugins.mocha({ + reporter: 'spec' + })) + .on('error', function (err) { + error = new Error('Mocha tests failed'); + }).on('end', function() { + 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 +140,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 @@ -176,7 +169,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 From ffde5e8067aa1513af2b258a85fb41689b575de3 Mon Sep 17 00:00:00 2001 From: reblace Date: Fri, 6 Mar 2015 15:17:58 -0500 Subject: [PATCH 2/4] #450 Use the error reported by mocha. Added some comments explaining what's going on in the mocha task. --- gulpfile.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/gulpfile.js b/gulpfile.js index 8fb826c57f..1821796752 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -115,16 +115,21 @@ gulp.task('less', function () { gulp.task('mocha', function (done) { // Open mongoose connections var mongoose = require('./config/lib/mongoose.js'); - var error; + + // Connect mongoose mongoose.connect(function() { + + // Run the tests gulp.src(testAssets.tests.server) .pipe(plugins.mocha({ reporter: 'spec' })) .on('error', function (err) { - error = new Error('Mocha tests failed'); + // 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); }); From b61d6a7c8b508bfc2d175d6d60e7dd460a224700 Mon Sep 17 00:00:00 2001 From: reblace Date: Sat, 7 Mar 2015 11:14:53 -0500 Subject: [PATCH 3/4] #450 Fixing unrelated jshint warnings --- gulpfile.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/gulpfile.js b/gulpfile.js index 1821796752..6e99e0d893 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -130,7 +130,7 @@ gulp.task('mocha', function (done) { error = err; }).on('end', function() { // When the tests are done, disconnect mongoose and pass the error state back to gulp - mongoose.disconnect(function(){ + mongoose.disconnect(function() { done(error); }); }); @@ -155,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. From 9f45e63a20625ccd459256182247f7d669ab4a76 Mon Sep 17 00:00:00 2001 From: reblace Date: Sat, 7 Mar 2015 11:21:47 -0500 Subject: [PATCH 4/4] #450 minor formatting fixes. --- gulpfile.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/gulpfile.js b/gulpfile.js index 6e99e0d893..c9b0fe6c12 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -119,7 +119,6 @@ gulp.task('mocha', function (done) { // Connect mongoose mongoose.connect(function() { - // Run the tests gulp.src(testAssets.tests.server) .pipe(plugins.mocha({ @@ -128,7 +127,8 @@ gulp.task('mocha', function (done) { .on('error', function (err) { // If an error occurs, save it error = err; - }).on('end', function() { + }) + .on('end', function() { // When the tests are done, disconnect mongoose and pass the error state back to gulp mongoose.disconnect(function() { done(error);