Skip to content

Commit 2665e93

Browse files
committed
fix: reporter elapsed parsing
gotest elapsed uses seconds but ctrf duration uses milliseconds
1 parent a656573 commit 2665e93

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

ctrf/ctrf.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ const (
186186
type TestResult struct {
187187
Name string `json:"name"`
188188
Status TestStatus `json:"status"`
189-
Duration float64 `json:"duration"`
189+
Duration int64 `json:"duration"`
190190
Start int64 `json:"start,omitempty"`
191191
Stop int64 `json:"stop,omitempty"`
192192
Suite string `json:"suite,omitempty"`

reporter/reporter.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,23 +49,23 @@ func ParseTestResults(r io.Reader, verbose bool, env *ctrf.Environment) (*ctrf.R
4949
report.Results.Tests = append(report.Results.Tests, &ctrf.TestResult{
5050
Name: event.Test,
5151
Status: ctrf.TestPassed,
52-
Duration: event.Elapsed,
52+
Duration: secondsToMillis(event.Elapsed),
5353
})
5454
} else if event.Action == "fail" {
5555
report.Results.Summary.Tests++
5656
report.Results.Summary.Failed++
5757
report.Results.Tests = append(report.Results.Tests, &ctrf.TestResult{
5858
Name: event.Test,
5959
Status: ctrf.TestFailed,
60-
Duration: event.Elapsed,
60+
Duration: secondsToMillis(event.Elapsed),
6161
})
6262
} else if event.Action == "skip" {
6363
report.Results.Summary.Tests++
6464
report.Results.Summary.Skipped++
6565
report.Results.Tests = append(report.Results.Tests, &ctrf.TestResult{
6666
Name: event.Test,
6767
Status: ctrf.TestSkipped,
68-
Duration: event.Elapsed,
68+
Duration: secondsToMillis(event.Elapsed),
6969
})
7070
}
7171
}
@@ -83,3 +83,7 @@ func WriteReportToFile(filename string, report *ctrf.Report) error {
8383
fmt.Println("go-ctrf-json-reporter: successfully written ctrf json to", filename)
8484
return nil
8585
}
86+
87+
func secondsToMillis(seconds float64) int64 {
88+
return int64(seconds * 1000)
89+
}

0 commit comments

Comments
 (0)