github.com/onsi/ginkgo@v1.16.6-0.20211118180735-4e1925ba4c95/internal/internal_integration/current_spec_report_test.go (about)

     1  package internal_integration_test
     2  
     3  import (
     4  	"time"
     5  
     6  	. "github.com/onsi/ginkgo"
     7  	"github.com/onsi/ginkgo/types"
     8  	. "github.com/onsi/gomega"
     9  )
    10  
    11  var _ = Describe("CurrentSpecReport", func() {
    12  	var specs map[string]types.SpecReport
    13  
    14  	BeforeEach(func() {
    15  		specs = map[string]types.SpecReport{}
    16  		outputInterceptor.AppendInterceptedOutput("output-interceptor-content")
    17  
    18  		logCurrentSpecReport := func(key string, andRun ...func()) func() {
    19  			return func() {
    20  				specs[key] = CurrentSpecReport()
    21  				if len(andRun) > 0 {
    22  					andRun[0]()
    23  				}
    24  			}
    25  		}
    26  
    27  		RunFixture("current test description", func() {
    28  			BeforeSuite(logCurrentSpecReport("before-suite"))
    29  			Context("a passing test", func() {
    30  				BeforeEach(logCurrentSpecReport("bef-A", func() {
    31  					writer.Println("hello bef-A")
    32  				}))
    33  				It("A", logCurrentSpecReport("it-A", func() {
    34  					writer.Println("hello it-A")
    35  					time.Sleep(20 * time.Millisecond)
    36  				}))
    37  				AfterEach(logCurrentSpecReport("aft-A"))
    38  			})
    39  			Context("a failing test", func() {
    40  				BeforeEach(logCurrentSpecReport("bef-B"))
    41  				It("B", logCurrentSpecReport("it-B", func() {
    42  					writer.Println("hello it-B")
    43  					F("failed")
    44  				}))
    45  				AfterEach(logCurrentSpecReport("aft-B"))
    46  			})
    47  
    48  			Context("an ordered container", Ordered, func() {
    49  				It("C", logCurrentSpecReport("C"))
    50  			})
    51  
    52  			Context("an serial spec", func() {
    53  				It("D", Serial, logCurrentSpecReport("D"))
    54  			})
    55  			AfterSuite(logCurrentSpecReport("after-suite"))
    56  		})
    57  	})
    58  
    59  	It("returns an a valid GinkgoTestDescription in the before suite and after suite", func() {
    60  		Ω(specs["before-suite"].LeafNodeType).Should(Equal(types.NodeTypeBeforeSuite))
    61  		Ω(specs["after-suite"].LeafNodeType).Should(Equal(types.NodeTypeAfterSuite))
    62  	})
    63  
    64  	It("reports as passed while the test is passing", func() {
    65  		Ω(specs["bef-A"].Failed()).Should(BeFalse())
    66  		Ω(specs["it-A"].Failed()).Should(BeFalse())
    67  		Ω(specs["aft-A"].Failed()).Should(BeFalse())
    68  	})
    69  
    70  	It("reports as failed when the test fails", func() {
    71  		Ω(specs["bef-B"].Failed()).Should(BeFalse())
    72  		Ω(specs["it-B"].Failed()).Should(BeFalse())
    73  		Ω(specs["aft-B"].Failed()).Should(BeTrue())
    74  	})
    75  
    76  	It("captures GinkgoWriter output", func() {
    77  		Ω(specs["bef-A"].CapturedGinkgoWriterOutput).Should(BeZero())
    78  		Ω(specs["it-A"].CapturedGinkgoWriterOutput).Should(Equal("hello bef-A\n"))
    79  		Ω(specs["aft-A"].CapturedGinkgoWriterOutput).Should(Equal("hello bef-A\nhello it-A\n"))
    80  
    81  		Ω(specs["bef-B"].CapturedGinkgoWriterOutput).Should(BeZero())
    82  		Ω(specs["it-B"].CapturedGinkgoWriterOutput).Should(BeZero())
    83  		Ω(specs["aft-B"].CapturedGinkgoWriterOutput).Should(Equal("hello it-B\n"))
    84  	})
    85  
    86  	It("does not capture stdout/err output", func() {
    87  		Ω(specs["aft-A"].CapturedStdOutErr).Should(BeZero())
    88  		Ω(specs["aft-B"].CapturedStdOutErr).Should(BeZero())
    89  	})
    90  
    91  	It("captures serial/ordered correctly", func() {
    92  		Ω(specs["A"].IsSerial).Should(BeFalse())
    93  		Ω(specs["A"].IsInOrderedContainer).Should(BeFalse())
    94  		Ω(specs["after-suite"].IsSerial).Should(BeFalse())
    95  		Ω(specs["after-suite"].IsInOrderedContainer).Should(BeFalse())
    96  		Ω(specs["C"].IsSerial).Should(BeFalse())
    97  		Ω(specs["C"].IsInOrderedContainer).Should(BeTrue())
    98  		Ω(specs["D"].IsSerial).Should(BeTrue())
    99  		Ω(specs["D"].IsInOrderedContainer).Should(BeFalse())
   100  	})
   101  
   102  	It("captures test details correctly", func() {
   103  		spec := specs["aft-A"]
   104  		Ω(spec.ContainerHierarchyTexts).Should(Equal([]string{"a passing test"}))
   105  		Ω(spec.LeafNodeText).Should(Equal("A"))
   106  		Ω(spec.FullText()).Should(Equal("a passing test A"))
   107  		location := reporter.Did.Find("A").LeafNodeLocation
   108  		Ω(spec.FileName()).Should(Equal(location.FileName))
   109  		Ω(spec.LineNumber()).Should(Equal(location.LineNumber))
   110  		Ω(spec.RunTime).Should(BeNumerically(">=", time.Millisecond*20))
   111  	})
   112  })