| 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. |