Remove beforeEach and afterEach, in combination with suite they are

triggered for every single test even outside of the suite they were
invoked in.
This commit is contained in:
Raul Ochoa 2015-01-30 16:50:06 +01:00
parent d0ef87b0cf
commit 358b296750
3 changed files with 37 additions and 26 deletions

View File

@ -18,7 +18,9 @@ config/environments/test.js: config.status--test
check-local: config/environments/test.js check-local: config/environments/test.js
./run_tests.sh ${RUNTESTFLAGS} \ ./run_tests.sh ${RUNTESTFLAGS} \
test/unit/cartodb/*.js \ test/unit/cartodb/*.js \
test/acceptance/*.js test/unit/cartodb/cache/model/*.js \
test/acceptance/*.js \
test/acceptance/cache/*.js
check-submodules: check-submodules:
PATH="$$PATH:$(srcdir)/node_modules/.bin/"; \ PATH="$$PATH:$(srcdir)/node_modules/.bin/"; \

View File

@ -16,9 +16,13 @@ var serverOptions = ServerOptions();
suite('templates surrogate keys', function() { suite('templates surrogate keys', function() {
var redisClient, var sqlApiServer;
sqlApiServer, var redisClient = redis.createClient(global.environment.redis.port);
server;
// Enable Varnish purge for tests
serverOptions.varnish_purge_enabled = true;
var server = new CartodbWindshaft(serverOptions);
var templateOwner = 'localhost', var templateOwner = 'localhost',
templateName = 'acceptance', templateName = 'acceptance',
@ -45,19 +49,12 @@ suite('templates surrogate keys', function() {
expectedBody = { template_id: expectedTemplateId }; expectedBody = { template_id: expectedTemplateId };
suiteSetup(function(done) { suiteSetup(function(done) {
// Enable Varnish purge for tests
serverOptions.varnish_purge_enabled = true;
server = new CartodbWindshaft(serverOptions);
sqlApiServer = new SqlApiEmulator(global.environment.sqlapi.port, done); sqlApiServer = new SqlApiEmulator(global.environment.sqlapi.port, done);
redisClient = redis.createClient(global.environment.redis.port);
}); });
var surrogateKeysCacheInvalidateFn = SurrogateKeysCache.prototype.invalidate; var surrogateKeysCacheInvalidateFn = SurrogateKeysCache.prototype.invalidate;
beforeEach(function(done) { function createTemplate(callback) {
var postTemplateRequest = { var postTemplateRequest = {
url: '/tiles/template?api_key=1234', url: '/tiles/template?api_key=1234',
method: 'POST', method: 'POST',
@ -90,10 +87,10 @@ suite('templates surrogate keys', function() {
return true; return true;
}, },
function finish(err) { function finish(err) {
done(err); callback(err);
} }
); );
}); }
test("update template calls surrogate keys invalidation", function(done) { test("update template calls surrogate keys invalidation", function(done) {
var cacheEntryKey; var cacheEntryKey;
@ -104,7 +101,13 @@ suite('templates surrogate keys', function() {
}; };
Step( Step(
function putValidTemplate() { function createTemplateToUpdate() {
createTemplate(this);
},
function putValidTemplate(err) {
if (err) {
throw err;
}
var updateTemplateRequest = { var updateTemplateRequest = {
url: '/tiles/template/' + expectedTemplateId + '/?api_key=1234', url: '/tiles/template/' + expectedTemplateId + '/?api_key=1234',
method: 'PUT', method: 'PUT',
@ -163,7 +166,13 @@ suite('templates surrogate keys', function() {
}; };
Step( Step(
function putValidTemplate() { function createTemplateToDelete() {
createTemplate(this);
},
function deleteValidTemplate(err) {
if (err) {
throw err;
}
var deleteTemplateRequest = { var deleteTemplateRequest = {
url: '/tiles/template/' + expectedTemplateId + '/?api_key=1234', url: '/tiles/template/' + expectedTemplateId + '/?api_key=1234',
method: 'DELETE', method: 'DELETE',
@ -199,12 +208,10 @@ suite('templates surrogate keys', function() {
); );
}); });
afterEach(function(done) {
SurrogateKeysCache.prototype.invalidate = surrogateKeysCacheInvalidateFn;
done();
});
suiteTeardown(function(done) { suiteTeardown(function(done) {
SurrogateKeysCache.prototype.invalidate = surrogateKeysCacheInvalidateFn;
// Enable Varnish purge for tests
serverOptions.varnish_purge_enabled = false;
sqlApiServer.close(done); sqlApiServer.close(done);
}); });

View File

@ -7,7 +7,7 @@ var server = new CartodbWindshaft(serverOptions);
suite('health checks', function () { suite('health checks', function () {
beforeEach(function (done) { function resetHealthConfig() {
global.environment.health = { global.environment.health = {
enabled: true, enabled: true,
username: 'localhost', username: 'localhost',
@ -15,8 +15,7 @@ suite('health checks', function () {
x: 0, x: 0,
y: 0 y: 0
}; };
done(); }
});
var healthCheckRequest = { var healthCheckRequest = {
url: '/health', url: '/health',
@ -27,13 +26,14 @@ suite('health checks', function () {
}; };
test('returns 200 and ok=true with enabled configuration', function (done) { test('returns 200 and ok=true with enabled configuration', function (done) {
resetHealthConfig();
assert.response(server, assert.response(server,
healthCheckRequest, healthCheckRequest,
{ {
status: 200 status: 200
}, },
function (res, err) { function (res, err) {
console.log(res.body);
assert.ok(!err); assert.ok(!err);
var parsed = JSON.parse(res.body); var parsed = JSON.parse(res.body);
@ -47,6 +47,8 @@ suite('health checks', function () {
}); });
test('fails for invalid user because it is not in redis', function (done) { test('fails for invalid user because it is not in redis', function (done) {
resetHealthConfig();
global.environment.health.username = 'invalid'; global.environment.health.username = 'invalid';
assert.response(server, assert.response(server,