Skip to content

Commit

Permalink
Add option to enable all output in junit xml
Browse files Browse the repository at this point in the history
  • Loading branch information
dnephin committed Nov 19, 2023
1 parent f2cfad7 commit 1f9d89b
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 1 deletion.
1 change: 1 addition & 0 deletions cmd/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ func newEventHandler(opts *options) (*eventHandler, error) {
FormatTestSuiteName: opts.junitTestSuiteNameFormat.Value(),
FormatTestCaseClassname: opts.junitTestCaseClassnameFormat.Value(),
HideEmptyPackages: opts.junitHideEmptyPackages,
Output: opts.junitOutput,
})
}

Expand Down
4 changes: 4 additions & 0 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,9 @@ func setupFlags(name string) (*pflag.FlagSet, *options) {
flags.BoolVar(&opts.junitHideEmptyPackages, "junitfile-hide-empty-pkg",
truthyFlag(lookEnvWithDefault("GOTESTSUM_JUNIT_HIDE_EMPTY_PKG", "")),
"omit packages with no tests from the junit.xml file")
flags.StringVar(&opts.junitOutput, "junitfile-output",
lookEnvWithDefault("GOTESTSUM_JUNITFILE_OUTPUT", "failed"),
"output to include in the junit file (all, failed)")

flags.IntVar(&opts.rerunFailsMaxAttempts, "rerun-fails", 0,
"rerun failed tests until they all pass, or attempts exceeds maximum. Defaults to max 2 reruns when enabled")
Expand Down Expand Up @@ -187,6 +190,7 @@ type options struct {
junitTestCaseClassnameFormat *junitFieldFormatValue
junitProjectName string
junitHideEmptyPackages bool
junitOutput string
rerunFailsMaxAttempts int
rerunFailsMaxInitialFailures int
rerunFailsReportFile string
Expand Down
1 change: 1 addition & 0 deletions cmd/testdata/gotestsum-help-text
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ Flags:
--jsonfile-timing-events string write only the pass, skip, and fail TestEvents to the file
--junitfile string write a JUnit XML file
--junitfile-hide-empty-pkg omit packages with no tests from the junit.xml file
--junitfile-output string output to include in the junit file (all, failed) (default "failed")
--junitfile-project-name string name of the project used in the junit.xml file
--junitfile-testcase-classname field-format format the testcase classname field as: full, relative, short (default full)
--junitfile-testsuite-name field-format format the testsuite name field as: full, relative, short (default full)
Expand Down
5 changes: 4 additions & 1 deletion internal/junitxml/report.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@ func (e *Encoder) Handle(event testjson.TestEvent, execution *testjson.Execution
return nil
}

// TODO: only store all output when cfg option is set
if e.cfg.Output != "all" {
return nil
}

pkg, ok := e.output[event.Package]
if !ok {
Expand Down Expand Up @@ -120,6 +122,7 @@ type Config struct {
FormatTestSuiteName FormatFunc
FormatTestCaseClassname FormatFunc
HideEmptyPackages bool
Output string
// This is used for tests to have a consistent timestamp
customTimestamp string
customElapsed string
Expand Down

0 comments on commit 1f9d89b

Please sign in to comment.