Skip to content

Commit

Permalink
Small UI updates (#2)
Browse files Browse the repository at this point in the history
* Adding command line flags (still need to cleanup some of the code)

* adds error message for missing pipe

* Adds unit test for the go side of the code

* adds go test in dockerfile

* some code refactoring and adds more test

* adds support for running go test in the CI docker file.

* adds a default to the groupSize flag

* adds test for groupSize

* some minor test updates

* more refactorings and updated test

* updated tests and added more tests

* adds shorthand flag for the title flag

* removed shortand tests

* moved the stdin checker into the main processing block

* updates to documentation and test

* added minor code-refactoring and fixing some broken test

* adds a short hand for the --groupSize flag

* adds AST parsing code to retrieve the filenames associated with test function names

* added initial code to map test names to their associated go test files.

* Adds the test file with line and col position information

* code cleanup

* added embedded assets into the binary

* updated dockerfile to fix broken build

* removed unnecessary generated code

* added verbose flag

* add total time at the end of process

* removed unneeded code

* updated readme

* adds a build script for mac, linux and windows builds

* updates release build file to create the destination folders before performing builds.

* added a little more clarity to the -groupSize usage description

* updates template to support change the html window title in addition to the title on the page

* updated readme and removed unneeded code

* nomenclature update

* added the embedded_assets.go file

* updates to the default test report template

* added the generate_embedded_go_code bash script

* moved some files around. preparing for commit to master

* moved assets to the root project folder and added test duration to the test report

* tweaked the test report template

* changes default groupSize from 10 to 20.

* small teak to the test report ui

* updated broken test

* added an ellipsis to test names that are to long

* updates the test report ui to show 'n/a' if a test was not found in the package

* Adds test execution date to test report html

* fixes date formatted problem in test execution date

* deleted jeykll file
  • Loading branch information
vakenbolt authored Jul 10, 2020
1 parent 3f6f427 commit 91e9f1a
Show file tree
Hide file tree
Showing 5 changed files with 112 additions and 88 deletions.
4 changes: 0 additions & 4 deletions _config.yml

This file was deleted.

4 changes: 2 additions & 2 deletions embedded_assets.go

Large diffs are not rendered by default.

151 changes: 78 additions & 73 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ type (
JsCode template.JS
numOfTestsPerGroup int
OutputFilename string
TestExecutionDate string
}

TestGroupData struct {
Expand Down Expand Up @@ -97,6 +98,79 @@ type (
TestFileDetailsByPackage map[string]map[string]*TestFileDetail
)

func main() {
rootCmd, _, _ := newRootCommand()
if err := rootCmd.Execute(); err != nil {
os.Exit(1)
}
}

func newRootCommand() (*cobra.Command, *TemplateData, *cmdFlags) {
flags := &cmdFlags{}
tmplData := &TemplateData{}
rootCmd := &cobra.Command{
Use: "go-test-report",
Long: "Captures go test output via stdin and parses it into a single self-contained html file.",
RunE: func(cmd *cobra.Command, args []string) error {
startTime := time.Now()
if err := parseSizeFlag(tmplData, flags); err != nil {
return err
}
tmplData.numOfTestsPerGroup = flags.groupSize
tmplData.ReportTitle = flags.titleFlag
tmplData.OutputFilename = flags.outputFlag
if err := generateTestReport(flags, tmplData, cmd); err != nil {
return errors.New(err.Error() + "\n")
}
elapsedTime := time.Since(startTime)
elapsedTimeMsg := []byte(fmt.Sprintf("[go-test-report] finished in %s\n", elapsedTime))
if _, err := cmd.OutOrStdout().Write(elapsedTimeMsg); err != nil {
return err
}
return nil
},
}
versionCmd := &cobra.Command{
Use: "version",
Short: "Prints the version number of go-test-report",
RunE: func(cmd *cobra.Command, args []string) error {
msg := fmt.Sprintf("go-test-report v%s", version)
if _, err := fmt.Fprintln(cmd.OutOrStdout(), msg); err != nil {
return err
}
return nil
},
}
rootCmd.AddCommand(versionCmd)
rootCmd.PersistentFlags().StringVarP(&flags.titleFlag,
"title",
"t",
"go-test-report",
"the title text shown in the test report")
rootCmd.PersistentFlags().StringVarP(&flags.sizeFlag,
"size",
"s",
"24",
"the size (in pixels) of the clickable indicator for test result groups")
rootCmd.PersistentFlags().IntVarP(&flags.groupSize,
"groupSize",
"g",
20,
"the number of tests per test group indicator")
rootCmd.PersistentFlags().StringVarP(&flags.outputFlag,
"output",
"o",
"test_report.html",
"the HTML output file")
rootCmd.PersistentFlags().BoolVarP(&flags.verbose,
"verbose",
"v",
false,
"while processing, show the complete output from go test ")

return rootCmd, tmplData, flags
}

func generateTestReport(flags *cmdFlags, tmplData *TemplateData, cmd *cobra.Command) error {
stdin := os.Stdin
if err := checkIfStdinIsPiped(); err != nil {
Expand Down Expand Up @@ -215,6 +289,10 @@ func generateTestReport(flags *cmdFlags, tmplData *TemplateData, cmd *cobra.Comm
}
tmplData.NumOfTests = tmplData.NumOfTestPassed + tmplData.NumOfTestFailed
tmplData.TestDuration = elapsedTestTime.Round(time.Millisecond)
td := time.Now()
tmplData.TestExecutionDate = fmt.Sprintf("%s %d, %d %02d:%02d:%02d",
td.Month(), td.Day(), td.Year(), td.Hour(), td.Minute(), td.Second())

err = tpl.Execute(w, tmplData)
}
return nil
Expand Down Expand Up @@ -309,76 +387,3 @@ func checkIfStdinIsPiped() error {
return errors.New("ERROR: missing ≪ stdin ≫ pipe")
}
}

func newRootCommand() (*cobra.Command, *TemplateData, *cmdFlags) {
flags := &cmdFlags{}
tmplData := &TemplateData{}
rootCmd := &cobra.Command{
Use: "go-test-report",
Long: "Captures go test output via stdin and parses it into a single self-contained html file.",
RunE: func(cmd *cobra.Command, args []string) error {
startTime := time.Now()
if err := parseSizeFlag(tmplData, flags); err != nil {
return err
}
tmplData.numOfTestsPerGroup = flags.groupSize
tmplData.ReportTitle = flags.titleFlag
tmplData.OutputFilename = flags.outputFlag
if err := generateTestReport(flags, tmplData, cmd); err != nil {
return errors.New(err.Error() + "\n")
}
elapsedTime := time.Since(startTime)
elapsedTimeMsg := []byte(fmt.Sprintf("[go-test-report] finished in %s\n", elapsedTime))
if _, err := cmd.OutOrStdout().Write(elapsedTimeMsg); err != nil {
return err
}
return nil
},
}
versionCmd := &cobra.Command{
Use: "version",
Short: "Prints the version number of go-test-report",
RunE: func(cmd *cobra.Command, args []string) error {
msg := fmt.Sprintf("go-test-report v%s", version)
if _, err := fmt.Fprintln(cmd.OutOrStdout(), msg); err != nil {
return err
}
return nil
},
}
rootCmd.AddCommand(versionCmd)
rootCmd.PersistentFlags().StringVarP(&flags.titleFlag,
"title",
"t",
"go-test-report",
"the title text shown in the test report")
rootCmd.PersistentFlags().StringVarP(&flags.sizeFlag,
"size",
"s",
"24",
"the size (in pixels) of the clickable indicator for test result groups")
rootCmd.PersistentFlags().IntVarP(&flags.groupSize,
"groupSize",
"g",
10,
"the number of tests per test group indicator")
rootCmd.PersistentFlags().StringVarP(&flags.outputFlag,
"output",
"o",
"test_report.html",
"the HTML output file")
rootCmd.PersistentFlags().BoolVarP(&flags.verbose,
"verbose",
"v",
false,
"while processing, show the complete output from go test ")

return rootCmd, tmplData, flags
}

func main() {
rootCmd, _, _ := newRootCommand()
if err := rootCmd.Execute(); err != nil {
os.Exit(1)
}
}
27 changes: 23 additions & 4 deletions test_report.html.template
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,16 @@
margin: 16px 32px 8px 40px;
font-size: 0.9em;
color: darkgrey;
display: block;
display: inline-block;
}

div.pageHeader .testExecutionDate {
display: inline-block;
position: absolute;
right: 10px;
margin: 14px 32px 8px 40px;
color: #9e9e9e;
font-size: 1.1em;
}

.testReportContainer {
Expand All @@ -89,6 +98,12 @@
background-color: #43c143;
margin-left: 1px;
margin-bottom: 1px;
box-sizing: border-box;
}

.testResultGroup.selected {
border: 1px white solid;
background-color: black !important;
}

.testResultGroup.failed {
Expand Down Expand Up @@ -117,8 +132,8 @@
color: #139e13;
padding: 0 4px 0 24px;
position: relative;
top: 2px;
pointer-events: none;
top: -11px;
pointer-events: none
}

.cardContainer.testGroupList .testGroupRow span.testStatus.failed {
Expand All @@ -127,10 +142,13 @@

.cardContainer.testGroupList .testGroupRow span.testTitle {
font-size: 0.9em;
padding: 12px 0px 12px;
padding: 12px 0 10px;
display: inline-block;
pointer-events: none;
color: #525252;
text-overflow: ellipsis;
overflow: hidden;
width: calc(100% - 110px);
}

.cardContainer.testGroupList .testGroupRow span.testDuration {
Expand Down Expand Up @@ -199,6 +217,7 @@
</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>
</div>
<div class="testReportContainer">
<div class="cardContainer">
Expand Down
14 changes: 9 additions & 5 deletions test_report.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ window.GoTestReport = function (elements) {
}
if (selectedItems.testResults != null) {
let testResultsElement = /**@type {HTMLElement}*/ selectedItems.testResults
testResultsElement.classList.remove("selected")
testResultsElement.style.backgroundColor = selectedItems.selectedTestGroupColor
}
const testGroupId = /**@type {number}*/ target.id
Expand All @@ -90,7 +91,7 @@ window.GoTestReport = function (elements) {
let testGroupList = /**@type {string}*/ ''
selectedItems.selectedTestGroupColor = getComputedStyle(target).getPropertyValue('background-color')
selectedItems.testResults = target
target.style.backgroundColor = 'black'
target.classList.add("selected")
for (let i = 0; i < testResults.length; i++) {
const testResult = /**@type {TestGroupData}*/ testResults[i]
const testPassed = /**@type {boolean}*/ testResult.Passed
Expand Down Expand Up @@ -139,10 +140,13 @@ window.GoTestReport = function (elements) {
packageNameDiv.innerHTML = `<strong>Package:</strong> ${testStatus.Package}`
const testFileNameDiv = document.createElement('div')
testFileNameDiv.classList.add('filename')
testFileNameDiv.innerHTML = `<strong>Filename:</strong> ${testStatus.TestFileName} &nbsp;&nbsp;`
testFileNameDiv.innerHTML += `<strong>Line:</strong> ${testStatus.TestFunctionDetail.Line} `
testFileNameDiv.innerHTML += `<strong>Col:</strong> ${testStatus.TestFunctionDetail.Col}`

if (testStatus.TestFileName.trim() === "") {
testFileNameDiv.innerHTML = `<strong>Filename:</strong> n/a &nbsp;&nbsp;`
} else {
testFileNameDiv.innerHTML = `<strong>Filename:</strong> ${testStatus.TestFileName} &nbsp;&nbsp;`
testFileNameDiv.innerHTML += `<strong>Line:</strong> ${testStatus.TestFunctionDetail.Line} `
testFileNameDiv.innerHTML += `<strong>Col:</strong> ${testStatus.TestFunctionDetail.Col}`
}
testDetailDiv.insertAdjacentElement('beforeend', packageNameDiv)
testDetailDiv.insertAdjacentElement('beforeend', testFileNameDiv)
testOutputDiv.insertAdjacentElement('afterbegin', consoleSpan)
Expand Down

0 comments on commit 91e9f1a

Please sign in to comment.