Skip to content

Commit 2324ae7

Browse files
committed
add tests
1 parent 00341b9 commit 2324ae7

File tree

3 files changed

+24
-11
lines changed

3 files changed

+24
-11
lines changed

packages/rum-core/src/domain/view/viewCollection.spec.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,10 @@ describe('viewCollection', () => {
115115
_dd: {
116116
document_version: 3,
117117
replay_stats: undefined,
118+
loading_time: {
119+
was_hidden_during_loading: undefined,
120+
duration: 20,
121+
},
118122
configuration: {
119123
start_session_replay_recording_manually: jasmine.any(Boolean),
120124
},
@@ -201,7 +205,7 @@ describe('viewCollection', () => {
201205
},
202206
},
203207
privacy: { replay_level: 'mask' },
204-
})
208+
} as unknown as RawRumViewEvent) // TODO fixme after updating rum-event-format
205209
})
206210

207211
it('should discard negative loading time', () => {

packages/rum-core/src/domain/view/viewMetrics/trackLoadingTime.spec.ts

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ describe('trackLoadingTime', () => {
2222
let clock: Clock
2323
let domMutationObservable: Observable<void>
2424
let windowOpenObservable: Observable<void>
25-
let loadingTimeCallback: jasmine.Spy<(loadingTime: Duration) => void>
25+
let loadingTimeCallback: jasmine.Spy<(loadingTime: Duration | undefined, wasHiddenDuringLoading: boolean) => void>
2626
let setLoadEvent: (loadEvent: Duration) => void
2727
let stopLoadingTimeTracking: () => void
2828

@@ -44,7 +44,7 @@ describe('trackLoadingTime', () => {
4444
clock = mockClock()
4545
domMutationObservable = new Observable()
4646
windowOpenObservable = new Observable()
47-
loadingTimeCallback = jasmine.createSpy<(loadingTime: Duration) => void>()
47+
loadingTimeCallback = jasmine.createSpy()
4848
})
4949

5050
afterEach(() => {
@@ -65,7 +65,7 @@ describe('trackLoadingTime', () => {
6565
domMutationObservable.notify()
6666
clock.tick(AFTER_PAGE_ACTIVITY_END_DELAY)
6767

68-
expect(loadingTimeCallback).toHaveBeenCalledOnceWith(clock.relative(BEFORE_PAGE_ACTIVITY_VALIDATION_DELAY))
68+
expect(loadingTimeCallback).toHaveBeenCalledOnceWith(clock.relative(BEFORE_PAGE_ACTIVITY_VALIDATION_DELAY), false)
6969
})
7070

7171
it('should use loadEventEnd for initial view when having no activity', () => {
@@ -77,7 +77,7 @@ describe('trackLoadingTime', () => {
7777
setLoadEvent(entry.loadEventEnd)
7878
clock.tick(PAGE_ACTIVITY_END_DELAY)
7979

80-
expect(loadingTimeCallback).toHaveBeenCalledOnceWith(entry.loadEventEnd)
80+
expect(loadingTimeCallback).toHaveBeenCalledOnceWith(entry.loadEventEnd, false)
8181
})
8282

8383
it('should use loadEventEnd for initial view when load event is bigger than computed loading time', () => {
@@ -90,7 +90,7 @@ describe('trackLoadingTime', () => {
9090
domMutationObservable.notify()
9191
clock.tick(AFTER_PAGE_ACTIVITY_END_DELAY)
9292

93-
expect(loadingTimeCallback).toHaveBeenCalledOnceWith(clock.relative(LOAD_EVENT_AFTER_ACTIVITY_TIMING))
93+
expect(loadingTimeCallback).toHaveBeenCalledOnceWith(clock.relative(LOAD_EVENT_AFTER_ACTIVITY_TIMING), false)
9494
})
9595

9696
it('should use computed loading time for initial view when load event is smaller than computed loading time', () => {
@@ -104,7 +104,7 @@ describe('trackLoadingTime', () => {
104104
domMutationObservable.notify()
105105
clock.tick(AFTER_PAGE_ACTIVITY_END_DELAY)
106106

107-
expect(loadingTimeCallback).toHaveBeenCalledOnceWith(clock.relative(BEFORE_PAGE_ACTIVITY_VALIDATION_DELAY))
107+
expect(loadingTimeCallback).toHaveBeenCalledOnceWith(clock.relative(BEFORE_PAGE_ACTIVITY_VALIDATION_DELAY), false)
108108
})
109109

110110
it('should use computed loading time from time origin for initial view', () => {
@@ -127,14 +127,19 @@ describe('trackLoadingTime', () => {
127127
clock.tick(AFTER_PAGE_ACTIVITY_END_DELAY)
128128

129129
expect(loadingTimeCallback).toHaveBeenCalledOnceWith(
130-
clock.relative(BEFORE_PAGE_ACTIVITY_VALIDATION_DELAY + CLOCK_GAP)
130+
clock.relative(BEFORE_PAGE_ACTIVITY_VALIDATION_DELAY + CLOCK_GAP),
131+
false
131132
)
132133
})
133134

134135
it('should discard loading time if page is hidden before activity', () => {
135136
setPageVisibility('hidden')
136137
startLoadingTimeTracking()
137138

138-
expect(loadingTimeCallback).not.toHaveBeenCalled()
139+
clock.tick(BEFORE_PAGE_ACTIVITY_VALIDATION_DELAY)
140+
domMutationObservable.notify()
141+
clock.tick(AFTER_PAGE_ACTIVITY_END_DELAY)
142+
143+
expect(loadingTimeCallback).toHaveBeenCalledOnceWith(undefined, true)
139144
})
140145
})

packages/rum-core/src/domain/view/viewMetrics/trackLoadingTime.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export function trackLoadingTime(
1313
configuration: RumConfiguration,
1414
loadType: ViewLoadingType,
1515
viewStart: ClocksState,
16-
callback: (loadingTime: Duration, wasHiddenDuringLoading: boolean) => void
16+
callback: (loadingTime: Duration | undefined, wasHiddenDuringLoading: boolean) => void
1717
) {
1818
let isWaitingForLoadEvent = loadType === ViewLoadingType.INITIAL_LOAD
1919
let isWaitingForActivityLoadingTime = true
@@ -23,7 +23,11 @@ export function trackLoadingTime(
2323
function invokeCallbackIfAllCandidatesAreReceived() {
2424
if (!isWaitingForActivityLoadingTime && !isWaitingForLoadEvent && loadingTimeCandidates.length > 0) {
2525
const loadingTime = Math.max(...loadingTimeCandidates)
26-
callback(loadingTime as Duration, loadingTime < firstHidden.timeStamp)
26+
if (loadingTime < firstHidden.timeStamp) {
27+
callback(loadingTime as Duration, false)
28+
} else {
29+
callback(undefined, true)
30+
}
2731
}
2832
}
2933

0 commit comments

Comments
 (0)