11import { Envelope , TestRunFinished , TestRunStarted , TestStepResultStatus } from '@cucumber/messages'
22import { Query } from '@cucumber/query'
33
4- import { formatCounts , formatDuration } from './helpers.js'
4+ import { formatCounts , formatDuration , formatSnippets } from './helpers.js'
55import type { Options } from './types.js'
66
77export class SummaryPrinter {
@@ -25,6 +25,11 @@ export class SummaryPrinter {
2525 }
2626
2727 private printSummary ( ) {
28+ this . printStats ( )
29+ this . printSnippets ( )
30+ }
31+
32+ private printStats ( ) {
2833 this . println ( )
2934 this . printGlobalHookCounts ( )
3035 this . printScenarioCounts ( )
@@ -92,4 +97,22 @@ export class SummaryPrinter {
9297
9398 this . println ( formatDuration ( testRunStarted . timestamp , testRunFinished . timestamp ) )
9499 }
100+
101+ private printSnippets ( ) {
102+ const snippets = this . query
103+ . findAllTestCaseFinished ( )
104+ . map ( ( testCaseFinished ) => this . query . findPickleBy ( testCaseFinished ) )
105+ . filter ( ( pickle ) => ! ! pickle )
106+ . sort ( ( a , b ) => {
107+ // TODO compare by location too
108+ return a ?. uri . localeCompare ( b ?. uri || '' ) || 0
109+ } )
110+ . flatMap ( ( pickle ) => this . query . findSuggestionsBy ( pickle ) )
111+ . flatMap ( ( suggestion ) => suggestion . snippets )
112+ . map ( ( snippet ) => snippet . code )
113+ const uniqueSnippets = new Set ( snippets )
114+ if ( snippets . length > 0 ) {
115+ this . println ( formatSnippets ( uniqueSnippets ) )
116+ }
117+ }
95118}
0 commit comments