Skip to content

Commit 92c506d

Browse files
committed
Add integration test for XHR interception.
1 parent 3bbc564 commit 92c506d

File tree

4 files changed

+76
-1
lines changed

4 files changed

+76
-1
lines changed

packages/integration-tests/suites/integrations/httpclient/fetch/test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { sentryTest } from '../../../../utils/fixtures';
55
import { getFirstSentryEnvelopeRequest } from '../../../../utils/helpers';
66

77
sentryTest(
8-
'should assign request and response context from a failed 500 request',
8+
'should assign request and response context from a failed 500 fetch request',
99
async ({ getLocalTestPath, page }) => {
1010
const url = await getLocalTestPath({ testDir: __dirname });
1111

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
const xhr = new XMLHttpRequest();
2+
3+
xhr.open('GET', 'http://localhost:7654/foo', true);
4+
xhr.withCredentials = true;
5+
xhr.setRequestHeader('Accept', 'application/json');
6+
xhr.setRequestHeader('Content-Type', 'application/json');
7+
xhr.setRequestHeader('Cache', 'no-cache');
8+
xhr.send();
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
import { expect } from '@playwright/test';
2+
import { Event } from '@sentry/types';
3+
4+
import { sentryTest } from '../../../../utils/fixtures';
5+
import { getFirstSentryEnvelopeRequest } from '../../../../utils/helpers';
6+
7+
sentryTest(
8+
'should assign request and response context from a failed 500 XHR request',
9+
async ({ getLocalTestPath, page }) => {
10+
const url = await getLocalTestPath({ testDir: __dirname });
11+
12+
await page.route('**/foo', route => {
13+
return route.fulfill({
14+
status: 500,
15+
body: JSON.stringify({
16+
error: {
17+
message: 'Internal Server Error',
18+
},
19+
}),
20+
headers: {
21+
'Content-Type': 'text/html',
22+
},
23+
});
24+
});
25+
26+
const eventData = await getFirstSentryEnvelopeRequest<Event>(page, url);
27+
28+
expect(eventData.exception?.values).toHaveLength(1);
29+
30+
// Not able to get the cookies from the request/response because of Playwright bug
31+
// https://github.com/microsoft/playwright/issues/11035
32+
expect(eventData).toMatchObject({
33+
message: 'HTTP Client Error with status code: 500',
34+
exception: {
35+
values: [
36+
{
37+
type: 'Error',
38+
value: 'HTTP Client Error with status code: 500',
39+
mechanism: {
40+
type: 'http.client',
41+
handled: true,
42+
},
43+
},
44+
],
45+
},
46+
request: {
47+
url: 'http://localhost:7654/foo',
48+
method: 'GET',
49+
headers: {
50+
Accept: 'application/json',
51+
Cache: 'no-cache',
52+
'Content-Type': 'application/json',
53+
},
54+
},
55+
contexts: {
56+
response: {
57+
status_code: 500,
58+
body_size: 45,
59+
headers: {
60+
'content-type': 'text/html',
61+
'content-length': '45',
62+
},
63+
},
64+
},
65+
});
66+
},
67+
);

0 commit comments

Comments
 (0)