From 5634f454b2833b484ea9a2eb7360490dd44d222e Mon Sep 17 00:00:00 2001 From: Ryan Williams <3375653+ryankwilliams@users.noreply.github.com> Date: Mon, 5 Dec 2022 15:17:25 -0500 Subject: [PATCH] Add support to customize junit report config to omit spec labels Ginkgo tests that generate JUnit XML report may wish to omit labels from appearing within the spec. This is helpful when these results get imported into third party applications for analyzing/displaying test results. This commit adds a new field to the JunitReportConfig to be able to omit labels from being included within a spec. By default, labels will be included in the spec within the junit xml report (current behavior). Users can override this based on their needs. --- reporters/junit_report.go | 5 ++++- reporters/junit_report_test.go | 3 ++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/reporters/junit_report.go b/reporters/junit_report.go index 576962e8f..46131d6e7 100644 --- a/reporters/junit_report.go +++ b/reporters/junit_report.go @@ -30,6 +30,9 @@ type JunitReportConfig struct { //Enable OmitCapturedStdOutErr to prevent captured stdout/stderr appearing in system-out OmitCapturedStdOutErr bool + + // Enable OmitSpecLabels to prevent labels from appearing in the spec name + OmitSpecLabels bool } type JUnitTestSuites struct { @@ -176,7 +179,7 @@ func GenerateJUnitReportWithConfig(report types.Report, dst string, config Junit name = name + " " + spec.FullText() } labels := spec.Labels() - if len(labels) > 0 { + if len(labels) > 0 && !config.OmitSpecLabels { name = name + " [" + strings.Join(labels, ", ") + "]" } diff --git a/reporters/junit_report_test.go b/reporters/junit_report_test.go index a017cc812..e160069fa 100644 --- a/reporters/junit_report_test.go +++ b/reporters/junit_report_test.go @@ -219,6 +219,7 @@ var _ = Describe("JunitReport", func() { OmitTimelinesForSpecState: types.SpecStatePassed, OmitFailureMessageAttr: true, OmitCapturedStdOutErr: true, + OmitSpecLabels: true, })).Should(Succeed()) DeferCleanup(os.Remove, fname) @@ -251,7 +252,7 @@ var _ = Describe("JunitReport", func() { Ω(suite.TestCases).Should(HaveLen(4)) failingSpec := suite.TestCases[0] - Ω(failingSpec.Name).Should(Equal("[It] A B C [dolphin, gorilla, cow, cat, dog]")) + Ω(failingSpec.Name).Should(Equal("[It] A B C")) Ω(failingSpec.Classname).Should(Equal("My Suite")) Ω(failingSpec.Status).Should(Equal("timedout")) Ω(failingSpec.Skipped).Should(BeNil())