diff options
Diffstat (limited to 'cli')
110 files changed, 8 insertions, 7941 deletions
diff --git a/cli/tests/node_compat/common.ts b/cli/tests/node_compat/common.ts index 0941e2c8f..e774991f6 100644 --- a/cli/tests/node_compat/common.ts +++ b/cli/tests/node_compat/common.ts @@ -1,6 +1,6 @@ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. -import { partition } from "std/collections/mod.ts"; -import { join } from "std/path/mod.ts"; +import { partition } from "../../../test_util/std/collections/partition.ts"; +import { join } from "../../../test_util/std/path/mod.ts"; /** * The test suite matches the folders inside the `test` folder inside the @@ -35,7 +35,7 @@ export const ignoreList = Object.entries(config.ignore).reduce( paths.forEach((path) => total.push(new RegExp(join(suite, path)))); return total; }, - [], + [/package\.json/], ); export function getPathsFromTestSuites(suites: TestSuites): string[] { diff --git a/cli/tests/node_compat/config.json b/cli/tests/node_compat/config.json index 2f21e0d46..90e4a9a35 100644 --- a/cli/tests/node_compat/config.json +++ b/cli/tests/node_compat/config.json @@ -100,10 +100,7 @@ "test-zlib-zero-byte.js", "test-zlib-zero-windowBits.js" ], - "pummel": [ - "test-net-bytes-per-incoming-chunk-overhead.js", - "test-net-write-callbacks.js" - ], + "pummel": [], "sequential": [ "test-child-process-exit.js" ] @@ -115,7 +112,7 @@ "dns.js", "duplexpair.js", "fixtures.js", - "hijackstdio", + "hijackstdio.js", "index.mjs", "internet.js" ], @@ -137,7 +134,6 @@ "agent1-key.pem" ], "internet": [ - "TODO:test-dgram-connect.js", "test-dns-any.js", "test-dns-idna2008.js", "test-dns-ipv4.js", @@ -155,7 +151,6 @@ "test-assert.js", "test-bad-unicode.js", "test-btoa-atob.js", - "TODO:test-buffer-alloc.js", "test-buffer-arraybuffer.js", "test-buffer-ascii.js", "test-buffer-badhex.js", @@ -170,7 +165,6 @@ "test-buffer-fakes.js", "test-buffer-from.js", "test-buffer-includes.js", - "TODO:test-buffer-indexof.js", "test-buffer-inheritance.js", "test-buffer-isencoding.js", "test-buffer-iterator.js", @@ -186,7 +180,6 @@ "test-buffer-readint.js", "test-buffer-readuint.js", "test-buffer-safe-unsafe.js", - "TODO:test-buffer-sharedarraybuffer.js", "test-buffer-slice.js", "test-buffer-slow.js", "test-buffer-swap.js", @@ -194,7 +187,6 @@ "test-buffer-tostring-range.js", "test-buffer-tostring-rangeerror.js", "test-buffer-tostring.js", - "TODO:test-buffer-write.js", "test-buffer-writedouble.js", "test-buffer-writefloat.js", "test-buffer-writeint.js", @@ -207,40 +199,29 @@ "test-child-process-double-pipe.js", "test-child-process-exec-abortcontroller-promisified.js", "test-child-process-exec-cwd.js", - "TODO:test-child-process-exec-encoding.js", "test-child-process-exec-env.js", "test-child-process-exec-error.js", "test-child-process-exec-kill-throws.js", "test-child-process-exec-maxbuf.js", - "TODO:test-child-process-exec-std-encoding.js", "test-child-process-exec-stdout-stderr-data-string.js", "test-child-process-exec-timeout-expire.js", "test-child-process-exec-timeout-kill.js", - "TODO:test-child-process-exec-timeout-not-expired.js", "test-child-process-execFile-promisified-abortController.js", "test-child-process-execfile-maxbuf.js", - "TODO:test-child-process-execfile.js", "test-child-process-execfilesync-maxbuf.js", "test-child-process-execsync-maxbuf.js", - "TODO:test-child-process-exit-code.js", "test-child-process-flush-stdio.js", - "TODO:test-child-process-ipc.js", "test-child-process-kill.js", "test-child-process-set-blocking.js", "test-child-process-spawn-args.js", "test-child-process-spawn-event.js", "test-child-process-spawnsync-args.js", - "TODO:test-child-process-spawnsync-env.js", "test-child-process-spawnsync-maxbuf.js", "test-child-process-spawnsync-validation-errors.js", "test-child-process-spawnsync.js", - "TODO:test-child-process-stdio-inherit.js", - "TODO:test-child-process-stdout-flush-exit.js", - "TODO:test-child-process-stdout-flush.js", "test-client-request-destroy.js", "test-console-async-write-error.js", "test-console-group.js", - "TODO:test-console-instance.js", "test-console-log-stdio-broken-dest.js", "test-console-log-throw-primitive.js", "test-console-no-swallow-stack-overflow.js", @@ -248,73 +229,21 @@ "test-console-table.js", "test-console-tty-colors.js", "test-crypto-hmac.js", - "TODO:test-dgram-address.js", - "TODO:test-dgram-bind-default-address.js", - "TODO:test-dgram-bind.js", - "TODO:test-dgram-bytes-length.js", "test-dgram-close-during-bind.js", - "TODO:test-dgram-close-in-listening.js", - "TODO:test-dgram-close-is-not-callback.js", "test-dgram-close-signal.js", - "TODO:test-dgram-close.js", - "TODO:test-dgram-connect-send-callback-buffer-length.js", - "TODO:test-dgram-connect-send-callback-buffer.js", - "TODO:test-dgram-connect-send-callback-multi-buffer.js", - "TODO:test-dgram-connect-send-default-host.js", - "TODO:test-dgram-connect-send-empty-array.js", - "TODO:test-dgram-connect-send-empty-buffer.js", - "TODO:test-dgram-connect-send-empty-packet.js", - "TODO:test-dgram-connect-send-multi-buffer-copy.js", - "TODO:test-dgram-connect-send-multi-string-array.js", - "TODO:test-dgram-connect.js", - "TODO:test-dgram-createSocket-type.js", - "TODO:test-dgram-custom-lookup.js", - "TODO:test-dgram-error-message-address.js", - "TODO:test-dgram-implicit-bind.js", - "TODO:test-dgram-ipv6only.js", - "TODO:test-dgram-listen-after-bind.js", - "TODO:test-dgram-msgsize.js", - "TODO:test-dgram-oob-buffer.js", - "TODO:test-dgram-recv-error.js", - "TODO:test-dgram-send-bad-arguments.js", - "TODO:test-dgram-send-callback-buffer-empty-address.js", - "TODO:test-dgram-send-callback-buffer-length-empty-address.js", - "TODO:test-dgram-send-callback-buffer-length.js", - "TODO:test-dgram-send-callback-buffer.js", - "TODO:test-dgram-send-callback-multi-buffer-empty-address.js", - "TODO:test-dgram-send-callback-multi-buffer.js", - "TODO:test-dgram-send-callback-recursive.js", - "TODO:test-dgram-send-cb-quelches-error.js", - "TODO:test-dgram-send-default-host.js", - "TODO:test-dgram-send-empty-array.js", - "TODO:test-dgram-send-empty-buffer.js", - "TODO:test-dgram-send-empty-packet.js", - "TODO:test-dgram-send-error.js", - "TODO:test-dgram-send-invalid-msg-type.js", - "TODO:test-dgram-send-multi-buffer-copy.js", - "TODO:test-dgram-send-multi-string-array.js", - "TODO:test-dgram-socket-buffer-size.js", - "TODO:test-dgram-udp4.js", - "TODO:test-dgram-udp6-link-local-address.js", - "TODO:test-dgram-udp6-send-default-host.js", "test-diagnostics-channel-has-subscribers.js", - "TODO:test-diagnostics-channel-net.js", "test-diagnostics-channel-object-channel-pub-sub.js", "test-diagnostics-channel-pub-sub.js", "test-diagnostics-channel-symbol-named.js", "test-diagnostics-channel-udp.js", "test-dns-lookup.js", "test-dns-memory-error.js", - "TODO:test-dns-multi-channel.js", "test-dns-promises-exists.js", - "TODO:test-dns-resolveany.js", "test-dns-resolvens-typeerror.js", "test-dns-setservers-type-check.js", - "TODO:test-dns.js", "test-eval-strict-referenceerror.js", "test-eval.js", "test-event-emitter-add-listeners.js", - "TODO:test-event-emitter-check-listener-leaks.js", "test-event-emitter-emit-context.js", "test-event-emitter-error-monitor.js", "test-event-emitter-errors.js", @@ -323,9 +252,6 @@ "test-event-emitter-listener-count.js", "test-event-emitter-listeners-side-effects.js", "test-event-emitter-listeners.js", - "TODO:test-event-emitter-max-listeners-warning-for-null.js", - "TODO:test-event-emitter-max-listeners-warning-for-symbol.js", - "TODO:test-event-emitter-max-listeners-warning.js", "test-event-emitter-max-listeners.js", "test-event-emitter-method-names.js", "test-event-emitter-modify-in-emit.js", @@ -383,7 +309,6 @@ "test-fs-readdir.js", "test-fs-readfile-empty.js", "test-fs-realpath-native.js", - "TODO:test-fs-rm.js", "test-fs-rmdir-recursive-sync-warns-not-found.js", "test-fs-rmdir-recursive-sync-warns-on-file.js", "test-fs-rmdir-recursive-throws-not-found.js", @@ -392,7 +317,6 @@ "test-fs-rmdir-recursive-warns-on-file.js", "test-fs-rmdir-recursive.js", "test-fs-rmdir-type-check.js", - "TODO:test-fs-watch.js", "test-fs-watchfile.js", "test-fs-write-buffer.js", "test-fs-write-file-buffer.js", @@ -410,14 +334,11 @@ "test-fs-write-sync.js", "test-fs-write.js", "test-fs-writev-sync.js", - "TODO:test-fs-writev.js", "test-handle-wrap-close-abort.js", "test-http-agent-getname.js", "test-http-client-get-url.js", "test-http-client-read-in-error.js", "test-http-outgoing-buffer.js", - "TODO:test-http-outgoing-destroy.js", - "TODO:test-http-outgoing-finish-writable.js", "test-http-outgoing-internal-headernames-getter.js", "test-http-outgoing-internal-headernames-setter.js", "test-http-outgoing-internal-headers.js", @@ -429,84 +350,39 @@ "test-http-url.parse-post.js", "test-http-url.parse-search.js", "test-net-access-byteswritten.js", - "TODO:test-net-after-close.js", - "TODO:test-net-allow-half-open.js", "test-net-better-error-messages-listen-path.js", - "TODO:test-net-better-error-messages-listen.js", "test-net-better-error-messages-path.js", "test-net-better-error-messages-port-hostname.js", - "TODO:test-net-bind-twice.js", - "TODO:test-net-buffersize.js", - "TODO:test-net-bytes-written-large.js", - "TODO:test-net-can-reset-timeout.js", "test-net-connect-after-destroy.js", - "TODO:test-net-connect-buffer.js", - "TODO:test-net-connect-buffer2.js", - "TODO:test-net-connect-call-socket-connect.js", "test-net-connect-destroy.js", "test-net-connect-immediate-destroy.js", "test-net-connect-immediate-finish.js", "test-net-connect-no-arg.js", - "TODO:test-net-connect-options-ipv6.js", - "TODO:test-net-connect-options-port.js", - "TODO:test-net-dns-custom-lookup.js", "test-net-dns-error.js", - "TODO:test-net-dns-lookup-skip.js", - "TODO:test-net-dns-lookup.js", "test-net-during-close.js", - "TODO:test-net-eaddrinuse.js", "test-net-end-close.js", - "TODO:test-net-end-destroyed.js", "test-net-end-without-connect.js", "test-net-isip.js", "test-net-isipv4.js", "test-net-isipv6.js", - "TODO:test-net-listen-after-destroying-stdin.js", "test-net-listen-close-server-callback-is-not-function.js", "test-net-listen-close-server.js", - "TODO:test-net-listen-error.js", "test-net-listen-invalid-port.js", "test-net-listening.js", - "TODO:test-net-local-address-port.js", "test-net-localerror.js", "test-net-options-lookup.js", - "TODO:test-net-pause-resume-connecting.js", - "TODO:test-net-persistent-ref-unref.js", "test-net-pipe-connect-errors.js", - "TODO:test-net-remote-address-port.js", - "TODO:test-net-server-call-listen-multiple-times.js", - "TODO:test-net-server-capture-rejection.js", - "TODO:test-net-server-close.js", "test-net-server-listen-options-signal.js", "test-net-server-listen-options.js", "test-net-server-listen-path.js", "test-net-server-listen-remove-callback.js", - "TODO:test-net-server-max-connections.js", "test-net-server-options.js", - "TODO:test-net-server-pause-on-connect.js", - "TODO:test-net-server-try-ports.js", "test-net-server-unref-persistent.js", "test-net-server-unref.js", - "TODO:test-net-socket-close-after-end.js", - "TODO:test-net-socket-connect-without-cb.js", - "TODO:test-net-socket-connecting.js", - "TODO:test-net-socket-destroy-send.js", "test-net-socket-destroy-twice.js", - "TODO:test-net-socket-end-before-connect.js", - "TODO:test-net-socket-end-callback.js", "test-net-socket-no-halfopen-enforcer.js", - "TODO:test-net-socket-ready-without-cb.js", - "TODO:test-net-socket-timeout.js", - "TODO:test-net-socket-write-after-close.js", - "TODO:test-net-socket-write-error.js", - "TODO:test-net-sync-cork.js", "test-net-timeout-no-handle.js", - "TODO:test-net-writable.js", - "TODO:test-net-write-after-end-nt.js", "test-net-write-arguments.js", - "TODO:test-net-write-fully-async-buffer.js", - "TODO:test-net-write-fully-async-hex-string.js", - "TODO:test-net-write-slow.js", "test-next-tick-doesnt-hang.js", "test-next-tick-fixed-queue-regression.js", "test-next-tick-intentional-starvation.js", @@ -515,7 +391,6 @@ "test-next-tick-when-exiting.js", "test-next-tick.js", "test-nodeeventtarget.js", - "TODO:test-os.js", "test-outgoing-message-destroy.js", "test-outgoing-message-pipe.js", "test-path-basename.js", @@ -543,19 +418,14 @@ "test-process-uptime.js", "test-promise-unhandled-silent.js", "test-promise-unhandled-throw-handler.js", - "TODO:test-punycode.js", "test-querystring-escape.js", "test-querystring-maxKeys-non-finite.js", "test-querystring-multichar-separator.js", "test-querystring.js", - "TODO:test-readline-csi.js", "test-readline-emit-keypress-events.js", "test-readline-interface-escapecodetimeout.js", - "TODO:test-readline-interface.js", "test-readline-keys.js", "test-readline-position.js", - "TODO:test-readline-promises-csi.mjs", - "TODO:test-readline-promises-interface.js", "test-readline-reopen.js", "test-readline-set-raw-mode.js", "test-readline-undefined-columns.js", @@ -563,14 +433,12 @@ "test-stdin-from-file-spawn.js", "test-stream-add-abort-signal.js", "test-stream-aliases-legacy.js", - "TODO:test-stream-asIndexedPairs.mjs", "test-stream-auto-destroy.js", "test-stream-await-drain-writers-in-synchronously-recursion-write.js", "test-stream-backpressure.js", "test-stream-big-packet.js", "test-stream-big-push.js", "test-stream-buffer-list.js", - "TODO:test-stream-catch-rejections.js", "test-stream-construct.js", "test-stream-destroy-event-order.js", "test-stream-duplex-destroy.js", @@ -640,7 +508,6 @@ "test-stream-readable-unshift.js", "test-stream-readable-with-unimplemented-_read.js", "test-stream-readableListening-state.js", - "TODO:test-stream-some-find-every.mjs", "test-stream-transform-callback-twice.js", "test-stream-transform-constructor-set-methods.js", "test-stream-transform-destroy.js", @@ -723,7 +590,6 @@ "test-timers-unref-throw-then-ref.js", "test-timers-user-call.js", "test-timers-zero-timeout.js", - "TODO:test-tls-connect-simple.js", "test-url-domain-ascii-unicode.js", "test-url-fileurltopath.js", "test-url-format-invalid-input.js", @@ -798,11 +664,7 @@ "test-tty-stdin-end.js", "test-tty-stdout-end.js" ], - "pummel": [ - "TODO:test-net-bytes-per-incoming-chunk-overhead.js", - "TODO:test-net-pingpong-delay.js", - "TODO:test-net-write-callbacks.js" - ], + "pummel": [], "sequential": [ "test-child-process-exit.js" ] diff --git a/cli/tests/node_compat/test.ts b/cli/tests/node_compat/test.ts index 505a20f08..ad2847f08 100644 --- a/cli/tests/node_compat/test.ts +++ b/cli/tests/node_compat/test.ts @@ -47,10 +47,9 @@ async function runTest(t: Deno.TestContext, path: string): Promise<void> { ) { return; } - const isTodo = path.includes("TODO"); const ignore = (Deno.build.os === "windows" && windowsIgnorePaths.has(path)) || - (Deno.build.os === "darwin" && darwinIgnorePaths.has(path)) || isTodo; + (Deno.build.os === "darwin" && darwinIgnorePaths.has(path)); await t.step({ name: `Node.js compatibility "${path}"`, ignore, @@ -124,8 +123,7 @@ Deno.test("Node.js compatibility", async (t) => { }); function checkConfigTestFilesOrder(testFileLists: Array<string[]>) { - for (let testFileList of testFileLists) { - testFileList = testFileList.filter((name) => !name.startsWith("TODO:")); + for (const testFileList of testFileLists) { const sortedTestList = JSON.parse(JSON.stringify(testFileList)); sortedTestList.sort(); if (JSON.stringify(testFileList) !== JSON.stringify(sortedTestList)) { diff --git a/cli/tests/node_compat/test/internet/test-dgram-connect.js b/cli/tests/node_compat/test/internet/test-dgram-connect.js deleted file mode 100644 index 17b52472c..000000000 --- a/cli/tests/node_compat/test/internet/test-dgram-connect.js +++ /dev/null @@ -1,26 +0,0 @@ -// deno-fmt-ignore-file -// deno-lint-ignore-file - -// Copyright Joyent and Node contributors. All rights reserved. MIT license. -// Taken from Node 18.12.1 -// This file is automatically generated by "node/_tools/setup.ts". Do not modify this file manually - -'use strict'; - -const common = require('../common'); -const { addresses } = require('../common/internet'); -const assert = require('assert'); -const dgram = require('dgram'); - -const client = dgram.createSocket('udp4'); -client.connect(common.PORT, addresses.INVALID_HOST, common.mustCall((err) => { - assert.ok(err.code === 'ENOTFOUND' || err.code === 'EAI_AGAIN'); - - client.once('error', common.mustCall((err) => { - assert.ok(err.code === 'ENOTFOUND' || err.code === 'EAI_AGAIN'); - client.once('connect', common.mustCall(() => client.close())); - client.connect(common.PORT); - })); - - client.connect(common.PORT, addresses.INVALID_HOST); -})); diff --git a/cli/tests/node_compat/test/parallel/test-buffer-sharedarraybuffer.js b/cli/tests/node_compat/test/parallel/test-buffer-sharedarraybuffer.js deleted file mode 100644 index 9ec8f1a6d..000000000 --- a/cli/tests/node_compat/test/parallel/test-buffer-sharedarraybuffer.js +++ /dev/null @@ -1,34 +0,0 @@ -// deno-fmt-ignore-file -// deno-lint-ignore-file - -// Copyright Joyent and Node contributors. All rights reserved. MIT license. -// Taken from Node 18.12.1 -// This file is automatically generated by "node/_tools/setup.ts". Do not modify this file manually - -'use strict'; - -require('../common'); -const assert = require('assert'); - -const sab = new SharedArrayBuffer(24); -const arr1 = new Uint16Array(sab); -const arr2 = new Uint16Array(12); -arr2[0] = 5000; -arr1[0] = 5000; -arr1[1] = 4000; -arr2[1] = 4000; - -const arr_buf = Buffer.from(arr1.buffer); -const ar_buf = Buffer.from(arr2.buffer); - -assert.deepStrictEqual(arr_buf, ar_buf); - -arr1[1] = 6000; -arr2[1] = 6000; - -assert.deepStrictEqual(arr_buf, ar_buf); - -// Checks for calling Buffer.byteLength on a SharedArrayBuffer. -assert.strictEqual(Buffer.byteLength(sab), sab.byteLength); - -Buffer.from({ buffer: sab }); // Should not throw. diff --git a/cli/tests/node_compat/test/parallel/test-buffer-write.js b/cli/tests/node_compat/test/parallel/test-buffer-write.js deleted file mode 100644 index 5ca26c96d..000000000 --- a/cli/tests/node_compat/test/parallel/test-buffer-write.js +++ /dev/null @@ -1,115 +0,0 @@ -// deno-fmt-ignore-file -// deno-lint-ignore-file - -// Copyright Joyent and Node contributors. All rights reserved. MIT license. -// Taken from Node 18.12.1 -// This file is automatically generated by "node/_tools/setup.ts". Do not modify this file manually - -'use strict'; - -const common = require('../common'); -const assert = require('assert'); - -[-1, 10].forEach((offset) => { - assert.throws( - () => Buffer.alloc(9).write('foo', offset), - { - code: 'ERR_OUT_OF_RANGE', - name: 'RangeError', - message: 'The value of "offset" is out of range. ' + - `It must be >= 0 && <= 9. Received ${offset}` - } - ); -}); - -const resultMap = new Map([ - ['utf8', Buffer.from([102, 111, 111, 0, 0, 0, 0, 0, 0])], - ['ucs2', Buffer.from([102, 0, 111, 0, 111, 0, 0, 0, 0])], - ['ascii', Buffer.from([102, 111, 111, 0, 0, 0, 0, 0, 0])], - ['latin1', Buffer.from([102, 111, 111, 0, 0, 0, 0, 0, 0])], - ['binary', Buffer.from([102, 111, 111, 0, 0, 0, 0, 0, 0])], - ['utf16le', Buffer.from([102, 0, 111, 0, 111, 0, 0, 0, 0])], - ['base64', Buffer.from([102, 111, 111, 0, 0, 0, 0, 0, 0])], - ['base64url', Buffer.from([102, 111, 111, 0, 0, 0, 0, 0, 0])], - ['hex', Buffer.from([102, 111, 111, 0, 0, 0, 0, 0, 0])], -]); - -// utf8, ucs2, ascii, latin1, utf16le -const encodings = ['utf8', 'utf-8', 'ucs2', 'ucs-2', 'ascii', 'latin1', - 'binary', 'utf16le', 'utf-16le']; - -encodings - .reduce((es, e) => es.concat(e, e.toUpperCase()), []) - .forEach((encoding) => { - const buf = Buffer.alloc(9); - const len = Buffer.byteLength('foo', encoding); - assert.strictEqual(buf.write('foo', 0, len, encoding), len); - - if (encoding.includes('-')) - encoding = encoding.replace('-', ''); - - assert.deepStrictEqual(buf, resultMap.get(encoding.toLowerCase())); - }); - -// base64 -['base64', 'BASE64', 'base64url', 'BASE64URL'].forEach((encoding) => { - const buf = Buffer.alloc(9); - const len = Buffer.byteLength('Zm9v', encoding); - - assert.strictEqual(buf.write('Zm9v', 0, len, encoding), len); - assert.deepStrictEqual(buf, resultMap.get(encoding.toLowerCase())); -}); - -// hex -['hex', 'HEX'].forEach((encoding) => { - const buf = Buffer.alloc(9); - const len = Buffer.byteLength('666f6f', encoding); - - assert.strictEqual(buf.write('666f6f', 0, len, encoding), len); - assert.deepStrictEqual(buf, resultMap.get(encoding.toLowerCase())); -}); - -// Invalid encodings -for (let i = 1; i < 10; i++) { - const encoding = String(i).repeat(i); - const error = common.expectsError({ - code: 'ERR_UNKNOWN_ENCODING', - name: 'TypeError', - message: `Unknown encoding: ${encoding}` - }); - - assert.ok(!Buffer.isEncoding(encoding)); - assert.throws(() => Buffer.alloc(9).write('foo', encoding), error); -} - -// UCS-2 overflow CVE-2018-12115 -for (let i = 1; i < 4; i++) { - // Allocate two Buffers sequentially off the pool. Run more than once in case - // we hit the end of the pool and don't get sequential allocations - const x = Buffer.allocUnsafe(4).fill(0); - const y = Buffer.allocUnsafe(4).fill(1); - // Should not write anything, pos 3 doesn't have enough room for a 16-bit char - assert.strictEqual(x.write('ыыыыыы', 3, 'ucs2'), 0); - // CVE-2018-12115 experienced via buffer overrun to next block in the pool - assert.strictEqual(Buffer.compare(y, Buffer.alloc(4, 1)), 0); -} - -// Should not write any data when there is no space for 16-bit chars -const z = Buffer.alloc(4, 0); -assert.strictEqual(z.write('\u0001', 3, 'ucs2'), 0); -assert.strictEqual(Buffer.compare(z, Buffer.alloc(4, 0)), 0); -// Make sure longer strings are written up to the buffer end. -assert.strictEqual(z.write('abcd', 2), 2); -assert.deepStrictEqual([...z], [0, 0, 0x61, 0x62]); - -// Large overrun could corrupt the process -assert.strictEqual(Buffer.alloc(4) - .write('ыыыыыы'.repeat(100), 3, 'utf16le'), 0); - -{ - // .write() does not affect the byte after the written-to slice of the Buffer. - // Refs: https://github.com/nodejs/node/issues/26422 - const buf = Buffer.alloc(8); - assert.strictEqual(buf.write('ыы', 1, 'utf16le'), 4); - assert.deepStrictEqual([...buf], [0, 0x4b, 0x04, 0x4b, 0x04, 0, 0, 0]); -} diff --git a/cli/tests/node_compat/test/parallel/test-dgram-address.js b/cli/tests/node_compat/test/parallel/test-dgram-address.js deleted file mode 100644 index ffcf8485e..000000000 --- a/cli/tests/node_compat/test/parallel/test-dgram-address.js +++ /dev/null @@ -1,88 +0,0 @@ -// deno-fmt-ignore-file -// deno-lint-ignore-file - -// Copyright Joyent and Node contributors. All rights reserved. MIT license. -// Taken from Node 18.12.1 -// This file is automatically generated by "node/_tools/setup.ts". Do not modify this file manually - -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -'use strict'; -const common = require('../common'); -const assert = require('assert'); -const dgram = require('dgram'); - -{ - // IPv4 Test - const socket = dgram.createSocket('udp4'); - - socket.on('listening', common.mustCall(() => { - const address = socket.address(); - - assert.strictEqual(address.address, common.localhostIPv4); - assert.strictEqual(typeof address.port, 'number'); - assert.ok(isFinite(address.port)); - assert.ok(address.port > 0); - assert.strictEqual(address.family, 'IPv4'); - socket.close(); - })); - - socket.on('error', (err) => { - socket.close(); - assert.fail(`Unexpected error on udp4 socket. ${err.toString()}`); - }); - - socket.bind(0, common.localhostIPv4); -} - -if (common.hasIPv6) { - // IPv6 Test - const socket = dgram.createSocket('udp6'); - const localhost = '::1'; - - socket.on('listening', common.mustCall(() => { - const address = socket.address(); - - assert.strictEqual(address.address, localhost); - assert.strictEqual(typeof address.port, 'number'); - assert.ok(isFinite(address.port)); - assert.ok(address.port > 0); - assert.strictEqual(address.family, 'IPv6'); - socket.close(); - })); - - socket.on('error', (err) => { - socket.close(); - assert.fail(`Unexpected error on udp6 socket. ${err.toString()}`); - }); - - socket.bind(0, localhost); -} - -{ - // Verify that address() throws if the socket is not bound. - const socket = dgram.createSocket('udp4'); - - assert.throws(() => { - socket.address(); - }, /^Error: getsockname EBADF$/); -} diff --git a/cli/tests/node_compat/test/parallel/test-dgram-bind-default-address.js b/cli/tests/node_compat/test/parallel/test-dgram-bind-default-address.js deleted file mode 100644 index 9a6e1412c..000000000 --- a/cli/tests/node_compat/test/parallel/test-dgram-bind-default-address.js +++ /dev/null @@ -1,60 +0,0 @@ -// deno-fmt-ignore-file -// deno-lint-ignore-file - -// Copyright Joyent and Node contributors. All rights reserved. MIT license. -// Taken from Node 18.12.1 -// This file is automatically generated by "node/_tools/setup.ts". Do not modify this file manually - -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -'use strict'; -const common = require('../common'); -// Skip test in FreeBSD jails since 0.0.0.0 will resolve to default interface -if (common.inFreeBSDJail) - common.skip('In a FreeBSD jail'); - -const assert = require('assert'); -const dgram = require('dgram'); - -dgram.createSocket('udp4').bind(0, common.mustCall(function() { - assert.strictEqual(typeof this.address().port, 'number'); - assert.ok(isFinite(this.address().port)); - assert.ok(this.address().port > 0); - assert.strictEqual(this.address().address, '0.0.0.0'); - this.close(); -})); - -if (!common.hasIPv6) { - common.printSkipMessage('udp6 part of test, because no IPv6 support'); - return; -} - -dgram.createSocket('udp6').bind(0, common.mustCall(function() { - assert.strictEqual(typeof this.address().port, 'number'); - assert.ok(isFinite(this.address().port)); - assert.ok(this.address().port > 0); - let address = this.address().address; - if (address === '::ffff:0.0.0.0') - address = '::'; - assert.strictEqual(address, '::'); - this.close(); -})); diff --git a/cli/tests/node_compat/test/parallel/test-dgram-bind.js b/cli/tests/node_compat/test/parallel/test-dgram-bind.js deleted file mode 100644 index 93d68fd8a..000000000 --- a/cli/tests/node_compat/test/parallel/test-dgram-bind.js +++ /dev/null @@ -1,50 +0,0 @@ -// deno-fmt-ignore-file -// deno-lint-ignore-file - -// Copyright Joyent and Node contributors. All rights reserved. MIT license. -// Taken from Node 18.12.1 -// This file is automatically generated by "node/_tools/setup.ts". Do not modify this file manually - -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -'use strict'; -const common = require('../common'); -const assert = require('assert'); -const dgram = require('dgram'); - -const socket = dgram.createSocket('udp4'); - -socket.on('listening', common.mustCall(() => { - assert.throws(() => { - socket.bind(); - }, { - code: 'ERR_SOCKET_ALREADY_BOUND', - name: 'Error', - message: /^Socket is already bound$/ - }); - - socket.close(); -})); - -const result = socket.bind(); // Should not throw. - -assert.strictEqual(result, socket); // Should have returned itself. diff --git a/cli/tests/node_compat/test/parallel/test-dgram-bytes-length.js b/cli/tests/node_compat/test/parallel/test-dgram-bytes-length.js deleted file mode 100644 index 4ce2dabc3..000000000 --- a/cli/tests/node_compat/test/parallel/test-dgram-bytes-length.js +++ /dev/null @@ -1,46 +0,0 @@ -// deno-fmt-ignore-file -// deno-lint-ignore-file - -// Copyright Joyent and Node contributors. All rights reserved. MIT license. -// Taken from Node 18.12.1 -// This file is automatically generated by "node/_tools/setup.ts". Do not modify this file manually - -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -'use strict'; -require('../common'); -const assert = require('assert'); -const dgram = require('dgram'); - -const message = Buffer.from('Some bytes'); -const client = dgram.createSocket('udp4'); -client.send( - message, - 0, - message.length, - 41234, - 'localhost', - function(err, bytes) { - assert.strictEqual(bytes, message.length); - client.close(); - } -); diff --git a/cli/tests/node_compat/test/parallel/test-dgram-close-in-listening.js b/cli/tests/node_compat/test/parallel/test-dgram-close-in-listening.js deleted file mode 100644 index 673b145b8..000000000 --- a/cli/tests/node_compat/test/parallel/test-dgram-close-in-listening.js +++ /dev/null @@ -1,33 +0,0 @@ -// deno-fmt-ignore-file -// deno-lint-ignore-file - -// Copyright Joyent and Node contributors. All rights reserved. MIT license. -// Taken from Node 18.12.1 -// This file is automatically generated by "node/_tools/setup.ts". Do not modify this file manually - -'use strict'; -// Ensure that if a dgram socket is closed before the sendQueue is drained -// will not crash - -const common = require('../common'); -const dgram = require('dgram'); - -const buf = Buffer.alloc(1024, 42); - -const socket = dgram.createSocket('udp4'); - -socket.on('listening', function() { - socket.close(); -}); - -// Get a random port for send -const portGetter = dgram.createSocket('udp4') - .bind(0, 'localhost', common.mustCall(() => { - // Adds a listener to 'listening' to send the data when - // the socket is available - socket.send(buf, 0, buf.length, - portGetter.address().port, - portGetter.address().address); - - portGetter.close(); - })); diff --git a/cli/tests/node_compat/test/parallel/test-dgram-close-is-not-callback.js b/cli/tests/node_compat/test/parallel/test-dgram-close-is-not-callback.js deleted file mode 100644 index d67bf5aa4..000000000 --- a/cli/tests/node_compat/test/parallel/test-dgram-close-is-not-callback.js +++ /dev/null @@ -1,28 +0,0 @@ -// deno-fmt-ignore-file -// deno-lint-ignore-file - -// Copyright Joyent and Node contributors. All rights reserved. MIT license. -// Taken from Node 18.12.1 -// This file is automatically generated by "node/_tools/setup.ts". Do not modify this file manually - -'use strict'; -const common = require('../common'); -const dgram = require('dgram'); - -const buf = Buffer.alloc(1024, 42); - -const socket = dgram.createSocket('udp4'); - -// Get a random port for send -const portGetter = dgram.createSocket('udp4') - .bind(0, 'localhost', common.mustCall(() => { - socket.send(buf, 0, buf.length, - portGetter.address().port, - portGetter.address().address); - - // If close callback is not function, ignore the argument. - socket.close('bad argument'); - portGetter.close(); - - socket.on('close', common.mustCall()); - })); diff --git a/cli/tests/node_compat/test/parallel/test-dgram-close.js b/cli/tests/node_compat/test/parallel/test-dgram-close.js deleted file mode 100644 index 46dfd8014..000000000 --- a/cli/tests/node_compat/test/parallel/test-dgram-close.js +++ /dev/null @@ -1,63 +0,0 @@ -// deno-fmt-ignore-file -// deno-lint-ignore-file - -// Copyright Joyent and Node contributors. All rights reserved. MIT license. -// Taken from Node 18.12.1 -// This file is automatically generated by "node/_tools/setup.ts". Do not modify this file manually - -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -// Flags: --expose-internals -'use strict'; -// Ensure that if a dgram socket is closed before the DNS lookup completes, it -// won't crash. - -const common = require('../common'); -const assert = require('assert'); -const dgram = require('dgram'); -const { kStateSymbol } = require('internal/dgram'); - -const buf = Buffer.alloc(1024, 42); - -let socket = dgram.createSocket('udp4'); -const { handle } = socket[kStateSymbol]; - -// Get a random port for send -const portGetter = dgram.createSocket('udp4') - .bind(0, 'localhost', common.mustCall(() => { - socket.send(buf, 0, buf.length, - portGetter.address().port, - portGetter.address().address); - - assert.strictEqual(socket.close(common.mustCall()), socket); - socket.on('close', common.mustCall()); - socket = null; - - // Verify that accessing handle after closure doesn't throw - setImmediate(function() { - setImmediate(function() { - console.log('Handle fd is: ', handle.fd); - }); - }); - - portGetter.close(); - })); diff --git a/cli/tests/node_compat/test/parallel/test-dgram-connect-send-callback-buffer-length.js b/cli/tests/node_compat/test/parallel/test-dgram-connect-send-callback-buffer-length.js deleted file mode 100644 index 87f878754..000000000 --- a/cli/tests/node_compat/test/parallel/test-dgram-connect-send-callback-buffer-length.js +++ /dev/null @@ -1,30 +0,0 @@ -// deno-fmt-ignore-file -// deno-lint-ignore-file - -// Copyright Joyent and Node contributors. All rights reserved. MIT license. -// Taken from Node 18.12.1 -// This file is automatically generated by "node/_tools/setup.ts". Do not modify this file manually - -'use strict'; - -const common = require('../common'); -const assert = require('assert'); - -const dgram = require('dgram'); -const client = dgram.createSocket('udp4'); - -const buf = Buffer.allocUnsafe(256); -const offset = 20; -const len = buf.length - offset; - -const messageSent = common.mustSucceed(function messageSent(bytes) { - assert.notStrictEqual(bytes, buf.length); - assert.strictEqual(bytes, buf.length - offset); - client.close(); -}); - -client.bind(0, common.mustCall(() => { - client.connect(client.address().port, common.mustCall(() => { - client.send(buf, offset, len, messageSent); - })); -})); diff --git a/cli/tests/node_compat/test/parallel/test-dgram-connect-send-callback-buffer.js b/cli/tests/node_compat/test/parallel/test-dgram-connect-send-callback-buffer.js deleted file mode 100644 index 3b1948cc0..000000000 --- a/cli/tests/node_compat/test/parallel/test-dgram-connect-send-callback-buffer.js +++ /dev/null @@ -1,27 +0,0 @@ -// deno-fmt-ignore-file -// deno-lint-ignore-file - -// Copyright Joyent and Node contributors. All rights reserved. MIT license. -// Taken from Node 18.12.1 -// This file is automatically generated by "node/_tools/setup.ts". Do not modify this file manually - -'use strict'; - -const common = require('../common'); -const assert = require('assert'); -const dgram = require('dgram'); - -const client = dgram.createSocket('udp4'); - -const buf = Buffer.allocUnsafe(256); - -const onMessage = common.mustSucceed((bytes) => { - assert.strictEqual(bytes, buf.length); - client.close(); -}); - -client.bind(0, common.mustCall(() => { - client.connect(client.address().port, common.mustCall(() => { - client.send(buf, onMessage); - })); -})); diff --git a/cli/tests/node_compat/test/parallel/test-dgram-connect-send-callback-multi-buffer.js b/cli/tests/node_compat/test/parallel/test-dgram-connect-send-callback-multi-buffer.js deleted file mode 100644 index 365d0c4e7..000000000 --- a/cli/tests/node_compat/test/parallel/test-dgram-connect-send-callback-multi-buffer.js +++ /dev/null @@ -1,36 +0,0 @@ -// deno-fmt-ignore-file -// deno-lint-ignore-file - -// Copyright Joyent and Node contributors. All rights reserved. MIT license. -// Taken from Node 18.12.1 -// This file is automatically generated by "node/_tools/setup.ts". Do not modify this file manually - -'use strict'; - -const common = require('../common'); -const assert = require('assert'); -const dgram = require('dgram'); - -const client = dgram.createSocket('udp4'); - -const messageSent = common.mustCall((err, bytes) => { - assert.strictEqual(bytes, buf1.length + buf2.length); -}); - -const buf1 = Buffer.alloc(256, 'x'); -const buf2 = Buffer.alloc(256, 'y'); - -client.on('listening', common.mustCall(() => { - const port = client.address().port; - client.connect(port, common.mustCall(() => { - client.send([buf1, buf2], messageSent); - })); -})); - -client.on('message', common.mustCall((buf, info) => { - const expected = Buffer.concat([buf1, buf2]); - assert.ok(buf.equals(expected), 'message was received correctly'); - client.close(); -})); - -client.bind(0); diff --git a/cli/tests/node_compat/test/parallel/test-dgram-connect-send-default-host.js b/cli/tests/node_compat/test/parallel/test-dgram-connect-send-default-host.js deleted file mode 100644 index 3b2a579c0..000000000 --- a/cli/tests/node_compat/test/parallel/test-dgram-connect-send-default-host.js +++ /dev/null @@ -1,55 +0,0 @@ -// deno-fmt-ignore-file -// deno-lint-ignore-file - -// Copyright Joyent and Node contributors. All rights reserved. MIT license. -// Taken from Node 18.12.1 -// This file is automatically generated by "node/_tools/setup.ts". Do not modify this file manually - -'use strict'; - -const common = require('../common'); -const assert = require('assert'); -const dgram = require('dgram'); - -const client = dgram.createSocket('udp4'); -const server = dgram.createSocket('udp4'); - -const toSend = [Buffer.alloc(256, 'x'), - Buffer.alloc(256, 'y'), - Buffer.alloc(256, 'z'), - 'hello']; - -const received = []; - -server.on('listening', common.mustCall(() => { - const port = server.address().port; - client.connect(port, (err) => { - assert.ifError(err); - client.send(toSend[0], 0, toSend[0].length); - client.send(toSend[1]); - client.send([toSend[2]]); - client.send(toSend[3], 0, toSend[3].length); - - client.send(new Uint8Array(toSend[0]), 0, toSend[0].length); - client.send(new Uint8Array(toSend[1])); - client.send([new Uint8Array(toSend[2])]); - client.send(new Uint8Array(Buffer.from(toSend[3])), - 0, toSend[3].length); - }); -})); - -server.on('message', common.mustCall((buf, info) => { - received.push(buf.toString()); - - if (received.length === toSend.length * 2) { - // The replies may arrive out of order -> sort them before checking. - received.sort(); - - const expected = toSend.concat(toSend).map(String).sort(); - assert.deepStrictEqual(received, expected); - client.close(); - server.close(); - } -}, toSend.length * 2)); - -server.bind(0); diff --git a/cli/tests/node_compat/test/parallel/test-dgram-connect-send-empty-array.js b/cli/tests/node_compat/test/parallel/test-dgram-connect-send-empty-array.js deleted file mode 100644 index 3ca2f930b..000000000 --- a/cli/tests/node_compat/test/parallel/test-dgram-connect-send-empty-array.js +++ /dev/null @@ -1,29 +0,0 @@ -// deno-fmt-ignore-file -// deno-lint-ignore-file - -// Copyright Joyent and Node contributors. All rights reserved. MIT license. -// Taken from Node 18.12.1 -// This file is automatically generated by "node/_tools/setup.ts". Do not modify this file manually - -'use strict'; - -const common = require('../common'); - -const assert = require('assert'); -const dgram = require('dgram'); - -const client = dgram.createSocket('udp4'); - -client.on('message', common.mustCall((buf, info) => { - const expected = Buffer.alloc(0); - assert.ok(buf.equals(expected), `Expected empty message but got ${buf}`); - client.close(); -})); - -client.on('listening', common.mustCall(() => { - client.connect(client.address().port, - common.localhostIPv4, - common.mustCall(() => client.send([]))); -})); - -client.bind(0); diff --git a/cli/tests/node_compat/test/parallel/test-dgram-connect-send-empty-buffer.js b/cli/tests/node_compat/test/parallel/test-dgram-connect-send-empty-buffer.js deleted file mode 100644 index 07a841305..000000000 --- a/cli/tests/node_compat/test/parallel/test-dgram-connect-send-empty-buffer.js +++ /dev/null @@ -1,27 +0,0 @@ -// deno-fmt-ignore-file -// deno-lint-ignore-file - -// Copyright Joyent and Node contributors. All rights reserved. MIT license. -// Taken from Node 18.12.1 -// This file is automatically generated by "node/_tools/setup.ts". Do not modify this file manually - -'use strict'; -const common = require('../common'); - -const assert = require('assert'); -const dgram = require('dgram'); - -const client = dgram.createSocket('udp4'); - -client.bind(0, common.mustCall(function() { - const port = this.address().port; - client.connect(port, common.mustCall(() => { - const buf = Buffer.alloc(0); - client.send(buf, 0, 0, common.mustSucceed()); - })); - - client.on('message', common.mustCall((buffer) => { - assert.strictEqual(buffer.length, 0); - client.close(); - })); -})); diff --git a/cli/tests/node_compat/test/parallel/test-dgram-connect-send-empty-packet.js b/cli/tests/node_compat/test/parallel/test-dgram-connect-send-empty-packet.js deleted file mode 100644 index 04bb36ab6..000000000 --- a/cli/tests/node_compat/test/parallel/test-dgram-connect-send-empty-packet.js +++ /dev/null @@ -1,35 +0,0 @@ -// deno-fmt-ignore-file -// deno-lint-ignore-file - -// Copyright Joyent and Node contributors. All rights reserved. MIT license. -// Taken from Node 18.12.1 -// This file is automatically generated by "node/_tools/setup.ts". Do not modify this file manually - -'use strict'; -const common = require('../common'); - -const assert = require('assert'); -const dgram = require('dgram'); - -const client = dgram.createSocket('udp4'); - -client.bind(0, common.mustCall(function() { - client.connect(client.address().port, common.mustCall(() => { - client.on('message', common.mustCall(callback)); - const buf = Buffer.alloc(1); - - const interval = setInterval(function() { - client.send(buf, 0, 0, common.mustCall(callback)); - }, 10); - - function callback(firstArg) { - // If client.send() callback, firstArg should be null. - // If client.on('message') listener, firstArg should be a 0-length buffer. - if (firstArg instanceof Buffer) { - assert.strictEqual(firstArg.length, 0); - clearInterval(interval); - client.close(); - } - } - })); -})); diff --git a/cli/tests/node_compat/test/parallel/test-dgram-connect-send-multi-buffer-copy.js b/cli/tests/node_compat/test/parallel/test-dgram-connect-send-multi-buffer-copy.js deleted file mode 100644 index aec62ee51..000000000 --- a/cli/tests/node_compat/test/parallel/test-dgram-connect-send-multi-buffer-copy.js +++ /dev/null @@ -1,36 +0,0 @@ -// deno-fmt-ignore-file -// deno-lint-ignore-file - -// Copyright Joyent and Node contributors. All rights reserved. MIT license. -// Taken from Node 18.12.1 -// This file is automatically generated by "node/_tools/setup.ts". Do not modify this file manually - -'use strict'; - -const common = require('../common'); -const assert = require('assert'); -const dgram = require('dgram'); - -const client = dgram.createSocket('udp4'); - -const onMessage = common.mustCall(common.mustSucceed((bytes) => { - assert.strictEqual(bytes, buf1.length + buf2.length); -})); - -const buf1 = Buffer.alloc(256, 'x'); -const buf2 = Buffer.alloc(256, 'y'); - -client.on('listening', common.mustCall(function() { - const toSend = [buf1, buf2]; - client.connect(client.address().port, common.mustCall(() => { - client.send(toSend, onMessage); - })); -})); - -client.on('message', common.mustCall(function onMessage(buf, info) { - const expected = Buffer.concat([buf1, buf2]); - assert.ok(buf.equals(expected), 'message was received correctly'); - client.close(); -})); - -client.bind(0); diff --git a/cli/tests/node_compat/test/parallel/test-dgram-connect-send-multi-string-array.js b/cli/tests/node_compat/test/parallel/test-dgram-connect-send-multi-string-array.js deleted file mode 100644 index daf787e25..000000000 --- a/cli/tests/node_compat/test/parallel/test-dgram-connect-send-multi-string-array.js +++ /dev/null @@ -1,24 +0,0 @@ -// deno-fmt-ignore-file -// deno-lint-ignore-file - -// Copyright Joyent and Node contributors. All rights reserved. MIT license. -// Taken from Node 18.12.1 -// This file is automatically generated by "node/_tools/setup.ts". Do not modify this file manually - -'use strict'; -const common = require('../common'); -const assert = require('assert'); -const dgram = require('dgram'); -const socket = dgram.createSocket('udp4'); -const data = ['foo', 'bar', 'baz']; - -socket.on('message', common.mustCall((msg, rinfo) => { - socket.close(); - assert.deepStrictEqual(msg.toString(), data.join('')); -})); - -socket.bind(0, () => { - socket.connect(socket.address().port, common.mustCall(() => { - socket.send(data); - })); -}); diff --git a/cli/tests/node_compat/test/parallel/test-dgram-connect.js b/cli/tests/node_compat/test/parallel/test-dgram-connect.js deleted file mode 100644 index 41d6a6062..000000000 --- a/cli/tests/node_compat/test/parallel/test-dgram-connect.js +++ /dev/null @@ -1,73 +0,0 @@ -// deno-fmt-ignore-file -// deno-lint-ignore-file - -// Copyright Joyent and Node contributors. All rights reserved. MIT license. -// Taken from Node 18.12.1 -// This file is automatically generated by "node/_tools/setup.ts". Do not modify this file manually - -'use strict'; - -const common = require('../common'); -const assert = require('assert'); -const dgram = require('dgram'); - -const PORT = 12345; - -const client = dgram.createSocket('udp4'); -client.connect(PORT, common.mustCall(() => { - const remoteAddr = client.remoteAddress(); - assert.strictEqual(remoteAddr.port, PORT); - assert.throws(() => { - client.connect(PORT, common.mustNotCall()); - }, { - name: 'Error', - message: 'Already connected', - code: 'ERR_SOCKET_DGRAM_IS_CONNECTED' - }); - - client.disconnect(); - assert.throws(() => { - client.disconnect(); - }, { - name: 'Error', - message: 'Not connected', - code: 'ERR_SOCKET_DGRAM_NOT_CONNECTED' - }); - - assert.throws(() => { - client.remoteAddress(); - }, { - name: 'Error', - message: 'Not connected', - code: 'ERR_SOCKET_DGRAM_NOT_CONNECTED' - }); - - client.once('connect', common.mustCall(() => client.close())); - client.connect(PORT); -})); - -assert.throws(() => { - client.connect(PORT); -}, { - name: 'Error', - message: 'Already connected', - code: 'ERR_SOCKET_DGRAM_IS_CONNECTED' -}); - -assert.throws(() => { - client.disconnect(); -}, { - name: 'Error', - message: 'Not connected', - code: 'ERR_SOCKET_DGRAM_NOT_CONNECTED' -}); - -[ 0, null, 78960, undefined ].forEach((port) => { - assert.throws(() => { - client.connect(port); - }, { - name: 'RangeError', - message: /^Port should be > 0 and < 65536/, - code: 'ERR_SOCKET_BAD_PORT' - }); -}); diff --git a/cli/tests/node_compat/test/parallel/test-dgram-createSocket-type.js b/cli/tests/node_compat/test/parallel/test-dgram-createSocket-type.js deleted file mode 100644 index afcb54ab2..000000000 --- a/cli/tests/node_compat/test/parallel/test-dgram-createSocket-type.js +++ /dev/null @@ -1,68 +0,0 @@ -// deno-fmt-ignore-file -// deno-lint-ignore-file - -// Copyright Joyent and Node contributors. All rights reserved. MIT license. -// Taken from Node 18.12.1 -// This file is automatically generated by "node/_tools/setup.ts". Do not modify this file manually - -'use strict'; -const common = require('../common'); -const assert = require('assert'); -const dgram = require('dgram'); -const invalidTypes = [ - 'test', - ['udp4'], - new String('udp4'), - 1, - {}, - true, - false, - null, - undefined, -]; -const validTypes = [ - 'udp4', - 'udp6', - { type: 'udp4' }, - { type: 'udp6' }, -]; -const errMessage = /^Bad socket type specified\. Valid types are: udp4, udp6$/; - -// Error must be thrown with invalid types -invalidTypes.forEach((invalidType) => { - assert.throws(() => { - dgram.createSocket(invalidType); - }, { - code: 'ERR_SOCKET_BAD_TYPE', - name: 'TypeError', - message: errMessage - }); -}); - -// Error must not be thrown with valid types -validTypes.forEach((validType) => { - const socket = dgram.createSocket(validType); - socket.close(); -}); - -// Ensure buffer sizes can be set -{ - const socket = dgram.createSocket({ - type: 'udp4', - recvBufferSize: 10000, - sendBufferSize: 15000 - }); - - socket.bind(common.mustCall(() => { - // note: linux will double the buffer size - assert.ok(socket.getRecvBufferSize() === 10000 || - socket.getRecvBufferSize() === 20000, - 'SO_RCVBUF not 10000 or 20000, ' + - `was ${socket.getRecvBufferSize()}`); - assert.ok(socket.getSendBufferSize() === 15000 || - socket.getSendBufferSize() === 30000, - 'SO_SNDBUF not 15000 or 30000, ' + - `was ${socket.getRecvBufferSize()}`); - socket.close(); - })); -} diff --git a/cli/tests/node_compat/test/parallel/test-dgram-error-message-address.js b/cli/tests/node_compat/test/parallel/test-dgram-error-message-address.js deleted file mode 100644 index 3bb144a89..000000000 --- a/cli/tests/node_compat/test/parallel/test-dgram-error-message-address.js +++ /dev/null @@ -1,64 +0,0 @@ -// deno-fmt-ignore-file -// deno-lint-ignore-file - -// Copyright Joyent and Node contributors. All rights reserved. MIT license. -// Taken from Node 18.12.1 -// This file is automatically generated by "node/_tools/setup.ts". Do not modify this file manually - -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -'use strict'; -const common = require('../common'); -const assert = require('assert'); -const dgram = require('dgram'); - -// IPv4 Test -const socket_ipv4 = dgram.createSocket('udp4'); - -socket_ipv4.on('listening', common.mustNotCall()); - -socket_ipv4.on('error', common.mustCall(function(e) { - assert.strictEqual(e.port, undefined); - assert.strictEqual(e.message, 'bind EADDRNOTAVAIL 1.1.1.1'); - assert.strictEqual(e.address, '1.1.1.1'); - assert.strictEqual(e.code, 'EADDRNOTAVAIL'); - socket_ipv4.close(); -})); - -socket_ipv4.bind(0, '1.1.1.1'); - -// IPv6 Test -const socket_ipv6 = dgram.createSocket('udp6'); - -socket_ipv6.on('listening', common.mustNotCall()); - -socket_ipv6.on('error', common.mustCall(function(e) { - // EAFNOSUPPORT or EPROTONOSUPPORT means IPv6 is disabled on this system. - const allowed = ['EADDRNOTAVAIL', 'EAFNOSUPPORT', 'EPROTONOSUPPORT']; - assert(allowed.includes(e.code), `'${e.code}' was not one of ${allowed}.`); - assert.strictEqual(e.port, undefined); - assert.strictEqual(e.message, `bind ${e.code} 111::1`); - assert.strictEqual(e.address, '111::1'); - socket_ipv6.close(); -})); - -socket_ipv6.bind(0, '111::1'); diff --git a/cli/tests/node_compat/test/parallel/test-dgram-implicit-bind.js b/cli/tests/node_compat/test/parallel/test-dgram-implicit-bind.js deleted file mode 100644 index 34167c95b..000000000 --- a/cli/tests/node_compat/test/parallel/test-dgram-implicit-bind.js +++ /dev/null @@ -1,53 +0,0 @@ -// deno-fmt-ignore-file -// deno-lint-ignore-file - -// Copyright Joyent and Node contributors. All rights reserved. MIT license. -// Taken from Node 18.12.1 -// This file is automatically generated by "node/_tools/setup.ts". Do not modify this file manually - -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -'use strict'; -const common = require('../common'); -const dgram = require('dgram'); - -const source = dgram.createSocket('udp4'); -const target = dgram.createSocket('udp4'); -let messages = 0; - -target.on('message', common.mustCall(function(buf) { - if (buf.toString() === 'abc') ++messages; - if (buf.toString() === 'def') ++messages; - if (messages === 2) { - source.close(); - target.close(); - } -}, 2)); - -target.on('listening', common.mustCall(function() { - // Second .send() call should not throw a bind error. - const port = this.address().port; - source.send(Buffer.from('abc'), 0, 3, port, '127.0.0.1'); - source.send(Buffer.from('def'), 0, 3, port, '127.0.0.1'); -})); - -target.bind(0); diff --git a/cli/tests/node_compat/test/parallel/test-dgram-listen-after-bind.js b/cli/tests/node_compat/test/parallel/test-dgram-listen-after-bind.js deleted file mode 100644 index 3b9fd9771..000000000 --- a/cli/tests/node_compat/test/parallel/test-dgram-listen-after-bind.js +++ /dev/null @@ -1,52 +0,0 @@ -// deno-fmt-ignore-file -// deno-lint-ignore-file - -// Copyright Joyent and Node contributors. All rights reserved. MIT license. -// Taken from Node 18.12.1 -// This file is automatically generated by "node/_tools/setup.ts". Do not modify this file manually - -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -'use strict'; -require('../common'); -const common = require('../common'); -const assert = require('assert'); -const dgram = require('dgram'); - -const socket = dgram.createSocket('udp4'); - -socket.bind(); - -let fired = false; -const timer = setTimeout(() => { - socket.close(); -}, 100); - -socket.on('listening', common.mustCall(() => { - clearTimeout(timer); - fired = true; - socket.close(); -})); - -socket.on('close', common.mustCall(() => { - assert(fired, 'listening should fire after bind'); -})); diff --git a/cli/tests/node_compat/test/parallel/test-dgram-msgsize.js b/cli/tests/node_compat/test/parallel/test-dgram-msgsize.js deleted file mode 100644 index 88587842d..000000000 --- a/cli/tests/node_compat/test/parallel/test-dgram-msgsize.js +++ /dev/null @@ -1,46 +0,0 @@ -// deno-fmt-ignore-file -// deno-lint-ignore-file - -// Copyright Joyent and Node contributors. All rights reserved. MIT license. -// Taken from Node 18.12.1 -// This file is automatically generated by "node/_tools/setup.ts". Do not modify this file manually - -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -'use strict'; -const common = require('../common'); -const assert = require('assert'); -const dgram = require('dgram'); - -// Send a too big datagram. The destination doesn't matter because it's -// not supposed to get sent out anyway. -const buf = Buffer.allocUnsafe(256 * 1024); -const sock = dgram.createSocket('udp4'); -sock.send(buf, 0, buf.length, 12345, '127.0.0.1', common.mustCall(cb)); -function cb(err) { - assert(err instanceof Error); - assert.strictEqual(err.code, 'EMSGSIZE'); - assert.strictEqual(err.address, '127.0.0.1'); - assert.strictEqual(err.port, 12345); - assert.strictEqual(err.message, 'send EMSGSIZE 127.0.0.1:12345'); - sock.close(); -} diff --git a/cli/tests/node_compat/test/parallel/test-dgram-oob-buffer.js b/cli/tests/node_compat/test/parallel/test-dgram-oob-buffer.js deleted file mode 100644 index 6ab59420c..000000000 --- a/cli/tests/node_compat/test/parallel/test-dgram-oob-buffer.js +++ /dev/null @@ -1,52 +0,0 @@ -// deno-fmt-ignore-file -// deno-lint-ignore-file - -// Copyright Joyent and Node contributors. All rights reserved. MIT license. -// Taken from Node 18.12.1 -// This file is automatically generated by "node/_tools/setup.ts". Do not modify this file manually - -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -'use strict'; -// Some operating systems report errors when an UDP message is sent to an -// unreachable host. This error can be reported by sendto() and even by -// recvfrom(). Node should not propagate this error to the user. - -const common = require('../common'); -const dgram = require('dgram'); - -const socket = dgram.createSocket('udp4'); -const buf = Buffer.from([1, 2, 3, 4]); -const portGetter = dgram.createSocket('udp4') - .bind(0, 'localhost', common.mustCall(() => { - const { address, port } = portGetter.address(); - portGetter.close(common.mustCall(() => { - socket.send(buf, 0, 0, port, address, common.mustNotCall()); - socket.send(buf, 0, 4, port, address, common.mustNotCall()); - socket.send(buf, 1, 3, port, address, common.mustNotCall()); - socket.send(buf, 3, 1, port, address, common.mustNotCall()); - // Since length of zero means nothing, don't error despite OOB. - socket.send(buf, 4, 0, port, address, common.mustNotCall()); - - socket.close(); - })); - })); diff --git a/cli/tests/node_compat/test/parallel/test-dgram-recv-error.js b/cli/tests/node_compat/test/parallel/test-dgram-recv-error.js deleted file mode 100644 index 11b2633d8..000000000 --- a/cli/tests/node_compat/test/parallel/test-dgram-recv-error.js +++ /dev/null @@ -1,26 +0,0 @@ -// deno-fmt-ignore-file -// deno-lint-ignore-file - -// Copyright Joyent and Node contributors. All rights reserved. MIT license. -// Taken from Node 18.12.1 -// This file is automatically generated by "node/_tools/setup.ts". Do not modify this file manually - -// Flags: --expose-internals -'use strict'; -const common = require('../common'); -const assert = require('assert'); -const dgram = require('dgram'); -const { kStateSymbol } = require('internal/dgram'); -const s = dgram.createSocket('udp4'); -const { handle } = s[kStateSymbol]; - -s.on('error', common.mustCall((err) => { - s.close(); - - // Don't check the full error message, as the errno is not important here. - assert.match(String(err), /^Error: recvmsg/); - assert.strictEqual(err.syscall, 'recvmsg'); -})); - -s.on('message', common.mustNotCall('no message should be received.')); -s.bind(common.mustCall(() => handle.onmessage(-1, handle, null, null))); diff --git a/cli/tests/node_compat/test/parallel/test-dgram-send-bad-arguments.js b/cli/tests/node_compat/test/parallel/test-dgram-send-bad-arguments.js deleted file mode 100644 index a465be098..000000000 --- a/cli/tests/node_compat/test/parallel/test-dgram-send-bad-arguments.js +++ /dev/null @@ -1,162 +0,0 @@ -// deno-fmt-ignore-file -// deno-lint-ignore-file - -// Copyright Joyent and Node contributors. All rights reserved. MIT license. -// Taken from Node 18.12.1 -// This file is automatically generated by "node/_tools/setup.ts". Do not modify this file manually - -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -'use strict'; -const common = require('../common'); -const assert = require('assert'); -const dgram = require('dgram'); - -const buf = Buffer.from('test'); -const host = '127.0.0.1'; -const sock = dgram.createSocket('udp4'); - -function checkArgs(connected) { - // First argument should be a buffer. - assert.throws( - () => { sock.send(); }, - { - code: 'ERR_INVALID_ARG_TYPE', - name: 'TypeError', - message: 'The "buffer" argument must be of type string or an instance ' + - 'of Buffer, TypedArray, or DataView. Received undefined' - } - ); - - // send(buf, offset, length, port, host) - if (connected) { - assert.throws( - () => { sock.send(buf, 1, 1, -1, host); }, - { - code: 'ERR_SOCKET_DGRAM_IS_CONNECTED', - name: 'Error', - message: 'Already connected' - } - ); - - assert.throws( - () => { sock.send(buf, 1, 1, 0, host); }, - { - code: 'ERR_SOCKET_DGRAM_IS_CONNECTED', - name: 'Error', - message: 'Already connected' - } - ); - - assert.throws( - () => { sock.send(buf, 1, 1, 65536, host); }, - { - code: 'ERR_SOCKET_DGRAM_IS_CONNECTED', - name: 'Error', - message: 'Already connected' - } - ); - - assert.throws( - () => { sock.send(buf, 1234, '127.0.0.1', common.mustNotCall()); }, - { - code: 'ERR_SOCKET_DGRAM_IS_CONNECTED', - name: 'Error', - message: 'Already connected' - } - ); - - const longArray = [1, 2, 3, 4, 5, 6, 7, 8]; - for (const input of ['hello', - Buffer.from('hello'), - Buffer.from('hello world').subarray(0, 5), - Buffer.from('hello world').subarray(4, 9), - Buffer.from('hello world').subarray(6), - new Uint8Array([1, 2, 3, 4, 5]), - new Uint8Array(longArray).subarray(0, 5), - new Uint8Array(longArray).subarray(2, 7), - new Uint8Array(longArray).subarray(3), - new DataView(new ArrayBuffer(5), 0), - new DataView(new ArrayBuffer(6), 1), - new DataView(new ArrayBuffer(7), 1, 5)]) { - assert.throws( - () => { sock.send(input, 6, 0); }, - { - code: 'ERR_BUFFER_OUT_OF_BOUNDS', - name: 'RangeError', - message: '"offset" is outside of buffer bounds', - } - ); - - assert.throws( - () => { sock.send(input, 0, 6); }, - { - code: 'ERR_BUFFER_OUT_OF_BOUNDS', - name: 'RangeError', - message: '"length" is outside of buffer bounds', - } - ); - - assert.throws( - () => { sock.send(input, 3, 4); }, - { - code: 'ERR_BUFFER_OUT_OF_BOUNDS', - name: 'RangeError', - message: '"length" is outside of buffer bounds', - } - ); - } - } else { - assert.throws(() => { sock.send(buf, 1, 1, -1, host); }, RangeError); - assert.throws(() => { sock.send(buf, 1, 1, 0, host); }, RangeError); - assert.throws(() => { sock.send(buf, 1, 1, 65536, host); }, RangeError); - } - - // send(buf, port, host) - assert.throws( - () => { sock.send(23, 12345, host); }, - { - code: 'ERR_INVALID_ARG_TYPE', - name: 'TypeError', - message: 'The "buffer" argument must be of type string or an instance ' + - 'of Buffer, TypedArray, or DataView. Received type number (23)' - } - ); - - // send([buf1, ..], port, host) - assert.throws( - () => { sock.send([buf, 23], 12345, host); }, - { - code: 'ERR_INVALID_ARG_TYPE', - name: 'TypeError', - message: 'The "buffer list arguments" argument must be of type string ' + - 'or an instance of Buffer, TypedArray, or DataView. ' + - 'Received an instance of Array' - } - ); -} - -checkArgs(); -sock.connect(12345, common.mustCall(() => { - checkArgs(true); - sock.close(); -})); diff --git a/cli/tests/node_compat/test/parallel/test-dgram-send-callback-buffer-empty-address.js b/cli/tests/node_compat/test/parallel/test-dgram-send-callback-buffer-empty-address.js deleted file mode 100644 index f04945597..000000000 --- a/cli/tests/node_compat/test/parallel/test-dgram-send-callback-buffer-empty-address.js +++ /dev/null @@ -1,23 +0,0 @@ -// deno-fmt-ignore-file -// deno-lint-ignore-file - -// Copyright Joyent and Node contributors. All rights reserved. MIT license. -// Taken from Node 18.12.1 -// This file is automatically generated by "node/_tools/setup.ts". Do not modify this file manually - -'use strict'; - -const common = require('../common'); -const assert = require('assert'); -const dgram = require('dgram'); - -const client = dgram.createSocket('udp4'); - -const buf = Buffer.alloc(256, 'x'); - -const onMessage = common.mustSucceed((bytes) => { - assert.strictEqual(bytes, buf.length); - client.close(); -}); - -client.bind(0, () => client.send(buf, client.address().port, onMessage)); diff --git a/cli/tests/node_compat/test/parallel/test-dgram-send-callback-buffer-length-empty-address.js b/cli/tests/node_compat/test/parallel/test-dgram-send-callback-buffer-length-empty-address.js deleted file mode 100644 index bb7095b59..000000000 --- a/cli/tests/node_compat/test/parallel/test-dgram-send-callback-buffer-length-empty-address.js +++ /dev/null @@ -1,28 +0,0 @@ -// deno-fmt-ignore-file -// deno-lint-ignore-file - -// Copyright Joyent and Node contributors. All rights reserved. MIT license. -// Taken from Node 18.12.1 -// This file is automatically generated by "node/_tools/setup.ts". Do not modify this file manually - -'use strict'; - -const common = require('../common'); -const assert = require('assert'); - -const dgram = require('dgram'); -const client = dgram.createSocket('udp4'); - -const buf = Buffer.alloc(256, 'x'); -const offset = 20; -const len = buf.length - offset; - -const onMessage = common.mustSucceed(function messageSent(bytes) { - assert.notStrictEqual(bytes, buf.length); - assert.strictEqual(bytes, buf.length - offset); - client.close(); -}); - -client.bind(0, () => client.send(buf, offset, len, - client.address().port, - onMessage)); diff --git a/cli/tests/node_compat/test/parallel/test-dgram-send-callback-buffer-length.js b/cli/tests/node_compat/test/parallel/test-dgram-send-callback-buffer-length.js deleted file mode 100644 index 03bb52a17..000000000 --- a/cli/tests/node_compat/test/parallel/test-dgram-send-callback-buffer-length.js +++ /dev/null @@ -1,50 +0,0 @@ -// deno-fmt-ignore-file -// deno-lint-ignore-file - -// Copyright Joyent and Node contributors. All rights reserved. MIT license. -// Taken from Node 18.12.1 -// This file is automatically generated by "node/_tools/setup.ts". Do not modify this file manually - -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -'use strict'; - -const common = require('../common'); -const assert = require('assert'); - -const dgram = require('dgram'); -const client = dgram.createSocket('udp4'); - -const buf = Buffer.allocUnsafe(256); -const offset = 20; -const len = buf.length - offset; - -const messageSent = common.mustSucceed(function messageSent(bytes) { - assert.notStrictEqual(bytes, buf.length); - assert.strictEqual(bytes, buf.length - offset); - client.close(); -}); - -client.bind(0, () => client.send(buf, offset, len, - client.address().port, - '127.0.0.1', - messageSent)); diff --git a/cli/tests/node_compat/test/parallel/test-dgram-send-callback-buffer.js b/cli/tests/node_compat/test/parallel/test-dgram-send-callback-buffer.js deleted file mode 100644 index c486df86b..000000000 --- a/cli/tests/node_compat/test/parallel/test-dgram-send-callback-buffer.js +++ /dev/null @@ -1,26 +0,0 @@ -// deno-fmt-ignore-file -// deno-lint-ignore-file - -// Copyright Joyent and Node contributors. All rights reserved. MIT license. -// Taken from Node 18.12.1 -// This file is automatically generated by "node/_tools/setup.ts". Do not modify this file manually - -'use strict'; - -const common = require('../common'); -const assert = require('assert'); -const dgram = require('dgram'); - -const client = dgram.createSocket('udp4'); - -const buf = Buffer.allocUnsafe(256); - -const onMessage = common.mustSucceed((bytes) => { - assert.strictEqual(bytes, buf.length); - client.close(); -}); - -client.bind(0, () => client.send(buf, - client.address().port, - common.localhostIPv4, - onMessage)); diff --git a/cli/tests/node_compat/test/parallel/test-dgram-send-callback-multi-buffer-empty-address.js b/cli/tests/node_compat/test/parallel/test-dgram-send-callback-multi-buffer-empty-address.js deleted file mode 100644 index 33bb8d7f4..000000000 --- a/cli/tests/node_compat/test/parallel/test-dgram-send-callback-multi-buffer-empty-address.js +++ /dev/null @@ -1,34 +0,0 @@ -// deno-fmt-ignore-file -// deno-lint-ignore-file - -// Copyright Joyent and Node contributors. All rights reserved. MIT license. -// Taken from Node 18.12.1 -// This file is automatically generated by "node/_tools/setup.ts". Do not modify this file manually - -'use strict'; - -const common = require('../common'); -const assert = require('assert'); -const dgram = require('dgram'); - -const client = dgram.createSocket('udp4'); - -const messageSent = common.mustSucceed(function messageSent(bytes) { - assert.strictEqual(bytes, buf1.length + buf2.length); -}); - -const buf1 = Buffer.alloc(256, 'x'); -const buf2 = Buffer.alloc(256, 'y'); - -client.on('listening', function() { - const port = this.address().port; - client.send([buf1, buf2], port, messageSent); -}); - -client.on('message', common.mustCall(function onMessage(buf) { - const expected = Buffer.concat([buf1, buf2]); - assert.ok(buf.equals(expected), 'message was received correctly'); - client.close(); -})); - -client.bind(0); diff --git a/cli/tests/node_compat/test/parallel/test-dgram-send-callback-multi-buffer.js b/cli/tests/node_compat/test/parallel/test-dgram-send-callback-multi-buffer.js deleted file mode 100644 index 3f6e79361..000000000 --- a/cli/tests/node_compat/test/parallel/test-dgram-send-callback-multi-buffer.js +++ /dev/null @@ -1,34 +0,0 @@ -// deno-fmt-ignore-file -// deno-lint-ignore-file - -// Copyright Joyent and Node contributors. All rights reserved. MIT license. -// Taken from Node 18.12.1 -// This file is automatically generated by "node/_tools/setup.ts". Do not modify this file manually - -'use strict'; - -const common = require('../common'); -const assert = require('assert'); -const dgram = require('dgram'); - -const client = dgram.createSocket('udp4'); - -const messageSent = common.mustCall((err, bytes) => { - assert.strictEqual(bytes, buf1.length + buf2.length); -}); - -const buf1 = Buffer.alloc(256, 'x'); -const buf2 = Buffer.alloc(256, 'y'); - -client.on('listening', () => { - const port = client.address().port; - client.send([buf1, buf2], port, common.localhostIPv4, messageSent); -}); - -client.on('message', common.mustCall((buf, info) => { - const expected = Buffer.concat([buf1, buf2]); - assert.ok(buf.equals(expected), 'message was received correctly'); - client.close(); -})); - -client.bind(0); diff --git a/cli/tests/node_compat/test/parallel/test-dgram-send-callback-recursive.js b/cli/tests/node_compat/test/parallel/test-dgram-send-callback-recursive.js deleted file mode 100644 index 6752cbf4a..000000000 --- a/cli/tests/node_compat/test/parallel/test-dgram-send-callback-recursive.js +++ /dev/null @@ -1,50 +0,0 @@ -// deno-fmt-ignore-file -// deno-lint-ignore-file - -// Copyright Joyent and Node contributors. All rights reserved. MIT license. -// Taken from Node 18.12.1 -// This file is automatically generated by "node/_tools/setup.ts". Do not modify this file manually - -'use strict'; -const common = require('../common'); -const assert = require('assert'); - -const dgram = require('dgram'); -const client = dgram.createSocket('udp4'); -const chunk = 'abc'; -let received = 0; -let sent = 0; -const limit = 10; -let async = false; -let port; - -function onsend() { - if (sent++ < limit) { - client.send(chunk, 0, chunk.length, port, common.localhostIPv4, onsend); - } else { - assert.strictEqual(async, true); - } -} - -client.on('listening', function() { - port = this.address().port; - - process.nextTick(() => { - async = true; - }); - - onsend(); -}); - -client.on('message', (buf, info) => { - received++; - if (received === limit) { - client.close(); - } -}); - -client.on('close', common.mustCall(function() { - assert.strictEqual(received, limit); -})); - -client.bind(0); diff --git a/cli/tests/node_compat/test/parallel/test-dgram-send-default-host.js b/cli/tests/node_compat/test/parallel/test-dgram-send-default-host.js deleted file mode 100644 index 694531347..000000000 --- a/cli/tests/node_compat/test/parallel/test-dgram-send-default-host.js +++ /dev/null @@ -1,79 +0,0 @@ -// deno-fmt-ignore-file -// deno-lint-ignore-file - -// Copyright Joyent and Node contributors. All rights reserved. MIT license. -// Taken from Node 18.12.1 -// This file is automatically generated by "node/_tools/setup.ts". Do not modify this file manually - -'use strict'; - -const common = require('../common'); -const assert = require('assert'); -const dgram = require('dgram'); - -const client = dgram.createSocket('udp4'); - -const toSend = [Buffer.alloc(256, 'x'), - Buffer.alloc(256, 'y'), - Buffer.alloc(256, 'z'), - 'hello']; - -const received = []; -let totalBytesSent = 0; -let totalBytesReceived = 0; -const arrayBufferViewsCount = common.getArrayBufferViews( - Buffer.from('') -).length; - -client.on('listening', common.mustCall(() => { - const port = client.address().port; - - client.send(toSend[0], 0, toSend[0].length, port); - client.send(toSend[1], port); - client.send([toSend[2]], port); - client.send(toSend[3], 0, toSend[3].length, port); - - totalBytesSent += toSend.map((buf) => buf.length) - .reduce((a, b) => a + b, 0); - - for (const msgBuf of common.getArrayBufferViews(toSend[0])) { - client.send(msgBuf, 0, msgBuf.byteLength, port); - totalBytesSent += msgBuf.byteLength; - } - for (const msgBuf of common.getArrayBufferViews(toSend[1])) { - client.send(msgBuf, port); - totalBytesSent += msgBuf.byteLength; - } - for (const msgBuf of common.getArrayBufferViews(toSend[2])) { - client.send([msgBuf], port); - totalBytesSent += msgBuf.byteLength; - } -})); - -client.on('message', common.mustCall((buf, info) => { - received.push(buf.toString()); - totalBytesReceived += info.size; - - if (totalBytesReceived === totalBytesSent) { - client.close(); - } - // For every buffer in `toSend`, we send the raw Buffer, - // as well as every TypedArray in getArrayBufferViews() -}, toSend.length + (toSend.length - 1) * arrayBufferViewsCount)); - -client.on('close', common.mustCall((buf, info) => { - // The replies may arrive out of order -> sort them before checking. - received.sort(); - - const repeated = [...toSend]; - for (let i = 0; i < arrayBufferViewsCount; i++) { - repeated.push(...toSend.slice(0, 3)); - } - - assert.strictEqual(totalBytesSent, totalBytesReceived); - - const expected = repeated.map(String).sort(); - assert.deepStrictEqual(received, expected); -})); - -client.bind(0); diff --git a/cli/tests/node_compat/test/parallel/test-dgram-send-empty-array.js b/cli/tests/node_compat/test/parallel/test-dgram-send-empty-array.js deleted file mode 100644 index 6554cb501..000000000 --- a/cli/tests/node_compat/test/parallel/test-dgram-send-empty-array.js +++ /dev/null @@ -1,32 +0,0 @@ -// deno-fmt-ignore-file -// deno-lint-ignore-file - -// Copyright Joyent and Node contributors. All rights reserved. MIT license. -// Taken from Node 18.12.1 -// This file is automatically generated by "node/_tools/setup.ts". Do not modify this file manually - -'use strict'; - -const common = require('../common'); - -const assert = require('assert'); -const dgram = require('dgram'); - -const client = dgram.createSocket('udp4'); - -let interval; - -client.on('message', common.mustCall(function onMessage(buf, info) { - const expected = Buffer.alloc(0); - assert.ok(buf.equals(expected), `Expected empty message but got ${buf}`); - clearInterval(interval); - client.close(); -})); - -client.on('listening', common.mustCall(function() { - interval = setInterval(function() { - client.send([], client.address().port, common.localhostIPv4); - }, 10); -})); - -client.bind(0); diff --git a/cli/tests/node_compat/test/parallel/test-dgram-send-empty-buffer.js b/cli/tests/node_compat/test/parallel/test-dgram-send-empty-buffer.js deleted file mode 100644 index 55ed56e5b..000000000 --- a/cli/tests/node_compat/test/parallel/test-dgram-send-empty-buffer.js +++ /dev/null @@ -1,50 +0,0 @@ -// deno-fmt-ignore-file -// deno-lint-ignore-file - -// Copyright Joyent and Node contributors. All rights reserved. MIT license. -// Taken from Node 18.12.1 -// This file is automatically generated by "node/_tools/setup.ts". Do not modify this file manually - -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -'use strict'; -const common = require('../common'); - -const assert = require('assert'); -const dgram = require('dgram'); - -const client = dgram.createSocket('udp4'); - -client.bind(0, common.mustCall(function() { - const port = this.address().port; - - client.on('message', common.mustCall(function onMessage(buffer) { - assert.strictEqual(buffer.length, 0); - clearInterval(interval); - client.close(); - })); - - const buf = Buffer.alloc(0); - const interval = setInterval(function() { - client.send(buf, 0, 0, port, '127.0.0.1', common.mustCall()); - }, 10); -})); diff --git a/cli/tests/node_compat/test/parallel/test-dgram-send-empty-packet.js b/cli/tests/node_compat/test/parallel/test-dgram-send-empty-packet.js deleted file mode 100644 index 78789a71a..000000000 --- a/cli/tests/node_compat/test/parallel/test-dgram-send-empty-packet.js +++ /dev/null @@ -1,36 +0,0 @@ -// deno-fmt-ignore-file -// deno-lint-ignore-file - -// Copyright Joyent and Node contributors. All rights reserved. MIT license. -// Taken from Node 18.12.1 -// This file is automatically generated by "node/_tools/setup.ts". Do not modify this file manually - -'use strict'; -const common = require('../common'); - -const assert = require('assert'); -const dgram = require('dgram'); - -const client = dgram.createSocket('udp4'); - -client.bind(0, common.mustCall(function() { - - client.on('message', common.mustCall(callback)); - - const port = this.address().port; - const buf = Buffer.alloc(1); - - const interval = setInterval(function() { - client.send(buf, 0, 0, port, '127.0.0.1', common.mustCall(callback)); - }, 10); - - function callback(firstArg) { - // If client.send() callback, firstArg should be null. - // If client.on('message') listener, firstArg should be a 0-length buffer. - if (firstArg instanceof Buffer) { - assert.strictEqual(firstArg.length, 0); - clearInterval(interval); - client.close(); - } - } -})); diff --git a/cli/tests/node_compat/test/parallel/test-dgram-send-error.js b/cli/tests/node_compat/test/parallel/test-dgram-send-error.js deleted file mode 100644 index 409097d08..000000000 --- a/cli/tests/node_compat/test/parallel/test-dgram-send-error.js +++ /dev/null @@ -1,77 +0,0 @@ -// deno-fmt-ignore-file -// deno-lint-ignore-file - -// Copyright Joyent and Node contributors. All rights reserved. MIT license. -// Taken from Node 18.12.1 -// This file is automatically generated by "node/_tools/setup.ts". Do not modify this file manually - -// Flags: --expose-internals -'use strict'; -const common = require('../common'); -const assert = require('assert'); -const dgram = require('dgram'); -const { internalBinding } = require('internal/test/binding'); -const { UV_UNKNOWN } = internalBinding('uv'); -const { getSystemErrorName } = require('util'); -const { kStateSymbol } = require('internal/dgram'); -const mockError = new Error('mock DNS error'); - -function getSocket(callback) { - const socket = dgram.createSocket('udp4'); - - socket.on('message', common.mustNotCall('Should not receive any messages.')); - socket.bind(common.mustCall(() => { - socket[kStateSymbol].handle.lookup = function(address, callback) { - process.nextTick(callback, mockError); - }; - - callback(socket); - })); - return socket; -} - -getSocket((socket) => { - socket.on('error', common.mustCall((err) => { - socket.close(); - assert.strictEqual(err, mockError); - })); - - socket.send('foo', socket.address().port, 'localhost'); -}); - -getSocket((socket) => { - const callback = common.mustCall((err) => { - socket.close(); - assert.strictEqual(err, mockError); - }); - - socket.send('foo', socket.address().port, 'localhost', callback); -}); - -{ - const socket = dgram.createSocket('udp4'); - - socket.on('message', common.mustNotCall('Should not receive any messages.')); - - socket.bind(common.mustCall(() => { - const port = socket.address().port; - const callback = common.mustCall((err) => { - socket.close(); - assert.strictEqual(err.code, 'UNKNOWN'); - assert.strictEqual(getSystemErrorName(err.errno), 'UNKNOWN'); - assert.strictEqual(err.syscall, 'send'); - assert.strictEqual(err.address, common.localhostIPv4); - assert.strictEqual(err.port, port); - assert.strictEqual( - err.message, - `${err.syscall} ${err.code} ${err.address}:${err.port}` - ); - }); - - socket[kStateSymbol].handle.send = function() { - return UV_UNKNOWN; - }; - - socket.send('foo', port, common.localhostIPv4, callback); - })); -} diff --git a/cli/tests/node_compat/test/parallel/test-dgram-send-invalid-msg-type.js b/cli/tests/node_compat/test/parallel/test-dgram-send-invalid-msg-type.js deleted file mode 100644 index 49d79c46a..000000000 --- a/cli/tests/node_compat/test/parallel/test-dgram-send-invalid-msg-type.js +++ /dev/null @@ -1,43 +0,0 @@ -// deno-fmt-ignore-file -// deno-lint-ignore-file - -// Copyright Joyent and Node contributors. All rights reserved. MIT license. -// Taken from Node 18.12.1 -// This file is automatically generated by "node/_tools/setup.ts". Do not modify this file manually - -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -'use strict'; -require('../common'); - -// This test ensures that a TypeError is raised when the argument to `send()` -// or `sendto()` is anything but a Buffer. -// https://github.com/nodejs/node-v0.x-archive/issues/4496 - -const assert = require('assert'); -const dgram = require('dgram'); - -// Should throw but not crash. -const socket = dgram.createSocket('udp4'); -assert.throws(function() { socket.send(true, 0, 1, 1, 'host'); }, TypeError); -assert.throws(function() { socket.sendto(5, 0, 1, 1, 'host'); }, TypeError); -socket.close(); diff --git a/cli/tests/node_compat/test/parallel/test-dgram-send-multi-buffer-copy.js b/cli/tests/node_compat/test/parallel/test-dgram-send-multi-buffer-copy.js deleted file mode 100644 index 437c1dc34..000000000 --- a/cli/tests/node_compat/test/parallel/test-dgram-send-multi-buffer-copy.js +++ /dev/null @@ -1,35 +0,0 @@ -// deno-fmt-ignore-file -// deno-lint-ignore-file - -// Copyright Joyent and Node contributors. All rights reserved. MIT license. -// Taken from Node 18.12.1 -// This file is automatically generated by "node/_tools/setup.ts". Do not modify this file manually - -'use strict'; - -const common = require('../common'); -const assert = require('assert'); -const dgram = require('dgram'); - -const client = dgram.createSocket('udp4'); - -const onMessage = common.mustCall(function(err, bytes) { - assert.strictEqual(bytes, buf1.length + buf2.length); -}); - -const buf1 = Buffer.alloc(256, 'x'); -const buf2 = Buffer.alloc(256, 'y'); - -client.on('listening', function() { - const toSend = [buf1, buf2]; - client.send(toSend, this.address().port, common.localhostIPv4, onMessage); - toSend.splice(0, 2); -}); - -client.on('message', common.mustCall(function onMessage(buf, info) { - const expected = Buffer.concat([buf1, buf2]); - assert.ok(buf.equals(expected), 'message was received correctly'); - client.close(); -})); - -client.bind(0); diff --git a/cli/tests/node_compat/test/parallel/test-dgram-send-multi-string-array.js b/cli/tests/node_compat/test/parallel/test-dgram-send-multi-string-array.js deleted file mode 100644 index 9754c90eb..000000000 --- a/cli/tests/node_compat/test/parallel/test-dgram-send-multi-string-array.js +++ /dev/null @@ -1,20 +0,0 @@ -// deno-fmt-ignore-file -// deno-lint-ignore-file - -// Copyright Joyent and Node contributors. All rights reserved. MIT license. -// Taken from Node 18.12.1 -// This file is automatically generated by "node/_tools/setup.ts". Do not modify this file manually - -'use strict'; -const common = require('../common'); -const assert = require('assert'); -const dgram = require('dgram'); -const socket = dgram.createSocket('udp4'); -const data = ['foo', 'bar', 'baz']; - -socket.on('message', common.mustCall((msg, rinfo) => { - socket.close(); - assert.deepStrictEqual(msg.toString(), data.join('')); -})); - -socket.bind(() => socket.send(data, socket.address().port, 'localhost')); diff --git a/cli/tests/node_compat/test/parallel/test-dgram-udp4.js b/cli/tests/node_compat/test/parallel/test-dgram-udp4.js deleted file mode 100644 index ebe5c2169..000000000 --- a/cli/tests/node_compat/test/parallel/test-dgram-udp4.js +++ /dev/null @@ -1,59 +0,0 @@ -// deno-fmt-ignore-file -// deno-lint-ignore-file - -// Copyright Joyent and Node contributors. All rights reserved. MIT license. -// Taken from Node 18.12.1 -// This file is automatically generated by "node/_tools/setup.ts". Do not modify this file manually - -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -'use strict'; -const common = require('../common'); -const assert = require('assert'); -const dgram = require('dgram'); -const message_to_send = 'A message to send'; - -const server = dgram.createSocket('udp4'); -server.on('message', common.mustCall((msg, rinfo) => { - assert.strictEqual(rinfo.address, common.localhostIPv4); - assert.strictEqual(msg.toString(), message_to_send.toString()); - server.send(msg, 0, msg.length, rinfo.port, rinfo.address); -})); -server.on('listening', common.mustCall(() => { - const client = dgram.createSocket('udp4'); - const port = server.address().port; - client.on('message', common.mustCall((msg, rinfo) => { - assert.strictEqual(rinfo.address, common.localhostIPv4); - assert.strictEqual(rinfo.port, port); - assert.strictEqual(msg.toString(), message_to_send.toString()); - client.close(); - server.close(); - })); - client.send(message_to_send, - 0, - message_to_send.length, - port, - 'localhost'); - client.on('close', common.mustCall()); -})); -server.on('close', common.mustCall()); -server.bind(0); diff --git a/cli/tests/node_compat/test/parallel/test-dgram-udp6-send-default-host.js b/cli/tests/node_compat/test/parallel/test-dgram-udp6-send-default-host.js deleted file mode 100644 index 94c9983ea..000000000 --- a/cli/tests/node_compat/test/parallel/test-dgram-udp6-send-default-host.js +++ /dev/null @@ -1,83 +0,0 @@ -// deno-fmt-ignore-file -// deno-lint-ignore-file - -// Copyright Joyent and Node contributors. All rights reserved. MIT license. -// Taken from Node 18.12.1 -// This file is automatically generated by "node/_tools/setup.ts". Do not modify this file manually - -'use strict'; - -const common = require('../common'); -if (!common.hasIPv6) - common.skip('no IPv6 support'); - -const assert = require('assert'); -const dgram = require('dgram'); - -const client = dgram.createSocket('udp6'); - -const toSend = [Buffer.alloc(256, 'x'), - Buffer.alloc(256, 'y'), - Buffer.alloc(256, 'z'), - 'hello']; - -const received = []; -let totalBytesSent = 0; -let totalBytesReceived = 0; -const arrayBufferViewLength = common.getArrayBufferViews( - Buffer.from('') -).length; - -client.on('listening', common.mustCall(() => { - const port = client.address().port; - - client.send(toSend[0], 0, toSend[0].length, port); - client.send(toSend[1], port); - client.send([toSend[2]], port); - client.send(toSend[3], 0, toSend[3].length, port); - - totalBytesSent += toSend.map((buf) => buf.length) - .reduce((a, b) => a + b, 0); - - for (const msgBuf of common.getArrayBufferViews(toSend[0])) { - client.send(msgBuf, 0, msgBuf.byteLength, port); - totalBytesSent += msgBuf.byteLength; - } - for (const msgBuf of common.getArrayBufferViews(toSend[1])) { - client.send(msgBuf, port); - totalBytesSent += msgBuf.byteLength; - } - for (const msgBuf of common.getArrayBufferViews(toSend[2])) { - client.send([msgBuf], port); - totalBytesSent += msgBuf.byteLength; - } -})); - -client.on('message', common.mustCall((buf, info) => { - received.push(buf.toString()); - totalBytesReceived += info.size; - - if (totalBytesReceived === totalBytesSent) { - client.close(); - } - // For every buffer in `toSend`, we send the raw Buffer, - // as well as every TypedArray in getArrayBufferViews() -}, toSend.length + (toSend.length - 1) * arrayBufferViewLength)); - -client.on('close', common.mustCall((buf, info) => { - // The replies may arrive out of order -> sort them before checking. - received.sort(); - - const repeated = [...toSend]; - for (let i = 0; i < arrayBufferViewLength; i++) { - // We get arrayBufferViews only for toSend[0..2]. - repeated.push(...toSend.slice(0, 3)); - } - - assert.strictEqual(totalBytesSent, totalBytesReceived); - - const expected = repeated.map(String).sort(); - assert.deepStrictEqual(received, expected); -})); - -client.bind(0); diff --git a/cli/tests/node_compat/test/parallel/test-diagnostics-channel-net.js b/cli/tests/node_compat/test/parallel/test-diagnostics-channel-net.js deleted file mode 100644 index 05405efde..000000000 --- a/cli/tests/node_compat/test/parallel/test-diagnostics-channel-net.js +++ /dev/null @@ -1,32 +0,0 @@ -// deno-fmt-ignore-file -// deno-lint-ignore-file - -// Copyright Joyent and Node contributors. All rights reserved. MIT license. -// Taken from Node 18.12.1 -// This file is automatically generated by "node/_tools/setup.ts". Do not modify this file manually - -'use strict'; -const common = require('../common'); -const assert = require('assert'); -const net = require('net'); -const dc = require('diagnostics_channel'); - -const isNetSocket = (socket) => socket instanceof net.Socket; - -dc.subscribe('net.client.socket', common.mustCall(({ socket }) => { - assert.strictEqual(isNetSocket(socket), true); -})); - -dc.subscribe('net.server.socket', common.mustCall(({ socket }) => { - assert.strictEqual(isNetSocket(socket), true); -})); - -const server = net.createServer(common.mustCall((socket) => { - socket.destroy(); - server.close(); -})); - -server.listen(() => { - const { port } = server.address(); - net.connect(port); -}); diff --git a/cli/tests/node_compat/test/parallel/test-dns-multi-channel.js b/cli/tests/node_compat/test/parallel/test-dns-multi-channel.js deleted file mode 100644 index 65d0a2f3a..000000000 --- a/cli/tests/node_compat/test/parallel/test-dns-multi-channel.js +++ /dev/null @@ -1,59 +0,0 @@ -// deno-fmt-ignore-file -// deno-lint-ignore-file - -// Copyright Joyent and Node contributors. All rights reserved. MIT license. -// Taken from Node 18.12.1 -// This file is automatically generated by "node/_tools/setup.ts". Do not modify this file manually - -'use strict'; -const common = require('../common'); -const dnstools = require('../common/dns'); -const { Resolver } = require('dns'); -const assert = require('assert'); -const dgram = require('dgram'); - -const servers = [ - { - socket: dgram.createSocket('udp4'), - reply: { type: 'A', address: '1.2.3.4', ttl: 123, domain: 'example.org' } - }, - { - socket: dgram.createSocket('udp4'), - reply: { type: 'A', address: '5.6.7.8', ttl: 123, domain: 'example.org' } - }, -]; - -let waiting = servers.length; -for (const { socket, reply } of servers) { - socket.on('message', common.mustCall((msg, { address, port }) => { - const parsed = dnstools.parseDNSPacket(msg); - const domain = parsed.questions[0].domain; - assert.strictEqual(domain, 'example.org'); - - socket.send(dnstools.writeDNSPacket({ - id: parsed.id, - questions: parsed.questions, - answers: [reply], - }), port, address); - })); - - socket.bind(0, common.mustCall(() => { - if (--waiting === 0) ready(); - })); -} - - -function ready() { - const resolvers = servers.map((server) => ({ - server, - resolver: new Resolver() - })); - - for (const { server: { socket, reply }, resolver } of resolvers) { - resolver.setServers([`127.0.0.1:${socket.address().port}`]); - resolver.resolve4('example.org', common.mustSucceed((res) => { - assert.deepStrictEqual(res, [reply.address]); - socket.close(); - })); - } -} diff --git a/cli/tests/node_compat/test/parallel/test-event-emitter-check-listener-leaks.js b/cli/tests/node_compat/test/parallel/test-event-emitter-check-listener-leaks.js deleted file mode 100644 index 977667abd..000000000 --- a/cli/tests/node_compat/test/parallel/test-event-emitter-check-listener-leaks.js +++ /dev/null @@ -1,110 +0,0 @@ -// deno-fmt-ignore-file -// deno-lint-ignore-file - -// Copyright Joyent and Node contributors. All rights reserved. MIT license. -// Taken from Node 18.12.1 -// This file is automatically generated by "node/_tools/setup.ts". Do not modify this file manually - -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -'use strict'; - -const common = require('../common'); -const assert = require('assert'); -const events = require('events'); - -// default -{ - const e = new events.EventEmitter(); - - for (let i = 0; i < 10; i++) { - e.on('default', common.mustNotCall()); - } - assert.ok(!Object.hasOwn(e._events.default, 'warned')); - e.on('default', common.mustNotCall()); - assert.ok(e._events.default.warned); - - // symbol - const symbol = Symbol('symbol'); - e.setMaxListeners(1); - e.on(symbol, common.mustNotCall()); - assert.ok(!Object.hasOwn(e._events[symbol], 'warned')); - e.on(symbol, common.mustNotCall()); - assert.ok(Object.hasOwn(e._events[symbol], 'warned')); - - // specific - e.setMaxListeners(5); - for (let i = 0; i < 5; i++) { - e.on('specific', common.mustNotCall()); - } - assert.ok(!Object.hasOwn(e._events.specific, 'warned')); - e.on('specific', common.mustNotCall()); - assert.ok(e._events.specific.warned); - - // only one - e.setMaxListeners(1); - e.on('only one', common.mustNotCall()); - assert.ok(!Object.hasOwn(e._events['only one'], 'warned')); - e.on('only one', common.mustNotCall()); - assert.ok(Object.hasOwn(e._events['only one'], 'warned')); - - // unlimited - e.setMaxListeners(0); - for (let i = 0; i < 1000; i++) { - e.on('unlimited', common.mustNotCall()); - } - assert.ok(!Object.hasOwn(e._events.unlimited, 'warned')); -} - -// process-wide -{ - events.EventEmitter.defaultMaxListeners = 42; - const e = new events.EventEmitter(); - - for (let i = 0; i < 42; ++i) { - e.on('fortytwo', common.mustNotCall()); - } - assert.ok(!Object.hasOwn(e._events.fortytwo, 'warned')); - e.on('fortytwo', common.mustNotCall()); - assert.ok(Object.hasOwn(e._events.fortytwo, 'warned')); - delete e._events.fortytwo.warned; - - events.EventEmitter.defaultMaxListeners = 44; - e.on('fortytwo', common.mustNotCall()); - assert.ok(!Object.hasOwn(e._events.fortytwo, 'warned')); - e.on('fortytwo', common.mustNotCall()); - assert.ok(Object.hasOwn(e._events.fortytwo, 'warned')); -} - -// But _maxListeners still has precedence over defaultMaxListeners -{ - events.EventEmitter.defaultMaxListeners = 42; - const e = new events.EventEmitter(); - e.setMaxListeners(1); - e.on('uno', common.mustNotCall()); - assert.ok(!Object.hasOwn(e._events.uno, 'warned')); - e.on('uno', common.mustNotCall()); - assert.ok(Object.hasOwn(e._events.uno, 'warned')); - - // chainable - assert.strictEqual(e, e.setMaxListeners(1)); -} diff --git a/cli/tests/node_compat/test/parallel/test-event-emitter-max-listeners-warning-for-null.js b/cli/tests/node_compat/test/parallel/test-event-emitter-max-listeners-warning-for-null.js deleted file mode 100644 index 0a17f5e71..000000000 --- a/cli/tests/node_compat/test/parallel/test-event-emitter-max-listeners-warning-for-null.js +++ /dev/null @@ -1,30 +0,0 @@ -// deno-fmt-ignore-file -// deno-lint-ignore-file - -// Copyright Joyent and Node contributors. All rights reserved. MIT license. -// Taken from Node 18.12.1 -// This file is automatically generated by "node/_tools/setup.ts". Do not modify this file manually - -// Flags: --no-warnings -// The flag suppresses stderr output but the warning event will still emit -'use strict'; - -const common = require('../common'); -const events = require('events'); -const assert = require('assert'); - -const e = new events.EventEmitter(); -e.setMaxListeners(1); - -process.on('warning', common.mustCall((warning) => { - assert.ok(warning instanceof Error); - assert.strictEqual(warning.name, 'MaxListenersExceededWarning'); - assert.strictEqual(warning.emitter, e); - assert.strictEqual(warning.count, 2); - assert.strictEqual(warning.type, null); - assert.ok(warning.message.includes( - '2 null listeners added to [EventEmitter].')); -})); - -e.on(null, () => {}); -e.on(null, () => {}); diff --git a/cli/tests/node_compat/test/parallel/test-event-emitter-max-listeners-warning-for-symbol.js b/cli/tests/node_compat/test/parallel/test-event-emitter-max-listeners-warning-for-symbol.js deleted file mode 100644 index 2bc5832e5..000000000 --- a/cli/tests/node_compat/test/parallel/test-event-emitter-max-listeners-warning-for-symbol.js +++ /dev/null @@ -1,32 +0,0 @@ -// deno-fmt-ignore-file -// deno-lint-ignore-file - -// Copyright Joyent and Node contributors. All rights reserved. MIT license. -// Taken from Node 18.12.1 -// This file is automatically generated by "node/_tools/setup.ts". Do not modify this file manually - -// Flags: --no-warnings -// The flag suppresses stderr output but the warning event will still emit -'use strict'; - -const common = require('../common'); -const events = require('events'); -const assert = require('assert'); - -const symbol = Symbol('symbol'); - -const e = new events.EventEmitter(); -e.setMaxListeners(1); - -process.on('warning', common.mustCall((warning) => { - assert.ok(warning instanceof Error); - assert.strictEqual(warning.name, 'MaxListenersExceededWarning'); - assert.strictEqual(warning.emitter, e); - assert.strictEqual(warning.count, 2); - assert.strictEqual(warning.type, symbol); - assert.ok(warning.message.includes( - '2 Symbol(symbol) listeners added to [EventEmitter].')); -})); - -e.on(symbol, () => {}); -e.on(symbol, () => {}); diff --git a/cli/tests/node_compat/test/parallel/test-event-emitter-max-listeners-warning.js b/cli/tests/node_compat/test/parallel/test-event-emitter-max-listeners-warning.js deleted file mode 100644 index f1a391402..000000000 --- a/cli/tests/node_compat/test/parallel/test-event-emitter-max-listeners-warning.js +++ /dev/null @@ -1,38 +0,0 @@ -// deno-fmt-ignore-file -// deno-lint-ignore-file - -// Copyright Joyent and Node contributors. All rights reserved. MIT license. -// Taken from Node 18.12.1 -// This file is automatically generated by "node/_tools/setup.ts". Do not modify this file manually - -// Flags: --no-warnings -// The flag suppresses stderr output but the warning event will still emit -'use strict'; - -const common = require('../common'); -const events = require('events'); -const assert = require('assert'); - -class FakeInput extends events.EventEmitter { - resume() {} - pause() {} - write() {} - end() {} -} - -const e = new FakeInput(); -e.setMaxListeners(1); - -process.on('warning', common.mustCall((warning) => { - assert.ok(warning instanceof Error); - assert.strictEqual(warning.name, 'MaxListenersExceededWarning'); - assert.strictEqual(warning.emitter, e); - assert.strictEqual(warning.count, 2); - assert.strictEqual(warning.type, 'event-type'); - assert.ok(warning.message.includes( - '2 event-type listeners added to [FakeInput].')); -})); - -e.on('event-type', () => {}); -e.on('event-type', () => {}); // Trigger warning. -e.on('event-type', () => {}); // Verify that warning is emitted only once. diff --git a/cli/tests/node_compat/test/parallel/test-fs-rm.js b/cli/tests/node_compat/test/parallel/test-fs-rm.js deleted file mode 100644 index d1b29b623..000000000 --- a/cli/tests/node_compat/test/parallel/test-fs-rm.js +++ /dev/null @@ -1,433 +0,0 @@ -// deno-fmt-ignore-file -// deno-lint-ignore-file - -// Copyright Joyent and Node contributors. All rights reserved. MIT license. -// Taken from Node 18.12.1 -// This file is automatically generated by "node/_tools/setup.ts". Do not modify this file manually - -// Flags: --expose-internals -'use strict'; -const common = require('../common'); -const tmpdir = require('../common/tmpdir'); -const assert = require('assert'); -const fs = require('fs'); -const path = require('path'); -const { pathToFileURL } = require('url'); -const { execSync } = require('child_process'); - -const { validateRmOptionsSync } = require('internal/fs/utils'); - -tmpdir.refresh(); - -let count = 0; -const nextDirPath = (name = 'rm') => - path.join(tmpdir.path, `${name}-${count++}`); - -const isGitPresent = (() => { - try { execSync('git --version'); return true; } catch { return false; } -})(); - -function gitInit(gitDirectory) { - fs.mkdirSync(gitDirectory); - execSync('git init', common.mustNotMutateObjectDeep({ cwd: gitDirectory })); -} - -function makeNonEmptyDirectory(depth, files, folders, dirname, createSymLinks) { - fs.mkdirSync(dirname, common.mustNotMutateObjectDeep({ recursive: true })); - fs.writeFileSync(path.join(dirname, 'text.txt'), 'hello', 'utf8'); - - const options = common.mustNotMutateObjectDeep({ flag: 'wx' }); - - for (let f = files; f > 0; f--) { - fs.writeFileSync(path.join(dirname, `f-${depth}-${f}`), '', options); - } - - if (createSymLinks) { - // Valid symlink - fs.symlinkSync( - `f-${depth}-1`, - path.join(dirname, `link-${depth}-good`), - 'file' - ); - - // Invalid symlink - fs.symlinkSync( - 'does-not-exist', - path.join(dirname, `link-${depth}-bad`), - 'file' - ); - } - - // File with a name that looks like a glob - fs.writeFileSync(path.join(dirname, '[a-z0-9].txt'), '', options); - - depth--; - if (depth <= 0) { - return; - } - - for (let f = folders; f > 0; f--) { - fs.mkdirSync( - path.join(dirname, `folder-${depth}-${f}`), - { recursive: true } - ); - makeNonEmptyDirectory( - depth, - files, - folders, - path.join(dirname, `d-${depth}-${f}`), - createSymLinks - ); - } -} - -function removeAsync(dir) { - // Removal should fail without the recursive option. - fs.rm(dir, common.mustCall((err) => { - assert.strictEqual(err.syscall, 'rm'); - - // Removal should fail without the recursive option set to true. - fs.rm(dir, common.mustNotMutateObjectDeep({ recursive: false }), common.mustCall((err) => { - assert.strictEqual(err.syscall, 'rm'); - - // Recursive removal should succeed. - fs.rm(dir, common.mustNotMutateObjectDeep({ recursive: true }), common.mustSucceed(() => { - - // Attempted removal should fail now because the directory is gone. - fs.rm(dir, common.mustCall((err) => { - assert.strictEqual(err.syscall, 'stat'); - })); - })); - })); - })); -} - -// Test the asynchronous version -{ - // Create a 4-level folder hierarchy including symlinks - let dir = nextDirPath(); - makeNonEmptyDirectory(4, 10, 2, dir, true); - removeAsync(dir); - - // Create a 2-level folder hierarchy without symlinks - dir = nextDirPath(); - makeNonEmptyDirectory(2, 10, 2, dir, false); - removeAsync(dir); - - // Same test using URL instead of a path - dir = nextDirPath(); - makeNonEmptyDirectory(2, 10, 2, dir, false); - removeAsync(pathToFileURL(dir)); - - // Create a flat folder including symlinks - dir = nextDirPath(); - makeNonEmptyDirectory(1, 10, 2, dir, true); - removeAsync(dir); - - // Should fail if target does not exist - fs.rm( - path.join(tmpdir.path, 'noexist.txt'), - common.mustNotMutateObjectDeep({ recursive: true }), - common.mustCall((err) => { - assert.strictEqual(err.code, 'ENOENT'); - }) - ); - - // Should delete a file - const filePath = path.join(tmpdir.path, 'rm-async-file.txt'); - fs.writeFileSync(filePath, ''); - fs.rm(filePath, common.mustNotMutateObjectDeep({ recursive: true }), common.mustCall((err) => { - try { - assert.strictEqual(err, null); - assert.strictEqual(fs.existsSync(filePath), false); - } finally { - fs.rmSync(filePath, common.mustNotMutateObjectDeep({ force: true })); - } - })); -} - -// Removing a .git directory should not throw an EPERM. -// Refs: https://github.com/isaacs/rimraf/issues/21. -if (isGitPresent) { - const gitDirectory = nextDirPath(); - gitInit(gitDirectory); - fs.rm(gitDirectory, common.mustNotMutateObjectDeep({ recursive: true }), common.mustSucceed(() => { - assert.strictEqual(fs.existsSync(gitDirectory), false); - })); -} - -// Test the synchronous version. -{ - const dir = nextDirPath(); - makeNonEmptyDirectory(4, 10, 2, dir, true); - - // Removal should fail without the recursive option set to true. - assert.throws(() => { - fs.rmSync(dir); - }, { syscall: 'rm' }); - assert.throws(() => { - fs.rmSync(dir, common.mustNotMutateObjectDeep({ recursive: false })); - }, { syscall: 'rm' }); - - // Should fail if target does not exist - assert.throws(() => { - fs.rmSync(path.join(tmpdir.path, 'noexist.txt'), common.mustNotMutateObjectDeep({ recursive: true })); - }, { - code: 'ENOENT', - name: 'Error', - message: /^ENOENT: no such file or directory, stat/ - }); - - // Should delete a file - const filePath = path.join(tmpdir.path, 'rm-file.txt'); - fs.writeFileSync(filePath, ''); - - try { - fs.rmSync(filePath, common.mustNotMutateObjectDeep({ recursive: true })); - } finally { - fs.rmSync(filePath, common.mustNotMutateObjectDeep({ force: true })); - } - - // Should accept URL - const fileURL = pathToFileURL(path.join(tmpdir.path, 'rm-file.txt')); - fs.writeFileSync(fileURL, ''); - - try { - fs.rmSync(fileURL, common.mustNotMutateObjectDeep({ recursive: true })); - } finally { - fs.rmSync(fileURL, common.mustNotMutateObjectDeep({ force: true })); - } - - // Recursive removal should succeed. - fs.rmSync(dir, { recursive: true }); - - // Attempted removal should fail now because the directory is gone. - assert.throws(() => fs.rmSync(dir), { syscall: 'stat' }); -} - -// Removing a .git directory should not throw an EPERM. -// Refs: https://github.com/isaacs/rimraf/issues/21. -if (isGitPresent) { - const gitDirectory = nextDirPath(); - gitInit(gitDirectory); - fs.rmSync(gitDirectory, common.mustNotMutateObjectDeep({ recursive: true })); - assert.strictEqual(fs.existsSync(gitDirectory), false); -} - -// Test the Promises based version. -(async () => { - const dir = nextDirPath(); - makeNonEmptyDirectory(4, 10, 2, dir, true); - - // Removal should fail without the recursive option set to true. - await assert.rejects(fs.promises.rm(dir), { syscall: 'rm' }); - await assert.rejects(fs.promises.rm(dir, common.mustNotMutateObjectDeep({ recursive: false })), { - syscall: 'rm' - }); - - // Recursive removal should succeed. - await fs.promises.rm(dir, common.mustNotMutateObjectDeep({ recursive: true })); - - // Attempted removal should fail now because the directory is gone. - await assert.rejects(fs.promises.rm(dir), { syscall: 'stat' }); - - // Should fail if target does not exist - await assert.rejects(fs.promises.rm( - path.join(tmpdir.path, 'noexist.txt'), - { recursive: true } - ), { - code: 'ENOENT', - name: 'Error', - message: /^ENOENT: no such file or directory, stat/ - }); - - // Should not fail if target does not exist and force option is true - await fs.promises.rm(path.join(tmpdir.path, 'noexist.txt'), common.mustNotMutateObjectDeep({ force: true })); - - // Should delete file - const filePath = path.join(tmpdir.path, 'rm-promises-file.txt'); - fs.writeFileSync(filePath, ''); - - try { - await fs.promises.rm(filePath, common.mustNotMutateObjectDeep({ recursive: true })); - } finally { - fs.rmSync(filePath, common.mustNotMutateObjectDeep({ force: true })); - } - - // Should accept URL - const fileURL = pathToFileURL(path.join(tmpdir.path, 'rm-promises-file.txt')); - fs.writeFileSync(fileURL, ''); - - try { - await fs.promises.rm(fileURL, common.mustNotMutateObjectDeep({ recursive: true })); - } finally { - fs.rmSync(fileURL, common.mustNotMutateObjectDeep({ force: true })); - } -})().then(common.mustCall()); - -// Removing a .git directory should not throw an EPERM. -// Refs: https://github.com/isaacs/rimraf/issues/21. -if (isGitPresent) { - (async () => { - const gitDirectory = nextDirPath(); - gitInit(gitDirectory); - await fs.promises.rm(gitDirectory, common.mustNotMutateObjectDeep({ recursive: true })); - assert.strictEqual(fs.existsSync(gitDirectory), false); - })().then(common.mustCall()); -} - -// Test input validation. -{ - const dir = nextDirPath(); - makeNonEmptyDirectory(4, 10, 2, dir, true); - const filePath = (path.join(tmpdir.path, 'rm-args-file.txt')); - fs.writeFileSync(filePath, ''); - - const defaults = { - retryDelay: 100, - maxRetries: 0, - recursive: false, - force: false - }; - const modified = { - retryDelay: 953, - maxRetries: 5, - recursive: true, - force: false - }; - - assert.deepStrictEqual(validateRmOptionsSync(filePath), defaults); - assert.deepStrictEqual(validateRmOptionsSync(filePath, {}), defaults); - assert.deepStrictEqual(validateRmOptionsSync(filePath, modified), modified); - assert.deepStrictEqual(validateRmOptionsSync(filePath, { - maxRetries: 99 - }), { - retryDelay: 100, - maxRetries: 99, - recursive: false, - force: false - }); - - [null, 'foo', 5, NaN].forEach((bad) => { - assert.throws(() => { - validateRmOptionsSync(filePath, bad); - }, { - code: 'ERR_INVALID_ARG_TYPE', - name: 'TypeError', - message: /^The "options" argument must be of type object\./ - }); - }); - - [undefined, null, 'foo', Infinity, function() {}].forEach((bad) => { - assert.throws(() => { - validateRmOptionsSync(filePath, { recursive: bad }); - }, { - code: 'ERR_INVALID_ARG_TYPE', - name: 'TypeError', - message: /^The "options\.recursive" property must be of type boolean\./ - }); - }); - - [undefined, null, 'foo', Infinity, function() {}].forEach((bad) => { - assert.throws(() => { - validateRmOptionsSync(filePath, { force: bad }); - }, { - code: 'ERR_INVALID_ARG_TYPE', - name: 'TypeError', - message: /^The "options\.force" property must be of type boolean\./ - }); - }); - - assert.throws(() => { - validateRmOptionsSync(filePath, { retryDelay: -1 }); - }, { - code: 'ERR_OUT_OF_RANGE', - name: 'RangeError', - message: /^The value of "options\.retryDelay" is out of range\./ - }); - - assert.throws(() => { - validateRmOptionsSync(filePath, { maxRetries: -1 }); - }, { - code: 'ERR_OUT_OF_RANGE', - name: 'RangeError', - message: /^The value of "options\.maxRetries" is out of range\./ - }); -} - -{ - // IBMi has a different access permission mechanism - // This test should not be run as `root` - if (!common.isIBMi && (common.isWindows || process.getuid() !== 0)) { - function makeDirectoryReadOnly(dir, mode) { - let accessErrorCode = 'EACCES'; - if (common.isWindows) { - accessErrorCode = 'EPERM'; - execSync(`icacls ${dir} /deny "everyone:(OI)(CI)(DE,DC)"`); - } else { - fs.chmodSync(dir, mode); - } - return accessErrorCode; - } - - function makeDirectoryWritable(dir) { - if (fs.existsSync(dir)) { - if (common.isWindows) { - execSync(`icacls ${dir} /remove:d "everyone"`); - } else { - fs.chmodSync(dir, 0o777); - } - } - } - - { - // Check that deleting a file that cannot be accessed using rmsync throws - // https://github.com/nodejs/node/issues/38683 - const dirname = nextDirPath(); - const filePath = path.join(dirname, 'text.txt'); - try { - fs.mkdirSync(dirname, common.mustNotMutateObjectDeep({ recursive: true })); - fs.writeFileSync(filePath, 'hello'); - const code = makeDirectoryReadOnly(dirname, 0o444); - assert.throws(() => { - fs.rmSync(filePath, common.mustNotMutateObjectDeep({ force: true })); - }, { - code, - name: 'Error', - }); - } finally { - makeDirectoryWritable(dirname); - } - } - - { - // Check endless recursion. - // https://github.com/nodejs/node/issues/34580 - const dirname = nextDirPath(); - fs.mkdirSync(dirname, common.mustNotMutateObjectDeep({ recursive: true })); - const root = fs.mkdtempSync(path.join(dirname, 'fs-')); - const middle = path.join(root, 'middle'); - fs.mkdirSync(middle); - fs.mkdirSync(path.join(middle, 'leaf')); // Make `middle` non-empty - try { - const code = makeDirectoryReadOnly(middle, 0o555); - try { - assert.throws(() => { - fs.rmSync(root, common.mustNotMutateObjectDeep({ recursive: true })); - }, { - code, - name: 'Error', - }); - } catch (err) { - // Only fail the test if the folder was not deleted. - // as in some cases rmSync succesfully deletes read-only folders. - if (fs.existsSync(root)) { - throw err; - } - } - } finally { - makeDirectoryWritable(middle); - } - } - } -} diff --git a/cli/tests/node_compat/test/parallel/test-fs-watch.js b/cli/tests/node_compat/test/parallel/test-fs-watch.js deleted file mode 100644 index 785d42911..000000000 --- a/cli/tests/node_compat/test/parallel/test-fs-watch.js +++ /dev/null @@ -1,105 +0,0 @@ -// deno-fmt-ignore-file -// deno-lint-ignore-file - -// Copyright Joyent and Node contributors. All rights reserved. MIT license. -// Taken from Node 18.12.1 -// This file is automatically generated by "node/_tools/setup.ts". Do not modify this file manually - -'use strict'; -const common = require('../common'); - -if (common.isIBMi) - common.skip('IBMi does not support `fs.watch()`'); - -// Tests if `filename` is provided to watcher on supported platforms - -const fs = require('fs'); -const assert = require('assert'); -const { join } = require('path'); - -class WatchTestCase { - constructor(shouldInclude, dirName, fileName, field) { - this.dirName = dirName; - this.fileName = fileName; - this.field = field; - this.shouldSkip = !shouldInclude; - } - get dirPath() { return join(tmpdir.path, this.dirName); } - get filePath() { return join(this.dirPath, this.fileName); } -} - -const cases = [ - // Watch on a file should callback with a filename on supported systems - new WatchTestCase( - common.isLinux || common.isOSX || common.isWindows || common.isAIX, - 'watch1', - 'foo', - 'filePath' - ), - // Watch on a directory should callback with a filename on supported systems - new WatchTestCase( - common.isLinux || common.isOSX || common.isWindows, - 'watch2', - 'bar', - 'dirPath' - ), -]; - -const tmpdir = require('../common/tmpdir'); -tmpdir.refresh(); - -for (const testCase of cases) { - if (testCase.shouldSkip) continue; - fs.mkdirSync(testCase.dirPath); - // Long content so it's actually flushed. - const content1 = Date.now() + testCase.fileName.toLowerCase().repeat(1e4); - fs.writeFileSync(testCase.filePath, content1); - - let interval; - const pathToWatch = testCase[testCase.field]; - const watcher = fs.watch(pathToWatch); - watcher.on('error', (err) => { - if (interval) { - clearInterval(interval); - interval = null; - } - assert.fail(err); - }); - watcher.on('close', common.mustCall(() => { - watcher.close(); // Closing a closed watcher should be a noop - })); - watcher.on('change', common.mustCall(function(eventType, argFilename) { - if (interval) { - clearInterval(interval); - interval = null; - } - if (common.isOSX) - assert.strictEqual(['rename', 'change'].includes(eventType), true); - else - assert.strictEqual(eventType, 'change'); - assert.strictEqual(argFilename, testCase.fileName); - - watcher.close(); - - // We document that watchers cannot be used anymore when it's closed, - // here we turn the methods into noops instead of throwing - watcher.close(); // Closing a closed watcher should be a noop - })); - - // Long content so it's actually flushed. toUpperCase so there's real change. - const content2 = Date.now() + testCase.fileName.toUpperCase().repeat(1e4); - interval = setInterval(() => { - fs.writeFileSync(testCase.filePath, ''); - fs.writeFileSync(testCase.filePath, content2); - }, 100); -} - -[false, 1, {}, [], null, undefined].forEach((input) => { - assert.throws( - () => fs.watch(input, common.mustNotCall()), - { - code: 'ERR_INVALID_ARG_TYPE', - name: 'TypeError' - } - ); -}); diff --git a/cli/tests/node_compat/test/parallel/test-fs-writev.js b/cli/tests/node_compat/test/parallel/test-fs-writev.js deleted file mode 100644 index a0f3622cc..000000000 --- a/cli/tests/node_compat/test/parallel/test-fs-writev.js +++ /dev/null @@ -1,114 +0,0 @@ -// deno-fmt-ignore-file -// deno-lint-ignore-file - -// Copyright Joyent and Node contributors. All rights reserved. MIT license. -// Taken from Node 18.12.1 -// This file is automatically generated by "node/_tools/setup.ts". Do not modify this file manually - -'use strict'; - -const common = require('../common'); -const assert = require('assert'); -const path = require('path'); -const fs = require('fs'); -const tmpdir = require('../common/tmpdir'); - -tmpdir.refresh(); - -const expected = 'ümlaut. Лорем 運務ホソモ指及 आपको करने विकास 紙読決多密所 أضف'; - -const getFileName = (i) => path.join(tmpdir.path, `writev_${i}.txt`); - -/** - * Testing with a array of buffers input - */ - -// fs.writev with array of buffers with all parameters -{ - const filename = getFileName(1); - const fd = fs.openSync(filename, 'w'); - - const buffer = Buffer.from(expected); - const bufferArr = [buffer, buffer]; - - const done = common.mustSucceed((written, buffers) => { - assert.deepStrictEqual(bufferArr, buffers); - const expectedLength = bufferArr.length * buffer.byteLength; - assert.deepStrictEqual(written, expectedLength); - fs.closeSync(fd); - - assert(Buffer.concat(bufferArr).equals(fs.readFileSync(filename))); - }); - - fs.writev(fd, bufferArr, null, done); -} - -// fs.writev with array of buffers without position -{ - const filename = getFileName(2); - const fd = fs.openSync(filename, 'w'); - - const buffer = Buffer.from(expected); - const bufferArr = [buffer, buffer]; - - const done = common.mustSucceed((written, buffers) => { - assert.deepStrictEqual(bufferArr, buffers); - - const expectedLength = bufferArr.length * buffer.byteLength; - assert.deepStrictEqual(written, expectedLength); - fs.closeSync(fd); - - assert(Buffer.concat(bufferArr).equals(fs.readFileSync(filename))); - }); - - fs.writev(fd, bufferArr, done); -} - - -// fs.writev with empty array of buffers -{ - const filename = getFileName(3); - const fd = fs.openSync(filename, 'w'); - const bufferArr = []; - let afterSyncCall = false; - - const done = common.mustSucceed((written, buffers) => { - assert.strictEqual(buffers.length, 0); - assert.strictEqual(written, 0); - assert(afterSyncCall); - fs.closeSync(fd); - }); - - fs.writev(fd, bufferArr, done); - afterSyncCall = true; -} - -/** - * Testing with wrong input types - */ -{ - const filename = getFileName(4); - const fd = fs.openSync(filename, 'w'); - - [false, 'test', {}, [{}], ['sdf'], null, undefined].forEach((i) => { - assert.throws( - () => fs.writev(fd, i, null, common.mustNotCall()), { - code: 'ERR_INVALID_ARG_TYPE', - name: 'TypeError' - } - ); - }); - - fs.closeSync(fd); -} - -// fs.writev with wrong fd types -[false, 'test', {}, [{}], null, undefined].forEach((i) => { - assert.throws( - () => fs.writev(i, common.mustNotCall()), - { - code: 'ERR_INVALID_ARG_TYPE', - name: 'TypeError' - } - ); -}); diff --git a/cli/tests/node_compat/test/parallel/test-http-outgoing-destroy.js b/cli/tests/node_compat/test/parallel/test-http-outgoing-destroy.js deleted file mode 100644 index 52b41d9c3..000000000 --- a/cli/tests/node_compat/test/parallel/test-http-outgoing-destroy.js +++ /dev/null @@ -1,24 +0,0 @@ -// deno-fmt-ignore-file -// deno-lint-ignore-file - -// Copyright Joyent and Node contributors. All rights reserved. MIT license. -// Taken from Node 18.12.1 -// This file is automatically generated by "node/_tools/setup.ts". Do not modify this file manually - -'use strict'; -const common = require('../common'); -const assert = require('assert'); - -const http = require('http'); -const OutgoingMessage = http.OutgoingMessage; - -{ - const msg = new OutgoingMessage(); - assert.strictEqual(msg.destroyed, false); - msg.destroy(); - assert.strictEqual(msg.destroyed, true); - msg.write('asd', common.mustCall((err) => { - assert.strictEqual(err.code, 'ERR_STREAM_DESTROYED'); - })); - msg.on('error', common.mustNotCall()); -} diff --git a/cli/tests/node_compat/test/parallel/test-http-outgoing-finish-writable.js b/cli/tests/node_compat/test/parallel/test-http-outgoing-finish-writable.js deleted file mode 100644 index f87a1130c..000000000 --- a/cli/tests/node_compat/test/parallel/test-http-outgoing-finish-writable.js +++ /dev/null @@ -1,47 +0,0 @@ -// deno-fmt-ignore-file -// deno-lint-ignore-file - -// Copyright Joyent and Node contributors. All rights reserved. MIT license. -// Taken from Node 18.12.1 -// This file is automatically generated by "node/_tools/setup.ts". Do not modify this file manually - -'use strict'; -const common = require('../common'); -const assert = require('assert'); -const http = require('http'); - -// Verify that after calling end() on an `OutgoingMessage` (or a type that -// inherits from `OutgoingMessage`), its `writable` property is not set to false - -const server = http.createServer(common.mustCall(function(req, res) { - assert.strictEqual(res.writable, true); - assert.strictEqual(res.finished, false); - assert.strictEqual(res.writableEnded, false); - res.end(); - - // res.writable is set to false after it has finished sending - // Ref: https://github.com/nodejs/node/issues/15029 - assert.strictEqual(res.writable, true); - assert.strictEqual(res.finished, true); - assert.strictEqual(res.writableEnded, true); - - server.close(); -})); - -server.listen(0); - -server.on('listening', common.mustCall(function() { - const clientRequest = http.request({ - port: server.address().port, - method: 'GET', - path: '/' - }); - - assert.strictEqual(clientRequest.writable, true); - clientRequest.end(); - - // Writable is still true when close - // THIS IS LEGACY, we cannot change it - // unless we break error detection - assert.strictEqual(clientRequest.writable, true); -})); diff --git a/cli/tests/node_compat/test/parallel/test-net-after-close.js b/cli/tests/node_compat/test/parallel/test-net-after-close.js deleted file mode 100644 index 9ffa68407..000000000 --- a/cli/tests/node_compat/test/parallel/test-net-after-close.js +++ /dev/null @@ -1,58 +0,0 @@ -// deno-fmt-ignore-file -// deno-lint-ignore-file - -// Copyright Joyent and Node contributors. All rights reserved. MIT license. -// Taken from Node 18.12.1 -// This file is automatically generated by "node/_tools/setup.ts". Do not modify this file manually - -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -'use strict'; -const common = require('../common'); -const assert = require('assert'); -const net = require('net'); - -const server = net.createServer(common.mustCall((s) => { - console.error('SERVER: got connection'); - s.end(); -})); - -server.listen(0, common.mustCall(() => { - const c = net.createConnection(server.address().port); - c.on('close', common.mustCall(() => { - /* eslint-disable no-unused-expressions */ - console.error('connection closed'); - assert.strictEqual(c._handle, null); - // Calling functions / accessing properties of a closed socket should not - // throw. - c.setNoDelay(); - c.setKeepAlive(); - c.bufferSize; - c.pause(); - c.resume(); - c.address(); - c.remoteAddress; - c.remotePort; - server.close(); - /* eslint-enable no-unused-expressions */ - })); -})); diff --git a/cli/tests/node_compat/test/parallel/test-net-allow-half-open.js b/cli/tests/node_compat/test/parallel/test-net-allow-half-open.js deleted file mode 100644 index cfc2ec552..000000000 --- a/cli/tests/node_compat/test/parallel/test-net-allow-half-open.js +++ /dev/null @@ -1,54 +0,0 @@ -// deno-fmt-ignore-file -// deno-lint-ignore-file - -// Copyright Joyent and Node contributors. All rights reserved. MIT license. -// Taken from Node 18.12.1 -// This file is automatically generated by "node/_tools/setup.ts". Do not modify this file manually - -'use strict'; - -const common = require('../common'); -const assert = require('assert'); -const net = require('net'); - -{ - const server = net.createServer(common.mustCall((socket) => { - socket.end(Buffer.alloc(1024)); - })).listen(0, common.mustCall(() => { - const socket = net.connect(server.address().port); - assert.strictEqual(socket.allowHalfOpen, false); - socket.resume(); - socket.on('end', common.mustCall(() => { - process.nextTick(() => { - // Ensure socket is not destroyed straight away - // without proper shutdown. - assert(!socket.destroyed); - server.close(); - }); - })); - socket.on('finish', common.mustCall(() => { - assert(!socket.destroyed); - })); - socket.on('close', common.mustCall()); - })); -} - -{ - const server = net.createServer(common.mustCall((socket) => { - socket.end(Buffer.alloc(1024)); - })).listen(0, common.mustCall(() => { - const socket = net.connect(server.address().port); - assert.strictEqual(socket.allowHalfOpen, false); - socket.resume(); - socket.on('end', common.mustCall(() => { - assert(!socket.destroyed); - })); - socket.end('asd'); - socket.on('finish', common.mustCall(() => { - assert(!socket.destroyed); - })); - socket.on('close', common.mustCall(() => { - server.close(); - })); - })); -} diff --git a/cli/tests/node_compat/test/parallel/test-net-better-error-messages-listen.js b/cli/tests/node_compat/test/parallel/test-net-better-error-messages-listen.js deleted file mode 100644 index 14febbcdf..000000000 --- a/cli/tests/node_compat/test/parallel/test-net-better-error-messages-listen.js +++ /dev/null @@ -1,19 +0,0 @@ -// deno-fmt-ignore-file -// deno-lint-ignore-file - -// Copyright Joyent and Node contributors. All rights reserved. MIT license. -// Taken from Node 18.12.1 -// This file is automatically generated by "node/_tools/setup.ts". Do not modify this file manually - -'use strict'; -const common = require('../common'); -const assert = require('assert'); -const net = require('net'); - -const server = net.createServer(common.mustNotCall()); -server.listen(1, '1.1.1.1', common.mustNotCall()); -server.on('error', common.mustCall(function(e) { - assert.strictEqual(e.address, '1.1.1.1'); - assert.strictEqual(e.port, 1); - assert.strictEqual(e.syscall, 'listen'); -})); diff --git a/cli/tests/node_compat/test/parallel/test-net-bind-twice.js b/cli/tests/node_compat/test/parallel/test-net-bind-twice.js deleted file mode 100644 index 6500f2aef..000000000 --- a/cli/tests/node_compat/test/parallel/test-net-bind-twice.js +++ /dev/null @@ -1,43 +0,0 @@ -// deno-fmt-ignore-file -// deno-lint-ignore-file - -// Copyright Joyent and Node contributors. All rights reserved. MIT license. -// Taken from Node 18.12.1 -// This file is automatically generated by "node/_tools/setup.ts". Do not modify this file manually - -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -'use strict'; -const common = require('../common'); -const assert = require('assert'); -const net = require('net'); - -const server1 = net.createServer(common.mustNotCall()); -server1.listen(0, '127.0.0.1', common.mustCall(function() { - const server2 = net.createServer(common.mustNotCall()); - server2.listen(this.address().port, '127.0.0.1', common.mustNotCall()); - - server2.on('error', common.mustCall(function(e) { - assert.strictEqual(e.code, 'EADDRINUSE'); - server1.close(); - })); -})); diff --git a/cli/tests/node_compat/test/parallel/test-net-buffersize.js b/cli/tests/node_compat/test/parallel/test-net-buffersize.js deleted file mode 100644 index 0831fa526..000000000 --- a/cli/tests/node_compat/test/parallel/test-net-buffersize.js +++ /dev/null @@ -1,59 +0,0 @@ -// deno-fmt-ignore-file -// deno-lint-ignore-file - -// Copyright Joyent and Node contributors. All rights reserved. MIT license. -// Taken from Node 18.12.1 -// This file is automatically generated by "node/_tools/setup.ts". Do not modify this file manually - -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -'use strict'; -const common = require('../common'); -const assert = require('assert'); -const net = require('net'); - -const iter = 10; - -const server = net.createServer(function(socket) { - socket.on('readable', function() { - socket.read(); - }); - - socket.on('end', function() { - server.close(); - }); -}); - -server.listen(0, common.mustCall(function() { - const client = net.connect(this.address().port); - - client.on('finish', common.mustCall(() => { - assert.strictEqual(client.bufferSize, 0); - })); - - for (let i = 1; i < iter; i++) { - client.write('a'); - assert.strictEqual(client.bufferSize, i); - } - - client.end(); -})); diff --git a/cli/tests/node_compat/test/parallel/test-net-bytes-written-large.js b/cli/tests/node_compat/test/parallel/test-net-bytes-written-large.js deleted file mode 100644 index 98df17dca..000000000 --- a/cli/tests/node_compat/test/parallel/test-net-bytes-written-large.js +++ /dev/null @@ -1,74 +0,0 @@ -// deno-fmt-ignore-file -// deno-lint-ignore-file - -// Copyright Joyent and Node contributors. All rights reserved. MIT license. -// Taken from Node 18.12.1 -// This file is automatically generated by "node/_tools/setup.ts". Do not modify this file manually - -'use strict'; -const common = require('../common'); -const assert = require('assert'); -const net = require('net'); - -// Regression test for https://github.com/nodejs/node/issues/19562: -// Writing to a socket first tries to push through as much data as possible -// without blocking synchronously, and, if that is not enough, queues more -// data up for asynchronous writing. -// Check that `bytesWritten` accounts for both parts of a write. - -const N = 10000000; -{ - // Variant 1: Write a Buffer. - const server = net.createServer(common.mustCall((socket) => { - socket.end(Buffer.alloc(N), common.mustCall(() => { - assert.strictEqual(socket.bytesWritten, N); - })); - assert.strictEqual(socket.bytesWritten, N); - })).listen(0, common.mustCall(() => { - const client = net.connect(server.address().port); - client.resume(); - client.on('close', common.mustCall(() => { - assert.strictEqual(client.bytesRead, N); - server.close(); - })); - })); -} - -{ - // Variant 2: Write a string. - const server = net.createServer(common.mustCall((socket) => { - socket.end('a'.repeat(N), common.mustCall(() => { - assert.strictEqual(socket.bytesWritten, N); - })); - assert.strictEqual(socket.bytesWritten, N); - })).listen(0, common.mustCall(() => { - const client = net.connect(server.address().port); - client.resume(); - client.on('close', common.mustCall(() => { - assert.strictEqual(client.bytesRead, N); - server.close(); - })); - })); -} - -{ - // Variant 2: writev() with mixed data. - const server = net.createServer(common.mustCall((socket) => { - socket.cork(); - socket.write('a'.repeat(N)); - assert.strictEqual(socket.bytesWritten, N); - socket.write(Buffer.alloc(N)); - assert.strictEqual(socket.bytesWritten, 2 * N); - socket.end('', common.mustCall(() => { - assert.strictEqual(socket.bytesWritten, 2 * N); - })); - socket.uncork(); - })).listen(0, common.mustCall(() => { - const client = net.connect(server.address().port); - client.resume(); - client.on('close', common.mustCall(() => { - assert.strictEqual(client.bytesRead, 2 * N); - server.close(); - })); - })); -} diff --git a/cli/tests/node_compat/test/parallel/test-net-can-reset-timeout.js b/cli/tests/node_compat/test/parallel/test-net-can-reset-timeout.js deleted file mode 100644 index 535a86a10..000000000 --- a/cli/tests/node_compat/test/parallel/test-net-can-reset-timeout.js +++ /dev/null @@ -1,64 +0,0 @@ -// deno-fmt-ignore-file -// deno-lint-ignore-file - -// Copyright Joyent and Node contributors. All rights reserved. MIT license. -// Taken from Node 18.12.1 -// This file is automatically generated by "node/_tools/setup.ts". Do not modify this file manually - -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -'use strict'; -const common = require('../common'); - -// Ref: https://github.com/nodejs/node-v0.x-archive/issues/481 - -const net = require('net'); - -const server = net.createServer(common.mustCall(function(stream) { - stream.setTimeout(100); - - stream.resume(); - - stream.once('timeout', common.mustCall(function() { - console.log('timeout'); - // Try to reset the timeout. - stream.write('WHAT.'); - })); - - stream.on('end', common.mustCall(function() { - console.log('server side end'); - stream.end(); - })); -})); - -server.listen(0, common.mustCall(function() { - const c = net.createConnection(this.address().port); - - c.on('data', function() { - c.end(); - }); - - c.on('end', function() { - console.log('client side end'); - server.close(); - }); -})); diff --git a/cli/tests/node_compat/test/parallel/test-net-connect-call-socket-connect.js b/cli/tests/node_compat/test/parallel/test-net-connect-call-socket-connect.js deleted file mode 100644 index 87412d4ad..000000000 --- a/cli/tests/node_compat/test/parallel/test-net-connect-call-socket-connect.js +++ /dev/null @@ -1,46 +0,0 @@ -// deno-fmt-ignore-file -// deno-lint-ignore-file - -// Copyright Joyent and Node contributors. All rights reserved. MIT license. -// Taken from Node 18.12.1 -// This file is automatically generated by "node/_tools/setup.ts". Do not modify this file manually - -'use strict'; -const common = require('../common'); - -// This test checks that calling `net.connect` internally calls -// `Socket.prototype.connect`. -// -// This is important for people who monkey-patch `Socket.prototype.connect` -// since it's not possible to monkey-patch `net.connect` directly (as the core -// `connect` function is called internally in Node instead of calling the -// `exports.connect` function). -// -// Monkey-patching of `Socket.prototype.connect` is done by - among others - -// most APM vendors, the async-listener module and the -// continuation-local-storage module. -// -// Related: -// - https://github.com/nodejs/node/pull/12342 -// - https://github.com/nodejs/node/pull/12852 - -const net = require('net'); -const Socket = net.Socket; - -// Monkey patch Socket.prototype.connect to check that it's called. -const orig = Socket.prototype.connect; -Socket.prototype.connect = common.mustCall(function() { - return orig.apply(this, arguments); -}); - -const server = net.createServer(); - -server.listen(common.mustCall(function() { - const port = server.address().port; - const client = net.connect({ port }, common.mustCall(function() { - client.end(); - })); - client.on('end', common.mustCall(function() { - server.close(); - })); -})); diff --git a/cli/tests/node_compat/test/parallel/test-net-connect-options-ipv6.js b/cli/tests/node_compat/test/parallel/test-net-connect-options-ipv6.js deleted file mode 100644 index af87d5713..000000000 --- a/cli/tests/node_compat/test/parallel/test-net-connect-options-ipv6.js +++ /dev/null @@ -1,74 +0,0 @@ -// deno-fmt-ignore-file -// deno-lint-ignore-file - -// Copyright Joyent and Node contributors. All rights reserved. MIT license. -// Taken from Node 18.12.1 -// This file is automatically generated by "node/_tools/setup.ts". Do not modify this file manually - -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -// Test that the family option of net.connect is honored. - -'use strict'; -const common = require('../common'); -if (!common.hasIPv6) - common.skip('no IPv6 support'); - -const assert = require('assert'); -const net = require('net'); - -const hostAddrIPv6 = '::1'; -const HOSTNAME = 'dummy'; - -const server = net.createServer({ allowHalfOpen: true }, (socket) => { - socket.resume(); - socket.on('end', common.mustCall()); - socket.end(); -}); - -function tryConnect() { - const connectOpt = { - host: HOSTNAME, - port: server.address().port, - family: 6, - allowHalfOpen: true, - lookup: common.mustCall((addr, opt, cb) => { - assert.strictEqual(addr, HOSTNAME); - assert.strictEqual(opt.family, 6); - cb(null, hostAddrIPv6, opt.family); - }) - }; - // No `mustCall`, since test could skip, and it's the only path to `close`. - const client = net.connect(connectOpt, () => { - client.resume(); - client.on('end', () => { - // Wait for next uv tick and make sure the socket stream is writable. - setTimeout(function() { - assert(client.writable); - client.end(); - }, 10); - }); - client.on('close', () => server.close()); - }); -} - -server.listen(0, hostAddrIPv6, tryConnect); diff --git a/cli/tests/node_compat/test/parallel/test-net-connect-options-port.js b/cli/tests/node_compat/test/parallel/test-net-connect-options-port.js deleted file mode 100644 index 6dd10461a..000000000 --- a/cli/tests/node_compat/test/parallel/test-net-connect-options-port.js +++ /dev/null @@ -1,237 +0,0 @@ -// deno-fmt-ignore-file -// deno-lint-ignore-file - -// Copyright Joyent and Node contributors. All rights reserved. MIT license. -// Taken from Node 18.12.1 -// This file is automatically generated by "node/_tools/setup.ts". Do not modify this file manually - -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -'use strict'; -const common = require('../common'); -const assert = require('assert'); -const dns = require('dns'); -const net = require('net'); - -// Test wrong type of ports -{ - const portTypeError = { - code: 'ERR_INVALID_ARG_TYPE', - name: 'TypeError' - }; - - syncFailToConnect(true, portTypeError); - syncFailToConnect(false, portTypeError); - syncFailToConnect([], portTypeError, true); - syncFailToConnect({}, portTypeError, true); - syncFailToConnect(null, portTypeError); -} - -// Test out of range ports -{ - const portRangeError = { - code: 'ERR_SOCKET_BAD_PORT', - name: 'RangeError' - }; - - syncFailToConnect('', portRangeError); - syncFailToConnect(' ', portRangeError); - syncFailToConnect('0x', portRangeError, true); - syncFailToConnect('-0x1', portRangeError, true); - syncFailToConnect(NaN, portRangeError); - syncFailToConnect(Infinity, portRangeError); - syncFailToConnect(-1, portRangeError); - syncFailToConnect(65536, portRangeError); -} - -// Test invalid hints -{ - // connect({hint}, cb) and connect({hint}) - const hints = (dns.ADDRCONFIG | dns.V4MAPPED | dns.ALL) + 42; - const hintOptBlocks = doConnect([{ port: 42, hints }], - () => common.mustNotCall()); - for (const fn of hintOptBlocks) { - assert.throws(fn, { - code: 'ERR_INVALID_ARG_VALUE', - name: 'TypeError', - message: /The argument 'hints' is invalid\. Received \d+/ - }); - } -} - -// Test valid combinations of connect(port) and connect(port, host) -{ - const expectedConnections = 72; - let serverConnected = 0; - - const server = net.createServer(common.mustCall((socket) => { - socket.end('ok'); - if (++serverConnected === expectedConnections) { - server.close(); - } - }, expectedConnections)); - - server.listen(0, common.localhostIPv4, common.mustCall(() => { - const port = server.address().port; - - // Total connections = 3 * 4(canConnect) * 6(doConnect) = 72 - canConnect(port); - canConnect(String(port)); - canConnect(`0x${port.toString(16)}`); - })); - - // Try connecting to random ports, but do so once the server is closed - server.on('close', () => { - asyncFailToConnect(0); - }); -} - -function doConnect(args, getCb) { - return [ - function createConnectionWithCb() { - return net.createConnection.apply(net, args.concat(getCb())) - .resume(); - }, - function createConnectionWithoutCb() { - return net.createConnection.apply(net, args) - .on('connect', getCb()) - .resume(); - }, - function connectWithCb() { - return net.connect.apply(net, args.concat(getCb())) - .resume(); - }, - function connectWithoutCb() { - return net.connect.apply(net, args) - .on('connect', getCb()) - .resume(); - }, - function socketConnectWithCb() { - const socket = new net.Socket(); - return socket.connect.apply(socket, args.concat(getCb())) - .resume(); - }, - function socketConnectWithoutCb() { - const socket = new net.Socket(); - return socket.connect.apply(socket, args) - .on('connect', getCb()) - .resume(); - }, - ]; -} - -function syncFailToConnect(port, assertErr, optOnly) { - const family = 4; - if (!optOnly) { - // connect(port, cb) and connect(port) - const portArgFunctions = doConnect([{ port, family }], - () => common.mustNotCall()); - for (const fn of portArgFunctions) { - assert.throws(fn, assertErr, `${fn.name}(${port})`); - } - - // connect(port, host, cb) and connect(port, host) - const portHostArgFunctions = doConnect([{ port, - host: 'localhost', - family }], - () => common.mustNotCall()); - for (const fn of portHostArgFunctions) { - assert.throws(fn, assertErr, `${fn.name}(${port}, 'localhost')`); - } - } - // connect({port}, cb) and connect({port}) - const portOptFunctions = doConnect([{ port, family }], - () => common.mustNotCall()); - for (const fn of portOptFunctions) { - assert.throws(fn, assertErr, `${fn.name}({port: ${port}})`); - } - - // connect({port, host}, cb) and connect({port, host}) - const portHostOptFunctions = doConnect([{ port: port, - host: 'localhost', - family: family }], - () => common.mustNotCall()); - for (const fn of portHostOptFunctions) { - assert.throws(fn, - assertErr, - `${fn.name}({port: ${port}, host: 'localhost'})`); - } -} - -function canConnect(port) { - const noop = () => common.mustCall(); - const family = 4; - - // connect(port, cb) and connect(port) - const portArgFunctions = doConnect([{ port, family }], noop); - for (const fn of portArgFunctions) { - fn(); - } - - // connect(port, host, cb) and connect(port, host) - const portHostArgFunctions = doConnect([{ port, host: 'localhost', family }], - noop); - for (const fn of portHostArgFunctions) { - fn(); - } - - // connect({port}, cb) and connect({port}) - const portOptFunctions = doConnect([{ port, family }], noop); - for (const fn of portOptFunctions) { - fn(); - } - - // connect({port, host}, cb) and connect({port, host}) - const portHostOptFns = doConnect([{ port, host: 'localhost', family }], - noop); - for (const fn of portHostOptFns) { - fn(); - } -} - -function asyncFailToConnect(port) { - const onError = () => common.mustCall((err) => { - const regexp = /^Error: connect E\w+.+$/; - assert.match(String(err), regexp); - }); - - const dont = () => common.mustNotCall(); - const family = 4; - // connect(port, cb) and connect(port) - const portArgFunctions = doConnect([{ port, family }], dont); - for (const fn of portArgFunctions) { - fn().on('error', onError()); - } - - // connect({port}, cb) and connect({port}) - const portOptFunctions = doConnect([{ port, family }], dont); - for (const fn of portOptFunctions) { - fn().on('error', onError()); - } - - // connect({port, host}, cb) and connect({port, host}) - const portHostOptFns = doConnect([{ port, host: 'localhost', family }], - dont); - for (const fn of portHostOptFns) { - fn().on('error', onError()); - } -} diff --git a/cli/tests/node_compat/test/parallel/test-net-dns-custom-lookup.js b/cli/tests/node_compat/test/parallel/test-net-dns-custom-lookup.js deleted file mode 100644 index 6847dc57e..000000000 --- a/cli/tests/node_compat/test/parallel/test-net-dns-custom-lookup.js +++ /dev/null @@ -1,61 +0,0 @@ -// deno-fmt-ignore-file -// deno-lint-ignore-file - -// Copyright Joyent and Node contributors. All rights reserved. MIT license. -// Taken from Node 18.12.1 -// This file is automatically generated by "node/_tools/setup.ts". Do not modify this file manually - -'use strict'; -const common = require('../common'); -const assert = require('assert'); -const net = require('net'); - -function check(addressType, cb) { - const server = net.createServer(function(client) { - client.end(); - server.close(); - cb && cb(); - }); - - const address = addressType === 4 ? common.localhostIPv4 : '::1'; - server.listen(0, address, common.mustCall(function() { - net.connect({ - port: this.address().port, - host: 'localhost', - family: addressType, - lookup: lookup - }).on('lookup', common.mustCall(function(err, ip, type) { - assert.strictEqual(err, null); - assert.strictEqual(address, ip); - assert.strictEqual(type, addressType); - })); - })); - - function lookup(host, dnsopts, cb) { - dnsopts.family = addressType; - if (addressType === 4) { - process.nextTick(function() { - cb(null, common.localhostIPv4, 4); - }); - } else { - process.nextTick(function() { - cb(null, '::1', 6); - }); - } - } -} - -check(4, function() { - common.hasIPv6 && check(6); -}); - -// Verify that bad lookup() IPs are handled. -{ - net.connect({ - host: 'localhost', - port: 80, - lookup(host, dnsopts, cb) { - cb(null, undefined, 4); - } - }).on('error', common.expectsError({ code: 'ERR_INVALID_IP_ADDRESS' })); -} diff --git a/cli/tests/node_compat/test/parallel/test-net-dns-lookup-skip.js b/cli/tests/node_compat/test/parallel/test-net-dns-lookup-skip.js deleted file mode 100644 index f0fb49781..000000000 --- a/cli/tests/node_compat/test/parallel/test-net-dns-lookup-skip.js +++ /dev/null @@ -1,26 +0,0 @@ -// deno-fmt-ignore-file -// deno-lint-ignore-file - -// Copyright Joyent and Node contributors. All rights reserved. MIT license. -// Taken from Node 18.12.1 -// This file is automatically generated by "node/_tools/setup.ts". Do not modify this file manually - -'use strict'; -const common = require('../common'); -const net = require('net'); - -function check(addressType) { - const server = net.createServer(function(client) { - client.end(); - server.close(); - }); - - const address = addressType === 4 ? '127.0.0.1' : '::1'; - server.listen(0, address, function() { - net.connect(this.address().port, address) - .on('lookup', common.mustNotCall()); - }); -} - -check(4); -common.hasIPv6 && check(6); diff --git a/cli/tests/node_compat/test/parallel/test-net-dns-lookup.js b/cli/tests/node_compat/test/parallel/test-net-dns-lookup.js deleted file mode 100644 index 57cb90d39..000000000 --- a/cli/tests/node_compat/test/parallel/test-net-dns-lookup.js +++ /dev/null @@ -1,47 +0,0 @@ -// deno-fmt-ignore-file -// deno-lint-ignore-file - -// Copyright Joyent and Node contributors. All rights reserved. MIT license. -// Taken from Node 18.12.1 -// This file is automatically generated by "node/_tools/setup.ts". Do not modify this file manually - -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -'use strict'; -const common = require('../common'); -const assert = require('assert'); -const net = require('net'); - -const server = net.createServer(function(client) { - client.end(); - server.close(); -}); - -server.listen(0, common.mustCall(function() { - net.connect(this.address().port, 'localhost') - .on('lookup', common.mustCall(function(err, ip, type, host) { - assert.strictEqual(err, null); - assert.match(ip, /^(127\.0\.0\.1|::1)$/); - assert.match(type.toString(), /^(4|6)$/); - assert.strictEqual(host, 'localhost'); - })); -})); diff --git a/cli/tests/node_compat/test/parallel/test-net-eaddrinuse.js b/cli/tests/node_compat/test/parallel/test-net-eaddrinuse.js deleted file mode 100644 index d4b9b234f..000000000 --- a/cli/tests/node_compat/test/parallel/test-net-eaddrinuse.js +++ /dev/null @@ -1,44 +0,0 @@ -// deno-fmt-ignore-file -// deno-lint-ignore-file - -// Copyright Joyent and Node contributors. All rights reserved. MIT license. -// Taken from Node 18.12.1 -// This file is automatically generated by "node/_tools/setup.ts". Do not modify this file manually - -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -'use strict'; -const common = require('../common'); -const assert = require('assert'); -const net = require('net'); - -const server1 = net.createServer(function(socket) { -}); -const server2 = net.createServer(function(socket) { -}); -server1.listen(0, common.mustCall(function() { - server2.on('error', function(error) { - assert.strictEqual(error.message.includes('EADDRINUSE'), true); - server1.close(); - }); - server2.listen(this.address().port); -})); diff --git a/cli/tests/node_compat/test/parallel/test-net-end-destroyed.js b/cli/tests/node_compat/test/parallel/test-net-end-destroyed.js deleted file mode 100644 index fc440844e..000000000 --- a/cli/tests/node_compat/test/parallel/test-net-end-destroyed.js +++ /dev/null @@ -1,33 +0,0 @@ -// deno-fmt-ignore-file -// deno-lint-ignore-file - -// Copyright Joyent and Node contributors. All rights reserved. MIT license. -// Taken from Node 18.12.1 -// This file is automatically generated by "node/_tools/setup.ts". Do not modify this file manually - -'use strict'; - -const common = require('../common'); -const net = require('net'); -const assert = require('assert'); - -const server = net.createServer(); - -server.on('connection', common.mustCall()); - -// Ensure that the socket is not destroyed when the 'end' event is emitted. - -server.listen(common.mustCall(function() { - const socket = net.createConnection({ - port: server.address().port - }); - - socket.on('connect', common.mustCall(function() { - socket.on('end', common.mustCall(function() { - assert.strictEqual(socket.destroyed, false); - server.close(); - })); - - socket.end(); - })); -})); diff --git a/cli/tests/node_compat/test/parallel/test-net-listen-after-destroying-stdin.js b/cli/tests/node_compat/test/parallel/test-net-listen-after-destroying-stdin.js deleted file mode 100644 index aa1c2ec28..000000000 --- a/cli/tests/node_compat/test/parallel/test-net-listen-after-destroying-stdin.js +++ /dev/null @@ -1,29 +0,0 @@ -// deno-fmt-ignore-file -// deno-lint-ignore-file - -// Copyright Joyent and Node contributors. All rights reserved. MIT license. -// Taken from Node 18.12.1 -// This file is automatically generated by "node/_tools/setup.ts". Do not modify this file manually - -'use strict'; -// Just test that destroying stdin doesn't mess up listening on a server. -// This is a regression test for -// https://github.com/nodejs/node-v0.x-archive/issues/746. - -const common = require('../common'); -const net = require('net'); - -process.stdin.destroy(); - -const server = net.createServer(common.mustCall((socket) => { - console.log('accepted...'); - socket.end(common.mustCall(() => { console.log('finished...'); })); - server.close(common.mustCall(() => { console.log('closed'); })); -})); - - -server.listen(0, common.mustCall(() => { - console.log('listening...'); - - net.createConnection(server.address().port); -})); diff --git a/cli/tests/node_compat/test/parallel/test-net-listen-error.js b/cli/tests/node_compat/test/parallel/test-net-listen-error.js deleted file mode 100644 index 25d2cd908..000000000 --- a/cli/tests/node_compat/test/parallel/test-net-listen-error.js +++ /dev/null @@ -1,36 +0,0 @@ -// deno-fmt-ignore-file -// deno-lint-ignore-file - -// Copyright Joyent and Node contributors. All rights reserved. MIT license. -// Taken from Node 18.12.1 -// This file is automatically generated by "node/_tools/setup.ts". Do not modify this file manually - -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -'use strict'; -const common = require('../common'); -const net = require('net'); - -const server = net.createServer(function(socket) { -}); -server.listen(1, '1.1.1.1', common.mustNotCall()); // EACCES or EADDRNOTAVAIL -server.on('error', common.mustCall()); diff --git a/cli/tests/node_compat/test/parallel/test-net-local-address-port.js b/cli/tests/node_compat/test/parallel/test-net-local-address-port.js deleted file mode 100644 index 98a63a952..000000000 --- a/cli/tests/node_compat/test/parallel/test-net-local-address-port.js +++ /dev/null @@ -1,50 +0,0 @@ -// deno-fmt-ignore-file -// deno-lint-ignore-file - -// Copyright Joyent and Node contributors. All rights reserved. MIT license. -// Taken from Node 18.12.1 -// This file is automatically generated by "node/_tools/setup.ts". Do not modify this file manually - -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -'use strict'; -const common = require('../common'); -const assert = require('assert'); -const net = require('net'); - -const server = net.createServer(common.mustCall(function(socket) { - assert.strictEqual(socket.localAddress, common.localhostIPv4); - assert.strictEqual(socket.localPort, this.address().port); - assert.strictEqual(socket.localFamily, this.address().family); - socket.on('end', function() { - server.close(); - }); - socket.resume(); -})); - -server.listen(0, common.localhostIPv4, function() { - const client = net.createConnection(this.address() - .port, common.localhostIPv4); - client.on('connect', function() { - client.end(); - }); -}); diff --git a/cli/tests/node_compat/test/parallel/test-net-pause-resume-connecting.js b/cli/tests/node_compat/test/parallel/test-net-pause-resume-connecting.js deleted file mode 100644 index 07f325462..000000000 --- a/cli/tests/node_compat/test/parallel/test-net-pause-resume-connecting.js +++ /dev/null @@ -1,102 +0,0 @@ -// deno-fmt-ignore-file -// deno-lint-ignore-file - -// Copyright Joyent and Node contributors. All rights reserved. MIT license. -// Taken from Node 18.12.1 -// This file is automatically generated by "node/_tools/setup.ts". Do not modify this file manually - -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -'use strict'; -const common = require('../common'); -const assert = require('assert'); -const net = require('net'); - -let connections = 0; -let dataEvents = 0; -let conn; - - -// Server -const server = net.createServer(function(conn) { - connections++; - conn.end('This was the year he fell to pieces.'); - - if (connections === 5) - server.close(); -}); - -server.listen(0, function() { - // Client 1 - conn = net.createConnection(this.address().port, 'localhost'); - conn.resume(); - conn.on('data', onDataOk); - - - // Client 2 - conn = net.createConnection(this.address().port, 'localhost'); - conn.pause(); - conn.resume(); - conn.on('data', onDataOk); - - - // Client 3 - conn = net.createConnection(this.address().port, 'localhost'); - conn.pause(); - conn.on('data', common.mustNotCall()); - scheduleTearDown(conn); - - - // Client 4 - conn = net.createConnection(this.address().port, 'localhost'); - conn.resume(); - conn.pause(); - conn.resume(); - conn.on('data', onDataOk); - - - // Client 5 - conn = net.createConnection(this.address().port, 'localhost'); - conn.resume(); - conn.resume(); - conn.pause(); - conn.on('data', common.mustNotCall()); - scheduleTearDown(conn); - - function onDataOk() { - dataEvents++; - } - - function scheduleTearDown(conn) { - setTimeout(function() { - conn.removeAllListeners('data'); - conn.resume(); - }, 100); - } -}); - - -// Exit sanity checks -process.on('exit', function() { - assert.strictEqual(connections, 5); - assert.strictEqual(dataEvents, 3); -}); diff --git a/cli/tests/node_compat/test/parallel/test-net-persistent-ref-unref.js b/cli/tests/node_compat/test/parallel/test-net-persistent-ref-unref.js deleted file mode 100644 index 06e2c6d0f..000000000 --- a/cli/tests/node_compat/test/parallel/test-net-persistent-ref-unref.js +++ /dev/null @@ -1,48 +0,0 @@ -// deno-fmt-ignore-file -// deno-lint-ignore-file - -// Copyright Joyent and Node contributors. All rights reserved. MIT license. -// Taken from Node 18.12.1 -// This file is automatically generated by "node/_tools/setup.ts". Do not modify this file manually - -// Flags: --expose-internals -'use strict'; -require('../common'); -const assert = require('assert'); -const net = require('net'); -const { internalBinding } = require('internal/test/binding'); -const TCPWrap = internalBinding('tcp_wrap').TCP; - -const echoServer = net.createServer((conn) => { - conn.end(); -}); - -const ref = TCPWrap.prototype.ref; -const unref = TCPWrap.prototype.unref; - -let refCount = 0; - -TCPWrap.prototype.ref = function() { - ref.call(this); - refCount++; - assert.strictEqual(refCount, 0); -}; - -TCPWrap.prototype.unref = function() { - unref.call(this); - refCount--; - assert.strictEqual(refCount, -1); -}; - -echoServer.listen(0); - -echoServer.on('listening', function() { - const sock = new net.Socket(); - sock.unref(); - sock.ref(); - sock.connect(this.address().port); - sock.on('end', () => { - assert.strictEqual(refCount, 0); - echoServer.close(); - }); -}); diff --git a/cli/tests/node_compat/test/parallel/test-net-remote-address-port.js b/cli/tests/node_compat/test/parallel/test-net-remote-address-port.js deleted file mode 100644 index c1dc0282c..000000000 --- a/cli/tests/node_compat/test/parallel/test-net-remote-address-port.js +++ /dev/null @@ -1,91 +0,0 @@ -// deno-fmt-ignore-file -// deno-lint-ignore-file - -// Copyright Joyent and Node contributors. All rights reserved. MIT license. -// Taken from Node 18.12.1 -// This file is automatically generated by "node/_tools/setup.ts". Do not modify this file manually - -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -'use strict'; -const common = require('../common'); -const assert = require('assert'); - -const net = require('net'); - -let conns_closed = 0; - -const remoteAddrCandidates = [ common.localhostIPv4, - '::1', - '::ffff:127.0.0.1' ]; - -const remoteFamilyCandidates = ['IPv4', 'IPv6']; - -const server = net.createServer(common.mustCall(function(socket) { - assert.ok(remoteAddrCandidates.includes(socket.remoteAddress), - `Invalid remoteAddress: ${socket.remoteAddress}`); - assert.ok(remoteFamilyCandidates.includes(socket.remoteFamily), - `Invalid remoteFamily: ${socket.remoteFamily}`); - assert.ok(socket.remotePort); - assert.notStrictEqual(socket.remotePort, this.address().port); - socket.on('end', function() { - if (++conns_closed === 2) server.close(); - }); - socket.on('close', function() { - assert.ok(remoteAddrCandidates.includes(socket.remoteAddress)); - assert.ok(remoteFamilyCandidates.includes(socket.remoteFamily)); - }); - socket.resume(); -}, 2)); - -server.listen(0, function() { - const client = net.createConnection(this.address().port, '127.0.0.1'); - const client2 = net.createConnection(this.address().port); - - assert.strictEqual(client.remoteAddress, undefined); - assert.strictEqual(client.remoteFamily, undefined); - assert.strictEqual(client.remotePort, undefined); - assert.strictEqual(client2.remoteAddress, undefined); - assert.strictEqual(client2.remoteFamily, undefined); - assert.strictEqual(client2.remotePort, undefined); - - client.on('connect', function() { - assert.ok(remoteAddrCandidates.includes(client.remoteAddress)); - assert.ok(remoteFamilyCandidates.includes(client.remoteFamily)); - assert.strictEqual(client.remotePort, server.address().port); - client.end(); - }); - client.on('close', function() { - assert.ok(remoteAddrCandidates.includes(client.remoteAddress)); - assert.ok(remoteFamilyCandidates.includes(client.remoteFamily)); - }); - client2.on('connect', function() { - assert.ok(remoteAddrCandidates.includes(client2.remoteAddress)); - assert.ok(remoteFamilyCandidates.includes(client2.remoteFamily)); - assert.strictEqual(client2.remotePort, server.address().port); - client2.end(); - }); - client2.on('close', function() { - assert.ok(remoteAddrCandidates.includes(client2.remoteAddress)); - assert.ok(remoteFamilyCandidates.includes(client2.remoteFamily)); - }); -}); diff --git a/cli/tests/node_compat/test/parallel/test-net-server-capture-rejection.js b/cli/tests/node_compat/test/parallel/test-net-server-capture-rejection.js deleted file mode 100644 index d8096251e..000000000 --- a/cli/tests/node_compat/test/parallel/test-net-server-capture-rejection.js +++ /dev/null @@ -1,34 +0,0 @@ -// deno-fmt-ignore-file -// deno-lint-ignore-file - -// Copyright Joyent and Node contributors. All rights reserved. MIT license. -// Taken from Node 18.12.1 -// This file is automatically generated by "node/_tools/setup.ts". Do not modify this file manually - -'use strict'; - -const common = require('../common'); -const assert = require('assert'); -const events = require('events'); -const { createServer, connect } = require('net'); - -events.captureRejections = true; - -const server = createServer(common.mustCall(async (sock) => { - server.close(); - - const _err = new Error('kaboom'); - sock.on('error', common.mustCall((err) => { - assert.strictEqual(err, _err); - })); - throw _err; -})); - -server.listen(0, common.mustCall(() => { - const sock = connect( - server.address().port, - server.address().host - ); - - sock.on('close', common.mustCall()); -})); diff --git a/cli/tests/node_compat/test/parallel/test-net-server-close.js b/cli/tests/node_compat/test/parallel/test-net-server-close.js deleted file mode 100644 index 1be4a9c44..000000000 --- a/cli/tests/node_compat/test/parallel/test-net-server-close.js +++ /dev/null @@ -1,52 +0,0 @@ -// deno-fmt-ignore-file -// deno-lint-ignore-file - -// Copyright Joyent and Node contributors. All rights reserved. MIT license. -// Taken from Node 18.12.1 -// This file is automatically generated by "node/_tools/setup.ts". Do not modify this file manually - -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -'use strict'; -const common = require('../common'); -const assert = require('assert'); -const net = require('net'); - -const sockets = []; - -const server = net.createServer(function(c) { - c.on('close', common.mustCall()); - - sockets.push(c); - - if (sockets.length === 2) { - assert.strictEqual(server.close(), server); - sockets.forEach((c) => c.destroy()); - } -}); - -server.on('close', common.mustCall()); - -assert.strictEqual(server, server.listen(0, () => { - net.createConnection(server.address().port); - net.createConnection(server.address().port); -})); diff --git a/cli/tests/node_compat/test/parallel/test-net-server-max-connections.js b/cli/tests/node_compat/test/parallel/test-net-server-max-connections.js deleted file mode 100644 index 76a609808..000000000 --- a/cli/tests/node_compat/test/parallel/test-net-server-max-connections.js +++ /dev/null @@ -1,114 +0,0 @@ -// deno-fmt-ignore-file -// deno-lint-ignore-file - -// Copyright Joyent and Node contributors. All rights reserved. MIT license. -// Taken from Node 18.12.1 -// This file is automatically generated by "node/_tools/setup.ts". Do not modify this file manually - -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -'use strict'; -const common = require('../common'); -const assert = require('assert'); - -const net = require('net'); - -// This test creates 20 connections to a server and sets the server's -// maxConnections property to 10. The first 10 connections make it through -// and the last 10 connections are rejected. - -const N = 20; -let closes = 0; -const waits = []; - -const server = net.createServer(common.mustCall(function(connection) { - connection.write('hello'); - waits.push(function() { connection.end(); }); -}, N / 2)); - -server.listen(0, function() { - makeConnection(0); -}); - -server.maxConnections = N / 2; - - -function makeConnection(index) { - const c = net.createConnection(server.address().port); - let gotData = false; - - c.on('connect', function() { - if (index + 1 < N) { - makeConnection(index + 1); - } - - c.on('close', function() { - console.error(`closed ${index}`); - closes++; - - if (closes < N / 2) { - assert.ok( - server.maxConnections <= index, - `${index} should not have been one of the first closed connections` - ); - } - - if (closes === N / 2) { - let cb; - console.error('calling wait callback.'); - while ((cb = waits.shift()) !== undefined) { - cb(); - } - server.close(); - } - - if (index < server.maxConnections) { - assert.strictEqual(gotData, true, - `${index} didn't get data, but should have`); - } else { - assert.strictEqual(gotData, false, - `${index} got data, but shouldn't have`); - } - }); - }); - - c.on('end', function() { c.end(); }); - - c.on('data', function(b) { - gotData = true; - assert.ok(b.length > 0); - }); - - c.on('error', function(e) { - // Retry if SmartOS and ECONNREFUSED. See - // https://github.com/nodejs/node/issues/2663. - if (common.isSunOS && (e.code === 'ECONNREFUSED')) { - c.connect(server.address().port); - } - console.error(`error ${index}: ${e}`); - }); -} - - -process.on('exit', function() { - assert.strictEqual(closes, N); -}); diff --git a/cli/tests/node_compat/test/parallel/test-net-server-pause-on-connect.js b/cli/tests/node_compat/test/parallel/test-net-server-pause-on-connect.js deleted file mode 100644 index 9329a306a..000000000 --- a/cli/tests/node_compat/test/parallel/test-net-server-pause-on-connect.js +++ /dev/null @@ -1,79 +0,0 @@ -// deno-fmt-ignore-file -// deno-lint-ignore-file - -// Copyright Joyent and Node contributors. All rights reserved. MIT license. -// Taken from Node 18.12.1 -// This file is automatically generated by "node/_tools/setup.ts". Do not modify this file manually - -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -'use strict'; -const common = require('../common'); -const assert = require('assert'); -const net = require('net'); -const msg = 'test'; -let stopped = true; -let server1Sock; - - -const server1ConnHandler = (socket) => { - socket.on('data', function(data) { - if (stopped) { - assert.fail('data event should not have happened yet'); - } - - assert.strictEqual(data.toString(), msg); - socket.end(); - server1.close(); - }); - - server1Sock = socket; -}; - -const server1 = net.createServer({ pauseOnConnect: true }, server1ConnHandler); - -const server2ConnHandler = (socket) => { - socket.on('data', function(data) { - assert.strictEqual(data.toString(), msg); - socket.end(); - server2.close(); - - assert.strictEqual(server1Sock.bytesRead, 0); - server1Sock.resume(); - stopped = false; - }); -}; - -const server2 = net.createServer({ pauseOnConnect: false }, server2ConnHandler); - -server1.listen(0, function() { - const clientHandler = common.mustCall(function() { - server2.listen(0, function() { - net.createConnection({ port: this.address().port }).write(msg); - }); - }); - net.createConnection({ port: this.address().port }).write(msg, clientHandler); -}); - -process.on('exit', function() { - assert.strictEqual(stopped, false); -}); diff --git a/cli/tests/node_compat/test/parallel/test-net-socket-close-after-end.js b/cli/tests/node_compat/test/parallel/test-net-socket-close-after-end.js deleted file mode 100644 index 8e19e09ab..000000000 --- a/cli/tests/node_compat/test/parallel/test-net-socket-close-after-end.js +++ /dev/null @@ -1,38 +0,0 @@ -// deno-fmt-ignore-file -// deno-lint-ignore-file - -// Copyright Joyent and Node contributors. All rights reserved. MIT license. -// Taken from Node 18.12.1 -// This file is automatically generated by "node/_tools/setup.ts". Do not modify this file manually - -'use strict'; -const common = require('../common'); - -const assert = require('assert'); -const net = require('net'); - -const server = net.createServer(); - -server.on('connection', (socket) => { - let endEmitted = false; - - socket.once('readable', () => { - setTimeout(() => { - socket.read(); - }, common.platformTimeout(100)); - }); - socket.on('end', () => { - endEmitted = true; - }); - socket.on('close', () => { - assert(endEmitted); - server.close(); - }); - socket.end('foo'); -}); - -server.listen(common.mustCall(() => { - const socket = net.createConnection(server.address().port, () => { - socket.end('foo'); - }); -})); diff --git a/cli/tests/node_compat/test/parallel/test-net-socket-connect-without-cb.js b/cli/tests/node_compat/test/parallel/test-net-socket-connect-without-cb.js deleted file mode 100644 index 8f8109380..000000000 --- a/cli/tests/node_compat/test/parallel/test-net-socket-connect-without-cb.js +++ /dev/null @@ -1,33 +0,0 @@ -// deno-fmt-ignore-file -// deno-lint-ignore-file - -// Copyright Joyent and Node contributors. All rights reserved. MIT license. -// Taken from Node 18.12.1 -// This file is automatically generated by "node/_tools/setup.ts". Do not modify this file manually - -'use strict'; -const common = require('../common'); - -// This test ensures that socket.connect can be called without callback -// which is optional. - -const net = require('net'); - -const server = net.createServer(common.mustCall(function(conn) { - conn.end(); - server.close(); -})).listen(0, common.mustCall(function() { - const client = new net.Socket(); - - client.on('connect', common.mustCall(function() { - client.end(); - })); - - const address = server.address(); - if (!common.hasIPv6 && address.family === 'IPv6') { - // Necessary to pass CI running inside containers. - client.connect(address.port); - } else { - client.connect(address); - } -})); diff --git a/cli/tests/node_compat/test/parallel/test-net-socket-connecting.js b/cli/tests/node_compat/test/parallel/test-net-socket-connecting.js deleted file mode 100644 index 96883f5e1..000000000 --- a/cli/tests/node_compat/test/parallel/test-net-socket-connecting.js +++ /dev/null @@ -1,28 +0,0 @@ -// deno-fmt-ignore-file -// deno-lint-ignore-file - -// Copyright Joyent and Node contributors. All rights reserved. MIT license. -// Taken from Node 18.12.1 -// This file is automatically generated by "node/_tools/setup.ts". Do not modify this file manually - -'use strict'; -require('../common'); -const assert = require('assert'); -const net = require('net'); - -const server = net.createServer((conn) => { - conn.end(); - server.close(); -}).listen(0, () => { - const client = net.connect(server.address().port, () => { - assert.strictEqual(client.connecting, false); - - // Legacy getter - assert.strictEqual(client._connecting, false); - client.end(); - }); - assert.strictEqual(client.connecting, true); - - // Legacy getter - assert.strictEqual(client._connecting, true); -}); diff --git a/cli/tests/node_compat/test/parallel/test-net-socket-destroy-send.js b/cli/tests/node_compat/test/parallel/test-net-socket-destroy-send.js deleted file mode 100644 index 47ac7c1ad..000000000 --- a/cli/tests/node_compat/test/parallel/test-net-socket-destroy-send.js +++ /dev/null @@ -1,31 +0,0 @@ -// deno-fmt-ignore-file -// deno-lint-ignore-file - -// Copyright Joyent and Node contributors. All rights reserved. MIT license. -// Taken from Node 18.12.1 -// This file is automatically generated by "node/_tools/setup.ts". Do not modify this file manually - -'use strict'; - -const common = require('../common'); -const net = require('net'); -const assert = require('assert'); - -const server = net.createServer(); -server.listen(0, common.mustCall(function() { - const port = server.address().port; - const conn = net.createConnection(port); - - conn.on('connect', common.mustCall(function() { - // Test destroy returns this, even on multiple calls when it short-circuits. - assert.strictEqual(conn, conn.destroy().destroy()); - conn.on('error', common.mustNotCall()); - - conn.write(Buffer.from('kaboom'), common.expectsError({ - code: 'ERR_STREAM_DESTROYED', - message: 'Cannot call write after a stream was destroyed', - name: 'Error' - })); - server.close(); - })); -})); diff --git a/cli/tests/node_compat/test/parallel/test-net-socket-end-before-connect.js b/cli/tests/node_compat/test/parallel/test-net-socket-end-before-connect.js deleted file mode 100644 index be83964be..000000000 --- a/cli/tests/node_compat/test/parallel/test-net-socket-end-before-connect.js +++ /dev/null @@ -1,20 +0,0 @@ -// deno-fmt-ignore-file -// deno-lint-ignore-file - -// Copyright Joyent and Node contributors. All rights reserved. MIT license. -// Taken from Node 18.12.1 -// This file is automatically generated by "node/_tools/setup.ts". Do not modify this file manually - -'use strict'; - -const common = require('../common'); - -const net = require('net'); - -const server = net.createServer(); - -server.listen(common.mustCall(() => { - const socket = net.createConnection(server.address().port); - socket.on('close', common.mustCall(() => server.close())); - socket.end(); -})); diff --git a/cli/tests/node_compat/test/parallel/test-net-socket-end-callback.js b/cli/tests/node_compat/test/parallel/test-net-socket-end-callback.js deleted file mode 100644 index 7b0e48df5..000000000 --- a/cli/tests/node_compat/test/parallel/test-net-socket-end-callback.js +++ /dev/null @@ -1,29 +0,0 @@ -// deno-fmt-ignore-file -// deno-lint-ignore-file - -// Copyright Joyent and Node contributors. All rights reserved. MIT license. -// Taken from Node 18.12.1 -// This file is automatically generated by "node/_tools/setup.ts". Do not modify this file manually - -'use strict'; - -const common = require('../common'); -const net = require('net'); - -const server = net.createServer((socket) => { - socket.resume(); -}).unref(); - -server.listen(common.mustCall(() => { - const connect = (...args) => { - const socket = net.createConnection(server.address().port, () => { - socket.end(...args); - }); - }; - - const cb = common.mustCall(() => {}, 3); - - connect(cb); - connect('foo', cb); - connect('foo', 'utf8', cb); -})); diff --git a/cli/tests/node_compat/test/parallel/test-net-socket-ready-without-cb.js b/cli/tests/node_compat/test/parallel/test-net-socket-ready-without-cb.js deleted file mode 100644 index 29cf729df..000000000 --- a/cli/tests/node_compat/test/parallel/test-net-socket-ready-without-cb.js +++ /dev/null @@ -1,27 +0,0 @@ -// deno-fmt-ignore-file -// deno-lint-ignore-file - -// Copyright Joyent and Node contributors. All rights reserved. MIT license. -// Taken from Node 18.12.1 -// This file is automatically generated by "node/_tools/setup.ts". Do not modify this file manually - -'use strict'; -const common = require('../common'); - -// This test ensures that socket.connect can be called without callback -// which is optional. - -const net = require('net'); - -const server = net.createServer(common.mustCall(function(conn) { - conn.end(); - server.close(); -})).listen(0, 'localhost', common.mustCall(function() { - const client = new net.Socket(); - - client.on('ready', common.mustCall(function() { - client.end(); - })); - - client.connect(server.address()); -})); diff --git a/cli/tests/node_compat/test/parallel/test-net-socket-write-after-close.js b/cli/tests/node_compat/test/parallel/test-net-socket-write-after-close.js deleted file mode 100644 index abd30aee1..000000000 --- a/cli/tests/node_compat/test/parallel/test-net-socket-write-after-close.js +++ /dev/null @@ -1,49 +0,0 @@ -// deno-fmt-ignore-file -// deno-lint-ignore-file - -// Copyright Joyent and Node contributors. All rights reserved. MIT license. -// Taken from Node 18.12.1 -// This file is automatically generated by "node/_tools/setup.ts". Do not modify this file manually - -'use strict'; -const common = require('../common'); -const assert = require('assert'); -const net = require('net'); - -{ - const server = net.createServer(); - - server.listen(common.mustCall(() => { - const port = server.address().port; - const client = net.connect({ port }, common.mustCall(() => { - client.on('error', common.mustCall((err) => { - server.close(); - assert.strictEqual(err.constructor, Error); - assert.strictEqual(err.message, 'write EBADF'); - })); - client._handle.close(); - client.write('foo'); - })); - })); -} - -{ - const server = net.createServer(); - - server.listen(common.mustCall(() => { - const port = server.address().port; - const client = net.connect({ port }, common.mustCall(() => { - client.on('error', common.expectsError({ - code: 'ERR_SOCKET_CLOSED', - message: 'Socket is closed', - name: 'Error' - })); - - server.close(); - - client._handle.close(); - client._handle = null; - client.write('foo'); - })); - })); -} diff --git a/cli/tests/node_compat/test/parallel/test-net-socket-write-error.js b/cli/tests/node_compat/test/parallel/test-net-socket-write-error.js deleted file mode 100644 index d38ab30b4..000000000 --- a/cli/tests/node_compat/test/parallel/test-net-socket-write-error.js +++ /dev/null @@ -1,29 +0,0 @@ -// deno-fmt-ignore-file -// deno-lint-ignore-file - -// Copyright Joyent and Node contributors. All rights reserved. MIT license. -// Taken from Node 18.12.1 -// This file is automatically generated by "node/_tools/setup.ts". Do not modify this file manually - -'use strict'; - -const common = require('../common'); -const net = require('net'); -const assert = require('assert'); - -const server = net.createServer().listen(0, connectToServer); - -function connectToServer() { - const client = net.createConnection(this.address().port, () => { - client.on('error', common.mustNotCall()); - assert.throws(() => { - client.write(1337); - }, { - code: 'ERR_INVALID_ARG_TYPE', - name: 'TypeError' - }); - - client.destroy(); - }) - .on('close', () => server.close()); -} diff --git a/cli/tests/node_compat/test/parallel/test-net-sync-cork.js b/cli/tests/node_compat/test/parallel/test-net-sync-cork.js deleted file mode 100644 index eb4274b74..000000000 --- a/cli/tests/node_compat/test/parallel/test-net-sync-cork.js +++ /dev/null @@ -1,40 +0,0 @@ -// deno-fmt-ignore-file -// deno-lint-ignore-file - -// Copyright Joyent and Node contributors. All rights reserved. MIT license. -// Taken from Node 18.12.1 -// This file is automatically generated by "node/_tools/setup.ts". Do not modify this file manually - -'use strict'; - -const common = require('../common'); -const assert = require('assert'); -const net = require('net'); - -const server = net.createServer(handle); - -const N = 100; -const buf = Buffer.alloc(2, 'a'); - -server.listen(0, function() { - const conn = net.connect(this.address().port); - - conn.on('connect', () => { - let res = true; - let i = 0; - for (; i < N && res; i++) { - conn.cork(); - conn.write(buf); - res = conn.write(buf); - conn.uncork(); - } - assert.strictEqual(i, N); - conn.end(); - }); -}); - -function handle(socket) { - socket.resume(); - socket.on('error', common.mustNotCall()) - .on('close', common.mustCall(() => server.close())); -} diff --git a/cli/tests/node_compat/test/parallel/test-net-writable.js b/cli/tests/node_compat/test/parallel/test-net-writable.js deleted file mode 100644 index a7cc5e5be..000000000 --- a/cli/tests/node_compat/test/parallel/test-net-writable.js +++ /dev/null @@ -1,22 +0,0 @@ -// deno-fmt-ignore-file -// deno-lint-ignore-file - -// Copyright Joyent and Node contributors. All rights reserved. MIT license. -// Taken from Node 18.12.1 -// This file is automatically generated by "node/_tools/setup.ts". Do not modify this file manually - -'use strict'; -const common = require('../common'); -const assert = require('assert'); -const net = require('net'); - -const server = net.createServer(common.mustCall(function(s) { - server.close(); - s.end(); -})).listen(0, '127.0.0.1', common.mustCall(function() { - const socket = net.connect(this.address().port, '127.0.0.1'); - socket.on('end', common.mustCall(() => { - assert.strictEqual(socket.writable, true); - socket.write('hello world'); - })); -})); diff --git a/cli/tests/node_compat/test/parallel/test-net-write-after-end-nt.js b/cli/tests/node_compat/test/parallel/test-net-write-after-end-nt.js deleted file mode 100644 index 8f38d3bfd..000000000 --- a/cli/tests/node_compat/test/parallel/test-net-write-after-end-nt.js +++ /dev/null @@ -1,39 +0,0 @@ -// deno-fmt-ignore-file -// deno-lint-ignore-file - -// Copyright Joyent and Node contributors. All rights reserved. MIT license. -// Taken from Node 18.12.1 -// This file is automatically generated by "node/_tools/setup.ts". Do not modify this file manually - -'use strict'; -const common = require('../common'); - -const assert = require('assert'); -const net = require('net'); - -const { expectsError, mustCall } = common; - -// This test ensures those errors caused by calling `net.Socket.write()` -// after sockets ending will be emitted in the next tick. -const server = net.createServer(mustCall((socket) => { - socket.end(); -})).listen(() => { - const client = net.connect(server.address().port, () => { - let hasError = false; - client.on('error', mustCall((err) => { - hasError = true; - server.close(); - })); - client.on('end', mustCall(() => { - const ret = client.write('hello', expectsError({ - code: 'EPIPE', - message: 'This socket has been ended by the other party', - name: 'Error' - })); - - assert.strictEqual(ret, false); - assert(!hasError, 'The error should be emitted in the next tick.'); - })); - client.end(); - }); -}); diff --git a/cli/tests/node_compat/test/parallel/test-net-write-fully-async-buffer.js b/cli/tests/node_compat/test/parallel/test-net-write-fully-async-buffer.js deleted file mode 100644 index 5e93ad4e2..000000000 --- a/cli/tests/node_compat/test/parallel/test-net-write-fully-async-buffer.js +++ /dev/null @@ -1,41 +0,0 @@ -// deno-fmt-ignore-file -// deno-lint-ignore-file - -// Copyright Joyent and Node contributors. All rights reserved. MIT license. -// Taken from Node 18.12.1 -// This file is automatically generated by "node/_tools/setup.ts". Do not modify this file manually - -'use strict'; -// Flags: --expose-gc - -// Note: This is a variant of test-net-write-fully-async-hex-string.js. -// This always worked, but it seemed appropriate to add a test that checks the -// behavior for Buffers, too. -const common = require('../common'); -const net = require('net'); - -const data = Buffer.alloc(1000000); - -const server = net.createServer(common.mustCall(function(conn) { - conn.resume(); -})).listen(0, common.mustCall(function() { - const conn = net.createConnection(this.address().port, common.mustCall(() => { - let count = 0; - - function writeLoop() { - if (count++ === 200) { - conn.destroy(); - server.close(); - return; - } - - while (conn.write(Buffer.from(data))); - global.gc({ type: 'minor' }); - // The buffer allocated above should still be alive. - } - - conn.on('drain', writeLoop); - - writeLoop(); - })); -})); diff --git a/cli/tests/node_compat/test/parallel/test-net-write-fully-async-hex-string.js b/cli/tests/node_compat/test/parallel/test-net-write-fully-async-hex-string.js deleted file mode 100644 index ff355aa2a..000000000 --- a/cli/tests/node_compat/test/parallel/test-net-write-fully-async-hex-string.js +++ /dev/null @@ -1,39 +0,0 @@ -// deno-fmt-ignore-file -// deno-lint-ignore-file - -// Copyright Joyent and Node contributors. All rights reserved. MIT license. -// Taken from Node 18.12.1 -// This file is automatically generated by "node/_tools/setup.ts". Do not modify this file manually - -'use strict'; -// Flags: --expose-gc - -// Regression test for https://github.com/nodejs/node/issues/8251. -const common = require('../common'); -const net = require('net'); - -const data = Buffer.alloc(1000000).toString('hex'); - -const server = net.createServer(common.mustCall(function(conn) { - conn.resume(); -})).listen(0, common.mustCall(function() { - const conn = net.createConnection(this.address().port, common.mustCall(() => { - let count = 0; - - function writeLoop() { - if (count++ === 20) { - conn.destroy(); - server.close(); - return; - } - - while (conn.write(data, 'hex')); - global.gc({ type: 'minor' }); - // The buffer allocated inside the .write() call should still be alive. - } - - conn.on('drain', writeLoop); - - writeLoop(); - })); -})); diff --git a/cli/tests/node_compat/test/parallel/test-net-write-slow.js b/cli/tests/node_compat/test/parallel/test-net-write-slow.js deleted file mode 100644 index 6c00efb1f..000000000 --- a/cli/tests/node_compat/test/parallel/test-net-write-slow.js +++ /dev/null @@ -1,70 +0,0 @@ -// deno-fmt-ignore-file -// deno-lint-ignore-file - -// Copyright Joyent and Node contributors. All rights reserved. MIT license. -// Taken from Node 18.12.1 -// This file is automatically generated by "node/_tools/setup.ts". Do not modify this file manually - -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -'use strict'; -const common = require('../common'); -const assert = require('assert'); -const net = require('net'); - -const SIZE = 2E5; -const N = 10; -let flushed = 0; -let received = 0; -const buf = Buffer.alloc(SIZE, 'a'); - -const server = net.createServer(function(socket) { - socket.setNoDelay(); - socket.setTimeout(9999); - socket.on('timeout', function() { - assert.fail(`flushed: ${flushed}, received: ${received}/${SIZE * N}`); - }); - - for (let i = 0; i < N; ++i) { - socket.write(buf, function() { - ++flushed; - if (flushed === N) { - socket.setTimeout(0); - } - }); - } - socket.end(); - -}).listen(0, common.mustCall(function() { - const conn = net.connect(this.address().port); - conn.on('data', function(buf) { - received += buf.length; - conn.pause(); - setTimeout(function() { - conn.resume(); - }, 20); - }); - conn.on('end', common.mustCall(function() { - server.close(); - assert.strictEqual(received, SIZE * N); - })); -})); diff --git a/cli/tests/node_compat/test/parallel/test-punycode.js b/cli/tests/node_compat/test/parallel/test-punycode.js deleted file mode 100644 index cb65954a0..000000000 --- a/cli/tests/node_compat/test/parallel/test-punycode.js +++ /dev/null @@ -1,280 +0,0 @@ -// deno-fmt-ignore-file -// deno-lint-ignore-file - -// Copyright Joyent and Node contributors. All rights reserved. MIT license. -// Taken from Node 18.12.1 -// This file is automatically generated by "node/_tools/setup.ts". Do not modify this file manually - -// Flags: --pending-deprecation - -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -'use strict'; -const common = require('../common'); - -const punycodeWarning = - 'The `punycode` module is deprecated. Please use a userland alternative ' + - 'instead.'; -common.expectWarning('DeprecationWarning', punycodeWarning, 'DEP0040'); - -const punycode = require('punycode'); -const assert = require('assert'); - -assert.strictEqual(punycode.encode('ü'), 'tda'); -assert.strictEqual(punycode.encode('Goethe'), 'Goethe-'); -assert.strictEqual(punycode.encode('Bücher'), 'Bcher-kva'); -assert.strictEqual( - punycode.encode( - 'Willst du die Blüthe des frühen, die Früchte des späteren Jahres' - ), - 'Willst du die Blthe des frhen, die Frchte des spteren Jahres-x9e96lkal' -); -assert.strictEqual(punycode.encode('日本語'), 'wgv71a119e'); -assert.strictEqual(punycode.encode('𩸽'), 'x73l'); - -assert.strictEqual(punycode.decode('tda'), 'ü'); -assert.strictEqual(punycode.decode('Goethe-'), 'Goethe'); -assert.strictEqual(punycode.decode('Bcher-kva'), 'Bücher'); -assert.strictEqual( - punycode.decode( - 'Willst du die Blthe des frhen, die Frchte des spteren Jahres-x9e96lkal' - ), - 'Willst du die Blüthe des frühen, die Früchte des späteren Jahres' -); -assert.strictEqual(punycode.decode('wgv71a119e'), '日本語'); -assert.strictEqual(punycode.decode('x73l'), '𩸽'); -assert.throws(() => { - punycode.decode(' '); -}, /^RangeError: Invalid input$/); -assert.throws(() => { - punycode.decode('α-'); -}, /^RangeError: Illegal input >= 0x80 \(not a basic code point\)$/); -assert.throws(() => { - punycode.decode('あ'); -}, /^RangeError: Overflow: input needs wider integers to process$/); - -// http://tools.ietf.org/html/rfc3492#section-7.1 -const tests = [ - // (A) Arabic (Egyptian) - { - encoded: 'egbpdaj6bu4bxfgehfvwxn', - decoded: '\u0644\u064A\u0647\u0645\u0627\u0628\u062A\u0643\u0644\u0645' + - '\u0648\u0634\u0639\u0631\u0628\u064A\u061F' - }, - - // (B) Chinese (simplified) - { - encoded: 'ihqwcrb4cv8a8dqg056pqjye', - decoded: '\u4ED6\u4EEC\u4E3A\u4EC0\u4E48\u4E0D\u8BF4\u4E2D\u6587' - }, - - // (C) Chinese (traditional) - { - encoded: 'ihqwctvzc91f659drss3x8bo0yb', - decoded: '\u4ED6\u5011\u7232\u4EC0\u9EBD\u4E0D\u8AAA\u4E2D\u6587' - }, - - // (D) Czech: Pro<ccaron>prost<ecaron>nemluv<iacute><ccaron>esky - { - encoded: 'Proprostnemluvesky-uyb24dma41a', - decoded: '\u0050\u0072\u006F\u010D\u0070\u0072\u006F\u0073\u0074\u011B' + - '\u006E\u0065\u006D\u006C\u0075\u0076\u00ED\u010D\u0065\u0073\u006B\u0079' - }, - - // (E) Hebrew - { - encoded: '4dbcagdahymbxekheh6e0a7fei0b', - decoded: '\u05DC\u05DE\u05D4\u05D4\u05DD\u05E4\u05E9\u05D5\u05D8\u05DC' + - '\u05D0\u05DE\u05D3\u05D1\u05E8\u05D9\u05DD\u05E2\u05D1\u05E8\u05D9\u05EA' - }, - - // (F) Hindi (Devanagari) - { - encoded: 'i1baa7eci9glrd9b2ae1bj0hfcgg6iyaf8o0a1dig0cd', - decoded: '\u092F\u0939\u0932\u094B\u0917\u0939\u093F\u0928\u094D\u0926' + - '\u0940\u0915\u094D\u092F\u094B\u0902\u0928\u0939\u0940\u0902\u092C' + - '\u094B\u0932\u0938\u0915\u0924\u0947\u0939\u0948\u0902' - }, - - // (G) Japanese (kanji and hiragana) - { - encoded: 'n8jok5ay5dzabd5bym9f0cm5685rrjetr6pdxa', - decoded: '\u306A\u305C\u307F\u3093\u306A\u65E5\u672C\u8A9E\u3092\u8A71' + - '\u3057\u3066\u304F\u308C\u306A\u3044\u306E\u304B' - }, - - // (H) Korean (Hangul syllables) - { - encoded: '989aomsvi5e83db1d2a355cv1e0vak1dwrv93d5xbh15a0dt30a5jpsd879' + - 'ccm6fea98c', - decoded: '\uC138\uACC4\uC758\uBAA8\uB4E0\uC0AC\uB78C\uB4E4\uC774\uD55C' + - '\uAD6D\uC5B4\uB97C\uC774\uD574\uD55C\uB2E4\uBA74\uC5BC\uB9C8\uB098' + - '\uC88B\uC744\uAE4C' - }, - - // (I) Russian (Cyrillic) - { - encoded: 'b1abfaaepdrnnbgefbadotcwatmq2g4l', - decoded: '\u043F\u043E\u0447\u0435\u043C\u0443\u0436\u0435\u043E\u043D' + - '\u0438\u043D\u0435\u0433\u043E\u0432\u043E\u0440\u044F\u0442\u043F' + - '\u043E\u0440\u0443\u0441\u0441\u043A\u0438' - }, - - // (J) Spanish: Porqu<eacute>nopuedensimplementehablarenEspa<ntilde>ol - { - encoded: 'PorqunopuedensimplementehablarenEspaol-fmd56a', - decoded: '\u0050\u006F\u0072\u0071\u0075\u00E9\u006E\u006F\u0070\u0075' + - '\u0065\u0064\u0065\u006E\u0073\u0069\u006D\u0070\u006C\u0065\u006D' + - '\u0065\u006E\u0074\u0065\u0068\u0061\u0062\u006C\u0061\u0072\u0065' + - '\u006E\u0045\u0073\u0070\u0061\u00F1\u006F\u006C' - }, - - // (K) Vietnamese: T<adotbelow>isaoh<odotbelow>kh<ocirc>ngth - // <ecirchookabove>ch<ihookabove>n<oacute>iti<ecircacute>ngVi<ecircdotbelow>t - { - encoded: 'TisaohkhngthchnitingVit-kjcr8268qyxafd2f1b9g', - decoded: '\u0054\u1EA1\u0069\u0073\u0061\u006F\u0068\u1ECD\u006B\u0068' + - '\u00F4\u006E\u0067\u0074\u0068\u1EC3\u0063\u0068\u1EC9\u006E\u00F3' + - '\u0069\u0074\u0069\u1EBF\u006E\u0067\u0056\u0069\u1EC7\u0074' - }, - - // (L) 3<nen>B<gumi><kinpachi><sensei> - { - encoded: '3B-ww4c5e180e575a65lsy2b', - decoded: '\u0033\u5E74\u0042\u7D44\u91D1\u516B\u5148\u751F' - }, - - // (M) <amuro><namie>-with-SUPER-MONKEYS - { - encoded: '-with-SUPER-MONKEYS-pc58ag80a8qai00g7n9n', - decoded: '\u5B89\u5BA4\u5948\u7F8E\u6075\u002D\u0077\u0069\u0074\u0068' + - '\u002D\u0053\u0055\u0050\u0045\u0052\u002D\u004D\u004F\u004E\u004B' + - '\u0045\u0059\u0053' - }, - - // (N) Hello-Another-Way-<sorezore><no><basho> - { - encoded: 'Hello-Another-Way--fc4qua05auwb3674vfr0b', - decoded: '\u0048\u0065\u006C\u006C\u006F\u002D\u0041\u006E\u006F\u0074' + - '\u0068\u0065\u0072\u002D\u0057\u0061\u0079\u002D\u305D\u308C\u305E' + - '\u308C\u306E\u5834\u6240' - }, - - // (O) <hitotsu><yane><no><shita>2 - { - encoded: '2-u9tlzr9756bt3uc0v', - decoded: '\u3072\u3068\u3064\u5C4B\u6839\u306E\u4E0B\u0032' - }, - - // (P) Maji<de>Koi<suru>5<byou><mae> - { - encoded: 'MajiKoi5-783gue6qz075azm5e', - decoded: '\u004D\u0061\u006A\u0069\u3067\u004B\u006F\u0069\u3059\u308B' + - '\u0035\u79D2\u524D' - }, - - // (Q) <pafii>de<runba> - { - encoded: 'de-jg4avhby1noc0d', - decoded: '\u30D1\u30D5\u30A3\u30FC\u0064\u0065\u30EB\u30F3\u30D0' - }, - - // (R) <sono><supiido><de> - { - encoded: 'd9juau41awczczp', - decoded: '\u305D\u306E\u30B9\u30D4\u30FC\u30C9\u3067' - }, - - // (S) -> $1.00 <- - { - encoded: '-> $1.00 <--', - decoded: '\u002D\u003E\u0020\u0024\u0031\u002E\u0030\u0030\u0020\u003C' + - '\u002D' - }, -]; - -let errors = 0; -const handleError = (error, name) => { - console.error( - `FAIL: ${name} expected ${error.expected}, got ${error.actual}` - ); - errors++; -}; - -const regexNonASCII = /[^\x20-\x7E]/; -const testBattery = { - encode: (test) => assert.strictEqual( - punycode.encode(test.decoded), - test.encoded - ), - decode: (test) => assert.strictEqual( - punycode.decode(test.encoded), - test.decoded - ), - toASCII: (test) => assert.strictEqual( - punycode.toASCII(test.decoded), - regexNonASCII.test(test.decoded) ? - `xn--${test.encoded}` : - test.decoded - ), - toUnicode: (test) => assert.strictEqual( - punycode.toUnicode( - regexNonASCII.test(test.decoded) ? - `xn--${test.encoded}` : - test.decoded - ), - regexNonASCII.test(test.decoded) ? - test.decoded.toLowerCase() : - test.decoded - ) -}; - -tests.forEach((testCase) => { - Object.keys(testBattery).forEach((key) => { - try { - testBattery[key](testCase); - } catch (error) { - handleError(error, key); - } - }); -}); - -// BMP code point -assert.strictEqual(punycode.ucs2.encode([0x61]), 'a'); -// Supplementary code point (surrogate pair) -assert.strictEqual(punycode.ucs2.encode([0x1D306]), '\uD834\uDF06'); -// high surrogate -assert.strictEqual(punycode.ucs2.encode([0xD800]), '\uD800'); -// High surrogate followed by non-surrogates -assert.strictEqual(punycode.ucs2.encode([0xD800, 0x61, 0x62]), '\uD800ab'); -// low surrogate -assert.strictEqual(punycode.ucs2.encode([0xDC00]), '\uDC00'); -// Low surrogate followed by non-surrogates -assert.strictEqual(punycode.ucs2.encode([0xDC00, 0x61, 0x62]), '\uDC00ab'); - -assert.strictEqual(errors, 0); - -// test map domain -assert.strictEqual(punycode.toASCII('Bücher@日本語.com'), - 'Bücher@xn--wgv71a119e.com'); -assert.strictEqual(punycode.toUnicode('Bücher@xn--wgv71a119e.com'), - 'Bücher@日本語.com'); diff --git a/cli/tests/node_compat/test/parallel/test-readline-csi.js b/cli/tests/node_compat/test/parallel/test-readline-csi.js deleted file mode 100644 index e9a87b138..000000000 --- a/cli/tests/node_compat/test/parallel/test-readline-csi.js +++ /dev/null @@ -1,183 +0,0 @@ -// deno-fmt-ignore-file -// deno-lint-ignore-file - -// Copyright Joyent and Node contributors. All rights reserved. MIT license. -// Taken from Node 18.12.1 -// This file is automatically generated by "node/_tools/setup.ts". Do not modify this file manually - -// Flags: --expose-internals -'use strict'; - -const common = require('../common'); -const assert = require('assert'); -const readline = require('readline'); -const { Writable } = require('stream'); -const { CSI } = require('internal/readline/utils'); - -{ - assert(CSI); - assert.strictEqual(CSI.kClearToLineBeginning, '\x1b[1K'); - assert.strictEqual(CSI.kClearToLineEnd, '\x1b[0K'); - assert.strictEqual(CSI.kClearLine, '\x1b[2K'); - assert.strictEqual(CSI.kClearScreenDown, '\x1b[0J'); - assert.strictEqual(CSI`1${2}3`, '\x1b[123'); -} - -class TestWritable extends Writable { - constructor() { - super(); - this.data = ''; - } - _write(chunk, encoding, callback) { - this.data += chunk.toString(); - callback(); - } -} - -const writable = new TestWritable(); - -assert.strictEqual(readline.clearScreenDown(writable), true); -assert.deepStrictEqual(writable.data, CSI.kClearScreenDown); -assert.strictEqual(readline.clearScreenDown(writable, common.mustCall()), true); - -// Verify that clearScreenDown() throws on invalid callback. -assert.throws(() => { - readline.clearScreenDown(writable, null); -}, /ERR_INVALID_ARG_TYPE/); - -// Verify that clearScreenDown() does not throw on null or undefined stream. -assert.strictEqual(readline.clearScreenDown(null, common.mustCall((err) => { - assert.strictEqual(err, null); -})), true); -assert.strictEqual(readline.clearScreenDown(undefined, common.mustCall()), - true); - -writable.data = ''; -assert.strictEqual(readline.clearLine(writable, -1), true); -assert.deepStrictEqual(writable.data, CSI.kClearToLineBeginning); - -writable.data = ''; -assert.strictEqual(readline.clearLine(writable, 1), true); -assert.deepStrictEqual(writable.data, CSI.kClearToLineEnd); - -writable.data = ''; -assert.strictEqual(readline.clearLine(writable, 0), true); -assert.deepStrictEqual(writable.data, CSI.kClearLine); - -writable.data = ''; -assert.strictEqual(readline.clearLine(writable, -1, common.mustCall()), true); -assert.deepStrictEqual(writable.data, CSI.kClearToLineBeginning); - -// Verify that clearLine() throws on invalid callback. -assert.throws(() => { - readline.clearLine(writable, 0, null); -}, /ERR_INVALID_ARG_TYPE/); - -// Verify that clearLine() does not throw on null or undefined stream. -assert.strictEqual(readline.clearLine(null, 0), true); -assert.strictEqual(readline.clearLine(undefined, 0), true); -assert.strictEqual(readline.clearLine(null, 0, common.mustCall((err) => { - assert.strictEqual(err, null); -})), true); -assert.strictEqual(readline.clearLine(undefined, 0, common.mustCall()), true); - -// Nothing is written when moveCursor 0, 0 -[ - [0, 0, ''], - [1, 0, '\x1b[1C'], - [-1, 0, '\x1b[1D'], - [0, 1, '\x1b[1B'], - [0, -1, '\x1b[1A'], - [1, 1, '\x1b[1C\x1b[1B'], - [-1, 1, '\x1b[1D\x1b[1B'], - [-1, -1, '\x1b[1D\x1b[1A'], - [1, -1, '\x1b[1C\x1b[1A'], -].forEach((set) => { - writable.data = ''; - assert.strictEqual(readline.moveCursor(writable, set[0], set[1]), true); - assert.deepStrictEqual(writable.data, set[2]); - writable.data = ''; - assert.strictEqual( - readline.moveCursor(writable, set[0], set[1], common.mustCall()), - true - ); - assert.deepStrictEqual(writable.data, set[2]); -}); - -// Verify that moveCursor() throws on invalid callback. -assert.throws(() => { - readline.moveCursor(writable, 1, 1, null); -}, /ERR_INVALID_ARG_TYPE/); - -// Verify that moveCursor() does not throw on null or undefined stream. -assert.strictEqual(readline.moveCursor(null, 1, 1), true); -assert.strictEqual(readline.moveCursor(undefined, 1, 1), true); -assert.strictEqual(readline.moveCursor(null, 1, 1, common.mustCall((err) => { - assert.strictEqual(err, null); -})), true); -assert.strictEqual(readline.moveCursor(undefined, 1, 1, common.mustCall()), - true); - -// Undefined or null as stream should not throw. -assert.strictEqual(readline.cursorTo(null), true); -assert.strictEqual(readline.cursorTo(), true); -assert.strictEqual(readline.cursorTo(null, 1, 1, common.mustCall()), true); -assert.strictEqual(readline.cursorTo(undefined, 1, 1, common.mustCall((err) => { - assert.strictEqual(err, null); -})), true); - -writable.data = ''; -assert.strictEqual(readline.cursorTo(writable, 'a'), true); -assert.strictEqual(writable.data, ''); - -writable.data = ''; -assert.strictEqual(readline.cursorTo(writable, 'a', 'b'), true); -assert.strictEqual(writable.data, ''); - -writable.data = ''; -assert.throws( - () => readline.cursorTo(writable, 'a', 1), - { - name: 'TypeError', - code: 'ERR_INVALID_CURSOR_POS', - message: 'Cannot set cursor row without setting its column' - }); -assert.strictEqual(writable.data, ''); - -writable.data = ''; -assert.strictEqual(readline.cursorTo(writable, 1, 'a'), true); -assert.strictEqual(writable.data, '\x1b[2G'); - -writable.data = ''; -assert.strictEqual(readline.cursorTo(writable, 1), true); -assert.strictEqual(writable.data, '\x1b[2G'); - -writable.data = ''; -assert.strictEqual(readline.cursorTo(writable, 1, 2), true); -assert.strictEqual(writable.data, '\x1b[3;2H'); - -writable.data = ''; -assert.strictEqual(readline.cursorTo(writable, 1, 2, common.mustCall()), true); -assert.strictEqual(writable.data, '\x1b[3;2H'); - -writable.data = ''; -assert.strictEqual(readline.cursorTo(writable, 1, common.mustCall()), true); -assert.strictEqual(writable.data, '\x1b[2G'); - -// Verify that cursorTo() throws on invalid callback. -assert.throws(() => { - readline.cursorTo(writable, 1, 1, null); -}, /ERR_INVALID_ARG_TYPE/); - -// Verify that cursorTo() throws if x or y is NaN. -assert.throws(() => { - readline.cursorTo(writable, NaN); -}, /ERR_INVALID_ARG_VALUE/); - -assert.throws(() => { - readline.cursorTo(writable, 1, NaN); -}, /ERR_INVALID_ARG_VALUE/); - -assert.throws(() => { - readline.cursorTo(writable, NaN, NaN); -}, /ERR_INVALID_ARG_VALUE/); diff --git a/cli/tests/node_compat/test/parallel/test-readline-promises-csi.mjs b/cli/tests/node_compat/test/parallel/test-readline-promises-csi.mjs deleted file mode 100644 index fb61b52d9..000000000 --- a/cli/tests/node_compat/test/parallel/test-readline-promises-csi.mjs +++ /dev/null @@ -1,233 +0,0 @@ -// deno-fmt-ignore-file -// deno-lint-ignore-file - -// Copyright Joyent and Node contributors. All rights reserved. MIT license. -// Taken from Node 18.12.1 -// This file is automatically generated by "node/_tools/setup.ts". Do not modify this file manually - -// Flags: --expose-internals - - -import '../common/index.mjs'; -import assert from 'assert'; -import { Readline } from 'readline/promises'; -import { setImmediate } from 'timers/promises'; -import { Writable } from 'stream'; - -import utils from 'internal/readline/utils'; -const { CSI } = utils; - -const INVALID_ARG = { - name: 'TypeError', - code: 'ERR_INVALID_ARG_TYPE', -}; - -class TestWritable extends Writable { - data = ''; - _write(chunk, encoding, callback) { - this.data += chunk.toString(); - callback(); - } -} - -[ - undefined, null, - 0, 1, 1n, 1.1, NaN, Infinity, - true, false, - Symbol(), - '', '1', - [], {}, () => {}, -].forEach((arg) => - assert.throws(() => new Readline(arg), INVALID_ARG) -); - -{ - const writable = new TestWritable(); - const readline = new Readline(writable); - - await readline.clearScreenDown().commit(); - assert.deepStrictEqual(writable.data, CSI.kClearScreenDown); - await readline.clearScreenDown().commit(); - - writable.data = ''; - await readline.clearScreenDown().rollback(); - assert.strictEqual(writable.data, ''); - - writable.data = ''; - await readline.clearLine(-1).commit(); - assert.deepStrictEqual(writable.data, CSI.kClearToLineBeginning); - - writable.data = ''; - await readline.clearLine(1).commit(); - assert.deepStrictEqual(writable.data, CSI.kClearToLineEnd); - - writable.data = ''; - await readline.clearLine(0).commit(); - assert.deepStrictEqual(writable.data, CSI.kClearLine); - - writable.data = ''; - await readline.clearLine(-1).commit(); - assert.deepStrictEqual(writable.data, CSI.kClearToLineBeginning); - - await readline.clearLine(0, null).commit(); - - // Nothing is written when moveCursor 0, 0 - for (const set of - [ - [0, 0, ''], - [1, 0, '\x1b[1C'], - [-1, 0, '\x1b[1D'], - [0, 1, '\x1b[1B'], - [0, -1, '\x1b[1A'], - [1, 1, '\x1b[1C\x1b[1B'], - [-1, 1, '\x1b[1D\x1b[1B'], - [-1, -1, '\x1b[1D\x1b[1A'], - [1, -1, '\x1b[1C\x1b[1A'], - ]) { - writable.data = ''; - await readline.moveCursor(set[0], set[1]).commit(); - assert.deepStrictEqual(writable.data, set[2]); - writable.data = ''; - await readline.moveCursor(set[0], set[1]).commit(); - assert.deepStrictEqual(writable.data, set[2]); - } - - - await readline.moveCursor(1, 1, null).commit(); - - writable.data = ''; - [ - undefined, null, - true, false, - Symbol(), - '', '1', - [], {}, () => {}, - ].forEach((arg) => - assert.throws(() => readline.cursorTo(arg), INVALID_ARG) - ); - assert.strictEqual(writable.data, ''); - - writable.data = ''; - assert.throws(() => readline.cursorTo('a', 'b'), INVALID_ARG); - assert.strictEqual(writable.data, ''); - - writable.data = ''; - assert.throws(() => readline.cursorTo('a', 1), INVALID_ARG); - assert.strictEqual(writable.data, ''); - - writable.data = ''; - assert.throws(() => readline.cursorTo(1, 'a'), INVALID_ARG); - assert.strictEqual(writable.data, ''); - - writable.data = ''; - await readline.cursorTo(1).commit(); - assert.strictEqual(writable.data, '\x1b[2G'); - - writable.data = ''; - await readline.cursorTo(1, 2).commit(); - assert.strictEqual(writable.data, '\x1b[3;2H'); - - writable.data = ''; - await readline.cursorTo(1, 2).commit(); - assert.strictEqual(writable.data, '\x1b[3;2H'); - - writable.data = ''; - await readline.cursorTo(1).cursorTo(1, 2).commit(); - assert.strictEqual(writable.data, '\x1b[2G\x1b[3;2H'); - - writable.data = ''; - await readline.cursorTo(1).commit(); - assert.strictEqual(writable.data, '\x1b[2G'); - - // Verify that cursorTo() rejects if x or y is NaN. - [1.1, NaN, Infinity].forEach((arg) => { - assert.throws(() => readline.cursorTo(arg), { - code: 'ERR_OUT_OF_RANGE', - name: 'RangeError', - }); - }); - - [1.1, NaN, Infinity].forEach((arg) => { - assert.throws(() => readline.cursorTo(1, arg), { - code: 'ERR_OUT_OF_RANGE', - name: 'RangeError', - }); - }); - - assert.throws(() => readline.cursorTo(NaN, NaN), { - code: 'ERR_OUT_OF_RANGE', - name: 'RangeError', - }); -} - -{ - const error = new Error(); - const writable = new class extends Writable { - _write() { throw error; } - }(); - const readline = new Readline(writable); - - await assert.rejects(readline.cursorTo(1).commit(), error); -} - -{ - const writable = new TestWritable(); - const readline = new Readline(writable, { autoCommit: true }); - - await readline.clearScreenDown(); - await setImmediate(); // Wait for next tick as auto commit is asynchronous. - assert.deepStrictEqual(writable.data, CSI.kClearScreenDown); -} - -{ - const writable = new TestWritable(); - const readline = new Readline(writable, { autoCommit: true }); - for (const [dir, data] of - [ - [-1, CSI.kClearToLineBeginning], - [1, CSI.kClearToLineEnd], - [0, CSI.kClearLine], - ]) { - writable.data = ''; - readline.clearLine(dir); - await setImmediate(); // Wait for next tick as auto commit is asynchronous. - assert.deepStrictEqual(writable.data, data); - } -} - -{ - const writable = new TestWritable(); - const readline = new Readline(writable, { autoCommit: true }); - for (const [x, y, data] of - [ - [0, 0, ''], - [1, 0, '\x1b[1C'], - [-1, 0, '\x1b[1D'], - [0, 1, '\x1b[1B'], - [0, -1, '\x1b[1A'], - [1, 1, '\x1b[1C\x1b[1B'], - [-1, 1, '\x1b[1D\x1b[1B'], - [-1, -1, '\x1b[1D\x1b[1A'], - [1, -1, '\x1b[1C\x1b[1A'], - ]) { - writable.data = ''; - readline.moveCursor(x, y); - await setImmediate(); // Wait for next tick as auto commit is asynchronous. - assert.deepStrictEqual(writable.data, data); - } -} - -{ - const writable = new TestWritable(); - const readline = new Readline(writable, { autoCommit: true }); - for (const [x, y, data] of - [ - [1, undefined, '\x1b[2G'], - [1, 2, '\x1b[3;2H'], - ]) { - writable.data = ''; - readline.cursorTo(x, y); - await setImmediate(); // Wait for next tick as auto commit is asynchronous. - assert.deepStrictEqual(writable.data, data); - } -} diff --git a/cli/tests/node_compat/test/parallel/test-readline-promises-interface.js b/cli/tests/node_compat/test/parallel/test-readline-promises-interface.js deleted file mode 100644 index fbbfb46ad..000000000 --- a/cli/tests/node_compat/test/parallel/test-readline-promises-interface.js +++ /dev/null @@ -1,1149 +0,0 @@ -// deno-fmt-ignore-file -// deno-lint-ignore-file - -// Copyright Joyent and Node contributors. All rights reserved. MIT license. -// Taken from Node 18.12.1 -// This file is automatically generated by "node/_tools/setup.ts". Do not modify this file manually - -// Flags: --expose-internals -'use strict'; -const common = require('../common'); -common.skipIfDumbTerminal(); - -const assert = require('assert'); -const readline = require('readline/promises'); -const { - getStringWidth, - stripVTControlCharacters -} = require('internal/util/inspect'); -const EventEmitter = require('events').EventEmitter; -const { Writable, Readable } = require('stream'); - -class FakeInput extends EventEmitter { - resume() {} - pause() {} - write() {} - end() {} -} - -function isWarned(emitter) { - for (const name in emitter) { - const listeners = emitter[name]; - if (listeners.warned) return true; - } - return false; -} - -function getInterface(options) { - const fi = new FakeInput(); - const rli = new readline.Interface({ - input: fi, - output: fi, - ...options, - }); - return [rli, fi]; -} - -function assertCursorRowsAndCols(rli, rows, cols) { - const cursorPos = rli.getCursorPos(); - assert.strictEqual(cursorPos.rows, rows); - assert.strictEqual(cursorPos.cols, cols); -} - -[ - undefined, - 50, - 0, - 100.5, - 5000, -].forEach((crlfDelay) => { - const [rli] = getInterface({ crlfDelay }); - assert.strictEqual(rli.crlfDelay, Math.max(crlfDelay || 100, 100)); - rli.close(); -}); - -{ - const input = new FakeInput(); - - // Constructor throws if completer is not a function or undefined - assert.throws(() => { - readline.createInterface({ - input, - completer: 'string is not valid' - }); - }, { - name: 'TypeError', - code: 'ERR_INVALID_ARG_VALUE' - }); - - assert.throws(() => { - readline.createInterface({ - input, - completer: '' - }); - }, { - name: 'TypeError', - code: 'ERR_INVALID_ARG_VALUE' - }); - - assert.throws(() => { - readline.createInterface({ - input, - completer: false - }); - }, { - name: 'TypeError', - code: 'ERR_INVALID_ARG_VALUE' - }); - - // Constructor throws if history is not an array - ['not an array', 123, 123n, {}, true, Symbol(), null].forEach((history) => { - assert.throws(() => { - readline.createInterface({ - input, - history, - }); - }, { - name: 'TypeError', - code: 'ERR_INVALID_ARG_TYPE' - }); - }); - - // Constructor throws if historySize is not a positive number - ['not a number', -1, NaN, {}, true, Symbol(), null].forEach((historySize) => { - assert.throws(() => { - readline.createInterface({ - input, - historySize, - }); - }, { - name: 'RangeError', - code: 'ERR_INVALID_ARG_VALUE' - }); - }); - - // Check for invalid tab sizes. - assert.throws( - () => new readline.Interface({ - input, - tabSize: 0 - }), - { code: 'ERR_OUT_OF_RANGE' } - ); - - assert.throws( - () => new readline.Interface({ - input, - tabSize: '4' - }), - { code: 'ERR_INVALID_ARG_TYPE' } - ); - - assert.throws( - () => new readline.Interface({ - input, - tabSize: 4.5 - }), - { - code: 'ERR_OUT_OF_RANGE', - message: 'The value of "tabSize" is out of range. ' + - 'It must be an integer. Received 4.5' - } - ); -} - -// Sending a single character with no newline -{ - const fi = new FakeInput(); - const rli = new readline.Interface(fi, {}); - rli.on('line', common.mustNotCall()); - fi.emit('data', 'a'); - rli.close(); -} - -// Sending multiple newlines at once that does not end with a new line and a -// `end` event(last line is). \r should behave like \n when alone. -{ - const [rli, fi] = getInterface({ terminal: true }); - const expectedLines = ['foo', 'bar', 'baz', 'bat']; - rli.on('line', common.mustCall((line) => { - assert.strictEqual(line, expectedLines.shift()); - }, expectedLines.length - 1)); - fi.emit('data', expectedLines.join('\r')); - rli.close(); -} - -// \r at start of input should output blank line -{ - const [rli, fi] = getInterface({ terminal: true }); - const expectedLines = ['', 'foo' ]; - rli.on('line', common.mustCall((line) => { - assert.strictEqual(line, expectedLines.shift()); - }, expectedLines.length)); - fi.emit('data', '\rfoo\r'); - rli.close(); -} - -// \t does not become part of the input when there is a completer function -{ - const completer = (line) => [[], line]; - const [rli, fi] = getInterface({ terminal: true, completer }); - rli.on('line', common.mustCall((line) => { - assert.strictEqual(line, 'foo'); - })); - for (const character of '\tfo\to\t') { - fi.emit('data', character); - } - fi.emit('data', '\n'); - rli.close(); -} - -// \t when there is no completer function should behave like an ordinary -// character -{ - const [rli, fi] = getInterface({ terminal: true }); - rli.on('line', common.mustCall((line) => { - assert.strictEqual(line, '\t'); - })); - fi.emit('data', '\t'); - fi.emit('data', '\n'); - rli.close(); -} - -// Adding history lines should emit the history event with -// the history array -{ - const [rli, fi] = getInterface({ terminal: true }); - const expectedLines = ['foo', 'bar', 'baz', 'bat']; - rli.on('history', common.mustCall((history) => { - const expectedHistory = expectedLines.slice(0, history.length).reverse(); - assert.deepStrictEqual(history, expectedHistory); - }, expectedLines.length)); - for (const line of expectedLines) { - fi.emit('data', `${line}\n`); - } - rli.close(); -} - -// Altering the history array in the listener should not alter -// the line being processed -{ - const [rli, fi] = getInterface({ terminal: true }); - const expectedLine = 'foo'; - rli.on('history', common.mustCall((history) => { - assert.strictEqual(history[0], expectedLine); - history.shift(); - })); - rli.on('line', common.mustCall((line) => { - assert.strictEqual(line, expectedLine); - assert.strictEqual(rli.history.length, 0); - })); - fi.emit('data', `${expectedLine}\n`); - rli.close(); -} - -// Duplicate lines are removed from history when -// `options.removeHistoryDuplicates` is `true` -{ - const [rli, fi] = getInterface({ - terminal: true, - removeHistoryDuplicates: true - }); - const expectedLines = ['foo', 'bar', 'baz', 'bar', 'bat', 'bat']; - // ['foo', 'baz', 'bar', bat']; - let callCount = 0; - rli.on('line', function(line) { - assert.strictEqual(line, expectedLines[callCount]); - callCount++; - }); - fi.emit('data', `${expectedLines.join('\n')}\n`); - assert.strictEqual(callCount, expectedLines.length); - fi.emit('keypress', '.', { name: 'up' }); // 'bat' - assert.strictEqual(rli.line, expectedLines[--callCount]); - fi.emit('keypress', '.', { name: 'up' }); // 'bar' - assert.notStrictEqual(rli.line, expectedLines[--callCount]); - assert.strictEqual(rli.line, expectedLines[--callCount]); - fi.emit('keypress', '.', { name: 'up' }); // 'baz' - assert.strictEqual(rli.line, expectedLines[--callCount]); - fi.emit('keypress', '.', { name: 'up' }); // 'foo' - assert.notStrictEqual(rli.line, expectedLines[--callCount]); - assert.strictEqual(rli.line, expectedLines[--callCount]); - assert.strictEqual(callCount, 0); - fi.emit('keypress', '.', { name: 'down' }); // 'baz' - assert.strictEqual(rli.line, 'baz'); - assert.strictEqual(rli.historyIndex, 2); - fi.emit('keypress', '.', { name: 'n', ctrl: true }); // 'bar' - assert.strictEqual(rli.line, 'bar'); - assert.strictEqual(rli.historyIndex, 1); - fi.emit('keypress', '.', { name: 'n', ctrl: true }); - assert.strictEqual(rli.line, 'bat'); - assert.strictEqual(rli.historyIndex, 0); - // Activate the substring history search. - fi.emit('keypress', '.', { name: 'down' }); // 'bat' - assert.strictEqual(rli.line, 'bat'); - assert.strictEqual(rli.historyIndex, -1); - // Deactivate substring history search. - fi.emit('keypress', '.', { name: 'backspace' }); // 'ba' - assert.strictEqual(rli.historyIndex, -1); - assert.strictEqual(rli.line, 'ba'); - // Activate the substring history search. - fi.emit('keypress', '.', { name: 'down' }); // 'ba' - assert.strictEqual(rli.historyIndex, -1); - assert.strictEqual(rli.line, 'ba'); - fi.emit('keypress', '.', { name: 'down' }); // 'ba' - assert.strictEqual(rli.historyIndex, -1); - assert.strictEqual(rli.line, 'ba'); - fi.emit('keypress', '.', { name: 'up' }); // 'bat' - assert.strictEqual(rli.historyIndex, 0); - assert.strictEqual(rli.line, 'bat'); - fi.emit('keypress', '.', { name: 'up' }); // 'bar' - assert.strictEqual(rli.historyIndex, 1); - assert.strictEqual(rli.line, 'bar'); - fi.emit('keypress', '.', { name: 'up' }); // 'baz' - assert.strictEqual(rli.historyIndex, 2); - assert.strictEqual(rli.line, 'baz'); - fi.emit('keypress', '.', { name: 'up' }); // 'ba' - assert.strictEqual(rli.historyIndex, 4); - assert.strictEqual(rli.line, 'ba'); - fi.emit('keypress', '.', { name: 'up' }); // 'ba' - assert.strictEqual(rli.historyIndex, 4); - assert.strictEqual(rli.line, 'ba'); - // Deactivate substring history search and reset history index. - fi.emit('keypress', '.', { name: 'right' }); // 'ba' - assert.strictEqual(rli.historyIndex, -1); - assert.strictEqual(rli.line, 'ba'); - // Substring history search activated. - fi.emit('keypress', '.', { name: 'up' }); // 'ba' - assert.strictEqual(rli.historyIndex, 0); - assert.strictEqual(rli.line, 'bat'); - rli.close(); -} - -// Duplicate lines are not removed from history when -// `options.removeHistoryDuplicates` is `false` -{ - const [rli, fi] = getInterface({ - terminal: true, - removeHistoryDuplicates: false - }); - const expectedLines = ['foo', 'bar', 'baz', 'bar', 'bat', 'bat']; - let callCount = 0; - rli.on('line', function(line) { - assert.strictEqual(line, expectedLines[callCount]); - callCount++; - }); - fi.emit('data', `${expectedLines.join('\n')}\n`); - assert.strictEqual(callCount, expectedLines.length); - fi.emit('keypress', '.', { name: 'up' }); // 'bat' - assert.strictEqual(rli.line, expectedLines[--callCount]); - fi.emit('keypress', '.', { name: 'up' }); // 'bar' - assert.notStrictEqual(rli.line, expectedLines[--callCount]); - assert.strictEqual(rli.line, expectedLines[--callCount]); - fi.emit('keypress', '.', { name: 'up' }); // 'baz' - assert.strictEqual(rli.line, expectedLines[--callCount]); - fi.emit('keypress', '.', { name: 'up' }); // 'bar' - assert.strictEqual(rli.line, expectedLines[--callCount]); - fi.emit('keypress', '.', { name: 'up' }); // 'foo' - assert.strictEqual(rli.line, expectedLines[--callCount]); - assert.strictEqual(callCount, 0); - rli.close(); -} - -// Regression test for repl freeze, #1968: -// check that nothing fails if 'keypress' event throws. -{ - const [rli, fi] = getInterface({ terminal: true }); - const keys = []; - const err = new Error('bad thing happened'); - fi.on('keypress', function(key) { - keys.push(key); - if (key === 'X') { - throw err; - } - }); - assert.throws( - () => fi.emit('data', 'fooX'), - (e) => { - assert.strictEqual(e, err); - return true; - } - ); - fi.emit('data', 'bar'); - assert.strictEqual(keys.join(''), 'fooXbar'); - rli.close(); -} - -// History is bound -{ - const [rli, fi] = getInterface({ terminal: true, historySize: 2 }); - const lines = ['line 1', 'line 2', 'line 3']; - fi.emit('data', lines.join('\n') + '\n'); - assert.strictEqual(rli.history.length, 2); - assert.strictEqual(rli.history[0], 'line 3'); - assert.strictEqual(rli.history[1], 'line 2'); -} - -// Question -{ - const [rli] = getInterface({ terminal: true }); - const expectedLines = ['foo']; - rli.question(expectedLines[0]).then(() => rli.close()); - assertCursorRowsAndCols(rli, 0, expectedLines[0].length); - rli.close(); -} - -// Sending a multi-line question -{ - const [rli] = getInterface({ terminal: true }); - const expectedLines = ['foo', 'bar']; - rli.question(expectedLines.join('\n')).then(() => rli.close()); - assertCursorRowsAndCols( - rli, expectedLines.length - 1, expectedLines.slice(-1)[0].length); - rli.close(); -} - -{ - // Beginning and end of line - const [rli, fi] = getInterface({ terminal: true, prompt: '' }); - fi.emit('data', 'the quick brown fox'); - fi.emit('keypress', '.', { ctrl: true, name: 'a' }); - assertCursorRowsAndCols(rli, 0, 0); - fi.emit('keypress', '.', { ctrl: true, name: 'e' }); - assertCursorRowsAndCols(rli, 0, 19); - rli.close(); -} - -{ - // Back and Forward one character - const [rli, fi] = getInterface({ terminal: true, prompt: '' }); - fi.emit('data', 'the quick brown fox'); - assertCursorRowsAndCols(rli, 0, 19); - - // Back one character - fi.emit('keypress', '.', { ctrl: true, name: 'b' }); - assertCursorRowsAndCols(rli, 0, 18); - // Back one character - fi.emit('keypress', '.', { ctrl: true, name: 'b' }); - assertCursorRowsAndCols(rli, 0, 17); - // Forward one character - fi.emit('keypress', '.', { ctrl: true, name: 'f' }); - assertCursorRowsAndCols(rli, 0, 18); - // Forward one character - fi.emit('keypress', '.', { ctrl: true, name: 'f' }); - assertCursorRowsAndCols(rli, 0, 19); - rli.close(); -} - -// Back and Forward one astral character -{ - const [rli, fi] = getInterface({ terminal: true, prompt: '' }); - fi.emit('data', '💻'); - - // Move left one character/code point - fi.emit('keypress', '.', { name: 'left' }); - assertCursorRowsAndCols(rli, 0, 0); - - // Move right one character/code point - fi.emit('keypress', '.', { name: 'right' }); - assertCursorRowsAndCols(rli, 0, 2); - - rli.on('line', common.mustCall((line) => { - assert.strictEqual(line, '💻'); - })); - fi.emit('data', '\n'); - rli.close(); -} - -// Two astral characters left -{ - const [rli, fi] = getInterface({ terminal: true, prompt: '' }); - fi.emit('data', '💻'); - - // Move left one character/code point - fi.emit('keypress', '.', { name: 'left' }); - assertCursorRowsAndCols(rli, 0, 0); - - fi.emit('data', '🐕'); - assertCursorRowsAndCols(rli, 0, 2); - - rli.on('line', common.mustCall((line) => { - assert.strictEqual(line, '🐕💻'); - })); - fi.emit('data', '\n'); - rli.close(); -} - -// Two astral characters right -{ - const [rli, fi] = getInterface({ terminal: true, prompt: '' }); - fi.emit('data', '💻'); - - // Move left one character/code point - fi.emit('keypress', '.', { name: 'right' }); - assertCursorRowsAndCols(rli, 0, 2); - - fi.emit('data', '🐕'); - assertCursorRowsAndCols(rli, 0, 4); - - rli.on('line', common.mustCall((line) => { - assert.strictEqual(line, '💻🐕'); - })); - fi.emit('data', '\n'); - rli.close(); -} - -{ - // `wordLeft` and `wordRight` - const [rli, fi] = getInterface({ terminal: true, prompt: '' }); - fi.emit('data', 'the quick brown fox'); - fi.emit('keypress', '.', { ctrl: true, name: 'left' }); - assertCursorRowsAndCols(rli, 0, 16); - fi.emit('keypress', '.', { meta: true, name: 'b' }); - assertCursorRowsAndCols(rli, 0, 10); - fi.emit('keypress', '.', { ctrl: true, name: 'right' }); - assertCursorRowsAndCols(rli, 0, 16); - fi.emit('keypress', '.', { meta: true, name: 'f' }); - assertCursorRowsAndCols(rli, 0, 19); - rli.close(); -} - -// `deleteWordLeft` -[ - { ctrl: true, name: 'w' }, - { ctrl: true, name: 'backspace' }, - { meta: true, name: 'backspace' }, -].forEach((deleteWordLeftKey) => { - let [rli, fi] = getInterface({ terminal: true, prompt: '' }); - fi.emit('data', 'the quick brown fox'); - fi.emit('keypress', '.', { ctrl: true, name: 'left' }); - rli.on('line', common.mustCall((line) => { - assert.strictEqual(line, 'the quick fox'); - })); - fi.emit('keypress', '.', deleteWordLeftKey); - fi.emit('data', '\n'); - rli.close(); - - // No effect if pressed at beginning of line - [rli, fi] = getInterface({ terminal: true, prompt: '' }); - fi.emit('data', 'the quick brown fox'); - fi.emit('keypress', '.', { ctrl: true, name: 'a' }); - rli.on('line', common.mustCall((line) => { - assert.strictEqual(line, 'the quick brown fox'); - })); - fi.emit('keypress', '.', deleteWordLeftKey); - fi.emit('data', '\n'); - rli.close(); -}); - -// `deleteWordRight` -[ - { ctrl: true, name: 'delete' }, - { meta: true, name: 'delete' }, - { meta: true, name: 'd' }, -].forEach((deleteWordRightKey) => { - let [rli, fi] = getInterface({ terminal: true, prompt: '' }); - fi.emit('data', 'the quick brown fox'); - fi.emit('keypress', '.', { ctrl: true, name: 'left' }); - fi.emit('keypress', '.', { ctrl: true, name: 'left' }); - rli.on('line', common.mustCall((line) => { - assert.strictEqual(line, 'the quick fox'); - })); - fi.emit('keypress', '.', deleteWordRightKey); - fi.emit('data', '\n'); - rli.close(); - - // No effect if pressed at end of line - [rli, fi] = getInterface({ terminal: true, prompt: '' }); - fi.emit('data', 'the quick brown fox'); - rli.on('line', common.mustCall((line) => { - assert.strictEqual(line, 'the quick brown fox'); - })); - fi.emit('keypress', '.', deleteWordRightKey); - fi.emit('data', '\n'); - rli.close(); -}); - -// deleteLeft -{ - const [rli, fi] = getInterface({ terminal: true, prompt: '' }); - fi.emit('data', 'the quick brown fox'); - assertCursorRowsAndCols(rli, 0, 19); - - // Delete left character - fi.emit('keypress', '.', { ctrl: true, name: 'h' }); - assertCursorRowsAndCols(rli, 0, 18); - rli.on('line', common.mustCall((line) => { - assert.strictEqual(line, 'the quick brown fo'); - })); - fi.emit('data', '\n'); - rli.close(); -} - -// deleteLeft astral character -{ - const [rli, fi] = getInterface({ terminal: true, prompt: '' }); - fi.emit('data', '💻'); - assertCursorRowsAndCols(rli, 0, 2); - // Delete left character - fi.emit('keypress', '.', { ctrl: true, name: 'h' }); - assertCursorRowsAndCols(rli, 0, 0); - rli.on('line', common.mustCall((line) => { - assert.strictEqual(line, ''); - })); - fi.emit('data', '\n'); - rli.close(); -} - -// deleteRight -{ - const [rli, fi] = getInterface({ terminal: true, prompt: '' }); - fi.emit('data', 'the quick brown fox'); - - // Go to the start of the line - fi.emit('keypress', '.', { ctrl: true, name: 'a' }); - assertCursorRowsAndCols(rli, 0, 0); - - // Delete right character - fi.emit('keypress', '.', { ctrl: true, name: 'd' }); - assertCursorRowsAndCols(rli, 0, 0); - rli.on('line', common.mustCall((line) => { - assert.strictEqual(line, 'he quick brown fox'); - })); - fi.emit('data', '\n'); - rli.close(); -} - -// deleteRight astral character -{ - const [rli, fi] = getInterface({ terminal: true, prompt: '' }); - fi.emit('data', '💻'); - - // Go to the start of the line - fi.emit('keypress', '.', { ctrl: true, name: 'a' }); - assertCursorRowsAndCols(rli, 0, 0); - - // Delete right character - fi.emit('keypress', '.', { ctrl: true, name: 'd' }); - assertCursorRowsAndCols(rli, 0, 0); - rli.on('line', common.mustCall((line) => { - assert.strictEqual(line, ''); - })); - fi.emit('data', '\n'); - rli.close(); -} - -// deleteLineLeft -{ - const [rli, fi] = getInterface({ terminal: true, prompt: '' }); - fi.emit('data', 'the quick brown fox'); - assertCursorRowsAndCols(rli, 0, 19); - - // Delete from current to start of line - fi.emit('keypress', '.', { ctrl: true, shift: true, name: 'backspace' }); - assertCursorRowsAndCols(rli, 0, 0); - rli.on('line', common.mustCall((line) => { - assert.strictEqual(line, ''); - })); - fi.emit('data', '\n'); - rli.close(); -} - -// deleteLineRight -{ - const [rli, fi] = getInterface({ terminal: true, prompt: '' }); - fi.emit('data', 'the quick brown fox'); - - // Go to the start of the line - fi.emit('keypress', '.', { ctrl: true, name: 'a' }); - assertCursorRowsAndCols(rli, 0, 0); - - // Delete from current to end of line - fi.emit('keypress', '.', { ctrl: true, shift: true, name: 'delete' }); - assertCursorRowsAndCols(rli, 0, 0); - rli.on('line', common.mustCall((line) => { - assert.strictEqual(line, ''); - })); - fi.emit('data', '\n'); - rli.close(); -} - -// Close readline interface -{ - const [rli, fi] = getInterface({ terminal: true, prompt: '' }); - fi.emit('keypress', '.', { ctrl: true, name: 'c' }); - assert(rli.closed); -} - -// Multi-line input cursor position -{ - const [rli, fi] = getInterface({ terminal: true, prompt: '' }); - fi.columns = 10; - fi.emit('data', 'multi-line text'); - assertCursorRowsAndCols(rli, 1, 5); - rli.close(); -} - -// Multi-line input cursor position and long tabs -{ - const [rli, fi] = getInterface({ tabSize: 16, terminal: true, prompt: '' }); - fi.columns = 10; - fi.emit('data', 'multi-line\ttext \t'); - assert.strictEqual(rli.cursor, 17); - assertCursorRowsAndCols(rli, 3, 2); - rli.close(); -} - -// Check for the default tab size. -{ - const [rli, fi] = getInterface({ terminal: true, prompt: '' }); - fi.emit('data', 'the quick\tbrown\tfox'); - assert.strictEqual(rli.cursor, 19); - // The first tab is 7 spaces long, the second one 3 spaces. - assertCursorRowsAndCols(rli, 0, 27); -} - -// Multi-line prompt cursor position -{ - const [rli, fi] = getInterface({ - terminal: true, - prompt: '\nfilledline\nwraping text\n> ' - }); - fi.columns = 10; - fi.emit('data', 't'); - assertCursorRowsAndCols(rli, 4, 3); - rli.close(); -} - -// Clear the whole screen -{ - const [rli, fi] = getInterface({ terminal: true, prompt: '' }); - const lines = ['line 1', 'line 2', 'line 3']; - fi.emit('data', lines.join('\n')); - fi.emit('keypress', '.', { ctrl: true, name: 'l' }); - assertCursorRowsAndCols(rli, 0, 6); - rli.on('line', common.mustCall((line) => { - assert.strictEqual(line, 'line 3'); - })); - fi.emit('data', '\n'); - rli.close(); -} - -// Wide characters should be treated as two columns. -assert.strictEqual(getStringWidth('a'), 1); -assert.strictEqual(getStringWidth('あ'), 2); -assert.strictEqual(getStringWidth('谢'), 2); -assert.strictEqual(getStringWidth('고'), 2); -assert.strictEqual(getStringWidth(String.fromCodePoint(0x1f251)), 2); -assert.strictEqual(getStringWidth('abcde'), 5); -assert.strictEqual(getStringWidth('古池や'), 6); -assert.strictEqual(getStringWidth('ノード.js'), 9); -assert.strictEqual(getStringWidth('你好'), 4); -assert.strictEqual(getStringWidth('안녕하세요'), 10); -assert.strictEqual(getStringWidth('A\ud83c\ude00BC'), 5); -assert.strictEqual(getStringWidth('👨👩👦👦'), 8); -assert.strictEqual(getStringWidth('🐕𐐷あ💻😀'), 9); -// TODO(BridgeAR): This should have a width of 4. -assert.strictEqual(getStringWidth('⓬⓪'), 2); -assert.strictEqual(getStringWidth('\u0301\u200D\u200E'), 0); - -// Check if vt control chars are stripped -assert.strictEqual(stripVTControlCharacters('\u001b[31m> \u001b[39m'), '> '); -assert.strictEqual( - stripVTControlCharacters('\u001b[31m> \u001b[39m> '), - '> > ' -); -assert.strictEqual(stripVTControlCharacters('\u001b[31m\u001b[39m'), ''); -assert.strictEqual(stripVTControlCharacters('> '), '> '); -assert.strictEqual(getStringWidth('\u001b[31m> \u001b[39m'), 2); -assert.strictEqual(getStringWidth('\u001b[31m> \u001b[39m> '), 4); -assert.strictEqual(getStringWidth('\u001b[31m\u001b[39m'), 0); -assert.strictEqual(getStringWidth('> '), 2); - -// Check EventEmitter memory leak -for (let i = 0; i < 12; i++) { - const rl = readline.createInterface({ - input: process.stdin, - output: process.stdout - }); - rl.close(); - assert.strictEqual(isWarned(process.stdin._events), false); - assert.strictEqual(isWarned(process.stdout._events), false); -} - -[true, false].forEach(function(terminal) { - // Disable history - { - const [rli, fi] = getInterface({ terminal, historySize: 0 }); - assert.strictEqual(rli.historySize, 0); - - fi.emit('data', 'asdf\n'); - assert.deepStrictEqual(rli.history, []); - rli.close(); - } - - // Default history size 30 - { - const [rli, fi] = getInterface({ terminal }); - assert.strictEqual(rli.historySize, 30); - - fi.emit('data', 'asdf\n'); - assert.deepStrictEqual(rli.history, terminal ? ['asdf'] : []); - rli.close(); - } - - // Sending a full line - { - const [rli, fi] = getInterface({ terminal }); - rli.on('line', common.mustCall((line) => { - assert.strictEqual(line, 'asdf'); - })); - fi.emit('data', 'asdf\n'); - } - - // Ensure that options.signal.removeEventListener was called - { - const ac = new AbortController(); - const signal = ac.signal; - const [rli] = getInterface({ terminal }); - signal.removeEventListener = common.mustCall( - (event, onAbortFn) => { - assert.strictEqual(event, 'abort'); - assert.strictEqual(onAbortFn.name, 'onAbort'); - }); - - rli.question('hello?', { signal }).then(common.mustCall()); - - rli.write('bar\n'); - ac.abort(); - rli.close(); - } - - // Sending a blank line - { - const [rli, fi] = getInterface({ terminal }); - rli.on('line', common.mustCall((line) => { - assert.strictEqual(line, ''); - })); - fi.emit('data', '\n'); - } - - // Sending a single character with no newline and then a newline - { - const [rli, fi] = getInterface({ terminal }); - let called = false; - rli.on('line', (line) => { - called = true; - assert.strictEqual(line, 'a'); - }); - fi.emit('data', 'a'); - assert.ok(!called); - fi.emit('data', '\n'); - assert.ok(called); - rli.close(); - } - - // Sending multiple newlines at once - { - const [rli, fi] = getInterface({ terminal }); - const expectedLines = ['foo', 'bar', 'baz']; - rli.on('line', common.mustCall((line) => { - assert.strictEqual(line, expectedLines.shift()); - }, expectedLines.length)); - fi.emit('data', `${expectedLines.join('\n')}\n`); - rli.close(); - } - - // Sending multiple newlines at once that does not end with a new line - { - const [rli, fi] = getInterface({ terminal }); - const expectedLines = ['foo', 'bar', 'baz', 'bat']; - rli.on('line', common.mustCall((line) => { - assert.strictEqual(line, expectedLines.shift()); - }, expectedLines.length - 1)); - fi.emit('data', expectedLines.join('\n')); - rli.close(); - } - - // Sending multiple newlines at once that does not end with a new(empty) - // line and a `end` event - { - const [rli, fi] = getInterface({ terminal }); - const expectedLines = ['foo', 'bar', 'baz', '']; - rli.on('line', common.mustCall((line) => { - assert.strictEqual(line, expectedLines.shift()); - }, expectedLines.length - 1)); - rli.on('close', common.mustCall()); - fi.emit('data', expectedLines.join('\n')); - fi.emit('end'); - rli.close(); - } - - // Sending a multi-byte utf8 char over multiple writes - { - const buf = Buffer.from('☮', 'utf8'); - const [rli, fi] = getInterface({ terminal }); - let callCount = 0; - rli.on('line', function(line) { - callCount++; - assert.strictEqual(line, buf.toString('utf8')); - }); - for (const i of buf) { - fi.emit('data', Buffer.from([i])); - } - assert.strictEqual(callCount, 0); - fi.emit('data', '\n'); - assert.strictEqual(callCount, 1); - rli.close(); - } - - // Calling readline without `new` - { - const [rli, fi] = getInterface({ terminal }); - rli.on('line', common.mustCall((line) => { - assert.strictEqual(line, 'asdf'); - })); - fi.emit('data', 'asdf\n'); - rli.close(); - } - - // Calling the question callback - { - const [rli] = getInterface({ terminal }); - rli.question('foo?').then(common.mustCall((answer) => { - assert.strictEqual(answer, 'bar'); - })); - rli.write('bar\n'); - rli.close(); - } - - // Calling the question callback with abort signal - { - const [rli] = getInterface({ terminal }); - const { signal } = new AbortController(); - rli.question('foo?', { signal }).then(common.mustCall((answer) => { - assert.strictEqual(answer, 'bar'); - })); - rli.write('bar\n'); - rli.close(); - } - - // Aborting a question - { - const ac = new AbortController(); - const signal = ac.signal; - const [rli] = getInterface({ terminal }); - rli.on('line', common.mustCall((line) => { - assert.strictEqual(line, 'bar'); - })); - assert.rejects(rli.question('hello?', { signal }), { name: 'AbortError' }) - .then(common.mustCall()); - ac.abort(); - rli.write('bar\n'); - rli.close(); - } - - (async () => { - const [rli] = getInterface({ terminal }); - const signal = AbortSignal.abort('boom'); - await assert.rejects(rli.question('hello', { signal }), { - cause: 'boom', - }); - rli.close(); - })().then(common.mustCall()); - - // Throw an error when question is executed with an aborted signal - { - const ac = new AbortController(); - const signal = ac.signal; - ac.abort(); - const [rli] = getInterface({ terminal }); - assert.rejects( - rli.question('hello?', { signal }), - { - name: 'AbortError' - } - ).then(common.mustCall()); - rli.close(); - } - - // Call question after close - { - const [rli, fi] = getInterface({ terminal }); - rli.question('What\'s your name?').then(common.mustCall((name) => { - assert.strictEqual(name, 'Node.js'); - rli.close(); - rli.question('How are you?') - .then(common.mustNotCall(), common.expectsError({ - code: 'ERR_USE_AFTER_CLOSE', - name: 'Error' - })); - assert.notStrictEqual(rli.getPrompt(), 'How are you?'); - })); - fi.emit('data', 'Node.js\n'); - } - - - // Can create a new readline Interface with a null output argument - { - const [rli, fi] = getInterface({ output: null, terminal }); - rli.on('line', common.mustCall((line) => { - assert.strictEqual(line, 'asdf'); - })); - fi.emit('data', 'asdf\n'); - - rli.setPrompt('ddd> '); - rli.prompt(); - rli.write("really shouldn't be seeing this"); - rli.question('What do you think of node.js? ', function(answer) { - console.log('Thank you for your valuable feedback:', answer); - rli.close(); - }); - } - - // Calling the getPrompt method - { - const expectedPrompts = ['$ ', '> ']; - const [rli] = getInterface({ terminal }); - for (const prompt of expectedPrompts) { - rli.setPrompt(prompt); - assert.strictEqual(rli.getPrompt(), prompt); - } - } - - { - const expected = terminal ? - ['\u001b[1G', '\u001b[0J', '$ ', '\u001b[3G'] : - ['$ ']; - - const output = new Writable({ - write: common.mustCall((chunk, enc, cb) => { - assert.strictEqual(chunk.toString(), expected.shift()); - cb(); - rl.close(); - }, expected.length) - }); - - const rl = readline.createInterface({ - input: new Readable({ read: common.mustCall() }), - output, - prompt: '$ ', - terminal - }); - - rl.prompt(); - - assert.strictEqual(rl.getPrompt(), '$ '); - } - - { - const fi = new FakeInput(); - assert.deepStrictEqual(fi.listeners(terminal ? 'keypress' : 'data'), []); - } - - // Emit two line events when the delay - // between \r and \n exceeds crlfDelay - { - const crlfDelay = 200; - const [rli, fi] = getInterface({ terminal, crlfDelay }); - let callCount = 0; - rli.on('line', function(line) { - callCount++; - }); - fi.emit('data', '\r'); - setTimeout(common.mustCall(() => { - fi.emit('data', '\n'); - assert.strictEqual(callCount, 2); - rli.close(); - }), crlfDelay + 10); - } - - // For the purposes of the following tests, we do not care about the exact - // value of crlfDelay, only that the behaviour conforms to what's expected. - // Setting it to Infinity allows the test to succeed even under extreme - // CPU stress. - const crlfDelay = Infinity; - - // Set crlfDelay to `Infinity` is allowed - { - const delay = 200; - const [rli, fi] = getInterface({ terminal, crlfDelay }); - let callCount = 0; - rli.on('line', function(line) { - callCount++; - }); - fi.emit('data', '\r'); - setTimeout(common.mustCall(() => { - fi.emit('data', '\n'); - assert.strictEqual(callCount, 1); - rli.close(); - }), delay); - } - - // Sending multiple newlines at once that does not end with a new line - // and a `end` event(last line is) - - // \r\n should emit one line event, not two - { - const [rli, fi] = getInterface({ terminal, crlfDelay }); - const expectedLines = ['foo', 'bar', 'baz', 'bat']; - rli.on('line', common.mustCall((line) => { - assert.strictEqual(line, expectedLines.shift()); - }, expectedLines.length - 1)); - fi.emit('data', expectedLines.join('\r\n')); - rli.close(); - } - - // \r\n should emit one line event when split across multiple writes. - { - const [rli, fi] = getInterface({ terminal, crlfDelay }); - const expectedLines = ['foo', 'bar', 'baz', 'bat']; - let callCount = 0; - rli.on('line', common.mustCall((line) => { - assert.strictEqual(line, expectedLines[callCount]); - callCount++; - }, expectedLines.length)); - expectedLines.forEach((line) => { - fi.emit('data', `${line}\r`); - fi.emit('data', '\n'); - }); - rli.close(); - } - - // Emit one line event when the delay between \r and \n is - // over the default crlfDelay but within the setting value. - { - const delay = 125; - const [rli, fi] = getInterface({ terminal, crlfDelay }); - let callCount = 0; - rli.on('line', () => callCount++); - fi.emit('data', '\r'); - setTimeout(common.mustCall(() => { - fi.emit('data', '\n'); - assert.strictEqual(callCount, 1); - rli.close(); - }), delay); - } -}); - -// Ensure that the _wordLeft method works even for large input -{ - const input = new Readable({ - read() { - this.push('\x1B[1;5D'); // CTRL + Left - this.push(null); - }, - }); - const output = new Writable({ - write: common.mustCall((data, encoding, cb) => { - assert.strictEqual(rl.cursor, rl.line.length - 1); - cb(); - }), - }); - const rl = new readline.createInterface({ - input, - output, - terminal: true, - }); - rl.line = `a${' '.repeat(1e6)}a`; - rl.cursor = rl.line.length; -} diff --git a/cli/tests/node_compat/test/parallel/test-stream-asIndexedPairs.mjs b/cli/tests/node_compat/test/parallel/test-stream-asIndexedPairs.mjs deleted file mode 100644 index f7f8b6d7c..000000000 --- a/cli/tests/node_compat/test/parallel/test-stream-asIndexedPairs.mjs +++ /dev/null @@ -1,60 +0,0 @@ -// deno-fmt-ignore-file -// deno-lint-ignore-file - -// Copyright Joyent and Node contributors. All rights reserved. MIT license. -// Taken from Node 18.12.1 -// This file is automatically generated by "node/_tools/setup.ts". Do not modify this file manually - -import '../common/index.mjs'; -import { Readable } from 'stream'; -import { deepStrictEqual, rejects, throws } from 'assert'; - -{ - // asIndexedPairs with a synchronous stream - const pairs = await Readable.from([1, 2, 3]).asIndexedPairs().toArray(); - deepStrictEqual(pairs, [[0, 1], [1, 2], [2, 3]]); - const empty = await Readable.from([]).asIndexedPairs().toArray(); - deepStrictEqual(empty, []); -} - -{ - // asIndexedPairs works an asynchronous streams - const asyncFrom = (...args) => Readable.from(...args).map(async (x) => x); - const pairs = await asyncFrom([1, 2, 3]).asIndexedPairs().toArray(); - deepStrictEqual(pairs, [[0, 1], [1, 2], [2, 3]]); - const empty = await asyncFrom([]).asIndexedPairs().toArray(); - deepStrictEqual(empty, []); -} - -{ - // Does not enumerate an infinite stream - const infinite = () => Readable.from(async function* () { - while (true) yield 1; - }()); - const pairs = await infinite().asIndexedPairs().take(3).toArray(); - deepStrictEqual(pairs, [[0, 1], [1, 1], [2, 1]]); - const empty = await infinite().asIndexedPairs().take(0).toArray(); - deepStrictEqual(empty, []); -} - -{ - // AbortSignal - await rejects(async () => { - const ac = new AbortController(); - const { signal } = ac; - const p = Readable.from([1, 2, 3]).asIndexedPairs({ signal }).toArray(); - ac.abort(); - await p; - }, { name: 'AbortError' }); - - await rejects(async () => { - const signal = AbortSignal.abort(); - await Readable.from([1, 2, 3]).asIndexedPairs({ signal }).toArray(); - }, /AbortError/); -} - -{ - // Error cases - throws(() => Readable.from([1]).asIndexedPairs(1), /ERR_INVALID_ARG_TYPE/); - throws(() => Readable.from([1]).asIndexedPairs({ signal: true }), /ERR_INVALID_ARG_TYPE/); -} diff --git a/cli/tests/node_compat/test/parallel/test-stream-catch-rejections.js b/cli/tests/node_compat/test/parallel/test-stream-catch-rejections.js deleted file mode 100644 index 066d68193..000000000 --- a/cli/tests/node_compat/test/parallel/test-stream-catch-rejections.js +++ /dev/null @@ -1,58 +0,0 @@ -// deno-fmt-ignore-file -// deno-lint-ignore-file - -// Copyright Joyent and Node contributors. All rights reserved. MIT license. -// Taken from Node 18.12.1 -// This file is automatically generated by "node/_tools/setup.ts". Do not modify this file manually - -'use strict'; - -const common = require('../common'); -const stream = require('stream'); -const assert = require('assert'); - -{ - const r = new stream.Readable({ - captureRejections: true, - read() { - } - }); - r.push('hello'); - r.push('world'); - - const err = new Error('kaboom'); - - r.on('error', common.mustCall((_err) => { - assert.strictEqual(err, _err); - assert.strictEqual(r.destroyed, true); - })); - - r.on('data', async () => { - throw err; - }); -} - -{ - const w = new stream.Writable({ - captureRejections: true, - highWaterMark: 1, - write(chunk, enc, cb) { - process.nextTick(cb); - } - }); - - const err = new Error('kaboom'); - - w.write('hello', () => { - w.write('world'); - }); - - w.on('error', common.mustCall((_err) => { - assert.strictEqual(err, _err); - assert.strictEqual(w.destroyed, true); - })); - - w.on('drain', common.mustCall(async () => { - throw err; - }, 2)); -} diff --git a/cli/tests/node_compat/test/parallel/test-stream-some-find-every.mjs b/cli/tests/node_compat/test/parallel/test-stream-some-find-every.mjs deleted file mode 100644 index 61bbce21d..000000000 --- a/cli/tests/node_compat/test/parallel/test-stream-some-find-every.mjs +++ /dev/null @@ -1,179 +0,0 @@ -// deno-fmt-ignore-file -// deno-lint-ignore-file - -// Copyright Joyent and Node contributors. All rights reserved. MIT license. -// Taken from Node 18.12.1 -// This file is automatically generated by "node/_tools/setup.ts". Do not modify this file manually - -import * as common from '../common/index.mjs'; -import { setTimeout } from 'timers/promises'; -import { Readable } from 'stream'; -import assert from 'assert'; - - -function oneTo5() { - return Readable.from([1, 2, 3, 4, 5]); -} - -function oneTo5Async() { - return oneTo5().map(async (x) => { - await Promise.resolve(); - return x; - }); -} -{ - // Some, find, and every work with a synchronous stream and predicate - assert.strictEqual(await oneTo5().some((x) => x > 3), true); - assert.strictEqual(await oneTo5().every((x) => x > 3), false); - assert.strictEqual(await oneTo5().find((x) => x > 3), 4); - assert.strictEqual(await oneTo5().some((x) => x > 6), false); - assert.strictEqual(await oneTo5().every((x) => x < 6), true); - assert.strictEqual(await oneTo5().find((x) => x > 6), undefined); - assert.strictEqual(await Readable.from([]).some(() => true), false); - assert.strictEqual(await Readable.from([]).every(() => true), true); - assert.strictEqual(await Readable.from([]).find(() => true), undefined); -} - -{ - // Some, find, and every work with an asynchronous stream and synchronous predicate - assert.strictEqual(await oneTo5Async().some((x) => x > 3), true); - assert.strictEqual(await oneTo5Async().every((x) => x > 3), false); - assert.strictEqual(await oneTo5Async().find((x) => x > 3), 4); - assert.strictEqual(await oneTo5Async().some((x) => x > 6), false); - assert.strictEqual(await oneTo5Async().every((x) => x < 6), true); - assert.strictEqual(await oneTo5Async().find((x) => x > 6), undefined); -} - -{ - // Some, find, and every work on synchronous streams with an asynchronous predicate - assert.strictEqual(await oneTo5().some(async (x) => x > 3), true); - assert.strictEqual(await oneTo5().every(async (x) => x > 3), false); - assert.strictEqual(await oneTo5().find(async (x) => x > 3), 4); - assert.strictEqual(await oneTo5().some(async (x) => x > 6), false); - assert.strictEqual(await oneTo5().every(async (x) => x < 6), true); - assert.strictEqual(await oneTo5().find(async (x) => x > 6), undefined); -} - -{ - // Some, find, and every work on asynchronous streams with an asynchronous predicate - assert.strictEqual(await oneTo5Async().some(async (x) => x > 3), true); - assert.strictEqual(await oneTo5Async().every(async (x) => x > 3), false); - assert.strictEqual(await oneTo5Async().find(async (x) => x > 3), 4); - assert.strictEqual(await oneTo5Async().some(async (x) => x > 6), false); - assert.strictEqual(await oneTo5Async().every(async (x) => x < 6), true); - assert.strictEqual(await oneTo5Async().find(async (x) => x > 6), undefined); -} - -{ - async function checkDestroyed(stream) { - await setTimeout(); - assert.strictEqual(stream.destroyed, true); - } - - { - // Some, find, and every short circuit - const someStream = oneTo5(); - await someStream.some(common.mustCall((x) => x > 2, 3)); - await checkDestroyed(someStream); - - const everyStream = oneTo5(); - await everyStream.every(common.mustCall((x) => x < 3, 3)); - await checkDestroyed(everyStream); - - const findStream = oneTo5(); - await findStream.find(common.mustCall((x) => x > 1, 2)); - await checkDestroyed(findStream); - - // When short circuit isn't possible the whole stream is iterated - await oneTo5().some(common.mustCall(() => false, 5)); - await oneTo5().every(common.mustCall(() => true, 5)); - await oneTo5().find(common.mustCall(() => false, 5)); - } - - { - // Some, find, and every short circuit async stream/predicate - const someStream = oneTo5Async(); - await someStream.some(common.mustCall(async (x) => x > 2, 3)); - await checkDestroyed(someStream); - - const everyStream = oneTo5Async(); - await everyStream.every(common.mustCall(async (x) => x < 3, 3)); - await checkDestroyed(everyStream); - - const findStream = oneTo5Async(); - await findStream.find(common.mustCall(async (x) => x > 1, 2)); - await checkDestroyed(findStream); - - // When short circuit isn't possible the whole stream is iterated - await oneTo5Async().some(common.mustCall(async () => false, 5)); - await oneTo5Async().every(common.mustCall(async () => true, 5)); - await oneTo5Async().find(common.mustCall(async () => false, 5)); - } -} - -{ - // Concurrency doesn't affect which value is found. - const found = await Readable.from([1, 2]).find(async (val) => { - if (val === 1) { - await setTimeout(100); - } - return true; - }, { concurrency: 2 }); - assert.strictEqual(found, 1); -} - -{ - // Support for AbortSignal - for (const op of ['some', 'every', 'find']) { - { - const ac = new AbortController(); - assert.rejects(Readable.from([1, 2, 3])[op]( - () => new Promise(() => { }), - { signal: ac.signal } - ), { - name: 'AbortError', - }, `${op} should abort correctly with sync abort`).then(common.mustCall()); - ac.abort(); - } - { - // Support for pre-aborted AbortSignal - assert.rejects(Readable.from([1, 2, 3])[op]( - () => new Promise(() => { }), - { signal: AbortSignal.abort() } - ), { - name: 'AbortError', - }, `${op} should abort with pre-aborted abort controller`).then(common.mustCall()); - } - } -} -{ - // Error cases - for (const op of ['some', 'every', 'find']) { - assert.rejects(async () => { - await Readable.from([1])[op](1); - }, /ERR_INVALID_ARG_TYPE/, `${op} should throw for invalid function`).then(common.mustCall()); - assert.rejects(async () => { - await Readable.from([1])[op]((x) => x, { - concurrency: 'Foo' - }); - }, /ERR_OUT_OF_RANGE/, `${op} should throw for invalid concurrency`).then(common.mustCall()); - assert.rejects(async () => { - await Readable.from([1])[op]((x) => x, 1); - }, /ERR_INVALID_ARG_TYPE/, `${op} should throw for invalid concurrency`).then(common.mustCall()); - assert.rejects(async () => { - await Readable.from([1])[op]((x) => x, { - signal: true - }); - }, /ERR_INVALID_ARG_TYPE/, `${op} should throw for invalid signal`).then(common.mustCall()); - } -} -{ - for (const op of ['some', 'every', 'find']) { - const stream = oneTo5(); - Object.defineProperty(stream, 'map', { - value: common.mustNotCall(() => {}), - }); - // Check that map isn't getting called. - stream[op](() => {}); - } -} diff --git a/cli/tests/node_compat/test/parallel/test-tls-connect-simple.js b/cli/tests/node_compat/test/parallel/test-tls-connect-simple.js deleted file mode 100644 index 01a688f3f..000000000 --- a/cli/tests/node_compat/test/parallel/test-tls-connect-simple.js +++ /dev/null @@ -1,69 +0,0 @@ -// deno-fmt-ignore-file -// deno-lint-ignore-file - -// Copyright Joyent and Node contributors. All rights reserved. MIT license. -// Taken from Node 18.12.1 -// This file is automatically generated by "node/_tools/setup.ts". Do not modify this file manually - -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -'use strict'; -const common = require('../common'); - -if (!common.hasCrypto) - common.skip('missing crypto'); - -const tls = require('tls'); -const fixtures = require('../common/fixtures'); - -let serverConnected = 0; - -const options = { - key: fixtures.readKey('agent1-key.pem'), - cert: fixtures.readKey('agent1-cert.pem') -}; - -const server = tls.Server(options, common.mustCall(function(socket) { - if (++serverConnected === 2) { - server.close(common.mustCall()); - server.on('close', common.mustCall()); - } -}, 2)); - -server.listen(0, function() { - const client1options = { - port: this.address().port, - rejectUnauthorized: false - }; - const client1 = tls.connect(client1options, common.mustCall(function() { - client1.end(); - })); - - const client2options = { - port: this.address().port, - rejectUnauthorized: false - }; - const client2 = tls.connect(client2options); - client2.on('secureConnect', common.mustCall(function() { - client2.end(); - })); -}); diff --git a/cli/tests/node_compat/test/pummel/test-net-bytes-per-incoming-chunk-overhead.js b/cli/tests/node_compat/test/pummel/test-net-bytes-per-incoming-chunk-overhead.js deleted file mode 100644 index 950fc74ec..000000000 --- a/cli/tests/node_compat/test/pummel/test-net-bytes-per-incoming-chunk-overhead.js +++ /dev/null @@ -1,58 +0,0 @@ -// deno-fmt-ignore-file -// deno-lint-ignore-file - -// Copyright Joyent and Node contributors. All rights reserved. MIT license. -// Taken from Node 16.13.0 -// This file is automatically generated by "node/_tools/setup.ts". Do not modify this file manually - -// Flags: --expose-gc -'use strict'; - -const common = require('../common'); - -if (process.config.variables.asan) { - common.skip('ASAN messes with memory measurements'); -} - -if (process.config.variables.arm_version === '7') { - common.skip('Too slow for armv7 bots'); -} - -const assert = require('assert'); -const net = require('net'); - -// Tests that, when receiving small chunks, we do not keep the full length -// of the original allocation for the libuv read call in memory. - -let client; -let baseRSS; -const receivedChunks = []; -const N = 250000; - -const server = net.createServer(common.mustCall((socket) => { - baseRSS = process.memoryUsage.rss(); - - socket.setNoDelay(true); - socket.on('data', (chunk) => { - receivedChunks.push(chunk); - if (receivedChunks.length < N) { - client.write('a'); - } else { - client.end(); - server.close(); - } - }); -})).listen(0, common.mustCall(() => { - client = net.connect(server.address().port); - client.setNoDelay(true); - client.write('hello!'); -})); - -process.on('exit', () => { - // TODO: support global.gc() compat - // global.gc(); - const bytesPerChunk = - (process.memoryUsage.rss() - baseRSS) / receivedChunks.length; - // We should always have less than one page (usually ~ 4 kB) per chunk. - assert(bytesPerChunk < 650, `measured ${bytesPerChunk} bytes per chunk`); -}); diff --git a/cli/tests/node_compat/test/pummel/test-net-pingpong-delay.js b/cli/tests/node_compat/test/pummel/test-net-pingpong-delay.js deleted file mode 100644 index 50f509b8e..000000000 --- a/cli/tests/node_compat/test/pummel/test-net-pingpong-delay.js +++ /dev/null @@ -1,114 +0,0 @@ -// deno-fmt-ignore-file -// deno-lint-ignore-file - -// Copyright Joyent and Node contributors. All rights reserved. MIT license. -// Taken from Node 18.12.1 -// This file is automatically generated by "node/_tools/setup.ts". Do not modify this file manually - -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -'use strict'; -const common = require('../common'); -const assert = require('assert'); -const net = require('net'); - -function pingPongTest(host, on_complete) { - const N = 100; - const DELAY = 1; - let count = 0; - let client_ended = false; - - const server = net.createServer({ allowHalfOpen: true }, function(socket) { - socket.setEncoding('utf8'); - - socket.on('data', function(data) { - console.log(data); - assert.strictEqual(data, 'PING'); - assert.strictEqual(socket.readyState, 'open'); - assert.strictEqual(count <= N, true); - setTimeout(function() { - assert.strictEqual(socket.readyState, 'open'); - socket.write('PONG'); - }, DELAY); - }); - - socket.on('timeout', function() { - console.error('server-side timeout!!'); - assert.strictEqual(false, true); - }); - - socket.on('end', function() { - console.log('server-side socket EOF'); - assert.strictEqual(socket.readyState, 'writeOnly'); - socket.end(); - }); - - socket.on('close', function(had_error) { - console.log('server-side socket.end'); - assert.strictEqual(had_error, false); - assert.strictEqual(socket.readyState, 'closed'); - socket.server.close(); - }); - }); - - server.listen(0, host, common.mustCall(function() { - const client = net.createConnection(server.address().port, host); - - client.setEncoding('utf8'); - - client.on('connect', function() { - assert.strictEqual(client.readyState, 'open'); - client.write('PING'); - }); - - client.on('data', function(data) { - console.log(data); - assert.strictEqual(data, 'PONG'); - assert.strictEqual(client.readyState, 'open'); - - setTimeout(function() { - assert.strictEqual(client.readyState, 'open'); - if (count++ < N) { - client.write('PING'); - } else { - console.log('closing client'); - client.end(); - client_ended = true; - } - }, DELAY); - }); - - client.on('timeout', function() { - console.error('client-side timeout!!'); - assert.strictEqual(false, true); - }); - - client.on('close', common.mustCall(function() { - console.log('client.end'); - assert.strictEqual(count, N + 1); - assert.ok(client_ended); - if (on_complete) on_complete(); - })); - })); -} - -pingPongTest(); diff --git a/cli/tests/node_compat/test/pummel/test-net-write-callbacks.js b/cli/tests/node_compat/test/pummel/test-net-write-callbacks.js deleted file mode 100644 index 7f6528107..000000000 --- a/cli/tests/node_compat/test/pummel/test-net-write-callbacks.js +++ /dev/null @@ -1,80 +0,0 @@ -// deno-fmt-ignore-file -// deno-lint-ignore-file - -// Copyright Joyent and Node contributors. All rights reserved. MIT license. -// Taken from Node 16.13.0 -// This file is automatically generated by "node/_tools/setup.ts". Do not modify this file manually - -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -'use strict'; -require('../common'); -const net = require('net'); -const assert = require('assert'); - -let cbcount = 0; -const N = 500000; - -// TODO: support net.Server() without new - -const server = new net.Server(function(socket) { - socket.on('data', function(d) { - console.error(`got ${d.length} bytes`); - }); - - socket.on('end', function() { - console.error('end'); - socket.destroy(); - server.close(); - }); -}); - -let lastCalled = -1; -function makeCallback(c) { - let called = false; - return function() { - if (called) - throw new Error(`called callback #${c} more than once`); - called = true; - if (c < lastCalled) { - throw new Error( - `callbacks out of order. last=${lastCalled} current=${c}`); - } - lastCalled = c; - cbcount++; - }; -} - -server.listen(0, function() { - const client = net.createConnection(server.address().port); - - client.on('connect', function() { - for (let i = 0; i < N; i++) { - client.write('hello world', makeCallback(i)); - } - client.end(); - }); -}); - -process.on('exit', function() { - assert.strictEqual(cbcount, N); -}); |