@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.08 kB
TypeScript
/**
* @module Lock
*/
import { type TestAPI, type SuiteAPI, type ExpectStatic, type beforeEach } from "vitest";
import { type ILockAdapter } from "../../../lock/contracts/_module-exports.js";
import { type Promisable } from "../../../utilities/_module-exports.js";
/**
*
* IMPORT_PATH: `"@daiso-tech/core/lock/test-utilities"`
* @group Utilities
*/
export type LockAdapterTestSuiteSettings = {
expect: ExpectStatic;
test: TestAPI;
describe: SuiteAPI;
beforeEach: typeof beforeEach;
createAdapter: () => Promisable<ILockAdapter>;
};
/**
* The `lockAdapterTestSuite` function simplifies the process of testing your custom implementation of {@link ILockAdapter | `ILockAdapter`} with `vitest`.
*
* IMPORT_PATH: `"@daiso-tech/core/lock/test-utilities"`
* @group Utilities
* @example
* ```ts
* import { afterEach, beforeEach, describe, expect, test } from "vitest";
* import { lockAdapterTestSuite } from "@daiso-tech/core/lock/test-utilities";
* import { RedisLockAdapter } from "@daiso-tech/core/lock/adapters";
* import { Redis } from "ioredis";
* import {
* RedisContainer,
* type StartedRedisContainer,
* } from "@testcontainers/redis";
* import { TimeSpan } from "@daiso-tech/core/utilities";
*
* const timeout = TimeSpan.fromMinutes(2);
* describe("class: RedisLockAdapter", () => {
* 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());
* lockAdapterTestSuite({
* createAdapter: () =>
* new RedisLockAdapter(client),
* test,
* beforeEach,
* expect,
* describe,
* });
* });
* ```
*/
export declare function lockAdapterTestSuite(settings: LockAdapterTestSuiteSettings): void;