File tree Expand file tree Collapse file tree 3 files changed +47
-0
lines changed
dev-packages/browser-integration-tests/suites/integrations/httpContext Expand file tree Collapse file tree 3 files changed +47
-0
lines changed Original file line number Diff line number Diff line change
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 ;
Original file line number Diff line number Diff line change
1
+ window . _sentryScope . captureException ( new Error ( 'client init' ) ) ;
Original file line number Diff line number Diff line change
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
+ } ) ;
You can’t perform that action at this time.
0 commit comments