MCPcopy
hub / github.com/redis/node-redis / testWithClient

Method testWithClient

packages/test-utils/lib/index.ts:371–421  ·  view source on GitHub ↗
(
    title: string,
    fn: (client: RedisClientType<M, F, S, RESP, TYPE_MAPPING>) => unknown,
    options: ClientTestOptions<M, F, S, RESP, TYPE_MAPPING>
  )

Source from the content-addressed store, hash-verified

369 }
370
371 testWithClient<
372 M extends RedisModules = {},
373 F extends RedisFunctions = {},
374 S extends RedisScripts = {},
375 RESP extends RespVersions = 2,
376 TYPE_MAPPING extends TypeMapping = {}
377 >(
378 title: string,
379 fn: (client: RedisClientType<M, F, S, RESP, TYPE_MAPPING>) => unknown,
380 options: ClientTestOptions<M, F, S, RESP, TYPE_MAPPING>
381 ): void {
382 let dockerPromise: ReturnType<typeof spawnRedisServer>;
383 if (this.isVersionGreaterThan(options.minimumDockerVersion)) {
384 const dockerImage = this.#DOCKER_IMAGE;
385 before(function () {
386 this.timeout(30000);
387
388 dockerPromise = spawnRedisServer(dockerImage, options.serverArguments);
389 return dockerPromise;
390 });
391 }
392
393 it(title, async function () {
394 if (options.skipTest) return this.skip();
395 if (!dockerPromise) return this.skip();
396
397 const client = createClient({
398 ...options.clientOptions,
399 socket: {
400 ...options.clientOptions?.socket,
401 port: (await dockerPromise).port
402 }
403 });
404
405 if (options.disableClientSetup) {
406 return fn(client);
407 }
408
409 await client.connect();
410
411 try {
412 await client.flushAll();
413 await fn(client);
414 } finally {
415 if (client.isOpen) {
416 await client.flushAll();
417 client.destroy();
418 }
419 }
420 });
421 }
422
423 /**
424 * Runs a test using a TLS-enabled Redis client.

Callers 15

testWithProxiedClientMethod · 0.95
testAllMethod · 0.95
testAllAutoMethod · 0.95
cache.spec.tsFile · 0.80
socket.spec.tsFile · 0.80
key-prefix.spec.tsFile · 0.80
testWithLegacyClientFunction · 0.80
tracing.spec.tsFile · 0.80
index.spec.tsFile · 0.80
types.spec.tsFile · 0.80
digest.spec.tsFile · 0.80

Calls 6

isVersionGreaterThanMethod · 0.95
spawnRedisServerFunction · 0.90
createClientFunction · 0.90
flushAllMethod · 0.80
destroyMethod · 0.65
connectMethod · 0.45

Tested by 1

testWithLegacyClientFunction · 0.64