@@ -9,29 +9,28 @@ sentryTest('should capture a LCP vital with element details.', async ({ browserN
9
9
if ( shouldSkipTracingTest ( ) || browserName !== 'chromium' ) {
10
10
sentryTest . skip ( ) ;
11
11
}
12
- const imageSrc = 'https://example.com/path/to/image.png' ;
13
- const imageResponsePromise = page . waitForResponse ( imageSrc ) ;
14
12
page . route ( '**' , route => route . continue ( ) ) ;
15
13
page . route ( '**/path/to/image.png' , async ( route : Route ) => {
16
14
return route . fulfill ( { path : `${ __dirname } /assets/sentry-logo-600x179.png` } ) ;
17
15
} ) ;
18
16
19
17
const url = await getLocalTestPath ( { testDir : __dirname } ) ;
20
- const [ eventData , imageResponse ] = await Promise . all ( [
18
+ const [ eventData ] = await Promise . all ( [
21
19
getFirstSentryEnvelopeRequest < Event > ( page ) ,
22
20
page . goto ( url ) ,
23
- imageResponsePromise ,
21
+ // Clicking the button before image loads will result in the button being the LCP
22
+ page . waitForFunction ( ( ) => {
23
+ const images = Array . from ( document . querySelectorAll ( 'img' ) ) ;
24
+ return images . every ( img => img . complete ) ;
25
+ } ) ,
24
26
] ) ;
25
27
26
- await imageResponse ?. finished ( ) ;
27
-
28
- // Clicking the button before image loads will result in the button being the LCP
29
28
await page . locator ( 'button' ) . click ( ) ;
30
29
31
30
expect ( eventData . measurements ) . toBeDefined ( ) ;
32
31
expect ( eventData . measurements ?. lcp ?. value ) . toBeDefined ( ) ;
33
32
34
33
expect ( eventData . contexts ?. trace ?. data ?. [ 'lcp.element' ] ) . toBe ( 'body > img' ) ;
35
34
expect ( eventData . contexts ?. trace ?. data ?. [ 'lcp.size' ] ) . toBe ( 107400 ) ;
36
- expect ( eventData . contexts ?. trace ?. data ?. [ 'lcp.url' ] ) . toBe ( imageSrc ) ;
35
+ expect ( eventData . contexts ?. trace ?. data ?. [ 'lcp.url' ] ) . toBe ( 'https://example.com/path/to/image.png' ) ;
37
36
} ) ;
0 commit comments