yukey

main.ts

// The e2e suite entrypoint: `npm run test:e2e` (or `make check-e2e` from the root).
//
// One harness per run (the gallery bundle served statically + a fresh headless Chrome),
// all scenarios against it, unconditional teardown, non-zero exit on any failure.
// Scenario names as CLI args select a subset: `npm run test:e2e -- mc ip`.

import { Checks, type Scenario } from "yukey-testkit/checks";
import { Harness } from "./harness.ts";
import { ipDrive } from "./scenarios/ip-drive.ts";
import { lcDrive } from "./scenarios/lc-drive.ts";
import { mcDrive } from "./scenarios/mc-drive.ts";
import { swDrive } from "./scenarios/yk-button-drive.ts";

const ALL: Scenario[] = [mcDrive, swDrive, ipDrive, lcDrive];

async function main(): Promise<void> {
	const wanted = process.argv.slice(2);
	const unknown = wanted.filter((w) => !ALL.some((s) => s.name === w));
	if (unknown.length > 0) {
		console.error(
			`unknown scenarios: ${unknown.join(", ")} (have: ${ALL.map((s) => s.name).join(", ")})`,
		);
		process.exit(2);
	}
	const chosen = wanted.length > 0 ? ALL.filter((s) => wanted.includes(s.name)) : ALL;

	// Harness.start owns the SIGINT/SIGTERM handlers (and the exit codes 130/143).
	const harness = await Harness.start();

	let failedScenarios = 0;
	const summary: string[] = [];
	try {
		for (const scenario of chosen) {
			console.log(`\n=== ${scenario.name} ===`);
			const checks = new Checks();
			let aborted = false;
			try {
				await scenario.run({ cdp: harness.cdp, baseUrl: harness.baseUrl, checks });
			} catch (err) {
				console.log(`ABORT ${scenario.name}: ${err instanceof Error ? err.message : String(err)}`);
				aborted = true;
			}
			console.log(`${scenario.name}: ${checks.passed}/${checks.total} checks passed`);
			summary.push(
				`${scenario.name} ${checks.passed}/${checks.total}${aborted ? " (aborted)" : ""}`,
			);
			if (aborted || checks.failed > 0) failedScenarios += 1;
		}
	} finally {
		harness.stop();
	}
	console.log(`\ntotal: ${summary.join(", ")}`);
	process.exit(failedScenarios > 0 ? 1 : 0);
}

main().catch((err) => {
	console.error(err);
	process.exit(1);
});

packages/e2e/main.ts · 2.1 KiB · 84fca238b7