Files
klz-cables.com/scripts/smoke.ts
Marc Mintel ff73aa7c4e
All checks were successful
Build & Deploy / 🔍 Prepare (push) Successful in 6s
Build & Deploy / 🧪 QA (push) Successful in 49s
Build & Deploy / 🏗️ Build (push) Successful in 1m40s
Build & Deploy / 🚀 Deploy (push) Successful in 13s
Build & Deploy / 🧪 Post-Deploy Verification (push) Successful in 2m8s
Build & Deploy / 🔔 Notify (push) Successful in 2s
fix: use setup-chrome action to install chromium and system dependencies
2026-05-04 22:10:36 +02:00

80 lines
2.9 KiB
TypeScript

import puppeteer from 'puppeteer';
const targetUrl = process.argv[2] || process.env.NEXT_PUBLIC_BASE_URL || 'http://localhost:3000';
const gatekeeperPassword = process.env.GATEKEEPER_PASSWORD || 'klz2026';
async function run() {
console.log(`🚀 Smoke Test: ${targetUrl}`);
const browser = await puppeteer.launch({
headless: true,
executablePath: process.env.PUPPETEER_EXECUTABLE_PATH || undefined,
args: ['--no-sandbox', '--disable-setuid-sandbox'],
});
const page = await browser.newPage();
try {
// 1. Login via Gatekeeper
console.log('🔑 Authenticating...');
await page.goto(targetUrl, { waitUntil: 'networkidle2' });
const isGatekeeper = await page.$('input[name="password"]');
if (isGatekeeper) {
await page.type('input[name="password"]', gatekeeperPassword);
await Promise.all([
page.waitForNavigation({ waitUntil: 'networkidle2' }),
page.click('button[type="submit"]'),
]);
}
// 2. Check Key Pages & Assets
const pages = ['/', '/de/kontakt', '/en/contact', '/de/blog'];
for (const p of pages) {
console.log(`📄 Checking ${p}...`);
const res = await page.goto(`${targetUrl}${p}`, { waitUntil: 'domcontentloaded' });
if (res?.status() !== 200) throw new Error(`Page ${p} returned ${res?.status()}`);
// Check for broken images on this page
const images = await page.$$eval('img', (imgs) => imgs.map((img) => img.src));
console.log(` Checking ${images.length} images...`);
for (const src of images.slice(0, 5)) {
// Check first 5 images per page
const imgRes = await page.goto(src, { waitUntil: 'domcontentloaded' }).catch(() => null);
if (imgRes && imgRes.status() >= 400)
console.warn(` ⚠️ Broken image: ${src} (${imgRes.status()})`);
}
await page.goto(`${targetUrl}${p}`, { waitUntil: 'domcontentloaded' }); // Go back
}
// 3. Test Contact Form
console.log('📝 Testing Contact Form...');
await page.goto(`${targetUrl}/de/kontakt`, { waitUntil: 'networkidle2' });
await page.type('input[name="name"]', 'Smoke Test');
await page.type('input[name="email"]', 'smoke@mintel.me');
await page.type('textarea[name="message"]', 'Automated smoke test submission.');
await Promise.all([
page.waitForSelector('[role="alert"]', { timeout: 10000 }),
page.click('button[type="submit"]'),
]);
const alertText = await page.$eval('[role="alert"]', (el) => el.textContent);
console.log(`🔔 Alert: ${alertText}`);
if (alertText?.toLowerCase().includes('error') || alertText?.toLowerCase().includes('fehler')) {
throw new Error(`Form submission failed: ${alertText}`);
}
console.log('✅ Smoke test passed!');
process.exit(0);
} catch (err: any) {
console.error(`❌ Smoke test failed: ${err.message}`);
process.exit(1);
} finally {
await browser.close();
}
}
run();