Update jasmine for server tests to 2.4.1, fix server focus tests

Before if you focused tests, they would bypass the setup "tests" and break.
Now the server setup logic is in a beforeEach.
This commit is contained in:
Scott Erickson 2016-01-19 16:34:48 -08:00
parent 6772d5bdf4
commit 51408a94de
2 changed files with 54 additions and 39 deletions

View file

@ -98,7 +98,7 @@
"css-brunch": "^1.7.0", "css-brunch": "^1.7.0",
"fs-extra": "^0.26.2", "fs-extra": "^0.26.2",
"jade-brunch": "1.7.5", "jade-brunch": "1.7.5",
"jasmine": "^2.3.2", "jasmine": "^2.4.1",
"javascript-brunch": "> 1.0 < 1.8", "javascript-brunch": "> 1.0 < 1.8",
"karma": "~0.13", "karma": "~0.13",
"karma-chrome-launcher": "~0.1.2", "karma-chrome-launcher": "~0.1.2",

View file

@ -38,43 +38,58 @@ if (database.generateMongoConnectionString() !== dbString) {
jasmine.DEFAULT_TIMEOUT_INTERVAL = 1000 * 120; // for long Stripe tests jasmine.DEFAULT_TIMEOUT_INTERVAL = 1000 * 120; // for long Stripe tests
describe('Server Test Helper', function() { var initialized = false;
it('starts the test server', function(done) { beforeEach(function(done) {
var server = require('../../server'); if (initialized) {
server.startServer(done); return done();
}
var async = require('async');
async.series([
function(cb) {
// Start the server
var server = require('../../server');
server.startServer(cb);
},
function(cb) {
// 5. Check actual database
var User = require('../../server/users/User');
User.find({}).count(function(err, count) {
// For this to serve as a line of defense against testing with the
// production DB, tests must be run with
expect(err).toBeNull();
expect(count).toBeLessThan(100);
if(err || count >= 100) {
// the only way to be sure we don't keep going with the tests
process.exit(1);
}
GLOBAL.mc.lists.subscribe = _.noop;
cb()
});
},
function(cb) {
// Clear db
var mongoose = require('mongoose');
mongoose.connection.db.command({dropDatabase:1}, function(err, result) {
if (err) { console.log(err); }
cb(err);
});
},
function(cb) {
// Initialize products
var request = require('request');
request.get(getURL('/db/products'), function(err, res, body) {
expect(err).toBe(null);
expect(res.statusCode).toBe(200);
cb(err);
});
}
],
function(err) {
if (err) {
process.exit(1);
}
initialized = true;
done();
}); });
it('checks the db is fairly empty', function(done) {
// 5. Check actual database.
var User = require('../../server/users/User');
User.find({}).count(function(err, count) {
// For this to serve as a line of defense against testing with the
// production DB, tests must be run with
expect(err).toBeNull();
expect(count).toBeLessThan(100);
if(err || count >= 100) {
// the only way to be sure we don't keep going with the tests
process.exit(1);
}
GLOBAL.mc.lists.subscribe = _.noop;
done()
});
});
it('clears the db', function(done) {
var mongoose = require('mongoose');
mongoose.connection.db.command({dropDatabase:1}, function(err, result) {
if (err) { console.log(err); }
done();
});
});
it('initializes products', function(done) {
var request = require('request');
request.get(getURL('/db/products'), function(err, res, body) {
expect(err).toBe(null);
expect(res.statusCode).toBe(200);
done();
});
})
}); });