|
| 1 | +import { expect } from '@playwright/test'; |
| 2 | + |
| 3 | +import { sentryTest } from '../../../../utils/fixtures'; |
| 4 | +import { envelopeRequestParser, waitForErrorRequestOnUrl } from '../../../../utils/helpers'; |
| 5 | + |
| 6 | +sentryTest('should capture an AggregateError with embedded errors', async ({ getLocalTestUrl, page }) => { |
| 7 | + const url = await getLocalTestUrl({ testDir: __dirname }); |
| 8 | + const req = await waitForErrorRequestOnUrl(page, url); |
| 9 | + const eventData = envelopeRequestParser(req); |
| 10 | + |
| 11 | + expect(eventData.exception?.values).toHaveLength(4); // AggregateError + 3 embedded errors |
| 12 | + |
| 13 | + // Verify the embedded errors come first |
| 14 | + expect(eventData.exception?.values?.[0]).toMatchObject({ |
| 15 | + type: 'RangeError', |
| 16 | + value: 'Third error message', |
| 17 | + mechanism: { |
| 18 | + type: 'chained', |
| 19 | + handled: true, |
| 20 | + source: expect.stringMatching(/^errors\[\d+\]$/), |
| 21 | + exception_id: expect.any(Number), |
| 22 | + }, |
| 23 | + }); |
| 24 | + |
| 25 | + expect(eventData.exception?.values?.[1]).toMatchObject({ |
| 26 | + type: 'TypeError', |
| 27 | + value: 'Second error message', |
| 28 | + mechanism: { |
| 29 | + type: 'chained', |
| 30 | + handled: true, |
| 31 | + source: expect.stringMatching(/^errors\[\d+\]$/), |
| 32 | + exception_id: expect.any(Number), |
| 33 | + }, |
| 34 | + }); |
| 35 | + |
| 36 | + expect(eventData.exception?.values?.[2]).toMatchObject({ |
| 37 | + type: 'Error', |
| 38 | + value: 'First error message', |
| 39 | + mechanism: { |
| 40 | + type: 'chained', |
| 41 | + handled: true, |
| 42 | + source: expect.stringMatching(/^errors\[\d+\]$/), |
| 43 | + exception_id: expect.any(Number), |
| 44 | + }, |
| 45 | + }); |
| 46 | + |
| 47 | + // Verify the AggregateError comes last |
| 48 | + expect(eventData.exception?.values?.[3]).toMatchObject({ |
| 49 | + type: 'AggregateError', |
| 50 | + value: 'Multiple errors occurred', |
| 51 | + mechanism: { |
| 52 | + type: 'generic', |
| 53 | + handled: true, |
| 54 | + is_exception_group: true, |
| 55 | + exception_id: expect.any(Number), |
| 56 | + }, |
| 57 | + stacktrace: { |
| 58 | + frames: expect.any(Array), |
| 59 | + }, |
| 60 | + }); |
| 61 | + |
| 62 | + // Get parent exception ID for reference checks |
| 63 | + const parentId = eventData.exception?.values?.[3].mechanism?.exception_id; |
| 64 | + |
| 65 | + // Verify parent_id references match for all child errors |
| 66 | + for (let i = 0; i < 3; i++) { |
| 67 | + expect(eventData.exception?.values?.[i].mechanism?.parent_id).toBe(parentId); |
| 68 | + } |
| 69 | +}); |
0 commit comments