Repository navigation
Expand file tree
/
Copy pathgotest_destinations.go
More file actions
93 lines (79 loc) · 2.3 KB
/
Copy pathgotest_destinations.go
File metadata and controls
93 lines (79 loc) · 2.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
package devflow
import (
"bytes"
"context"
"os"
"strings"
)
const (
edgeMainDir = "web/edge" // web/edge/main.go: the Worker main
browserMainDir = "web/browser" // web/browser/main.go: the browser main
mainFile = "main.go"
browserPassLabel = "browser"
workerPassLabel = "worker"
)
func buildTagsArg(runAll bool, extraTag string) string {
var tags []string
if runAll {
tags = append(tags, "integration")
}
if extraTag != "" {
tags = append(tags, extraTag)
}
if len(tags) > 0 {
return "-tags=" + strings.Join(tags, ",")
}
return ""
}
func (g *Go) runBrowserTests(dir string, runAll bool, timeoutSec int, extraArgs []string) (output string, failed bool) {
// A submodule with no browser-buildable tests (a stories/ module, all !wasm because it drives Chrome) has nothing
// to run here: skipped, never "no packages to test" counted as a failure.
pkgs, listed := g.listWasmTestPackages(dir, runAll, browserTag)
if listed && len(pkgs) == 0 && dir != g.rootDir {
return "", false
}
if len(pkgs) == 0 {
pkgs = []string{"./..."}
}
args := []string{"test", "-exec", g.wasmExecArg(), "-count=1"}
if tags := buildTagsArg(runAll, browserTag); tags != "" {
args = append(args, tags)
}
args = append(args, extraArgs...)
args = append(args, pkgs...)
ctx, cancel := context.WithTimeout(context.Background(), g.wasmTimeout(timeoutSec))
defer cancel()
cmd := GoTestCmdFn(ctx, dir, "go", args...)
cmd.Env = append(os.Environ(), "GOOS=js", "GOARCH=wasm")
var out bytes.Buffer
filter := NewConsoleFilter(g.consoleOutput)
pipe := ¶mWriter{
write: func(p []byte) (n int, err error) {
s := string(p)
out.Write(p)
filter.Add(s)
return len(p), nil
},
}
cmd.Stdout = pipe
cmd.Stderr = pipe
err := cmd.Run()
failed = err != nil || ctx.Err() == context.DeadlineExceeded
return out.String(), failed
}
func (g *Go) vetWebMain(pkgDir, tag string) (output string, failed bool) {
var args []string
if tag == "" {
args = []string{"vet", "./" + pkgDir}
} else {
args = []string{"vet", "-tags=" + tag, "./" + pkgDir}
}
cmd := GoTestCmdFn(context.Background(), g.rootDir, "go", args...)
cmd.Env = append(os.Environ(), "GOOS=js", "GOARCH=wasm")
var out bytes.Buffer
cmd.Stdout = &out
cmd.Stderr = &out
err := cmd.Run()
failed = err != nil
return out.String(), failed
}