Skip to content

Commit

Permalink
Add junit config option for omitting leafnodetype
Browse files Browse the repository at this point in the history
allow omitting the LeafNodeType (`[It]`) from being included in the
junit results file by adding a new config option and skipping over the
setting of name to LeafNodeType. Default behavior remains as is.

a follow up on de44005

Signed-off-by: Brady Pratt <[email protected]>
  • Loading branch information
jbpratt committed Dec 7, 2022
1 parent de44005 commit 2ba055e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
7 changes: 7 additions & 0 deletions reporters/junit_report.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ type JunitReportConfig struct {

// Enable OmitSpecLabels to prevent labels from appearing in the spec name
OmitSpecLabels bool

// Enable OmitLeafNodeType to prevent the spec
OmitLeafNodeType bool
}

type JUnitTestSuites struct {
Expand Down Expand Up @@ -175,13 +178,17 @@ func GenerateJUnitReportWithConfig(report types.Report, dst string, config Junit
}
for _, spec := range report.SpecReports {
name := fmt.Sprintf("[%s]", spec.LeafNodeType)
if config.OmitLeafNodeType {
name = ""
}
if spec.FullText() != "" {
name = name + " " + spec.FullText()
}
labels := spec.Labels()
if len(labels) > 0 && !config.OmitSpecLabels {
name = name + " [" + strings.Join(labels, ", ") + "]"
}
name = strings.TrimSpace(name)

test := JUnitTestCase{
Name: name,
Expand Down
9 changes: 5 additions & 4 deletions reporters/junit_report_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@ var _ = Describe("JunitReport", func() {
OmitFailureMessageAttr: true,
OmitCapturedStdOutErr: true,
OmitSpecLabels: true,
OmitLeafNodeType: true,
})).Should(Succeed())
DeferCleanup(os.Remove, fname)

Expand Down Expand Up @@ -252,7 +253,7 @@ var _ = Describe("JunitReport", func() {
Ω(suite.TestCases).Should(HaveLen(4))

failingSpec := suite.TestCases[0]
Ω(failingSpec.Name).Should(Equal("[It] A B C"))
Ω(failingSpec.Name).Should(Equal("A B C"))
Ω(failingSpec.Classname).Should(Equal("My Suite"))
Ω(failingSpec.Status).Should(Equal("timedout"))
Ω(failingSpec.Skipped).Should(BeNil())
Expand Down Expand Up @@ -303,7 +304,7 @@ var _ = Describe("JunitReport", func() {
))

passingSpec := suite.TestCases[1]
Ω(passingSpec.Name).Should(Equal("[It] A"))
Ω(passingSpec.Name).Should(Equal("A"))
Ω(passingSpec.Classname).Should(Equal("My Suite"))
Ω(passingSpec.Status).Should(Equal("passed"))
Ω(passingSpec.Skipped).Should(BeNil())
Expand All @@ -313,7 +314,7 @@ var _ = Describe("JunitReport", func() {
Ω(passingSpec.SystemErr).Should(BeEmpty())

pendingSpec := suite.TestCases[2]
Ω(pendingSpec.Name).Should(Equal("[It] A"))
Ω(pendingSpec.Name).Should(Equal("A"))
Ω(pendingSpec.Classname).Should(Equal("My Suite"))
Ω(pendingSpec.Status).Should(Equal("pending"))
Ω(pendingSpec.Skipped.Message).Should(Equal("pending"))
Expand All @@ -323,7 +324,7 @@ var _ = Describe("JunitReport", func() {
Ω(pendingSpec.SystemErr).Should(BeEmpty())

panickedSpec := suite.TestCases[3]
Ω(panickedSpec.Name).Should(Equal("[It] A"))
Ω(panickedSpec.Name).Should(Equal("A"))
Ω(panickedSpec.Classname).Should(Equal("My Suite"))
Ω(panickedSpec.Status).Should(Equal("panicked"))
Ω(panickedSpec.Skipped).Should(BeNil())
Expand Down

0 comments on commit 2ba055e

Please sign in to comment.