diff --git a/packages/core/src/browser/pageExitObservable.spec.ts b/packages/core/src/browser/pageExitObservable.spec.ts index cb283ce674..df9f9da74f 100644 --- a/packages/core/src/browser/pageExitObservable.spec.ts +++ b/packages/core/src/browser/pageExitObservable.spec.ts @@ -1,5 +1,5 @@ import type { Configuration } from '../domain/configuration' -import { createNewEvent, restorePageVisibility, setPageVisibility, registerCleanupTask } from '../../test' +import { createNewEvent, setPageVisibility, registerCleanupTask } from '../../test' import type { PageExitEvent } from './pageExitObservable' import { PageExitReason, createPageExitObservable } from './pageExitObservable' @@ -13,10 +13,6 @@ describe('createPageExitObservable', () => { registerCleanupTask(createPageExitObservable(configuration).subscribe(onExitSpy).unsubscribe) }) - afterEach(() => { - restorePageVisibility() - }) - it('notifies when the page fires beforeunload', () => { window.dispatchEvent(createNewEvent('beforeunload')) diff --git a/packages/core/src/domain/session/sessionManager.spec.ts b/packages/core/src/domain/session/sessionManager.spec.ts index 24fc2e4ddb..625dbf2ef2 100644 --- a/packages/core/src/domain/session/sessionManager.spec.ts +++ b/packages/core/src/domain/session/sessionManager.spec.ts @@ -1,11 +1,4 @@ -import { - createNewEvent, - expireCookie, - mockClock, - registerCleanupTask, - restorePageVisibility, - setPageVisibility, -} from '../../../test' +import { createNewEvent, expireCookie, mockClock, registerCleanupTask, setPageVisibility } from '../../../test' import type { Clock } from '../../../test' import { getCookie, setCookie } from '../../browser/cookie' import { isIE } from '../../tools/utils/browserDetection' @@ -365,10 +358,6 @@ describe('startSessionManager', () => { setPageVisibility('hidden') }) - afterEach(() => { - restorePageVisibility() - }) - it('should expire the session after expiration delay', () => { const sessionManager = startSessionManagerWithDefaults() const expireSessionSpy = jasmine.createSpy() diff --git a/packages/core/test/emulate/mockVisibilityState.ts b/packages/core/test/emulate/mockVisibilityState.ts index 4586a97bca..36a24dd9c1 100644 --- a/packages/core/test/emulate/mockVisibilityState.ts +++ b/packages/core/test/emulate/mockVisibilityState.ts @@ -1,4 +1,10 @@ +import { registerCleanupTask } from '../registerCleanupTask' + export function setPageVisibility(visibility: 'visible' | 'hidden') { + registerCleanupTask(() => { + delete (document as any).visibilityState + }) + Object.defineProperty(document, 'visibilityState', { get() { return visibility @@ -6,7 +12,3 @@ export function setPageVisibility(visibility: 'visible' | 'hidden') { configurable: true, }) } - -export function restorePageVisibility() { - delete (document as any).visibilityState -} diff --git a/packages/rum-core/src/domain/view/viewMetrics/trackFirstContentfulPaint.spec.ts b/packages/rum-core/src/domain/view/viewMetrics/trackFirstContentfulPaint.spec.ts index b30d771777..5332b2a950 100644 --- a/packages/rum-core/src/domain/view/viewMetrics/trackFirstContentfulPaint.spec.ts +++ b/packages/rum-core/src/domain/view/viewMetrics/trackFirstContentfulPaint.spec.ts @@ -1,5 +1,5 @@ import type { RelativeTime } from '@datadog/browser-core' -import { registerCleanupTask, restorePageVisibility, setPageVisibility } from '@datadog/browser-core/test' +import { registerCleanupTask, setPageVisibility } from '@datadog/browser-core/test' import type { RumPerformanceEntry } from '../../../browser/performanceObservable' import { RumPerformanceEntryType } from '../../../browser/performanceObservable' import { createPerformanceEntry, mockPerformanceObserver, mockRumConfiguration } from '../../../../test' @@ -20,7 +20,6 @@ describe('trackFirstContentfulPaint', () => { registerCleanupTask(() => { firstHidden.stop() firstContentfulPaint.stop() - restorePageVisibility() }) } diff --git a/packages/rum-core/src/domain/view/viewMetrics/trackFirstHidden.spec.ts b/packages/rum-core/src/domain/view/viewMetrics/trackFirstHidden.spec.ts index 5765acc61d..03527fb59c 100644 --- a/packages/rum-core/src/domain/view/viewMetrics/trackFirstHidden.spec.ts +++ b/packages/rum-core/src/domain/view/viewMetrics/trackFirstHidden.spec.ts @@ -1,6 +1,6 @@ import type { RelativeTime } from '@datadog/browser-core' import { DOM_EVENT } from '@datadog/browser-core' -import { createNewEvent, restorePageVisibility, setPageVisibility } from '@datadog/browser-core/test' +import { createNewEvent, setPageVisibility } from '@datadog/browser-core/test' import { mockRumConfiguration } from '../../../../test' import { trackFirstHidden } from './trackFirstHidden' @@ -9,7 +9,6 @@ describe('trackFirstHidden', () => { let firstHidden: { timeStamp: RelativeTime; stop: () => void } afterEach(() => { - restorePageVisibility() firstHidden.stop() }) diff --git a/packages/rum-core/src/domain/view/viewMetrics/trackFirstInput.spec.ts b/packages/rum-core/src/domain/view/viewMetrics/trackFirstInput.spec.ts index 3e4ebf30d7..5410fa25a4 100644 --- a/packages/rum-core/src/domain/view/viewMetrics/trackFirstInput.spec.ts +++ b/packages/rum-core/src/domain/view/viewMetrics/trackFirstInput.spec.ts @@ -1,5 +1,5 @@ import { type Duration, type RelativeTime } from '@datadog/browser-core' -import { registerCleanupTask, restorePageVisibility, setPageVisibility } from '@datadog/browser-core/test' +import { registerCleanupTask, setPageVisibility } from '@datadog/browser-core/test' import { appendElement, appendText, @@ -29,7 +29,6 @@ describe('firstInputTimings', () => { registerCleanupTask(() => { firstHidden.stop() firstInputTimings.stop() - restorePageVisibility() }) } diff --git a/packages/rum-core/src/domain/view/viewMetrics/trackLargestContentfulPaint.spec.ts b/packages/rum-core/src/domain/view/viewMetrics/trackLargestContentfulPaint.spec.ts index aa53ab0a26..02a51ed87d 100644 --- a/packages/rum-core/src/domain/view/viewMetrics/trackLargestContentfulPaint.spec.ts +++ b/packages/rum-core/src/domain/view/viewMetrics/trackLargestContentfulPaint.spec.ts @@ -1,11 +1,6 @@ import type { RelativeTime } from '@datadog/browser-core' import { DOM_EVENT } from '@datadog/browser-core' -import { - setPageVisibility, - createNewEvent, - restorePageVisibility, - registerCleanupTask, -} from '@datadog/browser-core/test' +import { setPageVisibility, createNewEvent, registerCleanupTask } from '@datadog/browser-core/test' import type { RumPerformanceEntry } from '../../../browser/performanceObservable' import { RumPerformanceEntryType } from '../../../browser/performanceObservable' import { appendElement, createPerformanceEntry, mockPerformanceObserver, mockRumConfiguration } from '../../../../test' @@ -32,7 +27,6 @@ describe('trackLargestContentfulPaint', () => { registerCleanupTask(() => { firstHidden.stop() largestContentfulPaint.stop() - restorePageVisibility() }) } diff --git a/packages/rum-core/src/domain/view/viewMetrics/trackLoadingTime.spec.ts b/packages/rum-core/src/domain/view/viewMetrics/trackLoadingTime.spec.ts index dc7581d1dd..d4f7427627 100644 --- a/packages/rum-core/src/domain/view/viewMetrics/trackLoadingTime.spec.ts +++ b/packages/rum-core/src/domain/view/viewMetrics/trackLoadingTime.spec.ts @@ -1,7 +1,7 @@ import type { RelativeTime, Duration } from '@datadog/browser-core' import { clocksOrigin, Observable } from '@datadog/browser-core' import type { Clock } from '@datadog/browser-core/test' -import { mockClock, setPageVisibility, restorePageVisibility } from '@datadog/browser-core/test' +import { mockClock, setPageVisibility } from '@datadog/browser-core/test' import { ViewLoadingType } from '../../../rawRumEvent.types' import { createPerformanceEntry, mockRumConfiguration } from '../../../../test' import { PAGE_ACTIVITY_END_DELAY, PAGE_ACTIVITY_VALIDATION_DELAY } from '../../waitPageActivityEnd' @@ -46,7 +46,6 @@ describe('trackLoadingTime', () => { afterEach(() => { stopLoadingTimeTracking() - restorePageVisibility() clock.cleanup() }) diff --git a/packages/rum/src/domain/segmentCollection/segmentCollection.spec.ts b/packages/rum/src/domain/segmentCollection/segmentCollection.spec.ts index 979354528b..62bd077866 100644 --- a/packages/rum/src/domain/segmentCollection/segmentCollection.spec.ts +++ b/packages/rum/src/domain/segmentCollection/segmentCollection.spec.ts @@ -3,7 +3,7 @@ import { DeflateEncoderStreamId, PageExitReason, isIE } from '@datadog/browser-c import type { ViewHistory, ViewHistoryEntry, RumConfiguration } from '@datadog/browser-rum-core' import { LifeCycle, LifeCycleEventType } from '@datadog/browser-rum-core' import type { Clock } from '@datadog/browser-core/test' -import { mockClock, registerCleanupTask, restorePageVisibility } from '@datadog/browser-core/test' +import { mockClock, registerCleanupTask } from '@datadog/browser-core/test' import { createRumSessionManagerMock } from '../../../../rum-core/test' import type { BrowserRecord, SegmentContext } from '../../types' import { RecordType } from '../../types' @@ -114,10 +114,6 @@ describe('startSegmentCollection', () => { }) describe('segment flush strategy', () => { - afterEach(() => { - restorePageVisibility() - }) - it('does not flush empty segments', () => { emulatePageUnload() worker.processAllMessages()