Skip to content

Commit

Permalink
add vitals e2e scenario
Browse files Browse the repository at this point in the history
  • Loading branch information
bcaudan committed Feb 5, 2024
1 parent e5f2666 commit 671a008
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 1 deletion.
17 changes: 16 additions & 1 deletion test/e2e/lib/framework/intakeRegistry.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
import type { LogsEvent } from '@datadog/browser-logs'
import type { RumEvent, RumActionEvent, RumErrorEvent, RumResourceEvent, RumViewEvent } from '@datadog/browser-rum'
import type {
RumEvent,
RumActionEvent,
RumErrorEvent,
RumResourceEvent,
RumViewEvent,
RumVitalEvent,
} from '@datadog/browser-rum'
import type { TelemetryEvent, TelemetryErrorEvent, TelemetryConfigurationEvent } from '@datadog/browser-core'
import type { BrowserSegment } from '@datadog/browser-rum/src/types'
import type { BrowserSegmentMetadataAndSegmentSizes } from '@datadog/browser-rum/src/domain/segmentCollection'
Expand Down Expand Up @@ -94,6 +101,10 @@ export class IntakeRegistry {
return this.rumEvents.filter(isRumViewEvent)
}

get rumVitalEvents() {
return this.rumEvents.filter(isRumVitalEvent)
}

//
// Telemetry
//
Expand Down Expand Up @@ -155,6 +166,10 @@ function isRumErrorEvent(event: RumEvent): event is RumErrorEvent {
return event.type === 'error'
}

function isRumVitalEvent(event: RumEvent): event is RumVitalEvent {
return event.type === 'vital'
}

function isTelemetryEvent(event: RumEvent | TelemetryEvent): event is TelemetryEvent {
return event.type === 'telemetry'
}
Expand Down
26 changes: 26 additions & 0 deletions test/e2e/scenario/rum/vitals.scenario.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { createTest, flushEvents } from '../../lib/framework'
import { browserExecuteAsync } from '../../lib/helpers/browser'

describe('vital collection', () => {
createTest('send custom duration vital')
.withRum({
enableExperimentalFeatures: ['custom_vitals'],
})
.run(async ({ intakeRegistry }) => {
await browserExecuteAsync<void>((done) => {
// TODO remove cast and unsafe calls when removing the flag
const global = window.DD_RUM! as any
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
global.startDurationVital('foo')
setTimeout(() => {
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
global.stopDurationVital('foo')
done()
}, 5)
})
await flushEvents()

expect(intakeRegistry.rumVitalEvents.length).toBe(1)
expect(intakeRegistry.rumVitalEvents[0].vital.custom).toEqual({ foo: jasmine.any(Number) })
})
})

0 comments on commit 671a008

Please sign in to comment.