diff --git a/jest.config.js b/jest.config.js index 7b5d107475..a9d1e4e3ff 100644 --- a/jest.config.js +++ b/jest.config.js @@ -4,6 +4,7 @@ process.env = Object.assign(process.env, { JWT_AUDIENCE: 'http://localhost', JWT_ISSUER: 'http://localhost', JWT_EXPIRES_IN: '1h', + MOCK_REDIS: '1', }); module.exports = { @@ -14,4 +15,5 @@ module.exports = { testEnvironment: 'node', coverageDirectory: '/coverage', collectCoverageFrom: ['/src/**/*.js'], + testTimeout: 8000, }; diff --git a/src/redis.js b/src/redis.js index da19b365b2..45bdad429e 100644 --- a/src/redis.js +++ b/src/redis.js @@ -9,20 +9,10 @@ const redisUrl = process.env.REDIS_URL || 'redis://redis:6379'; const useMockRedis = process.env.MOCK_REDIS; // RedisConstructor is one of Redis or MockRedis -const redisConstructor = useMockRedis ? MockRedis : Redis; +const RedisConstructor = useMockRedis ? MockRedis : Redis; -function createRedisClient() { - try { - const { port, host } = new URL(redisUrl); - return new redisConstructor(port, host, { - password: process.env.REDIS_PASSWORD, - }); - } catch (error) { - const message = `Unable to parse port and host from "${redisUrl}"`; - logger.error({ error }, message); - throw new Error(message); - //createError(error, message); Future Proofing when createError is merged. - } +function createRedisClient(options) { + return new RedisConstructor(redisUrl, options); } // If using MockRedis, shim info() until https://github.com/stipsan/ioredis-mock/issues/841 ships diff --git a/test.js b/test.js index bbfe50e315..2669e798e1 100644 --- a/test.js +++ b/test.js @@ -885,11 +885,21 @@ describe('createServiceToken()', () => { }); describe('Redis()', () => { - const redis = Redis(); + let redis; - test('Redis ping command should return pong', () => { - const pong = redis.ping((err, result) => { + beforeEach(() => { + redis = Redis(); + }); + + afterEach(() => { + redis.quit(); + }); + + test('Redis ping command should return pong', (done) => { + redis.ping((err, result) => { + expect(err).toBe(null); expect(result).toEqual('PONG'); + done(); }); }); });