- db-schema: Database schema types from kysely-codegen - db: Database client and helper functions - testing: Overview of testing packages - test-helpers: Database testing utilities - virtual-authenticator: WebAuthn virtual authenticator Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1.5 KiB
1.5 KiB
@reviq/test-helpers
Database testing utilities for integration and e2e tests.
Usage
import {
describeE2E,
createTestDb,
withTestTransaction,
createTestUser,
} from "@reviq/test-helpers";
describeE2E("My API tests", () => {
it("should create a user", async () => {
await withTestTransaction(async (trx) => {
const user = await createTestUser(trx, {
email: "test@example.com",
});
expect(user.id).toBeDefined();
});
});
});
Exports
Test Setup
describeE2E(name, fn)- Wrapper for describe() that skips whenSKIP_DB_TESTS=1SKIP_DB_TESTS- Boolean indicating if db tests should be skipped
Database Utilities
createTestDb()- Create an isolated test databasedestroyTestDb(db)- Destroy a test databasegetSharedDb()- Get the shared test database instancedestroySharedDb()- Destroy the shared databaseinitTestDb()- Initialize the test databaserunMigrations(url)- Run database migrationstruncateAllTables(db)- Clear all data from tablesgetTestDatabaseUrl()- Get the test database connection URL
Transaction Helpers
withTestTransaction(fn)- Run a function in a rolled-back transaction
Fixtures
createTestUser(trx, opts)- Create a test user
Constants
TEST_RP- Test relying party configuration for WebAuthnDEFAULT_TEST_AAGUID- Default AAGUID for virtual authenticatorKNOWN_AAGUIDS- Map of known authenticator AAGUIDs