Skip to content

Commit 37ec9e7

Browse files
committed
Improve test logging
The TestRun test created a test binary and executed it. So failures from that test bubbled up as a real failure. We improve that to just compile as a normal binary and execute that instead.
1 parent 9f69172 commit 37ec9e7

File tree

3 files changed

+36
-106
lines changed

3 files changed

+36
-106
lines changed

go.mod

+11-1
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,20 @@
11
module github.com/agnivade/wasmbrowsertest
22

3-
go 1.16
3+
go 1.19
44

55
require (
66
github.com/chromedp/cdproto v0.0.0-20221108233440-fad8339618ab
77
github.com/chromedp/chromedp v0.8.6
88
github.com/go-interpreter/wagon v0.6.0
99
github.com/google/pprof v0.0.0-20221103000818-d260c55eee4c
1010
)
11+
12+
require (
13+
github.com/chromedp/sysutil v1.0.0 // indirect
14+
github.com/gobwas/httphead v0.1.0 // indirect
15+
github.com/gobwas/pool v0.2.1 // indirect
16+
github.com/gobwas/ws v1.1.0 // indirect
17+
github.com/josharian/intern v1.0.0 // indirect
18+
github.com/mailru/easyjson v0.7.7 // indirect
19+
golang.org/x/sys v0.0.0-20220928140112-f11e5e49a4ec // indirect
20+
)

go.sum

-8
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,9 @@
1-
github.com/chromedp/cdproto v0.0.0-20220924210414-0e3390be1777/go.mod h1:5Y4sD/eXpwrChIuxhSr/G20n9CdbCmoerOHnuAf0Zr0=
21
github.com/chromedp/cdproto v0.0.0-20221108233440-fad8339618ab h1:qzilDZlsMUMBpXySlekH7rgrrH/feo11uQoQxTY7Uk0=
32
github.com/chromedp/cdproto v0.0.0-20221108233440-fad8339618ab/go.mod h1:GKljq0VrfU4D5yc+2qA6OVr8pmO/MBbPEWqWQ/oqGEs=
43
github.com/chromedp/chromedp v0.8.6 h1:KobeeqR2dpfKSG1prS3Y6+FbffMmGC6xmAobRXA9QEQ=
54
github.com/chromedp/chromedp v0.8.6/go.mod h1:nBYHoD6YSNzrr82cIeuOzhw1Jo/s2o0QQ+ifTeoCZ+c=
65
github.com/chromedp/sysutil v1.0.0 h1:+ZxhTpfpZlmchB58ih/LBHX52ky7w2VhQVKQMucy3Ic=
76
github.com/chromedp/sysutil v1.0.0/go.mod h1:kgWmDdq8fTzXYcKIBqIYvRRTnYb9aNS9moAV0xufSww=
8-
github.com/chzyer/logex v1.2.0/go.mod h1:9+9sk7u7pGNWYMkh0hdiL++6OeibzJccyQU4p4MedaY=
9-
github.com/chzyer/readline v1.5.0/go.mod h1:x22KAscuvRqlLoK9CsoYsmxoXZMMFVyOl86cAH8qUic=
10-
github.com/chzyer/test v0.0.0-20210722231415-061457976a23/go.mod h1:Q3SI9o4m/ZMnBNeIyt5eFwwo7qiLfzFZmjNmxjkiQlU=
117
github.com/edsrzf/mmap-go v1.0.0 h1:CEBF7HpRnUCSJgGUb5h1Gm7e3VkmVDrR8lvWVLtrOFw=
128
github.com/edsrzf/mmap-go v1.0.0/go.mod h1:YO35OhQPt3KJa3ryjFM5Bs14WD66h8eGKpfaBNrHW5M=
139
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=
2016
github.com/gobwas/ws v1.1.0/go.mod h1:nzvNcVha5eUziGrbxFCo6qFIojQHjJV5cLYIbezhfL0=
2117
github.com/google/pprof v0.0.0-20221103000818-d260c55eee4c h1:lvddKcYTQ545ADhBujtIJmqQrZBDsGo7XIMbAQe/sNY=
2218
github.com/google/pprof v0.0.0-20221103000818-d260c55eee4c/go.mod h1:dDKJzRmX4S37WGHujM7tX//fmj1uioxKzKxz3lo4HJo=
23-
github.com/ianlancetaylor/demangle v0.0.0-20220319035150-800ac71e25c2/go.mod h1:aYm2/VgdVmcIU8iMfdMvDMsRAQjcfZSKFby6HOFvi/w=
2419
github.com/josharian/intern v1.0.0 h1:vlS4z54oSdjm0bgjRigI+G1HpF+tI+9rE5LLzOg8HmY=
2520
github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFFd8Hwg//Y=
2621
github.com/ledongthuc/pdf v0.0.0-20220302134840-0c2507a12d80 h1:6Yzfa6GP0rIo/kULo2bwGEkFvCePZ3qHDDTC3/J9Swo=
27-
github.com/ledongthuc/pdf v0.0.0-20220302134840-0c2507a12d80/go.mod h1:imJHygn/1yfhB7XSJJKlFZKl/J+dCPAknuiaGOshXAs=
2822
github.com/mailru/easyjson v0.7.7 h1:UGYAvKxe3sBsEDzO8ZeWOSlIQfWFlxbzLZe7hwFURr0=
2923
github.com/mailru/easyjson v0.7.7/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc=
3024
github.com/orisano/pixelmatch v0.0.0-20220722002657-fb0b55479cde h1:x0TT0RDC7UhAVbbWWBzr41ElhJx5tXPWkIHA2HWPRuw=
31-
github.com/orisano/pixelmatch v0.0.0-20220722002657-fb0b55479cde/go.mod h1:nZgzbfBr3hhjoZnS66nKrHmduYNpc34ny7RK4z5/HM0=
3225
github.com/twitchyliquid64/golang-asm v0.0.0-20190126203739-365674df15fc h1:RTUQlKzoZZVG3umWNzOYeFecQLIh+dbxXvJp1zPQJTI=
3326
github.com/twitchyliquid64/golang-asm v0.0.0-20190126203739-365674df15fc/go.mod h1:NoCfSFWosfqMqmmD7hApkirIK9ozpHjxRnRxs1l413A=
3427
golang.org/x/sys v0.0.0-20190306220234-b354f8bf4d9e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
3528
golang.org/x/sys v0.0.0-20201207223542-d4d67f95c62d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
36-
golang.org/x/sys v0.0.0-20220310020820-b874c991c1a5/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
3729
golang.org/x/sys v0.0.0-20220928140112-f11e5e49a4ec h1:BkDtF2Ih9xZ7le9ndzTA7KJow28VbQW3odyk/8drmuI=
3830
golang.org/x/sys v0.0.0-20220928140112-f11e5e49a4ec/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=

main_test.go

+25-97
Original file line numberDiff line numberDiff line change
@@ -4,116 +4,59 @@ import (
44
"bytes"
55
"context"
66
"flag"
7-
"io"
87
"os"
98
"os/exec"
109
"path/filepath"
1110
"testing"
1211
)
1312

1413
func TestRun(t *testing.T) {
15-
t.Parallel()
16-
1714
for _, tc := range []struct {
1815
description string
1916
files map[string]string
2017
args []string
2118
expectErr string
2219
}{
23-
{
24-
description: "pass",
25-
files: map[string]string{
26-
"go.mod": `
27-
module foo
28-
`,
29-
"foo_test.go": `
30-
package foo
31-
32-
import "testing"
33-
34-
func TestFoo(t *testing.T) {
35-
if false {
36-
t.Errorf("foo failed")
37-
}
38-
}
39-
`,
40-
},
41-
},
42-
{
43-
description: "fails",
44-
files: map[string]string{
45-
"go.mod": `
46-
module foo
47-
`,
48-
"foo_test.go": `
49-
package foo
50-
51-
import "testing"
52-
53-
func TestFooFails(t *testing.T) {
54-
t.Errorf("foo failed")
55-
}
56-
`,
57-
},
58-
expectErr: "exit with status 1",
59-
},
6020
{
6121
description: "panic fails",
6222
files: map[string]string{
6323
"go.mod": `
6424
module foo
65-
`,
66-
"foo_test.go": `
67-
package foo
6825
69-
import "testing"
26+
go 1.19
27+
`,
28+
"foo.go": `
29+
package main
7030
71-
func TestFooPanic(t *testing.T) {
31+
func main() {
7232
panic("failed")
7333
}
7434
`,
7535
},
7636
expectErr: "exit with status 2",
7737
},
78-
{
79-
description: "panic in goroutine fails",
80-
files: map[string]string{
81-
"go.mod": `
82-
module foo
83-
`,
84-
"foo_test.go": `
85-
package foo
86-
87-
import "testing"
88-
89-
func TestFooGoroutinePanic(t *testing.T) {
90-
go panic("foo failed")
91-
}
92-
`,
93-
},
94-
expectErr: "exit with status 1",
95-
},
9638
{
9739
description: "panic in next run of event loop fails",
9840
files: map[string]string{
9941
"go.mod": `
100-
module foo
101-
`,
102-
"foo_test.go": `
103-
package foo
104-
105-
import (
106-
"syscall/js"
107-
"testing"
108-
)
109-
110-
func TestFooNextEventLoopPanic(t *testing.T) {
111-
js.Global().Call("setTimeout", js.FuncOf(func(js.Value, []js.Value) interface{} {
112-
panic("bad")
113-
return nil
114-
}), 0)
115-
}
116-
`,
42+
module foo
43+
44+
go 1.19
45+
`,
46+
"foo.go": `
47+
package main
48+
49+
import (
50+
"syscall/js"
51+
)
52+
53+
func main() {
54+
js.Global().Call("setTimeout", js.FuncOf(func(js.Value, []js.Value) any {
55+
panic("bad")
56+
return nil
57+
}), 0)
58+
}
59+
`,
11760
},
11861
expectErr: "context canceled",
11962
},
@@ -132,28 +75,13 @@ func TestFooNextEventLoopPanic(t *testing.T) {
13275
}
13376
}
13477

135-
type testWriter struct {
136-
testingT *testing.T
137-
}
138-
139-
func testLogger(t *testing.T) io.Writer {
140-
return &testWriter{t}
141-
}
142-
143-
func (w *testWriter) Write(b []byte) (int, error) {
144-
w.testingT.Helper()
145-
w.testingT.Log(string(b))
146-
return len(b), nil
147-
}
148-
14978
func testRun(t *testing.T, wasmFile string, flags ...string) ([]byte, error) {
15079
var logs bytes.Buffer
151-
output := io.MultiWriter(testLogger(t), &logs)
15280
flagSet := flag.NewFlagSet("wasmbrowsertest", flag.ContinueOnError)
15381
ctx, cancel := context.WithCancel(context.Background())
15482
t.Cleanup(cancel)
15583

156-
err := run(ctx, append([]string{"go_js_wasm_exec", wasmFile, "-test.v"}, flags...), output, flagSet)
84+
err := run(ctx, append([]string{"go_js_wasm_exec", wasmFile}, flags...), &logs, flagSet)
15785
return logs.Bytes(), err
15886
}
15987

@@ -176,7 +104,7 @@ func writeFile(t *testing.T, baseDir, path, contents string) {
176104
func buildTestWasm(t *testing.T, path string) string {
177105
t.Helper()
178106
outputFile := filepath.Join(t.TempDir(), "out.wasm")
179-
cmd := exec.Command("go", "test", "-c", "-o", outputFile, ".")
107+
cmd := exec.Command("go", "build", "-o", outputFile, ".")
180108
cmd.Dir = path
181109
cmd.Env = append(os.Environ(),
182110
"GOOS=js",

0 commit comments

Comments
 (0)