Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[REPLAY-149] implement ViewEnd record #711

Merged
merged 6 commits into from
Feb 3, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 14 additions & 12 deletions packages/rum-recorder/src/boot/recorder.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { setup, TestSetupBuilder } from '../../../rum-core/test/specHelper'
import { collectAsyncCalls } from '../../test/utils'

import { FocusRecord, RawRecord } from '../types'
import { MAX_SEGMENT_DURATION } from '../domain/segmentCollection'
import { startRecording, trackFocusRecords } from './recorder'

describe('startRecording', () => {
Expand All @@ -22,6 +23,7 @@ describe('startRecording', () => {
}
sessionId = 'session-id'
setupBuilder = setup()
.withFakeClock()
.withParentContexts({
findView() {
return {
Expand Down Expand Up @@ -52,8 +54,8 @@ describe('startRecording', () => {
})

it('sends recorded segments with valid context', (done) => {
const { lifeCycle } = setupBuilder.build()
flushSegment(lifeCycle)
setupBuilder.build()
flushSegment()

waitRequestSendCalls(1, (calls) => {
expect(calls.first().args).toEqual([jasmine.any(FormData), jasmine.any(Number)])
Expand Down Expand Up @@ -91,15 +93,15 @@ describe('startRecording', () => {
})

it('stops sending new segment when the session is expired', (done) => {
const { lifeCycle } = setupBuilder.build()
setupBuilder.build()

document.body.dispatchEvent(createNewEvent('click'))

sessionId = undefined
flushSegment(lifeCycle)
flushSegment()
document.body.dispatchEvent(createNewEvent('click'))

flushSegment(lifeCycle)
flushSegment()

waitRequestSendCalls(1, (calls) => {
expect(getRequestData(calls.first()).records_count).toBe('4')
Expand All @@ -109,15 +111,15 @@ describe('startRecording', () => {

it('restarts sending segments when the session is renewed', (done) => {
sessionId = undefined
const { lifeCycle } = setupBuilder.build()
setupBuilder.build()

document.body.dispatchEvent(createNewEvent('click'))

sessionId = 'new-session-id'
flushSegment(lifeCycle)
flushSegment()
document.body.dispatchEvent(createNewEvent('click'))

flushSegment(lifeCycle)
flushSegment()

waitRequestSendCalls(1, (calls) => {
const data = getRequestData(calls.first())
Expand All @@ -132,7 +134,7 @@ describe('startRecording', () => {

lifeCycle.notify(LifeCycleEventType.VIEW_CREATED, {} as any)

flushSegment(lifeCycle)
flushSegment()

waitRequestSendCalls(2, (calls) => {
expect(getRequestData(calls.mostRecent()).has_full_snapshot).toBe('true')
Expand All @@ -145,7 +147,7 @@ describe('startRecording', () => {

lifeCycle.notify(LifeCycleEventType.SESSION_RENEWED)

flushSegment(lifeCycle)
flushSegment()

waitRequestSendCalls(2, (calls) => {
expect(getRequestData(calls.mostRecent()).has_full_snapshot).toBe('true')
Expand Down Expand Up @@ -208,8 +210,8 @@ describe('trackFocusRecords', () => {
})
})

function flushSegment(lifeCycle: LifeCycle) {
lifeCycle.notify(LifeCycleEventType.BEFORE_UNLOAD)
function flushSegment() {
jasmine.clock().tick(MAX_SEGMENT_DURATION)
}

function getRequestData(call: jasmine.CallInfo<HttpRequest['send']>) {
Expand Down
2 changes: 2 additions & 0 deletions packages/rum-recorder/test/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ export function collectAsyncCalls<F extends jasmine.Func>(spy: jasmine.Spy<F>) {
spy.and.callFake((() => {
fail('Unexpected extra call')
}) as F)
// make sure the "setTimeout" is not mocked
jasmine.clock().uninstall()
bcaudan marked this conversation as resolved.
Show resolved Hide resolved
setTimeout(done, 300)
},
}
Expand Down