Skip to content

Commit 128ab44

Browse files
authored
test(browser): Add integration test for httpContextIntegration (#13553)
Add a test to our browser integration tests where we explicitly check that httpContextIntegration sets all its supported properties: url, user-agent and (previously untested) referer.
1 parent 9b8f9ea commit 128ab44

File tree

3 files changed

+47
-0
lines changed

3 files changed

+47
-0
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import * as Sentry from '@sentry/browser';
2+
3+
window.Sentry = Sentry;
4+
5+
const integrations = Sentry.getDefaultIntegrations({}).filter(
6+
defaultIntegration => defaultIntegration.name === 'HttpContext',
7+
);
8+
9+
const client = new Sentry.BrowserClient({
10+
dsn: 'https://[email protected]/1337',
11+
transport: Sentry.makeFetchTransport,
12+
stackParser: Sentry.defaultStackParser,
13+
integrations: integrations,
14+
});
15+
16+
const scope = new Sentry.Scope();
17+
scope.setClient(client);
18+
client.init();
19+
20+
window._sentryScope = scope;
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
window._sentryScope.captureException(new Error('client init'));
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import { expect } from '@playwright/test';
2+
import type { Event } from '@sentry/types';
3+
4+
import { sentryTest } from '../../../utils/fixtures';
5+
import { getFirstSentryEnvelopeRequest } from '../../../utils/helpers';
6+
7+
sentryTest('httpContextIntegration captures user-agent and referrer', async ({ getLocalTestPath, page }) => {
8+
const url = await getLocalTestPath({ testDir: __dirname });
9+
10+
const errorEventPromise = getFirstSentryEnvelopeRequest<Event>(page);
11+
12+
// Simulate document.referrer being set to test full functionality of the integration
13+
await page.goto(url, { referer: 'https://sentry.io/' });
14+
15+
const errorEvent = await errorEventPromise;
16+
17+
expect(errorEvent.exception?.values).toHaveLength(1);
18+
19+
expect(errorEvent.request).toEqual({
20+
headers: {
21+
'User-Agent': expect.any(String),
22+
Referer: 'https://sentry.io/',
23+
},
24+
url: expect.any(String),
25+
});
26+
});

0 commit comments

Comments
 (0)