Skip to content

Commit

Permalink
Better test logging
Browse files Browse the repository at this point in the history
  • Loading branch information
tombh committed Apr 7, 2018
1 parent 1acb178 commit 34497c8
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 11 deletions.
2 changes: 1 addition & 1 deletion interfacer/contrib/run_tests.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/bash
set -e

go test test/*.go
go test test/*.go -v
2 changes: 1 addition & 1 deletion interfacer/src/main.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package main

import "browsh"
import "browsh/interfacer/src/browsh"

func main() {
browsh.TtyStart()
Expand Down
36 changes: 27 additions & 9 deletions interfacer/test/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (

"github.com/gdamore/tcell"
"github.com/gdamore/tcell/terminfo"
gingko "github.com/onsi/ginkgo"
ginkgo "github.com/onsi/ginkgo"
gomega "github.com/onsi/gomega"

"browsh/interfacer/src/browsh"
Expand Down Expand Up @@ -48,8 +48,8 @@ func GetFrame() string {
line = 0
}
}
log += styleDefault
browsh.Log(log)
log = "\n" + log + styleDefault
ginkgo.GinkgoWriter.Write([]byte(log))
return frame
}

Expand All @@ -73,15 +73,27 @@ func waitForNextFrame() {
time.Sleep(500 * time.Millisecond)
}

// WaitForText waits for a particular string at particular position in the frame
func WaitForText(text string, x, y int) {
var found string
start := time.Now()
for time.Since(start) < perTestTimeout {
found = GetText(x, y, runeCount(text))
if found == text { return }
time.Sleep(100 * time.Millisecond)
}
panic("Waiting for '" + text + "' to appear but it didn't")
}

// GotoURL sends the browsh browser to the specified URL
func GotoURL(url string) {
SpecialKey(tcell.KeyCtrlL)
Keyboard(url)
SpecialKey(tcell.KeyEnter)
// TODO: Waiting and looking for the URL aren't optimal.
// Better to somehow create a unique identifier to poll for. Polling for the URL isn't
// good enough because it could be the same URL as the previous test.
time.Sleep(250 * time.Millisecond)
WaitForText("Loading", 0, 24)
WaitForText("▄▄▄▄▄▄▄", 0, 24)
// TODO: Looking for the URL isn't optimal because it could be the same URL
// as the previous test.
gomega.Expect(url).To(BeInFrameAt(9, 1))
}

Expand Down Expand Up @@ -165,13 +177,19 @@ func runeCount(text string) int {
return utf8.RuneCountInString(text)
}

var _ = gingko.BeforeSuite(func() {
var _ = ginkgo.BeforeEach(func() {
browsh.Log("\n---------")
browsh.Log(ginkgo.CurrentGinkgoTestDescription().FullTestText)
browsh.Log("---------")
})

var _ = ginkgo.BeforeSuite(func() {
initTerm()
go startHTTPServer()
go startBrowsh()
waitForBrowsh()
})

var _ = gingko.AfterSuite(func() {
var _ = ginkgo.AfterSuite(func() {
browsh.Shell(rootDir + "/webext/contrib/firefoxheadless.sh kill")
})

0 comments on commit 34497c8

Please sign in to comment.