@@ -7,7 +7,12 @@ import {
77 SEMANTIC_ATTRIBUTE_SENTRY_SOURCE ,
88} from '@sentry/core' ;
99import { sentryTest } from '../../../../utils/fixtures' ;
10- import { getFirstSentryEnvelopeRequest , shouldSkipTracingTest } from '../../../../utils/helpers' ;
10+ import {
11+ envelopeRequestParser ,
12+ getFirstSentryEnvelopeRequest ,
13+ shouldSkipTracingTest ,
14+ waitForTransactionRequest ,
15+ } from '../../../../utils/helpers' ;
1116
1217sentryTest ( 'should create a navigation transaction on page navigation' , async ( { getLocalTestUrl, page } ) => {
1318 if ( shouldSkipTracingTest ( ) ) {
@@ -85,3 +90,65 @@ sentryTest('should create a navigation transaction on page navigation', async ({
8590
8691 expect ( pageloadSpanId ) . not . toEqual ( navigationSpanId ) ;
8792} ) ;
93+
94+ //
95+ sentryTest ( 'should handle pushState with full URL' , async ( { getLocalTestUrl, page } ) => {
96+ if ( shouldSkipTracingTest ( ) ) {
97+ sentryTest . skip ( ) ;
98+ }
99+
100+ const url = await getLocalTestUrl ( { testDir : __dirname } ) ;
101+
102+ const pageloadRequestPromise = waitForTransactionRequest ( page , event => event . contexts ?. trace ?. op === 'pageload' ) ;
103+ const navigationRequestPromise = waitForTransactionRequest (
104+ page ,
105+ event => event . contexts ?. trace ?. op === 'navigation' && event . transaction === '/sub-page' ,
106+ ) ;
107+ const navigationRequestPromise2 = waitForTransactionRequest (
108+ page ,
109+ event => event . contexts ?. trace ?. op === 'navigation' && event . transaction === '/sub-page-2' ,
110+ ) ;
111+
112+ await page . goto ( url ) ;
113+ await pageloadRequestPromise ;
114+
115+ await page . evaluate ( "window.history.pushState({}, '', `${window.location.origin}/sub-page`);" ) ;
116+
117+ const navigationRequest = envelopeRequestParser ( await navigationRequestPromise ) ;
118+
119+ expect ( navigationRequest . transaction ) . toEqual ( '/sub-page' ) ;
120+
121+ expect ( navigationRequest . contexts ?. trace ?. data ) . toMatchObject ( {
122+ [ SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN ] : 'auto.navigation.browser' ,
123+ [ SEMANTIC_ATTRIBUTE_SENTRY_SAMPLE_RATE ] : 1 ,
124+ [ SEMANTIC_ATTRIBUTE_SENTRY_SOURCE ] : 'url' ,
125+ [ SEMANTIC_ATTRIBUTE_SENTRY_OP ] : 'navigation' ,
126+ [ 'sentry.idle_span_finish_reason' ] : 'idleTimeout' ,
127+ } ) ;
128+ expect ( navigationRequest . request ) . toEqual ( {
129+ headers : {
130+ 'User-Agent' : expect . any ( String ) ,
131+ } ,
132+ url : 'http://sentry-test.io/sub-page' ,
133+ } ) ;
134+
135+ await page . evaluate ( "window.history.pushState({}, '', `${window.location.origin}/sub-page-2`);" ) ;
136+
137+ const navigationRequest2 = envelopeRequestParser ( await navigationRequestPromise2 ) ;
138+
139+ expect ( navigationRequest2 . transaction ) . toEqual ( '/sub-page-2' ) ;
140+
141+ expect ( navigationRequest2 . contexts ?. trace ?. data ) . toMatchObject ( {
142+ [ SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN ] : 'auto.navigation.browser' ,
143+ [ SEMANTIC_ATTRIBUTE_SENTRY_SAMPLE_RATE ] : 1 ,
144+ [ SEMANTIC_ATTRIBUTE_SENTRY_SOURCE ] : 'url' ,
145+ [ SEMANTIC_ATTRIBUTE_SENTRY_OP ] : 'navigation' ,
146+ [ 'sentry.idle_span_finish_reason' ] : 'idleTimeout' ,
147+ } ) ;
148+ expect ( navigationRequest2 . request ) . toEqual ( {
149+ headers : {
150+ 'User-Agent' : expect . any ( String ) ,
151+ } ,
152+ url : 'http://sentry-test.io/sub-page-2' ,
153+ } ) ;
154+ } ) ;
0 commit comments