Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Small UI updates #2

Merged
merged 50 commits into from
Jul 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
8e471b0
Adding command line flags (still need to cleanup some of the code)
vakenbolt Jun 19, 2020
983d711
adds error message for missing pipe
vakenbolt Jun 19, 2020
c91d60d
Adds unit test for the go side of the code
vakenbolt Jun 20, 2020
1abcbb0
adds go test in dockerfile
vakenbolt Jun 20, 2020
2964a55
some code refactoring and adds more test
vakenbolt Jun 20, 2020
db12224
adds support for running go test in the CI docker file.
vakenbolt Jun 20, 2020
d472010
adds a default to the groupSize flag
vakenbolt Jun 20, 2020
72e4c9d
adds test for groupSize
vakenbolt Jun 20, 2020
67ea39b
some minor test updates
vakenbolt Jun 20, 2020
9b42ab9
more refactorings and updated test
vakenbolt Jun 20, 2020
029b0fc
updated tests and added more tests
vakenbolt Jun 21, 2020
6bda248
adds shorthand flag for the title flag
vakenbolt Jun 21, 2020
4e3da71
removed shortand tests
vakenbolt Jun 21, 2020
952431b
moved the stdin checker into the main processing block
vakenbolt Jun 21, 2020
ab892c7
updates to documentation and test
vakenbolt Jun 21, 2020
761bda5
added minor code-refactoring and fixing some broken test
vakenbolt Jun 21, 2020
d4cdf35
adds a short hand for the --groupSize flag
vakenbolt Jun 22, 2020
dcaacb7
adds AST parsing code to retrieve the filenames associated with test …
vakenbolt Jul 5, 2020
5453286
added initial code to map test names to their associated go test files.
vakenbolt Jul 6, 2020
df18e73
Adds the test file with line and col position information
vakenbolt Jul 6, 2020
03eb2f1
Merge branch 'master' of github.com:vakenbolt/go-test-report into vak…
vakenbolt Jul 6, 2020
2aecebb
code cleanup
vakenbolt Jul 6, 2020
f2cc568
added embedded assets into the binary
vakenbolt Jul 6, 2020
23ca87a
updated dockerfile to fix broken build
vakenbolt Jul 6, 2020
2774577
removed unnecessary generated code
vakenbolt Jul 7, 2020
3de66df
added verbose flag
vakenbolt Jul 7, 2020
8686697
add total time at the end of process
vakenbolt Jul 7, 2020
8248f65
removed unneeded code
vakenbolt Jul 7, 2020
4510ff3
updated readme
vakenbolt Jul 7, 2020
5195125
adds a build script for mac, linux and windows builds
vakenbolt Jul 7, 2020
e272d01
updates release build file to create the destination folders before p…
vakenbolt Jul 7, 2020
e13543b
added a little more clarity to the -groupSize usage description
vakenbolt Jul 7, 2020
cf989cb
updates template to support change the html window title in addition …
vakenbolt Jul 7, 2020
92e3300
updated readme and removed unneeded code
vakenbolt Jul 7, 2020
0b135d6
nomenclature update
vakenbolt Jul 7, 2020
060eeb5
added the embedded_assets.go file
vakenbolt Jul 7, 2020
29e4872
updates to the default test report template
vakenbolt Jul 7, 2020
50c90ea
added the generate_embedded_go_code bash script
vakenbolt Jul 7, 2020
d7f6489
moved some files around. preparing for commit to master
vakenbolt Jul 8, 2020
112683f
moved assets to the root project folder and added test duration to th…
vakenbolt Jul 8, 2020
f99c91f
tweaked the test report template
vakenbolt Jul 8, 2020
1662b03
changes default groupSize from 10 to 20.
vakenbolt Jul 9, 2020
1a46fc3
small teak to the test report ui
vakenbolt Jul 9, 2020
39a4090
updated broken test
vakenbolt Jul 9, 2020
a7d6f62
added an ellipsis to test names that are to long
vakenbolt Jul 9, 2020
120e7e7
updates the test report ui to show 'n/a' if a test was not found in t…
vakenbolt Jul 9, 2020
87a667c
Adds test execution date to test report html
vakenbolt Jul 10, 2020
a50cff4
fixes date formatted problem in test execution date
vakenbolt Jul 10, 2020
3c9ed22
Merge branch 'master' of github.com:vakenbolt/go-test-report into vak…
vakenbolt Jul 10, 2020
f9b32b1
deleted jeykll file
vakenbolt Jul 10, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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