From a0692d74af8d3e3e973d7ec992f1a28177eb6e5e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Mart=C3=AD?= Date: Sun, 27 Oct 2019 16:24:51 +0000 Subject: [PATCH] cmd/gogio: improve the UX of the e2e tests MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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í --- cmd/gogio/js_test.go | 14 ++++++++++---- cmd/gogio/main.go | 8 ++++---- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/cmd/gogio/js_test.go b/cmd/gogio/js_test.go index 5a4749f7..36b251b0 100644 --- a/cmd/gogio/js_test.go +++ b/cmd/gogio/js_test.go @@ -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) } diff --git a/cmd/gogio/main.go b/cmd/gogio/main.go index 389dce45..e100c10f 100644 --- a/cmd/gogio/main.go +++ b/cmd/gogio/main.go @@ -220,22 +220,22 @@ type arch struct { } var allArchs = map[string]arch{ - "arm": arch{ + "arm": { iosArch: "armv7", jniArch: "armeabi-v7a", clangArch: "armv7a-linux-androideabi", }, - "arm64": arch{ + "arm64": { iosArch: "arm64", jniArch: "arm64-v8a", clangArch: "aarch64-linux-android", }, - "386": arch{ + "386": { iosArch: "i386", jniArch: "x86", clangArch: "i686-linux-android", }, - "amd64": arch{ + "amd64": { iosArch: "x86_64", jniArch: "x86_64", clangArch: "x86_64-linux-android",