1
1
import { expect } from '@playwright/test' ;
2
2
import type { Event } from '@sentry/types' ;
3
3
import { sentryTest } from '../../../../utils/fixtures' ;
4
- import { getFirstSentryEnvelopeRequest , shouldSkipTracingTest } from '../../../../utils/helpers' ;
4
+ import {
5
+ getFirstSentryEnvelopeRequest ,
6
+ getMultipleSentryEnvelopeRequests ,
7
+ shouldSkipTracingTest ,
8
+ } from '../../../../utils/helpers' ;
5
9
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 } ) => {
7
11
if ( shouldSkipTracingTest ( ) ) {
8
12
sentryTest . skip ( ) ;
9
13
}
@@ -32,13 +36,13 @@ sentryTest('error after navigation has navigation traceId', async ({ getLocalTes
32
36
33
37
const url = await getLocalTestPath ( { testDir : __dirname } ) ;
34
38
35
- // ensure navigation transaction is finished
39
+ // ensure pageload transaction is finished
36
40
await getFirstSentryEnvelopeRequest < Event > ( page , url ) ;
37
41
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' ) ;
40
44
41
- const navigationTraceId = navigationEvent1 . contexts ?. trace ?. trace_id ;
45
+ const navigationTraceId = navigationEvent . contexts ?. trace ?. trace_id ;
42
46
expect ( navigationTraceId ) . toMatch ( / ^ [ 0 - 9 a - f ] { 32 } $ / ) ;
43
47
44
48
const [ , errorEvent ] = await Promise . all ( [
@@ -49,3 +53,30 @@ sentryTest('error after navigation has navigation traceId', async ({ getLocalTes
49
53
const errorTraceId = errorEvent . contexts ?. trace ?. trace_id ;
50
54
expect ( errorTraceId ) . toBe ( navigationTraceId ) ;
51
55
} ) ;
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