|
| 1 | +import { expect, test } from '@playwright/test'; |
| 2 | +import { waitForTransaction } from '@sentry-internal/test-utils'; |
| 3 | + |
| 4 | +test('Captures a pageload transaction', async ({ page }) => { |
| 5 | + const transactionEventPromise = waitForTransaction('react-create-browser-router', event => { |
| 6 | + return event.contexts?.trace?.op === 'pageload'; |
| 7 | + }); |
| 8 | + |
| 9 | + await page.goto('/'); |
| 10 | + |
| 11 | + const transactionEvent = await transactionEventPromise; |
| 12 | + |
| 13 | + expect(transactionEvent).toEqual( |
| 14 | + expect.objectContaining({ |
| 15 | + transaction: '/', |
| 16 | + type: 'transaction', |
| 17 | + transaction_info: { |
| 18 | + source: 'route', |
| 19 | + }, |
| 20 | + }), |
| 21 | + ); |
| 22 | + |
| 23 | + expect(transactionEvent.contexts?.trace).toEqual( |
| 24 | + expect.objectContaining({ |
| 25 | + data: expect.objectContaining({ |
| 26 | + deviceMemory: expect.any(String), |
| 27 | + effectiveConnectionType: expect.any(String), |
| 28 | + hardwareConcurrency: expect.any(String), |
| 29 | + 'sentry.idle_span_finish_reason': 'idleTimeout', |
| 30 | + 'sentry.op': 'pageload', |
| 31 | + 'sentry.origin': 'auto.pageload.react.reactrouter_v6', |
| 32 | + 'sentry.sample_rate': 1, |
| 33 | + 'sentry.source': 'route', |
| 34 | + }), |
| 35 | + op: 'pageload', |
| 36 | + span_id: expect.stringMatching(/[a-f0-9]{16}/), |
| 37 | + trace_id: expect.stringMatching(/[a-f0-9]{32}/), |
| 38 | + origin: 'auto.pageload.react.reactrouter_v6', |
| 39 | + }), |
| 40 | + ); |
| 41 | +}); |
| 42 | + |
| 43 | +test('Captures a navigation transaction', async ({ page }) => { |
| 44 | + const transactionEventPromise = waitForTransaction('react-create-browser-router', event => { |
| 45 | + return event.contexts?.trace?.op === 'navigation'; |
| 46 | + }); |
| 47 | + |
| 48 | + await page.goto('/'); |
| 49 | + const linkElement = page.locator('id=navigation'); |
| 50 | + await linkElement.click(); |
| 51 | + |
| 52 | + const transactionEvent = await transactionEventPromise; |
| 53 | + expect(transactionEvent.contexts?.trace).toEqual({ |
| 54 | + data: expect.objectContaining({ |
| 55 | + 'sentry.idle_span_finish_reason': 'idleTimeout', |
| 56 | + 'sentry.op': 'navigation', |
| 57 | + 'sentry.origin': 'auto.navigation.react.reactrouter_v6', |
| 58 | + 'sentry.sample_rate': 1, |
| 59 | + 'sentry.source': 'route', |
| 60 | + }), |
| 61 | + op: 'navigation', |
| 62 | + span_id: expect.stringMatching(/[a-f0-9]{16}/), |
| 63 | + trace_id: expect.stringMatching(/[a-f0-9]{32}/), |
| 64 | + origin: 'auto.navigation.react.reactrouter_v6', |
| 65 | + }); |
| 66 | + |
| 67 | + expect(transactionEvent).toEqual( |
| 68 | + expect.objectContaining({ |
| 69 | + transaction: '/user/:id', |
| 70 | + type: 'transaction', |
| 71 | + transaction_info: { |
| 72 | + source: 'route', |
| 73 | + }, |
| 74 | + }), |
| 75 | + ); |
| 76 | + |
| 77 | + expect(transactionEvent.spans).toEqual([]); |
| 78 | +}); |
0 commit comments