Skip to content

Commit

Permalink
Show skipped tests in gray color (vakenbolt#12)
Browse files Browse the repository at this point in the history
* Show skipped tests in gray color

Instead of showing the skipped tests as failed (not passed),
display them separately (using dimmed gray, not green or red).

* Add generated embedded assets file
  • Loading branch information
afbjorklund authored Apr 26, 2021
1 parent 46f9a36 commit f5fd116
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 13 deletions.
4 changes: 2 additions & 2 deletions embedded_assets.go

Large diffs are not rendered by default.

20 changes: 16 additions & 4 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ type (
ElapsedTime float64
Output []string
Passed bool
Skipped bool
TestFileName string
TestFunctionDetail testFunctionFilePos
}
Expand All @@ -49,6 +50,7 @@ type (
TestResults []*testGroupData
NumOfTestPassed int
NumOfTestFailed int
NumOfTestSkipped int
NumOfTests int
TestDuration time.Duration
ReportTitle string
Expand All @@ -60,6 +62,7 @@ type (

testGroupData struct {
FailureIndicator string
SkippedIndicator string
TestResults []*testStatus
}

Expand Down Expand Up @@ -226,10 +229,13 @@ func readTestDataFromStdIn(stdinScanner *bufio.Scanner, flags *cmdFlags, cmd *co
} else {
status = allTests[goTestOutputRow.TestName]
}
if goTestOutputRow.Action == "pass" || goTestOutputRow.Action == "fail" {
if goTestOutputRow.Action == "pass" || goTestOutputRow.Action == "fail" || goTestOutputRow.Action == "skip" {
if goTestOutputRow.Action == "pass" {
status.Passed = true
}
if goTestOutputRow.Action == "skip" {
status.Skipped = true
}
status.ElapsedTime = goTestOutputRow.Elapsed
}
allPackageNames[goTestOutputRow.Package] = nil
Expand Down Expand Up @@ -309,6 +315,7 @@ func generateReport(tmplData *templateData, allTests map[string]*testStatus, tes

tmplData.NumOfTestPassed = 0
tmplData.NumOfTestFailed = 0
tmplData.NumOfTestSkipped = 0
tmplData.JsCode = template.JS(testReportJsCodeStr)
tgCounter := 0
tgID := 0
Expand All @@ -332,8 +339,13 @@ func generateReport(tmplData *templateData, allTests map[string]*testStatus, tes
}
tmplData.TestResults[tgID].TestResults = append(tmplData.TestResults[tgID].TestResults, status)
if !status.Passed {
tmplData.TestResults[tgID].FailureIndicator = "failed"
tmplData.NumOfTestFailed++
if (!status.Skipped) {
tmplData.TestResults[tgID].FailureIndicator = "failed"
tmplData.NumOfTestFailed++
} else {
tmplData.TestResults[tgID].SkippedIndicator = "skipped"
tmplData.NumOfTestSkipped++
}
} else {
tmplData.NumOfTestPassed++
}
Expand All @@ -343,7 +355,7 @@ func generateReport(tmplData *templateData, allTests map[string]*testStatus, tes
tgID++
}
}
tmplData.NumOfTests = tmplData.NumOfTestPassed + tmplData.NumOfTestFailed
tmplData.NumOfTests = tmplData.NumOfTestPassed + tmplData.NumOfTestFailed + tmplData.NumOfTestSkipped
tmplData.TestDuration = elapsedTestTime.Round(time.Millisecond)
td := time.Now()
tmplData.TestExecutionDate = fmt.Sprintf("%s %d, %d %02d:%02d:%02d",
Expand Down
13 changes: 12 additions & 1 deletion main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,16 @@ func TestGenerateReport(t *testing.T) {
TestFileName: "",
TestFunctionDetail: testFunctionFilePos{},
}
allTests["TestFunc4"] = &testStatus{
TestName: "TestFunc4",
Package: "go-test-report",
ElapsedTime: 0,
Output: nil,
Passed: false,
Skipped: true,
TestFileName: "",
TestFunctionDetail: testFunctionFilePos{},
}
testFileDetailsByPackage := testFileDetailsByPackage{}
testFileDetailsByPackage["go-test-report"] = map[string]*testFileDetail{}
testFileDetailsByPackage["go-test-report"]["TestFunc1"] = &testFileDetail{
Expand Down Expand Up @@ -270,7 +280,8 @@ func TestGenerateReport(t *testing.T) {
assertions.Nil(err)
assertions.Equal(2, tmplData.NumOfTestPassed)
assertions.Equal(1, tmplData.NumOfTestFailed)
assertions.Equal(3, tmplData.NumOfTests)
assertions.Equal(1, tmplData.NumOfTestSkipped)
assertions.Equal(4, tmplData.NumOfTests)

assertions.Equal("TestFunc1", tmplData.TestResults[0].TestResults[0].TestName)
assertions.Equal("go-test-report", tmplData.TestResults[0].TestResults[0].Package)
Expand Down
29 changes: 26 additions & 3 deletions test_report.html.template
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@
background: #6fca83;
}

div.pageHeader div.testStats span.skipped {
background: #bababa;
}

div.pageHeader div.testStats span.failed {
background: #ff7676;
}
Expand Down Expand Up @@ -106,6 +110,10 @@
background-color: black !important;
}

.testResultGroup.skipped {
border: 2px gray solid;
}

.testResultGroup.failed {
background-color: red;
}
Expand Down Expand Up @@ -136,6 +144,10 @@
pointer-events: none
}

.cardContainer.testGroupList .testGroupRow span.testStatus.skipped {
color: gray;
}

.cardContainer.testGroupList .testGroupRow span.testStatus.failed {
color: red;
}
Expand All @@ -160,6 +172,11 @@
border-left: 4px #43c143 solid;
}

.cardContainer.testGroupList .testGroupRow.skipped {
color: gray;
border-left: 4px gray solid;
}

.cardContainer.testGroupList .testGroupRow.failed {
color: red;
border-left: 4px red solid;
Expand Down Expand Up @@ -194,6 +211,10 @@
font-size: 0.8em;
}

.cardContainer .console.skipped{
color: #d9d9d9;
}

.cardContainer .console.failed {
color: #ffb2b2;
}
Expand All @@ -214,7 +235,9 @@
<div class="testStats">
<span class="total"><span class="indicator">&boxbox;</span> Total: <strong>{{.NumOfTests}}</strong>Duration: <strong>{{.TestDuration}}</strong>
</span><span class="passed"><span class="indicator">&check;</span> Passed: <strong>{{.NumOfTestPassed}}</strong>
</span><span class="failed"><span class="indicator">&cross;</span> Failed: <strong>{{.NumOfTestFailed}}</strong></span>
</span><span class="skipped"><span class="indicator">&dash;</span> Skipped: <strong>{{.NumOfTestSkipped}}</strong>
</span><span class="failed"><span class="indicator">&cross;</span> Failed: <strong>{{.NumOfTestFailed}}</strong>
</span>
</div>
<span class="testGroupsTitle">Test Groups:</span>
<span class="testExecutionDate">{{.TestExecutionDate}}</span>
Expand All @@ -223,7 +246,7 @@
<div class="cardContainer">
<div id="testResults">
{{range $k, $v := .TestResults}}
<div class="testResultGroup {{.FailureIndicator}}" id="{{$k}}"></div>
<div class="testResultGroup {{.FailureIndicator}} {{.SkippedIndicator}}" id="{{$k}}"></div>
{{end}}
</div>
</div>
Expand All @@ -246,4 +269,4 @@

</script>
</body>
</html>
</html>
14 changes: 11 additions & 3 deletions test_report.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@
* @property {number} ElapsedTime
* @property {Array.<string>} Output
* @property {boolean} Passed
* @property {boolean} Skipped
*/
class TestStatus {}

/**
* @typedef TestGroupData
* @type {object}
* @property {string} FailureIndicator
* @property {string} SkippedIndicator
* @property {Array.<TestStatus>}
*/
class TestGroupData {}
Expand Down Expand Up @@ -95,10 +97,11 @@ window.GoTestReport = function (elements) {
for (let i = 0; i < testResults.length; i++) {
const testResult = /**@type {TestGroupData}*/ testResults[i]
const testPassed = /**@type {boolean}*/ testResult.Passed
const testPassedStatus = /**@type {string}*/ (testPassed) ? '' : 'failed'
const testSkipped = /**@type {boolean}*/ testResult.Skipped
const testPassedStatus = /**@type {string}*/ (testPassed) ? '' : (testSkipped ? 'skipped' : 'failed')
const testId = /**@type {string}*/ target.attributes['id'].value
testGroupList += `<div class="testGroupRow ${testPassedStatus}" data-groupid="${testId}" data-index="${i}">
<span class="testStatus ${testPassedStatus}">${(testPassed) ? '&check' : '&cross'};</span>
<span class="testStatus ${testPassedStatus}">${(testPassed) ? '&check' : (testSkipped ? '&dash' : '&cross')};</span>
<span class="testTitle">${testResult.TestName}</span>
<span class="testDuration"><span>${testResult.ElapsedTime}s </span>⏱</span>
</div>`
Expand Down Expand Up @@ -154,8 +157,13 @@ window.GoTestReport = function (elements) {
target.insertAdjacentElement('beforeend', testOutputDiv)

if (testStatus.Passed) {
consolePre.classList.remove('skipped')
consolePre.classList.remove('failed')
} else if (testStatus.Skipped) {
consolePre.classList.add('skipped')
consolePre.classList.remove('failed')
} else {
consolePre.classList.remove('skipped')
consolePre.classList.add('failed')
}
consolePre.textContent = testStatus.Output.join('')
Expand Down Expand Up @@ -183,4 +191,4 @@ window.GoTestReport = function (elements) {
elements.data))

return goTestReport
}
}

0 comments on commit f5fd116

Please sign in to comment.