chore(tests): simplify and optimize smoke test image validation
All checks were successful
Build & Deploy / 🔍 Prepare (push) Successful in 6s
Build & Deploy / 🧪 QA (push) Successful in 48s
Build & Deploy / 🏗️ Build (push) Successful in 1m42s
Build & Deploy / 🚀 Deploy (push) Successful in 12s
Build & Deploy / 🧪 Post-Deploy Verification (push) Has been skipped
Build & Deploy / 🔔 Notify (push) Successful in 2s
All checks were successful
Build & Deploy / 🔍 Prepare (push) Successful in 6s
Build & Deploy / 🧪 QA (push) Successful in 48s
Build & Deploy / 🏗️ Build (push) Successful in 1m42s
Build & Deploy / 🚀 Deploy (push) Successful in 12s
Build & Deploy / 🧪 Post-Deploy Verification (push) Has been skipped
Build & Deploy / 🔔 Notify (push) Successful in 2s
This commit is contained in:
@@ -34,16 +34,30 @@ async function run() {
|
|||||||
const res = await page.goto(`${targetUrl}${p}`, { waitUntil: 'domcontentloaded' });
|
const res = await page.goto(`${targetUrl}${p}`, { waitUntil: 'domcontentloaded' });
|
||||||
if (res?.status() !== 200) throw new Error(`Page ${p} returned ${res?.status()}`);
|
if (res?.status() !== 200) throw new Error(`Page ${p} returned ${res?.status()}`);
|
||||||
|
|
||||||
// Check for broken images on this page
|
// 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));
|
const images = await page.$$eval('img', (imgs) => imgs.map((img) => img.src).filter(Boolean));
|
||||||
console.log(` Checking ${images.length} images...`);
|
console.log(` Checking ${images.length} images...`);
|
||||||
for (const src of images.slice(0, 5)) {
|
|
||||||
// Check first 5 images per page
|
const brokenImages = await page.evaluate(async (urls) => {
|
||||||
const imgRes = await page.goto(src, { waitUntil: 'domcontentloaded' }).catch(() => null);
|
const broken: string[] = [];
|
||||||
if (imgRes && imgRes.status() >= 400)
|
await Promise.all(
|
||||||
console.warn(` ⚠️ Broken image: ${src} (${imgRes.status()})`);
|
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
|
// 3. Test Contact Form
|
||||||
|
|||||||
Reference in New Issue
Block a user