Skip to content

Commit

Permalink
♻️ cleanup scenarios using replay
Browse files Browse the repository at this point in the history
  • Loading branch information
bcaudan committed Jun 1, 2023
1 parent bd5766d commit 568cbca
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 43 deletions.
21 changes: 3 additions & 18 deletions test/e2e/scenario/recorder/recorder.scenario.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,14 @@ import {
} from '@datadog/browser-rum/test'
import { flushEvents, createTest, bundleSetup, html } from '../../lib/framework'
import { browserExecute, browserExecuteAsync } from '../../lib/helpers/browser'
import { getFirstSegment, getLastSegment, initRumAndStartRecording } from '../../lib/helpers/replay'
import { getFirstSegment, getLastSegment } from '../../lib/helpers/replay'

const TIMESTAMP_RE = /^\d{13}$/
const UUID_RE = /^[0-9a-f]{8}-([0-9a-f]{4}-){3}[0-9a-f]{12}$/

describe('recorder', () => {
createTest('record mouse move')
.withRum()
.withRumInit(initRumAndStartRecording)
.run(async ({ serverEvents }) => {
await browserExecute(() => document.documentElement.outerHTML)
const html = await $('html')
Expand Down Expand Up @@ -79,7 +78,6 @@ describe('recorder', () => {
describe('full snapshot', () => {
createTest('obfuscate elements')
.withRum()
.withRumInit(initRumAndStartRecording)
.withSetup(bundleSetup)
.withBody(
html`
Expand Down Expand Up @@ -125,7 +123,6 @@ describe('recorder', () => {
describe('mutations observer', () => {
createTest('record mutations')
.withRum()
.withRumInit(initRumAndStartRecording)
.withSetup(bundleSetup)
.withBody(
html`
Expand Down Expand Up @@ -172,7 +169,6 @@ describe('recorder', () => {

createTest('record character data mutations')
.withRum()
.withRumInit(initRumAndStartRecording)
.withSetup(bundleSetup)
.withBody(
html`
Expand Down Expand Up @@ -225,7 +221,6 @@ describe('recorder', () => {

createTest('record attributes mutations')
.withRum()
.withRumInit(initRumAndStartRecording)
.withSetup(bundleSetup)
.withBody(
html`
Expand Down Expand Up @@ -270,7 +265,6 @@ describe('recorder', () => {

createTest("don't record hidden elements mutations")
.withRum()
.withRumInit(initRumAndStartRecording)
.withSetup(bundleSetup)
.withBody(
html`
Expand Down Expand Up @@ -298,7 +292,6 @@ describe('recorder', () => {

createTest('record DOM node movement 1')
.withRum()
.withRumInit(initRumAndStartRecording)
.withSetup(bundleSetup)
.withBody(
// prettier-ignore
Expand Down Expand Up @@ -347,7 +340,6 @@ describe('recorder', () => {

createTest('record DOM node movement 2')
.withRum()
.withRumInit(initRumAndStartRecording)
.withSetup(bundleSetup)
.withBody(
// prettier-ignore
Expand Down Expand Up @@ -399,7 +391,6 @@ describe('recorder', () => {

createTest('serialize node before record')
.withRum()
.withRumInit(initRumAndStartRecording)
.withSetup(bundleSetup)
.withBody(
// prettier-ignore
Expand Down Expand Up @@ -455,7 +446,6 @@ describe('recorder', () => {
.withRum({
defaultPrivacyLevel: DefaultPrivacyLevel.ALLOW,
})
.withRumInit(initRumAndStartRecording)
.withSetup(bundleSetup)
.withBody(
html`
Expand Down Expand Up @@ -537,7 +527,6 @@ describe('recorder', () => {
.withRum({
defaultPrivacyLevel: DefaultPrivacyLevel.ALLOW,
})
.withRumInit(initRumAndStartRecording)
.withSetup(bundleSetup)
.withBody(
html`
Expand Down Expand Up @@ -574,7 +563,6 @@ describe('recorder', () => {

createTest('replace masked values by asterisks')
.withRum()
.withRumInit(initRumAndStartRecording)
.withSetup(bundleSetup)
.withBody(
html`
Expand Down Expand Up @@ -608,7 +596,6 @@ describe('recorder', () => {
describe('stylesheet rules observer', () => {
createTest('record dynamic CSS changes')
.withRum()
.withRumInit(initRumAndStartRecording)
.withSetup(bundleSetup)
.withBody(
html`
Expand Down Expand Up @@ -643,7 +630,6 @@ describe('recorder', () => {

createTest('record nested css rules changes')
.withRum()
.withRumInit(initRumAndStartRecording)
.withSetup(bundleSetup)
.withBody(
html`
Expand Down Expand Up @@ -691,7 +677,6 @@ describe('recorder', () => {
describe('frustration records', () => {
createTest('should detect a dead click and match it to mouse interaction record')
.withRum({ trackUserInteractions: true })
.withRumInit(initRumAndStartRecording)
.withSetup(bundleSetup)
.run(async ({ serverEvents }) => {
const html = await $('html')
Expand All @@ -715,7 +700,6 @@ describe('recorder', () => {

createTest('should detect a rage click and match it to mouse interaction records')
.withRum({ trackUserInteractions: true })
.withRumInit(initRumAndStartRecording)
.withSetup(bundleSetup)
.withBody(
html`
Expand Down Expand Up @@ -748,7 +732,8 @@ describe('recorder', () => {

describe('scroll positions', () => {
createTest('should be recorded across navigation')
.withRum()
// to control initial position before recording
.withRum({ startSessionReplayRecordingManually: true })
.withSetup(bundleSetup)
.withBody(
html`
Expand Down
11 changes: 0 additions & 11 deletions test/e2e/scenario/recorder/shadowDom.scenario.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import type { RumInitConfiguration } from '@datadog/browser-rum-core'
import { IncrementalSource, NodeType } from '@datadog/browser-rum/src/types'
import type { DocumentFragmentNode, MouseInteractionData, SerializedNodeWithId } from '@datadog/browser-rum/src/types'

Expand Down Expand Up @@ -113,7 +112,6 @@ class DivWithStyle extends HTMLElement {
describe('recorder with shadow DOM', () => {
createTest('can record fullsnapshot with the detail inside the shadow root')
.withRum({ defaultPrivacyLevel: 'allow' })
.withRumInit(initRumAndStartRecording)
.withSetup(bundleSetup)
.withBody(
html`
Expand All @@ -136,7 +134,6 @@ describe('recorder with shadow DOM', () => {

createTest('can record fullsnapshot with adoptedStylesheet')
.withRum()
.withRumInit(initRumAndStartRecording)
.withSetup(bundleSetup)
.withBody(
html`
Expand Down Expand Up @@ -164,7 +161,6 @@ describe('recorder with shadow DOM', () => {

createTest('can apply privacy level set from outside or inside the shadow DOM')
.withRum({ defaultPrivacyLevel: 'allow' })
.withRumInit(initRumAndStartRecording)
.withSetup(bundleSetup)
.withBody(
html`
Expand Down Expand Up @@ -202,7 +198,6 @@ describe('recorder with shadow DOM', () => {

createTest('can record click with target from inside the shadow root')
.withRum()
.withRumInit(initRumAndStartRecording)
.withSetup(bundleSetup)
.withBody(
html`
Expand All @@ -228,7 +223,6 @@ describe('recorder with shadow DOM', () => {

createTest('can record mutation from inside the shadow root')
.withRum({ defaultPrivacyLevel: 'allow' })
.withRumInit(initRumAndStartRecording)
.withSetup(bundleSetup)
.withBody(
html`
Expand Down Expand Up @@ -287,11 +281,6 @@ function getFirstSegment(events: EventRegistry) {
return events.sessionReplay[0].segment.data
}

function initRumAndStartRecording(initConfiguration: RumInitConfiguration) {
window.DD_RUM!.init(initConfiguration)
window.DD_RUM!.startSessionReplayRecording()
}

async function getNodeInsideShadowDom(hostTag: string, selector: string) {
const host = await $(hostTag)
return host.shadow$(selector)
Expand Down
10 changes: 0 additions & 10 deletions test/e2e/scenario/recorder/viewports.scenario.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import type { ViewportResizeData, ScrollData } from '@datadog/browser-rum/cjs/types'
import { IncrementalSource } from '@datadog/browser-rum/cjs/types'
import type { RumInitConfiguration } from '@datadog/browser-rum-core'

import { findAllIncrementalSnapshots, findAllVisualViewports } from '@datadog/browser-rum/test'
import type { EventRegistry } from '../../lib/framework'
Expand All @@ -26,7 +25,6 @@ describe('recorder', () => {
describe('layout viewport properties', () => {
createTest('getWindowWidth/Height should not be affected by pinch zoom')
.withRum()
.withRumInit(initRumAndStartRecording)
.withSetup(bundleSetup)
.withBody(html`${VIEWPORT_META_TAGS}`)
.run(async ({ serverEvents }) => {
Expand Down Expand Up @@ -57,7 +55,6 @@ describe('recorder', () => {
*/
createTest('getScrollX/Y should not be affected by pinch scroll')
.withRum()
.withRumInit(initRumAndStartRecording)
.withSetup(bundleSetup)
.withBody(html`${VIEWPORT_META_TAGS}`)
.run(async ({ serverEvents }) => {
Expand Down Expand Up @@ -99,7 +96,6 @@ describe('recorder', () => {
describe('visual viewport properties', () => {
createTest('pinch zoom "scroll" event reports visual viewport position')
.withRum()
.withRumInit(initRumAndStartRecording)
.withSetup(bundleSetup)
.withBody(html`${VIEWPORT_META_TAGS}`)
.run(async ({ serverEvents }) => {
Expand All @@ -114,7 +110,6 @@ describe('recorder', () => {

createTest('pinch zoom "resize" event reports visual viewport scale')
.withRum()
.withRumInit(initRumAndStartRecording)
.withSetup(bundleSetup)
.withBody(html`${VIEWPORT_META_TAGS}`)
.run(async ({ serverEvents }) => {
Expand All @@ -130,11 +125,6 @@ function getLastSegment(serverEvents: EventRegistry) {
return serverEvents.sessionReplay[serverEvents.sessionReplay.length - 1].segment.data
}

function initRumAndStartRecording(initConfiguration: RumInitConfiguration) {
window.DD_RUM!.init(initConfiguration)
window.DD_RUM!.startSessionReplayRecording()
}

const isGestureUnsupported = () =>
/firefox|safari|edge/.test(getBrowserName()) || /windows|linux/.test(getPlatformName())

Expand Down
7 changes: 3 additions & 4 deletions test/e2e/scenario/rum/sessions.scenario.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { RecordType } from '@datadog/browser-rum/src/types'
import { expireSession, findSessionCookie, renewSession } from '../../lib/helpers/session'
import { bundleSetup, createTest, flushEvents, waitForRequests } from '../../lib/framework'
import { browserExecute, browserExecuteAsync, sendXhr } from '../../lib/helpers/browser'
import { getLastSegment, initRumAndStartRecording } from '../../lib/helpers/replay'
import { getLastSegment } from '../../lib/helpers/replay'

describe('rum sessions', () => {
describe('session renewal', () => {
Expand All @@ -23,7 +23,6 @@ describe('rum sessions', () => {

createTest('a single fullSnapshot is taken when the session is renewed')
.withRum()
.withRumInit(initRumAndStartRecording)
.withSetup(bundleSetup)
.run(async ({ serverEvents }) => {
await renewSession()
Expand All @@ -43,7 +42,8 @@ describe('rum sessions', () => {

describe('session expiration', () => {
createTest("don't send events when session is expired")
.withRum()
// prevent recording start to generate late events
.withRum({ startSessionReplayRecordingManually: true })
.run(async ({ serverEvents }) => {
await expireSession()
serverEvents.empty()
Expand Down Expand Up @@ -98,7 +98,6 @@ describe('rum sessions', () => {
createTest('flush events when the session expires')
.withRum()
.withLogs()
.withRumInit(initRumAndStartRecording)
.run(async ({ serverEvents }) => {
expect(serverEvents.rumViews.length).toBe(0)
expect(serverEvents.logs.length).toBe(0)
Expand Down

0 comments on commit 568cbca

Please sign in to comment.