github.com/onsi/ginkgo@v1.16.6-0.20211118180735-4e1925ba4c95/internal/internal_integration/focus_test.go (about) 1 package internal_integration_test 2 3 import ( 4 . "github.com/onsi/ginkgo" 5 "github.com/onsi/ginkgo/types" 6 . "github.com/onsi/gomega" 7 8 . "github.com/onsi/ginkgo/internal/test_helpers" 9 ) 10 11 var _ = Describe("Focus", func() { 12 Describe("when a suite has pending tests", func() { 13 fixture := func() { 14 It("A", rt.T("A")) 15 It("B", rt.T("B")) 16 It("C", rt.T("C"), Pending) 17 Describe("container", func() { 18 It("D", rt.T("D")) 19 }) 20 PDescribe("pending container", func() { 21 It("E", rt.T("E")) 22 It("F", rt.T("F")) 23 }) 24 } 25 Context("without config.FailOnPending", func() { 26 BeforeEach(func() { 27 success, hPF := RunFixture("pending tests", fixture) 28 Ω(success).Should(BeTrue()) 29 Ω(hPF).Should(BeFalse()) 30 }) 31 32 It("should not report that the suite hasProgrammaticFocus", func() { 33 Ω(reporter.Begin.SuiteHasProgrammaticFocus).Should(BeFalse()) 34 Ω(reporter.End.SuiteHasProgrammaticFocus).Should(BeFalse()) 35 }) 36 37 It("does not run the pending tests", func() { 38 Ω(rt.TrackedRuns()).Should(ConsistOf("A", "B", "D")) 39 }) 40 41 It("reports on the pending tests", func() { 42 Ω(reporter.Did.WithState(types.SpecStatePassed).Names()).Should(ConsistOf("A", "B", "D")) 43 Ω(reporter.Did.WithState(types.SpecStatePending).Names()).Should(ConsistOf("C", "E", "F")) 44 }) 45 46 It("reports on the suite with accurate numbers", func() { 47 Ω(reporter.End).Should(BeASuiteSummary(true, NSpecs(6), NPassed(3), NPending(3), NWillRun(3), NSkipped(0))) 48 }) 49 50 It("does not include a special suite failure reason", func() { 51 Ω(reporter.End.SpecialSuiteFailureReasons).Should(BeEmpty()) 52 }) 53 }) 54 55 Context("with config.FailOnPending", func() { 56 BeforeEach(func() { 57 conf.FailOnPending = true 58 success, hPF := RunFixture("pending tests", fixture) 59 Ω(success).Should(BeFalse()) 60 Ω(hPF).Should(BeFalse()) 61 }) 62 63 It("reports on the suite with accurate numbers", func() { 64 Ω(reporter.End).Should(BeASuiteSummary(false, NPassed(3), NSpecs(6), NPending(3), NWillRun(3), NSkipped(0))) 65 }) 66 67 It("includes a special suite failure reason", func() { 68 Ω(reporter.End.SpecialSuiteFailureReasons).Should(ContainElement("Detected pending specs and --fail-on-pending is set")) 69 }) 70 }) 71 }) 72 73 Describe("with programmatic focus", func() { 74 var success bool 75 var hasProgrammaticFocus bool 76 BeforeEach(func() { 77 success, hasProgrammaticFocus = RunFixture("focused tests", func() { 78 It("A", rt.T("A")) 79 It("B", rt.T("B")) 80 FDescribe("focused container", func() { 81 It("C", rt.T("C")) 82 It("D", rt.T("D")) 83 PIt("E", rt.T("E")) 84 }) 85 FDescribe("focused container with focused child", func() { 86 It("F", rt.T("F")) 87 It("G", Focus, rt.T("G")) 88 }) 89 Describe("container", func() { 90 It("H", rt.T("H")) 91 }) 92 FIt("I", rt.T("I")) 93 }) 94 Ω(success).Should(BeTrue()) 95 }) 96 97 It("should return true for hasProgrammaticFocus", func() { 98 Ω(hasProgrammaticFocus).Should(BeTrue()) 99 }) 100 101 It("should report that the suite hasProgrammaticFocus", func() { 102 Ω(reporter.Begin.SuiteHasProgrammaticFocus).Should(BeTrue()) 103 Ω(reporter.End.SuiteHasProgrammaticFocus).Should(BeTrue()) 104 }) 105 106 It("should run the focused tests, honoring the nested focus policy", func() { 107 Ω(rt.TrackedRuns()).Should(ConsistOf("C", "D", "G", "I")) 108 }) 109 110 It("should report on the tests correctly", func() { 111 Ω(reporter.Did.WithState(types.SpecStateSkipped).Names()).Should(ConsistOf("A", "B", "F", "H")) 112 Ω(reporter.Did.WithState(types.SpecStatePending).Names()).Should(ConsistOf("E")) 113 Ω(reporter.Did.WithState(types.SpecStatePassed).Names()).Should(ConsistOf("C", "D", "G", "I")) 114 }) 115 116 It("report on the suite with accurate numbers", func() { 117 Ω(reporter.End).Should(BeASuiteSummary(true, NPassed(4), NSkipped(4), NPending(1), NSpecs(9), NWillRun(4))) 118 }) 119 }) 120 121 Describe("with config.FocusStrings and config.SkipStrings", func() { 122 BeforeEach(func() { 123 conf.FocusStrings = []string{"blue", "green"} 124 conf.SkipStrings = []string{"red"} 125 success, _ := RunFixture("cli focus tests", func() { 126 It("blue.1", rt.T("blue.1")) 127 It("blue.2", rt.T("blue.2")) 128 Describe("blue.container", func() { 129 It("yellow.1", rt.T("yellow.1")) 130 It("red.1", rt.T("red.1")) 131 PIt("blue.3", rt.T("blue.3")) 132 }) 133 Describe("green.container", func() { 134 It("yellow.2", rt.T("yellow.2")) 135 It("green.1", rt.T("green.1")) 136 }) 137 Describe("red.2", func() { 138 It("green.2", rt.T("green.2")) 139 }) 140 FIt("red.3", rt.T("red.3")) 141 }) 142 Ω(success).Should(BeTrue()) 143 }) 144 145 It("should run tests that match", func() { 146 Ω(rt.TrackedRuns()).Should(ConsistOf("blue.1", "blue.2", "yellow.1", "yellow.2", "green.1")) 147 }) 148 149 It("should report on the tests correctly", func() { 150 Ω(reporter.Did.WithState(types.SpecStateSkipped).Names()).Should(ConsistOf("red.1", "green.2", "red.3")) 151 Ω(reporter.Did.WithState(types.SpecStatePending).Names()).Should(ConsistOf("blue.3")) 152 Ω(reporter.Did.WithState(types.SpecStatePassed).Names()).Should(ConsistOf("blue.1", "blue.2", "yellow.1", "yellow.2", "green.1")) 153 }) 154 155 It("report on the suite with accurate numbers", func() { 156 Ω(reporter.End).Should(BeASuiteSummary(true, NPassed(5), NSkipped(3), NPending(1), NSpecs(9), NWillRun(5))) 157 }) 158 }) 159 160 Describe("when no tests will end up running", func() { 161 BeforeEach(func() { 162 conf.FocusStrings = []string{"red"} 163 success, _ := RunFixture("cli focus tests", func() { 164 BeforeSuite(rt.T("bef-suite")) 165 AfterSuite(rt.T("aft-suite")) 166 It("blue.1", rt.T("blue.1")) 167 It("blue.2", rt.T("blue.2")) 168 }) 169 Ω(success).Should(BeTrue()) 170 }) 171 172 It("does not run the BeforeSuite or the AfterSuite", func() { 173 Ω(rt).Should(HaveTrackedNothing()) 174 }) 175 }) 176 177 Describe("Skip()", func() { 178 BeforeEach(func() { 179 success, _ := RunFixture("Skip() tests", func() { 180 Describe("container to ensure order", func() { 181 It("A", rt.T("A")) 182 Describe("container", func() { 183 BeforeEach(rt.T("bef", func() { 184 failer.Skip("skip in Bef", cl) 185 panic("boom") //simulates what Ginkgo DSL does 186 })) 187 It("B", rt.T("B")) 188 It("C", rt.T("C")) 189 AfterEach(rt.T("aft")) 190 }) 191 It("D", rt.T("D", func() { 192 failer.Skip("skip D", cl) 193 panic("boom") //simulates what Ginkgo DSL does 194 })) 195 }) 196 }) 197 198 Ω(success).Should(BeTrue()) 199 }) 200 201 It("skips the tests that are Skipped()", func() { 202 Ω(rt).Should(HaveTracked("A", "bef", "aft", "bef", "aft", "D")) 203 Ω(reporter.Did.WithState(types.SpecStatePassed).Names()).Should(ConsistOf("A")) 204 Ω(reporter.Did.WithState(types.SpecStateSkipped).Names()).Should(ConsistOf("B", "C", "D")) 205 206 Ω(reporter.Did.Find("B").Failure.Message).Should(Equal("skip in Bef")) 207 Ω(reporter.Did.Find("B").Failure.Location).Should(Equal(cl)) 208 209 Ω(reporter.Did.Find("D").Failure.Message).Should(Equal("skip D")) 210 Ω(reporter.Did.Find("D").Failure.Location).Should(Equal(cl)) 211 }) 212 213 It("report on the suite with accurate numbers", func() { 214 Ω(reporter.End).Should(BeASuiteSummary(true, NPassed(1), NSkipped(3), NPending(0), NSpecs(4), NWillRun(4))) 215 }) 216 }) 217 })