File tree Expand file tree Collapse file tree 8 files changed +95
-0
lines changed
packages/integration-tests/suites/public-api/setContext Expand file tree Collapse file tree 8 files changed +95
-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
+ Sentry . init ( {
6
+ dsn :
'https://[email protected] /1337' ,
7
+ } ) ;
Original file line number Diff line number Diff line change
1
+ Sentry . setContext ( 'context_1' , {
2
+ foo : 'bar' ,
3
+ baz : {
4
+ qux : 'quux' ,
5
+ } ,
6
+ } ) ;
7
+
8
+ Sentry . setContext ( 'context_2' , {
9
+ 1 : 'foo' ,
10
+ bar : false ,
11
+ } ) ;
12
+
13
+ Sentry . setContext ( 'context_3' , null ) ;
14
+ Sentry . setContext ( 'context_4' ) ;
15
+ Sentry . setContext ( 'context_5' , NaN ) ;
16
+ Sentry . setContext ( 'context_6' , Math . PI ) ;
17
+
18
+ Sentry . captureMessage ( 'multiple_contexts' ) ;
Original file line number Diff line number Diff line change
1
+ import { expect } from '@playwright/test' ;
2
+
3
+ import { sentryTest } from '../../../../utils/fixtures' ;
4
+ import { getSentryRequest } from '../../../../utils/helpers' ;
5
+
6
+ sentryTest ( 'should record multiple contexts' , async ( { getLocalTestPath, page } ) => {
7
+ const url = await getLocalTestPath ( { testDir : __dirname } ) ;
8
+
9
+ const eventData = await getSentryRequest ( page , url ) ;
10
+
11
+ expect ( eventData . message ) . toBe ( 'multiple_contexts' ) ;
12
+ expect ( eventData . contexts ) . toMatchObject ( {
13
+ context_1 : {
14
+ foo : 'bar' ,
15
+ baz : { qux : 'quux' } ,
16
+ } ,
17
+ context_2 : { 1 : 'foo' , bar : false } ,
18
+ context_4 : '[undefined]' ,
19
+ context_5 : '[NaN]' ,
20
+ context_6 : 3.141592653589793 ,
21
+ } ) ;
22
+ } ) ;
Original file line number Diff line number Diff line change
1
+ const el = document . querySelector ( 'body' ) ;
2
+
3
+ Sentry . setContext ( 'non_serializable' , el ) ;
4
+
5
+ Sentry . captureMessage ( 'non_serializable' ) ;
Original file line number Diff line number Diff line change
1
+ import { expect } from '@playwright/test' ;
2
+
3
+ import { sentryTest } from '../../../../utils/fixtures' ;
4
+ import { getSentryRequest } from '../../../../utils/helpers' ;
5
+
6
+ sentryTest ( 'should normalize non-serializable context' , async ( { getLocalTestPath, page } ) => {
7
+ const url = await getLocalTestPath ( { testDir : __dirname } ) ;
8
+
9
+ const eventData = await getSentryRequest ( page , url ) ;
10
+
11
+ expect ( eventData . contexts ?. non_serializable ) . toMatchObject ( { } ) ;
12
+ expect ( eventData . message ) . toBe ( 'non_serializable' ) ;
13
+ } ) ;
Original file line number Diff line number Diff line change
1
+ Sentry . setContext ( 'foo' , { bar : 'baz' } ) ;
2
+ Sentry . captureMessage ( 'simple_context_object' ) ;
Original file line number Diff line number Diff line change
1
+ import { expect } from '@playwright/test' ;
2
+
3
+ import { sentryTest } from '../../../../utils/fixtures' ;
4
+ import { getSentryRequest } from '../../../../utils/helpers' ;
5
+
6
+ sentryTest ( 'should set a simple context' , async ( { getLocalTestPath, page } ) => {
7
+ const url = await getLocalTestPath ( { testDir : __dirname } ) ;
8
+
9
+ const eventData = await getSentryRequest ( page , url ) ;
10
+
11
+ expect ( eventData . message ) . toBe ( 'simple_context_object' ) ;
12
+ expect ( eventData . contexts ) . toMatchObject ( {
13
+ foo : {
14
+ bar : 'baz' ,
15
+ } ,
16
+ } ) ;
17
+ } ) ;
Original file line number Diff line number Diff line change
1
+ <!DOCTYPE html>
2
+ <html >
3
+ <head >
4
+ <meta charset =" utf-8" />
5
+ <title ></title >
6
+ <script src =" {{ htmlWebpackPlugin.options.initialization }} " ></script >
7
+ </head >
8
+ <body >
9
+ <script src =" {{ htmlWebpackPlugin.options.subject }} " ></script >
10
+ </body >
11
+ </html >
You can’t perform that action at this time.
0 commit comments