Skip to content

Commit c8059f8

Browse files
committed
✅ test performance timing matching
1 parent 96bb2bc commit c8059f8

File tree

1 file changed

+50
-22
lines changed

1 file changed

+50
-22
lines changed

packages/rum-core/src/domain/resource/resourceCollection.spec.ts

Lines changed: 50 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,11 @@ describe('resourceCollection', () => {
5858
beforeEach(() => {
5959
;({ notifyPerformanceEntries } = mockPerformanceObserver())
6060
globalPerformanceObjectMock = mockGlobalPerformanceBuffer()
61-
globalPerformanceObjectMock.addPerformanceEntry(createPerformanceEntry(RumPerformanceEntryType.RESOURCE))
61+
globalPerformanceObjectMock.addPerformanceEntry(
62+
createPerformanceEntry(RumPerformanceEntryType.RESOURCE, {
63+
responseStart: 250 as RelativeTime,
64+
})
65+
)
6266
wasInPageStateDuringPeriodSpy = spyOn(pageStateHistory, 'wasInPageStateDuringPeriod')
6367
})
6468

@@ -110,29 +114,30 @@ describe('resourceCollection', () => {
110114
lifeCycle.notify(
111115
LifeCycleEventType.REQUEST_COMPLETED,
112116
createCompletedRequest({
113-
duration: 100 as Duration,
114-
method: 'GET',
115-
startClocks: { relative: 1234 as RelativeTime, timeStamp: 123456789 as TimeStamp },
116-
status: 200,
117-
type: RequestType.XHR,
118-
url: 'https://resource.com/valid',
119117
xhr,
120118
isAborted: false,
121119
})
122120
)
123121

124-
expect(rawRumEvents[0].startTime).toBe(1234 as RelativeTime)
122+
expect(rawRumEvents[0].startTime).toBe(200 as RelativeTime)
125123
expect(rawRumEvents[0].rawRumEvent).toEqual({
126124
date: jasmine.any(Number),
127125
resource: {
128126
id: jasmine.any(String),
129127
duration: (100 * 1e6) as ServerDuration,
130128
method: 'GET',
131129
status_code: 200,
132-
delivery_type: undefined,
133-
protocol: undefined,
130+
delivery_type: 'cache',
131+
protocol: 'HTTP/1.0',
134132
type: ResourceType.XHR,
135133
url: 'https://resource.com/valid',
134+
render_blocking_status: 'non-blocking',
135+
size: 1000,
136+
encoded_body_size: 500,
137+
decoded_body_size: 1000,
138+
transfer_size: 500,
139+
download: Object({ duration: 50_000_000, start: 50_000_000 }),
140+
first_byte: Object({ duration: 50_000_000, start: 0 }),
136141
},
137142
type: RumEventType.RESOURCE,
138143
_dd: {
@@ -141,7 +146,7 @@ describe('resourceCollection', () => {
141146
})
142147
expect(rawRumEvents[0].domainContext).toEqual({
143148
xhr,
144-
performanceEntry: undefined,
149+
performanceEntry: jasmine.any(Object),
145150
response: undefined,
146151
requestInput: undefined,
147152
requestInit: undefined,
@@ -202,16 +207,36 @@ describe('resourceCollection', () => {
202207
})
203208
})
204209

205-
it('should not have a duration if a frozen state happens during the request and no performance entry matches', () => {
210+
it('should not have any duration properties if a frozen state happens during the request and no performance entry matches', () => {
206211
setupResourceCollection()
207212
const mockXHR = createCompletedRequest()
208213

209214
wasInPageStateDuringPeriodSpy.and.returnValue(true)
210215

211216
lifeCycle.notify(LifeCycleEventType.REQUEST_COMPLETED, mockXHR)
212217

213-
const rawRumResourceEventFetch = rawRumEvents[0].rawRumEvent as RawRumResourceEvent
214-
expect(rawRumResourceEventFetch.resource.duration).toBeUndefined()
218+
expect(rawRumEvents[0].rawRumEvent).toEqual({
219+
date: jasmine.any(Number),
220+
resource: {
221+
id: jasmine.any(String),
222+
duration: undefined,
223+
method: 'GET',
224+
status_code: 200,
225+
delivery_type: 'cache',
226+
protocol: 'HTTP/1.0',
227+
type: ResourceType.XHR,
228+
url: 'https://resource.com/valid',
229+
render_blocking_status: 'non-blocking',
230+
size: 1000,
231+
encoded_body_size: 500,
232+
decoded_body_size: 1000,
233+
transfer_size: 500,
234+
},
235+
type: RumEventType.RESOURCE,
236+
_dd: {
237+
discarded: false,
238+
},
239+
})
215240
})
216241

217242
it('should create resource from completed fetch request', () => {
@@ -220,10 +245,6 @@ describe('resourceCollection', () => {
220245
lifeCycle.notify(
221246
LifeCycleEventType.REQUEST_COMPLETED,
222247
createCompletedRequest({
223-
duration: 100 as Duration,
224-
method: 'GET',
225-
startClocks: { relative: 1234 as RelativeTime, timeStamp: 123456789 as TimeStamp },
226-
status: 200,
227248
type: RequestType.FETCH,
228249
url: 'https://resource.com/valid',
229250
response,
@@ -233,26 +254,33 @@ describe('resourceCollection', () => {
233254
})
234255
)
235256

236-
expect(rawRumEvents[0].startTime).toBe(1234 as RelativeTime)
257+
expect(rawRumEvents[0].startTime).toBe(200 as RelativeTime)
237258
expect(rawRumEvents[0].rawRumEvent).toEqual({
238259
date: jasmine.any(Number),
239260
resource: {
240261
id: jasmine.any(String),
241262
duration: (100 * 1e6) as ServerDuration,
242263
method: 'GET',
243264
status_code: 200,
244-
delivery_type: undefined,
245-
protocol: undefined,
265+
delivery_type: 'cache',
266+
protocol: 'HTTP/1.0',
246267
type: ResourceType.FETCH,
247268
url: 'https://resource.com/valid',
269+
render_blocking_status: 'non-blocking',
270+
size: 1000,
271+
encoded_body_size: 500,
272+
decoded_body_size: 1000,
273+
transfer_size: 500,
274+
download: Object({ duration: 50_000_000, start: 50_000_000 }),
275+
first_byte: Object({ duration: 50_000_000, start: 0 }),
248276
},
249277
type: RumEventType.RESOURCE,
250278
_dd: {
251279
discarded: false,
252280
},
253281
})
254282
expect(rawRumEvents[0].domainContext).toEqual({
255-
performanceEntry: undefined,
283+
performanceEntry: jasmine.any(Object),
256284
xhr: undefined,
257285
response,
258286
requestInput: 'https://resource.com/valid',

0 commit comments

Comments
 (0)