github.com/fnando/bolt@v0.0.4-0.20231107225351-5241e4d187b8/internal/reporters/json_reporter.go (about) 1 package reporters 2 3 import ( 4 "encoding/json" 5 "fmt" 6 7 c "github.com/fnando/bolt/common" 8 ) 9 10 type JSONReporter struct { 11 Output *c.Output 12 } 13 14 type JSONData struct { 15 Coverage []*c.Coverage 16 Tests []*c.Test 17 Benchmarks []*c.Benchmark 18 Elapsed float64 19 } 20 21 func (reporter JSONReporter) Name() string { 22 return "json" 23 } 24 25 func (reporter JSONReporter) OnFinished(options ReporterFinishedOptions) { 26 data := JSONData{ 27 Coverage: options.Aggregation.Coverages(), 28 Tests: options.Aggregation.Tests(), 29 Benchmarks: options.Aggregation.Benchmarks(), 30 Elapsed: float64(options.Aggregation.Elapsed()), 31 } 32 contents, _ := json.MarshalIndent(data, "", " ") 33 fmt.Fprintln(reporter.Output.Stdout, string(contents)) 34 } 35 36 func (reporter JSONReporter) OnProgress(test c.Test) { 37 } 38 39 func (reporter JSONReporter) OnData(line string) { 40 }