Files
publisher-dashboard/packages/testing/test-helpers
igm c9de0b1ac5 Add sideEffects: false to all library packages
Enables tree-shaking for bundlers by marking all library packages
as side-effect-free.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-12 15:22:24 +08:00
..
2026-01-12 13:59:34 +08:00

@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 when SKIP_DB_TESTS=1
  • SKIP_DB_TESTS - Boolean indicating if db tests should be skipped

Database Utilities

  • createTestDb() - Create an isolated test database
  • destroyTestDb(db) - Destroy a test database
  • getSharedDb() - Get the shared test database instance
  • destroySharedDb() - Destroy the shared database
  • initTestDb() - Initialize the test database
  • runMigrations(url) - Run database migrations
  • truncateAllTables(db) - Clear all data from tables
  • getTestDatabaseUrl() - 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 WebAuthn
  • DEFAULT_TEST_AAGUID - Default AAGUID for virtual authenticator
  • KNOWN_AAGUIDS - Map of known authenticator AAGUIDs