Skip to content

Commit

Permalink
Release v0.9.3 (vakenbolt#25)
Browse files Browse the repository at this point in the history
* Add Package to key to allow for duplicate Test (vakenbolt#20)

* Refactor: add variable for the allTests map key

* Add Package to key to allow for duplicate Test

* Bump hosted-git-info from 2.8.8 to 2.8.9 (vakenbolt#24)

Bumps [hosted-git-info](https://github.com/npm/hosted-git-info) from 2.8.8 to 2.8.9.
- [Release notes](https://github.com/npm/hosted-git-info/releases)
- [Changelog](https://github.com/npm/hosted-git-info/blob/v2.8.9/CHANGELOG.md)
- [Commits](npm/hosted-git-info@v2.8.8...v2.8.9)

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* Bump lodash from 4.17.20 to 4.17.21 (vakenbolt#23)

Bumps [lodash](https://github.com/lodash/lodash) from 4.17.20 to 4.17.21.
- [Release notes](https://github.com/lodash/lodash/releases)
- [Commits](lodash/lodash@4.17.20...4.17.21)

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* versioni bump

Co-authored-by: Anders Björklund <anders.f.bjorklund@gmail.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
  • Loading branch information
3 people authored May 12, 2021
1 parent ee7b463 commit 1d65f58
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 22 deletions.
35 changes: 26 additions & 9 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,15 +217,16 @@ func readTestDataFromStdIn(stdinScanner *bufio.Scanner, flags *cmdFlags, cmd *co
}
if goTestOutputRow.TestName != "" {
var status *testStatus
if _, exists := allTests[goTestOutputRow.TestName]; !exists {
key := goTestOutputRow.Package + "." + goTestOutputRow.TestName
if _, exists := allTests[key]; !exists {
status = &testStatus{
TestName: goTestOutputRow.TestName,
Package: goTestOutputRow.Package,
Output: []string{},
}
allTests[goTestOutputRow.TestName] = status
allTests[key] = status
} else {
status = allTests[goTestOutputRow.TestName]
status = allTests[key]
}
if goTestOutputRow.Action == "pass" || goTestOutputRow.Action == "fail" || goTestOutputRow.Action == "skip" {
if goTestOutputRow.Action == "pass" {
Expand Down Expand Up @@ -297,6 +298,22 @@ func getPackageDetails(allPackageNames map[string]*types.Nil) (testFileDetailsBy
return testFileDetailByPackage, nil
}

type testRef struct {
key string
name string
}
type byName []testRef

func (t byName) Len() int {
return len(t)
}
func (t byName) Swap(i, j int) {
t[i], t[j] = t[j], t[i]
}
func (t byName) Less(i, j int) bool {
return t[i].name < t[j].name
}

func generateReport(tmplData *templateData, allTests map[string]*testStatus, testFileDetailByPackage testFileDetailsByPackage, elapsedTestTime time.Duration, reportFileWriter *bufio.Writer) error {
// read the html template from the generated embedded asset go file
tpl := template.New("test_report.html.template")
Expand All @@ -322,13 +339,13 @@ func generateReport(tmplData *templateData, allTests map[string]*testStatus, tes
tgID := 0

// sort the allTests map by test name (this will produce a consistent order when iterating through the map)
var testNames []string
for test := range allTests {
testNames = append(testNames, test)
var tests []testRef
for test, status := range allTests {
tests = append(tests, testRef{test, status.TestName})
}
sort.Strings(testNames)
for _, testName := range testNames {
status := allTests[testName]
sort.Sort(byName(tests))
for _, test := range tests {
status := allTests[test.key]
if len(tmplData.TestResults) == tgID {
tmplData.TestResults = append(tmplData.TestResults, &testGroupData{})
}
Expand Down
34 changes: 28 additions & 6 deletions main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,11 +168,11 @@ func TestReadTestDataFromStdIn(t *testing.T) {
assertions.Contains(allPackageNames, "go-test-report")
assertions.Contains(allPackageNames, "package2")
assertions.Len(allTests, 3)
assertions.Contains(allTests, "TestFunc1")
assertions.Contains(allTests, "TestFunc2")
assertions.Contains(allTests, "TestFunc3")
assertions.Contains(allTests, "go-test-report.TestFunc1")
assertions.Contains(allTests, "package2.TestFunc2")
assertions.Contains(allTests, "go-test-report.TestFunc3")

val := allTests["TestFunc1"]
val := allTests["go-test-report.TestFunc1"]
assertions.True(val.Passed)
assertions.Equal("TestFunc1", val.TestName)
assertions.Equal(1.25, val.ElapsedTime)
Expand All @@ -182,7 +182,7 @@ func TestReadTestDataFromStdIn(t *testing.T) {
assertions.Equal(0, val.TestFunctionDetail.Line)
assertions.Equal(0, val.TestFunctionDetail.Col)

val = allTests["TestFunc2"]
val = allTests["package2.TestFunc2"]
assertions.True(val.Passed)
assertions.Equal("TestFunc2", val.TestName)
assertions.Equal(0.25, val.ElapsedTime)
Expand All @@ -192,7 +192,7 @@ func TestReadTestDataFromStdIn(t *testing.T) {
assertions.Equal(0, val.TestFunctionDetail.Line)
assertions.Equal(0, val.TestFunctionDetail.Col)

val = allTests["TestFunc3"]
val = allTests["go-test-report.TestFunc3"]
assertions.False(val.Passed)
assertions.Equal("TestFunc3", val.TestName)
assertions.Equal(0.00, val.ElapsedTime)
Expand Down Expand Up @@ -305,6 +305,28 @@ func TestGenerateReport(t *testing.T) {
assertions.Equal(0, tmplData.TestResults[1].TestResults[0].TestFunctionDetail.Line)
}

func TestSameTestName(t *testing.T) {
assertions := assert.New(t)
flags := &cmdFlags{}
data := `{"Time":"2020-07-10T01:24:44.269511-05:00","Action":"run","Package":"foo","Test":"Test"}
{"Time":"2020-07-10T01:24:44.270071-05:00","Action":"output","Package":"foo","Test":"Test","Output":"=== RUN Test\n"}
{"Time":"2020-07-10T01:24:44.270295-05:00","Action":"output","Package":"foo","Test":"Test","Output":"--- PASS: Test (1.5s)\n"}
{"Time":"2020-07-10T01:24:44.270311-05:00","Action":"pass","Package":"foo","Test":"Test","Elapsed":1.5}
{"Time":"2020-07-10T01:24:44.269511-05:00","Action":"run","Package":"bar","Test":"Test"}
{"Time":"2020-07-10T01:24:44.270071-05:00","Action":"output","Package":"bar","Test":"Test","Output":"=== RUN Test\n"}
{"Time":"2020-07-10T01:24:44.270295-05:00","Action":"output","Package":"bar","Test":"Test","Output":"--- FAIL: Test (0.5s)\n"}
{"Time":"2020-07-10T01:24:44.270311-05:00","Action":"fail","Package":"bar","Test":"Test","Elapsed":0.5}
`
stdinScanner := bufio.NewScanner(strings.NewReader(data))
cmd := &cobra.Command{}
allPackageNames, allTests, err := readTestDataFromStdIn(stdinScanner, flags, cmd)
assertions.Nil(err)
assertions.Len(allPackageNames, 2)
assertions.Contains(allPackageNames, "foo")
assertions.Contains(allPackageNames, "bar")
assertions.Len(allTests, 2)
}

func TestParseSizeFlagIfValueIsNotInteger(t *testing.T) {
assertions := assert.New(t)
tmplData := &templateData{}
Expand Down
12 changes: 6 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion version.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
package main

const version = "0.9.2"
const version = "0.9.3"

0 comments on commit 1d65f58

Please sign in to comment.