Use mocha hooks to create server just before perform the test

This commit is contained in:
Daniel García Aubert 2018-04-16 16:16:23 +02:00
parent 98f29f945b
commit 817afb13d1
32 changed files with 205 additions and 65 deletions

View File

@ -9,7 +9,12 @@ var TestClient = require('../../support/test-client');
var LayergroupToken = require('../../../lib/cartodb/models/layergroup-token');
describe('named-maps analysis', function() {
var server = new CartodbWindshaft(serverOptions);
var server;
before(function () {
server = new CartodbWindshaft(serverOptions);
});
var IMAGE_TOLERANCE_PER_MIL = 20;

View File

@ -45,7 +45,11 @@ var pointSqlPublic = "select * from test_table";
var keysToDelete;
describe('authorization fallback', function () {
const server = new CartodbWindshaft(serverOptions);
var server;
before(function () {
server = new CartodbWindshaft(serverOptions);
});
beforeEach(function () {
keysToDelete = {};

View File

@ -9,8 +9,13 @@ var serverOptions = require('../../../lib/cartodb/server_options');
var LayergroupToken = require('../../../lib/cartodb/models/layergroup-token');
describe('get requests with cache headers', function() {
var server = new CartodbWindshaft(serverOptions);
server.setMaxListeners(0);
var server;
before(function () {
server = new CartodbWindshaft(serverOptions);
server.setMaxListeners(0);
});
var keysToDelete;
beforeEach(function() {

View File

@ -30,7 +30,12 @@ describe('templates surrogate keys', function() {
serviceId: FAKE_FASTLY_SERVICE_ID
};
var server = new CartodbWindshaft(serverOptions);
var server;
before(function () {
server = new CartodbWindshaft(serverOptions);
});
var templateOwner = 'localhost';
var templateName = 'acceptance';

View File

@ -6,7 +6,11 @@ var CartodbWindshaft = require(__dirname + '/../../lib/cartodb/server');
var serverOptions = require(__dirname + '/../../lib/cartodb/server_options');
describe('dynamic styling for named maps', function() {
var server = new CartodbWindshaft(serverOptions);
var server;
before(function () {
server = new CartodbWindshaft(serverOptions);
});
var keysToDelete;

View File

@ -3,7 +3,12 @@ var CartodbWindshaft = require(__dirname + '/../../lib/cartodb/server');
var serverOptions = require(__dirname + '/../../lib/cartodb/server_options');
describe('error with context', function () {
var server = new CartodbWindshaft(serverOptions);
var server;
before(function () {
server = new CartodbWindshaft(serverOptions);
});
var layerOK = {
options: {

View File

@ -25,8 +25,12 @@ var QueryTables = require('cartodb-query-tables');
var suiteName = 'multilayer:postgres=layergroup_url=' + layergroup_url;
describe(suiteName, function() {
var server = new CartodbWindshaft(serverOptions);
server.setMaxListeners(0);
var server;
before(function () {
server = new CartodbWindshaft(serverOptions);
server.setMaxListeners(0);
});
var keysToDelete;

View File

@ -12,8 +12,12 @@ var CartodbWindshaft = require('../../lib/cartodb/server');
var serverOptions = require('../../lib/cartodb/server_options');
describe('tests from old api translated to multilayer', function() {
var server = new CartodbWindshaft(serverOptions);
server.setMaxListeners(0);
var server;
before(function () {
server = new CartodbWindshaft(serverOptions);
server.setMaxListeners(0);
});
var layergroupUrl = '/api/v1/map';

View File

@ -12,7 +12,11 @@ var TemplateMaps = require('../../lib/cartodb/backends/template_maps.js');
var step = require('step');
describe('named_layers', function() {
var server = new CartodbWindshaft(serverOptions);
var server;
before(function () {
server = new CartodbWindshaft(serverOptions);
});
// configure redis pool instance to use in tests
var redisPool = new RedisPool(global.environment.redis);

View File

@ -12,7 +12,12 @@ var mapnik = require('windshaft').mapnik;
var IMAGE_TOLERANCE = 20;
describe('layers visibility for previews', function() {
var server = new CartodbWindshaft(serverOptions);
var server;
before(function () {
server = new CartodbWindshaft(serverOptions);
});
// configure redis pool instance to use in tests
var redisPool = new RedisPool(global.environment.redis);
var templateMaps = new TemplateMaps(redisPool, {

View File

@ -10,7 +10,11 @@ var TemplateMaps = require('../../lib/cartodb/backends/template_maps.js');
var NamedMapsCacheEntry = require('../../lib/cartodb/cache/model/named_maps_entry');
describe('named maps authentication', function() {
var server = new CartodbWindshaft(serverOptions);
var server;
before(function () {
server = new CartodbWindshaft(serverOptions);
});
// configure redis pool instance to use in tests
var redisPool = new RedisPool(global.environment.redis);

View File

@ -8,7 +8,11 @@ var serverOptions = require('../../lib/cartodb/server_options');
var TemplateMaps = require('../../lib/cartodb/backends/template_maps.js');
describe('named maps provider cache', function() {
var server = new CartodbWindshaft(serverOptions);
var server;
before(function () {
server = new CartodbWindshaft(serverOptions);
});
// configure redis pool instance to use in tests
var redisPool = new RedisPool(global.environment.redis);

View File

@ -10,7 +10,11 @@ var TemplateMaps = require('../../lib/cartodb/backends/template_maps.js');
var NamedMapsCacheEntry = require('../../lib/cartodb/cache/model/named_maps_entry');
describe('named maps preview stats', function() {
var server = new CartodbWindshaft(serverOptions);
var server;
before(function () {
server = new CartodbWindshaft(serverOptions);
});
var redisPool = new RedisPool(global.environment.redis);

View File

@ -14,7 +14,11 @@ var windshaft = require('windshaft');
describe('overviews metadata', function() {
var server = new CartodbWindshaft(serverOptions);
var server;
before(function () {
server = new CartodbWindshaft(serverOptions);
});
// configure redis pool instance to use in tests
var redisPool = new RedisPool(global.environment.redis);
@ -112,7 +116,11 @@ describe('overviews metadata', function() {
});
describe('overviews metadata with filters', function() {
var server = new CartodbWindshaft(serverOptions);
var server;
before(function () {
server = new CartodbWindshaft(serverOptions);
});
// configure redis pool instance to use in tests
var redisPool = new RedisPool(global.environment.redis);

View File

@ -13,7 +13,11 @@ var step = require('step');
var windshaft = require('windshaft');
describe('overviews metadata for named maps', function() {
var server = new CartodbWindshaft(serverOptions);
var server;
before(function () {
server = new CartodbWindshaft(serverOptions);
});
// configure redis pool instance to use in tests
var redisPool = new RedisPool(global.environment.redis);

View File

@ -6,9 +6,12 @@ var ServerOptions = require('./ported/support/ported_server_options');
var testClient = require('./ported/support/test_client');
describe('overviews_queries', function() {
var server;
var server = cartodbServer(ServerOptions);
server.setMaxListeners(0);
before(function () {
server = cartodbServer(ServerOptions);
server.setMaxListeners(0);
});
var IMAGE_EQUALS_TOLERANCE_PER_MIL = 2;

View File

@ -7,8 +7,12 @@ var PortedServerOptions = require('./support/ported_server_options');
var LayergroupToken = require('../../../lib/cartodb/models/layergroup-token');
describe('attributes', function() {
var server = cartodbServer(PortedServerOptions);
server.setMaxListeners(0);
var server;
before(function () {
server = cartodbServer(PortedServerOptions);
server.setMaxListeners(0);
});
var test_mapconfig_1 = {
version: '1.1.0',

View File

@ -10,9 +10,13 @@ var ServerOptions = require('./support/ported_server_options');
var LayergroupToken = require('../../../lib/cartodb/models/layergroup-token');
describe('multilayer', function() {
var server;
before(function () {
server = cartodbServer(ServerOptions);
server.setMaxListeners(0);
});
var server = cartodbServer(ServerOptions);
server.setMaxListeners(0);
mapnik.register_system_fonts();
var available_system_fonts = _.keys(mapnik.fontFiles());

View File

@ -8,9 +8,12 @@ var testClient = require('./support/test_client');
var TestClient = require('../../support/test-client');
describe('multilayer error cases', function() {
var server;
var server = cartodbServer(ServerOptions);
server.setMaxListeners(0);
before(function () {
server = cartodbServer(ServerOptions);
server.setMaxListeners(0);
});
// var client = null;
afterEach(function(done) {

View File

@ -8,9 +8,12 @@ var PortedServerOptions = require('./support/ported_server_options');
var LayergroupToken = require('../../../lib/cartodb/models/layergroup-token');
describe('multilayer interactivity and layers order', function() {
var server;
var server = cartodbServer(PortedServerOptions);
server.setMaxListeners(0);
before(function () {
server = cartodbServer(PortedServerOptions);
server.setMaxListeners(0);
});
function layerType(layer) {
return layer.type || 'undefined';

View File

@ -8,8 +8,12 @@ var LayergroupToken = require('../../../lib/cartodb/models/layergroup-token');
describe('raster', function() {
var server = cartodbServer(ServerOptions);
server.setMaxListeners(0);
var server;
before(function () {
server = cartodbServer(ServerOptions);
server.setMaxListeners(0);
});
function checkCORSHeaders(res) {
assert.equal(res.headers['access-control-allow-headers'], 'X-Requested-With, X-Prototype-Version, X-CSRF-Token');

View File

@ -11,9 +11,12 @@ describe('retina support', function() {
var layergroupId = null;
var server = cartodbServer(ServerOptions);
server.setMaxListeners(0);
var server;
before(function () {
server = cartodbServer(ServerOptions);
server.setMaxListeners(0);
});
var keysToDelete;
beforeEach(function(done) {

View File

@ -6,9 +6,12 @@ var ServerOptions = require('./support/ported_server_options');
var testClient = require('./support/test_client');
describe('server', function() {
var server;
var server = cartodbServer(ServerOptions);
server.setMaxListeners(0);
before(function () {
server = cartodbServer(ServerOptions);
server.setMaxListeners(0);
});
after(function() {
testHelper.rmdirRecursiveSync(global.environment.millstone.cache_basedir);

View File

@ -8,9 +8,12 @@ var ServerOptions = require('./support/ported_server_options');
var testClient = require('./support/test_client');
describe('server_gettile', function() {
var server;
var server = cartodbServer(ServerOptions);
server.setMaxListeners(0);
before(function () {
server = cartodbServer(ServerOptions);
server.setMaxListeners(0);
});
var IMAGE_EQUALS_TOLERANCE_PER_MIL = 25;

View File

@ -11,17 +11,22 @@ var LayergroupToken = require('../../../lib/cartodb/models/layergroup-token');
var IMAGE_EQUALS_TOLERANCE_PER_MIL = 85;
describe('server_png8_format', function() {
var serverOptionsPng32 = ServerOptions;
serverOptionsPng32.grainstore = _.clone(ServerOptions.grainstore);
serverOptionsPng32.grainstore.mapnik_tile_format = 'png32';
var serverPng32 = cartodbServer(serverOptionsPng32);
serverPng32.setMaxListeners(0);
var serverPng32;
var serverPng8;
var serverOptionsPng8 = ServerOptions;
serverOptionsPng8.grainstore = _.clone(ServerOptions.grainstore);
serverOptionsPng8.grainstore.mapnik_tile_format = 'png8:m=h';
var serverPng8 = cartodbServer(serverOptionsPng8);
serverPng8.setMaxListeners(0);
before(function () {
var serverOptionsPng32 = ServerOptions;
serverOptionsPng32.grainstore = _.clone(ServerOptions.grainstore);
serverOptionsPng32.grainstore.mapnik_tile_format = 'png32';
serverPng32 = cartodbServer(serverOptionsPng32);
serverPng32.setMaxListeners(0);
var serverOptionsPng8 = ServerOptions;
serverOptionsPng8.grainstore = _.clone(ServerOptions.grainstore);
serverOptionsPng8.grainstore.mapnik_tile_format = 'png8:m=h';
serverPng8 = cartodbServer(serverOptionsPng8);
serverPng8.setMaxListeners(0);
});
var layergroupId;

View File

@ -39,9 +39,18 @@ module.exports = {
getTileLayer: getTileLayer
};
var server;
var server = new CartodbServer(PortedServerOptions);
server.setMaxListeners(0);
function getServer () {
if (server) {
return server;
}
server = new CartodbServer(PortedServerOptions);
server.setMaxListeners(0);
return server;
}
var jsonContentType = 'application/json; charset=utf-8';
var jsContentType = 'text/javascript; charset=utf-8';
@ -349,7 +358,7 @@ function getGeneric(layergroupConfig, url, expectedResponse, callback) {
'Content-Type': 'application/json; charset=utf-8'
}
};
assert.response(server, request, expectedResponse, function (res, err) {
assert.response(getServer(), request, expectedResponse, function (res, err) {
next(err, res);
});
},
@ -384,7 +393,7 @@ function getGeneric(layergroupConfig, url, expectedResponse, callback) {
request.encoding = 'binary';
}
assert.response(server, request, expectedResponse, function (res, err) {
assert.response(getServer(), request, expectedResponse, function (res, err) {
next(err, res);
});
},

View File

@ -9,9 +9,12 @@ var ServerOptions = require('./support/ported_server_options');
var LayergroupToken = require('../../../lib/cartodb/models/layergroup-token');
describe('torque', function() {
var server;
var server = cartodbServer(ServerOptions);
server.setMaxListeners(0);
before(function () {
server = cartodbServer(ServerOptions);
server.setMaxListeners(0);
});
var keysToDelete;
beforeEach(function() {

View File

@ -7,6 +7,13 @@ var ServerOptions = require('./support/ported_server_options');
var LayergroupToken = require('../../../lib/cartodb/models/layergroup-token');
describe('torque boundary points', function() {
var server;
before(function () {
server = cartodbServer(ServerOptions);
server.setMaxListeners(0);
});
var layergroupIdToDelete = null;
beforeEach(function() {
@ -22,9 +29,6 @@ describe('torque boundary points', function() {
testHelper.deleteRedisKeys(keysToDelete, done);
});
var server = cartodbServer(ServerOptions);
server.setMaxListeners(0);
var boundaryPointsMapConfig = {
version: '1.1.0',
layers: [

View File

@ -9,8 +9,12 @@ var serverOptions = require('../../lib/cartodb/server_options');
describe('server', function() {
var server = new CartodbWindshaft(serverOptions);
server.setMaxListeners(0);
var server;
before(function () {
server = new CartodbWindshaft(serverOptions);
server.setMaxListeners(0);
});
// TODO: I guess this should be a 404 instead...
it("get call to server returns 200", function(done){
@ -54,8 +58,12 @@ describe('server', function() {
});
describe('server old_api', function() {
var server = new CartodbWindshaft(serverOptions);
server.setMaxListeners(0);
var server;
before(function () {
server = new CartodbWindshaft(serverOptions);
server.setMaxListeners(0);
});
// See https://github.com/CartoDB/Windshaft-cartodb/issues/115
it.skip("get'ing tile with not-strictly-valid style", function(done) {

View File

@ -24,9 +24,13 @@ var serverOptions = require(__dirname + '/../../lib/cartodb/server_options');
var LayergroupToken = require('../../lib/cartodb/models/layergroup-token');
describe('template_api', function() {
var server = new CartodbWindshaft(serverOptions);
server.setMaxListeners(0);
server.layergroupAffectedTablesCache.cache.reset();
var server;
before(function () {
server = new CartodbWindshaft(serverOptions);
server.setMaxListeners(0);
server.layergroupAffectedTablesCache.cache.reset();
});
var httpRendererResourcesServer;
before(function(done) {

View File

@ -8,7 +8,11 @@ var mapnik = require('windshaft').mapnik;
var IMAGE_TOLERANCE_PER_MIL = 10;
describe('turbo-carto for named maps', function() {
var server = new CartodbWindshaft(serverOptions);
var server;
before(function () {
server = new CartodbWindshaft(serverOptions);
});
var keysToDelete;

View File

@ -12,7 +12,11 @@ var serverOptions = require('../../../lib/cartodb/server_options');
var LayergroupToken = require('../../../lib/cartodb/models/layergroup-token');
describe('named-maps widgets', function() {
var server = new CartodbWindshaft(serverOptions);
var server;
before(function () {
server = new CartodbWindshaft(serverOptions);
});
var username = 'localhost';
var widgetsTemplateName = 'widgets-template';