Skip to content

Commit

Permalink
Fix vitest parsing of times and durations (#80)
Browse files Browse the repository at this point in the history
  • Loading branch information
dustin-decker authored Sep 23, 2024
1 parent 34dc5f7 commit 5294685
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
10 changes: 5 additions & 5 deletions internal/parsing/javascript_vitest_parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ type JavaScriptVitestTaskMeta struct{}
// https://github.com/vitest-dev/vitest/blob/95f0203f27f5659f5758638edc4d1d90283801ac/packages/vitest/src/node/reporters/json.ts#L30-L39
type JavaScriptVitestAssertionResult struct {
AncestorTitles []string `json:"ancestorTitles"`
Duration *int `json:"duration"`
Duration *float64 `json:"duration"`
FailureMessages []string `json:"failureMessages"`
FullName string `json:"fullName"`
Location *JavaScriptVitestCallsite `json:"location"`
Expand All @@ -62,10 +62,10 @@ type JavaScriptVitestAssertionResult struct {
// https://github.com/vitest-dev/vitest/blob/95f0203f27f5659f5758638edc4d1d90283801ac/packages/vitest/src/node/reporters/json.ts#L41-L50
type JavaScriptVitestTestResult struct {
AssertionResults []JavaScriptVitestAssertionResult `json:"assertionResults"`
EndTime int `json:"endTime"`
EndTime float64 `json:"endTime"`
Message string `json:"message"`
Name string `json:"name"`
StartTime int `json:"startTime"`
StartTime float64 `json:"startTime"`
Status string `json:"status"`
}

Expand All @@ -81,7 +81,7 @@ type JavaScriptVitestTestResults struct {
NumTotalTests int `json:"numTotalTests"`
NumTotalTestSuites int `json:"numTotalTestSuites"`
Snapshot *JavaScriptVitestSnapshot `json:"snapshot"`
StartTime int `json:"startTime"`
StartTime float64 `json:"startTime"`
Success bool `json:"success"`
TestResults []JavaScriptVitestTestResult `json:"testResults"`
}
Expand Down Expand Up @@ -126,7 +126,7 @@ func (p JavaScriptVitestParser) Parse(data io.Reader) (*v1.TestResults, error) {

var duration *time.Duration
if assertionResult.Duration != nil {
transformedDuration := time.Duration(*assertionResult.Duration * int(time.Millisecond))
transformedDuration := time.Duration(*assertionResult.Duration * float64(time.Millisecond))
duration = &transformedDuration
}

Expand Down
6 changes: 3 additions & 3 deletions internal/parsing/javascript_vitest_parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ var _ = Describe("JavaScriptVitestParser", func() {
})

It("parses a minimally failing test", func() {
durationInMilliseconds := 653
durationInMilliseconds := 653.0
jestResults := parsing.JavaScriptVitestTestResults{
Snapshot: &parsing.JavaScriptVitestSnapshot{},
TestResults: []parsing.JavaScriptVitestTestResult{
Expand Down Expand Up @@ -101,7 +101,7 @@ var _ = Describe("JavaScriptVitestParser", func() {
})

It("parses a maximally failing test", func() {
durationInMilliseconds := 653
durationInMilliseconds := 653.0
jestResults := parsing.JavaScriptVitestTestResults{
Snapshot: &parsing.JavaScriptVitestSnapshot{},
TestResults: []parsing.JavaScriptVitestTestResult{
Expand Down Expand Up @@ -148,7 +148,7 @@ var _ = Describe("JavaScriptVitestParser", func() {
})

It("parses passed statuses", func() {
durationInMilliseconds := 653
durationInMilliseconds := 653.0
jestResults := parsing.JavaScriptVitestTestResults{
Snapshot: &parsing.JavaScriptVitestSnapshot{},
TestResults: []parsing.JavaScriptVitestTestResult{
Expand Down

0 comments on commit 5294685

Please sign in to comment.