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

Advocate gotestsum for running go test #61

Open
afbjorklund opened this issue Aug 19, 2023 · 6 comments
Open

Advocate gotestsum for running go test #61

afbjorklund opened this issue Aug 19, 2023 · 6 comments

Comments

@afbjorklund
Copy link
Contributor

afbjorklund commented Aug 19, 2023

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 afbjorklund changed the title Advocate gotestsum for running Advocate gotestsum for running go test Aug 19, 2023
@afbjorklund
Copy link
Contributor Author

afbjorklund commented Aug 19, 2023

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
Copy link

Victor-Chirinian-Vimeo commented Aug 23, 2023

@afbjorklund I saw the following PR :#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
Copy link
Contributor Author

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
Copy link

@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 #62 getting merged ?

@afbjorklund
Copy link
Contributor Author

afbjorklund commented Aug 24, 2023

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
Copy link
Contributor Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants