1
1
import { expect } from '@playwright/test' ;
2
+ import type * as Sentry from '@sentry/browser' ;
2
3
import type { EventEnvelopeHeaders } from '@sentry/types' ;
3
4
4
5
import { sentryTest } from '../../../utils/fixtures' ;
@@ -9,6 +10,8 @@ import {
9
10
} from '../../../utils/helpers' ;
10
11
import { getReplaySnapshot , shouldSkipReplayTest , waitForReplayRunning } from '../../../utils/replayHelpers' ;
11
12
13
+ type TestWindow = Window & { Sentry : typeof Sentry ; Replay : Sentry . Replay } ;
14
+
12
15
sentryTest ( 'should add replay_id to dsc of transactions' , async ( { getLocalTestPath, page, browserName } ) => {
13
16
// This is flaky on webkit, so skipping there...
14
17
if ( shouldSkipReplayTest ( ) || shouldSkipTracingTest ( ) || browserName === 'webkit' ) {
@@ -18,6 +21,13 @@ sentryTest('should add replay_id to dsc of transactions', async ({ getLocalTestP
18
21
const url = await getLocalTestPath ( { testDir : __dirname } ) ;
19
22
await page . goto ( url ) ;
20
23
24
+ await page . evaluate ( ( ) => {
25
+ ( window as unknown as TestWindow ) . Sentry . configureScope ( scope => {
26
+ scope . setUser ( { id : 'user123' , segment : 'segmentB' } ) ;
27
+ scope . setTransactionName ( 'testTransactionDSC' ) ;
28
+ } ) ;
29
+ } ) ;
30
+
21
31
const envHeader = await getFirstSentryEnvelopeRequest < EventEnvelopeHeaders > ( page , url , envelopeHeaderRequestParser ) ;
22
32
23
33
await waitForReplayRunning ( page ) ;
@@ -35,3 +45,41 @@ sentryTest('should add replay_id to dsc of transactions', async ({ getLocalTestP
35
45
replay_id : replay . session ?. id ,
36
46
} ) ;
37
47
} ) ;
48
+
49
+ sentryTest (
50
+ 'should not add replay_id to dsc of transactions if replay is not enabled' ,
51
+ async ( { getLocalTestPath, page, browserName } ) => {
52
+ // This is flaky on webkit, so skipping there...
53
+ if ( shouldSkipReplayTest ( ) || shouldSkipTracingTest ( ) || browserName === 'webkit' ) {
54
+ sentryTest . skip ( ) ;
55
+ }
56
+
57
+ const url = await getLocalTestPath ( { testDir : __dirname } ) ;
58
+ await page . goto ( url ) ;
59
+
60
+ await page . evaluate ( ( ) => {
61
+ ( window as unknown as TestWindow ) . Replay . stop ( ) ;
62
+
63
+ ( window as unknown as TestWindow ) . Sentry . configureScope ( scope => {
64
+ scope . setUser ( { id : 'user123' , segment : 'segmentB' } ) ;
65
+ scope . setTransactionName ( 'testTransactionDSC' ) ;
66
+ } ) ;
67
+ } ) ;
68
+
69
+ const envHeader = await getFirstSentryEnvelopeRequest < EventEnvelopeHeaders > ( page , url , envelopeHeaderRequestParser ) ;
70
+
71
+ await waitForReplayRunning ( page ) ;
72
+ const replay = await getReplaySnapshot ( page ) ;
73
+
74
+ expect ( replay . session ?. id ) . toBeDefined ( ) ;
75
+
76
+ expect ( envHeader . trace ) . toBeDefined ( ) ;
77
+ expect ( envHeader . trace ) . toEqual ( {
78
+ environment : 'production' ,
79
+ user_segment : 'segmentB' ,
80
+ sample_rate : '1' ,
81
+ trace_id : expect . any ( String ) ,
82
+ public_key : 'public' ,
83
+ } ) ;
84
+ } ,
85
+ ) ;
0 commit comments