11import { DefaultPrivacyLevel , findLast , noop } from '@datadog/browser-core'
22import type { RumConfiguration , ViewCreatedEvent } from '@datadog/browser-rum-core'
33import { LifeCycle , LifeCycleEventType } from '@datadog/browser-rum-core'
4- import { createNewEvent , collectAsyncCalls , registerCleanupTask } from '@datadog/browser-core/test'
4+ import { createNewEvent , collectAsyncCalls , mockClock , registerCleanupTask } from '@datadog/browser-core/test'
55import { recordsPerFullSnapshot } from '../../../test'
66import type {
77 AddNodeChange ,
@@ -34,7 +34,8 @@ describe('record', () => {
3434 } )
3535 } )
3636
37- it ( 'captures stylesheet rules' , async ( ) => {
37+ it ( 'captures stylesheet rules' , ( ) => {
38+ const clock = mockClock ( )
3839 const styleElement = appendElement ( '<style></style>' ) as HTMLStyleElement
3940
4041 startRecording ( )
@@ -53,61 +54,23 @@ describe('record', () => {
5354 styleSheet . insertRule ( 'body { color: #ccc; }' )
5455 } , 10 )
5556
56- await collectAsyncCalls ( emitSpy , recordsPerFullSnapshot ( ) + 6 )
57+ clock . tick ( 10 )
5758
58- const records = getEmittedRecords ( )
59- let i = 0
60-
61- expect ( records [ i ++ ] . type ) . toEqual ( RecordType . Meta )
62- expect ( records [ i ++ ] . type ) . toEqual ( RecordType . Focus )
63- expect ( records [ i ++ ] . type ) . toEqual ( RecordType . FullSnapshot )
64-
65- if ( window . visualViewport ) {
66- expect ( records [ i ++ ] . type ) . toEqual ( RecordType . VisualViewport )
67- }
68-
69- expect ( records [ i ] . type ) . toEqual ( RecordType . IncrementalSnapshot )
70- expect ( ( records [ i ++ ] as BrowserIncrementalSnapshotRecord ) . data ) . toEqual (
71- jasmine . objectContaining ( {
72- source : IncrementalSource . StyleSheetRule ,
73- adds : [ { rule : 'body { background: #000; }' , index : undefined } ] ,
74- } )
75- )
76- expect ( records [ i ] . type ) . toEqual ( RecordType . IncrementalSnapshot )
77- expect ( ( records [ i ++ ] as BrowserIncrementalSnapshotRecord ) . data ) . toEqual (
78- jasmine . objectContaining ( {
79- source : IncrementalSource . StyleSheetRule ,
80- adds : [ { rule : 'body { background: #111; }' , index : undefined } ] ,
81- } )
82- )
83- expect ( records [ i ] . type ) . toEqual ( RecordType . IncrementalSnapshot )
84- expect ( ( records [ i ++ ] as BrowserIncrementalSnapshotRecord ) . data ) . toEqual (
85- jasmine . objectContaining ( {
86- source : IncrementalSource . StyleSheetRule ,
87- removes : [ { index : 0 } ] ,
88- } )
89- )
90- expect ( records [ i ] . type ) . toEqual ( RecordType . IncrementalSnapshot )
91- expect ( ( records [ i ++ ] as BrowserIncrementalSnapshotRecord ) . data ) . toEqual (
92- jasmine . objectContaining ( {
93- source : IncrementalSource . StyleSheetRule ,
94- adds : [ { rule : 'body { color: #fff; }' , index : undefined } ] ,
95- } )
96- )
97- expect ( records [ i ] . type ) . toEqual ( RecordType . IncrementalSnapshot )
98- expect ( ( records [ i ++ ] as BrowserIncrementalSnapshotRecord ) . data ) . toEqual (
99- jasmine . objectContaining ( {
100- source : IncrementalSource . StyleSheetRule ,
101- removes : [ { index : 0 } ] ,
102- } )
103- )
104- expect ( records [ i ] . type ) . toEqual ( RecordType . IncrementalSnapshot )
105- expect ( ( records [ i ] as BrowserIncrementalSnapshotRecord ) . data ) . toEqual (
106- jasmine . objectContaining ( {
107- source : IncrementalSource . StyleSheetRule ,
108- adds : [ { rule : 'body { color: #ccc; }' , index : undefined } ] ,
109- } )
110- )
59+ const styleSheetRuleData = getEmittedRecords ( )
60+ . filter (
61+ ( record ) : record is BrowserIncrementalSnapshotRecord =>
62+ record . type === RecordType . IncrementalSnapshot && record . data . source === IncrementalSource . StyleSheetRule
63+ )
64+ . map ( ( record ) => record . data )
65+
66+ expect ( styleSheetRuleData ) . toEqual ( [
67+ jasmine . objectContaining ( { adds : [ { rule : 'body { background: #000; }' , index : undefined } ] } ) ,
68+ jasmine . objectContaining ( { adds : [ { rule : 'body { background: #111; }' , index : undefined } ] } ) ,
69+ jasmine . objectContaining ( { removes : [ { index : 0 } ] } ) ,
70+ jasmine . objectContaining ( { adds : [ { rule : 'body { color: #fff; }' , index : undefined } ] } ) ,
71+ jasmine . objectContaining ( { removes : [ { index : 0 } ] } ) ,
72+ jasmine . objectContaining ( { adds : [ { rule : 'body { color: #ccc; }' , index : undefined } ] } ) ,
73+ ] )
11174 } )
11275
11376 it ( 'flushes pending mutation records before taking a full snapshot' , async ( ) => {
0 commit comments