https://github.com/nhatthm/consolesteps
Terminal Emulator steps for cucumber/godog
https://github.com/nhatthm/consolesteps
bdd console cucumber emulator functional-testing gherkin go godog godog-extension golang integration-testing terminal
Last synced: about 1 month ago
JSON representation
Terminal Emulator steps for cucumber/godog
- Host: GitHub
- URL: https://github.com/nhatthm/consolesteps
- Owner: nhatthm
- License: mit
- Created: 2022-08-29T07:53:13.000Z (over 2 years ago)
- Default Branch: master
- Last Pushed: 2024-10-31T20:19:50.000Z (6 months ago)
- Last Synced: 2025-02-28T03:26:05.891Z (about 2 months ago)
- Topics: bdd, console, cucumber, emulator, functional-testing, gherkin, go, godog, godog-extension, golang, integration-testing, terminal
- Language: Go
- Homepage: https://go.nhat.io/consolesteps
- Size: 64.5 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Terminal Emulator for cucumber/godog
[](https://github.com/nhatthm/consolesteps/releases/latest)
[](https://github.com/nhatthm/consolesteps/actions/workflows/test.yaml)
[](https://codecov.io/gh/nhatthm/consolesteps)
[](https://goreportcard.com/report/go.nhat.io/consolesteps)
[](https://pkg.go.dev/go.nhat.io/consolesteps)
[](https://www.paypal.com/donate/?hosted_button_id=PJZSGJN57TDJY)`consolesteps` provides a new [`Console`](https://github.com/netflix/go-expect) for each `cucumber/godog` Scenario.
## Prerequisites
- `Go >= 1.17`
## Install
```bash
go get go.nhat.io/consolesteps
```## Usage
Initialize a `consolesteps.Manager` with `consolesteps.New()` then add it into the `ScenarioInitializer`. If you wish to add listeners to `Manager.NewConsole` and
`Manager.CloseConsole` event, use `consolesteps.WithStarter` and `consolesteps.WithCloser` option in the constructor.For example:
```go
package mypackageimport (
"math/rand"
"testing"expect "github.com/Netflix/go-expect"
"github.com/cucumber/godog"
"go.nhat.io/consolesteps"
)type writer struct {
console *expect.Console
}func (w *writer) registerContext(ctx *godog.ScenarioContext) {
ctx.Step(`write to console:`, func(s *godog.DocString) error {
_, err := w.console.Write([]byte(s.Content))return err
})
}func (w *writer) start(_ *godog.Scenario, console *expect.Console) {
w.console = console
}func (w *writer) close(_ *godog.Scenario) {
w.console = nil
}func TestIntegration(t *testing.T) {
t.Parallel()w := &writer{}
m := consolesteps.New(t,
consolesteps.WithStarter(w.start),
consolesteps.WithCloser(w.close),
)suite := godog.TestSuite{
Name: "Integration",
ScenarioInitializer: func(ctx *godog.ScenarioContext) {
m.RegisterContext(ctx)
},
Options: &godog.Options{
Strict: true,
Output: out,
Randomize: rand.Int63(),
},
}// Run the suite.
}
```See more: [#Examples](#Examples)
### Resize
In case you want to resize the terminal (default is `80x100`) to avoid text wrapping, for example:
```gherkin
Then console output is:
"""
panic: could not build credentials provider option: unsupported credentials prov
ider
"""
```Use `consolesteps.WithTermSize(cols, rows)` while initiating with `consolesteps.New()`, for example:
```go
package mypackageimport (
"testing""go.nhat.io/consolesteps"
)func TestIntegration(t *testing.T) {
// ...
m := consolesteps.New(t, consolesteps.WithTermSize(100, 100))
// ...
}
```Then your step will become:
```gherkin
Then console output is:
"""
panic: could not build credentials provider option: unsupported credentials provider
"""
```## Steps
### `console output is:`
Asserts the output of the console.
For example:
```gherkin
Scenario: Find all transaction in range with invalid format
When I run command "transactions -d --format invalid"Then console output is:
"""
panic: unknown output format
"""
```## Examples
Full suite: https://github.com/nhatthm/consolesteps/tree/master/features
## Donation
If this project help you reduce time to develop, you can give me a cup of coffee :)
### Paypal donation
[](https://www.paypal.com/donate/?hosted_button_id=PJZSGJN57TDJY)
or scan this
![]()