UNPKG

@daiso-tech/core

Version:

The library offers flexible, framework-agnostic solutions for modern web applications, built on adaptable components that integrate seamlessly with popular frameworks like Next Js.

60 lines (59 loc) 2.23 kB
/** * @module SharedLock */ import { type TestAPI, type SuiteAPI, type ExpectStatic, type beforeEach } from "vitest"; import { type ISharedLockAdapter } from "../../../shared-lock/contracts/_module.js"; import { type Promisable } from "../../../utilities/_module.js"; /** * * IMPORT_PATH: `"@daiso-tech/core/shared-lock/test-utilities"` * @group Utilities */ export type SharedLockAdapterTestSuiteSettings = { expect: ExpectStatic; test: TestAPI; describe: SuiteAPI; beforeEach: typeof beforeEach; createAdapter: () => Promisable<ISharedLockAdapter>; }; /** * The `sharedLockAdapterTestSuite` function simplifies the process of testing your custom implementation of {@link ISharedLockAdapter | `ISharedLockAdapter`} with `vitest`. * * IMPORT_PATH: `"@daiso-tech/core/shared-lock/test-utilities"` * @group Utilities * @example * ```ts * import { afterEach, beforeEach, describe, expect, test } from "vitest"; * import { sharedLockAdapterTestSuite } from "@daiso-tech/core/shared-lock/test-utilities"; * import { RedisSharedLockAdapter } from "@daiso-tech/core/shared-lock/redis-shared-lock-adapter"; * import { Redis } from "ioredis"; * import { * RedisContainer, * type StartedRedisContainer, * } from "@testcontainers/redis"; * import { TimeSpan } from "@daiso-tech/core/time-span" from "@daiso-tech/core/time-span"; * * const timeout = TimeSpan.fromMinutes(2); * describe("class: RedisSharedLockAdapter", () => { * let client: Redis; * let startedContainer: StartedRedisContainer; * beforeEach(async () => { * startedContainer = await new RedisContainer("redis:7.4.2").start(); * client = new Redis(startedContainer.getConnectionUrl()); * }, timeout.toMilliseconds()); * afterEach(async () => { * await client.quit(); * await startedContainer.stop(); * }, timeout.toMilliseconds()); * sharedLockAdapterTestSuite({ * createAdapter: () => * new RedisSharedLockAdapter(client), * test, * beforeEach, * expect, * describe, * }); * }); * ``` */ export declare function sharedLockAdapterTestSuite(settings: SharedLockAdapterTestSuiteSettings): void;