Skip to content

Commit

Permalink
Add RenderTimeline to GinkgoT()
Browse files Browse the repository at this point in the history
  • Loading branch information
onsi committed May 3, 2023
1 parent 8b925ab commit c0c77b6
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 4 deletions.
3 changes: 3 additions & 0 deletions ginkgo_t_dsl.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@ type FullGinkgoTInterface interface {
Fi(indentation uint, format string, args ...any) string
Fiw(indentation uint, maxWidth uint, format string, args ...any) string

//Generates a formatted string version of the current spec's timeline
RenderTimeline() string

GinkgoRecover()
DeferCleanup(args ...any)

Expand Down
4 changes: 4 additions & 0 deletions internal/testingtproxy/testing_t_proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (

"github.com/onsi/ginkgo/v2/formatter"
"github.com/onsi/ginkgo/v2/internal"
"github.com/onsi/ginkgo/v2/reporters"
"github.com/onsi/ginkgo/v2/types"
)

Expand Down Expand Up @@ -185,6 +186,9 @@ func (t *ginkgoTestingTProxy) Fi(indentation uint, format string, args ...any) s
func (t *ginkgoTestingTProxy) Fiw(indentation uint, maxWidth uint, format string, args ...any) string {
return t.f.Fiw(indentation, maxWidth, format, args...)
}
func (t *ginkgoTestingTProxy) RenderTimeline() string {
return reporters.RenderTimeline(t.report(), false)
}
func (t *ginkgoTestingTProxy) GinkgoRecover() {
t.ginkgoRecover()
}
Expand Down
36 changes: 33 additions & 3 deletions internal/testingtproxy/testingtproxy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package testingtproxy_test
import (
"os"
"runtime"
"time"

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
Expand Down Expand Up @@ -301,18 +302,47 @@ var _ = Describe("Testingtproxy", func() {
Ω(string(buf.Contents())).Should(Equal(" hi 3\n"))
})

It("can provides a correctly configured Ginkgo Formatter", func() {
It("can provide a correctly configured Ginkgo Formatter", func() {
Ω(t.F("{{blue}}%d{{/}}", 3)).Should(Equal("3"))
})

It("can printf to the GinkgoWriter", func() {
It("can provide a correctly configured Ginkgo Formatter, with indentation", func() {
Ω(t.Fi(1, "{{blue}}%d{{/}}", 3)).Should(Equal(" 3"))
})

It("can println to the GinkgoWriter", func() {
It("can provide a correctly configured Ginkgo Formatter, with indentation and width constraints", func() {
Ω(t.Fiw(1, 5, "{{blue}}%d{{/}} a number", 3)).Should(Equal(" 3 a\n number"))
})

It("can render the timeline of the current spec", func() {
cl := types.NewCustomCodeLocation("cl")
reportToReturn.CapturedGinkgoWriterOutput = "ABCDEFGHIJKLMNOP"
reportToReturn.SpecEvents = append(reportToReturn.SpecEvents, types.SpecEvent{
TimelineLocation: types.TimelineLocation{Offset: 5, Order: 1},
SpecEventType: types.SpecEventNodeStart,
Message: "The Test",
CodeLocation: cl,
NodeType: types.NodeTypeIt,
})
reportToReturn.SpecEvents = append(reportToReturn.SpecEvents, types.SpecEvent{
TimelineLocation: types.TimelineLocation{Offset: 10, Order: 3},
SpecEventType: types.SpecEventNodeEnd,
Message: "The Test",
CodeLocation: cl,
NodeType: types.NodeTypeIt,
Duration: time.Second,
})
reportToReturn.State = types.SpecStateFailed
reportToReturn.Failure = types.Failure{
Message: "The Failure",
FailureNodeType: types.NodeTypeIt,
Location: cl,
TimelineLocation: types.TimelineLocation{Offset: 10, Order: 2},
}

Ω(t.RenderTimeline()).Should(Equal("ABCDE\n> Enter \x1b[1m[It]\x1b[0m The Test \x1b[38;5;243m- cl @ 01/01/01 00:00:00\x1b[0m\nFGHIJ\n\x1b[38;5;9m[FAILED] The Failure\x1b[0m\n\x1b[38;5;9mIn \x1b[1m[It]\x1b[0m\x1b[38;5;9m at: \x1b[1mcl\x1b[0m \x1b[38;5;243m@ 01/01/01 00:00:00\x1b[0m\n< Exit \x1b[1m[It]\x1b[0m The Test \x1b[38;5;243m- cl @ 01/01/01 00:00:00 (1s)\x1b[0m\nKLMNOP"))
})

It("can provide GinkgoRecover", func() {
Ω(recoverCall).Should(BeFalse())
t.GinkgoRecover()
Expand Down
6 changes: 5 additions & 1 deletion reporters/junit_report.go
Original file line number Diff line number Diff line change
Expand Up @@ -344,8 +344,12 @@ func failureDescriptionForUnstructuredReporters(spec types.SpecReport) string {
}

func systemErrForUnstructuredReporters(spec types.SpecReport) string {
return RenderTimeline(spec, true)
}

func RenderTimeline(spec types.SpecReport, noColor bool) string {
out := &strings.Builder{}
NewDefaultReporter(types.ReporterConfig{NoColor: true, VeryVerbose: true}, out).emitTimeline(0, spec, spec.Timeline())
NewDefaultReporter(types.ReporterConfig{NoColor: noColor, VeryVerbose: true}, out).emitTimeline(0, spec, spec.Timeline())
return out.String()
}

Expand Down

0 comments on commit c0c77b6

Please sign in to comment.