Skip to content

Commit

Permalink
✨ [RUMF-1082] enable record-at-dom-loaded (#1182)
Browse files Browse the repository at this point in the history
  • Loading branch information
BenoitZugmeyer authored Dec 6, 2021
1 parent ce5c874 commit 8b19a16
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 79 deletions.
76 changes: 5 additions & 71 deletions packages/rum/src/boot/recorderApi.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ describe('makeRecorderApi', () => {

afterEach(() => {
setupBuilder.cleanup()
resetExperimentalFeatures()
})

describe('boot', () => {
Expand All @@ -68,17 +67,7 @@ describe('makeRecorderApi', () => {
expect(startRecordingSpy).not.toHaveBeenCalled()
})

it('without "record-at-dom-loaded", does not start recording after the page "load"', () => {
setupBuilder.build()
const { triggerOnLoad } = mockDocumentReadyState()
rumInit(DEFAULT_INIT_CONFIGURATION)
expect(startRecordingSpy).not.toHaveBeenCalled()
triggerOnLoad()
expect(startRecordingSpy).not.toHaveBeenCalled()
})

it('with "record-at-dom-loaded", does not start recording after the DOM is loaded', () => {
updateExperimentalFeatures(['record-at-dom-loaded'])
it('does not start recording after the DOM is loaded', () => {
setupBuilder.build()
const { triggerOnDomLoaded } = mockDocumentReadyState()
rumInit(DEFAULT_INIT_CONFIGURATION)
Expand All @@ -105,20 +94,7 @@ describe('makeRecorderApi', () => {
expect(startRecordingSpy).toHaveBeenCalled()
})

it('without "record-at-dom-loaded", does not start recording multiple times if restarted before onload', () => {
setupBuilder.build()
const { triggerOnLoad } = mockDocumentReadyState()
rumInit(DEFAULT_INIT_CONFIGURATION)
recorderApi.start()
recorderApi.stop()
recorderApi.start()
triggerOnLoad()
expect(startRecordingSpy).toHaveBeenCalledTimes(1)
})

// eslint-disable-next-line max-len
it('with "record-at-dom-loaded", does not start recording multiple times if restarted before the DOM is loaded', () => {
updateExperimentalFeatures(['record-at-dom-loaded'])
it('does not start recording multiple times if restarted before the DOM is loaded', () => {
setupBuilder.build()
const { triggerOnDomLoaded } = mockDocumentReadyState()
rumInit(DEFAULT_INIT_CONFIGURATION)
Expand Down Expand Up @@ -203,18 +179,7 @@ describe('makeRecorderApi', () => {
expect(startRecordingSpy).not.toHaveBeenCalled()
})

it('without "record-at-dom-loaded", prevents recording to start at page "load"', () => {
setupBuilder.build()
const { triggerOnLoad } = mockDocumentReadyState()
rumInit(DEFAULT_INIT_CONFIGURATION)
recorderApi.start()
recorderApi.stop()
triggerOnLoad()
expect(startRecordingSpy).not.toHaveBeenCalled()
})

it('with "record-at-dom-loaded", prevents recording to start when the DOM is loaded', () => {
updateExperimentalFeatures(['record-at-dom-loaded'])
it('prevents recording to start when the DOM is loaded', () => {
setupBuilder.build()
const { triggerOnDomLoaded } = mockDocumentReadyState()
rumInit(DEFAULT_INIT_CONFIGURATION)
Expand Down Expand Up @@ -304,22 +269,7 @@ describe('makeRecorderApi', () => {
expect(startRecordingSpy).toHaveBeenCalledTimes(1)
})

// eslint-disable-next-line max-len
it('without "record-at-dom-loaded", prevents session recording to start if the session is renewed before onload', () => {
setupBuilder.build()
const { triggerOnLoad } = mockDocumentReadyState()
rumInit(DEFAULT_INIT_CONFIGURATION)
recorderApi.start()
session.setLitePlan()
lifeCycle.notify(LifeCycleEventType.SESSION_EXPIRED)
lifeCycle.notify(LifeCycleEventType.SESSION_RENEWED)
triggerOnLoad()
expect(startRecordingSpy).not.toHaveBeenCalled()
})

// eslint-disable-next-line max-len
it('with "record-at-dom-loaded", prevents session recording to start if the session is renewed before the DOM is loaded', () => {
updateExperimentalFeatures(['record-at-dom-loaded'])
it('prevents session recording to start if the session is renewed before the DOM is loaded', () => {
setupBuilder.build()
const { triggerOnDomLoaded } = mockDocumentReadyState()
rumInit(DEFAULT_INIT_CONFIGURATION)
Expand Down Expand Up @@ -440,19 +390,7 @@ describe('makeRecorderApi', () => {
expect(recorderApi.isRecording()).toBeFalse()
})

it('without "record-at-dom-loaded", is false before page "load"', () => {
setupBuilder.build()
const { triggerOnLoad } = mockDocumentReadyState()
rumInit(DEFAULT_INIT_CONFIGURATION)
expect(recorderApi.isRecording()).toBeFalse()
recorderApi.start()
expect(recorderApi.isRecording()).toBeFalse()
triggerOnLoad()
expect(recorderApi.isRecording()).toBeTrue()
})

it('with "record-at-dom-loaded", is false before the DOM is loaded', () => {
updateExperimentalFeatures(['record-at-dom-loaded'])
it('is false before the DOM is loaded', () => {
setupBuilder.build()
const { triggerOnDomLoaded } = mockDocumentReadyState()
rumInit(DEFAULT_INIT_CONFIGURATION)
Expand All @@ -473,9 +411,5 @@ function mockDocumentReadyState() {
readyState = 'interactive'
window.dispatchEvent(createNewEvent('DOMContentLoaded'))
},
triggerOnLoad: () => {
readyState = 'complete'
window.dispatchEvent(createNewEvent('load'))
},
}
}
10 changes: 2 additions & 8 deletions packages/rum/src/boot/recorderApi.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
import {
Configuration,
canUseEventBridge,
noop,
runOnReadyState,
isExperimentalFeatureEnabled,
} from '@datadog/browser-core'
import { Configuration, canUseEventBridge, noop, runOnReadyState } from '@datadog/browser-core'
import {
LifeCycleEventType,
RumInitConfiguration,
Expand Down Expand Up @@ -107,7 +101,7 @@ export function makeRecorderApi(

state = { status: RecorderStatus.Starting }

runOnReadyState(isExperimentalFeatureEnabled('record-at-dom-loaded') ? 'interactive' : 'complete', () => {
runOnReadyState('interactive', () => {
if (state.status !== RecorderStatus.Starting) {
return
}
Expand Down

0 comments on commit 8b19a16

Please sign in to comment.