@@ -20,16 +20,25 @@ import {
2020 TimeConversion ,
2121 Timestamp ,
2222} from '@cucumber/messages'
23+ import { Interval } from 'luxon'
2324
2425import { TextBuilder } from './TextBuilder.js'
2526import { Theme } from './types.js'
26- import { Interval } from 'luxon'
2727
2828export const GHERKIN_INDENT_LENGTH = 2
2929export const STEP_ARGUMENT_INDENT_LENGTH = 2
3030export const ATTACHMENT_INDENT_LENGTH = 4
3131export const ERROR_INDENT_LENGTH = 4
3232const DURATION_FORMAT = "m'm' s.S's'"
33+ const STATUS_ORDER : TestStepResultStatus [ ] = [
34+ TestStepResultStatus . UNKNOWN ,
35+ TestStepResultStatus . PASSED ,
36+ TestStepResultStatus . SKIPPED ,
37+ TestStepResultStatus . PENDING ,
38+ TestStepResultStatus . UNDEFINED ,
39+ TestStepResultStatus . AMBIGUOUS ,
40+ TestStepResultStatus . FAILED ,
41+ ]
3342const STATUS_CHARACTERS : Record < TestStepResultStatus , string > = {
3443 [ TestStepResultStatus . AMBIGUOUS ] : 'A' ,
3544 [ TestStepResultStatus . FAILED ] : 'F' ,
@@ -340,3 +349,30 @@ export function formatDuration(start: Timestamp, finish: Timestamp) {
340349 ] )
341350 return duration . toFormat ( DURATION_FORMAT )
342351}
352+
353+ export function formatCounts (
354+ suffix : string ,
355+ counts : Partial < Record < TestStepResultStatus , number > > ,
356+ theme : Theme ,
357+ stream : NodeJS . WritableStream
358+ ) {
359+ const builder = new TextBuilder ( stream )
360+ const total = Object . values ( counts ) . reduce ( ( prev , curr ) => prev + curr , 0 )
361+ builder . append ( `${ total } ${ suffix } ` )
362+ if ( total > 0 ) {
363+ let first = true
364+ builder . append ( ' (' )
365+ for ( const status of STATUS_ORDER ) {
366+ const count = counts [ status ]
367+ if ( count ) {
368+ builder . append ( `${ count } ${ status . toLowerCase ( ) } ` , theme . status ?. all ?. [ status ] )
369+ if ( ! first ) {
370+ builder . append ( ', ' )
371+ }
372+ first = false
373+ }
374+ }
375+ builder . append ( ')' )
376+ }
377+ return builder . build ( )
378+ }
0 commit comments