Skip to content

Commit

Permalink
Add AutoReporter to use default if not in Goland
Browse files Browse the repository at this point in the history
  • Loading branch information
SemanticallyNull committed Aug 5, 2018
1 parent 46886d3 commit 5710897
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
15 changes: 12 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,22 @@ Goland to get a list of output.
This reporter will trick test2json into outputting the Ginkgo specs similar to
`go test` output.

![Ginkgo output in Goland's "Run" window](https://gist.githubusercontent.com/BenChapman/19215f014f3ef0db3c3cd0b46da4d929/raw/18801f7f19a26ea19ba48a1c95d5e068396f7dd7/image1.png)

## Usage

In your suite replace `RunSpecs(t, "Integration Suite")` with the following
In your suite replace `RunSpecs(t, "Integration Suite")` with the following:

```go

golandReporter := golandreporter.NewReporter()
golandReporter := golandreporter.NewGolandReporter()
RunSpecsWithCustomReporters(t, "Integration Suite", []Reporter{golangReporter})
```

If you want to retain normal Ginkgo formatting when using it from the CLI the
best option is to use an environment variable in your Run Configuration, and
use it like this:

```go
RunSpecsWithCustomReporters(t, "Integration Suite", []Reporter{golandreporter.NewAutoGolandReporter})
```

14 changes: 13 additions & 1 deletion golandreporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,30 @@ package golandreporter

import (
"fmt"
"os"
"strings"

"github.com/onsi/ginkgo/config"
"github.com/onsi/ginkgo/reporters"
"github.com/onsi/ginkgo/reporters/stenographer"
"github.com/onsi/ginkgo/types"
)

type GolandReporter struct{}

func NewGolandReporter() GolandReporter {
func NewGolandReporter() reporters.Reporter {
return GolandReporter{}
}

func NewAutoGolandReporter() reporters.Reporter {
if strings.Contains(os.Getenv("OLDPWD"), "Goland") {
return NewGolandReporter()
} else {
stenographer := stenographer.New(!config.DefaultReporterConfig.NoColor, config.GinkgoConfig.FlakeAttempts > 1)
return reporters.NewDefaultReporter(config.DefaultReporterConfig, stenographer)
}
}

func (g GolandReporter) SpecSuiteWillBegin(config config.GinkgoConfigType, summary *types.SuiteSummary) {

}
Expand Down

0 comments on commit 5710897

Please sign in to comment.