import type { Connection, EntityManager, QueryRunner } from "typeorm"; import { MockAgent } from "undici"; import { ConnectionName } from "../database"; export declare enum TestIsolationStrategy { /** * Isolate each test by running the whole test case in one wrapping database transaction * Useful for making changes to the DB that you know will be automatically and fully reverted before the next case runs */ Transaction = "Transaction", /** * Isolate each test by creating a new template database for each test (see https://www.postgresql.org/docs/current/manage-ag-templatedbs.html) * Useful for writing end-to-end tests that are imitating production. */ TemplateDatabase = "TemplateDatabase", /** * Isolate a whole test suite by creating a new template database for each test (see https://www.postgresql.org/docs/current/manage-ag-templatedbs.html) * Useful for writing end-to-end tests that are imitating production that do long or expensive setup in a `beforeAll` hook. */ SuiteWiseTemplateDatabase = "SuiteWiseTemplateDatabase", /** * Don't isolate each test case at all -- dangerous! * Will cause test state leaks if the tests make any writes that aren't rolled back or reset somehow. */ None = "None" } /** * Global context singleton for handy referencing during tests */ export declare class TestContext { isolationStrategy: TestIsolationStrategy; defaultConnections: Record; defaultManagers: Record; defaultQueryRunners: Record; utilityConnections: Record; utilityManagers: Record; undiciAgent: MockAgent; private managedDatabases; static boot(isolationStrategy?: TestIsolationStrategy): Promise; constructor(isolationStrategy?: TestIsolationStrategy); /** Get an entity manager using the default connection options for the given connection name */ manager(connectionName: ConnectionName): EntityManager; /** Get an entity manager using the utility connection options for the given connection name */ utilityManager(connectionName: ConnectionName): EntityManager; boot(): Promise; bootConnections(): Promise; resetBeforeTest(): Promise; resetAfterTest(): Promise; setupTransactionalConnections(): Promise; setupNontransactionalConnections(): void; takeoverServerGlobals(): void; restoreTemplateDatabases(): Promise; installJestHooks(): void; installTestIsolationHooks(isolationStrategy: TestIsolationStrategy): void; } export declare const testContext: TestContext; /** * Set up the starscream test context with active connections and managers. * Uses *real* connections that can serve multiple transactions simultaneously (and aren't locked to one transaction for test isolation) */ export declare const withActiveTestConnections: (run: () => Promise) => Promise; /** * Set up the starscream test context with an active connection, queryRunner and manager. * Uses one single connection locked in to one query runner for wrapping things in easily rolled back transactions for tests. */ export declare const withConnectionLockedTestManager: (run: () => Promise) => Promise;