- 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.2 KiB
TypeScript
38 lines
1.2 KiB
TypeScript
import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
import { dirname, resolve } from "node:path";
|
|
|
|
import { E2E_API_URL, assertOfficialE2EEnvironment } from "./e2e-contract";
|
|
|
|
function readEnvironment(path: string): Record<string, string | undefined> {
|
|
return Object.fromEntries(
|
|
readFileSync(path, "utf8")
|
|
.split(/\r?\n/)
|
|
.filter((line) => line && !line.startsWith("#"))
|
|
.map((line) => {
|
|
const separatorIndex = line.indexOf("=");
|
|
|
|
return [line.slice(0, separatorIndex), line.slice(separatorIndex + 1)];
|
|
})
|
|
);
|
|
}
|
|
|
|
const env = process.env;
|
|
assertOfficialE2EEnvironment(env);
|
|
|
|
const webEnv = readEnvironment(resolve("apps/web/.env.e2e"));
|
|
if (webEnv.VITE_API_SERVER_URL !== E2E_API_URL) {
|
|
throw new Error(`Official E2E requires VITE_API_SERVER_URL=${E2E_API_URL} in apps/web/.env.e2e.`);
|
|
}
|
|
|
|
const certificatesPath = env.COMPANY_CERTIFICATES_PATH;
|
|
if (!certificatesPath) {
|
|
throw new Error("E2E requires COMPANY_CERTIFICATES_PATH in apps/server/.env.e2e.");
|
|
}
|
|
|
|
const certificatesFile = resolve("apps/server", certificatesPath);
|
|
mkdirSync(dirname(certificatesFile), { recursive: true });
|
|
|
|
if (!existsSync(certificatesFile)) {
|
|
writeFileSync(certificatesFile, "{}\n");
|
|
}
|