From 11459a886d9cd66b319dac7ef1e917ee221372c9 Mon Sep 17 00:00:00 2001 From: Joe Fitzgerald Date: Mon, 28 Aug 2017 19:22:21 -0600 Subject: [PATCH] Allow coverage to be displayed for focused specs (#367) * Allow coverage to be displayed for focused specs * Add integration test for GINKGO_EDITOR_INTEGRATION --- ginkgo/run_command.go | 8 +++++--- ginkgo_dsl.go | 2 +- integration/run_test.go | 19 +++++++++++++++++++ 3 files changed, 25 insertions(+), 4 deletions(-) diff --git a/ginkgo/run_command.go b/ginkgo/run_command.go index 2fb4ab253..7ec8d82a3 100644 --- a/ginkgo/run_command.go +++ b/ginkgo/run_command.go @@ -5,14 +5,16 @@ import ( "fmt" "math/rand" "os" + "strings" "time" + "io/ioutil" + "path/filepath" + "github.com/onsi/ginkgo/config" "github.com/onsi/ginkgo/ginkgo/interrupthandler" "github.com/onsi/ginkgo/ginkgo/testrunner" "github.com/onsi/ginkgo/types" - "io/ioutil" - "path/filepath" ) func BuildRunCommand() *Command { @@ -121,7 +123,7 @@ func (r *SpecRunner) RunSpecs(args []string, additionalArgs []string) { fmt.Printf("\nGinkgo ran %d %s in %s\n", numSuites, pluralizedWord("suite", "suites", numSuites), time.Since(t)) if runResult.Passed { - if runResult.HasProgrammaticFocus { + if runResult.HasProgrammaticFocus && strings.TrimSpace(os.Getenv("GINKGO_EDITOR_INTEGRATION")) == "" { fmt.Printf("Test Suite Passed\n") fmt.Printf("Detected Programmatic Focus - setting exit status to %d\n", types.GINKGO_FOCUS_EXIT_CODE) os.Exit(types.GINKGO_FOCUS_EXIT_CODE) diff --git a/ginkgo_dsl.go b/ginkgo_dsl.go index de6757c9f..8befd35ad 100644 --- a/ginkgo_dsl.go +++ b/ginkgo_dsl.go @@ -216,7 +216,7 @@ func RunSpecsWithCustomReporters(t GinkgoTestingT, description string, specRepor reporters[i] = reporter } passed, hasFocusedTests := globalSuite.Run(t, description, reporters, writer, config.GinkgoConfig) - if passed && hasFocusedTests { + if passed && hasFocusedTests && strings.TrimSpace(os.Getenv("GINKGO_EDITOR_INTEGRATION")) == "" { fmt.Println("PASS | FOCUSED") os.Exit(types.GINKGO_FOCUS_EXIT_CODE) } diff --git a/integration/run_test.go b/integration/run_test.go index 7f320bd53..871ba7ecb 100644 --- a/integration/run_test.go +++ b/integration/run_test.go @@ -2,6 +2,7 @@ package integration_test import ( "fmt" + "os" "regexp" "runtime" "strings" @@ -98,6 +99,24 @@ var _ = Describe("Running Specs", func() { Ω(output).Should(ContainSubstring("Test Suite Passed")) Ω(output).Should(ContainSubstring("Detected Programmatic Focus - setting exit status to %d", types.GINKGO_FOCUS_EXIT_CODE)) }) + + Context("when the GINKGO_EDITOR_INTEGRATION environment variable is set", func() { + BeforeEach(func() { + os.Setenv("GINKGO_EDITOR_INTEGRATION", "true") + }) + AfterEach(func() { + os.Setenv("GINKGO_EDITOR_INTEGRATION", "") + }) + It("should exit with a status code of 0 to allow a coverage file to be generated", func() { + session := startGinkgo(tmpDir, "--noColor", "--succinct=false", "-r") + Eventually(session).Should(gexec.Exit(0)) + output := string(session.Out.Contents()) + + Ω(output).Should(ContainSubstring("Running Suite: Passing_ginkgo_tests Suite")) + Ω(output).Should(ContainSubstring("Running Suite: More_ginkgo_tests Suite")) + Ω(output).Should(ContainSubstring("Test Suite Passed")) + }) + }) }) Context("when told to skipPackages", func() {