1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-06-19 00:28:03 +02:00

add slow flag to integration tests

This commit is contained in:
Jesse Duffield
2022-08-14 20:47:09 +10:00
parent e875d6b448
commit b2ae651686
7 changed files with 27 additions and 14 deletions

View File

@ -13,7 +13,7 @@ Usage:
See https://github.com/jesseduffield/lazygit/tree/master/pkg/integration/README.md See https://github.com/jesseduffield/lazygit/tree/master/pkg/integration/README.md
CLI mode: 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 If you pass no test names, it runs all tests
Accepted environment variables: Accepted environment variables:
KEY_PRESS_DELAY (e.g. 200): the number of milliseconds to wait between keypresses KEY_PRESS_DELAY (e.g. 200): the number of milliseconds to wait between keypresses
@ -40,7 +40,14 @@ func main() {
case "help": case "help":
fmt.Println(usage) fmt.Println(usage)
case "cli": 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": case "tui":
clients.RunTUI() clients.RunTUI()
default: default:

View File

@ -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: 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 2. go run cmd/integration_test/main.go tui
3. go test pkg/integration/clients/go_test.go 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`. 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 ### Snapshots

View File

@ -23,14 +23,19 @@ import (
// If invoked directly, you can specify tests to run by passing their names as positional arguments // 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( err := components.RunTests(
getTestsToRun(testNames), getTestsToRun(testNames),
log.Printf, log.Printf,
runCmdInTerminal, runCmdInTerminal,
runAndPrintError, runAndPrintError,
getModeFromEnv(), getModeFromEnv(),
tryConvert(os.Getenv("KEY_PRESS_DELAY"), 0), keyPressDelay,
) )
if err != nil { if err != nil {
log.Print(err.Error()) log.Print(err.Error())
@ -39,7 +44,7 @@ func RunCLI(testNames []string) {
func runAndPrintError(test *components.IntegrationTest, f func() error) { func runAndPrintError(test *components.IntegrationTest, f func() error) {
if err := f(); err != nil { if err := f(); err != nil {
log.Print(err.Error()) log.Fatalf(err.Error())
} }
} }

View File

@ -19,6 +19,8 @@ import (
// This program lets you run integration tests from a TUI. See pkg/integration/README.md for more info. // 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() { func RunTUI() {
rootDir := utils.GetLazygitRootDirectory() rootDir := utils.GetLazygitRootDirectory()
testDir := filepath.Join(rootDir, "test", "integration") testDir := filepath.Join(rootDir, "test", "integration")
@ -106,7 +108,7 @@ func RunTUI() {
return nil return nil
} }
suspendAndRunTest(currentTest, components.ASK_TO_UPDATE_SNAPSHOT, 200) suspendAndRunTest(currentTest, components.ASK_TO_UPDATE_SNAPSHOT, SLOW_KEY_PRESS_DELAY)
return nil return nil
}); err != nil { }); err != nil {

View File

@ -7,7 +7,6 @@ import (
"github.com/jesseduffield/lazygit/pkg/gui/types" "github.com/jesseduffield/lazygit/pkg/gui/types"
integrationTypes "github.com/jesseduffield/lazygit/pkg/integration/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 // 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 &matcher{testFn: func(value string) (bool, string) {
return target == value, fmt.Sprintf("Expected '%T' to equal '%T'", value, target) 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) { func (self *Assert) MatchHeadCommitMessage(matcher *matcher) {
self.assertWithRetries(func() (bool, string) { 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.", self.matchString(matcher, "Unexpected commit message.",

View File

@ -77,7 +77,7 @@ func (self *Input) Cancel() {
} }
// i.e. pressing space // i.e. pressing space
func (self *Input) Select() { func (self *Input) PrimaryAction() {
self.pressKey(self.keys.Universal.Select) self.pressKey(self.keys.Universal.Select)
} }

View File

@ -17,9 +17,9 @@ var Commit = NewIntegrationTest(NewIntegrationTestArgs{
Run: func(shell *Shell, input *Input, assert *Assert, keys config.KeybindingConfig) { Run: func(shell *Shell, input *Input, assert *Assert, keys config.KeybindingConfig) {
assert.CommitCount(0) assert.CommitCount(0)
input.Select() input.PrimaryAction()
input.NextItem() input.NextItem()
input.Select() input.PrimaryAction()
input.PressKeys(keys.Files.CommitChanges) input.PressKeys(keys.Files.CommitChanges)
commitMessage := "my commit message" commitMessage := "my commit message"