Skip to content
This repository has been archived by the owner on Aug 29, 2022. It is now read-only.
/ consoledog Public archive

Terminal Emulator for cucumber/godog

License

Notifications You must be signed in to change notification settings

nhatthm/consoledog

Folders and files

NameName
Last commit message
Last commit date

Latest commit

5c8754d · Aug 29, 2022

History

40 Commits
Apr 8, 2022
Apr 19, 2021
Apr 19, 2021
Apr 17, 2021
Aug 24, 2021
Apr 17, 2021
Apr 19, 2021
Aug 29, 2022
Mar 23, 2022
Apr 19, 2021
Apr 19, 2021
Apr 17, 2021
Aug 29, 2022
Aug 29, 2022
Jun 30, 2022
Mar 23, 2022
Mar 23, 2022

Repository files navigation

⚠️ This package is deprecated, please use go.nhat.io/consolesteps instead.

Terminal Emulator for cucumber/godog

GitHub Releases Build Status codecov Go Report Card GoDevDoc Donate

consoledog provides a new Console for each cucumber/godog Scenario.

Prerequisites

  • Go >= 1.16

Install

go get github.com/nhatthm/consoledog

Usage

Initialize a consoledog.Manager with consoledog.New() then add it into the ScenarioInitializer. If you wish to add listeners to Manager.NewConsole and Manager.CloseConsole event, use consoledog.WithStarter and consoledog.WithCloser option in the constructor.

For example:

package mypackage

import (
    "math/rand"
    "testing"

    expect "github.com/Netflix/go-expect"
    "github.com/cucumber/godog"
    "github.com/nhatthm/consoledog"
)

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 := consoledog.New(t,
        consoledog.WithStarter(w.start),
        consoledog.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

Resize

In case you want to resize the terminal (default is 80x100) to avoid text wrapping, for example:

        Then console output is:
        """
        panic: could not build credentials provider option: unsupported credentials prov
        ider
        """

Use consoledog.WithTermSize(cols, rows) while initiating with consoledog.New(), for example:

package mypackage

import (
    "testing"

    "github.com/nhatthm/consoledog"
)

func TestIntegration(t *testing.T) {
    // ...
    m := consoledog.New(t, consoledog.WithTermSize(100, 100))
    // ...
}

Then your step will become:

        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:

    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/consoledog/tree/master/features

Donation

If this project help you reduce time to develop, you can give me a cup of coffee :)

Paypal donation

paypal

       or scan this