FactuGES_ERP/tests/e2e/support/run-e2e.ts

65 lines
2.2 KiB
TypeScript
Raw Normal View History

import { spawn } from "node:child_process";
import { logger } from "../../../apps/server/src/lib/logger";
import { bootstrapE2EData } from "../../../apps/server/src/testing/e2e/bootstrap-e2e-data";
import { prepareE2ESchema } from "../../../apps/server/src/testing/e2e/prepare-e2e-schema";
import { createE2EDatabaseEnvironment } from "./e2e-database-environment";
import { runE2ELifecycle } from "./e2e-lifecycle";
import { toE2ESchemaDatabaseConfig } from "./e2e-schema-database-config";
async function run(): Promise<void> {
let child: ReturnType<typeof spawn> | undefined;
const stop = () => child?.kill("SIGTERM");
process.once("SIGINT", stop);
process.once("SIGTERM", stop);
try {
const args = ["node_modules/@playwright/test/cli.js", "test", ...process.argv.slice(2)];
const exitCode = await runE2ELifecycle({
provision: createE2EDatabaseEnvironment,
prepare: async (environment) =>
await prepareE2ESchema(toE2ESchemaDatabaseConfig(environment)),
bootstrap: async (environment) =>
await bootstrapE2EData(
toE2ESchemaDatabaseConfig(environment),
{
executionId: environment.executionId,
email: requiredEnvironment("E2E_USER_EMAIL"),
password: requiredEnvironment("E2E_USER_PASSWORD"),
companyName: "FactuGes E2E",
companySlug: "factuges-e2e",
},
{ logger }
),
runChild: async (environment) =>
new Promise<number>((resolve, reject) => {
child = spawn(process.execPath, args, {
env: { ...process.env, ...environment },
stdio: "inherit",
});
child.once("error", reject);
child.once("close", (code) => resolve(code ?? 1));
}),
});
if (exitCode !== 0) {
process.exitCode = exitCode;
}
} finally {
process.removeListener("SIGINT", stop);
process.removeListener("SIGTERM", stop);
}
}
function requiredEnvironment(name: "E2E_USER_EMAIL" | "E2E_USER_PASSWORD"): string {
const value = process.env[name]?.trim();
if (!value) {
throw new Error(`Official E2E requires ${name}.`);
}
return value;
}
run().catch((error) => {
console.error(error);
process.exitCode = 1;
});