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

♻️ [RUMF-1368] use the PointerDown event target for click actions #1731

Merged
merged 15 commits into from
Sep 15, 2022
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
6 changes: 3 additions & 3 deletions packages/core/src/tools/contextHistory.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { Clock } from '../../test/specHelper'
import { mockClock } from '../../test/specHelper'
import type { RelativeTime } from './timeUtils'
import type { Duration, RelativeTime } from './timeUtils'
import { addDuration } from './timeUtils'
import { ONE_MINUTE } from './utils'
import { CLEAR_OLD_CONTEXTS_INTERVAL, ContextHistory } from './contextHistory'

Expand Down Expand Up @@ -115,8 +116,7 @@ describe('contextHistory', () => {

it('should clear old contexts', () => {
const originalTime = performance.now() as RelativeTime
// eslint-disable-next-line @typescript-eslint/restrict-plus-operands
BenoitZugmeyer marked this conversation as resolved.
Show resolved Hide resolved
contextHistory.add('foo', originalTime).close((originalTime + 10) as RelativeTime)
contextHistory.add('foo', originalTime).close(addDuration(originalTime, 10 as Duration))
clock.tick(10)

expect(contextHistory.find(originalTime)).toBeDefined()
Expand Down
7 changes: 7 additions & 0 deletions packages/core/src/tools/timeUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,13 @@ export function elapsed(start: number, end: number) {
return (end - start) as Duration
}

export function addDuration(a: TimeStamp, b: Duration): TimeStamp
export function addDuration(a: RelativeTime, b: Duration): RelativeTime
export function addDuration(a: Duration, b: Duration): Duration
export function addDuration(a: number, b: number) {
return a + b
}

/**
* Get the time since the navigation was started.
*
Expand Down
5 changes: 2 additions & 3 deletions packages/rum-core/src/domain/contexts/foregroundContexts.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { RelativeTime, Duration } from '@datadog/browser-core'
import { addEventListener, DOM_EVENT, elapsed, relativeNow, toServerDuration } from '@datadog/browser-core'
import { addDuration, addEventListener, DOM_EVENT, elapsed, relativeNow, toServerDuration } from '@datadog/browser-core'
import type { InForegroundPeriod } from '../../rawRumEvent.types'

// Arbitrary value to cap number of element mostly for backend & to save bandwidth
Expand Down Expand Up @@ -99,8 +99,7 @@ function isInForegroundAt(startTime: RelativeTime): boolean {
}

function selectInForegroundPeriodsFor(eventStartTime: RelativeTime, duration: Duration): InForegroundPeriod[] {
// eslint-disable-next-line @typescript-eslint/restrict-plus-operands
const eventEndTime = (eventStartTime + duration) as RelativeTime
const eventEndTime = addDuration(eventStartTime, duration)
const filteredForegroundPeriods: InForegroundPeriod[] = []

const earliestIndex = Math.max(0, foregroundPeriods.length - MAX_NUMBER_OF_SELECTABLE_FOREGROUND_PERIODS)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { Duration, RelativeTime } from '@datadog/browser-core'
import { addDuration } from '@datadog/browser-core'
import type { RumPerformanceResourceTiming } from '../../../browser/performanceCollection'
import type { RequestCompleteEvent } from '../../requestCollection'
import { toValidEntry } from './resourceUtils'
Expand Down Expand Up @@ -59,12 +60,10 @@ function firstCanBeOptionRequest(correspondingEntries: RumPerformanceResourceTim
}

function endTime(timing: Timing) {
// eslint-disable-next-line @typescript-eslint/restrict-plus-operands
return (timing.startTime + timing.duration) as RelativeTime
return addDuration(timing.startTime, timing.duration)
}

function isBetween(timing: Timing, start: RelativeTime, end: RelativeTime) {
const errorMargin = 1
// eslint-disable-next-line @typescript-eslint/restrict-plus-operands
return timing.startTime >= start - errorMargin && endTime(timing) <= end + errorMargin
const errorMargin = 1 as Duration
return timing.startTime >= start - errorMargin && endTime(timing) <= addDuration(end, errorMargin)
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { Context, RelativeTime, Duration } from '@datadog/browser-core'
import { relativeNow } from '@datadog/browser-core'
import { addDuration, relativeNow } from '@datadog/browser-core'
import type { RumEvent } from '../../../rumEvent.types'
import type { TestSetupBuilder, ViewTest } from '../../../../test/specHelper'
import { setup, setupViewTest } from '../../../../test/specHelper'
Expand Down Expand Up @@ -145,10 +145,9 @@ describe('rum track view metrics', () => {
// introduce a gap between time origin and tracking start
// ensure that `load event > activity delay` and `load event < activity delay + clock gap`
// to make the test fail if the clock gap is not correctly taken into account
const CLOCK_GAP =
FAKE_NAVIGATION_ENTRY_WITH_LOADEVENT_AFTER_ACTIVITY_TIMING.loadEventEnd -
const CLOCK_GAP = (FAKE_NAVIGATION_ENTRY_WITH_LOADEVENT_AFTER_ACTIVITY_TIMING.loadEventEnd -
BEFORE_PAGE_ACTIVITY_VALIDATION_DELAY +
1
1) as Duration

setupBuilder.clock!.tick(CLOCK_GAP)

Expand All @@ -169,8 +168,7 @@ describe('rum track view metrics', () => {
clock.tick(THROTTLE_VIEW_UPDATE_PERIOD)

expect(getViewUpdateCount()).toEqual(2)
// eslint-disable-next-line @typescript-eslint/restrict-plus-operands
expect(getViewUpdate(1).loadingTime).toEqual((BEFORE_PAGE_ACTIVITY_VALIDATION_DELAY + CLOCK_GAP) as Duration)
expect(getViewUpdate(1).loadingTime).toEqual(addDuration(BEFORE_PAGE_ACTIVITY_VALIDATION_DELAY, CLOCK_GAP))
})
})

Expand Down