1 package reporters_test
2
3 import (
4 "fmt"
5 "os"
6 "path/filepath"
7 "time"
8
9 . "github.com/onsi/ginkgo/v2"
10 . "github.com/onsi/gomega"
11
12 "github.com/onsi/ginkgo/v2/reporters"
13 "github.com/onsi/ginkgo/v2/types"
14 )
15
16 var _ = Describe("JSONReport", func() {
17 var report types.Report
18
19 BeforeEach(func() {
20 report = types.Report{
21 SuiteDescription: "My Suite",
22 SuitePath: "/path/to/suite",
23 PreRunStats: types.PreRunStats{SpecsThatWillRun: 15, TotalSpecs: 20},
24 SuiteConfig: types.SuiteConfig{RandomSeed: 17, ParallelTotal: 1},
25 RunTime: time.Minute,
26 SpecReports: types.SpecReports{
27 S(types.NodeTypeIt, Label("cat", "dog"), CLabels(Label("dolphin"), Label("gorilla", "cow")), CTS("A", "B"), CLS(cl0, cl1), "C", cl2, types.SpecStateTimedout, STD("some captured stdout\n"), GW("ginkgowriter\noutput\ncleanup!"), SE(types.SpecEventByStart, "a by step", cl0),
28 SE(types.SpecEventNodeStart, types.NodeTypeIt, "C", cl2, TL(0)),
29 F("failure\nmessage", cl3, types.FailureNodeIsLeafNode, FailureNodeLocation(cl2), types.NodeTypeIt, TL("ginkgowriter\n"), AF(types.SpecStatePanicked, cl4, types.FailureNodeIsLeafNode, FailureNodeLocation(cl2), types.NodeTypeIt, TL("ginkgowriter\noutput\n"), ForwardedPanic("the panic!"))),
30 SE(types.SpecEventNodeEnd, types.NodeTypeIt, "C", cl2, TL("ginkgowriter\noutput\n"), time.Microsecond*87230),
31 RE("a report entry", cl1, TL("ginkgowriter\noutput\n")),
32 RE("a hidden report entry", cl1, TL("ginkgowriter\noutput\n"), types.ReportEntryVisibilityNever),
33 AF(types.SpecStateFailed, "a subsequent failure", types.FailureNodeInContainer, FailureNodeLocation(cl3), types.NodeTypeAfterEach, 0, TL("ginkgowriter\noutput\ncleanup!")),
34 ),
35 S(types.NodeTypeIt, "A", cl0, STD("some captured stdout\n"), GW("some GinkgoWriter\noutput is interspersed\nhere and there\n"),
36 SE(types.SpecEventNodeStart, types.NodeTypeIt, "A", cl0),
37 PR("my progress report", LeafNodeText("A"), TL("some GinkgoWriter\n")),
38 SE(types.SpecEventByStart, "My Step", cl1, TL("some GinkgoWriter\n")),
39 RE("my entry", cl1, types.ReportEntryVisibilityFailureOrVerbose, TL("some GinkgoWriter\noutput is interspersed\n")),
40 RE("my hidden entry", cl1, types.ReportEntryVisibilityNever, TL("some GinkgoWriter\noutput is interspersed\n")),
41 SE(types.SpecEventByEnd, "My Step", cl1, time.Millisecond*200, TL("some GinkgoWriter\noutput is interspersed\n")),
42 SE(types.SpecEventNodeEnd, types.NodeTypeIt, "A", cl0, time.Millisecond*300, TL("some GinkgoWriter\noutput is interspersed\nhere and there\n")),
43 ),
44 S(types.NodeTypeIt, "A", cl0, types.SpecStatePending),
45 S(types.NodeTypeIt, "A", cl0, types.SpecStatePanicked, STD("some captured stdout\n"),
46 SE(types.SpecEventNodeStart, types.NodeTypeIt, "A", cl0),
47 F("failure\nmessage", cl1, types.FailureNodeIsLeafNode, FailureNodeLocation(cl0), types.NodeTypeIt, ForwardedPanic("the panic")),
48 SE(types.SpecEventNodeEnd, types.NodeTypeIt, "A", cl0, time.Millisecond*300, TL("some GinkgoWriter\noutput is interspersed\nhere and there\n")),
49 ),
50 S(types.NodeTypeBeforeSuite, "A", cl0, types.SpecStatePassed),
51 },
52 }
53 })
54
55 Describe("when configured to write the report inside a folder", func() {
56 var folderPath string
57 var filePath string
58
59 BeforeEach(func() {
60 folderPath = filepath.Join(fmt.Sprintf("test_outputs_%d", GinkgoParallelProcess()))
61 fileName := fmt.Sprintf("report-%d", GinkgoParallelProcess())
62 filePath = filepath.Join(folderPath, fileName)
63
64 Ω(reporters.GenerateJSONReport(report, filePath)).Should(Succeed())
65 DeferCleanup(os.RemoveAll, folderPath)
66 })
67
68 It("creates the folder and the report file", func() {
69 _, err := os.Stat(folderPath)
70 Ω(err).Should(Succeed(), "Parent folder should be created")
71 _, err = os.Stat(filePath)
72 Ω(err).Should(Succeed(), "Report file should be created")
73 })
74 })
75 })
76
View as plain text