X Tutup
Skip to content

Commit bcfe176

Browse files
committed
Fix flaky editor test
There was a race condition wherein the test didn't wait enough time for the prompt to get rendered before testing the terminal output.
1 parent ffebd23 commit bcfe176

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

pkg/surveyext/editor_test.go

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,15 @@ func Test_GhEditor_Prompt(t *testing.T) {
5959
errc <- err
6060
}()
6161

62-
time.Sleep(5 * time.Millisecond)
62+
for {
63+
time.Sleep(time.Millisecond)
64+
if strings.Contains(out.String(), "Body") {
65+
break
66+
}
67+
}
68+
6369
assert.Equal(t, "\x1b[0G\x1b[2K\x1b[0;1;92m? \x1b[0m\x1b[0;1;99mBody \x1b[0m\x1b[0;36m[(e) to launch false, enter to skip] \x1b[0m\x1b[?25l", out.String())
70+
out.Reset()
6471
fmt.Fprint(pty, "\n") // send Enter key
6572

6673
err = <-errc
@@ -126,7 +133,12 @@ func (f *teeWriter) Write(p []byte) (n int, err error) {
126133
func (f *teeWriter) String() string {
127134
f.mu.Lock()
128135
s := f.buf.String()
129-
f.buf.Reset()
130136
f.mu.Unlock()
131137
return s
132138
}
139+
140+
func (f *teeWriter) Reset() {
141+
f.mu.Lock()
142+
f.buf.Reset()
143+
f.mu.Unlock()
144+
}

0 commit comments

Comments
 (0)
X Tutup