@@ -5,6 +5,7 @@ import stripAnsi from 'strip-ansi';
55import type {
66 Duration ,
77 GetSourcemap ,
8+ ReporterWithOptions ,
89 SnapshotSummary ,
910 TestFileResult ,
1011 TestResult ,
@@ -38,6 +39,7 @@ export class GithubActionsReporter {
3839 private readonly stepSummaryPath ?: string ;
3940 private readonly enableAnnotations : boolean ;
4041 private readonly enableSummary : boolean ;
42+ private readonly summaryMaxCharsPerField : number ;
4143 private readonly reportName ?: string ;
4244
4345 constructor ( {
@@ -49,18 +51,24 @@ export class GithubActionsReporter {
4951 config ?: {
5052 name ?: string ;
5153 } ;
52- options : {
54+ options : ReporterWithOptions < 'github-actions' > [ 1 ] & {
5355 // `createReporters` never supplies this; only tests do. Optional is the truth.
5456 onWritePath ?: ( path : string ) => string ;
55- annotations ?: boolean ;
56- summary ?: boolean ;
5757 } ;
5858 } ) {
5959 this . onWritePath = options . onWritePath ;
6060 this . rootPath = rootPath ;
6161 this . stepSummaryPath = process . env . GITHUB_STEP_SUMMARY ;
6262 this . enableAnnotations = options . annotations !== false ;
6363 this . enableSummary = options . summary !== false ;
64+ this . summaryMaxCharsPerField =
65+ typeof options . summary === 'object'
66+ ? Math . max (
67+ 0 ,
68+ options . summary . maxCharsPerField ??
69+ STEP_SUMMARY_DEFAULT_MAX_CHARS_PER_FIELD ,
70+ )
71+ : STEP_SUMMARY_DEFAULT_MAX_CHARS_PER_FIELD ;
6472 this . reportName = config ?. name ;
6573 }
6674
@@ -162,6 +170,7 @@ export class GithubActionsReporter {
162170 failures,
163171 getSourcemap,
164172 unhandledErrors,
173+ maxCharsPerField : this . summaryMaxCharsPerField ,
165174 } ) ,
166175 ) ;
167176 }
@@ -179,7 +188,7 @@ function escapeData(s: string): string {
179188
180189const STEP_SUMMARY_MAX_FAILURES = 20 ;
181190const STEP_SUMMARY_MAX_FLAKY_TESTS = 20 ;
182- const STEP_SUMMARY_MAX_MESSAGE_LENGTH = 400 ;
191+ const STEP_SUMMARY_DEFAULT_MAX_CHARS_PER_FIELD = 400 ;
183192const STEP_SUMMARY_MAX_FLAKY_MESSAGE_LENGTH = 160 ;
184193const ROOT_PATH_PLACEHOLDER = '<ROOT>' ;
185194const DEFAULT_PROJECT_NAME = 'rstest' ;
@@ -274,6 +283,7 @@ async function renderStepSummary({
274283 failures,
275284 getSourcemap,
276285 unhandledErrors,
286+ maxCharsPerField,
277287} : {
278288 results : TestFileResult [ ] ;
279289 testResults : TestResult [ ] ;
@@ -283,6 +293,7 @@ async function renderStepSummary({
283293 failures : FailureItem [ ] ;
284294 getSourcemap : GetSourcemap ;
285295 unhandledErrors ?: Error [ ] ;
296+ maxCharsPerField : number ;
286297} ) : Promise < string > {
287298 const { parseErrorStacktrace } = await import ( '../utils/error' ) ;
288299 const packageManagerAgent = await detectPackageManagerAgent ( rootPath ) ;
@@ -365,12 +376,19 @@ async function renderStepSummary({
365376
366377 pushHeading ( lines , 3 , `❌ FAIL Unhandled Error ${ index + 1 } ` ) ;
367378 lines . push (
368- `**${ error . name || 'Error' } **: ${ trimForSummary ( error . message ) } ` ,
379+ `**${ error . name || 'Error' } **: ${ trimForSummary (
380+ error . message ,
381+ maxCharsPerField ,
382+ ) } `,
369383 ) ;
370384 lines . push ( '' ) ;
371385
372386 if ( error . stack ) {
373- pushFencedBlock ( lines , '' , stripAnsi ( trimForSummary ( error . stack ) ) ) ;
387+ pushFencedBlock (
388+ lines ,
389+ '' ,
390+ stripAnsi ( trimForSummary ( error . stack , maxCharsPerField ) ) ,
391+ ) ;
374392 }
375393 }
376394
@@ -398,15 +416,19 @@ async function renderStepSummary({
398416 ? errors
399417 : [ { message : 'Unknown error' } ] ) {
400418 const errorType = getErrorType ( error ) ;
401- const message = trimForSummary ( error . message ) ;
419+ const message = trimForSummary ( error . message , maxCharsPerField ) ;
402420 const retryLabel = getRetryErrorLabel ( error ) ;
403421 lines . push (
404422 `**${ retryLabel ? `${ retryLabel } - ` : '' } ${ errorType } **: ${ message } ` ,
405423 ) ;
406424 lines . push ( '' ) ;
407425
408426 if ( error . diff ) {
409- pushFencedBlock ( lines , 'diff' , stripAnsi ( trimForSummary ( error . diff ) ) ) ;
427+ pushFencedBlock (
428+ lines ,
429+ 'diff' ,
430+ stripAnsi ( trimForSummary ( error . diff , maxCharsPerField ) ) ,
431+ ) ;
410432 }
411433
412434 if ( error . stack ) {
@@ -449,12 +471,16 @@ async function renderStepSummary({
449471 return `${ lines . join ( '\n' ) } \n` ;
450472}
451473
452- function trimForSummary ( input : string ) : string {
453- if ( input . length <= STEP_SUMMARY_MAX_MESSAGE_LENGTH ) {
474+ function trimForSummary ( input : string , maxChars : number ) : string {
475+ if ( input . length <= maxChars ) {
454476 return input ;
455477 }
456478
457- return `${ input . slice ( 0 , STEP_SUMMARY_MAX_MESSAGE_LENGTH - 1 ) } …` ;
479+ if ( maxChars === 0 ) {
480+ return '' ;
481+ }
482+
483+ return `${ input . slice ( 0 , maxChars - 1 ) } …` ;
458484}
459485
460486function collectFlakyTests ( testResults : TestResult [ ] ) : TestResult [ ] {
0 commit comments