|
| 1 | +import { expect, test } from '@playwright/test'; |
| 2 | +import { waitForError, waitForTransaction } from '@sentry-internal/test-utils'; |
| 3 | + |
| 4 | +test('Sends correct error event', async ({ page, baseURL }) => { |
| 5 | + const errorEventPromise = waitForError('react-router-7-spa', event => { |
| 6 | + return !event.type && event.exception?.values?.[0]?.value === 'I am an error!'; |
| 7 | + }); |
| 8 | + |
| 9 | + await page.goto('/'); |
| 10 | + |
| 11 | + const exceptionButton = page.locator('id=exception-button'); |
| 12 | + await exceptionButton.click(); |
| 13 | + |
| 14 | + const errorEvent = await errorEventPromise; |
| 15 | + |
| 16 | + expect(errorEvent.exception?.values).toHaveLength(1); |
| 17 | + expect(errorEvent.exception?.values?.[0]?.value).toBe('I am an error!'); |
| 18 | + |
| 19 | + expect(errorEvent.request).toEqual({ |
| 20 | + headers: expect.any(Object), |
| 21 | + url: 'http://localhost:3030/', |
| 22 | + }); |
| 23 | + |
| 24 | + expect(errorEvent.transaction).toEqual('/'); |
| 25 | + |
| 26 | + expect(errorEvent.contexts?.trace).toEqual({ |
| 27 | + trace_id: expect.any(String), |
| 28 | + span_id: expect.any(String), |
| 29 | + }); |
| 30 | +}); |
| 31 | + |
| 32 | +test('Sets correct transactionName', async ({ page }) => { |
| 33 | + const transactionPromise = waitForTransaction('react-router-7-spa', async transactionEvent => { |
| 34 | + return !!transactionEvent?.transaction && transactionEvent.contexts?.trace?.op === 'pageload'; |
| 35 | + }); |
| 36 | + |
| 37 | + const errorEventPromise = waitForError('react-router-7-spa', event => { |
| 38 | + return !event.type && event.exception?.values?.[0]?.value === 'I am an error!'; |
| 39 | + }); |
| 40 | + |
| 41 | + await page.goto('/'); |
| 42 | + const transactionEvent = await transactionPromise; |
| 43 | + |
| 44 | + // Only capture error once transaction was sent |
| 45 | + const exceptionButton = page.locator('id=exception-button'); |
| 46 | + await exceptionButton.click(); |
| 47 | + |
| 48 | + const errorEvent = await errorEventPromise; |
| 49 | + |
| 50 | + expect(errorEvent.exception?.values).toHaveLength(1); |
| 51 | + expect(errorEvent.exception?.values?.[0]?.value).toBe('I am an error!'); |
| 52 | + |
| 53 | + expect(errorEvent.transaction).toEqual('/'); |
| 54 | + |
| 55 | + expect(errorEvent.contexts?.trace).toEqual({ |
| 56 | + trace_id: transactionEvent.contexts?.trace?.trace_id, |
| 57 | + span_id: expect.not.stringContaining(transactionEvent.contexts?.trace?.span_id || ''), |
| 58 | + }); |
| 59 | +}); |
0 commit comments