File: node_spec_events_test.go

package info (click to toggle)
golang-github-onsi-ginkgo-v2 2.15.0-1~bpo12%2B1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm-backports
  • size: 4,112 kB
  • sloc: javascript: 59; sh: 14; makefile: 7
file content (107 lines) | stat: -rw-r--r-- 6,930 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
package internal_integration_test

import (
	"time"

	. "github.com/onsi/ginkgo/v2"
	. "github.com/onsi/ginkgo/v2/internal/test_helpers"
	"github.com/onsi/ginkgo/v2/types"
	. "github.com/onsi/gomega"
)

var _ = Describe("Emitting Node SpecEvents", func() {
	BeforeEach(func() {
		cl = types.NewCodeLocation(0)
		success, _ := RunFixture("emitting spec progress", func() {
			BeforeSuite(func() {})
			Describe("a container", func() {
				BeforeEach(func() {})
				It("A", func() {
					time.Sleep(time.Millisecond * 20)
					writer.Print("hello\n")
				})
				It("B", func() {})
				AfterEach(func() {})
				ReportAfterEach(func(_ SpecReport) {})
			})
			AfterSuite(func() {})
			ReportAfterEach(func(_ SpecReport) {})
		})
		Ω(success).Should(BeTrue())
	})

	It("attaches appropriate spec events to each report", func() {
		Ω(reporter.Did.FindByLeafNodeType(types.NodeTypeBeforeSuite).Timeline()).Should(BeTimelineContaining(
			BeSpecEvent(types.SpecEventNodeStart, "TOP-LEVEL", types.NodeTypeBeforeSuite, clLine(2), TLWithOffset(0)),
			BeSpecEvent(types.SpecEventNodeEnd, "TOP-LEVEL", types.NodeTypeBeforeSuite, clLine(2), TLWithOffset(0)),
		))

		Ω(reporter.Did.Find("A").Timeline()).Should(BeTimelineContaining(
			BeSpecEvent(types.SpecEventNodeStart, "a container", types.NodeTypeBeforeEach, clLine(4), TLWithOffset(0)),
			BeSpecEvent(types.SpecEventNodeEnd, "a container", types.NodeTypeBeforeEach, clLine(4), TLWithOffset(0)),
			BeSpecEvent(types.SpecEventNodeStart, "A", types.NodeTypeIt, clLine(5), TLWithOffset(0)),
			BeSpecEvent(types.SpecEventNodeEnd, "A", types.NodeTypeIt, clLine(5), TLWithOffset("hello\n"), time.Millisecond*20),
			BeSpecEvent(types.SpecEventNodeStart, "a container", types.NodeTypeAfterEach, clLine(10), TLWithOffset("hello\n")),
			BeSpecEvent(types.SpecEventNodeEnd, "a container", types.NodeTypeAfterEach, clLine(10), TLWithOffset("hello\n")),
			BeSpecEvent(types.SpecEventNodeStart, "a container", types.NodeTypeReportAfterEach, clLine(11), TLWithOffset("hello\n")),
			BeSpecEvent(types.SpecEventNodeEnd, "a container", types.NodeTypeReportAfterEach, clLine(11), TLWithOffset("hello\n")),
			BeSpecEvent(types.SpecEventNodeStart, "TOP-LEVEL", types.NodeTypeReportAfterEach, clLine(14), TLWithOffset("hello\n")),
			BeSpecEvent(types.SpecEventNodeEnd, "TOP-LEVEL", types.NodeTypeReportAfterEach, clLine(14), TLWithOffset("hello\n")),
		))
		Ω(reporter.Did.Find("A").Timeline()).ShouldNot(BeTimelineContaining(BeSpecEvent(types.NodeTypeReportAfterEach, clLine(15))))

		Ω(reporter.Did.Find("B").Timeline()).Should(BeTimelineContaining(
			BeSpecEvent(types.SpecEventNodeStart, "a container", types.NodeTypeBeforeEach, clLine(4), TLWithOffset(0)),
			BeSpecEvent(types.SpecEventNodeEnd, "a container", types.NodeTypeBeforeEach, clLine(4), TLWithOffset(0)),
			BeSpecEvent(types.SpecEventNodeStart, "B", types.NodeTypeIt, clLine(9), TLWithOffset(0)),
			BeSpecEvent(types.SpecEventNodeEnd, "B", types.NodeTypeIt, clLine(9), TLWithOffset(0)),
			BeSpecEvent(types.SpecEventNodeStart, "a container", types.NodeTypeAfterEach, clLine(10), TLWithOffset(0)),
			BeSpecEvent(types.SpecEventNodeEnd, "a container", types.NodeTypeAfterEach, clLine(10), TLWithOffset(0)),
			BeSpecEvent(types.SpecEventNodeStart, "a container", types.NodeTypeReportAfterEach, clLine(11), TLWithOffset(0)),
			BeSpecEvent(types.SpecEventNodeEnd, "a container", types.NodeTypeReportAfterEach, clLine(11), TLWithOffset(0)),
			BeSpecEvent(types.SpecEventNodeStart, "TOP-LEVEL", types.NodeTypeReportAfterEach, clLine(14), TLWithOffset(0)),
			BeSpecEvent(types.SpecEventNodeEnd, "TOP-LEVEL", types.NodeTypeReportAfterEach, clLine(14), TLWithOffset(0)),
		))

		Ω(reporter.Did.FindByLeafNodeType(types.NodeTypeAfterSuite).Timeline()).Should(BeTimelineContaining(
			BeSpecEvent(types.SpecEventNodeStart, "TOP-LEVEL", types.NodeTypeAfterSuite, clLine(13), TLWithOffset(0)),
			BeSpecEvent(types.SpecEventNodeEnd, "TOP-LEVEL", types.NodeTypeAfterSuite, clLine(13), TLWithOffset(0)),
		))
	})

	It("emits each spec event as it goes", func() {
		timeline := types.Timeline{}
		for _, specEvent := range reporter.SpecEvents {
			timeline = append(timeline, specEvent)
		}
		Ω(timeline).Should(BeTimelineExactlyMatching(
			BeSpecEvent(types.SpecEventNodeStart, "TOP-LEVEL", types.NodeTypeBeforeSuite, clLine(2), TLWithOffset(0)),
			BeSpecEvent(types.SpecEventNodeEnd, "TOP-LEVEL", types.NodeTypeBeforeSuite, clLine(2), TLWithOffset(0)),

			BeSpecEvent(types.SpecEventNodeStart, "a container", types.NodeTypeBeforeEach, clLine(4), TLWithOffset(0)),
			BeSpecEvent(types.SpecEventNodeEnd, "a container", types.NodeTypeBeforeEach, clLine(4), TLWithOffset(0)),
			BeSpecEvent(types.SpecEventNodeStart, "A", types.NodeTypeIt, clLine(5), TLWithOffset(0)),
			BeSpecEvent(types.SpecEventNodeEnd, "A", types.NodeTypeIt, clLine(5), TLWithOffset("hello\n"), time.Millisecond*20),
			BeSpecEvent(types.SpecEventNodeStart, "a container", types.NodeTypeAfterEach, clLine(10), TLWithOffset("hello\n")),
			BeSpecEvent(types.SpecEventNodeEnd, "a container", types.NodeTypeAfterEach, clLine(10), TLWithOffset("hello\n")),
			BeSpecEvent(types.SpecEventNodeStart, "a container", types.NodeTypeReportAfterEach, clLine(11), TLWithOffset("hello\n")),
			BeSpecEvent(types.SpecEventNodeEnd, "a container", types.NodeTypeReportAfterEach, clLine(11), TLWithOffset("hello\n")),
			BeSpecEvent(types.SpecEventNodeStart, "TOP-LEVEL", types.NodeTypeReportAfterEach, clLine(14), TLWithOffset("hello\n")),
			BeSpecEvent(types.SpecEventNodeEnd, "TOP-LEVEL", types.NodeTypeReportAfterEach, clLine(14), TLWithOffset("hello\n")),

			BeSpecEvent(types.SpecEventNodeStart, "a container", types.NodeTypeBeforeEach, clLine(4), TLWithOffset(0)),
			BeSpecEvent(types.SpecEventNodeEnd, "a container", types.NodeTypeBeforeEach, clLine(4), TLWithOffset(0)),
			BeSpecEvent(types.SpecEventNodeStart, "B", types.NodeTypeIt, clLine(9), TLWithOffset(0)),
			BeSpecEvent(types.SpecEventNodeEnd, "B", types.NodeTypeIt, clLine(9), TLWithOffset(0)),
			BeSpecEvent(types.SpecEventNodeStart, "a container", types.NodeTypeAfterEach, clLine(10), TLWithOffset(0)),
			BeSpecEvent(types.SpecEventNodeEnd, "a container", types.NodeTypeAfterEach, clLine(10), TLWithOffset(0)),
			BeSpecEvent(types.SpecEventNodeStart, "a container", types.NodeTypeReportAfterEach, clLine(11), TLWithOffset(0)),
			BeSpecEvent(types.SpecEventNodeEnd, "a container", types.NodeTypeReportAfterEach, clLine(11), TLWithOffset(0)),
			BeSpecEvent(types.SpecEventNodeStart, "TOP-LEVEL", types.NodeTypeReportAfterEach, clLine(14), TLWithOffset(0)),
			BeSpecEvent(types.SpecEventNodeEnd, "TOP-LEVEL", types.NodeTypeReportAfterEach, clLine(14), TLWithOffset(0)),

			BeSpecEvent(types.SpecEventNodeStart, "TOP-LEVEL", types.NodeTypeAfterSuite, clLine(13), TLWithOffset(0)),
			BeSpecEvent(types.SpecEventNodeEnd, "TOP-LEVEL", types.NodeTypeAfterSuite, clLine(13), TLWithOffset(0)),
		))
	})
})