@@ -183,8 +183,8 @@ function mergeActionsAndUpdateTiming(contexts: ContextEntry[]) {
183
183
if ( traceFileToContexts . size > 1 )
184
184
makeCallIdsUniqueAcrossTraceFiles ( contexts , ++ traceFileId ) ;
185
185
// Align action times across runner and library contexts within each trace file.
186
- const map = mergeActionsAndUpdateTimingSameTrace ( contexts ) ;
187
- result . push ( ...map . values ( ) ) ;
186
+ const actions = mergeActionsAndUpdateTimingSameTrace ( contexts ) ;
187
+ result . push ( ...actions ) ;
188
188
}
189
189
result . sort ( ( a1 , a2 ) => {
190
190
if ( a2 . parentId === a1 . callId )
@@ -211,19 +211,26 @@ function makeCallIdsUniqueAcrossTraceFiles(contexts: ContextEntry[], traceFileId
211
211
}
212
212
}
213
213
214
- function mergeActionsAndUpdateTimingSameTrace ( contexts : ContextEntry [ ] ) {
214
+ function mergeActionsAndUpdateTimingSameTrace ( contexts : ContextEntry [ ] ) : ActionTraceEventInContext [ ] {
215
215
const map = new Map < string , ActionTraceEventInContext > ( ) ;
216
216
217
217
const libraryContexts = contexts . filter ( context => context . origin === 'library' ) ;
218
218
const testRunnerContexts = contexts . filter ( context => context . origin === 'testRunner' ) ;
219
219
220
+ // With library-only or test-runner-only traces there is nothing to match.
221
+ if ( ! testRunnerContexts . length || ! libraryContexts . length ) {
222
+ return contexts . map ( context => {
223
+ return context . actions . map ( action => ( { ...action , context } ) ) ;
224
+ } ) . flat ( ) ;
225
+ }
226
+
220
227
// Library actions are replaced with corresponding test runner steps. Matching with
221
228
// the test runner steps enables us to find parent steps.
222
229
// - In the newer versions the actions are matched by explicit step id stored in the
223
230
// library context actions.
224
231
// - In the older versions the step id is not stored and the match is perfomed based on
225
232
// action name and wallTime.
226
- const matchByStepId = ! libraryContexts . length || libraryContexts . some ( c => c . actions . some ( a => ! ! a . stepId ) ) ;
233
+ const matchByStepId = libraryContexts . some ( c => c . actions . some ( a => ! ! a . stepId ) ) ;
227
234
228
235
for ( const context of libraryContexts ) {
229
236
for ( const action of context . actions ) {
@@ -264,7 +271,7 @@ function mergeActionsAndUpdateTimingSameTrace(contexts: ContextEntry[]) {
264
271
map . set ( key , { ...action , context } ) ;
265
272
}
266
273
}
267
- return map ;
274
+ return [ ... map . values ( ) ] ;
268
275
}
269
276
270
277
function adjustMonotonicTime ( contexts : ContextEntry [ ] , monotonicTimeDelta : number ) {
0 commit comments