|
| 1 | +import { expect, test } from '@playwright/test'; |
| 2 | +import { waitForError } from '@sentry-internal/test-utils'; |
| 3 | + |
| 4 | +test.describe('client-side errors', () => { |
| 5 | + test('captures error thrown on click', async ({ page }) => { |
| 6 | + const errorEventPromise = waitForError('astro-4', errorEvent => { |
| 7 | + return errorEvent?.exception?.values?.[0]?.value === 'client error'; |
| 8 | + }); |
| 9 | + |
| 10 | + await page.goto('/client-error'); |
| 11 | + |
| 12 | + await page.getByText('Throw Error').click(); |
| 13 | + |
| 14 | + const errorEvent = await errorEventPromise; |
| 15 | + |
| 16 | + const errorEventFrames = errorEvent.exception?.values?.[0]?.stacktrace?.frames; |
| 17 | + |
| 18 | + expect(errorEventFrames?.[errorEventFrames?.length - 1]).toEqual( |
| 19 | + expect.objectContaining({ |
| 20 | + colno: expect.any(Number), |
| 21 | + lineno: expect.any(Number), |
| 22 | + filename: expect.stringContaining('/client-error'), |
| 23 | + function: 'HTMLButtonElement.onclick', |
| 24 | + in_app: true, |
| 25 | + }), |
| 26 | + ); |
| 27 | + |
| 28 | + expect(errorEvent).toMatchObject({ |
| 29 | + exception: { |
| 30 | + values: [ |
| 31 | + { |
| 32 | + mechanism: { |
| 33 | + handled: false, |
| 34 | + type: 'onerror', |
| 35 | + }, |
| 36 | + type: 'Error', |
| 37 | + value: 'client error', |
| 38 | + stacktrace: expect.any(Object), // detailed check above |
| 39 | + }, |
| 40 | + ], |
| 41 | + }, |
| 42 | + level: 'error', |
| 43 | + platform: 'javascript', |
| 44 | + request: { |
| 45 | + url: expect.stringContaining('/client-error'), |
| 46 | + headers: { |
| 47 | + 'User-Agent': expect.any(String), |
| 48 | + }, |
| 49 | + }, |
| 50 | + event_id: expect.stringMatching(/[a-f0-9]{32}/), |
| 51 | + timestamp: expect.any(Number), |
| 52 | + sdk: { |
| 53 | + integrations: expect.arrayContaining([ |
| 54 | + 'InboundFilters', |
| 55 | + 'FunctionToString', |
| 56 | + 'BrowserApiErrors', |
| 57 | + 'Breadcrumbs', |
| 58 | + 'GlobalHandlers', |
| 59 | + 'LinkedErrors', |
| 60 | + 'Dedupe', |
| 61 | + 'HttpContext', |
| 62 | + 'BrowserTracing', |
| 63 | + ]), |
| 64 | + name: 'sentry.javascript.astro', |
| 65 | + version: expect.any(String), |
| 66 | + packages: expect.any(Array), |
| 67 | + }, |
| 68 | + transaction: '/client-error', |
| 69 | + contexts: { |
| 70 | + trace: { |
| 71 | + trace_id: expect.stringMatching(/[a-f0-9]{32}/), |
| 72 | + parent_span_id: expect.stringMatching(/[a-f0-9]{16}/), |
| 73 | + span_id: expect.stringMatching(/[a-f0-9]{16}/), |
| 74 | + }, |
| 75 | + }, |
| 76 | + environment: 'qa', |
| 77 | + }); |
| 78 | + }); |
| 79 | +}); |
0 commit comments