1- import { Envelope , TestRunFinished , TestRunStarted , TestStepResultStatus } from '@cucumber/messages'
1+ import {
2+ Envelope ,
3+ Location ,
4+ Pickle ,
5+ TestRunFinished ,
6+ TestRunStarted ,
7+ TestStepResult ,
8+ TestStepResultStatus ,
9+ } from '@cucumber/messages'
210import { Query } from '@cucumber/query'
311
4- import { formatCounts , formatDuration , formatSnippets } from './helpers.js'
12+ import {
13+ ensure ,
14+ ERROR_INDENT_LENGTH ,
15+ formatCounts ,
16+ formatDuration ,
17+ formatNonPassingTitle ,
18+ formatPickleLocation ,
19+ formatTestStepResultError ,
20+ GHERKIN_INDENT_LENGTH ,
21+ indent ,
22+ } from './helpers.js'
523import type { Options } from './types.js'
624
725export class SummaryPrinter {
@@ -25,6 +43,7 @@ export class SummaryPrinter {
2543 }
2644
2745 private printSummary ( ) {
46+ this . printNonPassingScenarios ( )
2847 this . printStats ( )
2948 this . printSnippets ( )
3049 }
@@ -37,6 +56,70 @@ export class SummaryPrinter {
3756 this . printDuration ( )
3857 }
3958
59+ private printNonPassingScenarios ( ) {
60+ const theOrder : TestStepResultStatus [ ] = [
61+ TestStepResultStatus . UNKNOWN ,
62+ TestStepResultStatus . PENDING ,
63+ TestStepResultStatus . UNDEFINED ,
64+ TestStepResultStatus . AMBIGUOUS ,
65+ TestStepResultStatus . FAILED ,
66+ ]
67+
68+ const picklesByStatus = new Map <
69+ TestStepResultStatus ,
70+ Array < { pickle : Pickle ; location : Location | undefined ; testStepResult : TestStepResult } >
71+ > ( )
72+
73+ for ( const testCaseFinished of this . query . findAllTestCaseFinished ( ) ) {
74+ const pickle = ensure (
75+ this . query . findPickleBy ( testCaseFinished ) ,
76+ 'Pickle must exist for TestCaseFinished'
77+ )
78+ const location = this . query . findLocationOf ( pickle )
79+ const testStepResult = this . query . findMostSevereTestStepResultBy ( testCaseFinished )
80+ if ( testStepResult ) {
81+ if ( ! picklesByStatus . has ( testStepResult . status ) ) {
82+ picklesByStatus . set ( testStepResult . status , [ ] )
83+ }
84+ picklesByStatus . get ( testStepResult . status ) ! . push ( {
85+ pickle,
86+ location,
87+ testStepResult,
88+ } )
89+ }
90+ }
91+
92+ for ( const status of theOrder ) {
93+ const picklesForThisStatus = picklesByStatus . get ( status ) ?? [ ]
94+ if ( picklesForThisStatus . length > 0 ) {
95+ this . println ( )
96+ this . println ( formatNonPassingTitle ( status , this . options . theme , this . stream ) )
97+ picklesForThisStatus . forEach ( ( { pickle, location, testStepResult } , index ) => {
98+ const formattedLocation = formatPickleLocation (
99+ pickle ,
100+ location ,
101+ this . options . theme ,
102+ this . stream
103+ )
104+ this . println (
105+ indent ( `${ index + 1 } ) ${ pickle . name } ${ formattedLocation } ` , GHERKIN_INDENT_LENGTH )
106+ )
107+ if ( status === TestStepResultStatus . FAILED ) {
108+ const content = formatTestStepResultError (
109+ testStepResult ,
110+ this . options . theme ,
111+ this . stream
112+ )
113+ if ( content ) {
114+ this . println ( indent ( content , GHERKIN_INDENT_LENGTH + ERROR_INDENT_LENGTH + 1 ) )
115+ this . println ( )
116+ }
117+ }
118+ } )
119+ }
120+ }
121+ }
122+
40123 private printGlobalHookCounts ( ) {
41124 const testRunHookFinished = this . query . findAllTestRunHookFinished ( )
42125 if ( testRunHookFinished . length === 0 ) {
0 commit comments