runForm runs a huh form with the given interaction, returning any error. The form runs in a goroutine using bubbletea's real event loop via io.Pipe.
(t *testing.T, f *huh.Form, ix interaction)
| 112 | // runForm runs a huh form with the given interaction, returning any error. |
| 113 | // The form runs in a goroutine using bubbletea's real event loop via io.Pipe. |
| 114 | func runForm(t *testing.T, f *huh.Form, ix interaction) { |
| 115 | t.Helper() |
| 116 | r, w := io.Pipe() |
| 117 | f.WithInput(r).WithOutput(io.Discard).WithWidth(80) |
| 118 | |
| 119 | errCh := make(chan error, 1) |
| 120 | go func() { errCh <- f.Run() }() |
| 121 | |
| 122 | ix.run(t, w) |
| 123 | |
| 124 | select { |
| 125 | case err := <-errCh: |
| 126 | require.NoError(t, err) |
| 127 | case <-time.After(5 * time.Second): |
| 128 | t.Fatal("form.Run() did not complete in time") |
| 129 | } |
| 130 | } |
| 131 | |
| 132 | // --- Tests --- |
| 133 |
no test coverage detected