diff --git a/go.mod b/go.mod index 079c6a2..a10de19 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/agnivade/wasmbrowsertest -go 1.16 +go 1.19 require ( github.com/chromedp/cdproto v0.0.0-20221108233440-fad8339618ab @@ -8,3 +8,13 @@ require ( github.com/go-interpreter/wagon v0.6.0 github.com/google/pprof v0.0.0-20221103000818-d260c55eee4c ) + +require ( + github.com/chromedp/sysutil v1.0.0 // indirect + github.com/gobwas/httphead v0.1.0 // indirect + github.com/gobwas/pool v0.2.1 // indirect + github.com/gobwas/ws v1.1.0 // indirect + github.com/josharian/intern v1.0.0 // indirect + github.com/mailru/easyjson v0.7.7 // indirect + golang.org/x/sys v0.0.0-20220928140112-f11e5e49a4ec // indirect +) diff --git a/go.sum b/go.sum index fee93b6..8aec06e 100644 --- a/go.sum +++ b/go.sum @@ -1,13 +1,9 @@ -github.com/chromedp/cdproto v0.0.0-20220924210414-0e3390be1777/go.mod h1:5Y4sD/eXpwrChIuxhSr/G20n9CdbCmoerOHnuAf0Zr0= github.com/chromedp/cdproto v0.0.0-20221108233440-fad8339618ab h1:qzilDZlsMUMBpXySlekH7rgrrH/feo11uQoQxTY7Uk0= github.com/chromedp/cdproto v0.0.0-20221108233440-fad8339618ab/go.mod h1:GKljq0VrfU4D5yc+2qA6OVr8pmO/MBbPEWqWQ/oqGEs= github.com/chromedp/chromedp v0.8.6 h1:KobeeqR2dpfKSG1prS3Y6+FbffMmGC6xmAobRXA9QEQ= github.com/chromedp/chromedp v0.8.6/go.mod h1:nBYHoD6YSNzrr82cIeuOzhw1Jo/s2o0QQ+ifTeoCZ+c= github.com/chromedp/sysutil v1.0.0 h1:+ZxhTpfpZlmchB58ih/LBHX52ky7w2VhQVKQMucy3Ic= github.com/chromedp/sysutil v1.0.0/go.mod h1:kgWmDdq8fTzXYcKIBqIYvRRTnYb9aNS9moAV0xufSww= -github.com/chzyer/logex v1.2.0/go.mod h1:9+9sk7u7pGNWYMkh0hdiL++6OeibzJccyQU4p4MedaY= -github.com/chzyer/readline v1.5.0/go.mod h1:x22KAscuvRqlLoK9CsoYsmxoXZMMFVyOl86cAH8qUic= -github.com/chzyer/test v0.0.0-20210722231415-061457976a23/go.mod h1:Q3SI9o4m/ZMnBNeIyt5eFwwo7qiLfzFZmjNmxjkiQlU= github.com/edsrzf/mmap-go v1.0.0 h1:CEBF7HpRnUCSJgGUb5h1Gm7e3VkmVDrR8lvWVLtrOFw= github.com/edsrzf/mmap-go v1.0.0/go.mod h1:YO35OhQPt3KJa3ryjFM5Bs14WD66h8eGKpfaBNrHW5M= github.com/go-interpreter/wagon v0.6.0 h1:BBxDxjiJiHgw9EdkYXAWs8NHhwnazZ5P2EWBW5hFNWw= @@ -20,19 +16,15 @@ github.com/gobwas/ws v1.1.0 h1:7RFti/xnNkMJnrK7D1yQ/iCIB5OrrY/54/H930kIbHA= github.com/gobwas/ws v1.1.0/go.mod h1:nzvNcVha5eUziGrbxFCo6qFIojQHjJV5cLYIbezhfL0= github.com/google/pprof v0.0.0-20221103000818-d260c55eee4c h1:lvddKcYTQ545ADhBujtIJmqQrZBDsGo7XIMbAQe/sNY= github.com/google/pprof v0.0.0-20221103000818-d260c55eee4c/go.mod h1:dDKJzRmX4S37WGHujM7tX//fmj1uioxKzKxz3lo4HJo= -github.com/ianlancetaylor/demangle v0.0.0-20220319035150-800ac71e25c2/go.mod h1:aYm2/VgdVmcIU8iMfdMvDMsRAQjcfZSKFby6HOFvi/w= github.com/josharian/intern v1.0.0 h1:vlS4z54oSdjm0bgjRigI+G1HpF+tI+9rE5LLzOg8HmY= github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFFd8Hwg//Y= github.com/ledongthuc/pdf v0.0.0-20220302134840-0c2507a12d80 h1:6Yzfa6GP0rIo/kULo2bwGEkFvCePZ3qHDDTC3/J9Swo= -github.com/ledongthuc/pdf v0.0.0-20220302134840-0c2507a12d80/go.mod h1:imJHygn/1yfhB7XSJJKlFZKl/J+dCPAknuiaGOshXAs= github.com/mailru/easyjson v0.7.7 h1:UGYAvKxe3sBsEDzO8ZeWOSlIQfWFlxbzLZe7hwFURr0= github.com/mailru/easyjson v0.7.7/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc= github.com/orisano/pixelmatch v0.0.0-20220722002657-fb0b55479cde h1:x0TT0RDC7UhAVbbWWBzr41ElhJx5tXPWkIHA2HWPRuw= -github.com/orisano/pixelmatch v0.0.0-20220722002657-fb0b55479cde/go.mod h1:nZgzbfBr3hhjoZnS66nKrHmduYNpc34ny7RK4z5/HM0= github.com/twitchyliquid64/golang-asm v0.0.0-20190126203739-365674df15fc h1:RTUQlKzoZZVG3umWNzOYeFecQLIh+dbxXvJp1zPQJTI= github.com/twitchyliquid64/golang-asm v0.0.0-20190126203739-365674df15fc/go.mod h1:NoCfSFWosfqMqmmD7hApkirIK9ozpHjxRnRxs1l413A= golang.org/x/sys v0.0.0-20190306220234-b354f8bf4d9e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20201207223542-d4d67f95c62d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20220310020820-b874c991c1a5/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220928140112-f11e5e49a4ec h1:BkDtF2Ih9xZ7le9ndzTA7KJow28VbQW3odyk/8drmuI= golang.org/x/sys v0.0.0-20220928140112-f11e5e49a4ec/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= diff --git a/main_test.go b/main_test.go index 9cf4acf..f4df5ba 100644 --- a/main_test.go +++ b/main_test.go @@ -4,7 +4,6 @@ import ( "bytes" "context" "flag" - "io" "os" "os/exec" "path/filepath" @@ -12,108 +11,52 @@ import ( ) func TestRun(t *testing.T) { - t.Parallel() - for _, tc := range []struct { description string files map[string]string args []string expectErr string }{ - { - description: "pass", - files: map[string]string{ - "go.mod": ` -module foo -`, - "foo_test.go": ` -package foo - -import "testing" - -func TestFoo(t *testing.T) { - if false { - t.Errorf("foo failed") - } -} -`, - }, - }, - { - description: "fails", - files: map[string]string{ - "go.mod": ` -module foo -`, - "foo_test.go": ` -package foo - -import "testing" - -func TestFooFails(t *testing.T) { - t.Errorf("foo failed") -} -`, - }, - expectErr: "exit with status 1", - }, { description: "panic fails", files: map[string]string{ "go.mod": ` module foo -`, - "foo_test.go": ` -package foo -import "testing" +go 1.19 +`, + "foo.go": ` +package main -func TestFooPanic(t *testing.T) { +func main() { panic("failed") } `, }, expectErr: "exit with status 2", }, - { - description: "panic in goroutine fails", - files: map[string]string{ - "go.mod": ` -module foo -`, - "foo_test.go": ` -package foo - -import "testing" - -func TestFooGoroutinePanic(t *testing.T) { - go panic("foo failed") -} -`, - }, - expectErr: "exit with status 1", - }, { description: "panic in next run of event loop fails", files: map[string]string{ "go.mod": ` -module foo -`, - "foo_test.go": ` -package foo - -import ( - "syscall/js" - "testing" -) - -func TestFooNextEventLoopPanic(t *testing.T) { - js.Global().Call("setTimeout", js.FuncOf(func(js.Value, []js.Value) interface{} { - panic("bad") - return nil - }), 0) -} -`, + module foo + + go 1.19 + `, + "foo.go": ` + package main + + import ( + "syscall/js" + ) + + func main() { + js.Global().Call("setTimeout", js.FuncOf(func(js.Value, []js.Value) any { + panic("bad") + return nil + }), 0) + } + `, }, expectErr: "context canceled", }, @@ -132,28 +75,13 @@ func TestFooNextEventLoopPanic(t *testing.T) { } } -type testWriter struct { - testingT *testing.T -} - -func testLogger(t *testing.T) io.Writer { - return &testWriter{t} -} - -func (w *testWriter) Write(b []byte) (int, error) { - w.testingT.Helper() - w.testingT.Log(string(b)) - return len(b), nil -} - func testRun(t *testing.T, wasmFile string, flags ...string) ([]byte, error) { var logs bytes.Buffer - output := io.MultiWriter(testLogger(t), &logs) flagSet := flag.NewFlagSet("wasmbrowsertest", flag.ContinueOnError) ctx, cancel := context.WithCancel(context.Background()) t.Cleanup(cancel) - err := run(ctx, append([]string{"go_js_wasm_exec", wasmFile, "-test.v"}, flags...), output, flagSet) + err := run(ctx, append([]string{"go_js_wasm_exec", wasmFile}, flags...), &logs, flagSet) return logs.Bytes(), err } @@ -176,7 +104,7 @@ func writeFile(t *testing.T, baseDir, path, contents string) { func buildTestWasm(t *testing.T, path string) string { t.Helper() outputFile := filepath.Join(t.TempDir(), "out.wasm") - cmd := exec.Command("go", "test", "-c", "-o", outputFile, ".") + cmd := exec.Command("go", "build", "-o", outputFile, ".") cmd.Dir = path cmd.Env = append(os.Environ(), "GOOS=js",