github.com/onsi/ginkgo@v1.16.6-0.20211118180735-4e1925ba4c95/integration/abort_test.go (about)

     1  package integration_test
     2  
     3  import (
     4  	. "github.com/onsi/ginkgo"
     5  	. "github.com/onsi/gomega"
     6  	"github.com/onsi/gomega/gbytes"
     7  	"github.com/onsi/gomega/gexec"
     8  
     9  	"github.com/onsi/ginkgo/internal/interrupt_handler"
    10  	. "github.com/onsi/ginkgo/internal/test_helpers"
    11  	"github.com/onsi/ginkgo/reporters"
    12  	"github.com/onsi/ginkgo/types"
    13  )
    14  
    15  var _ = Describe("Abort", func() {
    16  	var session *gexec.Session
    17  	BeforeEach(func() {
    18  		fm.MountFixture("abort")
    19  		session = startGinkgo(fm.PathTo("abort"), "--no-color", "--json-report=out.json", "--junit-report=out.xml", "--procs=2")
    20  		Eventually(session).Should(gexec.Exit(1))
    21  	})
    22  
    23  	It("aborts the suite and does not run any subsequent tests", func() {
    24  		Ω(session).Should(gbytes.Say("this suite needs to end now!"))
    25  		Ω(string(session.Out.Contents())).ShouldNot(ContainSubstring("SHOULD NOT SEE THIS"))
    26  	})
    27  
    28  	It("reports on the test run correctly", func() {
    29  		report := fm.LoadJSONReports("abort", "out.json")[0]
    30  		specs := Reports(report.SpecReports)
    31  		Ω(specs.Find("runs and passes")).Should(HavePassed())
    32  		Ω(specs.Find("aborts")).Should(HaveAborted("this suite needs to end now!"))
    33  		Ω(specs.Find("never runs")).Should(HaveBeenInterrupted(interrupt_handler.InterruptCauseAbortByOtherProcess))
    34  		Ω(specs.Find("never runs either")).Should(HaveBeenSkipped())
    35  
    36  		junitSuites := fm.LoadJUnitReport("abort", "out.xml")
    37  		cases := junitSuites.TestSuites[0].TestCases
    38  		var abortCase reporters.JUnitTestCase
    39  		for _, testCase := range cases {
    40  			if testCase.Status == types.SpecStateAborted.String() {
    41  				abortCase = testCase
    42  			}
    43  		}
    44  		Ω(abortCase.Failure.Message).Should(Equal("this suite needs to end now!"))
    45  		Ω(abortCase.Failure.Type).Should(Equal("aborted"))
    46  	})
    47  })