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, 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();