package internal_integration_test
import (
. "github.com/onsi/ginkgo/v2"
"github.com/onsi/ginkgo/v2/types"
. "github.com/onsi/gomega"
. "github.com/onsi/ginkgo/v2/internal/test_helpers"
)
var _ = Describe("Skip", func() {
Context("When Skip() is called in individual subject and setup nodes", func() {
BeforeEach(func() {
success, _ := RunFixture("Skip() tests", func() {
Describe("container to ensure order", func() {
It("A", rt.T("A"))
Describe("container", func() {
BeforeEach(rt.T("bef", func() {
failer.Skip("skip in Bef", cl)
panic("boom") //simulates what Ginkgo DSL does
}))
It("B", rt.T("B"))
It("C", rt.T("C"))
AfterEach(rt.T("aft"))
})
It("D", rt.T("D", func() {
failer.Skip("skip D", cl)
panic("boom") //simulates what Ginkgo DSL does
}))
})
})
Ω(success).Should(BeTrue())
})
It("skips the tests that are Skipped()", func() {
Ω(rt).Should(HaveTracked("A", "bef", "aft", "bef", "aft", "D"))
Ω(reporter.Did.WithState(types.SpecStatePassed).Names()).Should(ConsistOf("A"))
Ω(reporter.Did.WithState(types.SpecStateSkipped).Names()).Should(ConsistOf("B", "C", "D"))
Ω(reporter.Did.Find("B").Failure.Message).Should(Equal("skip in Bef"))
Ω(reporter.Did.Find("B").Failure.Location).Should(Equal(cl))
Ω(reporter.Did.Find("D").Failure.Message).Should(Equal("skip D"))
Ω(reporter.Did.Find("D").Failure.Location).Should(Equal(cl))
})
It("report on the suite with accurate numbers", func() {
Ω(reporter.End).Should(BeASuiteSummary(true, NPassed(1), NSkipped(3), NPending(0), NSpecs(4), NWillRun(4)))
})
})
Context("when Skip() is called in BeforeSuite", func() {
BeforeEach(func() {
success, _ := RunFixture("Skip() BeforeSuite", func() {
BeforeSuite(func() {
rt.Run("befs")
Skip("skip please")
})
Describe("container to ensure order", func() {
It("A", rt.T("A"))
It("B", rt.T("B"))
It("C", rt.T("C"))
})
})
Ω(success).Should(BeTrue())
})
It("skips all the tsts", func() {
Ω(rt).Should(HaveTracked("befs"))
Ω(reporter.Did.FindByLeafNodeType(types.NodeTypeBeforeSuite)).Should(HaveBeenSkippedWithMessage("skip please"))
Ω(reporter.Did.Find("A")).Should(HaveBeenSkipped())
Ω(reporter.Did.Find("B")).Should(HaveBeenSkipped())
Ω(reporter.Did.Find("C")).Should(HaveBeenSkipped())
})
It("report on the suite with accurate numbers", func() {
Ω(reporter.End).Should(BeASuiteSummary(true, NPassed(0), NSkipped(3), NPending(0), NSpecs(3), NWillRun(3)))
Ω(reporter.End.SpecialSuiteFailureReasons).Should(ContainElement("Suite skipped in BeforeSuite"))
})
})
})
package internal_integration_test
import (
. "github.com/onsi/ginkgo/v2"
"github.com/onsi/ginkgo/v2/types"
. "github.com/onsi/gomega"
. "github.com/onsi/ginkgo/v2/internal/test_helpers"
)
var _ = Describe("Focus", func() {
Describe("when a suite has pending tests", func() {
fixture := func() {
It("A", rt.T("A"))
It("B", rt.T("B"))
It("C", rt.T("C"), Pending)
Describe("container", func() {
It("D", rt.T("D"))
})
PDescribe("pending container", func() {
It("E", rt.T("E"))
It("F", rt.T("F"))
})
}
Context("without config.FailOnPending", func() {
BeforeEach(func() {
success, hPF := RunFixture("pending tests", fixture)
Ω(success).Should(BeTrue())
Ω(hPF).Should(BeFalse())
})
It("should not report that the suite hasProgrammaticFocus", func() {
Ω(reporter.Begin.SuiteHasProgrammaticFocus).Should(BeFalse())
Ω(reporter.End.SuiteHasProgrammaticFocus).Should(BeFalse())
})
It("does not run the pending tests", func() {
Ω(rt.TrackedRuns()).Should(ConsistOf("A", "B", "D"))
})
It("reports on the pending tests", func() {
Ω(reporter.Did.WithState(types.SpecStatePassed).Names()).Should(ConsistOf("A", "B", "D"))
Ω(reporter.Did.WithState(types.SpecStatePending).Names()).Should(ConsistOf("C", "E", "F"))
})
It("reports on the suite with accurate numbers", func() {
Ω(reporter.End).Should(BeASuiteSummary(true, NSpecs(6), NPassed(3), NPending(3), NWillRun(3), NSkipped(0)))
})
It("does not include a special suite failure reason", func() {
Ω(reporter.End.SpecialSuiteFailureReasons).Should(BeEmpty())
})
})
Context("with config.FailOnPending", func() {
BeforeEach(func() {
conf.FailOnPending = true
success, hPF := RunFixture("pending tests", fixture)
Ω(success).Should(BeFalse())
Ω(hPF).Should(BeFalse())
})
It("reports on the suite with accurate numbers", func() {
Ω(reporter.End).Should(BeASuiteSummary(false, NPassed(3), NSpecs(6), NPending(3), NWillRun(3), NSkipped(0)))
})
It("includes a special suite failure reason", func() {
Ω(reporter.End.SpecialSuiteFailureReasons).Should(ContainElement("Detected pending specs and --fail-on-pending is set"))
})
})
})
Describe("with programmatic focus", func() {
var success bool
var hasProgrammaticFocus bool
BeforeEach(func() {
success, hasProgrammaticFocus = RunFixture("focused tests", func() {
It("A", rt.T("A"))
It("B", rt.T("B"))
FDescribe("focused container", func() {
It("C", rt.T("C"))
It("D", rt.T("D"))
PIt("E", rt.T("E"))
})
FDescribe("focused container with focused child", func() {
It("F", rt.T("F"))
It("G", Focus, rt.T("G"))
})
Describe("container", func() {
It("H", rt.T("H"))
})
FIt("I", rt.T("I"))
})
Ω(success).Should(BeTrue())
})
It("should return true for hasProgrammaticFocus", func() {
Ω(hasProgrammaticFocus).Should(BeTrue())
})
It("should report that the suite hasProgrammaticFocus", func() {
Ω(reporter.Begin.SuiteHasProgrammaticFocus).Should(BeTrue())
Ω(reporter.End.SuiteHasProgrammaticFocus).Should(BeTrue())
})
It("should run the focused tests, honoring the nested focus policy", func() {
Ω(rt.TrackedRuns()).Should(ConsistOf("C", "D", "G", "I"))
})
It("should report on the tests correctly", func() {
Ω(reporter.Did.WithState(types.SpecStateSkipped).Names()).Should(ConsistOf("A", "B", "F", "H"))
Ω(reporter.Did.WithState(types.SpecStatePending).Names()).Should(ConsistOf("E"))
Ω(reporter.Did.WithState(types.SpecStatePassed).Names()).Should(ConsistOf("C", "D", "G", "I"))
})
It("report on the suite with accurate numbers", func() {
Ω(reporter.End).Should(BeASuiteSummary(true, NPassed(4), NSkipped(4), NPending(1), NSpecs(9), NWillRun(4)))
})
})
Describe("with config.FocusStrings and config.SkipStrings", func() {
BeforeEach(func() {
conf.FocusStrings = []string{"blue", "green"}
conf.SkipStrings = []string{"red"}
success, _ := RunFixture("cli focus tests", func() {
It("blue.1", rt.T("blue.1"))
It("blue.2", rt.T("blue.2"))
Describe("blue.container", func() {
It("yellow.1", rt.T("yellow.1"))
It("red.1", rt.T("red.1"))
PIt("blue.3", rt.T("blue.3"))
})
Describe("green.container", func() {
It("yellow.2", rt.T("yellow.2"))
It("green.1", rt.T("green.1"))
})
Describe("red.2", func() {
It("green.2", rt.T("green.2"))
})
FIt("red.3", rt.T("red.3"))
})
Ω(success).Should(BeTrue())
})
It("should run tests that match", func() {
Ω(rt.TrackedRuns()).Should(ConsistOf("blue.1", "blue.2", "yellow.1", "yellow.2", "green.1"))
})
It("should report on the tests correctly", func() {
Ω(reporter.Did.WithState(types.SpecStateSkipped).Names()).Should(ConsistOf("red.1", "green.2", "red.3"))
Ω(reporter.Did.WithState(types.SpecStatePending).Names()).Should(ConsistOf("blue.3"))
Ω(reporter.Did.WithState(types.SpecStatePassed).Names()).Should(ConsistOf("blue.1", "blue.2", "yellow.1", "yellow.2", "green.1"))
})
It("report on the suite with accurate numbers", func() {
Ω(reporter.End).Should(BeASuiteSummary(true, NPassed(5), NSkipped(3), NPending(1), NSpecs(9), NWillRun(5)))
})
})
Describe("when no tests will end up running", func() {
BeforeEach(func() {
conf.FocusStrings = []string{"red"}
success, _ := RunFixture("cli focus tests", func() {
BeforeSuite(rt.T("bef-suite"))
AfterSuite(rt.T("aft-suite"))
It("blue.1", rt.T("blue.1"))
It("blue.2", rt.T("blue.2"))
})
Ω(success).Should(BeTrue())
})
It("does not run the BeforeSuite or the AfterSuite", func() {
Ω(rt).Should(HaveTrackedNothing())
})
})
Describe("Skip()", func() {
BeforeEach(func() {
success, _ := RunFixture("Skip() tests", func() {
Describe("container to ensure order", func() {
It("A", rt.T("A"))
Describe("container", func() {
BeforeEach(rt.T("bef", func() {
failer.Skip("skip in Bef", cl)
panic("boom") //simulates what Ginkgo DSL does
}))
It("B", rt.T("B"))
It("C", rt.T("C"))
AfterEach(rt.T("aft"))
})
It("D", rt.T("D", func() {
failer.Skip("skip D", cl)
panic("boom") //simulates what Ginkgo DSL does
}))
})
})
Ω(success).Should(BeTrue())
})
It("skips the tests that are Skipped()", func() {
Ω(rt).Should(HaveTracked("A", "bef", "aft", "bef", "aft", "D"))
Ω(reporter.Did.WithState(types.SpecStatePassed).Names()).Should(ConsistOf("A"))
Ω(reporter.Did.WithState(types.SpecStateSkipped).Names()).Should(ConsistOf("B", "C", "D"))
Ω(reporter.Did.Find("B").Failure.Message).Should(Equal("skip in Bef"))
Ω(reporter.Did.Find("B").Failure.Location).Should(Equal(cl))
Ω(reporter.Did.Find("D").Failure.Message).Should(Equal("skip D"))
Ω(reporter.Did.Find("D").Failure.Location).Should(Equal(cl))
})
It("report on the suite with accurate numbers", func() {
Ω(reporter.End).Should(BeASuiteSummary(true, NPassed(1), NSkipped(3), NPending(0), NSpecs(4), NWillRun(4)))
})
})
})
package internal_integration_test
import (
"time"
. "github.com/onsi/ginkgo/v2"
"github.com/onsi/ginkgo/v2/internal/interrupt_handler"
. "github.com/onsi/ginkgo/v2/internal/test_helpers"
"github.com/onsi/ginkgo/v2/types"
. "github.com/onsi/gomega"
)
var _ = Describe("When a test suite is interrupted", func() {
Describe("when it is interrupted in a BeforeSuite", func() {
BeforeEach(func() {
success, _ := RunFixture("interrupted test", func() {
BeforeSuite(rt.T("before-suite", func() {
interruptHandler.Interrupt(interrupt_handler.InterruptCauseTimeout)
time.Sleep(time.Hour)
}))
AfterSuite(rt.T("after-suite"))
It("A", rt.T("A"))
It("B", rt.T("B"))
})
Ω(success).Should(Equal(false))
})
It("runs the AfterSuite and skips all the tests", func() {
Ω(rt).Should(HaveTracked("before-suite", "after-suite"))
Ω(reporter.Did.FindByLeafNodeType(types.NodeTypeIt)).Should(BeZero())
})
It("reports the correct failure", func() {
summary := reporter.Did.FindByLeafNodeType(types.NodeTypeBeforeSuite)
Ω(summary.State).Should(Equal(types.SpecStateInterrupted))
Ω(summary.Failure.Message).Should(ContainSubstring("Interrupted by Timeout\nstack trace"))
})
It("reports the correct statistics", func() {
Ω(reporter.End).Should(BeASuiteSummary(false, NSpecs(2), NWillRun(2), NPassed(0), NSkipped(0), NFailed(0)))
})
It("reports the correct special failure reason", func() {
Ω(reporter.End.SpecialSuiteFailureReasons).Should(ContainElement("Interrupted by Timeout"))
})
})
Describe("when it is interrupted in a test", func() {
BeforeEach(func() {
conf.FlakeAttempts = 3
success, _ := RunFixture("interrupted test", func() {
BeforeSuite(rt.T("before-suite"))
AfterSuite(rt.T("after-suite"))
BeforeEach(rt.T("bef.1"))
AfterEach(rt.T("aft.1"))
Describe("container", func() {
BeforeEach(rt.T("bef.2"))
AfterEach(rt.T("aft.2"))
It("runs", rt.T("runs"))
Describe("nested-container", func() {
BeforeEach(rt.T("bef.3-interrupt!", func() {
interruptHandler.Interrupt(interrupt_handler.InterruptCauseTimeout)
time.Sleep(time.Hour)
}))
AfterEach(rt.T("aft.3a"))
AfterEach(rt.T("aft.3b", func() {
interruptHandler.Interrupt(interrupt_handler.InterruptCauseTimeout)
time.Sleep(time.Hour)
}))
Describe("deeply-nested-container", func() {
BeforeEach(rt.T("bef.4"))
AfterEach(rt.T("aft.4"))
It("the interrupted test", rt.T("the interrupted test"))
It("skipped.1", rt.T("skipped.1"))
})
})
It("skipped.2", rt.T("skipped.2"))
})
})
Ω(success).Should(Equal(false))
})
It("unwinds the after eaches at the appropriate nesting level, allowing additional interrupts of after eaches as it goes", func() {
Ω(rt).Should(HaveTracked("before-suite",
"bef.1", "bef.2", "runs", "aft.2", "aft.1",
"bef.1", "bef.2", "bef.3-interrupt!", "aft.3a", "aft.3b", "aft.2", "aft.1",
"after-suite"))
})
It("skips subsequent tests", func() {
Ω(reporter.Did.WithState(types.SpecStatePassed).Names()).Should(ConsistOf("runs"))
Ω(reporter.Did.WithState(types.SpecStateInterrupted).Names()).Should(ConsistOf("the interrupted test"))
Ω(reporter.Did.WithState(types.SpecStateSkipped).Names()).Should(ConsistOf("skipped.1", "skipped.2"))
})
It("reports the interrupted test as interrupted and emits a stack trace", func() {
message := reporter.Did.Find("the interrupted test").Failure.Message
Ω(message).Should(ContainSubstring("Interrupted by Timeout\nstack trace"))
})
It("reports the correct statistics", func() {
Ω(reporter.End).Should(BeASuiteSummary(false, NSpecs(4), NWillRun(4), NPassed(1), NSkipped(2), NFailed(1)))
Ω(reporter.End.SpecialSuiteFailureReasons).Should(ContainElement("Interrupted by Timeout"))
})
})
})