70 lines
2.4 KiB
TypeScript
70 lines
2.4 KiB
TypeScript
import { test } from "@playwright/test";
|
|
|
|
export function missingE2eInputs(keys: readonly string[], env: NodeJS.ProcessEnv = process.env): string[] {
|
|
return keys.filter((key) => !env[key]?.trim());
|
|
}
|
|
|
|
export function optionalE2eBooleanInput(key: string, env: NodeJS.ProcessEnv = process.env): boolean | undefined {
|
|
const value = env[key]?.trim();
|
|
if (!value) {
|
|
if (env.REQUIRE_E2E_READINESS === "1") {
|
|
throw new Error(`${key}=0|1 must be set while REQUIRE_E2E_READINESS=1`);
|
|
}
|
|
return undefined;
|
|
}
|
|
|
|
if (value === "0") return false;
|
|
if (value === "1") return true;
|
|
|
|
throw new Error(`${key} must be 0 or 1, got ${JSON.stringify(value)}`);
|
|
}
|
|
|
|
export function skipOrFailWhenE2eInputsMissing(keys: readonly string[], reason: string, env: NodeJS.ProcessEnv = process.env): void {
|
|
const missing = missingE2eInputs(keys, env);
|
|
if (missing.length === 0) return;
|
|
|
|
const message = `${reason}: missing ${missing.join(", ")}`;
|
|
if (env.REQUIRE_E2E_READINESS === "1") {
|
|
throw new Error(`${message} while REQUIRE_E2E_READINESS=1`);
|
|
}
|
|
test.skip(true, message);
|
|
}
|
|
|
|
export function skipOrFailWhenE2eOptInMissing(key: string, reason: string, env: NodeJS.ProcessEnv = process.env): void {
|
|
if (env[key] === "1") return;
|
|
|
|
const message = `${key}=1 not set - ${reason}`;
|
|
if (env.REQUIRE_E2E_MUTATING_READINESS === "1") {
|
|
throw new Error(`${message} while REQUIRE_E2E_MUTATING_READINESS=1`);
|
|
}
|
|
test.skip(true, message);
|
|
}
|
|
|
|
export function skipOrFailWhenE2eReadinessOptInMissing(key: string, reason: string, env: NodeJS.ProcessEnv = process.env): void {
|
|
if (env[key] === "1") return;
|
|
|
|
const message = `${key}=1 not set - ${reason}`;
|
|
if (env.REQUIRE_E2E_READINESS === "1" || env.REQUIRE_E2E_MUTATING_READINESS === "1") {
|
|
throw new Error(`${message} while REQUIRE_E2E_READINESS=1`);
|
|
}
|
|
test.skip(true, message);
|
|
}
|
|
|
|
export function isE2eOperatorOptInEnabled(key: string, env: NodeJS.ProcessEnv = process.env): boolean {
|
|
return env[key] === "1";
|
|
}
|
|
|
|
export function skipWhenE2eOperatorOptInMissing(key: string, reason: string, env: NodeJS.ProcessEnv = process.env): void {
|
|
if (isE2eOperatorOptInEnabled(key, env)) return;
|
|
|
|
test.skip(true, `${key}=1 not set - ${reason}`);
|
|
}
|
|
|
|
export function skipOrFailWhenE2eFixtureMissing(reason: string, env: NodeJS.ProcessEnv = process.env): never {
|
|
if (env.REQUIRE_E2E_READINESS === "1") {
|
|
throw new Error(`${reason} while REQUIRE_E2E_READINESS=1`);
|
|
}
|
|
test.skip(true, reason);
|
|
throw new Error(reason);
|
|
}
|