diff --git a/scripts/check-forms.ts b/scripts/check-forms.ts index 9ed0f973..6217b4ce 100644 --- a/scripts/check-forms.ts +++ b/scripts/check-forms.ts @@ -12,8 +12,8 @@ async function main() { console.log(`\nšŸš€ Starting E2E Form Submission Check for: ${targetUrl}`); // 0. Settlement Delay: Wait for deployment to settle (sync containers/Varnish) - console.log(`ā³ Waiting 5s for deployment settlement...`); - await delay(5000); + console.log(`ā³ Waiting 10s for deployment settlement...`); + await delay(10000); // 1. Fetch Sitemap to discover the contact page and a product page const sitemapUrl = `${targetUrl.replace(/\/$/, '')}/sitemap.xml`; @@ -80,6 +80,24 @@ async function main() { const page = await browser.newPage(); + // Enable Request Interception to force cache-busting on ALL static assets + await page.setRequestInterception(true); + page.on('request', (request) => { + const url = request.url(); + // Intercept Next.js chunks and data to bypass Varnish 404-caching + if ( + (url.includes('/_next/static/') || url.includes('/_next/data/')) && + !url.includes('?cb=') && + !url.includes('&cb=') + ) { + const buster = `cb=${Date.now()}`; + const newUrl = url.includes('?') ? `${url}&${buster}` : `${url}?${buster}`; + request.continue({ url: newUrl }); + } else { + request.continue(); + } + }); + let chunkErrorsDetected = false; page.on('console', (msg) => { const text = msg.text(); @@ -110,7 +128,7 @@ async function main() { // First attempt await page.goto(url, { waitUntil: 'domcontentloaded', timeout: 30000 }); - await delay(2000); // Allow initial JS execution + await delay(3000); // Allow initial JS execution if (chunkErrorsDetected) { const cbUrl = `${url}${url.includes('?') ? '&' : '?'}cb=${Date.now()}`; @@ -120,7 +138,7 @@ async function main() { } // Wait for network to settle slightly - await page.waitForNetworkIdle({ idleTime: 500, timeout: 10000 }).catch(() => {}); + await page.waitForNetworkIdle({ idleTime: 1000, timeout: 10000 }).catch(() => {}); }; // 3. Authenticate through Gatekeeper login form