Skip to content

Commit ef67fdc

Browse files
authored
test: Add browser integration test for AggregateErrors (#15723)
While trying to debug #15707 I added a new integration test. Figured we should merge this in for now.
1 parent e62f334 commit ef67fdc

File tree

2 files changed

+82
-0
lines changed
  • dev-packages/browser-integration-tests/suites/public-api/captureException/aggregateError

2 files changed

+82
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
try {
2+
// Create an AggregateError with multiple error objects
3+
const error1 = new Error('First error message');
4+
const error2 = new TypeError('Second error message');
5+
const error3 = new RangeError('Third error message');
6+
7+
// Create the AggregateError with these errors and a message
8+
const aggregateError = new AggregateError([error1, error2, error3], 'Multiple errors occurred');
9+
10+
throw aggregateError;
11+
} catch (err) {
12+
Sentry.captureException(err);
13+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
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

Comments
 (0)