typenative 0.3.1 → 0.4.1
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/.github/workflows/ci.yml +2 -0
- package/CHANGELOG.md +258 -0
- package/CONTRIBUTION.md +1 -1
- package/README.md +17 -1
- package/bin/cli.js +26 -11
- package/bin/go/bridge.js +74 -14
- package/bin/go/convert.js +59 -1
- package/bin/go/metadata.js +13 -4
- package/bin/go/overrides.js +4 -6
- package/bin/go/stdlib.generated.js +2 -0
- package/bin/index.js +338 -47
- package/bin/main.js +36 -14
- package/bin/node/assert.js +2 -2
- package/bin/node/buffer.js +9 -0
- package/bin/node/child_process.js +51 -3
- package/bin/node/cluster.js +41 -3
- package/bin/node/core.js +1 -1
- package/bin/node/crypto.js +205 -4
- package/bin/node/dgram.js +230 -6
- package/bin/node/dns.js +471 -8
- package/bin/node/errno_tables.js +445 -0
- package/bin/node/events.js +1 -1
- package/bin/node/fs.js +22 -15
- package/bin/node/fs_watch.js +407 -0
- package/bin/node/http.js +128 -30
- package/bin/node/http2.js +37 -7
- package/bin/node/module_v8.js +142 -0
- package/bin/node/net.js +9 -6
- package/bin/node/process.js +242 -0
- package/bin/node/readline.js +272 -1
- package/bin/node/registry.js +3 -1
- package/bin/node/sqlite.js +60 -12
- package/bin/node/stream.js +145 -10
- package/bin/node/test.js +311 -19
- package/bin/node/timers.js +1 -1
- package/bin/node/typed_arrays.js +608 -0
- package/bin/node/url.js +23 -5
- package/bin/node/util.js +21 -1
- package/bin/node/util_extra.js +6 -30
- package/bin/node/worker_threads.js +79 -19
- package/bin/node/zlib.js +131 -16
- package/bin/transpiler.js +4729 -616
- package/bin/typecheck-node.js +1 -0
- package/bin/version.js +1 -1
- package/conformance.md +1030 -877
- package/examples/README.md +54 -0
- package/examples/fibonacci/README.md +89 -0
- package/examples/fibonacci/bench.mjs +87 -0
- package/examples/fibonacci/main.ts +21 -0
- package/examples/hello-world/README.md +62 -0
- package/examples/hello-world/bench.mjs +66 -0
- package/examples/hello-world/main.ts +7 -0
- package/examples/json-server/README.md +127 -0
- package/examples/json-server/bench.mjs +263 -0
- package/examples/json-server/main.ts +67 -0
- package/govendor/github.com/andybalholm/brotli/LICENSE +19 -0
- package/govendor/github.com/andybalholm/brotli/README.md +19 -0
- package/govendor/github.com/andybalholm/brotli/backward_references.go +185 -0
- package/govendor/github.com/andybalholm/brotli/backward_references_hq.go +796 -0
- package/govendor/github.com/andybalholm/brotli/bit_cost.go +436 -0
- package/govendor/github.com/andybalholm/brotli/bit_reader.go +266 -0
- package/govendor/github.com/andybalholm/brotli/bitwriter.go +56 -0
- package/govendor/github.com/andybalholm/brotli/block_splitter.go +144 -0
- package/govendor/github.com/andybalholm/brotli/block_splitter_command.go +434 -0
- package/govendor/github.com/andybalholm/brotli/block_splitter_distance.go +433 -0
- package/govendor/github.com/andybalholm/brotli/block_splitter_literal.go +433 -0
- package/govendor/github.com/andybalholm/brotli/brotli_bit_stream.go +1435 -0
- package/govendor/github.com/andybalholm/brotli/cluster.go +30 -0
- package/govendor/github.com/andybalholm/brotli/cluster_command.go +164 -0
- package/govendor/github.com/andybalholm/brotli/cluster_distance.go +326 -0
- package/govendor/github.com/andybalholm/brotli/cluster_literal.go +326 -0
- package/govendor/github.com/andybalholm/brotli/command.go +254 -0
- package/govendor/github.com/andybalholm/brotli/compress_fragment.go +834 -0
- package/govendor/github.com/andybalholm/brotli/compress_fragment_two_pass.go +775 -0
- package/govendor/github.com/andybalholm/brotli/constants.go +77 -0
- package/govendor/github.com/andybalholm/brotli/context.go +2176 -0
- package/govendor/github.com/andybalholm/brotli/decode.go +2570 -0
- package/govendor/github.com/andybalholm/brotli/dictionary.go +122890 -0
- package/govendor/github.com/andybalholm/brotli/dictionary_hash.go +32779 -0
- package/govendor/github.com/andybalholm/brotli/encode.go +1220 -0
- package/govendor/github.com/andybalholm/brotli/encoder.go +177 -0
- package/govendor/github.com/andybalholm/brotli/encoder_dict.go +22 -0
- package/govendor/github.com/andybalholm/brotli/encoder_fast.go +201 -0
- package/govendor/github.com/andybalholm/brotli/entropy_encode.go +592 -0
- package/govendor/github.com/andybalholm/brotli/entropy_encode_static.go +4399 -0
- package/govendor/github.com/andybalholm/brotli/fast_log.go +290 -0
- package/govendor/github.com/andybalholm/brotli/find_match_length.go +45 -0
- package/govendor/github.com/andybalholm/brotli/go.mod +3 -0
- package/govendor/github.com/andybalholm/brotli/h10.go +287 -0
- package/govendor/github.com/andybalholm/brotli/h5.go +214 -0
- package/govendor/github.com/andybalholm/brotli/h6.go +216 -0
- package/govendor/github.com/andybalholm/brotli/hash.go +342 -0
- package/govendor/github.com/andybalholm/brotli/hash_composite.go +93 -0
- package/govendor/github.com/andybalholm/brotli/hash_forgetful_chain.go +252 -0
- package/govendor/github.com/andybalholm/brotli/hash_longest_match_quickly.go +214 -0
- package/govendor/github.com/andybalholm/brotli/hash_rolling.go +168 -0
- package/govendor/github.com/andybalholm/brotli/histogram.go +226 -0
- package/govendor/github.com/andybalholm/brotli/http.go +201 -0
- package/govendor/github.com/andybalholm/brotli/huffman.go +653 -0
- package/govendor/github.com/andybalholm/brotli/literal_cost.go +182 -0
- package/govendor/github.com/andybalholm/brotli/matchfinder/bargain1.go +212 -0
- package/govendor/github.com/andybalholm/brotli/matchfinder/bargain2.go +248 -0
- package/govendor/github.com/andybalholm/brotli/matchfinder/bargain3.go +278 -0
- package/govendor/github.com/andybalholm/brotli/matchfinder/emitter.go +34 -0
- package/govendor/github.com/andybalholm/brotli/matchfinder/m0.go +175 -0
- package/govendor/github.com/andybalholm/brotli/matchfinder/m4.go +339 -0
- package/govendor/github.com/andybalholm/brotli/matchfinder/matchfinder.go +103 -0
- package/govendor/github.com/andybalholm/brotli/matchfinder/pathfinder.go +328 -0
- package/govendor/github.com/andybalholm/brotli/matchfinder/textencoder.go +53 -0
- package/govendor/github.com/andybalholm/brotli/matchfinder/trio.go +327 -0
- package/govendor/github.com/andybalholm/brotli/matchfinder/zdfast.go +258 -0
- package/govendor/github.com/andybalholm/brotli/matchfinder/zfast.go +206 -0
- package/govendor/github.com/andybalholm/brotli/matchfinder/zm.go +302 -0
- package/govendor/github.com/andybalholm/brotli/memory.go +66 -0
- package/govendor/github.com/andybalholm/brotli/metablock.go +574 -0
- package/govendor/github.com/andybalholm/brotli/metablock_command.go +165 -0
- package/govendor/github.com/andybalholm/brotli/metablock_distance.go +165 -0
- package/govendor/github.com/andybalholm/brotli/metablock_literal.go +165 -0
- package/govendor/github.com/andybalholm/brotli/params.go +37 -0
- package/govendor/github.com/andybalholm/brotli/platform.go +103 -0
- package/govendor/github.com/andybalholm/brotli/prefix.go +30 -0
- package/govendor/github.com/andybalholm/brotli/prefix_dec.go +723 -0
- package/govendor/github.com/andybalholm/brotli/quality.go +196 -0
- package/govendor/github.com/andybalholm/brotli/reader.go +127 -0
- package/govendor/github.com/andybalholm/brotli/ringbuffer.go +134 -0
- package/govendor/github.com/andybalholm/brotli/state.go +313 -0
- package/govendor/github.com/andybalholm/brotli/static_dict.go +662 -0
- package/govendor/github.com/andybalholm/brotli/static_dict_lut.go +75094 -0
- package/govendor/github.com/andybalholm/brotli/symbol_list.go +22 -0
- package/govendor/github.com/andybalholm/brotli/transform.go +641 -0
- package/govendor/github.com/andybalholm/brotli/utf8_util.go +70 -0
- package/govendor/github.com/andybalholm/brotli/util.go +7 -0
- package/govendor/github.com/andybalholm/brotli/write_bits.go +52 -0
- package/govendor/github.com/andybalholm/brotli/writer.go +162 -0
- package/govendor/github.com/fsnotify/fsnotify/.mailmap +2 -0
- package/govendor/github.com/fsnotify/fsnotify/CHANGELOG.md +651 -0
- package/govendor/github.com/fsnotify/fsnotify/CONTRIBUTING.md +147 -0
- package/govendor/github.com/fsnotify/fsnotify/LICENSE +25 -0
- package/govendor/github.com/fsnotify/fsnotify/README.md +214 -0
- package/govendor/github.com/fsnotify/fsnotify/backend_fen.go +469 -0
- package/govendor/github.com/fsnotify/fsnotify/backend_inotify.go +597 -0
- package/govendor/github.com/fsnotify/fsnotify/backend_kqueue.go +735 -0
- package/govendor/github.com/fsnotify/fsnotify/backend_other.go +22 -0
- package/govendor/github.com/fsnotify/fsnotify/backend_windows.go +702 -0
- package/govendor/github.com/fsnotify/fsnotify/fsnotify.go +526 -0
- package/govendor/github.com/fsnotify/fsnotify/go.mod +3 -0
- package/govendor/github.com/fsnotify/fsnotify/internal/darwin.go +20 -0
- package/govendor/github.com/fsnotify/fsnotify/internal/debug_darwin.go +15 -0
- package/govendor/github.com/fsnotify/fsnotify/internal/debug_dragonfly.go +15 -0
- package/govendor/github.com/fsnotify/fsnotify/internal/debug_freebsd.go +20 -0
- package/govendor/github.com/fsnotify/fsnotify/internal/debug_kqueue.go +32 -0
- package/govendor/github.com/fsnotify/fsnotify/internal/debug_linux.go +56 -0
- package/govendor/github.com/fsnotify/fsnotify/internal/debug_netbsd.go +15 -0
- package/govendor/github.com/fsnotify/fsnotify/internal/debug_openbsd.go +16 -0
- package/govendor/github.com/fsnotify/fsnotify/internal/debug_solaris.go +45 -0
- package/govendor/github.com/fsnotify/fsnotify/internal/debug_windows.go +40 -0
- package/govendor/github.com/fsnotify/fsnotify/internal/freebsd.go +20 -0
- package/govendor/github.com/fsnotify/fsnotify/internal/internal.go +2 -0
- package/govendor/github.com/fsnotify/fsnotify/internal/unix.go +20 -0
- package/govendor/github.com/fsnotify/fsnotify/internal/unix2.go +25 -0
- package/govendor/github.com/fsnotify/fsnotify/internal/windows.go +40 -0
- package/govendor/github.com/fsnotify/fsnotify/shared.go +64 -0
- package/govendor/github.com/fsnotify/fsnotify/staticcheck.conf +3 -0
- package/govendor/github.com/fsnotify/fsnotify/system_bsd.go +7 -0
- package/govendor/github.com/fsnotify/fsnotify/system_darwin.go +8 -0
- package/govendor/manifest.txt +3 -1
- package/package.json +1 -1
- package/types/typenative-go.d.ts +23 -0
- package/types/typenative-npm.d.ts +241 -5
- package/types/typenative.d.ts +302 -12
package/bin/node/test.js
CHANGED
|
@@ -14,6 +14,7 @@ type TnTestNode struct {
|
|
|
14
14
|
skipMsg string
|
|
15
15
|
todo bool
|
|
16
16
|
todoMsg string
|
|
17
|
+
only bool
|
|
17
18
|
timeoutMs float64
|
|
18
19
|
parent *TnTestNode
|
|
19
20
|
children []*TnTestNode
|
|
@@ -37,6 +38,8 @@ var tnTestCurrent = tnTestRoot
|
|
|
37
38
|
var tnTestRunning *TnTestNode
|
|
38
39
|
var tnTestScheduled bool
|
|
39
40
|
var tnTestSpec bool
|
|
41
|
+
var tnTestTap bool
|
|
42
|
+
var tnTestReporter string
|
|
40
43
|
var tnTestColor bool
|
|
41
44
|
var tnTestStart time.Time
|
|
42
45
|
var tnTestCounts = map[string]int{}
|
|
@@ -145,6 +148,9 @@ func tnTestNew(suite bool, args []interface{}) *TnTestNode {
|
|
|
145
148
|
if ms, ok := TnGet(a, "timeout").(float64); ok {
|
|
146
149
|
n.timeoutMs = ms
|
|
147
150
|
}
|
|
151
|
+
if only, ok := TnGet(a, "only").(bool); ok {
|
|
152
|
+
n.only = only
|
|
153
|
+
}
|
|
148
154
|
}
|
|
149
155
|
}
|
|
150
156
|
return n
|
|
@@ -171,9 +177,16 @@ func TnTestRegister(variant string, args ...interface{}) chan struct{} {
|
|
|
171
177
|
n.skip = true
|
|
172
178
|
case "todo":
|
|
173
179
|
n.todo = true
|
|
180
|
+
case "only":
|
|
181
|
+
n.only = true
|
|
174
182
|
}
|
|
175
183
|
if tnTestRunning != nil && tnTestCurrent == tnTestRoot && tnTestRunning.ctx != nil {
|
|
176
184
|
n.parent = tnTestRunning
|
|
185
|
+
// subtests go through the same filters
|
|
186
|
+
if tnTestFilters().active() && !tnTestSelected(n) {
|
|
187
|
+
n.done <- struct{}{}
|
|
188
|
+
return n.done
|
|
189
|
+
}
|
|
177
190
|
tnTestRunning.children = append(tnTestRunning.children, n)
|
|
178
191
|
tnRunTestNode(n, tnTestDepth(n))
|
|
179
192
|
return n.done
|
|
@@ -192,6 +205,8 @@ func TnSuiteRegister(variant string, args ...interface{}) chan struct{} {
|
|
|
192
205
|
n.skip = true
|
|
193
206
|
case "todo":
|
|
194
207
|
n.todo = true
|
|
208
|
+
case "only":
|
|
209
|
+
n.only = true
|
|
195
210
|
}
|
|
196
211
|
n.parent = tnTestCurrent
|
|
197
212
|
tnTestCurrent.children = append(tnTestCurrent.children, n)
|
|
@@ -340,14 +355,174 @@ func tnTestAncestors(n *TnTestNode) []*TnTestNode {
|
|
|
340
355
|
return chain
|
|
341
356
|
}
|
|
342
357
|
|
|
358
|
+
// The test runner's flags, from NODE_OPTIONS as Node reads them:
|
|
359
|
+
// --test-name-pattern / --test-skip-pattern (repeatable, "/re/flags" or a
|
|
360
|
+
// plain regular expression), --test-only and --test-reporter
|
|
361
|
+
type tnTestConfig struct {
|
|
362
|
+
names []*regexp.Regexp
|
|
363
|
+
skips []*regexp.Regexp
|
|
364
|
+
only bool
|
|
365
|
+
reporter string
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
func (c *tnTestConfig) active() bool { return len(c.names) > 0 || len(c.skips) > 0 || c.only }
|
|
369
|
+
|
|
370
|
+
var tnTestCfg *tnTestConfig
|
|
371
|
+
|
|
372
|
+
// NODE_OPTIONS words: spaces separate them, double quotes group
|
|
373
|
+
func tnNodeOptionWords(s string) []string {
|
|
374
|
+
words := []string{}
|
|
375
|
+
cur := strings.Builder{}
|
|
376
|
+
inQuote, has := false, false
|
|
377
|
+
for _, r := range s {
|
|
378
|
+
switch {
|
|
379
|
+
case r == '"':
|
|
380
|
+
inQuote = !inQuote
|
|
381
|
+
has = true
|
|
382
|
+
case r == ' ' && !inQuote:
|
|
383
|
+
if has {
|
|
384
|
+
words = append(words, cur.String())
|
|
385
|
+
cur.Reset()
|
|
386
|
+
has = false
|
|
387
|
+
}
|
|
388
|
+
default:
|
|
389
|
+
cur.WriteRune(r)
|
|
390
|
+
has = true
|
|
391
|
+
}
|
|
392
|
+
}
|
|
393
|
+
if has {
|
|
394
|
+
words = append(words, cur.String())
|
|
395
|
+
}
|
|
396
|
+
return words
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
func tnTestPattern(s string) *regexp.Regexp {
|
|
400
|
+
if len(s) > 2 && s[0] == '/' {
|
|
401
|
+
if i := strings.LastIndexByte(s, '/'); i > 0 {
|
|
402
|
+
prefix := ""
|
|
403
|
+
if strings.Contains(s[i+1:], "i") {
|
|
404
|
+
prefix = "(?i)"
|
|
405
|
+
}
|
|
406
|
+
if re, err := regexp.Compile(prefix + s[1:i]); err == nil {
|
|
407
|
+
return re
|
|
408
|
+
}
|
|
409
|
+
}
|
|
410
|
+
}
|
|
411
|
+
re, err := regexp.Compile(s)
|
|
412
|
+
if err != nil {
|
|
413
|
+
return regexp.MustCompile(regexp.QuoteMeta(s))
|
|
414
|
+
}
|
|
415
|
+
return re
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
func tnTestFilters() *tnTestConfig {
|
|
419
|
+
if tnTestCfg != nil {
|
|
420
|
+
return tnTestCfg
|
|
421
|
+
}
|
|
422
|
+
c := &tnTestConfig{}
|
|
423
|
+
words := tnNodeOptionWords(os.Getenv("NODE_OPTIONS"))
|
|
424
|
+
for i := 0; i < len(words); i++ {
|
|
425
|
+
name, value, hasValue := strings.Cut(words[i], "=")
|
|
426
|
+
takesValue := name == "--test-name-pattern" || name == "--test-skip-pattern" || name == "--test-reporter"
|
|
427
|
+
if takesValue && !hasValue && i+1 < len(words) {
|
|
428
|
+
i++
|
|
429
|
+
value = words[i]
|
|
430
|
+
}
|
|
431
|
+
switch name {
|
|
432
|
+
case "--test-name-pattern":
|
|
433
|
+
c.names = append(c.names, tnTestPattern(value))
|
|
434
|
+
case "--test-skip-pattern":
|
|
435
|
+
c.skips = append(c.skips, tnTestPattern(value))
|
|
436
|
+
case "--test-only":
|
|
437
|
+
c.only = true
|
|
438
|
+
case "--test-reporter":
|
|
439
|
+
c.reporter = value
|
|
440
|
+
}
|
|
441
|
+
}
|
|
442
|
+
tnTestCfg = c
|
|
443
|
+
return c
|
|
444
|
+
}
|
|
445
|
+
|
|
446
|
+
// A pattern matches a test's name, an ancestor's, or the names joined with spaces
|
|
447
|
+
func tnTestNameMatches(n *TnTestNode, patterns []*regexp.Regexp) bool {
|
|
448
|
+
names := []string{}
|
|
449
|
+
for p := n; p != nil && p.parent != nil; p = p.parent {
|
|
450
|
+
for _, re := range patterns {
|
|
451
|
+
if re.MatchString(p.name) {
|
|
452
|
+
return true
|
|
453
|
+
}
|
|
454
|
+
}
|
|
455
|
+
names = append([]string{p.name}, names...)
|
|
456
|
+
}
|
|
457
|
+
full := strings.Join(names, " ")
|
|
458
|
+
for _, re := range patterns {
|
|
459
|
+
if re.MatchString(full) {
|
|
460
|
+
return true
|
|
461
|
+
}
|
|
462
|
+
}
|
|
463
|
+
return false
|
|
464
|
+
}
|
|
465
|
+
|
|
466
|
+
func tnTestSelected(n *TnTestNode) bool {
|
|
467
|
+
c := tnTestFilters()
|
|
468
|
+
if len(c.names) > 0 && !tnTestNameMatches(n, c.names) {
|
|
469
|
+
return false
|
|
470
|
+
}
|
|
471
|
+
if len(c.skips) > 0 && tnTestNameMatches(n, c.skips) {
|
|
472
|
+
return false
|
|
473
|
+
}
|
|
474
|
+
if c.only {
|
|
475
|
+
for p := n; p != nil; p = p.parent {
|
|
476
|
+
if p.only {
|
|
477
|
+
return true
|
|
478
|
+
}
|
|
479
|
+
}
|
|
480
|
+
return false
|
|
481
|
+
}
|
|
482
|
+
return true
|
|
483
|
+
}
|
|
484
|
+
|
|
485
|
+
// Drops the tests the filters leave out, and the suites left empty (Node
|
|
486
|
+
// does not report them)
|
|
487
|
+
func tnTestPrune(n *TnTestNode) bool {
|
|
488
|
+
kept := []*TnTestNode{}
|
|
489
|
+
for _, child := range n.children {
|
|
490
|
+
if child.suite {
|
|
491
|
+
if tnTestPrune(child) {
|
|
492
|
+
kept = append(kept, child)
|
|
493
|
+
}
|
|
494
|
+
} else if tnTestSelected(child) {
|
|
495
|
+
kept = append(kept, child)
|
|
496
|
+
}
|
|
497
|
+
}
|
|
498
|
+
n.children = kept
|
|
499
|
+
return len(kept) > 0
|
|
500
|
+
}
|
|
501
|
+
|
|
343
502
|
func tnRunRoot() {
|
|
344
503
|
tnTestStart = time.Now()
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
if
|
|
504
|
+
cfg := tnTestFilters()
|
|
505
|
+
tnTestReporter = cfg.reporter
|
|
506
|
+
if tnTestReporter != "spec" && tnTestReporter != "dot" && tnTestReporter != "junit" && tnTestReporter != "tap" {
|
|
507
|
+
tnTestReporter = "tap"
|
|
508
|
+
if TnIsTTY(os.Stdout) {
|
|
509
|
+
tnTestReporter = "spec"
|
|
510
|
+
}
|
|
511
|
+
}
|
|
512
|
+
tnTestSpec = tnTestReporter == "spec"
|
|
513
|
+
tnTestTap = tnTestReporter == "tap"
|
|
514
|
+
tnTestColor = (tnTestSpec || tnTestReporter == "dot") && TnIsTTY(os.Stdout) && os.Getenv("NO_COLOR") == ""
|
|
515
|
+
if tnTestTap {
|
|
348
516
|
fmt.Println("TAP version 13")
|
|
349
517
|
}
|
|
518
|
+
if tnTestReporter == "junit" {
|
|
519
|
+
fmt.Println("<?xml version=\\"1.0\\" encoding=\\"utf-8\\"?>")
|
|
520
|
+
fmt.Println("<testsuites>")
|
|
521
|
+
}
|
|
350
522
|
root := tnTestRoot
|
|
523
|
+
if cfg.active() {
|
|
524
|
+
tnTestPrune(root)
|
|
525
|
+
}
|
|
351
526
|
ctx := &TnTestContext{node: root}
|
|
352
527
|
failedHook := tnRunHooks(root.before, ctx)
|
|
353
528
|
for i := 0; i < len(root.children); i++ {
|
|
@@ -365,9 +540,13 @@ func tnRunTestNode(n *TnTestNode, depth int) {
|
|
|
365
540
|
n.started = true
|
|
366
541
|
tnTestShowParents(n)
|
|
367
542
|
indent := strings.Repeat(" ", depth)
|
|
368
|
-
if
|
|
543
|
+
if tnTestTap {
|
|
369
544
|
fmt.Println(indent + "# Subtest: " + n.name)
|
|
370
545
|
}
|
|
546
|
+
// .only without --test-only: Node's notice, as the test's diagnostic
|
|
547
|
+
if n.only && !tnTestFilters().only {
|
|
548
|
+
n.diagnostics = append(n.diagnostics, "'only' and 'runOnly' require the --test-only command-line option.")
|
|
549
|
+
}
|
|
371
550
|
start := time.Now()
|
|
372
551
|
ctx := &TnTestContext{node: n, mock: TnNewMockTracker(), signal: TnNewAbortSignal()}
|
|
373
552
|
n.ctx = ctx
|
|
@@ -548,9 +727,19 @@ func tnTestYamlString(s string, indent string) string {
|
|
|
548
727
|
}
|
|
549
728
|
|
|
550
729
|
func tnTestReport(n *TnTestNode, depth int) {
|
|
551
|
-
|
|
730
|
+
switch tnTestReporter {
|
|
731
|
+
case "spec":
|
|
552
732
|
tnTestReportSpec(n, depth)
|
|
553
733
|
return
|
|
734
|
+
case "dot":
|
|
735
|
+
mark := "."
|
|
736
|
+
if n.status == "fail" {
|
|
737
|
+
mark = tnTestColorize("31", "X")
|
|
738
|
+
}
|
|
739
|
+
fmt.Print(mark)
|
|
740
|
+
return
|
|
741
|
+
case "junit":
|
|
742
|
+
return
|
|
554
743
|
}
|
|
555
744
|
indent := strings.Repeat(" ", depth)
|
|
556
745
|
if len(n.children) > 0 {
|
|
@@ -650,9 +839,117 @@ func tnTestReportSpec(n *TnTestNode, depth int) {
|
|
|
650
839
|
}
|
|
651
840
|
}
|
|
652
841
|
|
|
842
|
+
// dot: the failures after the line of dots, in the spec reporter's format
|
|
843
|
+
func tnTestFailureLines(n *TnTestNode) {
|
|
844
|
+
fmt.Println("\\n" + tnTestColorize("31", "\\u2716 "+n.name+" ("+tnTestDuration(n.duration)+"ms)"))
|
|
845
|
+
name := TnJSString(tnTestErrorField(n.err, "name"))
|
|
846
|
+
head := name
|
|
847
|
+
if code, ok := tnTestErrorField(n.err, "code").(string); ok && code != "" {
|
|
848
|
+
head += " [" + code + "]"
|
|
849
|
+
}
|
|
850
|
+
for _, l := range strings.Split(head+": "+TnJSString(tnTestErrorField(n.err, "message")), "\\n") {
|
|
851
|
+
fmt.Println(" " + l)
|
|
852
|
+
}
|
|
853
|
+
}
|
|
854
|
+
|
|
855
|
+
func tnXMLEscape(s string, attr bool) string {
|
|
856
|
+
s = strings.ReplaceAll(s, "&", "&")
|
|
857
|
+
s = strings.ReplaceAll(s, "<", "<")
|
|
858
|
+
if attr {
|
|
859
|
+
s = strings.ReplaceAll(s, "\\"", """)
|
|
860
|
+
s = strings.ReplaceAll(s, "\\n", "")
|
|
861
|
+
}
|
|
862
|
+
return s
|
|
863
|
+
}
|
|
864
|
+
|
|
865
|
+
// junit: Node's layout (testcase / testsuite elements, diagnostics and the
|
|
866
|
+
// counters as comments); failure bodies show the error, without a stack
|
|
867
|
+
func tnTestJunit(n *TnTestNode, depth int) {
|
|
868
|
+
indent := strings.Repeat("\\t", depth+1)
|
|
869
|
+
dur := strconv.FormatFloat(n.duration/1000, 'f', 6, 64)
|
|
870
|
+
if n.suite {
|
|
871
|
+
tests, failures, skipped := 0, 0, 0
|
|
872
|
+
for _, c := range n.children {
|
|
873
|
+
if !c.suite {
|
|
874
|
+
tests++
|
|
875
|
+
if c.status == "fail" {
|
|
876
|
+
failures++
|
|
877
|
+
}
|
|
878
|
+
if c.status == "skip" || c.status == "todo" {
|
|
879
|
+
skipped++
|
|
880
|
+
}
|
|
881
|
+
}
|
|
882
|
+
}
|
|
883
|
+
host, _ := os.Hostname()
|
|
884
|
+
fmt.Printf("%s<testsuite name=\\"%s\\" time=\\"%s\\" disabled=\\"0\\" errors=\\"0\\" tests=\\"%d\\" failures=\\"%d\\" skipped=\\"%d\\" hostname=\\"%s\\">\\n", indent, tnXMLEscape(n.name, true), dur, tests, failures, skipped, tnXMLEscape(host, true))
|
|
885
|
+
for _, c := range n.children {
|
|
886
|
+
tnTestJunit(c, depth+1)
|
|
887
|
+
}
|
|
888
|
+
fmt.Println(indent + "</testsuite>")
|
|
889
|
+
} else {
|
|
890
|
+
open := fmt.Sprintf("%s<testcase name=\\"%s\\" time=\\"%s\\" classname=\\"test\\"", indent, tnXMLEscape(n.name, true), dur)
|
|
891
|
+
switch {
|
|
892
|
+
case n.status == "fail":
|
|
893
|
+
msg := tnXMLEscape(TnJSString(tnTestErrorField(n.err, "message")), true)
|
|
894
|
+
fmt.Printf("%s failure=\\"%s\\">\\n", open, msg)
|
|
895
|
+
fmt.Printf("%s\\t<failure type=\\"%s\\" message=\\"%s\\">\\n", indent, n.failureType, msg)
|
|
896
|
+
// Node wraps the error in an ERR_TEST_FAILURE whose cause it is
|
|
897
|
+
cause := strings.ReplaceAll(TnInspect(n.err), "\\n", "\\n ")
|
|
898
|
+
raw := strings.TrimSuffix(TnJSString(tnTestErrorField(n.err, "message")), "\\n")
|
|
899
|
+
fmt.Println(tnXMLEscape("[Error [ERR_TEST_FAILURE]: "+raw+"\\n] {\\n code: 'ERR_TEST_FAILURE',\\n failureType: '"+n.failureType+"',\\n cause: "+cause+"\\n}", false))
|
|
900
|
+
fmt.Println(indent + "\\t</failure>")
|
|
901
|
+
fmt.Println(indent + "</testcase>")
|
|
902
|
+
case n.status == "skip" || n.status == "todo":
|
|
903
|
+
kind := "skipped"
|
|
904
|
+
msg := n.skipMsg
|
|
905
|
+
if n.status == "todo" {
|
|
906
|
+
kind, msg = "todo", n.todoMsg
|
|
907
|
+
}
|
|
908
|
+
if msg == "" {
|
|
909
|
+
msg = "true"
|
|
910
|
+
}
|
|
911
|
+
fmt.Println(open + ">")
|
|
912
|
+
fmt.Printf("%s\\t<skipped type=\\"%s\\" message=\\"%s\\"/>\\n", indent, kind, tnXMLEscape(msg, true))
|
|
913
|
+
fmt.Println(indent + "</testcase>")
|
|
914
|
+
default:
|
|
915
|
+
fmt.Println(open + "/>")
|
|
916
|
+
}
|
|
917
|
+
for _, c := range n.children {
|
|
918
|
+
tnTestJunit(c, depth+1)
|
|
919
|
+
}
|
|
920
|
+
}
|
|
921
|
+
for _, d := range n.diagnostics {
|
|
922
|
+
fmt.Println(indent + "<!-- " + d + " -->")
|
|
923
|
+
}
|
|
924
|
+
}
|
|
925
|
+
|
|
653
926
|
func tnTestFinish() {
|
|
654
927
|
stats := []string{"tests", "suites", "pass", "fail", "cancelled", "skipped", "todo"}
|
|
655
|
-
|
|
928
|
+
duration := "duration_ms " + tnTestDuration(float64(time.Since(tnTestStart).Nanoseconds())/1e6)
|
|
929
|
+
switch tnTestReporter {
|
|
930
|
+
case "dot":
|
|
931
|
+
fmt.Println()
|
|
932
|
+
if len(tnTestFailures) > 0 {
|
|
933
|
+
fmt.Println("\\n" + tnTestColorize("31", "Failed tests:"))
|
|
934
|
+
for _, n := range tnTestFailures {
|
|
935
|
+
tnTestFailureLines(n)
|
|
936
|
+
}
|
|
937
|
+
}
|
|
938
|
+
tnTestExitCode()
|
|
939
|
+
return
|
|
940
|
+
case "junit":
|
|
941
|
+
for _, n := range tnTestRoot.children {
|
|
942
|
+
tnTestJunit(n, 0)
|
|
943
|
+
}
|
|
944
|
+
for _, key := range stats {
|
|
945
|
+
fmt.Println("\\t<!-- " + key + " " + strconv.Itoa(tnTestCounts[key]) + " -->")
|
|
946
|
+
}
|
|
947
|
+
fmt.Println("\\t<!-- " + duration + " -->")
|
|
948
|
+
fmt.Println("</testsuites>")
|
|
949
|
+
tnTestExitCode()
|
|
950
|
+
return
|
|
951
|
+
}
|
|
952
|
+
if tnTestTap {
|
|
656
953
|
fmt.Println("1.." + strconv.Itoa(len(tnTestRoot.children)))
|
|
657
954
|
}
|
|
658
955
|
for _, key := range stats {
|
|
@@ -663,26 +960,21 @@ func tnTestFinish() {
|
|
|
663
960
|
fmt.Println("# " + line)
|
|
664
961
|
}
|
|
665
962
|
}
|
|
666
|
-
duration := "duration_ms " + tnTestDuration(float64(time.Since(tnTestStart).Nanoseconds())/1e6)
|
|
667
963
|
if tnTestSpec {
|
|
668
964
|
fmt.Println(tnTestColorize("34", "\\u2139 "+duration))
|
|
669
965
|
if len(tnTestFailures) > 0 {
|
|
670
966
|
fmt.Println("\\n" + tnTestColorize("31", "\\u2716 failing tests:"))
|
|
671
967
|
for _, n := range tnTestFailures {
|
|
672
|
-
|
|
673
|
-
name := TnJSString(tnTestErrorField(n.err, "name"))
|
|
674
|
-
head := name
|
|
675
|
-
if code, ok := tnTestErrorField(n.err, "code").(string); ok && code != "" {
|
|
676
|
-
head += " [" + code + "]"
|
|
677
|
-
}
|
|
678
|
-
for _, l := range strings.Split(head+": "+TnJSString(tnTestErrorField(n.err, "message")), "\\n") {
|
|
679
|
-
fmt.Println(" " + l)
|
|
680
|
-
}
|
|
968
|
+
tnTestFailureLines(n)
|
|
681
969
|
}
|
|
682
970
|
}
|
|
683
971
|
} else {
|
|
684
972
|
fmt.Println("# " + duration)
|
|
685
973
|
}
|
|
974
|
+
tnTestExitCode()
|
|
975
|
+
}
|
|
976
|
+
|
|
977
|
+
func tnTestExitCode() {
|
|
686
978
|
if tnTestCounts["fail"] > 0 || tnTestCounts["cancelled"] > 0 {
|
|
687
979
|
TnSetExitCode(1)
|
|
688
980
|
}
|
|
@@ -972,7 +1264,7 @@ function eventFn(nodes) {
|
|
|
972
1264
|
}
|
|
973
1265
|
export function registerTest(r) {
|
|
974
1266
|
defineModule(r, 'test');
|
|
975
|
-
defineHelper(r, 'nodeTest', ['fmt', 'math', 'os', 'reflect', 'strconv', 'strings', 'time'], ['eventLoop', 'promise', 'nodeInvoke', 'dynamic', 'nodeEvents', 'nodeProcess', 'nodeUtil', 'error', 'timerWait', 'clock'], testHelper);
|
|
1267
|
+
defineHelper(r, 'nodeTest', ['fmt', 'math', 'os', 'reflect', 'regexp', 'strconv', 'strings', 'time'], ['eventLoop', 'promise', 'nodeInvoke', 'dynamic', 'nodeEvents', 'nodeProcess', 'nodeUtil', 'error', 'timerWait', 'clock'], testHelper);
|
|
976
1268
|
const use = () => r.helper('nodeTest');
|
|
977
1269
|
defineClass(r, 'test.TestContext', '*TnTestContext', 'class', 'skip=; todo=; diagnostic=; plan=; runOnly=; test=chan struct{}; before=; after=; beforeEach=; afterEach=', '', 'name=string; fullName=string; mock=*TnMockTracker; signal=*TnAbortSignal; filePath=string; assert=*TnTestAssert', '');
|
|
978
1270
|
r.classes['test.SuiteContext'] = r.classes['test.TestContext'];
|
|
@@ -1011,13 +1303,13 @@ export function registerTest(r) {
|
|
|
1011
1303
|
register(name, 'TnTestRegister', '');
|
|
1012
1304
|
register(`${name}.skip`, 'TnTestRegister', 'skip');
|
|
1013
1305
|
register(`${name}.todo`, 'TnTestRegister', 'todo');
|
|
1014
|
-
register(`${name}.only`, 'TnTestRegister', '');
|
|
1306
|
+
register(`${name}.only`, 'TnTestRegister', 'only');
|
|
1015
1307
|
}
|
|
1016
1308
|
for (const name of ['describe', 'suite']) {
|
|
1017
1309
|
register(name, 'TnSuiteRegister', '');
|
|
1018
1310
|
register(`${name}.skip`, 'TnSuiteRegister', 'skip');
|
|
1019
1311
|
register(`${name}.todo`, 'TnSuiteRegister', 'todo');
|
|
1020
|
-
register(`${name}.only`, 'TnSuiteRegister', '');
|
|
1312
|
+
register(`${name}.only`, 'TnSuiteRegister', 'only');
|
|
1021
1313
|
}
|
|
1022
1314
|
for (const variant of ['', '.skip', '.todo', '.only']) {
|
|
1023
1315
|
r.functions[`test.default${variant}`] = r.functions[`test.test${variant}`];
|
package/bin/node/timers.js
CHANGED