fix: replace waitForTimeout with event-driven waits in funnel spec

Replace three fixed-delay waitForTimeout calls with proper event-driven
alternatives per AGENTS.md Engineering Principle #1:
- navigateSPA to /app/stake: use waitForSelector('.stake-view, .login-wrapper')
  to detect when the route has mounted (handles login redirect too)
- wallet auto-connect: use waitForFunction to poll __analytics_events for
  wallet_connect, resolving as soon as the event fires

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
johba 2026-03-24 19:10:46 +00:00
parent 9eed0a258a
commit 4465869788

View file

@ -134,10 +134,10 @@ test.describe('Conversion Funnel: Landing → Swap → Stake', () => {
// ── Step 4: Navigate to stake page ──
console.log('[FUNNEL] Navigating to stake page...');
await navigateSPA(page, '/app/stake');
// eslint-disable-next-line no-restricted-syntax -- waitForTimeout: no event source exists for Ponder indexing lag and UI re-renders after on-chain transactions in E2E tests. See AGENTS.md #Engineering Principles.
await page.waitForTimeout(2_000);
// Stake page may redirect to /app/login if no wallet connected.
// Wait for either page's root element to confirm the route has mounted.
await page.waitForSelector('.stake-view, .login-wrapper', { timeout: 15_000 });
// Either outcome confirms the route is functional.
const currentUrl = page.url();
const isStakePage = currentUrl.includes('/app/stake');
@ -215,8 +215,8 @@ test.describe('Conversion Funnel: Landing → Swap → Stake', () => {
// ── Step 4: Navigate to stake ──
await navigateSPA(page, '/app/stake');
// eslint-disable-next-line no-restricted-syntax -- waitForTimeout: no event source exists for Ponder indexing lag and UI re-renders after on-chain transactions in E2E tests. See AGENTS.md #Engineering Principles.
await page.waitForTimeout(2_000);
// Wait for either page's root element — stake or login redirect.
await page.waitForSelector('.stake-view, .login-wrapper', { timeout: 15_000 });
const currentUrl = page.url();
expect(currentUrl.includes('/app/stake') || currentUrl.includes('/app/login')).toBeTruthy();
@ -274,9 +274,14 @@ test.describe('Conversion Funnel: Landing → Swap → Stake', () => {
expect(hasUmami).toBeTruthy();
console.log('[ANALYTICS] ✅ Analytics tracker available in web-app context');
// Wait for wallet auto-connection (injected provider)
// eslint-disable-next-line no-restricted-syntax -- waitForTimeout: no event source exists for Ponder indexing lag and UI re-renders after on-chain transactions in E2E tests. See AGENTS.md #Engineering Principles.
await page.waitForTimeout(3_000);
// Wait for wallet_connect event to appear in analytics — the injected provider
// fires this when the wallet auto-connects. Poll the events array rather than
// sleeping: this resolves as soon as the event fires, or times out gracefully.
await page.waitForFunction(
() => ((window as unknown as { __analytics_events?: Array<{ name: string }> }).__analytics_events ?? [])
.some(e => e.name === 'wallet_connect'),
{ timeout: 10_000 },
).catch(() => { /* wallet may not auto-connect on this page — see check below */ });
const webAppEvents = await getAnalyticsEvents(page);
console.log(`[ANALYTICS] Web-app events: ${JSON.stringify(webAppEvents)}`);
@ -286,7 +291,7 @@ test.describe('Conversion Funnel: Landing → Swap → Stake', () => {
if (walletEvent) {
console.log('[ANALYTICS] ✅ wallet_connect event verified');
} else {
console.log('[ANALYTICS] wallet_connect not fired yet (wallet may not auto-connect on this page)');
console.log('[ANALYTICS] wallet_connect not fired (wallet did not auto-connect on this page)');
}
console.log('[ANALYTICS] ✅ Analytics funnel verification complete');