@@ -2,7 +2,7 @@ import type { ServerDuration, Duration, RelativeTime } from '@datadog/browser-co
22import { HookNames } from '@datadog/browser-core'
33import type { Clock } from '../../../../core/test'
44import { mockClock , registerCleanupTask } from '../../../../core/test'
5- import { mockRumConfiguration , mockPerformanceObserver } from '../../../test'
5+ import { createPerformanceEntry , mockPerformanceObserver , mockRumConfiguration } from '../../../test'
66import { RumEventType } from '../../rawRumEvent.types'
77import * as performanceObservable from '../../browser/performanceObservable'
88import type { Hooks } from '../hooks'
@@ -14,18 +14,17 @@ describe('pageStateHistory', () => {
1414 let clock : Clock
1515 let hooks : Hooks
1616 const configuration = mockRumConfiguration ( )
17- let getEntriesByTypeSpy : jasmine . Spy < Performance [ 'getEntriesByType' ] >
1817
1918 beforeEach ( ( ) => {
2019 clock = mockClock ( )
2120 hooks = createHooks ( )
22- getEntriesByTypeSpy = spyOn ( performance , 'getEntriesByType' ) . and . returnValue ( [ ] )
2321 } )
2422
2523 describe ( 'wasInPageStateDuringPeriod' , ( ) => {
2624 let pageStateHistory : PageStateHistory
2725
2826 beforeEach ( ( ) => {
27+ mockPerformanceObserver ( )
2928 pageStateHistory = startPageStateHistory ( hooks , configuration )
3029 registerCleanupTask ( pageStateHistory . stop )
3130 } )
@@ -70,6 +69,7 @@ describe('pageStateHistory', () => {
7069 let pageStateHistory : PageStateHistory
7170
7271 beforeEach ( ( ) => {
72+ mockPerformanceObserver ( )
7373 pageStateHistory = startPageStateHistory ( hooks , configuration )
7474 registerCleanupTask ( pageStateHistory . stop )
7575 } )
@@ -180,6 +180,7 @@ describe('pageStateHistory', () => {
180180 let pageStateHistory : PageStateHistory
181181
182182 beforeEach ( ( ) => {
183+ mockPerformanceObserver ( )
183184 pageStateHistory = startPageStateHistory ( hooks , configuration )
184185 registerCleanupTask ( pageStateHistory . stop )
185186 } )
@@ -226,22 +227,20 @@ describe('pageStateHistory', () => {
226227 } )
227228
228229 it ( 'should backfill history if visibility-state is supported and entries exist' , ( ) => {
229- mockPerformanceObserver ( {
230- supportedEntryTypes : [
231- ...Object . values ( performanceObservable . RumPerformanceEntryType ) . filter (
232- ( type ) => type !== performanceObservable . RumPerformanceEntryType . VISIBILITY_STATE
233- ) ,
234- performanceObservable . RumPerformanceEntryType . VISIBILITY_STATE ,
235- ] ,
230+ const { notifyPerformanceEntries } = mockPerformanceObserver ( {
231+ supportedEntryTypes : [ performanceObservable . RumPerformanceEntryType . VISIBILITY_STATE ] ,
236232 } )
237233
238- const mockEntries = [
239- { entryType : 'visibility-state' , name : 'visible' , startTime : 5 } ,
240- { entryType : 'visibility-state' , name : 'hidden' , startTime : 15 } ,
241- ] as PerformanceEntry [ ]
242- getEntriesByTypeSpy
243- . withArgs ( performanceObservable . RumPerformanceEntryType . VISIBILITY_STATE )
244- . and . returnValue ( mockEntries )
234+ notifyPerformanceEntries ( [
235+ createPerformanceEntry ( performanceObservable . RumPerformanceEntryType . VISIBILITY_STATE , {
236+ name : 'visible' ,
237+ startTime : 5 as RelativeTime ,
238+ } ) ,
239+ createPerformanceEntry ( performanceObservable . RumPerformanceEntryType . VISIBILITY_STATE , {
240+ name : 'hidden' ,
241+ startTime : 15 as RelativeTime ,
242+ } ) ,
243+ ] )
245244
246245 pageStateHistory = startPageStateHistory ( hooks , configuration )
247246 registerCleanupTask ( pageStateHistory . stop )
@@ -254,19 +253,15 @@ describe('pageStateHistory', () => {
254253
255254 it ( 'should not backfill if visibility-state is not supported' , ( ) => {
256255 mockPerformanceObserver ( {
257- supportedEntryTypes : Object . values ( performanceObservable . RumPerformanceEntryType ) . filter (
258- ( type ) => type !== performanceObservable . RumPerformanceEntryType . VISIBILITY_STATE
259- ) ,
256+ supportedEntryTypes : [ ] ,
260257 } )
261258
262- getEntriesByTypeSpy . calls . reset ( )
263-
264259 pageStateHistory = startPageStateHistory ( hooks , configuration )
265260 registerCleanupTask ( pageStateHistory . stop )
266261
267- expect ( getEntriesByTypeSpy ) . not . toHaveBeenCalledWith (
268- performanceObservable . RumPerformanceEntryType . VISIBILITY_STATE
269- )
262+ expect (
263+ pageStateHistory . wasInPageStateDuringPeriod ( PageState . ACTIVE , 5 as RelativeTime , 5 as Duration )
264+ ) . toBeFalse ( )
270265 } )
271266 } )
272267} )
0 commit comments