@@ -59,14 +59,7 @@ function renderVerboseTestResult(result: ReplaySuiteTestResult): void {
5959 return ;
6060 }
6161
62- const prefix =
63- result . status === 'passed'
64- ? isFlakyReplayTestResult ( result )
65- ? 'FLAKY'
66- : 'PASS'
67- : result . status === 'skipped'
68- ? 'SKIP'
69- : 'INFO' ;
62+ const prefix = replayResultPrefix ( result ) ;
7063 const attemptSuffix =
7164 'attempts' in result && result . attempts > 1 ? ` after ${ result . attempts } attempts` : '' ;
7265 const durationSuffix = result . durationMs > 0 ? ` (${ result . durationMs } ms)` : '' ;
@@ -83,14 +76,28 @@ function renderFailedTestResult(
8376 const durationSuffix = result . durationMs > 0 ? ` (${ result . durationMs } ms)` : '' ;
8477 process . stdout . write ( `FAIL ${ result . file } ${ attemptSuffix } ${ durationSuffix } \n` ) ;
8578 process . stdout . write ( ` ${ result . error ?. message ?? 'Unknown test failure' } \n` ) ;
86- if ( result . error ?. hint ) process . stdout . write ( ` hint: ${ result . error . hint } \n` ) ;
87- if ( result . artifactsDir ) process . stdout . write ( ` artifacts: ${ result . artifactsDir } \n` ) ;
88- if ( result . error ?. logPath ) process . stdout . write ( ` log: ${ result . error . logPath } \n` ) ;
89- if ( result . error ?. diagnosticId ) {
90- process . stdout . write ( ` diagnostic: ${ result . error . diagnosticId } \n` ) ;
79+ for ( const line of replayFailureConsoleLines ( result ) ) {
80+ process . stdout . write ( ` ${ line } \n` ) ;
9181 }
9282}
9383
84+ function replayResultPrefix ( result : ReplaySuiteTestResult ) : string {
85+ if ( result . status === 'passed' ) return result . attempts > 1 ? 'FLAKY' : 'PASS' ;
86+ if ( result . status === 'skipped' ) return 'SKIP' ;
87+ return 'INFO' ;
88+ }
89+
90+ function replayFailureConsoleLines (
91+ result : Extract < ReplaySuiteTestResult , { status : 'failed' } > ,
92+ ) : string [ ] {
93+ return [
94+ result . error ?. hint ? `hint: ${ result . error . hint } ` : '' ,
95+ result . artifactsDir ? `artifacts: ${ result . artifactsDir } ` : '' ,
96+ result . error ?. logPath ? `log: ${ result . error . logPath } ` : '' ,
97+ result . error ?. diagnosticId ? `diagnostic: ${ result . error . diagnosticId } ` : '' ,
98+ ] . filter ( Boolean ) ;
99+ }
100+
94101function renderFlakyTestResult ( result : Extract < ReplaySuiteTestResult , { status : 'passed' } > ) : void {
95102 const durationSuffix = result . durationMs > 0 ? ` (${ result . durationMs } ms)` : '' ;
96103 process . stdout . write ( `FLAKY ${ result . file } after ${ result . attempts } attempts${ durationSuffix } \n` ) ;
@@ -166,26 +173,68 @@ function renderJUnitTestCase(test: ReplaySuiteTestResult): string[] {
166173
167174function buildFailureDetails ( test : Extract < ReplaySuiteTestResult , { status : 'failed' } > ) : string {
168175 const lines = [ test . error . message ] ;
169- if ( test . error . hint ) lines . push ( `hint: ${ test . error . hint } ` ) ;
170- if ( test . error . diagnosticId ) lines . push ( `diagnosticId: ${ test . error . diagnosticId } ` ) ;
171- if ( test . error . logPath ) lines . push ( `logPath: ${ test . error . logPath } ` ) ;
176+ appendReplayErrorMetadata ( lines , test . error , { includeDetails : false } ) ;
172177 if ( test . artifactsDir ) lines . push ( `artifactsDir: ${ test . artifactsDir } ` ) ;
173- const details = test . error . details ? JSON . stringify ( test . error . details , null , 2 ) : undefined ;
174- if ( details ) lines . push ( `details: ${ details } ` ) ;
178+ appendReplayErrorDetails ( lines , test . error , 2 ) ;
175179 return lines . join ( '\n' ) ;
176180}
177181
178182function buildSystemOut ( test : ReplaySuiteTestResult ) : string {
179183 const lines = [ `status: ${ test . status } ` , `durationMs: ${ test . durationMs } ` ] ;
180- if ( 'attempts' in test ) lines . push ( `attempts: ${ test . attempts } ` ) ;
181- if ( 'session' in test ) lines . push ( `session: ${ test . session } ` ) ;
182- if ( 'replayed' in test ) lines . push ( `replayed: ${ test . replayed } ` ) ;
183- if ( 'healed' in test ) lines . push ( `healed: ${ test . healed } ` ) ;
184- if ( 'artifactsDir' in test && test . artifactsDir ) lines . push ( `artifactsDir: ${ test . artifactsDir } ` ) ;
185- if ( test . status === 'passed' && test . attempts > 1 ) lines . push ( 'flaky: true' ) ;
184+ appendReplaySystemOutMetadata ( lines , test ) ;
186185 return lines . join ( '\n' ) ;
187186}
188187
188+ function appendReplaySystemOutMetadata ( lines : string [ ] , test : ReplaySuiteTestResult ) : void {
189+ appendOptionalLine ( lines , 'attempts' in test ? `attempts: ${ test . attempts } ` : undefined ) ;
190+ appendOptionalLine ( lines , 'session' in test ? `session: ${ test . session } ` : undefined ) ;
191+ appendOptionalLine ( lines , 'replayed' in test ? `replayed: ${ test . replayed } ` : undefined ) ;
192+ appendOptionalLine ( lines , 'healed' in test ? `healed: ${ test . healed } ` : undefined ) ;
193+ appendOptionalLine (
194+ lines ,
195+ 'artifactsDir' in test && test . artifactsDir ? `artifactsDir: ${ test . artifactsDir } ` : undefined ,
196+ ) ;
197+ if ( test . status === 'failed' ) {
198+ appendReplayFailureSystemOut ( lines , test ) ;
199+ }
200+ appendOptionalLine ( lines , isFlakyReplayTestResult ( test ) ? 'flaky: true' : undefined ) ;
201+ }
202+
203+ function appendReplayFailureSystemOut (
204+ lines : string [ ] ,
205+ test : Extract < ReplaySuiteTestResult , { status : 'failed' } > ,
206+ ) : void {
207+ lines . push ( `errorCode: ${ test . error . code } ` ) ;
208+ appendReplayErrorMetadata ( lines , test . error , { includeMessage : true } ) ;
209+ }
210+
211+ function appendReplayErrorMetadata (
212+ lines : string [ ] ,
213+ error : Extract < ReplaySuiteTestResult , { status : 'failed' } > [ 'error' ] ,
214+ options : { includeMessage ?: boolean ; includeDetails ?: boolean ; detailsIndent ?: number } = { } ,
215+ ) : void {
216+ if ( options . includeMessage ) lines . push ( `errorMessage: ${ error . message } ` ) ;
217+ if ( error . hint ) lines . push ( `hint: ${ error . hint } ` ) ;
218+ if ( error . diagnosticId ) lines . push ( `diagnosticId: ${ error . diagnosticId } ` ) ;
219+ if ( error . logPath ) lines . push ( `logPath: ${ error . logPath } ` ) ;
220+ if ( options . includeDetails !== false ) {
221+ appendReplayErrorDetails ( lines , error , options . detailsIndent ) ;
222+ }
223+ }
224+
225+ function appendReplayErrorDetails (
226+ lines : string [ ] ,
227+ error : Extract < ReplaySuiteTestResult , { status : 'failed' } > [ 'error' ] ,
228+ detailsIndent ?: number ,
229+ ) : void {
230+ const details = error . details ? JSON . stringify ( error . details , null , detailsIndent ) : undefined ;
231+ if ( details ) lines . push ( `details: ${ details } ` ) ;
232+ }
233+
234+ function appendOptionalLine ( lines : string [ ] , line : string | undefined ) : void {
235+ if ( line ) lines . push ( line ) ;
236+ }
237+
189238function formatJUnitSeconds ( durationMs : number ) : string {
190239 return ( Math . max ( 0 , durationMs ) / 1000 ) . toFixed ( 3 ) ;
191240}
0 commit comments