github.com/tinygo-org/tinygo@v0.31.3-0.20240404173401-90b0bf646c27/tests/wasm/event_test.go (about)

     1  package wasm
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/chromedp/chromedp"
     7  )
     8  
     9  func TestEvent(t *testing.T) {
    10  
    11  	wasmTmpDir, server := startServer(t)
    12  
    13  	err := run(t, "tinygo build -o "+wasmTmpDir+"/event.wasm -target wasm testdata/event.go")
    14  	if err != nil {
    15  		t.Fatal(err)
    16  	}
    17  
    18  	ctx := chromectx(t)
    19  
    20  	var log1, log2 string
    21  	err = chromedp.Run(ctx,
    22  		chromedp.Navigate(server.URL+"/run?file=event.wasm"),
    23  		chromedp.WaitVisible("#log"),
    24  		chromedp.InnerHTML("#log", &log1),
    25  		waitLog(`1
    26  4`),
    27  		chromedp.Click("#testbtn"),
    28  		chromedp.InnerHTML("#log", &log2),
    29  		waitLog(`1
    30  4
    31  2
    32  3
    33  true`),
    34  	)
    35  	t.Logf("log1: %s", log1)
    36  	t.Logf("log2: %s", log2)
    37  	if err != nil {
    38  		t.Fatal(err)
    39  	}
    40  
    41  }