|
| 1 | +import { expect, test } from '@playwright/test'; |
| 2 | +import { waitForTransaction } from '@sentry-internal/test-utils'; |
| 3 | + |
| 4 | +test('lazyRouteTimeout: Routes load within timeout window', async ({ page }) => { |
| 5 | + const transactionPromise = waitForTransaction('react-router-7-lazy-routes', async transactionEvent => { |
| 6 | + console.log('[WAIT] Transaction Event:', JSON.stringify(transactionEvent, null, 2)); |
| 7 | + return ( |
| 8 | + !!transactionEvent?.transaction && |
| 9 | + transactionEvent.contexts?.trace?.op === 'navigation' && |
| 10 | + transactionEvent.transaction.includes('deep') |
| 11 | + ); |
| 12 | + }); |
| 13 | + |
| 14 | + // Route takes ~900ms, timeout allows 1050ms (50 + 1000) |
| 15 | + // Routes will load in time → parameterized name |
| 16 | + await page.goto('/?idleTimeout=50&timeout=1000'); |
| 17 | + |
| 18 | + const navigationLink = page.locator('id=navigation-to-deep'); |
| 19 | + await expect(navigationLink).toBeVisible(); |
| 20 | + await navigationLink.click(); |
| 21 | + |
| 22 | + const event = await transactionPromise; |
| 23 | + |
| 24 | + console.log('[TEST] Routes load within timeout:'); |
| 25 | + console.log(' Transaction:', event.transaction); |
| 26 | + console.log(' Source:', event.contexts?.trace?.data?.['sentry.source']); |
| 27 | + console.log(' Finish reason:', event.contexts?.trace?.data?.['sentry.idle_span_finish_reason']); |
| 28 | + |
| 29 | + // Should get full parameterized route |
| 30 | + expect(event.transaction).toBe('/deep/level2/level3/:id'); |
| 31 | + expect(event.contexts?.trace?.data?.['sentry.source']).toBe('route'); |
| 32 | + expect(event.contexts?.trace?.data?.['sentry.idle_span_finish_reason']).toBe('idleTimeout'); |
| 33 | +}); |
| 34 | + |
| 35 | +test('lazyRouteTimeout: Infinity timeout always waits for routes', async ({ page }) => { |
| 36 | + const transactionPromise = waitForTransaction('react-router-7-lazy-routes', async transactionEvent => { |
| 37 | + console.log('[WAIT] Transaction Event:', JSON.stringify(transactionEvent, null, 2)); |
| 38 | + return ( |
| 39 | + !!transactionEvent?.transaction && |
| 40 | + transactionEvent.contexts?.trace?.op === 'navigation' && |
| 41 | + transactionEvent.transaction.includes('deep') |
| 42 | + ); |
| 43 | + }); |
| 44 | + |
| 45 | + // Infinity timeout → waits however long needed |
| 46 | + await page.goto('/?idleTimeout=50&timeout=Infinity'); |
| 47 | + |
| 48 | + const navigationLink = page.locator('id=navigation-to-deep'); |
| 49 | + await expect(navigationLink).toBeVisible(); |
| 50 | + await navigationLink.click(); |
| 51 | + |
| 52 | + const event = await transactionPromise; |
| 53 | + |
| 54 | + console.log('[TEST] Infinity timeout:'); |
| 55 | + console.log(' Transaction:', event.transaction); |
| 56 | + console.log(' Source:', event.contexts?.trace?.data?.['sentry.source']); |
| 57 | + |
| 58 | + // Should wait indefinitely and get full route |
| 59 | + expect(event.transaction).toBe('/deep/level2/level3/:id'); |
| 60 | + expect(event.contexts?.trace?.data?.['sentry.source']).toBe('route'); |
| 61 | + expect(event.contexts?.trace?.data?.['sentry.idle_span_finish_reason']).toBe('idleTimeout'); |
| 62 | +}); |
| 63 | + |
| 64 | +test('idleTimeout: Captures all activity with increased timeout', async ({ page }) => { |
| 65 | + const transactionPromise = waitForTransaction('react-router-7-lazy-routes', async transactionEvent => { |
| 66 | + console.log('[WAIT] Transaction Event:', JSON.stringify(transactionEvent, null, 2)); |
| 67 | + return ( |
| 68 | + !!transactionEvent?.transaction && |
| 69 | + transactionEvent.contexts?.trace?.op === 'navigation' && |
| 70 | + transactionEvent.transaction.includes('deep') |
| 71 | + ); |
| 72 | + }); |
| 73 | + |
| 74 | + // High idleTimeout (5000ms) ensures transaction captures all lazy loading activity |
| 75 | + await page.goto('/?idleTimeout=5000'); |
| 76 | + |
| 77 | + const navigationLink = page.locator('id=navigation-to-deep'); |
| 78 | + await expect(navigationLink).toBeVisible(); |
| 79 | + await navigationLink.click(); |
| 80 | + |
| 81 | + const event = await transactionPromise; |
| 82 | + |
| 83 | + console.log('[TEST] Increased idleTimeout:'); |
| 84 | + console.log(' Transaction:', event.transaction); |
| 85 | + console.log(' Duration:', event.timestamp! - event.start_timestamp); |
| 86 | + |
| 87 | + expect(event.transaction).toBe('/deep/level2/level3/:id'); |
| 88 | + expect(event.contexts?.trace?.data?.['sentry.source']).toBe('route'); |
| 89 | + expect(event.contexts?.trace?.data?.['sentry.idle_span_finish_reason']).toBe('idleTimeout'); |
| 90 | + |
| 91 | + // Transaction should wait for full idle timeout (5+ seconds) |
| 92 | + const duration = event.timestamp! - event.start_timestamp; |
| 93 | + expect(duration).toBeGreaterThan(5.0); |
| 94 | + expect(duration).toBeLessThan(7.0); |
| 95 | +}); |
| 96 | + |
| 97 | +test('idleTimeout: Finishes prematurely with low timeout', async ({ page }) => { |
| 98 | + const transactionPromise = waitForTransaction('react-router-7-lazy-routes', async transactionEvent => { |
| 99 | + console.log('[WAIT] Transaction Event:', JSON.stringify(transactionEvent, null, 2)); |
| 100 | + return ( |
| 101 | + !!transactionEvent?.transaction && |
| 102 | + transactionEvent.contexts?.trace?.op === 'navigation' && |
| 103 | + transactionEvent.transaction.includes('deep') |
| 104 | + ); |
| 105 | + }); |
| 106 | + |
| 107 | + // Very low idleTimeout (50ms) and lazyRouteTimeout (100ms) |
| 108 | + // Transaction finishes quickly, but still gets parameterized route name |
| 109 | + await page.goto('/?idleTimeout=50&timeout=100'); |
| 110 | + |
| 111 | + const navigationLink = page.locator('id=navigation-to-deep'); |
| 112 | + await expect(navigationLink).toBeVisible(); |
| 113 | + await navigationLink.click(); |
| 114 | + |
| 115 | + const event = await transactionPromise; |
| 116 | + |
| 117 | + console.log('[TEST] Low idleTimeout:'); |
| 118 | + console.log(' Transaction:', event.transaction); |
| 119 | + console.log(' Duration:', event.timestamp! - event.start_timestamp); |
| 120 | + |
| 121 | + expect(event.contexts?.trace?.data?.['sentry.idle_span_finish_reason']).toBe('idleTimeout'); |
| 122 | + expect(event.transaction).toBe('/deep/level2/level3/:id'); |
| 123 | + expect(event.contexts?.trace?.data?.['sentry.source']).toBe('route'); |
| 124 | + |
| 125 | + // Transaction should finish quickly (< 200ms) |
| 126 | + const duration = event.timestamp! - event.start_timestamp; |
| 127 | + expect(duration).toBeLessThan(0.2); |
| 128 | +}); |
| 129 | + |
| 130 | +test('idleTimeout: Pageload on deeply nested route', async ({ page }) => { |
| 131 | + const pageloadPromise = waitForTransaction('react-router-7-lazy-routes', async transactionEvent => { |
| 132 | + console.log('[WAIT] Transaction Event:', JSON.stringify(transactionEvent, null, 2)); |
| 133 | + return ( |
| 134 | + !!transactionEvent?.transaction && |
| 135 | + transactionEvent.contexts?.trace?.op === 'pageload' && |
| 136 | + transactionEvent.transaction.includes('deep') |
| 137 | + ); |
| 138 | + }); |
| 139 | + |
| 140 | + // Direct pageload to deeply nested route (not navigation) |
| 141 | + await page.goto('/deep/level2/level3/12345'); |
| 142 | + |
| 143 | + const pageloadEvent = await pageloadPromise; |
| 144 | + |
| 145 | + console.log('[TEST] Pageload on nested route:'); |
| 146 | + console.log(' Transaction:', pageloadEvent.transaction); |
| 147 | + console.log(' Op:', pageloadEvent.contexts?.trace?.op); |
| 148 | + |
| 149 | + expect(pageloadEvent.transaction).toBe('/deep/level2/level3/:id'); |
| 150 | + expect(pageloadEvent.contexts?.trace?.data?.['sentry.source']).toBe('route'); |
| 151 | + expect(pageloadEvent.contexts?.trace?.data?.['sentry.idle_span_finish_reason']).toBe('idleTimeout'); |
| 152 | +}); |
0 commit comments