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.

75 lines (74 loc) 2.75 kB
/** * @module Semaphore */ import { type TestAPI, type SuiteAPI, type ExpectStatic, type beforeEach } from "vitest"; import { type IReadableContext } from "../../../execution-context/contracts/_module.js"; import { type IDatabaseSemaphoreAdapter } from "../../../semaphore/contracts/_module.js"; import { type Promisable } from "../../../utilities/_module.js"; /** * IMPORT_PATH: `"@daiso-tech/core/semaphore/test-utilities"` * @group Utilities */ export type DatabaseSemaphoreAdapterTestSuiteSettings = { expect: ExpectStatic; test: TestAPI; describe: SuiteAPI; beforeEach: typeof beforeEach; createAdapter: () => Promisable<IDatabaseSemaphoreAdapter>; /** * @default * ```ts * import { ExecutionContext } from "@daiso-tech/core/execution-context" * import { NoOpExecutionContextAdapter } from "@daiso-tech/core/execution-context/no-op-execution-context-adapter" * * new ExecutionContext(new NoOpExecutionContextAdapter()) * ``` */ context?: IReadableContext; }; /** * The `databaseSemaphoreAdapterTestSuite` function simplifies the process of testing your custom implementation of {@link IDatabaseSemaphoreAdapter | `IDatabaseSemaphoreAdapter`} with `vitest`. * * IMPORT_PATH: `"@daiso-tech/core/semaphore/test-utilities"` * @group Utilities * @example * ```ts * import { afterEach, beforeEach, describe, expect, test } from "vitest"; * import { databaseSemaphoreAdapterTestSuite } from "@daiso-tech/core/semaphore/test-utilities"; * import { kyselySemaphoreAdapter, type KyselySemaphoreTables } from "@daiso-tech/core/semaphore/kysely-semaphore-adapter"; * import { Kysely, SqliteDialect } from "kysely"; * import Sqlite, { type Database } from "better-sqlite3"; * * describe("class: kyselySemaphoreAdapter", () => { * let database: Database; * let kysely: Kysely<KyselySemaphoreTables>; * * beforeEach(() => { * database = new Sqlite(":memory:"); * kysely = new Kysely({ * dialect: new SqliteDialect({ * database, * }), * }); * }); * afterEach(() => { * database.close(); * }); * databaseSemaphoreAdapterTestSuite({ * createAdapter: async () => { * const semaphoreAdapter = new kyselySemaphoreAdapter({ * kysely, * shouldRemoveExpiredKeys: false, * }); * await semaphoreAdapter.init(); * return semaphoreAdapter; * }, * test, * beforeEach, * expect, * describe, * }); * }); * ``` */ export declare function databaseSemaphoreAdapterTestSuite(settings: DatabaseSemaphoreAdapterTestSuiteSettings): void;