2018-05-27 12:31:47 +00:00
|
|
|
package test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"io/ioutil"
|
2018-07-11 09:00:06 +00:00
|
|
|
"net/http"
|
|
|
|
"time"
|
2018-05-27 12:31:47 +00:00
|
|
|
|
|
|
|
ginkgo "github.com/onsi/ginkgo"
|
|
|
|
|
|
|
|
"browsh/interfacer/src/browsh"
|
2018-07-18 07:52:37 +00:00
|
|
|
"github.com/spf13/viper"
|
2018-05-27 12:31:47 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
var staticFileServerPort = "4444"
|
|
|
|
var rootDir = browsh.Shell("git rev-parse --show-toplevel")
|
|
|
|
|
|
|
|
func startStaticFileServer() {
|
|
|
|
serverMux := http.NewServeMux()
|
2018-07-11 09:00:06 +00:00
|
|
|
serverMux.Handle("/", http.FileServer(http.Dir(rootDir+"/interfacer/test/sites")))
|
|
|
|
http.ListenAndServe(":"+staticFileServerPort, serverMux)
|
2018-05-27 12:31:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func startBrowsh() {
|
|
|
|
browsh.IsTesting = true
|
2018-07-18 07:52:37 +00:00
|
|
|
browsh.Initialise()
|
2018-07-17 10:43:52 +00:00
|
|
|
viper.Set("http-server-mode", true)
|
2018-05-27 12:31:47 +00:00
|
|
|
browsh.HTTPServerStart()
|
|
|
|
}
|
|
|
|
|
2018-07-18 09:38:17 +00:00
|
|
|
func getBrowshServiceBase() string {
|
|
|
|
return "http://localhost:" + viper.GetString("http-server.port")
|
|
|
|
}
|
|
|
|
|
2018-06-17 13:25:00 +00:00
|
|
|
func getPath(path string, mode string) string {
|
2018-07-18 09:38:17 +00:00
|
|
|
browshServiceBase := getBrowshServiceBase()
|
2018-05-27 12:31:47 +00:00
|
|
|
staticFileServerBase := "http://localhost:" + staticFileServerPort
|
|
|
|
fullBase := browshServiceBase + "/" + staticFileServerBase
|
2018-06-17 13:25:00 +00:00
|
|
|
client := &http.Client{}
|
2018-07-11 09:00:06 +00:00
|
|
|
request, err := http.NewRequest("GET", fullBase+path, nil)
|
2018-06-17 13:25:00 +00:00
|
|
|
if mode == "plain" {
|
|
|
|
request.Header.Add("X-Browsh-Raw-Mode", "PLAIN")
|
|
|
|
}
|
|
|
|
response, err := client.Do(request)
|
2018-05-27 12:31:47 +00:00
|
|
|
if err != nil {
|
|
|
|
panic(fmt.Sprintf("%s", err))
|
|
|
|
} else {
|
|
|
|
defer response.Body.Close()
|
|
|
|
contents, err := ioutil.ReadAll(response.Body)
|
|
|
|
if err != nil {
|
|
|
|
fmt.Printf("%s", err)
|
|
|
|
panic(fmt.Sprintf("%s", err))
|
|
|
|
}
|
|
|
|
return string(contents)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-11 09:00:06 +00:00
|
|
|
var _ = ginkgo.BeforeEach(func() {
|
2018-05-27 12:31:47 +00:00
|
|
|
browsh.IsMonochromeMode = false
|
|
|
|
browsh.Log("\n---------")
|
|
|
|
browsh.Log(ginkgo.CurrentGinkgoTestDescription().FullTestText)
|
|
|
|
browsh.Log("---------")
|
|
|
|
})
|
|
|
|
|
|
|
|
var _ = ginkgo.BeforeSuite(func() {
|
|
|
|
go startStaticFileServer()
|
|
|
|
go startBrowsh()
|
2018-07-24 13:28:14 +00:00
|
|
|
time.Sleep(15 * time.Second)
|
2018-06-11 07:49:30 +00:00
|
|
|
// Allow the browser to sort its sizing out, because sometimes the first test catches the
|
|
|
|
// browser before it's completed its resizing.
|
2018-06-17 13:25:00 +00:00
|
|
|
getPath("/smorgasbord", "plain")
|
2018-05-27 12:31:47 +00:00
|
|
|
})
|
|
|
|
|
2018-07-11 09:00:06 +00:00
|
|
|
var _ = ginkgo.AfterSuite(func() {
|
2018-05-27 12:31:47 +00:00
|
|
|
browsh.Shell(rootDir + "/webext/contrib/firefoxheadless.sh kill")
|
|
|
|
})
|