@@ -18,6 +18,7 @@ import type * as trace from '@trace/trace';
18
18
import type * as traceV3 from './versions/traceV3' ;
19
19
import type * as traceV4 from './versions/traceV4' ;
20
20
import type * as traceV5 from './versions/traceV5' ;
21
+ import type * as traceV6 from './versions/traceV6' ;
21
22
import type { ActionEntry , ContextEntry , PageEntry } from './entries' ;
22
23
import type { SnapshotStorage } from './snapshotStorage' ;
23
24
@@ -71,12 +72,13 @@ export class TraceModernizer {
71
72
switch ( event . type ) {
72
73
case 'context-options' : {
73
74
this . _version = event . version ;
74
- contextEntry . origin = 'library' ;
75
+ contextEntry . origin = event . origin ;
75
76
contextEntry . browserName = event . browserName ;
76
77
contextEntry . channel = event . channel ;
77
78
contextEntry . title = event . title ;
78
79
contextEntry . platform = event . platform ;
79
80
contextEntry . wallTime = event . wallTime ;
81
+ contextEntry . startTime = event . monotonicTime ;
80
82
contextEntry . sdkLanguage = event . sdkLanguage ;
81
83
contextEntry . options = event . options ;
82
84
contextEntry . testIdAttributeName = event . testIdAttributeName ;
@@ -145,11 +147,11 @@ export class TraceModernizer {
145
147
break ;
146
148
}
147
149
case 'resource-snapshot' :
148
- this . _snapshotStorage ! . addResource ( event . snapshot ) ;
150
+ this . _snapshotStorage . addResource ( event . snapshot ) ;
149
151
contextEntry . resources . push ( event . snapshot ) ;
150
152
break ;
151
153
case 'frame-snapshot' :
152
- this . _snapshotStorage ! . addFrameSnapshot ( event . snapshot ) ;
154
+ this . _snapshotStorage . addFrameSnapshot ( event . snapshot ) ;
153
155
break ;
154
156
}
155
157
// Make sure there is a page entry for each page, even without screencast frames,
@@ -170,12 +172,18 @@ export class TraceModernizer {
170
172
}
171
173
}
172
174
175
+ private _processedContextCreatedEvent ( ) {
176
+ return this . _version !== undefined ;
177
+ }
178
+
173
179
private _modernize ( event : any ) : trace . TraceEvent [ ] {
174
- if ( this . _version === undefined )
180
+ // In trace 6->7 we also need to modernize context-options event.
181
+ let version = this . _version || event . version ;
182
+ if ( version === undefined )
175
183
return [ event ] ;
176
- const lastVersion : trace . VERSION = 6 ;
184
+ const lastVersion : trace . VERSION = 7 ;
177
185
let events = [ event ] ;
178
- for ( let version = this . _version ; version < lastVersion ; ++ version )
186
+ for ( ; version < lastVersion ; ++ version )
179
187
events = ( this as any ) [ `_modernize_${ version } _to_${ version + 1 } ` ] . call ( this , events ) ;
180
188
return events ;
181
189
}
@@ -341,8 +349,8 @@ export class TraceModernizer {
341
349
return event ;
342
350
}
343
351
344
- _modernize_5_to_6 ( events : traceV5 . TraceEvent [ ] ) : trace . TraceEvent [ ] {
345
- const result : trace . TraceEvent [ ] = [ ] ;
352
+ _modernize_5_to_6 ( events : traceV5 . TraceEvent [ ] ) : traceV6 . TraceEvent [ ] {
353
+ const result : traceV6 . TraceEvent [ ] = [ ] ;
346
354
for ( const event of events ) {
347
355
result . push ( event ) ;
348
356
if ( event . type !== 'after' || ! event . log . length )
@@ -358,4 +366,35 @@ export class TraceModernizer {
358
366
}
359
367
return result ;
360
368
}
369
+
370
+ _modernize_6_to_7 ( events : traceV6 . TraceEvent [ ] ) : trace . TraceEvent [ ] {
371
+ const result : trace . TraceEvent [ ] = [ ] ;
372
+ if ( ! this . _processedContextCreatedEvent ( ) && events [ 0 ] . type !== 'context-options' ) {
373
+ const event : trace . ContextCreatedTraceEvent = {
374
+ type : 'context-options' ,
375
+ origin : 'testRunner' ,
376
+ version : 7 ,
377
+ browserName : '' ,
378
+ options : { } ,
379
+ platform : process . platform ,
380
+ wallTime : 0 ,
381
+ monotonicTime : 0 ,
382
+ sdkLanguage : 'javascript' ,
383
+ } ;
384
+ result . push ( event ) ;
385
+ }
386
+ for ( const event of events ) {
387
+ if ( event . type === 'context-options' ) {
388
+ result . push ( { ...event , monotonicTime : 0 , origin : 'library' } ) ;
389
+ continue ;
390
+ }
391
+ // Take wall and monotonic time from the first event.
392
+ if ( ! this . _contextEntry . wallTime && event . type === 'before' )
393
+ this . _contextEntry . wallTime = event . wallTime ;
394
+ if ( ! this . _contextEntry . startTime && event . type === 'before' )
395
+ this . _contextEntry . startTime = event . startTime ;
396
+ result . push ( event ) ;
397
+ }
398
+ return result ;
399
+ }
361
400
}
0 commit comments