Skip to content

Commit

Permalink
Allow coverage to be displayed for focused specs (#367)
Browse files Browse the repository at this point in the history
* Allow coverage to be displayed for focused specs

* Add integration test for GINKGO_EDITOR_INTEGRATION
  • Loading branch information
joefitzgerald authored and onsi committed Aug 29, 2017
1 parent 8382b23 commit 11459a8
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 4 deletions.
8 changes: 5 additions & 3 deletions ginkgo/run_command.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion ginkgo_dsl.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
19 changes: 19 additions & 0 deletions integration/run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package integration_test

import (
"fmt"
"os"
"regexp"
"runtime"
"strings"
Expand Down Expand Up @@ -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() {
Expand Down

0 comments on commit 11459a8

Please sign in to comment.