Skip to content

Commit

Permalink
#341 continue refactor of formatter event names
Browse files Browse the repository at this point in the history
  • Loading branch information
dumpsterfireproject committed Jul 4, 2022
1 parent 5a1eace commit ce7586e
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 13 deletions.
23 changes: 20 additions & 3 deletions formatters/fmt.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,14 @@ func AvailableFormatters() map[string]string {
return fmts
}

type MetaData struct{}

type Source struct {
Data string
MediaType string
Uri string
}

// Formatter is an interface for feature runner
// output summary presentation.
//
Expand All @@ -62,12 +70,21 @@ func AvailableFormatters() map[string]string {
// godog.Format function call
type Formatter interface {

// parsing phase messages
MetaData(*MetaData)
Source(*Source)
// Pickle()
// TestRun()
// hooks - execution?

TestRunStarted()
Feature(*messages.GherkinDocument, string, []byte)
TestCaseStarted(*messages.Pickle)
// step matching phase messages
Defined(*messages.Pickle, *messages.PickleStep, *StepDefinition)

// execution phase messages
TestRunStarted()
Feature(*messages.GherkinDocument, string, []byte) // this one is not part of Messages, legacy
TestCase(*messages.Pickle)
TestCaseStarted(*messages.TestCaseStarted)
Failed(*messages.Pickle, *messages.PickleStep, *StepDefinition, error)
Passed(*messages.Pickle, *messages.PickleStep, *StepDefinition)
Skipped(*messages.Pickle, *messages.PickleStep, *StepDefinition)
Expand Down
13 changes: 11 additions & 2 deletions internal/formatters/fmt_base.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,23 @@ func (f *Base) SetStorage(st *storage.Storage) {
f.Storage = st
}

// Metadata is triggered prior to parsing
func (f *Base) MetaData(*formatters.MetaData) {}

// Source is triggered prior to parsing
func (f *Base) Source(*formatters.Source) {}

// TestRunStarted is triggered on test start.
func (f *Base) TestRunStarted() {}

// Feature receives gherkin document.
func (f *Base) Feature(*messages.GherkinDocument, string, []byte) {}

// TestCaseStarted receives scenario.
func (f *Base) TestCaseStarted(*messages.Pickle) {}
// TestCase receives scenario.
func (f *Base) TestCase(*messages.Pickle) {}

// TestCaseStarted tracks attempt number and timestamp for a test case.
func (f *Base) TestCaseStarted(*messages.TestCaseStarted) {}

// Defined receives step definition.
func (f *Base) Defined(*messages.Pickle, *messages.PickleStep, *formatters.StepDefinition) {
Expand Down
4 changes: 2 additions & 2 deletions internal/formatters/fmt_events.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ func (f *Events) event(ev interface{}) {
}

// Pickle receives scenario.
func (f *Events) TestCaseStarted(pickle *messages.Pickle) {
f.Base.TestCaseStarted(pickle)
func (f *Events) TestCase(pickle *messages.Pickle) {
f.Base.TestCase(pickle)

f.Lock.Lock()
defer f.Lock.Unlock()
Expand Down
14 changes: 12 additions & 2 deletions internal/formatters/fmt_multi.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@ func (r repeater) SetStorage(s *storage.Storage) {
}
}

// Metadata is triggered prior to parsing
func (r repeater) MetaData(*formatters.MetaData) {}

// Source is triggered prior to parsing
func (r repeater) Source(*formatters.Source) {}

// TestRunStarted triggers TestRunStarted for all added formatters.
func (r repeater) TestRunStarted() {
for _, f := range r {
Expand All @@ -50,12 +56,16 @@ func (r repeater) Feature(document *messages.GherkinDocument, s string, bytes []
}

// TestCaseStarted triggers TestCaseStarted for all added formatters.
func (r repeater) TestCaseStarted(pickle *messages.Pickle) {
func (r repeater) TestCase(pickle *messages.Pickle) {
for _, f := range r {
f.TestCaseStarted(pickle)
f.TestCase(pickle)
}
}

func (r repeater) TestCaseStarted(*messages.TestCaseStarted) {

}

// Defined triggers Defined for all added formatters.
func (r repeater) Defined(pickle *messages.Pickle, step *messages.PickleStep, definition *formatters.StepDefinition) {
for _, f := range r {
Expand Down
4 changes: 2 additions & 2 deletions internal/formatters/fmt_pretty.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ func (f *Pretty) Feature(gd *messages.GherkinDocument, p string, c []byte) {
}

// Pickle takes a gherkin node for formatting.
func (f *Pretty) TestCaseStarted(pickle *messages.Pickle) {
f.Base.TestCaseStarted(pickle)
func (f *Pretty) TestCase(pickle *messages.Pickle) {
f.Base.TestCase(pickle)

f.Lock.Lock()
defer f.Lock.Unlock()
Expand Down
4 changes: 2 additions & 2 deletions suite.go
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,7 @@ func (s *suite) runPickle(pickle *messages.Pickle) (err error) {
pr := models.PickleResult{PickleID: pickle.Id, StartedAt: utils.TimeNowFunc()}
s.storage.MustInsertPickleResult(pr)

s.fmt.TestCaseStarted(pickle)
s.fmt.TestCase(pickle)
return ErrUndefined
}

Expand All @@ -439,7 +439,7 @@ func (s *suite) runPickle(pickle *messages.Pickle) (err error) {
pr := models.PickleResult{PickleID: pickle.Id, StartedAt: utils.TimeNowFunc()}
s.storage.MustInsertPickleResult(pr)

s.fmt.TestCaseStarted(pickle)
s.fmt.TestCase(pickle)

// scenario
if s.testingT != nil {
Expand Down

0 comments on commit ce7586e

Please sign in to comment.