typenative 0.4.1 → 0.6.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/.github/workflows/ci.yml +2 -2
- package/.github/workflows/npm-publish-github-packages.yml +2 -2
- package/CHANGELOG.md +442 -1
- package/CONTRIBUTION.md +2 -1
- package/README.md +73 -25
- package/bin/cli.js +2 -0
- package/bin/index.js +75 -5
- package/bin/main.js +2 -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/core.js +41 -0
- 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 +18 -13
- 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 +47 -11
- package/bin/node/punycode.js +2 -2
- 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 +8 -6
- package/bin/node/tls.js +5 -5
- package/bin/node/url.js +1 -1
- 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 +6 -2
- package/bin/regex_vm.js +2057 -0
- package/bin/transpiler.js +32872 -11265
- package/bin/typecheck-node.js +2 -1
- package/bin/version.js +1 -1
- package/conformance.md +515 -345
- package/examples/README.md +71 -11
- package/examples/angular-templates/README.md +139 -0
- package/examples/angular-templates/bench.mjs +173 -0
- package/examples/angular-templates/dom-type-globals.d.ts +21 -0
- package/examples/angular-templates/dom-type-stubs.ts +21 -0
- package/examples/angular-templates/main.ts +135 -0
- package/examples/angular-templates/parity.mjs +157 -0
- package/examples/angular-templates/run-node.mjs +69 -0
- package/examples/angular-templates/vendor/angular/compiler/LICENSE +21 -0
- package/examples/desktop-notes/README.md +106 -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 +78 -0
- package/examples/dupe-finder/bench.mjs +120 -0
- package/examples/dupe-finder/main.ts +87 -0
- package/examples/fibonacci/README.md +7 -7
- package/examples/hello-world/README.md +6 -6
- package/examples/json-server/README.md +19 -18
- package/examples/mandelbrot-png/README.md +63 -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 +160 -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/openai-chat/README.md +148 -0
- package/examples/openai-chat/bench.mjs +175 -0
- package/examples/openai-chat/main.ts +488 -0
- package/examples/react-compiler/README.md +170 -0
- package/examples/react-compiler/bench.mjs +181 -0
- package/examples/react-compiler/main.ts +158 -0
- package/examples/react-compiler/parity.mjs +362 -0
- package/examples/react-compiler/run-node.mjs +88 -0
- package/examples/react-compiler/vendor/babel/LICENSE +22 -0
- package/examples/react-compiler/vendor/babel/helper-globals/data/builtin-lower.json +15 -0
- package/examples/react-compiler/vendor/babel/helper-globals/data/builtin-upper.json +51 -0
- package/examples/react-compiler/vendor/charcodes/package.json +25 -0
- package/examples/react-compiler/vendor/invariant/LICENSE +21 -0
- package/examples/react-compiler/vendor/invariant/invariant.cjs +51 -0
- package/examples/react-compiler/vendor/invariant/invariant.d.cts +11 -0
- package/examples/react-compiler/vendor/invariant/types/LICENSE +21 -0
- package/examples/react-compiler/vendor/jridgewell/gen-mapping/LICENSE +19 -0
- package/examples/react-compiler/vendor/jridgewell/resolve-uri/LICENSE +19 -0
- package/examples/react-compiler/vendor/jridgewell/sourcemap-codec/LICENSE +19 -0
- package/examples/react-compiler/vendor/jridgewell/trace-mapping/LICENSE +19 -0
- package/examples/react-compiler/vendor/js-tokens/LICENSE +21 -0
- package/examples/react-compiler/vendor/js-tokens/index.cjs +23 -0
- package/examples/react-compiler/vendor/js-tokens/index.d.cts +13 -0
- package/examples/react-compiler/vendor/jsesc/LICENSE-MIT.txt +20 -0
- package/examples/react-compiler/vendor/jsesc/jsesc.cjs +337 -0
- package/examples/react-compiler/vendor/jsesc/jsesc.d.cts +384 -0
- package/examples/react-compiler/vendor/jsesc/types/LICENSE +21 -0
- package/examples/react-compiler/vendor/picocolors/LICENSE +15 -0
- package/examples/react-compiler/vendor/picocolors/picocolors.cjs +75 -0
- package/examples/react-compiler/vendor/picocolors/picocolors.d.cts +5 -0
- package/examples/react-compiler/vendor/picocolors/types.d.ts +51 -0
- package/examples/react-compiler/vendor/react-compiler/LICENSE +21 -0
- package/examples/react-compiler/vendor/stubs/babel-core.ts +31 -0
- package/examples/react-compiler/vendor/stubs/debug.ts +18 -0
- package/examples/react-compiler/vendor/stubs/js-tokens.d.ts +13 -0
- package/examples/react-compiler/vendor/stubs/pretty-format.ts +18 -0
- package/examples/react-compiler/vendor/zod/LICENSE +21 -0
- package/examples/react-compiler/vendor/zod-validation-error/LICENSE +9 -0
- package/examples/react-compiler/vendor/zod-validation-error/lib/utils/NonEmptyArray.ts +5 -0
- package/examples/react-compiler/vendor/zod-validation-error/lib/utils/joinPath.ts +49 -0
- package/examples/react-compiler/vendor/zod-validation-error/lib/utils/joinValues.ts +48 -0
- package/examples/react-compiler/vendor/zod-validation-error/lib/utils/stringify.ts +50 -0
- package/examples/react-compiler/vendor/zod-validation-error/lib/utils/titleCase.ts +6 -0
- package/examples/react-compiler/vendor/zod-validation-error/lib/v4/MessageBuilder.ts +126 -0
- package/examples/react-compiler/vendor/zod-validation-error/lib/v4/ValidationError.ts +39 -0
- package/examples/react-compiler/vendor/zod-validation-error/lib/v4/errorMap/custom.ts +12 -0
- package/examples/react-compiler/vendor/zod-validation-error/lib/v4/errorMap/errorMap.ts +78 -0
- package/examples/react-compiler/vendor/zod-validation-error/lib/v4/errorMap/index.ts +2 -0
- package/examples/react-compiler/vendor/zod-validation-error/lib/v4/errorMap/invalidElement.ts +12 -0
- package/examples/react-compiler/vendor/zod-validation-error/lib/v4/errorMap/invalidKey.ts +12 -0
- package/examples/react-compiler/vendor/zod-validation-error/lib/v4/errorMap/invalidStringFormat.ts +131 -0
- package/examples/react-compiler/vendor/zod-validation-error/lib/v4/errorMap/invalidType.ts +54 -0
- package/examples/react-compiler/vendor/zod-validation-error/lib/v4/errorMap/invalidUnion.ts +12 -0
- package/examples/react-compiler/vendor/zod-validation-error/lib/v4/errorMap/invalidValue.ts +40 -0
- package/examples/react-compiler/vendor/zod-validation-error/lib/v4/errorMap/notMultipleOf.ts +12 -0
- package/examples/react-compiler/vendor/zod-validation-error/lib/v4/errorMap/tooBig.ts +76 -0
- package/examples/react-compiler/vendor/zod-validation-error/lib/v4/errorMap/tooSmall.ts +76 -0
- package/examples/react-compiler/vendor/zod-validation-error/lib/v4/errorMap/types.ts +27 -0
- package/examples/react-compiler/vendor/zod-validation-error/lib/v4/errorMap/unrecognizedKeys.ts +27 -0
- package/examples/react-compiler/vendor/zod-validation-error/lib/v4/fromError.ts +13 -0
- package/examples/react-compiler/vendor/zod-validation-error/lib/v4/fromZodError.ts +61 -0
- package/examples/react-compiler/vendor/zod-validation-error/lib/v4/fromZodIssue.ts +38 -0
- package/examples/react-compiler/vendor/zod-validation-error/lib/v4/index.ts +20 -0
- package/examples/react-compiler/vendor/zod-validation-error/lib/v4/isValidationError.ts +5 -0
- package/examples/react-compiler/vendor/zod-validation-error/lib/v4/isValidationErrorLike.ts +8 -0
- package/examples/react-compiler/vendor/zod-validation-error/lib/v4/isZodErrorLike.ts +11 -0
- package/examples/react-compiler/vendor/zod-validation-error/lib/v4/toValidationError.ts +20 -0
- package/examples/react-compiler/vendor.mjs +688 -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 +146 -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 +8 -5
- package/performance/README.md +195 -0
- package/performance/any-dynamic.ts +21 -0
- package/performance/any-record-view.ts +20 -0
- package/performance/arr-hof.ts +21 -0
- package/performance/arr-push-index.ts +15 -0
- package/performance/arr-sort.ts +21 -0
- package/performance/async-await.ts +24 -0
- package/performance/class-dispatch.ts +52 -0
- package/performance/events-emit.ts +27 -0
- package/performance/exc-throw-rare.ts +25 -0
- package/performance/exc-try-catch.ts +26 -0
- package/performance/fn-closures.ts +29 -0
- package/performance/fn-recursion-tree.ts +31 -0
- package/performance/gen-for-of.ts +46 -0
- package/performance/json-roundtrip.ts +27 -0
- package/performance/map-delete.ts +24 -0
- package/performance/map-string-keys.ts +22 -0
- package/performance/num-arith-loop.ts +14 -0
- package/performance/num-bitwise.ts +21 -0
- package/performance/num-mod-int.ts +16 -0
- package/performance/num-to-string.ts +16 -0
- package/performance/obj-alloc.ts +32 -0
- package/performance/regex-exec.ts +29 -0
- package/performance/regex-site.ts +28 -0
- package/performance/set-ops.ts +20 -0
- package/performance/str-char-scan.ts +35 -0
- package/performance/str-concat-plus.ts +18 -0
- package/performance/str-concat.ts +24 -0
- package/performance/str-short-scan.ts +26 -0
- package/performance/str-split-join.ts +23 -0
- package/performance/str-template.ts +16 -0
- package/performance/union-switch.ts +57 -0
- package/tsparser/check.go +2 -1
- package/tsparser/main.go +5 -0
- package/types/typenative-npm.d.ts +193 -4
- package/types/typenative.d.ts +138 -41
|
@@ -0,0 +1,575 @@
|
|
|
1
|
+
// node:test run({ files }): each file is compiled into the program as a
|
|
2
|
+
// second entry point (like a Worker's file) and runs in a child process,
|
|
3
|
+
// whose runner sends its events back as frames on stdout. The parent relays
|
|
4
|
+
// them on a TestsStream (an object-mode Readable that also emits each event
|
|
5
|
+
// by type), renumbering top-level tests across files, and adds the totals
|
|
6
|
+
// at the end, as Node's run() does. Other child output becomes test:stdout /
|
|
7
|
+
// test:stderr events.
|
|
8
|
+
import { defineHelper, getOption, isObjectLiteral } from './registry.js';
|
|
9
|
+
const runHelper = `// node:test run()
|
|
10
|
+
const tnTestFrame = "\\x00tn-test "
|
|
11
|
+
|
|
12
|
+
// A child started by run(): its runner writes events instead of reports
|
|
13
|
+
func init() {
|
|
14
|
+
if os.Getenv("NODE_TEST_CONTEXT") == "child-tn" {
|
|
15
|
+
os.Unsetenv("NODE_TEST_CONTEXT")
|
|
16
|
+
tnTestChildSink = tnTestWriteFrame
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
func tnTestWriteFrame(e *TnTestEvent) {
|
|
21
|
+
var payload interface{}
|
|
22
|
+
func() {
|
|
23
|
+
defer func() {
|
|
24
|
+
// a value that can't be cloned (a function): the error as text
|
|
25
|
+
if recover() != nil && e.data.details != nil {
|
|
26
|
+
details := *e.data.details
|
|
27
|
+
details.error_ = tnTestFailure(tnTestInspectError(details.error_), "testCodeFailure")
|
|
28
|
+
data := *e.data
|
|
29
|
+
data.details = &details
|
|
30
|
+
payload = tnCloneEncode(&TnTestEvent{type_: e.type_, data: &data})
|
|
31
|
+
}
|
|
32
|
+
}()
|
|
33
|
+
payload = tnCloneEncode(e)
|
|
34
|
+
}()
|
|
35
|
+
b, err := json.Marshal(payload)
|
|
36
|
+
if err != nil {
|
|
37
|
+
return
|
|
38
|
+
}
|
|
39
|
+
os.Stdout.Write(append(append([]byte(tnTestFrame), b...), '\\n'))
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
type tnTestRunFile struct {
|
|
43
|
+
entry string
|
|
44
|
+
path string
|
|
45
|
+
// events held back while an earlier file is still reporting
|
|
46
|
+
held []*TnTestEvent
|
|
47
|
+
finished bool
|
|
48
|
+
summary *TnTestEventData
|
|
49
|
+
start time.Time
|
|
50
|
+
exitCode int
|
|
51
|
+
signal string
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
type tnTestRun struct {
|
|
55
|
+
stream *TnStream
|
|
56
|
+
files []*tnTestRunFile
|
|
57
|
+
next int
|
|
58
|
+
reporting int
|
|
59
|
+
running int
|
|
60
|
+
concurrency int
|
|
61
|
+
options interface{}
|
|
62
|
+
topLevel float64
|
|
63
|
+
counts TnTestCounts
|
|
64
|
+
coverage []*TnCoverageSummary
|
|
65
|
+
start time.Time
|
|
66
|
+
success bool
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
// run(options): files pairs each entry id with the file's path
|
|
70
|
+
func TnTestRun(options interface{}, files ...[]string) *TnStream {
|
|
71
|
+
s := TnNewReadable()
|
|
72
|
+
s.objectMode = true
|
|
73
|
+
r := &tnTestRun{stream: s, options: options, concurrency: 1, success: true}
|
|
74
|
+
for _, f := range files {
|
|
75
|
+
r.files = append(r.files, &tnTestRunFile{entry: f[0], path: f[1]})
|
|
76
|
+
}
|
|
77
|
+
if options != nil {
|
|
78
|
+
switch c := TnGetValue(options, "concurrency").(type) {
|
|
79
|
+
case float64:
|
|
80
|
+
if c > 1 {
|
|
81
|
+
r.concurrency = int(c)
|
|
82
|
+
}
|
|
83
|
+
case bool:
|
|
84
|
+
if c {
|
|
85
|
+
r.concurrency = runtime.NumCPU() - 1
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
if r.concurrency < 1 {
|
|
90
|
+
r.concurrency = 1
|
|
91
|
+
}
|
|
92
|
+
TnLoopRef()
|
|
93
|
+
TnLoopPost(func() {
|
|
94
|
+
if options != nil {
|
|
95
|
+
if setup := TnGet(options, "setup"); tnTestIsFunc(setup) {
|
|
96
|
+
TnInvoke(setup, s)
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
r.start = time.Now()
|
|
100
|
+
r.fill()
|
|
101
|
+
})
|
|
102
|
+
return s
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
func (r *tnTestRun) emit(e *TnTestEvent) {
|
|
106
|
+
r.stream.push(e)
|
|
107
|
+
r.stream.emit(e.type_, e.data)
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
func tnTestRunPatterns(v interface{}) []string {
|
|
111
|
+
out := []string{}
|
|
112
|
+
add := func(p interface{}) {
|
|
113
|
+
switch x := p.(type) {
|
|
114
|
+
case string:
|
|
115
|
+
out = append(out, x)
|
|
116
|
+
case *regexp.Regexp:
|
|
117
|
+
out = append(out, x.String())
|
|
118
|
+
default:
|
|
119
|
+
if p != nil {
|
|
120
|
+
out = append(out, TnJSString(p))
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
if list := tnTestList(v); list != nil {
|
|
125
|
+
for _, p := range list {
|
|
126
|
+
add(p)
|
|
127
|
+
}
|
|
128
|
+
} else {
|
|
129
|
+
add(v)
|
|
130
|
+
}
|
|
131
|
+
return out
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
func tnTestOptionWord(flag string, value string) string {
|
|
135
|
+
if strings.ContainsAny(value, " \\"") {
|
|
136
|
+
return flag + "=\\"" + strings.ReplaceAll(value, "\\"", "") + "\\""
|
|
137
|
+
}
|
|
138
|
+
return flag + "=" + value
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
// The NODE_OPTIONS a child runs with: run()'s filters and coverage
|
|
142
|
+
func (r *tnTestRun) childOptions() string {
|
|
143
|
+
words := []string{}
|
|
144
|
+
if r.options == nil {
|
|
145
|
+
return ""
|
|
146
|
+
}
|
|
147
|
+
for _, p := range tnTestRunPatterns(TnGet(r.options, "testNamePatterns")) {
|
|
148
|
+
words = append(words, tnTestOptionWord("--test-name-pattern", p))
|
|
149
|
+
}
|
|
150
|
+
for _, p := range tnTestRunPatterns(TnGet(r.options, "testSkipPatterns")) {
|
|
151
|
+
words = append(words, tnTestOptionWord("--test-skip-pattern", p))
|
|
152
|
+
}
|
|
153
|
+
if only, _ := TnGetValue(r.options, "only").(bool); only {
|
|
154
|
+
words = append(words, "--test-only")
|
|
155
|
+
}
|
|
156
|
+
if coverage, _ := TnGetValue(r.options, "coverage").(bool); coverage {
|
|
157
|
+
words = append(words, "--experimental-test-coverage")
|
|
158
|
+
}
|
|
159
|
+
if update, _ := TnGetValue(r.options, "updateSnapshots").(bool); update || tnTestFilters().updateSnapshots {
|
|
160
|
+
words = append(words, "--test-update-snapshots")
|
|
161
|
+
}
|
|
162
|
+
return strings.Join(words, " ")
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
// Starts files until concurrency children run
|
|
166
|
+
func (r *tnTestRun) fill() {
|
|
167
|
+
for r.running < r.concurrency && r.next < len(r.files) {
|
|
168
|
+
f := r.files[r.next]
|
|
169
|
+
r.next++
|
|
170
|
+
r.running++
|
|
171
|
+
r.startFile(f)
|
|
172
|
+
}
|
|
173
|
+
if r.running == 0 && r.next >= len(r.files) {
|
|
174
|
+
r.finish()
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
// Events of the file reporting now are relayed at once; later files' wait
|
|
179
|
+
func (r *tnTestRun) deliver(f *tnTestRunFile, e *TnTestEvent) {
|
|
180
|
+
if r.reporting < len(r.files) && r.files[r.reporting] == f {
|
|
181
|
+
r.relay(f, e)
|
|
182
|
+
return
|
|
183
|
+
}
|
|
184
|
+
f.held = append(f.held, e)
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
func (r *tnTestRun) relay(f *tnTestRunFile, e *TnTestEvent) {
|
|
188
|
+
d := e.data
|
|
189
|
+
switch e.type_ {
|
|
190
|
+
case "test:summary":
|
|
191
|
+
f.summary = d
|
|
192
|
+
return
|
|
193
|
+
case "test:coverage":
|
|
194
|
+
if d.summary != nil {
|
|
195
|
+
r.coverage = append(r.coverage, d.summary)
|
|
196
|
+
}
|
|
197
|
+
return
|
|
198
|
+
case "test:pass", "test:fail":
|
|
199
|
+
if d.nesting == 0 {
|
|
200
|
+
r.topLevel++
|
|
201
|
+
d.testNumber = r.topLevel
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
if d.file == "" && (e.type_ == "test:stdout" || e.type_ == "test:stderr") {
|
|
205
|
+
d.file = f.path
|
|
206
|
+
}
|
|
207
|
+
r.emit(e)
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
func (r *tnTestRun) startFile(f *tnTestRunFile) {
|
|
211
|
+
f.path, _ = filepath.Abs(f.path)
|
|
212
|
+
f.start = time.Now()
|
|
213
|
+
r.emit(&TnTestEvent{type_: "test:enqueue", data: &TnTestEventData{name: f.path, file: f.path, line: 1, column: 1}})
|
|
214
|
+
if f.entry == "" {
|
|
215
|
+
// not a literal path in run({ files }): it wasn't compiled into the program
|
|
216
|
+
f.finished = true
|
|
217
|
+
f.held = append(f.held, &TnTestEvent{type_: "test:stderr", data: &TnTestEventData{file: f.path, message: "run(): " + f.path + " is not compiled into this program (files need literal paths)\\n"}})
|
|
218
|
+
r.fileDone(f, 1, "")
|
|
219
|
+
return
|
|
220
|
+
}
|
|
221
|
+
exe, err := os.Executable()
|
|
222
|
+
if err != nil {
|
|
223
|
+
exe = os.Args[0]
|
|
224
|
+
}
|
|
225
|
+
args := []string{}
|
|
226
|
+
if r.options != nil {
|
|
227
|
+
for _, a := range tnTestList(TnGet(r.options, "argv")) {
|
|
228
|
+
args = append(args, TnJSString(a))
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
cmd := exec.Command(exe, args...)
|
|
232
|
+
if cwd, ok := TnGetValue(r.options, "cwd").(string); ok && cwd != "" {
|
|
233
|
+
cmd.Dir = cwd
|
|
234
|
+
}
|
|
235
|
+
env := os.Environ()
|
|
236
|
+
filtered := env[:0]
|
|
237
|
+
for _, kv := range env {
|
|
238
|
+
if !strings.HasPrefix(kv, "NODE_OPTIONS=") && !strings.HasPrefix(kv, "TN_ENTRY=") {
|
|
239
|
+
filtered = append(filtered, kv)
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
cmd.Env = append(filtered, "TN_ENTRY="+f.entry, "NODE_TEST_CONTEXT=child-tn", "NODE_OPTIONS="+r.childOptions())
|
|
243
|
+
stdout, _ := cmd.StdoutPipe()
|
|
244
|
+
stderr, _ := cmd.StderrPipe()
|
|
245
|
+
if err := cmd.Start(); err != nil {
|
|
246
|
+
f.finished = true
|
|
247
|
+
f.held = append(f.held, &TnTestEvent{type_: "test:stderr", data: &TnTestEventData{file: f.path, message: err.Error() + "\\n"}})
|
|
248
|
+
r.fileDone(f, 1, "")
|
|
249
|
+
return
|
|
250
|
+
}
|
|
251
|
+
r.emit(&TnTestEvent{type_: "test:dequeue", data: &TnTestEventData{name: f.path, file: f.path, line: 1, column: 1}})
|
|
252
|
+
var timer *time.Timer
|
|
253
|
+
if r.options != nil {
|
|
254
|
+
if ms, ok := TnGetValue(r.options, "timeout").(float64); ok && ms > 0 && !math.IsInf(ms, 1) {
|
|
255
|
+
timer = time.AfterFunc(time.Duration(ms*float64(time.Millisecond)), func() { cmd.Process.Kill() })
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
var pipes sync.WaitGroup
|
|
259
|
+
pipes.Add(2)
|
|
260
|
+
go func() {
|
|
261
|
+
defer pipes.Done()
|
|
262
|
+
tnTestReadFrames(stdout, func(e *TnTestEvent) {
|
|
263
|
+
TnLoopPost(func() { r.deliver(f, e) })
|
|
264
|
+
}, func(text string) {
|
|
265
|
+
TnLoopPost(func() {
|
|
266
|
+
r.deliver(f, &TnTestEvent{type_: "test:stdout", data: &TnTestEventData{file: f.path, message: text}})
|
|
267
|
+
})
|
|
268
|
+
})
|
|
269
|
+
}()
|
|
270
|
+
go func() {
|
|
271
|
+
defer pipes.Done()
|
|
272
|
+
buf := make([]byte, 32768)
|
|
273
|
+
for {
|
|
274
|
+
n, err := stderr.Read(buf)
|
|
275
|
+
if n > 0 {
|
|
276
|
+
text := string(buf[:n])
|
|
277
|
+
TnLoopPost(func() {
|
|
278
|
+
r.deliver(f, &TnTestEvent{type_: "test:stderr", data: &TnTestEventData{file: f.path, message: text}})
|
|
279
|
+
})
|
|
280
|
+
}
|
|
281
|
+
if err != nil {
|
|
282
|
+
return
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
}()
|
|
286
|
+
go func() {
|
|
287
|
+
pipes.Wait()
|
|
288
|
+
err := cmd.Wait()
|
|
289
|
+
if timer != nil {
|
|
290
|
+
timer.Stop()
|
|
291
|
+
}
|
|
292
|
+
code, signal := 0, ""
|
|
293
|
+
if err != nil {
|
|
294
|
+
code = 1
|
|
295
|
+
if exit, ok := err.(*exec.ExitError); ok {
|
|
296
|
+
code = exit.ExitCode()
|
|
297
|
+
if code < 0 {
|
|
298
|
+
signal = "SIGKILL"
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
TnLoopPost(func() {
|
|
303
|
+
f.finished = true
|
|
304
|
+
r.fileDone(f, code, signal)
|
|
305
|
+
})
|
|
306
|
+
}()
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
// A child exited: its file's summary (or a failure when it crashed), then
|
|
310
|
+
// the next files' held events
|
|
311
|
+
func (r *tnTestRun) fileDone(f *tnTestRunFile, code int, signal string) {
|
|
312
|
+
f.exitCode, f.signal = code, signal
|
|
313
|
+
r.running--
|
|
314
|
+
r.drain()
|
|
315
|
+
r.fill()
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
// Relays the held events of files whose turn has come
|
|
319
|
+
func (r *tnTestRun) drain() {
|
|
320
|
+
for r.reporting < len(r.files) {
|
|
321
|
+
f := r.files[r.reporting]
|
|
322
|
+
held := f.held
|
|
323
|
+
f.held = nil
|
|
324
|
+
for _, e := range held {
|
|
325
|
+
r.relay(f, e)
|
|
326
|
+
}
|
|
327
|
+
if !f.finished {
|
|
328
|
+
return
|
|
329
|
+
}
|
|
330
|
+
r.closeFile(f)
|
|
331
|
+
r.reporting++
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
func (r *tnTestRun) closeFile(f *tnTestRunFile) {
|
|
336
|
+
duration := math.Round(float64(time.Since(f.start).Nanoseconds())/1e3) / 1e3
|
|
337
|
+
// A child that exited with an error its failing tests don't explain crashed: the file fails
|
|
338
|
+
explained := f.summary != nil && f.summary.counts != nil && (f.summary.counts.failed > 0 || f.summary.counts.cancelled > 0)
|
|
339
|
+
if f.exitCode != 0 && !explained {
|
|
340
|
+
{
|
|
341
|
+
r.topLevel++
|
|
342
|
+
err := tnTestFailure("test failed", "testCodeFailure")
|
|
343
|
+
err.props["exitCode"] = float64(f.exitCode)
|
|
344
|
+
err.props["signal"] = tnTestNull
|
|
345
|
+
if f.signal != "" {
|
|
346
|
+
err.props["signal"] = f.signal
|
|
347
|
+
}
|
|
348
|
+
base := &TnTestEventData{name: f.path, file: f.path, line: 1, column: 1}
|
|
349
|
+
r.emit(&TnTestEvent{type_: "test:start", data: base})
|
|
350
|
+
fail := *base
|
|
351
|
+
fail.testNumber = r.topLevel
|
|
352
|
+
fail.details = &TnTestEventDetails{duration_ms: duration, type_: "test", error_: err}
|
|
353
|
+
r.emit(&TnTestEvent{type_: "test:fail", data: &fail})
|
|
354
|
+
r.counts.tests++
|
|
355
|
+
r.counts.failed++
|
|
356
|
+
r.counts.topLevel++
|
|
357
|
+
r.success = false
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
if f.summary != nil {
|
|
361
|
+
if c := f.summary.counts; c != nil {
|
|
362
|
+
r.counts.tests += c.tests
|
|
363
|
+
r.counts.failed += c.failed
|
|
364
|
+
r.counts.passed += c.passed
|
|
365
|
+
r.counts.cancelled += c.cancelled
|
|
366
|
+
r.counts.skipped += c.skipped
|
|
367
|
+
r.counts.todo += c.todo
|
|
368
|
+
r.counts.topLevel += c.topLevel
|
|
369
|
+
r.counts.suites += c.suites
|
|
370
|
+
}
|
|
371
|
+
if !f.summary.success {
|
|
372
|
+
r.success = false
|
|
373
|
+
}
|
|
374
|
+
f.summary.file = f.path
|
|
375
|
+
r.emit(&TnTestEvent{type_: "test:summary", data: f.summary})
|
|
376
|
+
}
|
|
377
|
+
complete := &TnTestEventData{name: f.path, nesting: 0, file: f.path, line: 1, column: 1, details: &TnTestEventDetails{duration_ms: duration, type_: "test", passed: f.summary != nil && f.summary.success}}
|
|
378
|
+
r.emit(&TnTestEvent{type_: "test:complete", data: complete})
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
func (r *tnTestRun) finish() {
|
|
382
|
+
r.emit(&TnTestEvent{type_: "test:plan", data: &TnTestEventData{count: r.topLevel}})
|
|
383
|
+
c := r.counts
|
|
384
|
+
duration := math.Round(float64(time.Since(r.start).Nanoseconds())/1e2) / 1e4
|
|
385
|
+
note := func(message string) {
|
|
386
|
+
r.emit(&TnTestEvent{type_: "test:diagnostic", data: &TnTestEventData{message: message, level: "info"}})
|
|
387
|
+
}
|
|
388
|
+
note("tests " + TnNumStr(c.tests))
|
|
389
|
+
note("suites " + TnNumStr(c.suites))
|
|
390
|
+
note("pass " + TnNumStr(c.passed))
|
|
391
|
+
note("fail " + TnNumStr(c.failed))
|
|
392
|
+
note("cancelled " + TnNumStr(c.cancelled))
|
|
393
|
+
note("skipped " + TnNumStr(c.skipped))
|
|
394
|
+
note("todo " + TnNumStr(c.todo))
|
|
395
|
+
note("duration_ms " + TnNumStr(duration))
|
|
396
|
+
if len(r.coverage) > 0 {
|
|
397
|
+
r.emit(&TnTestEvent{type_: "test:coverage", data: &TnTestEventData{summary: tnCoverageMerge(r.coverage)}})
|
|
398
|
+
}
|
|
399
|
+
counts := c
|
|
400
|
+
r.emit(&TnTestEvent{type_: "test:summary", data: &TnTestEventData{success: r.success && c.failed == 0 && c.cancelled == 0, counts: &counts, duration_ms: duration}})
|
|
401
|
+
r.stream.push(nil)
|
|
402
|
+
TnLoopUnref()
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
// The children's coverage of the same program: counts add up per file
|
|
406
|
+
func tnCoverageMerge(list []*TnCoverageSummary) *TnCoverageSummary {
|
|
407
|
+
if len(list) == 1 {
|
|
408
|
+
return list[0]
|
|
409
|
+
}
|
|
410
|
+
out := &TnCoverageSummary{workingDirectory: list[0].workingDirectory}
|
|
411
|
+
byPath := map[string]*TnCoverageFile{}
|
|
412
|
+
for _, s := range list {
|
|
413
|
+
for _, f := range s.files {
|
|
414
|
+
m, ok := byPath[f.path]
|
|
415
|
+
if !ok {
|
|
416
|
+
copy := *f
|
|
417
|
+
copy.functions = append([]*TnCoverageFunction{}, f.functions...)
|
|
418
|
+
copy.branches = append([]*TnCoverageCount{}, f.branches...)
|
|
419
|
+
copy.lines = append([]*TnCoverageCount{}, f.lines...)
|
|
420
|
+
byPath[f.path] = ©
|
|
421
|
+
out.files = append(out.files, ©)
|
|
422
|
+
continue
|
|
423
|
+
}
|
|
424
|
+
for i, fn := range f.functions {
|
|
425
|
+
if i < len(m.functions) {
|
|
426
|
+
m.functions[i] = &TnCoverageFunction{name: fn.name, line: fn.line, count: m.functions[i].count + fn.count}
|
|
427
|
+
}
|
|
428
|
+
}
|
|
429
|
+
for i, b := range f.branches {
|
|
430
|
+
if i < len(m.branches) {
|
|
431
|
+
m.branches[i] = &TnCoverageCount{line: b.line, count: m.branches[i].count + b.count}
|
|
432
|
+
}
|
|
433
|
+
}
|
|
434
|
+
for i, l := range f.lines {
|
|
435
|
+
if i < len(m.lines) {
|
|
436
|
+
m.lines[i] = &TnCoverageCount{line: l.line, count: m.lines[i].count + l.count}
|
|
437
|
+
}
|
|
438
|
+
}
|
|
439
|
+
}
|
|
440
|
+
}
|
|
441
|
+
totals := &TnCoverageTotals{}
|
|
442
|
+
for _, f := range out.files {
|
|
443
|
+
f.coveredFunctionCount, f.coveredBranchCount, f.coveredLineCount = 0, 0, 0
|
|
444
|
+
for _, fn := range f.functions {
|
|
445
|
+
if fn.count > 0 {
|
|
446
|
+
f.coveredFunctionCount++
|
|
447
|
+
}
|
|
448
|
+
}
|
|
449
|
+
for _, b := range f.branches {
|
|
450
|
+
if b.count > 0 {
|
|
451
|
+
f.coveredBranchCount++
|
|
452
|
+
}
|
|
453
|
+
}
|
|
454
|
+
ignored := f.totalLineCount - float64(len(f.lines))
|
|
455
|
+
f.coveredLineCount = ignored
|
|
456
|
+
for _, l := range f.lines {
|
|
457
|
+
if l.count > 0 {
|
|
458
|
+
f.coveredLineCount++
|
|
459
|
+
}
|
|
460
|
+
}
|
|
461
|
+
f.coveredLinePercent = tnCoveragePercent(f.coveredLineCount, f.totalLineCount)
|
|
462
|
+
f.coveredBranchPercent = tnCoveragePercent(f.coveredBranchCount, f.totalBranchCount)
|
|
463
|
+
f.coveredFunctionPercent = tnCoveragePercent(f.coveredFunctionCount, f.totalFunctionCount)
|
|
464
|
+
totals.totalLineCount += f.totalLineCount
|
|
465
|
+
totals.totalBranchCount += f.totalBranchCount
|
|
466
|
+
totals.totalFunctionCount += f.totalFunctionCount
|
|
467
|
+
totals.coveredLineCount += f.coveredLineCount
|
|
468
|
+
totals.coveredBranchCount += f.coveredBranchCount
|
|
469
|
+
totals.coveredFunctionCount += f.coveredFunctionCount
|
|
470
|
+
}
|
|
471
|
+
totals.coveredLinePercent = tnCoveragePercent(totals.coveredLineCount, totals.totalLineCount)
|
|
472
|
+
totals.coveredBranchPercent = tnCoveragePercent(totals.coveredBranchCount, totals.totalBranchCount)
|
|
473
|
+
totals.coveredFunctionPercent = tnCoveragePercent(totals.coveredFunctionCount, totals.totalFunctionCount)
|
|
474
|
+
out.totals = totals
|
|
475
|
+
return out
|
|
476
|
+
}
|
|
477
|
+
|
|
478
|
+
func tnCoveragePercent(covered float64, total float64) float64 {
|
|
479
|
+
if total == 0 {
|
|
480
|
+
return 100
|
|
481
|
+
}
|
|
482
|
+
return covered / total * 100
|
|
483
|
+
}
|
|
484
|
+
|
|
485
|
+
// Splits a child's stdout into event frames and plain output
|
|
486
|
+
func tnTestReadFrames(r io.Reader, onEvent func(e *TnTestEvent), onText func(text string)) {
|
|
487
|
+
marker := []byte(tnTestFrame)
|
|
488
|
+
buf := []byte{}
|
|
489
|
+
chunk := make([]byte, 32768)
|
|
490
|
+
for {
|
|
491
|
+
n, err := r.Read(chunk)
|
|
492
|
+
buf = append(buf, chunk[:n]...)
|
|
493
|
+
for len(buf) > 0 {
|
|
494
|
+
i := bytes.Index(buf, marker)
|
|
495
|
+
if i < 0 {
|
|
496
|
+
// keep what may be the start of a marker
|
|
497
|
+
keep := 0
|
|
498
|
+
for k := len(marker) - 1; k > 0; k-- {
|
|
499
|
+
if bytes.HasSuffix(buf, marker[:k]) {
|
|
500
|
+
keep = k
|
|
501
|
+
break
|
|
502
|
+
}
|
|
503
|
+
}
|
|
504
|
+
if len(buf) > keep {
|
|
505
|
+
onText(string(buf[:len(buf)-keep]))
|
|
506
|
+
}
|
|
507
|
+
buf = append([]byte{}, buf[len(buf)-keep:]...)
|
|
508
|
+
break
|
|
509
|
+
}
|
|
510
|
+
if i > 0 {
|
|
511
|
+
onText(string(buf[:i]))
|
|
512
|
+
}
|
|
513
|
+
end := bytes.IndexByte(buf[i:], '\\n')
|
|
514
|
+
if end < 0 {
|
|
515
|
+
buf = append([]byte{}, buf[i:]...)
|
|
516
|
+
break
|
|
517
|
+
}
|
|
518
|
+
var raw interface{}
|
|
519
|
+
if json.Unmarshal(buf[i+len(marker):i+end], &raw) == nil {
|
|
520
|
+
onEvent(tnTestEventOf(tnCloneDecode(raw)))
|
|
521
|
+
}
|
|
522
|
+
buf = append([]byte{}, buf[i+end+1:]...)
|
|
523
|
+
}
|
|
524
|
+
if err != nil {
|
|
525
|
+
if len(buf) > 0 {
|
|
526
|
+
onText(string(buf))
|
|
527
|
+
}
|
|
528
|
+
return
|
|
529
|
+
}
|
|
530
|
+
}
|
|
531
|
+
}`;
|
|
532
|
+
// The files of run({ files: [...] }): each literal path is compiled in as an
|
|
533
|
+
// entry point; [entry id, path] pairs ('' ids for paths only known at run time)
|
|
534
|
+
function runFiles(r, options) {
|
|
535
|
+
const files = isObjectLiteral(options) ? getOption(options, 'files') : undefined;
|
|
536
|
+
if (!files || files.kind !== 'ArrayLiteralExpression')
|
|
537
|
+
return [];
|
|
538
|
+
const out = [];
|
|
539
|
+
for (const element of files.elements ?? []) {
|
|
540
|
+
// path.resolve('./a.test.ts') / path.join(__dirname, 'a.test.ts') name the file too
|
|
541
|
+
let target = element;
|
|
542
|
+
if (element.kind === 'CallExpression' &&
|
|
543
|
+
element.expression?.kind === 'PropertyAccessExpression' &&
|
|
544
|
+
element.expression.name?.text === 'resolve' &&
|
|
545
|
+
(element.arguments ?? []).length === 1) {
|
|
546
|
+
target = element.arguments[0];
|
|
547
|
+
}
|
|
548
|
+
const entry = r.entryPoint(target);
|
|
549
|
+
out.push(`[]string{${JSON.stringify(entry)}, ${r.visit(element)}}`);
|
|
550
|
+
}
|
|
551
|
+
return out;
|
|
552
|
+
}
|
|
553
|
+
export function registerTestRun(r) {
|
|
554
|
+
defineHelper(r, 'nodeTestRun', ['bytes', 'encoding/json', 'io', 'math', 'os', 'os/exec', 'path/filepath', 'regexp', 'runtime', 'strings', 'sync', 'time'], ['nodeTest', 'nodeTestReporters', 'nodeClone', 'entryPoints', 'nodeEvents'], runHelper);
|
|
555
|
+
r.functions['test.run'] = (c) => {
|
|
556
|
+
r.helper('nodeTestRun');
|
|
557
|
+
const files = runFiles(r, c.nodes[0]);
|
|
558
|
+
const options = c.args.length > 0 ? c.args[0] : 'nil';
|
|
559
|
+
return `TnTestRun(${options}${files.length > 0 ? ', ' : ''}${files.join(', ')})`;
|
|
560
|
+
};
|
|
561
|
+
r.results['test.run'] = '*TnStream';
|
|
562
|
+
r.paramTypers['test.run'] = (_n) => ['*TnStream'];
|
|
563
|
+
// run(…).on('test:pass', (data) => …): the event's data
|
|
564
|
+
const streamListeners = r.paramTypers['stream.Duplex#on'];
|
|
565
|
+
const listeners = (nodes) => {
|
|
566
|
+
const event = nodes[0];
|
|
567
|
+
if (event && event.kind === 'StringLiteral' && String(event.text).startsWith('test:')) {
|
|
568
|
+
r.helper('nodeTestReport');
|
|
569
|
+
return ['*TnTestEventData'];
|
|
570
|
+
}
|
|
571
|
+
return streamListeners ? streamListeners(nodes) : [];
|
|
572
|
+
};
|
|
573
|
+
r.paramTypers['stream.Duplex#on'] = listeners;
|
|
574
|
+
r.paramTypers['stream.Duplex#once'] = listeners;
|
|
575
|
+
}
|
package/bin/node/timers.js
CHANGED
|
@@ -42,7 +42,7 @@ func TnPerfTimeOrigin() float64 {
|
|
|
42
42
|
func TnPerfMark(name string, options ...interface{}) *TnPerformanceEntry {
|
|
43
43
|
entry := &TnPerformanceEntry{name: name, entryType: "mark", startTime: TnPerfNow()}
|
|
44
44
|
if len(options) > 0 && options[0] != nil {
|
|
45
|
-
if t, ok :=
|
|
45
|
+
if t, ok := TnGetValue(options[0], "startTime").(float64); ok {
|
|
46
46
|
entry.startTime = t
|
|
47
47
|
}
|
|
48
48
|
entry.detail = TnGet(options[0], "detail")
|
|
@@ -74,10 +74,10 @@ func TnPerfMeasure(name string, marks ...interface{}) *TnPerformanceEntry {
|
|
|
74
74
|
if s, ok := marks[0].(string); ok {
|
|
75
75
|
start = tnPerfMarkTime(s)
|
|
76
76
|
} else if marks[0] != nil {
|
|
77
|
-
if s, ok :=
|
|
77
|
+
if s, ok := TnGetValue(marks[0], "start").(string); ok {
|
|
78
78
|
start = tnPerfMarkTime(s)
|
|
79
79
|
}
|
|
80
|
-
if e, ok :=
|
|
80
|
+
if e, ok := TnGetValue(marks[0], "end").(string); ok {
|
|
81
81
|
end = tnPerfMarkTime(e)
|
|
82
82
|
}
|
|
83
83
|
}
|
|
@@ -124,7 +124,7 @@ func TnPerfClear(entryType string, name ...string) {
|
|
|
124
124
|
const timerPromisesHelper = `// node:timers/promises
|
|
125
125
|
func tnTimerSignal(options []interface{}) *TnAbortSignal {
|
|
126
126
|
if len(options) > 0 && options[0] != nil {
|
|
127
|
-
if s, ok :=
|
|
127
|
+
if s, ok := TnGetValue(options[0], "signal").(*TnAbortSignal); ok {
|
|
128
128
|
return s
|
|
129
129
|
}
|
|
130
130
|
}
|
|
@@ -242,8 +242,10 @@ export function registerTimers(r) {
|
|
|
242
242
|
r.results[`perf_hooks.performance.${name}`] = result;
|
|
243
243
|
};
|
|
244
244
|
perf('now', 'float64', (_c) => 'TnPerfNow()');
|
|
245
|
-
|
|
246
|
-
|
|
245
|
+
// (the name of an any value: its string)
|
|
246
|
+
const named = (c) => [c.types[0] === 'string' ? c.args[0] : `TnJSString(${c.args[0]})`, ...c.args.slice(1)].join(', ');
|
|
247
|
+
perf('mark', '*TnPerformanceEntry', (c) => `TnPerfMark(${named(c)})`);
|
|
248
|
+
perf('measure', '*TnPerformanceEntry', (c) => `TnPerfMeasure(${named(c)})`);
|
|
247
249
|
perf('getEntries', '[]*TnPerformanceEntry', (_c) => 'TnPerfEntries("", "")');
|
|
248
250
|
perf('getEntriesByName', '[]*TnPerformanceEntry', (c) => `TnPerfEntries(${c.args[0]}, ${c.args[1] ?? '""'})`);
|
|
249
251
|
perf('getEntriesByType', '[]*TnPerformanceEntry', (c) => `TnPerfEntries("", ${c.args[0]})`);
|
package/bin/node/tls.js
CHANGED
|
@@ -131,9 +131,9 @@ func tnTLSServerConfig(options interface{}) (*tls.Config, error) {
|
|
|
131
131
|
}
|
|
132
132
|
cfg.Certificates = certs
|
|
133
133
|
cfg.ClientCAs = tnCertPool(tnPemStrings(TnGet(options, "ca")))
|
|
134
|
-
if b, ok :=
|
|
134
|
+
if b, ok := TnGetValue(options, "requestCert").(bool); ok && b {
|
|
135
135
|
cfg.ClientAuth = tls.RequestClientCert
|
|
136
|
-
if r, ok :=
|
|
136
|
+
if r, ok := TnGetValue(options, "rejectUnauthorized").(bool); (!ok || r) && cfg.ClientCAs != nil {
|
|
137
137
|
cfg.ClientAuth = tls.RequireAndVerifyClientCert
|
|
138
138
|
}
|
|
139
139
|
}
|
|
@@ -337,7 +337,7 @@ func TnCheckServerIdentity(hostname string, cert interface{}) *TnError {
|
|
|
337
337
|
} else {
|
|
338
338
|
altNames = tnNetString(TnGet(cert, "subjectaltname"))
|
|
339
339
|
subject := TnGet(cert, "subject")
|
|
340
|
-
switch cn :=
|
|
340
|
+
switch cn := TnGetValue(subject, "CN").(type) {
|
|
341
341
|
case string:
|
|
342
342
|
cns = []string{cn}
|
|
343
343
|
case []interface{}:
|
|
@@ -419,7 +419,7 @@ func tnTLSClientConfig(options interface{}, host string, verified func(err *TnEr
|
|
|
419
419
|
}
|
|
420
420
|
cfg.Certificates = certs
|
|
421
421
|
roots = tnCertPool(tnPemStrings(TnGet(options, "ca")))
|
|
422
|
-
if b, ok :=
|
|
422
|
+
if b, ok := TnGetValue(options, "rejectUnauthorized").(bool); ok {
|
|
423
423
|
reject = b
|
|
424
424
|
}
|
|
425
425
|
if sn := tnNetString(TnGet(options, "servername")); sn != "" {
|
|
@@ -617,7 +617,7 @@ func TnTLSCreateServer(args ...interface{}) *TnNetServer {
|
|
|
617
617
|
}
|
|
618
618
|
requestCert := false
|
|
619
619
|
if options != nil {
|
|
620
|
-
requestCert, _ =
|
|
620
|
+
requestCert, _ = TnGetValue(options, "requestCert").(bool)
|
|
621
621
|
}
|
|
622
622
|
srv.wrapConn = func(conn net.Conn) (net.Conn, error) {
|
|
623
623
|
tc := tls.Server(conn, cfg)
|
package/bin/node/url.js
CHANGED
|
@@ -113,7 +113,7 @@ func tnParseHost(host string, special bool) (string, bool) {
|
|
|
113
113
|
host = decoded
|
|
114
114
|
}
|
|
115
115
|
host = strings.ToLower(host)
|
|
116
|
-
if !
|
|
116
|
+
if !tnPunyIsASCII(host) {
|
|
117
117
|
host = TnPunycodeToASCII(host)
|
|
118
118
|
}
|
|
119
119
|
if strings.ContainsAny(host, " #%/:<>?@[\\\\]^|") {
|