createPgStateProviderConformanceContext

Function

Signature

function createPgStateProviderConformanceContext(options): Promise<PgStateProviderConformanceContext>;

postgres/src/conformance/state-provider-conformance.ts:180

Prepares the context the pgStateProviderConformanceCases run against: migrates the schema once through a provider from createStateProvider. Each case then builds its own adapter over a new provider from it, with the tables cleared. Call it once the database is ready, such as in beforeAll; the test file owns the database and releases it itself.

Parameters

  • options
    object
    Context configuration.
  • options.createStateProvider
    () => Promise<PgStateProvider<any>>
    Creates the provider under test, over a database the suite may create tables in. Each case's adapter gets its own provider and closes it when the case ends, so closing one must not release resources the next one needs, such as the pool or the database connection.
  • options.stateAdapterOptions?
    Omit<{ countCap?: number; generateJobId?: () => string; generateWorkerId?: () => string; jobIdType?: string; maxBlockersPerJob?: number; schema?: string; stateProvider: PgStateProvider<any>; tablePrefix?: string; validateJobId?: (id) => boolean; validateWorkerId?: (id) => boolean; workerIdType?: string; }, "stateProvider">
    Options every adapter of the suite is created with, besides its provider, such as the schema, tablePrefix and ID types your application configures. The suite migrates and clears the tables they name.
  • options.withNonTransactionContext
    <T>(fn) => Promise<T>
    Runs the callback with a context of the provider's shape that is not inside a transaction (e.g. a pool client with no BEGIN), so the suite can check isTransaction rejects it.
  • options.withSavepoint?
    <T>(txCtx, fn) => Promise<T>
    Runs fn in a savepoint of txCtx's transaction, opened the way the application opens one, and passes it the savepoint's context: releases the savepoint when fn resolves and rolls it back when fn throws, then rethrows. The suite checks that the provider's onTransactionCommit and onTransactionRollback follow it; without it, those cases pass without checking anything.

Returns

Used in guides

esc

Search guides, integrations and every exported symbol.

↑ ↓ to navigate↵ to open