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