@@ -10,10 +10,11 @@ import (
1010 "golang.org/x/text/message"
1111)
1212
13- // GenerateFlakyTestsTable generates a table of flaky tests from the given test report to print to the console or markdown .
14- func GenerateFlakyTestsTable (
15- testReport * TestReport ,
13+ // generateTestTable is a helper that builds the table based on the given filter function .
14+ func generateTestTable (
15+ testReport TestReport ,
1616 markdown bool ,
17+ filter func (result TestResult ) bool ,
1718) [][]string {
1819 p := message .NewPrinter (language .English )
1920
@@ -45,8 +46,7 @@ func GenerateFlakyTestsTable(
4546 table := [][]string {headers }
4647
4748 for _ , result := range testReport .Results {
48- // Exclude skipped tests and only include tests below the expected pass ratio
49- if ! result .Skipped && result .PassRatio < testReport .MaxPassRatio {
49+ if filter (result ) {
5050 row := []string {
5151 result .TestName ,
5252 formatRatio (result .PassRatio ),
@@ -75,8 +75,30 @@ func GenerateFlakyTestsTable(
7575 return table
7676}
7777
78+ // GenerateFlakyTestsTable returns a table with only the flaky tests.
79+ func GenerateFlakyTestsTable (
80+ testReport TestReport ,
81+ markdown bool ,
82+ ) [][]string {
83+ return generateTestTable (testReport , markdown , func (result TestResult ) bool {
84+ return ! result .Skipped && result .PassRatio < testReport .MaxPassRatio
85+ })
86+ }
87+
88+ // PrintTestTable prints a table with all test results.
89+ func PrintTestTable (
90+ w io.Writer ,
91+ testReport TestReport ,
92+ markdown bool ,
93+ collapsible bool ) {
94+ table := generateTestTable (testReport , markdown , func (result TestResult ) bool {
95+ return true // Include all tests
96+ })
97+ printTable (w , table , collapsible )
98+ }
99+
78100// GenerateGitHubSummaryMarkdown generates a markdown summary of the test results for a GitHub workflow summary
79- func GenerateGitHubSummaryMarkdown (w io.Writer , testReport * TestReport , maxPassRatio float64 , artifactName , artifactLink string ) {
101+ func GenerateGitHubSummaryMarkdown (w io.Writer , testReport TestReport , maxPassRatio float64 , artifactName , artifactLink string ) {
80102 fmt .Fprint (w , "# Flakeguard Summary\n \n " )
81103
82104 if len (testReport .Results ) == 0 {
@@ -109,7 +131,7 @@ func GenerateGitHubSummaryMarkdown(w io.Writer, testReport *TestReport, maxPassR
109131// GeneratePRCommentMarkdown generates a markdown summary of the test results for a GitHub PR comment.
110132func GeneratePRCommentMarkdown (
111133 w io.Writer ,
112- testReport * TestReport ,
134+ testReport TestReport ,
113135 maxPassRatio float64 ,
114136 baseBranch , currentBranch , currentCommitSHA , repoURL , actionRunID , artifactName , artifactLink string ,
115137) {
@@ -156,7 +178,7 @@ func GeneratePRCommentMarkdown(
156178 }
157179}
158180
159- func buildSettingsTable (testReport * TestReport , maxPassRatio float64 ) [][]string {
181+ func buildSettingsTable (testReport TestReport , maxPassRatio float64 ) [][]string {
160182 rows := [][]string {
161183 {"**Setting**" , "**Value**" },
162184 }
@@ -190,7 +212,7 @@ func RenderError(
190212// If in markdown mode, the table results can also be made collapsible.
191213func RenderResults (
192214 w io.Writer ,
193- testReport * TestReport ,
215+ testReport TestReport ,
194216 markdown bool ,
195217 collapsible bool ,
196218) {
0 commit comments