...

Source file src/github.com/onsi/ginkgo/v2/integration/report_entries_test.go

Documentation: github.com/onsi/ginkgo/v2/integration

     1  package integration_test
     2  
     3  import (
     4  	"time"
     5  
     6  	. "github.com/onsi/ginkgo/v2"
     7  	. "github.com/onsi/ginkgo/v2/internal/test_helpers"
     8  	"github.com/onsi/ginkgo/v2/types"
     9  	. "github.com/onsi/gomega"
    10  	"github.com/onsi/gomega/gbytes"
    11  	"github.com/onsi/gomega/gexec"
    12  )
    13  
    14  var _ = Describe("ReportEntries", func() {
    15  	var output string
    16  
    17  	Describe("when running a test that adds report entries", Ordered, func() {
    18  		BeforeAll(func() {
    19  			fm.MountFixture("report_entries")
    20  			session := startGinkgo(fm.PathTo("report_entries"), "--no-color", "--procs=2", "--json-report=out.json", "--junit-report=out.xml")
    21  			Eventually(session).Should(gexec.Exit(1))
    22  			output = string(session.Out.Contents())
    23  		})
    24  
    25  		It("should honor the report visibilities and stringer formatting when emitting output", func() {
    26  			Ω(output).Should(ContainSubstring("passes-first-report"))
    27  			Ω(output).Should(ContainSubstring("pass-bob 1"))
    28  			Ω(output).Should(ContainSubstring("passes-second-report"))
    29  			Ω(output).Should(ContainSubstring("passes-third-report"))
    30  			Ω(output).Should(ContainSubstring("passes-pointer-report"))
    31  			Ω(output).Should(ContainSubstring("passed 4"))
    32  			Ω(output).ShouldNot(ContainSubstring("passes-failure-report"))
    33  			Ω(output).ShouldNot(ContainSubstring("passes-never-see-report"))
    34  
    35  			Ω(output).Should(ContainSubstring("fails-first-report"))
    36  			Ω(output).Should(ContainSubstring("fail-bob 1"))
    37  			Ω(output).Should(ContainSubstring("fails-second-report"))
    38  			Ω(output).Should(ContainSubstring("fails-third-report"))
    39  			Ω(output).Should(ContainSubstring("fails-pointer-report"))
    40  			Ω(output).Should(ContainSubstring("failed 4"))
    41  			Ω(output).Should(ContainSubstring("fails-failure-report"))
    42  			Ω(output).ShouldNot(ContainSubstring("fails-never-see-report"))
    43  
    44  			Ω(output).ShouldNot(ContainSubstring("registers a hidden AddReportEntry"))
    45  		})
    46  
    47  		It("captures all report entries in the JSON report", func() {
    48  			report := fm.LoadJSONReports("report_entries", "out.json")[0]
    49  			reports := Reports(report.SpecReports)
    50  			passes := reports.Find("passes")
    51  			Ω(passes.ReportEntries).Should(HaveLen(6))
    52  			Ω(passes.ReportEntries[0].Name).Should(Equal("passes-first-report"))
    53  			Ω(passes.ReportEntries[0].GetRawValue()).Should(Equal(map[string]interface{}{"Label": "pass-bob", "Count": float64(1)}))
    54  			Ω(passes.ReportEntries[0].StringRepresentation()).Should(Equal("{{red}}pass-bob {{green}}1{{/}}"))
    55  			Ω(passes.ReportEntries[0].Time).Should(BeTemporally("~", time.Now(), time.Minute))
    56  
    57  			Ω(passes.ReportEntries[1].Name).Should(Equal("passes-second-report"))
    58  			Ω(passes.ReportEntries[1].GetRawValue()).Should(BeNil())
    59  			Ω(passes.ReportEntries[1].StringRepresentation()).Should(BeZero())
    60  
    61  			Ω(passes.ReportEntries[2].Name).Should(Equal("passes-third-report"))
    62  			Ω(passes.ReportEntries[2].GetRawValue()).Should(Equal(float64(3)))
    63  			Ω(passes.ReportEntries[2].StringRepresentation()).Should(Equal("3"))
    64  
    65  			Ω(passes.ReportEntries[3].Name).Should(Equal("passes-pointer-report"))
    66  			Ω(passes.ReportEntries[3].GetRawValue()).Should(Equal(map[string]interface{}{"Label": "passed", "Count": float64(4)}))
    67  			Ω(passes.ReportEntries[3].StringRepresentation()).Should(Equal("{{red}}passed {{green}}4{{/}}"))
    68  
    69  			Ω(passes.ReportEntries[4].Name).Should(Equal("passes-failure-report"))
    70  			Ω(passes.ReportEntries[4].GetRawValue()).Should(Equal(float64(5)))
    71  			Ω(passes.ReportEntries[4].StringRepresentation()).Should(Equal("5"))
    72  
    73  			Ω(passes.ReportEntries[5].Name).Should(Equal("passes-never-see-report"))
    74  			Ω(passes.ReportEntries[5].GetRawValue()).Should(Equal(float64(6)))
    75  			Ω(passes.ReportEntries[5].StringRepresentation()).Should(Equal("6"))
    76  
    77  			fails := reports.Find("fails")
    78  			Ω(fails.ReportEntries[0].Name).Should(Equal("fails-first-report"))
    79  			Ω(fails.ReportEntries[0].GetRawValue()).Should(Equal(map[string]interface{}{"Label": "fail-bob", "Count": float64(1)}))
    80  			Ω(fails.ReportEntries[0].StringRepresentation()).Should(Equal("{{red}}fail-bob {{green}}1{{/}}"))
    81  			Ω(fails.ReportEntries[0].Time).Should(BeTemporally("~", time.Now(), time.Minute))
    82  
    83  			Ω(fails.ReportEntries[1].Name).Should(Equal("fails-second-report"))
    84  			Ω(fails.ReportEntries[1].GetRawValue()).Should(BeNil())
    85  			Ω(fails.ReportEntries[1].StringRepresentation()).Should(BeZero())
    86  
    87  			Ω(fails.ReportEntries[2].Name).Should(Equal("fails-third-report"))
    88  			Ω(fails.ReportEntries[2].GetRawValue()).Should(Equal(float64(3)))
    89  			Ω(fails.ReportEntries[2].StringRepresentation()).Should(Equal("3"))
    90  
    91  			Ω(fails.ReportEntries[3].Name).Should(Equal("fails-pointer-report"))
    92  			Ω(fails.ReportEntries[3].GetRawValue()).Should(Equal(map[string]interface{}{"Label": "failed", "Count": float64(4)}))
    93  			Ω(fails.ReportEntries[3].StringRepresentation()).Should(Equal("{{red}}failed {{green}}4{{/}}"))
    94  
    95  			Ω(fails.ReportEntries[4].Name).Should(Equal("fails-failure-report"))
    96  			Ω(fails.ReportEntries[4].GetRawValue()).Should(Equal(float64(5)))
    97  			Ω(fails.ReportEntries[4].StringRepresentation()).Should(Equal("5"))
    98  
    99  			Ω(fails.ReportEntries[5].Name).Should(Equal("fails-never-see-report"))
   100  			Ω(fails.ReportEntries[5].GetRawValue()).Should(Equal(float64(6)))
   101  			Ω(fails.ReportEntries[5].StringRepresentation()).Should(Equal("6"))
   102  
   103  			by := reports.Find("has By entries")
   104  			byEvents := by.SpecEvents.WithType(types.SpecEventByStart | types.SpecEventByEnd)
   105  			Ω(byEvents[0].SpecEventType).Should(Equal(types.SpecEventByStart))
   106  			Ω(byEvents[0].Message).Should(Equal("registers a By event"))
   107  			Ω(byEvents[1].SpecEventType).Should(Equal(types.SpecEventByStart))
   108  			Ω(byEvents[1].Message).Should(Equal("includes durations"))
   109  			Ω(byEvents[2].SpecEventType).Should(Equal(types.SpecEventByEnd))
   110  			Ω(byEvents[2].Message).Should(Equal("includes durations"))
   111  			Ω(byEvents[2].Duration).Should(BeNumerically("~", time.Millisecond*100, time.Millisecond*100))
   112  		})
   113  
   114  		It("captures all report entries in the JUnit report", func() {
   115  			junit := fm.LoadJUnitReport("report_entries", "out.xml").TestSuites[0]
   116  			var content string
   117  			for _, testCase := range junit.TestCases {
   118  				if testCase.Name == "[It] top-level container passes" {
   119  					content = testCase.SystemErr
   120  				}
   121  			}
   122  
   123  			buf := gbytes.BufferWithBytes([]byte(content))
   124  
   125  			Ω(buf).Should(gbytes.Say("passes-first-report"))
   126  			Ω(buf).Should(gbytes.Say(`report_entries/report_entries_fixture_suite_test\.go:\d+`))
   127  			Ω(buf).Should(gbytes.Say("pass-bob 1"))
   128  			Ω(buf).Should(gbytes.Say("passes-second-report"))
   129  			Ω(buf).Should(gbytes.Say("passes-third-report"))
   130  			Ω(buf).Should(gbytes.Say("3"))
   131  			Ω(buf).Should(gbytes.Say("passes-pointer-report"))
   132  			Ω(buf).Should(gbytes.Say("passed 4"))
   133  			Ω(buf).Should(gbytes.Say("passes-failure-report"))
   134  			Ω(buf).Should(gbytes.Say("5"))
   135  			Ω(buf).Should(gbytes.Say("passes-never-see-report"))
   136  			Ω(buf).Should(gbytes.Say("6"))
   137  		})
   138  	})
   139  
   140  	Describe("when running in verbose mode", func() {
   141  		BeforeEach(func() {
   142  			fm.MountFixture("report_entries")
   143  			session := startGinkgo(fm.PathTo("report_entries"), "--no-color", "--procs=2", "-v")
   144  			Eventually(session).Should(gexec.Exit(1))
   145  			output = string(session.Out.Contents())
   146  		})
   147  
   148  		It("should honor the report visibilities and stringer formatting when emitting output", func() {
   149  			Ω(output).Should(ContainSubstring("passes-first-report"))
   150  			Ω(output).Should(ContainSubstring("pass-bob 1"))
   151  			Ω(output).Should(ContainSubstring("passes-second-report"))
   152  			Ω(output).Should(ContainSubstring("passes-third-report"))
   153  			Ω(output).Should(ContainSubstring("passes-pointer-report"))
   154  			Ω(output).Should(ContainSubstring("passed 4"))
   155  			Ω(output).Should(ContainSubstring("passes-failure-report"))
   156  			Ω(output).ShouldNot(ContainSubstring("passes-never-see-report"))
   157  
   158  			Ω(output).Should(ContainSubstring("fails-first-report"))
   159  			Ω(output).Should(ContainSubstring("fail-bob 1"))
   160  			Ω(output).Should(ContainSubstring("fails-second-report"))
   161  			Ω(output).Should(ContainSubstring("fails-third-report"))
   162  			Ω(output).Should(ContainSubstring("fails-pointer-report"))
   163  			Ω(output).Should(ContainSubstring("failed 4"))
   164  			Ω(output).Should(ContainSubstring("fails-failure-report"))
   165  			Ω(output).ShouldNot(ContainSubstring("fails-never-see-report"))
   166  		})
   167  	})
   168  })
   169  

View as plain text