From ae264ffb0f59a08759761d4a2fe7d711d7d57fe6 Mon Sep 17 00:00:00 2001 From: leibale Date: Mon, 18 Oct 2021 20:22:00 -0400 Subject: [PATCH] clean some tests --- lib/client/index.spec.ts | 64 +++++++++++++++------------------------- lib/test-utils.ts | 14 ++++----- 2 files changed, 30 insertions(+), 48 deletions(-) diff --git a/lib/client/index.spec.ts b/lib/client/index.spec.ts index 4d30e9be60..2f14e8eecd 100644 --- a/lib/client/index.spec.ts +++ b/lib/client/index.spec.ts @@ -339,24 +339,18 @@ describe('Client', () => { ); }); - it('with script', async () => { - const client = RedisClient.create({ + itWithClient(TestRedisServers.OPEN, 'with script', async client => { + assert.deepEqual( + await client.multi() + .square(2) + .exec(), + [4] + ); + }, { + clientOptions: { scripts: { square: SQUARE_SCRIPT } - }); - - await client.connect(); - - try { - assert.deepEqual( - await client.multi() - .square(2) - .exec(), - [4] - ); - } finally { - await client.disconnect(); } }); @@ -389,27 +383,26 @@ describe('Client', () => { }); }); - it('scripts', async () => { - const client = RedisClient.create({ + itWithClient(TestRedisServers.OPEN, 'scripts', async client => { + assert.equal( + await client.square(2), + 4 + ); + }, { + clientOptions: { scripts: { square: SQUARE_SCRIPT } - }); - - await client.connect(); - - try { - assert.equal( - await client.square(2), - 4 - ); - } finally { - await client.disconnect(); } }); - it('modules', async () => { - const client = RedisClient.create({ + itWithClient(TestRedisServers.OPEN, 'modules', async client => { + assert.equal( + await client.module.echo('message'), + 'message' + ); + }, { + clientOptions: { modules: { module: { echo: { @@ -422,17 +415,6 @@ describe('Client', () => { } } } - }); - - await client.connect(); - - try { - assert.equal( - await client.module.echo('message'), - 'message' - ); - } finally { - await client.disconnect(); } }); diff --git a/lib/test-utils.ts b/lib/test-utils.ts index 3b823ac6ee..42eb9df500 100644 --- a/lib/test-utils.ts +++ b/lib/test-utils.ts @@ -52,13 +52,13 @@ export enum TestRedisServers { PASSWORD } -export const TEST_REDIS_SERVERS: Record> = {}; +export const TEST_REDIS_SERVERS: Record, 'modules' | 'scripts'>> = {}; export enum TestRedisClusters { OPEN } -export const TEST_REDIS_CLUSTERES: Record> = {}; +export const TEST_REDIS_CLUSTERES: Record, 'modules' | 'scripts'>> = {}; let port = 6379; @@ -284,15 +284,15 @@ export function describeHandleMinimumRedisVersion(minimumVersion: PartialRedisVe }); } -interface RedisClientTestOptions extends RedisTestOptions { - clientOptions?: RedisClientOptions<{}, {}>; +interface RedisClientTestOptions extends RedisTestOptions { + clientOptions?: RedisClientOptions; } -export function itWithClient( +export function itWithClient( type: TestRedisServers, title: string, - fn: (client: RedisClientType) => Promise, - options?: RedisClientTestOptions + fn: (client: RedisClientType) => Promise, + options?: RedisClientTestOptions ): void { it(title, async function () { if (handleMinimumRedisVersion(this, options?.minimumRedisVersion)) return;