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.

65 lines (64 loc) 2.35 kB
/** * @module Cache */ import { type TestAPI, type SuiteAPI, type ExpectStatic, type beforeEach } from "vitest"; import { type ICacheAdapter } from "../../../cache/contracts/_module-exports.js"; import { type Promisable } from "../../../utilities/_module-exports.js"; /** * * IMPORT_PATH: `"@daiso-tech/core/cache/test-utilities"` * @group TestUtilities */ export type CacheAdapterTestSuiteSettings = { expect: ExpectStatic; test: TestAPI; describe: SuiteAPI; beforeEach: typeof beforeEach; createAdapter: () => Promisable<ICacheAdapter>; }; /** * The `cacheAdapterTestSuite` function simplifies the process of testing your custom implementation of {@link ICacheAdapter | `ICacheAdapter`} with `vitest`. * * IMPORT_PATH: `"@daiso-tech/core/cache/test-utilities"` * @group TestUtilities * @example * ```ts * import { afterEach, beforeEach, describe, expect, test } from "vitest"; * import { Redis } from "ioredis"; * import { * RedisContainer, * type StartedRedisContainer, * } from "@testcontainers/redis"; * import { cacheAdapterTestSuite } from "@daiso-tech/core/cache/test-utilities"; * import { RedisCacheAdapter } from "@daiso-tech/core/cache/adapters"; * import { TimeSpan } from "@daiso-tech/core/utilities"; * import { SuperJsonSerdeAdapter } from "@daiso-tech/core/serde/adapters"; * import { Serde } from "@daiso-tech/core/serde"; * * const timeout = TimeSpan.fromMinutes(2); * describe("class: RedisCacheAdapter", () => { * 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()); * cacheAdapterTestSuite({ * createAdapter: () => * new RedisCacheAdapter({ * database: client, * serde: new Serde(new SuperJsonSerdeAdapter()), * }), * test, * beforeEach, * expect, * describe, * }); * }); * ``` */ export declare function cacheAdapterTestSuite(settings: CacheAdapterTestSuiteSettings): void;