Skip to content

Commit

Permalink
Add SpecContext to ReportAfterSuite callback body.
Browse files Browse the repository at this point in the history
  • Loading branch information
eugenenosenko authored and onsi committed Feb 27, 2024
1 parent cd418b7 commit 9c771cd
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
8 changes: 6 additions & 2 deletions internal/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ type Node struct {
SynchronizedAfterSuiteProc1BodyHasContext bool

ReportEachBody func(types.SpecReport)
ReportSuiteBody func(types.Report)
ReportSuiteBody func(SpecContext, types.Report)

MarkedFocus bool
MarkedPending bool
Expand Down Expand Up @@ -333,7 +333,11 @@ func NewNode(deprecationTracker *types.DeprecationTracker, nodeType types.NodeTy
}
} else if nodeType.Is(types.NodeTypeReportBeforeSuite | types.NodeTypeReportAfterSuite) {
if node.ReportSuiteBody == nil {
node.ReportSuiteBody = arg.(func(types.Report))
if fn, ok := arg.(func(types.Report)); ok {
node.ReportSuiteBody = func(_ SpecContext, r types.Report) { fn(r) }
} else {
node.ReportSuiteBody = arg.(func(SpecContext, types.Report))
}
} else {
appendError(types.GinkgoErrors.MultipleBodyFunctions(node.CodeLocation, nodeType))
trackedFunctionError = true
Expand Down
4 changes: 2 additions & 2 deletions internal/node_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -861,7 +861,7 @@ var _ = Describe("Node", func() {
Ω(node.ID).Should(BeNumerically(">", 0))
Ω(node.NodeType).Should(Equal(types.NodeTypeReportAfterSuite))

node.ReportSuiteBody(types.Report{})
node.ReportSuiteBody(internal.NewSpecContext(nil), types.Report{})
Ω(didRun).Should(BeTrue())

Ω(node.CodeLocation).Should(Equal(cl))
Expand All @@ -885,7 +885,7 @@ var _ = Describe("Node", func() {
Ω(node.ID).Should(BeNumerically(">", 0))
Ω(node.NodeType).Should(Equal(types.NodeTypeReportBeforeSuite))

node.ReportSuiteBody(types.Report{})
node.ReportSuiteBody(internal.NewSpecContext(nil), types.Report{})
Ω(didRun).Should(BeTrue())

Ω(node.CodeLocation).Should(Equal(cl))
Expand Down
2 changes: 1 addition & 1 deletion internal/suite.go
Original file line number Diff line number Diff line change
Expand Up @@ -762,7 +762,7 @@ func (suite *Suite) runReportSuiteNode(node Node, report types.Report) {
report = report.Add(aggregatedReport)
}

node.Body = func(SpecContext) { node.ReportSuiteBody(report) }
node.Body = func(ctx SpecContext) { node.ReportSuiteBody(ctx, report) }
suite.currentSpecReport.State, suite.currentSpecReport.Failure = suite.runNode(node, time.Time{}, "")

suite.currentSpecReport.EndTime = time.Now()
Expand Down

0 comments on commit 9c771cd

Please sign in to comment.