Files
mintel.me/apps/web/scripts/check-forms.ts
Marc Mintel 88b4626d6e
All checks were successful
Build & Deploy / 🔍 Prepare (push) Successful in 6s
Build & Deploy / 🧪 QA (push) Successful in 1m55s
Build & Deploy / 🏗️ Build (push) Successful in 11m16s
Build & Deploy / 🚀 Deploy (push) Successful in 21s
Build & Deploy / 🧪 Post-Deploy Verification (push) Successful in 1m54s
Build & Deploy / 🔔 Notify (push) Successful in 1s
fix(ci): add redirect delay to Puppeteer to prevent ERR_ABORTED during Gatekeeper redirect
2026-03-02 18:39:32 +01:00

103 lines
3.2 KiB
TypeScript
Raw Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import puppeteer from "puppeteer";
const targetUrl = process.env.TEST_URL || "http://localhost:3000";
const gatekeeperPassword = process.env.GATEKEEPER_PASSWORD || "secret";
async function main() {
console.log(`\n🚀 Starting E2E Form Submission Check for: ${targetUrl}`);
// Launch browser with KLZ pattern: use system chromium via env
const browser = await puppeteer.launch({
headless: true,
executablePath:
process.env.PUPPETEER_EXECUTABLE_PATH ||
process.env.CHROME_PATH ||
undefined,
args: [
"--no-sandbox",
"--disable-setuid-sandbox",
"--disable-dev-shm-usage",
"--disable-gpu",
"--ignore-certificate-errors",
"--disable-web-security",
"--disable-features=IsolateOrigins,site-per-process",
],
});
const page = await browser.newPage();
// Enable console logging from the page for debugging
page.on("console", (msg) => console.log(` [PAGE] ${msg.text()}`));
page.on("pageerror", (err: Error) =>
console.error(` [PAGE ERROR] ${err.message}`),
);
page.on("requestfailed", (req) =>
console.error(
` [REQUEST FAILED] ${req.url()} - ${req.failure()?.errorText}`,
),
);
try {
// Authenticate through Gatekeeper
console.log(`\n🛡 Authenticating through Gatekeeper...`);
console.log(` Navigating to: ${targetUrl}`);
const response = await page.goto(targetUrl, {
waitUntil: "domcontentloaded",
timeout: 60000,
});
// Give Gatekeeper a second to redirect if needed
console.log(` Waiting for potential Gatekeeper redirect...`);
await new Promise((resolve) => setTimeout(resolve, 3000));
console.log(` Response status: ${response?.status()}`);
console.log(` Response URL: ${response?.url()}`);
const isGatekeeperPage = await page.$('input[name="password"]');
if (isGatekeeperPage) {
await page.type('input[name="password"]', gatekeeperPassword);
await Promise.all([
page.waitForNavigation({
waitUntil: "domcontentloaded",
timeout: 60000,
}),
page.click('button[type="submit"]'),
]);
await new Promise((resolve) => setTimeout(resolve, 3000));
console.log(`✅ Gatekeeper authentication successful!`);
} else {
console.log(`✅ Already authenticated (no Gatekeeper gate detected).`);
}
// Basic smoke test
console.log(`\n🧪 Testing page load...`);
const title = await page.title();
console.log(`✅ Page Title: ${title}`);
if (title.toLowerCase().includes("mintel")) {
console.log(`✅ Basic smoke test passed!`);
} else {
throw new Error(`Page title mismatch: "${title}"`);
}
} catch (err: any) {
console.error(`❌ Test Failed: ${err.message}`);
// Take a screenshot for debugging
try {
const screenshotPath = "/tmp/e2e-failure.png";
await page.screenshot({ path: screenshotPath, fullPage: true });
console.log(`📸 Screenshot saved to ${screenshotPath}`);
} catch {
/* ignore screenshot errors */
}
console.log(` Current URL: ${page.url()}`);
await browser.close();
process.exit(1);
}
await browser.close();
console.log(`\n🎉 SUCCESS: E2E smoke test passed!`);
process.exit(0);
}
main();