typenative 0.4.1 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +171 -0
- package/README.md +62 -22
- package/ROUND2-HANDOFF.md +200 -0
- package/bin/cli.js +1 -0
- package/bin/index.js +13 -2
- package/bin/main.js +1 -0
- package/bin/node/assert.js +2 -2
- package/bin/node/async_hooks.js +1 -1
- package/bin/node/buffer.js +16 -5
- package/bin/node/child_process.js +7 -7
- package/bin/node/cluster.js +3 -3
- package/bin/node/crypto_keys.js +21 -21
- package/bin/node/dgram.js +1 -1
- package/bin/node/diagnostics_channel.js +3 -3
- package/bin/node/dns.js +2 -2
- package/bin/node/events.js +3 -3
- package/bin/node/fetch.js +2 -2
- package/bin/node/fs.js +3 -3
- package/bin/node/fs_watch.js +5 -5
- package/bin/node/http.js +3 -3
- package/bin/node/http2.js +3 -3
- package/bin/node/net.js +8 -8
- package/bin/node/path.js +17 -3
- package/bin/node/process.js +34 -11
- package/bin/node/readline.js +1 -1
- package/bin/node/registry.js +4 -1
- package/bin/node/sqlite.js +6 -6
- package/bin/node/stream.js +81 -15
- package/bin/node/stream_web.js +10 -10
- package/bin/node/system_extra.js +3 -3
- package/bin/node/test.js +674 -366
- package/bin/node/test_coverage.js +187 -0
- package/bin/node/test_report.js +1392 -0
- package/bin/node/test_run.js +575 -0
- package/bin/node/timers.js +4 -4
- package/bin/node/tls.js +5 -5
- package/bin/node/util.js +31 -7
- package/bin/node/util_extra.js +7 -7
- package/bin/node/webview.js +654 -0
- package/bin/node/worker_threads.js +1 -1
- package/bin/node/zlib.js +3 -3
- package/bin/parse-node.js +4 -0
- package/bin/transpiler.js +10390 -1178
- package/bin/version.js +1 -1
- package/conformance.md +468 -340
- package/examples/README.md +47 -10
- package/examples/desktop-notes/README.md +108 -0
- package/examples/desktop-notes/bench.mjs +125 -0
- package/examples/desktop-notes/main.ts +131 -0
- package/examples/desktop-notes/package-lock.json +726 -0
- package/examples/desktop-notes/package.json +9 -0
- package/examples/desktop-notes/ui.ts +176 -0
- package/examples/dupe-finder/README.md +76 -0
- package/examples/dupe-finder/bench.mjs +120 -0
- package/examples/dupe-finder/main.ts +87 -0
- package/examples/mandelbrot-png/README.md +65 -0
- package/examples/mandelbrot-png/bench.mjs +95 -0
- package/examples/mandelbrot-png/main.ts +98 -0
- package/examples/mandelbrot-png/preview.png +0 -0
- package/examples/marked-cli/README.md +159 -0
- package/examples/marked-cli/bench.mjs +178 -0
- package/examples/marked-cli/main.ts +292 -0
- package/examples/marked-cli/parity.mjs +185 -0
- package/examples/marked-cli/vendor/marked/LICENSE +44 -0
- package/examples/marked-cli/vendor/marked/VENDOR.md +26 -0
- package/examples/todo-cli/README.md +69 -0
- package/examples/todo-cli/bench.mjs +89 -0
- package/examples/todo-cli/main.ts +92 -0
- package/examples/yaml-cli/README.md +136 -0
- package/examples/yaml-cli/bench.mjs +265 -0
- package/examples/yaml-cli/main.ts +29 -0
- package/examples/yaml-cli/parity.mjs +156 -0
- package/examples/yaml-cli/vendor/yaml/LICENSE +13 -0
- package/examples/yaml-cli/vendor/yaml/VENDOR.md +25 -0
- package/govendor/github.com/jchv/go-webview2/LICENSE +22 -0
- package/govendor/github.com/jchv/go-webview2/README.md +21 -0
- package/govendor/github.com/jchv/go-webview2/common.go +84 -0
- package/govendor/github.com/jchv/go-webview2/go.mod +3 -0
- package/govendor/github.com/jchv/go-webview2/internal/w32/w32.go +194 -0
- package/govendor/github.com/jchv/go-webview2/internal/w32/w32_386.go +14 -0
- package/govendor/github.com/jchv/go-webview2/internal/w32/w32_64bit.go +15 -0
- package/govendor/github.com/jchv/go-webview2/pkg/edge/COREWEBVIEW2_COLOR.go +8 -0
- package/govendor/github.com/jchv/go-webview2/pkg/edge/COREWEBVIEW2_HOST_RESOURCE_ACCESS_KIND.go +9 -0
- package/govendor/github.com/jchv/go-webview2/pkg/edge/COREWEBVIEW2_KEY_EVENT_KIND.go +10 -0
- package/govendor/github.com/jchv/go-webview2/pkg/edge/COREWEBVIEW2_MOVE_FOCUS_REASON.go +9 -0
- package/govendor/github.com/jchv/go-webview2/pkg/edge/COREWEBVIEW2_PHYSICAL_KEY_STATUS.go +10 -0
- package/govendor/github.com/jchv/go-webview2/pkg/edge/COREWEBVIEW2_WEB_RESOURCE_CONTEXT.go +23 -0
- package/govendor/github.com/jchv/go-webview2/pkg/edge/ICoreWebView2AcceleratorKeyPressedEventArgs.go +78 -0
- package/govendor/github.com/jchv/go-webview2/pkg/edge/ICoreWebView2AcceleratorKeyPressedEventHandler.go +52 -0
- package/govendor/github.com/jchv/go-webview2/pkg/edge/ICoreWebView2Controller.go +132 -0
- package/govendor/github.com/jchv/go-webview2/pkg/edge/ICoreWebView2Controller2.go +74 -0
- package/govendor/github.com/jchv/go-webview2/pkg/edge/ICoreWebView2CreateCoreWebView2ControllerCompletedHandler.go +48 -0
- package/govendor/github.com/jchv/go-webview2/pkg/edge/ICoreWebView2NavigationCompletedEventArgs.go +17 -0
- package/govendor/github.com/jchv/go-webview2/pkg/edge/ICoreWebView2NavigationCompletedEventHandler.go +48 -0
- package/govendor/github.com/jchv/go-webview2/pkg/edge/ICoreWebView2Settings.go +270 -0
- package/govendor/github.com/jchv/go-webview2/pkg/edge/ICoreWebView2WebResourceRequest.go +43 -0
- package/govendor/github.com/jchv/go-webview2/pkg/edge/ICoreWebView2WebResourceRequestedEventArgs.go +51 -0
- package/govendor/github.com/jchv/go-webview2/pkg/edge/ICoreWebView2WebResourceRequestedEventHandler.go +48 -0
- package/govendor/github.com/jchv/go-webview2/pkg/edge/ICoreWebView2WebResourceResponse.go +21 -0
- package/govendor/github.com/jchv/go-webview2/pkg/edge/ICoreWebView2_2.go +21 -0
- package/govendor/github.com/jchv/go-webview2/pkg/edge/ICoreWebView2_3.go +60 -0
- package/govendor/github.com/jchv/go-webview2/pkg/edge/ICoreWebViewSettings.go +396 -0
- package/govendor/github.com/jchv/go-webview2/pkg/edge/chromium.go +361 -0
- package/govendor/github.com/jchv/go-webview2/pkg/edge/chromium_386.go +24 -0
- package/govendor/github.com/jchv/go-webview2/pkg/edge/chromium_amd64.go +22 -0
- package/govendor/github.com/jchv/go-webview2/pkg/edge/chromium_arm64.go +26 -0
- package/govendor/github.com/jchv/go-webview2/pkg/edge/comproc.go +13 -0
- package/govendor/github.com/jchv/go-webview2/pkg/edge/comproc_go17.go +51 -0
- package/govendor/github.com/jchv/go-webview2/pkg/edge/comproc_go18.go +16 -0
- package/govendor/github.com/jchv/go-webview2/pkg/edge/corewebview2.go +411 -0
- package/govendor/github.com/jchv/go-webview2/pkg/edge/guid.go +223 -0
- package/govendor/github.com/jchv/go-webview2/webview.go +482 -0
- package/govendor/github.com/jchv/go-webview2/webviewloader/README.md +3 -0
- package/govendor/github.com/jchv/go-webview2/webviewloader/module.go +153 -0
- package/govendor/github.com/jchv/go-webview2/webviewloader/module_386.go +6 -0
- package/govendor/github.com/jchv/go-webview2/webviewloader/module_amd64.go +6 -0
- package/govendor/github.com/jchv/go-webview2/webviewloader/module_arm64.go +6 -0
- package/govendor/github.com/jchv/go-webview2/webviewloader/sdk/arm64/WebView2Loader.dll +0 -0
- package/govendor/github.com/jchv/go-webview2/webviewloader/sdk/x64/WebView2Loader.dll +0 -0
- package/govendor/github.com/jchv/go-webview2/webviewloader/sdk/x86/WebView2Loader.dll +0 -0
- package/govendor/github.com/jchv/go-winloader/LICENSE.md +7 -0
- package/govendor/github.com/jchv/go-winloader/README.md +124 -0
- package/govendor/github.com/jchv/go-winloader/common.go +11 -0
- package/govendor/github.com/jchv/go-winloader/go.mod +3 -0
- package/govendor/github.com/jchv/go-winloader/internal/loader/loader.go +25 -0
- package/govendor/github.com/jchv/go-winloader/internal/loader/machine.go +53 -0
- package/govendor/github.com/jchv/go-winloader/internal/memloader/cache.go +42 -0
- package/govendor/github.com/jchv/go-winloader/internal/memloader/loader.go +253 -0
- package/govendor/github.com/jchv/go-winloader/internal/pe/export.go +76 -0
- package/govendor/github.com/jchv/go-winloader/internal/pe/format.go +522 -0
- package/govendor/github.com/jchv/go-winloader/internal/pe/import.go +106 -0
- package/govendor/github.com/jchv/go-winloader/internal/pe/module.go +91 -0
- package/govendor/github.com/jchv/go-winloader/internal/pe/reloc.go +177 -0
- package/govendor/github.com/jchv/go-winloader/internal/pe/util.go +40 -0
- package/govendor/github.com/jchv/go-winloader/internal/vmem/common.go +55 -0
- package/govendor/github.com/jchv/go-winloader/internal/vmem/memory_other.go +71 -0
- package/govendor/github.com/jchv/go-winloader/internal/vmem/memory_windows.go +179 -0
- package/govendor/github.com/jchv/go-winloader/internal/winloader/hacks_other.go +17 -0
- package/govendor/github.com/jchv/go-winloader/internal/winloader/hacks_windows.go +73 -0
- package/govendor/github.com/jchv/go-winloader/internal/winloader/loader_windows.go +64 -0
- package/govendor/github.com/jchv/go-winloader/internal/winloader/machine_windows.go +32 -0
- package/govendor/github.com/jchv/go-winloader/internal/winloader/nativearch_386.go +9 -0
- package/govendor/github.com/jchv/go-winloader/internal/winloader/nativearch_amd64.go +9 -0
- package/govendor/github.com/jchv/go-winloader/internal/winloader/nativearch_arm64.go +9 -0
- package/govendor/github.com/jchv/go-winloader/loader_other.go +24 -0
- package/govendor/github.com/jchv/go-winloader/loader_windows.go +33 -0
- package/govendor/manifest.txt +3 -1
- package/package.json +1 -1
- package/tsparser/main.go +4 -0
- package/types/typenative-npm.d.ts +190 -2
- package/types/typenative.d.ts +98 -31
|
@@ -0,0 +1,1392 @@
|
|
|
1
|
+
// node:test reporting: the runner's events (Node's { type, data } objects)
|
|
2
|
+
// and the reporters that turn them into text, ported from Node 24's tap /
|
|
3
|
+
// spec / dot / junit / lcov reporters. The runner feeds its events to the
|
|
4
|
+
// reporters named by --test-reporter (each writing to its
|
|
5
|
+
// --test-reporter-destination); node:test/reporters exports the same
|
|
6
|
+
// reporters for run() streams and hand-made event sources.
|
|
7
|
+
import { defineClass, defineHelper, defineModule } from './registry.js';
|
|
8
|
+
const reportHelper = `// node:test events, as reporters and run() streams see them
|
|
9
|
+
type TnTestEvent struct {
|
|
10
|
+
type_ string
|
|
11
|
+
data *TnTestEventData
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
func (e *TnTestEvent) Get_type_() string { return e.type_ }
|
|
15
|
+
|
|
16
|
+
// One struct for every event's data (test:pass, test:plan, test:summary …)
|
|
17
|
+
type TnTestEventData struct {
|
|
18
|
+
name string
|
|
19
|
+
nesting float64
|
|
20
|
+
testNumber float64
|
|
21
|
+
details *TnTestEventDetails
|
|
22
|
+
skip interface{}
|
|
23
|
+
todo interface{}
|
|
24
|
+
file string
|
|
25
|
+
line float64
|
|
26
|
+
column float64
|
|
27
|
+
count float64
|
|
28
|
+
message string
|
|
29
|
+
level string
|
|
30
|
+
counts *TnTestCounts
|
|
31
|
+
duration_ms float64
|
|
32
|
+
success bool
|
|
33
|
+
summary *TnCoverageSummary
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
type TnTestEventDetails struct {
|
|
37
|
+
duration_ms float64
|
|
38
|
+
type_ string
|
|
39
|
+
error_ interface{}
|
|
40
|
+
passed bool
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
func (d *TnTestEventDetails) Get_type_() string { return d.type_ }
|
|
44
|
+
func (d *TnTestEventDetails) Get_error() interface{} { return d.error_ }
|
|
45
|
+
|
|
46
|
+
type TnTestCounts struct {
|
|
47
|
+
tests float64
|
|
48
|
+
failed float64
|
|
49
|
+
passed float64
|
|
50
|
+
cancelled float64
|
|
51
|
+
skipped float64
|
|
52
|
+
todo float64
|
|
53
|
+
topLevel float64
|
|
54
|
+
suites float64
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// test:coverage's summary (lines, branches and functions per file)
|
|
58
|
+
type TnCoverageSummary struct {
|
|
59
|
+
workingDirectory string
|
|
60
|
+
files []*TnCoverageFile
|
|
61
|
+
totals *TnCoverageTotals
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
type TnCoverageFile struct {
|
|
65
|
+
path string
|
|
66
|
+
totalLineCount float64
|
|
67
|
+
totalBranchCount float64
|
|
68
|
+
totalFunctionCount float64
|
|
69
|
+
coveredLineCount float64
|
|
70
|
+
coveredBranchCount float64
|
|
71
|
+
coveredFunctionCount float64
|
|
72
|
+
coveredLinePercent float64
|
|
73
|
+
coveredBranchPercent float64
|
|
74
|
+
coveredFunctionPercent float64
|
|
75
|
+
functions []*TnCoverageFunction
|
|
76
|
+
branches []*TnCoverageCount
|
|
77
|
+
lines []*TnCoverageCount
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
type TnCoverageTotals struct {
|
|
81
|
+
totalLineCount float64
|
|
82
|
+
totalBranchCount float64
|
|
83
|
+
totalFunctionCount float64
|
|
84
|
+
coveredLineCount float64
|
|
85
|
+
coveredBranchCount float64
|
|
86
|
+
coveredFunctionCount float64
|
|
87
|
+
coveredLinePercent float64
|
|
88
|
+
coveredBranchPercent float64
|
|
89
|
+
coveredFunctionPercent float64
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
type TnCoverageFunction struct {
|
|
93
|
+
name string
|
|
94
|
+
line float64
|
|
95
|
+
count float64
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
type TnCoverageCount struct {
|
|
99
|
+
line float64
|
|
100
|
+
count float64
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
func tnTestStr(v interface{}) string {
|
|
104
|
+
switch s := v.(type) {
|
|
105
|
+
case nil:
|
|
106
|
+
return ""
|
|
107
|
+
case string:
|
|
108
|
+
return s
|
|
109
|
+
}
|
|
110
|
+
return TnJSString(v)
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
func tnTestNum(v interface{}) float64 {
|
|
114
|
+
switch n := v.(type) {
|
|
115
|
+
case float64:
|
|
116
|
+
return n
|
|
117
|
+
case int:
|
|
118
|
+
return float64(n)
|
|
119
|
+
}
|
|
120
|
+
return 0
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
// Elements of an array-like value ([]T, *[]T)
|
|
124
|
+
func tnTestList(v interface{}) []interface{} {
|
|
125
|
+
if list, ok := v.([]interface{}); ok {
|
|
126
|
+
return list
|
|
127
|
+
}
|
|
128
|
+
rv := reflect.ValueOf(v)
|
|
129
|
+
if rv.Kind() == reflect.Pointer && !rv.IsNil() {
|
|
130
|
+
rv = rv.Elem()
|
|
131
|
+
}
|
|
132
|
+
if rv.Kind() != reflect.Slice && rv.Kind() != reflect.Array {
|
|
133
|
+
return nil
|
|
134
|
+
}
|
|
135
|
+
out := make([]interface{}, rv.Len())
|
|
136
|
+
for i := range out {
|
|
137
|
+
out[i] = rv.Index(i).Interface()
|
|
138
|
+
}
|
|
139
|
+
return out
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
// An event from any source: the runner's own, a decoded run() frame or a
|
|
143
|
+
// { type, data } object
|
|
144
|
+
func tnTestEventOf(v interface{}) *TnTestEvent {
|
|
145
|
+
if e, ok := v.(*TnTestEvent); ok {
|
|
146
|
+
return e
|
|
147
|
+
}
|
|
148
|
+
e := &TnTestEvent{type_: tnTestStr(TnGet(v, "type")), data: &TnTestEventData{}}
|
|
149
|
+
raw := TnGet(v, "data")
|
|
150
|
+
if d, ok := raw.(*TnTestEventData); ok {
|
|
151
|
+
e.data = d
|
|
152
|
+
return e
|
|
153
|
+
}
|
|
154
|
+
if raw == nil {
|
|
155
|
+
return e
|
|
156
|
+
}
|
|
157
|
+
d := e.data
|
|
158
|
+
d.name = tnTestStr(TnGet(raw, "name"))
|
|
159
|
+
d.nesting = tnTestNum(TnGet(raw, "nesting"))
|
|
160
|
+
d.testNumber = tnTestNum(TnGet(raw, "testNumber"))
|
|
161
|
+
d.skip = TnGet(raw, "skip")
|
|
162
|
+
d.todo = TnGet(raw, "todo")
|
|
163
|
+
d.file = tnTestStr(TnGet(raw, "file"))
|
|
164
|
+
d.line = tnTestNum(TnGet(raw, "line"))
|
|
165
|
+
d.column = tnTestNum(TnGet(raw, "column"))
|
|
166
|
+
d.count = tnTestNum(TnGet(raw, "count"))
|
|
167
|
+
d.message = tnTestStr(TnGet(raw, "message"))
|
|
168
|
+
d.level = tnTestStr(TnGet(raw, "level"))
|
|
169
|
+
d.duration_ms = tnTestNum(TnGet(raw, "duration_ms"))
|
|
170
|
+
d.success, _ = TnGetValue(raw, "success").(bool)
|
|
171
|
+
if det := TnGet(raw, "details"); det != nil {
|
|
172
|
+
if typed, ok := det.(*TnTestEventDetails); ok {
|
|
173
|
+
d.details = typed
|
|
174
|
+
} else {
|
|
175
|
+
d.details = &TnTestEventDetails{duration_ms: tnTestNum(TnGet(det, "duration_ms")), type_: tnTestStr(TnGet(det, "type")), error_: TnGet(det, "error")}
|
|
176
|
+
d.details.passed, _ = TnGetValue(det, "passed").(bool)
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
if c := TnGet(raw, "counts"); c != nil {
|
|
180
|
+
if typed, ok := c.(*TnTestCounts); ok {
|
|
181
|
+
d.counts = typed
|
|
182
|
+
} else {
|
|
183
|
+
d.counts = &TnTestCounts{tests: tnTestNum(TnGet(c, "tests")), failed: tnTestNum(TnGet(c, "failed")), passed: tnTestNum(TnGet(c, "passed")), cancelled: tnTestNum(TnGet(c, "cancelled")), skipped: tnTestNum(TnGet(c, "skipped")), todo: tnTestNum(TnGet(c, "todo")), topLevel: tnTestNum(TnGet(c, "topLevel")), suites: tnTestNum(TnGet(c, "suites"))}
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
if s := TnGet(raw, "summary"); s != nil {
|
|
187
|
+
d.summary = tnCoverageSummaryOf(s)
|
|
188
|
+
}
|
|
189
|
+
return e
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
func tnCoverageSummaryOf(v interface{}) *TnCoverageSummary {
|
|
193
|
+
if s, ok := v.(*TnCoverageSummary); ok {
|
|
194
|
+
return s
|
|
195
|
+
}
|
|
196
|
+
s := &TnCoverageSummary{workingDirectory: tnTestStr(TnGet(v, "workingDirectory")), totals: &TnCoverageTotals{}}
|
|
197
|
+
counts := func(src interface{}) []*TnCoverageCount {
|
|
198
|
+
out := []*TnCoverageCount{}
|
|
199
|
+
for _, item := range tnTestList(src) {
|
|
200
|
+
out = append(out, &TnCoverageCount{line: tnTestNum(TnGet(item, "line")), count: tnTestNum(TnGet(item, "count"))})
|
|
201
|
+
}
|
|
202
|
+
return out
|
|
203
|
+
}
|
|
204
|
+
for _, raw := range tnTestList(TnGet(v, "files")) {
|
|
205
|
+
f := &TnCoverageFile{path: tnTestStr(TnGet(raw, "path"))}
|
|
206
|
+
f.totalLineCount = tnTestNum(TnGet(raw, "totalLineCount"))
|
|
207
|
+
f.totalBranchCount = tnTestNum(TnGet(raw, "totalBranchCount"))
|
|
208
|
+
f.totalFunctionCount = tnTestNum(TnGet(raw, "totalFunctionCount"))
|
|
209
|
+
f.coveredLineCount = tnTestNum(TnGet(raw, "coveredLineCount"))
|
|
210
|
+
f.coveredBranchCount = tnTestNum(TnGet(raw, "coveredBranchCount"))
|
|
211
|
+
f.coveredFunctionCount = tnTestNum(TnGet(raw, "coveredFunctionCount"))
|
|
212
|
+
f.coveredLinePercent = tnTestNum(TnGet(raw, "coveredLinePercent"))
|
|
213
|
+
f.coveredBranchPercent = tnTestNum(TnGet(raw, "coveredBranchPercent"))
|
|
214
|
+
f.coveredFunctionPercent = tnTestNum(TnGet(raw, "coveredFunctionPercent"))
|
|
215
|
+
for _, fn := range tnTestList(TnGet(raw, "functions")) {
|
|
216
|
+
f.functions = append(f.functions, &TnCoverageFunction{name: tnTestStr(TnGet(fn, "name")), line: tnTestNum(TnGet(fn, "line")), count: tnTestNum(TnGet(fn, "count"))})
|
|
217
|
+
}
|
|
218
|
+
f.branches = counts(TnGet(raw, "branches"))
|
|
219
|
+
f.lines = counts(TnGet(raw, "lines"))
|
|
220
|
+
s.files = append(s.files, f)
|
|
221
|
+
}
|
|
222
|
+
if t := TnGet(v, "totals"); t != nil {
|
|
223
|
+
s.totals = &TnCoverageTotals{
|
|
224
|
+
totalLineCount: tnTestNum(TnGet(t, "totalLineCount")), totalBranchCount: tnTestNum(TnGet(t, "totalBranchCount")), totalFunctionCount: tnTestNum(TnGet(t, "totalFunctionCount")),
|
|
225
|
+
coveredLineCount: tnTestNum(TnGet(t, "coveredLineCount")), coveredBranchCount: tnTestNum(TnGet(t, "coveredBranchCount")), coveredFunctionCount: tnTestNum(TnGet(t, "coveredFunctionCount")),
|
|
226
|
+
coveredLinePercent: tnTestNum(TnGet(t, "coveredLinePercent")), coveredBranchPercent: tnTestNum(TnGet(t, "coveredBranchPercent")), coveredFunctionPercent: tnTestNum(TnGet(t, "coveredFunctionPercent")),
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
return s
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
// --- reporters ---
|
|
233
|
+
|
|
234
|
+
type tnTestReporter interface {
|
|
235
|
+
begin() string
|
|
236
|
+
report(e *TnTestEvent) string
|
|
237
|
+
end() string
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
// Node's reporter colors: on when stderr is a terminal (FORCE_COLOR / NO_COLOR win)
|
|
241
|
+
func tnTestColorsOn() bool {
|
|
242
|
+
if force, ok := os.LookupEnv("FORCE_COLOR"); ok {
|
|
243
|
+
return force != "0" && force != "false"
|
|
244
|
+
}
|
|
245
|
+
if os.Getenv("NO_COLOR") != "" || os.Getenv("NODE_DISABLE_COLORS") != "" {
|
|
246
|
+
return false
|
|
247
|
+
}
|
|
248
|
+
return TnIsTTY(os.Stderr)
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
type tnTestPalette struct{ on bool }
|
|
252
|
+
|
|
253
|
+
func (p tnTestPalette) c(code string) string {
|
|
254
|
+
if !p.on {
|
|
255
|
+
return ""
|
|
256
|
+
}
|
|
257
|
+
return "\\x1b[" + code + "m"
|
|
258
|
+
}
|
|
259
|
+
func (p tnTestPalette) green() string { return p.c("32") }
|
|
260
|
+
func (p tnTestPalette) red() string { return p.c("31") }
|
|
261
|
+
func (p tnTestPalette) gray() string { return p.c("90") }
|
|
262
|
+
func (p tnTestPalette) white() string { return p.c("39") }
|
|
263
|
+
func (p tnTestPalette) blue() string { return p.c("34") }
|
|
264
|
+
func (p tnTestPalette) yellow() string { return p.c("33") }
|
|
265
|
+
func (p tnTestPalette) reset() string { return p.c("0") }
|
|
266
|
+
|
|
267
|
+
func tnNewTestReporter(name string, colors bool) tnTestReporter {
|
|
268
|
+
p := tnTestPalette{on: colors}
|
|
269
|
+
switch name {
|
|
270
|
+
case "tap":
|
|
271
|
+
return &tnTapReporter{}
|
|
272
|
+
case "spec":
|
|
273
|
+
cwd, _ := os.Getwd()
|
|
274
|
+
return &tnSpecReporter{p: p, cwd: cwd}
|
|
275
|
+
case "dot":
|
|
276
|
+
return &tnDotReporter{p: p, columns: tnTestColumns()}
|
|
277
|
+
case "junit":
|
|
278
|
+
return &tnJunitReporter{}
|
|
279
|
+
case "lcov":
|
|
280
|
+
return &tnLcovReporter{}
|
|
281
|
+
}
|
|
282
|
+
return nil
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
// process.stdout.columns ?? 20 (at least 20)
|
|
286
|
+
func tnTestColumns() int {
|
|
287
|
+
if TnIsTTY(os.Stdout) {
|
|
288
|
+
if cols := int(TnTtyColumns(os.Stdout)); cols > 20 {
|
|
289
|
+
return cols
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
return 20
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
func tnTestLines(s string) []string {
|
|
296
|
+
return strings.Split(strings.ReplaceAll(s, "\\r\\n", "\\n"), "\\n")
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
func tnTestErrorOf(v interface{}) (*TnError, bool) {
|
|
300
|
+
switch e := v.(type) {
|
|
301
|
+
case *TnError:
|
|
302
|
+
return e, true
|
|
303
|
+
case interface{ TnBaseError() *TnError }:
|
|
304
|
+
return e.TnBaseError(), true
|
|
305
|
+
}
|
|
306
|
+
return nil, false
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
// An error's name: a custom error class's own, else the TnError's
|
|
310
|
+
func tnTestErrorName(v interface{}) string {
|
|
311
|
+
if named, ok := v.(interface{ Get_name() string }); ok {
|
|
312
|
+
return named.Get_name()
|
|
313
|
+
}
|
|
314
|
+
if e, ok := tnTestErrorOf(v); ok {
|
|
315
|
+
return e.Get_name()
|
|
316
|
+
}
|
|
317
|
+
return ""
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
func tnTestErrorCode(v interface{}) string {
|
|
321
|
+
if e, ok := tnTestErrorOf(v); ok {
|
|
322
|
+
if e.code != "" {
|
|
323
|
+
return e.code
|
|
324
|
+
}
|
|
325
|
+
code, _ := e.prop("code").(string)
|
|
326
|
+
return code
|
|
327
|
+
}
|
|
328
|
+
return ""
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
// AssertionError messages end with a line break, as node:assert's do
|
|
332
|
+
func tnTestErrorMessage(v interface{}) string {
|
|
333
|
+
e, ok := tnTestErrorOf(v)
|
|
334
|
+
if !ok {
|
|
335
|
+
return ""
|
|
336
|
+
}
|
|
337
|
+
msg := e.message
|
|
338
|
+
if tnTestErrorName(v) == "AssertionError" && strings.Contains(msg, "\\n") && !strings.HasSuffix(msg, "\\n") {
|
|
339
|
+
msg += "\\n"
|
|
340
|
+
}
|
|
341
|
+
return msg
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
// The error Node's runner reports: ERR_TEST_FAILURE wrapping what was thrown
|
|
345
|
+
func tnTestFailure(cause interface{}, failureType string) *TnError {
|
|
346
|
+
msg := ""
|
|
347
|
+
if s, ok := cause.(string); ok {
|
|
348
|
+
msg = s
|
|
349
|
+
} else if _, ok := tnTestErrorOf(cause); ok {
|
|
350
|
+
msg = tnTestErrorMessage(cause)
|
|
351
|
+
} else {
|
|
352
|
+
msg = TnInspect(cause)
|
|
353
|
+
}
|
|
354
|
+
e := TnNodeError("Error", "ERR_TEST_FAILURE", msg)
|
|
355
|
+
e.props["failureType"] = failureType
|
|
356
|
+
e.props["cause"] = cause
|
|
357
|
+
return e
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
func tnTestFailureType(v interface{}) string {
|
|
361
|
+
if e, ok := tnTestErrorOf(v); ok {
|
|
362
|
+
s, _ := e.prop("failureType").(string)
|
|
363
|
+
return s
|
|
364
|
+
}
|
|
365
|
+
return ""
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
// util.inspect of an error as the reporters show it ("Name [code]: message")
|
|
369
|
+
func tnTestInspectError(v interface{}) string {
|
|
370
|
+
if _, ok := tnTestErrorOf(v); !ok {
|
|
371
|
+
return TnInspect(v)
|
|
372
|
+
}
|
|
373
|
+
head := tnTestErrorName(v)
|
|
374
|
+
if code := tnTestErrorCode(v); code != "" {
|
|
375
|
+
head += " [" + code + "]"
|
|
376
|
+
}
|
|
377
|
+
return head + ": " + tnTestErrorMessage(v)
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
// --- tap ---
|
|
381
|
+
|
|
382
|
+
type tnTapReporter struct{ started bool }
|
|
383
|
+
|
|
384
|
+
func (r *tnTapReporter) begin() string {
|
|
385
|
+
if r.started {
|
|
386
|
+
return ""
|
|
387
|
+
}
|
|
388
|
+
r.started = true
|
|
389
|
+
return "TAP version 13\\n"
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
func (r *tnTapReporter) end() string { return r.begin() }
|
|
393
|
+
|
|
394
|
+
func (r *tnTapReporter) report(e *TnTestEvent) string {
|
|
395
|
+
out := r.begin()
|
|
396
|
+
d := e.data
|
|
397
|
+
indent := strings.Repeat(" ", int(d.nesting))
|
|
398
|
+
switch e.type_ {
|
|
399
|
+
case "test:fail":
|
|
400
|
+
location := ""
|
|
401
|
+
if d.file != "" {
|
|
402
|
+
location = d.file + ":" + TnNumStr(d.line) + ":" + TnNumStr(d.column)
|
|
403
|
+
}
|
|
404
|
+
out += tnTapTestLine(indent, d, "not ok") + tnTapDetails(indent, d.details, location)
|
|
405
|
+
case "test:pass":
|
|
406
|
+
out += tnTapTestLine(indent, d, "ok") + tnTapDetails(indent, d.details, "")
|
|
407
|
+
case "test:plan":
|
|
408
|
+
out += indent + "1.." + TnNumStr(d.count) + "\\n"
|
|
409
|
+
case "test:start":
|
|
410
|
+
out += indent + "# Subtest: " + tnTapEscape(d.name) + "\\n"
|
|
411
|
+
case "test:stdout", "test:stderr":
|
|
412
|
+
for _, line := range tnTestLines(d.message) {
|
|
413
|
+
if line != "" {
|
|
414
|
+
out += "# " + tnTapEscape(line) + "\\n"
|
|
415
|
+
}
|
|
416
|
+
}
|
|
417
|
+
case "test:diagnostic":
|
|
418
|
+
out += indent + "# " + tnTapEscape(d.message) + "\\n"
|
|
419
|
+
case "test:coverage":
|
|
420
|
+
if d.summary != nil {
|
|
421
|
+
out += tnCoverageReport(indent, d.summary, "# ", "", tnTestPalette{}, true)
|
|
422
|
+
}
|
|
423
|
+
}
|
|
424
|
+
return out
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
func tnTapEscape(s string) string {
|
|
428
|
+
s = strings.ReplaceAll(s, "\\\\", "\\\\\\\\")
|
|
429
|
+
s = strings.ReplaceAll(s, "#", "\\\\#")
|
|
430
|
+
s = strings.ReplaceAll(s, "\\b", "\\\\b")
|
|
431
|
+
s = strings.ReplaceAll(s, "\\f", "\\\\f")
|
|
432
|
+
s = strings.ReplaceAll(s, "\\t", "\\\\t")
|
|
433
|
+
s = strings.ReplaceAll(s, "\\n", "\\\\n")
|
|
434
|
+
s = strings.ReplaceAll(s, "\\r", "\\\\r")
|
|
435
|
+
s = strings.ReplaceAll(s, "\\v", "\\\\v")
|
|
436
|
+
return s
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
func tnTapTestLine(indent string, d *TnTestEventData, status string) string {
|
|
440
|
+
line := indent + status + " " + TnNumStr(d.testNumber)
|
|
441
|
+
if d.name != "" {
|
|
442
|
+
line += " " + tnTapEscape("- "+d.name)
|
|
443
|
+
}
|
|
444
|
+
if d.skip != nil {
|
|
445
|
+
line += " # SKIP"
|
|
446
|
+
if s, ok := d.skip.(string); ok && s != "" {
|
|
447
|
+
line += " " + tnTapEscape(s)
|
|
448
|
+
}
|
|
449
|
+
} else if d.todo != nil {
|
|
450
|
+
line += " # TODO"
|
|
451
|
+
if s, ok := d.todo.(string); ok && s != "" {
|
|
452
|
+
line += " " + tnTapEscape(s)
|
|
453
|
+
}
|
|
454
|
+
}
|
|
455
|
+
return line + "\\n"
|
|
456
|
+
}
|
|
457
|
+
|
|
458
|
+
func tnTapDetails(indent string, details *TnTestEventDetails, location string) string {
|
|
459
|
+
out := indent + " ---\\n"
|
|
460
|
+
if details != nil {
|
|
461
|
+
out += tnTapYaml(indent, "duration_ms", details.duration_ms, nil)
|
|
462
|
+
if details.type_ != "" {
|
|
463
|
+
out += tnTapYaml(indent, "type", details.type_, nil)
|
|
464
|
+
}
|
|
465
|
+
}
|
|
466
|
+
if location != "" {
|
|
467
|
+
out += tnTapYaml(indent, "location", location, nil)
|
|
468
|
+
}
|
|
469
|
+
if details != nil && details.error_ != nil {
|
|
470
|
+
out += tnTapYaml(indent, "", details.error_, map[uintptr]bool{})
|
|
471
|
+
}
|
|
472
|
+
return out + indent + " ...\\n"
|
|
473
|
+
}
|
|
474
|
+
|
|
475
|
+
// Identity of a reference value, for circular references (0 for the rest)
|
|
476
|
+
func tnTestIdentity(v interface{}) uintptr {
|
|
477
|
+
rv := reflect.ValueOf(v)
|
|
478
|
+
switch rv.Kind() {
|
|
479
|
+
case reflect.Pointer, reflect.Map, reflect.Slice:
|
|
480
|
+
return rv.Pointer()
|
|
481
|
+
}
|
|
482
|
+
return 0
|
|
483
|
+
}
|
|
484
|
+
|
|
485
|
+
// null where undefined and null differ (YAML's ~)
|
|
486
|
+
type tnTestNullValue struct{}
|
|
487
|
+
|
|
488
|
+
var tnTestNull = &tnTestNullValue{}
|
|
489
|
+
|
|
490
|
+
// Node's jsToYaml: a key and its value as YAML lines
|
|
491
|
+
func tnTapYaml(indent string, name string, value interface{}, seen map[uintptr]bool) string {
|
|
492
|
+
if value == tnTestNull {
|
|
493
|
+
return indent + " " + name + ": ~\\n"
|
|
494
|
+
}
|
|
495
|
+
if value == nil || TnIsNil(value) {
|
|
496
|
+
return ""
|
|
497
|
+
}
|
|
498
|
+
prefix := indent + " " + name + ":"
|
|
499
|
+
switch v := value.(type) {
|
|
500
|
+
case string:
|
|
501
|
+
lines := tnTestLines(v)
|
|
502
|
+
if len(lines) == 1 {
|
|
503
|
+
return prefix + " " + TnInspect(v) + "\\n"
|
|
504
|
+
}
|
|
505
|
+
out := prefix + " |-\\n"
|
|
506
|
+
for _, line := range lines {
|
|
507
|
+
out += indent + " " + line + "\\n"
|
|
508
|
+
}
|
|
509
|
+
return out
|
|
510
|
+
case float64, bool, int:
|
|
511
|
+
return prefix + " " + TnInspect(v) + "\\n"
|
|
512
|
+
}
|
|
513
|
+
if _, isErr := tnTestErrorOf(value); isErr {
|
|
514
|
+
return tnTapYamlError(indent, name, value, seen)
|
|
515
|
+
}
|
|
516
|
+
rv := reflect.ValueOf(value)
|
|
517
|
+
isList := rv.Kind() == reflect.Slice || rv.Kind() == reflect.Array
|
|
518
|
+
entries := [][]interface{}{}
|
|
519
|
+
if isList {
|
|
520
|
+
for i, item := range tnTestList(value) {
|
|
521
|
+
entries = append(entries, []interface{}{strconv.Itoa(i), item})
|
|
522
|
+
}
|
|
523
|
+
} else if rv.Kind() == reflect.Map || (rv.Kind() == reflect.Pointer && rv.Elem().Kind() == reflect.Struct) || TnKeys(value) != nil {
|
|
524
|
+
entries = TnEntries(value)
|
|
525
|
+
} else {
|
|
526
|
+
return prefix + " " + TnInspect(value) + "\\n"
|
|
527
|
+
}
|
|
528
|
+
if seen == nil {
|
|
529
|
+
seen = map[uintptr]bool{}
|
|
530
|
+
}
|
|
531
|
+
if id := tnTestIdentity(value); id != 0 {
|
|
532
|
+
seen[id] = true
|
|
533
|
+
}
|
|
534
|
+
result := ""
|
|
535
|
+
propsIndent := indent
|
|
536
|
+
if name != "" {
|
|
537
|
+
result += prefix + "\\n"
|
|
538
|
+
propsIndent += " "
|
|
539
|
+
}
|
|
540
|
+
for _, entry := range entries {
|
|
541
|
+
key := tnTestStr(entry[0])
|
|
542
|
+
if id := tnTestIdentity(entry[1]); id != 0 && seen[id] {
|
|
543
|
+
result += propsIndent + " " + key + ": <Circular>\\n"
|
|
544
|
+
continue
|
|
545
|
+
}
|
|
546
|
+
result += tnTapYaml(propsIndent, key, entry[1], seen)
|
|
547
|
+
}
|
|
548
|
+
return result
|
|
549
|
+
}
|
|
550
|
+
|
|
551
|
+
var tnTestUnwrapped = map[string]bool{"testCodeFailure": true, "hookFailure": true, "uncaughtException": true, "unhandledRejection": true}
|
|
552
|
+
|
|
553
|
+
func tnTestCopySeen(seen map[uintptr]bool) map[uintptr]bool {
|
|
554
|
+
out := map[uintptr]bool{}
|
|
555
|
+
for k, v := range seen {
|
|
556
|
+
out[k] = v
|
|
557
|
+
}
|
|
558
|
+
return out
|
|
559
|
+
}
|
|
560
|
+
|
|
561
|
+
// An error: its own properties, then error / code / name (and an assertion's
|
|
562
|
+
// expected / actual / operator), unwrapping ERR_TEST_FAILURE's cause
|
|
563
|
+
func tnTapYamlError(indent string, name string, value interface{}, seen map[uintptr]bool) string {
|
|
564
|
+
err, _ := tnTestErrorOf(value)
|
|
565
|
+
result := ""
|
|
566
|
+
propsIndent := indent
|
|
567
|
+
if name != "" {
|
|
568
|
+
result += indent + " " + name + ":\\n"
|
|
569
|
+
propsIndent += " "
|
|
570
|
+
}
|
|
571
|
+
keys := []string{}
|
|
572
|
+
for k := range err.props {
|
|
573
|
+
switch k {
|
|
574
|
+
case "cause", "code", "name", "message", "stack":
|
|
575
|
+
continue
|
|
576
|
+
}
|
|
577
|
+
keys = append(keys, k)
|
|
578
|
+
}
|
|
579
|
+
sort.Slice(keys, func(i, j int) bool {
|
|
580
|
+
if (keys[i] == "failureType") != (keys[j] == "failureType") {
|
|
581
|
+
return keys[i] == "failureType"
|
|
582
|
+
}
|
|
583
|
+
return keys[i] < keys[j]
|
|
584
|
+
})
|
|
585
|
+
for _, k := range keys {
|
|
586
|
+
result += tnTapYaml(propsIndent, k, err.props[k], seen)
|
|
587
|
+
}
|
|
588
|
+
msg := tnTestErrorMessage(value)
|
|
589
|
+
errName := tnTestErrorName(value)
|
|
590
|
+
errCode := tnTestErrorCode(value)
|
|
591
|
+
var expected, actual, operator interface{}
|
|
592
|
+
isAssertion := false
|
|
593
|
+
assertionOf := func(e *TnError) bool {
|
|
594
|
+
_, hasExpected := e.props["expected"]
|
|
595
|
+
_, hasActual := e.props["actual"]
|
|
596
|
+
return hasExpected && hasActual
|
|
597
|
+
}
|
|
598
|
+
if assertionOf(err) {
|
|
599
|
+
expected, actual, operator, isAssertion = err.props["expected"], err.props["actual"], err.props["operator"], true
|
|
600
|
+
}
|
|
601
|
+
if errCode == "ERR_TEST_FAILURE" && tnTestUnwrapped[tnTestFailureType(value)] {
|
|
602
|
+
cause := err.prop("cause")
|
|
603
|
+
if c, ok := tnTestErrorOf(cause); ok {
|
|
604
|
+
msg = tnTestErrorMessage(cause)
|
|
605
|
+
if code := tnTestErrorCode(cause); code != "" {
|
|
606
|
+
errCode = code
|
|
607
|
+
}
|
|
608
|
+
errName = tnTestErrorName(cause)
|
|
609
|
+
if assertionOf(c) {
|
|
610
|
+
expected, actual, isAssertion = c.props["expected"], c.props["actual"], true
|
|
611
|
+
if op := c.props["operator"]; op != nil {
|
|
612
|
+
operator = op
|
|
613
|
+
}
|
|
614
|
+
}
|
|
615
|
+
}
|
|
616
|
+
}
|
|
617
|
+
result += tnTapYaml(indent, "error", msg, seen)
|
|
618
|
+
if errCode != "" {
|
|
619
|
+
result += tnTapYaml(indent, "code", errCode, seen)
|
|
620
|
+
}
|
|
621
|
+
if errName != "" && errName != "Error" {
|
|
622
|
+
result += tnTapYaml(indent, "name", errName, seen)
|
|
623
|
+
}
|
|
624
|
+
if isAssertion {
|
|
625
|
+
result += tnTapYaml(indent, "expected", expected, tnTestCopySeen(seen))
|
|
626
|
+
result += tnTapYaml(indent, "actual", actual, tnTestCopySeen(seen))
|
|
627
|
+
if op, ok := operator.(string); ok && op != "" {
|
|
628
|
+
result += tnTapYaml(indent, "operator", op, seen)
|
|
629
|
+
}
|
|
630
|
+
}
|
|
631
|
+
return result
|
|
632
|
+
}
|
|
633
|
+
|
|
634
|
+
// --- spec ---
|
|
635
|
+
|
|
636
|
+
type tnSpecReporter struct {
|
|
637
|
+
p tnTestPalette
|
|
638
|
+
cwd string
|
|
639
|
+
stack []*TnTestEventData
|
|
640
|
+
reported []*TnTestEventData
|
|
641
|
+
failed []*TnTestEventData
|
|
642
|
+
}
|
|
643
|
+
|
|
644
|
+
func (r *tnSpecReporter) begin() string { return "" }
|
|
645
|
+
func (r *tnSpecReporter) end() string { return r.failures() }
|
|
646
|
+
|
|
647
|
+
func tnSpecIndent(nesting float64) string { return strings.Repeat(" ", int(nesting)) }
|
|
648
|
+
|
|
649
|
+
func (r *tnSpecReporter) report(e *TnTestEvent) string {
|
|
650
|
+
d := e.data
|
|
651
|
+
switch e.type_ {
|
|
652
|
+
case "test:fail":
|
|
653
|
+
if d.details == nil || tnTestFailureType(d.details.error_) != "subtestsFailed" {
|
|
654
|
+
r.failed = append(r.failed, d)
|
|
655
|
+
}
|
|
656
|
+
return r.result(e.type_, d)
|
|
657
|
+
case "test:pass":
|
|
658
|
+
return r.result(e.type_, d)
|
|
659
|
+
case "test:start":
|
|
660
|
+
r.stack = append([]*TnTestEventData{d}, r.stack...)
|
|
661
|
+
case "test:stdout", "test:stderr":
|
|
662
|
+
return d.message
|
|
663
|
+
case "test:diagnostic":
|
|
664
|
+
color := r.p.blue()
|
|
665
|
+
if d.level == "warn" {
|
|
666
|
+
color = r.p.yellow()
|
|
667
|
+
} else if d.level == "error" {
|
|
668
|
+
color = r.p.red()
|
|
669
|
+
}
|
|
670
|
+
return color + tnSpecIndent(d.nesting) + "\\u2139 " + d.message + r.p.white() + "\\n"
|
|
671
|
+
case "test:coverage":
|
|
672
|
+
if d.summary != nil {
|
|
673
|
+
return tnCoverageReport(tnSpecIndent(d.nesting), d.summary, "\\u2139 ", r.p.blue(), r.p, true)
|
|
674
|
+
}
|
|
675
|
+
case "test:summary":
|
|
676
|
+
// only the root's summary (run() also reports one per file)
|
|
677
|
+
if d.file == "" {
|
|
678
|
+
return r.failures()
|
|
679
|
+
}
|
|
680
|
+
}
|
|
681
|
+
return ""
|
|
682
|
+
}
|
|
683
|
+
|
|
684
|
+
// A test's line, after the ▶ lines of its parents not shown yet
|
|
685
|
+
func (r *tnSpecReporter) result(kind string, d *TnTestEventData) string {
|
|
686
|
+
if len(r.stack) > 0 {
|
|
687
|
+
r.stack = r.stack[1:]
|
|
688
|
+
}
|
|
689
|
+
prefix := ""
|
|
690
|
+
for len(r.stack) > 0 {
|
|
691
|
+
parent := r.stack[len(r.stack)-1]
|
|
692
|
+
r.stack = r.stack[:len(r.stack)-1]
|
|
693
|
+
r.reported = append([]*TnTestEventData{parent}, r.reported...)
|
|
694
|
+
prefix += tnSpecIndent(parent.nesting) + "\\u25b6 " + parent.name + "\\n"
|
|
695
|
+
}
|
|
696
|
+
hasChildren := false
|
|
697
|
+
if len(r.reported) > 0 && r.reported[0].nesting == d.nesting && r.reported[0].name == d.name {
|
|
698
|
+
r.reported = r.reported[1:]
|
|
699
|
+
hasChildren = true
|
|
700
|
+
}
|
|
701
|
+
_ = hasChildren
|
|
702
|
+
return tnSpecFormat(kind, d, false, prefix, tnSpecIndent(d.nesting), r.p) + "\\n"
|
|
703
|
+
}
|
|
704
|
+
|
|
705
|
+
func (r *tnSpecReporter) failures() string {
|
|
706
|
+
if len(r.failed) == 0 {
|
|
707
|
+
return ""
|
|
708
|
+
}
|
|
709
|
+
parts := []string{"\\n" + r.p.red() + "\\u2716 failing tests:" + r.p.white() + "\\n"}
|
|
710
|
+
for _, t := range r.failed {
|
|
711
|
+
if t.file != "" {
|
|
712
|
+
rel, err := filepath.Rel(r.cwd, t.file)
|
|
713
|
+
if err != nil {
|
|
714
|
+
rel = t.file
|
|
715
|
+
}
|
|
716
|
+
parts = append(parts, "test at "+rel+":"+TnNumStr(t.line)+":"+TnNumStr(t.column))
|
|
717
|
+
}
|
|
718
|
+
parts = append(parts, tnSpecFormat("test:fail", t, true, "", "", r.p))
|
|
719
|
+
}
|
|
720
|
+
r.failed = nil
|
|
721
|
+
return strings.Join(parts, "\\n")
|
|
722
|
+
}
|
|
723
|
+
|
|
724
|
+
// Node's formatTestReport
|
|
725
|
+
func tnSpecFormat(kind string, d *TnTestEventData, showError bool, prefix string, indent string, p tnTestPalette) string {
|
|
726
|
+
color, symbol := p.green(), "\\u2714 "
|
|
727
|
+
if kind == "test:fail" {
|
|
728
|
+
color, symbol = p.red(), "\\u2716 "
|
|
729
|
+
}
|
|
730
|
+
title := d.name
|
|
731
|
+
if d.details != nil && d.details.duration_ms != 0 {
|
|
732
|
+
title += " " + p.gray() + "(" + TnNumStr(d.details.duration_ms) + "ms)" + p.white()
|
|
733
|
+
}
|
|
734
|
+
if d.skip != nil {
|
|
735
|
+
msg, _ := d.skip.(string)
|
|
736
|
+
if msg == "" {
|
|
737
|
+
msg = "SKIP"
|
|
738
|
+
}
|
|
739
|
+
title += " # " + msg
|
|
740
|
+
color, symbol = p.gray(), "\\ufe63 "
|
|
741
|
+
} else if d.todo != nil {
|
|
742
|
+
msg, _ := d.todo.(string)
|
|
743
|
+
if msg == "" {
|
|
744
|
+
msg = "TODO"
|
|
745
|
+
}
|
|
746
|
+
title += " # " + msg
|
|
747
|
+
if kind == "test:fail" {
|
|
748
|
+
color, symbol = p.yellow(), "\\u26a0 "
|
|
749
|
+
}
|
|
750
|
+
}
|
|
751
|
+
errText := ""
|
|
752
|
+
if showError && kind == "test:fail" && d.todo == nil && d.details != nil && d.details.error_ != nil {
|
|
753
|
+
errText = tnSpecError(d.details.error_, indent)
|
|
754
|
+
}
|
|
755
|
+
return prefix + indent + color + symbol + title + p.white() + errText
|
|
756
|
+
}
|
|
757
|
+
|
|
758
|
+
func tnSpecError(err interface{}, indent string) string {
|
|
759
|
+
shown := err
|
|
760
|
+
if tnTestErrorCode(err) == "ERR_TEST_FAILURE" {
|
|
761
|
+
if e, ok := tnTestErrorOf(err); ok {
|
|
762
|
+
shown = e.prop("cause")
|
|
763
|
+
}
|
|
764
|
+
}
|
|
765
|
+
lines := tnTestLines(tnTestInspectError(shown))
|
|
766
|
+
return "\\n" + indent + " " + strings.Join(lines, "\\n"+indent+" ") + "\\n"
|
|
767
|
+
}
|
|
768
|
+
|
|
769
|
+
// --- dot ---
|
|
770
|
+
|
|
771
|
+
type tnDotReporter struct {
|
|
772
|
+
p tnTestPalette
|
|
773
|
+
count int
|
|
774
|
+
columns int
|
|
775
|
+
failed []*TnTestEventData
|
|
776
|
+
}
|
|
777
|
+
|
|
778
|
+
func (r *tnDotReporter) begin() string { return "" }
|
|
779
|
+
|
|
780
|
+
func (r *tnDotReporter) report(e *TnTestEvent) string {
|
|
781
|
+
out := ""
|
|
782
|
+
switch e.type_ {
|
|
783
|
+
case "test:pass":
|
|
784
|
+
out = r.p.green() + "." + r.p.reset()
|
|
785
|
+
case "test:fail":
|
|
786
|
+
out = r.p.red() + "X" + r.p.reset()
|
|
787
|
+
r.failed = append(r.failed, e.data)
|
|
788
|
+
default:
|
|
789
|
+
return ""
|
|
790
|
+
}
|
|
791
|
+
r.count++
|
|
792
|
+
if r.count == r.columns {
|
|
793
|
+
out += "\\n"
|
|
794
|
+
r.count = 0
|
|
795
|
+
}
|
|
796
|
+
return out
|
|
797
|
+
}
|
|
798
|
+
|
|
799
|
+
func (r *tnDotReporter) end() string {
|
|
800
|
+
out := "\\n"
|
|
801
|
+
if len(r.failed) > 0 {
|
|
802
|
+
out += "\\n" + r.p.red() + "Failed tests:" + r.p.white() + "\\n\\n"
|
|
803
|
+
for _, t := range r.failed {
|
|
804
|
+
out += tnSpecFormat("test:fail", t, true, "", "", r.p)
|
|
805
|
+
}
|
|
806
|
+
}
|
|
807
|
+
r.failed = nil
|
|
808
|
+
return out
|
|
809
|
+
}
|
|
810
|
+
|
|
811
|
+
// --- junit ---
|
|
812
|
+
|
|
813
|
+
type tnJunitNode struct {
|
|
814
|
+
tag string
|
|
815
|
+
keys []string
|
|
816
|
+
values map[string]string
|
|
817
|
+
nesting int
|
|
818
|
+
parent *tnJunitNode
|
|
819
|
+
children []*tnJunitNode
|
|
820
|
+
comment string
|
|
821
|
+
isNote bool
|
|
822
|
+
text string
|
|
823
|
+
isText bool
|
|
824
|
+
}
|
|
825
|
+
|
|
826
|
+
func (n *tnJunitNode) set(key string, value string) {
|
|
827
|
+
if n.values == nil {
|
|
828
|
+
n.values = map[string]string{}
|
|
829
|
+
}
|
|
830
|
+
if _, ok := n.values[key]; !ok {
|
|
831
|
+
n.keys = append(n.keys, key)
|
|
832
|
+
}
|
|
833
|
+
n.values[key] = value
|
|
834
|
+
}
|
|
835
|
+
|
|
836
|
+
type tnJunitReporter struct {
|
|
837
|
+
current *tnJunitNode
|
|
838
|
+
roots []*tnJunitNode
|
|
839
|
+
}
|
|
840
|
+
|
|
841
|
+
func (r *tnJunitReporter) begin() string { return "" }
|
|
842
|
+
|
|
843
|
+
func (r *tnJunitReporter) start(name string, nesting int) {
|
|
844
|
+
parent := r.current
|
|
845
|
+
r.current = &tnJunitNode{nesting: nesting, parent: parent}
|
|
846
|
+
r.current.set("name", name)
|
|
847
|
+
if parent != nil {
|
|
848
|
+
parent.children = append(parent.children, r.current)
|
|
849
|
+
} else {
|
|
850
|
+
r.roots = append(r.roots, r.current)
|
|
851
|
+
}
|
|
852
|
+
}
|
|
853
|
+
|
|
854
|
+
func tnJunitIsFailure(n *tnJunitNode) bool {
|
|
855
|
+
for _, c := range n.children {
|
|
856
|
+
if c.tag == "failure" {
|
|
857
|
+
return true
|
|
858
|
+
}
|
|
859
|
+
}
|
|
860
|
+
return n.values["failures"] != "" && n.values["failures"] != "0"
|
|
861
|
+
}
|
|
862
|
+
|
|
863
|
+
// (as in Node, a suite with failures counts as skipped too)
|
|
864
|
+
func tnJunitIsSkipped(n *tnJunitNode) bool {
|
|
865
|
+
for _, c := range n.children {
|
|
866
|
+
if c.tag == "skipped" {
|
|
867
|
+
return true
|
|
868
|
+
}
|
|
869
|
+
}
|
|
870
|
+
return n.values["failures"] != "" && n.values["failures"] != "0"
|
|
871
|
+
}
|
|
872
|
+
|
|
873
|
+
func (r *tnJunitReporter) report(e *TnTestEvent) string {
|
|
874
|
+
d := e.data
|
|
875
|
+
switch e.type_ {
|
|
876
|
+
case "test:start":
|
|
877
|
+
r.start(d.name, int(d.nesting))
|
|
878
|
+
case "test:pass", "test:fail":
|
|
879
|
+
if r.current == nil {
|
|
880
|
+
r.start("root", 0)
|
|
881
|
+
}
|
|
882
|
+
if r.current.values["name"] != d.name || r.current.nesting != int(d.nesting) {
|
|
883
|
+
r.start(d.name, int(d.nesting))
|
|
884
|
+
}
|
|
885
|
+
test := r.current
|
|
886
|
+
if r.current.nesting == int(d.nesting) {
|
|
887
|
+
r.current = r.current.parent
|
|
888
|
+
}
|
|
889
|
+
duration := 0.0
|
|
890
|
+
if d.details != nil {
|
|
891
|
+
duration = d.details.duration_ms
|
|
892
|
+
}
|
|
893
|
+
test.set("time", strconv.FormatFloat(duration/1000, 'f', 6, 64))
|
|
894
|
+
children := 0
|
|
895
|
+
for _, c := range test.children {
|
|
896
|
+
if !c.isNote {
|
|
897
|
+
children++
|
|
898
|
+
}
|
|
899
|
+
}
|
|
900
|
+
if children > 0 {
|
|
901
|
+
test.tag = "testsuite"
|
|
902
|
+
test.set("disabled", "0")
|
|
903
|
+
test.set("errors", "0")
|
|
904
|
+
test.set("tests", strconv.Itoa(children))
|
|
905
|
+
failures, skipped := 0, 0
|
|
906
|
+
for _, c := range test.children {
|
|
907
|
+
if tnJunitIsFailure(c) {
|
|
908
|
+
failures++
|
|
909
|
+
}
|
|
910
|
+
if tnJunitIsSkipped(c) {
|
|
911
|
+
skipped++
|
|
912
|
+
}
|
|
913
|
+
}
|
|
914
|
+
test.set("failures", strconv.Itoa(failures))
|
|
915
|
+
test.set("skipped", strconv.Itoa(skipped))
|
|
916
|
+
test.set("timestamp", time.Now().UTC().Format("2006-01-02T15:04:05.000Z"))
|
|
917
|
+
host, _ := os.Hostname()
|
|
918
|
+
test.set("hostname", host)
|
|
919
|
+
} else {
|
|
920
|
+
test.tag = "testcase"
|
|
921
|
+
test.set("classname", "test")
|
|
922
|
+
if d.file != "" {
|
|
923
|
+
test.set("file", d.file)
|
|
924
|
+
}
|
|
925
|
+
child := func(tag string) *tnJunitNode {
|
|
926
|
+
n := &tnJunitNode{tag: tag, nesting: int(d.nesting) + 1}
|
|
927
|
+
test.children = append(test.children, n)
|
|
928
|
+
return n
|
|
929
|
+
}
|
|
930
|
+
if d.skip != nil && d.skip != false {
|
|
931
|
+
n := child("skipped")
|
|
932
|
+
n.set("type", "skipped")
|
|
933
|
+
n.set("message", tnTestStr(d.skip))
|
|
934
|
+
}
|
|
935
|
+
if d.todo != nil && d.todo != false {
|
|
936
|
+
n := child("skipped")
|
|
937
|
+
n.set("type", "todo")
|
|
938
|
+
n.set("message", tnTestStr(d.todo))
|
|
939
|
+
}
|
|
940
|
+
if e.type_ == "test:fail" {
|
|
941
|
+
var err interface{}
|
|
942
|
+
if d.details != nil {
|
|
943
|
+
err = d.details.error_
|
|
944
|
+
}
|
|
945
|
+
msg := tnTestErrorMessage(err)
|
|
946
|
+
kind := tnTestFailureType(err)
|
|
947
|
+
if kind == "" {
|
|
948
|
+
kind = tnTestErrorCode(err)
|
|
949
|
+
}
|
|
950
|
+
n := child("failure")
|
|
951
|
+
n.set("type", kind)
|
|
952
|
+
n.set("message", strings.TrimSpace(msg))
|
|
953
|
+
n.children = []*tnJunitNode{{isText: true, text: tnJunitErrorText(err)}}
|
|
954
|
+
test.set("failure", msg)
|
|
955
|
+
}
|
|
956
|
+
}
|
|
957
|
+
case "test:diagnostic":
|
|
958
|
+
note := &tnJunitNode{nesting: int(d.nesting), isNote: true, comment: d.message}
|
|
959
|
+
if r.current != nil {
|
|
960
|
+
r.current.children = append(r.current.children, note)
|
|
961
|
+
} else {
|
|
962
|
+
r.roots = append(r.roots, note)
|
|
963
|
+
}
|
|
964
|
+
}
|
|
965
|
+
return ""
|
|
966
|
+
}
|
|
967
|
+
|
|
968
|
+
// util.inspect of the ERR_TEST_FAILURE wrapper, without its stack
|
|
969
|
+
func tnJunitErrorText(err interface{}) string {
|
|
970
|
+
if tnTestErrorCode(err) != "ERR_TEST_FAILURE" {
|
|
971
|
+
return tnTestInspectError(err)
|
|
972
|
+
}
|
|
973
|
+
e, _ := tnTestErrorOf(err)
|
|
974
|
+
head := "[Error [ERR_TEST_FAILURE]: " + tnTestErrorMessage(err) + "]"
|
|
975
|
+
cause := tnTestInspectError(e.prop("cause"))
|
|
976
|
+
failureType := TnInspect(tnTestFailureType(err))
|
|
977
|
+
if !strings.Contains(head+cause, "\\n") {
|
|
978
|
+
return head + " { code: 'ERR_TEST_FAILURE', failureType: " + failureType + ", cause: " + cause + " }"
|
|
979
|
+
}
|
|
980
|
+
return head + " {\\n code: 'ERR_TEST_FAILURE',\\n failureType: " + failureType + ",\\n cause: " + strings.ReplaceAll(cause, "\\n", "\\n ") + "\\n}"
|
|
981
|
+
}
|
|
982
|
+
|
|
983
|
+
func tnJunitContent(s string) string {
|
|
984
|
+
s = strings.ReplaceAll(s, "&", "&")
|
|
985
|
+
return strings.ReplaceAll(s, "<", "<")
|
|
986
|
+
}
|
|
987
|
+
|
|
988
|
+
func tnJunitAttr(s string) string {
|
|
989
|
+
s = strings.ReplaceAll(tnJunitContent(s), "\\"", """)
|
|
990
|
+
return strings.ReplaceAll(s, "\\n", " ")
|
|
991
|
+
}
|
|
992
|
+
|
|
993
|
+
func tnJunitXML(n *tnJunitNode) string {
|
|
994
|
+
if n.isText {
|
|
995
|
+
return tnJunitContent(n.text) + "\\n"
|
|
996
|
+
}
|
|
997
|
+
indent := strings.Repeat("\\t", n.nesting+1)
|
|
998
|
+
if n.isNote {
|
|
999
|
+
return indent + "<!-- " + strings.ReplaceAll(n.comment, "--", "--") + " -->\\n"
|
|
1000
|
+
}
|
|
1001
|
+
attrs := []string{}
|
|
1002
|
+
for _, k := range n.keys {
|
|
1003
|
+
attrs = append(attrs, k+"=\\""+tnJunitAttr(n.values[k])+"\\"")
|
|
1004
|
+
}
|
|
1005
|
+
if len(n.children) == 0 {
|
|
1006
|
+
return indent + "<" + n.tag + " " + strings.Join(attrs, " ") + "/>\\n"
|
|
1007
|
+
}
|
|
1008
|
+
out := indent + "<" + n.tag + " " + strings.Join(attrs, " ") + ">\\n"
|
|
1009
|
+
for _, c := range n.children {
|
|
1010
|
+
out += tnJunitXML(c)
|
|
1011
|
+
}
|
|
1012
|
+
return out + indent + "</" + n.tag + ">\\n"
|
|
1013
|
+
}
|
|
1014
|
+
|
|
1015
|
+
func (r *tnJunitReporter) end() string {
|
|
1016
|
+
out := "<?xml version=\\"1.0\\" encoding=\\"utf-8\\"?>\\n<testsuites>\\n"
|
|
1017
|
+
for _, n := range r.roots {
|
|
1018
|
+
out += tnJunitXML(n)
|
|
1019
|
+
}
|
|
1020
|
+
r.roots = nil
|
|
1021
|
+
return out + "</testsuites>\\n"
|
|
1022
|
+
}
|
|
1023
|
+
|
|
1024
|
+
// --- lcov ---
|
|
1025
|
+
|
|
1026
|
+
type tnLcovReporter struct{}
|
|
1027
|
+
|
|
1028
|
+
func (r *tnLcovReporter) begin() string { return "" }
|
|
1029
|
+
func (r *tnLcovReporter) end() string { return "" }
|
|
1030
|
+
|
|
1031
|
+
func (r *tnLcovReporter) report(e *TnTestEvent) string {
|
|
1032
|
+
if e.type_ != "test:coverage" || e.data.summary == nil {
|
|
1033
|
+
return ""
|
|
1034
|
+
}
|
|
1035
|
+
s := e.data.summary
|
|
1036
|
+
var b strings.Builder
|
|
1037
|
+
for _, f := range s.files {
|
|
1038
|
+
b.WriteString("TN:\\n")
|
|
1039
|
+
rel, err := filepath.Rel(s.workingDirectory, f.path)
|
|
1040
|
+
if err != nil {
|
|
1041
|
+
rel = f.path
|
|
1042
|
+
}
|
|
1043
|
+
b.WriteString("SF:" + rel + "\\n")
|
|
1044
|
+
names := make([]string, len(f.functions))
|
|
1045
|
+
for j, fn := range f.functions {
|
|
1046
|
+
names[j] = fn.name
|
|
1047
|
+
if names[j] == "" {
|
|
1048
|
+
names[j] = "anonymous_" + strconv.Itoa(j)
|
|
1049
|
+
}
|
|
1050
|
+
b.WriteString("FN:" + TnNumStr(fn.line) + "," + names[j] + "\\n")
|
|
1051
|
+
}
|
|
1052
|
+
for j, fn := range f.functions {
|
|
1053
|
+
b.WriteString("FNDA:" + TnNumStr(fn.count) + "," + names[j] + "\\n")
|
|
1054
|
+
}
|
|
1055
|
+
b.WriteString("FNF:" + TnNumStr(f.totalFunctionCount) + "\\n")
|
|
1056
|
+
b.WriteString("FNH:" + TnNumStr(f.coveredFunctionCount) + "\\n")
|
|
1057
|
+
for j, br := range f.branches {
|
|
1058
|
+
b.WriteString("BRDA:" + TnNumStr(br.line) + "," + strconv.Itoa(j) + ",0," + TnNumStr(br.count) + "\\n")
|
|
1059
|
+
}
|
|
1060
|
+
b.WriteString("BRF:" + TnNumStr(f.totalBranchCount) + "\\n")
|
|
1061
|
+
b.WriteString("BRH:" + TnNumStr(f.coveredBranchCount) + "\\n")
|
|
1062
|
+
lines := append([]*TnCoverageCount{}, f.lines...)
|
|
1063
|
+
sort.SliceStable(lines, func(i, j int) bool { return lines[i].line < lines[j].line })
|
|
1064
|
+
for _, l := range lines {
|
|
1065
|
+
b.WriteString("DA:" + TnNumStr(l.line) + "," + TnNumStr(l.count) + "\\n")
|
|
1066
|
+
}
|
|
1067
|
+
b.WriteString("LH:" + TnNumStr(f.coveredLineCount) + "\\n")
|
|
1068
|
+
b.WriteString("LF:" + TnNumStr(f.totalLineCount) + "\\n")
|
|
1069
|
+
b.WriteString("end_of_record\\n")
|
|
1070
|
+
}
|
|
1071
|
+
return b.String()
|
|
1072
|
+
}
|
|
1073
|
+
|
|
1074
|
+
// --- the coverage table (tap and spec) ---
|
|
1075
|
+
|
|
1076
|
+
type tnCoverageDir struct {
|
|
1077
|
+
name string
|
|
1078
|
+
children []*tnCoverageDir
|
|
1079
|
+
file *TnCoverageFile
|
|
1080
|
+
}
|
|
1081
|
+
|
|
1082
|
+
func (d *tnCoverageDir) child(name string) *tnCoverageDir {
|
|
1083
|
+
for _, c := range d.children {
|
|
1084
|
+
if c.name == name {
|
|
1085
|
+
return c
|
|
1086
|
+
}
|
|
1087
|
+
}
|
|
1088
|
+
c := &tnCoverageDir{name: name}
|
|
1089
|
+
d.children = append(d.children, c)
|
|
1090
|
+
return c
|
|
1091
|
+
}
|
|
1092
|
+
|
|
1093
|
+
func tnCoverageUncovered(lines []*TnCoverageCount) string {
|
|
1094
|
+
ranges := [][]float64{}
|
|
1095
|
+
for _, l := range lines {
|
|
1096
|
+
if l.count != 0 {
|
|
1097
|
+
continue
|
|
1098
|
+
}
|
|
1099
|
+
if n := len(ranges); n > 0 && l.line-ranges[n-1][len(ranges[n-1])-1] == 1 {
|
|
1100
|
+
if len(ranges[n-1]) == 1 {
|
|
1101
|
+
ranges[n-1] = append(ranges[n-1], l.line)
|
|
1102
|
+
} else {
|
|
1103
|
+
ranges[n-1][1] = l.line
|
|
1104
|
+
}
|
|
1105
|
+
continue
|
|
1106
|
+
}
|
|
1107
|
+
ranges = append(ranges, []float64{l.line})
|
|
1108
|
+
}
|
|
1109
|
+
parts := make([]string, len(ranges))
|
|
1110
|
+
for i, r := range ranges {
|
|
1111
|
+
parts[i] = TnNumStr(r[0])
|
|
1112
|
+
if len(r) > 1 {
|
|
1113
|
+
parts[i] += "-" + TnNumStr(r[1])
|
|
1114
|
+
}
|
|
1115
|
+
}
|
|
1116
|
+
return strings.Join(parts, " ")
|
|
1117
|
+
}
|
|
1118
|
+
|
|
1119
|
+
// Node's getCoverageReport: a table of the files (grouped by directory) and the totals
|
|
1120
|
+
func tnCoverageReport(pad string, s *TnCoverageSummary, symbol string, color string, p tnTestPalette, table bool) string {
|
|
1121
|
+
prefix := pad + symbol
|
|
1122
|
+
var b strings.Builder
|
|
1123
|
+
b.WriteString(color + prefix + "start of coverage report\\n")
|
|
1124
|
+
root := &tnCoverageDir{}
|
|
1125
|
+
depth, longest := 1, 0
|
|
1126
|
+
for _, f := range s.files {
|
|
1127
|
+
rel, err := filepath.Rel(s.workingDirectory, f.path)
|
|
1128
|
+
if err != nil {
|
|
1129
|
+
rel = f.path
|
|
1130
|
+
}
|
|
1131
|
+
parts := strings.Split(rel, string(filepath.Separator))
|
|
1132
|
+
node := root
|
|
1133
|
+
for _, part := range parts {
|
|
1134
|
+
node = node.child(part)
|
|
1135
|
+
if len(part) > longest {
|
|
1136
|
+
longest = len(part)
|
|
1137
|
+
}
|
|
1138
|
+
}
|
|
1139
|
+
node.file = f
|
|
1140
|
+
if len(parts) > depth {
|
|
1141
|
+
depth = len(parts)
|
|
1142
|
+
}
|
|
1143
|
+
}
|
|
1144
|
+
columns := []string{"line %", "branch %", "funcs %"}
|
|
1145
|
+
filePad := longest + depth - 1
|
|
1146
|
+
if color != "" {
|
|
1147
|
+
filePad += 2
|
|
1148
|
+
}
|
|
1149
|
+
if filePad < len("all files") {
|
|
1150
|
+
filePad = len("all files")
|
|
1151
|
+
}
|
|
1152
|
+
columnPads := []int{}
|
|
1153
|
+
columnsWidth := 0
|
|
1154
|
+
for _, c := range columns {
|
|
1155
|
+
w := len(c)
|
|
1156
|
+
if w < 6 {
|
|
1157
|
+
w = 6
|
|
1158
|
+
}
|
|
1159
|
+
columnPads = append(columnPads, w)
|
|
1160
|
+
columnsWidth += w + 3
|
|
1161
|
+
}
|
|
1162
|
+
uncoveredPad := len("uncovered lines")
|
|
1163
|
+
for _, f := range s.files {
|
|
1164
|
+
if n := len(tnCoverageUncovered(f.lines)); n > uncoveredPad {
|
|
1165
|
+
uncoveredPad = n
|
|
1166
|
+
}
|
|
1167
|
+
}
|
|
1168
|
+
tableWidth := filePad + 2 + columnsWidth + uncoveredPad + 2
|
|
1169
|
+
cell := func(text string, width int, padStart bool, coverage float64, colored bool) string {
|
|
1170
|
+
for len([]rune(text)) < width {
|
|
1171
|
+
if padStart {
|
|
1172
|
+
text = " " + text
|
|
1173
|
+
} else {
|
|
1174
|
+
text += " "
|
|
1175
|
+
}
|
|
1176
|
+
}
|
|
1177
|
+
if color != "" && colored {
|
|
1178
|
+
shade := p.red()
|
|
1179
|
+
if coverage > 90 {
|
|
1180
|
+
shade = p.green()
|
|
1181
|
+
} else if coverage > 50 {
|
|
1182
|
+
shade = p.yellow()
|
|
1183
|
+
}
|
|
1184
|
+
return shade + text + color
|
|
1185
|
+
}
|
|
1186
|
+
return text
|
|
1187
|
+
}
|
|
1188
|
+
line := func(file string, depth int, coverages []interface{}, fileCoverage float64, fileColored bool, uncovered string) string {
|
|
1189
|
+
name := file
|
|
1190
|
+
if r := []rune(name); len(r) > filePad-depth && filePad-depth > 0 {
|
|
1191
|
+
name = "\\u2026" + string(r[len(r)-(filePad-depth)+1:])
|
|
1192
|
+
}
|
|
1193
|
+
cols := make([]string, len(coverages))
|
|
1194
|
+
for j, c := range coverages {
|
|
1195
|
+
if pct, ok := c.(float64); ok {
|
|
1196
|
+
cols[j] = cell(strconv.FormatFloat(pct, 'f', 2, 64), columnPads[j], true, pct, true)
|
|
1197
|
+
} else {
|
|
1198
|
+
cols[j] = cell(tnTestStr(c), columnPads[j], true, 0, c != nil && !isColumnTitle(c))
|
|
1199
|
+
}
|
|
1200
|
+
}
|
|
1201
|
+
return prefix + strings.Repeat(" ", depth) + cell(name, filePad-depth, false, fileCoverage, fileColored) + " | " + strings.Join(cols, " | ") + " | " + uncovered + "\\n"
|
|
1202
|
+
}
|
|
1203
|
+
rule := func() {
|
|
1204
|
+
if table {
|
|
1205
|
+
b.WriteString(prefix + strings.Repeat("-", tableWidth) + "\\n")
|
|
1206
|
+
}
|
|
1207
|
+
}
|
|
1208
|
+
rule()
|
|
1209
|
+
b.WriteString(line("file", 0, []interface{}{tnCoverageTitle("line %"), tnCoverageTitle("branch %"), tnCoverageTitle("funcs %")}, 0, false, "uncovered lines"))
|
|
1210
|
+
rule()
|
|
1211
|
+
var walk func(dir *tnCoverageDir, depth int)
|
|
1212
|
+
walk = func(dir *tnCoverageDir, depth int) {
|
|
1213
|
+
for _, c := range dir.children {
|
|
1214
|
+
if c.file != nil {
|
|
1215
|
+
f := c.file
|
|
1216
|
+
coverage := (f.coveredLinePercent + f.coveredBranchPercent + f.coveredFunctionPercent) / 3
|
|
1217
|
+
b.WriteString(line(c.name, depth, []interface{}{f.coveredLinePercent, f.coveredBranchPercent, f.coveredFunctionPercent}, coverage, true, tnCoverageUncovered(f.lines)))
|
|
1218
|
+
} else {
|
|
1219
|
+
b.WriteString(line(c.name, depth, []interface{}{"", "", ""}, 0, false, ""))
|
|
1220
|
+
walk(c, depth+1)
|
|
1221
|
+
}
|
|
1222
|
+
}
|
|
1223
|
+
}
|
|
1224
|
+
walk(root, 0)
|
|
1225
|
+
rule()
|
|
1226
|
+
t := s.totals
|
|
1227
|
+
if t == nil {
|
|
1228
|
+
t = &TnCoverageTotals{}
|
|
1229
|
+
}
|
|
1230
|
+
b.WriteString(line("all files", 0, []interface{}{t.coveredLinePercent, t.coveredBranchPercent, t.coveredFunctionPercent}, 0, false, ""))
|
|
1231
|
+
rule()
|
|
1232
|
+
b.WriteString(prefix + "end of coverage report\\n")
|
|
1233
|
+
if color != "" {
|
|
1234
|
+
b.WriteString(p.white())
|
|
1235
|
+
}
|
|
1236
|
+
return b.String()
|
|
1237
|
+
}
|
|
1238
|
+
|
|
1239
|
+
// The header's column titles, which are never colored
|
|
1240
|
+
type tnCoverageTitle string
|
|
1241
|
+
|
|
1242
|
+
func isColumnTitle(v interface{}) bool {
|
|
1243
|
+
_, ok := v.(tnCoverageTitle)
|
|
1244
|
+
return ok
|
|
1245
|
+
}`;
|
|
1246
|
+
const reportersHelper = `// --- node:test/reporters: the reporters over any event source ---
|
|
1247
|
+
|
|
1248
|
+
// The events of a source: an array, an async generator (channel) or a
|
|
1249
|
+
// readable stream (run()'s TestsStream, Readable.from); posts each one to fn
|
|
1250
|
+
// on the event loop, then done
|
|
1251
|
+
func tnTestEachEvent(source interface{}, fn func(e *TnTestEvent), done func()) {
|
|
1252
|
+
if s, ok := source.(*TnStream); ok {
|
|
1253
|
+
source = s.tnIterator()
|
|
1254
|
+
}
|
|
1255
|
+
rv := reflect.ValueOf(source)
|
|
1256
|
+
if rv.Kind() != reflect.Chan {
|
|
1257
|
+
for _, item := range tnTestList(source) {
|
|
1258
|
+
fn(tnTestEventOf(item))
|
|
1259
|
+
}
|
|
1260
|
+
done()
|
|
1261
|
+
return
|
|
1262
|
+
}
|
|
1263
|
+
TnLoopRef()
|
|
1264
|
+
go func() {
|
|
1265
|
+
for {
|
|
1266
|
+
v, ok := rv.Recv()
|
|
1267
|
+
if !ok {
|
|
1268
|
+
break
|
|
1269
|
+
}
|
|
1270
|
+
item := v.Interface()
|
|
1271
|
+
TnLoopPost(func() { fn(tnTestEventOf(item)) })
|
|
1272
|
+
}
|
|
1273
|
+
TnLoopPost(func() {
|
|
1274
|
+
defer TnLoopUnref()
|
|
1275
|
+
done()
|
|
1276
|
+
})
|
|
1277
|
+
}()
|
|
1278
|
+
}
|
|
1279
|
+
|
|
1280
|
+
// tap / dot / junit (source): an async generator of the reporter's text
|
|
1281
|
+
func TnTestReporterOver(name string, source interface{}) chan string {
|
|
1282
|
+
reporter := tnNewTestReporter(name, tnTestColorsOn())
|
|
1283
|
+
out := make(chan string, 65536)
|
|
1284
|
+
if head := reporter.begin(); head != "" {
|
|
1285
|
+
out <- head
|
|
1286
|
+
}
|
|
1287
|
+
tnTestEachEvent(source, func(e *TnTestEvent) {
|
|
1288
|
+
if text := reporter.report(e); text != "" {
|
|
1289
|
+
out <- text
|
|
1290
|
+
}
|
|
1291
|
+
}, func() {
|
|
1292
|
+
if text := reporter.end(); text != "" {
|
|
1293
|
+
out <- text
|
|
1294
|
+
}
|
|
1295
|
+
close(out)
|
|
1296
|
+
})
|
|
1297
|
+
return out
|
|
1298
|
+
}
|
|
1299
|
+
|
|
1300
|
+
func TnTestReporterTap(source interface{}) chan string { return TnTestReporterOver("tap", source) }
|
|
1301
|
+
func TnTestReporterDot(source interface{}) chan string { return TnTestReporterOver("dot", source) }
|
|
1302
|
+
func TnTestReporterJunit(source interface{}) chan string { return TnTestReporterOver("junit", source) }
|
|
1303
|
+
|
|
1304
|
+
// new spec() / new lcov(): a Transform from events (object mode) to text
|
|
1305
|
+
func TnNewTestReporterStream(name string) *TnStream {
|
|
1306
|
+
reporter := tnNewTestReporter(name, tnTestColorsOn())
|
|
1307
|
+
s := TnNewTransform()
|
|
1308
|
+
s.objectMode = true
|
|
1309
|
+
s.setHook("_transform", func(chunk interface{}, encoding string, cb func(...interface{})) {
|
|
1310
|
+
if text := reporter.report(tnTestEventOf(chunk)); text != "" {
|
|
1311
|
+
s.push(text)
|
|
1312
|
+
}
|
|
1313
|
+
cb()
|
|
1314
|
+
})
|
|
1315
|
+
s.setHook("_flush", func(cb func(...interface{})) {
|
|
1316
|
+
if text := reporter.end(); text != "" {
|
|
1317
|
+
s.push(text)
|
|
1318
|
+
}
|
|
1319
|
+
cb()
|
|
1320
|
+
})
|
|
1321
|
+
return s
|
|
1322
|
+
}
|
|
1323
|
+
|
|
1324
|
+
func TnTestReporterSpec() *TnStream { return TnNewTestReporterStream("spec") }
|
|
1325
|
+
func TnTestReporterLcov() *TnStream { return TnNewTestReporterStream("lcov") }`;
|
|
1326
|
+
export function registerTestReporters(r) {
|
|
1327
|
+
defineHelper(r, 'nodeTestReport', ['os', 'path/filepath', 'reflect', 'sort', 'strconv', 'strings', 'time'], ['nodeTty', 'nodeUtil', 'nodeProcess', 'dynamic', 'error'], reportHelper);
|
|
1328
|
+
// Test durations: Go's monotonic clock on Windows ticks too coarsely for them
|
|
1329
|
+
defineHelper(r, 'nodeTestClock@windows', ['syscall', 'unsafe'], [], `// Milliseconds from QueryPerformanceCounter (what Node's hrtime reads)
|
|
1330
|
+
var tnQPC = syscall.NewLazyDLL("kernel32.dll").NewProc("QueryPerformanceCounter")
|
|
1331
|
+
var tnQPF = syscall.NewLazyDLL("kernel32.dll").NewProc("QueryPerformanceFrequency")
|
|
1332
|
+
|
|
1333
|
+
func tnTestNow() float64 {
|
|
1334
|
+
var count, frequency int64
|
|
1335
|
+
tnQPC.Call(uintptr(unsafe.Pointer(&count)))
|
|
1336
|
+
tnQPF.Call(uintptr(unsafe.Pointer(&frequency)))
|
|
1337
|
+
if frequency == 0 {
|
|
1338
|
+
return 0
|
|
1339
|
+
}
|
|
1340
|
+
return float64(count) / float64(frequency) * 1000
|
|
1341
|
+
}`);
|
|
1342
|
+
defineHelper(r, 'nodeTestClock@other', ['time'], [], `var tnTestEpoch = time.Now()
|
|
1343
|
+
|
|
1344
|
+
// Milliseconds on the monotonic clock
|
|
1345
|
+
func tnTestNow() float64 { return float64(time.Since(tnTestEpoch).Nanoseconds()) / 1e6 }`);
|
|
1346
|
+
defineHelper(r, 'nodeTestReporters', ['reflect'], ['nodeTestReport', 'nodeStream', 'eventLoop'], reportersHelper);
|
|
1347
|
+
const use = () => r.helper('nodeTestReporters');
|
|
1348
|
+
// Event data, for typed reads in run() listeners (stream.on('test:pass', (data) => …))
|
|
1349
|
+
defineClass(r, 'test.TestEvent', '*TnTestEvent', 'class', '', 'data=*TnTestEventData', 'type=string', '');
|
|
1350
|
+
defineClass(r, 'test.TestEventData', '*TnTestEventData', 'class', '', 'name=string; nesting=float64; testNumber=float64; details=*TnTestEventDetails; skip=interface{}; todo=interface{}; file=string; line=float64; column=float64; count=float64; message=string; level=string; counts=*TnTestCounts; duration_ms=float64; success=bool; summary=*TnCoverageSummary', '', '');
|
|
1351
|
+
defineClass(r, 'test.TestEventDetails', '*TnTestEventDetails', 'class', '', 'duration_ms=float64; passed=bool', 'type=string; error=interface{}', '');
|
|
1352
|
+
defineClass(r, 'test.TestCounts', '*TnTestCounts', 'class', '', 'tests=float64; failed=float64; passed=float64; cancelled=float64; skipped=float64; todo=float64; topLevel=float64; suites=float64', '', '');
|
|
1353
|
+
const counts = 'totalLineCount=float64; totalBranchCount=float64; totalFunctionCount=float64; coveredLineCount=float64; coveredBranchCount=float64; coveredFunctionCount=float64; coveredLinePercent=float64; coveredBranchPercent=float64; coveredFunctionPercent=float64';
|
|
1354
|
+
defineClass(r, 'test.CoverageSummary', '*TnCoverageSummary', 'class', '', 'workingDirectory=string; files=[]*TnCoverageFile; totals=*TnCoverageTotals', '', '');
|
|
1355
|
+
defineClass(r, 'test.CoverageFile', '*TnCoverageFile', 'class', '', `path=string; ${counts}; functions=[]*TnCoverageFunction; branches=[]*TnCoverageCount; lines=[]*TnCoverageCount`, '', '');
|
|
1356
|
+
defineClass(r, 'test.CoverageTotals', '*TnCoverageTotals', 'class', '', counts, '', '');
|
|
1357
|
+
defineClass(r, 'test.CoverageFunction', '*TnCoverageFunction', 'class', '', 'name=string; line=float64; count=float64', '', '');
|
|
1358
|
+
defineClass(r, 'test.CoverageCount', '*TnCoverageCount', 'class', '', 'line=float64; count=float64', '', '');
|
|
1359
|
+
// node:test/reporters
|
|
1360
|
+
defineModule(r, 'test/reporters');
|
|
1361
|
+
r.namespaces['test/reporters.default'] = 'test/reporters';
|
|
1362
|
+
const generators = { tap: 'TnTestReporterTap', dot: 'TnTestReporterDot', junit: 'TnTestReporterJunit' };
|
|
1363
|
+
for (const name of Object.keys(generators)) {
|
|
1364
|
+
const goFn = generators[name];
|
|
1365
|
+
r.functions[`test/reporters.${name}`] = (c) => {
|
|
1366
|
+
use();
|
|
1367
|
+
return `${goFn}(${c.args[0] ?? 'nil'})`;
|
|
1368
|
+
};
|
|
1369
|
+
r.results[`test/reporters.${name}`] = 'chan string';
|
|
1370
|
+
// passed to compose(): the generator function itself
|
|
1371
|
+
r.values[`test/reporters.${name}`] = (_c) => {
|
|
1372
|
+
use();
|
|
1373
|
+
return goFn;
|
|
1374
|
+
};
|
|
1375
|
+
r.valueTypes[`test/reporters.${name}`] = 'func(interface{}) chan string';
|
|
1376
|
+
}
|
|
1377
|
+
const streams = { spec: 'TnTestReporterSpec', lcov: 'TnTestReporterLcov' };
|
|
1378
|
+
for (const name of Object.keys(streams)) {
|
|
1379
|
+
const goFn = streams[name];
|
|
1380
|
+
r.constructors[`test/reporters.${name}`] = (_c) => {
|
|
1381
|
+
use();
|
|
1382
|
+
return `${goFn}()`;
|
|
1383
|
+
};
|
|
1384
|
+
r.classes[`test/reporters.${name}`] = r.classes['stream.Duplex'];
|
|
1385
|
+
// compose(spec): the factory, called with the source
|
|
1386
|
+
r.values[`test/reporters.${name}`] = (_c) => {
|
|
1387
|
+
use();
|
|
1388
|
+
return goFn;
|
|
1389
|
+
};
|
|
1390
|
+
r.valueTypes[`test/reporters.${name}`] = 'func() *TnStream';
|
|
1391
|
+
}
|
|
1392
|
+
}
|