@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.
61 lines (60 loc) • 2.15 kB
TypeScript
/**
* @module Cache
*/
import { type TestAPI, type SuiteAPI, type ExpectStatic, type beforeEach } from "vitest";
import { type IDatabaseCacheAdapter } 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 DatabaseCacheAdapterTestSuiteSettings = {
expect: ExpectStatic;
test: TestAPI;
describe: SuiteAPI;
beforeEach: typeof beforeEach;
createAdapter: () => Promisable<IDatabaseCacheAdapter>;
};
/**
* The `databaseCacheAdapterTestSuite` function simplifies the process of testing your custom implementation of {@link IDatabaseCacheAdapter | `IDatabaseCacheAdapter`} with `vitest`.
*
* IMPORT_PATH: `"@daiso-tech/core/cache/test-utilities"`
* @group TestUtilities
* @example
* ```ts
* import { afterEach, beforeEach, describe, expect, test } from "vitest";
* import Sqlite, { type Database } from "better-sqlite3";
* import { databaseCacheAdapterTestSuite } from "@daiso-tech/core/cache/test-utilities";
* import { SqliteCacheAdapter } from "@daiso-tech/core/cache/adapters";
* import { Serde } from "@daiso-tech/core/serde";
* import { SuperJsonSerdeAdapter } from "@daiso-tech/core/serde/adapters";
*
* describe("class: SqliteCacheAdapter", () => {
* let database: Database;
* beforeEach(() => {
* database = new Sqlite(":memory:");
* });
* afterEach(() => {
* database.close();
* });
* databaseCacheAdapterTestSuite({
* createAdapter: async () => {
* const adapter = new SqliteCacheAdapter({
* database: database,
* tableName: "custom_table",
* shouldRemoveExpiredKeys: false,
* serde: new Serde(new SuperJsonSerdeAdapter()),
* });
* await adapter.init();
* return adapter;
* },
* test,
* beforeEach,
* expect,
* describe,
* });
* });
* ```
*/
export declare function databaseCacheAdapterTestSuite(settings: DatabaseCacheAdapterTestSuiteSettings): void;