Skip to content

Commit

Permalink
meanjs#450 Now the mocha task synchronously calls mongoose connect and
Browse files Browse the repository at this point in the history
disconnect.
  • Loading branch information
reblace committed Mar 6, 2015
1 parent 6f09033 commit 5f57f9d
Showing 1 changed file with 17 additions and 24 deletions.
41 changes: 17 additions & 24 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 5f57f9d

Please sign in to comment.