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