11import { Observable } from '@datadog/browser-core'
22import { deepClone } from '@datadog/js-core/util'
3+ import { registerCleanupTask } from '@datadog/browser-core/test'
34import { mockRumConfiguration , setupLocationObserver } from '../../../test'
4- import type { LifeCycle } from '../lifeCycle'
5- import { LifeCycleEventType } from '../lifeCycle'
5+ import { LifeCycle , LifeCycleEventType } from '../lifeCycle'
66import type { RumConfiguration } from '../configuration'
77import type { RumMutationRecord } from '../../browser/domMutationObservable'
88import type { ViewCreatedEvent , ViewEvent , ViewOptions , ViewEndedEvent } from './trackViews'
99import { trackViews } from './trackViews'
1010
1111export type ViewTest = ReturnType < typeof setupViewTest >
1212
13- interface ViewTrackingContext {
14- lifeCycle : LifeCycle
13+ interface ViewTestOptions {
1514 initialLocation ?: string
1615 partialConfig ?: Partial < RumConfiguration >
16+ initialViewOptions ?: ViewOptions
1717}
1818
19- export function setupViewTest (
20- { lifeCycle, initialLocation, partialConfig } : ViewTrackingContext ,
21- initialViewOptions ?: ViewOptions
22- ) {
19+ export function setupViewTest ( { initialLocation, partialConfig, initialViewOptions } : ViewTestOptions = { } ) {
20+ const lifeCycle = new LifeCycle ( )
2321 const domMutationObservable = new Observable < RumMutationRecord [ ] > ( )
2422 const windowOpenObservable = new Observable < void > ( )
2523 const configuration = mockRumConfiguration ( partialConfig )
@@ -64,8 +62,11 @@ export function setupViewTest(
6462 ! configuration . trackViewsManually ,
6563 initialViewOptions
6664 )
65+
66+ registerCleanupTask ( stop )
67+
6768 return {
68- stop ,
69+ lifeCycle ,
6970 startView,
7071 setViewContext,
7172 setViewContextProperty,
@@ -80,9 +81,6 @@ export function setupViewTest(
8081 getViewCreateCount,
8182 getViewEnd,
8283 getViewEndCount,
83- getLatestViewContext : ( ) => ( {
84- id : getViewCreate ( getViewCreateCount ( ) - 1 ) . id ,
85- } ) ,
8684 }
8785}
8886
0 commit comments