@@ -286,30 +286,37 @@ export function printResults(diagnostic: Diagnostic): void {
286
286
logger . success ( ' UNCHANGED %s %s' , diagnostic . testName , chalk . gray ( `${ diagnostic . duration } s` ) ) ;
287
287
break ;
288
288
case DiagnosticReason . TEST_SUCCESS :
289
- logger . success ( ' SUCCESS %s %s\n ' , diagnostic . testName , chalk . gray ( `${ diagnostic . duration } s` ) , diagnostic . message ) ;
289
+ logger . success ( ' SUCCESS %s %s\n ' , diagnostic . testName , chalk . gray ( `${ diagnostic . duration } s` ) ) ;
290
290
break ;
291
291
case DiagnosticReason . NO_SNAPSHOT :
292
292
logger . error ( ' NEW %s %s' , diagnostic . testName , chalk . gray ( `${ diagnostic . duration } s` ) ) ;
293
293
break ;
294
294
case DiagnosticReason . SNAPSHOT_FAILED :
295
- logger . error ( ' CHANGED %s %s\n %s' , diagnostic . testName , chalk . gray ( `${ diagnostic . duration } s` ) , diagnostic . message ) ;
295
+ logger . error ( ' CHANGED %s %s\n%s' , diagnostic . testName , chalk . gray ( `${ diagnostic . duration } s` ) , indentLines ( diagnostic . message , 6 ) ) ;
296
296
break ;
297
297
case DiagnosticReason . SNAPSHOT_ERROR :
298
298
case DiagnosticReason . TEST_ERROR :
299
- logger . error ( ' ERROR %s %s\n %s' , diagnostic . testName , chalk . gray ( `${ diagnostic . duration } s` ) , diagnostic . message ) ;
299
+ logger . error ( ' ERROR %s %s\n%s' , diagnostic . testName , chalk . gray ( `${ diagnostic . duration } s` ) , indentLines ( diagnostic . message , 6 ) ) ;
300
300
break ;
301
301
case DiagnosticReason . TEST_FAILED :
302
- logger . error ( ' FAILED %s %s\n %s' , diagnostic . testName , chalk . gray ( `${ diagnostic . duration } s` ) , diagnostic . message ) ;
302
+ logger . error ( ' FAILED %s %s\n%s' , diagnostic . testName , chalk . gray ( `${ diagnostic . duration } s` ) , indentLines ( diagnostic . message , 6 ) ) ;
303
303
break ;
304
304
case DiagnosticReason . ASSERTION_FAILED :
305
- logger . error ( ' ASSERT %s %s\n %s' , diagnostic . testName , chalk . gray ( `${ diagnostic . duration } s` ) , diagnostic . message ) ;
305
+ logger . error ( ' ASSERT %s %s\n%s' , diagnostic . testName , chalk . gray ( `${ diagnostic . duration } s` ) , indentLines ( diagnostic . message , 6 ) ) ;
306
306
break ;
307
307
}
308
308
for ( const addl of diagnostic . additionalMessages ?? [ ] ) {
309
309
logger . print ( ` ${ addl } ` ) ;
310
310
}
311
311
}
312
312
313
+ /**
314
+ * Takes a multiline string and indents every line with the same number of spaces.
315
+ */
316
+ function indentLines ( message : string , count = 2 ) : string {
317
+ return message . split ( '\n' ) . map ( line => ' ' . repeat ( count ) + line ) . join ( '\n' ) ;
318
+ }
319
+
313
320
export function printLaggards ( testNames : Set < string > ) {
314
321
const parts = [
315
322
' ' ,
@@ -319,3 +326,14 @@ export function printLaggards(testNames: Set<string>) {
319
326
320
327
logger . print ( chalk . grey ( parts . filter ( x => x ) . join ( ' ' ) ) ) ;
321
328
}
329
+
330
+ export function formatError ( error : any ) : string {
331
+ const name = error . name || 'Error' ;
332
+ const message = error . message || String ( error ) ;
333
+
334
+ if ( error . cause ) {
335
+ return `${ name } : ${ message } \n${ chalk . gray ( 'Cause: ' + formatError ( error . cause ) ) } ` ;
336
+ }
337
+
338
+ return `${ name } : ${ message } ` ;
339
+ }
0 commit comments