@@ -33,7 +33,8 @@ var RunTestsCmd = &cobra.Command{
3333 timeout , _ := cmd .Flags ().GetDuration ("timeout" )
3434 tags , _ := cmd .Flags ().GetStringArray ("tags" )
3535 useRace , _ := cmd .Flags ().GetBool ("race" )
36- outputPath , _ := cmd .Flags ().GetString ("output-json" )
36+ mainReportPath , _ := cmd .Flags ().GetString ("main-report-path" )
37+ rerunReportPath , _ := cmd .Flags ().GetString ("rerun-report-path" )
3738 minPassRatio , _ := cmd .Flags ().GetFloat64 ("min-pass-ratio" )
3839 // For backward compatibility, check if max-pass-ratio was used
3940 maxPassRatio , _ := cmd .Flags ().GetFloat64 ("max-pass-ratio" )
@@ -102,51 +103,47 @@ var RunTestsCmd = &cobra.Command{
102103 FailFast : failFast ,
103104 }
104105
105- // Run the tests
106106 var (
107- firstReport * reports.TestReport
107+ mainReport * reports.TestReport // Main test report
108+ rerunReport * reports.TestReport // Test report after rerunning failed tests
108109 )
109110
111+ // Run the tests
110112 var err error
111113 if len (testCmdStrings ) > 0 {
112- firstReport , err = testRunner .RunTestCmd (testCmdStrings )
114+ mainReport , err = testRunner .RunTestCmd (testCmdStrings )
113115 if err != nil {
114116 log .Fatal ().Err (err ).Msg ("Error running custom test command" )
115117 os .Exit (ErrorExitCode )
116118 }
117119 } else {
118- firstReport , err = testRunner .RunTestPackages (testPackages )
120+ mainReport , err = testRunner .RunTestPackages (testPackages )
119121 if err != nil {
120122 log .Fatal ().Err (err ).Msg ("Error running test packages" )
121123 os .Exit (ErrorExitCode )
122124 }
123125 }
124126
125- // Save the test results in JSON format
126- if outputPath != "" && len (firstReport .Results ) > 0 {
127- jsonData , err := json .MarshalIndent (firstReport , "" , " " )
128- if err != nil {
129- log .Error ().Err (err ).Msg ("Error marshaling test results to JSON" )
130- os .Exit (ErrorExitCode )
131- }
132- if err := os .WriteFile (outputPath , jsonData , 0600 ); err != nil {
133- log .Error ().Err (err ).Msg ("Error writing test results to file" )
127+ // Save the main test report to file
128+ if mainReportPath != "" && len (mainReport .Results ) > 0 {
129+ if err := mainReport .SaveToFile (mainReportPath ); err != nil {
130+ log .Error ().Err (err ).Msg ("Error saving test results to file" )
134131 os .Exit (ErrorExitCode )
135132 }
136- log .Info ().Str ("path" , outputPath ).Msg ("Test results saved" )
133+ log .Info ().Str ("path" , mainReportPath ).Msg ("Main test report saved" )
137134 }
138135
139- if len (firstReport .Results ) == 0 {
136+ if len (mainReport .Results ) == 0 {
140137 log .Warn ().Msg ("No tests were run for the specified packages" )
141138 return
142139 }
143140
144141 fmt .Printf ("\n Flakeguard Initial Summary:\n " )
145- reports .RenderResults (os .Stdout , firstReport , false , false )
142+ reports .RenderResults (os .Stdout , mainReport , false , false )
146143
147144 // Rerun failed tests
148145 if rerunFailed > 0 {
149- rerunReport , err : = testRunner .RerunFailedTests (firstReport .Results )
146+ rerunReport , err = testRunner .RerunFailedTests (mainReport .Results )
150147 if err != nil {
151148 log .Fatal ().Err (err ).Msg ("Error rerunning failed tests" )
152149 os .Exit (ErrorExitCode )
@@ -159,6 +156,15 @@ var RunTestsCmd = &cobra.Command{
159156 fmt .Printf ("\n Flakeguard Rerun Summary:\n " )
160157 reports .RenderResults (os .Stdout , rerunReport , false , false )
161158
159+ // Save the rerun test report to file
160+ if rerunReportPath != "" && len (mainReport .Results ) > 0 {
161+ if err := rerunReport .SaveToFile (rerunReportPath ); err != nil {
162+ log .Error ().Err (err ).Msg ("Error saving test results to file" )
163+ os .Exit (ErrorExitCode )
164+ }
165+ log .Info ().Str ("path" , rerunReportPath ).Msg ("Main test report saved" )
166+ }
167+
162168 if len (failedAfterRerun ) > 0 {
163169 log .Error ().
164170 Int ("tests" , len (failedAfterRerun )).
@@ -169,23 +175,21 @@ var RunTestsCmd = &cobra.Command{
169175 log .Info ().Msg ("Failed tests passed at least once after reruns" )
170176 os .Exit (0 )
171177 }
172-
173- // TODO: save rerun test report to JSON file
174- }
175-
176- // Filter flaky tests using FilterTests
177- flakyTests := reports .FilterTests (firstReport .Results , func (tr reports.TestResult ) bool {
178- return ! tr .Skipped && tr .PassRatio < passRatioThreshold
179- })
180-
181- if len (flakyTests ) > 0 {
182- log .Info ().
183- Int ("count" , len (flakyTests )).
184- Str ("stability threshold" , fmt .Sprintf ("%.0f%%" , passRatioThreshold * 100 )).
185- Msg ("Found flaky tests" )
186- os .Exit (FlakyTestsExitCode )
187178 } else {
188- log .Info ().Msg ("All tests passed stability requirements" )
179+ // Filter flaky tests using FilterTests
180+ flakyTests := reports .FilterTests (mainReport .Results , func (tr reports.TestResult ) bool {
181+ return ! tr .Skipped && tr .PassRatio < passRatioThreshold
182+ })
183+
184+ if len (flakyTests ) > 0 {
185+ log .Info ().
186+ Int ("count" , len (flakyTests )).
187+ Str ("stability threshold" , fmt .Sprintf ("%.0f%%" , passRatioThreshold * 100 )).
188+ Msg ("Found flaky tests" )
189+ os .Exit (FlakyTestsExitCode )
190+ } else {
191+ log .Info ().Msg ("All tests passed stability requirements" )
192+ }
189193 }
190194 },
191195}
@@ -205,7 +209,8 @@ func init() {
205209 RunTestsCmd .Flags ().Bool ("shuffle" , false , "Enable test shuffling" )
206210 RunTestsCmd .Flags ().String ("shuffle-seed" , "" , "Set seed for test shuffling. Must be used with --shuffle" )
207211 RunTestsCmd .Flags ().Bool ("fail-fast" , false , "Stop on the first test failure" )
208- RunTestsCmd .Flags ().String ("output-json" , "" , "Path to output the test results in JSON format" )
212+ RunTestsCmd .Flags ().String ("main-report-path" , "" , "Path to the main test report in JSON format" )
213+ RunTestsCmd .Flags ().String ("rerun-report-path" , "" , "Path to the rerun test report in JSON format" )
209214 RunTestsCmd .Flags ().StringSlice ("skip-tests" , nil , "Comma-separated list of test names to skip from running" )
210215 RunTestsCmd .Flags ().StringSlice ("select-tests" , nil , "Comma-separated list of test names to specifically run" )
211216
0 commit comments