mirror of https://github.com/tinygo-org/tinygo.git
Brad Peabody
5 years ago
committed by
Ron Evans
3 changed files with 101 additions and 4 deletions
@ -0,0 +1,44 @@ |
|||
// +build go1.14
|
|||
|
|||
package wasm |
|||
|
|||
import ( |
|||
"testing" |
|||
"time" |
|||
|
|||
"github.com/chromedp/chromedp" |
|||
) |
|||
|
|||
func TestLog(t *testing.T) { |
|||
|
|||
t.Parallel() |
|||
|
|||
err := run("tinygo build -o " + wasmTmpDir + "/log.wasm -target wasm testdata/log.go") |
|||
if err != nil { |
|||
t.Fatal(err) |
|||
} |
|||
|
|||
ctx, cancel := chromectx(5 * time.Second) |
|||
defer cancel() |
|||
|
|||
var log1 string |
|||
err = chromedp.Run(ctx, |
|||
chromedp.Navigate("http://localhost:8826/run?file=log.wasm"), |
|||
chromedp.Sleep(time.Second), |
|||
chromedp.InnerHTML("#log", &log1), |
|||
waitLogRe(`^..../../.. ..:..:.. log 1 |
|||
..../../.. ..:..:.. log 2 |
|||
..../../.. ..:..:.. log 3 |
|||
println 4 |
|||
fmt.Println 5 |
|||
..../../.. ..:..:.. log 6 |
|||
in func 1 |
|||
..../../.. ..:..:.. in func 2 |
|||
$`), |
|||
) |
|||
t.Logf("log1: %s", log1) |
|||
if err != nil { |
|||
t.Fatal(err) |
|||
} |
|||
|
|||
} |
@ -0,0 +1,41 @@ |
|||
package main |
|||
|
|||
import ( |
|||
"fmt" |
|||
"log" |
|||
"syscall/js" |
|||
) |
|||
|
|||
func main() { |
|||
|
|||
// try various log and other output directly
|
|||
log.Println("log 1") |
|||
log.Print("log 2") |
|||
log.Printf("log %d\n", 3) |
|||
println("println 4") |
|||
fmt.Println("fmt.Println 5") |
|||
log.Printf("log %s", "6") |
|||
|
|||
// now set up some log output in a button click callback
|
|||
js.Global(). |
|||
Get("document"). |
|||
Call("querySelector", "#main"). |
|||
Set("innerHTML", `<button id="testbtn">Test</button>`) |
|||
|
|||
js.Global(). |
|||
Get("document"). |
|||
Call("querySelector", "#testbtn"). |
|||
Call("addEventListener", "click", |
|||
js.FuncOf(func(this js.Value, args []js.Value) interface{} { |
|||
println("in func 1") |
|||
log.Printf("in func 2") |
|||
return nil |
|||
})) |
|||
|
|||
// click the button
|
|||
js.Global(). |
|||
Get("document"). |
|||
Call("querySelector", "#testbtn"). |
|||
Call("click") |
|||
|
|||
} |
Loading…
Reference in new issue