cmd/gogio: improve the UX of the e2e tests

First, add a headless boolean flag that defaults to true. That way, one
can run 'go test -headless=false' to, for example, see how Chrome runs
the webassembly endtoend test.

Second, skip the Chrome test if the browser isn't installed.

While at it, run 'gofmt -s' on the package.

Signed-off-by: Daniel Martí <mvdan@mvdan.cc>
This commit is contained in:
Daniel Martí
2019-10-27 16:24:51 +00:00
committed by Elias Naur
parent 8fab2f8cb1
commit a0692d74af
2 changed files with 14 additions and 8 deletions
+10 -4
View File
@@ -5,6 +5,8 @@ package main_test
import (
"bytes"
"context"
"errors"
"flag"
"image/png"
"io/ioutil"
"net/http"
@@ -18,6 +20,8 @@ import (
_ "gioui.org/unit" // the build tool adds it to go.mod, so keep it there
)
var headless = flag.Bool("headless", true, "run end-to-end tests in headless mode")
func TestJSOnChrome(t *testing.T) {
// First, build the app.
dir, err := ioutil.TempDir("", "gio-endtoend-js")
@@ -35,8 +39,8 @@ func TestJSOnChrome(t *testing.T) {
// Second, start Chrome.
opts := append(chromedp.DefaultExecAllocatorOptions[:],
// Uncomment to get the browser's GUI.
// chromedp.Flag("headless", false),
chromedp.Flag("headless", *headless),
// We need use-gl=egl instead of the default of use-gl=desktop;
// "desktop" doesn't seem to work when we're in headless mode.
// TODO(mvdan): Does egl require a GPU? If so, consider
@@ -52,8 +56,10 @@ func TestJSOnChrome(t *testing.T) {
defer cancel()
if err := chromedp.Run(ctx); err != nil {
// TODO(mvdan): Skip the test if chrome/chromium/headless-shell
// aren't installed.
if errors.Is(err, exec.ErrNotFound) {
t.Skipf("test requires Chrome to be installed: %v", err)
return
}
t.Fatal(err)
}