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.2 kB
/** * @module Lock */ import { type TestAPI, type SuiteAPI, type ExpectStatic, type beforeEach } from "vitest"; import { type IDatabaseLockAdapter } 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 DatabaseLockAdapterTestSuiteSettings = { expect: ExpectStatic; test: TestAPI; describe: SuiteAPI; beforeEach: typeof beforeEach; createAdapter: () => Promisable<IDatabaseLockAdapter>; }; /** * The `databaseLockAdapterTestSuite` function simplifies the process of testing your custom implementation of {@link IDatabaseLockAdapter | `IDatabaseLockAdapter`} with `vitest`. * * IMPORT_PATH: `"@daiso-tech/core/lock/test-utilities"` * @group Utilities * @example * ```ts * import { afterEach, beforeEach, describe, expect, test } from "vitest"; * import { databaseLockAdapterTestSuite } from "@daiso-tech/core/lock/test-utilities"; * import { kyselyLockAdapter, type KyselyLockTables } from "@daiso-tech/core/lock/kysely-lock-adapter"; * import { Kysely, SqliteDialect } from "kysely"; * import Sqlite, { type Database } from "better-sqlite3"; * * describe("class: kyselyLockAdapter", () => { * let database: Database; * let kysely: Kysely<KyselyLockTables>; * * beforeEach(() => { * database = new Sqlite(":memory:"); * kysely = new Kysely({ * dialect: new SqliteDialect({ * database, * }), * }); * }); * afterEach(() => { * database.close(); * }); * databaseLockAdapterTestSuite({ * createAdapter: async () => { * const lockAdapter = new kyselyLockAdapter({ * kysely, * shouldRemoveExpiredKeys: false, * }); * await lockAdapter.init(); * return lockAdapter; * }, * test, * beforeEach, * expect, * describe, * }); * }); * ``` */ export declare function databaseLockAdapterTestSuite(settings: DatabaseLockAdapterTestSuiteSettings): void;