1
1
import type { Route } from '@playwright/test' ;
2
2
import { expect } from '@playwright/test' ;
3
- import type { Event , Span , SpanContext , Transaction } from '@sentry/types' ;
3
+ import type { Event as SentryEvent , Measurements , Span , SpanContext , SpanJSON , Transaction } from '@sentry/types' ;
4
4
5
5
import { sentryTest } from '../../../../utils/fixtures' ;
6
6
import {
@@ -30,7 +30,7 @@ sentryTest('should capture interaction transaction. @firefox', async ({ browserN
30
30
const url = await getLocalTestPath ( { testDir : __dirname } ) ;
31
31
32
32
await page . goto ( url ) ;
33
- await getFirstSentryEnvelopeRequest < Event > ( page ) ;
33
+ await getFirstSentryEnvelopeRequest < SentryEvent > ( page ) ;
34
34
35
35
await page . locator ( '[data-test-id=interaction-button]' ) . click ( ) ;
36
36
await page . locator ( '.clicked[data-test-id=interaction-button]' ) . isVisible ( ) ;
@@ -70,12 +70,12 @@ sentryTest(
70
70
71
71
const url = await getLocalTestPath ( { testDir : __dirname } ) ;
72
72
await page . goto ( url ) ;
73
- await getFirstSentryEnvelopeRequest < Event > ( page ) ;
73
+ await getFirstSentryEnvelopeRequest < SentryEvent > ( page ) ;
74
74
75
75
for ( let i = 0 ; i < 4 ; i ++ ) {
76
76
await wait ( 100 ) ;
77
77
await page . locator ( '[data-test-id=interaction-button]' ) . click ( ) ;
78
- const envelope = await getMultipleSentryEnvelopeRequests < Event > ( page , 1 ) ;
78
+ const envelope = await getMultipleSentryEnvelopeRequests < SentryEvent > ( page , 1 ) ;
79
79
expect ( envelope [ 0 ] . spans ) . toHaveLength ( 1 ) ;
80
80
}
81
81
} ,
@@ -97,7 +97,7 @@ sentryTest(
97
97
const url = await getLocalTestPath ( { testDir : __dirname } ) ;
98
98
99
99
await page . goto ( url ) ;
100
- await getFirstSentryEnvelopeRequest < Event > ( page ) ;
100
+ await getFirstSentryEnvelopeRequest < SentryEvent > ( page ) ;
101
101
102
102
await page . locator ( '[data-test-id=annotated-button]' ) . click ( ) ;
103
103
@@ -112,3 +112,51 @@ sentryTest(
112
112
expect ( interactionSpan . description ) . toBe ( 'body > AnnotatedButton' ) ;
113
113
} ,
114
114
) ;
115
+
116
+ sentryTest ( 'should capture an INP click event span. @firefox' , async ( { browserName, getLocalTestPath, page } ) => {
117
+ const supportedBrowsers = [ 'chromium' , 'firefox' ] ;
118
+
119
+ if ( shouldSkipTracingTest ( ) || ! supportedBrowsers . includes ( browserName ) ) {
120
+ sentryTest . skip ( ) ;
121
+ }
122
+
123
+ await page . route ( '**/path/to/script.js' , ( route : Route ) => route . fulfill ( { path : `${ __dirname } /assets/script.js` } ) ) ;
124
+ await page . route ( 'https://dsn.ingest.sentry.io/**/*' , route => {
125
+ return route . fulfill ( {
126
+ status : 200 ,
127
+ contentType : 'application/json' ,
128
+ body : JSON . stringify ( { id : 'test-id' } ) ,
129
+ } ) ;
130
+ } ) ;
131
+
132
+ const url = await getLocalTestPath ( { testDir : __dirname } ) ;
133
+
134
+ await page . goto ( url ) ;
135
+ await getFirstSentryEnvelopeRequest < SentryEvent > ( page ) ;
136
+
137
+ await page . locator ( '[data-test-id=interaction-button]' ) . click ( ) ;
138
+ await page . locator ( '.clicked[data-test-id=interaction-button]' ) . isVisible ( ) ;
139
+
140
+ // Wait for the interaction transaction from the enableInteractions experiment
141
+ await getMultipleSentryEnvelopeRequests < TransactionJSON > ( page , 1 ) ;
142
+
143
+ const spanEnvelopesPromise = getMultipleSentryEnvelopeRequests <
144
+ SpanJSON & { exclusive_time : number ; measurements : Measurements }
145
+ > ( page , 1 , {
146
+ envelopeType : 'span' ,
147
+ } ) ;
148
+ // Page hide to trigger INP
149
+ await page . evaluate ( ( ) => {
150
+ window . dispatchEvent ( new Event ( 'pagehide' ) ) ;
151
+ } ) ;
152
+
153
+ // Get the INP span envelope
154
+ const spanEnvelopes = await spanEnvelopesPromise ;
155
+
156
+ expect ( spanEnvelopes ) . toHaveLength ( 1 ) ;
157
+ expect ( spanEnvelopes [ 0 ] . op ) . toBe ( 'ui.interaction.click' ) ;
158
+ expect ( spanEnvelopes [ 0 ] . description ) . toBe ( 'body > button.clicked' ) ;
159
+ expect ( spanEnvelopes [ 0 ] . exclusive_time ) . toBeGreaterThan ( 0 ) ;
160
+ expect ( spanEnvelopes [ 0 ] . measurements . inp . value ) . toBeGreaterThan ( 0 ) ;
161
+ expect ( spanEnvelopes [ 0 ] . measurements . inp . unit ) . toBe ( 'millisecond' ) ;
162
+ } ) ;
0 commit comments