pgsql-test
Version:
pgsql-test offers isolated, role-aware, and rollback-friendly PostgreSQL environments for integration tests — giving developers realistic test coverage without external state pollution
39 lines (38 loc) • 1.63 kB
TypeScript
import { PgConfig } from 'pg-env';
import { PgClient, PgClientOpts } from 'pgsql-client';
import { type JsonSeedMap } from 'pgsql-seed';
import { type CsvSeedMap } from 'pgsql-seed';
import { QueryResult } from 'pg';
export type PgTestClientOpts = PgClientOpts & {
/**
* Enable enhanced PostgreSQL error messages with extended fields.
* Defaults to true. Errors will include detail, hint, where, position, etc.
* Can be disabled by setting enhancedErrors: false.
*/
enhancedErrors?: boolean;
};
export declare class PgTestClient extends PgClient {
protected testOpts: PgTestClientOpts;
constructor(config: PgConfig, opts?: PgTestClientOpts);
/**
* Check if enhanced errors are enabled. Defaults to true.
* Can be disabled by setting enhancedErrors: false in options.
*/
private shouldEnhanceErrors;
/**
* Override query to enhance PostgreSQL errors with extended fields.
* When enhancedErrors is enabled, errors will include detail, hint, where, position, etc.
*/
query<T = any>(query: string, values?: any[]): Promise<QueryResult<T>>;
beforeEach(): Promise<void>;
afterEach(): Promise<void>;
/**
* Commit current transaction to make data visible to other connections, then start fresh transaction.
* Maintains test isolation by creating a savepoint and reapplying session context.
*/
publish(): Promise<void>;
loadJson(data: JsonSeedMap): Promise<void>;
loadSql(files: string[]): Promise<void>;
loadCsv(tables: CsvSeedMap): Promise<void>;
loadPgpm(cwd?: string, cache?: boolean): Promise<void>;
}