@@ -57,6 +57,8 @@ export type ErrorDescription = {
5757 prompt ?: trace . AfterActionTraceEventAttachment & { traceUrl : string } ;
5858} ;
5959
60+ export type Attachment = trace . AfterActionTraceEventAttachment & { traceUrl : string } ;
61+
6062export class MultiTraceModel {
6163 readonly startTime : number ;
6264 readonly endTime : number ;
@@ -68,6 +70,8 @@ export class MultiTraceModel {
6870 readonly options : trace . BrowserContextEventOptions ;
6971 readonly pages : PageEntry [ ] ;
7072 readonly actions : ActionTraceEventInContext [ ] ;
73+ readonly attachments : Attachment [ ] ;
74+ readonly visibleAttachments : Attachment [ ] ;
7175 readonly events : ( trace . EventTraceEvent | trace . ConsoleMessageTraceEvent ) [ ] ;
7276 readonly stdio : trace . StdioTraceEvent [ ] ;
7377 readonly errors : trace . ErrorTraceEvent [ ] ;
@@ -103,6 +107,8 @@ export class MultiTraceModel {
103107 this . hasSource = contexts . some ( c => c . hasSource ) ;
104108 this . hasStepData = contexts . some ( context => context . origin === 'testRunner' ) ;
105109 this . resources = [ ...contexts . map ( c => c . resources ) ] . flat ( ) ;
110+ this . attachments = this . actions . flatMap ( action => action . attachments ?. map ( attachment => ( { ...attachment , traceUrl : action . context . traceUrl } ) ) ?? [ ] ) ;
111+ this . visibleAttachments = this . attachments . filter ( attachment => ! attachment . name . startsWith ( '_' ) ) ;
106112
107113 this . events . sort ( ( a1 , a2 ) => a1 . time - a2 . time ) ;
108114 this . resources . sort ( ( a1 , a2 ) => a1 . _monotonicTime ! - a2 . _monotonicTime ! ) ;
@@ -130,18 +136,10 @@ export class MultiTraceModel {
130136 }
131137
132138 private _errorDescriptorsFromTestRunner ( ) : ErrorDescription [ ] {
133- const errorPrompts : Record < string , trace . AfterActionTraceEventAttachment & { traceUrl : string } > = { } ;
134- for ( const action of this . actions ) {
135- for ( const attachment of action . attachments ?? [ ] ) {
136- if ( attachment . name . startsWith ( '_prompt-' ) )
137- errorPrompts [ attachment . name ] = { ...attachment , traceUrl : action . context . traceUrl } ;
138- }
139- }
140-
141139 return this . errors . filter ( e => ! ! e . message ) . map ( ( error , i ) => ( {
142140 stack : error . stack ,
143141 message : error . message ,
144- prompt : errorPrompts [ `_prompt-${ i } ` ] ,
142+ prompt : this . attachments . find ( a => a . name === `_prompt-${ i } ` ) ,
145143 } ) ) ;
146144 }
147145}
0 commit comments