Skip to content

Commit c0c77b6

Browse files
committedMay 3, 2023
Add RenderTimeline to GinkgoT()
1 parent 8b925ab commit c0c77b6

File tree

4 files changed

+45
-4
lines changed

4 files changed

+45
-4
lines changed
 

‎ginkgo_t_dsl.go

+3
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,9 @@ type FullGinkgoTInterface interface {
8080
Fi(indentation uint, format string, args ...any) string
8181
Fiw(indentation uint, maxWidth uint, format string, args ...any) string
8282

83+
//Generates a formatted string version of the current spec's timeline
84+
RenderTimeline() string
85+
8386
GinkgoRecover()
8487
DeferCleanup(args ...any)
8588

‎internal/testingtproxy/testing_t_proxy.go

+4
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77

88
"github.com/onsi/ginkgo/v2/formatter"
99
"github.com/onsi/ginkgo/v2/internal"
10+
"github.com/onsi/ginkgo/v2/reporters"
1011
"github.com/onsi/ginkgo/v2/types"
1112
)
1213

@@ -185,6 +186,9 @@ func (t *ginkgoTestingTProxy) Fi(indentation uint, format string, args ...any) s
185186
func (t *ginkgoTestingTProxy) Fiw(indentation uint, maxWidth uint, format string, args ...any) string {
186187
return t.f.Fiw(indentation, maxWidth, format, args...)
187188
}
189+
func (t *ginkgoTestingTProxy) RenderTimeline() string {
190+
return reporters.RenderTimeline(t.report(), false)
191+
}
188192
func (t *ginkgoTestingTProxy) GinkgoRecover() {
189193
t.ginkgoRecover()
190194
}

‎internal/testingtproxy/testingtproxy_test.go

+33-3
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package testingtproxy_test
33
import (
44
"os"
55
"runtime"
6+
"time"
67

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

304-
It("can provides a correctly configured Ginkgo Formatter", func() {
305+
It("can provide a correctly configured Ginkgo Formatter", func() {
305306
Ω(t.F("{{blue}}%d{{/}}", 3)).Should(Equal("3"))
306307
})
307308

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

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

317+
It("can render the timeline of the current spec", func() {
318+
cl := types.NewCustomCodeLocation("cl")
319+
reportToReturn.CapturedGinkgoWriterOutput = "ABCDEFGHIJKLMNOP"
320+
reportToReturn.SpecEvents = append(reportToReturn.SpecEvents, types.SpecEvent{
321+
TimelineLocation: types.TimelineLocation{Offset: 5, Order: 1},
322+
SpecEventType: types.SpecEventNodeStart,
323+
Message: "The Test",
324+
CodeLocation: cl,
325+
NodeType: types.NodeTypeIt,
326+
})
327+
reportToReturn.SpecEvents = append(reportToReturn.SpecEvents, types.SpecEvent{
328+
TimelineLocation: types.TimelineLocation{Offset: 10, Order: 3},
329+
SpecEventType: types.SpecEventNodeEnd,
330+
Message: "The Test",
331+
CodeLocation: cl,
332+
NodeType: types.NodeTypeIt,
333+
Duration: time.Second,
334+
})
335+
reportToReturn.State = types.SpecStateFailed
336+
reportToReturn.Failure = types.Failure{
337+
Message: "The Failure",
338+
FailureNodeType: types.NodeTypeIt,
339+
Location: cl,
340+
TimelineLocation: types.TimelineLocation{Offset: 10, Order: 2},
341+
}
342+
343+
Ω(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"))
344+
})
345+
316346
It("can provide GinkgoRecover", func() {
317347
Ω(recoverCall).Should(BeFalse())
318348
t.GinkgoRecover()

‎reporters/junit_report.go

+5-1
Original file line numberDiff line numberDiff line change
@@ -344,8 +344,12 @@ func failureDescriptionForUnstructuredReporters(spec types.SpecReport) string {
344344
}
345345

346346
func systemErrForUnstructuredReporters(spec types.SpecReport) string {
347+
return RenderTimeline(spec, true)
348+
}
349+
350+
func RenderTimeline(spec types.SpecReport, noColor bool) string {
347351
out := &strings.Builder{}
348-
NewDefaultReporter(types.ReporterConfig{NoColor: true, VeryVerbose: true}, out).emitTimeline(0, spec, spec.Timeline())
352+
NewDefaultReporter(types.ReporterConfig{NoColor: noColor, VeryVerbose: true}, out).emitTimeline(0, spec, spec.Timeline())
349353
return out.String()
350354
}
351355

0 commit comments

Comments
 (0)
Please sign in to comment.