diff --git a/cmd/integration_test/main.go b/cmd/integration_test/main.go index 492e5e19f..83321fc34 100644 --- a/cmd/integration_test/main.go +++ b/cmd/integration_test/main.go @@ -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 ... + > go run cmd/integration_test/main.go cli [--slow] ... 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 @@ -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: diff --git a/pkg/integration/README.md b/pkg/integration/README.md index b2aa2ddf9..658339a43 100644 --- a/pkg/integration/README.md +++ b/pkg/integration/README.md @@ -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 [...] +1. go run cmd/integration_test/main.go cli [--slow] [...] 2. go run cmd/integration_test/main.go tui 3. go test pkg/integration/clients/go_test.go @@ -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 diff --git a/pkg/integration/clients/cli.go b/pkg/integration/clients/cli.go index bb8a8d0b9..eedb82984 100644 --- a/pkg/integration/clients/cli.go +++ b/pkg/integration/clients/cli.go @@ -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()) @@ -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()) } } diff --git a/pkg/integration/clients/tui.go b/pkg/integration/clients/tui.go index 716d1abe8..9348cd1f3 100644 --- a/pkg/integration/clients/tui.go +++ b/pkg/integration/clients/tui.go @@ -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") @@ -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 { diff --git a/pkg/integration/components/assert.go b/pkg/integration/components/assert.go index ea67273a9..a5ad0aaf7 100644 --- a/pkg/integration/components/assert.go +++ b/pkg/integration/components/assert.go @@ -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 @@ -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) }} @@ -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.", diff --git a/pkg/integration/components/input.go b/pkg/integration/components/input.go index 63361e5c9..63e902613 100644 --- a/pkg/integration/components/input.go +++ b/pkg/integration/components/input.go @@ -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) } diff --git a/pkg/integration/tests/commit/commit.go b/pkg/integration/tests/commit/commit.go index 0c3fc484c..dbef083ae 100644 --- a/pkg/integration/tests/commit/commit.go +++ b/pkg/integration/tests/commit/commit.go @@ -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"