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

Add junit config option for omitting leafnodetype #1088

Merged
merged 1 commit into from Dec 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 7 additions & 0 deletions reporters/junit_report.go
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 leaf node type from appearing in the spec name
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
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