1- import type { RelativeTime , TimeStamp } from '@datadog/browser-core'
1+ import type { Duration , RelativeTime , TimeStamp } from '@datadog/browser-core'
22import { registerCleanupTask } from '@datadog/browser-core/test'
33import { LifeCycle , LifeCycleEventType } from '../lifeCycle'
44import { RumEventType } from '../../rawRumEvent.types'
@@ -34,6 +34,16 @@ describe('trackAction', () => {
3434
3535 expect ( action1 . id ) . not . toBe ( action2 . id )
3636 } )
37+
38+ it ( 'should compute duration from timestamps, not relative times' , ( ) => {
39+ const startClocks = { relative : 100 as RelativeTime , timeStamp : 1000 as TimeStamp }
40+ const trackedAction = actionTracker . createTrackedAction ( startClocks )
41+
42+ const endClocks = { relative : 300 as RelativeTime , timeStamp : 1050 as TimeStamp }
43+ trackedAction . stop ( endClocks )
44+
45+ expect ( trackedAction . duration ) . toBe ( 50 as Duration )
46+ } )
3747 } )
3848
3949 describe ( 'event counting' , ( ) => {
@@ -65,7 +75,7 @@ describe('trackAction', () => {
6575 } )
6676
6777 it ( 'should stop counting events after action is stopped' , ( ) => {
68- trackedAction . stop ( 200 as RelativeTime )
78+ trackedAction . stop ( { relative : 200 as RelativeTime , timeStamp : 1100 as TimeStamp } )
6979
7080 lifeCycle . notify ( LifeCycleEventType . RUM_EVENT_COLLECTED , {
7181 type : RumEventType . ERROR ,
@@ -93,7 +103,7 @@ describe('trackAction', () => {
93103 const startClocks = { relative : 100 as RelativeTime , timeStamp : 1000 as TimeStamp }
94104 const trackedAction = actionTracker . createTrackedAction ( startClocks )
95105
96- trackedAction . stop ( 200 as RelativeTime )
106+ trackedAction . stop ( { relative : 200 as RelativeTime , timeStamp : 1100 as TimeStamp } )
97107
98108 expect ( actionTracker . findActionId ( ) ) . toBeUndefined ( )
99109 } )
@@ -102,7 +112,7 @@ describe('trackAction', () => {
102112 const startClocks = { relative : 100 as RelativeTime , timeStamp : 1000 as TimeStamp }
103113 const trackedAction = actionTracker . createTrackedAction ( startClocks )
104114
105- trackedAction . stop ( 200 as RelativeTime )
115+ trackedAction . stop ( { relative : 200 as RelativeTime , timeStamp : 1100 as TimeStamp } )
106116
107117 expect ( actionTracker . findActionId ( 150 as RelativeTime ) ) . toEqual ( [ trackedAction . id ] )
108118 } )
@@ -111,7 +121,7 @@ describe('trackAction', () => {
111121 const startClocks = { relative : 100 as RelativeTime , timeStamp : 1000 as TimeStamp }
112122 const trackedAction = actionTracker . createTrackedAction ( startClocks )
113123
114- trackedAction . stop ( 200 as RelativeTime )
124+ trackedAction . stop ( { relative : 200 as RelativeTime , timeStamp : 1100 as TimeStamp } )
115125
116126 expect ( actionTracker . findActionId ( 250 as RelativeTime ) ) . toBeUndefined ( )
117127 } )
0 commit comments