99 spanToJSON ,
1010} from '@sentry/core' ;
1111import type { Span } from '@sentry/core' ;
12- import type { ResourceEntry } from '../../src/metrics/browserMetrics' ;
1312import { _addMeasureSpans , _addResourceSpans } from '../../src/metrics/browserMetrics' ;
1413import { WINDOW } from '../../src/types' ;
1514import { TestClient , getDefaultClientOptions } from '../utils/TestClient' ;
@@ -31,6 +30,17 @@ const originalLocation = WINDOW.location;
3130
3231const resourceEntryName = 'https://example.com/assets/to/css' ;
3332
33+ interface AdditionalPerformanceResourceTiming {
34+ renderBlockingStatus ?: 'non-blocking' | 'blocking' | '' ;
35+ deliveryType ?: 'cache' | 'navigational-prefetch' | '' ;
36+ }
37+
38+ function mockPerformanceResourceTiming (
39+ data : Partial < PerformanceResourceTiming > & AdditionalPerformanceResourceTiming ,
40+ ) : PerformanceResourceTiming & AdditionalPerformanceResourceTiming {
41+ return data as PerformanceResourceTiming & AdditionalPerformanceResourceTiming ;
42+ }
43+
3444describe ( '_addMeasureSpans' , ( ) => {
3545 const span = new SentrySpan ( { op : 'pageload' , name : '/' , sampled : true } ) ;
3646
@@ -54,13 +64,12 @@ describe('_addMeasureSpans', () => {
5464 spans . push ( span ) ;
5565 } ) ;
5666
57- const entry : Omit < PerformanceMeasure , 'toJSON' > = {
67+ const entry = {
5868 entryType : 'measure' ,
5969 name : 'measure-1' ,
6070 duration : 10 ,
6171 startTime : 12 ,
62- detail : undefined ,
63- } ;
72+ } as PerformanceEntry ;
6473
6574 const timeOrigin = 100 ;
6675 const startTime = 23 ;
@@ -116,13 +125,13 @@ describe('_addResourceSpans', () => {
116125 spans . push ( span ) ;
117126 } ) ;
118127
119- const entry : ResourceEntry = {
128+ const entry = mockPerformanceResourceTiming ( {
120129 initiatorType : 'xmlhttprequest' ,
121130 transferSize : 256 ,
122131 encodedBodySize : 256 ,
123132 decodedBodySize : 256 ,
124133 renderBlockingStatus : 'non-blocking' ,
125- } ;
134+ } ) ;
126135 _addResourceSpans ( span , entry , resourceEntryName , 123 , 456 , 100 ) ;
127136
128137 expect ( spans ) . toHaveLength ( 0 ) ;
@@ -135,13 +144,13 @@ describe('_addResourceSpans', () => {
135144 spans . push ( span ) ;
136145 } ) ;
137146
138- const entry : ResourceEntry = {
147+ const entry = mockPerformanceResourceTiming ( {
139148 initiatorType : 'fetch' ,
140149 transferSize : 256 ,
141150 encodedBodySize : 256 ,
142151 decodedBodySize : 256 ,
143152 renderBlockingStatus : 'non-blocking' ,
144- } ;
153+ } ) ;
145154 _addResourceSpans ( span , entry , 'https://example.com/assets/to/me' , 123 , 456 , 100 ) ;
146155
147156 expect ( spans ) . toHaveLength ( 0 ) ;
@@ -154,13 +163,13 @@ describe('_addResourceSpans', () => {
154163 spans . push ( span ) ;
155164 } ) ;
156165
157- const entry : ResourceEntry = {
166+ const entry = mockPerformanceResourceTiming ( {
158167 initiatorType : 'css' ,
159168 transferSize : 256 ,
160169 encodedBodySize : 456 ,
161170 decodedBodySize : 593 ,
162171 renderBlockingStatus : 'non-blocking' ,
163- } ;
172+ } ) ;
164173
165174 const timeOrigin = 100 ;
166175 const startTime = 23 ;
@@ -222,9 +231,9 @@ describe('_addResourceSpans', () => {
222231 ] ;
223232 for ( let i = 0 ; i < table . length ; i ++ ) {
224233 const { initiatorType, op } = table [ i ] ! ;
225- const entry : ResourceEntry = {
234+ const entry = mockPerformanceResourceTiming ( {
226235 initiatorType,
227- } ;
236+ } ) ;
228237 _addResourceSpans ( span , entry , 'https://example.com/assets/to/me' , 123 , 234 , 465 ) ;
229238
230239 expect ( spans ) . toHaveLength ( i + 1 ) ;
@@ -239,13 +248,13 @@ describe('_addResourceSpans', () => {
239248 spans . push ( span ) ;
240249 } ) ;
241250
242- const entry : ResourceEntry = {
251+ const entry = mockPerformanceResourceTiming ( {
243252 initiatorType : 'css' ,
244253 transferSize : 0 ,
245254 encodedBodySize : 0 ,
246255 decodedBodySize : 0 ,
247256 renderBlockingStatus : 'non-blocking' ,
248- } ;
257+ } ) ;
249258
250259 _addResourceSpans ( span , entry , resourceEntryName , 100 , 23 , 345 ) ;
251260
@@ -274,12 +283,12 @@ describe('_addResourceSpans', () => {
274283 spans . push ( span ) ;
275284 } ) ;
276285
277- const entry : ResourceEntry = {
286+ const entry = mockPerformanceResourceTiming ( {
278287 initiatorType : 'css' ,
279288 transferSize : 2147483647 ,
280289 encodedBodySize : 2147483647 ,
281290 decodedBodySize : 2147483647 ,
282- } ;
291+ } ) ;
283292
284293 _addResourceSpans ( span , entry , resourceEntryName , 100 , 23 , 345 ) ;
285294
@@ -316,7 +325,7 @@ describe('_addResourceSpans', () => {
316325 transferSize : null ,
317326 encodedBodySize : null ,
318327 decodedBodySize : null ,
319- } as unknown as ResourceEntry ;
328+ } as unknown as PerformanceResourceTiming ;
320329
321330 _addResourceSpans ( span , entry , resourceEntryName , 100 , 23 , 345 ) ;
322331
@@ -341,7 +350,7 @@ describe('_addResourceSpans', () => {
341350
342351 // resource delivery types: https://developer.mozilla.org/en-US/docs/Web/API/PerformanceResourceTiming/deliveryType
343352 // i.e. better but not yet widely supported way to check for browser cache hit
344- it . each ( [ 'cache' , 'navigational-prefetch' , '' ] ) (
353+ it . each ( [ 'cache' , 'navigational-prefetch' , '' ] as const ) (
345354 'attaches delivery type ("%s") to resource spans if available' ,
346355 deliveryType => {
347356 const spans : Span [ ] = [ ] ;
@@ -350,13 +359,13 @@ describe('_addResourceSpans', () => {
350359 spans . push ( span ) ;
351360 } ) ;
352361
353- const entry : ResourceEntry = {
362+ const entry = mockPerformanceResourceTiming ( {
354363 initiatorType : 'css' ,
355364 transferSize : 0 ,
356365 encodedBodySize : 0 ,
357366 decodedBodySize : 0 ,
358367 deliveryType,
359- } ;
368+ } ) ;
360369
361370 _addResourceSpans ( span , entry , resourceEntryName , 100 , 23 , 345 ) ;
362371
0 commit comments