vakenbolt / go-test-report

Captures go test output and parses it into a single self-contained HTML file.
Apache License 2.0
156 stars 34 forks source link

Advocate gotestsum for running go test #61

Open afbjorklund opened 1 year ago

afbjorklund commented 1 year ago

Since it allows both progress and json, at the same time (not either / or).

It also has a default format that is more friendly on the eyes than go test.

$ gotestsum --jsonfile test_report.json

https://github.com/gotestyourself/gotestsum


Main issue is recording the current date and execution time "somewhere"...

Duration (should be the test execution time, not the report execution time)

testExecutionDate (should be the test executation date, not the current date)

afbjorklund commented 1 year ago

When GOTESTSUM_ELAPSED and GOTESTSUM_JSONFILE are picked up automatically, the invocation becomes just:

gotestsum --jsonfile test_report.json --post-run-command "go-test-report --output test_report.html"
Victor-Chirinian-Vimeo commented 1 year ago

@afbjorklund I saw the following PR :https://github.com/vakenbolt/go-test-report/pull/62, that will allow users to specify the path to the test2json file produced by gotestsum, which is great! Currently I am running the invocation you shared above, which is dependent on the env vars being set, but I am still getting:

Error: ERROR: missing ≪ stdin ≫ pipe.

GOTESTSUM_JSONFILE I am manually setting before execution GOTESTSUM_ELAPSED is set by gotestsum itself.

afbjorklund commented 1 year ago

You should not have to set GOTESTSUM_JSONFILE, it should be exported by gotestsum when you use the --jsonfile parameter. There was a small change needed to the GOTESTSUM_ELAPSED variable, to add the "s" (for seconds)

$ gotestsum --jsonfile test_report.json --post-run-command env | grep GOTESTSUM
GOTESTSUM_JSONFILE=test_report.json
GOTESTSUM_JSONFILE_TIMING_EVENTS=
GOTESTSUM_JUNITFILE=
GOTESTSUM_ELAPSED=0.208s

Then what I did is to add two new parameters to go-test-report, and have them default to these environment variables. You can also specify them explicitly, like go-test-report -i test_report.json -e 0.208s, if not using post-run

$ go-test-report -i test_report.json -e 0.208s
[go-test-report] finished in 81.253371ms
$ grep Duration: test_report.html
        <span class="total"><span class="indicator">&boxbox;</span> Total: <strong>18</strong>Duration: <strong>208ms</strong>
Victor-Chirinian-Vimeo commented 1 year ago

@afbjorklund That is true, it is one or the other. I currently don't see any references to the GOTESTSUM_JSONFILE env var in master, which is likely why I am getting the stdin pipe error, unless I missed it while reviewing the code. Is that dependent on https://github.com/vakenbolt/go-test-report/pull/62 getting merged ?

afbjorklund commented 1 year ago

You can do something like sh -c "go-test-report <$GOTESTSUM_JSONFILE" (or just hardcode the file), until it is...

https://github.com/vakenbolt/go-test-report/pull/62/files#diff-2873f79a86c0d8b3335cd7731b0ecf7dd4301eb19a82ef7a1cba7589b5252261R248

The only missing features are the testExecutionDate and the Duration, as mentioned.

afbjorklund commented 1 year ago

I think we want to the name the file something other than "test_report.json"