import { afterEach, beforeEach, describe, expect, test } from "vitest";
import { databaseSemaphoreAdapterTestSuite } from "@daiso-tech/core/semaphore/test-utilities";
import { LibsqlSemaphoreAdapter } from "@daiso-tech/core/semaphore/adapters";
import { type Client, createClient } from "@libsql/client";
describe("class: LibsqlSemaphoreAdapter", () => {
let client: Client;
beforeEach(() => {
client = createClient({
url: ":memory:",
});
});
afterEach(() => {
client.close();
});
databaseSemaphoreAdapterTestSuite({
createAdapter: async () => {
const semaphoreAdapter = new LibsqlSemaphoreAdapter({
database: client,
tableName: "custom_table",
shouldRemoveExpiredKeys: false,
});
await semaphoreAdapter.init();
return semaphoreAdapter;
},
test,
beforeEach,
expect,
describe,
});
});
The
databaseSemaphoreAdapterTestSuite
function simplifies the process of testing your custom implementation ofIDatabaseSemaphoreAdapter
withvitest
.IMPORT_PATH:
"@daiso-tech/core/semaphore/test-utilities"