github.com/onsi/ginkgo@v1.16.6-0.20211118180735-4e1925ba4c95/internal/internal_integration/abort_test.go (about) 1 package internal_integration_test 2 3 import ( 4 . "github.com/onsi/ginkgo" 5 . "github.com/onsi/gomega" 6 7 . "github.com/onsi/ginkgo/internal/test_helpers" 8 "github.com/onsi/ginkgo/types" 9 ) 10 11 var _ = Describe("handling test aborts", func() { 12 Describe("when BeforeSuite aborts", func() { 13 BeforeEach(func() { 14 success, _ := RunFixture("abort beforesuite", func() { 15 BeforeSuite(rt.T("before-suite", func() { 16 writer.Write([]byte("before-suite")) 17 Abort("abort", cl) 18 })) 19 It("A", rt.T("A")) 20 It("B", rt.T("B")) 21 AfterSuite(rt.T("after-suite")) 22 }) 23 Ω(success).Should(BeFalse()) 24 }) 25 26 It("reports a suite failure", func() { 27 Ω(reporter.End).Should(BeASuiteSummary(false, NSpecs(2), NSkipped(0))) 28 }) 29 30 It("reports a failure for the BeforeSuite", func() { 31 Ω(reporter.Did.FindByLeafNodeType(types.NodeTypeBeforeSuite)).Should(HaveAborted("abort", cl, CapturedGinkgoWriterOutput("before-suite"))) 32 Ω(reporter.Did.FindByLeafNodeType(types.NodeTypeAfterSuite)).Should(HavePassed()) 33 }) 34 35 It("does not run any of the Its", func() { 36 Ω(rt).ShouldNot(HaveRun("A")) 37 Ω(rt).ShouldNot(HaveRun("B")) 38 }) 39 40 It("does run the AfterSuite", func() { 41 Ω(rt).Should(HaveTracked("before-suite", "after-suite")) 42 }) 43 }) 44 45 Describe("when AfterSuite aborts", func() { 46 BeforeEach(func() { 47 success, _ := RunFixture("abort aftersuite", func() { 48 BeforeSuite(rt.T("before-suite")) 49 Describe("top-level", func() { 50 It("A", rt.T("A")) 51 It("B", rt.T("B")) 52 }) 53 AfterSuite(rt.T("after-suite", func() { 54 writer.Write([]byte("after-suite")) 55 Abort("abort", cl) 56 })) 57 }) 58 Ω(success).Should(BeFalse()) 59 }) 60 61 It("reports a suite failure", func() { 62 Ω(reporter.End).Should(BeASuiteSummary(false, NSpecs(2), NPassed(2))) 63 }) 64 65 It("runs and reports on all the tests and reports a failure for the AfterSuite", func() { 66 Ω(rt).Should(HaveTracked("before-suite", "A", "B", "after-suite")) 67 Ω(reporter.Did.FindByLeafNodeType(types.NodeTypeBeforeSuite)).Should(HavePassed()) 68 Ω(reporter.Did.Find("A")).Should(HavePassed()) 69 Ω(reporter.Did.Find("B")).Should(HavePassed()) 70 Ω(reporter.Did.FindByLeafNodeType(types.NodeTypeAfterSuite)).Should(HaveAborted("abort", cl, CapturedGinkgoWriterOutput("after-suite"))) 71 }) 72 }) 73 74 Describe("individual test aborts", func() { 75 Describe("when an It aborts", func() { 76 BeforeEach(func() { 77 success, _ := RunFixture("failed it", func() { 78 BeforeSuite(rt.T("before-suite")) 79 Describe("top-level", func() { 80 It("A", rt.T("A", func() { 81 writer.Write([]byte("running A")) 82 })) 83 It("B", rt.T("B", func() { 84 writer.Write([]byte("running B")) 85 Abort("abort", cl) 86 })) 87 It("C", rt.T("C")) 88 It("D", rt.T("D")) 89 }) 90 AfterEach(rt.T("after-each")) 91 AfterSuite(rt.T("after-suite")) 92 }) 93 Ω(success).Should(BeFalse()) 94 }) 95 96 It("reports a suite failure", func() { 97 Ω(reporter.End).Should(BeASuiteSummary(false, NSpecs(4), NPassed(1), NFailed(1), NSkipped(2))) 98 }) 99 100 It("does not run subsequent Its, the AfterEach, and the AfterSuite", func() { 101 Ω(rt).Should(HaveTracked("before-suite", "A", "after-each", "B", "after-each", "after-suite")) 102 }) 103 104 It("reports the It's abort and subsequent tests as skipped", func() { 105 Ω(reporter.Did.Find("A")).Should(HavePassed(CapturedGinkgoWriterOutput("running A"))) 106 Ω(reporter.Did.Find("B")).Should(HaveAborted("abort", cl, CapturedGinkgoWriterOutput("running B"))) 107 Ω(reporter.Did.Find("C")).Should(HaveBeenSkipped()) 108 Ω(reporter.Did.Find("D")).Should(HaveBeenSkipped()) 109 }) 110 111 It("sets up the failure node location correctly", func() { 112 report := reporter.Did.Find("B") 113 Ω(report.Failure.FailureNodeContext).Should(Equal(types.FailureNodeIsLeafNode)) 114 Ω(report.Failure.FailureNodeType).Should(Equal(types.NodeTypeIt)) 115 Ω(report.Failure.FailureNodeLocation).Should(Equal(report.LeafNodeLocation)) 116 }) 117 }) 118 }) 119 120 Describe("when a test fails then an AfterEach aborts", func() { 121 BeforeEach(func() { 122 success, _ := RunFixture("failed it then after-each aborts", func() { 123 BeforeSuite(rt.T("before-suite")) 124 Describe("top-level", func() { 125 It("A", rt.T("A")) 126 It("B", rt.T("B", func() { 127 writer.Write([]byte("running B")) 128 F("fail") 129 })) 130 It("C", rt.T("C")) 131 It("D", rt.T("D")) 132 }) 133 ReportAfterEach(func(report SpecReport) { 134 rt.Run("report-after-each") 135 if report.State.Is(types.SpecStateFailed) { 136 Abort("abort", cl) 137 } 138 }) 139 AfterSuite(rt.T("after-suite")) 140 }) 141 Ω(success).Should(BeFalse()) 142 }) 143 144 It("reports a suite failure", func() { 145 Ω(reporter.End).Should(BeASuiteSummary(false, NSpecs(4), NPassed(1), NFailed(1), NSkipped(2))) 146 }) 147 148 It("does not run subsequent Its, the AfterEach, and the AfterSuite", func() { 149 Ω(rt).Should(HaveTracked("before-suite", "A", "report-after-each", "B", "report-after-each", "report-after-each", "report-after-each", "after-suite")) 150 }) 151 152 It("reports a failure and then aborts the rest of the suite", func() { 153 Ω(reporter.Did.Find("A")).Should(HavePassed()) 154 Ω(reporter.Did.Find("B")).Should(HaveAborted("abort", cl, CapturedGinkgoWriterOutput("running B"))) 155 Ω(reporter.Did.Find("C")).Should(HaveBeenSkipped()) 156 Ω(reporter.Did.Find("D")).Should(HaveBeenSkipped()) 157 }) 158 }) 159 160 Describe("when running in parallel and a test aborts", func() { 161 BeforeEach(func() { 162 SetUpForParallel(2) 163 }) 164 165 It("notifies the server of the abort", func() { 166 Ω(client.ShouldAbort()).Should(BeFalse()) 167 success, _ := RunFixture("aborting in parallel", func() { 168 It("A", func() { 169 Abort("abort") 170 }) 171 }) 172 Ω(success).Should(BeFalse()) 173 Ω(client.ShouldAbort()).Should(BeTrue()) 174 }) 175 }) 176 })