From 1fee592ee7df030df6b501741d738cdbccffdc61 Mon Sep 17 00:00:00 2001 From: Marc Mintel Date: Mon, 4 May 2026 22:22:08 +0200 Subject: [PATCH] chore(tests): simplify and optimize smoke test image validation --- scripts/smoke.ts | 30 ++++++++++++++++++++++-------- 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/scripts/smoke.ts b/scripts/smoke.ts index 5e9dccce..d078dbaa 100644 --- a/scripts/smoke.ts +++ b/scripts/smoke.ts @@ -34,16 +34,30 @@ async function run() { 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)); + // Check for broken images (using in-page fetch to preserve session and avoid heavy navigation) + const images = await page.$$eval('img', (imgs) => imgs.map((img) => img.src).filter(Boolean)); 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()})`); + + const brokenImages = await page.evaluate(async (urls) => { + const broken: string[] = []; + await Promise.all( + urls.map(async (url) => { + try { + const res = await fetch(url, { method: 'HEAD' }); + if (res.status >= 400) broken.push(`${url} (Status: ${res.status})`); + } catch (e) { + broken.push(`${url} (Fetch failed)`); + } + }), + ); + return broken; + }, images); + + if (brokenImages.length > 0) { + throw new Error( + `Found ${brokenImages.length} broken images on ${p}:\n${brokenImages.join('\n')}`, + ); } - await page.goto(`${targetUrl}${p}`, { waitUntil: 'domcontentloaded' }); // Go back } // 3. Test Contact Form