fix: use Promise.all for navigation-triggering clicks + cap test timeout

Playwright click() can race with waitForURL when the click triggers
window.location.href. Use Promise.all([waitForURL, click]) pattern
to ensure the URL listener is active before the click fires.

Also cap funnel test timeout to 3 minutes (these are navigation-only,
no blockchain transactions) to fail fast rather than hang.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
johba 2026-03-23 17:37:46 +00:00
parent 097121e0fe
commit ea700b224e

View file

@ -33,6 +33,9 @@ async function getAnalyticsEvents(page: Page): Promise<Array<{ name: string; dat
} }
test.describe('Conversion Funnel: Landing → Swap → Stake', () => { test.describe('Conversion Funnel: Landing → Swap → Stake', () => {
// Cap per-test timeout to 3 minutes — funnel tests are navigation-only, no transactions.
test.describe.configure({ timeout: 3 * 60 * 1000 });
test.beforeAll(async () => { test.beforeAll(async () => {
await validateStackHealthy(STACK_CONFIG); await validateStackHealthy(STACK_CONFIG);
}); });
@ -63,11 +66,12 @@ test.describe('Conversion Funnel: Landing → Swap → Stake', () => {
// ── Step 2: Click CTA → navigates to /app/get-krk ── // ── Step 2: Click CTA → navigates to /app/get-krk ──
console.log('[FUNNEL] Clicking hero "Get $KRK" CTA...'); console.log('[FUNNEL] Clicking hero "Get $KRK" CTA...');
await heroCta.click(); // Use Promise.all to avoid race: the click triggers window.location.href
// which starts a full-page navigation through Caddy to the webapp.
// The landing CTA sets window.location.href for /app/* paths, triggering await Promise.all([
// a full-page navigation through Caddy to the webapp service. page.waitForURL('**/app/get-krk**', { timeout: 30_000 }),
await page.waitForURL('**/app/get-krk**', { timeout: 30_000 }); heroCta.click(),
]);
console.log('[FUNNEL] Navigated to web-app get-krk page'); console.log('[FUNNEL] Navigated to web-app get-krk page');
// Verify the Get KRK page rendered // Verify the Get KRK page rendered
@ -173,9 +177,10 @@ test.describe('Conversion Funnel: Landing → Swap → Stake', () => {
const heroCta = page.locator('.header-cta button, .header-cta .k-button').first(); const heroCta = page.locator('.header-cta button, .header-cta .k-button').first();
await expect(heroCta).toBeVisible({ timeout: 15_000 }); await expect(heroCta).toBeVisible({ timeout: 15_000 });
console.log('[FUNNEL-MOBILE] Clicking hero CTA...'); console.log('[FUNNEL-MOBILE] Clicking hero CTA...');
await heroCta.click(); await Promise.all([
page.waitForURL('**/app/get-krk**', { timeout: 30_000 }),
await page.waitForURL('**/app/get-krk**', { timeout: 30_000 }); heroCta.click(),
]);
console.log('[FUNNEL-MOBILE] Navigated to get-krk page'); console.log('[FUNNEL-MOBILE] Navigated to get-krk page');
const getKrkHeading = page.getByRole('heading', { name: 'Get $KRK Tokens' }); const getKrkHeading = page.getByRole('heading', { name: 'Get $KRK Tokens' });