Skip to content

Commit 431f3b2

Browse files
authored
test(core): Add integration test for captureUserFeedback on captureException and captureMessage (#10239)
1 parent 4840408 commit 431f3b2

File tree

6 files changed

+80
-0
lines changed

6 files changed

+80
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import * as Sentry from '@sentry/browser';
2+
3+
window.Sentry = Sentry;
4+
5+
Sentry.init({
6+
dsn: 'https://[email protected]/1337',
7+
beforeSend(event) {
8+
Sentry.captureUserFeedback({
9+
event_id: event.event_id,
10+
name: 'John Doe',
11+
12+
comments: 'This feedback should be attached associated with the captured error',
13+
});
14+
return event;
15+
},
16+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Sentry.captureException(new Error('Error with Feedback'));
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import { expect } from '@playwright/test';
2+
import type { Event, UserFeedback } from '@sentry/types';
3+
4+
import { sentryTest } from '../../../../utils/fixtures';
5+
import { getMultipleSentryEnvelopeRequests } from '../../../../utils/helpers';
6+
7+
sentryTest('capture user feedback when captureException is called', async ({ getLocalTestPath, page }) => {
8+
const url = await getLocalTestPath({ testDir: __dirname });
9+
10+
const data = (await getMultipleSentryEnvelopeRequests(page, 2, { url })) as (Event | UserFeedback)[];
11+
12+
expect(data).toHaveLength(2);
13+
14+
const errorEvent = ('exception' in data[0] ? data[0] : data[1]) as Event;
15+
const feedback = ('exception' in data[0] ? data[1] : data[0]) as UserFeedback;
16+
17+
expect(feedback).toEqual({
18+
comments: 'This feedback should be attached associated with the captured error',
19+
20+
event_id: errorEvent.event_id,
21+
name: 'John Doe',
22+
});
23+
});
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import * as Sentry from '@sentry/browser';
2+
3+
window.Sentry = Sentry;
4+
5+
Sentry.init({
6+
dsn: 'https://[email protected]/1337',
7+
beforeSend(event) {
8+
Sentry.captureUserFeedback({
9+
event_id: event.event_id,
10+
name: 'John Doe',
11+
12+
comments: 'This feedback should be attached associated with the captured message',
13+
});
14+
return event;
15+
},
16+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Sentry.captureMessage('Message with Feedback');
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import { expect } from '@playwright/test';
2+
import type { Event, UserFeedback } from '@sentry/types';
3+
4+
import { sentryTest } from '../../../../utils/fixtures';
5+
import { getMultipleSentryEnvelopeRequests } from '../../../../utils/helpers';
6+
7+
sentryTest('capture user feedback when captureMessage is called', async ({ getLocalTestPath, page }) => {
8+
const url = await getLocalTestPath({ testDir: __dirname });
9+
10+
const data = (await getMultipleSentryEnvelopeRequests(page, 2, { url })) as (Event | UserFeedback)[];
11+
12+
expect(data).toHaveLength(2);
13+
14+
const errorEvent = ('exception' in data[0] ? data[0] : data[1]) as Event;
15+
const feedback = ('exception' in data[0] ? data[1] : data[0]) as UserFeedback;
16+
17+
expect(feedback).toEqual({
18+
comments: 'This feedback should be attached associated with the captured message',
19+
20+
event_id: errorEvent.event_id,
21+
name: 'John Doe',
22+
});
23+
});

0 commit comments

Comments
 (0)