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

     1  package internal_integration_test
     2  
     3  import (
     4  	. "github.com/onsi/ginkgo"
     5  	. "github.com/onsi/ginkgo/internal/test_helpers"
     6  	. "github.com/onsi/gomega"
     7  
     8  	"github.com/onsi/ginkgo/types"
     9  )
    10  
    11  var _ = Describe("Decorations test", func() {
    12  	var clForOffset types.CodeLocation
    13  	BeforeEach(func() {
    14  		customIt := func() {
    15  			It("is-offset", rt.T("is-offset"), Offset(1))
    16  		}
    17  		var count = 0
    18  		success, _ := RunFixture("happy-path decoration test", func() {
    19  			Describe("top-level-container", func() {
    20  				clForOffset = types.NewCodeLocation(0)
    21  				customIt()
    22  				It("flaky", FlakeAttempts(4), rt.T("flaky", func() {
    23  					count += 1
    24  					outputInterceptor.AppendInterceptedOutput("so flaky\n")
    25  					writer.Println("so tasty")
    26  					if count < 3 {
    27  						F("fail")
    28  					}
    29  				}))
    30  				It("never-passes", FlakeAttempts(2), rt.T("never-passes", func() {
    31  					F("fail")
    32  				}))
    33  				It("skips", FlakeAttempts(3), rt.T("skips", func() {
    34  					Skip("skip")
    35  				}))
    36  			})
    37  		})
    38  		Ω(success).Should(BeFalse())
    39  	})
    40  
    41  	It("runs all the test nodes in the expected order", func() {
    42  		Ω(rt).Should(HaveTracked(
    43  			"is-offset",
    44  			"flaky", "flaky", "flaky",
    45  			"never-passes", "never-passes",
    46  			"skips",
    47  		))
    48  	})
    49  
    50  	Describe("Offset", func() {
    51  		It("applies the offset when computing the codelocation", func() {
    52  			clForOffset.LineNumber = clForOffset.LineNumber + 1
    53  			Ω(reporter.Did.Find("is-offset").LeafNodeLocation).Should(Equal(clForOffset))
    54  		})
    55  	})
    56  
    57  	Describe("FlakeAttempts", func() {
    58  		It("reruns tests until they pass or until the number of flake attempts is exhausted, but does not rerun skipped tests", func() {
    59  			Ω(reporter.Did.Find("flaky")).Should(HavePassed(NumAttempts(3), CapturedStdOutput("so flaky\nso flaky\nso flaky\n"), CapturedGinkgoWriterOutput("so tasty\n\nGinkgo: Attempt #1 Failed.  Retrying...\nso tasty\n\nGinkgo: Attempt #2 Failed.  Retrying...\nso tasty\n")))
    60  			Ω(reporter.Did.Find("never-passes")).Should(HaveFailed("fail", NumAttempts(2)))
    61  			Ω(reporter.Did.Find("skips")).Should(HaveBeenSkippedWithMessage("skip", NumAttempts(1)))
    62  		})
    63  	})
    64  })