tinygo/tests/wasm/event_test.go
Elliott Sales de Andrade f3bdebe2a6 Use httptest to serve wasm test files.
This picks a port automatically, so avoids any conflicts that might
arise from running the tests in parallel.
2021-01-25 19:12:31 +01:00

50 строки
836 Б
Go

// +build go1.14
package wasm
import (
"testing"
"time"
"github.com/chromedp/chromedp"
)
func TestEvent(t *testing.T) {
t.Parallel()
wasmTmpDir, server, cleanup := startServer(t)
defer cleanup()
err := run("tinygo build -o " + wasmTmpDir + "/event.wasm -target wasm testdata/event.go")
if err != nil {
t.Fatal(err)
}
ctx, cancel := chromectx(5 * time.Second)
defer cancel()
var log1, log2 string
err = chromedp.Run(ctx,
chromedp.Navigate(server.URL+"/run?file=event.wasm"),
chromedp.WaitVisible("#log"),
chromedp.Sleep(time.Second),
chromedp.InnerHTML("#log", &log1),
waitLog(`1
4`),
chromedp.Click("#testbtn"),
chromedp.Sleep(time.Second),
chromedp.InnerHTML("#log", &log2),
waitLog(`1
4
2
3
true`),
)
t.Logf("log1: %s", log1)
t.Logf("log2: %s", log2)
if err != nil {
t.Fatal(err)
}
}