2026-09-22 14:49:08 +00:00
|
|
|
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;
|
2026-10-17 13:52:08 +00:00
|
|
|
let interrupted = false;
|
|
|
|
|
const stop = () => {
|
|
|
|
|
interrupted = true;
|
|
|
|
|
child?.kill("SIGTERM");
|
|
|
|
|
};
|
2026-09-22 14:49:08 +00:00
|
|
|
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 }
|
|
|
|
|
),
|
2026-10-17 13:52:08 +00:00
|
|
|
runChild: async (environment) => {
|
|
|
|
|
if (interrupted) {
|
|
|
|
|
throw new Error("E2E execution interrupted.");
|
|
|
|
|
}
|
|
|
|
|
return await new Promise<number>((resolve, reject) => {
|
2026-09-22 14:49:08 +00:00
|
|
|
child = spawn(process.execPath, args, {
|
|
|
|
|
env: { ...process.env, ...environment },
|
|
|
|
|
stdio: "inherit",
|
|
|
|
|
});
|
|
|
|
|
child.once("error", reject);
|
|
|
|
|
child.once("close", (code) => resolve(code ?? 1));
|
2026-10-17 13:52:08 +00:00
|
|
|
});
|
|
|
|
|
},
|
2026-09-22 14:49:08 +00:00
|
|
|
});
|
|
|
|
|
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;
|
|
|
|
|
});
|