-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(browser): Add integration test for
httpContextIntegration
- Loading branch information
Showing
3 changed files
with
47 additions
and
0 deletions.
There are no files selected for viewing
20 changes: 20 additions & 0 deletions
20
dev-packages/browser-integration-tests/suites/integrations/httpContext/init.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import * as Sentry from '@sentry/browser'; | ||
|
||
window.Sentry = Sentry; | ||
|
||
const integrations = Sentry.getDefaultIntegrations({}).filter( | ||
defaultIntegration => defaultIntegration.name === 'HttpContext', | ||
); | ||
|
||
const client = new Sentry.BrowserClient({ | ||
dsn: 'https://[email protected]/1337', | ||
transport: Sentry.makeFetchTransport, | ||
stackParser: Sentry.defaultStackParser, | ||
integrations: integrations, | ||
}); | ||
|
||
const scope = new Sentry.Scope(); | ||
scope.setClient(client); | ||
client.init(); | ||
|
||
window._sentryScope = scope; |
1 change: 1 addition & 0 deletions
1
dev-packages/browser-integration-tests/suites/integrations/httpContext/subject.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
window._sentryScope.captureException(new Error('client init')); |
26 changes: 26 additions & 0 deletions
26
dev-packages/browser-integration-tests/suites/integrations/httpContext/test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { expect } from '@playwright/test'; | ||
import type { Event } from '@sentry/types'; | ||
|
||
import { sentryTest } from '../../../utils/fixtures'; | ||
import { getFirstSentryEnvelopeRequest } from '../../../utils/helpers'; | ||
|
||
sentryTest('httpContextIntegration captures user-agent and referrer', async ({ getLocalTestPath, page }) => { | ||
const url = await getLocalTestPath({ testDir: __dirname }); | ||
|
||
const errorEventPromise = getFirstSentryEnvelopeRequest<Event>(page); | ||
|
||
// Simulate document.referrer being set to test full functionality of the integration | ||
await page.goto(url, { referer: 'https://sentry.io/' }); | ||
|
||
const errorEvent = await errorEventPromise; | ||
|
||
expect(errorEvent.exception?.values).toHaveLength(1); | ||
|
||
expect(errorEvent.request).toEqual({ | ||
headers: { | ||
'User-Agent': expect.any(String), | ||
Referer: 'https://sentry.io/', | ||
}, | ||
url: expect.any(String), | ||
}); | ||
}); |