- Add E2ESchemaDatabaseConfig interface for database configuration validation. - Implement assertE2ESchemaDatabaseConfig function to enforce schema requirements. - Create prepareE2ESchema function to handle schema preparation and initialization. - Develop E2E lifecycle management functions to provision, prepare, and run tests. - Introduce Docker Compose setup for E2E database environment. - Add Playwright configuration for E2E testing. - Implement various test cases to validate E2E schema preparation and lifecycle. - Create utility functions for environment variable management and database assertions. - Establish smoke tests to verify initial data setup and integrity.
38 lines
1.1 KiB
TypeScript
38 lines
1.1 KiB
TypeScript
export interface E2EEnvironment {
|
|
readonly environment: Record<string, string>;
|
|
destroy(): Promise<void>;
|
|
}
|
|
|
|
export async function runE2ELifecycle<TEnvironment extends E2EEnvironment>(params: {
|
|
provision: () => Promise<TEnvironment>;
|
|
prepare: (environment: TEnvironment) => Promise<void>;
|
|
bootstrap: (environment: TEnvironment) => Promise<void>;
|
|
runChild: (environment: Record<string, string>) => Promise<number>;
|
|
}): Promise<number> {
|
|
const environment = await params.provision();
|
|
let mainFailure: Error | undefined;
|
|
let exitCode: number | undefined;
|
|
|
|
try {
|
|
await params.prepare(environment);
|
|
await params.bootstrap(environment);
|
|
exitCode = await params.runChild(environment.environment);
|
|
} catch (error) {
|
|
mainFailure = error instanceof Error ? error : new Error(String(error));
|
|
}
|
|
|
|
try {
|
|
await environment.destroy();
|
|
} catch (cleanupError) {
|
|
if (!mainFailure) {
|
|
throw cleanupError;
|
|
}
|
|
throw new AggregateError([mainFailure, cleanupError], "E2E execution and cleanup failed.");
|
|
}
|
|
|
|
if (mainFailure) {
|
|
throw mainFailure;
|
|
}
|
|
return exitCode ?? 1;
|
|
}
|