|
1 | 1 | package cmd |
2 | 2 |
|
3 | 3 | import ( |
| 4 | + "encoding/json" |
4 | 5 | "fmt" |
5 | 6 | "path/filepath" |
6 | 7 | "strings" |
@@ -114,6 +115,19 @@ var ReportCmd = &cobra.Command{ |
114 | 115 | s.Stop() |
115 | 116 | fmt.Println("GitHub summary markdown generated successfully.") |
116 | 117 |
|
| 118 | + // Generate all-tests-summary.json |
| 119 | + s = spinner.New(spinner.CharSets[11], 100*time.Millisecond) |
| 120 | + s.Suffix = " Generating all-tests-summary.json..." |
| 121 | + s.Start() |
| 122 | + |
| 123 | + err = generateAllTestsSummaryJSON(aggregatedReport, filepath.Join(outputDir, "all-tests-summary.json"), reportMaxPassRatio) |
| 124 | + if err != nil { |
| 125 | + s.Stop() |
| 126 | + return fmt.Errorf("error generating all-tests-summary.json: %w", err) |
| 127 | + } |
| 128 | + s.Stop() |
| 129 | + fmt.Println("all-tests-summary.json generated successfully.") |
| 130 | + |
117 | 131 | if generatePRComment { |
118 | 132 | // Retrieve required flags |
119 | 133 | currentBranch, _ := cmd.Flags().GetString("current-branch") |
@@ -235,6 +249,29 @@ func generatePRCommentMarkdown(report *reports.TestReport, outputPath, baseBranc |
235 | 249 | return nil |
236 | 250 | } |
237 | 251 |
|
| 252 | +// New function to generate all-tests-summary.json |
| 253 | +func generateAllTestsSummaryJSON(report *reports.TestReport, outputPath string, maxPassRatio float64) error { |
| 254 | + summary := reports.GenerateSummaryData(report.Results, maxPassRatio) |
| 255 | + data, err := json.Marshal(summary) |
| 256 | + if err != nil { |
| 257 | + return fmt.Errorf("error marshaling summary data to JSON: %w", err) |
| 258 | + } |
| 259 | + |
| 260 | + fs := reports.OSFileSystem{} |
| 261 | + jsonFile, err := fs.Create(outputPath) |
| 262 | + if err != nil { |
| 263 | + return fmt.Errorf("error creating all-tests-summary.json file: %w", err) |
| 264 | + } |
| 265 | + defer jsonFile.Close() |
| 266 | + |
| 267 | + _, err = jsonFile.Write(data) |
| 268 | + if err != nil { |
| 269 | + return fmt.Errorf("error writing summary data to all-tests-summary.json: %w", err) |
| 270 | + } |
| 271 | + |
| 272 | + return nil |
| 273 | +} |
| 274 | + |
238 | 275 | // Helper functions to retrieve original outputs and package outputs |
239 | 276 | func getOriginalOutputs(reports []*reports.TestReport, testName, testPackage string) []string { |
240 | 277 | for _, report := range reports { |
|
0 commit comments