Skip to content

Commit 979fbc2

Browse files
authoredFeb 25, 2023
Add OmitSuiteSetupNodes to JunitReportConfig (#1147)
* Add OmitSuiteSetupNodes to JunitReportConfig This commit adds a new option to the JunitReportConfig that when enabled prevents the creation of testcase entries for setup nodes in the JUnit report. fix #1145 * Add unit test for the OmitSuiteSetupNodes feature Added a dummy BeforeSuite spec to validate that with the new OmitSuiteSetupNodes option, the generated JUnit report is omitting this spec and not displaying it as one of the testcases. fix #1145
1 parent a8bb39a commit 979fbc2

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed
 

‎reporters/junit_report.go

+6
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ type JunitReportConfig struct {
3636

3737
// Enable OmitLeafNodeType to prevent the spec leaf node type from appearing in the spec name
3838
OmitLeafNodeType bool
39+
40+
// Enable OmitSuiteSetupNodes to prevent the creation of testcase entries for setup nodes
41+
OmitSuiteSetupNodes bool
3942
}
4043

4144
type JUnitTestSuites struct {
@@ -177,6 +180,9 @@ func GenerateJUnitReportWithConfig(report types.Report, dst string, config Junit
177180
},
178181
}
179182
for _, spec := range report.SpecReports {
183+
if config.OmitSuiteSetupNodes && spec.LeafNodeType != types.NodeTypeIt {
184+
continue
185+
}
180186
name := fmt.Sprintf("[%s]", spec.LeafNodeType)
181187
if config.OmitLeafNodeType {
182188
name = ""

‎reporters/junit_report_test.go

+15-3
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ var _ = Describe("JunitReport", func() {
4747
F("failure\nmessage", cl1, types.FailureNodeIsLeafNode, FailureNodeLocation(cl0), types.NodeTypeIt, ForwardedPanic("the panic")),
4848
SE(types.SpecEventNodeEnd, types.NodeTypeIt, "A", cl0, time.Millisecond*300, TL("some GinkgoWriter\noutput is interspersed\nhere and there\n")),
4949
),
50+
S(types.NodeTypeBeforeSuite, "A", cl0, types.SpecStatePassed),
5051
},
5152
}
5253
})
@@ -66,7 +67,7 @@ var _ = Describe("JunitReport", func() {
6667
})
6768

6869
It("generates a Junit report and writes it to disk", func() {
69-
Ω(generated.Tests).Should(Equal(4))
70+
Ω(generated.Tests).Should(Equal(5))
7071
Ω(generated.Disabled).Should(Equal(1))
7172
Ω(generated.Errors).Should(Equal(1))
7273
Ω(generated.Failures).Should(Equal(1))
@@ -79,13 +80,13 @@ var _ = Describe("JunitReport", func() {
7980
Ω(suite.Properties.WithName("SuiteSucceeded")).Should(Equal("false"))
8081
Ω(suite.Properties.WithName("RandomSeed")).Should(Equal("17"))
8182

82-
Ω(suite.Tests).Should(Equal(4))
83+
Ω(suite.Tests).Should(Equal(5))
8384
Ω(suite.Disabled).Should(Equal(1))
8485
Ω(suite.Errors).Should(Equal(1))
8586
Ω(suite.Failures).Should(Equal(1))
8687
Ω(suite.Time).Should(Equal(60.0))
8788

88-
Ω(suite.TestCases).Should(HaveLen(4))
89+
Ω(suite.TestCases).Should(HaveLen(5))
8990

9091
failingSpec := suite.TestCases[0]
9192
Ω(failingSpec.Name).Should(Equal("[It] A B C [dolphin, gorilla, cow, cat, dog]"))
@@ -207,6 +208,16 @@ var _ = Describe("JunitReport", func() {
207208
spr("< Exit [It] A - cl0.go:12 @ %s (300ms)", FORMATTED_TIME),
208209
"",
209210
))
211+
212+
beforeSuiteSpec := suite.TestCases[4]
213+
Ω(beforeSuiteSpec.Name).Should(Equal("[BeforeSuite] A"))
214+
Ω(beforeSuiteSpec.Classname).Should(Equal("My Suite"))
215+
Ω(beforeSuiteSpec.Status).Should(Equal("passed"))
216+
Ω(beforeSuiteSpec.Skipped).Should(BeNil())
217+
Ω(beforeSuiteSpec.Error).Should(BeNil())
218+
Ω(beforeSuiteSpec.Failure).Should(BeNil())
219+
Ω(beforeSuiteSpec.SystemOut).Should(BeEmpty())
220+
Ω(beforeSuiteSpec.SystemErr).Should(BeEmpty())
210221
})
211222
})
212223

@@ -221,6 +232,7 @@ var _ = Describe("JunitReport", func() {
221232
OmitCapturedStdOutErr: true,
222233
OmitSpecLabels: true,
223234
OmitLeafNodeType: true,
235+
OmitSuiteSetupNodes: true,
224236
})).Should(Succeed())
225237
DeferCleanup(os.Remove, fname)
226238

0 commit comments

Comments
 (0)
Please sign in to comment.