11import { expect } from '@playwright/test' ;
22import type { Event } from '@sentry/types' ;
33import { sentryTest } from '../../../../utils/fixtures' ;
4- import { getFirstSentryEnvelopeRequest , shouldSkipTracingTest } from '../../../../utils/helpers' ;
4+ import {
5+ getFirstSentryEnvelopeRequest ,
6+ getMultipleSentryEnvelopeRequests ,
7+ shouldSkipTracingTest ,
8+ } from '../../../../utils/helpers' ;
59
6- sentryTest ( 'should create a new trace on each navigation' , async ( { getLocalTestPath, page } ) => {
10+ sentryTest ( 'creates a new trace on each navigation' , async ( { getLocalTestPath, page } ) => {
711 if ( shouldSkipTracingTest ( ) ) {
812 sentryTest . skip ( ) ;
913 }
@@ -32,13 +36,13 @@ sentryTest('error after navigation has navigation traceId', async ({ getLocalTes
3236
3337 const url = await getLocalTestPath ( { testDir : __dirname } ) ;
3438
35- // ensure navigation transaction is finished
39+ // ensure pageload transaction is finished
3640 await getFirstSentryEnvelopeRequest < Event > ( page , url ) ;
3741
38- const navigationEvent1 = await getFirstSentryEnvelopeRequest < Event > ( page , `${ url } #foo` ) ;
39- expect ( navigationEvent1 . contexts ?. trace ?. op ) . toBe ( 'navigation' ) ;
42+ const navigationEvent = await getFirstSentryEnvelopeRequest < Event > ( page , `${ url } #foo` ) ;
43+ expect ( navigationEvent . contexts ?. trace ?. op ) . toBe ( 'navigation' ) ;
4044
41- const navigationTraceId = navigationEvent1 . contexts ?. trace ?. trace_id ;
45+ const navigationTraceId = navigationEvent . contexts ?. trace ?. trace_id ;
4246 expect ( navigationTraceId ) . toMatch ( / ^ [ 0 - 9 a - f ] { 32 } $ / ) ;
4347
4448 const [ , errorEvent ] = await Promise . all ( [
@@ -49,3 +53,30 @@ sentryTest('error after navigation has navigation traceId', async ({ getLocalTes
4953 const errorTraceId = errorEvent . contexts ?. trace ?. trace_id ;
5054 expect ( errorTraceId ) . toBe ( navigationTraceId ) ;
5155} ) ;
56+
57+ sentryTest ( 'error during navigation has new navigation traceId' , async ( { getLocalTestPath, page } ) => {
58+ if ( shouldSkipTracingTest ( ) ) {
59+ sentryTest . skip ( ) ;
60+ }
61+
62+ const url = await getLocalTestPath ( { testDir : __dirname } ) ;
63+
64+ // ensure navigation transaction is finished
65+ await getFirstSentryEnvelopeRequest < Event > ( page , url ) ;
66+
67+ const envelopeRequestsPromise = getMultipleSentryEnvelopeRequests < Event > ( page , 2 ) ;
68+ await page . goto ( `${ url } #foo` ) ;
69+ await page . locator ( '#errorBtn' ) . click ( ) ;
70+ const events = await envelopeRequestsPromise ;
71+
72+ const navigationEvent = events . find ( event => event . type === 'transaction' ) ;
73+ const errorEvent = events . find ( event => ! event . type ) ;
74+
75+ expect ( navigationEvent ?. contexts ?. trace ?. op ) . toBe ( 'navigation' ) ;
76+
77+ const navigationTraceId = navigationEvent ?. contexts ?. trace ?. trace_id ;
78+ expect ( navigationTraceId ) . toMatch ( / ^ [ 0 - 9 a - f ] { 32 } $ / ) ;
79+
80+ const errorTraceId = errorEvent ?. contexts ?. trace ?. trace_id ;
81+ expect ( errorTraceId ) . toBe ( navigationTraceId ) ;
82+ } ) ;
0 commit comments