Skip to content

Commit

Permalink
add slow flag to integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jesseduffield committed Aug 14, 2022
1 parent e875d6b commit b2ae651
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 14 deletions.
11 changes: 9 additions & 2 deletions cmd/integration_test/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Usage:
See https://github.com/jesseduffield/lazygit/tree/master/pkg/integration/README.md
CLI mode:
> go run cmd/integration_test/main.go cli <test1> <test2> ...
> go run cmd/integration_test/main.go cli [--slow] <test1> <test2> ...
If you pass no test names, it runs all tests
Accepted environment variables:
KEY_PRESS_DELAY (e.g. 200): the number of milliseconds to wait between keypresses
Expand All @@ -40,7 +40,14 @@ func main() {
case "help":
fmt.Println(usage)
case "cli":
clients.RunCLI(os.Args[2:])
testNames := os.Args[2:]
slow := false
// get the next arg if it's --slow
if len(os.Args) > 2 && (os.Args[2] == "--slow" || os.Args[2] == "-slow") {
testNames = os.Args[3:]
slow = true
}
clients.RunCLI(testNames, slow)
case "tui":
clients.RunTUI()
default:
Expand Down
4 changes: 2 additions & 2 deletions pkg/integration/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ If you find yourself doing something frequently in a test, consider making it a

There are three ways to invoke a test:

1. go run cmd/integration_test/main.go cli [<testname or testpath>...]
1. go run cmd/integration_test/main.go cli [--slow] [<testname or testpath>...]
2. go run cmd/integration_test/main.go tui
3. go test pkg/integration/clients/go_test.go

Expand All @@ -47,7 +47,7 @@ The third, the go-test command, intended only for use in CI, to be run along wit

The name of a test is based on its path, so the name of the test at `pkg/integration/tests/commit/new_branch.go` is commit/new_branch. So to run it with our test runner you would run `go run cmd/integration_test/main.go cli commit/new_branch`.

You can pass the KEY_PRESS_DELAY env var to the test runner in order to set a delay in milliseconds between keypresses, which helps for watching a test at a realistic speed to understand what it's doing. Or in the tui you can press 't' to run the test with a pre-set delay.
You can pass the KEY_PRESS_DELAY env var to the test runner in order to set a delay in milliseconds between keypresses, which helps for watching a test at a realistic speed to understand what it's doing. Or you can pass the '--slow' flag which sets a pre-set 'slow' key delay. In the tui you can press 't' to run the test in slow mode.

### Snapshots

Expand Down
11 changes: 8 additions & 3 deletions pkg/integration/clients/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,19 @@ import (

// If invoked directly, you can specify tests to run by passing their names as positional arguments

func RunCLI(testNames []string) {
func RunCLI(testNames []string, slow bool) {
keyPressDelay := tryConvert(os.Getenv("KEY_PRESS_DELAY"), 0)
if slow {
keyPressDelay = SLOW_KEY_PRESS_DELAY
}

err := components.RunTests(
getTestsToRun(testNames),
log.Printf,
runCmdInTerminal,
runAndPrintError,
getModeFromEnv(),
tryConvert(os.Getenv("KEY_PRESS_DELAY"), 0),
keyPressDelay,
)
if err != nil {
log.Print(err.Error())
Expand All @@ -39,7 +44,7 @@ func RunCLI(testNames []string) {

func runAndPrintError(test *components.IntegrationTest, f func() error) {
if err := f(); err != nil {
log.Print(err.Error())
log.Fatalf(err.Error())
}
}

Expand Down
4 changes: 3 additions & 1 deletion pkg/integration/clients/tui.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ import (

// This program lets you run integration tests from a TUI. See pkg/integration/README.md for more info.

var SLOW_KEY_PRESS_DELAY = 300

func RunTUI() {
rootDir := utils.GetLazygitRootDirectory()
testDir := filepath.Join(rootDir, "test", "integration")
Expand Down Expand Up @@ -106,7 +108,7 @@ func RunTUI() {
return nil
}

suspendAndRunTest(currentTest, components.ASK_TO_UPDATE_SNAPSHOT, 200)
suspendAndRunTest(currentTest, components.ASK_TO_UPDATE_SNAPSHOT, SLOW_KEY_PRESS_DELAY)

return nil
}); err != nil {
Expand Down
5 changes: 2 additions & 3 deletions pkg/integration/components/assert.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (

"github.com/jesseduffield/lazygit/pkg/gui/types"
integrationTypes "github.com/jesseduffield/lazygit/pkg/integration/types"
"golang.org/x/exp/constraints"
)

// through this struct we assert on the state of the lazygit gui
Expand Down Expand Up @@ -51,7 +50,7 @@ func Contains(target string) *matcher {
}}
}

func Equals[T constraints.Ordered](target string) *matcher {
func Equals(target string) *matcher {
return &matcher{testFn: func(value string) (bool, string) {
return target == value, fmt.Sprintf("Expected '%T' to equal '%T'", value, target)
}}
Expand Down Expand Up @@ -81,7 +80,7 @@ func (self *Assert) CommitCount(expectedCount int) {

func (self *Assert) MatchHeadCommitMessage(matcher *matcher) {
self.assertWithRetries(func() (bool, string) {
return len(self.gui.Model().Commits) == 0, "Expected at least one commit to be present"
return len(self.gui.Model().Commits) > 0, "Expected at least one commit to be present"
})

self.matchString(matcher, "Unexpected commit message.",
Expand Down
2 changes: 1 addition & 1 deletion pkg/integration/components/input.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ func (self *Input) Cancel() {
}

// i.e. pressing space
func (self *Input) Select() {
func (self *Input) PrimaryAction() {
self.pressKey(self.keys.Universal.Select)
}

Expand Down
4 changes: 2 additions & 2 deletions pkg/integration/tests/commit/commit.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ var Commit = NewIntegrationTest(NewIntegrationTestArgs{
Run: func(shell *Shell, input *Input, assert *Assert, keys config.KeybindingConfig) {
assert.CommitCount(0)

input.Select()
input.PrimaryAction()
input.NextItem()
input.Select()
input.PrimaryAction()
input.PressKeys(keys.Files.CommitChanges)

commitMessage := "my commit message"
Expand Down

0 comments on commit b2ae651

Please sign in to comment.