Skip to content

Commit 24ffb18

Browse files
committed
print snippets
1 parent da2c4d6 commit 24ffb18

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed

javascript/src/SummaryPrinter.ts

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { Envelope, TestRunFinished, TestRunStarted, TestStepResultStatus } from '@cucumber/messages'
22
import { Query } from '@cucumber/query'
33

4-
import { formatCounts, formatDuration } from './helpers.js'
4+
import { formatCounts, formatDuration, formatSnippets } from './helpers.js'
55
import type { Options } from './types.js'
66

77
export 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
}

javascript/src/helpers.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111
PickleTable,
1212
Rule,
1313
Scenario,
14+
Snippet,
1415
Step,
1516
StepDefinition,
1617
TestRunFinished,
@@ -376,3 +377,10 @@ export function formatCounts(
376377
}
377378
return builder.build()
378379
}
380+
381+
export function formatSnippets(snippets: Set<string>) {
382+
return `
383+
You can implement missing steps with the snippets below:
384+
385+
${[...snippets].join('\n\n')}`
386+
}

0 commit comments

Comments
 (0)