From b9766bdd1b06a7698e433b909709dce5c2b36387 Mon Sep 17 00:00:00 2001 From: Michael Dawson Date: Fri, 17 Mar 2017 17:34:54 -0400 Subject: [PATCH 001/151] doc: add supported platforms list Original Commit Message: PR-URL: https://github.com/nodejs/node/pull/11872 Reviewed-By: James M Snell Reviewed-By: Rich Trott Reviewed-By: Roman Reiss Reviewed-By: Ben Noordhuis Reviewed-By: Gibson Fahnestock Backport-Of: https://github.com/nodejs/node/pull/11872 PR-URL: https://github.com/nodejs/node/pull/11943 Reviewed-By: Ben Noordhuis Reviewed-By: James M Snell --- BUILDING.md | 78 +++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 73 insertions(+), 5 deletions(-) diff --git a/BUILDING.md b/BUILDING.md index 75ef93f8c73a13..47287f06056f23 100644 --- a/BUILDING.md +++ b/BUILDING.md @@ -8,6 +8,71 @@ If you consistently can reproduce a test failure, search for it in the [Node.js issue tracker](https://github.com/nodejs/node/issues) or file a new issue. +## Supported platforms + +This list of supported platforms is current as of the branch / release to +which it is attached. + +### Input + +Node.js relies on V8 and libuv. Therefore, we adopt a subset of their +supported platforms. + +### Strategy + +Support is divided into three tiers: + +* **Tier 1**: Full test coverage and maintenance by the Node.js core team and + the broader community. +* **Tier 2**: Full test coverage but more limited maintenance, + often provided by the vendor of the platform. +* **Experimental**: Known to compile but not necessarily reliably or with + a full passing test suite. These are often working to be promoted to Tier + 2 but are not quite ready. There is at least one individual actively + providing maintenance and the team is striving to broaden quality and + reliability of support. + +### Supported platforms + +| System | Support type | Version | Architectures | Notes | +|--------------|--------------|----------------------------------|----------------------|------------------| +| GNU/Linux | Tier 1 | kernel >= 2.6.18, glibc >= 2.5 | x86, x64, arm, arm64 | | +| macOS | Tier 1 | >= 10.10 | x64 | | +| Windows | Tier 1 | >= Windows 7 or >= Windows2008R2 | x86, x64 | | +| SmartOS | Tier 2 | >= 15 < 16.4 | x86, x64 | see note1 | +| FreeBSD | Tier 2 | >= 10 | x64 | | +| GNU/Linux | Tier 2 | kernel >= 4.2.0, glibc >= 2.19 | ppc64be | | +| GNU/Linux | Tier 2 | kernel >= 3.13.0, glibc >= 2.19 | ppc64le | | +| AIX | Tier 2 | >= 6.1 TL09 | ppc64be | | +| GNU/Linux | Tier 2 | kernel >= 3.10, glibc >= 2.17 | s390x | | +| macOS | Experimental | >= 10.8 < 10.10 | x64 | no test coverage | +| Linux (musl) | Experimental | musl >= 1.0 | x64 | | + +note1 - The gcc4.8-libs package needs to be installed, because node + binaries have been built with GCC 4.8, for which runtime libraries are not + installed by default. For these node versions, the recommended binaries + are the ones available in pkgsrc, not the one available from nodejs.org. + Note that the binaries downloaded from the pkgsrc repositories are not + officially supported by the Node.js project, and instead are supported + by Joyent. SmartOS images >= 16.4 are not supported because + GCC 4.8 runtime libraries are not available in their pkgsrc repository + +### Supported toolchains + +Depending on host platform, the selection of toolchains may vary. + +#### Unix + +* GCC 4.8.5 or newer +* Clang 3.4.1 or newer + +#### Windows + +* Building Node: Visual Studio 2015 or Visual C++ Build Tools 2015 or newer +* Building native add-ons: Visual Studio 2013 or Visual C++ Build Tools 2015 + or newer + +## Building Node.js on supported platforms ### Unix / OS X @@ -20,9 +85,9 @@ Prerequisites: On OS X, you will also need: * [Xcode](https://developer.apple.com/xcode/download/) - * You also need to install the `Command Line Tools` via Xcode. You can find + - You also need to install the `Command Line Tools` via Xcode. You can find this under the menu `Xcode -> Preferences -> Downloads` - * This step will install `gcc` and the related toolchain containing `make` + - This step will install `gcc` and the related toolchain containing `make` * After building, you may want to setup [firewall rules](tools/macosx-firewall.sh) to avoid popups asking to accept incoming network connections when running tests: @@ -51,7 +116,8 @@ the `-j4` flag. See the [GNU Make Documentation](https://www.gnu.org/software/make/manual/html_node/Parallel.html) for more information. -Note that the above requires that `python` resolve to Python 2.6 or 2.7 and not a newer version. +Note that the above requires that `python` resolve to Python 2.6 or 2.7 +and not a newer version. To run the tests: @@ -252,9 +318,11 @@ It is possible to build Node.js with **Note**: building in this way does **not** allow you to claim that the runtime is FIPS 140-2 validated. Instead you can indicate that the runtime -uses a validated module. See the [security policy](http://csrc.nist.gov/groups/STM/cmvp/documents/140-1/140sp/140sp1747.pdf) +uses a validated module. See the +[security policy](http://csrc.nist.gov/groups/STM/cmvp/documents/140-1/140sp/140sp1747.pdf) page 60 for more details. In addition, the validation for the underlying module -is only valid if it is deployed in accordance with its [security policy](http://csrc.nist.gov/groups/STM/cmvp/documents/140-1/140sp/140sp1747.pdf). +is only valid if it is deployed in accordance with its +[security policy](http://csrc.nist.gov/groups/STM/cmvp/documents/140-1/140sp/140sp1747.pdf). If you need FIPS validated cryptography it is recommended that you read both the [security policy](http://csrc.nist.gov/groups/STM/cmvp/documents/140-1/140sp/140sp1747.pdf) and [user guide](https://openssl.org/docs/fips/UserGuide-2.0.pdf). From 0dfb9daa042f2c29b04a5a280d0e472e086c681c Mon Sep 17 00:00:00 2001 From: Michael Dawson Date: Mon, 20 Mar 2017 15:38:42 -0400 Subject: [PATCH 002/151] doc: add supported platforms list for v6.x PR-URL: https://github.com/nodejs/node/pull/11943 Reviewed-By: Ben Noordhuis Reviewed-By: James M Snell --- BUILDING.md | 6 +++--- README.md | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/BUILDING.md b/BUILDING.md index 47287f06056f23..ec56e386595ae3 100644 --- a/BUILDING.md +++ b/BUILDING.md @@ -39,7 +39,7 @@ Support is divided into three tiers: | GNU/Linux | Tier 1 | kernel >= 2.6.18, glibc >= 2.5 | x86, x64, arm, arm64 | | | macOS | Tier 1 | >= 10.10 | x64 | | | Windows | Tier 1 | >= Windows 7 or >= Windows2008R2 | x86, x64 | | -| SmartOS | Tier 2 | >= 15 < 16.4 | x86, x64 | see note1 | +| SmartOS | Tier 2 | >= 14 < 16.4 | x86, x64 | see note1 | | FreeBSD | Tier 2 | >= 10 | x64 | | | GNU/Linux | Tier 2 | kernel >= 4.2.0, glibc >= 2.19 | ppc64be | | | GNU/Linux | Tier 2 | kernel >= 3.13.0, glibc >= 2.19 | ppc64le | | @@ -63,8 +63,8 @@ Depending on host platform, the selection of toolchains may vary. #### Unix -* GCC 4.8.5 or newer -* Clang 3.4.1 or newer +* GCC 4.8 or newer +* Clang 3.4 or newer #### Windows diff --git a/README.md b/README.md index 7fe05e05e27ad0..77919134c3342c 100644 --- a/README.md +++ b/README.md @@ -132,7 +132,7 @@ the binary verification command above. ## Building Node.js See [BUILDING.md](BUILDING.md) for instructions on how to build -Node.js from source. +Node.js from source along with a list of officially supported platforms. ## Security From de22ff642fdde0b30f1ecf0e012bfaad6c3d492c Mon Sep 17 00:00:00 2001 From: Poker <306766053@qq.com> Date: Fri, 3 Mar 2017 19:36:22 +0800 Subject: [PATCH 003/151] doc: fix broken URL to event loop guide PR-URL: https://github.com/nodejs/node/pull/11670 Reviewed-By: Colin Ihrig Reviewed-By: Yuta Hiroto Reviewed-By: Rich Trott Reviewed-By: Luigi Pinca Reviewed-By: James M Snell --- doc/api/timers.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/api/timers.md b/doc/api/timers.md index 75d6a36737b7d9..aa99d619dbd284 100644 --- a/doc/api/timers.md +++ b/doc/api/timers.md @@ -163,7 +163,7 @@ added: v0.0.1 Cancels a `Timeout` object created by [`setTimeout()`][]. -[the Node.js Event Loop]: https://github.com/nodejs/node/blob/master/doc/topics/event-loop-timers-and-nexttick.md +[the Node.js Event Loop]: https://nodejs.org/en/docs/guides/event-loop-timers-and-nexttick [`TypeError`]: errors.html#errors_class_typeerror [`clearImmediate()`]: timers.html#timers_clearimmediate_immediate [`clearInterval()`]: timers.html#timers_clearinterval_timeout From f9287461ddc89924dede70da1e4635e2a87d5e5d Mon Sep 17 00:00:00 2001 From: Brian White Date: Mon, 2 Jan 2017 18:37:26 -0500 Subject: [PATCH 004/151] stream: avoid additional validation for Buffers MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit These changes result in ~50% improvement in the included benchmark. PR-URL: https://github.com/nodejs/node/pull/10580 Reviewed-By: Сковорода Никита Андреевич Reviewed-By: Matteo Collina Reviewed-By: James M Snell --- benchmark/streams/writable-manywrites.js | 23 +++++++++++++++ lib/_stream_writable.js | 37 +++++++++++------------- 2 files changed, 40 insertions(+), 20 deletions(-) create mode 100644 benchmark/streams/writable-manywrites.js diff --git a/benchmark/streams/writable-manywrites.js b/benchmark/streams/writable-manywrites.js new file mode 100644 index 00000000000000..fadafe86e4cf70 --- /dev/null +++ b/benchmark/streams/writable-manywrites.js @@ -0,0 +1,23 @@ +'use strict'; + +const common = require('../common'); +const Writable = require('stream').Writable; + +const bench = common.createBenchmark(main, { + n: [2e6] +}); + +function main(conf) { + const n = +conf.n; + const b = Buffer.allocUnsafe(1024); + const s = new Writable(); + s._write = function(chunk, encoding, cb) { + cb(); + }; + + bench.start(); + for (var k = 0; k < n; ++k) { + s.write(b); + } + bench.end(n); +} diff --git a/lib/_stream_writable.js b/lib/_stream_writable.js index 7220252fead27b..6cf7390b841a33 100644 --- a/lib/_stream_writable.js +++ b/lib/_stream_writable.js @@ -196,23 +196,18 @@ function writeAfterEnd(stream, cb) { process.nextTick(cb, er); } -// If we get something that is not a buffer, string, null, or undefined, -// and we're not in objectMode, then that's an error. -// Otherwise stream chunks are all considered to be of length=1, and the -// watermarks determine how many objects to keep in the buffer, rather than -// how many bytes or characters. +// Checks that a user-supplied chunk is valid, especially for the particular +// mode the stream is in. Currently this means that `null` is never accepted +// and undefined/non-string values are only allowed in object mode. function validChunk(stream, state, chunk, cb) { var valid = true; var er = false; - // Always throw error if a null is written - // if we are not in object mode then throw - // if it is not a buffer, string, or undefined. + if (chunk === null) { er = new TypeError('May not write null values to stream'); - } else if (!(chunk instanceof Buffer) && - typeof chunk !== 'string' && - chunk !== undefined && - !state.objectMode) { + } else if (typeof chunk !== 'string' && + chunk !== undefined && + !state.objectMode) { er = new TypeError('Invalid non-string/buffer chunk'); } if (er) { @@ -226,13 +221,14 @@ function validChunk(stream, state, chunk, cb) { Writable.prototype.write = function(chunk, encoding, cb) { var state = this._writableState; var ret = false; + var isBuf = (chunk instanceof Buffer); if (typeof encoding === 'function') { cb = encoding; encoding = null; } - if (chunk instanceof Buffer) + if (isBuf) encoding = 'buffer'; else if (!encoding) encoding = state.defaultEncoding; @@ -242,9 +238,9 @@ Writable.prototype.write = function(chunk, encoding, cb) { if (state.ended) writeAfterEnd(this, cb); - else if (validChunk(this, state, chunk, cb)) { + else if (isBuf || validChunk(this, state, chunk, cb)) { state.pendingcb++; - ret = writeOrBuffer(this, state, chunk, encoding, cb); + ret = writeOrBuffer(this, state, isBuf, chunk, encoding, cb); } return ret; @@ -293,11 +289,12 @@ function decodeChunk(state, chunk, encoding) { // if we're already writing something, then just put this // in the queue, and wait our turn. Otherwise, call _write // If we return false, then we need a drain event, so set that flag. -function writeOrBuffer(stream, state, chunk, encoding, cb) { - chunk = decodeChunk(state, chunk, encoding); - - if (chunk instanceof Buffer) - encoding = 'buffer'; +function writeOrBuffer(stream, state, isBuf, chunk, encoding, cb) { + if (!isBuf) { + chunk = decodeChunk(state, chunk, encoding); + if (chunk instanceof Buffer) + encoding = 'buffer'; + } var len = state.objectMode ? 1 : chunk.length; state.length += len; From de636980668017c2ed155ba6f75ac5e6a2af647b Mon Sep 17 00:00:00 2001 From: Gibson Fahnestock Date: Sun, 8 Jan 2017 15:23:00 +0000 Subject: [PATCH 005/151] tools, test: require const/let in test Backport-PR-URL: https://github.com/nodejs/node/pull/11775 PR-URL: https://github.com/nodejs/node/pull/10685 Reviewed-By: Colin Ihrig Reviewed-By: James M Snell Reviewed-By: Roman Reiss --- test/.eslintrc.yaml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/test/.eslintrc.yaml b/test/.eslintrc.yaml index 90bf5f6d88d4e5..8414b828137e5d 100644 --- a/test/.eslintrc.yaml +++ b/test/.eslintrc.yaml @@ -1,6 +1,11 @@ ## Test-specific linter rules rules: + # ECMAScript 6 + # http://eslint.org/docs/rules/#ecmascript-6 + no-var: 2 + prefer-const: 2 + ## common module is mandatory in tests required-modules: [2, common] prefer-assert-methods: 2 From db61c952de2aa4591c60f4772fa62f0bc3474577 Mon Sep 17 00:00:00 2001 From: Gibson Fahnestock Date: Thu, 9 Mar 2017 18:11:21 +0000 Subject: [PATCH 006/151] test: use eslint to fix var->const/let Manually fix issues that eslint --fix couldn't do automatically. Backport-PR-URL: https://github.com/nodejs/node/pull/11775 PR-URL: https://github.com/nodejs/node/pull/10685 Reviewed-By: Colin Ihrig Reviewed-By: James M Snell Reviewed-By: Roman Reiss --- test/addons/async-hello-world/test.js | 2 +- test/addons/buffer-free-callback/test.js | 4 +- .../hello-world-function-export/test.js | 2 +- test/addons/hello-world/test.js | 2 +- test/addons/load-long-path/test.js | 8 +- test/addons/make-callback-recurse/test.js | 2 +- test/addons/repl-domain-abort/test.js | 24 +-- .../test-stringbytes-external-at-max.js | 3 +- ...ingbytes-external-exceed-max-by-1-ascii.js | 3 +- ...ngbytes-external-exceed-max-by-1-base64.js | 3 +- ...ngbytes-external-exceed-max-by-1-binary.js | 5 +- ...tringbytes-external-exceed-max-by-1-hex.js | 3 +- ...ringbytes-external-exceed-max-by-1-utf8.js | 3 +- ...st-stringbytes-external-exceed-max-by-2.js | 3 +- .../test-stringbytes-external-exceed-max.js | 3 +- test/common.js | 2 +- test/debugger/helper-debugger-repl.js | 32 ++-- test/debugger/test-debugger-client.js | 70 +++---- .../test-debugger-repl-break-in-module.js | 2 +- test/debugger/test-debugger-repl-restart.js | 6 +- test/debugger/test-debugger-repl-term.js | 4 +- test/debugger/test-debugger-repl-utf8.js | 4 +- test/debugger/test-debugger-repl.js | 6 +- test/gc/test-http-client-connaborted.js | 8 +- test/gc/test-http-client-onerror.js | 8 +- test/gc/test-http-client-timeout.js | 8 +- test/gc/test-http-client.js | 6 +- test/gc/test-net-timeout.js | 6 +- test/inspector/inspector-helper.js | 4 +- .../test-dgram-multicast-multi-process.js | 20 +- .../test-dgram-send-cb-quelches-error.js | 14 +- test/internet/test-dns-cares-domains.js | 10 +- test/internet/test-dns-txt-sigsegv.js | 4 +- test/internet/test-dns.js | 84 ++++---- .../internet/test-http-https-default-ports.js | 6 +- test/internet/test-net-connect-timeout.js | 12 +- test/internet/test-net-connect-unref.js | 7 +- .../internet/test-tls-connnect-melissadata.js | 6 +- .../test-url-parse-conformance.js | 8 +- test/message/error_exit.js | 2 +- test/message/eval_messages.js | 10 +- test/message/max_tick_depth.js | 2 +- test/message/stdin_messages.js | 10 +- .../undefined_reference_in_new_context.js | 2 +- test/message/vm_display_runtime_error.js | 2 +- test/message/vm_display_syntax_error.js | 2 +- test/message/vm_dont_display_runtime_error.js | 2 +- test/message/vm_dont_display_syntax_error.js | 2 +- .../test-assert-typedarray-deepequal.js | 2 +- test/parallel/test-assert.js | 35 ++-- .../test-async-wrap-check-providers.js | 2 +- .../test-async-wrap-throw-from-callback.js | 6 +- test/parallel/test-async-wrap-uid.js | 2 +- test/parallel/test-beforeexit-event-exit.js | 2 +- test/parallel/test-buffer-ascii.js | 2 +- test/parallel/test-buffer-bytelength.js | 26 +-- test/parallel/test-buffer-concat.js | 2 +- test/parallel/test-buffer-copy.js | 2 +- test/parallel/test-buffer-fill.js | 6 +- test/parallel/test-buffer-includes.js | 10 +- test/parallel/test-buffer-indexof.js | 39 ++-- test/parallel/test-buffer-inspect.js | 6 +- test/parallel/test-buffer-iterator.js | 4 +- test/parallel/test-buffer-swap.js | 48 ++--- test/parallel/test-buffer.js | 98 +++++----- .../test-child-process-constructor.js | 8 +- .../test-child-process-default-options.js | 10 +- .../test-child-process-double-pipe.js | 4 +- test/parallel/test-child-process-env.js | 12 +- test/parallel/test-child-process-exec-cwd.js | 2 +- ...-process-exec-stdout-stderr-data-string.js | 4 +- test/parallel/test-child-process-exit-code.js | 18 +- .../parallel/test-child-process-fork-close.js | 2 +- .../parallel/test-child-process-fork-dgram.js | 4 +- .../test-child-process-fork-exec-argv.js | 16 +- .../test-child-process-fork-exec-path.js | 16 +- test/parallel/test-child-process-fork-net.js | 32 ++-- test/parallel/test-child-process-fork-net2.js | 28 +-- test/parallel/test-child-process-fork-ref.js | 9 +- test/parallel/test-child-process-fork-ref2.js | 4 +- .../test-child-process-fork-regr-gh-2847.js | 6 +- test/parallel/test-child-process-fork.js | 8 +- test/parallel/test-child-process-fork3.js | 4 +- test/parallel/test-child-process-internal.js | 12 +- ...test-child-process-send-returns-boolean.js | 2 +- .../test-child-process-set-blocking.js | 8 +- test/parallel/test-child-process-silent.js | 16 +- .../test-child-process-spawn-typeerror.js | 2 +- .../test-child-process-spawnsync-env.js | 8 +- .../test-child-process-spawnsync-input.js | 4 +- .../test-child-process-spawnsync-timeout.js | 6 +- test/parallel/test-child-process-stdin-ipc.js | 6 +- .../test-child-process-stdio-big-write-end.js | 3 +- .../test-child-process-stdio-inherit.js | 12 +- test/parallel/test-cli-eval.js | 4 +- test/parallel/test-cli-syntax.js | 20 +- test/parallel/test-cluster-basic.js | 4 +- .../test-cluster-bind-privileged-port.js | 2 +- test/parallel/test-cluster-dgram-1.js | 12 +- test/parallel/test-cluster-dgram-2.js | 6 +- test/parallel/test-cluster-dgram-reuse.js | 6 +- test/parallel/test-cluster-disconnect-race.js | 6 +- .../test-cluster-disconnect-suicide-race.js | 2 +- ...test-cluster-disconnect-with-no-workers.js | 6 +- test/parallel/test-cluster-disconnect.js | 16 +- test/parallel/test-cluster-eaccess.js | 2 +- test/parallel/test-cluster-eaddrinuse.js | 12 +- test/parallel/test-cluster-fork-env.js | 8 +- test/parallel/test-cluster-listening-port.js | 8 +- test/parallel/test-cluster-master-error.js | 10 +- test/parallel/test-cluster-master-kill.js | 4 +- test/parallel/test-cluster-message.js | 22 +-- .../parallel/test-cluster-rr-domain-listen.js | 12 +- test/parallel/test-cluster-send-deadlock.js | 18 +- .../test-cluster-setup-master-argv.js | 4 +- .../test-cluster-setup-master-cumulative.js | 4 +- .../test-cluster-setup-master-emit.js | 4 +- .../test-cluster-setup-master-multiple.js | 8 +- test/parallel/test-cluster-setup-master.js | 16 +- test/parallel/test-cluster-shared-leak.js | 4 +- test/parallel/test-cluster-worker-death.js | 6 +- test/parallel/test-cluster-worker-destroy.js | 4 +- test/parallel/test-cluster-worker-events.js | 14 +- .../test-cluster-worker-forced-exit.js | 6 +- .../test-cluster-worker-isconnected.js | 6 +- test/parallel/test-cluster-worker-isdead.js | 6 +- test/parallel/test-cluster-worker-no-exit.js | 16 +- .../test-cluster-worker-wait-server-close.js | 16 +- test/parallel/test-common.js | 4 +- test/parallel/test-console-instance.js | 2 +- .../test-console-not-call-toString.js | 6 +- test/parallel/test-crypto-binary-default.js | 118 ++++++------ test/parallel/test-crypto-certificate.js | 16 +- test/parallel/test-crypto-dh-odd-key.js | 10 +- test/parallel/test-crypto-dh.js | 61 +++--- test/parallel/test-crypto-domain.js | 14 +- test/parallel/test-crypto-domains.js | 12 +- test/parallel/test-crypto-fips.js | 12 +- test/parallel/test-crypto-from-binary.js | 12 +- test/parallel/test-crypto-hash.js | 42 ++-- test/parallel/test-crypto-hmac.js | 16 +- test/parallel/test-crypto-padding-aes256.js | 6 +- test/parallel/test-crypto-rsa-dsa.js | 55 +++--- test/parallel/test-crypto-sign-verify.js | 12 +- test/parallel/test-crypto-stream.js | 12 +- test/parallel/test-crypto-verify-failure.js | 12 +- test/parallel/test-cwd-enoent-repl.js | 12 +- test/parallel/test-cwd-enoent.js | 12 +- test/parallel/test-debug-brk.js | 14 +- test/parallel/test-debug-port-from-cmdline.js | 22 +-- test/parallel/test-debug-signal-cluster.js | 6 +- .../test-debug-uncaught-exception-async.js | 2 +- test/parallel/test-debug-usage.js | 2 +- test/parallel/test-debugger-pid.js | 10 +- test/parallel/test-debugger-repeat-last.js | 8 +- test/parallel/test-delayed-require.js | 6 +- test/parallel/test-dgram-address.js | 20 +- test/parallel/test-dgram-bind.js | 4 +- test/parallel/test-dgram-bytes-length.js | 8 +- .../test-dgram-close-is-not-callback.js | 8 +- test/parallel/test-dgram-close.js | 6 +- .../test-dgram-exclusive-implicit-bind.js | 6 +- test/parallel/test-dgram-implicit-bind.js | 8 +- test/parallel/test-dgram-listen-after-bind.js | 10 +- test/parallel/test-dgram-oob-buffer.js | 8 +- test/parallel/test-dgram-regress-4496.js | 6 +- .../parallel/test-dgram-send-bad-arguments.js | 10 +- test/parallel/test-dgram-send-empty-array.js | 2 +- test/parallel/test-dgram-send-empty-buffer.js | 2 +- test/parallel/test-dgram-unref.js | 2 +- test/parallel/test-dh-padding.js | 21 +- .../parallel/test-domain-abort-on-uncaught.js | 10 +- test/parallel/test-domain-crypto.js | 3 +- test/parallel/test-domain-enter-exit.js | 10 +- .../test-domain-exit-dispose-again.js | 10 +- test/parallel/test-domain-exit-dispose.js | 10 +- test/parallel/test-domain-http-server.js | 28 +-- test/parallel/test-domain-implicit-fs.js | 8 +- test/parallel/test-domain-multi.js | 4 +- test/parallel/test-domain-nested-throw.js | 26 +-- test/parallel/test-domain-nested.js | 4 +- ...in-no-error-handler-abort-on-uncaught-5.js | 2 +- ...in-no-error-handler-abort-on-uncaught-9.js | 2 +- test/parallel/test-domain-safe-exit.js | 8 +- test/parallel/test-domain-stack.js | 8 +- ...n-throw-from-uncaught-exception-handler.js | 2 +- test/parallel/test-domain-timers.js | 10 +- ...st-domain-top-level-error-handler-throw.js | 16 +- ...domain-with-abort-on-uncaught-exception.js | 14 +- test/parallel/test-domain.js | 28 +-- test/parallel/test-dsa-fips-invalid-key.js | 14 +- test/parallel/test-error-reporting.js | 12 +- ...test-event-emitter-check-listener-leaks.js | 6 +- test/parallel/test-event-emitter-errors.js | 6 +- .../test-event-emitter-get-max-listeners.js | 8 +- ...st-event-emitter-listeners-side-effects.js | 8 +- .../test-event-emitter-method-names.js | 6 +- ...mitter-no-error-provided-to-error-event.js | 10 +- test/parallel/test-event-emitter-num-args.js | 4 +- test/parallel/test-event-emitter-once.js | 2 +- test/parallel/test-event-emitter-prepend.js | 2 +- ...test-event-emitter-remove-all-listeners.js | 2 +- ...-emitter-set-max-listeners-side-effects.js | 6 +- test/parallel/test-event-emitter-subclass.js | 12 +- test/parallel/test-exception-handler.js | 4 +- test/parallel/test-file-write-stream2.js | 9 +- test/parallel/test-force-repl-with-eval.js | 4 +- test/parallel/test-force-repl.js | 2 +- test/parallel/test-freelist.js | 2 +- test/parallel/test-fs-access.js | 24 +-- test/parallel/test-fs-chmod.js | 2 +- test/parallel/test-fs-exists.js | 6 +- test/parallel/test-fs-long-path.js | 12 +- test/parallel/test-fs-make-callback.js | 4 +- test/parallel/test-fs-mkdir.js | 6 +- test/parallel/test-fs-null-bytes.js | 6 +- test/parallel/test-fs-open-flags.js | 18 +- .../test-fs-read-buffer-tostring-fail.js | 4 +- test/parallel/test-fs-read-buffer.js | 2 +- test/parallel/test-fs-read-stream-fd-leak.js | 6 +- test/parallel/test-fs-read-stream-fd.js | 17 +- test/parallel/test-fs-read-stream-resume.js | 2 +- test/parallel/test-fs-read-stream.js | 32 ++-- test/parallel/test-fs-read.js | 2 +- test/parallel/test-fs-readfile-fd.js | 2 +- .../test-fs-readfile-zero-byte-liar.js | 4 +- .../test-fs-realpath-buffer-encoding.js | 5 +- .../test-fs-realpath-on-substed-drive.js | 3 +- test/parallel/test-fs-realpath.js | 15 +- test/parallel/test-fs-sir-writes-alot.js | 27 +-- test/parallel/test-fs-stat.js | 6 +- test/parallel/test-fs-stream-double-close.js | 4 +- .../test-fs-symlink-dir-junction-relative.js | 22 +-- test/parallel/test-fs-symlink.js | 4 +- test/parallel/test-fs-sync-fd-leak.js | 9 +- test/parallel/test-fs-truncate-GH-6233.js | 8 +- test/parallel/test-fs-utimes.js | 8 +- test/parallel/test-fs-watch-recursive.js | 5 +- test/parallel/test-fs-watchfile.js | 2 +- test/parallel/test-fs-write-buffer.js | 2 +- test/parallel/test-fs-write-file-buffer.js | 12 +- .../test-fs-write-stream-change-open.js | 2 +- test/parallel/test-fs-write-stream-end.js | 8 +- test/parallel/test-fs-write-stream-err.js | 16 +- test/parallel/test-fs-write-stream.js | 2 +- test/parallel/test-fs-write-string-coerce.js | 16 +- test/parallel/test-fs-write-sync.js | 18 +- test/parallel/test-global-console-exists.js | 2 +- test/parallel/test-global.js | 4 +- test/parallel/test-http-1.0-keep-alive.js | 16 +- test/parallel/test-http-1.0.js | 18 +- test/parallel/test-http-abort-before-end.js | 8 +- test/parallel/test-http-abort-client.js | 4 +- test/parallel/test-http-abort-queued.js | 12 +- test/parallel/test-http-after-connect.js | 4 +- .../test-http-agent-destroyed-socket.js | 20 +- .../parallel/test-http-agent-error-on-idle.js | 18 +- test/parallel/test-http-agent-false.js | 10 +- ...test-http-agent-maxsockets-regress-4050.js | 4 +- test/parallel/test-http-agent-maxsockets.js | 12 +- test/parallel/test-http-agent-no-protocol.js | 8 +- test/parallel/test-http-agent-null.js | 6 +- test/parallel/test-http-agent.js | 16 +- test/parallel/test-http-automatic-headers.js | 8 +- test/parallel/test-http-blank-header.js | 10 +- test/parallel/test-http-buffer-sanity.js | 20 +- test/parallel/test-http-byteswritten.js | 14 +- test/parallel/test-http-chunked-304.js | 8 +- test/parallel/test-http-chunked.js | 28 +-- test/parallel/test-http-client-abort-event.js | 6 +- test/parallel/test-http-client-abort.js | 10 +- test/parallel/test-http-client-abort2.js | 6 +- test/parallel/test-http-client-agent.js | 18 +- .../test-http-client-default-headers-exist.js | 14 +- test/parallel/test-http-client-encoding.js | 2 +- test/parallel/test-http-client-get-url.js | 6 +- test/parallel/test-http-client-parse-error.js | 12 +- test/parallel/test-http-client-pipe-end.js | 8 +- test/parallel/test-http-client-race-2.js | 34 ++-- test/parallel/test-http-client-race.js | 22 +-- .../test-http-client-read-in-error.js | 12 +- test/parallel/test-http-client-readable.js | 4 +- .../test-http-client-response-domain.js | 6 +- .../test-http-client-timeout-agent.js | 14 +- .../test-http-client-timeout-option.js | 8 +- .../test-http-client-timeout-with-data.js | 2 +- test/parallel/test-http-client-timeout.js | 12 +- test/parallel/test-http-client-upload-buf.js | 12 +- test/parallel/test-http-client-upload.js | 10 +- test/parallel/test-http-conn-reset.js | 12 +- test/parallel/test-http-connect-req-res.js | 4 +- test/parallel/test-http-content-length.js | 18 +- test/parallel/test-http-contentLength0.js | 15 +- test/parallel/test-http-date-header.js | 12 +- test/parallel/test-http-default-encoding.js | 10 +- test/parallel/test-http-default-port.js | 3 +- .../test-http-destroyed-socket-write2.js | 10 +- test/parallel/test-http-dns-error.js | 3 +- test/parallel/test-http-eof-on-connect.js | 6 +- test/parallel/test-http-exceptions.js | 8 +- test/parallel/test-http-expect-continue.js | 20 +- test/parallel/test-http-extra-response.js | 16 +- .../test-http-flush-response-headers.js | 2 +- test/parallel/test-http-flush.js | 4 +- test/parallel/test-http-full-response.js | 24 +-- .../test-http-get-pipeline-problem.js | 34 ++-- test/parallel/test-http-head-request.js | 8 +- ...test-http-head-response-has-no-body-end.js | 6 +- .../test-http-head-response-has-no-body.js | 6 +- test/parallel/test-http-header-read.js | 10 +- test/parallel/test-http-hex-write.js | 8 +- .../test-http-host-header-ipv6-fail.js | 2 +- test/parallel/test-http-host-headers.js | 2 +- test/parallel/test-http-invalidheaderfield.js | 6 +- .../test-http-keep-alive-close-on-header.js | 18 +- test/parallel/test-http-keepalive-client.js | 20 +- .../test-http-keepalive-maxsockets.js | 16 +- test/parallel/test-http-keepalive-request.js | 20 +- test/parallel/test-http-legacy.js | 20 +- .../test-http-localaddress-bind-error.js | 6 +- test/parallel/test-http-localaddress.js | 14 +- test/parallel/test-http-malformed-request.js | 16 +- .../test-http-many-ended-pipelines.js | 17 +- test/parallel/test-http-max-headers-count.js | 30 +-- test/parallel/test-http-methods.js | 6 +- test/parallel/test-http-multi-line-headers.js | 12 +- test/parallel/test-http-mutable-headers.js | 20 +- test/parallel/test-http-no-content-length.js | 10 +- test/parallel/test-http-outgoing-finish.js | 14 +- test/parallel/test-http-parser-bad-ref.js | 22 +-- test/parallel/test-http-parser-free.js | 16 +- test/parallel/test-http-parser.js | 34 ++-- test/parallel/test-http-pause.js | 16 +- test/parallel/test-http-pipe-fs.js | 18 +- test/parallel/test-http-pipeline-flood.js | 4 +- test/parallel/test-http-pipeline-regr-2639.js | 6 +- test/parallel/test-http-pipeline-regr-3332.js | 6 +- test/parallel/test-http-pipeline-regr-3508.js | 16 +- test/parallel/test-http-proxy.js | 22 +-- test/parallel/test-http-raw-headers.js | 22 +-- .../test-http-remove-header-stays-removed.js | 8 +- ...test-http-request-dont-override-options.js | 6 +- test/parallel/test-http-request-end-twice.js | 8 +- test/parallel/test-http-request-end.js | 10 +- test/parallel/test-http-request-methods.js | 12 +- .../parallel/test-http-res-write-after-end.js | 8 +- ...test-http-res-write-end-dont-take-array.js | 8 +- test/parallel/test-http-response-close.js | 4 +- ...test-http-response-multi-content-length.js | 2 +- .../test-http-response-multiheaders.js | 4 +- .../parallel/test-http-response-no-headers.js | 20 +- test/parallel/test-http-response-readable.js | 6 +- test/parallel/test-http-response-splitting.js | 2 +- .../test-http-response-status-message.js | 22 +-- .../parallel/test-http-server-client-error.js | 2 +- .../parallel/test-http-server-multiheaders.js | 6 +- .../test-http-server-multiheaders2.js | 12 +- test/parallel/test-http-server-stale-close.js | 10 +- test/parallel/test-http-server-unconsume.js | 12 +- test/parallel/test-http-server.js | 30 +-- test/parallel/test-http-set-cookies.js | 8 +- test/parallel/test-http-set-timeout-server.js | 70 +++---- test/parallel/test-http-set-timeout.js | 6 +- test/parallel/test-http-set-trailers.js | 22 +-- test/parallel/test-http-should-keep-alive.js | 18 +- test/parallel/test-http-status-code.js | 16 +- test/parallel/test-http-status-message.js | 14 +- test/parallel/test-http-timeout-overflow.js | 12 +- test/parallel/test-http-timeout.js | 10 +- test/parallel/test-http-unix-socket.js | 4 +- test/parallel/test-http-upgrade-agent.js | 24 +-- test/parallel/test-http-upgrade-client.js | 18 +- test/parallel/test-http-upgrade-client2.js | 12 +- test/parallel/test-http-upgrade-server.js | 28 +-- test/parallel/test-http-upgrade-server2.js | 10 +- ...p-url.parse-auth-with-header-in-request.js | 11 +- test/parallel/test-http-url.parse-auth.js | 10 +- test/parallel/test-http-url.parse-basic.js | 12 +- .../test-http-url.parse-https.request.js | 18 +- ....parse-only-support-http-https-protocol.js | 6 +- test/parallel/test-http-url.parse-path.js | 10 +- test/parallel/test-http-url.parse-post.js | 10 +- test/parallel/test-http-url.parse-search.js | 10 +- test/parallel/test-http-wget.js | 12 +- test/parallel/test-http-write-callbacks.js | 20 +- test/parallel/test-http-write-empty-string.js | 8 +- test/parallel/test-http-write-head.js | 2 +- test/parallel/test-http-zero-length-write.js | 26 +-- test/parallel/test-http.js | 8 +- .../test-https-agent-disable-session-reuse.js | 4 +- test/parallel/test-https-agent-servername.js | 10 +- test/parallel/test-https-agent-sni.js | 6 +- test/parallel/test-https-agent.js | 6 +- test/parallel/test-https-byteswritten.js | 14 +- .../test-https-client-checkServerIdentity.js | 20 +- test/parallel/test-https-client-get-url.js | 10 +- test/parallel/test-https-client-reject.js | 24 +-- test/parallel/test-https-client-resume.js | 22 +-- test/parallel/test-https-close.js | 14 +- .../parallel/test-https-connecting-to-http.js | 10 +- test/parallel/test-https-drain.js | 26 +-- test/parallel/test-https-eof-for-eom.js | 16 +- test/parallel/test-https-foafssl.js | 38 ++-- test/parallel/test-https-host-headers.js | 8 +- .../test-https-localaddress-bind-error.js | 12 +- test/parallel/test-https-localaddress.js | 10 +- test/parallel/test-https-pfx.js | 16 +- test/parallel/test-https-req-split.js | 12 +- .../parallel/test-https-resume-after-renew.js | 23 +-- .../parallel/test-https-set-timeout-server.js | 50 ++--- test/parallel/test-https-socket-options.js | 20 +- test/parallel/test-https-strict.js | 62 +++--- test/parallel/test-https-timeout-server-2.js | 16 +- test/parallel/test-internal-modules-expose.js | 2 +- test/parallel/test-listen-fd-cluster.js | 22 +-- .../test-listen-fd-detached-inherit.js | 22 +-- test/parallel/test-listen-fd-detached.js | 24 +-- test/parallel/test-listen-fd-server.js | 18 +- test/parallel/test-memory-usage-emfile.js | 8 +- test/parallel/test-memory-usage.js | 4 +- ...test-microtask-queue-integration-domain.js | 10 +- .../test-microtask-queue-integration.js | 10 +- .../test-microtask-queue-run-domain.js | 6 +- ...st-microtask-queue-run-immediate-domain.js | 6 +- .../test-microtask-queue-run-immediate.js | 6 +- test/parallel/test-microtask-queue-run.js | 6 +- .../test-module-globalpaths-nodepath.js | 20 +- test/parallel/test-module-loading-error.js | 6 +- test/parallel/test-module-version.js | 2 +- test/parallel/test-net-after-close.js | 8 +- .../test-net-better-error-messages-path.js | 10 +- test/parallel/test-net-binary.js | 10 +- test/parallel/test-net-bind-twice.js | 8 +- test/parallel/test-net-buffersize.js | 12 +- test/parallel/test-net-bytes-stats.js | 14 +- test/parallel/test-net-can-reset-timeout.js | 6 +- test/parallel/test-net-connect-buffer.js | 20 +- test/parallel/test-net-connect-local-error.js | 2 +- .../parallel/test-net-connect-options-ipv6.js | 6 +- test/parallel/test-net-connect-options.js | 8 +- .../test-net-connect-paused-connection.js | 2 +- test/parallel/test-net-create-connection.js | 4 +- test/parallel/test-net-dns-custom-lookup.js | 10 +- test/parallel/test-net-dns-error.js | 8 +- test/parallel/test-net-dns-lookup-skip.js | 8 +- test/parallel/test-net-dns-lookup.js | 6 +- test/parallel/test-net-during-close.js | 8 +- test/parallel/test-net-eaddrinuse.js | 8 +- test/parallel/test-net-end-without-connect.js | 4 +- test/parallel/test-net-error-twice.js | 8 +- test/parallel/test-net-internal.js | 2 +- test/parallel/test-net-isip.js | 4 +- test/parallel/test-net-keepalive.js | 6 +- test/parallel/test-net-large-string.js | 16 +- ...n-close-server-callback-is-not-function.js | 4 +- test/parallel/test-net-listen-close-server.js | 4 +- test/parallel/test-net-listen-error.js | 4 +- .../test-net-listen-exclusive-random-ports.js | 12 +- test/parallel/test-net-listen-port-option.js | 6 +- test/parallel/test-net-listen-shared-ports.js | 16 +- test/parallel/test-net-local-address-port.js | 5 +- test/parallel/test-net-localport.js | 10 +- .../test-net-pause-resume-connecting.js | 2 +- .../parallel/test-net-persistent-keepalive.js | 12 +- test/parallel/test-net-persistent-nodelay.js | 18 +- .../parallel/test-net-persistent-ref-unref.js | 16 +- test/parallel/test-net-pingpong.js | 6 +- test/parallel/test-net-pipe-connect-errors.js | 8 +- test/parallel/test-net-reconnect.js | 16 +- test/parallel/test-net-remote-address-port.js | 12 +- test/parallel/test-net-server-bind.js | 30 +-- test/parallel/test-net-server-close.js | 10 +- test/parallel/test-net-server-connections.js | 6 +- .../test-net-server-listen-remove-callback.js | 8 +- ...-connections-close-makes-more-available.js | 20 +- .../test-net-server-max-connections.js | 6 +- .../test-net-server-pause-on-connect.js | 4 +- .../test-net-server-unref-persistent.js | 4 +- test/parallel/test-net-server-unref.js | 4 +- .../parallel/test-net-socket-destroy-twice.js | 6 +- .../parallel/test-net-socket-local-address.js | 6 +- .../parallel/test-net-socket-timeout-unref.js | 2 +- test/parallel/test-net-stream.js | 18 +- test/parallel/test-net-write-after-close.js | 6 +- test/parallel/test-net-write-connect-write.js | 10 +- test/parallel/test-net-write-slow.js | 20 +- test/parallel/test-next-tick-domain.js | 4 +- test/parallel/test-next-tick-errors.js | 2 +- .../test-next-tick-intentional-starvation.js | 12 +- test/parallel/test-next-tick-ordering.js | 8 +- test/parallel/test-next-tick-ordering2.js | 4 +- test/parallel/test-next-tick.js | 4 +- test/parallel/test-path-makelong.js | 8 +- test/parallel/test-path-parse-format.js | 2 +- test/parallel/test-path.js | 4 +- test/parallel/test-pipe-address.js | 8 +- test/parallel/test-pipe-return-val.js | 10 +- test/parallel/test-pipe-stream.js | 16 +- test/parallel/test-pipe-unref.js | 6 +- test/parallel/test-preload.js | 6 +- test/parallel/test-process-argv-0.js | 10 +- test/parallel/test-process-before-exit.js | 6 +- test/parallel/test-process-binding.js | 2 +- test/parallel/test-process-config.js | 10 +- test/parallel/test-process-exec-argv.js | 12 +- test/parallel/test-process-exit-code.js | 10 +- .../test-process-exit-from-before-exit.js | 2 +- test/parallel/test-process-exit-recursive.js | 4 +- test/parallel/test-process-exit.js | 4 +- .../parallel/test-process-getactivehandles.js | 2 +- test/parallel/test-process-getgroups.js | 10 +- test/parallel/test-process-hrtime.js | 2 +- test/parallel/test-process-kill-null.js | 8 +- test/parallel/test-process-kill-pid.js | 8 +- test/parallel/test-process-next-tick.js | 4 +- test/parallel/test-process-raw-debug.js | 12 +- ...est-process-remove-all-signal-listeners.js | 2 +- test/parallel/test-process-versions.js | 4 +- test/parallel/test-process-wrap.js | 18 +- .../test-promises-unhandled-rejections.js | 164 ++++++++-------- ...promises-warning-on-unhandled-rejection.js | 2 +- .../test-querystring-maxKeys-non-finite.js | 6 +- test/parallel/test-querystring.js | 26 +-- test/parallel/test-readdouble.js | 2 +- test/parallel/test-readfloat.js | 2 +- test/parallel/test-readint.js | 6 +- test/parallel/test-readline-interface.js | 28 +-- test/parallel/test-readline-keys.js | 6 +- test/parallel/test-readline-set-raw-mode.js | 18 +- .../test-readline-undefined-columns.js | 2 +- test/parallel/test-readuint.js | 6 +- test/parallel/test-ref-unref-return.js | 6 +- test/parallel/test-regress-GH-1531.js | 10 +- test/parallel/test-regress-GH-1899.js | 10 +- test/parallel/test-regress-GH-2245.js | 4 +- test/parallel/test-regress-GH-3542.js | 2 +- test/parallel/test-regress-GH-3739.js | 4 +- test/parallel/test-regress-GH-4948.js | 14 +- test/parallel/test-regress-GH-5927.js | 12 +- test/parallel/test-regress-GH-6235.js | 2 +- test/parallel/test-regress-GH-746.js | 4 +- test/parallel/test-regress-GH-7511.js | 4 +- test/parallel/test-regress-GH-819.js | 4 +- test/parallel/test-regress-GH-node-9326.js | 6 +- test/parallel/test-repl-.save.load.js | 18 +- test/parallel/test-repl-autolibs.js | 12 +- test/parallel/test-repl-console.js | 2 +- test/parallel/test-repl-definecommand.js | 2 +- test/parallel/test-repl-domain.js | 4 +- test/parallel/test-repl-end-emits-exit.js | 4 +- test/parallel/test-repl-harmony.js | 14 +- test/parallel/test-repl-history-perm.js | 2 +- test/parallel/test-repl-null.js | 2 +- test/parallel/test-repl-options.js | 6 +- test/parallel/test-repl-persistent-history.js | 2 +- test/parallel/test-repl-require.js | 2 +- test/parallel/test-repl-setprompt.js | 10 +- .../test-repl-syntax-error-handling.js | 13 +- test/parallel/test-repl-tab-complete.js | 6 +- test/parallel/test-repl-tab.js | 11 +- .../test-repl-unexpected-token-recoverable.js | 14 +- test/parallel/test-require-cache.js | 2 +- ...ons-same-filename-as-dir-trailing-slash.js | 6 +- test/parallel/test-require-process.js | 4 +- test/parallel/test-sigint-infinite-loop.js | 8 +- test/parallel/test-signal-handler.js | 2 +- test/parallel/test-signal-safety.js | 8 +- .../test-socket-write-after-fin-error.js | 18 +- test/parallel/test-socket-write-after-fin.js | 12 +- test/parallel/test-stdin-pipe-resume.js | 10 +- test/parallel/test-stdin-script-child.js | 2 +- test/parallel/test-stdio-readable-writable.js | 2 +- ...out-cannot-be-closed-child-process-pipe.js | 10 +- test/parallel/test-stdout-stderr-reading.js | 18 +- test/parallel/test-stdout-to-file.js | 16 +- test/parallel/test-stream-base-no-abort.js | 2 +- test/parallel/test-stream-big-push.js | 6 +- test/parallel/test-stream-pipe-event.js | 12 +- test/parallel/test-stream-push-order.js | 12 +- test/parallel/test-stream-push-strings.js | 14 +- ...stream-readable-constructor-set-methods.js | 8 +- .../test-stream-readable-flow-recursion.js | 14 +- ...tream-transform-constructor-set-methods.js | 10 +- ...tream-transform-objectmode-falsey-value.js | 20 +- .../test-stream-transform-split-objectmode.js | 12 +- .../test-stream-unshift-empty-chunk.js | 20 +- test/parallel/test-stream-wrap.js | 6 +- ...stream-writable-change-default-encoding.js | 14 +- ...stream-writable-constructor-set-methods.js | 14 +- .../test-stream-writable-decoded-encoding.js | 6 +- test/parallel/test-stream-writable-null.js | 12 +- test/parallel/test-stream-writev.js | 26 +-- ...est-stream2-base64-single-char-read-end.js | 16 +- test/parallel/test-stream2-compatibility.js | 14 +- test/parallel/test-stream2-decode-partial.js | 2 +- test/parallel/test-stream2-finish-pipe.js | 8 +- .../test-stream2-httpclient-response-end.js | 10 +- .../parallel/test-stream2-large-read-stall.js | 21 +- test/parallel/test-stream2-objects.js | 88 ++++----- .../test-stream2-pipe-error-handling.js | 4 +- .../test-stream2-pipe-error-once-listener.js | 12 +- test/parallel/test-stream2-push.js | 30 +-- test/parallel/test-stream2-read-sync-stack.js | 10 +- ...st-stream2-readable-empty-buffer-no-eof.js | 8 +- .../test-stream2-readable-from-list.js | 26 +-- .../test-stream2-readable-legacy-drain.js | 16 +- .../test-stream2-readable-non-empty-end.js | 24 +-- .../test-stream2-readable-wrap-empty.js | 8 +- test/parallel/test-stream2-readable-wrap.js | 36 ++-- test/parallel/test-stream2-set-encoding.js | 84 ++++---- test/parallel/test-stream2-transform.js | 74 +++---- test/parallel/test-stream2-unpipe-leak.js | 14 +- test/parallel/test-stream2-writable.js | 97 +++++----- test/parallel/test-stream3-cork-end.js | 18 +- test/parallel/test-stream3-cork-uncork.js | 18 +- test/parallel/test-stream3-pause-then-read.js | 40 ++-- test/parallel/test-string-decoder-end.js | 16 +- test/parallel/test-string-decoder.js | 24 +-- test/parallel/test-stringbytes-external.js | 30 +-- test/parallel/test-sync-io-option.js | 6 +- test/parallel/test-sys.js | 6 +- test/parallel/test-tcp-wrap-connect.js | 26 +-- test/parallel/test-tcp-wrap.js | 12 +- test/parallel/test-timer-close.js | 6 +- test/parallel/test-timers-active.js | 4 +- test/parallel/test-timers-args.js | 8 +- test/parallel/test-timers-clearImmediate.js | 4 +- test/parallel/test-timers-immediate-queue.js | 10 +- test/parallel/test-timers-nested.js | 2 +- .../parallel/test-timers-non-integer-delay.js | 8 +- test/parallel/test-timers-ordering.js | 14 +- ...imeout-removes-other-socket-unref-timer.js | 2 +- .../test-timers-uncaught-exception.js | 10 +- test/parallel/test-timers-unref-active.js | 4 +- test/parallel/test-timers-unref-call.js | 6 +- test/parallel/test-timers-unref-leak.js | 10 +- ...emove-other-unref-timers-only-one-fires.js | 2 +- test/parallel/test-timers-unref.js | 6 +- ...test-timers-unrefd-interval-still-fires.js | 2 +- .../test-timers-unrefed-in-beforeexit.js | 2 +- test/parallel/test-timers.js | 8 +- test/parallel/test-tls-alert.js | 22 +-- test/parallel/test-tls-alpn-server-client.js | 76 ++++---- .../test-tls-async-cb-after-socket-end.js | 22 +-- test/parallel/test-tls-cert-regression.js | 10 +- test/parallel/test-tls-cipher-list.js | 2 +- test/parallel/test-tls-client-abort.js | 16 +- test/parallel/test-tls-client-abort2.js | 8 +- .../test-tls-client-default-ciphers.js | 6 +- test/parallel/test-tls-client-destroy-soon.js | 20 +- .../test-tls-client-getephemeralkeyinfo.js | 18 +- test/parallel/test-tls-client-mindhsize.js | 24 +-- test/parallel/test-tls-client-resume.js | 20 +- test/parallel/test-tls-client-verify.js | 2 +- test/parallel/test-tls-close-error.js | 10 +- test/parallel/test-tls-close-notify.js | 10 +- test/parallel/test-tls-connect-no-host.js | 16 +- test/parallel/test-tls-connect-pipe.js | 14 +- .../test-tls-connect-stream-writes.js | 33 ++-- test/parallel/test-tls-connect.js | 10 +- .../parallel/test-tls-delayed-attach-error.js | 18 +- test/parallel/test-tls-delayed-attach.js | 22 +-- test/parallel/test-tls-dhe.js | 36 ++-- test/parallel/test-tls-ecdh-disable.js | 16 +- test/parallel/test-tls-econnreset.js | 49 ++--- test/parallel/test-tls-env-bad-extra-ca.js | 4 +- test/parallel/test-tls-fast-writing.js | 28 +-- .../test-tls-friendly-error-message.js | 2 +- test/parallel/test-tls-handshake-error.js | 10 +- test/parallel/test-tls-handshake-nohang.js | 4 +- test/parallel/test-tls-honorcipherorder.js | 24 +-- test/parallel/test-tls-inception.js | 2 +- test/parallel/test-tls-invoke-queued.js | 14 +- test/parallel/test-tls-js-stream.js | 26 +-- test/parallel/test-tls-legacy-onselect.js | 10 +- test/parallel/test-tls-max-send-fragment.js | 18 +- test/parallel/test-tls-multi-key.js | 18 +- test/parallel/test-tls-no-rsa-key.js | 14 +- test/parallel/test-tls-no-sslv23.js | 6 +- test/parallel/test-tls-npn-server-client.js | 10 +- test/parallel/test-tls-over-http-tunnel.js | 28 +-- test/parallel/test-tls-pause.js | 26 +-- .../test-tls-peer-certificate-encoding.js | 20 +- .../test-tls-peer-certificate-multi-keys.js | 20 +- test/parallel/test-tls-pfx-gh-5100-regr.js | 2 +- test/parallel/test-tls-request-timeout.js | 14 +- test/parallel/test-tls-securepair-fiftharg.js | 2 +- test/parallel/test-tls-securepair-server.js | 36 ++-- test/parallel/test-tls-session-cache.js | 8 +- test/parallel/test-tls-set-ciphers.js | 2 +- test/parallel/test-tls-sni-option.js | 16 +- test/parallel/test-tls-sni-server-client.js | 16 +- test/parallel/test-tls-wrap-timeout.js | 4 +- test/parallel/test-umask.js | 8 +- test/parallel/test-url.js | 26 +-- test/parallel/test-utf8-scripts.js | 2 +- test/parallel/test-util-inspect.js | 88 ++++----- test/parallel/test-util-log.js | 10 +- test/parallel/test-v8-flag-type-check.js | 4 +- test/parallel/test-v8-flags.js | 6 +- test/parallel/test-v8-stats.js | 8 +- test/parallel/test-vm-basic.js | 16 +- test/parallel/test-vm-context-async-script.js | 8 +- .../test-vm-context-property-forwarding.js | 8 +- test/parallel/test-vm-context.js | 16 +- .../test-vm-create-and-run-in-context.js | 10 +- .../test-vm-create-context-accessors.js | 10 +- test/parallel/test-vm-create-context-arg.js | 6 +- ...st-vm-create-context-circular-reference.js | 6 +- test/parallel/test-vm-cross-context.js | 6 +- test/parallel/test-vm-function-declaration.js | 10 +- .../test-vm-global-define-property.js | 12 +- test/parallel/test-vm-global-identity.js | 10 +- test/parallel/test-vm-harmony-symbols.js | 6 +- test/parallel/test-vm-is-context.js | 6 +- .../test-vm-new-script-new-context.js | 6 +- .../test-vm-new-script-this-context.js | 2 +- test/parallel/test-vm-proxies.js | 6 +- test/parallel/test-vm-run-in-new-context.js | 6 +- test/parallel/test-vm-static-this.js | 17 +- test/parallel/test-vm-syntax-error-message.js | 8 +- test/parallel/test-vm-timeout.js | 6 +- test/parallel/test-writedouble.js | 2 +- test/parallel/test-writefloat.js | 2 +- test/parallel/test-writeint.js | 6 +- test/parallel/test-writeuint.js | 14 +- test/parallel/test-zerolengthbufferbug.js | 6 +- .../parallel/test-zlib-convenience-methods.js | 4 +- test/parallel/test-zlib-flush-drain.js | 6 +- test/parallel/test-zlib-flush.js | 3 +- test/parallel/test-zlib-from-gzip.js | 2 +- test/parallel/test-zlib-from-string.js | 2 +- test/parallel/test-zlib-invalid-input.js | 2 +- test/parallel/test-zlib-params.js | 2 +- test/parallel/test-zlib-random-byte-pipes.js | 12 +- test/parallel/test-zlib-write-after-flush.js | 2 +- test/parallel/test-zlib-zero-byte.js | 2 +- test/parallel/test-zlib.js | 67 +++---- test/pseudo-tty/no_dropped_stdio.js | 2 +- test/pseudo-tty/no_interleaved_stdio.js | 2 +- test/pummel/test-abort-fatal-error.js | 6 +- test/pummel/test-child-process-spawn-loop.js | 6 +- test/pummel/test-crypto-dh.js | 18 +- test/pummel/test-dh-regr.js | 10 +- test/pummel/test-dtrace-jsstack.js | 32 ++-- test/pummel/test-exec.js | 22 +-- test/pummel/test-fs-watch-file-slow.js | 14 +- test/pummel/test-fs-watch-file.js | 32 ++-- test/pummel/test-fs-watch-non-recursive.js | 14 +- test/pummel/test-http-client-reconnect-bug.js | 6 +- .../test-http-many-keep-alive-connections.js | 18 +- test/pummel/test-http-upload-timeout.js | 6 +- test/pummel/test-https-ci-reneg-attack.js | 32 ++-- test/pummel/test-https-large-response.js | 16 +- test/pummel/test-https-no-reader.js | 22 +-- test/pummel/test-keep-alive.js | 10 +- test/pummel/test-net-connect-econnrefused.js | 19 +- test/pummel/test-net-connect-memleak.js | 12 +- test/pummel/test-net-many-clients.js | 24 +-- test/pummel/test-net-pause.js | 14 +- test/pummel/test-net-pingpong-delay.js | 18 +- test/pummel/test-net-pingpong.js | 20 +- test/pummel/test-net-throttle.js | 12 +- test/pummel/test-net-timeout.js | 20 +- test/pummel/test-net-timeout2.js | 14 +- test/pummel/test-net-write-callbacks.js | 20 +- test/pummel/test-next-tick-infinite-calls.js | 2 +- test/pummel/test-process-hrtime.js | 8 +- test/pummel/test-process-uptime.js | 6 +- test/pummel/test-regress-GH-814.js | 22 +-- test/pummel/test-regress-GH-814_2.js | 24 +-- test/pummel/test-regress-GH-892.js | 33 ++-- test/pummel/test-stream-pipe-multi.js | 28 +-- test/pummel/test-stream2-basic.js | 180 +++++++++--------- test/pummel/test-timer-wrap.js | 6 +- test/pummel/test-timer-wrap2.js | 2 +- test/pummel/test-timers.js | 32 ++-- test/pummel/test-tls-ci-reneg-attack.js | 28 +-- test/pummel/test-tls-connect-memleak.js | 14 +- test/pummel/test-tls-securepair-client.js | 42 ++-- test/pummel/test-tls-server-large-request.js | 22 +-- test/pummel/test-tls-session-timeout.js | 50 ++--- test/pummel/test-tls-throttle.js | 20 +- test/pummel/test-vm-memleak.js | 14 +- test/pummel/test-watch-file.js | 8 +- .../sequential/test-child-process-execsync.js | 31 +-- test/sequential/test-debugger-debug-brk.js | 10 +- test/sequential/test-deprecation-flags.js | 2 +- .../test-fs-readfile-tostring-fail.js | 2 +- test/sequential/test-http-regr-gh-2928.js | 8 +- test/sequential/test-module-loading.js | 38 ++-- test/sequential/test-net-GH-5504.js | 18 +- test/sequential/test-regress-GH-1697.js | 10 +- test/sequential/test-regress-GH-1726.js | 10 +- test/sequential/test-regress-GH-4015.js | 10 +- test/sequential/test-regress-GH-4027.js | 10 +- test/sequential/test-regress-GH-784.js | 22 +-- test/sequential/test-regress-GH-877.js | 26 +-- test/sequential/test-repl-timeout-throw.js | 6 +- .../test-require-cache-without-stat.js | 16 +- test/sequential/test-stream2-fs.js | 24 +-- test/sequential/test-stream2-stderr-sync.js | 16 +- .../test-timers-blocking-callback.js | 6 +- test/sequential/test-util-debug.js | 18 +- test/sequential/test-vm-timeout-rethrow.js | 10 +- test/timers/test-timers-reliability.js | 12 +- 806 files changed, 5037 insertions(+), 5001 deletions(-) diff --git a/test/addons/async-hello-world/test.js b/test/addons/async-hello-world/test.js index 7c27382c1c60f4..a6aa8aa20fffbc 100644 --- a/test/addons/async-hello-world/test.js +++ b/test/addons/async-hello-world/test.js @@ -1,6 +1,6 @@ 'use strict'; const common = require('../../common'); -var assert = require('assert'); +const assert = require('assert'); const binding = require(`./build/${common.buildType}/binding`); binding(5, common.mustCall(function(err, val) { diff --git a/test/addons/buffer-free-callback/test.js b/test/addons/buffer-free-callback/test.js index 8dbc2d57725c56..d25130a905ac90 100644 --- a/test/addons/buffer-free-callback/test.js +++ b/test/addons/buffer-free-callback/test.js @@ -5,8 +5,8 @@ const common = require('../../common'); const binding = require(`./build/${common.buildType}/binding`); function check(size, alignment, offset) { - var buf = binding.alloc(size, alignment, offset); - var slice = buf.slice(size >>> 1); + let buf = binding.alloc(size, alignment, offset); + let slice = buf.slice(size >>> 1); buf = null; binding.check(slice); diff --git a/test/addons/hello-world-function-export/test.js b/test/addons/hello-world-function-export/test.js index 74ea66c79c548c..173cf5428e086f 100644 --- a/test/addons/hello-world-function-export/test.js +++ b/test/addons/hello-world-function-export/test.js @@ -1,6 +1,6 @@ 'use strict'; const common = require('../../common'); -var assert = require('assert'); +const assert = require('assert'); const binding = require(`./build/${common.buildType}/binding`); assert.strictEqual(binding(), 'world'); console.log('binding.hello() =', binding()); diff --git a/test/addons/hello-world/test.js b/test/addons/hello-world/test.js index 32066388efe6cb..b0148e9d9e9014 100644 --- a/test/addons/hello-world/test.js +++ b/test/addons/hello-world/test.js @@ -1,6 +1,6 @@ 'use strict'; const common = require('../../common'); -var assert = require('assert'); +const assert = require('assert'); const binding = require(`./build/${common.buildType}/binding`); assert.strictEqual(binding.hello(), 'world'); console.log('binding.hello() =', binding.hello()); diff --git a/test/addons/load-long-path/test.js b/test/addons/load-long-path/test.js index b17942b45a6f34..ff612b66488f75 100644 --- a/test/addons/load-long-path/test.js +++ b/test/addons/load-long-path/test.js @@ -14,9 +14,9 @@ common.refreshTmpDir(); // make a path that is more than 260 chars long. // Any given folder cannot have a name longer than 260 characters, // so create 10 nested folders each with 30 character long names. -var addonDestinationDir = path.resolve(common.tmpDir); +let addonDestinationDir = path.resolve(common.tmpDir); -for (var i = 0; i < 10; i++) { +for (let i = 0; i < 10; i++) { addonDestinationDir = path.join(addonDestinationDir, 'x'.repeat(30)); fs.mkdirSync(addonDestinationDir); } @@ -28,10 +28,10 @@ const addonPath = path.join(__dirname, const addonDestinationPath = path.join(addonDestinationDir, 'binding.node'); // Copy binary to long path destination -var contents = fs.readFileSync(addonPath); +const contents = fs.readFileSync(addonPath); fs.writeFileSync(addonDestinationPath, contents); // Attempt to load at long path destination -var addon = require(addonDestinationPath); +const addon = require(addonDestinationPath); assert.notEqual(addon, null); assert.strictEqual(addon.hello(), 'world'); diff --git a/test/addons/make-callback-recurse/test.js b/test/addons/make-callback-recurse/test.js index 0145a142e40f09..46b1327d7dedac 100644 --- a/test/addons/make-callback-recurse/test.js +++ b/test/addons/make-callback-recurse/test.js @@ -65,7 +65,7 @@ assert.throws(function() { results.push(2); setImmediate(common.mustCall(function() { - for (var i = 0; i < results.length; i++) { + for (let i = 0; i < results.length; i++) { assert.strictEqual(results[i], i, `verifyExecutionOrder(${arg}) results: ${results}`); } diff --git a/test/addons/repl-domain-abort/test.js b/test/addons/repl-domain-abort/test.js index 5591b4f2b38e90..95536f99711324 100644 --- a/test/addons/repl-domain-abort/test.js +++ b/test/addons/repl-domain-abort/test.js @@ -1,30 +1,30 @@ 'use strict'; -var common = require('../../common'); -var assert = require('assert'); -var repl = require('repl'); -var stream = require('stream'); -var path = require('path'); -var buildType = process.config.target_defaults.default_configuration; -var buildPath = path.join(__dirname, 'build', buildType, 'binding'); +const common = require('../../common'); +const assert = require('assert'); +const repl = require('repl'); +const stream = require('stream'); +const path = require('path'); +const buildType = process.config.target_defaults.default_configuration; +let buildPath = path.join(__dirname, 'build', buildType, 'binding'); // On Windows, escape backslashes in the path before passing it to REPL. if (common.isWindows) buildPath = buildPath.replace(/\\/g, '/'); -var cb_ran = false; +let cb_ran = false; process.on('exit', function() { assert(cb_ran); console.log('ok'); }); -var lines = [ +const lines = [ // This line shouldn't cause an assertion error. 'require(\'' + buildPath + '\')' + // Log output to double check callback ran. '.method(function() { console.log(\'cb_ran\'); });', ]; -var dInput = new stream.Readable(); -var dOutput = new stream.Writable(); +const dInput = new stream.Readable(); +const dOutput = new stream.Writable(); dInput._read = function _read(size) { while (lines.length > 0 && this.push(lines.shift())); @@ -38,7 +38,7 @@ dOutput._write = function _write(chunk, encoding, cb) { cb(); }; -var options = { +const options = { input: dInput, output: dOutput, terminal: false, diff --git a/test/addons/stringbytes-external-exceed-max/test-stringbytes-external-at-max.js b/test/addons/stringbytes-external-exceed-max/test-stringbytes-external-at-max.js index 2ce695852e25ae..5dd727f8ffddd3 100644 --- a/test/addons/stringbytes-external-exceed-max/test-stringbytes-external-at-max.js +++ b/test/addons/stringbytes-external-exceed-max/test-stringbytes-external-at-max.js @@ -14,8 +14,9 @@ if (!common.enoughTestMem) { return; } +let buf; try { - var buf = Buffer.allocUnsafe(kStringMaxLength); + buf = Buffer.allocUnsafe(kStringMaxLength); } catch (e) { // If the exception is not due to memory confinement then rethrow it. if (e.message !== 'Array buffer allocation failed') throw (e); diff --git a/test/addons/stringbytes-external-exceed-max/test-stringbytes-external-exceed-max-by-1-ascii.js b/test/addons/stringbytes-external-exceed-max/test-stringbytes-external-exceed-max-by-1-ascii.js index 4be525d79fa39e..2466c8ec42ed57 100644 --- a/test/addons/stringbytes-external-exceed-max/test-stringbytes-external-exceed-max-by-1-ascii.js +++ b/test/addons/stringbytes-external-exceed-max/test-stringbytes-external-exceed-max-by-1-ascii.js @@ -14,8 +14,9 @@ if (!common.enoughTestMem) { // v8::String::kMaxLength defined in v8.h const kStringMaxLength = process.binding('buffer').kStringMaxLength; +let buf; try { - var buf = Buffer.allocUnsafe(kStringMaxLength + 1); + buf = Buffer.allocUnsafe(kStringMaxLength + 1); } catch (e) { // If the exception is not due to memory confinement then rethrow it. if (e.message !== 'Array buffer allocation failed') throw (e); diff --git a/test/addons/stringbytes-external-exceed-max/test-stringbytes-external-exceed-max-by-1-base64.js b/test/addons/stringbytes-external-exceed-max/test-stringbytes-external-exceed-max-by-1-base64.js index 47426bf6352bbb..16f0f5392e5206 100644 --- a/test/addons/stringbytes-external-exceed-max/test-stringbytes-external-exceed-max-by-1-base64.js +++ b/test/addons/stringbytes-external-exceed-max/test-stringbytes-external-exceed-max-by-1-base64.js @@ -14,8 +14,9 @@ if (!common.enoughTestMem) { // v8::String::kMaxLength defined in v8.h const kStringMaxLength = process.binding('buffer').kStringMaxLength; +let buf; try { - var buf = Buffer.allocUnsafe(kStringMaxLength + 1); + buf = Buffer.allocUnsafe(kStringMaxLength + 1); } catch (e) { // If the exception is not due to memory confinement then rethrow it. if (e.message !== 'Array buffer allocation failed') throw (e); diff --git a/test/addons/stringbytes-external-exceed-max/test-stringbytes-external-exceed-max-by-1-binary.js b/test/addons/stringbytes-external-exceed-max/test-stringbytes-external-exceed-max-by-1-binary.js index 51324a3f337731..1028706b1d1aa9 100644 --- a/test/addons/stringbytes-external-exceed-max/test-stringbytes-external-exceed-max-by-1-binary.js +++ b/test/addons/stringbytes-external-exceed-max/test-stringbytes-external-exceed-max-by-1-binary.js @@ -14,8 +14,9 @@ if (!common.enoughTestMem) { // v8::String::kMaxLength defined in v8.h const kStringMaxLength = process.binding('buffer').kStringMaxLength; +let buf; try { - var buf = Buffer.allocUnsafe(kStringMaxLength + 1); + buf = Buffer.allocUnsafe(kStringMaxLength + 1); } catch (e) { // If the exception is not due to memory confinement then rethrow it. if (e.message !== 'Array buffer allocation failed') throw (e); @@ -33,7 +34,7 @@ assert.throws(function() { buf.toString('latin1'); }, /"toString\(\)" failed/); -var maxString = buf.toString('latin1', 1); +let maxString = buf.toString('latin1', 1); assert.strictEqual(maxString.length, kStringMaxLength); // Free the memory early instead of at the end of the next assignment maxString = undefined; diff --git a/test/addons/stringbytes-external-exceed-max/test-stringbytes-external-exceed-max-by-1-hex.js b/test/addons/stringbytes-external-exceed-max/test-stringbytes-external-exceed-max-by-1-hex.js index ae6966d0545194..caf6112011e2a8 100644 --- a/test/addons/stringbytes-external-exceed-max/test-stringbytes-external-exceed-max-by-1-hex.js +++ b/test/addons/stringbytes-external-exceed-max/test-stringbytes-external-exceed-max-by-1-hex.js @@ -14,8 +14,9 @@ if (!common.enoughTestMem) { // v8::String::kMaxLength defined in v8.h const kStringMaxLength = process.binding('buffer').kStringMaxLength; +let buf; try { - var buf = Buffer.allocUnsafe(kStringMaxLength + 1); + buf = Buffer.allocUnsafe(kStringMaxLength + 1); } catch (e) { // If the exception is not due to memory confinement then rethrow it. if (e.message !== 'Array buffer allocation failed') throw (e); diff --git a/test/addons/stringbytes-external-exceed-max/test-stringbytes-external-exceed-max-by-1-utf8.js b/test/addons/stringbytes-external-exceed-max/test-stringbytes-external-exceed-max-by-1-utf8.js index cea175aa93ab5c..4d3199a033e6d5 100644 --- a/test/addons/stringbytes-external-exceed-max/test-stringbytes-external-exceed-max-by-1-utf8.js +++ b/test/addons/stringbytes-external-exceed-max/test-stringbytes-external-exceed-max-by-1-utf8.js @@ -14,8 +14,9 @@ if (!common.enoughTestMem) { // v8::String::kMaxLength defined in v8.h const kStringMaxLength = process.binding('buffer').kStringMaxLength; +let buf; try { - var buf = Buffer.allocUnsafe(kStringMaxLength + 1); + buf = Buffer.allocUnsafe(kStringMaxLength + 1); } catch (e) { // If the exception is not due to memory confinement then rethrow it. if (e.message !== 'Array buffer allocation failed') throw (e); diff --git a/test/addons/stringbytes-external-exceed-max/test-stringbytes-external-exceed-max-by-2.js b/test/addons/stringbytes-external-exceed-max/test-stringbytes-external-exceed-max-by-2.js index 0fab606e4663ec..786d0b679895e1 100644 --- a/test/addons/stringbytes-external-exceed-max/test-stringbytes-external-exceed-max-by-2.js +++ b/test/addons/stringbytes-external-exceed-max/test-stringbytes-external-exceed-max-by-2.js @@ -14,8 +14,9 @@ if (!common.enoughTestMem) { // v8::String::kMaxLength defined in v8.h const kStringMaxLength = process.binding('buffer').kStringMaxLength; +let buf; try { - var buf = Buffer.allocUnsafe(kStringMaxLength + 2); + buf = Buffer.allocUnsafe(kStringMaxLength + 2); } catch (e) { // If the exception is not due to memory confinement then rethrow it. if (e.message !== 'Array buffer allocation failed') throw (e); diff --git a/test/addons/stringbytes-external-exceed-max/test-stringbytes-external-exceed-max.js b/test/addons/stringbytes-external-exceed-max/test-stringbytes-external-exceed-max.js index f984179525abeb..36b0d4174a030b 100644 --- a/test/addons/stringbytes-external-exceed-max/test-stringbytes-external-exceed-max.js +++ b/test/addons/stringbytes-external-exceed-max/test-stringbytes-external-exceed-max.js @@ -14,8 +14,9 @@ if (!common.enoughTestMem) { // v8::String::kMaxLength defined in v8.h const kStringMaxLength = process.binding('buffer').kStringMaxLength; +let buf; try { - var buf = Buffer.allocUnsafe(kStringMaxLength * 2 + 2); + buf = Buffer.allocUnsafe(kStringMaxLength * 2 + 2); } catch (e) { // If the exception is not due to memory confinement then rethrow it. if (e.message !== 'Array buffer allocation failed') throw (e); diff --git a/test/common.js b/test/common.js index 0721ad94ec7c2b..af6e27c4db3c46 100644 --- a/test/common.js +++ b/test/common.js @@ -208,7 +208,7 @@ exports.hasIPv6 = Object.keys(ifaces).some(function(name) { * the process aborts. */ exports.childShouldThrowAndAbort = function() { - var testCmd = ''; + let testCmd = ''; if (!exports.isWindows) { // Do not create core files, as it can take a lot of disk space on // continuous testing and developers' machines diff --git a/test/debugger/helper-debugger-repl.js b/test/debugger/helper-debugger-repl.js index 602ab1c05e53d6..38c65a03fa590d 100644 --- a/test/debugger/helper-debugger-repl.js +++ b/test/debugger/helper-debugger-repl.js @@ -1,15 +1,15 @@ 'use strict'; const common = require('../common'); -var assert = require('assert'); -var spawn = require('child_process').spawn; +const assert = require('assert'); +const spawn = require('child_process').spawn; process.env.NODE_DEBUGGER_TIMEOUT = 2000; -var port = common.PORT; +const port = common.PORT; -var child; -var buffer = ''; -var expected = []; -var quit; +let child; +let buffer = ''; +const expected = []; +let quit; function startDebugger(scriptToDebug) { scriptToDebug = process.env.NODE_DEBUGGER_TEST_SCRIPT || @@ -34,23 +34,23 @@ function startDebugger(scriptToDebug) { console.log(line); assert.ok(expected.length > 0, 'Got unexpected line: ' + line); - var expectedLine = expected[0].lines.shift(); + const expectedLine = expected[0].lines.shift(); assert.ok(line.match(expectedLine) !== null, line + ' != ' + expectedLine); if (expected[0].lines.length === 0) { - var callback = expected[0].callback; + const callback = expected[0].callback; expected.shift(); callback && callback(); } }); - var childClosed = false; + let childClosed = false; child.on('close', function(code) { assert(!code); childClosed = true; }); - var quitCalled = false; + let quitCalled = false; quit = function() { if (quitCalled || childClosed) return; quitCalled = true; @@ -60,7 +60,7 @@ function startDebugger(scriptToDebug) { setTimeout(function() { console.error('dying badly buffer=%j', buffer); - var err = 'Timeout'; + let err = 'Timeout'; if (expected.length > 0 && expected[0].lines) { err = err + '. Expected: ' + expected[0].lines.shift(); } @@ -95,7 +95,7 @@ function addTest(input, output) { child.stdin.write(expected[0].input + '\n'); if (!expected[0].lines) { - var callback = expected[0].callback; + const callback = expected[0].callback; expected.shift(); callback && callback(); @@ -107,17 +107,17 @@ function addTest(input, output) { expected.push({input: input, lines: output, callback: next}); } -var handshakeLines = [ +const handshakeLines = [ /listening on /, /connecting.* ok/ ]; -var initialBreakLines = [ +const initialBreakLines = [ /break in .*:1/, /1/, /2/, /3/ ]; -var initialLines = handshakeLines.concat(initialBreakLines); +const initialLines = handshakeLines.concat(initialBreakLines); // Process initial lines addTest(null, initialLines); diff --git a/test/debugger/test-debugger-client.js b/test/debugger/test-debugger-client.js index 869dabc6ef0c43..660d8e286ee250 100644 --- a/test/debugger/test-debugger-client.js +++ b/test/debugger/test-debugger-client.js @@ -1,12 +1,12 @@ 'use strict'; const common = require('../common'); -var assert = require('assert'); -var debug = require('_debugger'); +const assert = require('assert'); +const debug = require('_debugger'); process.env.NODE_DEBUGGER_TIMEOUT = 2000; -var debugPort = common.PORT; +const debugPort = common.PORT; debug.port = debugPort; -var spawn = require('child_process').spawn; +const spawn = require('child_process').spawn; setTimeout(function() { if (nodeProcess) nodeProcess.kill('SIGTERM'); @@ -14,8 +14,8 @@ setTimeout(function() { }, 10000).unref(); -var resCount = 0; -var p = new debug.Protocol(); +let resCount = 0; +const p = new debug.Protocol(); p.onResponse = function() { resCount++; }; @@ -29,12 +29,12 @@ assert.strictEqual(resCount, 1); // Make sure split messages go in. -var parts = []; +const parts = []; parts.push('Content-Length: 336\r\n'); assert.strictEqual(parts[0].length, 21); parts.push('\r\n'); assert.strictEqual(parts[1].length, 2); -var bodyLength = 0; +let bodyLength = 0; parts.push('{"seq":12,"type":"event","event":"break","body":' + '{"invocationText":"#'); @@ -55,7 +55,7 @@ bodyLength += parts[4].length; assert.strictEqual(bodyLength, 336); -for (var i = 0; i < parts.length; i++) { +for (let i = 0; i < parts.length; i++) { p.execute(parts[i]); } assert.strictEqual(resCount, 2); @@ -63,24 +63,24 @@ assert.strictEqual(resCount, 2); // Make sure that if we get backed up, we still manage to get all the // messages -var d = 'Content-Length: 466\r\n\r\n' + - '{"seq":10,"type":"event","event":"afterCompile","success":true,' + - '"body":{"script":{"handle":1,"type":"script","name":"dns.js",' + - '"id":34,"lineOffset":0,"columnOffset":0,"lineCount":241,' + - '"sourceStart":"(function(module, exports, require) {' + - 'var dns = process.binding(\'cares\')' + - ';\\nvar ne","sourceLength":6137,"scriptType":2,"compilationType":0,' + - '"context":{"ref":0},"text":"dns.js (lines: 241)"}},"refs":' + - '[{"handle":0' + - ',"type":"context","text":"#"}],"running":true}' + - '\r\n\r\nContent-Length: 119\r\n\r\n' + - '{"seq":11,"type":"event","event":"scriptCollected","success":true,' + - '"body":{"script":{"id":26}},"refs":[],"running":true}'; +const d = 'Content-Length: 466\r\n\r\n' + + '{"seq":10,"type":"event","event":"afterCompile","success":true,' + + '"body":{"script":{"handle":1,"type":"script","name":"dns.js",' + + '"id":34,"lineOffset":0,"columnOffset":0,"lineCount":241,' + + '"sourceStart":"(function(module, exports, require) {' + + 'let dns = process.binding(\'cares\')' + + ';\\nlet ne","sourceLength":6137,"scriptType":2,"compilationType":0' + + ',"context":{"ref":0},"text":"dns.js (lines: 241)"}},"refs":' + + '[{"handle":0' + + ',"type":"context","text":"#"}],"running":true}' + + '\r\n\r\nContent-Length: 119\r\n\r\n' + + '{"seq":11,"type":"event","event":"scriptCollected","success":true,' + + '"body":{"script":{"id":26}},"refs":[],"running":true}'; p.execute(d); assert.strictEqual(resCount, 4); -var expectedConnections = 0; -var tests = []; +let expectedConnections = 0; +const tests = []; function addTest(cb) { expectedConnections++; tests.push(cb); @@ -102,9 +102,9 @@ addTest(function(client, done) { assert.ifError(err); console.error('got %d scripts', Object.keys(client.scripts).length); - var foundMainScript = false; - for (var k in client.scripts) { - var script = client.scripts[k]; + let foundMainScript = false; + for (const k in client.scripts) { + const script = client.scripts[k]; if (script && script.name === 'bootstrap_node.js') { foundMainScript = true; break; @@ -127,19 +127,19 @@ addTest(function(client, done) { }); -var connectCount = 0; -var script = 'setTimeout(function() { console.log("blah"); });' + - 'setInterval(function() {}, 1000000);'; +let connectCount = 0; +const script = 'setTimeout(function() { console.log("blah"); });' + + 'setInterval(function() {}, 1000000);'; -var nodeProcess; +let nodeProcess; function doTest(cb, done) { - var args = ['--debug=' + debugPort, '-e', script]; + const args = ['--debug=' + debugPort, '-e', script]; nodeProcess = spawn(process.execPath, args); nodeProcess.stdout.once('data', function() { console.log('>>> new node process: %d', nodeProcess.pid); - var failed = true; + let failed = true; try { process._debugProcess(nodeProcess.pid); failed = false; @@ -151,9 +151,9 @@ function doTest(cb, done) { console.log('>>> starting debugger session'); }); - var didTryConnect = false; + let didTryConnect = false; nodeProcess.stderr.setEncoding('utf8'); - var b = ''; + let b = ''; nodeProcess.stderr.on('data', function(data) { console.error('got stderr data %j', data); nodeProcess.stderr.resume(); diff --git a/test/debugger/test-debugger-repl-break-in-module.js b/test/debugger/test-debugger-repl-break-in-module.js index 91782ae6e3ef28..2e7b9a58aacb0e 100644 --- a/test/debugger/test-debugger-repl-break-in-module.js +++ b/test/debugger/test-debugger-repl-break-in-module.js @@ -1,6 +1,6 @@ 'use strict'; require('../common'); -var repl = require('./helper-debugger-repl.js'); +const repl = require('./helper-debugger-repl.js'); repl.startDebugger('break-in-module/main.js'); diff --git a/test/debugger/test-debugger-repl-restart.js b/test/debugger/test-debugger-repl-restart.js index 206cd2e7417627..f5de9f5ee95778 100644 --- a/test/debugger/test-debugger-repl-restart.js +++ b/test/debugger/test-debugger-repl-restart.js @@ -1,15 +1,15 @@ 'use strict'; require('../common'); -var repl = require('./helper-debugger-repl.js'); +const repl = require('./helper-debugger-repl.js'); repl.startDebugger('breakpoints.js'); -var linesWithBreakpoint = [ +const linesWithBreakpoint = [ /1/, /2/, /3/, /4/, /5/, /\* 6/ ]; // We slice here, because addTest will change the given array. repl.addTest('sb(6)', linesWithBreakpoint.slice()); -var initialLines = repl.initialLines.slice(); +const initialLines = repl.initialLines.slice(); initialLines.splice(2, 0, /Restoring/, /Warning/); // Restart the debugged script diff --git a/test/debugger/test-debugger-repl-term.js b/test/debugger/test-debugger-repl-term.js index 6872f6ce2f9c72..4932df12e713bb 100644 --- a/test/debugger/test-debugger-repl-term.js +++ b/test/debugger/test-debugger-repl-term.js @@ -2,11 +2,11 @@ require('../common'); process.env.NODE_FORCE_READLINE = 1; -var repl = require('./helper-debugger-repl.js'); +const repl = require('./helper-debugger-repl.js'); repl.startDebugger('breakpoints.js'); -var addTest = repl.addTest; +const addTest = repl.addTest; // next addTest('n', [ diff --git a/test/debugger/test-debugger-repl-utf8.js b/test/debugger/test-debugger-repl-utf8.js index 6654a498219859..90214158884371 100644 --- a/test/debugger/test-debugger-repl-utf8.js +++ b/test/debugger/test-debugger-repl-utf8.js @@ -1,6 +1,6 @@ 'use strict'; -var common = require('../common'); -var script = common.fixturesDir + '/breakpoints_utf8.js'; +const common = require('../common'); +const script = common.fixturesDir + '/breakpoints_utf8.js'; process.env.NODE_DEBUGGER_TEST_SCRIPT = script; require('./test-debugger-repl.js'); diff --git a/test/debugger/test-debugger-repl.js b/test/debugger/test-debugger-repl.js index ab0468448bef4d..32dbfa22c0d3a9 100644 --- a/test/debugger/test-debugger-repl.js +++ b/test/debugger/test-debugger-repl.js @@ -1,10 +1,10 @@ 'use strict'; -var common = require('../common'); -var repl = require('./helper-debugger-repl.js'); +const common = require('../common'); +const repl = require('./helper-debugger-repl.js'); repl.startDebugger('breakpoints.js'); -var addTest = repl.addTest; +const addTest = repl.addTest; // Next addTest('n', [ diff --git a/test/gc/test-http-client-connaborted.js b/test/gc/test-http-client-connaborted.js index 071baf738ee9d3..6ff2a282d89c98 100644 --- a/test/gc/test-http-client-connaborted.js +++ b/test/gc/test-http-client-connaborted.js @@ -18,7 +18,7 @@ let countGC = 0; console.log('We should do ' + todo + ' requests'); -var server = http.createServer(serverHandler); +const server = http.createServer(serverHandler); server.listen(0, getall); function getall() { @@ -31,7 +31,7 @@ function getall() { statusLater(); } - var req = http.get({ + const req = http.get({ hostname: 'localhost', pathname: '/', port: server.address().port @@ -44,14 +44,14 @@ function getall() { setImmediate(getall); } -for (var i = 0; i < 10; i++) +for (let i = 0; i < 10; i++) getall(); function afterGC() { countGC++; } -var timer; +let timer; function statusLater() { global.gc(); if (timer) clearTimeout(timer); diff --git a/test/gc/test-http-client-onerror.js b/test/gc/test-http-client-onerror.js index a2ef0fa4bee9b7..b17ab428a2ccd7 100644 --- a/test/gc/test-http-client-onerror.js +++ b/test/gc/test-http-client-onerror.js @@ -20,7 +20,7 @@ let countGC = 0; console.log('We should do ' + todo + ' requests'); -var server = http.createServer(serverHandler); +const server = http.createServer(serverHandler); server.listen(0, runTest); function getall() { @@ -37,7 +37,7 @@ function getall() { throw er; } - var req = http.get({ + const req = http.get({ hostname: 'localhost', pathname: '/', port: server.address().port @@ -51,7 +51,7 @@ function getall() { } function runTest() { - for (var i = 0; i < 10; i++) + for (let i = 0; i < 10; i++) getall(); } @@ -59,7 +59,7 @@ function afterGC() { countGC++; } -var timer; +let timer; function statusLater() { global.gc(); if (timer) clearTimeout(timer); diff --git a/test/gc/test-http-client-timeout.js b/test/gc/test-http-client-timeout.js index 27baf837ca8282..fb4e8ba0f7058d 100644 --- a/test/gc/test-http-client-timeout.js +++ b/test/gc/test-http-client-timeout.js @@ -22,7 +22,7 @@ let countGC = 0; console.log('We should do ' + todo + ' requests'); -var server = http.createServer(serverHandler); +const server = http.createServer(serverHandler); server.listen(0, getall); function getall() { @@ -36,7 +36,7 @@ function getall() { statusLater(); } - var req = http.get({ + const req = http.get({ hostname: 'localhost', pathname: '/', port: server.address().port @@ -53,14 +53,14 @@ function getall() { setImmediate(getall); } -for (var i = 0; i < 10; i++) +for (let i = 0; i < 10; i++) getall(); function afterGC() { countGC++; } -var timer; +let timer; function statusLater() { global.gc(); if (timer) clearTimeout(timer); diff --git a/test/gc/test-http-client.js b/test/gc/test-http-client.js index 06bd08b2651d1b..f81cab0b09d2c2 100644 --- a/test/gc/test-http-client.js +++ b/test/gc/test-http-client.js @@ -18,7 +18,7 @@ let countGC = 0; console.log('We should do ' + todo + ' requests'); -var server = http.createServer(serverHandler); +const server = http.createServer(serverHandler); server.listen(0, getall); @@ -34,7 +34,7 @@ function getall() { res.on('end', global.gc); } - var req = http.get({ + const req = http.get({ hostname: 'localhost', pathname: '/', port: server.address().port @@ -47,7 +47,7 @@ function getall() { setImmediate(getall); } -for (var i = 0; i < 10; i++) +for (let i = 0; i < 10; i++) getall(); function afterGC() { diff --git a/test/gc/test-net-timeout.js b/test/gc/test-net-timeout.js index 9bc19a04256108..34893707a07d84 100644 --- a/test/gc/test-net-timeout.js +++ b/test/gc/test-net-timeout.js @@ -7,7 +7,7 @@ require('../common'); function serverHandler(sock) { sock.setTimeout(120000); sock.resume(); - var timer; + let timer; sock.on('close', function() { clearTimeout(timer); }); @@ -29,7 +29,7 @@ let countGC = 0; console.log('We should do ' + todo + ' requests'); -var server = net.createServer(serverHandler); +const server = net.createServer(serverHandler); server.listen(0, getall); function getall() { @@ -50,7 +50,7 @@ function getall() { setImmediate(getall); } -for (var i = 0; i < 10; i++) +for (let i = 0; i < 10; i++) getall(); function afterGC() { diff --git a/test/inspector/inspector-helper.js b/test/inspector/inspector-helper.js index 3e517123fe27f9..e22ca87dff7858 100644 --- a/test/inspector/inspector-helper.js +++ b/test/inspector/inspector-helper.js @@ -110,7 +110,7 @@ function makeBufferingDataCallback(dataCallback) { buffer = Buffer.alloc(0); else buffer = Buffer.from(lines.pop(), 'utf8'); - for (var line of lines) + for (const line of lines) dataCallback(line); }; } @@ -222,7 +222,7 @@ TestSession.prototype.sendInspectorCommands = function(commands) { }; TestSession.prototype.createCallbackWithTimeout_ = function(message) { - var promise = new Promise((resolve) => { + const promise = new Promise((resolve) => { this.enqueue((callback) => { const timeoutId = timeout(message); resolve(() => { diff --git a/test/internet/test-dgram-multicast-multi-process.js b/test/internet/test-dgram-multicast-multi-process.js index 36b429d6cf3f68..13141a9d44fb04 100644 --- a/test/internet/test-dgram-multicast-multi-process.js +++ b/test/internet/test-dgram-multicast-multi-process.js @@ -13,7 +13,7 @@ const messages = [ ]; const workers = {}; const listeners = 3; - +let dead, listening, sendSocket, done, timer; // Skip test in FreeBSD jails. if (common.inFreeBSDJail) { @@ -76,10 +76,10 @@ function launchChildProcess() { Object.keys(workers).forEach(function(pid) { const worker = workers[pid]; - var count = 0; + let count = 0; worker.messagesReceived.forEach(function(buf) { - for (var i = 0; i < messages.length; ++i) { + for (let i = 0; i < messages.length; ++i) { if (buf.toString() === messages[i].toString()) { count++; break; @@ -110,13 +110,13 @@ function killChildren(children) { } if (process.argv[2] !== 'child') { - var listening = 0; - var dead = 0; - var i = 0; - var done = 0; + listening = 0; + dead = 0; + let i = 0; + done = 0; // Exit the test if it doesn't succeed within TIMEOUT. - var timer = setTimeout(function() { + timer = setTimeout(function() { console.error('[PARENT] Responses were not received within %d ms.', TIMEOUT); console.error('[PARENT] Fail'); @@ -127,11 +127,11 @@ if (process.argv[2] !== 'child') { }, TIMEOUT); // Launch child processes. - for (var x = 0; x < listeners; x++) { + for (let x = 0; x < listeners; x++) { launchChildProcess(x); } - var sendSocket = dgram.createSocket('udp4'); + sendSocket = dgram.createSocket('udp4'); // The socket is actually created async now. sendSocket.on('listening', function() { diff --git a/test/internet/test-dgram-send-cb-quelches-error.js b/test/internet/test-dgram-send-cb-quelches-error.js index 56612edead4fd2..abcc36859b96d9 100644 --- a/test/internet/test-dgram-send-cb-quelches-error.js +++ b/test/internet/test-dgram-send-cb-quelches-error.js @@ -1,12 +1,12 @@ 'use strict'; -var common = require('../common'); -var mustCall = common.mustCall; -var assert = require('assert'); -var dgram = require('dgram'); -var dns = require('dns'); +const common = require('../common'); +const mustCall = common.mustCall; +const assert = require('assert'); +const dgram = require('dgram'); +const dns = require('dns'); -var socket = dgram.createSocket('udp4'); -var buffer = Buffer.from('gary busey'); +const socket = dgram.createSocket('udp4'); +const buffer = Buffer.from('gary busey'); dns.setServers([]); diff --git a/test/internet/test-dns-cares-domains.js b/test/internet/test-dns-cares-domains.js index 76ebf0d628b1c4..5328d7e3d97925 100644 --- a/test/internet/test-dns-cares-domains.js +++ b/test/internet/test-dns-cares-domains.js @@ -1,10 +1,10 @@ 'use strict'; require('../common'); -var assert = require('assert'); -var dns = require('dns'); -var domain = require('domain'); +const assert = require('assert'); +const dns = require('dns'); +const domain = require('domain'); -var methods = [ +const methods = [ 'resolve4', 'resolve6', 'resolveCname', @@ -18,7 +18,7 @@ var methods = [ ]; methods.forEach(function(method) { - var d = domain.create(); + const d = domain.create(); d.run(function() { dns[method]('google.com', function() { assert.strictEqual(process.domain, d, method + ' retains domain'); diff --git a/test/internet/test-dns-txt-sigsegv.js b/test/internet/test-dns-txt-sigsegv.js index 4c2f12f7a97c28..3c85d546cfcddd 100644 --- a/test/internet/test-dns-txt-sigsegv.js +++ b/test/internet/test-dns-txt-sigsegv.js @@ -1,7 +1,7 @@ 'use strict'; require('../common'); -var assert = require('assert'); -var dns = require('dns'); +const assert = require('assert'); +const dns = require('dns'); dns.resolveTxt('www.microsoft.com', function(err, records) { assert.equal(err, null); diff --git a/test/internet/test-dns.js b/test/internet/test-dns.js index 893992e66096db..6fc939ee3a3b6c 100644 --- a/test/internet/test-dns.js +++ b/test/internet/test-dns.js @@ -15,7 +15,7 @@ const queue = []; function TEST(f) { function next() { - var f = queue.shift(); + const f = queue.shift(); if (f) { running = true; console.log(f.name); @@ -44,7 +44,7 @@ function checkWrap(req) { TEST(function test_reverse_bogus(done) { - var error; + let error; try { dns.reverse('bogus ip', function() { @@ -62,13 +62,13 @@ TEST(function test_reverse_bogus(done) { TEST(function test_resolveMx(done) { - var req = dns.resolveMx('gmail.com', function(err, result) { + const req = dns.resolveMx('gmail.com', function(err, result) { if (err) throw err; assert.ok(result.length > 0); - for (var i = 0; i < result.length; i++) { - var item = result[i]; + for (let i = 0; i < result.length; i++) { + const item = result[i]; assert.ok(item); assert.strictEqual(typeof item, 'object'); @@ -85,7 +85,7 @@ TEST(function test_resolveMx(done) { }); TEST(function test_resolveMx_failure(done) { - var req = dns.resolveMx('something.invalid', function(err, result) { + const req = dns.resolveMx('something.invalid', function(err, result) { assert.ok(err instanceof Error); assert.strictEqual(err.errno, 'ENOTFOUND'); @@ -98,13 +98,13 @@ TEST(function test_resolveMx_failure(done) { }); TEST(function test_resolveNs(done) { - var req = dns.resolveNs('rackspace.com', function(err, names) { + const req = dns.resolveNs('rackspace.com', function(err, names) { if (err) throw err; assert.ok(names.length > 0); - for (var i = 0; i < names.length; i++) { - var name = names[i]; + for (let i = 0; i < names.length; i++) { + const name = names[i]; assert.ok(name); assert.strictEqual(typeof name, 'string'); } @@ -116,7 +116,7 @@ TEST(function test_resolveNs(done) { }); TEST(function test_resolveNs_failure(done) { - var req = dns.resolveNs('something.invalid', function(err, result) { + const req = dns.resolveNs('something.invalid', function(err, result) { assert.ok(err instanceof Error); assert.strictEqual(err.errno, 'ENOTFOUND'); @@ -129,13 +129,13 @@ TEST(function test_resolveNs_failure(done) { }); TEST(function test_resolveSrv(done) { - var req = dns.resolveSrv('_jabber._tcp.google.com', function(err, result) { + const req = dns.resolveSrv('_jabber._tcp.google.com', function(err, result) { if (err) throw err; assert.ok(result.length > 0); - for (var i = 0; i < result.length; i++) { - var item = result[i]; + for (let i = 0; i < result.length; i++) { + const item = result[i]; assert.ok(item); assert.strictEqual(typeof item, 'object'); @@ -154,7 +154,7 @@ TEST(function test_resolveSrv(done) { }); TEST(function test_resolveSrv_failure(done) { - var req = dns.resolveSrv('something.invalid', function(err, result) { + const req = dns.resolveSrv('something.invalid', function(err, result) { assert.ok(err instanceof Error); assert.strictEqual(err.errno, 'ENOTFOUND'); @@ -167,13 +167,13 @@ TEST(function test_resolveSrv_failure(done) { }); TEST(function test_resolvePtr(done) { - var req = dns.resolvePtr('8.8.8.8.in-addr.arpa', function(err, result) { + const req = dns.resolvePtr('8.8.8.8.in-addr.arpa', function(err, result) { if (err) throw err; assert.ok(result.length > 0); - for (var i = 0; i < result.length; i++) { - var item = result[i]; + for (let i = 0; i < result.length; i++) { + const item = result[i]; assert.ok(item); assert.strictEqual(typeof item, 'string'); } @@ -185,7 +185,7 @@ TEST(function test_resolvePtr(done) { }); TEST(function test_resolvePtr_failure(done) { - var req = dns.resolvePtr('something.invalid', function(err, result) { + const req = dns.resolvePtr('something.invalid', function(err, result) { assert.ok(err instanceof Error); assert.strictEqual(err.errno, 'ENOTFOUND'); @@ -198,13 +198,13 @@ TEST(function test_resolvePtr_failure(done) { }); TEST(function test_resolveNaptr(done) { - var req = dns.resolveNaptr('sip2sip.info', function(err, result) { + const req = dns.resolveNaptr('sip2sip.info', function(err, result) { if (err) throw err; assert.ok(result.length > 0); - for (var i = 0; i < result.length; i++) { - var item = result[i]; + for (let i = 0; i < result.length; i++) { + const item = result[i]; assert.ok(item); assert.strictEqual(typeof item, 'object'); @@ -223,7 +223,7 @@ TEST(function test_resolveNaptr(done) { }); TEST(function test_resolveNaptr_failure(done) { - var req = dns.resolveNaptr('something.invalid', function(err, result) { + const req = dns.resolveNaptr('something.invalid', function(err, result) { assert.ok(err instanceof Error); assert.strictEqual(err.errno, 'ENOTFOUND'); @@ -236,7 +236,7 @@ TEST(function test_resolveNaptr_failure(done) { }); TEST(function test_resolveSoa(done) { - var req = dns.resolveSoa('nodejs.org', function(err, result) { + const req = dns.resolveSoa('nodejs.org', function(err, result) { if (err) throw err; assert.ok(result); @@ -270,7 +270,7 @@ TEST(function test_resolveSoa(done) { }); TEST(function test_resolveSoa_failure(done) { - var req = dns.resolveSoa('something.invalid', function(err, result) { + const req = dns.resolveSoa('something.invalid', function(err, result) { assert.ok(err instanceof Error); assert.strictEqual(err.errno, 'ENOTFOUND'); @@ -283,13 +283,13 @@ TEST(function test_resolveSoa_failure(done) { }); TEST(function test_resolveCname(done) { - var req = dns.resolveCname('www.microsoft.com', function(err, names) { + const req = dns.resolveCname('www.microsoft.com', function(err, names) { if (err) throw err; assert.ok(names.length > 0); - for (var i = 0; i < names.length; i++) { - var name = names[i]; + for (let i = 0; i < names.length; i++) { + const name = names[i]; assert.ok(name); assert.strictEqual(typeof name, 'string'); } @@ -301,7 +301,7 @@ TEST(function test_resolveCname(done) { }); TEST(function test_resolveCname_failure(done) { - var req = dns.resolveCname('something.invalid', function(err, result) { + const req = dns.resolveCname('something.invalid', function(err, result) { assert.ok(err instanceof Error); assert.strictEqual(err.errno, 'ENOTFOUND'); @@ -315,7 +315,7 @@ TEST(function test_resolveCname_failure(done) { TEST(function test_resolveTxt(done) { - var req = dns.resolveTxt('google.com', function(err, records) { + const req = dns.resolveTxt('google.com', function(err, records) { if (err) throw err; assert.strictEqual(records.length, 1); assert.ok(util.isArray(records[0])); @@ -327,7 +327,7 @@ TEST(function test_resolveTxt(done) { }); TEST(function test_resolveTxt_failure(done) { - var req = dns.resolveTxt('something.invalid', function(err, result) { + const req = dns.resolveTxt('something.invalid', function(err, result) { assert.ok(err instanceof Error); assert.strictEqual(err.errno, 'ENOTFOUND'); @@ -341,7 +341,7 @@ TEST(function test_resolveTxt_failure(done) { TEST(function test_lookup_failure(done) { - var req = dns.lookup('does.not.exist', 4, function(err, ip, family) { + const req = dns.lookup('does.not.exist', 4, function(err, ip, family) { assert.ok(err instanceof Error); assert.strictEqual(err.errno, dns.NOTFOUND); assert.strictEqual(err.errno, 'ENOTFOUND'); @@ -356,7 +356,7 @@ TEST(function test_lookup_failure(done) { TEST(function test_lookup_null(done) { - var req = dns.lookup(null, function(err, ip, family) { + const req = dns.lookup(null, function(err, ip, family) { if (err) throw err; assert.strictEqual(ip, null); assert.strictEqual(family, 4); @@ -369,7 +369,7 @@ TEST(function test_lookup_null(done) { TEST(function test_lookup_ip_all(done) { - var req = dns.lookup('127.0.0.1', {all: true}, function(err, ips, family) { + const req = dns.lookup('127.0.0.1', {all: true}, function(err, ips, family) { if (err) throw err; assert.ok(Array.isArray(ips)); assert.ok(ips.length > 0); @@ -384,7 +384,7 @@ TEST(function test_lookup_ip_all(done) { TEST(function test_lookup_null_all(done) { - var req = dns.lookup(null, {all: true}, function(err, ips, family) { + const req = dns.lookup(null, {all: true}, function(err, ips, family) { if (err) throw err; assert.ok(Array.isArray(ips)); assert.strictEqual(ips.length, 0); @@ -397,7 +397,7 @@ TEST(function test_lookup_null_all(done) { TEST(function test_lookup_all_mixed(done) { - var req = dns.lookup('www.google.com', {all: true}, function(err, ips) { + const req = dns.lookup('www.google.com', {all: true}, function(err, ips) { if (err) throw err; assert.ok(Array.isArray(ips)); assert.ok(ips.length > 0); @@ -419,7 +419,7 @@ TEST(function test_lookup_all_mixed(done) { TEST(function test_lookupservice_invalid(done) { - var req = dns.lookupService('1.2.3.4', 80, function(err, host, service) { + const req = dns.lookupService('1.2.3.4', 80, function(err, host, service) { assert(err instanceof Error); assert.strictEqual(err.code, 'ENOTFOUND'); assert.ok(/1\.2\.3\.4/.test(err.message)); @@ -432,7 +432,7 @@ TEST(function test_lookupservice_invalid(done) { TEST(function test_reverse_failure(done) { - var req = dns.reverse('0.0.0.0', function(err) { + const req = dns.reverse('0.0.0.0', function(err) { assert(err instanceof Error); assert.strictEqual(err.code, 'ENOTFOUND'); // Silly error code... assert.strictEqual(err.hostname, '0.0.0.0'); @@ -446,7 +446,7 @@ TEST(function test_reverse_failure(done) { TEST(function test_lookup_failure(done) { - var req = dns.lookup('nosuchhostimsure', function(err) { + const req = dns.lookup('nosuchhostimsure', function(err) { assert(err instanceof Error); assert.strictEqual(err.code, 'ENOTFOUND'); // Silly error code... assert.strictEqual(err.hostname, 'nosuchhostimsure'); @@ -460,7 +460,7 @@ TEST(function test_lookup_failure(done) { TEST(function test_resolve_failure(done) { - var req = dns.resolve4('nosuchhostimsure', function(err) { + const req = dns.resolve4('nosuchhostimsure', function(err) { assert(err instanceof Error); switch (err.code) { @@ -482,12 +482,12 @@ TEST(function test_resolve_failure(done) { }); -var getaddrinfoCallbackCalled = false; +let getaddrinfoCallbackCalled = false; console.log('looking up nodejs.org...'); -var cares = process.binding('cares_wrap'); -var req = new cares.GetAddrInfoReqWrap(); +const cares = process.binding('cares_wrap'); +const req = new cares.GetAddrInfoReqWrap(); cares.getaddrinfo(req, 'nodejs.org', 4); req.oncomplete = function(err, domains) { diff --git a/test/internet/test-http-https-default-ports.js b/test/internet/test-http-https-default-ports.js index 8b00e434e9cba6..c7e6b3baf7ccdc 100644 --- a/test/internet/test-http-https-default-ports.js +++ b/test/internet/test-http-https-default-ports.js @@ -1,13 +1,13 @@ 'use strict'; -var common = require('../common'); +const common = require('../common'); if (!common.hasCrypto) { common.skip('missing crypto'); return; } -var https = require('https'); +const https = require('https'); -var http = require('http'); +const http = require('http'); https.get('https://www.google.com/', common.mustCall(function(res) { res.resume(); diff --git a/test/internet/test-net-connect-timeout.js b/test/internet/test-net-connect-timeout.js index 0f58622aa19912..95e25614ffa2b7 100644 --- a/test/internet/test-net-connect-timeout.js +++ b/test/internet/test-net-connect-timeout.js @@ -4,24 +4,24 @@ // https://groups.google.com/forum/#!topic/nodejs-dev/jR7-5UDqXkw const common = require('../common'); -var net = require('net'); -var assert = require('assert'); +const net = require('net'); +const assert = require('assert'); -var start = new Date(); +const start = new Date(); -var T = 100; +const T = 100; // 192.0.2.1 is part of subnet assigned as "TEST-NET" in RFC 5737. // For use solely in documentation and example source code. // In short, it should be unreachable. // In practice, it's a network black hole. -var socket = net.createConnection(9999, '192.0.2.1'); +const socket = net.createConnection(9999, '192.0.2.1'); socket.setTimeout(T); socket.on('timeout', common.mustCall(function() { console.error('timeout'); - var now = new Date(); + const now = new Date(); assert.ok(now - start < T + 500); socket.destroy(); })); diff --git a/test/internet/test-net-connect-unref.js b/test/internet/test-net-connect-unref.js index 52929d2152774d..f3be8409844702 100644 --- a/test/internet/test-net-connect-unref.js +++ b/test/internet/test-net-connect-unref.js @@ -1,11 +1,10 @@ 'use strict'; const common = require('../common'); -var net = require('net'); +const net = require('net'); -var client; -var TIMEOUT = 10 * 1000; +const TIMEOUT = 10 * 1000; -client = net.createConnection(53, '8.8.8.8', function() { +const client = net.createConnection(53, '8.8.8.8', function() { client.unref(); }); diff --git a/test/internet/test-tls-connnect-melissadata.js b/test/internet/test-tls-connnect-melissadata.js index 7ab7f2aa7a7895..f57b897099fc2d 100644 --- a/test/internet/test-tls-connnect-melissadata.js +++ b/test/internet/test-tls-connnect-melissadata.js @@ -2,14 +2,14 @@ // Test for authorized access to the server which has a cross root // certification between Starfield Class 2 and ValiCert Class 2 -var common = require('../common'); +const common = require('../common'); if (!common.hasCrypto) { common.skip('missing crypto'); return; } -var tls = require('tls'); -var socket = tls.connect(443, 'address.melissadata.net', function() { +const tls = require('tls'); +const socket = tls.connect(443, 'address.melissadata.net', function() { socket.resume(); socket.destroy(); }); diff --git a/test/known_issues/test-url-parse-conformance.js b/test/known_issues/test-url-parse-conformance.js index d70a322d6b7455..f7fcec821c8e50 100644 --- a/test/known_issues/test-url-parse-conformance.js +++ b/test/known_issues/test-url-parse-conformance.js @@ -9,14 +9,14 @@ const path = require('path'); const tests = require(path.join(common.fixturesDir, 'url-tests.json')); -var failed = 0; -var attempted = 0; +let failed = 0; +let attempted = 0; tests.forEach((test) => { attempted++; // Skip comments if (typeof test === 'string') return; - var parsed; + let parsed; try { // Attempt to parse @@ -28,7 +28,7 @@ tests.forEach((test) => { } else { // Test was not supposed to fail, so we're good so far. Now // check the results of the parse. - var username, password; + let username, password; try { assert.strictEqual(test.href, parsed.href); assert.strictEqual(test.protocol, parsed.protocol); diff --git a/test/message/error_exit.js b/test/message/error_exit.js index 18d9dfb4ee998c..7235801514dd45 100644 --- a/test/message/error_exit.js +++ b/test/message/error_exit.js @@ -1,6 +1,6 @@ 'use strict'; require('../common'); -var assert = require('assert'); +const assert = require('assert'); process.on('exit', function(code) { console.error('Exiting with code=%d', code); diff --git a/test/message/eval_messages.js b/test/message/eval_messages.js index bb1569601c889f..d50df9081b2d25 100644 --- a/test/message/eval_messages.js +++ b/test/message/eval_messages.js @@ -2,19 +2,19 @@ require('../common'); -var spawn = require('child_process').spawn; +const spawn = require('child_process').spawn; function run(cmd, strict, cb) { - var args = []; + const args = []; if (strict) args.push('--use_strict'); args.push('-pe', cmd); - var child = spawn(process.execPath, args); + const child = spawn(process.execPath, args); child.stdout.pipe(process.stdout); child.stderr.pipe(process.stdout); child.on('close', cb); } -var queue = +const queue = [ 'with(this){__filename}', '42', 'throw new Error("hello")', @@ -22,7 +22,7 @@ var queue = 'var ______________________________________________; throw 10' ]; function go() { - var c = queue.shift(); + const c = queue.shift(); if (!c) return console.log('done'); run(c, false, function() { run(c, true, go); diff --git a/test/message/max_tick_depth.js b/test/message/max_tick_depth.js index 1d2ec175c5d957..c433c0bab3f100 100644 --- a/test/message/max_tick_depth.js +++ b/test/message/max_tick_depth.js @@ -2,7 +2,7 @@ require('../common'); process.maxTickDepth = 10; -var i = 20; +let i = 20; process.nextTick(function f() { console.error('tick %d', i); if (i-- > 0) diff --git a/test/message/stdin_messages.js b/test/message/stdin_messages.js index 6e1ced4124f2a6..b32004c329dead 100644 --- a/test/message/stdin_messages.js +++ b/test/message/stdin_messages.js @@ -2,20 +2,20 @@ require('../common'); -var spawn = require('child_process').spawn; +const spawn = require('child_process').spawn; function run(cmd, strict, cb) { - var args = []; + const args = []; if (strict) args.push('--use_strict'); args.push('-p'); - var child = spawn(process.execPath, args); + const child = spawn(process.execPath, args); child.stdout.pipe(process.stdout); child.stderr.pipe(process.stdout); child.stdin.end(cmd); child.on('close', cb); } -var queue = +const queue = [ 'with(this){__filename}', '42', 'throw new Error("hello")', @@ -23,7 +23,7 @@ var queue = 'var ______________________________________________; throw 10' ]; function go() { - var c = queue.shift(); + const c = queue.shift(); if (!c) return console.log('done'); run(c, false, function() { run(c, true, go); diff --git a/test/message/undefined_reference_in_new_context.js b/test/message/undefined_reference_in_new_context.js index 73821ae53d4f5f..77c5e1e29111b9 100644 --- a/test/message/undefined_reference_in_new_context.js +++ b/test/message/undefined_reference_in_new_context.js @@ -1,6 +1,6 @@ 'use strict'; require('../common'); -var vm = require('vm'); +const vm = require('vm'); console.error('before'); diff --git a/test/message/vm_display_runtime_error.js b/test/message/vm_display_runtime_error.js index a7ca9907444181..861e87f2f2bb93 100644 --- a/test/message/vm_display_runtime_error.js +++ b/test/message/vm_display_runtime_error.js @@ -1,6 +1,6 @@ 'use strict'; require('../common'); -var vm = require('vm'); +const vm = require('vm'); console.error('beginning'); diff --git a/test/message/vm_display_syntax_error.js b/test/message/vm_display_syntax_error.js index 62bbd432a2f98a..02612fb92d9a22 100644 --- a/test/message/vm_display_syntax_error.js +++ b/test/message/vm_display_syntax_error.js @@ -1,6 +1,6 @@ 'use strict'; require('../common'); -var vm = require('vm'); +const vm = require('vm'); console.error('beginning'); diff --git a/test/message/vm_dont_display_runtime_error.js b/test/message/vm_dont_display_runtime_error.js index 19d0120a90abfd..6a96243a83cf4a 100644 --- a/test/message/vm_dont_display_runtime_error.js +++ b/test/message/vm_dont_display_runtime_error.js @@ -1,6 +1,6 @@ 'use strict'; require('../common'); -var vm = require('vm'); +const vm = require('vm'); console.error('beginning'); diff --git a/test/message/vm_dont_display_syntax_error.js b/test/message/vm_dont_display_syntax_error.js index bff0433a144b09..76c3043330946d 100644 --- a/test/message/vm_dont_display_syntax_error.js +++ b/test/message/vm_dont_display_syntax_error.js @@ -1,6 +1,6 @@ 'use strict'; require('../common'); -var vm = require('vm'); +const vm = require('vm'); console.error('beginning'); diff --git a/test/parallel/test-assert-typedarray-deepequal.js b/test/parallel/test-assert-typedarray-deepequal.js index 2e6c88848a809f..f5ecb274a86a32 100644 --- a/test/parallel/test-assert-typedarray-deepequal.js +++ b/test/parallel/test-assert-typedarray-deepequal.js @@ -5,7 +5,7 @@ const assert = require('assert'); const a = require('assert'); function makeBlock(f) { - var args = Array.prototype.slice.call(arguments, 1); + const args = Array.prototype.slice.call(arguments, 1); return function() { return f.apply(this, args); }; diff --git a/test/parallel/test-assert.js b/test/parallel/test-assert.js index 003cbdcc90d4e7..44723ef45bb964 100644 --- a/test/parallel/test-assert.js +++ b/test/parallel/test-assert.js @@ -1,10 +1,10 @@ 'use strict'; require('../common'); -var assert = require('assert'); -var a = require('assert'); +const assert = require('assert'); +const a = require('assert'); function makeBlock(f) { - var args = Array.prototype.slice.call(arguments, 1); + const args = Array.prototype.slice.call(arguments, 1); return function() { return f.apply(this, args); }; @@ -127,8 +127,8 @@ assert.throws(makeBlock(a.deepEqual, {a: 4}, {a: 4, b: true}), assert.doesNotThrow(makeBlock(a.deepEqual, ['a'], {0: 'a'})); //(although not necessarily the same order), assert.doesNotThrow(makeBlock(a.deepEqual, {a: 4, b: '1'}, {b: '1', a: 4})); -var a1 = [1, 2, 3]; -var a2 = [1, 2, 3]; +const a1 = [1, 2, 3]; +const a2 = [1, 2, 3]; a1.a = 'test'; a1.b = true; a2.b = true; @@ -138,7 +138,7 @@ assert.throws(makeBlock(a.deepEqual, Object.keys(a1), Object.keys(a2)), assert.doesNotThrow(makeBlock(a.deepEqual, a1, a2)); // having an identical prototype property -var nbRoot = { +const nbRoot = { toString: function() { return this.first + ' ' + this.last; } }; @@ -156,8 +156,8 @@ function nameBuilder2(first, last) { } nameBuilder2.prototype = nbRoot; -var nb1 = new nameBuilder('Ryan', 'Dahl'); -var nb2 = new nameBuilder2('Ryan', 'Dahl'); +const nb1 = new nameBuilder('Ryan', 'Dahl'); +let nb2 = new nameBuilder2('Ryan', 'Dahl'); assert.doesNotThrow(makeBlock(a.deepEqual, nb1, nb2)); @@ -289,8 +289,8 @@ function Constructor2(first, last) { this.last = last; } -var obj1 = new Constructor1('Ryan', 'Dahl'); -var obj2 = new Constructor2('Ryan', 'Dahl'); +const obj1 = new Constructor1('Ryan', 'Dahl'); +let obj2 = new Constructor2('Ryan', 'Dahl'); assert.throws(makeBlock(a.deepStrictEqual, obj1, obj2), a.AssertionError); @@ -307,7 +307,7 @@ assert.throws(makeBlock(assert.deepStrictEqual, true, 1), assert.throws(makeBlock(assert.deepStrictEqual, Symbol(), Symbol()), a.AssertionError); -var s = Symbol(); +const s = Symbol(); assert.doesNotThrow(makeBlock(assert.deepStrictEqual, s, s)); @@ -348,7 +348,7 @@ assert.throws(makeBlock(thrower, a.AssertionError)); assert.throws(makeBlock(thrower, TypeError)); // when passing a type, only catch errors of the appropriate type -var threw = false; +let threw = false; try { a.throws(makeBlock(thrower, TypeError), a.AssertionError); } catch (e) { @@ -417,10 +417,11 @@ a.throws(makeBlock(thrower, TypeError), function(err) { // https://github.com/nodejs/node/issues/3188 threw = false; +let AnotherErrorType; try { - var ES6Error = class extends Error {}; + const ES6Error = class extends Error {}; - var AnotherErrorType = class extends Error {}; + AnotherErrorType = class extends Error {}; const functionThatThrows = function() { throw new AnotherErrorType('foo'); @@ -459,7 +460,7 @@ assert.ok(threw); a.throws(makeBlock(a.deepStrictEqual, d, e), /AssertionError/); } // GH-7178. Ensure reflexivity of deepEqual with `arguments` objects. -var args = (function() { return arguments; })(); +const args = (function() { return arguments; })(); a.throws(makeBlock(a.deepEqual, [], args)); a.throws(makeBlock(a.deepEqual, args, [])); @@ -478,7 +479,7 @@ a.throws(makeBlock(a.deepEqual, args, [])); a.doesNotThrow(makeBlock(a.deepEqual, someArgs, sameArgs)); } -var circular = {y: 1}; +const circular = {y: 1}; circular.x = circular; function testAssertionMessage(actual, expected) { @@ -543,7 +544,7 @@ try { // Verify that throws() and doesNotThrow() throw on non-function block function testBlockTypeError(method, block) { - var threw = true; + let threw = true; try { method(block); diff --git a/test/parallel/test-async-wrap-check-providers.js b/test/parallel/test-async-wrap-check-providers.js index a130e130e98a8e..f4b50df576fb6f 100644 --- a/test/parallel/test-async-wrap-check-providers.js +++ b/test/parallel/test-async-wrap-check-providers.js @@ -23,7 +23,7 @@ keyList.splice(0, 1); // want to improve under https://github.com/nodejs/node/issues/5085. // strip out fs watch related parts for now if (common.isAix) { - for (var i = 0; i < keyList.length; i++) { + for (let i = 0; i < keyList.length; i++) { if ((keyList[i] === 'FSEVENTWRAP') || (keyList[i] === 'STATWATCHER')) { keyList.splice(i, 1); } diff --git a/test/parallel/test-async-wrap-throw-from-callback.js b/test/parallel/test-async-wrap-throw-from-callback.js index 93b5bee470ce3f..41e3e4efa2d607 100644 --- a/test/parallel/test-async-wrap-throw-from-callback.js +++ b/test/parallel/test-async-wrap-throw-from-callback.js @@ -8,8 +8,8 @@ const domain = require('domain'); const spawn = require('child_process').spawn; const callbacks = [ 'init', 'pre', 'post' ]; const toCall = process.argv[2]; -var msgCalled = 0; -var msgReceived = 0; +let msgCalled = 0; +let msgReceived = 0; function init() { if (toCall === 'init') @@ -48,7 +48,7 @@ if (typeof process.argv[2] === 'string') { msgCalled++; const child = spawn(process.execPath, [__filename, item]); - var errstring = ''; + let errstring = ''; child.stderr.on('data', (data) => { errstring += data.toString(); diff --git a/test/parallel/test-async-wrap-uid.js b/test/parallel/test-async-wrap-uid.js index 19cb01cfa83c7a..f16388cfe766f0 100644 --- a/test/parallel/test-async-wrap-uid.js +++ b/test/parallel/test-async-wrap-uid.js @@ -6,7 +6,7 @@ const assert = require('assert'); const async_wrap = process.binding('async_wrap'); // Give the event loop time to clear out the final uv_close(). -var si_cntr = 3; +let si_cntr = 3; process.on('beforeExit', () => { if (--si_cntr > 0) setImmediate(() => {}); }); diff --git a/test/parallel/test-beforeexit-event-exit.js b/test/parallel/test-beforeexit-event-exit.js index 67676a7990041f..6878135ce4d6d3 100644 --- a/test/parallel/test-beforeexit-event-exit.js +++ b/test/parallel/test-beforeexit-event-exit.js @@ -1,6 +1,6 @@ 'use strict'; require('../common'); -var assert = require('assert'); +const assert = require('assert'); process.on('beforeExit', function() { assert(false, 'exit should not allow this to occur'); diff --git a/test/parallel/test-buffer-ascii.js b/test/parallel/test-buffer-ascii.js index ea125283f23f93..cf5b529183cabf 100644 --- a/test/parallel/test-buffer-ascii.js +++ b/test/parallel/test-buffer-ascii.js @@ -16,7 +16,7 @@ const expected = 'Cb\u0000\u0019est, graphiquement, la rC)union ' + const buf = Buffer.from(input); -for (var i = 0; i < expected.length; ++i) { +for (let i = 0; i < expected.length; ++i) { assert.strictEqual(buf.slice(i).toString('ascii'), expected.slice(i)); // Skip remainder of multi-byte sequence. diff --git a/test/parallel/test-buffer-bytelength.js b/test/parallel/test-buffer-bytelength.js index 58286e61b4899b..9bb3b759e0208f 100644 --- a/test/parallel/test-buffer-bytelength.js +++ b/test/parallel/test-buffer-bytelength.js @@ -20,37 +20,37 @@ assert(ArrayBuffer.isView(Buffer.allocUnsafeSlow(10))); assert(ArrayBuffer.isView(Buffer.from(''))); // buffer -var incomplete = Buffer.from([0xe4, 0xb8, 0xad, 0xe6, 0x96]); +const incomplete = Buffer.from([0xe4, 0xb8, 0xad, 0xe6, 0x96]); assert.strictEqual(Buffer.byteLength(incomplete), 5); -var ascii = Buffer.from('abc'); +const ascii = Buffer.from('abc'); assert.strictEqual(Buffer.byteLength(ascii), 3); // ArrayBuffer -var buffer = new ArrayBuffer(8); +const buffer = new ArrayBuffer(8); assert.strictEqual(Buffer.byteLength(buffer), 8); // TypedArray -var int8 = new Int8Array(8); +const int8 = new Int8Array(8); assert.strictEqual(Buffer.byteLength(int8), 8); -var uint8 = new Uint8Array(8); +const uint8 = new Uint8Array(8); assert.strictEqual(Buffer.byteLength(uint8), 8); -var uintc8 = new Uint8ClampedArray(2); +const uintc8 = new Uint8ClampedArray(2); assert.strictEqual(Buffer.byteLength(uintc8), 2); -var int16 = new Int16Array(8); +const int16 = new Int16Array(8); assert.strictEqual(Buffer.byteLength(int16), 16); -var uint16 = new Uint16Array(8); +const uint16 = new Uint16Array(8); assert.strictEqual(Buffer.byteLength(uint16), 16); -var int32 = new Int32Array(8); +const int32 = new Int32Array(8); assert.strictEqual(Buffer.byteLength(int32), 32); -var uint32 = new Uint32Array(8); +const uint32 = new Uint32Array(8); assert.strictEqual(Buffer.byteLength(uint32), 32); -var float32 = new Float32Array(8); +const float32 = new Float32Array(8); assert.strictEqual(Buffer.byteLength(float32), 32); -var float64 = new Float64Array(8); +const float64 = new Float64Array(8); assert.strictEqual(Buffer.byteLength(float64), 64); // DataView -var dv = new DataView(new ArrayBuffer(2)); +const dv = new DataView(new ArrayBuffer(2)); assert.strictEqual(Buffer.byteLength(dv), 2); // special case: zero length string diff --git a/test/parallel/test-buffer-concat.js b/test/parallel/test-buffer-concat.js index 800f1055aa6222..1016dd8103447d 100644 --- a/test/parallel/test-buffer-concat.js +++ b/test/parallel/test-buffer-concat.js @@ -5,7 +5,7 @@ const assert = require('assert'); const zero = []; const one = [ Buffer.from('asdf') ]; const long = []; -for (var i = 0; i < 10; i++) long.push(Buffer.from('asdf')); +for (let i = 0; i < 10; i++) long.push(Buffer.from('asdf')); const flatZero = Buffer.concat(zero); const flatOne = Buffer.concat(one); diff --git a/test/parallel/test-buffer-copy.js b/test/parallel/test-buffer-copy.js index 0fb37cc0b41cf7..1b10dadb5b709b 100644 --- a/test/parallel/test-buffer-copy.js +++ b/test/parallel/test-buffer-copy.js @@ -5,7 +5,7 @@ const assert = require('assert'); const b = Buffer.allocUnsafe(1024); const c = Buffer.allocUnsafe(512); -var cntr = 0; +let cntr = 0; { // copy 512 bytes, from 0 to 512. diff --git a/test/parallel/test-buffer-fill.js b/test/parallel/test-buffer-fill.js index 8cfeeabe91eebe..06a9044bec3103 100644 --- a/test/parallel/test-buffer-fill.js +++ b/test/parallel/test-buffer-fill.js @@ -243,7 +243,7 @@ function writeToFill(string, offset, end, encoding) { // Convert "end" to "length" (which write understands). const length = end - offset < 0 ? 0 : end - offset; - var wasZero = false; + let wasZero = false; do { const written = buf2.write(string, offset, length, encoding); offset += written; @@ -324,7 +324,7 @@ Buffer.alloc(8, ''); { let elseWasLast = false; assert.throws(() => { - var ctr = 0; + let ctr = 0; const start = { [Symbol.toPrimitive]() { // We use this condition to get around the check in lib/buffer.js @@ -357,7 +357,7 @@ assert.throws(() => { { let elseWasLast = false; assert.throws(() => { - var ctr = 0; + let ctr = 0; const end = { [Symbol.toPrimitive]() { // We use this condition to get around the check in lib/buffer.js diff --git a/test/parallel/test-buffer-includes.js b/test/parallel/test-buffer-includes.js index 15e1eedeb54d15..9b0aef0ad7652d 100644 --- a/test/parallel/test-buffer-includes.js +++ b/test/parallel/test-buffer-includes.js @@ -140,7 +140,7 @@ assert.strictEqual( // test usc2 encoding -var twoByteString = Buffer.from('\u039a\u0391\u03a3\u03a3\u0395', 'ucs2'); +let twoByteString = Buffer.from('\u039a\u0391\u03a3\u03a3\u0395', 'ucs2'); assert(twoByteString.includes('\u0395', 4, 'ucs2')); assert(twoByteString.includes('\u03a3', -4, 'ucs2')); @@ -190,7 +190,7 @@ assert(!mixedByteStringUtf8.includes('\u0396')); // Test complex string includes algorithms. Only trigger for long strings. // Long string that isn't a simple repeat of a shorter string. -var longString = 'A'; +let longString = 'A'; for (let i = 66; i < 76; i++) { // from 'B' to 'K' longString = longString + String.fromCharCode(i) + longString; } @@ -198,7 +198,7 @@ for (let i = 66; i < 76; i++) { // from 'B' to 'K' const longBufferString = Buffer.from(longString); // pattern of 15 chars, repeated every 16 chars in long -var pattern = 'ABACABADABACABA'; +let pattern = 'ABACABADABACABA'; for (let i = 0; i < longBufferString.length - pattern.length; i += 7) { const includes = longBufferString.includes(pattern, i); assert(includes, 'Long ABACABA...-string at index ' + i); @@ -229,8 +229,8 @@ assert(!allCharsBufferUtf8.includes('notfound')); assert(!allCharsBufferUcs2.includes('notfound')); // Find substrings in Utf8. -var lengths = [1, 3, 15]; // Single char, simple and complex. -var indices = [0x5, 0x60, 0x400, 0x680, 0x7ee, 0xFF02, 0x16610, 0x2f77b]; +let lengths = [1, 3, 15]; // Single char, simple and complex. +let indices = [0x5, 0x60, 0x400, 0x680, 0x7ee, 0xFF02, 0x16610, 0x2f77b]; for (let lengthIndex = 0; lengthIndex < lengths.length; lengthIndex++) { for (let i = 0; i < indices.length; i++) { const index = indices[i]; diff --git a/test/parallel/test-buffer-indexof.js b/test/parallel/test-buffer-indexof.js index d0379ec17162e9..5bb7424581bc6a 100644 --- a/test/parallel/test-buffer-indexof.js +++ b/test/parallel/test-buffer-indexof.js @@ -193,7 +193,7 @@ assert.equal(Buffer.from('aaaa00a').indexOf('3030', 'hex'), 4); assert.equal(-1, twoByteString.indexOf('\u03a3', -2, 'ucs2')); } -var mixedByteStringUcs2 = +const mixedByteStringUcs2 = Buffer.from('\u039a\u0391abc\u03a3\u03a3\u0395', 'ucs2'); assert.equal(6, mixedByteStringUcs2.indexOf('bc', 0, 'ucs2')); assert.equal(10, mixedByteStringUcs2.indexOf('\u03a3', 0, 'ucs2')); @@ -228,7 +228,7 @@ assert.equal( 6, twoByteString.indexOf('\u03a3\u0395', 0, 'ucs2'), 'Sigma Epsilon'); } -var mixedByteStringUtf8 = Buffer.from('\u039a\u0391abc\u03a3\u03a3\u0395'); +const mixedByteStringUtf8 = Buffer.from('\u039a\u0391abc\u03a3\u03a3\u0395'); assert.equal(5, mixedByteStringUtf8.indexOf('bc')); assert.equal(5, mixedByteStringUtf8.indexOf('bc', 5)); assert.equal(5, mixedByteStringUtf8.indexOf('bc', -8)); @@ -238,15 +238,15 @@ assert.equal(-1, mixedByteStringUtf8.indexOf('\u0396')); // Test complex string indexOf algorithms. Only trigger for long strings. // Long string that isn't a simple repeat of a shorter string. -var longString = 'A'; +let longString = 'A'; for (let i = 66; i < 76; i++) { // from 'B' to 'K' longString = longString + String.fromCharCode(i) + longString; } -var longBufferString = Buffer.from(longString); +const longBufferString = Buffer.from(longString); // pattern of 15 chars, repeated every 16 chars in long -var pattern = 'ABACABADABACABA'; +let pattern = 'ABACABADABACABA'; for (let i = 0; i < longBufferString.length - pattern.length; i += 7) { const index = longBufferString.indexOf(pattern, i); assert.equal((i + 15) & ~0xf, index, 'Long ABACABA...-string at index ' + i); @@ -262,17 +262,17 @@ assert.equal( 1535, longBufferString.indexOf(pattern, 512), 'Long JABACABA..., Second J'); // Search for a non-ASCII string in a pure ASCII string. -var asciiString = Buffer.from( +const asciiString = Buffer.from( 'arglebargleglopglyfarglebargleglopglyfarglebargleglopglyf'); assert.equal(-1, asciiString.indexOf('\x2061')); assert.equal(3, asciiString.indexOf('leb', 0)); // Search in string containing many non-ASCII chars. -var allCodePoints = []; +const allCodePoints = []; for (let i = 0; i < 65536; i++) allCodePoints[i] = i; -var allCharsString = String.fromCharCode.apply(String, allCodePoints); -var allCharsBufferUtf8 = Buffer.from(allCharsString); -var allCharsBufferUcs2 = Buffer.from(allCharsString, 'ucs2'); +const allCharsString = String.fromCharCode.apply(String, allCodePoints); +const allCharsBufferUtf8 = Buffer.from(allCharsString); +const allCharsBufferUcs2 = Buffer.from(allCharsString, 'ucs2'); // Search for string long enough to trigger complex search with ASCII pattern // and UC16 subject. @@ -309,10 +309,10 @@ assert.strictEqual(Buffer.from('aaaaa').indexOf('b', 'ucs2'), -1); length = 4 * length; } - var patternBufferUtf8 = allCharsBufferUtf8.slice(index, index + length); + const patternBufferUtf8 = allCharsBufferUtf8.slice(index, index + length); assert.equal(index, allCharsBufferUtf8.indexOf(patternBufferUtf8)); - var patternStringUtf8 = patternBufferUtf8.toString(); + const patternStringUtf8 = patternBufferUtf8.toString(); assert.equal(index, allCharsBufferUtf8.indexOf(patternStringUtf8)); } } @@ -327,12 +327,12 @@ assert.strictEqual(Buffer.from('aaaaa').indexOf('b', 'ucs2'), -1); const index = indices[i] * 2; const length = lengths[lengthIndex]; - var patternBufferUcs2 = + const patternBufferUcs2 = allCharsBufferUcs2.slice(index, index + length); assert.equal( index, allCharsBufferUcs2.indexOf(patternBufferUcs2, 0, 'ucs2')); - var patternStringUcs2 = patternBufferUcs2.toString('ucs2'); + const patternStringUcs2 = patternBufferUcs2.toString('ucs2'); assert.equal( index, allCharsBufferUcs2.indexOf(patternStringUcs2, 0, 'ucs2')); } @@ -491,7 +491,7 @@ assert.strictEqual(buf_bc.lastIndexOf('你好', 5, 'binary'), -1); assert.strictEqual(buf_bc.lastIndexOf(Buffer.from('你好'), 7), -1); // Test lastIndexOf on a longer buffer: -var bufferString = new Buffer('a man a plan a canal panama'); +const bufferString = new Buffer('a man a plan a canal panama'); assert.equal(15, bufferString.lastIndexOf('canal')); assert.equal(21, bufferString.lastIndexOf('panama')); assert.equal(0, bufferString.lastIndexOf('a man a plan a canal panama')); @@ -542,16 +542,17 @@ assert.equal(511, longBufferString.lastIndexOf(pattern, 1534)); // countBits returns the number of bits in the binary reprsentation of n. function countBits(n) { - for (var count = 0; n > 0; count++) { + let count; + for (count = 0; n > 0; count++) { n = n & (n - 1); // remove top bit } return count; } -var parts = []; -for (var i = 0; i < 1000000; i++) { +const parts = []; +for (let i = 0; i < 1000000; i++) { parts.push((countBits(i) % 2 === 0) ? 'yolo' : 'swag'); } -var reallyLong = new Buffer(parts.join(' ')); +const reallyLong = new Buffer(parts.join(' ')); assert.equal('yolo swag swag yolo', reallyLong.slice(0, 19).toString()); // Expensive reverse searches. Stress test lastIndexOf: diff --git a/test/parallel/test-buffer-inspect.js b/test/parallel/test-buffer-inspect.js index 4fed249207611b..41e8197da6a38a 100644 --- a/test/parallel/test-buffer-inspect.js +++ b/test/parallel/test-buffer-inspect.js @@ -6,13 +6,13 @@ const buffer = require('buffer'); buffer.INSPECT_MAX_BYTES = 2; -var b = Buffer.allocUnsafe(4); +let b = Buffer.allocUnsafe(4); b.fill('1234'); -var s = buffer.SlowBuffer(4); +let s = buffer.SlowBuffer(4); s.fill('1234'); -var expected = ''; +let expected = ''; assert.strictEqual(util.inspect(b), expected); assert.strictEqual(util.inspect(s), expected); diff --git a/test/parallel/test-buffer-iterator.js b/test/parallel/test-buffer-iterator.js index 7a25682ebc27d9..3120ff1d2ab457 100644 --- a/test/parallel/test-buffer-iterator.js +++ b/test/parallel/test-buffer-iterator.js @@ -3,8 +3,8 @@ require('../common'); const assert = require('assert'); const buffer = Buffer.from([1, 2, 3, 4, 5]); -var arr; -var b; +let arr; +let b; // buffers should be iterable diff --git a/test/parallel/test-buffer-swap.js b/test/parallel/test-buffer-swap.js index f72b638f75a30b..bcb636edb1733f 100644 --- a/test/parallel/test-buffer-swap.js +++ b/test/parallel/test-buffer-swap.js @@ -45,80 +45,80 @@ assert.deepStrictEqual(buf3_64, Buffer.from([0x01, 0x02, 0x0a, 0x09, 0x08, 0x07, 0x0f, 0x10])); // Force use of native code (Buffer size above threshold limit for js impl) -var buf4A = new Uint32Array(256).fill(0x04030201); -var buf4 = Buffer.from(buf4A.buffer, buf4A.byteOffset); -var buf5A = new Uint32Array(256).fill(0x03040102); -var buf5 = Buffer.from(buf5A.buffer, buf5A.byteOffset); +const buf4A = new Uint32Array(256).fill(0x04030201); +const buf4 = Buffer.from(buf4A.buffer, buf4A.byteOffset); +const buf5A = new Uint32Array(256).fill(0x03040102); +const buf5 = Buffer.from(buf5A.buffer, buf5A.byteOffset); buf4.swap16(); assert.deepStrictEqual(buf4, buf5); -var buf6A = new Uint32Array(256).fill(0x04030201); -var buf6 = Buffer.from(buf6A.buffer); -var bu7A = new Uint32Array(256).fill(0x01020304); -var buf7 = Buffer.from(bu7A.buffer, bu7A.byteOffset); +const buf6A = new Uint32Array(256).fill(0x04030201); +const buf6 = Buffer.from(buf6A.buffer); +const bu7A = new Uint32Array(256).fill(0x01020304); +const buf7 = Buffer.from(bu7A.buffer, bu7A.byteOffset); buf6.swap32(); assert.deepStrictEqual(buf6, buf7); -var buf8A = new Uint8Array(256 * 8); -var buf9A = new Uint8Array(256 * 8); +const buf8A = new Uint8Array(256 * 8); +const buf9A = new Uint8Array(256 * 8); for (let i = 0; i < buf8A.length; i++) { buf8A[i] = i % 8; buf9A[buf9A.length - i - 1] = i % 8; } -var buf8 = Buffer.from(buf8A.buffer, buf8A.byteOffset); -var buf9 = Buffer.from(buf9A.buffer, buf9A.byteOffset); +const buf8 = Buffer.from(buf8A.buffer, buf8A.byteOffset); +const buf9 = Buffer.from(buf9A.buffer, buf9A.byteOffset); buf8.swap64(); assert.deepStrictEqual(buf8, buf9); // Test native code with buffers that are not memory-aligned -var buf10A = new Uint8Array(256 * 8); -var buf11A = new Uint8Array(256 * 8 - 2); +const buf10A = new Uint8Array(256 * 8); +const buf11A = new Uint8Array(256 * 8 - 2); for (let i = 0; i < buf10A.length; i++) { buf10A[i] = i % 2; } for (let i = 1; i < buf11A.length; i++) { buf11A[buf11A.length - i] = (i + 1) % 2; } -var buf10 = Buffer.from(buf10A.buffer, buf10A.byteOffset); +const buf10 = Buffer.from(buf10A.buffer, buf10A.byteOffset); // 0|1 0|1 0|1... -var buf11 = Buffer.from(buf11A.buffer, buf11A.byteOffset); +const buf11 = Buffer.from(buf11A.buffer, buf11A.byteOffset); // 0|0 1|0 1|0... buf10.slice(1, buf10.length - 1).swap16(); assert.deepStrictEqual(buf10.slice(0, buf11.length), buf11); -var buf12A = new Uint8Array(256 * 8); -var buf13A = new Uint8Array(256 * 8 - 4); +const buf12A = new Uint8Array(256 * 8); +const buf13A = new Uint8Array(256 * 8 - 4); for (let i = 0; i < buf12A.length; i++) { buf12A[i] = i % 4; } for (let i = 1; i < buf13A.length; i++) { buf13A[buf13A.length - i] = (i + 1) % 4; } -var buf12 = Buffer.from(buf12A.buffer, buf12A.byteOffset); +const buf12 = Buffer.from(buf12A.buffer, buf12A.byteOffset); // 0|1 2 3 0|1 2 3... -var buf13 = Buffer.from(buf13A.buffer, buf13A.byteOffset); +const buf13 = Buffer.from(buf13A.buffer, buf13A.byteOffset); // 0|0 3 2 1|0 3 2... buf12.slice(1, buf12.length - 3).swap32(); assert.deepStrictEqual(buf12.slice(0, buf13.length), buf13); -var buf14A = new Uint8Array(256 * 8); -var buf15A = new Uint8Array(256 * 8 - 8); +const buf14A = new Uint8Array(256 * 8); +const buf15A = new Uint8Array(256 * 8 - 8); for (let i = 0; i < buf14A.length; i++) { buf14A[i] = i % 8; } for (let i = 1; i < buf15A.length; i++) { buf15A[buf15A.length - i] = (i + 1) % 8; } -var buf14 = Buffer.from(buf14A.buffer, buf14A.byteOffset); +const buf14 = Buffer.from(buf14A.buffer, buf14A.byteOffset); // 0|1 2 3 4 5 6 7 0|1 2 3 4... -var buf15 = Buffer.from(buf15A.buffer, buf15A.byteOffset); +const buf15 = Buffer.from(buf15A.buffer, buf15A.byteOffset); // 0|0 7 6 5 4 3 2 1|0 7 6 5... buf14.slice(1, buf14.length - 7).swap64(); diff --git a/test/parallel/test-buffer.js b/test/parallel/test-buffer.js index ba564d758d9757..d07ccc3550aece 100644 --- a/test/parallel/test-buffer.js +++ b/test/parallel/test-buffer.js @@ -1,14 +1,14 @@ 'use strict'; -var common = require('../common'); -var assert = require('assert'); +const common = require('../common'); +const assert = require('assert'); -var Buffer = require('buffer').Buffer; -var SlowBuffer = require('buffer').SlowBuffer; +const Buffer = require('buffer').Buffer; +const SlowBuffer = require('buffer').SlowBuffer; // counter to ensure unique value is always copied -var cntr = 0; +let cntr = 0; -var b = Buffer(1024); // safe constructor +const b = Buffer(1024); // safe constructor console.log('b.length == %d', b.length); assert.strictEqual(1024, b.length); @@ -24,15 +24,15 @@ for (let i = 0; i < 1024; i++) { assert.strictEqual(i % 256, b[i]); } -var c = Buffer(512); +const c = Buffer(512); console.log('c.length == %d', c.length); assert.strictEqual(512, c.length); -var d = new Buffer([]); +const d = new Buffer([]); assert.strictEqual(0, d.length); -var ui32 = new Uint32Array(4).fill(42); -var e = Buffer(ui32); +const ui32 = new Uint32Array(4).fill(42); +const e = Buffer(ui32); for (const [key, value] of e.entries()) { assert.deepStrictEqual(value, ui32[key]); } @@ -179,7 +179,7 @@ Buffer(8).fill(''); } // copy string longer than buffer length (failure will segfault) -var bb = Buffer(10); +const bb = Buffer(10); bb.fill('hello crazy world'); @@ -214,7 +214,7 @@ assert.equal(b.copy(c, 0, 100, 10), 0); // when targetStart > targetLength, zero copied assert.equal(b.copy(c, 512, 0, 10), 0); -var caught_error; +let caught_error; // invalid encoding for Buffer.toString caught_error = null; @@ -352,7 +352,7 @@ assert.equal(rangeBuffer.toString({toString: function() { }}), 'abc'); // testing for smart defaults and ability to pass string values as offset -var writeTest = new Buffer('abcdes'); +const writeTest = new Buffer('abcdes'); writeTest.write('n', 'ascii'); writeTest.write('o', '1', 'ascii'); writeTest.write('d', '2', 'ascii'); @@ -394,20 +394,20 @@ assert.equal(writeTest.toString(), 'nodejs'); // UTF-8 slice test -var utf8String = '¡hέlló wôrld!'; -var offset = 100; +const utf8String = '¡hέlló wôrld!'; +const offset = 100; b.write(utf8String, 0, Buffer.byteLength(utf8String), 'utf8'); -var utf8Slice = b.toString('utf8', 0, Buffer.byteLength(utf8String)); +let utf8Slice = b.toString('utf8', 0, Buffer.byteLength(utf8String)); assert.equal(utf8String, utf8Slice); -var written = b.write(utf8String, offset, 'utf8'); +let written = b.write(utf8String, offset, 'utf8'); assert.equal(Buffer.byteLength(utf8String), written); utf8Slice = b.toString('utf8', offset, offset + Buffer.byteLength(utf8String)); assert.equal(utf8String, utf8Slice); -var sliceA = b.slice(offset, offset + Buffer.byteLength(utf8String)); -var sliceB = b.slice(offset, offset + Buffer.byteLength(utf8String)); +const sliceA = b.slice(offset, offset + Buffer.byteLength(utf8String)); +const sliceB = b.slice(offset, offset + Buffer.byteLength(utf8String)); for (let i = 0; i < Buffer.byteLength(utf8String); i++) { assert.equal(sliceA[i], sliceB[i]); } @@ -514,10 +514,10 @@ for (let i = 0; i < Buffer.byteLength(utf8String); i++) { } -var arrayIsh = {0: 0, 1: 1, 2: 2, 3: 3, length: 4}; -var g = new Buffer(arrayIsh); +const arrayIsh = {0: 0, 1: 1, 2: 2, 3: 3, length: 4}; +let g = new Buffer(arrayIsh); assert.deepStrictEqual(g, new Buffer([0, 1, 2, 3])); -var strArrayIsh = {0: '0', 1: '1', 2: '2', 3: '3', length: 4}; +const strArrayIsh = {0: '0', 1: '1', 2: '2', 3: '3', length: 4}; g = new Buffer(strArrayIsh); assert.deepStrictEqual(g, new Buffer([0, 1, 2, 3])); @@ -670,7 +670,7 @@ assert.equal( ); // This string encodes single '.' character in UTF-16 -var dot = new Buffer('//4uAA==', 'base64'); +const dot = new Buffer('//4uAA==', 'base64'); assert.equal(dot[0], 0xff); assert.equal(dot[1], 0xfe); assert.equal(dot[2], 0x2e); @@ -722,11 +722,11 @@ assert.equal(0, Buffer('hello').slice(0, 0).length); // test hex toString console.log('Create hex string from buffer'); -var hexb = new Buffer(256); +const hexb = new Buffer(256); for (let i = 0; i < 256; i++) { hexb[i] = i; } -var hexStr = hexb.toString('hex'); +const hexStr = hexb.toString('hex'); assert.equal(hexStr, '000102030405060708090a0b0c0d0e0f' + '101112131415161718191a1b1c1d1e1f' + @@ -746,7 +746,7 @@ assert.equal(hexStr, 'f0f1f2f3f4f5f6f7f8f9fafbfcfdfeff'); console.log('Create buffer from hex string'); -var hexb2 = new Buffer(hexStr, 'hex'); +const hexb2 = new Buffer(hexStr, 'hex'); for (let i = 0; i < 256; i++) { assert.equal(hexb2[i], hexb[i]); } @@ -773,7 +773,7 @@ assert.strictEqual(Buffer.from('A', 'base64').length, 0); function buildBuffer(data) { if (Array.isArray(data)) { - var buffer = Buffer(data.length); + const buffer = Buffer(data.length); data.forEach(function(v, k) { buffer[k] = v; }); @@ -782,7 +782,7 @@ function buildBuffer(data) { return null; } -var x = buildBuffer([0x81, 0xa3, 0x66, 0x6f, 0x6f, 0xa3, 0x62, 0x61, 0x72]); +const x = buildBuffer([0x81, 0xa3, 0x66, 0x6f, 0x6f, 0xa3, 0x62, 0x61, 0x72]); console.log(x.inspect()); assert.equal('', x.inspect()); @@ -991,7 +991,7 @@ assert.equal(0, Buffer('hello').slice(0, 0).length); { // test for buffer overrun const buf = new Buffer([0, 0, 0, 0, 0]); // length: 5 - var sub = buf.slice(0, 4); // length: 4 + const sub = buf.slice(0, 4); // length: 4 written = sub.write('12345', 'latin1'); assert.equal(written, 4); assert.equal(buf[4], 0); @@ -1087,55 +1087,55 @@ assert.throws(function() { // issue GH-5587 assert.throws(function() { - var buf = new Buffer(8); + const buf = new Buffer(8); buf.writeFloatLE(0, 5); }, RangeError); assert.throws(function() { - var buf = new Buffer(16); + const buf = new Buffer(16); buf.writeDoubleLE(0, 9); }, RangeError); // attempt to overflow buffers, similar to previous bug in array buffers assert.throws(function() { - var buf = Buffer(8); + const buf = Buffer(8); buf.readFloatLE(0xffffffff); }, RangeError); assert.throws(function() { - var buf = Buffer(8); + const buf = Buffer(8); buf.writeFloatLE(0.0, 0xffffffff); }, RangeError); assert.throws(function() { - var buf = Buffer(8); + const buf = Buffer(8); buf.readFloatLE(0xffffffff); }, RangeError); assert.throws(function() { - var buf = Buffer(8); + const buf = Buffer(8); buf.writeFloatLE(0.0, 0xffffffff); }, RangeError); // ensure negative values can't get past offset assert.throws(function() { - var buf = Buffer(8); + const buf = Buffer(8); buf.readFloatLE(-1); }, RangeError); assert.throws(function() { - var buf = Buffer(8); + const buf = Buffer(8); buf.writeFloatLE(0.0, -1); }, RangeError); assert.throws(function() { - var buf = Buffer(8); + const buf = Buffer(8); buf.readFloatLE(-1); }, RangeError); assert.throws(function() { - var buf = Buffer(8); + const buf = Buffer(8); buf.writeFloatLE(0.0, -1); }, RangeError); @@ -1155,7 +1155,7 @@ assert.throws(function() { } [16, 32].forEach(function(bits) { - var buf = new Buffer(bits / 8 - 1); + const buf = new Buffer(bits / 8 - 1); assert.throws(function() { buf['readUInt' + bits + 'BE'](0); }, RangeError, @@ -1175,7 +1175,7 @@ assert.throws(function() { }); [16, 32].forEach(function(bits) { - var buf = new Buffer([0xFF, 0xFF, 0xFF, 0xFF]); + const buf = new Buffer([0xFF, 0xFF, 0xFF, 0xFF]); assert.equal(buf['readUInt' + bits + 'BE'](0), (0xFFFFFFFF >>> (32 - bits))); @@ -1389,10 +1389,10 @@ assert.throws(function() { if (common.hasCrypto) { // Test truncation after decode - var crypto = require('crypto'); + const crypto = require('crypto'); - var b1 = new Buffer('YW55=======', 'base64'); - var b2 = new Buffer('YW55', 'base64'); + const b1 = new Buffer('YW55=======', 'base64'); + const b2 = new Buffer('YW55', 'base64'); assert.equal( crypto.createHash('sha1').update(b1).digest('hex'), @@ -1426,17 +1426,17 @@ if (common.hasCrypto) { } assert.throws(function() { - var b = Buffer(1); + const b = Buffer(1); Buffer.compare(b, 'abc'); }); assert.throws(function() { - var b = Buffer(1); + const b = Buffer(1); Buffer.compare('abc', b); }); assert.throws(function() { - var b = Buffer(1); + const b = Buffer(1); b.compare('abc'); }); @@ -1454,14 +1454,14 @@ assert.throws(function() { } assert.throws(function() { - var b = Buffer(1); + const b = Buffer(1); b.equals('abc'); }); // Regression test for https://github.com/nodejs/node/issues/649. assert.throws(function() { Buffer(1422561062959).toString('utf8'); }); -var ps = Buffer.poolSize; +const ps = Buffer.poolSize; Buffer.poolSize = 0; assert.equal(Buffer(1).parent, undefined); Buffer.poolSize = ps; diff --git a/test/parallel/test-child-process-constructor.js b/test/parallel/test-child-process-constructor.js index 0abf1289f0737d..d33c7ae3acf626 100644 --- a/test/parallel/test-child-process-constructor.js +++ b/test/parallel/test-child-process-constructor.js @@ -1,13 +1,13 @@ 'use strict'; require('../common'); -var assert = require('assert'); -var child_process = require('child_process'); -var ChildProcess = child_process.ChildProcess; +const assert = require('assert'); +const child_process = require('child_process'); +const ChildProcess = child_process.ChildProcess; assert.strictEqual(typeof ChildProcess, 'function'); // test that we can call spawn -var child = new ChildProcess(); +const child = new ChildProcess(); child.spawn({ file: process.execPath, args: ['--interactive'], diff --git a/test/parallel/test-child-process-default-options.js b/test/parallel/test-child-process-default-options.js index 38a1b291b9967c..37e7ea7494670e 100644 --- a/test/parallel/test-child-process-default-options.js +++ b/test/parallel/test-child-process-default-options.js @@ -1,19 +1,19 @@ 'use strict'; -var common = require('../common'); -var assert = require('assert'); +const common = require('../common'); +const assert = require('assert'); -var spawn = require('child_process').spawn; +const spawn = require('child_process').spawn; process.env.HELLO = 'WORLD'; -var child; +let child; if (common.isWindows) { child = spawn('cmd.exe', ['/c', 'set'], {}); } else { child = spawn('/usr/bin/env', [], {}); } -var response = ''; +let response = ''; child.stdout.setEncoding('utf8'); diff --git a/test/parallel/test-child-process-double-pipe.js b/test/parallel/test-child-process-double-pipe.js index c5b7c093af8a4a..dac48a2db7212a 100644 --- a/test/parallel/test-child-process-double-pipe.js +++ b/test/parallel/test-child-process-double-pipe.js @@ -8,7 +8,7 @@ const spawn = require('child_process').spawn; // We're trying to reproduce: // $ echo "hello\nnode\nand\nworld" | grep o | sed s/o/a/ -var grep, sed, echo; +let grep, sed, echo; if (common.isWindows) { grep = spawn('grep', ['--binary', 'o']), @@ -82,7 +82,7 @@ grep.stdout.on('end', function(code) { }); -var result = ''; +let result = ''; // print sed's output sed.stdout.on('data', function(data) { diff --git a/test/parallel/test-child-process-env.js b/test/parallel/test-child-process-env.js index 2ebc653e9a067d..ad41f978e21768 100644 --- a/test/parallel/test-child-process-env.js +++ b/test/parallel/test-child-process-env.js @@ -1,17 +1,17 @@ 'use strict'; -var common = require('../common'); -var assert = require('assert'); +const common = require('../common'); +const assert = require('assert'); -var spawn = require('child_process').spawn; +const spawn = require('child_process').spawn; -var env = { +const env = { 'HELLO': 'WORLD' }; Object.setPrototypeOf(env, { 'FOO': 'BAR' }); -var child; +let child; if (common.isWindows) { child = spawn('cmd.exe', ['/c', 'set'], {env: env}); } else { @@ -19,7 +19,7 @@ if (common.isWindows) { } -var response = ''; +let response = ''; child.stdout.setEncoding('utf8'); diff --git a/test/parallel/test-child-process-exec-cwd.js b/test/parallel/test-child-process-exec-cwd.js index 3b6e428a4aca65..95feb42314fc8d 100644 --- a/test/parallel/test-child-process-exec-cwd.js +++ b/test/parallel/test-child-process-exec-cwd.js @@ -3,7 +3,7 @@ const common = require('../common'); const assert = require('assert'); const exec = require('child_process').exec; -var pwdcommand, dir; +let pwdcommand, dir; if (common.isWindows) { pwdcommand = 'echo %cd%'; diff --git a/test/parallel/test-child-process-exec-stdout-stderr-data-string.js b/test/parallel/test-child-process-exec-stdout-stderr-data-string.js index 8ab834c98f8d79..472d31f16ac920 100644 --- a/test/parallel/test-child-process-exec-stdout-stderr-data-string.js +++ b/test/parallel/test-child-process-exec-stdout-stderr-data-string.js @@ -4,8 +4,8 @@ const common = require('../common'); const assert = require('assert'); const exec = require('child_process').exec; -var stdoutCalls = 0; -var stderrCalls = 0; +let stdoutCalls = 0; +let stderrCalls = 0; const command = common.isWindows ? 'dir' : 'ls'; exec(command).stdout.on('data', (data) => { diff --git a/test/parallel/test-child-process-exit-code.js b/test/parallel/test-child-process-exit-code.js index 3a393f126fbe13..9596a202223993 100644 --- a/test/parallel/test-child-process-exit-code.js +++ b/test/parallel/test-child-process-exit-code.js @@ -1,20 +1,20 @@ 'use strict'; -var common = require('../common'); -var assert = require('assert'); -var spawn = require('child_process').spawn; -var path = require('path'); +const common = require('../common'); +const assert = require('assert'); +const spawn = require('child_process').spawn; +const path = require('path'); -var exitScript = path.join(common.fixturesDir, 'exit.js'); -var exitChild = spawn(process.argv[0], [exitScript, 23]); +const exitScript = path.join(common.fixturesDir, 'exit.js'); +const exitChild = spawn(process.argv[0], [exitScript, 23]); exitChild.on('exit', common.mustCall(function(code, signal) { assert.strictEqual(code, 23); assert.strictEqual(signal, null); })); -var errorScript = path.join(common.fixturesDir, - 'child_process_should_emit_error.js'); -var errorChild = spawn(process.argv[0], [errorScript]); +const errorScript = path.join(common.fixturesDir, + 'child_process_should_emit_error.js'); +const errorChild = spawn(process.argv[0], [errorScript]); errorChild.on('exit', common.mustCall(function(code, signal) { assert.ok(code !== 0); assert.strictEqual(signal, null); diff --git a/test/parallel/test-child-process-fork-close.js b/test/parallel/test-child-process-fork-close.js index d6e9675ba82012..d8b1aa0bf3267c 100644 --- a/test/parallel/test-child-process-fork-close.js +++ b/test/parallel/test-child-process-fork-close.js @@ -3,7 +3,7 @@ const common = require('../common'); const assert = require('assert'); const fork = require('child_process').fork; -var cp = fork(common.fixturesDir + '/child-process-message-and-exit.js'); +const cp = fork(common.fixturesDir + '/child-process-message-and-exit.js'); let gotMessage = false; let gotExit = false; diff --git a/test/parallel/test-child-process-fork-dgram.js b/test/parallel/test-child-process-fork-dgram.js index 8bdf006a743e0d..7b9f0b8e23fbf4 100644 --- a/test/parallel/test-child-process-fork-dgram.js +++ b/test/parallel/test-child-process-fork-dgram.js @@ -37,8 +37,8 @@ if (process.argv[2] === 'child') { const msg = Buffer.from('Some bytes'); - var childGotMessage = false; - var parentGotMessage = false; + let childGotMessage = false; + let parentGotMessage = false; parentServer.once('message', function(msg, rinfo) { parentGotMessage = true; diff --git a/test/parallel/test-child-process-fork-exec-argv.js b/test/parallel/test-child-process-fork-exec-argv.js index 5ccc17fb3fc7c4..97d1e21a2f6d7a 100644 --- a/test/parallel/test-child-process-fork-exec-argv.js +++ b/test/parallel/test-child-process-fork-exec-argv.js @@ -1,9 +1,9 @@ 'use strict'; require('../common'); -var assert = require('assert'); -var child_process = require('child_process'); -var spawn = child_process.spawn; -var fork = child_process.fork; +const assert = require('assert'); +const child_process = require('child_process'); +const spawn = child_process.spawn; +const fork = child_process.fork; if (process.argv[2] === 'fork') { process.stdout.write(JSON.stringify(process.execArgv), function() { @@ -12,11 +12,11 @@ if (process.argv[2] === 'fork') { } else if (process.argv[2] === 'child') { fork(__filename, ['fork']); } else { - var execArgv = ['--stack-size=256']; - var args = [__filename, 'child', 'arg0']; + const execArgv = ['--stack-size=256']; + const args = [__filename, 'child', 'arg0']; - var child = spawn(process.execPath, execArgv.concat(args)); - var out = ''; + const child = spawn(process.execPath, execArgv.concat(args)); + let out = ''; child.stdout.on('data', function(chunk) { out += chunk; diff --git a/test/parallel/test-child-process-fork-exec-path.js b/test/parallel/test-child-process-fork-exec-path.js index e2f7e4b4d20eef..5af0184a21f55d 100644 --- a/test/parallel/test-child-process-fork-exec-path.js +++ b/test/parallel/test-child-process-fork-exec-path.js @@ -1,11 +1,11 @@ 'use strict'; const common = require('../common'); -var assert = require('assert'); -var fs = require('fs'); -var path = require('path'); -var msg = {test: 'this'}; -var nodePath = process.execPath; -var copyPath = path.join(common.tmpDir, 'node-copy.exe'); +const assert = require('assert'); +const fs = require('fs'); +const path = require('path'); +const msg = {test: 'this'}; +const nodePath = process.execPath; +const copyPath = path.join(common.tmpDir, 'node-copy.exe'); if (process.env.FORK) { assert(process.send); @@ -23,9 +23,9 @@ if (process.env.FORK) { fs.chmodSync(copyPath, '0755'); // slow but simple - var envCopy = JSON.parse(JSON.stringify(process.env)); + const envCopy = JSON.parse(JSON.stringify(process.env)); envCopy.FORK = 'true'; - var child = require('child_process').fork(__filename, { + const child = require('child_process').fork(__filename, { execPath: copyPath, env: envCopy }); diff --git a/test/parallel/test-child-process-fork-net.js b/test/parallel/test-child-process-fork-net.js index cbafcb13fbb068..063028e8280582 100644 --- a/test/parallel/test-child-process-fork-net.js +++ b/test/parallel/test-child-process-fork-net.js @@ -19,7 +19,7 @@ ProgressTracker.prototype.check = function() { if (process.argv[2] === 'child') { - var serverScope; + let serverScope; process.on('message', function onServer(msg, server) { if (msg.what !== 'server') return; @@ -58,17 +58,17 @@ if (process.argv[2] === 'child') { process.send({what: 'ready'}); } else { - var child = fork(process.argv[1], ['child']); + const child = fork(process.argv[1], ['child']); child.on('exit', function() { console.log('CHILD: died'); }); // send net.Server to child and test by connecting - var testServer = function(callback) { + const testServer = function(callback) { // destroy server execute callback when done - var progress = new ProgressTracker(2, function() { + const progress = new ProgressTracker(2, function() { server.on('close', function() { console.log('PARENT: server closed'); child.send({what: 'close'}); @@ -77,11 +77,11 @@ if (process.argv[2] === 'child') { }); // we expect 4 connections and close events - var connections = new ProgressTracker(4, progress.done.bind(progress)); - var closed = new ProgressTracker(4, progress.done.bind(progress)); + const connections = new ProgressTracker(4, progress.done.bind(progress)); + const closed = new ProgressTracker(4, progress.done.bind(progress)); // create server and send it to child - var server = net.createServer(); + let server = net.createServer(); server.on('connection', function(socket) { console.log('PARENT: got connection'); socket.destroy(); @@ -94,12 +94,12 @@ if (process.argv[2] === 'child') { server.listen(0); // handle client messages - var messageHandlers = function(msg) { + const messageHandlers = function(msg) { if (msg.what === 'listening') { // make connections - var socket; - for (var i = 0; i < 4; i++) { + let socket; + for (let i = 0; i < 4; i++) { socket = net.connect(server.address().port, function() { console.log('CLIENT: connected'); }); @@ -122,11 +122,11 @@ if (process.argv[2] === 'child') { }; // send net.Socket to child - var testSocket = function(callback) { + const testSocket = function(callback) { // create a new server and connect to it, // but the socket will be handled by the child - var server = net.createServer(); + const server = net.createServer(); server.on('connection', function(socket) { socket.on('close', function() { console.log('CLIENT: socket closed'); @@ -145,8 +145,8 @@ if (process.argv[2] === 'child') { // will have to do. server.listen(0, function() { console.error('testSocket, listening'); - var connect = net.connect(server.address().port); - var store = ''; + const connect = net.connect(server.address().port); + let store = ''; connect.on('data', function(chunk) { store += chunk; console.log('CLIENT: got data'); @@ -160,8 +160,8 @@ if (process.argv[2] === 'child') { }; // create server and send it to child - var serverSuccess = false; - var socketSuccess = false; + let serverSuccess = false; + let socketSuccess = false; child.on('message', function onReady(msg) { if (msg.what !== 'ready') return; child.removeListener('message', onReady); diff --git a/test/parallel/test-child-process-fork-net2.js b/test/parallel/test-child-process-fork-net2.js index be1ee5d3a4145a..760645932069bb 100644 --- a/test/parallel/test-child-process-fork-net2.js +++ b/test/parallel/test-child-process-fork-net2.js @@ -1,13 +1,13 @@ 'use strict'; const common = require('../common'); -var assert = require('assert'); -var fork = require('child_process').fork; -var net = require('net'); -var count = 12; +const assert = require('assert'); +const fork = require('child_process').fork; +const net = require('net'); +const count = 12; if (process.argv[2] === 'child') { - var needEnd = []; - var id = process.argv[3]; + const needEnd = []; + const id = process.argv[3]; process.on('message', function(m, socket) { if (!socket) return; @@ -60,11 +60,11 @@ if (process.argv[2] === 'child') { } else { - var child1 = fork(process.argv[1], ['child', '1']); - var child2 = fork(process.argv[1], ['child', '2']); - var child3 = fork(process.argv[1], ['child', '3']); + const child1 = fork(process.argv[1], ['child', '1']); + const child2 = fork(process.argv[1], ['child', '2']); + const child3 = fork(process.argv[1], ['child', '3']); - var server = net.createServer(); + const server = net.createServer(); let connected = 0; let closed = 0; @@ -94,10 +94,10 @@ if (process.argv[2] === 'child') { } }); - var disconnected = 0; + let disconnected = 0; server.on('listening', function() { - var j = count, client; + let j = count, client; while (j--) { client = net.connect(this.address().port, '127.0.0.1'); client.on('error', function() { @@ -112,7 +112,7 @@ if (process.argv[2] === 'child') { } }); - var closeEmitted = false; + let closeEmitted = false; server.on('close', common.mustCall(function() { closeEmitted = true; @@ -123,7 +123,7 @@ if (process.argv[2] === 'child') { server.listen(0, '127.0.0.1'); - var closeServer = function() { + let closeServer = function() { server.close(); setTimeout(function() { diff --git a/test/parallel/test-child-process-fork-ref.js b/test/parallel/test-child-process-fork-ref.js index 50a944e71ba83c..1f8816c0cfaf1c 100644 --- a/test/parallel/test-child-process-fork-ref.js +++ b/test/parallel/test-child-process-fork-ref.js @@ -1,7 +1,7 @@ 'use strict'; require('../common'); -var assert = require('assert'); -var fork = require('child_process').fork; +const assert = require('assert'); +const fork = require('child_process').fork; if (process.argv[2] === 'child') { process.send('1'); @@ -16,9 +16,10 @@ if (process.argv[2] === 'child') { }); } else { - var child = fork(__filename, ['child'], {silent: true}); + const child = fork(__filename, ['child'], {silent: true}); - var ipc = [], stdout = ''; + const ipc = []; + let stdout = ''; child.on('message', function(msg) { ipc.push(msg); diff --git a/test/parallel/test-child-process-fork-ref2.js b/test/parallel/test-child-process-fork-ref2.js index 42c43ed8882b78..9f59aa344aa2c9 100644 --- a/test/parallel/test-child-process-fork-ref2.js +++ b/test/parallel/test-child-process-fork-ref2.js @@ -1,6 +1,6 @@ 'use strict'; require('../common'); -var fork = require('child_process').fork; +const fork = require('child_process').fork; if (process.argv[2] === 'child') { console.log('child -> call disconnect'); @@ -12,7 +12,7 @@ if (process.argv[2] === 'child') { }, 400); } else { - var child = fork(__filename, ['child']); + const child = fork(__filename, ['child']); child.on('disconnect', function() { console.log('parent -> disconnect'); diff --git a/test/parallel/test-child-process-fork-regr-gh-2847.js b/test/parallel/test-child-process-fork-regr-gh-2847.js index 7b4c262fbdcf61..fe95e8dbb5b4ac 100644 --- a/test/parallel/test-child-process-fork-regr-gh-2847.js +++ b/test/parallel/test-child-process-fork-regr-gh-2847.js @@ -14,7 +14,7 @@ if (!cluster.isMaster) { return; } -var server = net.createServer(function(s) { +const server = net.createServer(function(s) { if (common.isWindows) { s.on('error', function(err) { // Prevent possible ECONNRESET errors from popping up @@ -26,10 +26,10 @@ var server = net.createServer(function(s) { s.destroy(); }, 100); }).listen(0, function() { - var worker = cluster.fork(); + const worker = cluster.fork(); function send(callback) { - var s = net.connect(server.address().port, function() { + const s = net.connect(server.address().port, function() { worker.send({}, s, callback); }); diff --git a/test/parallel/test-child-process-fork.js b/test/parallel/test-child-process-fork.js index 5ae231ef0357ac..36864cbd663ce0 100644 --- a/test/parallel/test-child-process-fork.js +++ b/test/parallel/test-child-process-fork.js @@ -1,10 +1,10 @@ 'use strict'; const common = require('../common'); -var assert = require('assert'); -var fork = require('child_process').fork; -var args = ['foo', 'bar']; +const assert = require('assert'); +const fork = require('child_process').fork; +const args = ['foo', 'bar']; -var n = fork(common.fixturesDir + '/child-process-spawn-node.js', args); +const n = fork(common.fixturesDir + '/child-process-spawn-node.js', args); assert.deepStrictEqual(args, ['foo', 'bar']); n.on('message', function(m) { diff --git a/test/parallel/test-child-process-fork3.js b/test/parallel/test-child-process-fork3.js index fe0e68b6a6436e..5588c41422e21b 100644 --- a/test/parallel/test-child-process-fork3.js +++ b/test/parallel/test-child-process-fork3.js @@ -1,5 +1,5 @@ 'use strict'; -var common = require('../common'); -var child_process = require('child_process'); +const common = require('../common'); +const child_process = require('child_process'); child_process.fork(common.fixturesDir + '/empty.js'); // should not hang diff --git a/test/parallel/test-child-process-internal.js b/test/parallel/test-child-process-internal.js index f3e452ef87ea76..d795b69d7ee0e5 100644 --- a/test/parallel/test-child-process-internal.js +++ b/test/parallel/test-child-process-internal.js @@ -1,11 +1,11 @@ 'use strict'; const common = require('../common'); -var assert = require('assert'); +const assert = require('assert'); //messages -var PREFIX = 'NODE_'; -var normal = {cmd: 'foo' + PREFIX}; -var internal = {cmd: PREFIX + 'bar'}; +const PREFIX = 'NODE_'; +const normal = {cmd: 'foo' + PREFIX}; +const internal = {cmd: PREFIX + 'bar'}; if (process.argv[2] === 'child') { //send non-internal message containing PREFIX at a non prefix position @@ -18,8 +18,8 @@ if (process.argv[2] === 'child') { } else { - var fork = require('child_process').fork; - var child = fork(process.argv[1], ['child']); + const fork = require('child_process').fork; + const child = fork(process.argv[1], ['child']); child.once('message', common.mustCall(function(data) { assert.deepStrictEqual(data, normal); diff --git a/test/parallel/test-child-process-send-returns-boolean.js b/test/parallel/test-child-process-send-returns-boolean.js index 941a2da645f958..460c2b0022fc6b 100644 --- a/test/parallel/test-child-process-send-returns-boolean.js +++ b/test/parallel/test-child-process-send-returns-boolean.js @@ -15,7 +15,7 @@ assert.strictEqual(rv, true); const spawnOptions = { stdio: ['pipe', 'pipe', 'pipe', 'ipc'] }; const s = spawn(process.execPath, [emptyFile], spawnOptions); -var handle = null; +let handle = null; s.on('exit', function() { handle.close(); }); diff --git a/test/parallel/test-child-process-set-blocking.js b/test/parallel/test-child-process-set-blocking.js index fb0b11f433130a..54037aea69feb2 100644 --- a/test/parallel/test-child-process-set-blocking.js +++ b/test/parallel/test-child-process-set-blocking.js @@ -1,11 +1,11 @@ 'use strict'; const common = require('../common'); -var assert = require('assert'); -var ch = require('child_process'); +const assert = require('assert'); +const ch = require('child_process'); -var SIZE = 100000; +const SIZE = 100000; -var cp = ch.spawn('python', ['-c', 'print ' + SIZE + ' * "C"'], { +const cp = ch.spawn('python', ['-c', 'print ' + SIZE + ' * "C"'], { stdio: 'inherit' }); diff --git a/test/parallel/test-child-process-silent.js b/test/parallel/test-child-process-silent.js index ce5e28cc320af4..562b34ad823e17 100644 --- a/test/parallel/test-child-process-silent.js +++ b/test/parallel/test-child-process-silent.js @@ -1,7 +1,7 @@ 'use strict'; require('../common'); -var assert = require('assert'); -var childProcess = require('child_process'); +const assert = require('assert'); +const childProcess = require('child_process'); // Child pipe test if (process.argv[2] === 'pipe') { @@ -32,15 +32,15 @@ if (process.argv[2] === 'pipe') { // testcase | start parent && child IPC test // testing: is stderr and stdout piped to parent - var args = [process.argv[1], 'parent']; - var parent = childProcess.spawn(process.execPath, args); + const args = [process.argv[1], 'parent']; + const parent = childProcess.spawn(process.execPath, args); //got any stderr or std data - var stdoutData = false; + let stdoutData = false; parent.stdout.on('data', function() { stdoutData = true; }); - var stderrData = false; + let stderrData = false; parent.stdout.on('data', function() { stderrData = true; }); @@ -52,8 +52,8 @@ if (process.argv[2] === 'pipe') { child.stderr.pipe(process.stderr, {end: false}); child.stdout.pipe(process.stdout, {end: false}); - var childSending = false; - var childReciveing = false; + let childSending = false; + let childReciveing = false; child.on('message', function(message) { if (childSending === false) { childSending = (message === 'message from child'); diff --git a/test/parallel/test-child-process-spawn-typeerror.js b/test/parallel/test-child-process-spawn-typeerror.js index b6eac63c4eb048..3e3e38153de35c 100644 --- a/test/parallel/test-child-process-spawn-typeerror.js +++ b/test/parallel/test-child-process-spawn-typeerror.js @@ -12,7 +12,7 @@ const invalidOptionsMsg = /"options" argument must be an object/; const empty = common.fixturesDir + '/empty.js'; assert.throws(function() { - var child = spawn(invalidcmd, 'this is not an array'); + const child = spawn(invalidcmd, 'this is not an array'); child.on('error', common.fail); }, TypeError); diff --git a/test/parallel/test-child-process-spawnsync-env.js b/test/parallel/test-child-process-spawnsync-env.js index 4455b867e30108..6f5ea3dc83d107 100644 --- a/test/parallel/test-child-process-spawnsync-env.js +++ b/test/parallel/test-child-process-spawnsync-env.js @@ -1,13 +1,13 @@ 'use strict'; require('../common'); -var assert = require('assert'); -var cp = require('child_process'); +const assert = require('assert'); +const cp = require('child_process'); if (process.argv[2] === 'child') { console.log(process.env.foo); } else { - var expected = 'bar'; - var child = cp.spawnSync(process.execPath, [__filename, 'child'], { + const expected = 'bar'; + const child = cp.spawnSync(process.execPath, [__filename, 'child'], { env: Object.assign(process.env, { foo: expected }) }); diff --git a/test/parallel/test-child-process-spawnsync-input.js b/test/parallel/test-child-process-spawnsync-input.js index fdd29aa7d0cc50..1bda3d5dcf9da2 100644 --- a/test/parallel/test-child-process-spawnsync-input.js +++ b/test/parallel/test-child-process-spawnsync-input.js @@ -17,7 +17,7 @@ const args = [ `console.log("${msgOut}"); console.error("${msgErr}");` ]; -var ret; +let ret; function checkSpawnSyncRet(ret) { @@ -51,7 +51,7 @@ if (process.argv.indexOf('spawnchild') !== -1) { verifyBufOutput(spawnSync(process.execPath, [__filename, 'spawnchild', 1])); verifyBufOutput(spawnSync(process.execPath, [__filename, 'spawnchild', 2])); -var options = { +let options = { input: 1234 }; diff --git a/test/parallel/test-child-process-spawnsync-timeout.js b/test/parallel/test-child-process-spawnsync-timeout.js index c804f7502755bb..38f22deef26ae7 100644 --- a/test/parallel/test-child-process-spawnsync-timeout.js +++ b/test/parallel/test-child-process-spawnsync-timeout.js @@ -2,7 +2,7 @@ const common = require('../common'); const assert = require('assert'); -var spawnSync = require('child_process').spawnSync; +const spawnSync = require('child_process').spawnSync; const TIMER = 200; const SLEEP = common.platformTimeout(5000); @@ -15,8 +15,8 @@ switch (process.argv[2]) { }, SLEEP); break; default: - var start = Date.now(); - var ret = spawnSync(process.execPath, [__filename, 'child'], + const start = Date.now(); + const ret = spawnSync(process.execPath, [__filename, 'child'], {timeout: TIMER}); assert.strictEqual(ret.error.errno, 'ETIMEDOUT'); const end = Date.now() - start; diff --git a/test/parallel/test-child-process-stdin-ipc.js b/test/parallel/test-child-process-stdin-ipc.js index 2ce7c66c2053e0..2623e2deeeee8a 100644 --- a/test/parallel/test-child-process-stdin-ipc.js +++ b/test/parallel/test-child-process-stdin-ipc.js @@ -1,8 +1,8 @@ 'use strict'; const common = require('../common'); -var assert = require('assert'); +const assert = require('assert'); -var spawn = require('child_process').spawn; +const spawn = require('child_process').spawn; if (process.argv[2] === 'child') { // Just reference stdin, it should start it @@ -10,7 +10,7 @@ if (process.argv[2] === 'child') { return; } -var proc = spawn(process.execPath, [__filename, 'child'], { +const proc = spawn(process.execPath, [__filename, 'child'], { stdio: ['ipc', 'inherit', 'inherit'] }); diff --git a/test/parallel/test-child-process-stdio-big-write-end.js b/test/parallel/test-child-process-stdio-big-write-end.js index 4c9f4159d0d8bc..24991492f63d32 100644 --- a/test/parallel/test-child-process-stdio-big-write-end.js +++ b/test/parallel/test-child-process-stdio-big-write-end.js @@ -28,8 +28,9 @@ function parent() { }); // Write until the buffer fills up. + let buf; do { - var buf = Buffer.alloc(BUFSIZE, '.'); + buf = Buffer.alloc(BUFSIZE, '.'); sent += BUFSIZE; } while (child.stdin.write(buf)); diff --git a/test/parallel/test-child-process-stdio-inherit.js b/test/parallel/test-child-process-stdio-inherit.js index dc3bb3e9aa9391..d2b64aeb30dd31 100644 --- a/test/parallel/test-child-process-stdio-inherit.js +++ b/test/parallel/test-child-process-stdio-inherit.js @@ -1,7 +1,7 @@ 'use strict'; -var common = require('../common'); -var assert = require('assert'); -var spawn = require('child_process').spawn; +const common = require('../common'); +const assert = require('assert'); +const spawn = require('child_process').spawn; if (process.argv[2] === 'parent') parent(); @@ -9,10 +9,10 @@ else grandparent(); function grandparent() { - var child = spawn(process.execPath, [__filename, 'parent']); + const child = spawn(process.execPath, [__filename, 'parent']); child.stderr.pipe(process.stderr); - var output = ''; - var input = 'asdfasdf'; + let output = ''; + const input = 'asdfasdf'; child.stdout.on('data', function(chunk) { output += chunk; diff --git a/test/parallel/test-cli-eval.js b/test/parallel/test-cli-eval.js index 8db7ad30872223..9a1714cb6ea7c2 100644 --- a/test/parallel/test-cli-eval.js +++ b/test/parallel/test-cli-eval.js @@ -14,7 +14,7 @@ const nodejs = '"' + process.execPath + '"'; // replace \ by / because windows uses backslashes in paths, but they're still // interpreted as the escape character when put between quotes. -var filename = __filename.replace(/\\/g, '/'); +const filename = __filename.replace(/\\/g, '/'); // assert that nothing is written to stdout child.exec(nodejs + ' --eval 42', @@ -32,7 +32,7 @@ child.exec(nodejs + ' --eval "console.error(42)"', // assert that the expected output is written to stdout ['--print', '-p -e', '-pe', '-p'].forEach(function(s) { - var cmd = nodejs + ' ' + s + ' '; + const cmd = nodejs + ' ' + s + ' '; child.exec(cmd + '42', function(err, stdout, stderr) { diff --git a/test/parallel/test-cli-syntax.js b/test/parallel/test-cli-syntax.js index 839e50d7d94b40..d7781eddffbb42 100644 --- a/test/parallel/test-cli-syntax.js +++ b/test/parallel/test-cli-syntax.js @@ -5,10 +5,10 @@ const assert = require('assert'); const spawnSync = require('child_process').spawnSync; const path = require('path'); -var node = process.execPath; +const node = process.execPath; // test both sets of arguments that check syntax -var syntaxArgs = [ +const syntaxArgs = [ ['-c'], ['--check'] ]; @@ -25,8 +25,8 @@ var syntaxArgs = [ // loop each possible option, `-c` or `--check` syntaxArgs.forEach(function(args) { - var _args = args.concat(file); - var c = spawnSync(node, _args, {encoding: 'utf8'}); + const _args = args.concat(file); + const c = spawnSync(node, _args, {encoding: 'utf8'}); // no output should be produced assert.strictEqual(c.stdout, '', 'stdout produced'); @@ -46,14 +46,14 @@ var syntaxArgs = [ // loop each possible option, `-c` or `--check` syntaxArgs.forEach(function(args) { - var _args = args.concat(file); - var c = spawnSync(node, _args, {encoding: 'utf8'}); + const _args = args.concat(file); + const c = spawnSync(node, _args, {encoding: 'utf8'}); // no stdout should be produced assert.strictEqual(c.stdout, '', 'stdout produced'); // stderr should have a syntax error message - var match = c.stderr.match(/^SyntaxError: Unexpected identifier$/m); + const match = c.stderr.match(/^SyntaxError: Unexpected identifier$/m); assert(match, 'stderr incorrect'); assert.strictEqual(c.status, 1, 'code == ' + c.status); @@ -69,14 +69,14 @@ var syntaxArgs = [ // loop each possible option, `-c` or `--check` syntaxArgs.forEach(function(args) { - var _args = args.concat(file); - var c = spawnSync(node, _args, {encoding: 'utf8'}); + const _args = args.concat(file); + const c = spawnSync(node, _args, {encoding: 'utf8'}); // no stdout should be produced assert.strictEqual(c.stdout, '', 'stdout produced'); // stderr should have a module not found error message - var match = c.stderr.match(/^Error: Cannot find module/m); + const match = c.stderr.match(/^Error: Cannot find module/m); assert(match, 'stderr incorrect'); assert.strictEqual(c.status, 1, 'code == ' + c.status); diff --git a/test/parallel/test-cluster-basic.js b/test/parallel/test-cluster-basic.js index 0ffdcf180bd8a8..89413c154ef937 100644 --- a/test/parallel/test-cluster-basic.js +++ b/test/parallel/test-cluster-basic.js @@ -56,7 +56,7 @@ if (cluster.isWorker) { } }; - var worker; + let worker; const stateNames = Object.keys(checks.worker.states); //Check events, states, and emit arguments @@ -72,7 +72,7 @@ if (cluster.isWorker) { checks.cluster.equal[name] = worker === arguments[0]; //Check state - var state = stateNames[index]; + const state = stateNames[index]; checks.worker.states[state] = (state === worker.state); })); }); diff --git a/test/parallel/test-cluster-bind-privileged-port.js b/test/parallel/test-cluster-bind-privileged-port.js index 228e1f0f1eaab0..3e062697fd2fea 100644 --- a/test/parallel/test-cluster-bind-privileged-port.js +++ b/test/parallel/test-cluster-bind-privileged-port.js @@ -19,7 +19,7 @@ if (cluster.isMaster) { assert.strictEqual(exitCode, 0); })); } else { - var s = net.createServer(common.fail); + const s = net.createServer(common.fail); s.listen(42, common.fail.bind(null, 'listen should have failed')); s.on('error', common.mustCall((err) => { assert.strictEqual(err.code, 'EACCES'); diff --git a/test/parallel/test-cluster-dgram-1.js b/test/parallel/test-cluster-dgram-1.js index 3b27fa8e20cb6c..25391997755f6b 100644 --- a/test/parallel/test-cluster-dgram-1.js +++ b/test/parallel/test-cluster-dgram-1.js @@ -21,10 +21,10 @@ else function master() { - var listening = 0; + let listening = 0; // Fork 4 workers. - for (var i = 0; i < NUM_WORKERS; i++) + for (let i = 0; i < NUM_WORKERS; i++) cluster.fork(); // Wait until all workers are listening. @@ -35,7 +35,7 @@ function master() { // Start sending messages. const buf = Buffer.from('hello world'); const socket = dgram.createSocket('udp4'); - var sent = 0; + let sent = 0; doSend(); function doSend() { @@ -60,7 +60,7 @@ function master() { } function setupWorker(worker) { - var received = 0; + let received = 0; worker.on('message', common.mustCall((msg) => { received = msg.received; @@ -75,10 +75,10 @@ function master() { function worker() { - var received = 0; + let received = 0; // Create udp socket and start listening. - var socket = dgram.createSocket('udp4'); + const socket = dgram.createSocket('udp4'); socket.on('message', common.mustCall((data, info) => { received++; diff --git a/test/parallel/test-cluster-dgram-2.js b/test/parallel/test-cluster-dgram-2.js index 863e0fa358c73e..37aea29e1a4263 100644 --- a/test/parallel/test-cluster-dgram-2.js +++ b/test/parallel/test-cluster-dgram-2.js @@ -20,10 +20,10 @@ else function master() { - var received = 0; + let received = 0; // Start listening on a socket. - var socket = dgram.createSocket('udp4'); + const socket = dgram.createSocket('udp4'); socket.bind(common.PORT); // Disconnect workers when the expected number of messages have been @@ -42,7 +42,7 @@ function master() { }, NUM_WORKERS * PACKETS_PER_WORKER)); // Fork workers. - for (var i = 0; i < NUM_WORKERS; i++) + for (let i = 0; i < NUM_WORKERS; i++) cluster.fork(); } diff --git a/test/parallel/test-cluster-dgram-reuse.js b/test/parallel/test-cluster-dgram-reuse.js index 27fc1be985d4b7..aed565a3806e97 100644 --- a/test/parallel/test-cluster-dgram-reuse.js +++ b/test/parallel/test-cluster-dgram-reuse.js @@ -25,16 +25,16 @@ function next() { // Work around health check issue process.nextTick(() => { - for (var i = 0; i < sockets.length; i++) + for (let i = 0; i < sockets.length; i++) sockets[i].close(close); }); } -var waiting = 2; +let waiting = 2; function close() { if (--waiting === 0) cluster.worker.disconnect(); } -for (var i = 0; i < 2; i++) +for (let i = 0; i < 2; i++) dgram.createSocket({ type: 'udp4', reuseAddr: true }).bind(common.PORT, next); diff --git a/test/parallel/test-cluster-disconnect-race.js b/test/parallel/test-cluster-disconnect-race.js index e89b9e134fa83f..09966cbab84496 100644 --- a/test/parallel/test-cluster-disconnect-race.js +++ b/test/parallel/test-cluster-disconnect-race.js @@ -16,9 +16,9 @@ if (common.isWindows) { cluster.schedulingPolicy = cluster.SCHED_NONE; if (cluster.isMaster) { - var worker1, worker2; + let worker2; - worker1 = cluster.fork(); + const worker1 = cluster.fork(); worker1.on('message', common.mustCall(function() { worker2 = cluster.fork(); worker1.disconnect(); @@ -32,7 +32,7 @@ if (cluster.isMaster) { return; } -var server = net.createServer(); +const server = net.createServer(); server.listen(common.PORT, function() { process.send('listening'); diff --git a/test/parallel/test-cluster-disconnect-suicide-race.js b/test/parallel/test-cluster-disconnect-suicide-race.js index 6f23b23fd2d4ff..15d07002252ee9 100644 --- a/test/parallel/test-cluster-disconnect-suicide-race.js +++ b/test/parallel/test-cluster-disconnect-suicide-race.js @@ -14,7 +14,7 @@ if (cluster.isMaster) { return cluster.fork(); } -var eventFired = false; +let eventFired = false; cluster.worker.disconnect(); diff --git a/test/parallel/test-cluster-disconnect-with-no-workers.js b/test/parallel/test-cluster-disconnect-with-no-workers.js index 4c2425d82d656b..15c5898a7d6f69 100644 --- a/test/parallel/test-cluster-disconnect-with-no-workers.js +++ b/test/parallel/test-cluster-disconnect-with-no-workers.js @@ -1,9 +1,9 @@ 'use strict'; require('../common'); -var assert = require('assert'); -var cluster = require('cluster'); +const assert = require('assert'); +const cluster = require('cluster'); -var disconnected; +let disconnected; process.on('exit', function() { assert(disconnected); diff --git a/test/parallel/test-cluster-disconnect.js b/test/parallel/test-cluster-disconnect.js index 4609724130f2ec..0fc1611e2d9577 100644 --- a/test/parallel/test-cluster-disconnect.js +++ b/test/parallel/test-cluster-disconnect.js @@ -14,13 +14,13 @@ if (cluster.isWorker) { }).listen(common.PORT + 1, '127.0.0.1'); } else if (cluster.isMaster) { - var servers = 2; + const servers = 2; // test a single TCP server const testConnection = function(port, cb) { - var socket = net.connect(port, '127.0.0.1', () => { + const socket = net.connect(port, '127.0.0.1', () => { // buffer result - var result = ''; + let result = ''; socket.on('data', common.mustCall((chunk) => { result += chunk; })); // check result @@ -32,9 +32,9 @@ if (cluster.isWorker) { // test both servers created in the cluster const testCluster = function(cb) { - var done = 0; + let done = 0; - for (var i = 0, l = servers; i < l; i++) { + for (let i = 0, l = servers; i < l; i++) { testConnection(common.PORT + i, (success) => { assert.ok(success); done += 1; @@ -47,10 +47,10 @@ if (cluster.isWorker) { // start two workers and execute callback when both is listening const startCluster = function(cb) { - var workers = 8; - var online = 0; + const workers = 8; + let online = 0; - for (var i = 0, l = workers; i < l; i++) { + for (let i = 0, l = workers; i < l; i++) { cluster.fork().on('listening', common.mustCall(() => { online += 1; if (online === workers * servers) { diff --git a/test/parallel/test-cluster-eaccess.js b/test/parallel/test-cluster-eaccess.js index 2de4af8b1a108b..75b60248a22381 100644 --- a/test/parallel/test-cluster-eaccess.js +++ b/test/parallel/test-cluster-eaccess.js @@ -37,7 +37,7 @@ if (cluster.isMaster) { } else { common.refreshTmpDir(); - var cp = fork(common.fixturesDir + '/listen-on-socket-and-exit.js', + const cp = fork(common.fixturesDir + '/listen-on-socket-and-exit.js', { stdio: 'inherit' }); // message from the child indicates it's ready and listening diff --git a/test/parallel/test-cluster-eaddrinuse.js b/test/parallel/test-cluster-eaddrinuse.js index 88b6de2dde4230..a0936ef4b9d471 100644 --- a/test/parallel/test-cluster-eaddrinuse.js +++ b/test/parallel/test-cluster-eaddrinuse.js @@ -3,17 +3,17 @@ // leave the master process in a confused state. Releasing the port and // trying again should Just Work[TM]. -var common = require('../common'); -var assert = require('assert'); -var fork = require('child_process').fork; -var net = require('net'); +const common = require('../common'); +const assert = require('assert'); +const fork = require('child_process').fork; +const net = require('net'); -var id = '' + process.argv[2]; +const id = '' + process.argv[2]; if (id === 'undefined') { const server = net.createServer(common.fail); server.listen(common.PORT, function() { - var worker = fork(__filename, ['worker']); + const worker = fork(__filename, ['worker']); worker.on('message', function(msg) { if (msg !== 'stop-listening') return; server.close(function() { diff --git a/test/parallel/test-cluster-fork-env.js b/test/parallel/test-cluster-fork-env.js index 17b7af3d061926..55ea684f3b4ce3 100644 --- a/test/parallel/test-cluster-fork-env.js +++ b/test/parallel/test-cluster-fork-env.js @@ -1,7 +1,7 @@ 'use strict'; require('../common'); -var assert = require('assert'); -var cluster = require('cluster'); +const assert = require('assert'); +const cluster = require('cluster'); if (cluster.isWorker) { const result = cluster.worker.send({ @@ -12,7 +12,7 @@ if (cluster.isWorker) { assert.strictEqual(result, true); } else if (cluster.isMaster) { - var checks = { + const checks = { using: false, overwrite: false }; @@ -22,7 +22,7 @@ if (cluster.isWorker) { process.env['cluster_test_overwrite'] = 'old'; // Fork worker - var worker = cluster.fork({ + const worker = cluster.fork({ 'cluster_test_prop': 'custom', 'cluster_test_overwrite': 'new' }); diff --git a/test/parallel/test-cluster-listening-port.js b/test/parallel/test-cluster-listening-port.js index b0fbf9499041d2..ce86205c1e792a 100644 --- a/test/parallel/test-cluster-listening-port.js +++ b/test/parallel/test-cluster-listening-port.js @@ -1,8 +1,8 @@ 'use strict'; -var common = require('../common'); -var assert = require('assert'); -var cluster = require('cluster'); -var net = require('net'); +const common = require('../common'); +const assert = require('assert'); +const cluster = require('cluster'); +const net = require('net'); if (cluster.isMaster) { cluster.fork(); diff --git a/test/parallel/test-cluster-master-error.js b/test/parallel/test-cluster-master-error.js index 6f9c78a7ba601f..11ed09c64ed04e 100644 --- a/test/parallel/test-cluster-master-error.js +++ b/test/parallel/test-cluster-master-error.js @@ -15,7 +15,7 @@ if (cluster.isWorker) { } else if (process.argv[2] === 'cluster') { // Send PID to testcase process - var forkNum = 0; + let forkNum = 0; cluster.on('fork', common.mustCall(function forkEvent(worker) { // Send PID @@ -31,7 +31,7 @@ if (cluster.isWorker) { })); // Throw accidental error when all workers are listening - var listeningNum = 0; + let listeningNum = 0; cluster.on('listening', common.mustCall(function listeningEvent() { // When all workers are listening @@ -56,8 +56,8 @@ if (cluster.isWorker) { const fork = require('child_process').fork; - var masterExited = false; - var workersExited = false; + let masterExited = false; + let workersExited = false; // List all workers const workers = []; @@ -82,7 +82,7 @@ if (cluster.isWorker) { const pollWorkers = function() { // When master is dead all workers should be dead too - var alive = false; + let alive = false; workers.forEach((pid) => alive = common.isAlive(pid)); if (alive) { setTimeout(pollWorkers, 50); diff --git a/test/parallel/test-cluster-master-kill.js b/test/parallel/test-cluster-master-kill.js index 44eedec47b58e5..094e5ad256de7d 100644 --- a/test/parallel/test-cluster-master-kill.js +++ b/test/parallel/test-cluster-master-kill.js @@ -34,13 +34,13 @@ if (cluster.isWorker) { const master = fork(process.argv[1], ['cluster']); // get pid info - var pid = null; + let pid = null; master.once('message', (data) => { pid = data.pid; }); // When master is dead - var alive = true; + let alive = true; master.on('exit', common.mustCall((code) => { // make sure that the master died on purpose diff --git a/test/parallel/test-cluster-message.js b/test/parallel/test-cluster-message.js index 0587eecb4dd4b5..5b537bbe73a755 100644 --- a/test/parallel/test-cluster-message.js +++ b/test/parallel/test-cluster-message.js @@ -1,8 +1,8 @@ 'use strict'; -var common = require('../common'); -var assert = require('assert'); -var cluster = require('cluster'); -var net = require('net'); +const common = require('../common'); +const assert = require('assert'); +const cluster = require('cluster'); +const net = require('net'); function forEach(obj, fn) { Object.keys(obj).forEach(function(name, index) { @@ -13,8 +13,8 @@ function forEach(obj, fn) { if (cluster.isWorker) { // Create a tcp server. This will be used as cluster-shared-server and as an // alternative IPC channel. - var server = net.Server(); - var socket, message; + const server = net.Server(); + let socket, message; function maybeReply() { if (!socket || !message) return; @@ -42,7 +42,7 @@ if (cluster.isWorker) { server.listen(common.PORT, '127.0.0.1'); } else if (cluster.isMaster) { - var checks = { + const checks = { global: { 'receive': false, 'correct': false @@ -58,13 +58,13 @@ if (cluster.isWorker) { }; - var client; - var check = function(type, result) { + let client; + const check = function(type, result) { checks[type].receive = true; checks[type].correct = result; console.error('check', checks); - var missing = false; + let missing = false; forEach(checks, function(type) { if (type.receive === false) missing = true; }); @@ -76,7 +76,7 @@ if (cluster.isWorker) { }; // Spawn worker - var worker = cluster.fork(); + const worker = cluster.fork(); // When a IPC message is received from the worker worker.on('message', function(message) { diff --git a/test/parallel/test-cluster-rr-domain-listen.js b/test/parallel/test-cluster-rr-domain-listen.js index 1328483abb72df..ee507cd47b2a23 100644 --- a/test/parallel/test-cluster-rr-domain-listen.js +++ b/test/parallel/test-cluster-rr-domain-listen.js @@ -1,20 +1,20 @@ 'use strict'; -var common = require('../common'); -var cluster = require('cluster'); -var domain = require('domain'); +const common = require('../common'); +const cluster = require('cluster'); +const domain = require('domain'); // RR is the default for v0.11.9+ so the following line is redundant: // cluster.schedulingPolicy = cluster.SCHED_RR; if (cluster.isWorker) { - var d = domain.create(); + const d = domain.create(); d.run(function() { }); - var http = require('http'); + const http = require('http'); http.Server(function() { }).listen(common.PORT, '127.0.0.1'); } else if (cluster.isMaster) { - var worker; + let worker; //Kill worker when listening cluster.on('listening', function() { diff --git a/test/parallel/test-cluster-send-deadlock.js b/test/parallel/test-cluster-send-deadlock.js index fa3e1138248221..d9eac63a92f84c 100644 --- a/test/parallel/test-cluster-send-deadlock.js +++ b/test/parallel/test-cluster-send-deadlock.js @@ -2,20 +2,20 @@ // Testing mutual send of handles: from master to worker, and from worker to // master. -var common = require('../common'); -var assert = require('assert'); -var cluster = require('cluster'); -var net = require('net'); +const common = require('../common'); +const assert = require('assert'); +const cluster = require('cluster'); +const net = require('net'); if (cluster.isMaster) { - var worker = cluster.fork(); + const worker = cluster.fork(); worker.on('exit', function(code, signal) { assert.strictEqual(code, 0, 'Worker exited with an error code'); assert(!signal, 'Worker exited by a signal'); server.close(); }); - var server = net.createServer(function(socket) { + let server = net.createServer(function(socket) { worker.send('handle', socket); }); @@ -25,9 +25,9 @@ if (cluster.isMaster) { } else { process.on('message', function(msg, handle) { if (msg === 'listen') { - var client1 = net.connect({ host: 'localhost', port: common.PORT }); - var client2 = net.connect({ host: 'localhost', port: common.PORT }); - var waiting = 2; + const client1 = net.connect({ host: 'localhost', port: common.PORT }); + const client2 = net.connect({ host: 'localhost', port: common.PORT }); + let waiting = 2; client1.on('close', onclose); client2.on('close', onclose); function onclose() { diff --git a/test/parallel/test-cluster-setup-master-argv.js b/test/parallel/test-cluster-setup-master-argv.js index 32c5a91b3caab4..72211918eff0cb 100644 --- a/test/parallel/test-cluster-setup-master-argv.js +++ b/test/parallel/test-cluster-setup-master-argv.js @@ -6,8 +6,8 @@ const cluster = require('cluster'); setTimeout(common.fail.bind(assert, 'setup not emitted'), 1000).unref(); cluster.on('setup', common.mustCall(function() { - var clusterArgs = cluster.settings.args; - var realArgs = process.argv; + const clusterArgs = cluster.settings.args; + const realArgs = process.argv; assert.strictEqual(clusterArgs[clusterArgs.length - 1], realArgs[realArgs.length - 1]); })); diff --git a/test/parallel/test-cluster-setup-master-cumulative.js b/test/parallel/test-cluster-setup-master-cumulative.js index 6a55df29d4411f..977c89a56aa573 100644 --- a/test/parallel/test-cluster-setup-master-cumulative.js +++ b/test/parallel/test-cluster-setup-master-cumulative.js @@ -1,7 +1,7 @@ 'use strict'; require('../common'); -var assert = require('assert'); -var cluster = require('cluster'); +const assert = require('assert'); +const cluster = require('cluster'); assert(cluster.isMaster); diff --git a/test/parallel/test-cluster-setup-master-emit.js b/test/parallel/test-cluster-setup-master-emit.js index aad1cea75eda97..5b828e7b8e360f 100644 --- a/test/parallel/test-cluster-setup-master-emit.js +++ b/test/parallel/test-cluster-setup-master-emit.js @@ -1,7 +1,7 @@ 'use strict'; const common = require('../common'); -var assert = require('assert'); -var cluster = require('cluster'); +const assert = require('assert'); +const cluster = require('cluster'); assert(cluster.isMaster); diff --git a/test/parallel/test-cluster-setup-master-multiple.js b/test/parallel/test-cluster-setup-master-multiple.js index 5ceff2bddfaf9d..25cff7cb33e0c1 100644 --- a/test/parallel/test-cluster-setup-master-multiple.js +++ b/test/parallel/test-cluster-setup-master-multiple.js @@ -1,7 +1,7 @@ 'use strict'; require('../common'); -var assert = require('assert'); -var cluster = require('cluster'); +const assert = require('assert'); +const cluster = require('cluster'); assert(cluster.isMaster); @@ -13,7 +13,7 @@ function cheapClone(obj) { return JSON.parse(JSON.stringify(obj)); } -var configs = []; +const configs = []; // Capture changes cluster.on('setup', function() { @@ -21,7 +21,7 @@ cluster.on('setup', function() { configs.push(cheapClone(cluster.settings)); }); -var execs = [ +const execs = [ 'node-next', 'node-next-2', 'node-next-3', diff --git a/test/parallel/test-cluster-setup-master.js b/test/parallel/test-cluster-setup-master.js index 66193203fdc665..5a92b988e61e5e 100644 --- a/test/parallel/test-cluster-setup-master.js +++ b/test/parallel/test-cluster-setup-master.js @@ -1,7 +1,7 @@ 'use strict'; require('../common'); -var assert = require('assert'); -var cluster = require('cluster'); +const assert = require('assert'); +const cluster = require('cluster'); if (cluster.isWorker) { @@ -10,14 +10,14 @@ if (cluster.isWorker) { } else if (cluster.isMaster) { - var checks = { + const checks = { args: false, setupEvent: false, settingsObject: false }; - var totalWorkers = 2; - var onlineWorkers = 0; + const totalWorkers = 2; + let onlineWorkers = 0; // Setup master cluster.setupMaster({ @@ -28,7 +28,7 @@ if (cluster.isWorker) { cluster.once('setup', function() { checks.setupEvent = true; - var settings = cluster.settings; + const settings = cluster.settings; if (settings && settings.args && settings.args[0] === 'custom argument' && settings.silent === true && @@ -37,7 +37,7 @@ if (cluster.isWorker) { } }); - var correctIn = 0; + let correctIn = 0; cluster.on('online', function lisenter(worker) { @@ -66,7 +66,7 @@ if (cluster.isWorker) { assert.ok(checks.workers, 'Not all workers went online'); assert.ok(checks.args, 'The arguments was noy send to the worker'); assert.ok(checks.setupEvent, 'The setup event was never emitted'); - var m = 'The settingsObject do not have correct properties'; + const m = 'The settingsObject do not have correct properties'; assert.ok(checks.settingsObject, m); }); diff --git a/test/parallel/test-cluster-shared-leak.js b/test/parallel/test-cluster-shared-leak.js index ad13a869b2b8e0..d578ee6373f3b6 100644 --- a/test/parallel/test-cluster-shared-leak.js +++ b/test/parallel/test-cluster-shared-leak.js @@ -10,9 +10,9 @@ const cluster = require('cluster'); cluster.schedulingPolicy = cluster.SCHED_NONE; if (cluster.isMaster) { - var conn, worker1, worker2; + let conn, worker2; - worker1 = cluster.fork(); + const worker1 = cluster.fork(); worker1.on('message', common.mustCall(function() { worker2 = cluster.fork(); worker2.on('online', function() { diff --git a/test/parallel/test-cluster-worker-death.js b/test/parallel/test-cluster-worker-death.js index ac32705106e03c..7a33721a9aba17 100644 --- a/test/parallel/test-cluster-worker-death.js +++ b/test/parallel/test-cluster-worker-death.js @@ -1,12 +1,12 @@ 'use strict'; const common = require('../common'); -var assert = require('assert'); -var cluster = require('cluster'); +const assert = require('assert'); +const cluster = require('cluster'); if (!cluster.isMaster) { process.exit(42); } else { - var worker = cluster.fork(); + const worker = cluster.fork(); worker.on('exit', common.mustCall(function(exitCode, signalCode) { assert.strictEqual(exitCode, 42); assert.strictEqual(signalCode, null); diff --git a/test/parallel/test-cluster-worker-destroy.js b/test/parallel/test-cluster-worker-destroy.js index c802177530e4af..91091318afa1d3 100644 --- a/test/parallel/test-cluster-worker-destroy.js +++ b/test/parallel/test-cluster-worker-destroy.js @@ -8,8 +8,8 @@ */ const common = require('../common'); -var cluster = require('cluster'); -var worker1, worker2; +const cluster = require('cluster'); +let worker1, worker2; if (cluster.isMaster) { worker1 = cluster.fork(); diff --git a/test/parallel/test-cluster-worker-events.js b/test/parallel/test-cluster-worker-events.js index 08bf456a735b7d..6c2e278f5e4639 100644 --- a/test/parallel/test-cluster-worker-events.js +++ b/test/parallel/test-cluster-worker-events.js @@ -1,13 +1,13 @@ 'use strict'; require('../common'); -var assert = require('assert'); -var cluster = require('cluster'); +const assert = require('assert'); +const cluster = require('cluster'); -var OK = 2; +const OK = 2; if (cluster.isMaster) { - var worker = cluster.fork(); + const worker = cluster.fork(); worker.on('exit', function(code) { assert.strictEqual(code, OK); @@ -25,8 +25,8 @@ if (cluster.isMaster) { assert(cluster.isWorker); -var sawProcess; -var sawWorker; +let sawProcess; +let sawWorker; process.on('message', function(m) { assert(!sawProcess); @@ -40,7 +40,7 @@ cluster.worker.on('message', function(m) { check(m); }); -var messages = []; +const messages = []; function check(m) { messages.push(m); diff --git a/test/parallel/test-cluster-worker-forced-exit.js b/test/parallel/test-cluster-worker-forced-exit.js index 3e1f7905ee50d1..828188254724ae 100644 --- a/test/parallel/test-cluster-worker-forced-exit.js +++ b/test/parallel/test-cluster-worker-forced-exit.js @@ -1,9 +1,9 @@ 'use strict'; const common = require('../common'); -var assert = require('assert'); -var cluster = require('cluster'); +const assert = require('assert'); +const cluster = require('cluster'); -var SENTINEL = 42; +const SENTINEL = 42; // workers forcibly exit when control channel is disconnected, if // their .exitedAfterDisconnect flag isn't set diff --git a/test/parallel/test-cluster-worker-isconnected.js b/test/parallel/test-cluster-worker-isconnected.js index 985d15ce6475e6..8b2ad865899c60 100644 --- a/test/parallel/test-cluster-worker-isconnected.js +++ b/test/parallel/test-cluster-worker-isconnected.js @@ -1,10 +1,10 @@ 'use strict'; require('../common'); -var cluster = require('cluster'); -var assert = require('assert'); +const cluster = require('cluster'); +const assert = require('assert'); if (cluster.isMaster) { - var worker = cluster.fork(); + const worker = cluster.fork(); assert.ok(worker.isConnected(), 'isConnected() should return true as soon as the worker has ' + diff --git a/test/parallel/test-cluster-worker-isdead.js b/test/parallel/test-cluster-worker-isdead.js index 90454cb86089a7..cd360ff248aa13 100644 --- a/test/parallel/test-cluster-worker-isdead.js +++ b/test/parallel/test-cluster-worker-isdead.js @@ -1,10 +1,10 @@ 'use strict'; require('../common'); -var cluster = require('cluster'); -var assert = require('assert'); +const cluster = require('cluster'); +const assert = require('assert'); if (cluster.isMaster) { - var worker = cluster.fork(); + const worker = cluster.fork(); assert.ok(!worker.isDead(), 'isDead() should return false right after the worker has been ' + 'created.'); diff --git a/test/parallel/test-cluster-worker-no-exit.js b/test/parallel/test-cluster-worker-no-exit.js index 0cec652b68648c..9cfd8401a0c678 100644 --- a/test/parallel/test-cluster-worker-no-exit.js +++ b/test/parallel/test-cluster-worker-no-exit.js @@ -1,13 +1,13 @@ 'use strict'; const common = require('../common'); -var assert = require('assert'); -var cluster = require('cluster'); -var net = require('net'); +const assert = require('assert'); +const cluster = require('cluster'); +const net = require('net'); -var destroyed; -var success; -var worker; -var server; +let destroyed; +let success; +let worker; +let server; // workers do not exit on disconnect, they exit under normal node rules: when // they have nothing keeping their loop alive, like an active connection @@ -35,7 +35,7 @@ if (cluster.isMaster) { }); }).listen(common.PORT, function() { - var port = this.address().port; + const port = this.address().port; worker = cluster.fork() .on('online', function() { diff --git a/test/parallel/test-cluster-worker-wait-server-close.js b/test/parallel/test-cluster-worker-wait-server-close.js index bdf60971fee5c1..d1a0d73678d67a 100644 --- a/test/parallel/test-cluster-worker-wait-server-close.js +++ b/test/parallel/test-cluster-worker-wait-server-close.js @@ -1,14 +1,14 @@ 'use strict'; -var common = require('../common'); -var assert = require('assert'); -var cluster = require('cluster'); -var net = require('net'); +const common = require('../common'); +const assert = require('assert'); +const cluster = require('cluster'); +const net = require('net'); -var serverClosed = false; +let serverClosed = false; if (cluster.isWorker) { - var server = net.createServer(function(socket) { + const server = net.createServer(function(socket) { // Wait for any data, then close connection socket.write('.'); socket.on('data', function discard() {}); @@ -20,7 +20,7 @@ if (cluster.isWorker) { // Although not typical, the worker process can exit before the disconnect // event fires. Use this to keep the process open until the event has fired. - var keepOpen = setInterval(function() {}, 9999); + const keepOpen = setInterval(function() {}, 9999); // Check worker events and properties process.once('disconnect', function() { @@ -30,7 +30,7 @@ if (cluster.isWorker) { }); } else if (cluster.isMaster) { // start worker - var worker = cluster.fork(); + const worker = cluster.fork(); // Disconnect worker when it is ready worker.once('listening', function() { diff --git a/test/parallel/test-common.js b/test/parallel/test-common.js index 59485eec4a327f..17f41840e4ffa5 100644 --- a/test/parallel/test-common.js +++ b/test/parallel/test-common.js @@ -1,6 +1,6 @@ 'use strict'; -var common = require('../common'); -var assert = require('assert'); +const common = require('../common'); +const assert = require('assert'); common.globalCheck = false; global.gc = 42; // Not a valid global unless --expose_gc is set. diff --git a/test/parallel/test-console-instance.js b/test/parallel/test-console-instance.js index ab5e5c9e6b3ce7..328adfde0ed803 100644 --- a/test/parallel/test-console-instance.js +++ b/test/parallel/test-console-instance.js @@ -29,7 +29,7 @@ assert.throws(() => { out.write = err.write = (d) => {}; -var c = new Console(out, err); +const c = new Console(out, err); out.write = err.write = common.mustCall((d) => { assert.strictEqual(d, 'test\n'); diff --git a/test/parallel/test-console-not-call-toString.js b/test/parallel/test-console-not-call-toString.js index f152e33e98f087..0c1c209374ac17 100644 --- a/test/parallel/test-console-not-call-toString.js +++ b/test/parallel/test-console-not-call-toString.js @@ -1,9 +1,9 @@ 'use strict'; require('../common'); -var assert = require('assert'); +const assert = require('assert'); -var func = function() {}; -var toStringCalled = false; +const func = function() {}; +let toStringCalled = false; func.toString = function() { toStringCalled = true; }; diff --git a/test/parallel/test-crypto-binary-default.js b/test/parallel/test-crypto-binary-default.js index 33a0783fe99963..6ee3aeac36dd89 100644 --- a/test/parallel/test-crypto-binary-default.js +++ b/test/parallel/test-crypto-binary-default.js @@ -53,7 +53,7 @@ const hmacHash = crypto.createHmac('sha1', 'Node') assert.strictEqual(hmacHash, '19fd6e1ba73d9ed2224dd5094a71babe85d9a892'); // Test HMAC-SHA-* (rfc 4231 Test Cases) -var rfc4231 = [ +const rfc4231 = [ { key: Buffer.from('0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b', 'hex'), data: Buffer.from('4869205468657265', 'hex'), // 'Hi There' @@ -200,8 +200,8 @@ var rfc4231 = [ ]; for (let i = 0, l = rfc4231.length; i < l; i++) { - for (var hash in rfc4231[i]['hmac']) { - var result = crypto.createHmac(hash, rfc4231[i]['key']) + for (const hash in rfc4231[i]['hmac']) { + let result = crypto.createHmac(hash, rfc4231[i]['key']) .update(rfc4231[i]['data']) .digest('hex'); if (rfc4231[i]['truncate']) { @@ -216,7 +216,7 @@ for (let i = 0, l = rfc4231.length; i < l; i++) { } // Test HMAC-MD5/SHA1 (rfc 2202 Test Cases) -var rfc2202_md5 = [ +const rfc2202_md5 = [ { key: Buffer.from('0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b', 'hex'), data: 'Hi There', @@ -269,7 +269,7 @@ var rfc2202_md5 = [ hmac: '6f630fad67cda0ee1fb1f562db3aa53e' } ]; -var rfc2202_sha1 = [ +const rfc2202_sha1 = [ { key: Buffer.from('0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b', 'hex'), data: 'Hi There', @@ -346,13 +346,13 @@ for (let i = 0, l = rfc2202_sha1.length; i < l; i++) { } // Test hashing -var a1 = crypto.createHash('sha1').update('Test123').digest('hex'); -var a2 = crypto.createHash('sha256').update('Test123').digest('base64'); -var a3 = crypto.createHash('sha512').update('Test123').digest(); // binary -var a4 = crypto.createHash('sha1').update('Test123').digest('buffer'); +const a1 = crypto.createHash('sha1').update('Test123').digest('hex'); +const a2 = crypto.createHash('sha256').update('Test123').digest('base64'); +const a3 = crypto.createHash('sha512').update('Test123').digest(); // binary +const a4 = crypto.createHash('sha1').update('Test123').digest('buffer'); if (!common.hasFipsCrypto) { - var a0 = crypto.createHash('md5').update('Test123').digest('latin1'); + const a0 = crypto.createHash('md5').update('Test123').digest('latin1'); assert.strictEqual( a0, 'h\u00ea\u00cb\u0097\u00d8o\fF!\u00fa+\u000e\u0017\u00ca\u00bd\u008c', @@ -382,14 +382,14 @@ assert.deepStrictEqual( ); // Test multiple updates to same hash -var h1 = crypto.createHash('sha1').update('Test123').digest('hex'); -var h2 = crypto.createHash('sha1').update('Test').update('123').digest('hex'); +const h1 = crypto.createHash('sha1').update('Test123').digest('hex'); +const h2 = crypto.createHash('sha1').update('Test').update('123').digest('hex'); assert.strictEqual(h1, h2, 'multipled updates'); // Test hashing for binary files -var fn = path.join(common.fixturesDir, 'sample.png'); -var sha1Hash = crypto.createHash('sha1'); -var fileStream = fs.createReadStream(fn); +const fn = path.join(common.fixturesDir, 'sample.png'); +const sha1Hash = crypto.createHash('sha1'); +const fileStream = fs.createReadStream(fn); fileStream.on('data', function(data) { sha1Hash.update(data); }); @@ -407,28 +407,28 @@ assert.throws(function() { }, /^Error: Digest method not supported$/); // Test signing and verifying -var s1 = crypto.createSign('RSA-SHA1') +const s1 = crypto.createSign('RSA-SHA1') .update('Test123') .sign(keyPem, 'base64'); -var s1Verified = crypto.createVerify('RSA-SHA1') +const s1Verified = crypto.createVerify('RSA-SHA1') .update('Test') .update('123') .verify(certPem, s1, 'base64'); assert.strictEqual(s1Verified, true, 'sign and verify (base 64)'); -var s2 = crypto.createSign('RSA-SHA256') +const s2 = crypto.createSign('RSA-SHA256') .update('Test123') .sign(keyPem); // binary -var s2Verified = crypto.createVerify('RSA-SHA256') +const s2Verified = crypto.createVerify('RSA-SHA256') .update('Test') .update('123') .verify(certPem, s2); // binary assert.strictEqual(s2Verified, true, 'sign and verify (binary)'); -var s3 = crypto.createSign('RSA-SHA1') +const s3 = crypto.createSign('RSA-SHA1') .update('Test123') .sign(keyPem, 'buffer'); -var s3Verified = crypto.createVerify('RSA-SHA1') +const s3Verified = crypto.createVerify('RSA-SHA1') .update('Test') .update('123') .verify(certPem, s3); @@ -437,17 +437,17 @@ assert.strictEqual(s3Verified, true, 'sign and verify (buffer)'); function testCipher1(key) { // Test encryption and decryption - var plaintext = 'Keep this a secret? No! Tell everyone about node.js!'; - var cipher = crypto.createCipher('aes192', key); + const plaintext = 'Keep this a secret? No! Tell everyone about node.js!'; + const cipher = crypto.createCipher('aes192', key); // encrypt plaintext which is in utf8 format // to a ciphertext which will be in hex - var ciph = cipher.update(plaintext, 'utf8', 'hex'); + let ciph = cipher.update(plaintext, 'utf8', 'hex'); // Only use binary or hex, not base64. ciph += cipher.final('hex'); - var decipher = crypto.createDecipher('aes192', key); - var txt = decipher.update(ciph, 'hex', 'utf8'); + const decipher = crypto.createDecipher('aes192', key); + let txt = decipher.update(ciph, 'hex', 'utf8'); txt += decipher.final('utf8'); assert.strictEqual(txt, plaintext, 'encryption and decryption'); @@ -457,19 +457,19 @@ function testCipher1(key) { function testCipher2(key) { // encryption and decryption with Base64 // reported in https://github.com/joyent/node/issues/738 - var plaintext = + const plaintext = '32|RmVZZkFUVmpRRkp0TmJaUm56ZU9qcnJkaXNNWVNpTTU*|iXmckfRWZBGWWELw' + 'eCBsThSsfUHLeRe0KCsK8ooHgxie0zOINpXxfZi/oNG7uq9JWFVCk70gfzQH8ZUJ' + 'jAfaFg**'; - var cipher = crypto.createCipher('aes256', key); + const cipher = crypto.createCipher('aes256', key); // encrypt plaintext which is in utf8 format // to a ciphertext which will be in Base64 - var ciph = cipher.update(plaintext, 'utf8', 'base64'); + let ciph = cipher.update(plaintext, 'utf8', 'base64'); ciph += cipher.final('base64'); - var decipher = crypto.createDecipher('aes256', key); - var txt = decipher.update(ciph, 'base64', 'utf8'); + const decipher = crypto.createDecipher('aes256', key); + let txt = decipher.update(ciph, 'base64', 'utf8'); txt += decipher.final('utf8'); assert.strictEqual(txt, plaintext, 'encryption and decryption with Base64'); @@ -478,16 +478,16 @@ function testCipher2(key) { function testCipher3(key, iv) { // Test encyrption and decryption with explicit key and iv - var plaintext = + const plaintext = '32|RmVZZkFUVmpRRkp0TmJaUm56ZU9qcnJkaXNNWVNpTTU*|iXmckfRWZBGWWELw' + 'eCBsThSsfUHLeRe0KCsK8ooHgxie0zOINpXxfZi/oNG7uq9JWFVCk70gfzQH8ZUJ' + 'jAfaFg**'; - var cipher = crypto.createCipheriv('des-ede3-cbc', key, iv); - var ciph = cipher.update(plaintext, 'utf8', 'hex'); + const cipher = crypto.createCipheriv('des-ede3-cbc', key, iv); + let ciph = cipher.update(plaintext, 'utf8', 'hex'); ciph += cipher.final('hex'); - var decipher = crypto.createDecipheriv('des-ede3-cbc', key, iv); - var txt = decipher.update(ciph, 'hex', 'utf8'); + const decipher = crypto.createDecipheriv('des-ede3-cbc', key, iv); + let txt = decipher.update(ciph, 'hex', 'utf8'); txt += decipher.final('utf8'); assert.strictEqual(txt, plaintext, @@ -497,16 +497,16 @@ function testCipher3(key, iv) { function testCipher4(key, iv) { // Test encyrption and decryption with explicit key and iv - var plaintext = + const plaintext = '32|RmVZZkFUVmpRRkp0TmJaUm56ZU9qcnJkaXNNWVNpTTU*|iXmckfRWZBGWWELw' + 'eCBsThSsfUHLeRe0KCsK8ooHgxie0zOINpXxfZi/oNG7uq9JWFVCk70gfzQH8ZUJ' + 'jAfaFg**'; - var cipher = crypto.createCipheriv('des-ede3-cbc', key, iv); - var ciph = cipher.update(plaintext, 'utf8', 'buffer'); + const cipher = crypto.createCipheriv('des-ede3-cbc', key, iv); + let ciph = cipher.update(plaintext, 'utf8', 'buffer'); ciph = Buffer.concat([ciph, cipher.final('buffer')]); - var decipher = crypto.createDecipheriv('des-ede3-cbc', key, iv); - var txt = decipher.update(ciph, 'buffer', 'utf8'); + const decipher = crypto.createDecipheriv('des-ede3-cbc', key, iv); + let txt = decipher.update(ciph, 'buffer', 'utf8'); txt += decipher.final('utf8'); assert.strictEqual(txt, plaintext, @@ -537,20 +537,20 @@ assert.throws(function() { // Test Diffie-Hellman with two parties sharing a secret, // using various encodings as we go along -var dh1 = crypto.createDiffieHellman(common.hasFipsCrypto ? 1024 : 256); -var p1 = dh1.getPrime('buffer'); -var dh2 = crypto.createDiffieHellman(p1, 'base64'); -var key1 = dh1.generateKeys(); -var key2 = dh2.generateKeys('hex'); -var secret1 = dh1.computeSecret(key2, 'hex', 'base64'); -var secret2 = dh2.computeSecret(key1, 'latin1', 'buffer'); +const dh1 = crypto.createDiffieHellman(common.hasFipsCrypto ? 1024 : 256); +const p1 = dh1.getPrime('buffer'); +const dh2 = crypto.createDiffieHellman(p1, 'base64'); +const key1 = dh1.generateKeys(); +const key2 = dh2.generateKeys('hex'); +const secret1 = dh1.computeSecret(key2, 'hex', 'base64'); +const secret2 = dh2.computeSecret(key1, 'latin1', 'buffer'); assert.strictEqual(secret1, secret2.toString('base64')); // Create "another dh1" using generated keys from dh1, // and compute secret again -var dh3 = crypto.createDiffieHellman(p1, 'buffer'); -var privkey1 = dh1.getPrivateKey(); +const dh3 = crypto.createDiffieHellman(p1, 'buffer'); +const privkey1 = dh1.getPrivateKey(); dh3.setPublicKey(key1); dh3.setPrivateKey(privkey1); @@ -559,26 +559,26 @@ assert.strictEqual(dh1.getGenerator(), dh3.getGenerator()); assert.strictEqual(dh1.getPublicKey(), dh3.getPublicKey()); assert.strictEqual(dh1.getPrivateKey(), dh3.getPrivateKey()); -var secret3 = dh3.computeSecret(key2, 'hex', 'base64'); +const secret3 = dh3.computeSecret(key2, 'hex', 'base64'); assert.strictEqual(secret1, secret3); // https://github.com/joyent/node/issues/2338 -var p = 'FFFFFFFFFFFFFFFFC90FDAA22168C234C4C6628B80DC1CD129024E088A67CC74' + - '020BBEA63B139B22514A08798E3404DDEF9519B3CD3A431B302B0A6DF25F1437' + - '4FE1356D6D51C245E485B576625E7EC6F44C42E9A637ED6B0BFF5CB6F406B7ED' + - 'EE386BFB5A899FA5AE9F24117C4B1FE649286651ECE65381FFFFFFFFFFFFFFFF'; -var d = crypto.createDiffieHellman(p, 'hex'); +const p = 'FFFFFFFFFFFFFFFFC90FDAA22168C234C4C6628B80DC1CD129024E088A67CC74' + + '020BBEA63B139B22514A08798E3404DDEF9519B3CD3A431B302B0A6DF25F1437' + + '4FE1356D6D51C245E485B576625E7EC6F44C42E9A637ED6B0BFF5CB6F406B7ED' + + 'EE386BFB5A899FA5AE9F24117C4B1FE649286651ECE65381FFFFFFFFFFFFFFFF'; +const d = crypto.createDiffieHellman(p, 'hex'); assert.strictEqual(d.verifyError, DH_NOT_SUITABLE_GENERATOR); // Test RSA key signing/verification -var rsaSign = crypto.createSign('RSA-SHA1'); -var rsaVerify = crypto.createVerify('RSA-SHA1'); +const rsaSign = crypto.createSign('RSA-SHA1'); +const rsaVerify = crypto.createVerify('RSA-SHA1'); assert.ok(rsaSign instanceof crypto.Sign); assert.ok(rsaVerify instanceof crypto.Verify); rsaSign.update(rsaPubPem); -var rsaSignature = rsaSign.sign(rsaKeyPem, 'hex'); +const rsaSignature = rsaSign.sign(rsaKeyPem, 'hex'); assert.strictEqual( rsaSignature, '5c50e3145c4e2497aadb0eabc83b342d0b0021ece0d4c4a064b7c' + diff --git a/test/parallel/test-crypto-certificate.js b/test/parallel/test-crypto-certificate.js index 8dba530fc54a45..c051716556410d 100644 --- a/test/parallel/test-crypto-certificate.js +++ b/test/parallel/test-crypto-certificate.js @@ -1,23 +1,23 @@ 'use strict'; -var common = require('../common'); -var assert = require('assert'); +const common = require('../common'); +const assert = require('assert'); if (!common.hasCrypto) { common.skip('missing crypto'); return; } -var crypto = require('crypto'); +const crypto = require('crypto'); crypto.DEFAULT_ENCODING = 'buffer'; -var fs = require('fs'); +const fs = require('fs'); // Test Certificates -var spkacValid = fs.readFileSync(common.fixturesDir + '/spkac.valid'); -var spkacFail = fs.readFileSync(common.fixturesDir + '/spkac.fail'); -var spkacPem = fs.readFileSync(common.fixturesDir + '/spkac.pem'); +const spkacValid = fs.readFileSync(common.fixturesDir + '/spkac.valid'); +const spkacFail = fs.readFileSync(common.fixturesDir + '/spkac.fail'); +const spkacPem = fs.readFileSync(common.fixturesDir + '/spkac.pem'); -var certificate = new crypto.Certificate(); +const certificate = new crypto.Certificate(); assert.strictEqual(certificate.verifySpkac(spkacValid), true); assert.strictEqual(certificate.verifySpkac(spkacFail), false); diff --git a/test/parallel/test-crypto-dh-odd-key.js b/test/parallel/test-crypto-dh-odd-key.js index cb8757efff0bde..f6bfcf72c0fd7e 100644 --- a/test/parallel/test-crypto-dh-odd-key.js +++ b/test/parallel/test-crypto-dh-odd-key.js @@ -1,17 +1,17 @@ 'use strict'; -var common = require('../common'); -var assert = require('assert'); +const common = require('../common'); +const assert = require('assert'); if (!common.hasCrypto) { common.skip('missing crypto'); return; } -var crypto = require('crypto'); +const crypto = require('crypto'); function test() { - var odd = Buffer.alloc(39, 'A'); + const odd = Buffer.alloc(39, 'A'); - var c = crypto.createDiffieHellman(32); + const c = crypto.createDiffieHellman(32); c.setPrivateKey(odd); c.generateKeys(); } diff --git a/test/parallel/test-crypto-dh.js b/test/parallel/test-crypto-dh.js index 884b482fc53450..b26ac78f3146a0 100644 --- a/test/parallel/test-crypto-dh.js +++ b/test/parallel/test-crypto-dh.js @@ -11,13 +11,13 @@ const DH_NOT_SUITABLE_GENERATOR = crypto.constants.DH_NOT_SUITABLE_GENERATOR; // Test Diffie-Hellman with two parties sharing a secret, // using various encodings as we go along -var dh1 = crypto.createDiffieHellman(common.hasFipsCrypto ? 1024 : 256); -var p1 = dh1.getPrime('buffer'); -var dh2 = crypto.createDiffieHellman(p1, 'buffer'); -var key1 = dh1.generateKeys(); -var key2 = dh2.generateKeys('hex'); -var secret1 = dh1.computeSecret(key2, 'hex', 'base64'); -var secret2 = dh2.computeSecret(key1, 'latin1', 'buffer'); +const dh1 = crypto.createDiffieHellman(common.hasFipsCrypto ? 1024 : 256); +const p1 = dh1.getPrime('buffer'); +const dh2 = crypto.createDiffieHellman(p1, 'buffer'); +let key1 = dh1.generateKeys(); +let key2 = dh2.generateKeys('hex'); +let secret1 = dh1.computeSecret(key2, 'hex', 'base64'); +let secret2 = dh2.computeSecret(key1, 'latin1', 'buffer'); assert.equal(secret1, secret2.toString('base64')); assert.equal(dh1.verifyError, 0); @@ -41,8 +41,8 @@ assert.throws(function() { // Create "another dh1" using generated keys from dh1, // and compute secret again -var dh3 = crypto.createDiffieHellman(p1, 'buffer'); -var privkey1 = dh1.getPrivateKey(); +const dh3 = crypto.createDiffieHellman(p1, 'buffer'); +const privkey1 = dh1.getPrivateKey(); dh3.setPublicKey(key1); dh3.setPrivateKey(privkey1); @@ -52,7 +52,7 @@ assert.deepStrictEqual(dh1.getPublicKey(), dh3.getPublicKey()); assert.deepStrictEqual(dh1.getPrivateKey(), dh3.getPrivateKey()); assert.equal(dh3.verifyError, 0); -var secret3 = dh3.computeSecret(key2, 'hex', 'base64'); +const secret3 = dh3.computeSecret(key2, 'hex', 'base64'); assert.equal(secret1, secret3); @@ -72,12 +72,12 @@ assert.throws(function() { } // Create a shared using a DH group. -var alice = crypto.createDiffieHellmanGroup('modp5'); -var bob = crypto.createDiffieHellmanGroup('modp5'); +const alice = crypto.createDiffieHellmanGroup('modp5'); +const bob = crypto.createDiffieHellmanGroup('modp5'); alice.generateKeys(); bob.generateKeys(); -var aSecret = alice.computeSecret(bob.getPublicKey()).toString('hex'); -var bSecret = bob.computeSecret(alice.getPublicKey()).toString('hex'); +const aSecret = alice.computeSecret(bob.getPublicKey()).toString('hex'); +const bSecret = bob.computeSecret(alice.getPublicKey()).toString('hex'); assert.equal(aSecret, bSecret); assert.equal(alice.verifyError, DH_NOT_SUITABLE_GENERATOR); assert.equal(bob.verifyError, DH_NOT_SUITABLE_GENERATOR); @@ -85,8 +85,8 @@ assert.equal(bob.verifyError, DH_NOT_SUITABLE_GENERATOR); /* Ensure specific generator (buffer) works as expected. * The values below (modp2/modp2buf) are for a 1024 bits long prime from * RFC 2412 E.2, see https://tools.ietf.org/html/rfc2412. */ -var modp2 = crypto.createDiffieHellmanGroup('modp2'); -var modp2buf = Buffer.from([ +const modp2 = crypto.createDiffieHellmanGroup('modp2'); +const modp2buf = Buffer.from([ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xc9, 0x0f, 0xda, 0xa2, 0x21, 0x68, 0xc2, 0x34, 0xc4, 0xc6, 0x62, 0x8b, 0x80, 0xdc, 0x1c, 0xd1, 0x29, 0x02, 0x4e, 0x08, 0x8a, 0x67, @@ -101,51 +101,52 @@ var modp2buf = Buffer.from([ 0x1f, 0xe6, 0x49, 0x28, 0x66, 0x51, 0xec, 0xe6, 0x53, 0x81, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff ]); -var exmodp2 = crypto.createDiffieHellman(modp2buf, Buffer.from([2])); +const exmodp2 = crypto.createDiffieHellman(modp2buf, Buffer.from([2])); modp2.generateKeys(); exmodp2.generateKeys(); -var modp2Secret = modp2.computeSecret(exmodp2.getPublicKey()).toString('hex'); -var exmodp2Secret = exmodp2.computeSecret(modp2.getPublicKey()).toString('hex'); +let modp2Secret = modp2.computeSecret(exmodp2.getPublicKey()).toString('hex'); +const exmodp2Secret = exmodp2.computeSecret(modp2.getPublicKey()) + .toString('hex'); assert.equal(modp2Secret, exmodp2Secret); assert.equal(modp2.verifyError, DH_NOT_SUITABLE_GENERATOR); assert.equal(exmodp2.verifyError, DH_NOT_SUITABLE_GENERATOR); // Ensure specific generator (string with encoding) works as expected. -var exmodp2_2 = crypto.createDiffieHellman(modp2buf, '02', 'hex'); +const exmodp2_2 = crypto.createDiffieHellman(modp2buf, '02', 'hex'); exmodp2_2.generateKeys(); modp2Secret = modp2.computeSecret(exmodp2_2.getPublicKey()).toString('hex'); -var exmodp2_2Secret = exmodp2_2.computeSecret(modp2.getPublicKey()) +const exmodp2_2Secret = exmodp2_2.computeSecret(modp2.getPublicKey()) .toString('hex'); assert.equal(modp2Secret, exmodp2_2Secret); assert.equal(exmodp2_2.verifyError, DH_NOT_SUITABLE_GENERATOR); // Ensure specific generator (string without encoding) works as expected. -var exmodp2_3 = crypto.createDiffieHellman(modp2buf, '\x02'); +const exmodp2_3 = crypto.createDiffieHellman(modp2buf, '\x02'); exmodp2_3.generateKeys(); modp2Secret = modp2.computeSecret(exmodp2_3.getPublicKey()).toString('hex'); -var exmodp2_3Secret = exmodp2_3.computeSecret(modp2.getPublicKey()) +const exmodp2_3Secret = exmodp2_3.computeSecret(modp2.getPublicKey()) .toString('hex'); assert.equal(modp2Secret, exmodp2_3Secret); assert.equal(exmodp2_3.verifyError, DH_NOT_SUITABLE_GENERATOR); // Ensure specific generator (numeric) works as expected. -var exmodp2_4 = crypto.createDiffieHellman(modp2buf, 2); +const exmodp2_4 = crypto.createDiffieHellman(modp2buf, 2); exmodp2_4.generateKeys(); modp2Secret = modp2.computeSecret(exmodp2_4.getPublicKey()).toString('hex'); -var exmodp2_4Secret = exmodp2_4.computeSecret(modp2.getPublicKey()) +const exmodp2_4Secret = exmodp2_4.computeSecret(modp2.getPublicKey()) .toString('hex'); assert.equal(modp2Secret, exmodp2_4Secret); assert.equal(exmodp2_4.verifyError, DH_NOT_SUITABLE_GENERATOR); -var p = 'FFFFFFFFFFFFFFFFC90FDAA22168C234C4C6628B80DC1CD129024E088A67CC74' + - '020BBEA63B139B22514A08798E3404DDEF9519B3CD3A431B302B0A6DF25F1437' + - '4FE1356D6D51C245E485B576625E7EC6F44C42E9A637ED6B0BFF5CB6F406B7ED' + - 'EE386BFB5A899FA5AE9F24117C4B1FE649286651ECE65381FFFFFFFFFFFFFFFF'; -var bad_dh = crypto.createDiffieHellman(p, 'hex'); +const p = 'FFFFFFFFFFFFFFFFC90FDAA22168C234C4C6628B80DC1CD129024E088A67CC74' + + '020BBEA63B139B22514A08798E3404DDEF9519B3CD3A431B302B0A6DF25F1437' + + '4FE1356D6D51C245E485B576625E7EC6F44C42E9A637ED6B0BFF5CB6F406B7ED' + + 'EE386BFB5A899FA5AE9F24117C4B1FE649286651ECE65381FFFFFFFFFFFFFFFF'; +const bad_dh = crypto.createDiffieHellman(p, 'hex'); assert.equal(bad_dh.verifyError, DH_NOT_SUITABLE_GENERATOR); diff --git a/test/parallel/test-crypto-domain.js b/test/parallel/test-crypto-domain.js index ec9985719933d3..6586f7d48a94ce 100644 --- a/test/parallel/test-crypto-domain.js +++ b/test/parallel/test-crypto-domain.js @@ -1,21 +1,21 @@ 'use strict'; -var common = require('../common'); -var assert = require('assert'); -var domain = require('domain'); +const common = require('../common'); +const assert = require('assert'); +const domain = require('domain'); if (!common.hasCrypto) { common.skip('missing crypto'); return; } -var crypto = require('crypto'); +const crypto = require('crypto'); function test(fn) { - var ex = new Error('BAM'); - var d = domain.create(); + const ex = new Error('BAM'); + const d = domain.create(); d.on('error', common.mustCall(function(err) { assert.strictEqual(err, ex); })); - var cb = common.mustCall(function() { + const cb = common.mustCall(function() { throw ex; }); d.run(cb); diff --git a/test/parallel/test-crypto-domains.js b/test/parallel/test-crypto-domains.js index 5d8caf37ee2f41..2749382fa5c780 100644 --- a/test/parallel/test-crypto-domains.js +++ b/test/parallel/test-crypto-domains.js @@ -1,15 +1,15 @@ 'use strict'; -var common = require('../common'); -var domain = require('domain'); -var assert = require('assert'); -var d = domain.create(); -var expect = ['pbkdf2', 'randomBytes', 'pseudoRandomBytes']; +const common = require('../common'); +const domain = require('domain'); +const assert = require('assert'); +const d = domain.create(); +const expect = ['pbkdf2', 'randomBytes', 'pseudoRandomBytes']; if (!common.hasCrypto) { common.skip('missing crypto'); return; } -var crypto = require('crypto'); +const crypto = require('crypto'); d.on('error', common.mustCall(function(e) { assert.equal(e.message, expect.shift()); diff --git a/test/parallel/test-crypto-fips.js b/test/parallel/test-crypto-fips.js index 24b1af70b70329..60263cb01b6809 100644 --- a/test/parallel/test-crypto-fips.js +++ b/test/parallel/test-crypto-fips.js @@ -1,8 +1,8 @@ 'use strict'; -var common = require('../common'); -var assert = require('assert'); -var spawnSync = require('child_process').spawnSync; -var path = require('path'); +const common = require('../common'); +const assert = require('assert'); +const spawnSync = require('child_process').spawnSync; +const path = require('path'); if (!common.hasCrypto) { common.skip('missing crypto'); @@ -15,14 +15,14 @@ const FIPS_ERROR_STRING = 'Error: Cannot set FIPS mode'; const OPTION_ERROR_STRING = 'bad option'; const CNF_FIPS_ON = path.join(common.fixturesDir, 'openssl_fips_enabled.cnf'); const CNF_FIPS_OFF = path.join(common.fixturesDir, 'openssl_fips_disabled.cnf'); -var num_children_ok = 0; +let num_children_ok = 0; function compiledWithFips() { return process.config.variables.openssl_fips ? true : false; } function addToEnv(newVar, value) { - var envCopy = {}; + const envCopy = {}; for (const e in process.env) { envCopy[e] = process.env[e]; } diff --git a/test/parallel/test-crypto-from-binary.js b/test/parallel/test-crypto-from-binary.js index 0889541ef6e144..485735e83ce5cc 100644 --- a/test/parallel/test-crypto-from-binary.js +++ b/test/parallel/test-crypto-from-binary.js @@ -3,19 +3,19 @@ // to use buffers by default. -var common = require('../common'); -var assert = require('assert'); +const common = require('../common'); +const assert = require('assert'); if (!common.hasCrypto) { common.skip('missing crypto'); return; } -var crypto = require('crypto'); +const crypto = require('crypto'); -var EXTERN_APEX = 0xFBEE9; +const EXTERN_APEX = 0xFBEE9; // manually controlled string for checking binary output -var ucs2_control = 'a\u0000'; +let ucs2_control = 'a\u0000'; // grow the strings to proper length while (ucs2_control.length <= EXTERN_APEX) { @@ -24,7 +24,7 @@ while (ucs2_control.length <= EXTERN_APEX) { // check resultant buffer and output string -var b = Buffer.from(ucs2_control + ucs2_control, 'ucs2'); +const b = Buffer.from(ucs2_control + ucs2_control, 'ucs2'); // // Test updating from birant data diff --git a/test/parallel/test-crypto-hash.js b/test/parallel/test-crypto-hash.js index 79353ede3b49dc..9008b8f9b1614c 100644 --- a/test/parallel/test-crypto-hash.js +++ b/test/parallel/test-crypto-hash.js @@ -1,44 +1,44 @@ 'use strict'; -var common = require('../common'); -var assert = require('assert'); -var fs = require('fs'); -var path = require('path'); +const common = require('../common'); +const assert = require('assert'); +const fs = require('fs'); +const path = require('path'); if (!common.hasCrypto) { common.skip('missing crypto'); return; } -var crypto = require('crypto'); +const crypto = require('crypto'); // Test hashing -var a1 = crypto.createHash('sha1').update('Test123').digest('hex'); -var a2 = crypto.createHash('sha256').update('Test123').digest('base64'); -var a3 = crypto.createHash('sha512').update('Test123').digest(); // buffer -var a4 = crypto.createHash('sha1').update('Test123').digest('buffer'); +const a1 = crypto.createHash('sha1').update('Test123').digest('hex'); +const a2 = crypto.createHash('sha256').update('Test123').digest('base64'); +const a3 = crypto.createHash('sha512').update('Test123').digest(); // buffer +const a4 = crypto.createHash('sha1').update('Test123').digest('buffer'); // stream interface -var a5 = crypto.createHash('sha512'); +let a5 = crypto.createHash('sha512'); a5.end('Test123'); a5 = a5.read(); -var a6 = crypto.createHash('sha512'); +let a6 = crypto.createHash('sha512'); a6.write('Te'); a6.write('st'); a6.write('123'); a6.end(); a6 = a6.read(); -var a7 = crypto.createHash('sha512'); +let a7 = crypto.createHash('sha512'); a7.end(); a7 = a7.read(); -var a8 = crypto.createHash('sha512'); +let a8 = crypto.createHash('sha512'); a8.write(''); a8.end(); a8 = a8.read(); if (!common.hasFipsCrypto) { - var a0 = crypto.createHash('md5').update('Test123').digest('latin1'); + const a0 = crypto.createHash('md5').update('Test123').digest('latin1'); assert.strictEqual( a0, 'h\u00ea\u00cb\u0097\u00d8o\fF!\u00fa+\u000e\u0017\u00ca\u00bd\u008c', @@ -71,14 +71,14 @@ assert.notEqual(a7, undefined, 'no data should return data'); assert.notEqual(a8, undefined, 'empty string should generate data'); // Test multiple updates to same hash -var h1 = crypto.createHash('sha1').update('Test123').digest('hex'); -var h2 = crypto.createHash('sha1').update('Test').update('123').digest('hex'); +const h1 = crypto.createHash('sha1').update('Test123').digest('hex'); +const h2 = crypto.createHash('sha1').update('Test').update('123').digest('hex'); assert.strictEqual(h1, h2, 'multipled updates'); // Test hashing for binary files -var fn = path.join(common.fixturesDir, 'sample.png'); -var sha1Hash = crypto.createHash('sha1'); -var fileStream = fs.createReadStream(fn); +const fn = path.join(common.fixturesDir, 'sample.png'); +const sha1Hash = crypto.createHash('sha1'); +const fileStream = fs.createReadStream(fn); fileStream.on('data', function(data) { sha1Hash.update(data); }); @@ -94,7 +94,7 @@ assert.throws(function() { }, /Digest method not supported/); // Default UTF-8 encoding -var hutf8 = crypto.createHash('sha512').update('УТФ-8 text').digest('hex'); +const hutf8 = crypto.createHash('sha512').update('УТФ-8 text').digest('hex'); assert.strictEqual( hutf8, '4b21bbd1a68e690a730ddcb5a8bc94ead9879ffe82580767ad7ec6fa8ba2dea6' + @@ -104,7 +104,7 @@ assert.notEqual( hutf8, crypto.createHash('sha512').update('УТФ-8 text', 'latin1').digest('hex')); -var h3 = crypto.createHash('sha256'); +const h3 = crypto.createHash('sha256'); h3.digest(); assert.throws(function() { h3.digest(); diff --git a/test/parallel/test-crypto-hmac.js b/test/parallel/test-crypto-hmac.js index eeb8cd152567f8..a3372bcb7242b9 100644 --- a/test/parallel/test-crypto-hmac.js +++ b/test/parallel/test-crypto-hmac.js @@ -1,12 +1,12 @@ 'use strict'; -var common = require('../common'); -var assert = require('assert'); +const common = require('../common'); +const assert = require('assert'); if (!common.hasCrypto) { common.skip('missing crypto'); return; } -var crypto = require('crypto'); +const crypto = require('crypto'); // Test for binding layer robustness { @@ -17,14 +17,14 @@ var crypto = require('crypto'); } // Test HMAC -var h1 = crypto.createHmac('sha1', 'Node') +const h1 = crypto.createHmac('sha1', 'Node') .update('some data') .update('to hmac') .digest('hex'); assert.strictEqual(h1, '19fd6e1ba73d9ed2224dd5094a71babe85d9a892', 'test HMAC'); // Test HMAC (Wikipedia Test Cases) -var wikipedia = [ +const wikipedia = [ { key: 'key', data: 'The quick brown fox jumps over the lazy dog', hmac: { // HMACs lifted from Wikipedia. @@ -83,7 +83,7 @@ for (let i = 0, l = wikipedia.length; i < l; i++) { // Test HMAC-SHA-* (rfc 4231 Test Cases) -var rfc4231 = [ +const rfc4231 = [ { key: Buffer.from('0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b', 'hex'), data: Buffer.from('4869205468657265', 'hex'), // 'Hi There' @@ -249,7 +249,7 @@ for (let i = 0, l = rfc4231.length; i < l; i++) { } // Test HMAC-MD5/SHA1 (rfc 2202 Test Cases) -var rfc2202_md5 = [ +const rfc2202_md5 = [ { key: Buffer.from('0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b', 'hex'), data: 'Hi There', @@ -302,7 +302,7 @@ var rfc2202_md5 = [ hmac: '6f630fad67cda0ee1fb1f562db3aa53e' } ]; -var rfc2202_sha1 = [ +const rfc2202_sha1 = [ { key: Buffer.from('0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b', 'hex'), data: 'Hi There', diff --git a/test/parallel/test-crypto-padding-aes256.js b/test/parallel/test-crypto-padding-aes256.js index 7fd2e98de617cf..40bbfed0f2824f 100644 --- a/test/parallel/test-crypto-padding-aes256.js +++ b/test/parallel/test-crypto-padding-aes256.js @@ -1,12 +1,12 @@ 'use strict'; -var common = require('../common'); -var assert = require('assert'); +const common = require('../common'); +const assert = require('assert'); if (!common.hasCrypto) { common.skip('missing crypto'); return; } -var crypto = require('crypto'); +const crypto = require('crypto'); crypto.DEFAULT_ENCODING = 'buffer'; diff --git a/test/parallel/test-crypto-rsa-dsa.js b/test/parallel/test-crypto-rsa-dsa.js index bbc043fbc3aee2..eadb948491f19c 100644 --- a/test/parallel/test-crypto-rsa-dsa.js +++ b/test/parallel/test-crypto-rsa-dsa.js @@ -1,29 +1,29 @@ 'use strict'; -var common = require('../common'); -var assert = require('assert'); -var fs = require('fs'); -var constants = require('crypto').constants; +const common = require('../common'); +const assert = require('assert'); +const fs = require('fs'); +const constants = require('crypto').constants; if (!common.hasCrypto) { common.skip('missing crypto'); return; } -var crypto = require('crypto'); +const crypto = require('crypto'); // Test certificates -var certPem = fs.readFileSync(common.fixturesDir + '/test_cert.pem', 'ascii'); -var keyPem = fs.readFileSync(common.fixturesDir + '/test_key.pem', 'ascii'); -var rsaPubPem = fs.readFileSync(common.fixturesDir + '/test_rsa_pubkey.pem', - 'ascii'); -var rsaKeyPem = fs.readFileSync(common.fixturesDir + '/test_rsa_privkey.pem', - 'ascii'); -var rsaKeyPemEncrypted = fs.readFileSync( +const certPem = fs.readFileSync(common.fixturesDir + '/test_cert.pem', 'ascii'); +const keyPem = fs.readFileSync(common.fixturesDir + '/test_key.pem', 'ascii'); +const rsaPubPem = fs.readFileSync(common.fixturesDir + '/test_rsa_pubkey.pem', + 'ascii'); +const rsaKeyPem = fs.readFileSync(common.fixturesDir + '/test_rsa_privkey.pem', + 'ascii'); +const rsaKeyPemEncrypted = fs.readFileSync( common.fixturesDir + '/test_rsa_privkey_encrypted.pem', 'ascii'); -var dsaPubPem = fs.readFileSync(common.fixturesDir + '/test_dsa_pubkey.pem', - 'ascii'); -var dsaKeyPem = fs.readFileSync(common.fixturesDir + '/test_dsa_privkey.pem', - 'ascii'); -var dsaKeyPemEncrypted = fs.readFileSync( +const dsaPubPem = fs.readFileSync(common.fixturesDir + '/test_dsa_pubkey.pem', + 'ascii'); +const dsaKeyPem = fs.readFileSync(common.fixturesDir + '/test_dsa_privkey.pem', + 'ascii'); +const dsaKeyPemEncrypted = fs.readFileSync( common.fixturesDir + '/test_dsa_privkey_encrypted.pem', 'ascii'); // Test RSA encryption/decryption @@ -107,19 +107,20 @@ var dsaKeyPemEncrypted = fs.readFileSync( } function test_rsa(padding) { - var input = Buffer.allocUnsafe(padding === 'RSA_NO_PADDING' ? 1024 / 8 : 32); - for (var i = 0; i < input.length; i++) + const input = Buffer + .allocUnsafe(padding === 'RSA_NO_PADDING' ? 1024 / 8 : 32); + for (let i = 0; i < input.length; i++) input[i] = (i * 7 + 11) & 0xff; - var bufferToEncrypt = Buffer.from(input); + const bufferToEncrypt = Buffer.from(input); padding = constants[padding]; - var encryptedBuffer = crypto.publicEncrypt({ + const encryptedBuffer = crypto.publicEncrypt({ key: rsaPubPem, padding: padding }, bufferToEncrypt); - var decryptedBuffer = crypto.privateDecrypt({ + const decryptedBuffer = crypto.privateDecrypt({ key: rsaKeyPem, padding: padding }, encryptedBuffer); @@ -131,13 +132,13 @@ test_rsa('RSA_PKCS1_PADDING'); test_rsa('RSA_PKCS1_OAEP_PADDING'); // Test RSA key signing/verification -var rsaSign = crypto.createSign('RSA-SHA1'); -var rsaVerify = crypto.createVerify('RSA-SHA1'); +let rsaSign = crypto.createSign('RSA-SHA1'); +let rsaVerify = crypto.createVerify('RSA-SHA1'); assert.ok(rsaSign); assert.ok(rsaVerify); rsaSign.update(rsaPubPem); -var rsaSignature = rsaSign.sign(rsaKeyPem, 'hex'); +let rsaSignature = rsaSign.sign(rsaKeyPem, 'hex'); assert.equal(rsaSignature, '5c50e3145c4e2497aadb0eabc83b342d0b0021ece0d4c4a064b7c' + '8f020d7e2688b122bfb54c724ac9ee169f83f66d2fe90abeb95e8' + @@ -152,7 +153,7 @@ assert.strictEqual(rsaVerify.verify(rsaPubPem, rsaSignature, 'hex'), true); rsaSign = crypto.createSign('RSA-SHA1'); rsaSign.update(rsaPubPem); assert.doesNotThrow(function() { - var signOptions = { key: rsaKeyPemEncrypted, passphrase: 'password' }; + const signOptions = { key: rsaKeyPemEncrypted, passphrase: 'password' }; rsaSignature = rsaSign.sign(signOptions, 'hex'); }); assert.equal(rsaSignature, @@ -169,7 +170,7 @@ assert.strictEqual(rsaVerify.verify(rsaPubPem, rsaSignature, 'hex'), true); rsaSign = crypto.createSign('RSA-SHA1'); rsaSign.update(rsaPubPem); assert.throws(function() { - var signOptions = { key: rsaKeyPemEncrypted, passphrase: 'wrong' }; + const signOptions = { key: rsaKeyPemEncrypted, passphrase: 'wrong' }; rsaSign.sign(signOptions, 'hex'); }); diff --git a/test/parallel/test-crypto-sign-verify.js b/test/parallel/test-crypto-sign-verify.js index b4ef8296282b7f..81b2c109b69b20 100644 --- a/test/parallel/test-crypto-sign-verify.js +++ b/test/parallel/test-crypto-sign-verify.js @@ -1,17 +1,17 @@ 'use strict'; -var common = require('../common'); -var assert = require('assert'); -var fs = require('fs'); +const common = require('../common'); +const assert = require('assert'); +const fs = require('fs'); if (!common.hasCrypto) { common.skip('missing crypto'); return; } -var crypto = require('crypto'); +const crypto = require('crypto'); // Test certificates -var certPem = fs.readFileSync(common.fixturesDir + '/test_cert.pem', 'ascii'); -var keyPem = fs.readFileSync(common.fixturesDir + '/test_key.pem', 'ascii'); +const certPem = fs.readFileSync(common.fixturesDir + '/test_cert.pem', 'ascii'); +const keyPem = fs.readFileSync(common.fixturesDir + '/test_key.pem', 'ascii'); // Test signing and verifying { diff --git a/test/parallel/test-crypto-stream.js b/test/parallel/test-crypto-stream.js index 1720cc7c4e0aea..f558851b7940a0 100644 --- a/test/parallel/test-crypto-stream.js +++ b/test/parallel/test-crypto-stream.js @@ -1,14 +1,14 @@ 'use strict'; -var common = require('../common'); -var assert = require('assert'); -var stream = require('stream'); -var util = require('util'); +const common = require('../common'); +const assert = require('assert'); +const stream = require('stream'); +const util = require('util'); if (!common.hasCrypto) { common.skip('missing crypto'); return; } -var crypto = require('crypto'); +const crypto = require('crypto'); // Small stream to buffer converter function Stream2buffer(callback) { @@ -28,7 +28,7 @@ Stream2buffer.prototype._write = function(data, encodeing, done) { if (!common.hasFipsCrypto) { // Create an md5 hash of "Hallo world" - var hasher1 = crypto.createHash('md5'); + const hasher1 = crypto.createHash('md5'); hasher1.pipe(new Stream2buffer(common.mustCall(function end(err, hash) { assert.strictEqual(err, null); assert.strictEqual( diff --git a/test/parallel/test-crypto-verify-failure.js b/test/parallel/test-crypto-verify-failure.js index 415e13ff64e640..fdf0d6f6456dac 100644 --- a/test/parallel/test-crypto-verify-failure.js +++ b/test/parallel/test-crypto-verify-failure.js @@ -1,20 +1,20 @@ 'use strict'; -var common = require('../common'); +const common = require('../common'); if (!common.hasCrypto) { common.skip('missing crypto'); return; } -var crypto = require('crypto'); -var tls = require('tls'); +const crypto = require('crypto'); +const tls = require('tls'); crypto.DEFAULT_ENCODING = 'buffer'; -var fs = require('fs'); +const fs = require('fs'); -var certPem = fs.readFileSync(common.fixturesDir + '/test_cert.pem', 'ascii'); +const certPem = fs.readFileSync(common.fixturesDir + '/test_cert.pem', 'ascii'); -var options = { +const options = { key: fs.readFileSync(common.fixturesDir + '/keys/agent1-key.pem'), cert: fs.readFileSync(common.fixturesDir + '/keys/agent1-cert.pem') }; diff --git a/test/parallel/test-cwd-enoent-repl.js b/test/parallel/test-cwd-enoent-repl.js index 1d03bd3e9112c1..942fc07b64a90b 100644 --- a/test/parallel/test-cwd-enoent-repl.js +++ b/test/parallel/test-cwd-enoent-repl.js @@ -1,8 +1,8 @@ 'use strict'; -var common = require('../common'); -var assert = require('assert'); -var fs = require('fs'); -var spawn = require('child_process').spawn; +const common = require('../common'); +const assert = require('assert'); +const fs = require('fs'); +const spawn = require('child_process').spawn; // Fails with EINVAL on SmartOS, EBUSY on Windows, EBUSY on AIX. if (common.isSunOS || common.isWindows || common.isAix) { @@ -10,13 +10,13 @@ if (common.isSunOS || common.isWindows || common.isAix) { return; } -var dirname = common.tmpDir + '/cwd-does-not-exist-' + process.pid; +const dirname = common.tmpDir + '/cwd-does-not-exist-' + process.pid; common.refreshTmpDir(); fs.mkdirSync(dirname); process.chdir(dirname); fs.rmdirSync(dirname); -var proc = spawn(process.execPath, ['--interactive']); +const proc = spawn(process.execPath, ['--interactive']); proc.stdout.pipe(process.stdout); proc.stderr.pipe(process.stderr); proc.stdin.write('require("path");\n'); diff --git a/test/parallel/test-cwd-enoent.js b/test/parallel/test-cwd-enoent.js index c671ef2be4619e..736121a7c89d6e 100644 --- a/test/parallel/test-cwd-enoent.js +++ b/test/parallel/test-cwd-enoent.js @@ -1,8 +1,8 @@ 'use strict'; -var common = require('../common'); -var assert = require('assert'); -var fs = require('fs'); -var spawn = require('child_process').spawn; +const common = require('../common'); +const assert = require('assert'); +const fs = require('fs'); +const spawn = require('child_process').spawn; // Fails with EINVAL on SmartOS, EBUSY on Windows, EBUSY on AIX. if (common.isSunOS || common.isWindows || common.isAix) { @@ -10,13 +10,13 @@ if (common.isSunOS || common.isWindows || common.isAix) { return; } -var dirname = common.tmpDir + '/cwd-does-not-exist-' + process.pid; +const dirname = common.tmpDir + '/cwd-does-not-exist-' + process.pid; common.refreshTmpDir(); fs.mkdirSync(dirname); process.chdir(dirname); fs.rmdirSync(dirname); -var proc = spawn(process.execPath, ['-e', '0']); +const proc = spawn(process.execPath, ['-e', '0']); proc.stdout.pipe(process.stdout); proc.stderr.pipe(process.stderr); diff --git a/test/parallel/test-debug-brk.js b/test/parallel/test-debug-brk.js index 89d9c892145676..769e3a6c5b504e 100644 --- a/test/parallel/test-debug-brk.js +++ b/test/parallel/test-debug-brk.js @@ -7,13 +7,13 @@ let run = () => {}; function test(extraArgs, stdoutPattern) { const next = run; run = () => { - var procStdout = ''; - var procStderr = ''; - var agentStdout = ''; - var debuggerListening = false; - var outputMatched = false; - var needToSpawnAgent = true; - var needToExit = true; + let procStdout = ''; + let procStderr = ''; + let agentStdout = ''; + let debuggerListening = false; + let outputMatched = false; + let needToSpawnAgent = true; + let needToExit = true; const procArgs = [`--debug-brk=${common.PORT}`].concat(extraArgs); const proc = spawn(process.execPath, procArgs); diff --git a/test/parallel/test-debug-port-from-cmdline.js b/test/parallel/test-debug-port-from-cmdline.js index cd92764df29c8e..f81f683c880b08 100644 --- a/test/parallel/test-debug-port-from-cmdline.js +++ b/test/parallel/test-debug-port-from-cmdline.js @@ -1,17 +1,17 @@ 'use strict'; -var common = require('../common'); -var assert = require('assert'); -var spawn = require('child_process').spawn; +const common = require('../common'); +const assert = require('assert'); +const spawn = require('child_process').spawn; -var debugPort = common.PORT; -var args = ['--interactive', '--debug-port=' + debugPort]; -var childOptions = { stdio: ['pipe', 'pipe', 'pipe', 'ipc'] }; -var child = spawn(process.execPath, args, childOptions); +const debugPort = common.PORT; +const args = ['--interactive', '--debug-port=' + debugPort]; +const childOptions = { stdio: ['pipe', 'pipe', 'pipe', 'ipc'] }; +const child = spawn(process.execPath, args, childOptions); child.stdin.write("process.send({ msg: 'childready' });\n"); child.stderr.on('data', function(data) { - var lines = data.toString().replace(/\r/g, '').trim().split('\n'); + const lines = data.toString().replace(/\r/g, '').trim().split('\n'); lines.forEach(processStderrLine); }); @@ -26,7 +26,7 @@ process.on('exit', function() { assertOutputLines(); }); -var outputLines = []; +const outputLines = []; function processStderrLine(line) { console.log('> ' + line); outputLines.push(line); @@ -37,12 +37,12 @@ function processStderrLine(line) { } function assertOutputLines() { - var expectedLines = [ + const expectedLines = [ 'Starting debugger agent.', 'Debugger listening on (\\[::\\]|0\\.0\\.0\\.0):' + debugPort, ]; assert.strictEqual(outputLines.length, expectedLines.length); - for (var i = 0; i < expectedLines.length; i++) + for (let i = 0; i < expectedLines.length; i++) assert(RegExp(expectedLines[i]).test(outputLines[i])); } diff --git a/test/parallel/test-debug-signal-cluster.js b/test/parallel/test-debug-signal-cluster.js index d5319a616939d1..22bfdfb09dbdc5 100644 --- a/test/parallel/test-debug-signal-cluster.js +++ b/test/parallel/test-debug-signal-cluster.js @@ -12,9 +12,9 @@ const options = { stdio: ['inherit', 'inherit', 'pipe', 'ipc'] }; const child = spawn(process.execPath, args, options); const outputLines = []; -var waitingForDebuggers = false; +let waitingForDebuggers = false; -var pids; +let pids; child.stderr.on('data', function(data) { const lines = data.toString().replace(/\r/g, '').trim().split('\n'); @@ -76,6 +76,6 @@ function assertOutputLines() { expectedLines.sort(); assert.equal(outputLines.length, expectedLines.length); - for (var i = 0; i < expectedLines.length; i++) + for (let i = 0; i < expectedLines.length; i++) assert(RegExp(expectedLines[i]).test(outputLines[i])); } diff --git a/test/parallel/test-debug-uncaught-exception-async.js b/test/parallel/test-debug-uncaught-exception-async.js index 29947cfd92fbb9..8d0d7957c22e12 100644 --- a/test/parallel/test-debug-uncaught-exception-async.js +++ b/test/parallel/test-debug-uncaught-exception-async.js @@ -7,7 +7,7 @@ const spawn = require('child_process').spawn; const emitUncaught = path.join(common.fixturesDir, 'debug-uncaught-async.js'); const result = spawn(process.execPath, [emitUncaught], {encoding: 'utf8'}); -var stderr = ''; +let stderr = ''; result.stderr.on('data', (data) => { stderr += data; }); diff --git a/test/parallel/test-debug-usage.js b/test/parallel/test-debug-usage.js index 5406a82cc8d229..67ee08ce729431 100644 --- a/test/parallel/test-debug-usage.js +++ b/test/parallel/test-debug-usage.js @@ -10,7 +10,7 @@ const expectedUsageMessage = `Usage: node debug script.js node debug : node debug -p `; -var actualUsageMessage = ''; +let actualUsageMessage = ''; child.stderr.on('data', function(data) { actualUsageMessage += data.toString(); }); diff --git a/test/parallel/test-debugger-pid.js b/test/parallel/test-debugger-pid.js index 7d03b0fc5c2308..7617e84bb409d8 100644 --- a/test/parallel/test-debugger-pid.js +++ b/test/parallel/test-debugger-pid.js @@ -3,15 +3,15 @@ const common = require('../common'); const assert = require('assert'); const spawn = require('child_process').spawn; -var buffer = ''; +let buffer = ''; // connect to debug agent -var interfacer = spawn(process.execPath, ['debug', '-p', '655555']); +const interfacer = spawn(process.execPath, ['debug', '-p', '655555']); console.error(process.execPath, 'debug', '-p', '655555'); interfacer.stdout.setEncoding('utf-8'); interfacer.stderr.setEncoding('utf-8'); -var onData = function(data) { +const onData = function(data) { data = (buffer + data).split('\n'); buffer = data.pop(); data.forEach(function(line) { @@ -21,9 +21,9 @@ var onData = function(data) { interfacer.stdout.on('data', onData); interfacer.stderr.on('data', onData); -var lineCount = 0; +let lineCount = 0; interfacer.on('line', function(line) { - var expected; + let expected; const pid = interfacer.pid; if (common.isWindows) { switch (++lineCount) { diff --git a/test/parallel/test-debugger-repeat-last.js b/test/parallel/test-debugger-repeat-last.js index 7a43bbb6c767ae..cacedbbd7c6e99 100644 --- a/test/parallel/test-debugger-repeat-last.js +++ b/test/parallel/test-debugger-repeat-last.js @@ -17,11 +17,11 @@ const args = [ const proc = spawn(process.execPath, args, { stdio: 'pipe' }); proc.stdout.setEncoding('utf8'); -var stdout = ''; +let stdout = ''; -var sentCommand = false; -var sentEmpty = false; -var sentExit = false; +let sentCommand = false; +let sentEmpty = false; +let sentExit = false; proc.stdout.on('data', (data) => { stdout += data; diff --git a/test/parallel/test-delayed-require.js b/test/parallel/test-delayed-require.js index bc110388fc0380..8e07367eb47366 100644 --- a/test/parallel/test-delayed-require.js +++ b/test/parallel/test-delayed-require.js @@ -1,7 +1,7 @@ 'use strict'; -var common = require('../common'); -var path = require('path'); -var assert = require('assert'); +const common = require('../common'); +const path = require('path'); +const assert = require('assert'); setTimeout(common.mustCall(function() { const a = require(path.join(common.fixturesDir, 'a')); diff --git a/test/parallel/test-dgram-address.js b/test/parallel/test-dgram-address.js index 38729de67098da..09c5ba31f6c5b5 100644 --- a/test/parallel/test-dgram-address.js +++ b/test/parallel/test-dgram-address.js @@ -1,14 +1,14 @@ 'use strict'; -var common = require('../common'); -var assert = require('assert'); -var dgram = require('dgram'); +const common = require('../common'); +const assert = require('assert'); +const dgram = require('dgram'); // IPv4 Test -var socket_ipv4 = dgram.createSocket('udp4'); -var family_ipv4 = 'IPv4'; +const socket_ipv4 = dgram.createSocket('udp4'); +const family_ipv4 = 'IPv4'; socket_ipv4.on('listening', function() { - var address_ipv4 = socket_ipv4.address(); + const address_ipv4 = socket_ipv4.address(); assert.strictEqual(address_ipv4.address, common.localhostIPv4); assert.strictEqual(typeof address_ipv4.port, 'number'); assert.ok(isFinite(address_ipv4.port)); @@ -25,12 +25,12 @@ socket_ipv4.on('error', function(e) { socket_ipv4.bind(0, common.localhostIPv4); // IPv6 Test -var localhost_ipv6 = '::1'; -var socket_ipv6 = dgram.createSocket('udp6'); -var family_ipv6 = 'IPv6'; +const localhost_ipv6 = '::1'; +const socket_ipv6 = dgram.createSocket('udp6'); +const family_ipv6 = 'IPv6'; socket_ipv6.on('listening', function() { - var address_ipv6 = socket_ipv6.address(); + const address_ipv6 = socket_ipv6.address(); assert.strictEqual(address_ipv6.address, localhost_ipv6); assert.strictEqual(typeof address_ipv6.port, 'number'); assert.ok(isFinite(address_ipv6.port)); diff --git a/test/parallel/test-dgram-bind.js b/test/parallel/test-dgram-bind.js index 2d11fba6443ad8..f4624358a4fab4 100644 --- a/test/parallel/test-dgram-bind.js +++ b/test/parallel/test-dgram-bind.js @@ -3,7 +3,7 @@ const common = require('../common'); const assert = require('assert'); const dgram = require('dgram'); -var socket = dgram.createSocket('udp4'); +const socket = dgram.createSocket('udp4'); socket.on('listening', common.mustCall(() => { assert.throws(() => { @@ -13,6 +13,6 @@ socket.on('listening', common.mustCall(() => { socket.close(); })); -var result = socket.bind(); // should not throw +const result = socket.bind(); // should not throw assert.strictEqual(result, socket); // should have returned itself diff --git a/test/parallel/test-dgram-bytes-length.js b/test/parallel/test-dgram-bytes-length.js index 8e2233e9c4daad..07a8bb0e43452b 100644 --- a/test/parallel/test-dgram-bytes-length.js +++ b/test/parallel/test-dgram-bytes-length.js @@ -1,10 +1,10 @@ 'use strict'; require('../common'); -var assert = require('assert'); -var dgram = require('dgram'); +const assert = require('assert'); +const dgram = require('dgram'); -var message = Buffer.from('Some bytes'); -var client = dgram.createSocket('udp4'); +const message = Buffer.from('Some bytes'); +const client = dgram.createSocket('udp4'); client.send( message, 0, diff --git a/test/parallel/test-dgram-close-is-not-callback.js b/test/parallel/test-dgram-close-is-not-callback.js index 61e08200360452..d0f23d5808c7b7 100644 --- a/test/parallel/test-dgram-close-is-not-callback.js +++ b/test/parallel/test-dgram-close-is-not-callback.js @@ -1,10 +1,10 @@ 'use strict'; -var common = require('../common'); -var dgram = require('dgram'); +const common = require('../common'); +const dgram = require('dgram'); -var buf = Buffer.alloc(1024, 42); +const buf = Buffer.alloc(1024, 42); -var socket = dgram.createSocket('udp4'); +const socket = dgram.createSocket('udp4'); socket.send(buf, 0, buf.length, common.PORT, 'localhost'); diff --git a/test/parallel/test-dgram-close.js b/test/parallel/test-dgram-close.js index 41d28553ca8cb7..43047db697a2eb 100644 --- a/test/parallel/test-dgram-close.js +++ b/test/parallel/test-dgram-close.js @@ -6,10 +6,10 @@ const common = require('../common'); const assert = require('assert'); const dgram = require('dgram'); -var buf = Buffer.alloc(1024, 42); +const buf = Buffer.alloc(1024, 42); -var socket = dgram.createSocket('udp4'); -var handle = socket._handle; +let socket = dgram.createSocket('udp4'); +const handle = socket._handle; socket.send(buf, 0, buf.length, common.PORT, 'localhost'); assert.strictEqual(socket.close(common.mustCall(function() {})), socket); diff --git a/test/parallel/test-dgram-exclusive-implicit-bind.js b/test/parallel/test-dgram-exclusive-implicit-bind.js index 97fd6bed5d6e33..d6ec7097e40827 100644 --- a/test/parallel/test-dgram-exclusive-implicit-bind.js +++ b/test/parallel/test-dgram-exclusive-implicit-bind.js @@ -40,11 +40,11 @@ const dgram = require('dgram'); // with ENOTSUP. if (cluster.isMaster) { - var messages = 0; + let messages = 0; const ports = {}; const pids = []; - var target = dgram.createSocket('udp4'); + const target = dgram.createSocket('udp4'); const done = common.mustCall(function() { cluster.disconnect(); @@ -84,7 +84,7 @@ if (cluster.isMaster) { } const source = dgram.createSocket('udp4'); -var interval; +let interval; source.on('close', function() { clearInterval(interval); diff --git a/test/parallel/test-dgram-implicit-bind.js b/test/parallel/test-dgram-implicit-bind.js index 8cbb3f771e2d47..bfc86803b463f1 100644 --- a/test/parallel/test-dgram-implicit-bind.js +++ b/test/parallel/test-dgram-implicit-bind.js @@ -1,10 +1,10 @@ 'use strict'; const common = require('../common'); -var dgram = require('dgram'); +const dgram = require('dgram'); -var source = dgram.createSocket('udp4'); -var target = dgram.createSocket('udp4'); -var messages = 0; +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; diff --git a/test/parallel/test-dgram-listen-after-bind.js b/test/parallel/test-dgram-listen-after-bind.js index 498a17a0e5b053..e60687649cda30 100644 --- a/test/parallel/test-dgram-listen-after-bind.js +++ b/test/parallel/test-dgram-listen-after-bind.js @@ -1,14 +1,14 @@ 'use strict'; require('../common'); -var assert = require('assert'); -var dgram = require('dgram'); +const assert = require('assert'); +const dgram = require('dgram'); -var socket = dgram.createSocket('udp4'); +const socket = dgram.createSocket('udp4'); socket.bind(); -var fired = false; -var timer = setTimeout(function() { +let fired = false; +const timer = setTimeout(function() { socket.close(); }, 100); diff --git a/test/parallel/test-dgram-oob-buffer.js b/test/parallel/test-dgram-oob-buffer.js index ec5c0f943cb7df..5d869114b3a4e4 100644 --- a/test/parallel/test-dgram-oob-buffer.js +++ b/test/parallel/test-dgram-oob-buffer.js @@ -3,11 +3,11 @@ // unreachable host. This error can be reported by sendto() and even by // recvfrom(). Node should not propagate this error to the user. -var common = require('../common'); -var dgram = require('dgram'); +const common = require('../common'); +const dgram = require('dgram'); -var socket = dgram.createSocket('udp4'); -var buf = Buffer.from([1, 2, 3, 4]); +const socket = dgram.createSocket('udp4'); +const buf = Buffer.from([1, 2, 3, 4]); function ok() {} socket.send(buf, 0, 0, common.PORT, '127.0.0.1', ok); // useful? no diff --git a/test/parallel/test-dgram-regress-4496.js b/test/parallel/test-dgram-regress-4496.js index 4bdd0d6520d7dc..b4ec8195d7e7f0 100644 --- a/test/parallel/test-dgram-regress-4496.js +++ b/test/parallel/test-dgram-regress-4496.js @@ -2,11 +2,11 @@ // Remove this test once we support sending strings. require('../common'); -var assert = require('assert'); -var dgram = require('dgram'); +const assert = require('assert'); +const dgram = require('dgram'); // Should throw but not crash. -var socket = dgram.createSocket('udp4'); +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/test/parallel/test-dgram-send-bad-arguments.js b/test/parallel/test-dgram-send-bad-arguments.js index a3918697addc4e..c7ec6b51eecfa8 100644 --- a/test/parallel/test-dgram-send-bad-arguments.js +++ b/test/parallel/test-dgram-send-bad-arguments.js @@ -1,11 +1,11 @@ 'use strict'; require('../common'); -var assert = require('assert'); -var dgram = require('dgram'); +const assert = require('assert'); +const dgram = require('dgram'); -var buf = Buffer.from('test'); -var host = '127.0.0.1'; -var sock = dgram.createSocket('udp4'); +const buf = Buffer.from('test'); +const host = '127.0.0.1'; +const sock = dgram.createSocket('udp4'); assert.throws(function() { sock.send(); diff --git a/test/parallel/test-dgram-send-empty-array.js b/test/parallel/test-dgram-send-empty-array.js index 442803e6db8632..1bfcacd9a40497 100644 --- a/test/parallel/test-dgram-send-empty-array.js +++ b/test/parallel/test-dgram-send-empty-array.js @@ -12,7 +12,7 @@ const dgram = require('dgram'); const client = dgram.createSocket('udp4'); -var interval; +let interval; client.on('message', common.mustCall(function onMessage(buf, info) { const expected = Buffer.alloc(0); diff --git a/test/parallel/test-dgram-send-empty-buffer.js b/test/parallel/test-dgram-send-empty-buffer.js index 70e7e46e0a327e..56a0383eb14c9e 100644 --- a/test/parallel/test-dgram-send-empty-buffer.js +++ b/test/parallel/test-dgram-send-empty-buffer.js @@ -21,7 +21,7 @@ client.bind(0, common.mustCall(function() { })); const buf = Buffer.alloc(0); - var interval = setInterval(function() { + let interval = setInterval(function() { client.send(buf, 0, 0, port, '127.0.0.1', common.mustCall(function() {})); }, 10); })); diff --git a/test/parallel/test-dgram-unref.js b/test/parallel/test-dgram-unref.js index 1b92428a38e18b..da148d3216582d 100644 --- a/test/parallel/test-dgram-unref.js +++ b/test/parallel/test-dgram-unref.js @@ -1,6 +1,6 @@ 'use strict'; const common = require('../common'); -var dgram = require('dgram'); +const dgram = require('dgram'); { // Test the case of unref()'ing a socket with a handle. diff --git a/test/parallel/test-dh-padding.js b/test/parallel/test-dh-padding.js index a9cd95225abedb..72d54798d79da0 100644 --- a/test/parallel/test-dh-padding.js +++ b/test/parallel/test-dh-padding.js @@ -1,9 +1,10 @@ 'use strict'; const common = require('../common'); -var assert = require('assert'); +const assert = require('assert'); +let crypto; try { - var crypto = require('crypto'); + crypto = require('crypto'); } catch (e) { common.skip('node compiled without OpenSSL.'); return; @@ -25,13 +26,13 @@ try { * crypto = require('crypto'); * * for (;;) { - * var a = crypto.getDiffieHellman('modp14'), - * var b = crypto.getDiffieHellman('modp14'); + * let a = crypto.getDiffieHellman('modp14'), + * let b = crypto.getDiffieHellman('modp14'); * * a.generateKeys(); * b.generateKeys(); * - * var aSecret = a.computeSecret(b.getPublicKey()).toString('hex'); + * let aSecret = a.computeSecret(b.getPublicKey()).toString('hex'); * console.log("A public: " + a.getPublicKey().toString('hex')); * console.log("A private: " + a.getPrivateKey().toString('hex')); * console.log("B public: " + b.getPublicKey().toString('hex')); @@ -45,7 +46,7 @@ try { * } */ -var apub = +const apub = '5484455905d3eff34c70980e871f27f05448e66f5a6efbb97cbcba4e927196c2bd9ea272cded91\ 10a4977afa8d9b16c9139a444ed2d954a794650e5d7cb525204f385e1af81530518563822ecd0f9\ 524a958d02b3c269e79d6d69850f0968ad567a4404fbb0b19efc8bc73e267b6136b88cafb33299f\ @@ -53,7 +54,7 @@ f7c7cace3ffab1a88c2c9ee841f88b4c3679b4efc465f5c93cca11d487be57373e4c5926f634c4e\ efee6721d01db91cd66321615b2522f96368dbc818875d422140d0edf30bdb97d9721feddcb9ff6\ 453741a4f687ee46fc54bf1198801f1210ac789879a5ee123f79e2d2ce1209df2445d32166bc9e4\ 8f89e944ec9c3b2e16c8066cd8eebd4e33eb941'; -var bpub = +const bpub = '3fca64510e36bc7da8a3a901c7b74c2eabfa25deaf7cbe1d0c50235866136ad677317279e1fb0\ 06e9c0a07f63e14a3363c8e016fbbde2b2c7e79fed1cc3e08e95f7459f547a8cd0523ee9dc744d\ e5a956d92b937db4448917e1f6829437f05e408ee7aea70c0362b37370c7c75d14449d8b2d2133\ @@ -61,7 +62,7 @@ e5a956d92b937db4448917e1f6829437f05e408ee7aea70c0362b37370c7c75d14449d8b2d2133\ 788a1fdc6cdf17f5fffaf024ce8711a2ebde0b52e9f1cb56224483826d6e5ac6ecfaae07b75d20\ 6e8ac97f5be1a5b68f20382f2a7dac189cf169325c4cf845b26a0cd616c31fec905c5d9035e5f7\ 8e9880c812374ac0f3ca3d365f06e4be526b5affd4b79'; -var apriv = +const apriv = '62411e34704637d99c6c958a7db32ac22fcafafbe1c33d2cfdb76e12ded41f38fc16b792b9041\ 2e4c82755a3815ba52f780f0ee296ad46e348fc4d1dcd6b64f4eea1b231b2b7d95c5b1c2e26d34\ 83520558b9860a6eb668f01422a54e6604aa7702b4e67511397ef3ecb912bff1a83899c5a5bfb2\ @@ -69,7 +70,7 @@ var apriv = 08c3b3e6fc60668f7be81cce6784482af228dd7f489005253a165e292802cfd0399924f6c56827\ 7012f68255207722355634290acc7fddeefbba75650a85ece95b6a12de67eac016ba78960108dd\ 5dbadfaa43cc9fed515a1f307b7d90ae0623bc7b8cefb'; -var secret = +const secret = '00c37b1e06a436d6717816a40e6d72907a6f255638b93032267dcb9a5f0b4a9aa0236f3dce63b\ 1c418c60978a00acd1617dfeecf1661d8a3fafb4d0d8824386750f4853313400e7e4afd22847e4\ fa56bc9713872021265111906673b38db83d10cbfa1dea3b6b4c97c8655f4ae82125281af7f234\ @@ -79,7 +80,7 @@ dc8fe984ddaf532fc1531ce43155fa0ab32532bf1ece5356b8a3447b5267798a904f16f3f4e635\ 8612314311231f905f91c63a1aea52e0b60cead8b57df'; /* FIPS-friendly 2048 bit prime */ -var p = crypto.createDiffieHellman( +const p = crypto.createDiffieHellman( crypto.getDiffieHellman('modp14').getPrime()); p.setPublicKey(apub, 'hex'); diff --git a/test/parallel/test-domain-abort-on-uncaught.js b/test/parallel/test-domain-abort-on-uncaught.js index d61debc06067f6..f754541f37462b 100644 --- a/test/parallel/test-domain-abort-on-uncaught.js +++ b/test/parallel/test-domain-abort-on-uncaught.js @@ -9,7 +9,7 @@ const assert = require('assert'); const domain = require('domain'); const child_process = require('child_process'); -var errorHandlerCalled = false; +let errorHandlerCalled = false; const tests = [ function nextTick() { @@ -90,7 +90,7 @@ const tests = [ }); d.run(function() { - var fs = require('fs'); + const fs = require('fs'); fs.exists('/non/existing/file', function onExists(exists) { throw new Error('boom!'); }); @@ -212,7 +212,7 @@ const tests = [ d.run(function() { d2.run(function() { - var fs = require('fs'); + const fs = require('fs'); fs.exists('/non/existing/file', function onExists(exists) { throw new Error('boom!'); }); @@ -232,7 +232,7 @@ if (process.argv[2] === 'child') { } else { tests.forEach(function(test, testIndex) { - var testCmd = ''; + let testCmd = ''; if (!common.isWindows) { // Do not create core files, as it can take a lot of disk space on // continuous testing and developers' machines @@ -245,7 +245,7 @@ if (process.argv[2] === 'child') { testCmd += ' ' + 'child'; testCmd += ' ' + testIndex; - var child = child_process.exec(testCmd); + const child = child_process.exec(testCmd); child.on('exit', function onExit(code, signal) { assert.strictEqual(code, 0, 'Test at index ' + testIndex + diff --git a/test/parallel/test-domain-crypto.js b/test/parallel/test-domain-crypto.js index 1109591fee9631..dfa2636816aff4 100644 --- a/test/parallel/test-domain-crypto.js +++ b/test/parallel/test-domain-crypto.js @@ -2,8 +2,9 @@ const common = require('../common'); +let crypto; try { - var crypto = require('crypto'); + crypto = require('crypto'); } catch (e) { common.skip('node compiled without OpenSSL.'); return; diff --git a/test/parallel/test-domain-enter-exit.js b/test/parallel/test-domain-enter-exit.js index 2973e833f3a1b9..4a11c3a206a5fe 100644 --- a/test/parallel/test-domain-enter-exit.js +++ b/test/parallel/test-domain-enter-exit.js @@ -2,8 +2,8 @@ // Make sure the domain stack is a stack require('../common'); -var assert = require('assert'); -var domain = require('domain'); +const assert = require('assert'); +const domain = require('domain'); function names(array) { return array.map(function(d) { @@ -11,11 +11,11 @@ function names(array) { }).join(', '); } -var a = domain.create(); +const a = domain.create(); a.name = 'a'; -var b = domain.create(); +const b = domain.create(); b.name = 'b'; -var c = domain.create(); +const c = domain.create(); c.name = 'c'; a.enter(); // push diff --git a/test/parallel/test-domain-exit-dispose-again.js b/test/parallel/test-domain-exit-dispose-again.js index b1911bb40e0c93..542950f8af428e 100644 --- a/test/parallel/test-domain-exit-dispose-again.js +++ b/test/parallel/test-domain-exit-dispose-again.js @@ -6,22 +6,22 @@ // the same invocation of listOnTimeout, _are_ called. require('../common'); -var assert = require('assert'); -var domain = require('domain'); -var disposalFailed = false; +const assert = require('assert'); +const domain = require('domain'); +let disposalFailed = false; // Repeatedly schedule a timer with a delay different than the timers attached // to a domain that will eventually be disposed to make sure that they are // called, regardless of what happens with those timers attached to domains // that will eventually be disposed. -var a = 0; +let a = 0; log(); function log() { console.log(a++, process.domain); if (a < 10) setTimeout(log, 20); } -var secondTimerRan = false; +let secondTimerRan = false; // Use the same timeout duration for both "firstTimer" and "secondTimer" // callbacks so that they are called during the same invocation of the diff --git a/test/parallel/test-domain-exit-dispose.js b/test/parallel/test-domain-exit-dispose.js index 508cec18dccb7d..e1797cb660a0c0 100644 --- a/test/parallel/test-domain-exit-dispose.js +++ b/test/parallel/test-domain-exit-dispose.js @@ -1,11 +1,11 @@ 'use strict'; require('../common'); -var common = require('../common'); -var assert = require('assert'); -var domain = require('domain'); +const common = require('../common'); +const assert = require('assert'); +const domain = require('domain'); // no matter what happens, we should increment a 10 times. -var a = 0; +let a = 0; log(); function log() { console.log(a++, process.domain); @@ -15,7 +15,7 @@ function log() { // in 50ms we'll throw an error. setTimeout(err, 50); function err() { - var d = domain.create(); + const d = domain.create(); d.on('error', handle); d.run(err2); diff --git a/test/parallel/test-domain-http-server.js b/test/parallel/test-domain-http-server.js index 26264e8ec987d8..94bafe7f0e3d5e 100644 --- a/test/parallel/test-domain-http-server.js +++ b/test/parallel/test-domain-http-server.js @@ -1,17 +1,17 @@ 'use strict'; require('../common'); -var domain = require('domain'); -var http = require('http'); -var assert = require('assert'); +const domain = require('domain'); +const http = require('http'); +const assert = require('assert'); -var objects = { foo: 'bar', baz: {}, num: 42, arr: [1, 2, 3] }; +const objects = { foo: 'bar', baz: {}, num: 42, arr: [1, 2, 3] }; objects.baz.asdf = objects; -var serverCaught = 0; -var clientCaught = 0; +let serverCaught = 0; +let clientCaught = 0; -var server = http.createServer(function(req, res) { - var dom = domain.create(); +const server = http.createServer(function(req, res) { + const dom = domain.create(); req.resume(); dom.add(req); dom.add(res); @@ -27,7 +27,7 @@ var server = http.createServer(function(req, res) { dom.run(function() { // Now, an action that has the potential to fail! // if you request 'baz', then it'll throw a JSON circular ref error. - var data = JSON.stringify(objects[req.url.replace(/[^a-z]/g, '')]); + const data = JSON.stringify(objects[req.url.replace(/[^a-z]/g, '')]); // this line will throw if you pick an unknown key assert.notStrictEqual(data, undefined, 'Data should not be undefined'); @@ -43,8 +43,8 @@ function next() { const port = this.address().port; console.log('listening on localhost:%d', port); - var requests = 0; - var responses = 0; + let requests = 0; + let responses = 0; makeReq('/'); makeReq('/foo'); @@ -55,14 +55,14 @@ function next() { function makeReq(p) { requests++; - var dom = domain.create(); + const dom = domain.create(); dom.on('error', function(er) { clientCaught++; console.log('client error', er); req.socket.destroy(); }); - var req = http.get({ host: 'localhost', port: port, path: p }); + let req = http.get({ host: 'localhost', port: port, path: p }); dom.add(req); req.on('response', function(res) { responses++; @@ -74,7 +74,7 @@ function next() { } dom.add(res); - var d = ''; + let d = ''; res.on('data', function(c) { d += c; }); diff --git a/test/parallel/test-domain-implicit-fs.js b/test/parallel/test-domain-implicit-fs.js index a92653aff1de1c..8039e788312ec9 100644 --- a/test/parallel/test-domain-implicit-fs.js +++ b/test/parallel/test-domain-implicit-fs.js @@ -2,10 +2,10 @@ // Simple tests of most basic domain functionality. const common = require('../common'); -var assert = require('assert'); -var domain = require('domain'); +const assert = require('assert'); +const domain = require('domain'); -var d = new domain.Domain(); +const d = new domain.Domain(); d.on('error', common.mustCall(function(er) { console.error('caught', er); @@ -28,7 +28,7 @@ d.on('error', common.mustCall(function(er) { // handles are created. d.run(function() { setTimeout(function() { - var fs = require('fs'); + const fs = require('fs'); fs.readdir(__dirname, function() { fs.open('this file does not exist', 'r', function(er) { if (er) throw er; diff --git a/test/parallel/test-domain-multi.js b/test/parallel/test-domain-multi.js index e8c5d4924cb553..a38b6a2bc42bdf 100644 --- a/test/parallel/test-domain-multi.js +++ b/test/parallel/test-domain-multi.js @@ -5,14 +5,14 @@ const common = require('../common'); const domain = require('domain'); const http = require('http'); -var a = domain.create(); +const a = domain.create(); a.enter(); // this will be our "root" domain a.on('error', common.fail); const server = http.createServer((req, res) => { // child domain of a. - var b = domain.create(); + const b = domain.create(); a.add(b); // treat these EE objects as if they are a part of the b domain diff --git a/test/parallel/test-domain-nested-throw.js b/test/parallel/test-domain-nested-throw.js index 69a80b7ab104d0..39507446a3acfc 100644 --- a/test/parallel/test-domain-nested-throw.js +++ b/test/parallel/test-domain-nested-throw.js @@ -1,10 +1,10 @@ 'use strict'; require('../common'); -var assert = require('assert'); +const assert = require('assert'); -var domain = require('domain'); +const domain = require('domain'); -var dispose; +let dispose; switch (process.argv[2]) { case 'true': dispose = true; @@ -18,10 +18,10 @@ switch (process.argv[2]) { } function parent() { - var node = process.execPath; - var spawn = require('child_process').spawn; - var opt = { stdio: 'inherit' }; - var child = spawn(node, [__filename, 'true'], opt); + const node = process.execPath; + const spawn = require('child_process').spawn; + const opt = { stdio: 'inherit' }; + let child = spawn(node, [__filename, 'true'], opt); child.on('exit', function(c) { assert(!c); child = spawn(node, [__filename, 'false'], opt); @@ -32,11 +32,11 @@ function parent() { }); } -var gotDomain1Error = false; -var gotDomain2Error = false; +let gotDomain1Error = false; +let gotDomain2Error = false; -var threw1 = false; -var threw2 = false; +let threw1 = false; +let threw2 = false; function throw1() { threw1 = true; @@ -49,7 +49,7 @@ function throw2() { } function inner(throw1, throw2) { - var domain1 = domain.createDomain(); + const domain1 = domain.createDomain(); domain1.on('error', function(err) { if (gotDomain1Error) { @@ -67,7 +67,7 @@ function inner(throw1, throw2) { } function outer() { - var domain2 = domain.createDomain(); + const domain2 = domain.createDomain(); domain2.on('error', function(err) { if (gotDomain2Error) { diff --git a/test/parallel/test-domain-nested.js b/test/parallel/test-domain-nested.js index 68c56d0c3c8b2c..d0618b5bad724b 100644 --- a/test/parallel/test-domain-nested.js +++ b/test/parallel/test-domain-nested.js @@ -2,8 +2,8 @@ // Make sure that the nested domains don't cause the domain stack to grow require('../common'); -var assert = require('assert'); -var domain = require('domain'); +const assert = require('assert'); +const domain = require('domain'); process.on('exit', function(c) { assert.equal(domain._stack.length, 0); diff --git a/test/parallel/test-domain-no-error-handler-abort-on-uncaught-5.js b/test/parallel/test-domain-no-error-handler-abort-on-uncaught-5.js index 78ef3662a20229..ade72147e148e7 100644 --- a/test/parallel/test-domain-no-error-handler-abort-on-uncaught-5.js +++ b/test/parallel/test-domain-no-error-handler-abort-on-uncaught-5.js @@ -7,7 +7,7 @@ function test() { const d = domain.create(); d.run(function() { - var fs = require('fs'); + const fs = require('fs'); fs.exists('/non/existing/file', function onExists() { throw new Error('boom!'); }); diff --git a/test/parallel/test-domain-no-error-handler-abort-on-uncaught-9.js b/test/parallel/test-domain-no-error-handler-abort-on-uncaught-9.js index a4eebd50e96388..2e86a2125e86ee 100644 --- a/test/parallel/test-domain-no-error-handler-abort-on-uncaught-9.js +++ b/test/parallel/test-domain-no-error-handler-abort-on-uncaught-9.js @@ -12,7 +12,7 @@ function test() { d.run(function() { d2.run(function() { - var fs = require('fs'); + const fs = require('fs'); fs.exists('/non/existing/file', function onExists() { throw new Error('boom!'); }); diff --git a/test/parallel/test-domain-safe-exit.js b/test/parallel/test-domain-safe-exit.js index 399ae37bcd94c5..bbc3b2fe22cae8 100644 --- a/test/parallel/test-domain-safe-exit.js +++ b/test/parallel/test-domain-safe-exit.js @@ -2,11 +2,11 @@ // Make sure the domain stack doesn't get clobbered by un-matched .exit() require('../common'); -var assert = require('assert'); -var domain = require('domain'); +const assert = require('assert'); +const domain = require('domain'); -var a = domain.create(); -var b = domain.create(); +const a = domain.create(); +const b = domain.create(); a.enter(); // push b.enter(); // push diff --git a/test/parallel/test-domain-stack.js b/test/parallel/test-domain-stack.js index e30d3b21f3af57..43152a4a3bb1c9 100644 --- a/test/parallel/test-domain-stack.js +++ b/test/parallel/test-domain-stack.js @@ -2,9 +2,9 @@ // Make sure that the domain stack doesn't get out of hand. require('../common'); -var domain = require('domain'); +const domain = require('domain'); -var a = domain.create(); +const a = domain.create(); a.name = 'a'; a.on('error', function() { @@ -14,11 +14,11 @@ a.on('error', function() { } }); -var foo = a.bind(function() { +const foo = a.bind(function() { throw new Error('error from foo'); }); -for (var i = 0; i < 1000; i++) { +for (let i = 0; i < 1000; i++) { process.nextTick(foo); } diff --git a/test/parallel/test-domain-throw-error-then-throw-from-uncaught-exception-handler.js b/test/parallel/test-domain-throw-error-then-throw-from-uncaught-exception-handler.js index 48c77bd2d490cc..135877ebae44ff 100644 --- a/test/parallel/test-domain-throw-error-then-throw-from-uncaught-exception-handler.js +++ b/test/parallel/test-domain-throw-error-then-throw-from-uncaught-exception-handler.js @@ -82,7 +82,7 @@ function runTestWithAbortOnUncaughtException() { } function createTestCmdLine(options) { - var testCmd = ''; + let testCmd = ''; if (!common.isWindows) { // Do not create core files, as it can take a lot of disk space on diff --git a/test/parallel/test-domain-timers.js b/test/parallel/test-domain-timers.js index d42afa7471791a..7d51b61fd04be6 100644 --- a/test/parallel/test-domain-timers.js +++ b/test/parallel/test-domain-timers.js @@ -1,11 +1,11 @@ 'use strict'; const common = require('../common'); -var domain = require('domain'); -var assert = require('assert'); +const domain = require('domain'); +const assert = require('assert'); -var timeout; +let timeout; -var timeoutd = domain.create(); +const timeoutd = domain.create(); timeoutd.on('error', common.mustCall(function(e) { assert.strictEqual(e.message, 'Timeout UNREFd', @@ -19,7 +19,7 @@ timeoutd.run(function() { }, 0).unref(); }); -var immediated = domain.create(); +const immediated = domain.create(); immediated.on('error', common.mustCall(function(e) { assert.strictEqual(e.message, 'Immediate Error', diff --git a/test/parallel/test-domain-top-level-error-handler-throw.js b/test/parallel/test-domain-top-level-error-handler-throw.js index b65b94012393c6..53a73eac426232 100644 --- a/test/parallel/test-domain-top-level-error-handler-throw.js +++ b/test/parallel/test-domain-top-level-error-handler-throw.js @@ -13,8 +13,8 @@ const domainErrHandlerExMessage = 'exception from domain error handler'; const internalExMessage = 'You should NOT see me'; if (process.argv[2] === 'child') { - var domain = require('domain'); - var d = domain.create(); + const domain = require('domain'); + const d = domain.create(); d.on('error', function() { throw new Error(domainErrHandlerExMessage); @@ -26,11 +26,11 @@ if (process.argv[2] === 'child') { }); }); } else { - var fork = require('child_process').fork; - var assert = require('assert'); + const fork = require('child_process').fork; + const assert = require('assert'); - var child = fork(process.argv[1], ['child'], {silent: true}); - var stderrOutput = ''; + const child = fork(process.argv[1], ['child'], {silent: true}); + let stderrOutput = ''; if (child) { child.stderr.on('data', function onStderrData(data) { stderrOutput += data.toString(); @@ -45,8 +45,8 @@ if (process.argv[2] === 'child') { }); child.on('exit', function onChildExited(exitCode, signal) { - var expectedExitCode = 7; - var expectedSignal = null; + const expectedExitCode = 7; + const expectedSignal = null; assert.strictEqual(exitCode, expectedExitCode); assert.strictEqual(signal, expectedSignal); diff --git a/test/parallel/test-domain-with-abort-on-uncaught-exception.js b/test/parallel/test-domain-with-abort-on-uncaught-exception.js index 6fb3912e5b8d9c..0da8f1368f7c98 100644 --- a/test/parallel/test-domain-with-abort-on-uncaught-exception.js +++ b/test/parallel/test-domain-with-abort-on-uncaught-exception.js @@ -29,8 +29,8 @@ const fs = require('fs'); const domainErrHandlerExMessage = 'exception from domain error handler'; if (process.argv[2] === 'child') { - var domain = require('domain'); - var d = domain.create(); + const domain = require('domain'); + const d = domain.create(); process.on('uncaughtException', function onUncaughtException() { // The process' uncaughtException event must not be emitted when @@ -80,7 +80,7 @@ if (process.argv[2] === 'child') { throw new Error('Error from domain.run callback'); }); } else { - var exec = require('child_process').exec; + const exec = require('child_process').exec; function testDomainExceptionHandling(cmdLineOption, options) { if (typeof cmdLineOption === 'object') { @@ -88,18 +88,18 @@ if (process.argv[2] === 'child') { cmdLineOption = undefined; } - var throwInDomainErrHandlerOpt; + let throwInDomainErrHandlerOpt; if (options.throwInDomainErrHandler) throwInDomainErrHandlerOpt = 'throwInDomainErrHandler'; - var cmdToExec = ''; + let cmdToExec = ''; if (!common.isWindows) { // Do not create core files, as it can take a lot of disk space on // continuous testing and developers' machines cmdToExec += 'ulimit -c 0 && '; } - var useTryCatchOpt; + let useTryCatchOpt; if (options.useTryCatch) useTryCatchOpt = 'useTryCatch'; @@ -112,7 +112,7 @@ if (process.argv[2] === 'child') { useTryCatchOpt ].join(' '); - var child = exec(cmdToExec); + const child = exec(cmdToExec); if (child) { child.on('exit', function onChildExited(exitCode, signal) { diff --git a/test/parallel/test-domain.js b/test/parallel/test-domain.js index 73ab3b96168930..fe51cc46820770 100644 --- a/test/parallel/test-domain.js +++ b/test/parallel/test-domain.js @@ -6,24 +6,24 @@ const assert = require('assert'); const domain = require('domain'); const events = require('events'); const fs = require('fs'); -var caught = 0; -var expectCaught = 0; +let caught = 0; +let expectCaught = 0; -var d = new domain.Domain(); -var e = new events.EventEmitter(); +const d = new domain.Domain(); +const e = new events.EventEmitter(); d.on('error', function(er) { console.error('caught', er && (er.message || er)); - var er_message = er.message; - var er_path = er.path; + let er_message = er.message; + let er_path = er.path; // On windows, error messages can contain full path names. If this is the // case, remove the directory part. if (typeof er_path === 'string') { - var slash = er_path.lastIndexOf('\\'); + const slash = er_path.lastIndexOf('\\'); if (slash !== -1) { - var dir = er_path.slice(0, slash + 1); + const dir = er_path.slice(0, slash + 1); er_path = er_path.replace(dir, ''); er_message = er_message.replace(dir, ''); } @@ -129,7 +129,7 @@ expectCaught++; // set up while in the scope of the d domain. d.run(function() { process.nextTick(function() { - var i = setInterval(function() { + const i = setInterval(function() { clearInterval(i); setTimeout(function() { fs.stat('this file does not exist', function(er, stat) { @@ -166,7 +166,7 @@ function fn() { throw new Error('This function should never be called!'); } -var bound = d.intercept(fn); +let bound = d.intercept(fn); bound(new Error('bound')); expectCaught++; @@ -210,7 +210,7 @@ expectCaught++; // implicit addition by being created within a domain-bound context. -var implicit; +let implicit; d.run(function() { implicit = new events.EventEmitter(); @@ -223,7 +223,7 @@ setTimeout(function() { expectCaught++; -var result = d.run(function() { +let result = d.run(function() { return 'return value'; }); assert.strictEqual(result, 'return value'); @@ -236,12 +236,12 @@ result = d.run(function(a, b) { assert.strictEqual(result, 'return value'); -var fst = fs.createReadStream('stream for nonexistent file'); +let fst = fs.createReadStream('stream for nonexistent file'); d.add(fst); expectCaught++; [42, null, , false, function() {}, 'string'].forEach(function(something) { - var d = new domain.Domain(); + const d = new domain.Domain(); d.run(function() { process.nextTick(function() { throw something; diff --git a/test/parallel/test-dsa-fips-invalid-key.js b/test/parallel/test-dsa-fips-invalid-key.js index ede3adab66c527..6055a9b4c47862 100644 --- a/test/parallel/test-dsa-fips-invalid-key.js +++ b/test/parallel/test-dsa-fips-invalid-key.js @@ -1,20 +1,20 @@ 'use strict'; -var common = require('../common'); -var assert = require('assert'); +const common = require('../common'); +const assert = require('assert'); if (!common.hasFipsCrypto) { common.skip('node compiled without FIPS OpenSSL.'); return; } -var crypto = require('crypto'); -var fs = require('fs'); +const crypto = require('crypto'); +const fs = require('fs'); -var input = 'hello'; +const input = 'hello'; -var dsapri = fs.readFileSync(common.fixturesDir + +const dsapri = fs.readFileSync(common.fixturesDir + '/keys/dsa_private_1025.pem'); -var sign = crypto.createSign('DSS1'); +const sign = crypto.createSign('DSS1'); sign.update(input); assert.throws(function() { diff --git a/test/parallel/test-error-reporting.js b/test/parallel/test-error-reporting.js index 62525a5494d5a0..fa7332a67a482b 100644 --- a/test/parallel/test-error-reporting.js +++ b/test/parallel/test-error-reporting.js @@ -1,12 +1,12 @@ 'use strict'; -var common = require('../common'); -var assert = require('assert'); -var exec = require('child_process').exec; -var path = require('path'); +const common = require('../common'); +const assert = require('assert'); +const exec = require('child_process').exec; +const path = require('path'); function errExec(script, callback) { - var cmd = '"' + process.argv[0] + '" "' + - path.join(common.fixturesDir, script) + '"'; + const cmd = '"' + process.argv[0] + '" "' + + path.join(common.fixturesDir, script) + '"'; return exec(cmd, function(err, stdout, stderr) { // There was some error assert.ok(err); diff --git a/test/parallel/test-event-emitter-check-listener-leaks.js b/test/parallel/test-event-emitter-check-listener-leaks.js index 1e357cd027d0f5..244bfa97bfa86a 100644 --- a/test/parallel/test-event-emitter-check-listener-leaks.js +++ b/test/parallel/test-event-emitter-check-listener-leaks.js @@ -1,9 +1,9 @@ 'use strict'; require('../common'); -var assert = require('assert'); -var events = require('events'); +const assert = require('assert'); +const events = require('events'); -var e = new events.EventEmitter(); +let e = new events.EventEmitter(); // default for (let i = 0; i < 10; i++) { diff --git a/test/parallel/test-event-emitter-errors.js b/test/parallel/test-event-emitter-errors.js index 3effb999b37e8c..2b4a93ae9808df 100644 --- a/test/parallel/test-event-emitter-errors.js +++ b/test/parallel/test-event-emitter-errors.js @@ -1,9 +1,9 @@ 'use strict'; require('../common'); -var EventEmitter = require('events'); -var assert = require('assert'); +const EventEmitter = require('events'); +const assert = require('assert'); -var EE = new EventEmitter(); +const EE = new EventEmitter(); assert.throws(function() { EE.emit('error', 'Accepts a string'); diff --git a/test/parallel/test-event-emitter-get-max-listeners.js b/test/parallel/test-event-emitter-get-max-listeners.js index 34ffee3600e5e9..9acc71fd7920e3 100644 --- a/test/parallel/test-event-emitter-get-max-listeners.js +++ b/test/parallel/test-event-emitter-get-max-listeners.js @@ -1,9 +1,9 @@ 'use strict'; require('../common'); -var assert = require('assert'); -var EventEmitter = require('events'); +const assert = require('assert'); +const EventEmitter = require('events'); -var emitter = new EventEmitter(); +const emitter = new EventEmitter(); assert.strictEqual(emitter.getMaxListeners(), EventEmitter.defaultMaxListeners); @@ -14,6 +14,6 @@ emitter.setMaxListeners(3); assert.strictEqual(emitter.getMaxListeners(), 3); // https://github.com/nodejs/node/issues/523 - second call should not throw. -var recv = {}; +const recv = {}; EventEmitter.prototype.on.call(recv, 'event', function() {}); EventEmitter.prototype.on.call(recv, 'event', function() {}); diff --git a/test/parallel/test-event-emitter-listeners-side-effects.js b/test/parallel/test-event-emitter-listeners-side-effects.js index 906138af2367c3..022750da406500 100644 --- a/test/parallel/test-event-emitter-listeners-side-effects.js +++ b/test/parallel/test-event-emitter-listeners-side-effects.js @@ -1,12 +1,12 @@ 'use strict'; const common = require('../common'); -var assert = require('assert'); +const assert = require('assert'); -var EventEmitter = require('events').EventEmitter; +const EventEmitter = require('events').EventEmitter; -var e = new EventEmitter(); -var fl; // foo listeners +const e = new EventEmitter(); +let fl; // foo listeners fl = e.listeners('foo'); assert(Array.isArray(fl)); diff --git a/test/parallel/test-event-emitter-method-names.js b/test/parallel/test-event-emitter-method-names.js index e268e229b06b5b..d0464b80a44fe1 100644 --- a/test/parallel/test-event-emitter-method-names.js +++ b/test/parallel/test-event-emitter-method-names.js @@ -1,9 +1,9 @@ 'use strict'; require('../common'); -var assert = require('assert'); -var events = require('events'); +const assert = require('assert'); +const events = require('events'); -var E = events.EventEmitter.prototype; +const E = events.EventEmitter.prototype; assert.strictEqual(E.constructor.name, 'EventEmitter'); assert.strictEqual(E.on, E.addListener); // Same method. Object.getOwnPropertyNames(E).forEach(function(name) { diff --git a/test/parallel/test-event-emitter-no-error-provided-to-error-event.js b/test/parallel/test-event-emitter-no-error-provided-to-error-event.js index 0a3ecb33d6e697..3e7242915e1854 100644 --- a/test/parallel/test-event-emitter-no-error-provided-to-error-event.js +++ b/test/parallel/test-event-emitter-no-error-provided-to-error-event.js @@ -1,11 +1,11 @@ 'use strict'; const common = require('../common'); -var assert = require('assert'); -var events = require('events'); -var domain = require('domain'); -var e = new events.EventEmitter(); +const assert = require('assert'); +const events = require('events'); +const domain = require('domain'); +const e = new events.EventEmitter(); -var d = domain.create(); +const d = domain.create(); d.add(e); d.on('error', common.mustCall(function(er) { assert(er instanceof Error, 'error created'); diff --git a/test/parallel/test-event-emitter-num-args.js b/test/parallel/test-event-emitter-num-args.js index 31e57c89c8f23d..53ac0f79c20333 100644 --- a/test/parallel/test-event-emitter-num-args.js +++ b/test/parallel/test-event-emitter-num-args.js @@ -1,7 +1,7 @@ 'use strict'; require('../common'); -var assert = require('assert'); -var events = require('events'); +const assert = require('assert'); +const events = require('events'); const e = new events.EventEmitter(); const num_args_emitted = []; diff --git a/test/parallel/test-event-emitter-once.js b/test/parallel/test-event-emitter-once.js index cca21a454b43bc..724b2ffd16aad1 100644 --- a/test/parallel/test-event-emitter-once.js +++ b/test/parallel/test-event-emitter-once.js @@ -12,7 +12,7 @@ e.emit('hello', 'a', 'b'); e.emit('hello', 'a', 'b'); e.emit('hello', 'a', 'b'); -var remove = function() { +const remove = function() { common.fail('once->foo should not be emitted'); }; diff --git a/test/parallel/test-event-emitter-prepend.js b/test/parallel/test-event-emitter-prepend.js index aa755a723c583e..5a3b66b0cb3250 100644 --- a/test/parallel/test-event-emitter-prepend.js +++ b/test/parallel/test-event-emitter-prepend.js @@ -5,7 +5,7 @@ const EventEmitter = require('events'); const assert = require('assert'); const myEE = new EventEmitter(); -var m = 0; +let m = 0; // This one comes last. myEE.on('foo', common.mustCall(() => assert.equal(m, 2))); diff --git a/test/parallel/test-event-emitter-remove-all-listeners.js b/test/parallel/test-event-emitter-remove-all-listeners.js index 1970904df25a75..9cf08369f82986 100644 --- a/test/parallel/test-event-emitter-remove-all-listeners.js +++ b/test/parallel/test-event-emitter-remove-all-listeners.js @@ -66,7 +66,7 @@ function listener() {} { const ee = new events.EventEmitter(); - var expectLength = 2; + let expectLength = 2; ee.on('removeListener', function(name, listener) { assert.strictEqual(expectLength--, this.listeners('baz').length); }); diff --git a/test/parallel/test-event-emitter-set-max-listeners-side-effects.js b/test/parallel/test-event-emitter-set-max-listeners-side-effects.js index cadaf3adc36014..5235d05638441b 100644 --- a/test/parallel/test-event-emitter-set-max-listeners-side-effects.js +++ b/test/parallel/test-event-emitter-set-max-listeners-side-effects.js @@ -1,9 +1,9 @@ 'use strict'; require('../common'); -var assert = require('assert'); -var events = require('events'); +const assert = require('assert'); +const events = require('events'); -var e = new events.EventEmitter(); +const e = new events.EventEmitter(); assert(!(e._events instanceof Object)); assert.deepStrictEqual(Object.keys(e._events), []); diff --git a/test/parallel/test-event-emitter-subclass.js b/test/parallel/test-event-emitter-subclass.js index d2651defeeaa23..d35802b413136b 100644 --- a/test/parallel/test-event-emitter-subclass.js +++ b/test/parallel/test-event-emitter-subclass.js @@ -1,8 +1,8 @@ 'use strict'; const common = require('../common'); -var assert = require('assert'); -var EventEmitter = require('events').EventEmitter; -var util = require('util'); +const assert = require('assert'); +const EventEmitter = require('events').EventEmitter; +const util = require('util'); util.inherits(MyEE, EventEmitter); @@ -13,7 +13,7 @@ function MyEE(cb) { EventEmitter.call(this); } -var myee = new MyEE(common.mustCall(function() {})); +const myee = new MyEE(common.mustCall(function() {})); util.inherits(ErrorEE, EventEmitter); @@ -38,8 +38,8 @@ function MyEE2() { MyEE2.prototype = new EventEmitter(); -var ee1 = new MyEE2(); -var ee2 = new MyEE2(); +const ee1 = new MyEE2(); +const ee2 = new MyEE2(); ee1.on('x', function() {}); diff --git a/test/parallel/test-exception-handler.js b/test/parallel/test-exception-handler.js index e0e1b0086d9a7f..506fbaed0ebf63 100644 --- a/test/parallel/test-exception-handler.js +++ b/test/parallel/test-exception-handler.js @@ -1,8 +1,8 @@ 'use strict'; const common = require('../common'); -var assert = require('assert'); +const assert = require('assert'); -var MESSAGE = 'catch me if you can'; +const MESSAGE = 'catch me if you can'; process.on('uncaughtException', common.mustCall(function(e) { console.log('uncaught exception! 1'); diff --git a/test/parallel/test-file-write-stream2.js b/test/parallel/test-file-write-stream2.js index 77e8119d25b8a7..504a572dde67d7 100644 --- a/test/parallel/test-file-write-stream2.js +++ b/test/parallel/test-file-write-stream2.js @@ -7,14 +7,13 @@ const fs = require('fs'); const filepath = path.join(common.tmpDir, 'write.txt'); -var file; const EXPECTED = '012345678910'; const cb_expected = 'write open drain write drain close error '; -var cb_occurred = ''; +let cb_occurred = ''; -var countDrains = 0; +let countDrains = 0; process.on('exit', function() { @@ -41,7 +40,7 @@ function removeTestFile() { common.refreshTmpDir(); // drain at 0, return false at 10. -file = fs.createWriteStream(filepath, { +const file = fs.createWriteStream(filepath, { highWaterMark: 11 }); @@ -80,7 +79,7 @@ file.on('error', function(err) { }); -for (var i = 0; i < 11; i++) { +for (let i = 0; i < 11; i++) { const ret = file.write(i + ''); console.error('%d %j', i, ret); diff --git a/test/parallel/test-force-repl-with-eval.js b/test/parallel/test-force-repl-with-eval.js index e5044ba59df4d5..8c75818508d17e 100644 --- a/test/parallel/test-force-repl-with-eval.js +++ b/test/parallel/test-force-repl-with-eval.js @@ -5,11 +5,11 @@ const spawn = require('child_process').spawn; // spawn a node child process in "interactive" mode (force the repl) and eval const cp = spawn(process.execPath, ['-i', '-e', 'console.log("42")']); -var gotToEnd = false; +let gotToEnd = false; cp.stdout.setEncoding('utf8'); -var output = ''; +let output = ''; cp.stdout.on('data', function(b) { output += b; if (output === '> 42\n') { diff --git a/test/parallel/test-force-repl.js b/test/parallel/test-force-repl.js index 37f2f603342a1c..5507d7401b72d3 100644 --- a/test/parallel/test-force-repl.js +++ b/test/parallel/test-force-repl.js @@ -5,7 +5,7 @@ const spawn = require('child_process').spawn; // spawn a node child process in "interactive" mode (force the repl) const cp = spawn(process.execPath, ['-i']); -var timeoutId = setTimeout(function() { +const timeoutId = setTimeout(function() { common.fail('timeout!'); }, common.platformTimeout(5000)); // give node + the repl 5 seconds to start diff --git a/test/parallel/test-freelist.js b/test/parallel/test-freelist.js index 65758bd7114de8..8ec7134dad0eb5 100644 --- a/test/parallel/test-freelist.js +++ b/test/parallel/test-freelist.js @@ -12,7 +12,7 @@ assert.strictEqual(typeof freelist.FreeList, 'function'); const flist1 = new freelist.FreeList('flist1', 3, String); // Allocating when empty, should not change the list size -var result = flist1.alloc('test'); +const result = flist1.alloc('test'); assert.strictEqual(typeof result, 'string'); assert.strictEqual(result, 'test'); assert.strictEqual(flist1.list.length, 0); diff --git a/test/parallel/test-fs-access.js b/test/parallel/test-fs-access.js index 6da26fe47beb92..ad4023ea74ac83 100644 --- a/test/parallel/test-fs-access.js +++ b/test/parallel/test-fs-access.js @@ -1,13 +1,13 @@ 'use strict'; -var common = require('../common'); -var assert = require('assert'); -var fs = require('fs'); -var path = require('path'); -var doesNotExist = path.join(common.tmpDir, '__this_should_not_exist'); -var readOnlyFile = path.join(common.tmpDir, 'read_only_file'); -var readWriteFile = path.join(common.tmpDir, 'read_write_file'); - -var removeFile = function(file) { +const common = require('../common'); +const assert = require('assert'); +const fs = require('fs'); +const path = require('path'); +const doesNotExist = path.join(common.tmpDir, '__this_should_not_exist'); +const readOnlyFile = path.join(common.tmpDir, 'read_only_file'); +const readWriteFile = path.join(common.tmpDir, 'read_write_file'); + +const removeFile = function(file) { try { fs.unlinkSync(file); } catch (err) { @@ -15,7 +15,7 @@ var removeFile = function(file) { } }; -var createFileWithPerms = function(file, mode) { +const createFileWithPerms = function(file, mode) { removeFile(file); fs.writeFileSync(file, ''); fs.chmodSync(file, mode); @@ -48,7 +48,7 @@ createFileWithPerms(readWriteFile, 0o666); * id, but that's fine. In this case, it is the responsability of the * continuous integration platform to take care of that. */ -var hasWriteAccessForReadonlyFile = false; +let hasWriteAccessForReadonlyFile = false; if (!common.isWindows && process.getuid() === 0) { hasWriteAccessForReadonlyFile = true; try { @@ -107,7 +107,7 @@ assert.doesNotThrow(function() { }); assert.doesNotThrow(function() { - var mode = fs.F_OK | fs.R_OK | fs.W_OK; + const mode = fs.F_OK | fs.R_OK | fs.W_OK; fs.accessSync(readWriteFile, mode); }); diff --git a/test/parallel/test-fs-chmod.js b/test/parallel/test-fs-chmod.js index 2e5d839ae97720..5121fd89f99466 100644 --- a/test/parallel/test-fs-chmod.js +++ b/test/parallel/test-fs-chmod.js @@ -99,7 +99,7 @@ fs.open(file2, 'a', common.mustCall((err, fd) => { // lchmod if (fs.lchmod) { - var link = path.join(common.tmpDir, 'symbolic-link'); + const link = path.join(common.tmpDir, 'symbolic-link'); common.refreshTmpDir(); fs.symlinkSync(file2, link); diff --git a/test/parallel/test-fs-exists.js b/test/parallel/test-fs-exists.js index 83e6adaf1100f7..14e1446f5a6d3d 100644 --- a/test/parallel/test-fs-exists.js +++ b/test/parallel/test-fs-exists.js @@ -1,8 +1,8 @@ 'use strict'; const common = require('../common'); -var assert = require('assert'); -var fs = require('fs'); -var f = __filename; +const assert = require('assert'); +const fs = require('fs'); +const f = __filename; fs.exists(f, common.mustCall(function(y) { assert.strictEqual(y, true); diff --git a/test/parallel/test-fs-long-path.js b/test/parallel/test-fs-long-path.js index 64585467ed6a77..7082e740ed47c9 100644 --- a/test/parallel/test-fs-long-path.js +++ b/test/parallel/test-fs-long-path.js @@ -1,7 +1,7 @@ 'use strict'; -var common = require('../common'); -var fs = require('fs'); -var path = require('path'); +const common = require('../common'); +const fs = require('fs'); +const path = require('path'); if (!common.isWindows) { common.skip('this test is Windows-specific.'); @@ -9,9 +9,9 @@ if (!common.isWindows) { } // make a path that will be at least 260 chars long. -var fileNameLen = Math.max(260 - common.tmpDir.length - 1, 1); -var fileName = path.join(common.tmpDir, new Array(fileNameLen + 1).join('x')); -var fullPath = path.resolve(fileName); +const fileNameLen = Math.max(260 - common.tmpDir.length - 1, 1); +const fileName = path.join(common.tmpDir, new Array(fileNameLen + 1).join('x')); +const fullPath = path.resolve(fileName); common.refreshTmpDir(); diff --git a/test/parallel/test-fs-make-callback.js b/test/parallel/test-fs-make-callback.js index 4fbe64437eaff0..2dc9874a546574 100644 --- a/test/parallel/test-fs-make-callback.js +++ b/test/parallel/test-fs-make-callback.js @@ -1,7 +1,7 @@ 'use strict'; require('../common'); -var assert = require('assert'); -var fs = require('fs'); +const assert = require('assert'); +const fs = require('fs'); function test(cb) { return function() { diff --git a/test/parallel/test-fs-mkdir.js b/test/parallel/test-fs-mkdir.js index 2b8e8b8f026637..620231102273e3 100644 --- a/test/parallel/test-fs-mkdir.js +++ b/test/parallel/test-fs-mkdir.js @@ -1,7 +1,7 @@ 'use strict'; -var common = require('../common'); -var assert = require('assert'); -var fs = require('fs'); +const common = require('../common'); +const assert = require('assert'); +const fs = require('fs'); function unlink(pathname) { try { diff --git a/test/parallel/test-fs-null-bytes.js b/test/parallel/test-fs-null-bytes.js index e04aa1cb76cb6f..fa29e64c9b2382 100644 --- a/test/parallel/test-fs-null-bytes.js +++ b/test/parallel/test-fs-null-bytes.js @@ -1,7 +1,7 @@ 'use strict'; -var common = require('../common'); -var assert = require('assert'); -var fs = require('fs'); +const common = require('../common'); +const assert = require('assert'); +const fs = require('fs'); function check(async, sync) { const expected = /Path must be a string without null bytes/; diff --git a/test/parallel/test-fs-open-flags.js b/test/parallel/test-fs-open-flags.js index d212130bc903d1..f07da13569b56a 100644 --- a/test/parallel/test-fs-open-flags.js +++ b/test/parallel/test-fs-open-flags.js @@ -1,16 +1,16 @@ 'use strict'; require('../common'); -var assert = require('assert'); +const assert = require('assert'); -var fs = require('fs'); +const fs = require('fs'); -var O_APPEND = fs.constants.O_APPEND || 0; -var O_CREAT = fs.constants.O_CREAT || 0; -var O_EXCL = fs.constants.O_EXCL || 0; -var O_RDONLY = fs.constants.O_RDONLY || 0; -var O_RDWR = fs.constants.O_RDWR || 0; -var O_TRUNC = fs.constants.O_TRUNC || 0; -var O_WRONLY = fs.constants.O_WRONLY || 0; +const O_APPEND = fs.constants.O_APPEND || 0; +const O_CREAT = fs.constants.O_CREAT || 0; +const O_EXCL = fs.constants.O_EXCL || 0; +const O_RDONLY = fs.constants.O_RDONLY || 0; +const O_RDWR = fs.constants.O_RDWR || 0; +const O_TRUNC = fs.constants.O_TRUNC || 0; +const O_WRONLY = fs.constants.O_WRONLY || 0; assert.equal(fs._stringToFlags('r'), O_RDONLY); assert.equal(fs._stringToFlags('r+'), O_RDWR); diff --git a/test/parallel/test-fs-read-buffer-tostring-fail.js b/test/parallel/test-fs-read-buffer-tostring-fail.js index cce33edf4e6947..3ef058e4aa031e 100644 --- a/test/parallel/test-fs-read-buffer-tostring-fail.js +++ b/test/parallel/test-fs-read-buffer-tostring-fail.js @@ -14,7 +14,7 @@ const path = require('path'); const Buffer = require('buffer').Buffer; const kStringMaxLength = process.binding('buffer').kStringMaxLength; -var fd; +let fd; common.refreshTmpDir(); @@ -26,7 +26,7 @@ const stream = fs.createWriteStream(file, { const size = kStringMaxLength / 200; const a = Buffer.alloc(size, 'a'); -for (var i = 0; i < 201; i++) { +for (let i = 0; i < 201; i++) { stream.write(a); } diff --git a/test/parallel/test-fs-read-buffer.js b/test/parallel/test-fs-read-buffer.js index 32f52b13cc7594..cc1d1052351849 100644 --- a/test/parallel/test-fs-read-buffer.js +++ b/test/parallel/test-fs-read-buffer.js @@ -20,6 +20,6 @@ fs.read(fd, assert.deepStrictEqual(bufferAsync, Buffer.from(expected)); })); -var r = fs.readSync(fd, bufferSync, 0, expected.length, 0); +const r = fs.readSync(fd, bufferSync, 0, expected.length, 0); assert.deepStrictEqual(bufferSync, Buffer.from(expected)); assert.equal(r, expected.length); diff --git a/test/parallel/test-fs-read-stream-fd-leak.js b/test/parallel/test-fs-read-stream-fd-leak.js index 45847270097348..0a7a42a3bab3c1 100644 --- a/test/parallel/test-fs-read-stream-fd-leak.js +++ b/test/parallel/test-fs-read-stream-fd-leak.js @@ -5,7 +5,7 @@ const assert = require('assert'); const fs = require('fs'); const path = require('path'); -var openCount = 0; +let openCount = 0; const _fsopen = fs.open; const _fsclose = fs.close; @@ -26,8 +26,8 @@ fs.close = function() { function testLeak(endFn, callback) { console.log('testing for leaks from fs.createReadStream().%s()...', endFn); - var i = 0; - var check = 0; + let i = 0; + let check = 0; const checkFunction = function() { if (openCount !== 0 && check < totalCheck) { diff --git a/test/parallel/test-fs-read-stream-fd.js b/test/parallel/test-fs-read-stream-fd.js index 5af5200e30eb68..93b93085159ac6 100644 --- a/test/parallel/test-fs-read-stream-fd.js +++ b/test/parallel/test-fs-read-stream-fd.js @@ -1,18 +1,17 @@ 'use strict'; const common = require('../common'); -var fs = require('fs'); -var assert = require('assert'); -var path = require('path'); -var file = path.join(common.tmpDir, '/read_stream_fd_test.txt'); -var input = 'hello world'; -var output = ''; -var fd, stream; +const fs = require('fs'); +const assert = require('assert'); +const path = require('path'); +const file = path.join(common.tmpDir, '/read_stream_fd_test.txt'); +const input = 'hello world'; +let output = ''; common.refreshTmpDir(); fs.writeFileSync(file, input); -fd = fs.openSync(file, 'r'); +const fd = fs.openSync(file, 'r'); -stream = fs.createReadStream(null, { fd: fd, encoding: 'utf8' }); +const stream = fs.createReadStream(null, { fd: fd, encoding: 'utf8' }); stream.on('data', function(data) { output += data; }); diff --git a/test/parallel/test-fs-read-stream-resume.js b/test/parallel/test-fs-read-stream-resume.js index 3ff89644e5c018..6c8b2c2421c8e3 100644 --- a/test/parallel/test-fs-read-stream-resume.js +++ b/test/parallel/test-fs-read-stream-resume.js @@ -9,7 +9,7 @@ const file = path.join(common.fixturesDir, 'x.txt'); let data = ''; let first = true; -var stream = fs.createReadStream(file); +const stream = fs.createReadStream(file); stream.setEncoding('utf8'); stream.on('data', function(chunk) { data += chunk; diff --git a/test/parallel/test-fs-read-stream.js b/test/parallel/test-fs-read-stream.js index c8da0275c53c9b..d4fad6e6f79c07 100644 --- a/test/parallel/test-fs-read-stream.js +++ b/test/parallel/test-fs-read-stream.js @@ -7,13 +7,13 @@ const fs = require('fs'); const fn = path.join(common.fixturesDir, 'elipses.txt'); const rangeFile = path.join(common.fixturesDir, 'x.txt'); -var callbacks = { open: 0, end: 0, close: 0 }; +const callbacks = { open: 0, end: 0, close: 0 }; -var paused = false; -var bytesRead = 0; +let paused = false; +let bytesRead = 0; -var file = fs.ReadStream(fn); -var fileSize = fs.statSync(fn).size; +const file = fs.ReadStream(fn); +const fileSize = fs.statSync(fn).size; assert.strictEqual(file.bytesRead, 0); @@ -64,13 +64,13 @@ file.on('close', function() { //assert.equal(fs.readFileSync(fn), fileContent); }); -var file3 = fs.createReadStream(fn, {encoding: 'utf8'}); +const file3 = fs.createReadStream(fn, {encoding: 'utf8'}); file3.length = 0; file3.on('data', function(data) { assert.strictEqual('string', typeof data); file3.length += data.length; - for (var i = 0; i < data.length; i++) { + for (let i = 0; i < data.length; i++) { // http://www.fileformat.info/info/unicode/char/2026/index.htm assert.strictEqual('\u2026', data[i]); } @@ -89,8 +89,8 @@ process.on('exit', function() { console.error('ok'); }); -var file4 = fs.createReadStream(rangeFile, {bufferSize: 1, start: 1, end: 2}); -var contentRead = ''; +const file4 = fs.createReadStream(rangeFile, {bufferSize: 1, start: 1, end: 2}); +let contentRead = ''; file4.on('data', function(data) { contentRead += data.toString('utf-8'); }); @@ -98,7 +98,7 @@ file4.on('end', function(data) { assert.strictEqual(contentRead, 'yz'); }); -var file5 = fs.createReadStream(rangeFile, {bufferSize: 1, start: 1}); +const file5 = fs.createReadStream(rangeFile, {bufferSize: 1, start: 1}); file5.data = ''; file5.on('data', function(data) { file5.data += data.toString('utf-8'); @@ -108,7 +108,7 @@ file5.on('end', function() { }); // https://github.com/joyent/node/issues/2320 -var file6 = fs.createReadStream(rangeFile, {bufferSize: 1.23, start: 1}); +const file6 = fs.createReadStream(rangeFile, {bufferSize: 1.23, start: 1}); file6.data = ''; file6.on('data', function(data) { file6.data += data.toString('utf-8'); @@ -121,7 +121,7 @@ assert.throws(function() { fs.createReadStream(rangeFile, {start: 10, end: 2}); }, /"start" option must be <= "end" option/); -var stream = fs.createReadStream(rangeFile, { start: 0, end: 0 }); +const stream = fs.createReadStream(rangeFile, { start: 0, end: 0 }); stream.data = ''; stream.on('data', function(chunk) { @@ -133,11 +133,11 @@ stream.on('end', function() { }); // pause and then resume immediately. -var pauseRes = fs.createReadStream(rangeFile); +const pauseRes = fs.createReadStream(rangeFile); pauseRes.pause(); pauseRes.resume(); -var file7 = fs.createReadStream(rangeFile, {autoClose: false }); +let file7 = fs.createReadStream(rangeFile, {autoClose: false }); file7.on('data', function() {}); file7.on('end', function() { process.nextTick(function() { @@ -160,12 +160,12 @@ function file7Next() { } // Just to make sure autoClose won't close the stream because of error. -var file8 = fs.createReadStream(null, {fd: 13337, autoClose: false }); +const file8 = fs.createReadStream(null, {fd: 13337, autoClose: false }); file8.on('data', function() {}); file8.on('error', common.mustCall(function() {})); // Make sure stream is destroyed when file does not exist. -var file9 = fs.createReadStream('/path/to/file/that/does/not/exist'); +const file9 = fs.createReadStream('/path/to/file/that/does/not/exist'); file9.on('data', function() {}); file9.on('error', common.mustCall(function() {})); diff --git a/test/parallel/test-fs-read.js b/test/parallel/test-fs-read.js index 41957c228ea944..06755c0d6e050f 100644 --- a/test/parallel/test-fs-read.js +++ b/test/parallel/test-fs-read.js @@ -17,6 +17,6 @@ fs.read(fd, assert.strictEqual(bytesRead, expected.length); })); -var r = fs.readSync(fd, expected.length, 0, 'utf-8'); +const r = fs.readSync(fd, expected.length, 0, 'utf-8'); assert.strictEqual(r[0], expected); assert.strictEqual(r[1], expected.length); diff --git a/test/parallel/test-fs-readfile-fd.js b/test/parallel/test-fs-readfile-fd.js index 6420dbfdd004e5..47eeccf0a31b87 100644 --- a/test/parallel/test-fs-readfile-fd.js +++ b/test/parallel/test-fs-readfile-fd.js @@ -40,7 +40,7 @@ function tempFd(callback) { } function tempFdSync(callback) { - var fd = fs.openSync(fn, 'r'); + const fd = fs.openSync(fn, 'r'); callback(fd); fs.closeSync(fd); } diff --git a/test/parallel/test-fs-readfile-zero-byte-liar.js b/test/parallel/test-fs-readfile-zero-byte-liar.js index c3887979bb0b4a..82037a77e62122 100644 --- a/test/parallel/test-fs-readfile-zero-byte-liar.js +++ b/test/parallel/test-fs-readfile-zero-byte-liar.js @@ -1,7 +1,7 @@ 'use strict'; const common = require('../common'); -var assert = require('assert'); -var fs = require('fs'); +const assert = require('assert'); +const fs = require('fs'); const dataExpected = fs.readFileSync(__filename, 'utf8'); diff --git a/test/parallel/test-fs-realpath-buffer-encoding.js b/test/parallel/test-fs-realpath-buffer-encoding.js index 78ec02549bbd27..54054bb479f8d4 100644 --- a/test/parallel/test-fs-realpath-buffer-encoding.js +++ b/test/parallel/test-fs-realpath-buffer-encoding.js @@ -8,14 +8,15 @@ const buffer_dir = Buffer.from(string_dir); const encodings = ['ascii', 'utf8', 'utf16le', 'ucs2', 'base64', 'binary', 'hex']; -var expected = {}; +const expected = {}; encodings.forEach((encoding) => { expected[encoding] = buffer_dir.toString(encoding); }); // test sync version -for (var encoding in expected) { +let encoding; +for (encoding in expected) { const expected_value = expected[encoding]; let result; diff --git a/test/parallel/test-fs-realpath-on-substed-drive.js b/test/parallel/test-fs-realpath-on-substed-drive.js index c9109362691845..a5c542162c3b65 100644 --- a/test/parallel/test-fs-realpath-on-substed-drive.js +++ b/test/parallel/test-fs-realpath-on-substed-drive.js @@ -14,7 +14,8 @@ let result; // create a subst drive const driveLetters = 'ABCDEFGHIJKLMNOPQRSTUWXYZ'; let drive; -for (var i = 0; i < driveLetters.length; ++i) { +let i; +for (i = 0; i < driveLetters.length; ++i) { drive = `${driveLetters[i]}:`; result = spawnSync('subst', [drive, common.fixturesDir]); if (result.status === 0) diff --git a/test/parallel/test-fs-realpath.js b/test/parallel/test-fs-realpath.js index adc8459a3eca46..54c509d55e1fed 100644 --- a/test/parallel/test-fs-realpath.js +++ b/test/parallel/test-fs-realpath.js @@ -4,13 +4,14 @@ const assert = require('assert'); const fs = require('fs'); const path = require('path'); const exec = require('child_process').exec; -var async_completed = 0, async_expected = 0, unlink = []; -var skipSymlinks = false; +let async_completed = 0, async_expected = 0; +const unlink = []; +let skipSymlinks = false; common.refreshTmpDir(); -var root = '/'; -var assertEqualPath = assert.strictEqual; +let root = '/'; +let assertEqualPath = assert.strictEqual; if (common.isWindows) { // something like "C:\\" root = process.cwd().substr(0, 3); @@ -54,7 +55,7 @@ fs.mkdirSync(path.join(targetsAbsDir, 'nested-index', 'two')); function asynctest(testBlock, args, callback, assertBlock) { async_expected++; testBlock.apply(testBlock, args.concat(function(err) { - var ignoreError = false; + let ignoreError = false; if (assertBlock) { try { ignoreError = assertBlock.apply(assertBlock, arguments); @@ -216,7 +217,7 @@ function test_cyclic_link_overprotection(callback) { const expected = fs.realpathSync(cycles); const folder = cycles + '/folder'; const link = folder + '/cycles'; - var testPath = cycles; + let testPath = cycles; testPath += '/folder/cycles'.repeat(10); try { fs.unlinkSync(link); } catch (ex) {} fs.symlinkSync(cycles, link, 'dir'); @@ -474,7 +475,7 @@ const tests = [ test_up_multiple ]; const numtests = tests.length; -var testsRun = 0; +let testsRun = 0; function runNextTest(err) { if (err) throw err; const test = tests.shift(); diff --git a/test/parallel/test-fs-sir-writes-alot.js b/test/parallel/test-fs-sir-writes-alot.js index 8e1385ed4da2a0..dab1cb2447c46a 100644 --- a/test/parallel/test-fs-sir-writes-alot.js +++ b/test/parallel/test-fs-sir-writes-alot.js @@ -1,36 +1,37 @@ 'use strict'; -var common = require('../common'); -var fs = require('fs'); -var assert = require('assert'); -var join = require('path').join; +const common = require('../common'); +const fs = require('fs'); +const assert = require('assert'); +const join = require('path').join; -var filename = join(common.tmpDir, 'out.txt'); +const filename = join(common.tmpDir, 'out.txt'); common.refreshTmpDir(); -var fd = fs.openSync(filename, 'w'); +const fd = fs.openSync(filename, 'w'); -var line = 'aaaaaaaaaaaaaaaaaaaaaaaaaaaa\n'; +const line = 'aaaaaaaaaaaaaaaaaaaaaaaaaaaa\n'; -var N = 10240, complete = 0; -for (var i = 0; i < N; i++) { +const N = 10240; +let complete = 0; +for (let i = 0; i < N; i++) { // Create a new buffer for each write. Before the write is actually // executed by the thread pool, the buffer will be collected. - var buffer = Buffer.from(line); + const buffer = Buffer.from(line); fs.write(fd, buffer, 0, buffer.length, null, function(er, written) { complete++; if (complete === N) { fs.closeSync(fd); - var s = fs.createReadStream(filename); + const s = fs.createReadStream(filename); s.on('data', testBuffer); } }); } -var bytesChecked = 0; +let bytesChecked = 0; function testBuffer(b) { - for (var i = 0; i < b.length; i++) { + for (let i = 0; i < b.length; i++) { bytesChecked++; if (b[i] !== 'a'.charCodeAt(0) && b[i] !== '\n'.charCodeAt(0)) { throw new Error('invalid char ' + i + ',' + b[i]); diff --git a/test/parallel/test-fs-stat.js b/test/parallel/test-fs-stat.js index 2c844452f05540..32ba47c2fe0c1e 100644 --- a/test/parallel/test-fs-stat.js +++ b/test/parallel/test-fs-stat.js @@ -1,7 +1,7 @@ /* eslint-disable strict */ const common = require('../common'); -var assert = require('assert'); -var fs = require('fs'); +const assert = require('assert'); +const fs = require('fs'); fs.stat('.', common.mustCall(function(err, stats) { assert.ifError(err); @@ -37,7 +37,7 @@ fs.open('.', 'r', undefined, common.mustCall(function(err, fd) { // fstatSync fs.open('.', 'r', undefined, common.mustCall(function(err, fd) { - var stats; + let stats; try { stats = fs.fstatSync(fd); } catch (err) { diff --git a/test/parallel/test-fs-stream-double-close.js b/test/parallel/test-fs-stream-double-close.js index df5010293729a3..ae6429a62b4f3c 100644 --- a/test/parallel/test-fs-stream-double-close.js +++ b/test/parallel/test-fs-stream-double-close.js @@ -1,6 +1,6 @@ 'use strict'; -var common = require('../common'); -var fs = require('fs'); +const common = require('../common'); +const fs = require('fs'); common.refreshTmpDir(); diff --git a/test/parallel/test-fs-symlink-dir-junction-relative.js b/test/parallel/test-fs-symlink-dir-junction-relative.js index d4e32c4b7eeb5a..9244dd20b4349c 100644 --- a/test/parallel/test-fs-symlink-dir-junction-relative.js +++ b/test/parallel/test-fs-symlink-dir-junction-relative.js @@ -1,15 +1,15 @@ 'use strict'; // Test creating and resolving relative junction or symbolic link -var common = require('../common'); -var assert = require('assert'); -var path = require('path'); -var fs = require('fs'); +const common = require('../common'); +const assert = require('assert'); +const path = require('path'); +const fs = require('fs'); -var linkPath1 = path.join(common.tmpDir, 'junction1'); -var linkPath2 = path.join(common.tmpDir, 'junction2'); -var linkTarget = path.join(common.fixturesDir); -var linkData = path.join(common.fixturesDir); +const linkPath1 = path.join(common.tmpDir, 'junction1'); +const linkPath2 = path.join(common.tmpDir, 'junction2'); +const linkTarget = path.join(common.fixturesDir); +const linkData = path.join(common.fixturesDir); common.refreshTmpDir(); @@ -24,11 +24,11 @@ fs.symlinkSync(linkData, linkPath2, 'junction'); verifyLink(linkPath2); function verifyLink(linkPath) { - var stats = fs.lstatSync(linkPath); + const stats = fs.lstatSync(linkPath); assert.ok(stats.isSymbolicLink()); - var data1 = fs.readFileSync(linkPath + '/x.txt', 'ascii'); - var data2 = fs.readFileSync(linkTarget + '/x.txt', 'ascii'); + const data1 = fs.readFileSync(linkPath + '/x.txt', 'ascii'); + const data2 = fs.readFileSync(linkTarget + '/x.txt', 'ascii'); assert.strictEqual(data1, data2); // Clean up. diff --git a/test/parallel/test-fs-symlink.js b/test/parallel/test-fs-symlink.js index ab52ba22923f3d..9f3f0251e76b58 100644 --- a/test/parallel/test-fs-symlink.js +++ b/test/parallel/test-fs-symlink.js @@ -5,8 +5,8 @@ const path = require('path'); const fs = require('fs'); const exec = require('child_process').exec; -var linkTime; -var fileTime; +let linkTime; +let fileTime; if (common.isWindows) { // On Windows, creating symlinks requires admin privileges. diff --git a/test/parallel/test-fs-sync-fd-leak.js b/test/parallel/test-fs-sync-fd-leak.js index f7cfd25f4b9b4c..0adf407d25d7a4 100644 --- a/test/parallel/test-fs-sync-fd-leak.js +++ b/test/parallel/test-fs-sync-fd-leak.js @@ -1,12 +1,14 @@ 'use strict'; require('../common'); -var assert = require('assert'); -var fs = require('fs'); +const assert = require('assert'); +const fs = require('fs'); // ensure that (read|write|append)FileSync() closes the file descriptor fs.openSync = function() { return 42; }; + +let close_called = 0; fs.closeSync = function(fd) { assert.equal(fd, 42); close_called++; @@ -32,9 +34,8 @@ ensureThrows(function() { fs.appendFileSync('dummy', 'xxx'); }); -var close_called = 0; function ensureThrows(cb) { - var got_exception = false; + let got_exception = false; close_called = 0; try { diff --git a/test/parallel/test-fs-truncate-GH-6233.js b/test/parallel/test-fs-truncate-GH-6233.js index acfdd1ccae1259..95eaf12cbb77f9 100644 --- a/test/parallel/test-fs-truncate-GH-6233.js +++ b/test/parallel/test-fs-truncate-GH-6233.js @@ -1,9 +1,9 @@ 'use strict'; -var common = require('../common'); -var assert = require('assert'); -var fs = require('fs'); +const common = require('../common'); +const assert = require('assert'); +const fs = require('fs'); -var filename = common.tmpDir + '/truncate-file.txt'; +const filename = common.tmpDir + '/truncate-file.txt'; common.refreshTmpDir(); diff --git a/test/parallel/test-fs-utimes.js b/test/parallel/test-fs-utimes.js index 108ca7c7d71c03..b28a2b96e2075e 100644 --- a/test/parallel/test-fs-utimes.js +++ b/test/parallel/test-fs-utimes.js @@ -1,8 +1,8 @@ 'use strict'; -var common = require('../common'); -var assert = require('assert'); -var util = require('util'); -var fs = require('fs'); +const common = require('../common'); +const assert = require('assert'); +const util = require('util'); +const fs = require('fs'); let tests_ok = 0; let tests_run = 0; diff --git a/test/parallel/test-fs-watch-recursive.js b/test/parallel/test-fs-watch-recursive.js index 97c65fccf4a1fb..5fb13623dff543 100644 --- a/test/parallel/test-fs-watch-recursive.js +++ b/test/parallel/test-fs-watch-recursive.js @@ -22,7 +22,7 @@ const filepathOne = path.join(testsubdir, filenameOne); const watcher = fs.watch(testDir, {recursive: true}); -var watcherClosed = false; +let watcherClosed = false; watcher.on('change', function(event, filename) { assert.ok('change' === event || 'rename' === event); @@ -37,8 +37,9 @@ watcher.on('change', function(event, filename) { watcherClosed = true; }); +let interval; if (common.isOSX) { - var interval = setInterval(function() { + interval = setInterval(function() { fs.writeFileSync(filepathOne, 'world'); }, 10); } else { diff --git a/test/parallel/test-fs-watchfile.js b/test/parallel/test-fs-watchfile.js index d30261859c39b7..fcd28be0c1f126 100644 --- a/test/parallel/test-fs-watchfile.js +++ b/test/parallel/test-fs-watchfile.js @@ -40,7 +40,7 @@ common.refreshTmpDir(); // If the file initially didn't exist, and gets created at a later point of // time, the callback should be invoked again with proper values in stat object -var fileExists = false; +let fileExists = false; fs.watchFile(enoentFile, {interval: 0}, common.mustCall(function(curr, prev) { if (!fileExists) { diff --git a/test/parallel/test-fs-write-buffer.js b/test/parallel/test-fs-write-buffer.js index b6404a036a78c2..7b4081010fd6d7 100644 --- a/test/parallel/test-fs-write-buffer.js +++ b/test/parallel/test-fs-write-buffer.js @@ -23,7 +23,7 @@ fs.open(filename, 'w', 0o644, common.mustCall(function(err, fd) { assert.equal(expected.length, written); fs.closeSync(fd); - var found = fs.readFileSync(filename, 'utf8'); + const found = fs.readFileSync(filename, 'utf8'); assert.deepStrictEqual(expected.toString(), found); fs.unlinkSync(filename); })); diff --git a/test/parallel/test-fs-write-file-buffer.js b/test/parallel/test-fs-write-file-buffer.js index a23ccc21336976..409ddf1d51f557 100644 --- a/test/parallel/test-fs-write-file-buffer.js +++ b/test/parallel/test-fs-write-file-buffer.js @@ -1,10 +1,10 @@ 'use strict'; -var common = require('../common'); -var join = require('path').join; -var util = require('util'); -var fs = require('fs'); +const common = require('../common'); +const join = require('path').join; +const util = require('util'); +const fs = require('fs'); -var data = [ +let data = [ '/9j/4AAQSkZJRgABAQAAAQABAAD/2wBDAAUDBAQEAwUEBAQFBQUGBwwIBwcH', 'Bw8LCwkMEQ8SEhEPERETFhwXExQaFRERGCEYGh0dHx8fExciJCIeJBweHx7/', '2wBDAQUFBQcGBw4ICA4eFBEUHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4e', @@ -27,7 +27,7 @@ data = data.join('\n'); common.refreshTmpDir(); -var buf = Buffer.from(data, 'base64'); +const buf = Buffer.from(data, 'base64'); fs.writeFileSync(join(common.tmpDir, 'test.jpg'), buf); util.log('Done!'); diff --git a/test/parallel/test-fs-write-stream-change-open.js b/test/parallel/test-fs-write-stream-change-open.js index a9d31a3074dcd6..f68cc0a6d386e2 100644 --- a/test/parallel/test-fs-write-stream-change-open.js +++ b/test/parallel/test-fs-write-stream-change-open.js @@ -4,7 +4,7 @@ const assert = require('assert'); const path = require('path'); const fs = require('fs'); -var file = path.join(common.tmpDir, 'write.txt'); +const file = path.join(common.tmpDir, 'write.txt'); common.refreshTmpDir(); diff --git a/test/parallel/test-fs-write-stream-end.js b/test/parallel/test-fs-write-stream-end.js index ade6777d5f68ac..6329aee4167d7b 100644 --- a/test/parallel/test-fs-write-stream-end.js +++ b/test/parallel/test-fs-write-stream-end.js @@ -1,8 +1,8 @@ 'use strict'; -var common = require('../common'); -var assert = require('assert'); -var path = require('path'); -var fs = require('fs'); +const common = require('../common'); +const assert = require('assert'); +const path = require('path'); +const fs = require('fs'); common.refreshTmpDir(); diff --git a/test/parallel/test-fs-write-stream-err.js b/test/parallel/test-fs-write-stream-err.js index c1151b12531f92..d50fd07103222e 100644 --- a/test/parallel/test-fs-write-stream-err.js +++ b/test/parallel/test-fs-write-stream-err.js @@ -1,17 +1,17 @@ 'use strict'; -var common = require('../common'); -var assert = require('assert'); -var fs = require('fs'); +const common = require('../common'); +const assert = require('assert'); +const fs = require('fs'); common.refreshTmpDir(); -var stream = fs.createWriteStream(common.tmpDir + '/out', { +const stream = fs.createWriteStream(common.tmpDir + '/out', { highWaterMark: 10 }); -var err = new Error('BAM'); +const err = new Error('BAM'); -var write = fs.write; -var writeCalls = 0; +const write = fs.write; +let writeCalls = 0; fs.write = function() { switch (writeCalls++) { case 0: @@ -21,7 +21,7 @@ fs.write = function() { case 1: // then it breaks console.error('second write'); - var cb = arguments[arguments.length - 1]; + const cb = arguments[arguments.length - 1]; return process.nextTick(function() { cb(err); }); diff --git a/test/parallel/test-fs-write-stream.js b/test/parallel/test-fs-write-stream.js index 71aaaa75dd5845..a3ba0377e2e26e 100644 --- a/test/parallel/test-fs-write-stream.js +++ b/test/parallel/test-fs-write-stream.js @@ -4,7 +4,7 @@ const assert = require('assert'); const path = require('path'); const fs = require('fs'); -var file = path.join(common.tmpDir, 'write.txt'); +const file = path.join(common.tmpDir, 'write.txt'); common.refreshTmpDir(); diff --git a/test/parallel/test-fs-write-string-coerce.js b/test/parallel/test-fs-write-string-coerce.js index 5c7999e9b1158c..9daae645822acb 100644 --- a/test/parallel/test-fs-write-string-coerce.js +++ b/test/parallel/test-fs-write-string-coerce.js @@ -1,15 +1,15 @@ 'use strict'; -var common = require('../common'); -var assert = require('assert'); -var path = require('path'); -var Buffer = require('buffer').Buffer; -var fs = require('fs'); +const common = require('../common'); +const assert = require('assert'); +const path = require('path'); +const Buffer = require('buffer').Buffer; +const fs = require('fs'); common.refreshTmpDir(); -var fn = path.join(common.tmpDir, 'write-string-coerce.txt'); -var data = true; -var expected = data + ''; +const fn = path.join(common.tmpDir, 'write-string-coerce.txt'); +const data = true; +const expected = data + ''; fs.open(fn, 'w', 0o644, common.mustCall(function(err, fd) { if (err) throw err; diff --git a/test/parallel/test-fs-write-sync.js b/test/parallel/test-fs-write-sync.js index 12f34f81d8e06b..8f1a8f75c5dac0 100644 --- a/test/parallel/test-fs-write-sync.js +++ b/test/parallel/test-fs-write-sync.js @@ -1,21 +1,21 @@ 'use strict'; -var common = require('../common'); -var assert = require('assert'); -var path = require('path'); -var fs = require('fs'); -var fn = path.join(common.tmpDir, 'write.txt'); +const common = require('../common'); +const assert = require('assert'); +const path = require('path'); +const fs = require('fs'); +const fn = path.join(common.tmpDir, 'write.txt'); common.refreshTmpDir(); -var foo = 'foo'; -var fd = fs.openSync(fn, 'w'); +const foo = 'foo'; +const fd = fs.openSync(fn, 'w'); -var written = fs.writeSync(fd, ''); +let written = fs.writeSync(fd, ''); assert.strictEqual(0, written); fs.writeSync(fd, foo); -var bar = 'bár'; +const bar = 'bár'; written = fs.writeSync(fd, Buffer.from(bar), 0, Buffer.byteLength(bar)); assert.ok(written > 3); fs.closeSync(fd); diff --git a/test/parallel/test-global-console-exists.js b/test/parallel/test-global-console-exists.js index 32e640cc52f7fc..d4a7c21222b807 100644 --- a/test/parallel/test-global-console-exists.js +++ b/test/parallel/test-global-console-exists.js @@ -9,7 +9,7 @@ const assert = require('assert'); const EventEmitter = require('events'); const leak_warning = /EventEmitter memory leak detected\. 2 hello listeners/; -var write_calls = 0; +let write_calls = 0; process.on('warning', (warning) => { // This will be called after the default internal diff --git a/test/parallel/test-global.js b/test/parallel/test-global.js index 1bf1bd7cd69303..9ebbd0f604434d 100644 --- a/test/parallel/test-global.js +++ b/test/parallel/test-global.js @@ -15,8 +15,8 @@ assert.strictEqual('bar', baseBar, // eslint-disable-line no-undef 'global.x -> x in base level not working'); -var module = require(path.join(common.fixturesDir, 'global', 'plain')); -const fooBar = module.fooBar; +const mod = require(path.join(common.fixturesDir, 'global', 'plain')); +const fooBar = mod.fooBar; assert.strictEqual('foo', fooBar.foo, 'x -> global.x in sub level not working'); diff --git a/test/parallel/test-http-1.0-keep-alive.js b/test/parallel/test-http-1.0-keep-alive.js index 383f67c90a31b5..dea5f65c54184d 100644 --- a/test/parallel/test-http-1.0-keep-alive.js +++ b/test/parallel/test-http-1.0-keep-alive.js @@ -1,7 +1,7 @@ 'use strict'; require('../common'); -var http = require('http'); -var net = require('net'); +const http = require('http'); +const net = require('net'); // Check that our HTTP server correctly handles HTTP/1.0 keep-alive requests. check([{ @@ -83,12 +83,12 @@ check([{ }]); function check(tests) { - var test = tests[0]; - var server; + const test = tests[0]; + let server; if (test) { server = http.createServer(serverHandler).listen(0, '127.0.0.1', client); } - var current = 0; + let current = 0; function next() { check(tests.slice(1)); @@ -96,7 +96,7 @@ function check(tests) { function serverHandler(req, res) { if (current + 1 === test.responses.length) this.close(); - var ctx = test.responses[current]; + const ctx = test.responses[current]; console.error('< SERVER SENDING RESPONSE', ctx); res.writeHead(200, ctx.headers); ctx.chunks.slice(0, -1).forEach(function(chunk) { res.write(chunk); }); @@ -106,10 +106,10 @@ function check(tests) { function client() { if (current === test.requests.length) return next(); const port = server.address().port; - var conn = net.createConnection(port, '127.0.0.1', connected); + const conn = net.createConnection(port, '127.0.0.1', connected); function connected() { - var ctx = test.requests[current]; + const ctx = test.requests[current]; console.error(' > CLIENT SENDING REQUEST', ctx); conn.setEncoding('utf8'); conn.write(ctx.data); diff --git a/test/parallel/test-http-1.0.js b/test/parallel/test-http-1.0.js index d01613de45452d..d98da182a9fee5 100644 --- a/test/parallel/test-http-1.0.js +++ b/test/parallel/test-http-1.0.js @@ -1,20 +1,20 @@ 'use strict'; -var common = require('../common'); -var assert = require('assert'); -var net = require('net'); -var http = require('http'); +const common = require('../common'); +const assert = require('assert'); +const net = require('net'); +const http = require('http'); -var body = 'hello world\n'; +const body = 'hello world\n'; function test(handler, request_generator, response_validator) { - var server = http.createServer(handler); + const server = http.createServer(handler); - var client_got_eof = false; - var server_response = ''; + let client_got_eof = false; + let server_response = ''; server.listen(0); server.on('listening', function() { - var c = net.createConnection(this.address().port); + const c = net.createConnection(this.address().port); c.setEncoding('utf8'); diff --git a/test/parallel/test-http-abort-before-end.js b/test/parallel/test-http-abort-before-end.js index ee22dc847b5882..046f439cb33195 100644 --- a/test/parallel/test-http-abort-before-end.js +++ b/test/parallel/test-http-abort-before-end.js @@ -1,12 +1,12 @@ 'use strict'; const common = require('../common'); -var http = require('http'); -var assert = require('assert'); +const http = require('http'); +const assert = require('assert'); -var server = http.createServer(common.fail); +const server = http.createServer(common.fail); server.listen(0, function() { - var req = http.request({ + const req = http.request({ method: 'GET', host: '127.0.0.1', port: this.address().port diff --git a/test/parallel/test-http-abort-client.js b/test/parallel/test-http-abort-client.js index addcec1ef3e9f9..6c00a1e6c64328 100644 --- a/test/parallel/test-http-abort-client.js +++ b/test/parallel/test-http-abort-client.js @@ -1,8 +1,8 @@ 'use strict'; const common = require('../common'); -var http = require('http'); +const http = require('http'); -var server = http.Server(function(req, res) { +const server = http.Server(function(req, res) { console.log('Server accepted request.'); res.writeHead(200); res.write('Part of my res.'); diff --git a/test/parallel/test-http-abort-queued.js b/test/parallel/test-http-abort-queued.js index 0a993a2658ca11..8e8339aa82d3dd 100644 --- a/test/parallel/test-http-abort-queued.js +++ b/test/parallel/test-http-abort-queued.js @@ -3,9 +3,9 @@ require('../common'); const assert = require('assert'); const http = require('http'); -var complete; +let complete; -var server = http.createServer(function(req, res) { +const server = http.createServer(function(req, res) { // We should not see the queued /thatotherone request within the server // as it should be aborted before it is sent. assert.equal(req.url, '/'); @@ -22,10 +22,10 @@ var server = http.createServer(function(req, res) { server.listen(0, function() { console.log('listen', server.address().port); - var agent = new http.Agent({maxSockets: 1}); + const agent = new http.Agent({maxSockets: 1}); assert.equal(Object.keys(agent.sockets).length, 0); - var options = { + const options = { hostname: 'localhost', port: server.address().port, method: 'GET', @@ -33,12 +33,12 @@ server.listen(0, function() { agent: agent }; - var req1 = http.request(options); + const req1 = http.request(options); req1.on('response', function(res1) { assert.equal(Object.keys(agent.sockets).length, 1); assert.equal(Object.keys(agent.requests).length, 0); - var req2 = http.request({ + const req2 = http.request({ method: 'GET', host: 'localhost', port: server.address().port, diff --git a/test/parallel/test-http-after-connect.js b/test/parallel/test-http-after-connect.js index 0580f428ed70f5..a93d0b83aa6f4f 100644 --- a/test/parallel/test-http-after-connect.js +++ b/test/parallel/test-http-after-connect.js @@ -3,7 +3,7 @@ const common = require('../common'); const assert = require('assert'); const http = require('http'); -var clientResponses = 0; +let clientResponses = 0; const server = http.createServer(common.mustCall(function(req, res) { console.error('Server got GET request'); @@ -46,7 +46,7 @@ function doRequest(i) { path: '/request' + i }, common.mustCall(function(res) { console.error('Client got GET response'); - var data = ''; + let data = ''; res.setEncoding('utf8'); res.on('data', function(chunk) { data += chunk; diff --git a/test/parallel/test-http-agent-destroyed-socket.js b/test/parallel/test-http-agent-destroyed-socket.js index a2693637728439..4bb14c2d7e01ce 100644 --- a/test/parallel/test-http-agent-destroyed-socket.js +++ b/test/parallel/test-http-agent-destroyed-socket.js @@ -1,28 +1,28 @@ 'use strict'; require('../common'); -var assert = require('assert'); -var http = require('http'); +const assert = require('assert'); +const http = require('http'); -var server = http.createServer(function(req, res) { +const server = http.createServer(function(req, res) { res.writeHead(200, {'Content-Type': 'text/plain'}); res.end('Hello World\n'); }).listen(0, function() { - var agent = new http.Agent({maxSockets: 1}); + const agent = new http.Agent({maxSockets: 1}); agent.on('free', function(socket, host, port) { console.log('freeing socket. destroyed? ', socket.destroyed); }); - var requestOptions = { + const requestOptions = { agent: agent, host: 'localhost', port: this.address().port, path: '/' }; - var request1 = http.get(requestOptions, function(response) { + const request1 = http.get(requestOptions, function(response) { // assert request2 is queued in the agent - var key = agent.getName(requestOptions); + const key = agent.getName(requestOptions); assert.strictEqual(agent.requests[key].length, 1); console.log('got response1'); request1.socket.on('close', function() { @@ -58,14 +58,14 @@ var server = http.createServer(function(req, res) { }); }); - var request2 = http.get(requestOptions, function(response) { + let request2 = http.get(requestOptions, function(response) { assert(!request2.socket.destroyed); assert(request1.socket.destroyed); // assert not reusing the same socket, since it was destroyed. assert.notStrictEqual(request1.socket, request2.socket); console.log('got response2'); - var gotClose = false; - var gotResponseEnd = false; + let gotClose = false; + let gotResponseEnd = false; request2.socket.on('close', function() { console.log('request2 socket closed'); gotClose = true; diff --git a/test/parallel/test-http-agent-error-on-idle.js b/test/parallel/test-http-agent-error-on-idle.js index 59b0109ef1c398..b2bf6334dcbc1b 100644 --- a/test/parallel/test-http-agent-error-on-idle.js +++ b/test/parallel/test-http-agent-error-on-idle.js @@ -1,38 +1,38 @@ 'use strict'; require('../common'); -var assert = require('assert'); -var http = require('http'); -var Agent = http.Agent; +const assert = require('assert'); +const http = require('http'); +const Agent = http.Agent; -var server = http.createServer(function(req, res) { +const server = http.createServer(function(req, res) { res.end('hello world'); }); server.listen(0, function() { - var agent = new Agent({ + const agent = new Agent({ keepAlive: true, }); - var requestParams = { + const requestParams = { host: 'localhost', port: this.address().port, agent: agent, path: '/' }; - var socketKey = agent.getName(requestParams); + const socketKey = agent.getName(requestParams); get(function(res) { assert.equal(res.statusCode, 200); res.resume(); res.on('end', function() { process.nextTick(function() { - var freeSockets = agent.freeSockets[socketKey]; + const freeSockets = agent.freeSockets[socketKey]; assert.equal(freeSockets.length, 1, 'expect a free socket on ' + socketKey); //generate a random error on the free socket - var freeSocket = freeSockets[0]; + const freeSocket = freeSockets[0]; freeSocket.emit('error', new Error('ECONNRESET: test')); get(done); diff --git a/test/parallel/test-http-agent-false.js b/test/parallel/test-http-agent-false.js index 96606028bf7a45..5c9907bb706d32 100644 --- a/test/parallel/test-http-agent-false.js +++ b/test/parallel/test-http-agent-false.js @@ -1,12 +1,12 @@ 'use strict'; require('../common'); -var assert = require('assert'); -var http = require('http'); +const assert = require('assert'); +const http = require('http'); // sending `agent: false` when `port: null` is also passed in (i.e. the result // of a `url.parse()` call with the default port used, 80 or 443), should not // result in an assertion error... -var opts = { +const opts = { host: '127.0.0.1', port: null, path: '/', @@ -14,7 +14,7 @@ var opts = { agent: false }; -var good = false; +let good = false; process.on('exit', function() { assert(good, 'expected either an "error" or "response" event'); }); @@ -22,7 +22,7 @@ process.on('exit', function() { // we just want an "error" (no local HTTP server on port 80) or "response" // to happen (user happens ot have HTTP server running on port 80). // As long as the process doesn't crash from a C++ assertion then we're good. -var req = http.request(opts); +const req = http.request(opts); req.on('response', function(res) { good = true; }); diff --git a/test/parallel/test-http-agent-maxsockets-regress-4050.js b/test/parallel/test-http-agent-maxsockets-regress-4050.js index 0ba3d1304f0d68..fd3a8c33f3e39a 100644 --- a/test/parallel/test-http-agent-maxsockets-regress-4050.js +++ b/test/parallel/test-http-agent-maxsockets-regress-4050.js @@ -26,9 +26,9 @@ function get(path, callback) { } server.listen(0, function() { - var finished = 0; + let finished = 0; const num_requests = 6; - for (var i = 0; i < num_requests; i++) { + for (let i = 0; i < num_requests; i++) { const request = get('/1', function() { }); request.on('response', function() { diff --git a/test/parallel/test-http-agent-maxsockets.js b/test/parallel/test-http-agent-maxsockets.js index ea443ff9bd1107..6814aca3e76fbc 100644 --- a/test/parallel/test-http-agent-maxsockets.js +++ b/test/parallel/test-http-agent-maxsockets.js @@ -1,16 +1,16 @@ 'use strict'; require('../common'); -var assert = require('assert'); -var http = require('http'); +const assert = require('assert'); +const http = require('http'); -var agent = new http.Agent({ +const agent = new http.Agent({ keepAlive: true, keepAliveMsecs: 1000, maxSockets: 2, maxFreeSockets: 2 }); -var server = http.createServer(function(req, res) { +const server = http.createServer(function(req, res) { res.end('hello world'); }); @@ -23,12 +23,12 @@ function get(path, callback) { }, callback); } -var count = 0; +let count = 0; function done() { if (++count !== 2) { return; } - var freepool = agent.freeSockets[Object.keys(agent.freeSockets)[0]]; + const freepool = agent.freeSockets[Object.keys(agent.freeSockets)[0]]; assert.equal(freepool.length, 2, 'expect keep 2 free sockets, but got ' + freepool.length); agent.destroy(); diff --git a/test/parallel/test-http-agent-no-protocol.js b/test/parallel/test-http-agent-no-protocol.js index 94fd525b908c30..a11489b6c5bc2b 100644 --- a/test/parallel/test-http-agent-no-protocol.js +++ b/test/parallel/test-http-agent-no-protocol.js @@ -1,12 +1,12 @@ 'use strict'; const common = require('../common'); -var http = require('http'); -var url = require('url'); +const http = require('http'); +const url = require('url'); -var server = http.createServer(common.mustCall(function(req, res) { +const server = http.createServer(common.mustCall(function(req, res) { res.end(); })).listen(0, '127.0.0.1', common.mustCall(function() { - var opts = url.parse(`http://127.0.0.1:${this.address().port}/`); + const opts = url.parse(`http://127.0.0.1:${this.address().port}/`); // remove the `protocol` field… the `http` module should fall back // to "http:", as defined by the global, default `http.Agent` instance. diff --git a/test/parallel/test-http-agent-null.js b/test/parallel/test-http-agent-null.js index f1dfeddea8b0e3..9071b88b98997a 100644 --- a/test/parallel/test-http-agent-null.js +++ b/test/parallel/test-http-agent-null.js @@ -1,11 +1,11 @@ 'use strict'; const common = require('../common'); -var http = require('http'); +const http = require('http'); -var server = http.createServer(common.mustCall(function(req, res) { +const server = http.createServer(common.mustCall(function(req, res) { res.end(); })).listen(0, common.mustCall(function() { - var options = { + const options = { agent: null, port: this.address().port }; diff --git a/test/parallel/test-http-agent.js b/test/parallel/test-http-agent.js index dae982ed51a302..85975979cb3265 100644 --- a/test/parallel/test-http-agent.js +++ b/test/parallel/test-http-agent.js @@ -1,22 +1,22 @@ 'use strict'; require('../common'); -var assert = require('assert'); -var http = require('http'); +const assert = require('assert'); +const http = require('http'); -var server = http.Server(function(req, res) { +const server = http.Server(function(req, res) { res.writeHead(200); res.end('hello world\n'); }); -var responses = 0; -var N = 4; -var M = 4; +let responses = 0; +const N = 4; +const M = 4; server.listen(0, function() { const port = this.address().port; - for (var i = 0; i < N; i++) { + for (let i = 0; i < N; i++) { setTimeout(function() { - for (var j = 0; j < M; j++) { + for (let j = 0; j < M; j++) { http.get({ port: port, path: '/' }, function(res) { console.log('%d %d', responses, res.statusCode); if (++responses === N * M) { diff --git a/test/parallel/test-http-automatic-headers.js b/test/parallel/test-http-automatic-headers.js index 600be8e43ee23c..5fc8d780af9396 100644 --- a/test/parallel/test-http-automatic-headers.js +++ b/test/parallel/test-http-automatic-headers.js @@ -1,9 +1,9 @@ 'use strict'; require('../common'); -var assert = require('assert'); -var http = require('http'); +const assert = require('assert'); +const http = require('http'); -var server = http.createServer(function(req, res) { +const server = http.createServer(function(req, res) { res.setHeader('X-Date', 'foo'); res.setHeader('X-Connection', 'bar'); res.setHeader('X-Content-Length', 'baz'); @@ -12,7 +12,7 @@ var server = http.createServer(function(req, res) { server.listen(0); server.on('listening', function() { - var agent = new http.Agent({ port: this.address().port, maxSockets: 1 }); + const agent = new http.Agent({ port: this.address().port, maxSockets: 1 }); http.get({ port: this.address().port, path: '/hello', diff --git a/test/parallel/test-http-blank-header.js b/test/parallel/test-http-blank-header.js index 13b1a2f3b0d449..2a6bf482077166 100644 --- a/test/parallel/test-http-blank-header.js +++ b/test/parallel/test-http-blank-header.js @@ -1,10 +1,10 @@ 'use strict'; const common = require('../common'); -var assert = require('assert'); -var http = require('http'); -var net = require('net'); +const assert = require('assert'); +const http = require('http'); +const net = require('net'); -var server = http.createServer(common.mustCall(function(req, res) { +const server = http.createServer(common.mustCall(function(req, res) { assert.equal('GET', req.method); assert.equal('/blah', req.url); assert.deepStrictEqual({ @@ -16,7 +16,7 @@ var server = http.createServer(common.mustCall(function(req, res) { server.listen(0, function() { - var c = net.createConnection(this.address().port); + const c = net.createConnection(this.address().port); c.on('connect', function() { c.write('GET /blah HTTP/1.1\r\n' + diff --git a/test/parallel/test-http-buffer-sanity.js b/test/parallel/test-http-buffer-sanity.js index 542d4ad5af2cbc..c240cd13b1825c 100644 --- a/test/parallel/test-http-buffer-sanity.js +++ b/test/parallel/test-http-buffer-sanity.js @@ -1,28 +1,28 @@ 'use strict'; const common = require('../common'); -var assert = require('assert'); -var http = require('http'); +const assert = require('assert'); +const http = require('http'); -var bufferSize = 5 * 1024 * 1024; -var measuredSize = 0; +const bufferSize = 5 * 1024 * 1024; +let measuredSize = 0; -var buffer = Buffer.allocUnsafe(bufferSize); -for (var i = 0; i < buffer.length; i++) { +const buffer = Buffer.allocUnsafe(bufferSize); +for (let i = 0; i < buffer.length; i++) { buffer[i] = i % 256; } -var web = http.Server(function(req, res) { +const web = http.Server(function(req, res) { web.close(); console.log(req.headers); - var i = 0; + let i = 0; req.on('data', function(d) { process.stdout.write(','); measuredSize += d.length; - for (var j = 0; j < d.length; j++) { + for (let j = 0; j < d.length; j++) { assert.equal(buffer[i], d[j]); i++; } @@ -45,7 +45,7 @@ var web = http.Server(function(req, res) { web.listen(0, common.mustCall(function() { console.log('Making request'); - var req = http.request({ + const req = http.request({ port: this.address().port, method: 'GET', path: '/', diff --git a/test/parallel/test-http-byteswritten.js b/test/parallel/test-http-byteswritten.js index bb914439a76b78..3b295ebdcc1c49 100644 --- a/test/parallel/test-http-byteswritten.js +++ b/test/parallel/test-http-byteswritten.js @@ -1,11 +1,11 @@ 'use strict'; const common = require('../common'); -var assert = require('assert'); -var http = require('http'); +const assert = require('assert'); +const http = require('http'); -var body = 'hello world\n'; +const body = 'hello world\n'; -var httpServer = http.createServer(common.mustCall(function(req, res) { +const httpServer = http.createServer(common.mustCall(function(req, res) { httpServer.close(); res.on('finish', common.mustCall(function() { @@ -16,9 +16,9 @@ var httpServer = http.createServer(common.mustCall(function(req, res) { // Write 1.5mb to cause some requests to buffer // Also, mix up the encodings a bit. - var chunk = new Array(1024 + 1).join('7'); - var bchunk = Buffer.from(chunk); - for (var i = 0; i < 1024; i++) { + const chunk = new Array(1024 + 1).join('7'); + const bchunk = Buffer.from(chunk); + for (let i = 0; i < 1024; i++) { res.write(chunk); res.write(bchunk); res.write(chunk, 'hex'); diff --git a/test/parallel/test-http-chunked-304.js b/test/parallel/test-http-chunked-304.js index 82fe138fd926da..b130004d1a83e7 100644 --- a/test/parallel/test-http-chunked-304.js +++ b/test/parallel/test-http-chunked-304.js @@ -1,8 +1,8 @@ 'use strict'; -var common = require('../common'); -var assert = require('assert'); -var http = require('http'); -var net = require('net'); +const common = require('../common'); +const assert = require('assert'); +const http = require('http'); +const net = require('net'); // RFC 2616, section 10.2.5: // diff --git a/test/parallel/test-http-chunked.js b/test/parallel/test-http-chunked.js index bb91dadd159de5..516523221133ec 100644 --- a/test/parallel/test-http-chunked.js +++ b/test/parallel/test-http-chunked.js @@ -1,25 +1,25 @@ 'use strict'; require('../common'); -var assert = require('assert'); -var http = require('http'); +const assert = require('assert'); +const http = require('http'); -var UTF8_STRING = '南越国是前203年至前111年存在于岭南地区的一个国家,' + - '国都位于番禺,疆域包括今天中国的广东、广西两省区的大部份地区,福建省、湖南、' + - '贵州、云南的一小部份地区和越南的北部。南越国是秦朝灭亡后,' + - '由南海郡尉赵佗于前203年起兵兼并桂林郡和象郡后建立。前196年和前179年,' + - '南越国曾先后两次名义上臣属于西汉,成为西汉的“外臣”。前112年,' + - '南越国末代君主赵建德与西汉发生战争,被汉武帝于前111年所灭。' + - '南越国共存在93年,历经五代君主。南越国是岭南地区的第一个有记载的政权国家,' + - '采用封建制和郡县制并存的制度,它的建立保证了秦末乱世岭南地区社会秩序的稳定,' + - '有效的改善了岭南地区落后的政治、经济现状。'; +const UTF8_STRING = '南越国是前203年至前111年存在于岭南地区的一个国家,' + + '国都位于番禺,疆域包括今天中国的广东、广西两省区的大部份地区,福建省、湖南、' + + '贵州、云南的一小部份地区和越南的北部。南越国是秦朝灭亡后,' + + '由南海郡尉赵佗于前203年起兵兼并桂林郡和象郡后建立。前196年和前179年,' + + '南越国曾先后两次名义上臣属于西汉,成为西汉的“外臣”。前112年,' + + '南越国末代君主赵建德与西汉发生战争,被汉武帝于前111年所灭。' + + '南越国共存在93年,历经五代君主。南越国是岭南地区的第一个有记载的政权国家,' + + '采用封建制和郡县制并存的制度,它的建立保证了秦末乱世岭南地区社会秩序的稳定,' + + '有效的改善了岭南地区落后的政治、经济现状。'; -var server = http.createServer(function(req, res) { +const server = http.createServer(function(req, res) { res.writeHead(200, {'Content-Type': 'text/plain; charset=utf8'}); res.end(UTF8_STRING, 'utf8'); }); server.listen(0, function() { - var data = ''; - var get = http.get({ + let data = ''; + const get = http.get({ path: '/', host: 'localhost', port: this.address().port diff --git a/test/parallel/test-http-client-abort-event.js b/test/parallel/test-http-client-abort-event.js index c0c1f9e4c73c92..b62186e724d919 100644 --- a/test/parallel/test-http-client-abort-event.js +++ b/test/parallel/test-http-client-abort-event.js @@ -1,12 +1,12 @@ 'use strict'; const common = require('../common'); -var http = require('http'); -var server = http.createServer(function(req, res) { +const http = require('http'); +const server = http.createServer(function(req, res) { res.end(); }); server.listen(0, common.mustCall(function() { - var req = http.request({ + const req = http.request({ port: this.address().port }, common.fail); diff --git a/test/parallel/test-http-client-abort.js b/test/parallel/test-http-client-abort.js index 4f46128f0e804a..738c620815a21a 100644 --- a/test/parallel/test-http-client-abort.js +++ b/test/parallel/test-http-client-abort.js @@ -3,7 +3,7 @@ require('../common'); const assert = require('assert'); const http = require('http'); -var clientAborts = 0; +let clientAborts = 0; const server = http.Server(function(req, res) { console.log('Got connection'); @@ -23,17 +23,17 @@ const server = http.Server(function(req, res) { }); }); -var responses = 0; +let responses = 0; const N = 8; const requests = []; server.listen(0, function() { console.log('Server listening.'); - for (var i = 0; i < N; i++) { + for (let i = 0; i < N; i++) { console.log('Making client ' + i); - var options = { port: this.address().port, path: '/?id=' + i }; - var req = http.get(options, function(res) { + const options = { port: this.address().port, path: '/?id=' + i }; + const req = http.get(options, function(res) { console.log('Client response code ' + res.statusCode); res.resume(); diff --git a/test/parallel/test-http-client-abort2.js b/test/parallel/test-http-client-abort2.js index 30269a193f0eab..7c7be9b530e2d2 100644 --- a/test/parallel/test-http-client-abort2.js +++ b/test/parallel/test-http-client-abort2.js @@ -1,13 +1,13 @@ 'use strict'; require('../common'); -var http = require('http'); +const http = require('http'); -var server = http.createServer(function(req, res) { +const server = http.createServer(function(req, res) { res.end('Hello'); }); server.listen(0, function() { - var req = http.get({port: this.address().port}, function(res) { + const req = http.get({port: this.address().port}, function(res) { res.on('data', function(data) { req.abort(); server.close(); diff --git a/test/parallel/test-http-client-agent.js b/test/parallel/test-http-client-agent.js index 36ed24ec526255..3c2b9c89727467 100644 --- a/test/parallel/test-http-client-agent.js +++ b/test/parallel/test-http-client-agent.js @@ -1,13 +1,13 @@ 'use strict'; require('../common'); -var assert = require('assert'); -var http = require('http'); +const assert = require('assert'); +const http = require('http'); -var name; -var max = 3; -var count = 0; +let name; +const max = 3; +let count = 0; -var server = http.Server(function(req, res) { +const server = http.Server(function(req, res) { if (req.url === '/0') { setTimeout(function() { res.writeHead(200); @@ -20,17 +20,17 @@ var server = http.Server(function(req, res) { }); server.listen(0, function() { name = http.globalAgent.getName({ port: this.address().port }); - for (var i = 0; i < max; ++i) { + for (let i = 0; i < max; ++i) { request(i); } }); function request(i) { - var req = http.get({ + const req = http.get({ port: server.address().port, path: '/' + i }, function(res) { - var socket = req.socket; + const socket = req.socket; socket.on('close', function() { ++count; if (count < max) { diff --git a/test/parallel/test-http-client-default-headers-exist.js b/test/parallel/test-http-client-default-headers-exist.js index 9b73f2db32aad6..2271944773d9db 100644 --- a/test/parallel/test-http-client-default-headers-exist.js +++ b/test/parallel/test-http-client-default-headers-exist.js @@ -1,9 +1,9 @@ 'use strict'; require('../common'); -var assert = require('assert'); -var http = require('http'); +const assert = require('assert'); +const http = require('http'); -var expectedHeaders = { +const expectedHeaders = { 'DELETE': ['host', 'connection'], 'GET': ['host', 'connection'], 'HEAD': ['host', 'connection'], @@ -12,18 +12,18 @@ var expectedHeaders = { 'PUT': ['host', 'connection', 'content-length'] }; -var expectedMethods = Object.keys(expectedHeaders); +const expectedMethods = Object.keys(expectedHeaders); -var requestCount = 0; +let requestCount = 0; -var server = http.createServer(function(req, res) { +const server = http.createServer(function(req, res) { requestCount++; res.end(); assert(expectedHeaders.hasOwnProperty(req.method), req.method + ' was an unexpected method'); - var requestHeaders = Object.keys(req.headers); + const requestHeaders = Object.keys(req.headers); requestHeaders.forEach(function(header) { assert.notStrictEqual( expectedHeaders[req.method].indexOf(header.toLowerCase()), diff --git a/test/parallel/test-http-client-encoding.js b/test/parallel/test-http-client-encoding.js index b02463aa5188d5..d2aa8fdcbbac46 100644 --- a/test/parallel/test-http-client-encoding.js +++ b/test/parallel/test-http-client-encoding.js @@ -1,7 +1,7 @@ 'use strict'; require('../common'); -var http = require('http'); +const http = require('http'); http.createServer(function(req, res) { res.end('ok\n'); diff --git a/test/parallel/test-http-client-get-url.js b/test/parallel/test-http-client-get-url.js index 51f8413b675244..d666fdd8354e71 100644 --- a/test/parallel/test-http-client-get-url.js +++ b/test/parallel/test-http-client-get-url.js @@ -1,9 +1,9 @@ 'use strict'; const common = require('../common'); -var assert = require('assert'); -var http = require('http'); +const assert = require('assert'); +const http = require('http'); -var server = http.createServer(common.mustCall(function(req, res) { +const server = http.createServer(common.mustCall(function(req, res) { assert.equal('GET', req.method); assert.equal('/foo?bar', req.url); res.writeHead(200, {'Content-Type': 'text/plain'}); diff --git a/test/parallel/test-http-client-parse-error.js b/test/parallel/test-http-client-parse-error.js index cd6f135d889534..0d8f577a78566c 100644 --- a/test/parallel/test-http-client-parse-error.js +++ b/test/parallel/test-http-client-parse-error.js @@ -1,12 +1,12 @@ 'use strict'; require('../common'); -var assert = require('assert'); +const assert = require('assert'); -var http = require('http'); -var net = require('net'); +const http = require('http'); +const net = require('net'); -var connects = 0; -var parseErrors = 0; +let connects = 0; +let parseErrors = 0; // Create a TCP server net.createServer(function(c) { @@ -18,7 +18,7 @@ net.createServer(function(c) { this.close(); } }).listen(0, '127.0.0.1', function() { - for (var i = 0; i < 2; i++) { + for (let i = 0; i < 2; i++) { http.request({ host: '127.0.0.1', port: this.address().port, diff --git a/test/parallel/test-http-client-pipe-end.js b/test/parallel/test-http-client-pipe-end.js index 5b2db49435a1b6..d4ccba8d55b036 100644 --- a/test/parallel/test-http-client-pipe-end.js +++ b/test/parallel/test-http-client-pipe-end.js @@ -1,10 +1,10 @@ 'use strict'; // see https://github.com/joyent/node/issues/3257 -var common = require('../common'); -var http = require('http'); +const common = require('../common'); +const http = require('http'); -var server = http.createServer(function(req, res) { +const server = http.createServer(function(req, res) { req.resume(); req.once('end', function() { res.writeHead(200); @@ -16,7 +16,7 @@ var server = http.createServer(function(req, res) { common.refreshTmpDir(); server.listen(common.PIPE, function() { - var req = http.request({ + const req = http.request({ socketPath: common.PIPE, headers: {'Content-Length': '1'}, method: 'POST', diff --git a/test/parallel/test-http-client-race-2.js b/test/parallel/test-http-client-race-2.js index 477c6c25c4e396..a6ccc7297967a5 100644 --- a/test/parallel/test-http-client-race-2.js +++ b/test/parallel/test-http-client-race-2.js @@ -1,22 +1,22 @@ 'use strict'; require('../common'); -var assert = require('assert'); -var http = require('http'); -var url = require('url'); +const assert = require('assert'); +const http = require('http'); +const url = require('url'); // // Slight variation on test-http-client-race to test for another race // condition involving the parsers FreeList used internally by http.Client. // -var body1_s = '1111111111111111'; -var body2_s = '22222'; -var body3_s = '3333333333333333333'; +const body1_s = '1111111111111111'; +const body2_s = '22222'; +const body3_s = '3333333333333333333'; -var server = http.createServer(function(req, res) { - var pathname = url.parse(req.url).pathname; +const server = http.createServer(function(req, res) { + const pathname = url.parse(req.url).pathname; - var body; + let body; switch (pathname) { case '/1': body = body1_s; break; case '/2': body = body2_s; break; @@ -29,17 +29,17 @@ var server = http.createServer(function(req, res) { }); server.listen(0); -var body1 = ''; -var body2 = ''; -var body3 = ''; +let body1 = ''; +let body2 = ''; +let body3 = ''; server.on('listening', function() { - var client = http.createClient(this.address().port); + const client = http.createClient(this.address().port); // // Client #1 is assigned Parser #1 // - var req1 = client.request('/1'); + const req1 = client.request('/1'); req1.end(); req1.on('response', function(res1) { res1.setEncoding('utf8'); @@ -59,13 +59,13 @@ server.on('listening', function() { // parser that previously belonged to Client #1. But we're not finished // with Client #1 yet! // - var client2 = http.createClient(server.address().port); + const client2 = http.createClient(server.address().port); // // At this point, the bug would manifest itself and crash because the // internal state of the parser was no longer valid for use by Client #1 // - var req2 = client.request('/2'); + const req2 = client.request('/2'); req2.end(); req2.on('response', function(res2) { res2.setEncoding('utf8'); @@ -76,7 +76,7 @@ server.on('listening', function() { // Just to be really sure we've covered all our bases, execute a // request using client2. // - var req3 = client2.request('/3'); + const req3 = client2.request('/3'); req3.end(); req3.on('response', function(res3) { res3.setEncoding('utf8'); diff --git a/test/parallel/test-http-client-race.js b/test/parallel/test-http-client-race.js index 30ebb34fc7fcff..14e3300f20a436 100644 --- a/test/parallel/test-http-client-race.js +++ b/test/parallel/test-http-client-race.js @@ -1,25 +1,25 @@ 'use strict'; require('../common'); -var assert = require('assert'); -var http = require('http'); -var url = require('url'); +const assert = require('assert'); +const http = require('http'); +const url = require('url'); -var body1_s = '1111111111111111'; -var body2_s = '22222'; +const body1_s = '1111111111111111'; +const body2_s = '22222'; -var server = http.createServer(function(req, res) { - var body = url.parse(req.url).pathname === '/1' ? body1_s : body2_s; +const server = http.createServer(function(req, res) { + const body = url.parse(req.url).pathname === '/1' ? body1_s : body2_s; res.writeHead(200, {'Content-Type': 'text/plain', 'Content-Length': body.length}); res.end(body); }); server.listen(0); -var body1 = ''; -var body2 = ''; +let body1 = ''; +let body2 = ''; server.on('listening', function() { - var req1 = http.request({ port: this.address().port, path: '/1' }); + const req1 = http.request({ port: this.address().port, path: '/1' }); req1.end(); req1.on('response', function(res1) { res1.setEncoding('utf8'); @@ -29,7 +29,7 @@ server.on('listening', function() { }); res1.on('end', function() { - var req2 = http.request({ port: server.address().port, path: '/2' }); + const req2 = http.request({ port: server.address().port, path: '/2' }); req2.end(); req2.on('response', function(res2) { res2.setEncoding('utf8'); diff --git a/test/parallel/test-http-client-read-in-error.js b/test/parallel/test-http-client-read-in-error.js index 142c0ee3715aed..69b24f73771d41 100644 --- a/test/parallel/test-http-client-read-in-error.js +++ b/test/parallel/test-http-client-read-in-error.js @@ -1,8 +1,8 @@ 'use strict'; require('../common'); -var net = require('net'); -var http = require('http'); -var util = require('util'); +const net = require('net'); +const http = require('http'); +const util = require('util'); function Agent() { http.Agent.call(this); @@ -10,8 +10,8 @@ function Agent() { util.inherits(Agent, http.Agent); Agent.prototype.createConnection = function() { - var self = this; - var socket = new net.Socket(); + const self = this; + const socket = new net.Socket(); socket.on('error', function() { socket.push('HTTP/1.1 200\r\n\r\n'); @@ -35,7 +35,7 @@ Agent.prototype.breakSocket = function breakSocket(socket) { socket.emit('error', new Error('Intentional error')); }; -var agent = new Agent(); +const agent = new Agent(); http.request({ agent: agent diff --git a/test/parallel/test-http-client-readable.js b/test/parallel/test-http-client-readable.js index e49181cedf63d6..bc6421692b305b 100644 --- a/test/parallel/test-http-client-readable.js +++ b/test/parallel/test-http-client-readable.js @@ -13,7 +13,7 @@ util.inherits(FakeAgent, http.Agent); FakeAgent.prototype.createConnection = function() { const s = new Duplex(); - var once = false; + let once = false; s._read = function() { if (once) @@ -38,7 +38,7 @@ FakeAgent.prototype.createConnection = function() { return s; }; -var received = ''; +let received = ''; const req = http.request({ agent: new FakeAgent() diff --git a/test/parallel/test-http-client-response-domain.js b/test/parallel/test-http-client-response-domain.js index 5355a301e8031d..eb8b226acef169 100644 --- a/test/parallel/test-http-client-response-domain.js +++ b/test/parallel/test-http-client-response-domain.js @@ -4,12 +4,12 @@ const assert = require('assert'); const http = require('http'); const domain = require('domain'); -var d; +let d; common.refreshTmpDir(); // first fire up a simple HTTP server -var server = http.createServer(function(req, res) { +const server = http.createServer(function(req, res) { res.writeHead(200); res.end(); server.close(); @@ -26,7 +26,7 @@ function test() { assert.equal('should be caught by domain', err.message); })); - var req = http.get({ + const req = http.get({ socketPath: common.PIPE, headers: {'Content-Length': '1'}, method: 'POST', diff --git a/test/parallel/test-http-client-timeout-agent.js b/test/parallel/test-http-client-timeout-agent.js index 4ed217c171f28a..16a18342468f94 100644 --- a/test/parallel/test-http-client-timeout-agent.js +++ b/test/parallel/test-http-client-timeout-agent.js @@ -1,11 +1,11 @@ 'use strict'; require('../common'); -var assert = require('assert'); -var http = require('http'); +const assert = require('assert'); +const http = require('http'); -var requests_sent = 0; -var requests_done = 0; -var options = { +let requests_sent = 0; +let requests_done = 0; +const options = { method: 'GET', port: undefined, host: '127.0.0.1', @@ -13,7 +13,7 @@ var options = { //http.globalAgent.maxSockets = 15; -var server = http.createServer(function(req, res) { +const server = http.createServer(function(req, res) { const m = /\/(.*)/.exec(req.url); const reqid = parseInt(m[1], 10); if (reqid % 2) { @@ -27,7 +27,7 @@ var server = http.createServer(function(req, res) { server.listen(0, options.host, function() { options.port = this.address().port; - var req; + let req; for (requests_sent = 0; requests_sent < 30; requests_sent += 1) { options.path = '/' + requests_sent; diff --git a/test/parallel/test-http-client-timeout-option.js b/test/parallel/test-http-client-timeout-option.js index 79aa6ba46b6579..6741fbe0bd1e35 100644 --- a/test/parallel/test-http-client-timeout-option.js +++ b/test/parallel/test-http-client-timeout-option.js @@ -3,7 +3,7 @@ const common = require('../common'); const assert = require('assert'); const http = require('http'); -var options = { +const options = { method: 'GET', port: undefined, host: '127.0.0.1', @@ -11,17 +11,17 @@ var options = { timeout: 1 }; -var server = http.createServer(); +const server = http.createServer(); server.listen(0, options.host, function() { options.port = this.address().port; - var req = http.request(options); + const req = http.request(options); req.on('error', function() { // this space is intentionally left blank }); req.on('close', common.mustCall(() => server.close())); - var timeout_events = 0; + let timeout_events = 0; req.on('timeout', common.mustCall(() => timeout_events += 1)); setTimeout(function() { req.destroy(); diff --git a/test/parallel/test-http-client-timeout-with-data.js b/test/parallel/test-http-client-timeout-with-data.js index c82327beb295da..a21a2181752701 100644 --- a/test/parallel/test-http-client-timeout-with-data.js +++ b/test/parallel/test-http-client-timeout-with-data.js @@ -3,7 +3,7 @@ const common = require('../common'); const assert = require('assert'); const http = require('http'); -var nchunks = 0; +let nchunks = 0; const options = { method: 'GET', diff --git a/test/parallel/test-http-client-timeout.js b/test/parallel/test-http-client-timeout.js index 402736e9b7d47c..0caae0d04c333c 100644 --- a/test/parallel/test-http-client-timeout.js +++ b/test/parallel/test-http-client-timeout.js @@ -1,22 +1,22 @@ 'use strict'; require('../common'); -var assert = require('assert'); -var http = require('http'); +const assert = require('assert'); +const http = require('http'); -var options = { +const options = { method: 'GET', port: undefined, host: '127.0.0.1', path: '/' }; -var server = http.createServer(function(req, res) { +const server = http.createServer(function(req, res) { // this space intentionally left blank }); server.listen(0, options.host, function() { options.port = this.address().port; - var req = http.request(options, function(res) { + const req = http.request(options, function(res) { // this space intentionally left blank }); req.on('close', function() { @@ -25,7 +25,7 @@ server.listen(0, options.host, function() { function destroy() { req.destroy(); } - var s = req.setTimeout(1, destroy); + const s = req.setTimeout(1, destroy); assert.ok(s instanceof http.ClientRequest); req.on('error', destroy); req.end(); diff --git a/test/parallel/test-http-client-upload-buf.js b/test/parallel/test-http-client-upload-buf.js index 512a438ef82115..338aab9cc59ba0 100644 --- a/test/parallel/test-http-client-upload-buf.js +++ b/test/parallel/test-http-client-upload-buf.js @@ -1,14 +1,14 @@ 'use strict'; const common = require('../common'); -var assert = require('assert'); -var http = require('http'); +const assert = require('assert'); +const http = require('http'); -var N = 1024; +const N = 1024; -var server = http.createServer(common.mustCall(function(req, res) { +const server = http.createServer(common.mustCall(function(req, res) { assert.equal('POST', req.method); - var bytesReceived = 0; + let bytesReceived = 0; req.on('data', function(chunk) { bytesReceived += chunk.length; @@ -25,7 +25,7 @@ var server = http.createServer(common.mustCall(function(req, res) { server.listen(0); server.on('listening', common.mustCall(function() { - var req = http.request({ + const req = http.request({ port: this.address().port, method: 'POST', path: '/' diff --git a/test/parallel/test-http-client-upload.js b/test/parallel/test-http-client-upload.js index a5c8f5b92bc761..ba60681776ba49 100644 --- a/test/parallel/test-http-client-upload.js +++ b/test/parallel/test-http-client-upload.js @@ -1,13 +1,13 @@ 'use strict'; const common = require('../common'); -var assert = require('assert'); -var http = require('http'); +const assert = require('assert'); +const http = require('http'); -var server = http.createServer(common.mustCall(function(req, res) { +const server = http.createServer(common.mustCall(function(req, res) { assert.equal('POST', req.method); req.setEncoding('utf8'); - var sent_body = ''; + let sent_body = ''; req.on('data', function(chunk) { console.log('server got: ' + JSON.stringify(chunk)); @@ -25,7 +25,7 @@ var server = http.createServer(common.mustCall(function(req, res) { server.listen(0); server.on('listening', common.mustCall(function() { - var req = http.request({ + const req = http.request({ port: this.address().port, method: 'POST', path: '/' diff --git a/test/parallel/test-http-conn-reset.js b/test/parallel/test-http-conn-reset.js index d7852bf32c9ec3..f7f08a6bf42c81 100644 --- a/test/parallel/test-http-conn-reset.js +++ b/test/parallel/test-http-conn-reset.js @@ -1,16 +1,16 @@ 'use strict'; const common = require('../common'); -var assert = require('assert'); -var http = require('http'); -var net = require('net'); +const assert = require('assert'); +const http = require('http'); +const net = require('net'); -var options = { +const options = { host: '127.0.0.1', port: undefined }; // start a tcp server that closes incoming connections immediately -var server = net.createServer(function(client) { +const server = net.createServer(function(client) { client.destroy(); server.close(); }); @@ -19,7 +19,7 @@ server.listen(0, options.host, common.mustCall(onListen)); // do a GET request, expect it to fail function onListen() { options.port = this.address().port; - var req = http.request(options, function(res) { + const req = http.request(options, function(res) { assert.ok(false, 'this should never run'); }); req.on('error', common.mustCall(function(err) { diff --git a/test/parallel/test-http-connect-req-res.js b/test/parallel/test-http-connect-req-res.js index 1cee61e4c2fb37..0b1ca4630a562e 100644 --- a/test/parallel/test-http-connect-req-res.js +++ b/test/parallel/test-http-connect-req-res.js @@ -18,7 +18,7 @@ server.on('connect', common.mustCall(function(req, socket, firstBodyChunk) { 'Head' ); - var data = firstBodyChunk.toString(); + let data = firstBodyChunk.toString(); socket.on('data', function(buf) { data += buf.toString(); }); @@ -49,7 +49,7 @@ server.listen(0, common.mustCall(function() { assert.equal(socket.listeners('connect').length, 0); assert.equal(socket.listeners('data').length, 0); - var data = firstBodyChunk.toString(); + let data = firstBodyChunk.toString(); // test that the firstBodyChunk was not parsed as HTTP assert.equal(data, 'Head'); diff --git a/test/parallel/test-http-content-length.js b/test/parallel/test-http-content-length.js index 9104e5ba0d74cb..3d6882d92f04b3 100644 --- a/test/parallel/test-http-content-length.js +++ b/test/parallel/test-http-content-length.js @@ -1,27 +1,27 @@ 'use strict'; require('../common'); -var assert = require('assert'); -var http = require('http'); +const assert = require('assert'); +const http = require('http'); -var expectedHeadersMultipleWrites = { +const expectedHeadersMultipleWrites = { 'connection': 'close', 'transfer-encoding': 'chunked', }; -var expectedHeadersEndWithData = { +const expectedHeadersEndWithData = { 'connection': 'close', 'content-length': String('hello world'.length) }; -var expectedHeadersEndNoData = { +const expectedHeadersEndNoData = { 'connection': 'close', 'content-length': '0', }; -var receivedRequests = 0; -var totalRequests = 3; +let receivedRequests = 0; +const totalRequests = 3; -var server = http.createServer(function(req, res) { +const server = http.createServer(function(req, res) { res.removeHeader('Date'); switch (req.url.substr(1)) { @@ -47,7 +47,7 @@ var server = http.createServer(function(req, res) { }); server.listen(0, function() { - var req; + let req; req = http.request({ port: this.address().port, diff --git a/test/parallel/test-http-contentLength0.js b/test/parallel/test-http-contentLength0.js index 19e90e151382be..537c7c0691af16 100644 --- a/test/parallel/test-http-contentLength0.js +++ b/test/parallel/test-http-contentLength0.js @@ -1,23 +1,24 @@ 'use strict'; require('../common'); -var http = require('http'); +const http = require('http'); // Simple test of Node's HTTP Client choking on a response // with a 'Content-Length: 0 ' response header. // I.E. a space character after the 'Content-Length' throws an `error` event. -var s = http.createServer(function(req, res) { +const s = http.createServer(function(req, res) { res.writeHead(200, {'Content-Length': '0 '}); res.end(); }); s.listen(0, function() { - var request = http.request({ port: this.address().port }, function(response) { - console.log('STATUS: ' + response.statusCode); - s.close(); - response.resume(); - }); + const request = + http.request({ port: this.address().port }, function(response) { + console.log('STATUS: ' + response.statusCode); + s.close(); + response.resume(); + }); request.end(); }); diff --git a/test/parallel/test-http-date-header.js b/test/parallel/test-http-date-header.js index e0b93c1f8718f5..e14a92b310f2d1 100644 --- a/test/parallel/test-http-date-header.js +++ b/test/parallel/test-http-date-header.js @@ -1,11 +1,11 @@ 'use strict'; require('../common'); -var assert = require('assert'); -var http = require('http'); +const assert = require('assert'); +const http = require('http'); -var testResBody = 'other stuff!\n'; +const testResBody = 'other stuff!\n'; -var server = http.createServer(function(req, res) { +const server = http.createServer(function(req, res) { assert.ok(!('date' in req.headers), 'Request headers contained a Date.'); res.writeHead(200, { @@ -17,12 +17,12 @@ server.listen(0); server.addListener('listening', function() { - var options = { + const options = { port: this.address().port, path: '/', method: 'GET' }; - var req = http.request(options, function(res) { + const req = http.request(options, function(res) { assert.ok('date' in res.headers, 'Response headers didn\'t contain a Date.'); res.addListener('end', function() { diff --git a/test/parallel/test-http-default-encoding.js b/test/parallel/test-http-default-encoding.js index 4fb386bf4bb0e8..46327085184069 100644 --- a/test/parallel/test-http-default-encoding.js +++ b/test/parallel/test-http-default-encoding.js @@ -1,12 +1,12 @@ 'use strict'; require('../common'); -var assert = require('assert'); -var http = require('http'); +const assert = require('assert'); +const http = require('http'); -var expected = 'This is a unicode text: سلام'; -var result = ''; +const expected = 'This is a unicode text: سلام'; +let result = ''; -var server = http.Server(function(req, res) { +const server = http.Server(function(req, res) { req.setEncoding('utf8'); req.on('data', function(chunk) { result += chunk; diff --git a/test/parallel/test-http-default-port.js b/test/parallel/test-http-default-port.js index fcea5aac7b156b..dbe1a44c6a2c1b 100644 --- a/test/parallel/test-http-default-port.js +++ b/test/parallel/test-http-default-port.js @@ -13,8 +13,9 @@ const options = { let gotHttpsResp = false; let gotHttpResp = false; +let https; if (common.hasCrypto) { - var https = require('https'); + https = require('https'); } else { common.skip('missing crypto'); } diff --git a/test/parallel/test-http-destroyed-socket-write2.js b/test/parallel/test-http-destroyed-socket-write2.js index 7d2f235a27f7fb..01023a088576ef 100644 --- a/test/parallel/test-http-destroyed-socket-write2.js +++ b/test/parallel/test-http-destroyed-socket-write2.js @@ -1,19 +1,19 @@ 'use strict'; -var common = require('../common'); -var assert = require('assert'); +const common = require('../common'); +const assert = require('assert'); // Verify that ECONNRESET is raised when writing to a http request // where the server has ended the socket. -var http = require('http'); -var server = http.createServer(function(req, res) { +const http = require('http'); +const server = http.createServer(function(req, res) { setImmediate(function() { res.destroy(); }); }); server.listen(0, function() { - var req = http.request({ + const req = http.request({ port: this.address().port, path: '/', method: 'POST' diff --git a/test/parallel/test-http-dns-error.js b/test/parallel/test-http-dns-error.js index 5e15ab9a3fa0da..6dad7322ed45a0 100644 --- a/test/parallel/test-http-dns-error.js +++ b/test/parallel/test-http-dns-error.js @@ -4,8 +4,9 @@ const assert = require('assert'); const http = require('http'); +let https; if (common.hasCrypto) { - var https = require('https'); + https = require('https'); } else { common.skip('missing crypto'); } diff --git a/test/parallel/test-http-eof-on-connect.js b/test/parallel/test-http-eof-on-connect.js index 6f70dc239172ee..f67e45ed403225 100644 --- a/test/parallel/test-http-eof-on-connect.js +++ b/test/parallel/test-http-eof-on-connect.js @@ -1,13 +1,13 @@ 'use strict'; require('../common'); -var net = require('net'); -var http = require('http'); +const net = require('net'); +const http = require('http'); // This is a regression test for https://github.com/joyent/node/issues/44 // It is separate from test-http-malformed-request.js because it is only // reproduceable on the first packet on the first connection to a server. -var server = http.createServer(function(req, res) {}); +const server = http.createServer(function(req, res) {}); server.listen(0); server.on('listening', function() { diff --git a/test/parallel/test-http-exceptions.js b/test/parallel/test-http-exceptions.js index b9958007609fd0..c003db131065a3 100644 --- a/test/parallel/test-http-exceptions.js +++ b/test/parallel/test-http-exceptions.js @@ -1,8 +1,8 @@ 'use strict'; require('../common'); -var http = require('http'); +const http = require('http'); -var server = http.createServer(function(req, res) { +const server = http.createServer(function(req, res) { intentionally_not_defined(); // eslint-disable-line no-undef res.writeHead(200, {'Content-Type': 'text/plain'}); res.write('Thank you, come again.'); @@ -10,12 +10,12 @@ var server = http.createServer(function(req, res) { }); server.listen(0, function() { - for (var i = 0; i < 4; i += 1) { + for (let i = 0; i < 4; i += 1) { http.get({ port: this.address().port, path: '/busy/' + i }); } }); -var exception_count = 0; +let exception_count = 0; process.on('uncaughtException', function(err) { console.log('Caught an exception: ' + err); diff --git a/test/parallel/test-http-expect-continue.js b/test/parallel/test-http-expect-continue.js index a0ebf83b3301a5..0cf90e3b115e60 100644 --- a/test/parallel/test-http-expect-continue.js +++ b/test/parallel/test-http-expect-continue.js @@ -1,13 +1,13 @@ 'use strict'; require('../common'); -var assert = require('assert'); -var http = require('http'); +const assert = require('assert'); +const http = require('http'); -var outstanding_reqs = 0; -var test_req_body = 'some stuff...\n'; -var test_res_body = 'other stuff!\n'; -var sent_continue = false; -var got_continue = false; +let outstanding_reqs = 0; +const test_req_body = 'some stuff...\n'; +const test_res_body = 'other stuff!\n'; +let sent_continue = false; +let got_continue = false; function handler(req, res) { assert.equal(sent_continue, true, 'Full response sent before 100 Continue'); @@ -19,7 +19,7 @@ function handler(req, res) { res.end(test_res_body); } -var server = http.createServer(handler); +const server = http.createServer(handler); server.on('checkContinue', function(req, res) { console.error('Server got Expect: 100-continue...'); res.writeContinue(); @@ -32,7 +32,7 @@ server.listen(0); server.on('listening', function() { - var req = http.request({ + const req = http.request({ port: this.address().port, method: 'POST', path: '/world', @@ -40,7 +40,7 @@ server.on('listening', function() { }); console.error('Client sending request...'); outstanding_reqs++; - var body = ''; + let body = ''; req.on('continue', function() { console.error('Client got 100 Continue...'); got_continue = true; diff --git a/test/parallel/test-http-extra-response.js b/test/parallel/test-http-extra-response.js index 8364684a1ec23f..6ebecaad1300de 100644 --- a/test/parallel/test-http-extra-response.js +++ b/test/parallel/test-http-extra-response.js @@ -1,15 +1,15 @@ 'use strict'; const common = require('../common'); -var assert = require('assert'); -var http = require('http'); -var net = require('net'); +const assert = require('assert'); +const http = require('http'); +const net = require('net'); // If an HTTP server is broken and sends data after the end of the response, // node should ignore it and drop the connection. // Demos this bug: https://github.com/joyent/node/issues/680 -var body = 'hello world\r\n'; -var fullResponse = +const body = 'hello world\r\n'; +const fullResponse = 'HTTP/1.1 500 Internal Server Error\r\n' + 'Content-Length: ' + body.length + '\r\n' + 'Content-Type: text/plain\r\n' + @@ -20,8 +20,8 @@ var fullResponse = '\r\n' + body; -var server = net.createServer(function(socket) { - var postBody = ''; +const server = net.createServer(function(socket) { + let postBody = ''; socket.setEncoding('utf8'); @@ -43,7 +43,7 @@ var server = net.createServer(function(socket) { server.listen(0, common.mustCall(function() { http.get({ port: this.address().port }, common.mustCall(function(res) { - var buffer = ''; + let buffer = ''; console.log('Got res code: ' + res.statusCode); res.setEncoding('utf8'); diff --git a/test/parallel/test-http-flush-response-headers.js b/test/parallel/test-http-flush-response-headers.js index 1cd8402df361b0..ea7d2d97b4dc7a 100644 --- a/test/parallel/test-http-flush-response-headers.js +++ b/test/parallel/test-http-flush-response-headers.js @@ -11,7 +11,7 @@ server.on('request', function(req, res) { res.flushHeaders(); // Should be idempotent. }); server.listen(0, common.localhostIPv4, function() { - var req = http.request({ + const req = http.request({ method: 'GET', host: common.localhostIPv4, port: this.address().port, diff --git a/test/parallel/test-http-flush.js b/test/parallel/test-http-flush.js index 8b3dacb803d9bd..e8f5782c2f7857 100644 --- a/test/parallel/test-http-flush.js +++ b/test/parallel/test-http-flush.js @@ -1,12 +1,12 @@ 'use strict'; require('../common'); -var http = require('http'); +const http = require('http'); http.createServer(function(req, res) { res.end('ok'); this.close(); }).listen(0, '127.0.0.1', function() { - var req = http.request({ + const req = http.request({ method: 'POST', host: '127.0.0.1', port: this.address().port, diff --git a/test/parallel/test-http-full-response.js b/test/parallel/test-http-full-response.js index e59456a710aac3..c834c6e6545320 100644 --- a/test/parallel/test-http-full-response.js +++ b/test/parallel/test-http-full-response.js @@ -1,15 +1,15 @@ 'use strict'; -var common = require('../common'); -var assert = require('assert'); +const common = require('../common'); +const assert = require('assert'); // This test requires the program 'ab' -var http = require('http'); -var exec = require('child_process').exec; +const http = require('http'); +const exec = require('child_process').exec; -var bodyLength = 12345; +const bodyLength = 12345; -var body = 'c'.repeat(bodyLength); +const body = 'c'.repeat(bodyLength); -var server = http.createServer(function(req, res) { +const server = http.createServer(function(req, res) { res.writeHead(200, { 'Content-Length': bodyLength, 'Content-Type': 'text/plain' @@ -18,7 +18,7 @@ var server = http.createServer(function(req, res) { }); function runAb(opts, callback) { - var command = `ab ${opts} http://127.0.0.1:${server.address().port}/`; + const command = `ab ${opts} http://127.0.0.1:${server.address().port}/`; exec(command, function(err, stdout, stderr) { if (err) { if (/ab|apr/mi.test(stderr)) { @@ -29,14 +29,14 @@ function runAb(opts, callback) { return; } - var m = /Document Length:\s*(\d+) bytes/mi.exec(stdout); - var documentLength = parseInt(m[1]); + let m = /Document Length:\s*(\d+) bytes/mi.exec(stdout); + const documentLength = parseInt(m[1]); m = /Complete requests:\s*(\d+)/mi.exec(stdout); - var completeRequests = parseInt(m[1]); + const completeRequests = parseInt(m[1]); m = /HTML transferred:\s*(\d+) bytes/mi.exec(stdout); - var htmlTransfered = parseInt(m[1]); + const htmlTransfered = parseInt(m[1]); assert.equal(bodyLength, documentLength); assert.equal(completeRequests * documentLength, htmlTransfered); diff --git a/test/parallel/test-http-get-pipeline-problem.js b/test/parallel/test-http-get-pipeline-problem.js index cc681f675a791e..15c96a9a4e12ea 100644 --- a/test/parallel/test-http-get-pipeline-problem.js +++ b/test/parallel/test-http-get-pipeline-problem.js @@ -2,23 +2,23 @@ // In previous versions of Node.js (e.g., 0.6.0), this sort of thing would halt // after http.globalAgent.maxSockets number of files. // See https://groups.google.com/forum/#!topic/nodejs-dev/V5fB69hFa9o -var common = require('../common'); -var assert = require('assert'); -var http = require('http'); -var fs = require('fs'); +const common = require('../common'); +const assert = require('assert'); +const http = require('http'); +const fs = require('fs'); http.globalAgent.maxSockets = 1; common.refreshTmpDir(); -var image = fs.readFileSync(common.fixturesDir + '/person.jpg'); +const image = fs.readFileSync(common.fixturesDir + '/person.jpg'); console.log('image.length = ' + image.length); -var total = 10; -var requests = 0, responses = 0; +const total = 10; +let requests = 0, responses = 0; -var server = http.Server(function(req, res) { +const server = http.Server(function(req, res) { if (++requests === total) { server.close(); } @@ -35,18 +35,18 @@ var server = http.Server(function(req, res) { server.listen(0, function() { - for (var i = 0; i < total; i++) { + for (let i = 0; i < total; i++) { (function() { - var x = i; + const x = i; - var opts = { + const opts = { port: server.address().port, headers: { connection: 'close' } }; http.get(opts, function(res) { console.error('recv ' + x); - var s = fs.createWriteStream(common.tmpDir + '/' + x + '.jpg'); + const s = fs.createWriteStream(common.tmpDir + '/' + x + '.jpg'); res.pipe(s); s.on('finish', function() { @@ -64,16 +64,16 @@ server.listen(0, function() { }); -var checkedFiles = false; +let checkedFiles = false; function checkFiles() { // Should see 1.jpg, 2.jpg, ..., 100.jpg in tmpDir - var files = fs.readdirSync(common.tmpDir); + const files = fs.readdirSync(common.tmpDir); assert(total <= files.length); - for (var i = 0; i < total; i++) { - var fn = i + '.jpg'; + for (let i = 0; i < total; i++) { + const fn = i + '.jpg'; assert.ok(files.indexOf(fn) >= 0, "couldn't find '" + fn + "'"); - var stat = fs.statSync(common.tmpDir + '/' + fn); + const stat = fs.statSync(common.tmpDir + '/' + fn); assert.equal(image.length, stat.size, "size doesn't match on '" + fn + "'. Got " + stat.size + ' bytes'); diff --git a/test/parallel/test-http-head-request.js b/test/parallel/test-http-head-request.js index e8626b18811bda..de94dfb8b7d6e7 100644 --- a/test/parallel/test-http-head-request.js +++ b/test/parallel/test-http-head-request.js @@ -1,11 +1,11 @@ 'use strict'; const common = require('../common'); -var http = require('http'); +const http = require('http'); -var body = 'hello world\n'; +const body = 'hello world\n'; function test(headers) { - var server = http.createServer(function(req, res) { + const server = http.createServer(function(req, res) { console.error('req: %s headers: %j', req.method, headers); res.writeHead(200, headers); res.end(); @@ -13,7 +13,7 @@ function test(headers) { }); server.listen(0, common.mustCall(function() { - var request = http.request({ + const request = http.request({ port: this.address().port, method: 'HEAD', path: '/' diff --git a/test/parallel/test-http-head-response-has-no-body-end.js b/test/parallel/test-http-head-response-has-no-body-end.js index 87ce957df3499f..de5ca976fc47b0 100644 --- a/test/parallel/test-http-head-response-has-no-body-end.js +++ b/test/parallel/test-http-head-response-has-no-body-end.js @@ -1,19 +1,19 @@ 'use strict'; const common = require('../common'); -var http = require('http'); +const http = require('http'); // This test is to make sure that when the HTTP server // responds to a HEAD request with data to res.end, // it does not send any body. -var server = http.createServer(function(req, res) { +const server = http.createServer(function(req, res) { res.writeHead(200); res.end('FAIL'); // broken: sends FAIL from hot path. }); server.listen(0); server.on('listening', common.mustCall(function() { - var req = http.request({ + const req = http.request({ port: this.address().port, method: 'HEAD', path: '/' diff --git a/test/parallel/test-http-head-response-has-no-body.js b/test/parallel/test-http-head-response-has-no-body.js index 445b522b8dea51..b2eb98b1eea06c 100644 --- a/test/parallel/test-http-head-response-has-no-body.js +++ b/test/parallel/test-http-head-response-has-no-body.js @@ -1,19 +1,19 @@ 'use strict'; const common = require('../common'); -var http = require('http'); +const http = require('http'); // This test is to make sure that when the HTTP server // responds to a HEAD request, it does not send any body. // In this case it was sending '0\r\n\r\n' -var server = http.createServer(function(req, res) { +const server = http.createServer(function(req, res) { res.writeHead(200); // broken: defaults to TE chunked res.end(); }); server.listen(0); server.on('listening', common.mustCall(function() { - var req = http.request({ + const req = http.request({ port: this.address().port, method: 'HEAD', path: '/' diff --git a/test/parallel/test-http-header-read.js b/test/parallel/test-http-header-read.js index b726fe130f0ee4..3d9e756d505238 100644 --- a/test/parallel/test-http-header-read.js +++ b/test/parallel/test-http-header-read.js @@ -1,14 +1,14 @@ 'use strict'; require('../common'); -var assert = require('assert'); -var http = require('http'); +const assert = require('assert'); +const http = require('http'); // Verify that ServerResponse.getHeader() works correctly even after // the response header has been sent. Issue 752 on github. -var s = http.createServer(function(req, res) { - var contentType = 'Content-Type'; - var plain = 'text/plain'; +const s = http.createServer(function(req, res) { + const contentType = 'Content-Type'; + const plain = 'text/plain'; res.setHeader(contentType, plain); assert.ok(!res.headersSent); res.writeHead(200); diff --git a/test/parallel/test-http-hex-write.js b/test/parallel/test-http-hex-write.js index adfe18077a8259..211f818e566699 100644 --- a/test/parallel/test-http-hex-write.js +++ b/test/parallel/test-http-hex-write.js @@ -1,10 +1,10 @@ 'use strict'; const common = require('../common'); -var assert = require('assert'); +const assert = require('assert'); -var http = require('http'); +const http = require('http'); -var expect = 'hex\nutf8\n'; +const expect = 'hex\nutf8\n'; http.createServer(function(q, s) { s.setHeader('content-length', expect.length); @@ -15,7 +15,7 @@ http.createServer(function(q, s) { }).listen(0, common.mustCall(function() { http.request({ port: this.address().port }) .on('response', common.mustCall(function(res) { - var data = ''; + let data = ''; res.setEncoding('ascii'); res.on('data', function(c) { diff --git a/test/parallel/test-http-host-header-ipv6-fail.js b/test/parallel/test-http-host-header-ipv6-fail.js index 5f81234edba352..94351bc5c167e4 100644 --- a/test/parallel/test-http-host-header-ipv6-fail.js +++ b/test/parallel/test-http-host-header-ipv6-fail.js @@ -16,7 +16,7 @@ const http = require('http'); const hostname = '::1'; function httpreq() { - var req = http.request({ + const req = http.request({ host: hostname, port: server.address().port, path: '/', diff --git a/test/parallel/test-http-host-headers.js b/test/parallel/test-http-host-headers.js index 863dbae365d164..b7a916816ffe1d 100644 --- a/test/parallel/test-http-host-headers.js +++ b/test/parallel/test-http-host-headers.js @@ -20,7 +20,7 @@ testHttp(); function testHttp() { - var counter = 0; + let counter = 0; function cb(res) { counter--; diff --git a/test/parallel/test-http-invalidheaderfield.js b/test/parallel/test-http-invalidheaderfield.js index 9d4a12a952a838..aaed46c69cd592 100644 --- a/test/parallel/test-http-invalidheaderfield.js +++ b/test/parallel/test-http-invalidheaderfield.js @@ -5,7 +5,7 @@ const EventEmitter = require('events'); const http = require('http'); const ee = new EventEmitter(); -var count = 3; +let count = 3; const server = http.createServer(function(req, res) { assert.doesNotThrow(function() { @@ -24,7 +24,7 @@ server.listen(0, function() { assert.throws( function() { - var options = { + const options = { port: server.address().port, headers: {'testing 123': 123} }; @@ -38,7 +38,7 @@ server.listen(0, function() { assert.doesNotThrow( function() { - var options = { + const options = { port: server.address().port, headers: {'testing_123': 123} }; diff --git a/test/parallel/test-http-keep-alive-close-on-header.js b/test/parallel/test-http-keep-alive-close-on-header.js index d9396b258e7515..15d5d62d429658 100644 --- a/test/parallel/test-http-keep-alive-close-on-header.js +++ b/test/parallel/test-http-keep-alive-close-on-header.js @@ -1,24 +1,24 @@ 'use strict'; require('../common'); -var assert = require('assert'); -var http = require('http'); +const assert = require('assert'); +const http = require('http'); -var body = 'hello world\n'; -var headers = {'connection': 'keep-alive'}; +const body = 'hello world\n'; +const headers = {'connection': 'keep-alive'}; -var server = http.createServer(function(req, res) { +const server = http.createServer(function(req, res) { res.writeHead(200, {'Content-Length': body.length, 'Connection': 'close'}); res.write(body); res.end(); }); -var connectCount = 0; +let connectCount = 0; server.listen(0, function() { - var agent = new http.Agent({ maxSockets: 1 }); - var name = agent.getName({ port: this.address().port }); - var request = http.request({ + const agent = new http.Agent({ maxSockets: 1 }); + const name = agent.getName({ port: this.address().port }); + let request = http.request({ method: 'GET', path: '/', headers: headers, diff --git a/test/parallel/test-http-keepalive-client.js b/test/parallel/test-http-keepalive-client.js index 955fc006e22d58..1fcf12b0dbcddf 100644 --- a/test/parallel/test-http-keepalive-client.js +++ b/test/parallel/test-http-keepalive-client.js @@ -1,12 +1,12 @@ 'use strict'; require('../common'); -var assert = require('assert'); +const assert = require('assert'); -var http = require('http'); +const http = require('http'); -var serverSocket = null; -var server = http.createServer(function(req, res) { +let serverSocket = null; +const server = http.createServer(function(req, res) { // They should all come in on the same server socket. if (serverSocket) { assert.equal(req.socket, serverSocket); @@ -20,12 +20,12 @@ server.listen(0, function() { makeRequest(expectRequests); }); -var agent = http.Agent({ keepAlive: true }); +const agent = http.Agent({ keepAlive: true }); -var clientSocket = null; -var expectRequests = 10; -var actualRequests = 0; +let clientSocket = null; +let expectRequests = 10; +let actualRequests = 0; function makeRequest(n) { @@ -35,7 +35,7 @@ function makeRequest(n) { return; } - var req = http.request({ + const req = http.request({ port: server.address().port, agent: agent, path: '/' + n @@ -52,7 +52,7 @@ function makeRequest(n) { }); req.on('response', function(res) { - var data = ''; + let data = ''; res.setEncoding('utf8'); res.on('data', function(c) { data += c; diff --git a/test/parallel/test-http-keepalive-maxsockets.js b/test/parallel/test-http-keepalive-maxsockets.js index 6f1476d0ce3aed..14e9e88ef7fd09 100644 --- a/test/parallel/test-http-keepalive-maxsockets.js +++ b/test/parallel/test-http-keepalive-maxsockets.js @@ -1,25 +1,25 @@ 'use strict'; require('../common'); -var assert = require('assert'); +const assert = require('assert'); -var http = require('http'); +const http = require('http'); -var serverSockets = []; -var server = http.createServer(function(req, res) { +const serverSockets = []; +const server = http.createServer(function(req, res) { if (serverSockets.indexOf(req.socket) === -1) { serverSockets.push(req.socket); } res.end(req.url); }); server.listen(0, function() { - var agent = http.Agent({ + const agent = http.Agent({ keepAlive: true, maxSockets: 5, maxFreeSockets: 2 }); - var closed = false; + let closed = false; makeReqs(10, function(er) { assert.ifError(er); assert.equal(count(agent.freeSockets), 2); @@ -49,7 +49,7 @@ server.listen(0, function() { // make 10 requests in parallel, // then 10 more when they all finish. function makeReqs(n, cb) { - for (var i = 0; i < n; i++) + for (let i = 0; i < n; i++) makeReq(i, then); function then(er) { @@ -66,7 +66,7 @@ server.listen(0, function() { path: '/' + i, agent: agent }, function(res) { - var data = ''; + let data = ''; res.setEncoding('ascii'); res.on('data', function(c) { data += c; diff --git a/test/parallel/test-http-keepalive-request.js b/test/parallel/test-http-keepalive-request.js index daae5aa9944294..b9e9f1e9798cfc 100644 --- a/test/parallel/test-http-keepalive-request.js +++ b/test/parallel/test-http-keepalive-request.js @@ -1,12 +1,12 @@ 'use strict'; require('../common'); -var assert = require('assert'); +const assert = require('assert'); -var http = require('http'); +const http = require('http'); -var serverSocket = null; -var server = http.createServer(function(req, res) { +let serverSocket = null; +const server = http.createServer(function(req, res) { // They should all come in on the same server socket. if (serverSocket) { assert.equal(req.socket, serverSocket); @@ -20,12 +20,12 @@ server.listen(0, function() { makeRequest(expectRequests); }); -var agent = http.Agent({ keepAlive: true }); +const agent = http.Agent({ keepAlive: true }); -var clientSocket = null; -var expectRequests = 10; -var actualRequests = 0; +let clientSocket = null; +let expectRequests = 10; +let actualRequests = 0; function makeRequest(n) { @@ -35,7 +35,7 @@ function makeRequest(n) { return; } - var req = http.request({ + const req = http.request({ port: server.address().port, path: '/' + n, agent: agent @@ -52,7 +52,7 @@ function makeRequest(n) { }); req.on('response', function(res) { - var data = ''; + let data = ''; res.setEncoding('utf8'); res.on('data', function(c) { data += c; diff --git a/test/parallel/test-http-legacy.js b/test/parallel/test-http-legacy.js index 165e51ff418ed0..bf2f83d71bbc2a 100644 --- a/test/parallel/test-http-legacy.js +++ b/test/parallel/test-http-legacy.js @@ -1,14 +1,14 @@ 'use strict'; const common = require('../common'); -var assert = require('assert'); -var http = require('http'); -var url = require('url'); +const assert = require('assert'); +const http = require('http'); +const url = require('url'); -var responses_sent = 0; -var body0 = ''; -var body1 = ''; +let responses_sent = 0; +let body0 = ''; +let body1 = ''; -var server = http.createServer(function(req, res) { +const server = http.createServer(function(req, res) { if (responses_sent === 0) { assert.equal('GET', req.method); assert.equal('/hello', url.parse(req.url).pathname); @@ -37,8 +37,8 @@ var server = http.createServer(function(req, res) { }); server.listen(0, common.mustCall(function() { - var client = http.createClient(this.address().port); - var req = client.request('/hello', {'Accept': '*/*', 'Foo': 'bar'}); + const client = http.createClient(this.address().port); + const req = client.request('/hello', {'Accept': '*/*', 'Foo': 'bar'}); setTimeout(function() { req.end(); }, 100); @@ -50,7 +50,7 @@ server.listen(0, common.mustCall(function() { })); setTimeout(common.mustCall(function() { - var req = client.request('POST', '/world'); + const req = client.request('POST', '/world'); req.end(); req.on('response', common.mustCall(function(res) { assert.equal(200, res.statusCode); diff --git a/test/parallel/test-http-localaddress-bind-error.js b/test/parallel/test-http-localaddress-bind-error.js index 0b828910f12873..a23c6f2a4452a6 100644 --- a/test/parallel/test-http-localaddress-bind-error.js +++ b/test/parallel/test-http-localaddress-bind-error.js @@ -1,10 +1,10 @@ 'use strict'; const common = require('../common'); -var http = require('http'); +const http = require('http'); -var invalidLocalAddress = '1.2.3.4'; +const invalidLocalAddress = '1.2.3.4'; -var server = http.createServer(function(req, res) { +const server = http.createServer(function(req, res) { console.log('Connect from: ' + req.connection.remoteAddress); req.on('end', function() { diff --git a/test/parallel/test-http-localaddress.js b/test/parallel/test-http-localaddress.js index d507d12ec89e25..e8df6888866f9c 100644 --- a/test/parallel/test-http-localaddress.js +++ b/test/parallel/test-http-localaddress.js @@ -8,7 +8,7 @@ if (!common.hasMultiLocalhost()) { return; } -var server = http.createServer(function(req, res) { +const server = http.createServer(function(req, res) { console.log('Connect from: ' + req.connection.remoteAddress); assert.equal('127.0.0.2', req.connection.remoteAddress); @@ -20,13 +20,13 @@ var server = http.createServer(function(req, res) { }); server.listen(0, '127.0.0.1', function() { - var options = { host: 'localhost', - port: this.address().port, - path: '/', - method: 'GET', - localAddress: '127.0.0.2' }; + const options = { host: 'localhost', + port: this.address().port, + path: '/', + method: 'GET', + localAddress: '127.0.0.2' }; - var req = http.request(options, function(res) { + const req = http.request(options, function(res) { res.on('end', function() { server.close(); process.exit(); diff --git a/test/parallel/test-http-malformed-request.js b/test/parallel/test-http-malformed-request.js index 647b67bcd3ff78..a36c9fdbe29451 100644 --- a/test/parallel/test-http-malformed-request.js +++ b/test/parallel/test-http-malformed-request.js @@ -1,17 +1,17 @@ 'use strict'; require('../common'); -var assert = require('assert'); -var net = require('net'); -var http = require('http'); -var url = require('url'); +const assert = require('assert'); +const net = require('net'); +const http = require('http'); +const url = require('url'); // Make sure no exceptions are thrown when receiving malformed HTTP // requests. -var nrequests_completed = 0; -var nrequests_expected = 1; +let nrequests_completed = 0; +const nrequests_expected = 1; -var server = http.createServer(function(req, res) { +const server = http.createServer(function(req, res) { console.log('req: ' + JSON.stringify(url.parse(req.url))); res.writeHead(200, {'Content-Type': 'text/plain'}); @@ -23,7 +23,7 @@ var server = http.createServer(function(req, res) { server.listen(0); server.on('listening', function() { - var c = net.createConnection(this.address().port); + const c = net.createConnection(this.address().port); c.on('connect', function() { c.write('GET /hello?foo=%99bar HTTP/1.1\r\n\r\n'); c.end(); diff --git a/test/parallel/test-http-many-ended-pipelines.js b/test/parallel/test-http-many-ended-pipelines.js index 7966f47a9efa19..1d443d0b2b5dc4 100644 --- a/test/parallel/test-http-many-ended-pipelines.js +++ b/test/parallel/test-http-many-ended-pipelines.js @@ -2,19 +2,19 @@ require('../common'); // no warnings should happen! -var trace = console.trace; +const trace = console.trace; console.trace = function() { trace.apply(console, arguments); throw new Error('no tracing should happen here'); }; -var http = require('http'); -var net = require('net'); +const http = require('http'); +const net = require('net'); -var numRequests = 20; -var first = false; +const numRequests = 20; +let first = false; -var server = http.createServer(function(req, res) { +const server = http.createServer(function(req, res) { if (!first) { first = true; req.socket.on('close', function() { @@ -28,8 +28,9 @@ var server = http.createServer(function(req, res) { }); server.listen(0, function() { - var client = net.connect({ port: this.address().port, allowHalfOpen: true }); - for (var i = 0; i < numRequests; i++) { + const client = + net.connect({ port: this.address().port, allowHalfOpen: true }); + for (let i = 0; i < numRequests; i++) { client.write('GET / HTTP/1.1\r\n' + 'Host: some.host.name\r\n' + '\r\n\r\n'); diff --git a/test/parallel/test-http-max-headers-count.js b/test/parallel/test-http-max-headers-count.js index 2d68ead110fc6c..018ed33c1b9e49 100644 --- a/test/parallel/test-http-max-headers-count.js +++ b/test/parallel/test-http-max-headers-count.js @@ -1,26 +1,26 @@ 'use strict'; require('../common'); -var assert = require('assert'); -var http = require('http'); +const assert = require('assert'); +const http = require('http'); -var requests = 0; -var responses = 0; +let requests = 0; +let responses = 0; -var headers = {}; -var N = 2000; -for (var i = 0; i < N; ++i) { +const headers = {}; +const N = 2000; +for (let i = 0; i < N; ++i) { headers['key' + i] = i; } -var maxAndExpected = [ // for server +const maxAndExpected = [ // for server [50, 50], [1500, 1500], [0, N + 2] // Host and Connection ]; -var max = maxAndExpected[requests][0]; -var expected = maxAndExpected[requests][1]; +let max = maxAndExpected[requests][0]; +let expected = maxAndExpected[requests][1]; -var server = http.createServer(function(req, res) { +const server = http.createServer(function(req, res) { assert.equal(Object.keys(req.headers).length, expected); if (++requests < maxAndExpected.length) { max = maxAndExpected[requests][0]; @@ -33,7 +33,7 @@ var server = http.createServer(function(req, res) { server.maxHeadersCount = max; server.listen(0, function() { - var maxAndExpected = [ // for client + const maxAndExpected = [ // for client [20, 20], [1200, 1200], [0, N + 3] // Connection, Date and Transfer-Encoding @@ -41,9 +41,9 @@ server.listen(0, function() { doRequest(); function doRequest() { - var max = maxAndExpected[responses][0]; - var expected = maxAndExpected[responses][1]; - var req = http.request({ + const max = maxAndExpected[responses][0]; + const expected = maxAndExpected[responses][1]; + const req = http.request({ port: server.address().port, headers: headers }, function(res) { diff --git a/test/parallel/test-http-methods.js b/test/parallel/test-http-methods.js index d3d4fedd46361b..6ba02807f8706b 100644 --- a/test/parallel/test-http-methods.js +++ b/test/parallel/test-http-methods.js @@ -1,8 +1,8 @@ 'use strict'; require('../common'); -var assert = require('assert'); -var http = require('http'); -var util = require('util'); +const assert = require('assert'); +const http = require('http'); +const util = require('util'); assert(Array.isArray(http.METHODS)); assert(http.METHODS.length > 0); diff --git a/test/parallel/test-http-multi-line-headers.js b/test/parallel/test-http-multi-line-headers.js index df333cdd62bf9b..2096f533a196d1 100644 --- a/test/parallel/test-http-multi-line-headers.js +++ b/test/parallel/test-http-multi-line-headers.js @@ -1,14 +1,14 @@ 'use strict'; const common = require('../common'); -var assert = require('assert'); +const assert = require('assert'); -var http = require('http'); -var net = require('net'); +const http = require('http'); +const net = require('net'); -var server = net.createServer(function(conn) { - var body = 'Yet another node.js server.'; +const server = net.createServer(function(conn) { + const body = 'Yet another node.js server.'; - var response = + const response = 'HTTP/1.1 200 OK\r\n' + 'Connection: close\r\n' + 'Content-Length: ' + body.length + '\r\n' + diff --git a/test/parallel/test-http-mutable-headers.js b/test/parallel/test-http-mutable-headers.js index 0228a4e216ec46..fcff395cffe9bb 100644 --- a/test/parallel/test-http-mutable-headers.js +++ b/test/parallel/test-http-mutable-headers.js @@ -1,7 +1,7 @@ 'use strict'; require('../common'); -var assert = require('assert'); -var http = require('http'); +const assert = require('assert'); +const http = require('http'); // Simple test of Node's HTTP Client mutable headers // OutgoingMessage.prototype.setHeader(name, value) @@ -11,15 +11,15 @@ var http = require('http'); // .method // .path -var testsComplete = 0; -var test = 'headers'; -var content = 'hello world\n'; -var cookies = [ +let testsComplete = 0; +let test = 'headers'; +const content = 'hello world\n'; +const cookies = [ 'session_token=; path=/; expires=Sun, 15-Sep-2030 13:48:52 GMT', 'prefers_open_id=; path=/; expires=Thu, 01-Jan-1970 00:00:00 GMT' ]; -var s = http.createServer(function(req, res) { +const s = http.createServer(function(req, res) { switch (test) { case 'headers': assert.throws(function() { res.setHeader(); }); @@ -32,8 +32,8 @@ var s = http.createServer(function(req, res) { res.setHeader('set-cookie', cookies); res.setHeader('x-test-array-header', [1, 2, 3]); - var val1 = res.getHeader('x-test-header'); - var val2 = res.getHeader('x-test-header2'); + const val1 = res.getHeader('x-test-header'); + const val2 = res.getHeader('x-test-header2'); assert.equal(val1, 'testing'); assert.equal(val2, 'testing'); @@ -69,7 +69,7 @@ function nextTest() { return s.close(); } - var bufferedResponse = ''; + let bufferedResponse = ''; http.get({ port: s.address().port }, function(response) { console.log('TEST: ' + test); diff --git a/test/parallel/test-http-no-content-length.js b/test/parallel/test-http-no-content-length.js index b27ffda727129e..a6cfad13aa2b44 100644 --- a/test/parallel/test-http-no-content-length.js +++ b/test/parallel/test-http-no-content-length.js @@ -1,15 +1,15 @@ 'use strict'; const common = require('../common'); -var assert = require('assert'); -var net = require('net'); -var http = require('http'); +const assert = require('assert'); +const net = require('net'); +const http = require('http'); -var server = net.createServer(function(socket) { +const server = net.createServer(function(socket) { // Neither Content-Length nor Connection socket.end('HTTP/1.1 200 ok\r\n\r\nHello'); }).listen(0, common.mustCall(function() { http.get({port: this.address().port}, common.mustCall(function(res) { - var body = ''; + let body = ''; res.setEncoding('utf8'); res.on('data', function(chunk) { diff --git a/test/parallel/test-http-outgoing-finish.js b/test/parallel/test-http-outgoing-finish.js index 56ce777cb3eaaf..73654909d88e1b 100644 --- a/test/parallel/test-http-outgoing-finish.js +++ b/test/parallel/test-http-outgoing-finish.js @@ -1,8 +1,8 @@ 'use strict'; require('../common'); -var assert = require('assert'); +const assert = require('assert'); -var http = require('http'); +const http = require('http'); http.createServer(function(req, res) { req.resume(); @@ -11,7 +11,7 @@ http.createServer(function(req, res) { }); this.close(); }).listen(0, function() { - var req = http.request({ + const req = http.request({ port: this.address().port, method: 'PUT' }); @@ -21,11 +21,11 @@ http.createServer(function(req, res) { }); }); -var buf = Buffer.alloc(1024 * 16, 'x'); +const buf = Buffer.alloc(1024 * 16, 'x'); function write(out) { - var name = out.constructor.name; - var finishEvent = false; - var endCb = false; + const name = out.constructor.name; + let finishEvent = false; + let endCb = false; // first, write until it gets some backpressure while (out.write(buf)) {} diff --git a/test/parallel/test-http-parser-bad-ref.js b/test/parallel/test-http-parser-bad-ref.js index 73d5f7eb13049c..69682128fadbdf 100644 --- a/test/parallel/test-http-parser-bad-ref.js +++ b/test/parallel/test-http-parser-bad-ref.js @@ -5,16 +5,16 @@ // Flags: --expose_gc require('../common'); -var assert = require('assert'); -var HTTPParser = process.binding('http_parser').HTTPParser; +const assert = require('assert'); +const HTTPParser = process.binding('http_parser').HTTPParser; -var kOnHeaders = HTTPParser.kOnHeaders | 0; -var kOnHeadersComplete = HTTPParser.kOnHeadersComplete | 0; -var kOnBody = HTTPParser.kOnBody | 0; -var kOnMessageComplete = HTTPParser.kOnMessageComplete | 0; +const kOnHeaders = HTTPParser.kOnHeaders | 0; +const kOnHeadersComplete = HTTPParser.kOnHeadersComplete | 0; +const kOnBody = HTTPParser.kOnBody | 0; +const kOnMessageComplete = HTTPParser.kOnMessageComplete | 0; -var headersComplete = 0; -var messagesComplete = 0; +let headersComplete = 0; +let messagesComplete = 0; function flushPool() { Buffer.allocUnsafe(Buffer.poolSize - 1); @@ -24,7 +24,7 @@ function flushPool() { function demoBug(part1, part2) { flushPool(); - var parser = new HTTPParser('REQUEST'); + const parser = new HTTPParser('REQUEST'); parser.headers = []; parser.url = ''; @@ -49,7 +49,7 @@ function demoBug(part1, part2) { // We use a function to eliminate references to the Buffer b // We want b to be GCed. The parser will hold a bad reference to it. (function() { - var b = Buffer.from(part1); + const b = Buffer.from(part1); flushPool(); console.log('parse the first part of the message'); @@ -59,7 +59,7 @@ function demoBug(part1, part2) { flushPool(); (function() { - var b = Buffer.from(part2); + const b = Buffer.from(part2); console.log('parse the second part of the message'); parser.execute(b, 0, b.length); diff --git a/test/parallel/test-http-parser-free.js b/test/parallel/test-http-parser-free.js index 125374bbedde63..80cc3cc64ee5b3 100644 --- a/test/parallel/test-http-parser-free.js +++ b/test/parallel/test-http-parser-free.js @@ -1,20 +1,20 @@ 'use strict'; require('../common'); -var assert = require('assert'); -var http = require('http'); -var N = 100; -var responses = 0; +const assert = require('assert'); +const http = require('http'); +const N = 100; +let responses = 0; -var server = http.createServer(function(req, res) { +const server = http.createServer(function(req, res) { res.end('Hello'); }); server.listen(0, function() { http.globalAgent.maxSockets = 1; - var parser; - for (var i = 0; i < N; ++i) { + let parser; + for (let i = 0; i < N; ++i) { (function makeRequest(i) { - var req = http.get({port: server.address().port}, function(res) { + const req = http.get({port: server.address().port}, function(res) { if (!parser) { parser = req.parser; } else { diff --git a/test/parallel/test-http-parser.js b/test/parallel/test-http-parser.js index abc1d096dff0d8..e1215fbd13ae40 100644 --- a/test/parallel/test-http-parser.js +++ b/test/parallel/test-http-parser.js @@ -1,19 +1,19 @@ 'use strict'; require('../common'); -var assert = require('assert'); +const assert = require('assert'); const binding = process.binding('http_parser'); const methods = binding.methods; const HTTPParser = binding.HTTPParser; -var CRLF = '\r\n'; -var REQUEST = HTTPParser.REQUEST; -var RESPONSE = HTTPParser.RESPONSE; +const CRLF = '\r\n'; +const REQUEST = HTTPParser.REQUEST; +const RESPONSE = HTTPParser.RESPONSE; -var kOnHeaders = HTTPParser.kOnHeaders | 0; -var kOnHeadersComplete = HTTPParser.kOnHeadersComplete | 0; -var kOnBody = HTTPParser.kOnBody | 0; -var kOnMessageComplete = HTTPParser.kOnMessageComplete | 0; +const kOnHeaders = HTTPParser.kOnHeaders | 0; +const kOnHeadersComplete = HTTPParser.kOnHeadersComplete | 0; +const kOnBody = HTTPParser.kOnBody | 0; +const kOnMessageComplete = HTTPParser.kOnMessageComplete | 0; // The purpose of this test is not to check HTTP compliance but to test the // binding. Tests for pathological http messages should be submitted @@ -22,7 +22,7 @@ var kOnMessageComplete = HTTPParser.kOnMessageComplete | 0; function newParser(type) { - var parser = new HTTPParser(type); + const parser = new HTTPParser(type); parser.headers = []; parser.url = ''; @@ -47,7 +47,7 @@ function newParser(type) { function mustCall(f, times) { - var actual = 0; + let actual = 0; process.setMaxListeners(256); process.on('exit', function() { @@ -63,7 +63,7 @@ function mustCall(f, times) { function expectBody(expected) { return mustCall(function(buf, start, len) { - var body = '' + buf.slice(start, start + len); + const body = '' + buf.slice(start, start + len); assert.equal(body, expected); }); } @@ -447,11 +447,11 @@ function expectBody(expected) { assert.strictEqual(expected_body, ''); } - for (var i = 1; i < request.length - 1; ++i) { - var a = request.slice(0, i); + for (let i = 1; i < request.length - 1; ++i) { + const a = request.slice(0, i); console.error('request.slice(0, ' + i + ') = ', JSON.stringify(a.toString())); - var b = request.slice(i); + const b = request.slice(i); console.error('request.slice(' + i + ') = ', JSON.stringify(b.toString())); test(a, b); @@ -571,11 +571,11 @@ function expectBody(expected) { // Test parser 'this' safety // https://github.com/joyent/node/issues/6690 assert.throws(function() { - var request = Buffer.from( + const request = Buffer.from( 'GET /hello HTTP/1.1' + CRLF + CRLF); - var parser = newParser(REQUEST); - var notparser = { execute: parser.execute }; + const parser = newParser(REQUEST); + const notparser = { execute: parser.execute }; notparser.execute(request, 0, request.length); }, TypeError); diff --git a/test/parallel/test-http-pause.js b/test/parallel/test-http-pause.js index f6562b3afc94ae..8bb8dd4b5da25c 100644 --- a/test/parallel/test-http-pause.js +++ b/test/parallel/test-http-pause.js @@ -1,14 +1,14 @@ 'use strict'; require('../common'); -var assert = require('assert'); -var http = require('http'); +const assert = require('assert'); +const http = require('http'); -var expectedServer = 'Request Body from Client'; -var resultServer = ''; -var expectedClient = 'Response Body from Server'; -var resultClient = ''; +const expectedServer = 'Request Body from Client'; +let resultServer = ''; +const expectedClient = 'Response Body from Server'; +let resultClient = ''; -var server = http.createServer(function(req, res) { +const server = http.createServer(function(req, res) { console.error('pause server request'); req.pause(); setTimeout(function() { @@ -27,7 +27,7 @@ var server = http.createServer(function(req, res) { }); server.listen(0, function() { - var req = http.request({ + const req = http.request({ port: this.address().port, path: '/', method: 'POST' diff --git a/test/parallel/test-http-pipe-fs.js b/test/parallel/test-http-pipe-fs.js index 3205802d7ab0f2..5348637bd07145 100644 --- a/test/parallel/test-http-pipe-fs.js +++ b/test/parallel/test-http-pipe-fs.js @@ -1,15 +1,15 @@ 'use strict'; -var common = require('../common'); -var http = require('http'); -var fs = require('fs'); -var path = require('path'); +const common = require('../common'); +const http = require('http'); +const fs = require('fs'); +const path = require('path'); common.refreshTmpDir(); -var file = path.join(common.tmpDir, 'http-pipe-fs-test.txt'); +const file = path.join(common.tmpDir, 'http-pipe-fs-test.txt'); -var server = http.createServer(common.mustCall(function(req, res) { - var stream = fs.createWriteStream(file); +const server = http.createServer(common.mustCall(function(req, res) { + const stream = fs.createWriteStream(file); req.pipe(stream); stream.on('close', function() { res.writeHead(200); @@ -18,9 +18,9 @@ var server = http.createServer(common.mustCall(function(req, res) { }, 2)).listen(0, function() { http.globalAgent.maxSockets = 1; - for (var i = 0; i < 2; ++i) { + for (let i = 0; i < 2; ++i) { (function(i) { - var req = http.request({ + const req = http.request({ port: server.address().port, method: 'POST', headers: { diff --git a/test/parallel/test-http-pipeline-flood.js b/test/parallel/test-http-pipeline-flood.js index 4f6775656e4e49..99e4c3e7b5b9fe 100644 --- a/test/parallel/test-http-pipeline-flood.js +++ b/test/parallel/test-http-pipeline-flood.js @@ -26,7 +26,7 @@ switch (process.argv[2]) { function parent() { const http = require('http'); const bigResponse = Buffer.alloc(10240, 'x'); - var backloggedReqs = 0; + let backloggedReqs = 0; const server = http.createServer(function(req, res) { res.setHeader('content-length', bigResponse.length); @@ -68,7 +68,7 @@ function child() { const port = +process.argv[3]; const conn = net.connect({ port: port }); - var req = `GET / HTTP/1.1\r\nHost: localhost:${port}\r\nAccept: */*\r\n\r\n`; + let req = `GET / HTTP/1.1\r\nHost: localhost:${port}\r\nAccept: */*\r\n\r\n`; req = new Array(10241).join(req); diff --git a/test/parallel/test-http-pipeline-regr-2639.js b/test/parallel/test-http-pipeline-regr-2639.js index f67803ba159c74..7933e419d324f7 100644 --- a/test/parallel/test-http-pipeline-regr-2639.js +++ b/test/parallel/test-http-pipeline-regr-2639.js @@ -6,9 +6,9 @@ const net = require('net'); const COUNT = 10; -var received = 0; +let received = 0; -var server = http.createServer(function(req, res) { +const server = http.createServer(function(req, res) { // Close the server, we have only one TCP connection anyway if (received++ === 0) server.close(); @@ -22,7 +22,7 @@ var server = http.createServer(function(req, res) { }).listen(0, function() { const s = net.connect(this.address().port); - var big = 'GET / HTTP/1.0\r\n\r\n'.repeat(COUNT); + const big = 'GET / HTTP/1.0\r\n\r\n'.repeat(COUNT); s.write(big); s.resume(); diff --git a/test/parallel/test-http-pipeline-regr-3332.js b/test/parallel/test-http-pipeline-regr-3332.js index fdbb76bf8d643d..3ab9e6104c9848 100644 --- a/test/parallel/test-http-pipeline-regr-3332.js +++ b/test/parallel/test-http-pipeline-regr-3332.js @@ -8,9 +8,9 @@ const big = Buffer.alloc(16 * 1024, 'A'); const COUNT = 1e4; -var received = 0; +let received = 0; -var client; +let client; const server = http.createServer(function(req, res) { res.end(big, function() { if (++received === COUNT) { @@ -19,7 +19,7 @@ const server = http.createServer(function(req, res) { } }); }).listen(0, function() { - var req = new Array(COUNT + 1).join('GET / HTTP/1.1\r\n\r\n'); + const req = new Array(COUNT + 1).join('GET / HTTP/1.1\r\n\r\n'); client = net.connect(this.address().port, function() { client.write(req); }); diff --git a/test/parallel/test-http-pipeline-regr-3508.js b/test/parallel/test-http-pipeline-regr-3508.js index b368bae0d7790e..ff735818f68121 100644 --- a/test/parallel/test-http-pipeline-regr-3508.js +++ b/test/parallel/test-http-pipeline-regr-3508.js @@ -3,18 +3,18 @@ require('../common'); const http = require('http'); const net = require('net'); -var once = false; -var first = null; -var second = null; +let once = false; +let first = null; +let second = null; const chunk = Buffer.alloc(1024, 'X'); -var size = 0; +let size = 0; -var more; -var done; +let more; +let done; -var server = http.createServer(function(req, res) { +const server = http.createServer(function(req, res) { if (!once) server.close(); once = true; @@ -41,7 +41,7 @@ var server = http.createServer(function(req, res) { }); first.end('hello'); }).listen(0, function() { - var s = net.connect(this.address().port); + const s = net.connect(this.address().port); more = function() { s.write('GET / HTTP/1.1\r\n\r\n'); }; diff --git a/test/parallel/test-http-proxy.js b/test/parallel/test-http-proxy.js index 48367caaa7d89e..8e7fd55a0ed6ea 100644 --- a/test/parallel/test-http-proxy.js +++ b/test/parallel/test-http-proxy.js @@ -1,26 +1,26 @@ 'use strict'; require('../common'); -var assert = require('assert'); -var http = require('http'); -var url = require('url'); +const assert = require('assert'); +const http = require('http'); +const url = require('url'); -var cookies = [ +const cookies = [ 'session_token=; path=/; expires=Sun, 15-Sep-2030 13:48:52 GMT', 'prefers_open_id=; path=/; expires=Thu, 01-Jan-1970 00:00:00 GMT' ]; -var headers = {'content-type': 'text/plain', - 'set-cookie': cookies, - 'hello': 'world' }; +const headers = {'content-type': 'text/plain', + 'set-cookie': cookies, + 'hello': 'world' }; -var backend = http.createServer(function(req, res) { +const backend = http.createServer(function(req, res) { console.error('backend request'); res.writeHead(200, headers); res.write('hello world\n'); res.end(); }); -var proxy = http.createServer(function(req, res) { +const proxy = http.createServer(function(req, res) { console.error('proxy req headers: ' + JSON.stringify(req.headers)); http.get({ port: backend.address().port, @@ -46,9 +46,9 @@ var proxy = http.createServer(function(req, res) { }); }); -var body = ''; +let body = ''; -var nlistening = 0; +let nlistening = 0; function startReq() { nlistening++; if (nlistening < 2) return; diff --git a/test/parallel/test-http-raw-headers.js b/test/parallel/test-http-raw-headers.js index 2e2e9631490395..7ae0c35e3d8d11 100644 --- a/test/parallel/test-http-raw-headers.js +++ b/test/parallel/test-http-raw-headers.js @@ -1,11 +1,11 @@ 'use strict'; require('../common'); -var assert = require('assert'); +const assert = require('assert'); -var http = require('http'); +const http = require('http'); http.createServer(function(req, res) { - var expectRawHeaders = [ + const expectRawHeaders = [ 'Host', `localhost:${this.address().port}`, 'transfer-ENCODING', @@ -15,13 +15,13 @@ http.createServer(function(req, res) { 'Connection', 'close' ]; - var expectHeaders = { + const expectHeaders = { host: `localhost:${this.address().port}`, 'transfer-encoding': 'CHUNKED', 'x-bar': 'yoyoyo', connection: 'close' }; - var expectRawTrailers = [ + const expectRawTrailers = [ 'x-bAr', 'yOyOyOy', 'x-baR', @@ -31,7 +31,7 @@ http.createServer(function(req, res) { 'X-baR', 'OyOyOyO' ]; - var expectTrailers = { 'x-bar': 'yOyOyOy, OyOyOyO, yOyOyOy, OyOyOyO' }; + const expectTrailers = { 'x-bar': 'yOyOyOy, OyOyOyO, yOyOyOy, OyOyOyO' }; this.close(); @@ -53,7 +53,7 @@ http.createServer(function(req, res) { ]); res.end('x f o o'); }).listen(0, function() { - var req = http.request({ port: this.address().port, path: '/' }); + const req = http.request({ port: this.address().port, path: '/' }); req.addTrailers([ ['x-bAr', 'yOyOyOy'], ['x-baR', 'OyOyOyO'], @@ -64,7 +64,7 @@ http.createServer(function(req, res) { req.setHeader('x-BaR', 'yoyoyo'); req.end('y b a r'); req.on('response', function(res) { - var expectRawHeaders = [ + const expectRawHeaders = [ 'Trailer', 'x-foo', 'Date', @@ -74,7 +74,7 @@ http.createServer(function(req, res) { 'Transfer-Encoding', 'chunked' ]; - var expectHeaders = { + const expectHeaders = { trailer: 'x-foo', date: null, connection: 'close', @@ -85,7 +85,7 @@ http.createServer(function(req, res) { assert.deepStrictEqual(res.rawHeaders, expectRawHeaders); assert.deepStrictEqual(res.headers, expectHeaders); res.on('end', function() { - var expectRawTrailers = [ + const expectRawTrailers = [ 'x-fOo', 'xOxOxOx', 'x-foO', @@ -95,7 +95,7 @@ http.createServer(function(req, res) { 'X-foO', 'OxOxOxO' ]; - var expectTrailers = { 'x-foo': 'xOxOxOx, OxOxOxO, xOxOxOx, OxOxOxO' }; + const expectTrailers = { 'x-foo': 'xOxOxOx, OxOxOxO, xOxOxOx, OxOxOxO' }; assert.deepStrictEqual(res.rawTrailers, expectRawTrailers); assert.deepStrictEqual(res.trailers, expectTrailers); diff --git a/test/parallel/test-http-remove-header-stays-removed.js b/test/parallel/test-http-remove-header-stays-removed.js index 9b8ff35b0fe5d3..077ff0f5b33f40 100644 --- a/test/parallel/test-http-remove-header-stays-removed.js +++ b/test/parallel/test-http-remove-header-stays-removed.js @@ -1,10 +1,10 @@ 'use strict'; require('../common'); -var assert = require('assert'); +const assert = require('assert'); -var http = require('http'); +const http = require('http'); -var server = http.createServer(function(request, response) { +const server = http.createServer(function(request, response) { // removed headers should stay removed, even if node automatically adds them // to the output: response.removeHeader('connection'); @@ -20,7 +20,7 @@ var server = http.createServer(function(request, response) { this.close(); }); -var response = ''; +let response = ''; process.on('exit', function() { assert.equal('beep boop\n', response); diff --git a/test/parallel/test-http-request-dont-override-options.js b/test/parallel/test-http-request-dont-override-options.js index 5570dd49a2fc1b..04235fd0e42b4e 100644 --- a/test/parallel/test-http-request-dont-override-options.js +++ b/test/parallel/test-http-request-dont-override-options.js @@ -4,7 +4,7 @@ const common = require('../common'); const assert = require('assert'); const http = require('http'); -var requests = 0; +let requests = 0; http.createServer(function(req, res) { res.writeHead(200); @@ -12,13 +12,13 @@ http.createServer(function(req, res) { requests++; }).listen(0, function() { - var agent = new http.Agent(); + const agent = new http.Agent(); agent.defaultPort = this.address().port; // options marked as explicitly undefined for readability // in this test, they should STAY undefined as options should not // be mutable / modified - var options = { + const options = { host: undefined, hostname: common.localhostIPv4, port: undefined, diff --git a/test/parallel/test-http-request-end-twice.js b/test/parallel/test-http-request-end-twice.js index 230175be8e95c1..ab30c0a1eef8a1 100644 --- a/test/parallel/test-http-request-end-twice.js +++ b/test/parallel/test-http-request-end-twice.js @@ -1,14 +1,14 @@ 'use strict'; require('../common'); -var assert = require('assert'); -var http = require('http'); +const assert = require('assert'); +const http = require('http'); -var server = http.Server(function(req, res) { +const server = http.Server(function(req, res) { res.writeHead(200, {'Content-Type': 'text/plain'}); res.end('hello world\n'); }); server.listen(0, function() { - var req = http.get({port: this.address().port}, function(res) { + const req = http.get({port: this.address().port}, function(res) { res.on('end', function() { assert.ok(!req.end()); server.close(); diff --git a/test/parallel/test-http-request-end.js b/test/parallel/test-http-request-end.js index 6beedae20d9e00..dd4a8caf105329 100644 --- a/test/parallel/test-http-request-end.js +++ b/test/parallel/test-http-request-end.js @@ -1,12 +1,12 @@ 'use strict'; require('../common'); -var assert = require('assert'); -var http = require('http'); +const assert = require('assert'); +const http = require('http'); -var expected = 'Post Body For Test'; +const expected = 'Post Body For Test'; -var server = http.Server(function(req, res) { - var result = ''; +const server = http.Server(function(req, res) { + let result = ''; req.setEncoding('utf8'); req.on('data', function(chunk) { diff --git a/test/parallel/test-http-request-methods.js b/test/parallel/test-http-request-methods.js index 7f42a9c00a85f3..e4579791ef301a 100644 --- a/test/parallel/test-http-request-methods.js +++ b/test/parallel/test-http-request-methods.js @@ -1,13 +1,13 @@ 'use strict'; const common = require('../common'); -var assert = require('assert'); -var net = require('net'); -var http = require('http'); +const assert = require('assert'); +const net = require('net'); +const http = require('http'); // Test that the DELETE, PATCH and PURGE verbs get passed through correctly ['DELETE', 'PATCH', 'PURGE'].forEach(function(method, index) { - var server = http.createServer(common.mustCall(function(req, res) { + const server = http.createServer(common.mustCall(function(req, res) { assert.strictEqual(req.method, method); res.writeHead(200, {'Content-Type': 'text/plain'}); res.write('hello '); @@ -17,8 +17,8 @@ var http = require('http'); server.listen(0); server.on('listening', common.mustCall(function() { - var c = net.createConnection(this.address().port); - var server_response = ''; + const c = net.createConnection(this.address().port); + let server_response = ''; c.setEncoding('utf8'); diff --git a/test/parallel/test-http-res-write-after-end.js b/test/parallel/test-http-res-write-after-end.js index 5a91c556340b1c..2ee0e4e29d95e4 100644 --- a/test/parallel/test-http-res-write-after-end.js +++ b/test/parallel/test-http-res-write-after-end.js @@ -1,9 +1,9 @@ 'use strict'; const common = require('../common'); -var assert = require('assert'); -var http = require('http'); +const assert = require('assert'); +const http = require('http'); -var server = http.Server(common.mustCall(function(req, res) { +const server = http.Server(common.mustCall(function(req, res) { res.on('error', common.mustCall(function onResError(err) { assert.strictEqual(err.message, 'write after end'); })); @@ -11,7 +11,7 @@ var server = http.Server(common.mustCall(function(req, res) { res.write('This should write.'); res.end(); - var r = res.write('This should raise an error.'); + const r = res.write('This should raise an error.'); assert.equal(r, true, 'write after end should return true'); })); diff --git a/test/parallel/test-http-res-write-end-dont-take-array.js b/test/parallel/test-http-res-write-end-dont-take-array.js index 5c14b0678520c4..6964ec15965a96 100644 --- a/test/parallel/test-http-res-write-end-dont-take-array.js +++ b/test/parallel/test-http-res-write-end-dont-take-array.js @@ -1,11 +1,11 @@ 'use strict'; require('../common'); -var assert = require('assert'); -var http = require('http'); +const assert = require('assert'); +const http = require('http'); -var test = 1; +let test = 1; -var server = http.createServer(function(req, res) { +const server = http.createServer(function(req, res) { res.writeHead(200, {'Content-Type': 'text/plain'}); if (test === 1) { // write should accept string diff --git a/test/parallel/test-http-response-close.js b/test/parallel/test-http-response-close.js index 54ee61efccf1ea..de179c113e1db1 100644 --- a/test/parallel/test-http-response-close.js +++ b/test/parallel/test-http-response-close.js @@ -1,8 +1,8 @@ 'use strict'; const common = require('../common'); -var http = require('http'); +const http = require('http'); -var server = http.createServer(common.mustCall(function(req, res) { +const server = http.createServer(common.mustCall(function(req, res) { res.writeHead(200); res.write('a'); diff --git a/test/parallel/test-http-response-multi-content-length.js b/test/parallel/test-http-response-multi-content-length.js index 3290f74c16e250..7cd802a74aa80c 100644 --- a/test/parallel/test-http-response-multi-content-length.js +++ b/test/parallel/test-http-response-multi-content-length.js @@ -24,7 +24,7 @@ const server = http.createServer((req, res) => { res.end('ok'); }); -var count = 0; +let count = 0; server.listen(0, common.mustCall(() => { for (let n = 1; n <= MAX_COUNT; n++) { diff --git a/test/parallel/test-http-response-multiheaders.js b/test/parallel/test-http-response-multiheaders.js index f4c1fd4116b735..8f48dc2377f3c3 100644 --- a/test/parallel/test-http-response-multiheaders.js +++ b/test/parallel/test-http-response-multiheaders.js @@ -29,7 +29,7 @@ const norepeat = [ ]; const server = http.createServer(function(req, res) { - var num = req.headers['x-num']; + const num = req.headers['x-num']; if (num === '1') { for (const name of norepeat) { res.setHeader(name, ['A', 'B']); @@ -47,7 +47,7 @@ const server = http.createServer(function(req, res) { }); server.listen(0, common.mustCall(function() { - var count = 0; + let count = 0; for (let n = 1; n <= 2; n++) { // this runs twice, the first time, the server will use // setHeader, the second time it uses writeHead. The diff --git a/test/parallel/test-http-response-no-headers.js b/test/parallel/test-http-response-no-headers.js index 4a3460bc645140..3f44b4ef5fde0b 100644 --- a/test/parallel/test-http-response-no-headers.js +++ b/test/parallel/test-http-response-no-headers.js @@ -1,31 +1,31 @@ 'use strict'; const common = require('../common'); -var assert = require('assert'); -var http = require('http'); -var net = require('net'); +const assert = require('assert'); +const http = require('http'); +const net = require('net'); -var expected = { +const expected = { '0.9': 'I AM THE WALRUS', '1.0': 'I AM THE WALRUS', '1.1': '' }; function test(httpVersion, callback) { - var server = net.createServer(function(conn) { - var reply = 'HTTP/' + httpVersion + ' 200 OK\r\n\r\n' + - expected[httpVersion]; + const server = net.createServer(function(conn) { + const reply = 'HTTP/' + httpVersion + ' 200 OK\r\n\r\n' + + expected[httpVersion]; conn.end(reply); }); server.listen(0, '127.0.0.1', common.mustCall(function() { - var options = { + const options = { host: '127.0.0.1', port: this.address().port }; - var req = http.get(options, common.mustCall(function(res) { - var body = ''; + const req = http.get(options, common.mustCall(function(res) { + let body = ''; res.on('data', function(data) { body += data; diff --git a/test/parallel/test-http-response-readable.js b/test/parallel/test-http-response-readable.js index 1d561ca4704808..07c0a40e4bf1a8 100644 --- a/test/parallel/test-http-response-readable.js +++ b/test/parallel/test-http-response-readable.js @@ -1,9 +1,9 @@ 'use strict'; require('../common'); -var assert = require('assert'); -var http = require('http'); +const assert = require('assert'); +const http = require('http'); -var testServer = new http.Server(function(req, res) { +const testServer = new http.Server(function(req, res) { res.writeHead(200); res.end('Hello world'); }); diff --git a/test/parallel/test-http-response-splitting.js b/test/parallel/test-http-response-splitting.js index f2c7bc5d8d1219..e6927bc1e63f77 100644 --- a/test/parallel/test-http-response-splitting.js +++ b/test/parallel/test-http-response-splitting.js @@ -17,7 +17,7 @@ const str = '/welcome?lang=bar%c4%8d%c4%8aContent­Length:%200%c4%8d%c4%8a%c' + const x = 'fooഊSet-Cookie: foo=barഊഊ'; const y = 'foo⠊Set-Cookie: foo=bar'; -var count = 0; +let count = 0; function test(res, code, header) { assert.throws(() => { diff --git a/test/parallel/test-http-response-status-message.js b/test/parallel/test-http-response-status-message.js index b14c1f2faf0fce..d17dfb24c6b4c8 100644 --- a/test/parallel/test-http-response-status-message.js +++ b/test/parallel/test-http-response-status-message.js @@ -1,12 +1,12 @@ 'use strict'; require('../common'); -var assert = require('assert'); -var http = require('http'); -var net = require('net'); +const assert = require('assert'); +const http = require('http'); +const net = require('net'); -var testsComplete = 0; +let testsComplete = 0; -var testCases = [ +const testCases = [ { path: '/200', statusMessage: 'OK', response: 'HTTP/1.1 200 OK\r\n\r\n' }, { path: '/500', statusMessage: 'Internal Server Error', @@ -19,7 +19,7 @@ var testCases = [ response: 'HTTP/1.1 200\r\n\r\n' } ]; testCases.findByPath = function(path) { - var matching = this.filter(function(testCase) { + const matching = this.filter(function(testCase) { return testCase.path === path; }); if (matching.length === 0) { @@ -28,18 +28,18 @@ testCases.findByPath = function(path) { return matching[0]; }; -var server = net.createServer(function(connection) { +const server = net.createServer(function(connection) { connection.on('data', function(data) { - var path = data.toString().match(/GET (.*) HTTP.1.1/)[1]; - var testCase = testCases.findByPath(path); + const path = data.toString().match(/GET (.*) HTTP.1.1/)[1]; + const testCase = testCases.findByPath(path); connection.write(testCase.response); connection.end(); }); }); -var runTest = function(testCaseIndex) { - var testCase = testCases[testCaseIndex]; +const runTest = function(testCaseIndex) { + const testCase = testCases[testCaseIndex]; http.get({ port: server.address().port, diff --git a/test/parallel/test-http-server-client-error.js b/test/parallel/test-http-server-client-error.js index cd20b7321a63f7..260963dc24daaa 100644 --- a/test/parallel/test-http-server-client-error.js +++ b/test/parallel/test-http-server-client-error.js @@ -21,7 +21,7 @@ server.listen(0, function() { const client = net.connect(server.address().port); client.end('Oopsie-doopsie\r\n'); - var chunks = ''; + let chunks = ''; client.on('data', function(chunk) { chunks += chunk; }); diff --git a/test/parallel/test-http-server-multiheaders.js b/test/parallel/test-http-server-multiheaders.js index 5b41ee89d87e50..189ab0657bacb0 100644 --- a/test/parallel/test-http-server-multiheaders.js +++ b/test/parallel/test-http-server-multiheaders.js @@ -4,10 +4,10 @@ // that support it, and dropping duplicates for other fields. require('../common'); -var assert = require('assert'); -var http = require('http'); +const assert = require('assert'); +const http = require('http'); -var srv = http.createServer(function(req, res) { +const srv = http.createServer(function(req, res) { assert.equal(req.headers.accept, 'abc, def, ghijklmnopqrst'); assert.equal(req.headers.host, 'foo'); assert.equal(req.headers['www-authenticate'], 'foo, bar, baz'); diff --git a/test/parallel/test-http-server-multiheaders2.js b/test/parallel/test-http-server-multiheaders2.js index 9f6d41e6a10cea..82cc9960329a11 100644 --- a/test/parallel/test-http-server-multiheaders2.js +++ b/test/parallel/test-http-server-multiheaders2.js @@ -4,10 +4,10 @@ // that support it, and dropping duplicates for other fields. require('../common'); -var assert = require('assert'); -var http = require('http'); +const assert = require('assert'); +const http = require('http'); -var multipleAllowed = [ +const multipleAllowed = [ 'Accept', 'Accept-Charset', 'Accept-Encoding', @@ -31,7 +31,7 @@ var multipleAllowed = [ 'X-Some-Random-Header', ]; -var multipleForbidden = [ +const multipleForbidden = [ 'Content-Type', 'User-Agent', 'Referer', @@ -48,7 +48,7 @@ var multipleForbidden = [ //'Content-Length', ]; -var srv = http.createServer(function(req, res) { +const srv = http.createServer(function(req, res) { multipleForbidden.forEach(function(header) { assert.equal(req.headers[header.toLowerCase()], 'foo', 'header parsed incorrectly: ' + header); @@ -70,7 +70,7 @@ function makeHeader(value) { }; } -var headers = [] +const headers = [] .concat(multipleAllowed.map(makeHeader('foo'))) .concat(multipleForbidden.map(makeHeader('foo'))) .concat(multipleAllowed.map(makeHeader('bar'))) diff --git a/test/parallel/test-http-server-stale-close.js b/test/parallel/test-http-server-stale-close.js index 819f503de547e4..3728453c039447 100644 --- a/test/parallel/test-http-server-stale-close.js +++ b/test/parallel/test-http-server-stale-close.js @@ -1,11 +1,11 @@ 'use strict'; require('../common'); -var http = require('http'); -var util = require('util'); -var fork = require('child_process').fork; +const http = require('http'); +const util = require('util'); +const fork = require('child_process').fork; if (process.env.NODE_TEST_FORK_PORT) { - var req = http.request({ + const req = http.request({ headers: {'Content-Length': '42'}, method: 'POST', host: '127.0.0.1', @@ -14,7 +14,7 @@ if (process.env.NODE_TEST_FORK_PORT) { req.write('BAM'); req.end(); } else { - var server = http.createServer(function(req, res) { + const server = http.createServer(function(req, res) { res.writeHead(200, {'Content-Length': '42'}); req.pipe(res); req.on('close', function() { diff --git a/test/parallel/test-http-server-unconsume.js b/test/parallel/test-http-server-unconsume.js index 76238380c7cfde..fca2691aacc25d 100644 --- a/test/parallel/test-http-server-unconsume.js +++ b/test/parallel/test-http-server-unconsume.js @@ -1,12 +1,12 @@ 'use strict'; require('../common'); -var assert = require('assert'); -var http = require('http'); -var net = require('net'); +const assert = require('assert'); +const http = require('http'); +const net = require('net'); -var received = ''; +let received = ''; -var server = http.createServer(function(req, res) { +const server = http.createServer(function(req, res) { res.writeHead(200); res.end(); @@ -16,7 +16,7 @@ var server = http.createServer(function(req, res) { server.close(); }).listen(0, function() { - var socket = net.connect(this.address().port, function() { + const socket = net.connect(this.address().port, function() { socket.write('PUT / HTTP/1.1\r\n\r\n'); socket.once('data', function() { diff --git a/test/parallel/test-http-server.js b/test/parallel/test-http-server.js index 1870bcc7170726..90c2709ebdbc5c 100644 --- a/test/parallel/test-http-server.js +++ b/test/parallel/test-http-server.js @@ -1,17 +1,17 @@ 'use strict'; require('../common'); -var assert = require('assert'); -var net = require('net'); -var http = require('http'); -var url = require('url'); -var qs = require('querystring'); - -var request_number = 0; -var requests_sent = 0; -var server_response = ''; -var client_got_eof = false; - -var server = http.createServer(function(req, res) { +const assert = require('assert'); +const net = require('net'); +const http = require('http'); +const url = require('url'); +const qs = require('querystring'); + +let request_number = 0; +let requests_sent = 0; +let server_response = ''; +let client_got_eof = false; + +const server = http.createServer(function(req, res) { res.id = request_number; req.id = request_number++; @@ -48,7 +48,7 @@ server.listen(0); server.httpAllowHalfOpen = true; server.on('listening', function() { - var c = net.createConnection(this.address().port); + const c = net.createConnection(this.address().port); c.setEncoding('utf8'); @@ -94,10 +94,10 @@ process.on('exit', function() { assert.strictEqual(4, request_number); assert.strictEqual(4, requests_sent); - var hello = new RegExp('/hello'); + const hello = new RegExp('/hello'); assert.notStrictEqual(null, hello.exec(server_response)); - var quit = new RegExp('/quit'); + const quit = new RegExp('/quit'); assert.notStrictEqual(null, quit.exec(server_response)); assert.strictEqual(true, client_got_eof); diff --git a/test/parallel/test-http-set-cookies.js b/test/parallel/test-http-set-cookies.js index 1f00ebb65e34de..cb06352b3ca85d 100644 --- a/test/parallel/test-http-set-cookies.js +++ b/test/parallel/test-http-set-cookies.js @@ -1,11 +1,11 @@ 'use strict'; require('../common'); -var assert = require('assert'); -var http = require('http'); +const assert = require('assert'); +const http = require('http'); -var nresponses = 0; +let nresponses = 0; -var server = http.createServer(function(req, res) { +const server = http.createServer(function(req, res) { if (req.url === '/one') { res.writeHead(200, [['set-cookie', 'A'], ['content-type', 'text/plain']]); diff --git a/test/parallel/test-http-set-timeout-server.js b/test/parallel/test-http-set-timeout-server.js index d530503aa1e9aa..7a2447763e4cf9 100644 --- a/test/parallel/test-http-set-timeout-server.js +++ b/test/parallel/test-http-set-timeout-server.js @@ -1,10 +1,10 @@ 'use strict'; -var common = require('../common'); -var assert = require('assert'); -var http = require('http'); -var net = require('net'); +const common = require('../common'); +const assert = require('assert'); +const http = require('http'); +const net = require('net'); -var tests = []; +const tests = []; function test(fn) { if (!tests.length) @@ -13,7 +13,7 @@ function test(fn) { } function run() { - var fn = tests.shift(); + const fn = tests.shift(); if (fn) { console.log('# %s', fn.name); fn(run); @@ -23,17 +23,17 @@ function run() { } test(function serverTimeout(cb) { - var caughtTimeout = false; + let caughtTimeout = false; process.on('exit', function() { assert(caughtTimeout); }); - var server = http.createServer(function(req, res) { + const server = http.createServer(function(req, res) { // just do nothing, we should get a timeout event. }); server.listen(common.mustCall(function() { http.get({ port: server.address().port }).on('error', function() {}); })); - var s = server.setTimeout(50, function(socket) { + const s = server.setTimeout(50, function(socket) { caughtTimeout = true; socket.destroy(); server.close(); @@ -43,13 +43,13 @@ test(function serverTimeout(cb) { }); test(function serverRequestTimeout(cb) { - var caughtTimeout = false; + let caughtTimeout = false; process.on('exit', function() { assert(caughtTimeout); }); - var server = http.createServer(function(req, res) { + const server = http.createServer(function(req, res) { // just do nothing, we should get a timeout event. - var s = req.setTimeout(50, function() { + const s = req.setTimeout(50, function() { caughtTimeout = true; req.socket.destroy(); server.close(); @@ -58,8 +58,8 @@ test(function serverRequestTimeout(cb) { assert.ok(s instanceof http.IncomingMessage); }); server.listen(common.mustCall(function() { - var port = server.address().port; - var req = http.request({ port: port, method: 'POST' }); + const port = server.address().port; + const req = http.request({ port: port, method: 'POST' }); req.on('error', function() {}); req.write('Hello'); // req is in progress @@ -67,13 +67,13 @@ test(function serverRequestTimeout(cb) { }); test(function serverResponseTimeout(cb) { - var caughtTimeout = false; + let caughtTimeout = false; process.on('exit', function() { assert(caughtTimeout); }); - var server = http.createServer(function(req, res) { + const server = http.createServer(function(req, res) { // just do nothing, we should get a timeout event. - var s = res.setTimeout(50, function() { + const s = res.setTimeout(50, function() { caughtTimeout = true; res.socket.destroy(); server.close(); @@ -82,21 +82,21 @@ test(function serverResponseTimeout(cb) { assert.ok(s instanceof http.OutgoingMessage); }); server.listen(common.mustCall(function() { - var port = server.address().port; + const port = server.address().port; http.get({ port: port }).on('error', function() {}); })); }); test(function serverRequestNotTimeoutAfterEnd(cb) { - var caughtTimeoutOnRequest = false; - var caughtTimeoutOnResponse = false; + let caughtTimeoutOnRequest = false; + let caughtTimeoutOnResponse = false; process.on('exit', function() { assert(!caughtTimeoutOnRequest); assert(caughtTimeoutOnResponse); }); - var server = http.createServer(function(req, res) { + const server = http.createServer(function(req, res) { // just do nothing, we should get a timeout event. - var s = req.setTimeout(50, function(socket) { + const s = req.setTimeout(50, function(socket) { caughtTimeoutOnRequest = true; }); assert.ok(s instanceof http.IncomingMessage); @@ -110,18 +110,18 @@ test(function serverRequestNotTimeoutAfterEnd(cb) { cb(); }); server.listen(common.mustCall(function() { - var port = server.address().port; + const port = server.address().port; http.get({ port: port }).on('error', function() {}); })); }); test(function serverResponseTimeoutWithPipeline(cb) { - var caughtTimeout = ''; + let caughtTimeout = ''; process.on('exit', function() { assert.equal(caughtTimeout, '/2'); }); - var server = http.createServer(function(req, res) { - var s = res.setTimeout(50, function() { + const server = http.createServer(function(req, res) { + const s = res.setTimeout(50, function() { caughtTimeout += req.url; }); assert.ok(s instanceof http.OutgoingMessage); @@ -133,8 +133,8 @@ test(function serverResponseTimeoutWithPipeline(cb) { cb(); }); server.listen(common.mustCall(function() { - var port = server.address().port; - var c = net.connect({ port: port, allowHalfOpen: true }, function() { + const port = server.address().port; + const c = net.connect({ port: port, allowHalfOpen: true }, function() { c.write('GET /1 HTTP/1.1\r\nHost: localhost\r\n\r\n'); c.write('GET /2 HTTP/1.1\r\nHost: localhost\r\n\r\n'); c.write('GET /3 HTTP/1.1\r\nHost: localhost\r\n\r\n'); @@ -143,15 +143,15 @@ test(function serverResponseTimeoutWithPipeline(cb) { }); test(function idleTimeout(cb) { - var caughtTimeoutOnRequest = false; - var caughtTimeoutOnResponse = false; - var caughtTimeoutOnServer = false; + let caughtTimeoutOnRequest = false; + let caughtTimeoutOnResponse = false; + let caughtTimeoutOnServer = false; process.on('exit', function() { assert(!caughtTimeoutOnRequest); assert(!caughtTimeoutOnResponse); assert(caughtTimeoutOnServer); }); - var server = http.createServer(function(req, res) { + const server = http.createServer(function(req, res) { req.on('timeout', function(socket) { caughtTimeoutOnRequest = true; }); @@ -160,7 +160,7 @@ test(function idleTimeout(cb) { }); res.end(); }); - var s = server.setTimeout(50, function(socket) { + const s = server.setTimeout(50, function(socket) { caughtTimeoutOnServer = true; socket.destroy(); server.close(); @@ -168,8 +168,8 @@ test(function idleTimeout(cb) { }); assert.ok(s instanceof http.Server); server.listen(common.mustCall(function() { - var port = server.address().port; - var c = net.connect({ port: port, allowHalfOpen: true }, function() { + const port = server.address().port; + const c = net.connect({ port: port, allowHalfOpen: true }, function() { c.write('GET /1 HTTP/1.1\r\nHost: localhost\r\n\r\n'); // Keep-Alive }); diff --git a/test/parallel/test-http-set-timeout.js b/test/parallel/test-http-set-timeout.js index e8df29e0ccdc67..965b3486faee95 100644 --- a/test/parallel/test-http-set-timeout.js +++ b/test/parallel/test-http-set-timeout.js @@ -4,9 +4,9 @@ const assert = require('assert'); const http = require('http'); const net = require('net'); -var server = http.createServer(function(req, res) { +const server = http.createServer(function(req, res) { console.log('got request. setting 500ms timeout'); - var socket = req.connection.setTimeout(500); + const socket = req.connection.setTimeout(500); assert.ok(socket instanceof net.Socket); req.connection.on('timeout', common.mustCall(function() { req.connection.destroy(); @@ -18,7 +18,7 @@ var server = http.createServer(function(req, res) { server.listen(0, function() { console.log(`Server running at http://127.0.0.1:${this.address().port}/`); - var request = http.get({port: this.address().port, path: '/'}); + const request = http.get({port: this.address().port, path: '/'}); request.on('error', common.mustCall(function() { console.log('HTTP REQUEST COMPLETE (this is good)'); })); diff --git a/test/parallel/test-http-set-trailers.js b/test/parallel/test-http-set-trailers.js index b3f331c6d8b172..7b66933ecd12cd 100644 --- a/test/parallel/test-http-set-trailers.js +++ b/test/parallel/test-http-set-trailers.js @@ -1,12 +1,12 @@ 'use strict'; -var common = require('../common'); -var assert = require('assert'); -var http = require('http'); -var net = require('net'); +const common = require('../common'); +const assert = require('assert'); +const http = require('http'); +const net = require('net'); -var outstanding_reqs = 0; +let outstanding_reqs = 0; -var server = http.createServer(function(req, res) { +const server = http.createServer(function(req, res) { res.writeHead(200, [['content-type', 'text/plain']]); res.addTrailers({'x-foo': 'bar'}); res.end('stuff' + '\n'); @@ -16,8 +16,8 @@ server.listen(0); // first, we test an HTTP/1.0 request. server.on('listening', function() { - var c = net.createConnection(this.address().port); - var res_buffer = ''; + const c = net.createConnection(this.address().port); + let res_buffer = ''; c.setEncoding('utf8'); @@ -44,9 +44,9 @@ server.on('listening', function() { // now, we test an HTTP/1.1 request. server.on('listening', function() { - var c = net.createConnection(this.address().port); - var res_buffer = ''; - var tid; + const c = net.createConnection(this.address().port); + let res_buffer = ''; + let tid; c.setEncoding('utf8'); diff --git a/test/parallel/test-http-should-keep-alive.js b/test/parallel/test-http-should-keep-alive.js index 3aaa2d3d73acdc..77a3c3922a20f0 100644 --- a/test/parallel/test-http-should-keep-alive.js +++ b/test/parallel/test-http-should-keep-alive.js @@ -1,10 +1,10 @@ 'use strict'; require('../common'); -var assert = require('assert'); -var http = require('http'); -var net = require('net'); +const assert = require('assert'); +const http = require('http'); +const net = require('net'); -var SERVER_RESPONSES = [ +const SERVER_RESPONSES = [ 'HTTP/1.0 200 ok\r\nContent-Length: 0\r\n\r\n', 'HTTP/1.0 200 ok\r\nContent-Length: 0\r\nConnection: keep-alive\r\n\r\n', 'HTTP/1.0 200 ok\r\nContent-Length: 0\r\nConnection: close\r\n\r\n', @@ -12,7 +12,7 @@ var SERVER_RESPONSES = [ 'HTTP/1.1 200 ok\r\nContent-Length: 0\r\nConnection: keep-alive\r\n\r\n', 'HTTP/1.1 200 ok\r\nContent-Length: 0\r\nConnection: close\r\n\r\n' ]; -var SHOULD_KEEP_ALIVE = [ +const SHOULD_KEEP_ALIVE = [ false, // HTTP/1.0, default true, // HTTP/1.0, Connection: keep-alive false, // HTTP/1.0, Connection: close @@ -20,16 +20,16 @@ var SHOULD_KEEP_ALIVE = [ true, // HTTP/1.1, Connection: keep-alive false // HTTP/1.1, Connection: close ]; -var requests = 0; -var responses = 0; +let requests = 0; +let responses = 0; http.globalAgent.maxSockets = 5; -var server = net.createServer(function(socket) { +const server = net.createServer(function(socket) { socket.write(SERVER_RESPONSES[requests]); ++requests; }).listen(0, function() { function makeRequest() { - var req = http.get({port: server.address().port}, function(res) { + const req = http.get({port: server.address().port}, function(res) { assert.equal(req.shouldKeepAlive, SHOULD_KEEP_ALIVE[responses], SERVER_RESPONSES[responses] + ' should ' + (SHOULD_KEEP_ALIVE[responses] ? '' : 'not ') + diff --git a/test/parallel/test-http-status-code.js b/test/parallel/test-http-status-code.js index c0086a3e3d672f..b5060109bf4985 100644 --- a/test/parallel/test-http-status-code.js +++ b/test/parallel/test-http-status-code.js @@ -1,17 +1,17 @@ 'use strict'; require('../common'); -var assert = require('assert'); -var http = require('http'); +const assert = require('assert'); +const http = require('http'); // Simple test of Node's HTTP ServerResponse.statusCode // ServerResponse.prototype.statusCode -var testsComplete = 0; -var tests = [200, 202, 300, 404, 451, 500]; -var testIdx = 0; +let testsComplete = 0; +const tests = [200, 202, 300, 404, 451, 500]; +let testIdx = 0; -var s = http.createServer(function(req, res) { - var t = tests[testIdx]; +const s = http.createServer(function(req, res) { + const t = tests[testIdx]; res.writeHead(t, {'Content-Type': 'text/plain'}); console.log('--\nserver: statusCode after writeHead: ' + res.statusCode); assert.equal(res.statusCode, t); @@ -25,7 +25,7 @@ function nextTest() { if (testIdx + 1 === tests.length) { return s.close(); } - var test = tests[testIdx]; + const test = tests[testIdx]; http.get({ port: s.address().port }, function(response) { console.log('client: expected status: ' + test); diff --git a/test/parallel/test-http-status-message.js b/test/parallel/test-http-status-message.js index 6da4b6e4281171..668b02ee0780b4 100644 --- a/test/parallel/test-http-status-message.js +++ b/test/parallel/test-http-status-message.js @@ -1,10 +1,10 @@ 'use strict'; require('../common'); -var assert = require('assert'); -var http = require('http'); -var net = require('net'); +const assert = require('assert'); +const http = require('http'); +const net = require('net'); -var s = http.createServer(function(req, res) { +const s = http.createServer(function(req, res) { res.statusCode = 200; res.statusMessage = 'Custom Message'; res.end(''); @@ -14,15 +14,15 @@ s.listen(0, test); function test() { - var bufs = []; - var client = net.connect(this.address().port, function() { + const bufs = []; + const client = net.connect(this.address().port, function() { client.write('GET / HTTP/1.1\r\nConnection: close\r\n\r\n'); }); client.on('data', function(chunk) { bufs.push(chunk); }); client.on('end', function() { - var head = Buffer.concat(bufs).toString('latin1').split('\r\n')[0]; + const head = Buffer.concat(bufs).toString('latin1').split('\r\n')[0]; assert.equal('HTTP/1.1 200 Custom Message', head); console.log('ok'); s.close(); diff --git a/test/parallel/test-http-timeout-overflow.js b/test/parallel/test-http-timeout-overflow.js index 49cf3ec0278fca..39b4550d57e529 100644 --- a/test/parallel/test-http-timeout-overflow.js +++ b/test/parallel/test-http-timeout-overflow.js @@ -1,13 +1,13 @@ 'use strict'; require('../common'); -var assert = require('assert'); +const assert = require('assert'); -var http = require('http'); +const http = require('http'); -var serverRequests = 0; -var clientRequests = 0; +let serverRequests = 0; +let clientRequests = 0; -var server = http.createServer(function(req, res) { +const server = http.createServer(function(req, res) { serverRequests++; res.writeHead(200, {'Content-Type': 'text/plain'}); res.end('OK'); @@ -16,7 +16,7 @@ var server = http.createServer(function(req, res) { server.listen(0, function() { function callback() {} - var req = http.request({ + const req = http.request({ port: this.address().port, path: '/', agent: false diff --git a/test/parallel/test-http-timeout.js b/test/parallel/test-http-timeout.js index b8a28fc2c4cf32..63f87ed63089ee 100644 --- a/test/parallel/test-http-timeout.js +++ b/test/parallel/test-http-timeout.js @@ -1,24 +1,24 @@ 'use strict'; require('../common'); -var http = require('http'); +const http = require('http'); -var server = http.createServer(function(req, res) { +const server = http.createServer(function(req, res) { res.writeHead(200, {'Content-Type': 'text/plain'}); res.end('OK'); }); -var agent = new http.Agent({maxSockets: 1}); +const agent = new http.Agent({maxSockets: 1}); server.listen(0, function() { - for (var i = 0; i < 11; ++i) { + for (let i = 0; i < 11; ++i) { createRequest().end(); } function callback() {} - var count = 0; + let count = 0; function createRequest() { const req = http.request( diff --git a/test/parallel/test-http-unix-socket.js b/test/parallel/test-http-unix-socket.js index d2b99bde95a234..f9308d86325cd1 100644 --- a/test/parallel/test-http-unix-socket.js +++ b/test/parallel/test-http-unix-socket.js @@ -17,12 +17,12 @@ common.refreshTmpDir(); server.listen(common.PIPE, common.mustCall(function() { - var options = { + const options = { socketPath: common.PIPE, path: '/' }; - var req = http.get(options, common.mustCall(function(res) { + const req = http.get(options, common.mustCall(function(res) { assert.strictEqual(res.statusCode, 200); assert.strictEqual(res.headers['content-type'], 'text/plain'); diff --git a/test/parallel/test-http-upgrade-agent.js b/test/parallel/test-http-upgrade-agent.js index 48eaa16f898021..a196ba904905a3 100644 --- a/test/parallel/test-http-upgrade-agent.js +++ b/test/parallel/test-http-upgrade-agent.js @@ -3,14 +3,14 @@ // the HTTP client. This test uses a raw TCP server to better control server // behavior. -var common = require('../common'); -var assert = require('assert'); +const common = require('../common'); +const assert = require('assert'); -var http = require('http'); -var net = require('net'); +const http = require('http'); +const net = require('net'); // Create a TCP server -var srv = net.createServer(function(c) { +const srv = net.createServer(function(c) { c.on('data', function(d) { c.write('HTTP/1.1 101\r\n'); c.write('hello: world\r\n'); @@ -27,7 +27,7 @@ var srv = net.createServer(function(c) { srv.listen(0, '127.0.0.1', common.mustCall(function() { - var options = { + const options = { port: this.address().port, host: '127.0.0.1', headers: { @@ -35,13 +35,13 @@ srv.listen(0, '127.0.0.1', common.mustCall(function() { 'upgrade': 'websocket' } }; - var name = options.host + ':' + options.port; + const name = options.host + ':' + options.port; - var req = http.request(options); + const req = http.request(options); req.end(); req.on('upgrade', common.mustCall(function(res, socket, upgradeHead) { - var recvData = upgradeHead; + let recvData = upgradeHead; socket.on('data', function(d) { recvData += d; }); @@ -51,9 +51,9 @@ srv.listen(0, '127.0.0.1', common.mustCall(function() { })); console.log(res.headers); - var expectedHeaders = { 'hello': 'world', - 'connection': 'upgrade', - 'upgrade': 'websocket' }; + const expectedHeaders = { 'hello': 'world', + 'connection': 'upgrade', + 'upgrade': 'websocket' }; assert.deepStrictEqual(expectedHeaders, res.headers); // Make sure this request got removed from the pool. diff --git a/test/parallel/test-http-upgrade-client.js b/test/parallel/test-http-upgrade-client.js index 51c70122b99d87..34e3e8f24158e7 100644 --- a/test/parallel/test-http-upgrade-client.js +++ b/test/parallel/test-http-upgrade-client.js @@ -3,14 +3,14 @@ // the HTTP client. This test uses a raw TCP server to better control server // behavior. -var common = require('../common'); -var assert = require('assert'); +const common = require('../common'); +const assert = require('assert'); -var http = require('http'); -var net = require('net'); +const http = require('http'); +const net = require('net'); // Create a TCP server -var srv = net.createServer(function(c) { +const srv = net.createServer(function(c) { c.on('data', function(d) { c.write('HTTP/1.1 101\r\n'); c.write('hello: world\r\n'); @@ -39,16 +39,16 @@ srv.listen(0, '127.0.0.1', common.mustCall(function() { ['Origin', 'http://www.websocket.org'] ] ]; - var left = headers.length; + let left = headers.length; headers.forEach(function(h) { - var req = http.get({ + const req = http.get({ port: port, headers: h }); - var sawUpgrade = false; + let sawUpgrade = false; req.on('upgrade', common.mustCall(function(res, socket, upgradeHead) { sawUpgrade = true; - var recvData = upgradeHead; + let recvData = upgradeHead; socket.on('data', function(d) { recvData += d; }); diff --git a/test/parallel/test-http-upgrade-client2.js b/test/parallel/test-http-upgrade-client2.js index 0c229a354add48..fa14f8ca51f030 100644 --- a/test/parallel/test-http-upgrade-client2.js +++ b/test/parallel/test-http-upgrade-client2.js @@ -1,10 +1,10 @@ 'use strict'; const common = require('../common'); -var http = require('http'); +const http = require('http'); -var CRLF = '\r\n'; +const CRLF = '\r\n'; -var server = http.createServer(); +const server = http.createServer(); server.on('upgrade', function(req, socket, head) { socket.write('HTTP/1.1 101 Ok' + CRLF + 'Connection: Upgrade' + CRLF + @@ -18,12 +18,12 @@ server.listen(0, common.mustCall(function() { function upgradeRequest(fn) { console.log('req'); - var header = { 'Connection': 'Upgrade', 'Upgrade': 'Test' }; - var request = http.request({ + const header = { 'Connection': 'Upgrade', 'Upgrade': 'Test' }; + const request = http.request({ port: server.address().port, headers: header }); - var wasUpgrade = false; + let wasUpgrade = false; function onUpgrade(res, socket, head) { console.log('client upgraded'); diff --git a/test/parallel/test-http-upgrade-server.js b/test/parallel/test-http-upgrade-server.js index 8570dec899b672..6c5a62c2ffcc33 100644 --- a/test/parallel/test-http-upgrade-server.js +++ b/test/parallel/test-http-upgrade-server.js @@ -1,15 +1,15 @@ 'use strict'; require('../common'); -var assert = require('assert'); +const assert = require('assert'); -var util = require('util'); -var net = require('net'); -var http = require('http'); +const util = require('util'); +const net = require('net'); +const http = require('http'); -var requests_recv = 0; -var requests_sent = 0; -var request_upgradeHead = null; +let requests_recv = 0; +let requests_sent = 0; +let request_upgradeHead = null; function createTestServer() { return new testServer(); @@ -37,7 +37,7 @@ function testServer() { request_upgradeHead = upgradeHead; socket.on('data', function(d) { - var data = d.toString('utf8'); + const data = d.toString('utf8'); if (data === 'kill') { socket.end(); } else { @@ -60,9 +60,9 @@ function writeReq(socket, data, encoding) { connection: Upgrade with listener -----------------------------------------------*/ function test_upgrade_with_listener() { - var conn = net.createConnection(server.address().port); + const conn = net.createConnection(server.address().port); conn.setEncoding('utf8'); - var state = 0; + let state = 0; conn.on('connect', function() { writeReq(conn, @@ -99,10 +99,10 @@ function test_upgrade_with_listener() { /*----------------------------------------------- connection: Upgrade, no listener -----------------------------------------------*/ -var test_upgrade_no_listener_ended = false; +let test_upgrade_no_listener_ended = false; function test_upgrade_no_listener() { - var conn = net.createConnection(server.address().port); + const conn = net.createConnection(server.address().port); conn.setEncoding('utf8'); conn.on('connect', function() { @@ -127,7 +127,7 @@ function test_upgrade_no_listener() { connection: normal -----------------------------------------------*/ function test_standard_http() { - var conn = net.createConnection(server.address().port); + const conn = net.createConnection(server.address().port); conn.setEncoding('utf8'); conn.on('connect', function() { @@ -146,7 +146,7 @@ function test_standard_http() { } -var server = createTestServer(); +let server = createTestServer(); server.listen(0, function() { // All tests get chained after this: diff --git a/test/parallel/test-http-upgrade-server2.js b/test/parallel/test-http-upgrade-server2.js index 1644f54977af85..c64b2e843637af 100644 --- a/test/parallel/test-http-upgrade-server2.js +++ b/test/parallel/test-http-upgrade-server2.js @@ -1,10 +1,10 @@ 'use strict'; const common = require('../common'); -var assert = require('assert'); -var http = require('http'); -var net = require('net'); +const assert = require('assert'); +const http = require('http'); +const net = require('net'); -var server = http.createServer(function(req, res) { +const server = http.createServer(function(req, res) { throw new Error('This shouldn\'t happen.'); }); @@ -21,7 +21,7 @@ process.on('uncaughtException', common.mustCall(function(e) { server.listen(0, function() { - var c = net.createConnection(this.address().port); + const c = net.createConnection(this.address().port); c.on('connect', function() { c.write('GET /blah HTTP/1.1\r\n' + diff --git a/test/parallel/test-http-url.parse-auth-with-header-in-request.js b/test/parallel/test-http-url.parse-auth-with-header-in-request.js index fa930bd5ec2e34..cdf3f7a5aea8af 100644 --- a/test/parallel/test-http-url.parse-auth-with-header-in-request.js +++ b/test/parallel/test-http-url.parse-auth-with-header-in-request.js @@ -1,15 +1,15 @@ 'use strict'; require('../common'); -var assert = require('assert'); -var http = require('http'); -var url = require('url'); +const assert = require('assert'); +const http = require('http'); +const url = require('url'); function check(request) { // the correct authorization header is be passed assert.strictEqual(request.headers.authorization, 'NoAuthForYOU'); } -var server = http.createServer(function(request, response) { +const server = http.createServer(function(request, response) { // run the check function check.call(this, request, response); response.writeHead(200, {}); @@ -18,7 +18,8 @@ var server = http.createServer(function(request, response) { }); server.listen(0, function() { - var testURL = url.parse(`http://asdf:qwer@localhost:${this.address().port}`); + const testURL = + url.parse(`http://asdf:qwer@localhost:${this.address().port}`); // the test here is if you set a specific authorization header in the // request we should not override that with basic auth testURL.headers = { diff --git a/test/parallel/test-http-url.parse-auth.js b/test/parallel/test-http-url.parse-auth.js index 0e901ebb599b00..25913f4e49a12a 100644 --- a/test/parallel/test-http-url.parse-auth.js +++ b/test/parallel/test-http-url.parse-auth.js @@ -1,15 +1,15 @@ 'use strict'; require('../common'); -var assert = require('assert'); -var http = require('http'); -var url = require('url'); +const assert = require('assert'); +const http = require('http'); +const url = require('url'); function check(request) { // the correct authorization header is be passed assert.strictEqual(request.headers.authorization, 'Basic dXNlcjpwYXNzOg=='); } -var server = http.createServer(function(request, response) { +const server = http.createServer(function(request, response) { // run the check function check.call(this, request, response); response.writeHead(200, {}); @@ -20,7 +20,7 @@ var server = http.createServer(function(request, response) { server.listen(0, function() { const port = this.address().port; // username = "user", password = "pass:" - var testURL = url.parse(`http://user:pass%3A@localhost:${port}`); + const testURL = url.parse(`http://user:pass%3A@localhost:${port}`); // make the request http.request(testURL).end(); diff --git a/test/parallel/test-http-url.parse-basic.js b/test/parallel/test-http-url.parse-basic.js index b0d1274b594d7e..ac22b6e38d80e1 100644 --- a/test/parallel/test-http-url.parse-basic.js +++ b/test/parallel/test-http-url.parse-basic.js @@ -1,10 +1,10 @@ 'use strict'; require('../common'); -var assert = require('assert'); -var http = require('http'); -var url = require('url'); +const assert = require('assert'); +const http = require('http'); +const url = require('url'); -var testURL; +let testURL; // make sure the basics work function check(request) { @@ -17,7 +17,7 @@ function check(request) { testURL.hostname + ':' + testURL.port); } -var server = http.createServer(function(request, response) { +const server = http.createServer(function(request, response) { // run the check function check.call(this, request, response); response.writeHead(200, {}); @@ -29,7 +29,7 @@ server.listen(0, function() { testURL = url.parse(`http://localhost:${this.address().port}`); // make the request - var clientRequest = http.request(testURL); + const clientRequest = http.request(testURL); // since there is a little magic with the agent // make sure that an http request uses the http.Agent assert.ok(clientRequest.agent instanceof http.Agent); diff --git a/test/parallel/test-http-url.parse-https.request.js b/test/parallel/test-http-url.parse-https.request.js index edd83a2d1306f5..ad40e76debee90 100644 --- a/test/parallel/test-http-url.parse-https.request.js +++ b/test/parallel/test-http-url.parse-https.request.js @@ -1,18 +1,18 @@ 'use strict'; -var common = require('../common'); -var assert = require('assert'); +const common = require('../common'); +const assert = require('assert'); if (!common.hasCrypto) { common.skip('missing crypto'); return; } -var https = require('https'); +const https = require('https'); -var url = require('url'); -var fs = require('fs'); +const url = require('url'); +const fs = require('fs'); // https options -var httpsOptions = { +const httpsOptions = { key: fs.readFileSync(common.fixturesDir + '/keys/agent1-key.pem'), cert: fs.readFileSync(common.fixturesDir + '/keys/agent1-cert.pem') }; @@ -22,7 +22,7 @@ function check(request) { assert.ok(request.socket._secureEstablished); } -var server = https.createServer(httpsOptions, function(request, response) { +const server = https.createServer(httpsOptions, function(request, response) { // run the check function check.call(this, request, response); response.writeHead(200, {}); @@ -31,11 +31,11 @@ var server = https.createServer(httpsOptions, function(request, response) { }); server.listen(0, function() { - var testURL = url.parse(`https://localhost:${this.address().port}`); + const testURL = url.parse(`https://localhost:${this.address().port}`); testURL.rejectUnauthorized = false; // make the request - var clientRequest = https.request(testURL); + const clientRequest = https.request(testURL); // since there is a little magic with the agent // make sure that the request uses the https.Agent assert.ok(clientRequest.agent instanceof https.Agent); diff --git a/test/parallel/test-http-url.parse-only-support-http-https-protocol.js b/test/parallel/test-http-url.parse-only-support-http-https-protocol.js index e7ed82817146ea..b3d7795e72cefa 100644 --- a/test/parallel/test-http-url.parse-only-support-http-https-protocol.js +++ b/test/parallel/test-http-url.parse-only-support-http-https-protocol.js @@ -1,8 +1,8 @@ 'use strict'; require('../common'); -var assert = require('assert'); -var http = require('http'); -var url = require('url'); +const assert = require('assert'); +const http = require('http'); +const url = require('url'); assert.throws(function() { diff --git a/test/parallel/test-http-url.parse-path.js b/test/parallel/test-http-url.parse-path.js index 73de297d45fca5..6fab8bb0eb3b6b 100644 --- a/test/parallel/test-http-url.parse-path.js +++ b/test/parallel/test-http-url.parse-path.js @@ -1,15 +1,15 @@ 'use strict'; require('../common'); -var assert = require('assert'); -var http = require('http'); -var url = require('url'); +const assert = require('assert'); +const http = require('http'); +const url = require('url'); function check(request) { // a path should come over assert.strictEqual(request.url, '/asdf'); } -var server = http.createServer(function(request, response) { +const server = http.createServer(function(request, response) { // run the check function check.call(this, request, response); response.writeHead(200, {}); @@ -18,7 +18,7 @@ var server = http.createServer(function(request, response) { }); server.listen(0, function() { - var testURL = url.parse(`http://localhost:${this.address().port}/asdf`); + const testURL = url.parse(`http://localhost:${this.address().port}/asdf`); // make the request http.request(testURL).end(); diff --git a/test/parallel/test-http-url.parse-post.js b/test/parallel/test-http-url.parse-post.js index 0af482c94a875d..d63f404c5403dd 100644 --- a/test/parallel/test-http-url.parse-post.js +++ b/test/parallel/test-http-url.parse-post.js @@ -1,10 +1,10 @@ 'use strict'; require('../common'); -var assert = require('assert'); -var http = require('http'); -var url = require('url'); +const assert = require('assert'); +const http = require('http'); +const url = require('url'); -var testURL; +let testURL; function check(request) { //url.parse should not mess with the method @@ -16,7 +16,7 @@ function check(request) { testURL.hostname + ':' + testURL.port); } -var server = http.createServer(function(request, response) { +const server = http.createServer(function(request, response) { // run the check function check.call(this, request, response); response.writeHead(200, {}); diff --git a/test/parallel/test-http-url.parse-search.js b/test/parallel/test-http-url.parse-search.js index 9a1e7565572fcc..f2a5d1806d89a2 100644 --- a/test/parallel/test-http-url.parse-search.js +++ b/test/parallel/test-http-url.parse-search.js @@ -1,15 +1,15 @@ 'use strict'; require('../common'); -var assert = require('assert'); -var http = require('http'); -var url = require('url'); +const assert = require('assert'); +const http = require('http'); +const url = require('url'); function check(request) { // a path should come over with params assert.strictEqual(request.url, '/asdf?qwer=zxcv'); } -var server = http.createServer(function(request, response) { +const server = http.createServer(function(request, response) { // run the check function check.call(this, request, response); response.writeHead(200, {}); @@ -19,7 +19,7 @@ var server = http.createServer(function(request, response) { server.listen(0, function() { const port = this.address().port; - var testURL = url.parse(`http://localhost:${port}/asdf?qwer=zxcv`); + const testURL = url.parse(`http://localhost:${port}/asdf?qwer=zxcv`); // make the request http.request(testURL).end(); diff --git a/test/parallel/test-http-wget.js b/test/parallel/test-http-wget.js index f7fb1a3656c623..a633873c8bb16f 100644 --- a/test/parallel/test-http-wget.js +++ b/test/parallel/test-http-wget.js @@ -1,8 +1,8 @@ 'use strict'; const common = require('../common'); -var assert = require('assert'); -var net = require('net'); -var http = require('http'); +const assert = require('assert'); +const net = require('net'); +const http = require('http'); // wget sends an HTTP/1.0 request with Connection: Keep-Alive // @@ -19,7 +19,7 @@ var http = require('http'); // content-length is not provided, that the connection is in fact // closed. -var server = http.createServer(function(req, res) { +const server = http.createServer(function(req, res) { res.writeHead(200, {'Content-Type': 'text/plain'}); res.write('hello '); res.write('world\n'); @@ -28,8 +28,8 @@ var server = http.createServer(function(req, res) { server.listen(0); server.on('listening', common.mustCall(function() { - var c = net.createConnection(this.address().port); - var server_response = ''; + const c = net.createConnection(this.address().port); + let server_response = ''; c.setEncoding('utf8'); diff --git a/test/parallel/test-http-write-callbacks.js b/test/parallel/test-http-write-callbacks.js index b89cdf89af7b90..3783dc305e39a7 100644 --- a/test/parallel/test-http-write-callbacks.js +++ b/test/parallel/test-http-write-callbacks.js @@ -1,16 +1,16 @@ 'use strict'; require('../common'); -var assert = require('assert'); +const assert = require('assert'); -var http = require('http'); +const http = require('http'); -var serverEndCb = false; -var serverIncoming = ''; -var serverIncomingExpect = 'bazquuxblerg'; +let serverEndCb = false; +let serverIncoming = ''; +const serverIncomingExpect = 'bazquuxblerg'; -var clientEndCb = false; -var clientIncoming = ''; -var clientIncomingExpect = 'asdffoobar'; +let clientEndCb = false; +let clientIncoming = ''; +const clientIncomingExpect = 'asdffoobar'; process.on('exit', function() { assert(serverEndCb); @@ -21,7 +21,7 @@ process.on('exit', function() { }); // Verify that we get a callback when we do res.write(..., cb) -var server = http.createServer(function(req, res) { +const server = http.createServer(function(req, res) { res.statusCode = 400; res.end('Bad Request.\nMust send Expect:100-continue\n'); }); @@ -51,7 +51,7 @@ server.on('checkContinue', function(req, res) { }); server.listen(0, function() { - var req = http.request({ + const req = http.request({ port: this.address().port, method: 'PUT', headers: { 'expect': '100-continue' } diff --git a/test/parallel/test-http-write-empty-string.js b/test/parallel/test-http-write-empty-string.js index 534a55823accee..69463fb3a50852 100644 --- a/test/parallel/test-http-write-empty-string.js +++ b/test/parallel/test-http-write-empty-string.js @@ -1,10 +1,10 @@ 'use strict'; const common = require('../common'); -var assert = require('assert'); +const assert = require('assert'); -var http = require('http'); +const http = require('http'); -var server = http.createServer(function(request, response) { +const server = http.createServer(function(request, response) { console.log('responding to ' + request.url); response.writeHead(200, {'Content-Type': 'text/plain'}); @@ -19,7 +19,7 @@ var server = http.createServer(function(request, response) { server.listen(0, common.mustCall(function() { http.get({ port: this.address().port }, common.mustCall(function(res) { - var response = ''; + let response = ''; assert.equal(200, res.statusCode); res.setEncoding('ascii'); diff --git a/test/parallel/test-http-write-head.js b/test/parallel/test-http-write-head.js index bdb5d906a0096f..8ebc2695c82178 100644 --- a/test/parallel/test-http-write-head.js +++ b/test/parallel/test-http-write-head.js @@ -10,7 +10,7 @@ const s = http.createServer(common.mustCall((req, res) => { res.setHeader('test', '1'); // toLowerCase() is used on the name argument, so it must be a string. - var threw = false; + let threw = false; try { res.setHeader(0xf00, 'bar'); } catch (e) { diff --git a/test/parallel/test-http-zero-length-write.js b/test/parallel/test-http-zero-length-write.js index b928aaeb341a88..63446e460471e4 100644 --- a/test/parallel/test-http-zero-length-write.js +++ b/test/parallel/test-http-zero-length-write.js @@ -1,18 +1,18 @@ 'use strict'; require('../common'); -var assert = require('assert'); +const assert = require('assert'); -var http = require('http'); +const http = require('http'); -var Stream = require('stream'); +const Stream = require('stream'); function getSrc() { // An old-style readable stream. // The Readable class prevents this behavior. - var src = new Stream(); + const src = new Stream(); // start out paused, just so we don't miss anything yet. - var paused = false; + let paused = false; src.pause = function() { paused = true; }; @@ -20,12 +20,12 @@ function getSrc() { paused = false; }; - var chunks = [ '', 'asdf', '', 'foo', '', 'bar', '' ]; - var interval = setInterval(function() { + const chunks = [ '', 'asdf', '', 'foo', '', 'bar', '' ]; + const interval = setInterval(function() { if (paused) return; - var chunk = chunks.shift(); + const chunk = chunks.shift(); if (chunk !== undefined) { src.emit('data', chunk); } else { @@ -38,10 +38,10 @@ function getSrc() { } -var expect = 'asdffoobar'; +const expect = 'asdffoobar'; -var server = http.createServer(function(req, res) { - var actual = ''; +const server = http.createServer(function(req, res) { + let actual = ''; req.setEncoding('utf8'); req.on('data', function(c) { actual += c; @@ -54,8 +54,8 @@ var server = http.createServer(function(req, res) { }); server.listen(0, function() { - var req = http.request({ port: this.address().port, method: 'POST' }); - var actual = ''; + const req = http.request({ port: this.address().port, method: 'POST' }); + let actual = ''; req.on('response', function(res) { res.setEncoding('utf8'); res.on('data', function(c) { diff --git a/test/parallel/test-http.js b/test/parallel/test-http.js index f755bca8bc74ec..a80a2b8856558b 100644 --- a/test/parallel/test-http.js +++ b/test/parallel/test-http.js @@ -4,10 +4,10 @@ const assert = require('assert'); const http = require('http'); const url = require('url'); -var responses_sent = 0; -var responses_recvd = 0; -var body0 = ''; -var body1 = ''; +let responses_sent = 0; +let responses_recvd = 0; +let body0 = ''; +let body1 = ''; const server = http.Server(function(req, res) { if (responses_sent === 0) { diff --git a/test/parallel/test-https-agent-disable-session-reuse.js b/test/parallel/test-https-agent-disable-session-reuse.js index dc9878d4a1c1ed..72f6d068822338 100644 --- a/test/parallel/test-https-agent-disable-session-reuse.js +++ b/test/parallel/test-https-agent-disable-session-reuse.js @@ -19,7 +19,7 @@ const options = { }; const clientSessions = []; -var serverRequests = 0; +let serverRequests = 0; const agent = new https.Agent({ maxCachedSessions: 0 @@ -29,7 +29,7 @@ const server = https.createServer(options, function(req, res) { serverRequests++; res.end('ok'); }).listen(0, function() { - var waiting = TOTAL_REQS; + let waiting = TOTAL_REQS; function request() { const options = { agent: agent, diff --git a/test/parallel/test-https-agent-servername.js b/test/parallel/test-https-agent-servername.js index 348cf499b65f56..a321f7140396a3 100644 --- a/test/parallel/test-https-agent-servername.js +++ b/test/parallel/test-https-agent-servername.js @@ -1,22 +1,22 @@ 'use strict'; -var common = require('../common'); +const common = require('../common'); if (!common.hasCrypto) { common.skip('missing crypto'); return; } -var https = require('https'); -var fs = require('fs'); +const https = require('https'); +const fs = require('fs'); -var options = { +const options = { key: fs.readFileSync(common.fixturesDir + '/keys/agent1-key.pem'), cert: fs.readFileSync(common.fixturesDir + '/keys/agent1-cert.pem'), ca: fs.readFileSync(common.fixturesDir + '/keys/ca1-cert.pem') }; -var server = https.Server(options, function(req, res) { +const server = https.Server(options, function(req, res) { res.writeHead(200); res.end('hello world\n'); }); diff --git a/test/parallel/test-https-agent-sni.js b/test/parallel/test-https-agent-sni.js index 4174fd0b9c1fed..ca15dc3db3a88d 100644 --- a/test/parallel/test-https-agent-sni.js +++ b/test/parallel/test-https-agent-sni.js @@ -16,7 +16,7 @@ const options = { }; const TOTAL = 4; -var waiting = TOTAL; +let waiting = TOTAL; const server = https.Server(options, function(req, res) { if (--waiting === 0) server.close(); @@ -35,10 +35,10 @@ server.listen(0, function() { }); } - var agent = new https.Agent({ + const agent = new https.Agent({ maxSockets: 1 }); - for (var j = 0; j < TOTAL; j++) { + for (let j = 0; j < TOTAL; j++) { https.get({ agent: agent, diff --git a/test/parallel/test-https-agent.js b/test/parallel/test-https-agent.js index 221ed2bbd2fe49..392bdcbf033000 100644 --- a/test/parallel/test-https-agent.js +++ b/test/parallel/test-https-agent.js @@ -22,15 +22,15 @@ const server = https.Server(options, function(req, res) { }); -var responses = 0; +let responses = 0; const N = 4; const M = 4; server.listen(0, function() { - for (var i = 0; i < N; i++) { + for (let i = 0; i < N; i++) { setTimeout(function() { - for (var j = 0; j < M; j++) { + for (let j = 0; j < M; j++) { https.get({ path: '/', port: server.address().port, diff --git a/test/parallel/test-https-byteswritten.js b/test/parallel/test-https-byteswritten.js index 58dfb12dbe2eda..cdea4d1ee930f3 100644 --- a/test/parallel/test-https-byteswritten.js +++ b/test/parallel/test-https-byteswritten.js @@ -1,22 +1,22 @@ 'use strict'; -var common = require('../common'); -var assert = require('assert'); -var fs = require('fs'); +const common = require('../common'); +const assert = require('assert'); +const fs = require('fs'); if (!common.hasCrypto) { common.skip('missing crypto'); return; } -var https = require('https'); +const https = require('https'); -var options = { +const options = { key: fs.readFileSync(common.fixturesDir + '/keys/agent1-key.pem'), cert: fs.readFileSync(common.fixturesDir + '/keys/agent1-cert.pem') }; -var body = 'hello world\n'; +const body = 'hello world\n'; -var httpsServer = https.createServer(options, function(req, res) { +const httpsServer = https.createServer(options, function(req, res) { res.on('finish', function() { assert.strictEqual(typeof req.connection.bytesWritten, 'number'); assert(req.connection.bytesWritten > 0); diff --git a/test/parallel/test-https-client-checkServerIdentity.js b/test/parallel/test-https-client-checkServerIdentity.js index 053a5630050748..688c7e22706e0e 100644 --- a/test/parallel/test-https-client-checkServerIdentity.js +++ b/test/parallel/test-https-client-checkServerIdentity.js @@ -1,22 +1,22 @@ 'use strict'; -var common = require('../common'); -var assert = require('assert'); +const common = require('../common'); +const assert = require('assert'); if (!common.hasCrypto) { common.skip('missing crypto'); return; } -var https = require('https'); +const https = require('https'); -var fs = require('fs'); -var path = require('path'); +const fs = require('fs'); +const path = require('path'); -var options = { +const options = { key: fs.readFileSync(path.join(common.fixturesDir, 'keys/agent3-key.pem')), cert: fs.readFileSync(path.join(common.fixturesDir, 'keys/agent3-cert.pem')) }; -var server = https.createServer(options, common.mustCall(function(req, res) { +const server = https.createServer(options, common.mustCall(function(req, res) { res.writeHead(200); res.end(); req.resume(); @@ -25,7 +25,7 @@ var server = https.createServer(options, common.mustCall(function(req, res) { }); function authorized() { - var req = https.request({ + const req = https.request({ port: server.address().port, rejectUnauthorized: true, ca: [fs.readFileSync(path.join(common.fixturesDir, 'keys/ca2-cert.pem'))] @@ -37,7 +37,7 @@ function authorized() { } function override() { - var options = { + const options = { port: server.address().port, rejectUnauthorized: true, ca: [fs.readFileSync(path.join(common.fixturesDir, 'keys/ca2-cert.pem'))], @@ -46,7 +46,7 @@ function override() { } }; options.agent = new https.Agent(options); - var req = https.request(options, function(res) { + const req = https.request(options, function(res) { assert(req.socket.authorized); server.close(); }); diff --git a/test/parallel/test-https-client-get-url.js b/test/parallel/test-https-client-get-url.js index 1a9fdf5f3f808e..e098f32d7c9794 100644 --- a/test/parallel/test-https-client-get-url.js +++ b/test/parallel/test-https-client-get-url.js @@ -3,22 +3,22 @@ const common = require('../common'); // disable strict server certificate validation by the client process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0'; -var assert = require('assert'); +const assert = require('assert'); if (!common.hasCrypto) { common.skip('missing crypto'); return; } -var https = require('https'); +const https = require('https'); -var fs = require('fs'); +const fs = require('fs'); -var options = { +const options = { key: fs.readFileSync(common.fixturesDir + '/keys/agent1-key.pem'), cert: fs.readFileSync(common.fixturesDir + '/keys/agent1-cert.pem') }; -var server = https.createServer(options, common.mustCall(function(req, res) { +const server = https.createServer(options, common.mustCall(function(req, res) { assert.equal('GET', req.method); assert.equal('/foo?bar', req.url); res.writeHead(200, {'Content-Type': 'text/plain'}); diff --git a/test/parallel/test-https-client-reject.js b/test/parallel/test-https-client-reject.js index b1708f24b10b83..92bbabe8b3be90 100644 --- a/test/parallel/test-https-client-reject.js +++ b/test/parallel/test-https-client-reject.js @@ -1,22 +1,22 @@ 'use strict'; -var common = require('../common'); -var assert = require('assert'); +const common = require('../common'); +const assert = require('assert'); if (!common.hasCrypto) { common.skip('missing crypto'); return; } -var https = require('https'); +const https = require('https'); -var fs = require('fs'); -var path = require('path'); +const fs = require('fs'); +const path = require('path'); -var options = { +const options = { key: fs.readFileSync(path.join(common.fixturesDir, 'test_key.pem')), cert: fs.readFileSync(path.join(common.fixturesDir, 'test_cert.pem')) }; -var server = https.createServer(options, common.mustCall(function(req, res) { +const server = https.createServer(options, common.mustCall(function(req, res) { res.writeHead(200); res.end(); req.resume(); @@ -25,7 +25,7 @@ var server = https.createServer(options, common.mustCall(function(req, res) { }); function unauthorized() { - var req = https.request({ + const req = https.request({ port: server.address().port, rejectUnauthorized: false }, function(res) { @@ -40,11 +40,11 @@ function unauthorized() { } function rejectUnauthorized() { - var options = { + const options = { port: server.address().port }; options.agent = new https.Agent(options); - var req = https.request(options, common.fail); + const req = https.request(options, common.fail); req.on('error', function(err) { authorized(); }); @@ -52,12 +52,12 @@ function rejectUnauthorized() { } function authorized() { - var options = { + const options = { port: server.address().port, ca: [fs.readFileSync(path.join(common.fixturesDir, 'test_cert.pem'))] }; options.agent = new https.Agent(options); - var req = https.request(options, function(res) { + const req = https.request(options, function(res) { res.resume(); assert(req.socket.authorized); server.close(); diff --git a/test/parallel/test-https-client-resume.js b/test/parallel/test-https-client-resume.js index 734e8069021f78..79e1a716bd77cf 100644 --- a/test/parallel/test-https-client-resume.js +++ b/test/parallel/test-https-client-resume.js @@ -2,33 +2,33 @@ // Create an ssl server. First connection, validate that not resume. // Cache session and close connection. Use session on second connection. // ASSERT resumption. -var common = require('../common'); -var assert = require('assert'); +const common = require('../common'); +const assert = require('assert'); if (!common.hasCrypto) { common.skip('missing crypto'); return; } -var https = require('https'); +const https = require('https'); -var tls = require('tls'); -var fs = require('fs'); +const tls = require('tls'); +const fs = require('fs'); -var options = { +const options = { key: fs.readFileSync(common.fixturesDir + '/keys/agent2-key.pem'), cert: fs.readFileSync(common.fixturesDir + '/keys/agent2-cert.pem') }; // create server -var server = https.createServer(options, common.mustCall(function(req, res) { +const server = https.createServer(options, common.mustCall(function(req, res) { res.end('Goodbye'); }, 2)); // start listening server.listen(0, function() { - var session1 = null; - var client1 = tls.connect({ + let session1 = null; + const client1 = tls.connect({ port: this.address().port, rejectUnauthorized: false }, function() { @@ -43,13 +43,13 @@ server.listen(0, function() { client1.on('close', function() { console.log('close1'); - var opts = { + const opts = { port: server.address().port, rejectUnauthorized: false, session: session1 }; - var client2 = tls.connect(opts, function() { + const client2 = tls.connect(opts, function() { console.log('connect2'); assert.ok(client2.isSessionReused(), 'Session *should* be reused.'); client2.write('GET / HTTP/1.0\r\n' + diff --git a/test/parallel/test-https-close.js b/test/parallel/test-https-close.js index f77726ceb68bf9..cf950f29d6f8ad 100644 --- a/test/parallel/test-https-close.js +++ b/test/parallel/test-https-close.js @@ -13,17 +13,17 @@ const options = { cert: fs.readFileSync(common.fixturesDir + '/keys/agent1-cert.pem') }; -var connections = {}; +const connections = {}; -var server = https.createServer(options, function(req, res) { - var interval = setInterval(function() { +const server = https.createServer(options, function(req, res) { + const interval = setInterval(function() { res.write('data'); }, 1000); interval.unref(); }); server.on('connection', function(connection) { - var key = connection.remoteAddress + ':' + connection.remotePort; + const key = connection.remoteAddress + ':' + connection.remotePort; connection.on('close', function() { delete connections[key]; }); @@ -33,14 +33,14 @@ server.on('connection', function(connection) { function shutdown() { server.close(common.mustCall(function() {})); - for (var key in connections) { + for (const key in connections) { connections[key].destroy(); delete connections[key]; } } server.listen(0, function() { - var requestOptions = { + const requestOptions = { hostname: '127.0.0.1', port: this.address().port, path: '/', @@ -48,7 +48,7 @@ server.listen(0, function() { rejectUnauthorized: false }; - var req = https.request(requestOptions, function(res) { + const req = https.request(requestOptions, function(res) { res.on('data', function(d) {}); setImmediate(shutdown); }); diff --git a/test/parallel/test-https-connecting-to-http.js b/test/parallel/test-https-connecting-to-http.js index 53158595054714..ae8507f99cbc00 100644 --- a/test/parallel/test-https-connecting-to-http.js +++ b/test/parallel/test-https-connecting-to-http.js @@ -1,19 +1,19 @@ 'use strict'; // This tests the situation where you try to connect a https client // to an http server. You should get an error and exit. -var common = require('../common'); -var http = require('http'); +const common = require('../common'); +const http = require('http'); if (!common.hasCrypto) { common.skip('missing crypto'); return; } -var https = require('https'); +const https = require('https'); -var server = http.createServer(common.fail); +const server = http.createServer(common.fail); server.listen(0, common.mustCall(function() { - var req = https.get({ port: this.address().port }, common.fail); + const req = https.get({ port: this.address().port }, common.fail); req.on('error', common.mustCall(function(e) { console.log('Got expected error: ', e.message); diff --git a/test/parallel/test-https-drain.js b/test/parallel/test-https-drain.js index 7648469b0f54a7..0b18795078fd1f 100644 --- a/test/parallel/test-https-drain.js +++ b/test/parallel/test-https-drain.js @@ -1,38 +1,38 @@ 'use strict'; -var common = require('../common'); -var assert = require('assert'); +const common = require('../common'); +const assert = require('assert'); if (!common.hasCrypto) { common.skip('missing crypto'); return; } -var https = require('https'); +const https = require('https'); -var fs = require('fs'); -var path = require('path'); +const fs = require('fs'); +const path = require('path'); -var options = { +const options = { key: fs.readFileSync(path.join(common.fixturesDir, 'test_key.pem')), cert: fs.readFileSync(path.join(common.fixturesDir, 'test_cert.pem')) }; -var bufSize = 1024 * 1024; -var sent = 0; -var received = 0; +const bufSize = 1024 * 1024; +let sent = 0; +let received = 0; -var server = https.createServer(options, function(req, res) { +const server = https.createServer(options, function(req, res) { res.writeHead(200); req.pipe(res); }); server.listen(0, function() { - var resumed = false; - var req = https.request({ + let resumed = false; + const req = https.request({ method: 'POST', port: this.address().port, rejectUnauthorized: false }, function(res) { - var timer; + let timer; res.pause(); console.error('paused'); send(); diff --git a/test/parallel/test-https-eof-for-eom.js b/test/parallel/test-https-eof-for-eom.js index 1c814714bfef96..d5e896c7695cfd 100644 --- a/test/parallel/test-https-eof-for-eom.js +++ b/test/parallel/test-https-eof-for-eom.js @@ -7,25 +7,25 @@ // This test is to be sure that the https client is handling this case // correctly. -var common = require('../common'); -var assert = require('assert'); +const common = require('../common'); +const assert = require('assert'); if (!common.hasCrypto) { common.skip('missing crypto'); return; } -var https = require('https'); -var tls = require('tls'); +const https = require('https'); +const tls = require('tls'); -var fs = require('fs'); +const fs = require('fs'); -var options = { +const options = { key: fs.readFileSync(common.fixturesDir + '/keys/agent1-key.pem'), cert: fs.readFileSync(common.fixturesDir + '/keys/agent1-cert.pem') }; -var server = tls.Server(options, function(socket) { +const server = tls.Server(options, function(socket) { console.log('2) Server got request'); socket.write('HTTP/1.1 200 OK\r\n' + 'Date: Tue, 15 Feb 2011 22:14:54 GMT\r\n' + @@ -52,7 +52,7 @@ server.listen(0, common.mustCall(function() { port: this.address().port, rejectUnauthorized: false }, common.mustCall(function(res) { - var bodyBuffer = ''; + let bodyBuffer = ''; server.close(); console.log('3) Client got response headers.'); diff --git a/test/parallel/test-https-foafssl.js b/test/parallel/test-https-foafssl.js index 5c9fb613e6fa95..f1b8d442e27893 100644 --- a/test/parallel/test-https-foafssl.js +++ b/test/parallel/test-https-foafssl.js @@ -1,24 +1,24 @@ 'use strict'; -var common = require('../common'); +const common = require('../common'); if (!common.opensslCli) { common.skip('node compiled without OpenSSL CLI.'); return; } -var assert = require('assert'); -var join = require('path').join; +const assert = require('assert'); +const join = require('path').join; -var fs = require('fs'); -var spawn = require('child_process').spawn; +const fs = require('fs'); +const spawn = require('child_process').spawn; if (!common.hasCrypto) { common.skip('missing crypto'); return; } -var https = require('https'); +const https = require('https'); -var options = { +const options = { key: fs.readFileSync(common.fixturesDir + '/agent.key'), cert: fs.readFileSync(common.fixturesDir + '/agent.crt'), requestCert: true @@ -34,11 +34,11 @@ const modulus = 'A6F44A9C25791431214F5C87AF9E040177A8BB89AC803F7E09BBC3A5519F' + 'EBDAF1191F4A4E26D71879C4C7867B62FCD508E8CE66E82D128A71E91580' + '9FCF44E8DE774067F1DE5D70B9C03687'; -var CRLF = '\r\n'; -var body = 'hello world\n'; -var cert; +const CRLF = '\r\n'; +const body = 'hello world\n'; +let cert; -var server = https.createServer(options, common.mustCall(function(req, res) { +const server = https.createServer(options, common.mustCall(function(req, res) { console.log('got request'); cert = req.connection.getPeerCertificate(); @@ -51,21 +51,21 @@ var server = https.createServer(options, common.mustCall(function(req, res) { })); server.listen(0, function() { - var args = ['s_client', - '-quiet', - '-connect', `127.0.0.1:${this.address().port}`, - '-cert', join(common.fixturesDir, 'foafssl.crt'), - '-key', join(common.fixturesDir, 'foafssl.key')]; + const args = ['s_client', + '-quiet', + '-connect', `127.0.0.1:${this.address().port}`, + '-cert', join(common.fixturesDir, 'foafssl.crt'), + '-key', join(common.fixturesDir, 'foafssl.key')]; // for the performance and stability issue in s_client on Windows if (common.isWindows) args.push('-no_rand_screen'); - var client = spawn(common.opensslCli, args); + const client = spawn(common.opensslCli, args); client.stdout.on('data', function(data) { - var message = data.toString(); - var contents = message.split(CRLF + CRLF).pop(); + const message = data.toString(); + const contents = message.split(CRLF + CRLF).pop(); assert.equal(body, contents); server.close(); }); diff --git a/test/parallel/test-https-host-headers.js b/test/parallel/test-https-host-headers.js index e4fd6dfe92ef15..d16afa16006576 100644 --- a/test/parallel/test-https-host-headers.js +++ b/test/parallel/test-https-host-headers.js @@ -1,12 +1,12 @@ 'use strict'; -var common = require('../common'); -var assert = require('assert'); +const common = require('../common'); +const assert = require('assert'); if (!common.hasCrypto) { common.skip('missing crypto'); return; } -var https = require('https'); +const https = require('https'); const fs = require('fs'); const options = { @@ -37,7 +37,7 @@ testHttps(); function testHttps() { - var counter = 0; + let counter = 0; function cb(res) { counter--; diff --git a/test/parallel/test-https-localaddress-bind-error.js b/test/parallel/test-https-localaddress-bind-error.js index 91c3062a6e1896..662d6f080a0fff 100644 --- a/test/parallel/test-https-localaddress-bind-error.js +++ b/test/parallel/test-https-localaddress-bind-error.js @@ -1,21 +1,21 @@ 'use strict'; -var common = require('../common'); -var fs = require('fs'); +const common = require('../common'); +const fs = require('fs'); if (!common.hasCrypto) { common.skip('missing crypto'); return; } -var https = require('https'); +const https = require('https'); -var options = { +const options = { key: fs.readFileSync(common.fixturesDir + '/keys/agent1-key.pem'), cert: fs.readFileSync(common.fixturesDir + '/keys/agent1-cert.pem') }; -var invalidLocalAddress = '1.2.3.4'; +const invalidLocalAddress = '1.2.3.4'; -var server = https.createServer(options, function(req, res) { +const server = https.createServer(options, function(req, res) { console.log('Connect from: ' + req.connection.remoteAddress); req.on('end', function() { diff --git a/test/parallel/test-https-localaddress.js b/test/parallel/test-https-localaddress.js index e6aa0c93a2aaaa..78583b38ecf1cf 100644 --- a/test/parallel/test-https-localaddress.js +++ b/test/parallel/test-https-localaddress.js @@ -7,19 +7,19 @@ if (!common.hasCrypto) { common.skip('missing crypto'); return; } -var https = require('https'); +const https = require('https'); if (!common.hasMultiLocalhost()) { common.skip('platform-specific test.'); return; } -var options = { +const options = { key: fs.readFileSync(common.fixturesDir + '/keys/agent1-key.pem'), cert: fs.readFileSync(common.fixturesDir + '/keys/agent1-cert.pem') }; -var server = https.createServer(options, function(req, res) { +const server = https.createServer(options, function(req, res) { console.log('Connect from: ' + req.connection.remoteAddress); assert.equal('127.0.0.2', req.connection.remoteAddress); @@ -31,7 +31,7 @@ var server = https.createServer(options, function(req, res) { }); server.listen(0, '127.0.0.1', function() { - var options = { + const options = { host: 'localhost', port: this.address().port, path: '/', @@ -40,7 +40,7 @@ server.listen(0, '127.0.0.1', function() { rejectUnauthorized: false }; - var req = https.request(options, function(res) { + const req = https.request(options, function(res) { res.on('end', function() { server.close(); process.exit(); diff --git a/test/parallel/test-https-pfx.js b/test/parallel/test-https-pfx.js index 02715de60da3c8..c30bbc0848d137 100644 --- a/test/parallel/test-https-pfx.js +++ b/test/parallel/test-https-pfx.js @@ -1,17 +1,17 @@ 'use strict'; -var common = require('../common'); -var assert = require('assert'); -var fs = require('fs'); +const common = require('../common'); +const assert = require('assert'); +const fs = require('fs'); if (!common.hasCrypto) { common.skip('missing crypto'); return; } -var https = require('https'); +const https = require('https'); -var pfx = fs.readFileSync(common.fixturesDir + '/test_cert.pfx'); +const pfx = fs.readFileSync(common.fixturesDir + '/test_cert.pfx'); -var options = { +const options = { host: '127.0.0.1', port: undefined, path: '/', @@ -21,7 +21,7 @@ var options = { rejectUnauthorized: false }; -var server = https.createServer(options, function(req, res) { +const server = https.createServer(options, function(req, res) { assert.equal(req.socket.authorized, false); // not a client cert assert.equal(req.socket.authorizationError, 'DEPTH_ZERO_SELF_SIGNED_CERT'); res.writeHead(200); @@ -32,7 +32,7 @@ server.listen(0, options.host, common.mustCall(function() { options.port = this.address().port; https.get(options, common.mustCall(function(res) { - var data = ''; + let data = ''; res.on('data', function(data_) { data += data_; }); res.on('end', common.mustCall(function() { diff --git a/test/parallel/test-https-req-split.js b/test/parallel/test-https-req-split.js index b49c17f28879be..4298abe5eff43d 100644 --- a/test/parallel/test-https-req-split.js +++ b/test/parallel/test-https-req-split.js @@ -7,12 +7,12 @@ if (!common.hasCrypto) { common.skip('missing crypto'); return; } -var https = require('https'); +const https = require('https'); -var tls = require('tls'); -var fs = require('fs'); +const tls = require('tls'); +const fs = require('fs'); -var options = { +const options = { key: fs.readFileSync(common.fixturesDir + '/keys/agent1-key.pem'), cert: fs.readFileSync(common.fixturesDir + '/keys/agent1-cert.pem') }; @@ -20,7 +20,7 @@ var options = { // Force splitting incoming data tls.SLAB_BUFFER_SIZE = 1; -var server = https.createServer(options); +const server = https.createServer(options); server.on('upgrade', common.mustCall(function(req, socket, upgrade) { socket.on('data', function(data) { throw new Error('Unexpected data: ' + data); @@ -29,7 +29,7 @@ server.on('upgrade', common.mustCall(function(req, socket, upgrade) { })); server.listen(0, function() { - var req = https.request({ + const req = https.request({ host: '127.0.0.1', port: this.address().port, agent: false, diff --git a/test/parallel/test-https-resume-after-renew.js b/test/parallel/test-https-resume-after-renew.js index 001952bfd9b591..72006b03750d82 100644 --- a/test/parallel/test-https-resume-after-renew.js +++ b/test/parallel/test-https-resume-after-renew.js @@ -1,27 +1,28 @@ 'use strict'; -var common = require('../common'); -var fs = require('fs'); -var https = require('https'); -var crypto = require('crypto'); +const common = require('../common'); +const fs = require('fs'); +const https = require('https'); +const crypto = require('crypto'); -var options = { +const options = { key: fs.readFileSync(common.fixturesDir + '/keys/agent1-key.pem'), cert: fs.readFileSync(common.fixturesDir + '/keys/agent1-cert.pem'), ca: fs.readFileSync(common.fixturesDir + '/keys/ca1-cert.pem') }; -var server = https.createServer(options, function(req, res) { +const server = https.createServer(options, function(req, res) { res.end('hello'); }); -var aes = Buffer.alloc(16, 'S'); -var hmac = Buffer.alloc(16, 'H'); +const aes = Buffer.alloc(16, 'S'); +const hmac = Buffer.alloc(16, 'H'); server._sharedCreds.context.enableTicketKeyCallback(); +let newName, newIV; server._sharedCreds.context.onticketkeycallback = function(name, iv, enc) { if (enc) { - var newName = Buffer.alloc(16, 'A'); - var newIV = crypto.randomBytes(16); + newName = Buffer.alloc(16, 'A'); + newIV = crypto.randomBytes(16); } else { // Renew return [ 2, hmac, aes ]; @@ -31,7 +32,7 @@ server._sharedCreds.context.onticketkeycallback = function(name, iv, enc) { }; server.listen(0, function() { - var addr = this.address(); + const addr = this.address(); function doReq(callback) { https.request({ diff --git a/test/parallel/test-https-set-timeout-server.js b/test/parallel/test-https-set-timeout-server.js index fd00a521a03cb5..99457fea5cbec4 100644 --- a/test/parallel/test-https-set-timeout-server.js +++ b/test/parallel/test-https-set-timeout-server.js @@ -1,19 +1,19 @@ 'use strict'; -var common = require('../common'); -var assert = require('assert'); +const common = require('../common'); +const assert = require('assert'); if (!common.hasCrypto) { common.skip('missing crypto'); return; } -var https = require('https'); +const https = require('https'); -var tls = require('tls'); -var fs = require('fs'); +const tls = require('tls'); +const fs = require('fs'); -var tests = []; +const tests = []; -var serverOptions = { +const serverOptions = { key: fs.readFileSync(common.fixturesDir + '/keys/agent1-key.pem'), cert: fs.readFileSync(common.fixturesDir + '/keys/agent1-cert.pem') }; @@ -25,7 +25,7 @@ function test(fn) { } function run() { - var fn = tests.shift(); + const fn = tests.shift(); if (fn) { console.log('# %s', fn.name); fn(run); @@ -35,11 +35,11 @@ function run() { } test(function serverTimeout(cb) { - var server = https.createServer(serverOptions, function(req, res) { + const server = https.createServer(serverOptions, function(req, res) { // just do nothing, we should get a timeout event. }); server.listen(0, common.mustCall(function() { - var s = server.setTimeout(50, common.mustCall(function(socket) { + const s = server.setTimeout(50, common.mustCall(function(socket) { socket.destroy(); server.close(); cb(); @@ -62,9 +62,9 @@ test(function serverRequestTimeout(cb) { })); } - var server = https.createServer(serverOptions, common.mustCall(handler)); + let server = https.createServer(serverOptions, common.mustCall(handler)); server.listen(0, function() { - var req = https.request({ + const req = https.request({ port: this.address().port, method: 'POST', rejectUnauthorized: false @@ -85,7 +85,7 @@ test(function serverResponseTimeout(cb) { })); } - var server = https.createServer(serverOptions, common.mustCall(handler)); + let server = https.createServer(serverOptions, common.mustCall(handler)); server.listen(0, function() { https.get({ port: this.address().port, @@ -100,7 +100,7 @@ test(function serverRequestNotTimeoutAfterEnd(cb) { req.setTimeout(50, common.fail); res.on('timeout', common.mustCall(function(socket) {})); } - var server = https.createServer(serverOptions, common.mustCall(handler)); + const server = https.createServer(serverOptions, common.mustCall(handler)); server.on('timeout', function(socket) { socket.destroy(); server.close(); @@ -115,11 +115,11 @@ test(function serverRequestNotTimeoutAfterEnd(cb) { }); test(function serverResponseTimeoutWithPipeline(cb) { - var caughtTimeout = ''; + let caughtTimeout = ''; process.on('exit', function() { assert.equal(caughtTimeout, '/2'); }); - var server = https.createServer(serverOptions, function(req, res) { + const server = https.createServer(serverOptions, function(req, res) { res.setTimeout(50, function() { caughtTimeout += req.url; }); @@ -131,12 +131,12 @@ test(function serverResponseTimeoutWithPipeline(cb) { cb(); }); server.listen(0, function() { - var options = { + const options = { port: this.address().port, allowHalfOpen: true, rejectUnauthorized: false }; - var c = tls.connect(options, function() { + const c = tls.connect(options, function() { c.write('GET /1 HTTP/1.1\r\nHost: localhost\r\n\r\n'); c.write('GET /2 HTTP/1.1\r\nHost: localhost\r\n\r\n'); c.write('GET /3 HTTP/1.1\r\nHost: localhost\r\n\r\n'); @@ -145,19 +145,19 @@ test(function serverResponseTimeoutWithPipeline(cb) { }); test(function idleTimeout(cb) { - var server = https.createServer(serverOptions, - common.mustCall(function(req, res) { - req.on('timeout', common.fail); - res.on('timeout', common.fail); - res.end(); - })); + const server = https.createServer(serverOptions, + common.mustCall(function(req, res) { + req.on('timeout', common.fail); + res.on('timeout', common.fail); + res.end(); + })); server.setTimeout(50, common.mustCall(function(socket) { socket.destroy(); server.close(); cb(); })); server.listen(0, function() { - var options = { + const options = { port: this.address().port, allowHalfOpen: true, rejectUnauthorized: false diff --git a/test/parallel/test-https-socket-options.js b/test/parallel/test-https-socket-options.js index 70013d1770ff98..05137b35c437ff 100644 --- a/test/parallel/test-https-socket-options.js +++ b/test/parallel/test-https-socket-options.js @@ -1,26 +1,26 @@ 'use strict'; -var common = require('../common'); +const common = require('../common'); if (!common.hasCrypto) { common.skip('missing crypto'); return; } -var https = require('https'); +const https = require('https'); -var fs = require('fs'); +const fs = require('fs'); -var http = require('http'); +const http = require('http'); -var options = { +const options = { key: fs.readFileSync(common.fixturesDir + '/keys/agent1-key.pem'), cert: fs.readFileSync(common.fixturesDir + '/keys/agent1-cert.pem') }; -var body = 'hello world\n'; +const body = 'hello world\n'; // Try first with http server -var server_http = http.createServer(function(req, res) { +const server_http = http.createServer(function(req, res) { console.log('got HTTP request'); res.writeHead(200, { 'content-type': 'text/plain' }); res.end(body); @@ -28,7 +28,7 @@ var server_http = http.createServer(function(req, res) { server_http.listen(0, function() { - var req = http.request({ + const req = http.request({ port: this.address().port, rejectUnauthorized: false }, function(res) { @@ -45,14 +45,14 @@ server_http.listen(0, function() { // Then try https server (requires functions to be // mirroed in tls.js's CryptoStream) -var server_https = https.createServer(options, function(req, res) { +const server_https = https.createServer(options, function(req, res) { console.log('got HTTPS request'); res.writeHead(200, { 'content-type': 'text/plain' }); res.end(body); }); server_https.listen(0, function() { - var req = https.request({ + const req = https.request({ port: this.address().port, rejectUnauthorized: false }, function(res) { diff --git a/test/parallel/test-https-strict.js b/test/parallel/test-https-strict.js index e62f8ad01549e5..f4cff31bdf3538 100644 --- a/test/parallel/test-https-strict.js +++ b/test/parallel/test-https-strict.js @@ -3,16 +3,16 @@ const common = require('../common'); // disable strict server certificate validation by the client process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0'; -var assert = require('assert'); +const assert = require('assert'); if (!common.hasCrypto) { common.skip('missing crypto'); return; } -var https = require('https'); +const https = require('https'); -var fs = require('fs'); -var path = require('path'); +const fs = require('fs'); +const path = require('path'); function file(fname) { return path.resolve(common.fixturesDir, 'keys', fname); @@ -23,60 +23,60 @@ function read(fname) { } // key1 is signed by ca1. -var key1 = read('agent1-key.pem'); -var cert1 = read('agent1-cert.pem'); +const key1 = read('agent1-key.pem'); +const cert1 = read('agent1-cert.pem'); // key2 has a self signed cert -var key2 = read('agent2-key.pem'); -var cert2 = read('agent2-cert.pem'); +const key2 = read('agent2-key.pem'); +const cert2 = read('agent2-cert.pem'); // key3 is signed by ca2. -var key3 = read('agent3-key.pem'); -var cert3 = read('agent3-cert.pem'); +const key3 = read('agent3-key.pem'); +const cert3 = read('agent3-cert.pem'); -var ca1 = read('ca1-cert.pem'); -var ca2 = read('ca2-cert.pem'); +const ca1 = read('ca1-cert.pem'); +const ca2 = read('ca2-cert.pem'); // different agents to use different CA lists. // this api is beyond bad. -var agent0 = new https.Agent(); -var agent1 = new https.Agent({ ca: [ca1] }); -var agent2 = new https.Agent({ ca: [ca2] }); -var agent3 = new https.Agent({ ca: [ca1, ca2] }); +const agent0 = new https.Agent(); +const agent1 = new https.Agent({ ca: [ca1] }); +const agent2 = new https.Agent({ ca: [ca2] }); +const agent3 = new https.Agent({ ca: [ca1, ca2] }); -var options1 = { +const options1 = { key: key1, cert: cert1 }; -var options2 = { +const options2 = { key: key2, cert: cert2 }; -var options3 = { +const options3 = { key: key3, cert: cert3 }; -var server1 = server(options1); -var server2 = server(options2); -var server3 = server(options3); +const server1 = server(options1); +const server2 = server(options2); +const server3 = server(options3); -var listenWait = 0; +let listenWait = 0; server1.listen(0, listening()); server2.listen(0, listening()); server3.listen(0, listening()); -var responseErrors = {}; -var expectResponseCount = 0; -var responseCount = 0; -var pending = 0; +const responseErrors = {}; +let expectResponseCount = 0; +let responseCount = 0; +let pending = 0; function server(options, port) { - var s = https.createServer(options, handler); + const s = https.createServer(options, handler); s.requests = []; s.expectCount = 0; return s; @@ -101,7 +101,7 @@ function listening() { function makeReq(path, port, error, host, ca) { pending++; - var options = { + const options = { port: port, path: path, ca: ca @@ -125,9 +125,9 @@ function makeReq(path, port, error, host, ca) { if (host) { options.headers = { host: host }; } - var req = https.get(options); + const req = https.get(options); expectResponseCount++; - var server = port === server1.address().port ? server1 + const server = port === server1.address().port ? server1 : port === server2.address().port ? server2 : port === server3.address().port ? server3 : null; diff --git a/test/parallel/test-https-timeout-server-2.js b/test/parallel/test-https-timeout-server-2.js index 07b7984f2d644b..8729af1ae8b4ba 100644 --- a/test/parallel/test-https-timeout-server-2.js +++ b/test/parallel/test-https-timeout-server-2.js @@ -1,26 +1,26 @@ 'use strict'; -var common = require('../common'); -var assert = require('assert'); +const common = require('../common'); +const assert = require('assert'); if (!common.hasCrypto) { common.skip('missing crypto'); return; } -var https = require('https'); +const https = require('https'); -var tls = require('tls'); -var fs = require('fs'); +const tls = require('tls'); +const fs = require('fs'); -var options = { +const options = { key: fs.readFileSync(common.fixturesDir + '/keys/agent1-key.pem'), cert: fs.readFileSync(common.fixturesDir + '/keys/agent1-cert.pem') }; -var server = https.createServer(options, common.fail); +const server = https.createServer(options, common.fail); server.on('secureConnection', function(cleartext) { - var s = cleartext.setTimeout(50, function() { + const s = cleartext.setTimeout(50, function() { cleartext.destroy(); server.close(); }); diff --git a/test/parallel/test-internal-modules-expose.js b/test/parallel/test-internal-modules-expose.js index ed3cecb6f29719..dd3a7f7a3cd0b7 100644 --- a/test/parallel/test-internal-modules-expose.js +++ b/test/parallel/test-internal-modules-expose.js @@ -2,6 +2,6 @@ // Flags: --expose_internals require('../common'); -var assert = require('assert'); +const assert = require('assert'); assert.equal(typeof require('internal/freelist').FreeList, 'function'); diff --git a/test/parallel/test-listen-fd-cluster.js b/test/parallel/test-listen-fd-cluster.js index 606109030b51d0..de1fbed7b56aff 100644 --- a/test/parallel/test-listen-fd-cluster.js +++ b/test/parallel/test-listen-fd-cluster.js @@ -1,9 +1,9 @@ 'use strict'; -var common = require('../common'); -var assert = require('assert'); -var http = require('http'); -var net = require('net'); -var cluster = require('cluster'); +const common = require('../common'); +const assert = require('assert'); +const http = require('http'); +const net = require('net'); +const cluster = require('cluster'); console.error('Cluster listen fd test', process.argv[2] || 'runner'); @@ -22,7 +22,7 @@ switch (process.argv[2]) { case 'worker': return worker(); } -var ok; +let ok; process.on('exit', function() { assert.ok(ok); @@ -41,7 +41,7 @@ test(function(parent, port) { port: port, path: '/', }).on('response', function(res) { - var s = ''; + let s = ''; res.on('data', function(c) { s += c.toString(); }); @@ -61,15 +61,15 @@ test(function(parent, port) { function test(cb) { console.error('about to listen in parent'); - var server = net.createServer(function(conn) { + const server = net.createServer(function(conn) { console.error('connection on parent'); conn.end('hello from parent\n'); }).listen(0, function() { const port = this.address().port; console.error('server listening on %d', port); - var spawn = require('child_process').spawn; - var master = spawn(process.execPath, [__filename, 'master'], { + const spawn = require('child_process').spawn; + const master = spawn(process.execPath, [__filename, 'master'], { stdio: [ 0, 'pipe', 2, server._handle, 'ipc' ], detached: true }); @@ -100,7 +100,7 @@ function master() { cluster.setupMaster({ args: [ 'worker' ] }); - var worker = cluster.fork(); + const worker = cluster.fork(); worker.on('message', function(msg) { if (msg === 'worker ready') { process.send('started worker'); diff --git a/test/parallel/test-listen-fd-detached-inherit.js b/test/parallel/test-listen-fd-detached-inherit.js index 5dfe346a49f441..2ac4d83dba6691 100644 --- a/test/parallel/test-listen-fd-detached-inherit.js +++ b/test/parallel/test-listen-fd-detached-inherit.js @@ -1,9 +1,9 @@ 'use strict'; -var common = require('../common'); -var assert = require('assert'); -var http = require('http'); -var net = require('net'); -var spawn = require('child_process').spawn; +const common = require('../common'); +const assert = require('assert'); +const http = require('http'); +const net = require('net'); +const spawn = require('child_process').spawn; if (common.isWindows) { common.skip('This test is disabled on windows.'); @@ -23,24 +23,24 @@ switch (process.argv[2]) { // concurrency in HTTP servers! Use the cluster module, or if you want // a more low-level approach, use child process IPC manually. function test() { - var parent = spawn(process.execPath, [__filename, 'parent'], { + const parent = spawn(process.execPath, [__filename, 'parent'], { stdio: [ 0, 'pipe', 2 ] }); - var json = ''; + let json = ''; parent.stdout.on('data', function(c) { json += c.toString(); if (json.indexOf('\n') !== -1) next(); }); function next() { console.error('output from parent = %s', json); - var child = JSON.parse(json); + const child = JSON.parse(json); // now make sure that we can request to the child, then kill it. http.get({ server: 'localhost', port: child.port, path: '/', }).on('response', function(res) { - var s = ''; + let s = ''; res.on('data', function(c) { s += c.toString(); }); @@ -62,13 +62,13 @@ function test() { // Listen on port, and then pass the handle to the detached child. // Then output the child's pid, and immediately exit. function parent() { - var server = net.createServer(function(conn) { + const server = net.createServer(function(conn) { conn.end('HTTP/1.1 403 Forbidden\r\n\r\nI got problems.\r\n'); throw new Error('Should not see connections on parent'); }).listen(0, function() { console.error('server listening on %d', this.address().port); - var child = spawn(process.execPath, [__filename, 'child'], { + const child = spawn(process.execPath, [__filename, 'child'], { stdio: [ 0, 1, 2, server._handle ], detached: true }); diff --git a/test/parallel/test-listen-fd-detached.js b/test/parallel/test-listen-fd-detached.js index 0629f7ea7970d7..1194d001610fce 100644 --- a/test/parallel/test-listen-fd-detached.js +++ b/test/parallel/test-listen-fd-detached.js @@ -1,9 +1,9 @@ 'use strict'; -var common = require('../common'); -var assert = require('assert'); -var http = require('http'); -var net = require('net'); -var spawn = require('child_process').spawn; +const common = require('../common'); +const assert = require('assert'); +const http = require('http'); +const net = require('net'); +const spawn = require('child_process').spawn; if (common.isWindows) { common.skip('This test is disabled on windows.'); @@ -23,24 +23,24 @@ switch (process.argv[2]) { // concurrency in HTTP servers! Use the cluster module, or if you want // a more low-level approach, use child process IPC manually. function test() { - var parent = spawn(process.execPath, [__filename, 'parent'], { + const parent = spawn(process.execPath, [__filename, 'parent'], { stdio: [ 0, 'pipe', 2 ] }); - var json = ''; + let json = ''; parent.stdout.on('data', function(c) { json += c.toString(); if (json.indexOf('\n') !== -1) next(); }); function next() { console.error('output from parent = %s', json); - var child = JSON.parse(json); + const child = JSON.parse(json); // now make sure that we can request to the child, then kill it. http.get({ server: 'localhost', port: child.port, path: '/', }).on('response', function(res) { - var s = ''; + let s = ''; res.on('data', function(c) { s += c.toString(); }); @@ -60,14 +60,14 @@ function test() { } function parent() { - var server = net.createServer(function(conn) { + const server = net.createServer(function(conn) { console.error('connection on parent'); conn.end('hello from parent\n'); }).listen(0, function() { console.error('server listening on %d', this.address().port); - var spawn = require('child_process').spawn; - var child = spawn(process.execPath, [__filename, 'child'], { + const spawn = require('child_process').spawn; + const child = spawn(process.execPath, [__filename, 'child'], { stdio: [ 'ignore', 'ignore', 'ignore', server._handle ], detached: true }); diff --git a/test/parallel/test-listen-fd-server.js b/test/parallel/test-listen-fd-server.js index eda75e5c723261..60aa8717a8c24e 100644 --- a/test/parallel/test-listen-fd-server.js +++ b/test/parallel/test-listen-fd-server.js @@ -1,8 +1,8 @@ 'use strict'; -var common = require('../common'); -var assert = require('assert'); -var http = require('http'); -var net = require('net'); +const common = require('../common'); +const assert = require('assert'); +const http = require('http'); +const net = require('net'); if (common.isWindows) { common.skip('This test is disabled on windows.'); @@ -13,7 +13,7 @@ switch (process.argv[2]) { case 'child': return child(); } -var ok; +let ok; process.on('exit', function() { assert.ok(ok); @@ -31,7 +31,7 @@ test(function(child, port) { port: port, path: '/', }).on('response', function(res) { - var s = ''; + let s = ''; res.on('data', function(c) { s += c.toString(); }); @@ -67,15 +67,15 @@ function child() { } function test(cb) { - var server = net.createServer(function(conn) { + const server = net.createServer(function(conn) { console.error('connection on parent'); conn.end('hello from parent\n'); }).listen(0, function() { const port = this.address().port; console.error('server listening on %d', port); - var spawn = require('child_process').spawn; - var child = spawn(process.execPath, [__filename, 'child'], { + const spawn = require('child_process').spawn; + const child = spawn(process.execPath, [__filename, 'child'], { stdio: [ 0, 1, 2, server._handle, 'ipc' ] }); diff --git a/test/parallel/test-memory-usage-emfile.js b/test/parallel/test-memory-usage-emfile.js index 92c103669a9a85..09ab270b70fa21 100644 --- a/test/parallel/test-memory-usage-emfile.js +++ b/test/parallel/test-memory-usage-emfile.js @@ -1,13 +1,13 @@ 'use strict'; require('../common'); -var assert = require('assert'); +const assert = require('assert'); -var fs = require('fs'); +const fs = require('fs'); -var files = []; +const files = []; while (files.length < 256) files.push(fs.openSync(__filename, 'r')); -var r = process.memoryUsage(); +const r = process.memoryUsage(); assert.equal(true, r['rss'] > 0); diff --git a/test/parallel/test-memory-usage.js b/test/parallel/test-memory-usage.js index c5905c537ac613..cba3f9a5172a07 100644 --- a/test/parallel/test-memory-usage.js +++ b/test/parallel/test-memory-usage.js @@ -1,8 +1,8 @@ 'use strict'; require('../common'); -var assert = require('assert'); +const assert = require('assert'); -var r = process.memoryUsage(); +const r = process.memoryUsage(); assert.ok(r.rss > 0); assert.ok(r.heapTotal > 0); assert.ok(r.heapUsed > 0); diff --git a/test/parallel/test-microtask-queue-integration-domain.js b/test/parallel/test-microtask-queue-integration-domain.js index 1e07fa5d415ba3..7110af7648ae8a 100644 --- a/test/parallel/test-microtask-queue-integration-domain.js +++ b/test/parallel/test-microtask-queue-integration-domain.js @@ -1,6 +1,6 @@ 'use strict'; require('../common'); -var assert = require('assert'); +const assert = require('assert'); // Requiring the domain module here changes the function that is used by node to // call process.nextTick's callbacks to a variant that specifically handles @@ -9,21 +9,21 @@ var assert = require('assert'); // removed. require('domain'); -var implementations = [ +const implementations = [ function(fn) { Promise.resolve().then(fn); } ]; -var expected = 0; -var done = 0; +let expected = 0; +let done = 0; process.on('exit', function() { assert.equal(done, expected); }); function test(scheduleMicrotask) { - var nextTickCalled = false; + let nextTickCalled = false; expected++; scheduleMicrotask(function() { diff --git a/test/parallel/test-microtask-queue-integration.js b/test/parallel/test-microtask-queue-integration.js index 2cc608d96aec3d..d212bbae96b001 100644 --- a/test/parallel/test-microtask-queue-integration.js +++ b/test/parallel/test-microtask-queue-integration.js @@ -1,22 +1,22 @@ 'use strict'; require('../common'); -var assert = require('assert'); +const assert = require('assert'); -var implementations = [ +const implementations = [ function(fn) { Promise.resolve().then(fn); } ]; -var expected = 0; -var done = 0; +let expected = 0; +let done = 0; process.on('exit', function() { assert.equal(done, expected); }); function test(scheduleMicrotask) { - var nextTickCalled = false; + let nextTickCalled = false; expected++; scheduleMicrotask(function() { diff --git a/test/parallel/test-microtask-queue-run-domain.js b/test/parallel/test-microtask-queue-run-domain.js index fb5139f71d65aa..7d34ec829a003c 100644 --- a/test/parallel/test-microtask-queue-run-domain.js +++ b/test/parallel/test-microtask-queue-run-domain.js @@ -1,6 +1,6 @@ 'use strict'; require('../common'); -var assert = require('assert'); +const assert = require('assert'); // Requiring the domain module here changes the function that is used by node to // call process.nextTick's callbacks to a variant that specifically handles @@ -13,7 +13,7 @@ function enqueueMicrotask(fn) { Promise.resolve().then(fn); } -var done = 0; +let done = 0; process.on('exit', function() { assert.equal(done, 2); @@ -29,7 +29,7 @@ setTimeout(function() { // no nextTick, microtask with nextTick setTimeout(function() { - var called = false; + let called = false; enqueueMicrotask(function() { process.nextTick(function() { diff --git a/test/parallel/test-microtask-queue-run-immediate-domain.js b/test/parallel/test-microtask-queue-run-immediate-domain.js index 4a7729ab98a062..e09087f74e32a9 100644 --- a/test/parallel/test-microtask-queue-run-immediate-domain.js +++ b/test/parallel/test-microtask-queue-run-immediate-domain.js @@ -1,6 +1,6 @@ 'use strict'; require('../common'); -var assert = require('assert'); +const assert = require('assert'); // Requiring the domain module here changes the function that is used by node to // call process.nextTick's callbacks to a variant that specifically handles @@ -13,7 +13,7 @@ function enqueueMicrotask(fn) { Promise.resolve().then(fn); } -var done = 0; +let done = 0; process.on('exit', function() { assert.equal(done, 2); @@ -29,7 +29,7 @@ setImmediate(function() { // no nextTick, microtask with nextTick setImmediate(function() { - var called = false; + let called = false; enqueueMicrotask(function() { process.nextTick(function() { diff --git a/test/parallel/test-microtask-queue-run-immediate.js b/test/parallel/test-microtask-queue-run-immediate.js index 479062ad4710f4..c5ed6c6dcbc1ae 100644 --- a/test/parallel/test-microtask-queue-run-immediate.js +++ b/test/parallel/test-microtask-queue-run-immediate.js @@ -1,12 +1,12 @@ 'use strict'; require('../common'); -var assert = require('assert'); +const assert = require('assert'); function enqueueMicrotask(fn) { Promise.resolve().then(fn); } -var done = 0; +let done = 0; process.on('exit', function() { assert.equal(done, 2); @@ -22,7 +22,7 @@ setImmediate(function() { // no nextTick, microtask with nextTick setImmediate(function() { - var called = false; + let called = false; enqueueMicrotask(function() { process.nextTick(function() { diff --git a/test/parallel/test-microtask-queue-run.js b/test/parallel/test-microtask-queue-run.js index ce743d93003249..71e1fbedbaecbd 100644 --- a/test/parallel/test-microtask-queue-run.js +++ b/test/parallel/test-microtask-queue-run.js @@ -1,12 +1,12 @@ 'use strict'; require('../common'); -var assert = require('assert'); +const assert = require('assert'); function enqueueMicrotask(fn) { Promise.resolve().then(fn); } -var done = 0; +let done = 0; process.on('exit', function() { assert.equal(done, 2); @@ -22,7 +22,7 @@ setTimeout(function() { // no nextTick, microtask with nextTick setTimeout(function() { - var called = false; + let called = false; enqueueMicrotask(function() { process.nextTick(function() { diff --git a/test/parallel/test-module-globalpaths-nodepath.js b/test/parallel/test-module-globalpaths-nodepath.js index 3369df0676015b..a4781d27a7a9c6 100644 --- a/test/parallel/test-module-globalpaths-nodepath.js +++ b/test/parallel/test-module-globalpaths-nodepath.js @@ -1,11 +1,11 @@ 'use strict'; -var common = require('../common'); -var assert = require('assert'); +const common = require('../common'); +const assert = require('assert'); -var module = require('module'); +const mod = require('module'); -var partA, partB; -var partC = ''; +let partA, partB; +const partC = ''; if (common.isWindows) { partA = 'C:\\Users\\Rocko Artischocko\\AppData\\Roaming\\npm'; @@ -17,10 +17,10 @@ if (common.isWindows) { process.env['NODE_PATH'] = partA + ':' + partB + ':' + partC; } -module._initPaths(); +mod._initPaths(); -assert.ok(module.globalPaths.indexOf(partA) !== -1); -assert.ok(module.globalPaths.indexOf(partB) !== -1); -assert.ok(module.globalPaths.indexOf(partC) === -1); +assert.ok(mod.globalPaths.indexOf(partA) !== -1); +assert.ok(mod.globalPaths.indexOf(partB) !== -1); +assert.ok(mod.globalPaths.indexOf(partC) === -1); -assert.ok(Array.isArray(module.globalPaths)); +assert.ok(Array.isArray(mod.globalPaths)); diff --git a/test/parallel/test-module-loading-error.js b/test/parallel/test-module-loading-error.js index 145530985401e4..03481b690f79f4 100644 --- a/test/parallel/test-module-loading-error.js +++ b/test/parallel/test-module-loading-error.js @@ -1,16 +1,16 @@ 'use strict'; const common = require('../common'); -var assert = require('assert'); +const assert = require('assert'); console.error('load test-module-loading-error.js'); -var error_desc = { +const error_desc = { win32: ['%1 is not a valid Win32 application'], linux: ['file too short', 'Exec format error'], sunos: ['unknown file type', 'not an ELF file'], darwin: ['file too short'] }; -var dlerror_msg = error_desc[process.platform]; +const dlerror_msg = error_desc[process.platform]; if (!dlerror_msg) { common.skip('platform not supported.'); diff --git a/test/parallel/test-module-version.js b/test/parallel/test-module-version.js index 7f96e8bb60f0ac..04f011bbfacd8e 100644 --- a/test/parallel/test-module-version.js +++ b/test/parallel/test-module-version.js @@ -1,6 +1,6 @@ 'use strict'; require('../common'); -var assert = require('assert'); +const assert = require('assert'); // check for existence assert(process.config.variables.hasOwnProperty('node_module_version')); diff --git a/test/parallel/test-net-after-close.js b/test/parallel/test-net-after-close.js index a73663e7da86db..d46f096116d02e 100644 --- a/test/parallel/test-net-after-close.js +++ b/test/parallel/test-net-after-close.js @@ -1,15 +1,15 @@ 'use strict'; const common = require('../common'); -var assert = require('assert'); -var net = require('net'); +const assert = require('assert'); +const net = require('net'); -var server = net.createServer(function(s) { +const server = net.createServer(function(s) { console.error('SERVER: got connection'); s.end(); }); server.listen(0, common.mustCall(function() { - var c = net.createConnection(this.address().port); + const c = net.createConnection(this.address().port); c.on('close', common.mustCall(function() { console.error('connection closed'); assert.strictEqual(c._handle, null); diff --git a/test/parallel/test-net-better-error-messages-path.js b/test/parallel/test-net-better-error-messages-path.js index 9222a1cc758aaa..2f821ef5d703be 100644 --- a/test/parallel/test-net-better-error-messages-path.js +++ b/test/parallel/test-net-better-error-messages-path.js @@ -1,9 +1,9 @@ 'use strict'; -var common = require('../common'); -var net = require('net'); -var assert = require('assert'); -var fp = '/tmp/fadagagsdfgsdf'; -var c = net.connect(fp); +const common = require('../common'); +const net = require('net'); +const assert = require('assert'); +const fp = '/tmp/fadagagsdfgsdf'; +const c = net.connect(fp); c.on('connect', common.fail); diff --git a/test/parallel/test-net-binary.js b/test/parallel/test-net-binary.js index 47e0be8d04dcf6..bcc554ac4024f6 100644 --- a/test/parallel/test-net-binary.js +++ b/test/parallel/test-net-binary.js @@ -3,8 +3,8 @@ require('../common'); const assert = require('assert'); const net = require('net'); -var binaryString = ''; -for (var i = 255; i >= 0; i--) { +let binaryString = ''; +for (let i = 255; i >= 0; i--) { const s = `'\\${i.toString(8)}'`; const S = eval(s); assert.strictEqual(S.charCodeAt(0), i); @@ -13,7 +13,7 @@ for (var i = 255; i >= 0; i--) { } // safe constructor -var echoServer = net.Server(function(connection) { +const echoServer = net.Server(function(connection) { connection.setEncoding('latin1'); connection.on('data', function(chunk) { connection.write(chunk, 'latin1'); @@ -24,10 +24,10 @@ var echoServer = net.Server(function(connection) { }); echoServer.listen(0); -var recv = ''; +let recv = ''; echoServer.on('listening', function() { - var j = 0; + let j = 0; const c = net.createConnection({ port: this.address().port }); diff --git a/test/parallel/test-net-bind-twice.js b/test/parallel/test-net-bind-twice.js index 9b9fc7c5db37dd..17fdc90cb3742b 100644 --- a/test/parallel/test-net-bind-twice.js +++ b/test/parallel/test-net-bind-twice.js @@ -1,11 +1,11 @@ 'use strict'; const common = require('../common'); -var assert = require('assert'); -var net = require('net'); +const assert = require('assert'); +const net = require('net'); -var server1 = net.createServer(common.fail); +const server1 = net.createServer(common.fail); server1.listen(0, '127.0.0.1', common.mustCall(function() { - var server2 = net.createServer(common.fail); + const server2 = net.createServer(common.fail); server2.listen(this.address().port, '127.0.0.1', common.fail); server2.on('error', common.mustCall(function(e) { diff --git a/test/parallel/test-net-buffersize.js b/test/parallel/test-net-buffersize.js index 872d8de7b42f3b..e8ba17a76e6c69 100644 --- a/test/parallel/test-net-buffersize.js +++ b/test/parallel/test-net-buffersize.js @@ -1,11 +1,11 @@ 'use strict'; require('../common'); -var assert = require('assert'); -var net = require('net'); +const assert = require('assert'); +const net = require('net'); -var iter = 10; +const iter = 10; -var server = net.createServer(function(socket) { +const server = net.createServer(function(socket) { socket.on('readable', function() { socket.read(); }); @@ -16,13 +16,13 @@ var server = net.createServer(function(socket) { }); server.listen(0, function() { - var client = net.connect(this.address().port); + const client = net.connect(this.address().port); client.on('finish', function() { assert.strictEqual(client.bufferSize, 0); }); - for (var i = 1; i < iter; i++) { + for (let i = 1; i < iter; i++) { client.write('a'); assert.strictEqual(client.bufferSize, i); } diff --git a/test/parallel/test-net-bytes-stats.js b/test/parallel/test-net-bytes-stats.js index a8643b03b97250..4cc6eee8373e86 100644 --- a/test/parallel/test-net-bytes-stats.js +++ b/test/parallel/test-net-bytes-stats.js @@ -1,13 +1,13 @@ 'use strict'; require('../common'); -var assert = require('assert'); -var net = require('net'); +const assert = require('assert'); +const net = require('net'); -var bytesRead = 0; -var bytesWritten = 0; -var count = 0; +let bytesRead = 0; +let bytesWritten = 0; +let count = 0; -var tcp = net.Server(function(s) { +const tcp = net.Server(function(s) { console.log('tcp server connection'); // trigger old mode. @@ -21,7 +21,7 @@ var tcp = net.Server(function(s) { tcp.listen(0, function doTest() { console.error('listening'); - var socket = net.createConnection(this.address().port); + const socket = net.createConnection(this.address().port); socket.on('connect', function() { count++; diff --git a/test/parallel/test-net-can-reset-timeout.js b/test/parallel/test-net-can-reset-timeout.js index 7dbd5cad2ae6bb..faa460e847aa08 100644 --- a/test/parallel/test-net-can-reset-timeout.js +++ b/test/parallel/test-net-can-reset-timeout.js @@ -1,8 +1,8 @@ 'use strict'; const common = require('../common'); -var net = require('net'); +const net = require('net'); -var server = net.createServer(common.mustCall(function(stream) { +const server = net.createServer(common.mustCall(function(stream) { stream.setTimeout(100); stream.resume(); @@ -20,7 +20,7 @@ var server = net.createServer(common.mustCall(function(stream) { })); server.listen(0, function() { - var c = net.createConnection(this.address().port); + const c = net.createConnection(this.address().port); c.on('data', function() { c.end(); diff --git a/test/parallel/test-net-connect-buffer.js b/test/parallel/test-net-connect-buffer.js index 3ef5b0ea9f075d..c43ee1abd0e305 100644 --- a/test/parallel/test-net-connect-buffer.js +++ b/test/parallel/test-net-connect-buffer.js @@ -1,17 +1,17 @@ 'use strict'; require('../common'); -var assert = require('assert'); -var net = require('net'); +const assert = require('assert'); +const net = require('net'); -var dataWritten = false; -var connectHappened = false; +let dataWritten = false; +let connectHappened = false; -var tcp = net.Server(function(s) { +const tcp = net.Server(function(s) { tcp.close(); console.log('tcp server connection'); - var buf = ''; + let buf = ''; s.on('data', function(d) { buf += d; }); @@ -30,7 +30,7 @@ var tcp = net.Server(function(s) { }); tcp.listen(0, function() { - var socket = net.Stream({ highWaterMark: 0 }); + const socket = net.Stream({ highWaterMark: 0 }); console.log('Connecting to socket '); @@ -65,13 +65,13 @@ tcp.listen(0, function() { // Write a string that contains a multi-byte character sequence to test that // `bytesWritten` is incremented with the # of bytes, not # of characters. - var a = "L'État, c'est "; - var b = 'moi'; + const a = "L'État, c'est "; + const b = 'moi'; // We're still connecting at this point so the datagram is first pushed onto // the connect queue. Make sure that it's not added to `bytesWritten` again // when the actual write happens. - var r = socket.write(a, function(er) { + const r = socket.write(a, function(er) { console.error('write cb'); dataWritten = true; assert.ok(connectHappened); diff --git a/test/parallel/test-net-connect-local-error.js b/test/parallel/test-net-connect-local-error.js index 2a0c20f6ea4a5e..f23245ac93a49f 100644 --- a/test/parallel/test-net-connect-local-error.js +++ b/test/parallel/test-net-connect-local-error.js @@ -3,7 +3,7 @@ const common = require('../common'); const assert = require('assert'); const net = require('net'); -var client = net.connect({ +const client = net.connect({ port: common.PORT + 1, localPort: common.PORT, localAddress: common.localhostIPv4 diff --git a/test/parallel/test-net-connect-options-ipv6.js b/test/parallel/test-net-connect-options-ipv6.js index 7f638d66f59508..e9d8a78cbbefef 100644 --- a/test/parallel/test-net-connect-options-ipv6.js +++ b/test/parallel/test-net-connect-options-ipv6.js @@ -9,9 +9,9 @@ if (!common.hasIPv6) { } const hosts = common.localIPv6Hosts; -var hostIdx = 0; -var host = hosts[hostIdx]; -var localhostTries = 10; +let hostIdx = 0; +let host = hosts[hostIdx]; +let localhostTries = 10; const server = net.createServer({allowHalfOpen: true}, function(socket) { socket.resume(); diff --git a/test/parallel/test-net-connect-options.js b/test/parallel/test-net-connect-options.js index 3446790d7b3c4a..e794c40859856a 100644 --- a/test/parallel/test-net-connect-options.js +++ b/test/parallel/test-net-connect-options.js @@ -1,9 +1,9 @@ 'use strict'; const common = require('../common'); -var assert = require('assert'); -var net = require('net'); +const assert = require('assert'); +const net = require('net'); -var server = net.createServer({ +const server = net.createServer({ allowHalfOpen: true }, common.mustCall(function(socket) { socket.resume(); @@ -12,7 +12,7 @@ var server = net.createServer({ })); server.listen(0, function() { - var client = net.connect({ + const client = net.connect({ host: '127.0.0.1', port: this.address().port, allowHalfOpen: true diff --git a/test/parallel/test-net-connect-paused-connection.js b/test/parallel/test-net-connect-paused-connection.js index 8c0e1c93cfb208..a0a90eefc1db3e 100644 --- a/test/parallel/test-net-connect-paused-connection.js +++ b/test/parallel/test-net-connect-paused-connection.js @@ -1,7 +1,7 @@ 'use strict'; const common = require('../common'); -var net = require('net'); +const net = require('net'); net.createServer(function(conn) { conn.unref(); diff --git a/test/parallel/test-net-create-connection.js b/test/parallel/test-net-create-connection.js index a21f92a3a5674c..a5d8cd101d974d 100644 --- a/test/parallel/test-net-create-connection.js +++ b/test/parallel/test-net-create-connection.js @@ -5,8 +5,8 @@ const dns = require('dns'); const net = require('net'); const expectedConnections = 7; -var clientConnected = 0; -var serverConnected = 0; +let clientConnected = 0; +let serverConnected = 0; const server = net.createServer(function(socket) { socket.end(); diff --git a/test/parallel/test-net-dns-custom-lookup.js b/test/parallel/test-net-dns-custom-lookup.js index 07eb71c5ed5811..c7a01f5fa6faec 100644 --- a/test/parallel/test-net-dns-custom-lookup.js +++ b/test/parallel/test-net-dns-custom-lookup.js @@ -1,16 +1,16 @@ 'use strict'; -var common = require('../common'); -var assert = require('assert'); -var net = require('net'); +const common = require('../common'); +const assert = require('assert'); +const net = require('net'); function check(addressType, cb) { - var server = net.createServer(function(client) { + const server = net.createServer(function(client) { client.end(); server.close(); cb && cb(); }); - var address = addressType === 4 ? common.localhostIPv4 : '::1'; + const address = addressType === 4 ? common.localhostIPv4 : '::1'; server.listen(0, address, common.mustCall(function() { net.connect({ port: this.address().port, diff --git a/test/parallel/test-net-dns-error.js b/test/parallel/test-net-dns-error.js index b36d84d3e9e214..aa288c5fde1ffa 100644 --- a/test/parallel/test-net-dns-error.js +++ b/test/parallel/test-net-dns-error.js @@ -1,16 +1,16 @@ 'use strict'; const common = require('../common'); -var assert = require('assert'); +const assert = require('assert'); -var net = require('net'); +const net = require('net'); -var host = '*'.repeat(256); +const host = '*'.repeat(256); function do_not_call() { throw new Error('This function should not have been called.'); } -var socket = net.connect(42, host, do_not_call); +const socket = net.connect(42, host, do_not_call); socket.on('error', common.mustCall(function(err) { assert.equal(err.code, 'ENOTFOUND'); })); diff --git a/test/parallel/test-net-dns-lookup-skip.js b/test/parallel/test-net-dns-lookup-skip.js index 513a6d0422498e..0997e6cc6c1c5d 100644 --- a/test/parallel/test-net-dns-lookup-skip.js +++ b/test/parallel/test-net-dns-lookup-skip.js @@ -1,14 +1,14 @@ 'use strict'; -var common = require('../common'); -var net = require('net'); +const common = require('../common'); +const net = require('net'); function check(addressType) { - var server = net.createServer(function(client) { + const server = net.createServer(function(client) { client.end(); server.close(); }); - var address = addressType === 4 ? '127.0.0.1' : '::1'; + const address = addressType === 4 ? '127.0.0.1' : '::1'; server.listen(0, address, function() { net.connect(this.address().port, address).on('lookup', common.fail); }); diff --git a/test/parallel/test-net-dns-lookup.js b/test/parallel/test-net-dns-lookup.js index 4f3cd2991cf925..8d9930f4b7a366 100644 --- a/test/parallel/test-net-dns-lookup.js +++ b/test/parallel/test-net-dns-lookup.js @@ -1,9 +1,9 @@ 'use strict'; const common = require('../common'); -var assert = require('assert'); -var net = require('net'); +const assert = require('assert'); +const net = require('net'); -var server = net.createServer(function(client) { +const server = net.createServer(function(client) { client.end(); server.close(); }); diff --git a/test/parallel/test-net-during-close.js b/test/parallel/test-net-during-close.js index 2649995f89a02f..e8723fb1a692a8 100644 --- a/test/parallel/test-net-during-close.js +++ b/test/parallel/test-net-during-close.js @@ -1,14 +1,14 @@ 'use strict'; const common = require('../common'); -var assert = require('assert'); -var net = require('net'); +const assert = require('assert'); +const net = require('net'); -var server = net.createServer(function(socket) { +const server = net.createServer(function(socket) { socket.end(); }); server.listen(0, common.mustCall(function() { - var client = net.createConnection(this.address().port); + const client = net.createConnection(this.address().port); server.close(); // server connection event has not yet fired // client is still attempting to connect diff --git a/test/parallel/test-net-eaddrinuse.js b/test/parallel/test-net-eaddrinuse.js index 4741c820797154..3d7ceb8d5e38f7 100644 --- a/test/parallel/test-net-eaddrinuse.js +++ b/test/parallel/test-net-eaddrinuse.js @@ -1,11 +1,11 @@ 'use strict'; require('../common'); -var assert = require('assert'); -var net = require('net'); +const assert = require('assert'); +const net = require('net'); -var server1 = net.createServer(function(socket) { +const server1 = net.createServer(function(socket) { }); -var server2 = net.createServer(function(socket) { +const server2 = net.createServer(function(socket) { }); server1.listen(0, function() { server2.on('error', function(error) { diff --git a/test/parallel/test-net-end-without-connect.js b/test/parallel/test-net-end-without-connect.js index 69abf486316ff2..99324b071d27d6 100644 --- a/test/parallel/test-net-end-without-connect.js +++ b/test/parallel/test-net-end-without-connect.js @@ -1,6 +1,6 @@ 'use strict'; require('../common'); -var net = require('net'); +const net = require('net'); -var sock = new net.Socket(); +const sock = new net.Socket(); sock.end(); // Should not throw. diff --git a/test/parallel/test-net-error-twice.js b/test/parallel/test-net-error-twice.js index 36c33b4b1cc012..98a2c337559b06 100644 --- a/test/parallel/test-net-error-twice.js +++ b/test/parallel/test-net-error-twice.js @@ -6,8 +6,8 @@ const net = require('net'); const buf = Buffer.alloc(10 * 1024 * 1024, 0x62); const errs = []; -var clientSocket; -var serverSocket; +let clientSocket; +let serverSocket; function ready() { if (clientSocket && serverSocket) { @@ -16,7 +16,7 @@ function ready() { } } -var srv = net.createServer(function onConnection(conn) { +const srv = net.createServer(function onConnection(conn) { conn.on('error', function(err) { errs.push(err); if (errs.length > 1 && errs[0] === errs[1]) @@ -28,7 +28,7 @@ var srv = net.createServer(function onConnection(conn) { serverSocket = conn; ready(); }).listen(0, function() { - var client = net.connect({ port: this.address().port }); + const client = net.connect({ port: this.address().port }); client.on('connect', function() { clientSocket = client; diff --git a/test/parallel/test-net-internal.js b/test/parallel/test-net-internal.js index 0c8d1cf9e17a0e..a79d022a5d7eaa 100644 --- a/test/parallel/test-net-internal.js +++ b/test/parallel/test-net-internal.js @@ -6,7 +6,7 @@ require('../common'); const assert = require('assert'); const isLegalPort = require('internal/net').isLegalPort; -for (var n = 0; n <= 0xFFFF; n++) { +for (let n = 0; n <= 0xFFFF; n++) { assert(isLegalPort(n)); assert(isLegalPort('' + n)); assert(`0x${n.toString(16)}`); diff --git a/test/parallel/test-net-isip.js b/test/parallel/test-net-isip.js index 6b159b59d8c8c0..65d88523fe930e 100644 --- a/test/parallel/test-net-isip.js +++ b/test/parallel/test-net-isip.js @@ -1,7 +1,7 @@ 'use strict'; require('../common'); -var assert = require('assert'); -var net = require('net'); +const assert = require('assert'); +const net = require('net'); assert.equal(net.isIP('127.0.0.1'), 4); assert.equal(net.isIP('x127.0.0.1'), 0); diff --git a/test/parallel/test-net-keepalive.js b/test/parallel/test-net-keepalive.js index e466f0ff580d06..950a005addecdf 100644 --- a/test/parallel/test-net-keepalive.js +++ b/test/parallel/test-net-keepalive.js @@ -3,9 +3,9 @@ const common = require('../common'); const assert = require('assert'); const net = require('net'); -var serverConnection; -var clientConnection; -var echoServer = net.createServer(function(connection) { +let serverConnection; +let clientConnection; +const echoServer = net.createServer(function(connection) { serverConnection = connection; setTimeout(common.mustCall(function() { // make sure both connections are still open diff --git a/test/parallel/test-net-large-string.js b/test/parallel/test-net-large-string.js index b469b0289546a1..83612111e2a0aa 100644 --- a/test/parallel/test-net-large-string.js +++ b/test/parallel/test-net-large-string.js @@ -1,14 +1,14 @@ 'use strict'; const common = require('../common'); -var assert = require('assert'); -var net = require('net'); +const assert = require('assert'); +const net = require('net'); -var kPoolSize = 40 * 1024; -var data = 'あ'.repeat(kPoolSize); -var encoding = 'UTF-8'; +const kPoolSize = 40 * 1024; +const data = 'あ'.repeat(kPoolSize); +const encoding = 'UTF-8'; -var server = net.createServer(common.mustCall(function(socket) { - var receivedSize = 0; +const server = net.createServer(common.mustCall(function(socket) { + let receivedSize = 0; socket.setEncoding(encoding); socket.on('data', function(data) { @@ -21,7 +21,7 @@ var server = net.createServer(common.mustCall(function(socket) { })); server.listen(0, function() { - var client = net.createConnection(this.address().port); + const client = net.createConnection(this.address().port); client.on('end', function() { server.close(); }); diff --git a/test/parallel/test-net-listen-close-server-callback-is-not-function.js b/test/parallel/test-net-listen-close-server-callback-is-not-function.js index 03c08d4f51bf15..472ea37e7146b9 100644 --- a/test/parallel/test-net-listen-close-server-callback-is-not-function.js +++ b/test/parallel/test-net-listen-close-server-callback-is-not-function.js @@ -1,8 +1,8 @@ 'use strict'; const common = require('../common'); -var net = require('net'); +const net = require('net'); -var server = net.createServer(common.fail); +const server = net.createServer(common.fail); server.on('close', common.mustCall(function() {})); diff --git a/test/parallel/test-net-listen-close-server.js b/test/parallel/test-net-listen-close-server.js index 92c7274f328918..0a45adecbe83e7 100644 --- a/test/parallel/test-net-listen-close-server.js +++ b/test/parallel/test-net-listen-close-server.js @@ -1,8 +1,8 @@ 'use strict'; const common = require('../common'); -var net = require('net'); +const net = require('net'); -var server = net.createServer(function(socket) { +const server = net.createServer(function(socket) { }); server.listen(0, common.fail); server.on('error', common.fail); diff --git a/test/parallel/test-net-listen-error.js b/test/parallel/test-net-listen-error.js index 9523fcb2e7f456..7b721d1004f37f 100644 --- a/test/parallel/test-net-listen-error.js +++ b/test/parallel/test-net-listen-error.js @@ -1,8 +1,8 @@ 'use strict'; const common = require('../common'); -var net = require('net'); +const net = require('net'); -var server = net.createServer(function(socket) { +const server = net.createServer(function(socket) { }); server.listen(1, '1.1.1.1', common.fail); // EACCESS or EADDRNOTAVAIL server.on('error', common.mustCall(function(error) {})); diff --git a/test/parallel/test-net-listen-exclusive-random-ports.js b/test/parallel/test-net-listen-exclusive-random-ports.js index f46f9a01d773ce..6b9c750f55ea69 100644 --- a/test/parallel/test-net-listen-exclusive-random-ports.js +++ b/test/parallel/test-net-listen-exclusive-random-ports.js @@ -1,17 +1,17 @@ 'use strict'; require('../common'); -var assert = require('assert'); -var cluster = require('cluster'); -var net = require('net'); +const assert = require('assert'); +const cluster = require('cluster'); +const net = require('net'); function noop() {} if (cluster.isMaster) { - var worker1 = cluster.fork(); + const worker1 = cluster.fork(); worker1.on('message', function(port1) { assert.equal(port1, port1 | 0, 'first worker could not listen'); - var worker2 = cluster.fork(); + const worker2 = cluster.fork(); worker2.on('message', function(port2) { assert.equal(port2, port2 | 0, 'second worker could not listen'); @@ -21,7 +21,7 @@ if (cluster.isMaster) { }); }); } else { - var server = net.createServer(noop); + const server = net.createServer(noop); server.on('error', function(err) { process.send(err.code); diff --git a/test/parallel/test-net-listen-port-option.js b/test/parallel/test-net-listen-port-option.js index 77c9cb42f0a930..c4851bd533dfbe 100644 --- a/test/parallel/test-net-listen-port-option.js +++ b/test/parallel/test-net-listen-port-option.js @@ -1,7 +1,7 @@ 'use strict'; -var common = require('../common'); -var assert = require('assert'); -var net = require('net'); +const common = require('../common'); +const assert = require('assert'); +const net = require('net'); function close() { this.close(); } net.Server().listen({ port: undefined }, close); diff --git a/test/parallel/test-net-listen-shared-ports.js b/test/parallel/test-net-listen-shared-ports.js index 2062dd0ce136bb..ce344be4a6f492 100644 --- a/test/parallel/test-net-listen-shared-ports.js +++ b/test/parallel/test-net-listen-shared-ports.js @@ -1,17 +1,17 @@ 'use strict'; -var common = require('../common'); -var assert = require('assert'); -var cluster = require('cluster'); -var net = require('net'); +const common = require('../common'); +const assert = require('assert'); +const cluster = require('cluster'); +const net = require('net'); function noop() {} if (cluster.isMaster) { - var worker1 = cluster.fork(); + const worker1 = cluster.fork(); worker1.on('message', function(msg) { assert.equal(msg, 'success'); - var worker2 = cluster.fork(); + const worker2 = cluster.fork(); worker2.on('message', function(msg) { assert.equal(msg, 'server2:EADDRINUSE'); @@ -20,8 +20,8 @@ if (cluster.isMaster) { }); }); } else { - var server1 = net.createServer(noop); - var server2 = net.createServer(noop); + const server1 = net.createServer(noop); + const server2 = net.createServer(noop); server1.on('error', function(err) { // no errors expected diff --git a/test/parallel/test-net-local-address-port.js b/test/parallel/test-net-local-address-port.js index 56f8eab5855c46..e6f1bbaa6c7ed7 100644 --- a/test/parallel/test-net-local-address-port.js +++ b/test/parallel/test-net-local-address-port.js @@ -3,7 +3,7 @@ const common = require('../common'); const assert = require('assert'); const net = require('net'); -var server = net.createServer(common.mustCall(function(socket) { +const server = net.createServer(common.mustCall(function(socket) { assert.strictEqual(socket.localAddress, common.localhostIPv4); assert.strictEqual(socket.localPort, this.address().port); socket.on('end', function() { @@ -13,7 +13,8 @@ var server = net.createServer(common.mustCall(function(socket) { })); server.listen(0, common.localhostIPv4, function() { - var client = net.createConnection(this.address().port, common.localhostIPv4); + const client = net.createConnection(this.address().port, + common.localhostIPv4); client.on('connect', function() { client.end(); }); diff --git a/test/parallel/test-net-localport.js b/test/parallel/test-net-localport.js index 4af9dcfd08aeca..b100e4ae768c29 100644 --- a/test/parallel/test-net-localport.js +++ b/test/parallel/test-net-localport.js @@ -1,9 +1,9 @@ 'use strict'; -var common = require('../common'); -var assert = require('assert'); -var net = require('net'); +const common = require('../common'); +const assert = require('assert'); +const net = require('net'); -var server = net.createServer(function(socket) { +const server = net.createServer(function(socket) { console.log(socket.remotePort); assert.strictEqual(socket.remotePort, common.PORT); socket.end(); @@ -11,7 +11,7 @@ var server = net.createServer(function(socket) { server.close(); }); }).listen(0).on('listening', function() { - var client = net.connect({ + const client = net.connect({ host: '127.0.0.1', port: this.address().port, localPort: common.PORT, diff --git a/test/parallel/test-net-pause-resume-connecting.js b/test/parallel/test-net-pause-resume-connecting.js index 6f3e78a94a56df..f441252fed6e70 100644 --- a/test/parallel/test-net-pause-resume-connecting.js +++ b/test/parallel/test-net-pause-resume-connecting.js @@ -9,7 +9,7 @@ let conn; // Server -var server = net.createServer(function(conn) { +const server = net.createServer(function(conn) { connections++; conn.end('This was the year he fell to pieces.'); diff --git a/test/parallel/test-net-persistent-keepalive.js b/test/parallel/test-net-persistent-keepalive.js index d1dfb370167714..6338b5932de1fa 100644 --- a/test/parallel/test-net-persistent-keepalive.js +++ b/test/parallel/test-net-persistent-keepalive.js @@ -1,11 +1,11 @@ 'use strict'; require('../common'); -var assert = require('assert'); -var net = require('net'); +const assert = require('assert'); +const net = require('net'); -var serverConnection; -var clientConnection; -var echoServer = net.createServer(function(connection) { +let serverConnection; +let clientConnection; +const echoServer = net.createServer(function(connection) { serverConnection = connection; setTimeout(function() { // make sure both connections are still open @@ -27,7 +27,7 @@ echoServer.on('listening', function() { clientConnection = new net.Socket(); // send a keepalive packet after 1000 ms // and make sure it persists - var s = clientConnection.setKeepAlive(true, 400); + const s = clientConnection.setKeepAlive(true, 400); assert.ok(s instanceof net.Socket); clientConnection.connect(this.address().port); clientConnection.setTimeout(0); diff --git a/test/parallel/test-net-persistent-nodelay.js b/test/parallel/test-net-persistent-nodelay.js index e23b8718dfee6d..3f94424b0e1197 100644 --- a/test/parallel/test-net-persistent-nodelay.js +++ b/test/parallel/test-net-persistent-nodelay.js @@ -1,18 +1,18 @@ 'use strict'; require('../common'); -var assert = require('assert'); -var net = require('net'); -var TCPWrap = process.binding('tcp_wrap').TCP; +const assert = require('assert'); +const net = require('net'); +const TCPWrap = process.binding('tcp_wrap').TCP; -var echoServer = net.createServer(function(connection) { +const echoServer = net.createServer(function(connection) { connection.end(); }); echoServer.listen(0); -var callCount = 0; +let callCount = 0; -var Socket = net.Socket; -var setNoDelay = TCPWrap.prototype.setNoDelay; +const Socket = net.Socket; +const setNoDelay = TCPWrap.prototype.setNoDelay; TCPWrap.prototype.setNoDelay = function(enable) { setNoDelay.call(this, enable); @@ -20,11 +20,11 @@ TCPWrap.prototype.setNoDelay = function(enable) { }; echoServer.on('listening', function() { - var sock1 = new Socket(); + const sock1 = new Socket(); // setNoDelay before the handle is created // there is probably a better way to test this - var s = sock1.setNoDelay(); + const s = sock1.setNoDelay(); assert.ok(s instanceof net.Socket); sock1.connect(this.address().port); sock1.on('end', function() { diff --git a/test/parallel/test-net-persistent-ref-unref.js b/test/parallel/test-net-persistent-ref-unref.js index 32782e7c591444..1d3cbc6ffaef18 100644 --- a/test/parallel/test-net-persistent-ref-unref.js +++ b/test/parallel/test-net-persistent-ref-unref.js @@ -1,17 +1,17 @@ 'use strict'; require('../common'); -var assert = require('assert'); -var net = require('net'); -var TCPWrap = process.binding('tcp_wrap').TCP; +const assert = require('assert'); +const net = require('net'); +const TCPWrap = process.binding('tcp_wrap').TCP; -var echoServer = net.createServer(function(conn) { +const echoServer = net.createServer(function(conn) { conn.end(); }); -var ref = TCPWrap.prototype.ref; -var unref = TCPWrap.prototype.unref; +const ref = TCPWrap.prototype.ref; +const unref = TCPWrap.prototype.unref; -var refCount = 0; +let refCount = 0; TCPWrap.prototype.ref = function() { ref.call(this); @@ -28,7 +28,7 @@ TCPWrap.prototype.unref = function() { echoServer.listen(0); echoServer.on('listening', function() { - var sock = new net.Socket(); + const sock = new net.Socket(); sock.unref(); sock.ref(); sock.connect(this.address().port); diff --git a/test/parallel/test-net-pingpong.js b/test/parallel/test-net-pingpong.js index b49b3a78778719..9280991f39e5d9 100644 --- a/test/parallel/test-net-pingpong.js +++ b/test/parallel/test-net-pingpong.js @@ -5,9 +5,9 @@ const net = require('net'); function pingPongTest(port, host) { const N = 1000; - var count = 0; - var sentPongs = 0; - var sent_final_ping = false; + let count = 0; + let sentPongs = 0; + let sent_final_ping = false; const server = net.createServer( { allowHalfOpen: true }, diff --git a/test/parallel/test-net-pipe-connect-errors.js b/test/parallel/test-net-pipe-connect-errors.js index 3e00befc341682..2c1332efa11429 100644 --- a/test/parallel/test-net-pipe-connect-errors.js +++ b/test/parallel/test-net-pipe-connect-errors.js @@ -8,7 +8,7 @@ const assert = require('assert'); // Test if ENOTSOCK is fired when trying to connect to a file which is not // a socket. -var emptyTxt; +let emptyTxt; if (common.isWindows) { // on Win, common.PIPE will be a named pipe, so we use an existing empty @@ -34,7 +34,7 @@ if (common.isWindows) { fs.writeFileSync(emptyTxt, ''); } -var notSocketClient = net.createConnection(emptyTxt, function() { +const notSocketClient = net.createConnection(emptyTxt, function() { common.fail('connection callback should not run'); }); @@ -45,7 +45,7 @@ notSocketClient.on('error', common.mustCall(function(err) { // Trying to connect to not-existing socket should result in ENOENT error -var noEntSocketClient = net.createConnection('no-ent-file', function() { +const noEntSocketClient = net.createConnection('no-ent-file', function() { common.fail('connection to non-existent socket, callback should not run'); }); @@ -63,7 +63,7 @@ if (!common.isWindows && process.getuid() !== 0) { accessServer.listen(common.PIPE, common.mustCall(function() { fs.chmodSync(common.PIPE, 0); - var accessClient = net.createConnection(common.PIPE, function() { + const accessClient = net.createConnection(common.PIPE, function() { common.fail('connection should get EACCES, callback should not run'); }); diff --git a/test/parallel/test-net-reconnect.js b/test/parallel/test-net-reconnect.js index 980de2637b18bf..47171093ca13f9 100644 --- a/test/parallel/test-net-reconnect.js +++ b/test/parallel/test-net-reconnect.js @@ -1,15 +1,15 @@ 'use strict'; require('../common'); -var assert = require('assert'); +const assert = require('assert'); -var net = require('net'); +const net = require('net'); -var N = 50; -var client_recv_count = 0; -var client_end_count = 0; -var disconnect_count = 0; +const N = 50; +let client_recv_count = 0; +let client_end_count = 0; +let disconnect_count = 0; -var server = net.createServer(function(socket) { +const server = net.createServer(function(socket) { console.error('SERVER: got socket connection'); socket.resume(); @@ -29,7 +29,7 @@ var server = net.createServer(function(socket) { server.listen(0, function() { console.log('SERVER listening'); - var client = net.createConnection(this.address().port); + const client = net.createConnection(this.address().port); client.setEncoding('UTF8'); diff --git a/test/parallel/test-net-remote-address-port.js b/test/parallel/test-net-remote-address-port.js index 62a7ebfe572908..96e2049f9e32fa 100644 --- a/test/parallel/test-net-remote-address-port.js +++ b/test/parallel/test-net-remote-address-port.js @@ -4,15 +4,15 @@ const assert = require('assert'); const net = require('net'); -var conns_closed = 0; +let conns_closed = 0; -var remoteAddrCandidates = [ common.localhostIPv4 ]; +const remoteAddrCandidates = [ common.localhostIPv4 ]; if (common.hasIPv6) remoteAddrCandidates.push('::ffff:127.0.0.1'); -var remoteFamilyCandidates = ['IPv4']; +const remoteFamilyCandidates = ['IPv4']; if (common.hasIPv6) remoteFamilyCandidates.push('IPv6'); -var server = net.createServer(common.mustCall(function(socket) { +const server = net.createServer(common.mustCall(function(socket) { assert.notEqual(-1, remoteAddrCandidates.indexOf(socket.remoteAddress)); assert.notEqual(-1, remoteFamilyCandidates.indexOf(socket.remoteFamily)); assert.ok(socket.remotePort); @@ -28,8 +28,8 @@ var server = net.createServer(common.mustCall(function(socket) { }, 2)); server.listen(0, 'localhost', function() { - var client = net.createConnection(this.address().port, 'localhost'); - var client2 = net.createConnection(this.address().port); + const client = net.createConnection(this.address().port, 'localhost'); + const client2 = net.createConnection(this.address().port); client.on('connect', function() { assert.notEqual(-1, remoteAddrCandidates.indexOf(client.remoteAddress)); assert.notEqual(-1, remoteFamilyCandidates.indexOf(client.remoteFamily)); diff --git a/test/parallel/test-net-server-bind.js b/test/parallel/test-net-server-bind.js index c77341418c2c6d..e4dc64216441cf 100644 --- a/test/parallel/test-net-server-bind.js +++ b/test/parallel/test-net-server-bind.js @@ -1,13 +1,13 @@ 'use strict'; -var common = require('../common'); -var assert = require('assert'); -var net = require('net'); +const common = require('../common'); +const assert = require('assert'); +const net = require('net'); // With only a callback, server should get a port assigned by the OS -var address0; -var server0 = net.createServer(function(socket) { }); +let address0; +const server0 = net.createServer(function(socket) { }); server0.listen(function() { address0 = server0.address(); @@ -18,9 +18,9 @@ server0.listen(function() { // No callback to listen(), assume we can bind in 100 ms -var address1; -var connectionKey1; -var server1 = net.createServer(function(socket) { }); +let address1; +let connectionKey1; +const server1 = net.createServer(function(socket) { }); server1.listen(common.PORT); @@ -34,8 +34,8 @@ setTimeout(function() { // Callback to listen() -var address2; -var server2 = net.createServer(function(socket) { }); +let address2; +const server2 = net.createServer(function(socket) { }); server2.listen(common.PORT + 1, function() { address2 = server2.address(); @@ -46,8 +46,8 @@ server2.listen(common.PORT + 1, function() { // Backlog argument -var address3; -var server3 = net.createServer(function(socket) { }); +let address3; +const server3 = net.createServer(function(socket) { }); server3.listen(common.PORT + 2, '0.0.0.0', 127, function() { address3 = server3.address(); @@ -58,8 +58,8 @@ server3.listen(common.PORT + 2, '0.0.0.0', 127, function() { // Backlog argument without host argument -var address4; -var server4 = net.createServer(function(socket) { }); +let address4; +const server4 = net.createServer(function(socket) { }); server4.listen(common.PORT + 3, 127, function() { address4 = server4.address(); @@ -72,7 +72,7 @@ process.on('exit', function() { assert.ok(address0.port > 100); assert.equal(common.PORT, address1.port); - var expectedConnectionKey1; + let expectedConnectionKey1; if (address1.family === 'IPv6') expectedConnectionKey1 = '6::::' + address1.port; diff --git a/test/parallel/test-net-server-close.js b/test/parallel/test-net-server-close.js index 006ca529c79ab3..c44dc230c90662 100644 --- a/test/parallel/test-net-server-close.js +++ b/test/parallel/test-net-server-close.js @@ -1,10 +1,10 @@ 'use strict'; require('../common'); -var assert = require('assert'); -var net = require('net'); +const assert = require('assert'); +const net = require('net'); -var events = []; -var sockets = []; +const events = []; +const sockets = []; process.on('exit', function() { assert.equal(server.connections, 0); @@ -15,7 +15,7 @@ process.on('exit', function() { assert.equal(events.join(' ').match(/client/g).length, 2); }); -var server = net.createServer(function(c) { +let server = net.createServer(function(c) { c.on('close', function() { events.push('client'); }); diff --git a/test/parallel/test-net-server-connections.js b/test/parallel/test-net-server-connections.js index ae89d9aac7b3f7..4e41d29a505199 100644 --- a/test/parallel/test-net-server-connections.js +++ b/test/parallel/test-net-server-connections.js @@ -1,12 +1,12 @@ 'use strict'; require('../common'); -var assert = require('assert'); +const assert = require('assert'); -var net = require('net'); +const net = require('net'); // test that server.connections property is no longer enumerable now that it // has been marked as deprecated -var server = new net.Server(); +const server = new net.Server(); assert.equal(Object.keys(server).indexOf('connections'), -1); diff --git a/test/parallel/test-net-server-listen-remove-callback.js b/test/parallel/test-net-server-listen-remove-callback.js index 9bdfd628072798..a678922683eeb1 100644 --- a/test/parallel/test-net-server-listen-remove-callback.js +++ b/test/parallel/test-net-server-listen-remove-callback.js @@ -1,13 +1,13 @@ 'use strict'; require('../common'); -var assert = require('assert'); -var net = require('net'); +const assert = require('assert'); +const net = require('net'); // Server should only fire listen callback once -var server = net.createServer(); +const server = net.createServer(); server.on('close', function() { - var listeners = server.listeners('listening'); + const listeners = server.listeners('listening'); console.log('Closed, listeners:', listeners.length); assert.equal(0, listeners.length); }); diff --git a/test/parallel/test-net-server-max-connections-close-makes-more-available.js b/test/parallel/test-net-server-max-connections-close-makes-more-available.js index fb9831d05b3e50..06233f6c8633ed 100644 --- a/test/parallel/test-net-server-max-connections-close-makes-more-available.js +++ b/test/parallel/test-net-server-max-connections-close-makes-more-available.js @@ -1,8 +1,8 @@ 'use strict'; const common = require('../common'); -var assert = require('assert'); +const assert = require('assert'); -var net = require('net'); +const net = require('net'); // Sets the server's maxConnections property to 1. // Open 2 connections (connection 0 and connection 1). @@ -13,16 +13,16 @@ var net = require('net'); // Connection 2 should be accepted. // Connection 3 should be rejected. -var connections = []; -var received = []; -var sent = []; +const connections = []; +const received = []; +const sent = []; -var createConnection = function(index) { +const createConnection = function(index) { console.error('creating connection ' + index); return new Promise(function(resolve, reject) { - var connection = net.createConnection(server.address().port, function() { - var msg = '' + index; + const connection = net.createConnection(server.address().port, function() { + const msg = '' + index; console.error('sending message: ' + msg); this.write(msg); sent.push(msg); @@ -47,7 +47,7 @@ var createConnection = function(index) { }); }; -var closeConnection = function(index) { +const closeConnection = function(index) { console.error('closing connection ' + index); return new Promise(function(resolve, reject) { connections[index].on('end', function() { @@ -57,7 +57,7 @@ var closeConnection = function(index) { }); }; -var server = net.createServer(function(socket) { +let server = net.createServer(function(socket) { socket.on('data', function(data) { console.error('received message: ' + data); received.push('' + data); diff --git a/test/parallel/test-net-server-max-connections.js b/test/parallel/test-net-server-max-connections.js index 99d3b345f40974..f560a7dafc4446 100644 --- a/test/parallel/test-net-server-max-connections.js +++ b/test/parallel/test-net-server-max-connections.js @@ -9,7 +9,7 @@ const net = require('net'); // and the last 10 connections are rejected. const N = 20; -var closes = 0; +let closes = 0; const waits = []; const server = net.createServer(common.mustCall(function(connection) { @@ -26,7 +26,7 @@ server.maxConnections = N / 2; function makeConnection(index) { const c = net.createConnection(server.address().port); - var gotData = false; + let gotData = false; c.on('connect', function() { if (index + 1 < N) { @@ -45,7 +45,7 @@ function makeConnection(index) { } if (closes === N / 2) { - var cb; + let cb; console.error('calling wait callback.'); while (cb = waits.shift()) { cb(); diff --git a/test/parallel/test-net-server-pause-on-connect.js b/test/parallel/test-net-server-pause-on-connect.js index 798175737b80b3..ee5ac4e2807b0a 100644 --- a/test/parallel/test-net-server-pause-on-connect.js +++ b/test/parallel/test-net-server-pause-on-connect.js @@ -3,8 +3,8 @@ const common = require('../common'); const assert = require('assert'); const net = require('net'); const msg = 'test'; -var stopped = true; -var server1Sock; +let stopped = true; +let server1Sock; const server1ConnHandler = function(socket) { diff --git a/test/parallel/test-net-server-unref-persistent.js b/test/parallel/test-net-server-unref-persistent.js index d68e94cfbda8c8..beb91832ea9448 100644 --- a/test/parallel/test-net-server-unref-persistent.js +++ b/test/parallel/test-net-server-unref-persistent.js @@ -1,7 +1,7 @@ 'use strict'; const common = require('../common'); -var net = require('net'); -var server = net.createServer(); +const net = require('net'); +const server = net.createServer(); // unref before listening server.unref(); diff --git a/test/parallel/test-net-server-unref.js b/test/parallel/test-net-server-unref.js index 91b25887a28d3e..60df9fc700ec64 100644 --- a/test/parallel/test-net-server-unref.js +++ b/test/parallel/test-net-server-unref.js @@ -1,8 +1,8 @@ 'use strict'; const common = require('../common'); -var net = require('net'); +const net = require('net'); -var s = net.createServer(); +const s = net.createServer(); s.listen(0); s.unref(); diff --git a/test/parallel/test-net-socket-destroy-twice.js b/test/parallel/test-net-socket-destroy-twice.js index 917e9849999b05..998ad05a1d6487 100644 --- a/test/parallel/test-net-socket-destroy-twice.js +++ b/test/parallel/test-net-socket-destroy-twice.js @@ -1,8 +1,8 @@ 'use strict'; -var common = require('../common'); -var net = require('net'); +const common = require('../common'); +const net = require('net'); -var conn = net.createConnection(common.PORT); +const conn = net.createConnection(common.PORT); conn.on('error', common.mustCall(function() { conn.destroy(); diff --git a/test/parallel/test-net-socket-local-address.js b/test/parallel/test-net-socket-local-address.js index 82f174dc2c1924..e888667eab4c4f 100644 --- a/test/parallel/test-net-socket-local-address.js +++ b/test/parallel/test-net-socket-local-address.js @@ -9,9 +9,9 @@ if (common.inFreeBSDJail) { return; } -var conns = 0; -var clientLocalPorts = []; -var serverRemotePorts = []; +let conns = 0; +const clientLocalPorts = []; +const serverRemotePorts = []; const client = new net.Socket(); const server = net.createServer((socket) => { serverRemotePorts.push(socket.remotePort); diff --git a/test/parallel/test-net-socket-timeout-unref.js b/test/parallel/test-net-socket-timeout-unref.js index fb4f6a658e21d2..1789ec7a1cabbd 100644 --- a/test/parallel/test-net-socket-timeout-unref.js +++ b/test/parallel/test-net-socket-timeout-unref.js @@ -12,7 +12,7 @@ const server = net.createServer(function(c) { server.listen(0); server.unref(); -var connections = 0; +let connections = 0; const sockets = []; const delays = [8, 5, 3, 6, 2, 4]; diff --git a/test/parallel/test-net-stream.js b/test/parallel/test-net-stream.js index d090038ce753be..9d091bd66f3a1e 100644 --- a/test/parallel/test-net-stream.js +++ b/test/parallel/test-net-stream.js @@ -1,9 +1,9 @@ 'use strict'; require('../common'); -var assert = require('assert'); -var net = require('net'); +const assert = require('assert'); +const net = require('net'); -var s = new net.Stream(); +const s = new net.Stream(); // test that destroy called on a stream with a server only ever decrements the // server connection count once @@ -18,11 +18,11 @@ assert.equal(9, s.server.connections); s.destroy(); assert.equal(9, s.server.connections); -var SIZE = 2E6; -var N = 10; -var buf = Buffer.alloc(SIZE, 'a'); +const SIZE = 2E6; +const N = 10; +const buf = Buffer.alloc(SIZE, 'a'); -var server = net.createServer(function(socket) { +const server = net.createServer(function(socket) { socket.setNoDelay(); socket.on('error', function(err) { @@ -31,13 +31,13 @@ var server = net.createServer(function(socket) { server.close(); }); - for (var i = 0; i < N; ++i) { + for (let i = 0; i < N; ++i) { socket.write(buf, function() { }); } socket.end(); }).listen(0, function() { - var conn = net.connect(this.address().port); + const conn = net.connect(this.address().port); conn.on('data', function(buf) { conn.pause(); setTimeout(function() { diff --git a/test/parallel/test-net-write-after-close.js b/test/parallel/test-net-write-after-close.js index e01aef80f3635b..0a1dcd98b2b3c7 100644 --- a/test/parallel/test-net-write-after-close.js +++ b/test/parallel/test-net-write-after-close.js @@ -1,8 +1,8 @@ 'use strict'; const common = require('../common'); -var net = require('net'); +const net = require('net'); -var server = net.createServer(common.mustCall(function(socket) { +const server = net.createServer(common.mustCall(function(socket) { socket.resume(); socket.on('error', common.mustCall(function(error) { @@ -17,7 +17,7 @@ var server = net.createServer(common.mustCall(function(socket) { })); server.listen(0, function() { - var client = net.connect(this.address().port, function() { + const client = net.connect(this.address().port, function() { client.end(); }); }); diff --git a/test/parallel/test-net-write-connect-write.js b/test/parallel/test-net-write-connect-write.js index 315db6bc02b309..ee20ede49fb5a5 100644 --- a/test/parallel/test-net-write-connect-write.js +++ b/test/parallel/test-net-write-connect-write.js @@ -1,13 +1,13 @@ 'use strict'; const common = require('../common'); -var assert = require('assert'); -var net = require('net'); +const assert = require('assert'); +const net = require('net'); -var server = net.createServer(function(socket) { +const server = net.createServer(function(socket) { socket.pipe(socket); }).listen(0, common.mustCall(function() { - var conn = net.connect(this.address().port); - var received = ''; + const conn = net.connect(this.address().port); + let received = ''; conn.setEncoding('utf8'); conn.write('before'); diff --git a/test/parallel/test-net-write-slow.js b/test/parallel/test-net-write-slow.js index 6054e2b7882ac2..c1b2c60e2e202a 100644 --- a/test/parallel/test-net-write-slow.js +++ b/test/parallel/test-net-write-slow.js @@ -1,22 +1,22 @@ 'use strict'; const common = require('../common'); -var assert = require('assert'); -var net = require('net'); +const assert = require('assert'); +const net = require('net'); -var SIZE = 2E5; -var N = 10; -var flushed = 0; -var received = 0; -var buf = Buffer.alloc(SIZE, 'a'); +const SIZE = 2E5; +const N = 10; +let flushed = 0; +let received = 0; +const buf = Buffer.alloc(SIZE, 'a'); -var server = net.createServer(function(socket) { +const server = net.createServer(function(socket) { socket.setNoDelay(); socket.setTimeout(9999); socket.on('timeout', function() { common.fail(`flushed: ${flushed}, received: ${received}/${SIZE * N}`); }); - for (var i = 0; i < N; ++i) { + for (let i = 0; i < N; ++i) { socket.write(buf, function() { ++flushed; if (flushed === N) { @@ -27,7 +27,7 @@ var server = net.createServer(function(socket) { socket.end(); }).listen(0, common.mustCall(function() { - var conn = net.connect(this.address().port); + const conn = net.connect(this.address().port); conn.on('data', function(buf) { received += buf.length; conn.pause(); diff --git a/test/parallel/test-next-tick-domain.js b/test/parallel/test-next-tick-domain.js index 8f9d9bb4aa50f7..6edb7e3050c067 100644 --- a/test/parallel/test-next-tick-domain.js +++ b/test/parallel/test-next-tick-domain.js @@ -1,8 +1,8 @@ 'use strict'; require('../common'); -var assert = require('assert'); +const assert = require('assert'); -var origNextTick = process.nextTick; +const origNextTick = process.nextTick; require('domain'); diff --git a/test/parallel/test-next-tick-errors.js b/test/parallel/test-next-tick-errors.js index 180b769eaa105b..4f47c3f954d92e 100644 --- a/test/parallel/test-next-tick-errors.js +++ b/test/parallel/test-next-tick-errors.js @@ -1,6 +1,6 @@ 'use strict'; require('../common'); -var assert = require('assert'); +const assert = require('assert'); const order = []; let exceptionHandled = false; diff --git a/test/parallel/test-next-tick-intentional-starvation.js b/test/parallel/test-next-tick-intentional-starvation.js index 414524e5405ecc..ee829c94ab6929 100644 --- a/test/parallel/test-next-tick-intentional-starvation.js +++ b/test/parallel/test-next-tick-intentional-starvation.js @@ -1,6 +1,6 @@ 'use strict'; require('../common'); -var assert = require('assert'); +const assert = require('assert'); // this is the inverse of test-next-tick-starvation. // it verifies that process.nextTick will *always* come before other @@ -9,14 +9,14 @@ var assert = require('assert'); // WARNING: unsafe! process.maxTickDepth = Infinity; -var ran = false; -var starved = false; -var start = +new Date(); -var timerRan = false; +let ran = false; +let starved = false; +const start = +new Date(); +let timerRan = false; function spin() { ran = true; - var now = +new Date(); + const now = +new Date(); if (now - start > 100) { console.log('The timer is starving, just as we planned.'); starved = true; diff --git a/test/parallel/test-next-tick-ordering.js b/test/parallel/test-next-tick-ordering.js index 63f8d37828e53c..2f13147d8ed733 100644 --- a/test/parallel/test-next-tick-ordering.js +++ b/test/parallel/test-next-tick-ordering.js @@ -1,10 +1,10 @@ 'use strict'; require('../common'); -var assert = require('assert'); -var i; +const assert = require('assert'); +let i; -var N = 30; -var done = []; +const N = 30; +const done = []; function get_printer(timeout) { return function() { diff --git a/test/parallel/test-next-tick-ordering2.js b/test/parallel/test-next-tick-ordering2.js index 11ac84b5319dda..7cfec867f3ed01 100644 --- a/test/parallel/test-next-tick-ordering2.js +++ b/test/parallel/test-next-tick-ordering2.js @@ -1,8 +1,8 @@ 'use strict'; require('../common'); -var assert = require('assert'); +const assert = require('assert'); -var order = []; +const order = []; process.nextTick(function() { setTimeout(function() { order.push('setTimeout'); diff --git a/test/parallel/test-next-tick.js b/test/parallel/test-next-tick.js index 2a98b46da10f17..3001ad0e561a77 100644 --- a/test/parallel/test-next-tick.js +++ b/test/parallel/test-next-tick.js @@ -1,6 +1,6 @@ 'use strict'; const common = require('../common'); -var assert = require('assert'); +const assert = require('assert'); process.nextTick(common.mustCall(function() { process.nextTick(common.mustCall(function() { @@ -14,7 +14,7 @@ setTimeout(common.mustCall(function() { process.nextTick(common.mustCall(function() {})); -var obj = {}; +const obj = {}; process.nextTick(function(a, b) { assert.equal(a, 42); diff --git a/test/parallel/test-path-makelong.js b/test/parallel/test-path-makelong.js index 50a77e9d87b8dc..293d6284f173bc 100644 --- a/test/parallel/test-path-makelong.js +++ b/test/parallel/test-path-makelong.js @@ -1,11 +1,11 @@ 'use strict'; const common = require('../common'); -var assert = require('assert'); -var path = require('path'); +const assert = require('assert'); +const path = require('path'); if (common.isWindows) { - var file = path.join(common.fixturesDir, 'a.js'); - var resolvedFile = path.resolve(file); + const file = path.join(common.fixturesDir, 'a.js'); + const resolvedFile = path.resolve(file); assert.equal('\\\\?\\' + resolvedFile, path._makeLong(file)); assert.equal('\\\\?\\' + resolvedFile, path._makeLong('\\\\?\\' + file)); diff --git a/test/parallel/test-path-parse-format.js b/test/parallel/test-path-parse-format.js index aaa92111074099..b316dc5e754a8b 100644 --- a/test/parallel/test-path-parse-format.js +++ b/test/parallel/test-path-parse-format.js @@ -170,7 +170,7 @@ function checkErrors(path) { function checkParseFormat(path, paths) { paths.forEach(function(element) { - var output = path.parse(element); + const output = path.parse(element); assert.strictEqual(typeof output.root, 'string'); assert.strictEqual(typeof output.dir, 'string'); assert.strictEqual(typeof output.base, 'string'); diff --git a/test/parallel/test-path.js b/test/parallel/test-path.js index 49d77bd440aa0d..6f2ea3fd48ad55 100644 --- a/test/parallel/test-path.js +++ b/test/parallel/test-path.js @@ -453,9 +453,9 @@ if (common.isWindows) { // See https://github.com/nodejs/node/issues/7215 const currentDriveLetter = path.parse(process.cwd()).root.substring(0, 2); const resolveFixture = path.join(common.fixturesDir, 'path-resolve.js'); - var spawnResult = child.spawnSync( + const spawnResult = child.spawnSync( process.argv[0], [resolveFixture, currentDriveLetter]); - var resolvedPath = spawnResult.stdout.toString().trim(); + const resolvedPath = spawnResult.stdout.toString().trim(); assert.equal(resolvedPath.toLowerCase(), process.cwd().toLowerCase()); } diff --git a/test/parallel/test-pipe-address.js b/test/parallel/test-pipe-address.js index 85e3daa3522e78..49f6802d3f7c7a 100644 --- a/test/parallel/test-pipe-address.js +++ b/test/parallel/test-pipe-address.js @@ -1,8 +1,8 @@ 'use strict'; -var common = require('../common'); -var assert = require('assert'); -var net = require('net'); -var server = net.createServer(common.fail); +const common = require('../common'); +const assert = require('assert'); +const net = require('net'); +const server = net.createServer(common.fail); common.refreshTmpDir(); diff --git a/test/parallel/test-pipe-return-val.js b/test/parallel/test-pipe-return-val.js index a14f925916bee0..5e6e83dbc7a952 100644 --- a/test/parallel/test-pipe-return-val.js +++ b/test/parallel/test-pipe-return-val.js @@ -2,11 +2,11 @@ // This test ensures SourceStream.pipe(DestStream) returns DestStream require('../common'); -var Stream = require('stream').Stream; -var assert = require('assert'); +const Stream = require('stream').Stream; +const assert = require('assert'); -var sourceStream = new Stream(); -var destStream = new Stream(); -var result = sourceStream.pipe(destStream); +const sourceStream = new Stream(); +const destStream = new Stream(); +const result = sourceStream.pipe(destStream); assert.strictEqual(result, destStream); diff --git a/test/parallel/test-pipe-stream.js b/test/parallel/test-pipe-stream.js index 6298495087ac06..2776ba868e6963 100644 --- a/test/parallel/test-pipe-stream.js +++ b/test/parallel/test-pipe-stream.js @@ -1,13 +1,13 @@ 'use strict'; -var common = require('../common'); -var assert = require('assert'); -var net = require('net'); +const common = require('../common'); +const assert = require('assert'); +const net = require('net'); common.refreshTmpDir(); function test(clazz, cb) { - var have_ping = false; - var have_pong = false; + let have_ping = false; + let have_pong = false; function check() { assert.ok(have_ping); @@ -15,7 +15,7 @@ function test(clazz, cb) { } function ping() { - var conn = new clazz(); + const conn = new clazz(); conn.on('error', function(err) { throw err; @@ -48,11 +48,11 @@ function test(clazz, cb) { }); } - var timeout = setTimeout(function() { + const timeout = setTimeout(function() { server.close(); }, 2000); - var server = net.Server(); + let server = net.Server(); server.listen(common.PIPE, ping); server.on('connection', pong); server.on('close', function() { diff --git a/test/parallel/test-pipe-unref.js b/test/parallel/test-pipe-unref.js index 35c25524b4cfc8..34b5ef651bf6aa 100644 --- a/test/parallel/test-pipe-unref.js +++ b/test/parallel/test-pipe-unref.js @@ -1,10 +1,10 @@ 'use strict'; -var common = require('../common'); -var net = require('net'); +const common = require('../common'); +const net = require('net'); common.refreshTmpDir(); -var s = net.Server(); +const s = net.Server(); s.listen(common.PIPE); s.unref(); diff --git a/test/parallel/test-preload.js b/test/parallel/test-preload.js index 8cae173f87ae37..88b441d887df54 100644 --- a/test/parallel/test-preload.js +++ b/test/parallel/test-preload.js @@ -14,7 +14,7 @@ if (common.isSunOS) { const nodeBinary = process.argv[0]; const preloadOption = function(preloads) { - var option = ''; + let option = ''; preloads.forEach(function(preload, index) { option += '-r ' + preload + ' '; }); @@ -75,7 +75,7 @@ const stdinProc = childProcess.spawn( {stdio: 'pipe'} ); stdinProc.stdin.end("console.log('hello');"); -var stdinStdout = ''; +let stdinStdout = ''; stdinProc.stdout.on('data', function(d) { stdinStdout += d; }); @@ -91,7 +91,7 @@ const replProc = childProcess.spawn( {stdio: 'pipe'} ); replProc.stdin.end('.exit\n'); -var replStdout = ''; +let replStdout = ''; replProc.stdout.on('data', function(d) { replStdout += d; }); diff --git a/test/parallel/test-process-argv-0.js b/test/parallel/test-process-argv-0.js index c3aacb60fa5403..d6b4bfe232323e 100644 --- a/test/parallel/test-process-argv-0.js +++ b/test/parallel/test-process-argv-0.js @@ -1,15 +1,15 @@ 'use strict'; require('../common'); -var path = require('path'); -var assert = require('assert'); -var spawn = require('child_process').spawn; +const path = require('path'); +const assert = require('assert'); +const spawn = require('child_process').spawn; if (process.argv[2] !== 'child') { - var child = spawn(process.execPath, [__filename, 'child'], { + const child = spawn(process.execPath, [__filename, 'child'], { cwd: path.dirname(process.execPath) }); - var childArgv0 = ''; + let childArgv0 = ''; child.stdout.on('data', function(chunk) { childArgv0 += chunk; }); diff --git a/test/parallel/test-process-before-exit.js b/test/parallel/test-process-before-exit.js index 5d8855869a8e4a..ec7a7f76e57ef9 100644 --- a/test/parallel/test-process-before-exit.js +++ b/test/parallel/test-process-before-exit.js @@ -1,9 +1,9 @@ 'use strict'; require('../common'); -var assert = require('assert'); +const assert = require('assert'); -var N = 5; -var n = 0; +const N = 5; +let n = 0; function f() { if (++n < N) setTimeout(f, 5); diff --git a/test/parallel/test-process-binding.js b/test/parallel/test-process-binding.js index 722e9333aff60a..475891aa5d30d8 100644 --- a/test/parallel/test-process-binding.js +++ b/test/parallel/test-process-binding.js @@ -1,6 +1,6 @@ 'use strict'; require('../common'); -var assert = require('assert'); +const assert = require('assert'); assert.throws( function() { diff --git a/test/parallel/test-process-config.js b/test/parallel/test-process-config.js index ab38a48e5aacdd..a1767464fd5978 100644 --- a/test/parallel/test-process-config.js +++ b/test/parallel/test-process-config.js @@ -1,8 +1,8 @@ 'use strict'; require('../common'); -var assert = require('assert'); -var fs = require('fs'); -var path = require('path'); +const assert = require('assert'); +const fs = require('fs'); +const path = require('path'); // check for existence assert(process.hasOwnProperty('config')); @@ -10,8 +10,8 @@ assert(process.hasOwnProperty('config')); // ensure that `process.config` is an Object assert.strictEqual(Object(process.config), process.config); -var configPath = path.resolve(__dirname, '..', '..', 'config.gypi'); -var config = fs.readFileSync(configPath, 'utf8'); +const configPath = path.resolve(__dirname, '..', '..', 'config.gypi'); +let config = fs.readFileSync(configPath, 'utf8'); // clean up comment at the first line config = config.split('\n').slice(1).join('\n').replace(/'/g, '"'); diff --git a/test/parallel/test-process-exec-argv.js b/test/parallel/test-process-exec-argv.js index e32971ae81a893..8125850b424d84 100644 --- a/test/parallel/test-process-exec-argv.js +++ b/test/parallel/test-process-exec-argv.js @@ -1,15 +1,15 @@ 'use strict'; require('../common'); -var assert = require('assert'); -var spawn = require('child_process').spawn; +const assert = require('assert'); +const spawn = require('child_process').spawn; if (process.argv[2] === 'child') { process.stdout.write(JSON.stringify(process.execArgv)); } else { - var execArgv = ['--stack-size=256']; - var args = [__filename, 'child', 'arg0']; - var child = spawn(process.execPath, execArgv.concat(args)); - var out = ''; + const execArgv = ['--stack-size=256']; + const args = [__filename, 'child', 'arg0']; + const child = spawn(process.execPath, execArgv.concat(args)); + let out = ''; child.stdout.on('data', function(chunk) { out += chunk; diff --git a/test/parallel/test-process-exit-code.js b/test/parallel/test-process-exit-code.js index 8d657528d05561..337502ffcb30e8 100644 --- a/test/parallel/test-process-exit-code.js +++ b/test/parallel/test-process-exit-code.js @@ -1,6 +1,6 @@ 'use strict'; require('../common'); -var assert = require('assert'); +const assert = require('assert'); switch (process.argv[2]) { case 'child1': @@ -70,10 +70,10 @@ function parent() { } function test(arg, exit) { - var spawn = require('child_process').spawn; - var node = process.execPath; - var f = __filename; - var option = { stdio: [ 0, 1, 'ignore' ] }; + const spawn = require('child_process').spawn; + const node = process.execPath; + const f = __filename; + const option = { stdio: [ 0, 1, 'ignore' ] }; spawn(node, [f, arg], option).on('exit', function(code) { assert.equal(code, exit, 'wrong exit for ' + arg + '\nexpected:' + exit + diff --git a/test/parallel/test-process-exit-from-before-exit.js b/test/parallel/test-process-exit-from-before-exit.js index b37df0a5bd340d..82458217c6f062 100644 --- a/test/parallel/test-process-exit-from-before-exit.js +++ b/test/parallel/test-process-exit-from-before-exit.js @@ -1,5 +1,5 @@ 'use strict'; -var common = require('../common'); +const common = require('../common'); process.on('beforeExit', common.mustCall(function() { setTimeout(common.fail, 5); diff --git a/test/parallel/test-process-exit-recursive.js b/test/parallel/test-process-exit-recursive.js index 53426a6b1cdaf0..1634aad15497f5 100644 --- a/test/parallel/test-process-exit-recursive.js +++ b/test/parallel/test-process-exit-recursive.js @@ -1,9 +1,9 @@ 'use strict'; require('../common'); -var assert = require('assert'); +const assert = require('assert'); // recursively calling .exit() should not overflow the call stack -var nexits = 0; +let nexits = 0; process.on('exit', function(code) { assert.equal(nexits++, 0); diff --git a/test/parallel/test-process-exit.js b/test/parallel/test-process-exit.js index 0ea36f158eaf9b..f7df7737ed1531 100644 --- a/test/parallel/test-process-exit.js +++ b/test/parallel/test-process-exit.js @@ -1,9 +1,9 @@ 'use strict'; require('../common'); -var assert = require('assert'); +const assert = require('assert'); // calling .exit() from within "exit" should not overflow the call stack -var nexits = 0; +let nexits = 0; process.on('exit', function(code) { assert.equal(nexits++, 0); diff --git a/test/parallel/test-process-getactivehandles.js b/test/parallel/test-process-getactivehandles.js index a9222c984b30ca..8ceb2bcd2a32f7 100644 --- a/test/parallel/test-process-getactivehandles.js +++ b/test/parallel/test-process-getactivehandles.js @@ -6,7 +6,7 @@ const net = require('net'); const NUM = 8; const connections = []; const clients = []; -var clients_counter = 0; +let clients_counter = 0; const server = net.createServer(function listener(c) { connections.push(c); diff --git a/test/parallel/test-process-getgroups.js b/test/parallel/test-process-getgroups.js index 002ec7c1ab4c7c..87b5a29863f2ed 100644 --- a/test/parallel/test-process-getgroups.js +++ b/test/parallel/test-process-getgroups.js @@ -1,7 +1,7 @@ 'use strict'; const common = require('../common'); -var assert = require('assert'); -var exec = require('child_process').exec; +const assert = require('assert'); +const exec = require('child_process').exec; if (common.isOSX) { common.skip('Output of `id -G` is unreliable on Darwin.'); @@ -9,12 +9,12 @@ if (common.isOSX) { } if (typeof process.getgroups === 'function') { - var groups = process.getgroups(); + const groups = process.getgroups(); assert(Array.isArray(groups)); assert(groups.length > 0); exec('id -G', function(err, stdout) { if (err) throw err; - var real_groups = stdout.match(/\d+/g).map(Number); + const real_groups = stdout.match(/\d+/g).map(Number); assert.equal(groups.length, real_groups.length); check(groups, real_groups); check(real_groups, groups); @@ -22,5 +22,5 @@ if (typeof process.getgroups === 'function') { } function check(a, b) { - for (var i = 0; i < a.length; ++i) assert.notStrictEqual(b.indexOf(a[i]), -1); + for (let i = 0; i < a.length; ++i) assert.notStrictEqual(b.indexOf(a[i]), -1); } diff --git a/test/parallel/test-process-hrtime.js b/test/parallel/test-process-hrtime.js index 9280b671f316d6..faa598d0a57362 100644 --- a/test/parallel/test-process-hrtime.js +++ b/test/parallel/test-process-hrtime.js @@ -1,6 +1,6 @@ 'use strict'; require('../common'); -var assert = require('assert'); +const assert = require('assert'); // the default behavior, return an Array "tuple" of numbers const tuple = process.hrtime(); diff --git a/test/parallel/test-process-kill-null.js b/test/parallel/test-process-kill-null.js index 2516773f08786a..6c0ee8fa049a50 100644 --- a/test/parallel/test-process-kill-null.js +++ b/test/parallel/test-process-kill-null.js @@ -1,10 +1,10 @@ 'use strict'; require('../common'); -var assert = require('assert'); -var spawn = require('child_process').spawn; +const assert = require('assert'); +const spawn = require('child_process').spawn; -var cat = spawn('cat'); -var called; +const cat = spawn('cat'); +let called; assert.ok(process.kill(cat.pid, 0)); diff --git a/test/parallel/test-process-kill-pid.js b/test/parallel/test-process-kill-pid.js index ee0554c32083f6..2c6ef37fc120df 100644 --- a/test/parallel/test-process-kill-pid.js +++ b/test/parallel/test-process-kill-pid.js @@ -1,6 +1,6 @@ 'use strict'; require('../common'); -var assert = require('assert'); +const assert = require('assert'); // test variants of pid // @@ -34,9 +34,9 @@ assert.throws(function() { process.kill(1, 'test'); }, Error); // that we don't kill our process group, or try to actually send ANY signals on // windows, which doesn't support them. function kill(tryPid, trySig, expectPid, expectSig) { - var getPid; - var getSig; - var origKill = process._kill; + let getPid; + let getSig; + const origKill = process._kill; process._kill = function(pid, sig) { getPid = pid; getSig = sig; diff --git a/test/parallel/test-process-next-tick.js b/test/parallel/test-process-next-tick.js index 343511445280d4..e67ebae0a29559 100644 --- a/test/parallel/test-process-next-tick.js +++ b/test/parallel/test-process-next-tick.js @@ -1,12 +1,12 @@ 'use strict'; const common = require('../common'); -var N = 2; +const N = 2; function cb() { throw new Error(); } -for (var i = 0; i < N; ++i) { +for (let i = 0; i < N; ++i) { process.nextTick(common.mustCall(cb)); } diff --git a/test/parallel/test-process-raw-debug.js b/test/parallel/test-process-raw-debug.js index ab461902911a93..74c99b1f8f8058 100644 --- a/test/parallel/test-process-raw-debug.js +++ b/test/parallel/test-process-raw-debug.js @@ -1,7 +1,7 @@ 'use strict'; require('../common'); -var assert = require('assert'); -var os = require('os'); +const assert = require('assert'); +const os = require('os'); switch (process.argv[2]) { case 'child': @@ -13,10 +13,10 @@ switch (process.argv[2]) { } function parent() { - var spawn = require('child_process').spawn; - var child = spawn(process.execPath, [__filename, 'child']); + const spawn = require('child_process').spawn; + const child = spawn(process.execPath, [__filename, 'child']); - var output = ''; + let output = ''; child.stderr.on('data', function(c) { output += c; @@ -42,7 +42,7 @@ function child() { throw new Error('No ticking!'); }; - var stderr = process.stderr; + const stderr = process.stderr; stderr.write = function() { throw new Error('No writing to stderr!'); }; diff --git a/test/parallel/test-process-remove-all-signal-listeners.js b/test/parallel/test-process-remove-all-signal-listeners.js index 131d57cdfccaa7..76a96f7683e452 100644 --- a/test/parallel/test-process-remove-all-signal-listeners.js +++ b/test/parallel/test-process-remove-all-signal-listeners.js @@ -14,7 +14,7 @@ if (process.argv[2] !== '--do-test') { // We are the master, fork a child so we can verify it exits with correct // status. process.env.DOTEST = 'y'; - var child = spawn(process.execPath, [__filename, '--do-test']); + const child = spawn(process.execPath, [__filename, '--do-test']); child.once('exit', common.mustCall(function(code, signal) { assert.equal(signal, 'SIGINT'); diff --git a/test/parallel/test-process-versions.js b/test/parallel/test-process-versions.js index 12136958fc8c37..27311f7eda84e3 100644 --- a/test/parallel/test-process-versions.js +++ b/test/parallel/test-process-versions.js @@ -2,8 +2,8 @@ const common = require('../common'); const assert = require('assert'); -var expected_keys = ['ares', 'http_parser', 'modules', 'node', - 'uv', 'v8', 'zlib']; +const expected_keys = ['ares', 'http_parser', 'modules', 'node', + 'uv', 'v8', 'zlib']; if (common.hasCrypto) { expected_keys.push('openssl'); diff --git a/test/parallel/test-process-wrap.js b/test/parallel/test-process-wrap.js index b5d4dc35e4fe00..326854e98335df 100644 --- a/test/parallel/test-process-wrap.js +++ b/test/parallel/test-process-wrap.js @@ -1,14 +1,14 @@ 'use strict'; require('../common'); -var assert = require('assert'); -var Process = process.binding('process_wrap').Process; -var Pipe = process.binding('pipe_wrap').Pipe; -var pipe = new Pipe(); -var p = new Process(); +const assert = require('assert'); +const Process = process.binding('process_wrap').Process; +const Pipe = process.binding('pipe_wrap').Pipe; +const pipe = new Pipe(); +const p = new Process(); -var processExited = false; -var gotPipeEOF = false; -var gotPipeData = false; +let processExited = false; +let gotPipeEOF = false; +let gotPipeData = false; p.onexit = function(exitCode, signal) { console.log('exit'); @@ -45,7 +45,7 @@ p.spawn({ // 'this' safety // https://github.com/joyent/node/issues/6690 assert.throws(function() { - var notp = { spawn: p.spawn }; + const notp = { spawn: p.spawn }; notp.spawn({ file: process.execPath, args: [process.execPath, '-v'], diff --git a/test/parallel/test-promises-unhandled-rejections.js b/test/parallel/test-promises-unhandled-rejections.js index 3c7a40380505de..e2453c915a4a24 100644 --- a/test/parallel/test-promises-unhandled-rejections.js +++ b/test/parallel/test-promises-unhandled-rejections.js @@ -1,17 +1,17 @@ 'use strict'; -var common = require('../common'); -var assert = require('assert'); -var domain = require('domain'); +const common = require('../common'); +const assert = require('assert'); +const domain = require('domain'); -var asyncTest = (function() { - var asyncTestsEnabled = false; - var asyncTestLastCheck; - var asyncTestQueue = []; - var asyncTestHandle; - var currentTest = null; +const asyncTest = (function() { + let asyncTestsEnabled = false; + let asyncTestLastCheck; + const asyncTestQueue = []; + let asyncTestHandle; + let currentTest = null; function fail(error) { - var stack = currentTest + const stack = currentTest ? error.stack + '\nFrom previous event:\n' + currentTest.stack : error.stack; @@ -23,7 +23,7 @@ var asyncTest = (function() { } function nextAsyncTest() { - var called = false; + let called = false; function done(err) { if (called) return fail(new Error('done called twice')); called = true; @@ -33,7 +33,7 @@ var asyncTest = (function() { } if (asyncTestQueue.length) { - var test = asyncTestQueue.shift(); + const test = asyncTestQueue.shift(); currentTest = test; test.action(done); } else { @@ -42,7 +42,7 @@ var asyncTest = (function() { } return function asyncTest(description, fn) { - var stack = new Error().stack.split('\n').slice(1).join('\n'); + const stack = new Error().stack.split('\n').slice(1).join('\n'); asyncTestQueue.push({ action: fn, stack: stack, @@ -53,7 +53,7 @@ var asyncTest = (function() { asyncTestLastCheck = Date.now(); process.on('uncaughtException', fail); asyncTestHandle = setInterval(function() { - var now = Date.now(); + const now = Date.now(); if (now - asyncTestLastCheck > 10000) { return fail(new Error('Async test timeout exceeded')); } @@ -65,7 +65,7 @@ var asyncTest = (function() { })(); function setupException(fn) { - var listeners = process.listeners('uncaughtException'); + const listeners = process.listeners('uncaughtException'); process.removeAllListeners('uncaughtException'); process.on('uncaughtException', fn); return function clean() { @@ -108,7 +108,7 @@ function onUnhandledFail(done) { asyncTest('synchronously rejected promise should trigger' + ' unhandledRejection', function(done) { - var e = new Error(); + const e = new Error(); onUnhandledSucceed(done, function(reason, promise) { assert.strictEqual(e, reason); }); @@ -117,7 +117,7 @@ asyncTest('synchronously rejected promise should trigger' + asyncTest('synchronously rejected promise should trigger' + ' unhandledRejection', function(done) { - var e = new Error(); + const e = new Error(); onUnhandledSucceed(done, function(reason, promise) { assert.strictEqual(e, reason); }); @@ -128,7 +128,7 @@ asyncTest('synchronously rejected promise should trigger' + asyncTest('Promise rejected after setImmediate should trigger' + ' unhandledRejection', function(done) { - var e = new Error(); + const e = new Error(); onUnhandledSucceed(done, function(reason, promise) { assert.strictEqual(e, reason); }); @@ -141,7 +141,7 @@ asyncTest('Promise rejected after setImmediate should trigger' + asyncTest('Promise rejected after setTimeout(,1) should trigger' + ' unhandled rejection', function(done) { - var e = new Error(); + const e = new Error(); onUnhandledSucceed(done, function(reason, promise) { assert.strictEqual(e, reason); }); @@ -154,12 +154,12 @@ asyncTest('Promise rejected after setTimeout(,1) should trigger' + asyncTest('Catching a promise rejection after setImmediate is not' + ' soon enough to stop unhandledRejection', function(done) { - var e = new Error(); + const e = new Error(); onUnhandledSucceed(done, function(reason, promise) { assert.strictEqual(e, reason); }); - var _reject; - var promise = new Promise(function(_, reject) { + let _reject; + const promise = new Promise(function(_, reject) { _reject = reject; }); _reject(e); @@ -170,13 +170,13 @@ asyncTest('Catching a promise rejection after setImmediate is not' + asyncTest('When re-throwing new errors in a promise catch, only the' + ' re-thrown error should hit unhandledRejection', function(done) { - var e = new Error(); - var e2 = new Error(); + const e = new Error(); + const e2 = new Error(); onUnhandledSucceed(done, function(reason, promise) { assert.strictEqual(e2, reason); assert.strictEqual(promise2, promise); }); - var promise2 = Promise.reject(e).then(common.fail, function(reason) { + let promise2 = Promise.reject(e).then(common.fail, function(reason) { assert.strictEqual(e, reason); throw e2; }); @@ -184,7 +184,7 @@ asyncTest('When re-throwing new errors in a promise catch, only the' + asyncTest('Test params of unhandledRejection for a synchronously-rejected' + 'promise', function(done) { - var e = new Error(); + const e = new Error(); onUnhandledSucceed(done, function(reason, promise) { assert.strictEqual(e, reason); assert.strictEqual(promise, promise); @@ -195,13 +195,13 @@ asyncTest('Test params of unhandledRejection for a synchronously-rejected' + asyncTest('When re-throwing new errors in a promise catch, only the ' + 're-thrown error should hit unhandledRejection: original promise' + ' rejected async with setTimeout(,1)', function(done) { - var e = new Error(); - var e2 = new Error(); + const e = new Error(); + const e2 = new Error(); onUnhandledSucceed(done, function(reason, promise) { assert.strictEqual(e2, reason); assert.strictEqual(promise2, promise); }); - var promise2 = new Promise(function(_, reject) { + let promise2 = new Promise(function(_, reject) { setTimeout(function() { reject(e); }, 1); @@ -214,13 +214,13 @@ asyncTest('When re-throwing new errors in a promise catch, only the ' + asyncTest('When re-throwing new errors in a promise catch, only the re-thrown' + ' error should hit unhandledRejection: promise catch attached a' + ' process.nextTick after rejection', function(done) { - var e = new Error(); - var e2 = new Error(); + const e = new Error(); + const e2 = new Error(); onUnhandledSucceed(done, function(reason, promise) { assert.strictEqual(e2, reason); assert.strictEqual(promise2, promise); }); - var promise = new Promise(function(_, reject) { + const promise = new Promise(function(_, reject) { setTimeout(function() { reject(e); process.nextTick(function() { @@ -231,14 +231,14 @@ asyncTest('When re-throwing new errors in a promise catch, only the re-thrown' + }); }, 1); }); - var promise2; + let promise2; }); asyncTest( 'unhandledRejection should not be triggered if a promise catch is' + ' attached synchronously upon the promise\'s creation', function(done) { - var e = new Error(); + const e = new Error(); onUnhandledFail(done); Promise.reject(e).then(common.fail, function() {}); } @@ -248,7 +248,7 @@ asyncTest( 'unhandledRejection should not be triggered if a promise catch is' + ' attached synchronously upon the promise\'s creation', function(done) { - var e = new Error(); + const e = new Error(); onUnhandledFail(done); new Promise(function(_, reject) { reject(e); @@ -258,9 +258,9 @@ asyncTest( asyncTest('Attaching a promise catch in a process.nextTick is soon enough to' + ' prevent unhandledRejection', function(done) { - var e = new Error(); + const e = new Error(); onUnhandledFail(done); - var promise = Promise.reject(e); + const promise = Promise.reject(e); process.nextTick(function() { promise.then(common.fail, function() {}); }); @@ -268,9 +268,9 @@ asyncTest('Attaching a promise catch in a process.nextTick is soon enough to' + asyncTest('Attaching a promise catch in a process.nextTick is soon enough to' + ' prevent unhandledRejection', function(done) { - var e = new Error(); + const e = new Error(); onUnhandledFail(done); - var promise = new Promise(function(_, reject) { + const promise = new Promise(function(_, reject) { reject(e); }); process.nextTick(function() { @@ -297,7 +297,7 @@ asyncTest('While inside setImmediate, catching a rejected promise derived ' + asyncTest('catching a promise which is asynchronously rejected (via' + 'resolution to an asynchronously-rejected promise) prevents' + ' unhandledRejection', function(done) { - var e = new Error(); + const e = new Error(); onUnhandledFail(done); Promise.resolve().then(function() { return new Promise(function(_, reject) { @@ -312,7 +312,7 @@ asyncTest('catching a promise which is asynchronously rejected (via' + asyncTest('Catching a rejected promise derived from throwing in a' + ' fulfillment handler prevents unhandledRejection', function(done) { - var e = new Error(); + const e = new Error(); onUnhandledFail(done); Promise.resolve().then(function() { throw e; @@ -324,7 +324,7 @@ asyncTest('Catching a rejected promise derived from throwing in a' + asyncTest('Catching a rejected promise derived from returning a' + ' synchronously-rejected promise in a fulfillment handler' + ' prevents unhandledRejection', function(done) { - var e = new Error(); + const e = new Error(); onUnhandledFail(done); Promise.resolve().then(function() { return Promise.reject(e); @@ -336,8 +336,8 @@ asyncTest('Catching a rejected promise derived from returning a' + asyncTest('A rejected promise derived from returning an' + ' asynchronously-rejected promise in a fulfillment handler' + ' does trigger unhandledRejection', function(done) { - var e = new Error(); - var _promise; + const e = new Error(); + let _promise; onUnhandledSucceed(done, function(reason, promise) { assert.strictEqual(e, reason); assert.strictEqual(_promise, promise); @@ -353,8 +353,8 @@ asyncTest('A rejected promise derived from returning an' + asyncTest('A rejected promise derived from throwing in a fulfillment handler' + ' does trigger unhandledRejection', function(done) { - var e = new Error(); - var _promise; + const e = new Error(); + let _promise; onUnhandledSucceed(done, function(reason, promise) { assert.strictEqual(e, reason); assert.strictEqual(_promise, promise); @@ -368,8 +368,8 @@ asyncTest( 'A rejected promise derived from returning a synchronously-rejected' + ' promise in a fulfillment handler does trigger unhandledRejection', function(done) { - var e = new Error(); - var _promise; + const e = new Error(); + let _promise; onUnhandledSucceed(done, function(reason, promise) { assert.strictEqual(e, reason); assert.strictEqual(_promise, promise); @@ -383,7 +383,7 @@ asyncTest( // Combinations with Promise.all asyncTest('Catching the Promise.all() of a collection that includes a' + 'rejected promise prevents unhandledRejection', function(done) { - var e = new Error(); + const e = new Error(); onUnhandledFail(done); Promise.all([Promise.reject(e)]).then(common.fail, function() {}); }); @@ -392,9 +392,9 @@ asyncTest( 'Catching the Promise.all() of a collection that includes a ' + 'nextTick-async rejected promise prevents unhandledRejection', function(done) { - var e = new Error(); + const e = new Error(); onUnhandledFail(done); - var p = new Promise(function(_, reject) { + let p = new Promise(function(_, reject) { process.nextTick(function() { reject(e); }); @@ -409,19 +409,19 @@ asyncTest( asyncTest('Failing to catch the Promise.all() of a collection that includes' + ' a rejected promise triggers unhandledRejection for the returned' + ' promise, not the passed promise', function(done) { - var e = new Error(); + const e = new Error(); onUnhandledSucceed(done, function(reason, promise) { assert.strictEqual(e, reason); assert.strictEqual(p, promise); }); - var p = Promise.all([Promise.reject(e)]); + let p = Promise.all([Promise.reject(e)]); }); asyncTest('Waiting setTimeout(, 10) to catch a promise causes an' + ' unhandledRejection + rejectionHandled pair', function(done) { clean(); - var unhandledPromises = []; - var e = new Error(); + const unhandledPromises = []; + const e = new Error(); process.on('unhandledRejection', function(reason, promise) { assert.strictEqual(e, reason); unhandledPromises.push(promise); @@ -433,7 +433,7 @@ asyncTest('Waiting setTimeout(, 10) to catch a promise causes an' + done(); }); - var thePromise = new Promise(function() { + let thePromise = new Promise(function() { throw e; }); setTimeout(function() { @@ -446,11 +446,11 @@ asyncTest('Waiting setTimeout(, 10) to catch a promise causes an' + asyncTest('Waiting for some combination of process.nextTick + promise' + ' microtasks to attach a catch handler is still soon enough to' + ' prevent unhandledRejection', function(done) { - var e = new Error(); + const e = new Error(); onUnhandledFail(done); - var a = Promise.reject(e); + const a = Promise.reject(e); process.nextTick(function() { Promise.resolve().then(function() { process.nextTick(function() { @@ -465,11 +465,11 @@ asyncTest('Waiting for some combination of process.nextTick + promise' + asyncTest('Waiting for some combination of process.nextTick + promise' + ' microtasks to attach a catch handler is still soon enough to ' + 'prevent unhandledRejection: inside setImmediate', function(done) { - var e = new Error(); + const e = new Error(); onUnhandledFail(done); setImmediate(function() { - var a = Promise.reject(e); + const a = Promise.reject(e); process.nextTick(function() { Promise.resolve().then(function() { process.nextTick(function() { @@ -485,11 +485,11 @@ asyncTest('Waiting for some combination of process.nextTick + promise' + asyncTest('Waiting for some combination of process.nextTick + promise ' + 'microtasks to attach a catch handler is still soon enough to ' + 'prevent unhandledRejection: inside setTimeout', function(done) { - var e = new Error(); + const e = new Error(); onUnhandledFail(done); setTimeout(function() { - var a = Promise.reject(e); + const a = Promise.reject(e); process.nextTick(function() { Promise.resolve().then(function() { process.nextTick(function() { @@ -505,11 +505,11 @@ asyncTest('Waiting for some combination of process.nextTick + promise ' + asyncTest('Waiting for some combination of promise microtasks + ' + 'process.nextTick to attach a catch handler is still soon enough' + ' to prevent unhandledRejection', function(done) { - var e = new Error(); + const e = new Error(); onUnhandledFail(done); - var a = Promise.reject(e); + const a = Promise.reject(e); Promise.resolve().then(function() { process.nextTick(function() { Promise.resolve().then(function() { @@ -526,11 +526,11 @@ asyncTest( ' process.nextTick to attach a catch handler is still soon enough' + ' to prevent unhandledRejection: inside setImmediate', function(done) { - var e = new Error(); + const e = new Error(); onUnhandledFail(done); setImmediate(function() { - var a = Promise.reject(e); + const a = Promise.reject(e); Promise.resolve().then(function() { process.nextTick(function() { Promise.resolve().then(function() { @@ -547,11 +547,11 @@ asyncTest( asyncTest('Waiting for some combination of promise microtasks +' + ' process.nextTick to attach a catch handler is still soon enough' + ' to prevent unhandledRejection: inside setTimeout', function(done) { - var e = new Error(); + const e = new Error(); onUnhandledFail(done); setTimeout(function() { - var a = Promise.reject(e); + const a = Promise.reject(e); Promise.resolve().then(function() { process.nextTick(function() { Promise.resolve().then(function() { @@ -567,12 +567,12 @@ asyncTest('Waiting for some combination of promise microtasks +' + asyncTest('setImmediate + promise microtasks is too late to attach a catch' + ' handler; unhandledRejection will be triggered in that case.' + ' (setImmediate before promise creation/rejection)', function(done) { - var e = new Error(); + const e = new Error(); onUnhandledSucceed(done, function(reason, promise) { assert.strictEqual(e, reason); assert.strictEqual(p, promise); }); - var p = Promise.reject(e); + let p = Promise.reject(e); setImmediate(function() { Promise.resolve().then(function() { p.catch(function() {}); @@ -598,7 +598,7 @@ asyncTest('setImmediate + promise microtasks is too late to attach a catch' + }); }); }); - var p = Promise.reject(); + let p = Promise.reject(); }); asyncTest('setImmediate + promise microtasks is too late to attach a catch' + @@ -608,7 +608,7 @@ asyncTest('setImmediate + promise microtasks is too late to attach a catch' + assert.strictEqual(undefined, reason); assert.strictEqual(p, promise); }); - var p = Promise.reject(); + let p = Promise.reject(); setImmediate(function() { Promise.resolve().then(function() { Promise.resolve().then(function() { @@ -626,14 +626,14 @@ asyncTest( 'Promise unhandledRejection handler does not interfere with domain' + ' error handlers being given exceptions thrown from nextTick.', function(done) { - var d = domain.create(); - var domainReceivedError; + const d = domain.create(); + let domainReceivedError; d.on('error', function(e) { domainReceivedError = e; }); d.run(function() { - var e = new Error('error'); - var domainError = new Error('domain error'); + const e = new Error('error'); + const domainError = new Error('domain error'); onUnhandledSucceed(done, function(reason, promise) { assert.strictEqual(reason, e); assert.strictEqual(domainReceivedError, domainError); @@ -650,9 +650,9 @@ asyncTest( asyncTest('nextTick is immediately scheduled when called inside an event' + ' handler', function(done) { clean(); - var e = new Error('error'); + const e = new Error('error'); process.on('unhandledRejection', function(reason, promise) { - var order = []; + const order = []; process.nextTick(function() { order.push(1); }); @@ -669,9 +669,9 @@ asyncTest('Throwing an error inside a rejectionHandled handler goes to' + ' unhandledException, and does not cause .catch() to throw an' + 'exception', function(done) { clean(); - var e = new Error(); - var e2 = new Error(); - var tearDownException = setupException(function(err) { + const e = new Error(); + const e2 = new Error(); + const tearDownException = setupException(function(err) { assert.equal(e2, err); tearDownException(); done(); @@ -679,7 +679,7 @@ asyncTest('Throwing an error inside a rejectionHandled handler goes to' + process.on('rejectionHandled', function() { throw e2; }); - var p = Promise.reject(e); + const p = Promise.reject(e); setTimeout(function() { try { p.catch(function() {}); diff --git a/test/parallel/test-promises-warning-on-unhandled-rejection.js b/test/parallel/test-promises-warning-on-unhandled-rejection.js index 9b1e7f3266aba0..92bdc27e4a68cf 100644 --- a/test/parallel/test-promises-warning-on-unhandled-rejection.js +++ b/test/parallel/test-promises-warning-on-unhandled-rejection.js @@ -7,7 +7,7 @@ const common = require('../common'); const assert = require('assert'); -var b = 0; +let b = 0; process.on('warning', common.mustCall((warning) => { switch (b++) { diff --git a/test/parallel/test-querystring-maxKeys-non-finite.js b/test/parallel/test-querystring-maxKeys-non-finite.js index aab7c45f1b6bed..8aa47f7de0e2dc 100644 --- a/test/parallel/test-querystring-maxKeys-non-finite.js +++ b/test/parallel/test-querystring-maxKeys-non-finite.js @@ -13,7 +13,7 @@ https://github.com/expressjs/body-parser/ blob/ed25264fb494cf0c8bc992b8257092cd4f694d5e/test/urlencoded.js#L636-L651 */ function createManyParams(count) { - var str = ''; + let str = ''; if (count === 0) { return str; @@ -21,8 +21,8 @@ function createManyParams(count) { str += '0=0'; - for (var i = 1; i < count; i++) { - var n = i.toString(36); + for (let i = 1; i < count; i++) { + const n = i.toString(36); str += '&' + n + '=' + n; } diff --git a/test/parallel/test-querystring.js b/test/parallel/test-querystring.js index 6247235e967ac2..fed9eb9b8506ac 100644 --- a/test/parallel/test-querystring.js +++ b/test/parallel/test-querystring.js @@ -1,9 +1,9 @@ 'use strict'; require('../common'); -var assert = require('assert'); +const assert = require('assert'); // test using assert -var qs = require('querystring'); +const qs = require('querystring'); function createWithNoPrototype(properties) { const noProto = Object.create(null); @@ -15,7 +15,7 @@ function createWithNoPrototype(properties) { // folding block, commented to pass gjslint // {{{ // [ wonkyQS, canonicalQS, obj ] -var qsTestCases = [ +const qsTestCases = [ ['__proto__=1', '__proto__=1', createWithNoPrototype([{key: '__proto__', value: '1'}])], @@ -56,7 +56,7 @@ var qsTestCases = [ ]; // [ wonkyQS, canonicalQS, obj ] -var qsColonTestCases = [ +const qsColonTestCases = [ ['foo:bar', 'foo:bar', {'foo': 'bar'}], ['foo:bar;foo:quux', 'foo:bar;foo:quux', {'foo': ['bar', 'quux']}], ['foo:1&bar:2;baz:quux', @@ -67,9 +67,9 @@ var qsColonTestCases = [ ]; // [wonkyObj, qs, canonicalObj] -var extendedFunction = function() {}; +const extendedFunction = function() {}; extendedFunction.prototype = {a: 'b'}; -var qsWeirdObjects = [ +const qsWeirdObjects = [ [{regexp: /./g}, 'regexp=', {'regexp': ''}], [{regexp: new RegExp('.', 'g')}, 'regexp=', {'regexp': ''}], [{fn: function() {}}, 'fn=', {'fn': ''}], @@ -87,10 +87,10 @@ var qsWeirdObjects = [ ]; // }}} -var vm = require('vm'); -var foreignObject = vm.runInNewContext('({"foo": ["bar", "baz"]})'); +const vm = require('vm'); +const foreignObject = vm.runInNewContext('({"foo": ["bar", "baz"]})'); -var qsNoMungeTestCases = [ +const qsNoMungeTestCases = [ ['', {}], ['foo=bar&foo=baz', {'foo': ['bar', 'baz']}], ['foo=bar&foo=baz', foreignObject], @@ -259,7 +259,7 @@ assert.equal( function testUnlimitedKeys() { const query = {}; - for (var i = 0; i < 2000; i++) query[i] = i; + for (let i = 0; i < 2000; i++) query[i] = i; const url = qs.stringify(query); @@ -270,7 +270,7 @@ function testUnlimitedKeys() { testUnlimitedKeys(); -var b = qs.unescapeBuffer('%d3%f2Ug%1f6v%24%5e%98%cb' + +const b = qs.unescapeBuffer('%d3%f2Ug%1f6v%24%5e%98%cb' + '%0d%ac%a2%2f%9d%eb%d8%a2%e6'); // assert.equal(0xd3, b[0]); @@ -320,7 +320,7 @@ check(qs.parse('a=a', null, null, { decodeURIComponent: errDecode }), function demoEncode(str) { return str[0]; } -var obj = { aa: 'aa', bb: 'bb', cc: 'cc' }; +const obj = { aa: 'aa', bb: 'bb', cc: 'cc' }; assert.equal( qs.stringify(obj, null, null, { encodeURIComponent: demoEncode }), 'a=a&b=b&c=c'); @@ -332,7 +332,7 @@ qsUnescapeTestCases.forEach(function(testCase) { }); // test overriding .unescape -var prevUnescape = qs.unescape; +const prevUnescape = qs.unescape; qs.unescape = function(str) { return str.replace(/o/g, '_'); }; diff --git a/test/parallel/test-readdouble.js b/test/parallel/test-readdouble.js index a6fc91c351f089..728a2b4605d9ff 100644 --- a/test/parallel/test-readdouble.js +++ b/test/parallel/test-readdouble.js @@ -9,7 +9,7 @@ const assert = require('assert'); * Test (64 bit) double */ function test(clazz) { - var buffer = new clazz(8); + const buffer = new clazz(8); buffer[0] = 0x55; buffer[1] = 0x55; diff --git a/test/parallel/test-readfloat.js b/test/parallel/test-readfloat.js index 533b7caa8f1047..437e4778671bd2 100644 --- a/test/parallel/test-readfloat.js +++ b/test/parallel/test-readfloat.js @@ -9,7 +9,7 @@ const assert = require('assert'); * Test (32 bit) float */ function test(clazz) { - var buffer = new clazz(4); + const buffer = new clazz(4); buffer[0] = 0; buffer[1] = 0; diff --git a/test/parallel/test-readint.js b/test/parallel/test-readint.js index c068ddcb6c554a..086dd4e3aa0d1a 100644 --- a/test/parallel/test-readint.js +++ b/test/parallel/test-readint.js @@ -9,7 +9,7 @@ const assert = require('assert'); * Test 8 bit signed integers */ function test8(clazz) { - var data = new clazz(4); + const data = new clazz(4); data[0] = 0x23; assert.equal(0x23, data.readInt8(0)); @@ -29,7 +29,7 @@ function test8(clazz) { function test16(clazz) { - var buffer = new clazz(6); + const buffer = new clazz(6); buffer[0] = 0x16; buffer[1] = 0x79; @@ -62,7 +62,7 @@ function test16(clazz) { function test32(clazz) { - var buffer = new clazz(6); + const buffer = new clazz(6); buffer[0] = 0x43; buffer[1] = 0x53; diff --git a/test/parallel/test-readline-interface.js b/test/parallel/test-readline-interface.js index 96f67c320e1789..49809dda81a3a2 100644 --- a/test/parallel/test-readline-interface.js +++ b/test/parallel/test-readline-interface.js @@ -17,8 +17,8 @@ FakeInput.prototype.write = function() {}; FakeInput.prototype.end = function() {}; function isWarned(emitter) { - for (var name in emitter) { - var listeners = emitter[name]; + for (const name in emitter) { + const listeners = emitter[name]; if (listeners.warned) return true; } return false; @@ -53,9 +53,9 @@ function isWarned(emitter) { } [ true, false ].forEach(function(terminal) { - var fi; - var rli; - var called; + let fi; + let rli; + let called; // disable history fi = new FakeInput(); @@ -126,8 +126,8 @@ function isWarned(emitter) { // sending multiple newlines at once fi = new FakeInput(); rli = new readline.Interface({ input: fi, output: fi, terminal: terminal }); - var expectedLines = ['foo', 'bar', 'baz']; - var callCount = 0; + let expectedLines = ['foo', 'bar', 'baz']; + let callCount = 0; rli.on('line', function(line) { assert.equal(line, expectedLines[callCount]); callCount++; @@ -265,7 +265,7 @@ function isWarned(emitter) { // \t does not become part of the input when there is a completer function fi = new FakeInput(); - var completer = function(line) { + const completer = function(line) { return [[], line]; }; rli = new readline.Interface({ @@ -280,7 +280,7 @@ function isWarned(emitter) { assert.strictEqual(called, false); called = true; }); - for (var character of '\tfo\to\t') { + for (const character of '\tfo\to\t') { fi.emit('data', character); } fi.emit('data', '\n'); @@ -304,7 +304,7 @@ function isWarned(emitter) { }); // sending a multi-byte utf8 char over multiple writes - var buf = Buffer.from('☮', 'utf8'); + const buf = Buffer.from('☮', 'utf8'); fi = new FakeInput(); rli = new readline.Interface({ input: fi, output: fi, terminal: terminal }); callCount = 0; @@ -324,7 +324,7 @@ function isWarned(emitter) { // check that nothing fails if 'keypress' event throws. fi = new FakeInput(); rli = new readline.Interface({ input: fi, output: fi, terminal: true }); - var keys = []; + const keys = []; fi.on('keypress', function(key) { keys.push(key); if (key === 'X') { @@ -358,7 +358,7 @@ function isWarned(emitter) { rli.question(expectedLines[0], function() { rli.close(); }); - var cursorPos = rli._getCursorPos(); + let cursorPos = rli._getCursorPos(); assert.equal(cursorPos.rows, 0); assert.equal(cursorPos.cols, expectedLines[0].length); rli.close(); @@ -425,8 +425,8 @@ function isWarned(emitter) { assert.deepStrictEqual(fi.listeners(terminal ? 'keypress' : 'data'), []); // check EventEmitter memory leak - for (var i = 0; i < 12; i++) { - var rl = readline.createInterface({ + for (let i = 0; i < 12; i++) { + const rl = readline.createInterface({ input: process.stdin, output: process.stdout }); diff --git a/test/parallel/test-readline-keys.js b/test/parallel/test-readline-keys.js index 85e3f4df6ff917..f45bcb97e02d55 100644 --- a/test/parallel/test-readline-keys.js +++ b/test/parallel/test-readline-keys.js @@ -13,11 +13,11 @@ function FakeInput() { inherits(FakeInput, PassThrough); -var fi = new FakeInput(); -var fo = new FakeInput(); +const fi = new FakeInput(); +const fo = new FakeInput(); new Interface({ input: fi, output: fo, terminal: true }); -var keys = []; +let keys = []; fi.on('keypress', function(s, k) { keys.push(k); }); diff --git a/test/parallel/test-readline-set-raw-mode.js b/test/parallel/test-readline-set-raw-mode.js index acf0dc44a631c7..78c42f5f5f627d 100644 --- a/test/parallel/test-readline-set-raw-mode.js +++ b/test/parallel/test-readline-set-raw-mode.js @@ -1,14 +1,14 @@ 'use strict'; require('../common'); -var assert = require('assert'); -var readline = require('readline'); -var Stream = require('stream'); +const assert = require('assert'); +const readline = require('readline'); +const Stream = require('stream'); -var stream = new Stream(); -var expectedRawMode = true; -var rawModeCalled = false; -var resumeCalled = false; -var pauseCalled = false; +const stream = new Stream(); +let expectedRawMode = true; +let rawModeCalled = false; +let resumeCalled = false; +let pauseCalled = false; stream.setRawMode = function(mode) { rawModeCalled = true; @@ -23,7 +23,7 @@ stream.pause = function() { // when the "readline" starts in "terminal" mode, // then setRawMode(true) should be called -var rli = readline.createInterface({ +const rli = readline.createInterface({ input: stream, output: stream, terminal: true diff --git a/test/parallel/test-readline-undefined-columns.js b/test/parallel/test-readline-undefined-columns.js index f3197ff59a9a55..a56a3d54dbbb96 100644 --- a/test/parallel/test-readline-undefined-columns.js +++ b/test/parallel/test-readline-undefined-columns.js @@ -20,7 +20,7 @@ readline.createInterface({ } }); -var output = ''; +let output = ''; oStream.on('data', function(data) { output += data; diff --git a/test/parallel/test-readuint.js b/test/parallel/test-readuint.js index 9fcaf45603fd83..0d1f79b12eabd4 100644 --- a/test/parallel/test-readuint.js +++ b/test/parallel/test-readuint.js @@ -14,7 +14,7 @@ const assert = require('assert'); * - Correctly interpreting values that are beyond the signed range as unsigned */ function test8(clazz) { - var data = new clazz(4); + const data = new clazz(4); data[0] = 23; data[1] = 23; @@ -39,7 +39,7 @@ function test8(clazz) { * - Correctly interpreting values that are beyond the signed range as unsigned */ function test16(clazz) { - var data = new clazz(4); + const data = new clazz(4); data[0] = 0; data[1] = 0x23; @@ -67,7 +67,7 @@ function test16(clazz) { * - Correctly interpreting values that are beyond the signed range as unsigned */ function test32(clazz) { - var data = new clazz(8); + const data = new clazz(8); data[0] = 0x32; data[1] = 0x65; diff --git a/test/parallel/test-ref-unref-return.js b/test/parallel/test-ref-unref-return.js index 89ac52d2bcaa50..aec2fff5ce2271 100644 --- a/test/parallel/test-ref-unref-return.js +++ b/test/parallel/test-ref-unref-return.js @@ -1,8 +1,8 @@ 'use strict'; require('../common'); -var assert = require('assert'); -var net = require('net'); -var dgram = require('dgram'); +const assert = require('assert'); +const net = require('net'); +const dgram = require('dgram'); assert.ok((new net.Server()).ref() instanceof net.Server); assert.ok((new net.Server()).unref() instanceof net.Server); diff --git a/test/parallel/test-regress-GH-1531.js b/test/parallel/test-regress-GH-1531.js index fa0781c2e2fa72..5189e50929105c 100644 --- a/test/parallel/test-regress-GH-1531.js +++ b/test/parallel/test-regress-GH-1531.js @@ -1,20 +1,20 @@ 'use strict'; -var common = require('../common'); +const common = require('../common'); if (!common.hasCrypto) { common.skip('missing crypto'); return; } -var https = require('https'); +const https = require('https'); -var fs = require('fs'); +const fs = require('fs'); -var options = { +const options = { key: fs.readFileSync(common.fixturesDir + '/keys/agent1-key.pem'), cert: fs.readFileSync(common.fixturesDir + '/keys/agent1-cert.pem') }; -var server = https.createServer(options, function(req, res) { +const server = https.createServer(options, function(req, res) { res.writeHead(200); res.end('hello world\n'); }); diff --git a/test/parallel/test-regress-GH-1899.js b/test/parallel/test-regress-GH-1899.js index 7ce83e00092449..838391acd23b5f 100644 --- a/test/parallel/test-regress-GH-1899.js +++ b/test/parallel/test-regress-GH-1899.js @@ -1,13 +1,13 @@ 'use strict'; const common = require('../common'); -var path = require('path'); -var assert = require('assert'); -var spawn = require('child_process').spawn; +const path = require('path'); +const assert = require('assert'); +const spawn = require('child_process').spawn; -var child = spawn(process.argv[0], [ +const child = spawn(process.argv[0], [ path.join(common.fixturesDir, 'GH-1899-output.js') ]); -var output = ''; +let output = ''; child.stdout.on('data', function(data) { output += data; diff --git a/test/parallel/test-regress-GH-2245.js b/test/parallel/test-regress-GH-2245.js index 7558529f9fc50c..c5b0ae4982d993 100644 --- a/test/parallel/test-regress-GH-2245.js +++ b/test/parallel/test-regress-GH-2245.js @@ -1,6 +1,6 @@ /* eslint-disable strict */ require('../common'); -var assert = require('assert'); +const assert = require('assert'); /* In Node.js 0.10, a bug existed that caused strict functions to not capture @@ -10,7 +10,7 @@ their environment when evaluated. When run in 0.10 `test()` fails with a function test() { - var code = [ + const code = [ 'var foo = {m: 1};', '', 'function bar() {', diff --git a/test/parallel/test-regress-GH-3542.js b/test/parallel/test-regress-GH-3542.js index 8db34e72157371..cc0285f7475697 100644 --- a/test/parallel/test-regress-GH-3542.js +++ b/test/parallel/test-regress-GH-3542.js @@ -11,7 +11,7 @@ if (!common.isWindows) { } function test(p) { - var result = fs.realpathSync(p); + const result = fs.realpathSync(p); assert.strictEqual(result.toLowerCase(), path.resolve(p).toLowerCase()); fs.realpath(p, common.mustCall(function(err, result) { diff --git a/test/parallel/test-regress-GH-3739.js b/test/parallel/test-regress-GH-3739.js index aef54c3ea6c7c4..6b4a62700c6dec 100644 --- a/test/parallel/test-regress-GH-3739.js +++ b/test/parallel/test-regress-GH-3739.js @@ -5,13 +5,13 @@ const assert = require('assert'); const fs = require('fs'); const path = require('path'); -var dir = path.resolve(common.tmpDir); +let dir = path.resolve(common.tmpDir); // Make sure that the tmp directory is clean common.refreshTmpDir(); // Make a long path. -for (var i = 0; i < 50; i++) { +for (let i = 0; i < 50; i++) { dir = dir + '/1234567890'; try { fs.mkdirSync(dir, '0777'); diff --git a/test/parallel/test-regress-GH-4948.js b/test/parallel/test-regress-GH-4948.js index 0317778787c2e2..196c973cd093e3 100644 --- a/test/parallel/test-regress-GH-4948.js +++ b/test/parallel/test-regress-GH-4948.js @@ -2,10 +2,10 @@ // https://github.com/joyent/node/issues/4948 require('../common'); -var http = require('http'); +const http = require('http'); -var reqCount = 0; -var server = http.createServer(function(serverReq, serverRes) { +let reqCount = 0; +const server = http.createServer(function(serverReq, serverRes) { if (reqCount) { serverRes.end(); server.close(); @@ -16,8 +16,8 @@ var server = http.createServer(function(serverReq, serverRes) { // normally the use case would be to call an external site // does not require connecting locally or to itself to fail - var r = http.request({hostname: 'localhost', - port: this.address().port}, function(res) { + const r = http.request({hostname: 'localhost', + port: this.address().port}, function(res) { // required, just needs to be in the client response somewhere serverRes.end(); @@ -31,9 +31,9 @@ var server = http.createServer(function(serverReq, serverRes) { serverRes.write('some data'); }).listen(0, function() { // simulate a client request that closes early - var net = require('net'); + const net = require('net'); - var sock = new net.Socket(); + const sock = new net.Socket(); sock.connect(this.address().port, 'localhost'); sock.on('connect', function() { diff --git a/test/parallel/test-regress-GH-5927.js b/test/parallel/test-regress-GH-5927.js index a23c947c320cfc..7f55356a15e027 100644 --- a/test/parallel/test-regress-GH-5927.js +++ b/test/parallel/test-regress-GH-5927.js @@ -1,20 +1,20 @@ 'use strict'; require('../common'); -var assert = require('assert'); -var readline = require('readline'); +const assert = require('assert'); +const readline = require('readline'); -var rl = readline.createInterface(process.stdin, process.stdout); +const rl = readline.createInterface(process.stdin, process.stdout); rl.resume(); -var hasPaused = false; +let hasPaused = false; -var origPause = rl.pause; +const origPause = rl.pause; rl.pause = function() { hasPaused = true; origPause.apply(this, arguments); }; -var origSetRawMode = rl._setRawMode; +const origSetRawMode = rl._setRawMode; rl._setRawMode = function(mode) { assert.ok(hasPaused); origSetRawMode.apply(this, arguments); diff --git a/test/parallel/test-regress-GH-6235.js b/test/parallel/test-regress-GH-6235.js index 0bf9b8965d1184..10092884670980 100644 --- a/test/parallel/test-regress-GH-6235.js +++ b/test/parallel/test-regress-GH-6235.js @@ -1,6 +1,6 @@ 'use strict'; require('../common'); -var assert = require('assert'); +const assert = require('assert'); assert.doesNotThrow(function() { require('vm').runInNewContext('"use strict"; var v = 1; v = 2'); diff --git a/test/parallel/test-regress-GH-746.js b/test/parallel/test-regress-GH-746.js index 8bfcb0c3e22f12..9a6e0e8980f311 100644 --- a/test/parallel/test-regress-GH-746.js +++ b/test/parallel/test-regress-GH-746.js @@ -3,11 +3,11 @@ // This is a regression test for GH-746. const common = require('../common'); -var net = require('net'); +const net = require('net'); process.stdin.destroy(); -var server = net.createServer(common.mustCall(function(socket) { +const server = net.createServer(common.mustCall(function(socket) { console.log('accepted'); socket.end(); server.close(); diff --git a/test/parallel/test-regress-GH-7511.js b/test/parallel/test-regress-GH-7511.js index d18a3ae02c0d03..11bb5bfd4cb170 100644 --- a/test/parallel/test-regress-GH-7511.js +++ b/test/parallel/test-regress-GH-7511.js @@ -4,7 +4,7 @@ const assert = require('assert'); const vm = require('vm'); assert.doesNotThrow(function() { - var context = vm.createContext({ process: process }); - var result = vm.runInContext('process.env["PATH"]', context); + const context = vm.createContext({ process: process }); + const result = vm.runInContext('process.env["PATH"]', context); assert.notEqual(undefined, result); }); diff --git a/test/parallel/test-regress-GH-819.js b/test/parallel/test-regress-GH-819.js index 20ca75c793ce24..719d4398251eab 100644 --- a/test/parallel/test-regress-GH-819.js +++ b/test/parallel/test-regress-GH-819.js @@ -1,7 +1,7 @@ 'use strict'; require('../common'); -var net = require('net'); +const net = require('net'); // Connect to something that we need to DNS resolve -var c = net.createConnection(80, 'google.com'); +const c = net.createConnection(80, 'google.com'); c.destroy(); diff --git a/test/parallel/test-regress-GH-node-9326.js b/test/parallel/test-regress-GH-node-9326.js index bb55050d2ce55e..f32f45cbd02943 100644 --- a/test/parallel/test-regress-GH-node-9326.js +++ b/test/parallel/test-regress-GH-node-9326.js @@ -1,10 +1,10 @@ 'use strict'; require('../common'); -var assert = require('assert'); -var child_process = require('child_process'); +const assert = require('assert'); +const child_process = require('child_process'); // NOTE: Was crashing on FreeBSD -var cp = child_process.spawn(process.execPath, [ +const cp = child_process.spawn(process.execPath, [ '-e', 'process.kill(process.pid, "SIGINT")' ]); diff --git a/test/parallel/test-repl-.save.load.js b/test/parallel/test-repl-.save.load.js index 247f359e829d25..00d5f6791d54a5 100644 --- a/test/parallel/test-repl-.save.load.js +++ b/test/parallel/test-repl-.save.load.js @@ -1,24 +1,24 @@ 'use strict'; const common = require('../common'); -var assert = require('assert'); -var join = require('path').join; -var fs = require('fs'); +const assert = require('assert'); +const join = require('path').join; +const fs = require('fs'); common.refreshTmpDir(); -var repl = require('repl'); +const repl = require('repl'); -var works = [['inner.one'], 'inner.o']; +const works = [['inner.one'], 'inner.o']; const putIn = new common.ArrayStream(); -var testMe = repl.start('', putIn); +const testMe = repl.start('', putIn); -var testFile = [ +const testFile = [ 'var top = function() {', 'var inner = {one:1};' ]; -var saveFileName = join(common.tmpDir, 'test.save.js'); +const saveFileName = join(common.tmpDir, 'test.save.js'); // input some data putIn.run(testFile); @@ -69,7 +69,7 @@ testMe.complete('inner.o', function(error, data) { // clear the REPL putIn.run(['.clear']); -var loadFile = join(common.tmpDir, 'file.does.not.exist'); +let loadFile = join(common.tmpDir, 'file.does.not.exist'); // should not break putIn.write = function(data) { diff --git a/test/parallel/test-repl-autolibs.js b/test/parallel/test-repl-autolibs.js index 15f779d3b12269..859ff5c3c9652a 100644 --- a/test/parallel/test-repl-autolibs.js +++ b/test/parallel/test-repl-autolibs.js @@ -1,8 +1,8 @@ 'use strict'; const common = require('../common'); -var assert = require('assert'); -var util = require('util'); -var repl = require('repl'); +const assert = require('assert'); +const util = require('util'); +const repl = require('repl'); // This test adds global variables common.globalCheck = false; @@ -13,7 +13,7 @@ repl.start('', putIn, null, true); test1(); function test1() { - var gotWrite = false; + let gotWrite = false; putIn.write = function(data) { gotWrite = true; if (data.length) { @@ -31,7 +31,7 @@ function test1() { } function test2() { - var gotWrite = false; + let gotWrite = false; putIn.write = function(data) { gotWrite = true; if (data.length) { @@ -41,7 +41,7 @@ function test2() { assert.equal(val, global.url); } }; - var val = {}; + let val = {}; global.url = val; assert(!gotWrite); putIn.run(['url']); diff --git a/test/parallel/test-repl-console.js b/test/parallel/test-repl-console.js index 98cb958cac8e68..f37dde008044ed 100644 --- a/test/parallel/test-repl-console.js +++ b/test/parallel/test-repl-console.js @@ -6,7 +6,7 @@ const repl = require('repl'); // Create a dummy stream that does nothing const stream = new common.ArrayStream(); -var r = repl.start({ +const r = repl.start({ input: stream, output: stream, useGlobal: false diff --git a/test/parallel/test-repl-definecommand.js b/test/parallel/test-repl-definecommand.js index 6c0c75bca8db79..07732d534e9def 100644 --- a/test/parallel/test-repl-definecommand.js +++ b/test/parallel/test-repl-definecommand.js @@ -6,7 +6,7 @@ const stream = require('stream'); const assert = require('assert'); const repl = require('repl'); -var output = ''; +let output = ''; const inputStream = new stream.PassThrough(); const outputStream = new stream.PassThrough(); outputStream.on('data', function(d) { diff --git a/test/parallel/test-repl-domain.js b/test/parallel/test-repl-domain.js index 3cc88b75f72428..19c85980cdcc72 100644 --- a/test/parallel/test-repl-domain.js +++ b/test/parallel/test-repl-domain.js @@ -1,7 +1,7 @@ 'use strict'; -var common = require('../common'); +const common = require('../common'); -var repl = require('repl'); +const repl = require('repl'); const putIn = new common.ArrayStream(); repl.start('', putIn); diff --git a/test/parallel/test-repl-end-emits-exit.js b/test/parallel/test-repl-end-emits-exit.js index 7f2c4b9eb2893f..661f9f0ad0e3a4 100644 --- a/test/parallel/test-repl-end-emits-exit.js +++ b/test/parallel/test-repl-end-emits-exit.js @@ -9,7 +9,7 @@ let regularExit = 0; const stream = new common.ArrayStream(); function testTerminalMode() { - var r1 = repl.start({ + const r1 = repl.start({ input: stream, output: stream, terminal: true @@ -28,7 +28,7 @@ function testTerminalMode() { } function testRegularMode() { - var r2 = repl.start({ + const r2 = repl.start({ input: stream, output: stream, terminal: false diff --git a/test/parallel/test-repl-harmony.js b/test/parallel/test-repl-harmony.js index a5928800381cfe..743bbe4fabfcd1 100644 --- a/test/parallel/test-repl-harmony.js +++ b/test/parallel/test-repl-harmony.js @@ -1,13 +1,13 @@ 'use strict'; require('../common'); -var assert = require('assert'); +const assert = require('assert'); -var spawn = require('child_process').spawn; -var args = ['-i']; -var child = spawn(process.execPath, args); +const spawn = require('child_process').spawn; +const args = ['-i']; +const child = spawn(process.execPath, args); -var input = '(function(){"use strict"; const y=1;y=2})()\n'; -var expectOut = /^> TypeError: Assignment to constant variable.\n/; +const input = '(function(){"use strict"; const y=1;y=2})()\n'; +const expectOut = /^> TypeError: Assignment to constant variable.\n/; child.stderr.setEncoding('utf8'); child.stderr.on('data', function(c) { @@ -15,7 +15,7 @@ child.stderr.on('data', function(c) { }); child.stdout.setEncoding('utf8'); -var out = ''; +let out = ''; child.stdout.on('data', function(c) { out += c; }); diff --git a/test/parallel/test-repl-history-perm.js b/test/parallel/test-repl-history-perm.js index 4a374cb0ab12e8..69b973db2b79bc 100644 --- a/test/parallel/test-repl-history-perm.js +++ b/test/parallel/test-repl-history-perm.js @@ -18,7 +18,7 @@ const Duplex = require('stream').Duplex; // Invoking the REPL should create a repl history file at the specified path // and mode 600. -var stream = new Duplex(); +const stream = new Duplex(); stream.pause = stream.resume = function() {}; // ends immediately stream._read = function() { diff --git a/test/parallel/test-repl-null.js b/test/parallel/test-repl-null.js index 337e194447d1f8..66d09b28f28b84 100644 --- a/test/parallel/test-repl-null.js +++ b/test/parallel/test-repl-null.js @@ -3,7 +3,7 @@ require('../common'); const repl = require('repl'); const assert = require('assert'); -var replserver = new repl.REPLServer(); +const replserver = new repl.REPLServer(); replserver._inTemplateLiteral = true; diff --git a/test/parallel/test-repl-options.js b/test/parallel/test-repl-options.js index 70244802dd0f45..79994c66d148c0 100644 --- a/test/parallel/test-repl-options.js +++ b/test/parallel/test-repl-options.js @@ -9,7 +9,7 @@ common.globalCheck = false; const stream = new common.ArrayStream(); // 1, mostly defaults -var r1 = repl.start({ +const r1 = repl.start({ input: stream, output: stream, terminal: true @@ -37,7 +37,7 @@ assert.equal(r1.useColors, r1.rli.terminal); // 2 function writer() {} function evaler() {} -var r2 = repl.start({ +const r2 = repl.start({ input: stream, output: stream, terminal: false, @@ -67,7 +67,7 @@ assert.equal(r2.rli.output, r2.outputStream); assert.equal(r2.rli.terminal, false); // testing out "magic" replMode -var r3 = repl.start({ +const r3 = repl.start({ input: stream, output: stream, writer: writer, diff --git a/test/parallel/test-repl-persistent-history.js b/test/parallel/test-repl-persistent-history.js index 25fdef81a8d5ab..2b0ceac530a65f 100644 --- a/test/parallel/test-repl-persistent-history.js +++ b/test/parallel/test-repl-persistent-history.js @@ -178,7 +178,7 @@ const tests = [ const numtests = tests.length; -var testsNotRan = tests.length; +let testsNotRan = tests.length; process.on('beforeExit', () => assert.strictEqual(testsNotRan, 0) diff --git a/test/parallel/test-repl-require.js b/test/parallel/test-repl-require.js index 9dc3b51de7a88a..25aaac47a4ed36 100644 --- a/test/parallel/test-repl-require.js +++ b/test/parallel/test-repl-require.js @@ -18,7 +18,7 @@ const host = common.localhostIPv4; const port = 0; const options = { host, port }; -var answer = ''; +let answer = ''; server.listen(options, function() { options.port = this.address().port; const conn = net.connect(options); diff --git a/test/parallel/test-repl-setprompt.js b/test/parallel/test-repl-setprompt.js index 2708a3e6af5448..8dcc4fe94452da 100644 --- a/test/parallel/test-repl-setprompt.js +++ b/test/parallel/test-repl-setprompt.js @@ -4,18 +4,18 @@ const assert = require('assert'); const spawn = require('child_process').spawn; const os = require('os'); -var args = [ +const args = [ '-e', 'var e = new (require("repl")).REPLServer("foo.. "); e.context.e = e;', ]; -var p = 'bar.. '; +const p = 'bar.. '; -var child = spawn(process.execPath, args); +const child = spawn(process.execPath, args); child.stdout.setEncoding('utf8'); -var data = ''; +let data = ''; child.stdout.on('data', function(d) { data += d; }); child.stdin.end(`e.setPrompt("${p}");${os.EOL}`); @@ -23,6 +23,6 @@ child.stdin.end(`e.setPrompt("${p}");${os.EOL}`); child.on('close', function(code, signal) { assert.strictEqual(code, 0); assert.ok(!signal); - var lines = data.split(/\n/); + const lines = data.split(/\n/); assert.strictEqual(lines.pop(), p); }); diff --git a/test/parallel/test-repl-syntax-error-handling.js b/test/parallel/test-repl-syntax-error-handling.js index 10166b4f06a692..6a65d53a029379 100644 --- a/test/parallel/test-repl-syntax-error-handling.js +++ b/test/parallel/test-repl-syntax-error-handling.js @@ -1,6 +1,6 @@ 'use strict'; require('../common'); -var assert = require('assert'); +const assert = require('assert'); switch (process.argv[2]) { case 'child': @@ -12,8 +12,8 @@ switch (process.argv[2]) { } function parent() { - var spawn = require('child_process').spawn; - var child = spawn(process.execPath, [__filename, 'child']); + const spawn = require('child_process').spawn; + const child = spawn(process.execPath, [__filename, 'child']); child.stderr.setEncoding('utf8'); child.stderr.on('data', function(c) { @@ -22,7 +22,7 @@ function parent() { }); child.stdout.setEncoding('utf8'); - var out = ''; + let out = ''; child.stdout.on('data', function(c) { out += c; }); @@ -38,11 +38,12 @@ function parent() { } function child() { - var vm = require('vm'); + const vm = require('vm'); + let caught; try { vm.runInThisContext('haf!@##&$!@$*!@', { displayErrors: false }); } catch (er) { - var caught = true; + caught = true; } assert(caught); vm.runInThisContext('console.log(10)', { displayErrors: false }); diff --git a/test/parallel/test-repl-tab-complete.js b/test/parallel/test-repl-tab-complete.js index 58201f7446f365..2eca418acb01d9 100644 --- a/test/parallel/test-repl-tab-complete.js +++ b/test/parallel/test-repl-tab-complete.js @@ -17,9 +17,9 @@ function getNoResultsFunction() { }); } -var works = [['inner.one'], 'inner.o']; +const works = [['inner.one'], 'inner.o']; const putIn = new common.ArrayStream(); -var testMe = repl.start('', putIn); +const testMe = repl.start('', putIn); // Some errors are passed to the domain, but do not callback testMe._domain.on('error', function(err) { @@ -165,7 +165,7 @@ testMe.complete('str.len', common.mustCall(function(error, data) { putIn.run(['.clear']); // tab completion should not break on spaces -var spaceTimeout = setTimeout(function() { +const spaceTimeout = setTimeout(function() { throw new Error('timeout'); }, 1000); diff --git a/test/parallel/test-repl-tab.js b/test/parallel/test-repl-tab.js index c075b8d4f1125f..a381d603fbeb84 100644 --- a/test/parallel/test-repl-tab.js +++ b/test/parallel/test-repl-tab.js @@ -1,12 +1,13 @@ 'use strict'; const common = require('../common'); -var assert = require('assert'); -var repl = require('repl'); -var zlib = require('zlib'); +const assert = require('assert'); +const repl = require('repl'); +const zlib = require('zlib'); // just use builtin stream inherited from Duplex -var putIn = zlib.createGzip(); -var testMe = repl.start('', putIn, function(cmd, context, filename, callback) { +const putIn = zlib.createGzip(); +const testMe = repl.start('', putIn, function(cmd, context, + filename, callback) { callback(null, cmd); }); diff --git a/test/parallel/test-repl-unexpected-token-recoverable.js b/test/parallel/test-repl-unexpected-token-recoverable.js index 84668c8657c453..0f783d3dcaf27b 100644 --- a/test/parallel/test-repl-unexpected-token-recoverable.js +++ b/test/parallel/test-repl-unexpected-token-recoverable.js @@ -3,16 +3,16 @@ * This is a regression test for https://github.com/joyent/node/issues/8874. */ require('../common'); -var assert = require('assert'); +const assert = require('assert'); -var spawn = require('child_process').spawn; +const spawn = require('child_process').spawn; // use -i to force node into interactive mode, despite stdout not being a TTY -var args = [ '-i' ]; -var child = spawn(process.execPath, args); +const args = [ '-i' ]; +const child = spawn(process.execPath, args); -var input = 'var foo = "bar\\\nbaz"'; +const input = 'var foo = "bar\\\nbaz"'; // Match '...' as well since it marks a multi-line statement -var expectOut = /^> ... undefined\n/; +const expectOut = /^> ... undefined\n/; child.stderr.setEncoding('utf8'); child.stderr.on('data', function(c) { @@ -20,7 +20,7 @@ child.stderr.on('data', function(c) { }); child.stdout.setEncoding('utf8'); -var out = ''; +let out = ''; child.stdout.on('data', function(c) { out += c; }); diff --git a/test/parallel/test-require-cache.js b/test/parallel/test-require-cache.js index 247590197d6126..437dd80e581e38 100644 --- a/test/parallel/test-require-cache.js +++ b/test/parallel/test-require-cache.js @@ -1,6 +1,6 @@ 'use strict'; require('../common'); -var assert = require('assert'); +const assert = require('assert'); { const relativePath = '../fixtures/semicolon'; diff --git a/test/parallel/test-require-extensions-same-filename-as-dir-trailing-slash.js b/test/parallel/test-require-extensions-same-filename-as-dir-trailing-slash.js index 1837a17bab0add..0a80a860388de9 100644 --- a/test/parallel/test-require-extensions-same-filename-as-dir-trailing-slash.js +++ b/test/parallel/test-require-extensions-same-filename-as-dir-trailing-slash.js @@ -1,9 +1,9 @@ /* eslint-disable max-len */ 'use strict'; -var common = require('../common'); -var assert = require('assert'); +const common = require('../common'); +const assert = require('assert'); -var content = require(common.fixturesDir + +const content = require(common.fixturesDir + '/json-with-directory-name-module/module-stub/one-trailing-slash/two/three.js'); assert.notEqual(content.rocko, 'artischocko'); diff --git a/test/parallel/test-require-process.js b/test/parallel/test-require-process.js index 4e5821add13183..f2a3ac89a862fe 100644 --- a/test/parallel/test-require-process.js +++ b/test/parallel/test-require-process.js @@ -1,7 +1,7 @@ 'use strict'; require('../common'); -var assert = require('assert'); +const assert = require('assert'); -var nativeProcess = require('process'); +const nativeProcess = require('process'); assert.strictEqual(nativeProcess, process, 'require("process") should return global process reference'); diff --git a/test/parallel/test-sigint-infinite-loop.js b/test/parallel/test-sigint-infinite-loop.js index ecd64802acb627..30eb98ecb8a265 100644 --- a/test/parallel/test-sigint-infinite-loop.js +++ b/test/parallel/test-sigint-infinite-loop.js @@ -3,14 +3,14 @@ // Ref(http): // groups.google.com/group/nodejs-dev/browse_thread/thread/e20f2f8df0296d3f const common = require('../common'); -var assert = require('assert'); -var spawn = require('child_process').spawn; +const assert = require('assert'); +const spawn = require('child_process').spawn; console.log('start'); -var c = spawn(process.execPath, ['-e', 'while(true) { console.log("hi"); }']); +const c = spawn(process.execPath, ['-e', 'while(true) { console.log("hi"); }']); -var sentKill = false; +let sentKill = false; c.stdout.on('data', function(s) { // Prevent race condition: diff --git a/test/parallel/test-signal-handler.js b/test/parallel/test-signal-handler.js index 079c72a9e56a8a..b796ebb11d211c 100644 --- a/test/parallel/test-signal-handler.js +++ b/test/parallel/test-signal-handler.js @@ -18,7 +18,7 @@ process.on('SIGUSR1', common.mustCall(function() { }, 5); })); -var i = 0; +let i = 0; setInterval(function() { console.log('running process...' + ++i); diff --git a/test/parallel/test-signal-safety.js b/test/parallel/test-signal-safety.js index 7938ae04d6591b..34722b712f8889 100644 --- a/test/parallel/test-signal-safety.js +++ b/test/parallel/test-signal-safety.js @@ -1,12 +1,12 @@ 'use strict'; require('../common'); -var assert = require('assert'); -var Signal = process.binding('signal_wrap').Signal; +const assert = require('assert'); +const Signal = process.binding('signal_wrap').Signal; // Test Signal `this` safety // https://github.com/joyent/node/issues/6690 assert.throws(function() { - var s = new Signal(); - var nots = { start: s.start }; + const s = new Signal(); + const nots = { start: s.start }; nots.start(9); }, TypeError); diff --git a/test/parallel/test-socket-write-after-fin-error.js b/test/parallel/test-socket-write-after-fin-error.js index 480d5d2edc321e..58ae1d62b2f172 100644 --- a/test/parallel/test-socket-write-after-fin-error.js +++ b/test/parallel/test-socket-write-after-fin-error.js @@ -1,20 +1,20 @@ 'use strict'; require('../common'); -var assert = require('assert'); +const assert = require('assert'); // This is similar to simple/test-socket-write-after-fin, except that // we don't set allowHalfOpen. Then we write after the client has sent // a FIN, and this is an error. However, the standard "write after end" // message is too vague, and doesn't actually tell you what happens. -var net = require('net'); -var serverData = ''; -var gotServerEnd = false; -var clientData = ''; -var gotClientEnd = false; -var gotServerError = false; +const net = require('net'); +let serverData = ''; +let gotServerEnd = false; +let clientData = ''; +let gotClientEnd = false; +let gotServerError = false; -var server = net.createServer(function(sock) { +const server = net.createServer(function(sock) { sock.setEncoding('utf8'); sock.on('error', function(er) { console.error(er.code + ': ' + er.message); @@ -32,7 +32,7 @@ var server = net.createServer(function(sock) { server.close(); }); server.listen(0, function() { - var sock = net.connect(this.address().port); + const sock = net.connect(this.address().port); sock.setEncoding('utf8'); sock.on('data', function(c) { clientData += c; diff --git a/test/parallel/test-socket-write-after-fin.js b/test/parallel/test-socket-write-after-fin.js index 70f0d9bf843f9b..c8ff56871734af 100644 --- a/test/parallel/test-socket-write-after-fin.js +++ b/test/parallel/test-socket-write-after-fin.js @@ -1,13 +1,13 @@ 'use strict'; const common = require('../common'); -var assert = require('assert'); -var net = require('net'); +const assert = require('assert'); +const net = require('net'); const expected = 'hello1hello2hello3\nTHUNDERMUSCLE!'; -var server = net.createServer({ +const server = net.createServer({ allowHalfOpen: true }, common.mustCall(function(sock) { - var serverData = ''; + let serverData = ''; sock.setEncoding('utf8'); sock.on('data', function(c) { @@ -20,8 +20,8 @@ var server = net.createServer({ })); })); server.listen(0, common.mustCall(function() { - var sock = net.connect(this.address().port); - var clientData = ''; + const sock = net.connect(this.address().port); + let clientData = ''; sock.setEncoding('utf8'); sock.on('data', function(c) { diff --git a/test/parallel/test-stdin-pipe-resume.js b/test/parallel/test-stdin-pipe-resume.js index cb288070450a1f..06cce3edfe403f 100644 --- a/test/parallel/test-stdin-pipe-resume.js +++ b/test/parallel/test-stdin-pipe-resume.js @@ -1,19 +1,19 @@ 'use strict'; // This tests that piping stdin will cause it to resume() as well. require('../common'); -var assert = require('assert'); +const assert = require('assert'); if (process.argv[2] === 'child') { process.stdin.pipe(process.stdout); } else { - var spawn = require('child_process').spawn; - var buffers = []; - var child = spawn(process.execPath, [__filename, 'child']); + const spawn = require('child_process').spawn; + const buffers = []; + const child = spawn(process.execPath, [__filename, 'child']); child.stdout.on('data', function(c) { buffers.push(c); }); child.stdout.on('close', function() { - var b = Buffer.concat(buffers).toString(); + const b = Buffer.concat(buffers).toString(); assert.equal(b, 'Hello, world\n'); console.log('ok'); }); diff --git a/test/parallel/test-stdin-script-child.js b/test/parallel/test-stdin-script-child.js index 091c5cb29ad296..a8a161686eeeef 100644 --- a/test/parallel/test-stdin-script-child.js +++ b/test/parallel/test-stdin-script-child.js @@ -9,7 +9,7 @@ const child = spawn(process.execPath, [], { }) }); const wanted = child.pid + '\n'; -var found = ''; +let found = ''; child.stdout.setEncoding('utf8'); child.stdout.on('data', function(c) { diff --git a/test/parallel/test-stdio-readable-writable.js b/test/parallel/test-stdio-readable-writable.js index 7b9b69d309aec5..0bc7fe269b3303 100644 --- a/test/parallel/test-stdio-readable-writable.js +++ b/test/parallel/test-stdio-readable-writable.js @@ -1,6 +1,6 @@ 'use strict'; require('../common'); -var assert = require('assert'); +const assert = require('assert'); assert(process.stdout.writable); assert(!process.stdout.readable); diff --git a/test/parallel/test-stdout-cannot-be-closed-child-process-pipe.js b/test/parallel/test-stdout-cannot-be-closed-child-process-pipe.js index a138108fae7e01..aa1939ebe2c334 100644 --- a/test/parallel/test-stdout-cannot-be-closed-child-process-pipe.js +++ b/test/parallel/test-stdout-cannot-be-closed-child-process-pipe.js @@ -1,6 +1,6 @@ 'use strict'; require('../common'); -var assert = require('assert'); +const assert = require('assert'); if (process.argv[2] === 'child') process.stdout.end('foo'); @@ -8,10 +8,10 @@ else parent(); function parent() { - var spawn = require('child_process').spawn; - var child = spawn(process.execPath, [__filename, 'child']); - var out = ''; - var err = ''; + const spawn = require('child_process').spawn; + const child = spawn(process.execPath, [__filename, 'child']); + let out = ''; + let err = ''; child.stdout.setEncoding('utf8'); child.stderr.setEncoding('utf8'); diff --git a/test/parallel/test-stdout-stderr-reading.js b/test/parallel/test-stdout-stderr-reading.js index e154d41b6bb8d1..6aa961301349fc 100644 --- a/test/parallel/test-stdout-stderr-reading.js +++ b/test/parallel/test-stdout-stderr-reading.js @@ -1,10 +1,10 @@ 'use strict'; const common = require('../common'); -var assert = require('assert'); +const assert = require('assert'); // verify that stdout is never read from. -var net = require('net'); -var read = net.Socket.prototype.read; +const net = require('net'); +const read = net.Socket.prototype.read; net.Socket.prototype.read = function() { if (this.fd === 1) @@ -20,11 +20,11 @@ else parent(); function parent() { - var spawn = require('child_process').spawn; - var node = process.execPath; + const spawn = require('child_process').spawn; + const node = process.execPath; - var c1 = spawn(node, [__filename, 'child']); - var c1out = ''; + const c1 = spawn(node, [__filename, 'child']); + let c1out = ''; c1.stdout.setEncoding('utf8'); c1.stdout.on('data', function(chunk) { c1out += chunk; @@ -40,8 +40,8 @@ function parent() { console.log('ok'); })); - var c2 = spawn(node, ['-e', 'console.log("ok")']); - var c2out = ''; + const c2 = spawn(node, ['-e', 'console.log("ok")']); + let c2out = ''; c2.stdout.setEncoding('utf8'); c2.stdout.on('data', function(chunk) { c2out += chunk; diff --git a/test/parallel/test-stdout-to-file.js b/test/parallel/test-stdout-to-file.js index 10391c481a826d..870d77eadf41f3 100644 --- a/test/parallel/test-stdout-to-file.js +++ b/test/parallel/test-stdout-to-file.js @@ -13,13 +13,13 @@ const tmpFile = path.join(common.tmpDir, 'stdout.txt'); common.refreshTmpDir(); function test(size, useBuffer, cb) { - var cmd = '"' + process.argv[0] + '"' + - ' ' + - '"' + (useBuffer ? scriptBuffer : scriptString) + '"' + - ' ' + - size + - ' > ' + - '"' + tmpFile + '"'; + const cmd = '"' + process.argv[0] + '"' + + ' ' + + '"' + (useBuffer ? scriptBuffer : scriptString) + '"' + + ' ' + + size + + ' > ' + + '"' + tmpFile + '"'; try { fs.unlinkSync(tmpFile); @@ -32,7 +32,7 @@ function test(size, useBuffer, cb) { console.log('done!'); - var stat = fs.statSync(tmpFile); + const stat = fs.statSync(tmpFile); console.log(`${tmpFile} has ${stat.size} bytes`); diff --git a/test/parallel/test-stream-base-no-abort.js b/test/parallel/test-stream-base-no-abort.js index 85840c4c1c3b42..87c8f963485ab8 100644 --- a/test/parallel/test-stream-base-no-abort.js +++ b/test/parallel/test-stream-base-no-abort.js @@ -9,7 +9,7 @@ const fs = require('fs'); const net = require('net'); const tls = require('tls'); const providers = Object.keys(async_wrap.Providers); -var flags = 0; +let flags = 0; // Make sure all asserts have run at least once. process.on('exit', () => assert.equal(flags, 0b111)); diff --git a/test/parallel/test-stream-big-push.js b/test/parallel/test-stream-big-push.js index 27feef35ef536d..9083820d42b546 100644 --- a/test/parallel/test-stream-big-push.js +++ b/test/parallel/test-stream-big-push.js @@ -18,7 +18,7 @@ function _read() { }, 1); reads++; } else if (reads === 1) { - var ret = r.push(str); + const ret = r.push(str); assert.strictEqual(ret, false); reads++; } else { @@ -32,10 +32,10 @@ r.on('end', common.mustCall(function() {})); // push some data in to start. // we've never gotten any read event at this point. -var ret = r.push(str); +const ret = r.push(str); // should be false. > hwm assert(!ret); -var chunk = r.read(); +let chunk = r.read(); assert.strictEqual(chunk, str); chunk = r.read(); assert.strictEqual(chunk, null); diff --git a/test/parallel/test-stream-pipe-event.js b/test/parallel/test-stream-pipe-event.js index d8601dd04a4d8e..1b5447eaa21ff9 100644 --- a/test/parallel/test-stream-pipe-event.js +++ b/test/parallel/test-stream-pipe-event.js @@ -1,8 +1,8 @@ 'use strict'; require('../common'); -var stream = require('stream'); -var assert = require('assert'); -var util = require('util'); +const stream = require('stream'); +const assert = require('assert'); +const util = require('util'); function Writable() { this.writable = true; @@ -16,14 +16,14 @@ function Readable() { } util.inherits(Readable, stream.Stream); -var passed = false; +let passed = false; -var w = new Writable(); +const w = new Writable(); w.on('pipe', function(src) { passed = true; }); -var r = new Readable(); +const r = new Readable(); r.pipe(w); assert.ok(passed); diff --git a/test/parallel/test-stream-push-order.js b/test/parallel/test-stream-push-order.js index 22a3156f62f502..5fc1f5e89cf156 100644 --- a/test/parallel/test-stream-push-order.js +++ b/test/parallel/test-stream-push-order.js @@ -1,21 +1,21 @@ 'use strict'; require('../common'); -var Readable = require('stream').Readable; -var assert = require('assert'); +const Readable = require('stream').Readable; +const assert = require('assert'); -var s = new Readable({ +const s = new Readable({ highWaterMark: 20, encoding: 'ascii' }); -var list = ['1', '2', '3', '4', '5', '6']; +const list = ['1', '2', '3', '4', '5', '6']; s._read = function(n) { - var one = list.shift(); + const one = list.shift(); if (!one) { s.push(null); } else { - var two = list.shift(); + const two = list.shift(); s.push(one); s.push(two); } diff --git a/test/parallel/test-stream-push-strings.js b/test/parallel/test-stream-push-strings.js index a5ebe4d3e917f6..7bce493bbd33ce 100644 --- a/test/parallel/test-stream-push-strings.js +++ b/test/parallel/test-stream-push-strings.js @@ -1,9 +1,9 @@ 'use strict'; require('../common'); -var assert = require('assert'); +const assert = require('assert'); -var Readable = require('stream').Readable; -var util = require('util'); +const Readable = require('stream').Readable; +const util = require('util'); util.inherits(MyStream, Readable); function MyStream(options) { @@ -30,15 +30,15 @@ MyStream.prototype._read = function(n) { } }; -var ms = new MyStream(); -var results = []; +const ms = new MyStream(); +const results = []; ms.on('readable', function() { - var chunk; + let chunk; while (null !== (chunk = ms.read())) results.push(chunk + ''); }); -var expect = [ 'first chunksecond to last chunk', 'last chunk' ]; +const expect = [ 'first chunksecond to last chunk', 'last chunk' ]; process.on('exit', function() { assert.equal(ms._chunks, -1); assert.deepStrictEqual(results, expect); diff --git a/test/parallel/test-stream-readable-constructor-set-methods.js b/test/parallel/test-stream-readable-constructor-set-methods.js index fb2114f44dad19..a5d7e48bfb3fa9 100644 --- a/test/parallel/test-stream-readable-constructor-set-methods.js +++ b/test/parallel/test-stream-readable-constructor-set-methods.js @@ -1,16 +1,16 @@ 'use strict'; require('../common'); -var assert = require('assert'); +const assert = require('assert'); -var Readable = require('stream').Readable; +const Readable = require('stream').Readable; -var _readCalled = false; +let _readCalled = false; function _read(n) { _readCalled = true; this.push(null); } -var r = new Readable({ read: _read }); +const r = new Readable({ read: _read }); r.resume(); process.on('exit', function() { diff --git a/test/parallel/test-stream-readable-flow-recursion.js b/test/parallel/test-stream-readable-flow-recursion.js index 0c0b16e8f5ca7e..b1e421a71fd15b 100644 --- a/test/parallel/test-stream-readable-flow-recursion.js +++ b/test/parallel/test-stream-readable-flow-recursion.js @@ -1,20 +1,20 @@ 'use strict'; require('../common'); -var assert = require('assert'); +const assert = require('assert'); // this test verifies that passing a huge number to read(size) // will push up the highWaterMark, and cause the stream to read // more data continuously, but without triggering a nextTick // warning or RangeError. -var Readable = require('stream').Readable; +const Readable = require('stream').Readable; // throw an error if we trigger a nextTick warning. process.throwDeprecation = true; -var stream = new Readable({ highWaterMark: 2 }); -var reads = 0; -var total = 5000; +const stream = new Readable({ highWaterMark: 2 }); +let reads = 0; +let total = 5000; stream._read = function(size) { reads++; size = Math.min(size, total); @@ -25,11 +25,11 @@ stream._read = function(size) { stream.push(Buffer.allocUnsafe(size)); }; -var depth = 0; +let depth = 0; function flow(stream, size, callback) { depth += 1; - var chunk = stream.read(size); + const chunk = stream.read(size); if (!chunk) stream.once('readable', flow.bind(null, stream, size, callback)); diff --git a/test/parallel/test-stream-transform-constructor-set-methods.js b/test/parallel/test-stream-transform-constructor-set-methods.js index 720357a01b9839..7be673c517b30b 100644 --- a/test/parallel/test-stream-transform-constructor-set-methods.js +++ b/test/parallel/test-stream-transform-constructor-set-methods.js @@ -1,22 +1,22 @@ 'use strict'; require('../common'); -var assert = require('assert'); +const assert = require('assert'); -var Transform = require('stream').Transform; +const Transform = require('stream').Transform; -var _transformCalled = false; +let _transformCalled = false; function _transform(d, e, n) { _transformCalled = true; n(); } -var _flushCalled = false; +let _flushCalled = false; function _flush(n) { _flushCalled = true; n(); } -var t = new Transform({ +const t = new Transform({ transform: _transform, flush: _flush }); diff --git a/test/parallel/test-stream-transform-objectmode-falsey-value.js b/test/parallel/test-stream-transform-objectmode-falsey-value.js index 5291a4b7fe89a0..4107bc1675421e 100644 --- a/test/parallel/test-stream-transform-objectmode-falsey-value.js +++ b/test/parallel/test-stream-transform-objectmode-falsey-value.js @@ -1,16 +1,16 @@ 'use strict'; require('../common'); -var assert = require('assert'); +const assert = require('assert'); -var stream = require('stream'); -var PassThrough = stream.PassThrough; +const stream = require('stream'); +const PassThrough = stream.PassThrough; -var src = new PassThrough({ objectMode: true }); -var tx = new PassThrough({ objectMode: true }); -var dest = new PassThrough({ objectMode: true }); +const src = new PassThrough({ objectMode: true }); +const tx = new PassThrough({ objectMode: true }); +const dest = new PassThrough({ objectMode: true }); -var expect = [ -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ]; -var results = []; +const expect = [ -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ]; +const results = []; process.on('exit', function() { assert.deepStrictEqual(results, expect); console.log('ok'); @@ -22,8 +22,8 @@ dest.on('data', function(x) { src.pipe(tx).pipe(dest); -var i = -1; -var int = setInterval(function() { +let i = -1; +const int = setInterval(function() { if (i > 10) { src.end(); clearInterval(int); diff --git a/test/parallel/test-stream-transform-split-objectmode.js b/test/parallel/test-stream-transform-split-objectmode.js index 610f234bead901..52185e18711090 100644 --- a/test/parallel/test-stream-transform-split-objectmode.js +++ b/test/parallel/test-stream-transform-split-objectmode.js @@ -1,10 +1,10 @@ 'use strict'; require('../common'); -var assert = require('assert'); +const assert = require('assert'); -var Transform = require('stream').Transform; +const Transform = require('stream').Transform; -var parser = new Transform({ readableObjectMode: true }); +const parser = new Transform({ readableObjectMode: true }); assert(parser._readableState.objectMode); assert(!parser._writableState.objectMode); @@ -15,7 +15,7 @@ parser._transform = function(chunk, enc, callback) { callback(null, { val: chunk[0] }); }; -var parsed; +let parsed; parser.on('data', function(obj) { parsed = obj; @@ -28,7 +28,7 @@ process.on('exit', function() { }); -var serializer = new Transform({ writableObjectMode: true }); +const serializer = new Transform({ writableObjectMode: true }); assert(!serializer._readableState.objectMode); assert(serializer._writableState.objectMode); @@ -39,7 +39,7 @@ serializer._transform = function(obj, _, callback) { callback(null, Buffer.from([obj.val])); }; -var serialized; +let serialized; serializer.on('data', function(chunk) { serialized = chunk; diff --git a/test/parallel/test-stream-unshift-empty-chunk.js b/test/parallel/test-stream-unshift-empty-chunk.js index 477f5c4be56bac..d555fd7cae2330 100644 --- a/test/parallel/test-stream-unshift-empty-chunk.js +++ b/test/parallel/test-stream-unshift-empty-chunk.js @@ -1,14 +1,14 @@ 'use strict'; require('../common'); -var assert = require('assert'); +const assert = require('assert'); // This test verifies that stream.unshift(Buffer.alloc(0)) or // stream.unshift('') does not set state.reading=false. -var Readable = require('stream').Readable; +const Readable = require('stream').Readable; -var r = new Readable(); -var nChunks = 10; -var chunk = Buffer.alloc(10, 'x'); +const r = new Readable(); +let nChunks = 10; +const chunk = Buffer.alloc(10, 'x'); r._read = function(n) { setImmediate(function() { @@ -16,10 +16,10 @@ r._read = function(n) { }); }; -var readAll = false; -var seen = []; +let readAll = false; +const seen = []; r.on('readable', function() { - var chunk; + let chunk; while (chunk = r.read()) { seen.push(chunk.toString()); // simulate only reading a certain amount of the data, @@ -27,13 +27,13 @@ r.on('readable', function() { // stream, like a parser might do. We just fill it with // 'y' so that it's easy to see which bits were touched, // and which were not. - var putBack = Buffer.alloc(readAll ? 0 : 5, 'y'); + const putBack = Buffer.alloc(readAll ? 0 : 5, 'y'); readAll = !readAll; r.unshift(putBack); } }); -var expect = +const expect = [ 'xxxxxxxxxx', 'yyyyy', 'xxxxxxxxxx', diff --git a/test/parallel/test-stream-wrap.js b/test/parallel/test-stream-wrap.js index 69e4dee89d3b13..dbcb58a98cd8b2 100644 --- a/test/parallel/test-stream-wrap.js +++ b/test/parallel/test-stream-wrap.js @@ -7,16 +7,16 @@ const Duplex = require('stream').Duplex; const ShutdownWrap = process.binding('stream_wrap').ShutdownWrap; function testShutdown(callback) { - var stream = new Duplex({ + const stream = new Duplex({ read: function() { }, write: function() { } }); - var wrap = new StreamWrap(stream); + const wrap = new StreamWrap(stream); - var req = new ShutdownWrap(); + const req = new ShutdownWrap(); req.oncomplete = function(code) { assert(code < 0); callback(); diff --git a/test/parallel/test-stream-writable-change-default-encoding.js b/test/parallel/test-stream-writable-change-default-encoding.js index d1d4af5b824baf..9eac52bc1aea44 100644 --- a/test/parallel/test-stream-writable-change-default-encoding.js +++ b/test/parallel/test-stream-writable-change-default-encoding.js @@ -1,9 +1,9 @@ 'use strict'; require('../common'); -var assert = require('assert'); +const assert = require('assert'); -var stream = require('stream'); -var util = require('util'); +const stream = require('stream'); +const util = require('util'); function MyWritable(fn, options) { stream.Writable.call(this, options); @@ -18,7 +18,7 @@ MyWritable.prototype._write = function(chunk, encoding, callback) { }; (function defaultCondingIsUtf8() { - var m = new MyWritable(function(isBuffer, type, enc) { + const m = new MyWritable(function(isBuffer, type, enc) { assert.equal(enc, 'utf8'); }, { decodeStrings: false }); m.write('foo'); @@ -26,7 +26,7 @@ MyWritable.prototype._write = function(chunk, encoding, callback) { }()); (function changeDefaultEncodingToAscii() { - var m = new MyWritable(function(isBuffer, type, enc) { + const m = new MyWritable(function(isBuffer, type, enc) { assert.equal(enc, 'ascii'); }, { decodeStrings: false }); m.setDefaultEncoding('ascii'); @@ -35,7 +35,7 @@ MyWritable.prototype._write = function(chunk, encoding, callback) { }()); assert.throws(function changeDefaultEncodingToInvalidValue() { - var m = new MyWritable(function(isBuffer, type, enc) { + const m = new MyWritable(function(isBuffer, type, enc) { }, { decodeStrings: false }); m.setDefaultEncoding({}); m.write('bar'); @@ -43,7 +43,7 @@ assert.throws(function changeDefaultEncodingToInvalidValue() { }, TypeError); (function checkVairableCaseEncoding() { - var m = new MyWritable(function(isBuffer, type, enc) { + const m = new MyWritable(function(isBuffer, type, enc) { assert.equal(enc, 'ascii'); }, { decodeStrings: false }); m.setDefaultEncoding('AsCii'); diff --git a/test/parallel/test-stream-writable-constructor-set-methods.js b/test/parallel/test-stream-writable-constructor-set-methods.js index 7d7dfb5f1ccfa0..9b344487f61580 100644 --- a/test/parallel/test-stream-writable-constructor-set-methods.js +++ b/test/parallel/test-stream-writable-constructor-set-methods.js @@ -1,25 +1,25 @@ 'use strict'; require('../common'); -var assert = require('assert'); +const assert = require('assert'); -var Writable = require('stream').Writable; +const Writable = require('stream').Writable; -var _writeCalled = false; +let _writeCalled = false; function _write(d, e, n) { _writeCalled = true; } -var w = new Writable({ write: _write }); +const w = new Writable({ write: _write }); w.end(Buffer.from('blerg')); -var _writevCalled = false; -var dLength = 0; +let _writevCalled = false; +let dLength = 0; function _writev(d, n) { dLength = d.length; _writevCalled = true; } -var w2 = new Writable({ writev: _writev }); +const w2 = new Writable({ writev: _writev }); w2.cork(); w2.write(Buffer.from('blerg')); diff --git a/test/parallel/test-stream-writable-decoded-encoding.js b/test/parallel/test-stream-writable-decoded-encoding.js index 621e342a3c2d74..4c903a0b012e3e 100644 --- a/test/parallel/test-stream-writable-decoded-encoding.js +++ b/test/parallel/test-stream-writable-decoded-encoding.js @@ -1,9 +1,9 @@ 'use strict'; require('../common'); -var assert = require('assert'); +const assert = require('assert'); -var stream = require('stream'); -var util = require('util'); +const stream = require('stream'); +const util = require('util'); function MyWritable(fn, options) { stream.Writable.call(this, options); diff --git a/test/parallel/test-stream-writable-null.js b/test/parallel/test-stream-writable-null.js index 2cc396bd916a3e..438f250a17dde6 100644 --- a/test/parallel/test-stream-writable-null.js +++ b/test/parallel/test-stream-writable-null.js @@ -17,11 +17,11 @@ MyWritable.prototype._write = function(chunk, encoding, callback) { }; assert.throws(() => { - var m = new MyWritable({objectMode: true}); + const m = new MyWritable({objectMode: true}); m.write(null, (err) => assert.ok(err)); }, TypeError, 'May not write null values to stream'); assert.doesNotThrow(() => { - var m = new MyWritable({objectMode: true}).on('error', (e) => { + const m = new MyWritable({objectMode: true}).on('error', (e) => { assert.ok(e); }); m.write(null, (err) => { @@ -30,11 +30,11 @@ assert.doesNotThrow(() => { }); assert.throws(() => { - var m = new MyWritable(); + const m = new MyWritable(); m.write(false, (err) => assert.ok(err)); }, TypeError, 'Invalid non-string/buffer chunk'); assert.doesNotThrow(() => { - var m = new MyWritable().on('error', (e) => { + const m = new MyWritable().on('error', (e) => { assert.ok(e); }); m.write(false, (err) => { @@ -43,11 +43,11 @@ assert.doesNotThrow(() => { }); assert.doesNotThrow(() => { - var m = new MyWritable({objectMode: true}); + const m = new MyWritable({objectMode: true}); m.write(false, (err) => assert.ifError(err)); }); assert.doesNotThrow(() => { - var m = new MyWritable({objectMode: true}).on('error', (e) => { + const m = new MyWritable({objectMode: true}).on('error', (e) => { assert.ifError(e || new Error('should not get here')); }); m.write(false, (err) => { diff --git a/test/parallel/test-stream-writev.js b/test/parallel/test-stream-writev.js index 92479fc88f2958..91c064c102b490 100644 --- a/test/parallel/test-stream-writev.js +++ b/test/parallel/test-stream-writev.js @@ -1,13 +1,13 @@ 'use strict'; require('../common'); -var assert = require('assert'); +const assert = require('assert'); -var stream = require('stream'); +const stream = require('stream'); -var queue = []; -for (var decode = 0; decode < 2; decode++) { - for (var uncork = 0; uncork < 2; uncork++) { - for (var multi = 0; multi < 2; multi++) { +const queue = []; +for (let decode = 0; decode < 2; decode++) { + for (let uncork = 0; uncork < 2; uncork++) { + for (let multi = 0; multi < 2; multi++) { queue.push([!!decode, !!uncork, !!multi]); } } @@ -16,7 +16,7 @@ for (var decode = 0; decode < 2; decode++) { run(); function run() { - var t = queue.pop(); + const t = queue.pop(); if (t) test(t[0], t[1], t[2], run); else @@ -25,11 +25,11 @@ function run() { function test(decode, uncork, multi, next) { console.log('# decode=%j uncork=%j multi=%j', decode, uncork, multi); - var counter = 0; - var expectCount = 0; + let counter = 0; + let expectCount = 0; function cnt(msg) { expectCount++; - var expect = expectCount; + const expect = expectCount; return function(er) { if (er) throw er; @@ -38,12 +38,12 @@ function test(decode, uncork, multi, next) { }; } - var w = new stream.Writable({ decodeStrings: decode }); + const w = new stream.Writable({ decodeStrings: decode }); w._write = function(chunk, e, cb) { assert(false, 'Should not call _write'); }; - var expectChunks = decode ? [ + const expectChunks = decode ? [ { encoding: 'buffer', chunk: [104, 101, 108, 108, 111, 44, 32] }, { encoding: 'buffer', @@ -62,7 +62,7 @@ function test(decode, uncork, multi, next) { { encoding: 'hex', chunk: 'facebea7deadbeefdecafbad' } ]; - var actualChunks; + let actualChunks; w._writev = function(chunks, cb) { actualChunks = chunks.map(function(chunk) { return { diff --git a/test/parallel/test-stream2-base64-single-char-read-end.js b/test/parallel/test-stream2-base64-single-char-read-end.js index 50bafc3737385d..1b14b7f6b4517c 100644 --- a/test/parallel/test-stream2-base64-single-char-read-end.js +++ b/test/parallel/test-stream2-base64-single-char-read-end.js @@ -1,14 +1,14 @@ 'use strict'; const common = require('../common'); -var R = require('_stream_readable'); -var W = require('_stream_writable'); -var assert = require('assert'); +const R = require('_stream_readable'); +const W = require('_stream_writable'); +const assert = require('assert'); -var src = new R({encoding: 'base64'}); -var dst = new W(); -var hasRead = false; -var accum = []; -var timeout; +const src = new R({encoding: 'base64'}); +const dst = new W(); +let hasRead = false; +const accum = []; +let timeout; src._read = function(n) { if (!hasRead) { diff --git a/test/parallel/test-stream2-compatibility.js b/test/parallel/test-stream2-compatibility.js index 77312456590b25..f7c980791311da 100644 --- a/test/parallel/test-stream2-compatibility.js +++ b/test/parallel/test-stream2-compatibility.js @@ -1,12 +1,12 @@ 'use strict'; require('../common'); -var R = require('_stream_readable'); -var W = require('_stream_writable'); -var assert = require('assert'); +const R = require('_stream_readable'); +const W = require('_stream_writable'); +const assert = require('assert'); -var util = require('util'); +const util = require('util'); -var ondataCalled = 0; +let ondataCalled = 0; function TestReader() { R.apply(this); @@ -24,7 +24,7 @@ TestReader.prototype._read = function(n) { this._buffer = Buffer.alloc(0); }; -var reader = new TestReader(); +const reader = new TestReader(); setImmediate(function() { assert.equal(ondataCalled, 1); console.log('ok'); @@ -43,7 +43,7 @@ TestWriter.prototype._write = function(chunk, enc, cb) { cb(); }; -var writer = new TestWriter(); +const writer = new TestWriter(); process.on('exit', function() { assert.strictEqual(reader.readable, false); diff --git a/test/parallel/test-stream2-decode-partial.js b/test/parallel/test-stream2-decode-partial.js index b58e192b9c33bb..b43101dbc84c3a 100644 --- a/test/parallel/test-stream2-decode-partial.js +++ b/test/parallel/test-stream2-decode-partial.js @@ -3,7 +3,7 @@ require('../common'); const Readable = require('_stream_readable'); const assert = require('assert'); -var buf = ''; +let buf = ''; const euro = new Buffer([0xE2, 0x82, 0xAC]); const cent = new Buffer([0xC2, 0xA2]); const source = Buffer.concat([euro, cent]); diff --git a/test/parallel/test-stream2-finish-pipe.js b/test/parallel/test-stream2-finish-pipe.js index fb489978f498ad..87edf5a5fa6437 100644 --- a/test/parallel/test-stream2-finish-pipe.js +++ b/test/parallel/test-stream2-finish-pipe.js @@ -1,14 +1,14 @@ 'use strict'; require('../common'); -var stream = require('stream'); -var Buffer = require('buffer').Buffer; +const stream = require('stream'); +const Buffer = require('buffer').Buffer; -var r = new stream.Readable(); +const r = new stream.Readable(); r._read = function(size) { r.push(Buffer.allocUnsafe(size)); }; -var w = new stream.Writable(); +const w = new stream.Writable(); w._write = function(data, encoding, cb) { cb(null); }; diff --git a/test/parallel/test-stream2-httpclient-response-end.js b/test/parallel/test-stream2-httpclient-response-end.js index d674086055e431..6d3da191b06cb9 100644 --- a/test/parallel/test-stream2-httpclient-response-end.js +++ b/test/parallel/test-stream2-httpclient-response-end.js @@ -1,14 +1,14 @@ 'use strict'; const common = require('../common'); -var assert = require('assert'); -var http = require('http'); -var msg = 'Hello'; -var server = http.createServer(function(req, res) { +const assert = require('assert'); +const http = require('http'); +const msg = 'Hello'; +const server = http.createServer(function(req, res) { res.writeHead(200, {'Content-Type': 'text/plain'}); res.end(msg); }).listen(0, function() { http.get({port: this.address().port}, function(res) { - var data = ''; + let data = ''; res.on('readable', common.mustCall(function() { console.log('readable event'); data += res.read(); diff --git a/test/parallel/test-stream2-large-read-stall.js b/test/parallel/test-stream2-large-read-stall.js index 91eb716cfa8e2a..2422747f820bc1 100644 --- a/test/parallel/test-stream2-large-read-stall.js +++ b/test/parallel/test-stream2-large-read-stall.js @@ -1,28 +1,29 @@ 'use strict'; const common = require('../common'); -var assert = require('assert'); +const assert = require('assert'); // If everything aligns so that you do a read(n) of exactly the // remaining buffer, then make sure that 'end' still emits. -var READSIZE = 100; -var PUSHSIZE = 20; -var PUSHCOUNT = 1000; -var HWM = 50; +const READSIZE = 100; +const PUSHSIZE = 20; +const PUSHCOUNT = 1000; +const HWM = 50; -var Readable = require('stream').Readable; -var r = new Readable({ +const Readable = require('stream').Readable; +const r = new Readable({ highWaterMark: HWM }); -var rs = r._readableState; +const rs = r._readableState; r._read = push; r.on('readable', function() { console.error('>> readable'); + let ret; do { console.error(' > read(%d)', READSIZE); - var ret = r.read(READSIZE); + ret = r.read(READSIZE); console.error(' < %j (%d remain)', ret && ret.length, rs.length); } while (ret && ret.length === READSIZE); @@ -36,7 +37,7 @@ r.on('end', common.mustCall(function() { assert.strictEqual(pushes, PUSHCOUNT + 1); })); -var pushes = 0; +let pushes = 0; function push() { if (pushes > PUSHCOUNT) return; diff --git a/test/parallel/test-stream2-objects.js b/test/parallel/test-stream2-objects.js index b18be26dc530fb..6c00f1b8691364 100644 --- a/test/parallel/test-stream2-objects.js +++ b/test/parallel/test-stream2-objects.js @@ -1,12 +1,12 @@ 'use strict'; require('../common'); -var Readable = require('_stream_readable'); -var Writable = require('_stream_writable'); -var assert = require('assert'); +const Readable = require('_stream_readable'); +const Writable = require('_stream_writable'); +const assert = require('assert'); // tiny node-tap lookalike. -var tests = []; -var count = 0; +const tests = []; +let count = 0; function test(name, fn) { count++; @@ -14,12 +14,12 @@ function test(name, fn) { } function run() { - var next = tests.shift(); + const next = tests.shift(); if (!next) return console.error('ok'); - var name = next[0]; - var fn = next[1]; + const name = next[0]; + const fn = next[1]; console.log('# %s', name); fn({ same: assert.deepStrictEqual, @@ -39,8 +39,8 @@ process.on('exit', function() { process.nextTick(run); function toArray(callback) { - var stream = new Writable({ objectMode: true }); - var list = []; + const stream = new Writable({ objectMode: true }); + const list = []; stream.write = function(chunk) { list.push(chunk); }; @@ -53,7 +53,7 @@ function toArray(callback) { } function fromArray(list) { - var r = new Readable({ objectMode: true }); + const r = new Readable({ objectMode: true }); r._read = noop; list.forEach(function(chunk) { r.push(chunk); @@ -66,11 +66,11 @@ function fromArray(list) { function noop() {} test('can read objects from stream', function(t) { - var r = fromArray([{ one: '1'}, { two: '2' }]); + const r = fromArray([{ one: '1'}, { two: '2' }]); - var v1 = r.read(); - var v2 = r.read(); - var v3 = r.read(); + const v1 = r.read(); + const v2 = r.read(); + const v3 = r.read(); assert.deepStrictEqual(v1, { one: '1' }); assert.deepStrictEqual(v2, { two: '2' }); @@ -80,7 +80,7 @@ test('can read objects from stream', function(t) { }); test('can pipe objects into stream', function(t) { - var r = fromArray([{ one: '1'}, { two: '2' }]); + const r = fromArray([{ one: '1'}, { two: '2' }]); r.pipe(toArray(function(list) { assert.deepStrictEqual(list, [ @@ -93,9 +93,9 @@ test('can pipe objects into stream', function(t) { }); test('read(n) is ignored', function(t) { - var r = fromArray([{ one: '1'}, { two: '2' }]); + const r = fromArray([{ one: '1'}, { two: '2' }]); - var value = r.read(2); + const value = r.read(2); assert.deepStrictEqual(value, { one: '1' }); @@ -103,10 +103,10 @@ test('read(n) is ignored', function(t) { }); test('can read objects from _read (sync)', function(t) { - var r = new Readable({ objectMode: true }); - var list = [{ one: '1'}, { two: '2' }]; + const r = new Readable({ objectMode: true }); + const list = [{ one: '1'}, { two: '2' }]; r._read = function(n) { - var item = list.shift(); + const item = list.shift(); r.push(item || null); }; @@ -121,10 +121,10 @@ test('can read objects from _read (sync)', function(t) { }); test('can read objects from _read (async)', function(t) { - var r = new Readable({ objectMode: true }); - var list = [{ one: '1'}, { two: '2' }]; + const r = new Readable({ objectMode: true }); + const list = [{ one: '1'}, { two: '2' }]; r._read = function(n) { - var item = list.shift(); + const item = list.shift(); process.nextTick(function() { r.push(item || null); }); @@ -141,11 +141,11 @@ test('can read objects from _read (async)', function(t) { }); test('can read strings as objects', function(t) { - var r = new Readable({ + const r = new Readable({ objectMode: true }); r._read = noop; - var list = ['one', 'two', 'three']; + const list = ['one', 'two', 'three']; list.forEach(function(str) { r.push(str); }); @@ -159,7 +159,7 @@ test('can read strings as objects', function(t) { }); test('read(0) for object streams', function(t) { - var r = new Readable({ + const r = new Readable({ objectMode: true }); r._read = noop; @@ -175,7 +175,7 @@ test('read(0) for object streams', function(t) { }); test('falsey values', function(t) { - var r = new Readable({ + const r = new Readable({ objectMode: true }); r._read = noop; @@ -193,12 +193,12 @@ test('falsey values', function(t) { }); test('high watermark _read', function(t) { - var r = new Readable({ + const r = new Readable({ highWaterMark: 6, objectMode: true }); - var calls = 0; - var list = ['1', '2', '3', '4', '5', '6', '7', '8']; + let calls = 0; + const list = ['1', '2', '3', '4', '5', '6', '7', '8']; r._read = function(n) { calls++; @@ -208,15 +208,15 @@ test('high watermark _read', function(t) { r.push(c); }); - var v = r.read(); + const v = r.read(); assert.strictEqual(calls, 0); assert.strictEqual(v, '1'); - var v2 = r.read(); + const v2 = r.read(); assert.strictEqual(v2, '2'); - var v3 = r.read(); + const v3 = r.read(); assert.strictEqual(v3, '3'); assert.strictEqual(calls, 1); @@ -225,13 +225,13 @@ test('high watermark _read', function(t) { }); test('high watermark push', function(t) { - var r = new Readable({ + const r = new Readable({ highWaterMark: 6, objectMode: true }); r._read = function(n) {}; - for (var i = 0; i < 6; i++) { - var bool = r.push(i); + for (let i = 0; i < 6; i++) { + const bool = r.push(i); assert.strictEqual(bool, i !== 5); } @@ -239,7 +239,7 @@ test('high watermark push', function(t) { }); test('can write objects to stream', function(t) { - var w = new Writable({ objectMode: true }); + const w = new Writable({ objectMode: true }); w._write = function(chunk, encoding, cb) { assert.deepStrictEqual(chunk, { foo: 'bar' }); @@ -255,8 +255,8 @@ test('can write objects to stream', function(t) { }); test('can write multiple objects to stream', function(t) { - var w = new Writable({ objectMode: true }); - var list = []; + const w = new Writable({ objectMode: true }); + const list = []; w._write = function(chunk, encoding, cb) { list.push(chunk); @@ -278,10 +278,10 @@ test('can write multiple objects to stream', function(t) { }); test('can write strings as objects', function(t) { - var w = new Writable({ + const w = new Writable({ objectMode: true }); - var list = []; + const list = []; w._write = function(chunk, encoding, cb) { list.push(chunk); @@ -303,10 +303,10 @@ test('can write strings as objects', function(t) { }); test('buffers finish until cb is called', function(t) { - var w = new Writable({ + const w = new Writable({ objectMode: true }); - var called = false; + let called = false; w._write = function(chunk, encoding, cb) { assert.strictEqual(chunk, 'foo'); diff --git a/test/parallel/test-stream2-pipe-error-handling.js b/test/parallel/test-stream2-pipe-error-handling.js index bdf7a4a9a33a77..cdd1b1a364e183 100644 --- a/test/parallel/test-stream2-pipe-error-handling.js +++ b/test/parallel/test-stream2-pipe-error-handling.js @@ -1,7 +1,7 @@ 'use strict'; require('../common'); -var assert = require('assert'); -var stream = require('stream'); +const assert = require('assert'); +const stream = require('stream'); { let count = 1000; diff --git a/test/parallel/test-stream2-pipe-error-once-listener.js b/test/parallel/test-stream2-pipe-error-once-listener.js index c9cfd1d1c80c19..908ac1bdb8e4ab 100644 --- a/test/parallel/test-stream2-pipe-error-once-listener.js +++ b/test/parallel/test-stream2-pipe-error-once-listener.js @@ -1,11 +1,11 @@ 'use strict'; require('../common'); -var util = require('util'); -var stream = require('stream'); +const util = require('util'); +const stream = require('stream'); -var Read = function() { +const Read = function() { stream.Readable.call(this); }; util.inherits(Read, stream.Readable); @@ -16,7 +16,7 @@ Read.prototype._read = function(size) { }; -var Write = function() { +const Write = function() { stream.Writable.call(this); }; util.inherits(Write, stream.Writable); @@ -26,8 +26,8 @@ Write.prototype._write = function(buffer, encoding, cb) { this.emit('alldone'); }; -var read = new Read(); -var write = new Write(); +const read = new Read(); +const write = new Write(); write.once('error', function(err) {}); write.once('alldone', function(err) { diff --git a/test/parallel/test-stream2-push.js b/test/parallel/test-stream2-push.js index 445a186715b659..80315f2fb3f0cb 100644 --- a/test/parallel/test-stream2-push.js +++ b/test/parallel/test-stream2-push.js @@ -1,11 +1,11 @@ 'use strict'; require('../common'); -var stream = require('stream'); -var Readable = stream.Readable; -var Writable = stream.Writable; -var assert = require('assert'); +let stream = require('stream'); +const Readable = stream.Readable; +const Writable = stream.Writable; +const assert = require('assert'); -var EE = require('events').EventEmitter; +const EE = require('events').EventEmitter; // a mock thing a bit like the net.Socket/tcp_wrap.handle interaction @@ -15,20 +15,20 @@ stream = new Readable({ encoding: 'utf8' }); -var source = new EE(); +const source = new EE(); stream._read = function() { console.error('stream._read'); readStart(); }; -var ended = false; +let ended = false; stream.on('end', function() { ended = true; }); source.on('data', function(chunk) { - var ret = stream.push(chunk); + const ret = stream.push(chunk); console.error('data', stream._readableState.length); if (!ret) readStop(); @@ -38,7 +38,7 @@ source.on('end', function() { stream.push(null); }); -var reading = false; +let reading = false; function readStart() { console.error('readStart'); @@ -49,19 +49,19 @@ function readStop() { console.error('readStop'); reading = false; process.nextTick(function() { - var r = stream.read(); + const r = stream.read(); if (r !== null) writer.write(r); }); } -var writer = new Writable({ +let writer = new Writable({ decodeStrings: false }); -var written = []; +const written = []; -var expectWritten = +const expectWritten = [ 'asdfgasdfgasdfgasdfg', 'asdfgasdfgasdfgasdfg', 'asdfgasdfgasdfgasdfg', @@ -80,9 +80,9 @@ writer.on('finish', finish); // now emit some chunks. -var chunk = 'asdfg'; +const chunk = 'asdfg'; -var set = 0; +let set = 0; readStart(); data(); function data() { diff --git a/test/parallel/test-stream2-read-sync-stack.js b/test/parallel/test-stream2-read-sync-stack.js index b2cfd05f872e30..d4e11af3b8f7c1 100644 --- a/test/parallel/test-stream2-read-sync-stack.js +++ b/test/parallel/test-stream2-read-sync-stack.js @@ -1,16 +1,16 @@ 'use strict'; const common = require('../common'); -var Readable = require('stream').Readable; -var r = new Readable(); -var N = 256 * 1024; +const Readable = require('stream').Readable; +const r = new Readable(); +const N = 256 * 1024; // Go ahead and allow the pathological case for this test. // Yes, it's an infinite loop, that's the point. process.maxTickDepth = N + 2; -var reads = 0; +let reads = 0; r._read = function(n) { - var chunk = reads++ === N ? null : Buffer.allocUnsafe(1); + const chunk = reads++ === N ? null : Buffer.allocUnsafe(1); r.push(chunk); }; diff --git a/test/parallel/test-stream2-readable-empty-buffer-no-eof.js b/test/parallel/test-stream2-readable-empty-buffer-no-eof.js index ccbf087df00bf5..71d6f1e7236db2 100644 --- a/test/parallel/test-stream2-readable-empty-buffer-no-eof.js +++ b/test/parallel/test-stream2-readable-empty-buffer-no-eof.js @@ -69,8 +69,8 @@ function test1() { } function test2() { - var r = new Readable({ encoding: 'base64' }); - var reads = 5; + const r = new Readable({ encoding: 'base64' }); + let reads = 5; r._read = function(n) { if (!reads--) return r.push(null); // EOF @@ -78,9 +78,9 @@ function test2() { return r.push(Buffer.from('x')); }; - var results = []; + const results = []; function flow() { - var chunk; + let chunk; while (null !== (chunk = r.read())) results.push(chunk + ''); } diff --git a/test/parallel/test-stream2-readable-from-list.js b/test/parallel/test-stream2-readable-from-list.js index 2aa0725f734117..f3f39507e89dab 100644 --- a/test/parallel/test-stream2-readable-from-list.js +++ b/test/parallel/test-stream2-readable-from-list.js @@ -1,13 +1,13 @@ // Flags: --expose_internals 'use strict'; require('../common'); -var assert = require('assert'); -var fromList = require('_stream_readable')._fromList; -var BufferList = require('internal/streams/BufferList'); +const assert = require('assert'); +const fromList = require('_stream_readable')._fromList; +const BufferList = require('internal/streams/BufferList'); // tiny node-tap lookalike. -var tests = []; -var count = 0; +const tests = []; +let count = 0; function test(name, fn) { count++; @@ -15,12 +15,12 @@ function test(name, fn) { } function run() { - var next = tests.shift(); + const next = tests.shift(); if (!next) return console.error('ok'); - var name = next[0]; - var fn = next[1]; + const name = next[0]; + const fn = next[1]; console.log('# %s', name); fn({ same: assert.deepStrictEqual, @@ -34,7 +34,7 @@ function run() { function bufferListFromArray(arr) { const bl = new BufferList(); - for (var i = 0; i < arr.length; ++i) + for (let i = 0; i < arr.length; ++i) bl.push(arr[i]); return bl; } @@ -48,14 +48,14 @@ process.nextTick(run); test('buffers', function(t) { - var list = [ Buffer.from('foog'), + let list = [ Buffer.from('foog'), Buffer.from('bark'), Buffer.from('bazy'), Buffer.from('kuel') ]; list = bufferListFromArray(list); // read more than the first element. - var ret = fromList(6, { buffer: list, length: 16 }); + let ret = fromList(6, { buffer: list, length: 16 }); t.equal(ret.toString(), 'foogba'); // read exactly the first element. @@ -77,14 +77,14 @@ test('buffers', function(t) { }); test('strings', function(t) { - var list = [ 'foog', + let list = [ 'foog', 'bark', 'bazy', 'kuel' ]; list = bufferListFromArray(list); // read more than the first element. - var ret = fromList(6, { buffer: list, length: 16, decoder: true }); + let ret = fromList(6, { buffer: list, length: 16, decoder: true }); t.equal(ret, 'foogba'); // read exactly the first element. diff --git a/test/parallel/test-stream2-readable-legacy-drain.js b/test/parallel/test-stream2-readable-legacy-drain.js index 8a0687a6ebd90c..d6db6ba232c693 100644 --- a/test/parallel/test-stream2-readable-legacy-drain.js +++ b/test/parallel/test-stream2-readable-legacy-drain.js @@ -1,22 +1,22 @@ 'use strict'; const common = require('../common'); -var assert = require('assert'); +const assert = require('assert'); -var Stream = require('stream'); -var Readable = Stream.Readable; +const Stream = require('stream'); +const Readable = Stream.Readable; -var r = new Readable(); -var N = 256; -var reads = 0; +const r = new Readable(); +const N = 256; +let reads = 0; r._read = function(n) { return r.push(++reads === N ? null : Buffer.allocUnsafe(1)); }; r.on('end', common.mustCall(function() {})); -var w = new Stream(); +const w = new Stream(); w.writable = true; -var buffered = 0; +let buffered = 0; w.write = function(c) { buffered += c.length; process.nextTick(drain); diff --git a/test/parallel/test-stream2-readable-non-empty-end.js b/test/parallel/test-stream2-readable-non-empty-end.js index dd2cb8d51055c7..66fae8274ecf3c 100644 --- a/test/parallel/test-stream2-readable-non-empty-end.js +++ b/test/parallel/test-stream2-readable-non-empty-end.js @@ -1,19 +1,19 @@ 'use strict'; const common = require('../common'); -var assert = require('assert'); -var Readable = require('_stream_readable'); +const assert = require('assert'); +const Readable = require('_stream_readable'); -var len = 0; -var chunks = new Array(10); -for (var i = 1; i <= 10; i++) { +let len = 0; +const chunks = new Array(10); +for (let i = 1; i <= 10; i++) { chunks[i - 1] = Buffer.allocUnsafe(i); len += i; } -var test = new Readable(); -var n = 0; +const test = new Readable(); +let n = 0; test._read = function(size) { - var chunk = chunks[n++]; + const chunk = chunks[n++]; setTimeout(function() { test.push(chunk === undefined ? null : chunk); }, 1); @@ -24,10 +24,10 @@ function thrower() { throw new Error('this should not happen!'); } -var bytesread = 0; +let bytesread = 0; test.on('readable', function() { - var b = len - bytesread - 1; - var res = test.read(b); + const b = len - bytesread - 1; + const res = test.read(b); if (res) { bytesread += res.length; console.error('br=%d len=%d', bytesread, len); @@ -43,7 +43,7 @@ function next() { test.on('end', common.mustCall(function() {})); // one to get the last byte - var r = test.read(); + let r = test.read(); assert(r); assert.equal(r.length, 1); r = test.read(); diff --git a/test/parallel/test-stream2-readable-wrap-empty.js b/test/parallel/test-stream2-readable-wrap-empty.js index 02de3cf5b4cb23..5b2dae3c5327fa 100644 --- a/test/parallel/test-stream2-readable-wrap-empty.js +++ b/test/parallel/test-stream2-readable-wrap-empty.js @@ -1,14 +1,14 @@ 'use strict'; const common = require('../common'); -var Readable = require('_stream_readable'); -var EE = require('events').EventEmitter; +const Readable = require('_stream_readable'); +const EE = require('events').EventEmitter; -var oldStream = new EE(); +const oldStream = new EE(); oldStream.pause = function() {}; oldStream.resume = function() {}; -var newStream = new Readable().wrap(oldStream); +const newStream = new Readable().wrap(oldStream); newStream .on('readable', function() {}) diff --git a/test/parallel/test-stream2-readable-wrap.js b/test/parallel/test-stream2-readable-wrap.js index 3bbd5ef0809dcd..4c736c6f369514 100644 --- a/test/parallel/test-stream2-readable-wrap.js +++ b/test/parallel/test-stream2-readable-wrap.js @@ -1,21 +1,21 @@ 'use strict'; require('../common'); -var assert = require('assert'); +const assert = require('assert'); -var Readable = require('_stream_readable'); -var Writable = require('_stream_writable'); -var EE = require('events').EventEmitter; +const Readable = require('_stream_readable'); +const Writable = require('_stream_writable'); +const EE = require('events').EventEmitter; -var testRuns = 0, completedRuns = 0; +let testRuns = 0, completedRuns = 0; function runTest(highWaterMark, objectMode, produce) { testRuns++; - var old = new EE(); - var r = new Readable({ highWaterMark: highWaterMark, - objectMode: objectMode }); + const old = new EE(); + const r = new Readable({ highWaterMark: highWaterMark, + objectMode: objectMode }); assert.equal(r, r.wrap(old)); - var ended = false; + let ended = false; r.on('end', function() { ended = true; }); @@ -32,14 +32,14 @@ function runTest(highWaterMark, objectMode, produce) { flow(); }; - var flowing; - var chunks = 10; - var oldEnded = false; - var expected = []; + let flowing; + let chunks = 10; + let oldEnded = false; + const expected = []; function flow() { flowing = true; while (flowing && chunks-- > 0) { - var item = produce(); + const item = produce(); expected.push(item); console.log('old.emit', chunks, flowing); old.emit('data', item); @@ -52,9 +52,9 @@ function runTest(highWaterMark, objectMode, produce) { } } - var w = new Writable({ highWaterMark: highWaterMark * 2, - objectMode: objectMode }); - var written = []; + const w = new Writable({ highWaterMark: highWaterMark * 2, + objectMode: objectMode }); + const written = []; w._write = function(chunk, encoding, cb) { console.log('_write', chunk); written.push(chunk); @@ -81,7 +81,7 @@ runTest(100, false, function() { return Buffer.allocUnsafe(100); }); runTest(10, false, function() { return Buffer.from('xxxxxxxxxx'); }); runTest(1, true, function() { return { foo: 'bar' }; }); -var objectChunks = [ 5, 'a', false, 0, '', 'xyz', { x: 4 }, 7, [], 555 ]; +const objectChunks = [ 5, 'a', false, 0, '', 'xyz', { x: 4 }, 7, [], 555 ]; runTest(1, true, function() { return objectChunks.shift(); }); process.on('exit', function() { diff --git a/test/parallel/test-stream2-set-encoding.js b/test/parallel/test-stream2-set-encoding.js index 3deb67d48e7156..fdbd81e61332b1 100644 --- a/test/parallel/test-stream2-set-encoding.js +++ b/test/parallel/test-stream2-set-encoding.js @@ -1,12 +1,12 @@ 'use strict'; require('../common'); -var assert = require('assert'); -var R = require('_stream_readable'); -var util = require('util'); +const assert = require('assert'); +const R = require('_stream_readable'); +const util = require('util'); // tiny node-tap lookalike. -var tests = []; -var count = 0; +const tests = []; +let count = 0; function test(name, fn) { count++; @@ -14,12 +14,12 @@ function test(name, fn) { } function run() { - var next = tests.shift(); + const next = tests.shift(); if (!next) return console.error('ok'); - var name = next[0]; - var fn = next[1]; + const name = next[0]; + const fn = next[1]; console.log('# %s', name); fn({ same: assert.deepStrictEqual, @@ -66,7 +66,7 @@ TestReader.prototype._read = function(n) { } this.pos += n; - var ret = Buffer.alloc(n, 'a'); + const ret = Buffer.alloc(n, 'a'); console.log('this.push(ret)', ret); @@ -75,10 +75,10 @@ TestReader.prototype._read = function(n) { }; test('setEncoding utf8', function(t) { - var tr = new TestReader(100); + const tr = new TestReader(100); tr.setEncoding('utf8'); - var out = []; - var expect = + const out = []; + const expect = [ 'aaaaaaaaaa', 'aaaaaaaaaa', 'aaaaaaaaaa', @@ -91,7 +91,7 @@ test('setEncoding utf8', function(t) { 'aaaaaaaaaa' ]; tr.on('readable', function flow() { - var chunk; + let chunk; while (null !== (chunk = tr.read(10))) out.push(chunk); }); @@ -104,10 +104,10 @@ test('setEncoding utf8', function(t) { test('setEncoding hex', function(t) { - var tr = new TestReader(100); + const tr = new TestReader(100); tr.setEncoding('hex'); - var out = []; - var expect = + const out = []; + const expect = [ '6161616161', '6161616161', '6161616161', @@ -130,7 +130,7 @@ test('setEncoding hex', function(t) { '6161616161' ]; tr.on('readable', function flow() { - var chunk; + let chunk; while (null !== (chunk = tr.read(10))) out.push(chunk); }); @@ -142,10 +142,10 @@ test('setEncoding hex', function(t) { }); test('setEncoding hex with read(13)', function(t) { - var tr = new TestReader(100); + const tr = new TestReader(100); tr.setEncoding('hex'); - var out = []; - var expect = + const out = []; + const expect = [ '6161616161616', '1616161616161', '6161616161616', @@ -165,7 +165,7 @@ test('setEncoding hex with read(13)', function(t) { tr.on('readable', function flow() { console.log('readable once'); - var chunk; + let chunk; while (null !== (chunk = tr.read(13))) out.push(chunk); }); @@ -178,10 +178,10 @@ test('setEncoding hex with read(13)', function(t) { }); test('setEncoding base64', function(t) { - var tr = new TestReader(100); + const tr = new TestReader(100); tr.setEncoding('base64'); - var out = []; - var expect = + const out = []; + const expect = [ 'YWFhYWFhYW', 'FhYWFhYWFh', 'YWFhYWFhYW', @@ -198,7 +198,7 @@ test('setEncoding base64', function(t) { 'FhYQ==' ]; tr.on('readable', function flow() { - var chunk; + let chunk; while (null !== (chunk = tr.read(10))) out.push(chunk); }); @@ -210,9 +210,9 @@ test('setEncoding base64', function(t) { }); test('encoding: utf8', function(t) { - var tr = new TestReader(100, { encoding: 'utf8' }); - var out = []; - var expect = + const tr = new TestReader(100, { encoding: 'utf8' }); + const out = []; + const expect = [ 'aaaaaaaaaa', 'aaaaaaaaaa', 'aaaaaaaaaa', @@ -225,7 +225,7 @@ test('encoding: utf8', function(t) { 'aaaaaaaaaa' ]; tr.on('readable', function flow() { - var chunk; + let chunk; while (null !== (chunk = tr.read(10))) out.push(chunk); }); @@ -238,9 +238,9 @@ test('encoding: utf8', function(t) { test('encoding: hex', function(t) { - var tr = new TestReader(100, { encoding: 'hex' }); - var out = []; - var expect = + const tr = new TestReader(100, { encoding: 'hex' }); + const out = []; + const expect = [ '6161616161', '6161616161', '6161616161', @@ -263,7 +263,7 @@ test('encoding: hex', function(t) { '6161616161' ]; tr.on('readable', function flow() { - var chunk; + let chunk; while (null !== (chunk = tr.read(10))) out.push(chunk); }); @@ -275,9 +275,9 @@ test('encoding: hex', function(t) { }); test('encoding: hex with read(13)', function(t) { - var tr = new TestReader(100, { encoding: 'hex' }); - var out = []; - var expect = + const tr = new TestReader(100, { encoding: 'hex' }); + const out = []; + const expect = [ '6161616161616', '1616161616161', '6161616161616', @@ -296,7 +296,7 @@ test('encoding: hex with read(13)', function(t) { '16161' ]; tr.on('readable', function flow() { - var chunk; + let chunk; while (null !== (chunk = tr.read(13))) out.push(chunk); }); @@ -308,9 +308,9 @@ test('encoding: hex with read(13)', function(t) { }); test('encoding: base64', function(t) { - var tr = new TestReader(100, { encoding: 'base64' }); - var out = []; - var expect = + const tr = new TestReader(100, { encoding: 'base64' }); + const out = []; + const expect = [ 'YWFhYWFhYW', 'FhYWFhYWFh', 'YWFhYWFhYW', @@ -327,7 +327,7 @@ test('encoding: base64', function(t) { 'FhYQ==' ]; tr.on('readable', function flow() { - var chunk; + let chunk; while (null !== (chunk = tr.read(10))) out.push(chunk); }); @@ -339,7 +339,7 @@ test('encoding: base64', function(t) { }); test('chainable', function(t) { - var tr = new TestReader(100); + const tr = new TestReader(100); t.equal(tr.setEncoding('utf8'), tr); t.end(); }); diff --git a/test/parallel/test-stream2-transform.js b/test/parallel/test-stream2-transform.js index 6a4036681f90b7..d66f1f064375e4 100644 --- a/test/parallel/test-stream2-transform.js +++ b/test/parallel/test-stream2-transform.js @@ -1,12 +1,12 @@ 'use strict'; require('../common'); -var assert = require('assert'); -var PassThrough = require('_stream_passthrough'); -var Transform = require('_stream_transform'); +const assert = require('assert'); +const PassThrough = require('_stream_passthrough'); +const Transform = require('_stream_transform'); // tiny node-tap lookalike. -var tests = []; -var count = 0; +const tests = []; +let count = 0; function test(name, fn) { count++; @@ -14,12 +14,12 @@ function test(name, fn) { } function run() { - var next = tests.shift(); + const next = tests.shift(); if (!next) return console.error('ok'); - var name = next[0]; - var fn = next[1]; + const name = next[0]; + const fn = next[1]; console.log('# %s', name); fn({ same: assert.deepStrictEqual, @@ -42,18 +42,18 @@ process.nextTick(run); ///// test('writable side consumption', function(t) { - var tx = new Transform({ + const tx = new Transform({ highWaterMark: 10 }); - var transformed = 0; + let transformed = 0; tx._transform = function(chunk, encoding, cb) { transformed += chunk.length; tx.push(chunk); cb(); }; - for (var i = 1; i <= 10; i++) { + for (let i = 1; i <= 10; i++) { tx.write(Buffer.allocUnsafe(i)); } tx.end(); @@ -69,7 +69,7 @@ test('writable side consumption', function(t) { }); test('passthrough', function(t) { - var pt = new PassThrough(); + const pt = new PassThrough(); pt.write(Buffer.from('foog')); pt.write(Buffer.from('bark')); @@ -85,7 +85,7 @@ test('passthrough', function(t) { }); test('object passthrough', function(t) { - var pt = new PassThrough({ objectMode: true }); + const pt = new PassThrough({ objectMode: true }); pt.write(1); pt.write(true); @@ -115,9 +115,9 @@ test('passthrough constructor', function(t) { }); test('simple transform', function(t) { - var pt = new Transform(); + const pt = new Transform(); pt._transform = function(c, e, cb) { - var ret = Buffer.alloc(c.length, 'x'); + const ret = Buffer.alloc(c.length, 'x'); pt.push(ret); cb(); }; @@ -136,7 +136,7 @@ test('simple transform', function(t) { }); test('simple object transform', function(t) { - var pt = new Transform({ objectMode: true }); + const pt = new Transform({ objectMode: true }); pt._transform = function(c, e, cb) { pt.push(JSON.stringify(c)); cb(); @@ -162,7 +162,7 @@ test('simple object transform', function(t) { }); test('async passthrough', function(t) { - var pt = new Transform(); + const pt = new Transform(); pt._transform = function(chunk, encoding, cb) { setTimeout(function() { pt.push(chunk); @@ -186,7 +186,7 @@ test('async passthrough', function(t) { }); test('assymetric transform (expand)', function(t) { - var pt = new Transform(); + const pt = new Transform(); // emit each chunk 2 times. pt._transform = function(chunk, encoding, cb) { @@ -218,7 +218,7 @@ test('assymetric transform (expand)', function(t) { }); test('assymetric transform (compress)', function(t) { - var pt = new Transform(); + const pt = new Transform(); // each output is the first char of 3 consecutive chunks, // or whatever's left. @@ -227,7 +227,7 @@ test('assymetric transform (compress)', function(t) { pt._transform = function(chunk, encoding, cb) { if (!chunk) chunk = ''; - var s = chunk.toString(); + const s = chunk.toString(); setTimeout(function() { this.state += s.charAt(0); if (this.state.length === 3) { @@ -273,9 +273,9 @@ test('assymetric transform (compress)', function(t) { // this tests for a stall when data is written to a full stream // that has empty transforms. test('complex transform', function(t) { - var count = 0; - var saved = null; - var pt = new Transform({highWaterMark: 3}); + let count = 0; + let saved = null; + const pt = new Transform({highWaterMark: 3}); pt._transform = function(c, e, cb) { if (count++ === 1) saved = c; @@ -307,8 +307,8 @@ test('complex transform', function(t) { test('passthrough event emission', function(t) { - var pt = new PassThrough(); - var emits = 0; + const pt = new PassThrough(); + let emits = 0; pt.on('readable', function() { console.error('>>> emit readable %d', emits); emits++; @@ -353,8 +353,8 @@ test('passthrough event emission', function(t) { }); test('passthrough event emission reordered', function(t) { - var pt = new PassThrough(); - var emits = 0; + const pt = new PassThrough(); + let emits = 0; pt.on('readable', function() { console.error('emit readable', emits); emits++; @@ -395,8 +395,8 @@ test('passthrough event emission reordered', function(t) { test('passthrough facaded', function(t) { console.error('passthrough facaded'); - var pt = new PassThrough(); - var datas = []; + const pt = new PassThrough(); + const datas = []; pt.on('data', function(chunk) { datas.push(chunk.toString()); }); @@ -423,7 +423,7 @@ test('passthrough facaded', function(t) { test('object transform (json parse)', function(t) { console.error('json parse stream'); - var jp = new Transform({ objectMode: true }); + const jp = new Transform({ objectMode: true }); jp._transform = function(data, encoding, cb) { try { jp.push(JSON.parse(data)); @@ -435,21 +435,21 @@ test('object transform (json parse)', function(t) { // anything except null/undefined is fine. // those are "magic" in the stream API, because they signal EOF. - var objects = [ + const objects = [ { foo: 'bar' }, 100, 'string', { nested: { things: [ { foo: 'bar' }, 100, 'string' ] } } ]; - var ended = false; + let ended = false; jp.on('end', function() { ended = true; }); objects.forEach(function(obj) { jp.write(JSON.stringify(obj)); - var res = jp.read(); + const res = jp.read(); t.same(res, obj); }); @@ -465,7 +465,7 @@ test('object transform (json parse)', function(t) { test('object transform (json stringify)', function(t) { console.error('json parse stream'); - var js = new Transform({ objectMode: true }); + const js = new Transform({ objectMode: true }); js._transform = function(data, encoding, cb) { try { js.push(JSON.stringify(data)); @@ -477,21 +477,21 @@ test('object transform (json stringify)', function(t) { // anything except null/undefined is fine. // those are "magic" in the stream API, because they signal EOF. - var objects = [ + const objects = [ { foo: 'bar' }, 100, 'string', { nested: { things: [ { foo: 'bar' }, 100, 'string' ] } } ]; - var ended = false; + let ended = false; js.on('end', function() { ended = true; }); objects.forEach(function(obj) { js.write(obj); - var res = js.read(); + const res = js.read(); t.equal(res, JSON.stringify(obj)); }); diff --git a/test/parallel/test-stream2-unpipe-leak.js b/test/parallel/test-stream2-unpipe-leak.js index d94e39f7667df4..1a1599ca32b4c7 100644 --- a/test/parallel/test-stream2-unpipe-leak.js +++ b/test/parallel/test-stream2-unpipe-leak.js @@ -1,11 +1,11 @@ 'use strict'; require('../common'); -var assert = require('assert'); -var stream = require('stream'); +const assert = require('assert'); +const stream = require('stream'); -var chunk = Buffer.from('hallo'); +const chunk = Buffer.from('hallo'); -var util = require('util'); +const util = require('util'); function TestWriter() { stream.Writable.call(this); @@ -16,7 +16,7 @@ TestWriter.prototype._write = function(buffer, encoding, callback) { callback(null); }; -var dest = new TestWriter(); +const dest = new TestWriter(); // Set this high so that we'd trigger a nextTick warning // and/or RangeError if we do maybeReadMore wrong. @@ -29,9 +29,9 @@ TestReader.prototype._read = function(size) { this.push(chunk); }; -var src = new TestReader(); +const src = new TestReader(); -for (var i = 0; i < 10; i++) { +for (let i = 0; i < 10; i++) { src.pipe(dest); src.unpipe(dest); } diff --git a/test/parallel/test-stream2-writable.js b/test/parallel/test-stream2-writable.js index 5ecdd0f76ecb5a..c377ce9a510caa 100644 --- a/test/parallel/test-stream2-writable.js +++ b/test/parallel/test-stream2-writable.js @@ -1,10 +1,10 @@ 'use strict'; require('../common'); -var W = require('_stream_writable'); -var D = require('_stream_duplex'); -var assert = require('assert'); +const W = require('_stream_writable'); +const D = require('_stream_duplex'); +const assert = require('assert'); -var util = require('util'); +const util = require('util'); util.inherits(TestWriter, W); function TestWriter() { @@ -22,14 +22,14 @@ TestWriter.prototype._write = function(chunk, encoding, cb) { }.bind(this), Math.floor(Math.random() * 10)); }; -var chunks = new Array(50); -for (var i = 0; i < chunks.length; i++) { +const chunks = new Array(50); +for (let i = 0; i < chunks.length; i++) { chunks[i] = new Array(i + 1).join('x'); } // tiny node-tap lookalike. -var tests = []; -var count = 0; +const tests = []; +let count = 0; function test(name, fn) { count++; @@ -37,12 +37,12 @@ function test(name, fn) { } function run() { - var next = tests.shift(); + const next = tests.shift(); if (!next) return console.error('ok'); - var name = next[0]; - var fn = next[1]; + const name = next[0]; + const fn = next[1]; console.log('# %s', name); fn({ same: assert.deepStrictEqual, @@ -62,7 +62,7 @@ process.on('exit', function() { process.nextTick(run); test('write fast', function(t) { - var tw = new TestWriter({ + const tw = new TestWriter({ highWaterMark: 100 }); @@ -79,7 +79,7 @@ test('write fast', function(t) { }); test('write slow', function(t) { - var tw = new TestWriter({ + const tw = new TestWriter({ highWaterMark: 100 }); @@ -88,7 +88,7 @@ test('write slow', function(t) { t.end(); }); - var i = 0; + let i = 0; (function W() { tw.write(chunks[i++]); if (i < chunks.length) @@ -99,11 +99,11 @@ test('write slow', function(t) { }); test('write backpressure', function(t) { - var tw = new TestWriter({ + const tw = new TestWriter({ highWaterMark: 50 }); - var drains = 0; + let drains = 0; tw.on('finish', function() { t.same(tw.buffer, chunks, 'got chunks in the right order'); @@ -115,10 +115,11 @@ test('write backpressure', function(t) { drains++; }); - var i = 0; + let i = 0; (function W() { + let ret; do { - var ret = tw.write(chunks[i++]); + ret = tw.write(chunks[i++]); } while (ret !== false && i < chunks.length); if (i < chunks.length) { @@ -131,11 +132,11 @@ test('write backpressure', function(t) { }); test('write bufferize', function(t) { - var tw = new TestWriter({ + const tw = new TestWriter({ highWaterMark: 100 }); - var encodings = + const encodings = [ 'hex', 'utf8', 'utf-8', @@ -154,7 +155,7 @@ test('write bufferize', function(t) { }); chunks.forEach(function(chunk, i) { - var enc = encodings[i % encodings.length]; + const enc = encodings[i % encodings.length]; chunk = Buffer.from(chunk); tw.write(chunk.toString(enc), enc); }); @@ -162,7 +163,7 @@ test('write bufferize', function(t) { }); test('write no bufferize', function(t) { - var tw = new TestWriter({ + const tw = new TestWriter({ highWaterMark: 100, decodeStrings: false }); @@ -173,7 +174,7 @@ test('write no bufferize', function(t) { return TestWriter.prototype._write.call(this, chunk, encoding, cb); }; - var encodings = + const encodings = [ 'hex', 'utf8', 'utf-8', @@ -192,7 +193,7 @@ test('write no bufferize', function(t) { }); chunks.forEach(function(chunk, i) { - var enc = encodings[i % encodings.length]; + const enc = encodings[i % encodings.length]; chunk = Buffer.from(chunk); tw.write(chunk.toString(enc), enc); }); @@ -200,7 +201,7 @@ test('write no bufferize', function(t) { }); test('write callbacks', function(t) { - var callbacks = chunks.map(function(chunk, i) { + const callbacks = chunks.map(function(chunk, i) { return [i, function() { callbacks._called[i] = chunk; }]; @@ -210,7 +211,7 @@ test('write callbacks', function(t) { }, {}); callbacks._called = []; - var tw = new TestWriter({ + const tw = new TestWriter({ highWaterMark: 100 }); @@ -229,28 +230,28 @@ test('write callbacks', function(t) { }); test('end callback', function(t) { - var tw = new TestWriter(); + const tw = new TestWriter(); tw.end(function() { t.end(); }); }); test('end callback with chunk', function(t) { - var tw = new TestWriter(); + const tw = new TestWriter(); tw.end(Buffer.from('hello world'), function() { t.end(); }); }); test('end callback with chunk and encoding', function(t) { - var tw = new TestWriter(); + const tw = new TestWriter(); tw.end('hello world', 'ascii', function() { t.end(); }); }); test('end callback after .write() call', function(t) { - var tw = new TestWriter(); + const tw = new TestWriter(); tw.write(Buffer.from('hello world')); tw.end(function() { t.end(); @@ -258,8 +259,8 @@ test('end callback after .write() call', function(t) { }); test('end callback called after write callback', function(t) { - var tw = new TestWriter(); - var writeCalledback = false; + const tw = new TestWriter(); + let writeCalledback = false; tw.write(Buffer.from('hello world'), function() { writeCalledback = true; }); @@ -270,20 +271,20 @@ test('end callback called after write callback', function(t) { }); test('encoding should be ignored for buffers', function(t) { - var tw = new W(); - var hex = '018b5e9a8f6236ffe30e31baf80d2cf6eb'; + const tw = new W(); + const hex = '018b5e9a8f6236ffe30e31baf80d2cf6eb'; tw._write = function(chunk) { t.equal(chunk.toString('hex'), hex); t.end(); }; - var buf = Buffer.from(hex, 'hex'); + const buf = Buffer.from(hex, 'hex'); tw.write(buf, 'latin1'); }); test('writables are not pipable', function(t) { - var w = new W(); + const w = new W(); w._write = function() {}; - var gotError = false; + let gotError = false; w.on('error', function() { gotError = true; }); @@ -293,10 +294,10 @@ test('writables are not pipable', function(t) { }); test('duplexes are pipable', function(t) { - var d = new D(); + const d = new D(); d._read = function() {}; d._write = function() {}; - var gotError = false; + let gotError = false; d.on('error', function() { gotError = true; }); @@ -306,9 +307,9 @@ test('duplexes are pipable', function(t) { }); test('end(chunk) two times is an error', function(t) { - var w = new W(); + const w = new W(); w._write = function() {}; - var gotError = false; + let gotError = false; w.on('error', function(er) { gotError = true; t.equal(er.message, 'write after end'); @@ -322,8 +323,8 @@ test('end(chunk) two times is an error', function(t) { }); test('dont end while writing', function(t) { - var w = new W(); - var wrote = false; + const w = new W(); + let wrote = false; w._write = function(chunk, e, cb) { assert(!this.writing); wrote = true; @@ -342,8 +343,8 @@ test('dont end while writing', function(t) { }); test('finish does not come before write cb', function(t) { - var w = new W(); - var writeCb = false; + const w = new W(); + let writeCb = false; w._write = function(chunk, e, cb) { setTimeout(function() { writeCb = true; @@ -359,8 +360,8 @@ test('finish does not come before write cb', function(t) { }); test('finish does not come before sync _write cb', function(t) { - var w = new W(); - var writeCb = false; + const w = new W(); + let writeCb = false; w._write = function(chunk, e, cb) { cb(); }; @@ -375,7 +376,7 @@ test('finish does not come before sync _write cb', function(t) { }); test('finish is emitted if last chunk is empty', function(t) { - var w = new W(); + const w = new W(); w._write = function(chunk, e, cb) { process.nextTick(cb); }; diff --git a/test/parallel/test-stream3-cork-end.js b/test/parallel/test-stream3-cork-end.js index a0b611d0da1b66..230227e0b13ddb 100644 --- a/test/parallel/test-stream3-cork-end.js +++ b/test/parallel/test-stream3-cork-end.js @@ -12,11 +12,11 @@ const Writable = stream.Writable; // node version target: 0.12 const expectedChunks = ['please', 'buffer', 'me', 'kindly']; -var inputChunks = expectedChunks.slice(0); -var seenChunks = []; -var seenEnd = false; +const inputChunks = expectedChunks.slice(0); +let seenChunks = []; +let seenEnd = false; -var w = new Writable(); +const w = new Writable(); // lets arrange to store the chunks w._write = function(chunk, encoding, cb) { // stream end event is not seen before the last write @@ -33,8 +33,8 @@ w.on('finish', () => { }); function writeChunks(remainingChunks, callback) { - var writeChunk = remainingChunks.shift(); - var writeState; + const writeChunk = remainingChunks.shift(); + let writeState; if (writeChunk) { setImmediate(() => { @@ -74,12 +74,12 @@ writeChunks(inputChunks, () => { assert.equal(seenChunks.length, 4); // did the chunks match - for (var i = 0, l = expectedChunks.length; i < l; i++) { - var seen = seenChunks[i]; + for (let i = 0, l = expectedChunks.length; i < l; i++) { + const seen = seenChunks[i]; // there was a chunk assert.ok(seen); - var expected = new Buffer(expectedChunks[i]); + const expected = new Buffer(expectedChunks[i]); // it was what we expected assert.ok(seen.equals(expected)); } diff --git a/test/parallel/test-stream3-cork-uncork.js b/test/parallel/test-stream3-cork-uncork.js index cd86e8cf809bac..821fd22bf8b8a3 100644 --- a/test/parallel/test-stream3-cork-uncork.js +++ b/test/parallel/test-stream3-cork-uncork.js @@ -12,11 +12,11 @@ const Writable = stream.Writable; // node version target: 0.12 const expectedChunks = ['please', 'buffer', 'me', 'kindly']; -var inputChunks = expectedChunks.slice(0); -var seenChunks = []; -var seenEnd = false; +const inputChunks = expectedChunks.slice(0); +let seenChunks = []; +let seenEnd = false; -var w = new Writable(); +const w = new Writable(); // lets arrange to store the chunks w._write = function(chunk, encoding, cb) { // default encoding given none was specified @@ -31,8 +31,8 @@ w.on('finish', () => { }); function writeChunks(remainingChunks, callback) { - var writeChunk = remainingChunks.shift(); - var writeState; + const writeChunk = remainingChunks.shift(); + let writeState; if (writeChunk) { setImmediate(() => { @@ -69,12 +69,12 @@ writeChunks(inputChunks, () => { assert.equal(seenChunks.length, 4); // did the chunks match - for (var i = 0, l = expectedChunks.length; i < l; i++) { - var seen = seenChunks[i]; + for (let i = 0, l = expectedChunks.length; i < l; i++) { + const seen = seenChunks[i]; // there was a chunk assert.ok(seen); - var expected = new Buffer(expectedChunks[i]); + const expected = new Buffer(expectedChunks[i]); // it was what we expected assert.ok(seen.equals(expected)); } diff --git a/test/parallel/test-stream3-pause-then-read.js b/test/parallel/test-stream3-pause-then-read.js index 64d25fefc94c86..5a9550bcd41d7f 100644 --- a/test/parallel/test-stream3-pause-then-read.js +++ b/test/parallel/test-stream3-pause-then-read.js @@ -1,18 +1,18 @@ 'use strict'; require('../common'); -var assert = require('assert'); +const assert = require('assert'); -var stream = require('stream'); -var Readable = stream.Readable; -var Writable = stream.Writable; +const stream = require('stream'); +const Readable = stream.Readable; +const Writable = stream.Writable; -var totalChunks = 100; -var chunkSize = 99; -var expectTotalData = totalChunks * chunkSize; -var expectEndingData = expectTotalData; +const totalChunks = 100; +const chunkSize = 99; +const expectTotalData = totalChunks * chunkSize; +let expectEndingData = expectTotalData; -var r = new Readable({ highWaterMark: 1000 }); -var chunks = totalChunks; +const r = new Readable({ highWaterMark: 1000 }); +let chunks = totalChunks; r._read = function(n) { if (!(chunks % 2)) setImmediate(push); @@ -22,9 +22,9 @@ r._read = function(n) { push(); }; -var totalPushed = 0; +let totalPushed = 0; function push() { - var chunk = chunks-- > 0 ? Buffer.alloc(chunkSize, 'x') : null; + const chunk = chunks-- > 0 ? Buffer.alloc(chunkSize, 'x') : null; if (chunk) { totalPushed += chunk.length; } @@ -42,7 +42,7 @@ function readn(n, then) { console.error('read %d', n); expectEndingData -= n; (function read() { - var c = r.read(n); + const c = r.read(n); if (!c) r.once('readable', read); else { @@ -57,7 +57,7 @@ function readn(n, then) { function onData() { expectEndingData -= 100; console.error('onData'); - var seen = 0; + let seen = 0; r.on('data', function od(c) { seen += c.length; if (seen >= 100) { @@ -67,7 +67,7 @@ function onData() { if (seen > 100) { // oh no, seen too much! // put the extra back. - var diff = seen - 100; + const diff = seen - 100; r.unshift(c.slice(c.length - diff)); console.error('seen too much', seen, diff); } @@ -82,8 +82,8 @@ function onData() { function pipeLittle() { expectEndingData -= 200; console.error('pipe a little'); - var w = new Writable(); - var written = 0; + const w = new Writable(); + let written = 0; w.on('finish', function() { assert.equal(written, 200); setImmediate(read1234); @@ -95,7 +95,7 @@ function pipeLittle() { w.end(); cb(); if (written > 200) { - var diff = written - 200; + const diff = written - 200; written -= diff; r.unshift(chunk.slice(chunk.length - diff)); } @@ -130,8 +130,8 @@ function resumePause() { function pipe() { console.error('pipe the rest'); - var w = new Writable(); - var written = 0; + const w = new Writable(); + let written = 0; w._write = function(chunk, encoding, cb) { written += chunk.length; cb(); diff --git a/test/parallel/test-string-decoder-end.js b/test/parallel/test-string-decoder-end.js index 4769d880cf8d34..16f605d2dd8198 100644 --- a/test/parallel/test-string-decoder-end.js +++ b/test/parallel/test-string-decoder-end.js @@ -4,9 +4,9 @@ // result of the entire buffer. require('../common'); -var assert = require('assert'); -var SD = require('string_decoder').StringDecoder; -var encodings = ['base64', 'hex', 'utf8', 'utf16le', 'ucs2']; +const assert = require('assert'); +const SD = require('string_decoder').StringDecoder; +const encodings = ['base64', 'hex', 'utf8', 'utf16le', 'ucs2']; const bufs = [ '☃💩', 'asdf' ].map((b) => Buffer.from(b)); @@ -30,21 +30,21 @@ function testBuf(encoding, buf) { console.error('# %s', encoding, buf); // write one byte at a time. - var s = new SD(encoding); - var res1 = ''; - for (var i = 0; i < buf.length; i++) { + let s = new SD(encoding); + let res1 = ''; + for (let i = 0; i < buf.length; i++) { res1 += s.write(buf.slice(i, i + 1)); } res1 += s.end(); // write the whole buffer at once. - var res2 = ''; + let res2 = ''; s = new SD(encoding); res2 += s.write(buf); res2 += s.end(); // .toString() on the buffer - var res3 = buf.toString(encoding); + const res3 = buf.toString(encoding); console.log('expect=%j', res3); console.log('res1=%j', res1); diff --git a/test/parallel/test-string-decoder.js b/test/parallel/test-string-decoder.js index 4cdd235fbaa191..07883a14ec8b7a 100644 --- a/test/parallel/test-string-decoder.js +++ b/test/parallel/test-string-decoder.js @@ -1,11 +1,11 @@ 'use strict'; require('../common'); -var assert = require('assert'); -var inspect = require('util').inspect; -var StringDecoder = require('string_decoder').StringDecoder; +const assert = require('assert'); +const inspect = require('util').inspect; +const StringDecoder = require('string_decoder').StringDecoder; // Test default encoding -var decoder = new StringDecoder(); +let decoder = new StringDecoder(); assert.strictEqual(decoder.encoding, 'utf8'); process.stdout.write('scanning '); @@ -121,7 +121,7 @@ assert.throws(() => { // singleSequence allows for easy debugging of a specific sequence which is // useful in case of test failures. function test(encoding, input, expected, singleSequence) { - var sequences; + let sequences; if (!singleSequence) { sequences = writeSequences(input.length); } else { @@ -136,7 +136,7 @@ function test(encoding, input, expected, singleSequence) { output += decoder.end(); process.stdout.write('.'); if (output !== expected) { - var message = + const message = 'Expected "' + unicodeEscape(expected) + '", ' + 'but got "' + unicodeEscape(output) + '"\n' + 'input: ' + input.toString('hex').match(/.{2}/g) + '\n' + @@ -149,8 +149,8 @@ function test(encoding, input, expected, singleSequence) { // unicodeEscape prints the str contents as unicode escape codes. function unicodeEscape(str) { - var r = ''; - for (var i = 0; i < str.length; i++) { + let r = ''; + for (let i = 0; i < str.length; i++) { r += '\\u' + str.charCodeAt(i).toString(16); } return r; @@ -173,10 +173,10 @@ function writeSequences(length, start, sequence) { } else if (start === length) { return [sequence]; } - var sequences = []; - for (var end = length; end > start; end--) { - var subSequence = sequence.concat([[start, end]]); - var subSequences = writeSequences(length, end, subSequence, sequences); + let sequences = []; + for (let end = length; end > start; end--) { + const subSequence = sequence.concat([[start, end]]); + const subSequences = writeSequences(length, end, subSequence, sequences); sequences = sequences.concat(subSequences); } return sequences; diff --git a/test/parallel/test-stringbytes-external.js b/test/parallel/test-stringbytes-external.js index a34612f75d71f6..a242b943c91a4d 100644 --- a/test/parallel/test-stringbytes-external.js +++ b/test/parallel/test-stringbytes-external.js @@ -1,18 +1,18 @@ 'use strict'; require('../common'); -var assert = require('assert'); +const assert = require('assert'); // minimum string size to overflow into external string space -var EXTERN_APEX = 0xFBEE9; +const EXTERN_APEX = 0xFBEE9; // manually controlled string for checking binary output -var ucs2_control = 'a\u0000'; -var write_str = 'a'; +let ucs2_control = 'a\u0000'; +let write_str = 'a'; // first do basic checks -var b = Buffer.from(write_str, 'ucs2'); +let b = Buffer.from(write_str, 'ucs2'); // first check latin1 -var c = b.toString('latin1'); +let c = b.toString('latin1'); assert.equal(b[0], 0x61); assert.equal(b[1], 0); assert.equal(ucs2_control, c); @@ -23,7 +23,7 @@ assert.equal(b[1], 0); assert.equal(ucs2_control, c); // now create big strings -var size = 1 + (1 << 20); +const size = 1 + (1 << 20); write_str = Array(size).join(write_str); ucs2_control = Array(size).join(ucs2_control); @@ -36,19 +36,19 @@ for (let i = 0; i < b.length; i += 2) { } // create another string to create an external string -var b_ucs = b.toString('ucs2'); +const b_ucs = b.toString('ucs2'); // check control against external binary string -var l_bin = b.toString('latin1'); +const l_bin = b.toString('latin1'); assert.equal(ucs2_control, l_bin); // check control against external binary string -var b_bin = b.toString('binary'); +const b_bin = b.toString('binary'); assert.equal(ucs2_control, b_bin); // create buffer copy from external -var c_bin = Buffer.from(l_bin, 'latin1'); -var c_ucs = Buffer.from(b_ucs, 'ucs2'); +const c_bin = Buffer.from(l_bin, 'latin1'); +const c_ucs = Buffer.from(b_ucs, 'ucs2'); // make sure they're the same length assert.equal(c_bin.length, c_ucs.length); // make sure Buffers from externals are the same @@ -62,9 +62,9 @@ assert.equal(c_ucs.toString('latin1'), ucs2_control); // now let's test BASE64 and HEX ecoding/decoding -var RADIOS = 2; -var PRE_HALF_APEX = Math.ceil(EXTERN_APEX / 2) - RADIOS; -var PRE_3OF4_APEX = Math.ceil((EXTERN_APEX / 4) * 3) - RADIOS; +const RADIOS = 2; +const PRE_HALF_APEX = Math.ceil(EXTERN_APEX / 2) - RADIOS; +const PRE_3OF4_APEX = Math.ceil((EXTERN_APEX / 4) * 3) - RADIOS; { for (let j = 0; j < RADIOS * 2; j += 1) { diff --git a/test/parallel/test-sync-io-option.js b/test/parallel/test-sync-io-option.js index fec61ef62f370e..6166bffc0bd68c 100644 --- a/test/parallel/test-sync-io-option.js +++ b/test/parallel/test-sync-io-option.js @@ -12,9 +12,9 @@ if (process.argv[2] === 'child') { } else { (function runTest(flags) { - var execArgv = [flags.pop()]; - var args = [__filename, 'child']; - var cntr = 0; + const execArgv = [flags.pop()]; + let args = [__filename, 'child']; + let cntr = 0; args = execArgv.concat(args); if (!args[0]) args.shift(); execFile(process.execPath, args, function(err, stdout, stderr) { diff --git a/test/parallel/test-sys.js b/test/parallel/test-sys.js index 3e28f020333c20..234744bb118fd7 100644 --- a/test/parallel/test-sys.js +++ b/test/parallel/test-sys.js @@ -1,7 +1,7 @@ 'use strict'; require('../common'); -var assert = require('assert'); -var sys = require('sys'); // eslint-disable-line no-restricted-modules -var util = require('util'); +const assert = require('assert'); +const sys = require('sys'); // eslint-disable-line no-restricted-modules +const util = require('util'); assert.strictEqual(sys, util); diff --git a/test/parallel/test-tcp-wrap-connect.js b/test/parallel/test-tcp-wrap-connect.js index 7ce88d194cd648..77f9814db2ebe5 100644 --- a/test/parallel/test-tcp-wrap-connect.js +++ b/test/parallel/test-tcp-wrap-connect.js @@ -1,15 +1,15 @@ 'use strict'; require('../common'); -var assert = require('assert'); -var TCP = process.binding('tcp_wrap').TCP; -var TCPConnectWrap = process.binding('tcp_wrap').TCPConnectWrap; -var ShutdownWrap = process.binding('stream_wrap').ShutdownWrap; +const assert = require('assert'); +const TCP = process.binding('tcp_wrap').TCP; +const TCPConnectWrap = process.binding('tcp_wrap').TCPConnectWrap; +const ShutdownWrap = process.binding('stream_wrap').ShutdownWrap; function makeConnection() { - var client = new TCP(); + const client = new TCP(); - var req = new TCPConnectWrap(); - var err = client.connect(req, '127.0.0.1', this.address().port); + const req = new TCPConnectWrap(); + const err = client.connect(req, '127.0.0.1', this.address().port); assert.strictEqual(err, 0); req.oncomplete = function(status, client_, req_, readable, writable) { @@ -19,8 +19,8 @@ function makeConnection() { assert.strictEqual(true, readable); assert.strictEqual(true, writable); - var shutdownReq = new ShutdownWrap(); - var err = client.shutdown(shutdownReq); + const shutdownReq = new ShutdownWrap(); + const err = client.shutdown(shutdownReq); assert.strictEqual(err, 0); shutdownReq.oncomplete = function(status, client_, req_) { @@ -35,11 +35,11 @@ function makeConnection() { ///// -var connectCount = 0; -var endCount = 0; -var shutdownCount = 0; +let connectCount = 0; +let endCount = 0; +let shutdownCount = 0; -var server = require('net').Server(function(s) { +const server = require('net').Server(function(s) { connectCount++; s.resume(); s.on('end', function() { diff --git a/test/parallel/test-tcp-wrap.js b/test/parallel/test-tcp-wrap.js index 18b8fe401f8902..6b9dbd90a4c113 100644 --- a/test/parallel/test-tcp-wrap.js +++ b/test/parallel/test-tcp-wrap.js @@ -1,18 +1,18 @@ 'use strict'; require('../common'); -var assert = require('assert'); +const assert = require('assert'); -var TCP = process.binding('tcp_wrap').TCP; -var uv = process.binding('uv'); +const TCP = process.binding('tcp_wrap').TCP; +const uv = process.binding('uv'); -var handle = new TCP(); +const handle = new TCP(); // Should be able to bind to the port -var err = handle.bind('0.0.0.0', 0); +let err = handle.bind('0.0.0.0', 0); assert.equal(err, 0); // Should not be able to bind to the same port again -var out = {}; +const out = {}; handle.getsockname(out); err = handle.bind('0.0.0.0', out.port); assert.equal(err, uv.UV_EINVAL); diff --git a/test/parallel/test-timer-close.js b/test/parallel/test-timer-close.js index f13078e5a5bed1..158b082cf3167a 100644 --- a/test/parallel/test-timer-close.js +++ b/test/parallel/test-timer-close.js @@ -1,9 +1,9 @@ 'use strict'; require('../common'); -var assert = require('assert'); +const assert = require('assert'); -var t = new (process.binding('timer_wrap').Timer)(); -var called = 0; +const t = new (process.binding('timer_wrap').Timer)(); +let called = 0; function onclose() { called++; } diff --git a/test/parallel/test-timers-active.js b/test/parallel/test-timers-active.js index 8677e43971ac89..62707cf18c0ab7 100644 --- a/test/parallel/test-timers-active.js +++ b/test/parallel/test-timers-active.js @@ -4,7 +4,7 @@ const assert = require('assert'); const active = require('timers').active; // active() should create timers for these -var legitTimers = [ +const legitTimers = [ { _idleTimeout: 0 }, { _idleTimeout: 1 } ]; @@ -21,7 +21,7 @@ legitTimers.forEach(function(legit) { // active() should not create a timer for these -var bogusTimers = [ +const bogusTimers = [ { _idleTimeout: -1 }, { _idleTimeout: undefined }, ]; diff --git a/test/parallel/test-timers-args.js b/test/parallel/test-timers-args.js index 21eafd1bcd9ea6..1ba44d8bcf3664 100644 --- a/test/parallel/test-timers-args.js +++ b/test/parallel/test-timers-args.js @@ -1,13 +1,13 @@ 'use strict'; require('../common'); -var assert = require('assert'); +const assert = require('assert'); function range(n) { return 'x'.repeat(n + 1).split('').map(function(_, i) { return i; }); } function timeout(nargs) { - var args = range(nargs); + const args = range(nargs); setTimeout.apply(null, [callback, 1].concat(args)); function callback() { @@ -17,8 +17,8 @@ function timeout(nargs) { } function interval(nargs) { - var args = range(nargs); - var timer = setTimeout.apply(null, [callback, 1].concat(args)); + const args = range(nargs); + const timer = setTimeout.apply(null, [callback, 1].concat(args)); function callback() { clearInterval(timer); diff --git a/test/parallel/test-timers-clearImmediate.js b/test/parallel/test-timers-clearImmediate.js index ab65b7bf1ce05d..c49fd7622f4ab6 100644 --- a/test/parallel/test-timers-clearImmediate.js +++ b/test/parallel/test-timers-clearImmediate.js @@ -3,14 +3,14 @@ require('../common'); const assert = require('assert'); const N = 3; -var count = 0; +let count = 0; function next() { const immediate = setImmediate(function() { clearImmediate(immediate); ++count; }); } -for (var i = 0; i < N; ++i) +for (let i = 0; i < N; ++i) next(); process.on('exit', () => { diff --git a/test/parallel/test-timers-immediate-queue.js b/test/parallel/test-timers-immediate-queue.js index 62482d510a6608..43897f50617fd7 100644 --- a/test/parallel/test-timers-immediate-queue.js +++ b/test/parallel/test-timers-immediate-queue.js @@ -1,6 +1,6 @@ 'use strict'; require('../common'); -var assert = require('assert'); +const assert = require('assert'); // setImmediate should run clear its queued cbs once per event loop turn // but immediates queued while processing the current queue should happen @@ -11,10 +11,10 @@ var assert = require('assert'); // if we're letting things recursively add to the immediate QUEUE hit will be // > QUEUE -var ticked = false; +let ticked = false; -var hit = 0; -var QUEUE = 1000; +let hit = 0; +const QUEUE = 1000; function run() { if (hit === 0) @@ -26,7 +26,7 @@ function run() { setImmediate(run); } -for (var i = 0; i < QUEUE; i++) +for (let i = 0; i < QUEUE; i++) setImmediate(run); process.on('exit', function() { diff --git a/test/parallel/test-timers-nested.js b/test/parallel/test-timers-nested.js index d5d272ed2eae11..0ff228abf50311 100644 --- a/test/parallel/test-timers-nested.js +++ b/test/parallel/test-timers-nested.js @@ -11,7 +11,7 @@ const assert = require('assert'); const scenarios = [0, 100]; scenarios.forEach(function(delay) { - var nestedCalled = false; + let nestedCalled = false; setTimeout(function A() { // Create the nested timer with the same delay as the outer timer so that it diff --git a/test/parallel/test-timers-non-integer-delay.js b/test/parallel/test-timers-non-integer-delay.js index b42053db3b1895..b062fcb6f229b0 100644 --- a/test/parallel/test-timers-non-integer-delay.js +++ b/test/parallel/test-timers-non-integer-delay.js @@ -17,11 +17,11 @@ require('../common'); -var TIMEOUT_DELAY = 1.1; -var NB_TIMEOUTS_FIRED = 50; +const TIMEOUT_DELAY = 1.1; +const NB_TIMEOUTS_FIRED = 50; -var nbTimeoutFired = 0; -var interval = setInterval(function() { +let nbTimeoutFired = 0; +const interval = setInterval(function() { ++nbTimeoutFired; if (nbTimeoutFired === NB_TIMEOUTS_FIRED) { clearInterval(interval); diff --git a/test/parallel/test-timers-ordering.js b/test/parallel/test-timers-ordering.js index c23af9d8307e9a..55fb141cb272ce 100644 --- a/test/parallel/test-timers-ordering.js +++ b/test/parallel/test-timers-ordering.js @@ -1,14 +1,14 @@ 'use strict'; require('../common'); -var assert = require('assert'); -var Timer = process.binding('timer_wrap').Timer; +const assert = require('assert'); +const Timer = process.binding('timer_wrap').Timer; -var N = 30; +const N = 30; -var last_i = 0; -var last_ts = 0; +let last_i = 0; +let last_ts = 0; -var f = function(i) { +const f = function(i) { if (i <= N) { // check order assert.equal(i, last_i + 1, 'order is broken: ' + i + ' != ' + @@ -16,7 +16,7 @@ var f = function(i) { last_i = i; // check that this iteration is fired at least 1ms later than the previous - var now = Timer.now(); + const now = Timer.now(); console.log(i, now); assert(now >= last_ts + 1, 'current ts ' + now + ' < prev ts ' + last_ts + ' + 1'); diff --git a/test/parallel/test-timers-socket-timeout-removes-other-socket-unref-timer.js b/test/parallel/test-timers-socket-timeout-removes-other-socket-unref-timer.js index 8670c3c2b6e8f3..f42144360b6941 100644 --- a/test/parallel/test-timers-socket-timeout-removes-other-socket-unref-timer.js +++ b/test/parallel/test-timers-socket-timeout-removes-other-socket-unref-timer.js @@ -32,7 +32,7 @@ const server = net.createServer(function onClient(client) { }); server.listen(0, common.localhostIPv4, function() { - var nbClientsEnded = 0; + let nbClientsEnded = 0; function addEndedClient(client) { ++nbClientsEnded; diff --git a/test/parallel/test-timers-uncaught-exception.js b/test/parallel/test-timers-uncaught-exception.js index 6b6dc583715849..87fd880de4bf89 100644 --- a/test/parallel/test-timers-uncaught-exception.js +++ b/test/parallel/test-timers-uncaught-exception.js @@ -1,10 +1,10 @@ 'use strict'; require('../common'); -var assert = require('assert'); +const assert = require('assert'); -var exceptions = 0; -var timer1 = 0; -var timer2 = 0; +let exceptions = 0; +let timer1 = 0; +let timer2 = 0; // the first timer throws... console.error('set first timer'); @@ -29,7 +29,7 @@ function uncaughtException(err) { } process.on('uncaughtException', uncaughtException); -var exited = false; +let exited = false; process.on('exit', function() { assert(!exited); exited = true; diff --git a/test/parallel/test-timers-unref-active.js b/test/parallel/test-timers-unref-active.js index 69027277ea0ff2..8b1c89673bc35f 100644 --- a/test/parallel/test-timers-unref-active.js +++ b/test/parallel/test-timers-unref-active.js @@ -19,8 +19,8 @@ require('../common'); const timers = require('timers'); const assert = require('assert'); -var someObject = {}; -var nbTimeouts = 0; +const someObject = {}; +let nbTimeouts = 0; /* * libuv 0.10.x uses GetTickCount on Windows to implement timers, which uses diff --git a/test/parallel/test-timers-unref-call.js b/test/parallel/test-timers-unref-call.js index edd5865e8f610b..5384441838763a 100644 --- a/test/parallel/test-timers-unref-call.js +++ b/test/parallel/test-timers-unref-call.js @@ -1,12 +1,12 @@ 'use strict'; require('../common'); -var Timer = process.binding('timer_wrap').Timer; +const Timer = process.binding('timer_wrap').Timer; Timer.now = function() { return ++Timer.now.ticks; }; Timer.now.ticks = 0; -var t = setInterval(function() {}, 1); -var o = { _idleStart: 0, _idleTimeout: 1 }; +const t = setInterval(function() {}, 1); +const o = { _idleStart: 0, _idleTimeout: 1 }; t.unref.call(o); setTimeout(clearInterval.bind(null, t), 2); diff --git a/test/parallel/test-timers-unref-leak.js b/test/parallel/test-timers-unref-leak.js index a1b1265763bf1d..d970910b24abe6 100644 --- a/test/parallel/test-timers-unref-leak.js +++ b/test/parallel/test-timers-unref-leak.js @@ -1,17 +1,17 @@ 'use strict'; require('../common'); -var assert = require('assert'); +const assert = require('assert'); -var called = 0; -var closed = 0; +let called = 0; +let closed = 0; -var timeout = setTimeout(function() { +const timeout = setTimeout(function() { called++; }, 10); timeout.unref(); // Wrap `close` method to check if the handle was closed -var close = timeout._handle.close; +const close = timeout._handle.close; timeout._handle.close = function() { closed++; return close.apply(this, arguments); diff --git a/test/parallel/test-timers-unref-remove-other-unref-timers-only-one-fires.js b/test/parallel/test-timers-unref-remove-other-unref-timers-only-one-fires.js index 971c485a4cf986..1dcc3e68de9eaa 100644 --- a/test/parallel/test-timers-unref-remove-other-unref-timers-only-one-fires.js +++ b/test/parallel/test-timers-unref-remove-other-unref-timers-only-one-fires.js @@ -14,7 +14,7 @@ require('../common'); const timers = require('timers'); const assert = require('assert'); -var nbTimersFired = 0; +let nbTimersFired = 0; const foo = { _onTimeout: function() { diff --git a/test/parallel/test-timers-unref.js b/test/parallel/test-timers-unref.js index 801b34792a1f73..2bde08f914d790 100644 --- a/test/parallel/test-timers-unref.js +++ b/test/parallel/test-timers-unref.js @@ -1,6 +1,6 @@ 'use strict'; require('../common'); -var assert = require('assert'); +const assert = require('assert'); let interval_fired = false; let timeout_fired = false; @@ -9,8 +9,8 @@ let unref_timer = false; let unref_callbacks = 0; let checks = 0; -var LONG_TIME = 10 * 1000; -var SHORT_TIME = 100; +const LONG_TIME = 10 * 1000; +const SHORT_TIME = 100; assert.doesNotThrow(function() { setTimeout(function() {}, 10).unref().ref().unref(); diff --git a/test/parallel/test-timers-unrefd-interval-still-fires.js b/test/parallel/test-timers-unrefd-interval-still-fires.js index 39bb2cdb138205..bf16013f004965 100644 --- a/test/parallel/test-timers-unrefd-interval-still-fires.js +++ b/test/parallel/test-timers-unrefd-interval-still-fires.js @@ -6,7 +6,7 @@ const common = require('../common'); const TEST_DURATION = common.platformTimeout(1000); const N = 3; -var nbIntervalFired = 0; +let nbIntervalFired = 0; const keepOpen = setTimeout(() => { console.error('[FAIL] Interval fired %d/%d times.', nbIntervalFired, N); diff --git a/test/parallel/test-timers-unrefed-in-beforeexit.js b/test/parallel/test-timers-unrefed-in-beforeexit.js index 0ac3311816fb4d..530d97674d8bf7 100644 --- a/test/parallel/test-timers-unrefed-in-beforeexit.js +++ b/test/parallel/test-timers-unrefed-in-beforeexit.js @@ -3,7 +3,7 @@ require('../common'); const assert = require('assert'); -var once = 0; +let once = 0; process.on('beforeExit', () => { if (once > 1) diff --git a/test/parallel/test-timers.js b/test/parallel/test-timers.js index 87397735eebff2..df2240d2c444af 100644 --- a/test/parallel/test-timers.js +++ b/test/parallel/test-timers.js @@ -2,7 +2,7 @@ const common = require('../common'); const assert = require('assert'); -var inputs = [ +const inputs = [ undefined, null, true, @@ -30,15 +30,15 @@ var inputs = [ 12345678901234 // ditto ]; -var timeouts = []; -var intervals = []; +const timeouts = []; +const intervals = []; inputs.forEach(function(value, index) { setTimeout(function() { timeouts[index] = true; }, value); - var handle = setInterval(function() { + const handle = setInterval(function() { clearInterval(handle); // disarm timer or we'll never finish intervals[index] = true; }, value); diff --git a/test/parallel/test-tls-alert.js b/test/parallel/test-tls-alert.js index db22443918453b..a8c6016f6218b7 100644 --- a/test/parallel/test-tls-alert.js +++ b/test/parallel/test-tls-alert.js @@ -1,6 +1,6 @@ 'use strict'; -var common = require('../common'); -var assert = require('assert'); +const common = require('../common'); +const assert = require('assert'); if (!common.opensslCli) { common.skip('node compiled without OpenSSL CLI.'); @@ -11,12 +11,12 @@ if (!common.hasCrypto) { common.skip('missing crypto'); return; } -var tls = require('tls'); +const tls = require('tls'); -var fs = require('fs'); -var spawn = require('child_process').spawn; +const fs = require('fs'); +const spawn = require('child_process').spawn; -var success = false; +let success = false; function filenamePEM(n) { return require('path').join(common.fixturesDir, 'keys', n + '.pem'); @@ -26,20 +26,20 @@ function loadPEM(n) { return fs.readFileSync(filenamePEM(n)); } -var server = tls.Server({ +const server = tls.Server({ secureProtocol: 'TLSv1_2_server_method', key: loadPEM('agent2-key'), cert: loadPEM('agent2-cert') }, null).listen(0, function() { - var args = ['s_client', '-quiet', '-tls1_1', - '-connect', `127.0.0.1:${this.address().port}`]; + const args = ['s_client', '-quiet', '-tls1_1', + '-connect', `127.0.0.1:${this.address().port}`]; // for the performance and stability issue in s_client on Windows if (common.isWindows) args.push('-no_rand_screen'); - var client = spawn(common.opensslCli, args); - var out = ''; + const client = spawn(common.opensslCli, args); + let out = ''; client.stderr.setEncoding('utf8'); client.stderr.on('data', function(d) { out += d; diff --git a/test/parallel/test-tls-alpn-server-client.js b/test/parallel/test-tls-alpn-server-client.js index 0da2086f4de506..ca5785b09ac05a 100644 --- a/test/parallel/test-tls-alpn-server-client.js +++ b/test/parallel/test-tls-alpn-server-client.js @@ -24,7 +24,7 @@ function loadPEM(n) { return fs.readFileSync(filenamePEM(n)); } -var serverIP = common.localhostIPv4; +const serverIP = common.localhostIPv4; function checkResults(result, expected) { assert.strictEqual(result.server.ALPN, expected.server.ALPN); @@ -36,9 +36,9 @@ function checkResults(result, expected) { function runTest(clientsOptions, serverOptions, cb) { serverOptions.key = loadPEM('agent2-key'); serverOptions.cert = loadPEM('agent2-cert'); - var results = []; - var index = 0; - var server = tls.createServer(serverOptions, function(c) { + const results = []; + let index = 0; + const server = tls.createServer(serverOptions, function(c) { results[index].server = {ALPN: c.alpnProtocol, NPN: c.npnProtocol}; }); @@ -47,13 +47,13 @@ function runTest(clientsOptions, serverOptions, cb) { }); function connectClient(options) { - var opt = options.shift(); + const opt = options.shift(); opt.port = server.address().port; opt.host = serverIP; opt.rejectUnauthorized = false; results[index] = {}; - var client = tls.connect(opt, function() { + const client = tls.connect(opt, function() { results[index].client = {ALPN: client.alpnProtocol, NPN: client.npnProtocol}; client.destroy(); @@ -71,12 +71,12 @@ function runTest(clientsOptions, serverOptions, cb) { // Server: ALPN/NPN, Client: ALPN/NPN function Test1() { - var serverOptions = { + const serverOptions = { ALPNProtocols: ['a', 'b', 'c'], NPNProtocols: ['a', 'b', 'c'] }; - var clientsOptions = [{ + const clientsOptions = [{ ALPNProtocols: ['a', 'b', 'c'], NPNProtocols: ['a', 'b', 'c'] }, { @@ -107,12 +107,12 @@ function Test1() { // Server: ALPN/NPN, Client: ALPN function Test2() { - var serverOptions = { + const serverOptions = { ALPNProtocols: ['a', 'b', 'c'], NPNProtocols: ['a', 'b', 'c'] }; - var clientsOptions = [{ + const clientsOptions = [{ ALPNProtocols: ['a', 'b', 'c'] }, { ALPNProtocols: ['c', 'b', 'e'] @@ -140,12 +140,12 @@ function Test2() { // Server: ALPN/NPN, Client: NPN function Test3() { - var serverOptions = { + const serverOptions = { ALPNProtocols: ['a', 'b', 'c'], NPNProtocols: ['a', 'b', 'c'] }; - var clientsOptions = [{ + const clientsOptions = [{ NPNProtocols: ['a', 'b', 'c'] }, { NPPNProtocols: ['c', 'b', 'e'] @@ -173,12 +173,12 @@ function Test3() { // Server: ALPN/NPN, Client: Nothing function Test4() { - var serverOptions = { + const serverOptions = { ALPNProtocols: ['a', 'b', 'c'], NPNProtocols: ['a', 'b', 'c'] }; - var clientsOptions = [{}, {}, {}]; + const clientsOptions = [{}, {}, {}]; runTest(clientsOptions, serverOptions, function(results) { // nothing is selected by ALPN @@ -200,11 +200,11 @@ function Test4() { // Server: ALPN, Client: ALPN/NPN function Test5() { - var serverOptions = { + const serverOptions = { ALPNProtocols: ['a', 'b', 'c'] }; - var clientsOptions = [{ + const clientsOptions = [{ ALPNProtocols: ['a', 'b', 'c'], NPNProtocols: ['a', 'b', 'c'] }, { @@ -233,11 +233,11 @@ function Test5() { // Server: ALPN, Client: ALPN function Test6() { - var serverOptions = { + const serverOptions = { ALPNProtocols: ['a', 'b', 'c'] }; - var clientsOptions = [{ + const clientsOptions = [{ ALPNProtocols: ['a', 'b', 'c'] }, { ALPNProtocols: ['c', 'b', 'e'] @@ -262,11 +262,11 @@ function Test6() { // Server: ALPN, Client: NPN function Test7() { - var serverOptions = { + const serverOptions = { ALPNProtocols: ['a', 'b', 'c'] }; - var clientsOptions = [{ + const clientsOptions = [{ NPNProtocols: ['a', 'b', 'c'] }, { NPNProtocols: ['c', 'b', 'e'] @@ -292,11 +292,11 @@ function Test7() { // Server: ALPN, Client: Nothing function Test8() { - var serverOptions = { + const serverOptions = { ALPNProtocols: ['a', 'b', 'c'] }; - var clientsOptions = [{}, {}, {}]; + const clientsOptions = [{}, {}, {}]; runTest(clientsOptions, serverOptions, function(results) { // nothing is selected by ALPN @@ -316,11 +316,11 @@ function Test8() { // Server: NPN, Client: ALPN/NPN function Test9() { - var serverOptions = { + const serverOptions = { NPNProtocols: ['a', 'b', 'c'] }; - var clientsOptions = [{ + const clientsOptions = [{ ALPNrotocols: ['a', 'b', 'c'], NPNProtocols: ['a', 'b', 'c'] }, { @@ -349,11 +349,11 @@ function Test9() { // Server: NPN, Client: ALPN function Test10() { - var serverOptions = { + const serverOptions = { NPNProtocols: ['a', 'b', 'c'] }; - var clientsOptions = [{ + const clientsOptions = [{ ALPNProtocols: ['a', 'b', 'c'] }, { ALPNProtocols: ['c', 'b', 'e'] @@ -378,11 +378,11 @@ function Test10() { // Server: NPN, Client: NPN function Test11() { - var serverOptions = { + const serverOptions = { NPNProtocols: ['a', 'b', 'c'] }; - var clientsOptions = [{ + const clientsOptions = [{ NPNProtocols: ['a', 'b', 'c'] }, { NPNProtocols: ['c', 'b', 'e'] @@ -408,11 +408,11 @@ function Test11() { // Server: NPN, Client: Nothing function Test12() { - var serverOptions = { + const serverOptions = { NPNProtocols: ['a', 'b', 'c'] }; - var clientsOptions = [{}, {}, {}]; + const clientsOptions = [{}, {}, {}]; runTest(clientsOptions, serverOptions, function(results) { // nothing is selected @@ -432,9 +432,9 @@ function Test12() { // Server: Nothing, Client: ALPN/NPN function Test13() { - var serverOptions = {}; + const serverOptions = {}; - var clientsOptions = [{ + const clientsOptions = [{ ALPNrotocols: ['a', 'b', 'c'], NPNProtocols: ['a', 'b', 'c'] }, { @@ -463,9 +463,9 @@ function Test13() { // Server: Nothing, Client: ALPN function Test14() { - var serverOptions = {}; + const serverOptions = {}; - var clientsOptions = [{ + const clientsOptions = [{ ALPNrotocols: ['a', 'b', 'c'] }, { ALPNProtocols: ['c', 'b', 'e'] @@ -491,9 +491,9 @@ function Test14() { // Server: Nothing, Client: NPN function Test15() { - var serverOptions = {}; + const serverOptions = {}; - var clientsOptions = [{ + const clientsOptions = [{ NPNProtocols: ['a', 'b', 'c'] }, { NPNProtocols: ['c', 'b', 'e'] @@ -519,9 +519,9 @@ function Test15() { // Server: Nothing, Client: Nothing function Test16() { - var serverOptions = {}; + const serverOptions = {}; - var clientsOptions = [{}, {}, {}]; + const clientsOptions = [{}, {}, {}]; runTest(clientsOptions, serverOptions, function(results) { // nothing is selected diff --git a/test/parallel/test-tls-async-cb-after-socket-end.js b/test/parallel/test-tls-async-cb-after-socket-end.js index c72deb133c3e35..7e24835ee689e9 100644 --- a/test/parallel/test-tls-async-cb-after-socket-end.js +++ b/test/parallel/test-tls-async-cb-after-socket-end.js @@ -1,9 +1,9 @@ 'use strict'; -var common = require('../common'); +const common = require('../common'); -var path = require('path'); -var fs = require('fs'); +const path = require('path'); +const fs = require('fs'); const SSL_OP_NO_TICKET = require('crypto').constants.SSL_OP_NO_TICKET; if (!common.hasCrypto) { @@ -11,19 +11,19 @@ if (!common.hasCrypto) { return; } -var tls = require('tls'); +const tls = require('tls'); -var options = { +const options = { secureOptions: SSL_OP_NO_TICKET, key: fs.readFileSync(path.join(common.fixturesDir, 'test_key.pem')), cert: fs.readFileSync(path.join(common.fixturesDir, 'test_cert.pem')) }; -var server = tls.createServer(options, function(c) { +const server = tls.createServer(options, function(c) { }); -var sessionCb = null; -var client = null; +let sessionCb = null; +let client = null; server.on('newSession', function(key, session, done) { done(); @@ -36,18 +36,18 @@ server.on('resumeSession', function(id, cb) { }); server.listen(0, function() { - var clientOpts = { + const clientOpts = { port: this.address().port, rejectUnauthorized: false, session: false }; - var s1 = tls.connect(clientOpts, function() { + const s1 = tls.connect(clientOpts, function() { clientOpts.session = s1.getSession(); console.log('1st secure'); s1.destroy(); - var s2 = tls.connect(clientOpts, function(s) { + const s2 = tls.connect(clientOpts, function(s) { console.log('2nd secure'); s2.destroy(); diff --git a/test/parallel/test-tls-cert-regression.js b/test/parallel/test-tls-cert-regression.js index a26bab7c46e107..ff5827bcf844ee 100644 --- a/test/parallel/test-tls-cert-regression.js +++ b/test/parallel/test-tls-cert-regression.js @@ -1,14 +1,14 @@ 'use strict'; -var common = require('../common'); +const common = require('../common'); if (!common.hasCrypto) { common.skip('missing crypto'); return; } -var tls = require('tls'); +const tls = require('tls'); -var cert = +const cert = `-----BEGIN CERTIFICATE----- MIIBfjCCASgCCQDmmNjAojbDQjANBgkqhkiG9w0BAQUFADBFMQswCQYDVQQGEwJB VTETMBEGA1UECBMKU29tZS1TdGF0ZTEhMB8GA1UEChMYSW50ZXJuZXQgV2lkZ2l0 @@ -21,7 +21,7 @@ uvCyndyeB4d24FlfqEUlkfaWCZlNKRaV9YhLDiEg3BcIreFo4brtKQfZzTRs0GVm KHg= -----END CERTIFICATE-----`; -var key = +const key = `-----BEGIN RSA PRIVATE KEY----- MIIBPQIBAAJBAPKwlfMX6HGZIt1xm7fna72eWcOYfUfSxSugghvqYgJt2Oi3lH+w sU1O9FzRIVmpeIjDXhbpMjsa1HtzSiccPXsCAwEAAQJBAM4uU9aJE0OfdE1p/X+K @@ -33,7 +33,7 @@ AOaJnkQrmurlRdePX6LvN/LgGAQoxwovfjcOYNnZsIVY -----END RSA PRIVATE KEY-----`; function test(cert, key, cb) { - var server = tls.createServer({ + const server = tls.createServer({ cert: cert, key: key }).listen(0, function() { diff --git a/test/parallel/test-tls-cipher-list.js b/test/parallel/test-tls-cipher-list.js index 44ebd3d2f824ad..4acb30bc1c74bf 100644 --- a/test/parallel/test-tls-cipher-list.js +++ b/test/parallel/test-tls-cipher-list.js @@ -11,7 +11,7 @@ const spawn = require('child_process').spawn; const defaultCoreList = require('crypto').constants.defaultCoreCipherList; function doCheck(arg, check) { - var out = ''; + let out = ''; arg = arg.concat([ '-pe', 'require("crypto").constants.defaultCipherList' diff --git a/test/parallel/test-tls-client-abort.js b/test/parallel/test-tls-client-abort.js index d2fcf3e687e676..21ee41e927873b 100644 --- a/test/parallel/test-tls-client-abort.js +++ b/test/parallel/test-tls-client-abort.js @@ -1,20 +1,20 @@ 'use strict'; -var common = require('../common'); -var assert = require('assert'); +const common = require('../common'); +const assert = require('assert'); if (!common.hasCrypto) { common.skip('missing crypto'); return; } -var tls = require('tls'); +const tls = require('tls'); -var fs = require('fs'); -var path = require('path'); +const fs = require('fs'); +const path = require('path'); -var cert = fs.readFileSync(path.join(common.fixturesDir, 'test_cert.pem')); -var key = fs.readFileSync(path.join(common.fixturesDir, 'test_key.pem')); +const cert = fs.readFileSync(path.join(common.fixturesDir, 'test_cert.pem')); +const key = fs.readFileSync(path.join(common.fixturesDir, 'test_key.pem')); -var conn = tls.connect({cert: cert, key: key, port: common.PORT}, function() { +const conn = tls.connect({cert: cert, key: key, port: common.PORT}, function() { assert.ok(false); // callback should never be executed }); conn.on('error', function() { diff --git a/test/parallel/test-tls-client-abort2.js b/test/parallel/test-tls-client-abort2.js index f3295f6d854a72..3247a2899acdfb 100644 --- a/test/parallel/test-tls-client-abort2.js +++ b/test/parallel/test-tls-client-abort2.js @@ -1,14 +1,14 @@ 'use strict'; -var common = require('../common'); -var assert = require('assert'); +const common = require('../common'); +const assert = require('assert'); if (!common.hasCrypto) { common.skip('missing crypto'); return; } -var tls = require('tls'); +const tls = require('tls'); -var conn = tls.connect(common.PORT, common.fail); +const conn = tls.connect(common.PORT, common.fail); conn.on('error', common.mustCall(function() { assert.doesNotThrow(function() { conn.destroy(); diff --git a/test/parallel/test-tls-client-default-ciphers.js b/test/parallel/test-tls-client-default-ciphers.js index 33766dfd5b13b2..618178d4a497ad 100644 --- a/test/parallel/test-tls-client-default-ciphers.js +++ b/test/parallel/test-tls-client-default-ciphers.js @@ -1,17 +1,17 @@ 'use strict'; const common = require('../common'); -var assert = require('assert'); +const assert = require('assert'); if (!common.hasCrypto) { common.skip('missing crypto'); return; } -var tls = require('tls'); +const tls = require('tls'); function Done() {} function test1() { - var ciphers = ''; + let ciphers = ''; tls.createSecureContext = function(options) { ciphers = options.ciphers; diff --git a/test/parallel/test-tls-client-destroy-soon.js b/test/parallel/test-tls-client-destroy-soon.js index 171aa328142e13..016fcfa4da6a95 100644 --- a/test/parallel/test-tls-client-destroy-soon.js +++ b/test/parallel/test-tls-client-destroy-soon.js @@ -3,40 +3,40 @@ // Cache session and close connection. Use session on second connection. // ASSERT resumption. -var common = require('../common'); -var assert = require('assert'); +const common = require('../common'); +const assert = require('assert'); if (!common.hasCrypto) { common.skip('missing crypto'); return; } -var tls = require('tls'); +const tls = require('tls'); -var fs = require('fs'); +const fs = require('fs'); -var options = { +const options = { key: fs.readFileSync(common.fixturesDir + '/keys/agent2-key.pem'), cert: fs.readFileSync(common.fixturesDir + '/keys/agent2-cert.pem') }; -var big = Buffer.alloc(2 * 1024 * 1024, 'Y'); +const big = Buffer.alloc(2 * 1024 * 1024, 'Y'); // create server -var server = tls.createServer(options, common.mustCall(function(socket) { +const server = tls.createServer(options, common.mustCall(function(socket) { socket.end(big); socket.destroySoon(); })); // start listening server.listen(0, common.mustCall(function() { - var client = tls.connect({ + const client = tls.connect({ port: this.address().port, rejectUnauthorized: false }, common.mustCall(function() { - var bytesRead = 0; + let bytesRead = 0; client.on('readable', function() { - var d = client.read(); + const d = client.read(); if (d) bytesRead += d.length; }); diff --git a/test/parallel/test-tls-client-getephemeralkeyinfo.js b/test/parallel/test-tls-client-getephemeralkeyinfo.js index c1e6597245a612..fd7dca4b6b7076 100644 --- a/test/parallel/test-tls-client-getephemeralkeyinfo.js +++ b/test/parallel/test-tls-client-getephemeralkeyinfo.js @@ -12,27 +12,27 @@ const fs = require('fs'); const key = fs.readFileSync(common.fixturesDir + '/keys/agent2-key.pem'); const cert = fs.readFileSync(common.fixturesDir + '/keys/agent2-cert.pem'); -var ntests = 0; -var nsuccess = 0; +let ntests = 0; +let nsuccess = 0; function loadDHParam(n) { - var path = common.fixturesDir; + let path = common.fixturesDir; if (n !== 'error') path += '/keys'; return fs.readFileSync(path + '/dh' + n + '.pem'); } -var cipherlist = { +const cipherlist = { 'NOT_PFS': 'AES128-SHA256', 'DH': 'DHE-RSA-AES128-GCM-SHA256', 'ECDH': 'ECDHE-RSA-AES128-GCM-SHA256' }; function test(size, type, name, next) { - var cipher = type ? cipherlist[type] : cipherlist['NOT_PFS']; + const cipher = type ? cipherlist[type] : cipherlist['NOT_PFS']; if (name) tls.DEFAULT_ECDH_CURVE = name; - var options = { + const options = { key: key, cert: cert, ciphers: cipher @@ -40,7 +40,7 @@ function test(size, type, name, next) { if (type === 'DH') options.dhparam = loadDHParam(size); - var server = tls.createServer(options, function(conn) { + const server = tls.createServer(options, function(conn) { assert.strictEqual(conn.getEphemeralKeyInfo(), null); conn.end(); }); @@ -51,11 +51,11 @@ function test(size, type, name, next) { })); server.listen(0, '127.0.0.1', common.mustCall(function() { - var client = tls.connect({ + const client = tls.connect({ port: this.address().port, rejectUnauthorized: false }, function() { - var ekeyinfo = client.getEphemeralKeyInfo(); + const ekeyinfo = client.getEphemeralKeyInfo(); assert.strictEqual(ekeyinfo.type, type); assert.strictEqual(ekeyinfo.size, size); assert.strictEqual(ekeyinfo.name, name); diff --git a/test/parallel/test-tls-client-mindhsize.js b/test/parallel/test-tls-client-mindhsize.js index 1d812a72093ba9..76e1034621f031 100644 --- a/test/parallel/test-tls-client-mindhsize.js +++ b/test/parallel/test-tls-client-mindhsize.js @@ -1,35 +1,35 @@ 'use strict'; -var common = require('../common'); -var assert = require('assert'); +const common = require('../common'); +const assert = require('assert'); if (!common.hasCrypto) { common.skip('missing crypto'); process.exit(); } -var tls = require('tls'); +const tls = require('tls'); -var fs = require('fs'); -var key = fs.readFileSync(common.fixturesDir + '/keys/agent2-key.pem'); -var cert = fs.readFileSync(common.fixturesDir + '/keys/agent2-cert.pem'); +const fs = require('fs'); +const key = fs.readFileSync(common.fixturesDir + '/keys/agent2-key.pem'); +const cert = fs.readFileSync(common.fixturesDir + '/keys/agent2-cert.pem'); -var nsuccess = 0; -var nerror = 0; +let nsuccess = 0; +let nerror = 0; function loadDHParam(n) { - var path = common.fixturesDir; + let path = common.fixturesDir; if (n !== 'error') path += '/keys'; return fs.readFileSync(path + '/dh' + n + '.pem'); } function test(size, err, next) { - var options = { + const options = { key: key, cert: cert, dhparam: loadDHParam(size), ciphers: 'DHE-RSA-AES128-GCM-SHA256' }; - var server = tls.createServer(options, function(conn) { + const server = tls.createServer(options, function(conn) { conn.end(); }); @@ -42,7 +42,7 @@ function test(size, err, next) { // client set minimum DH parameter size to 2048 bits so that // it fails when it make a connection to the tls server where // dhparams is 1024 bits - var client = tls.connect({ + const client = tls.connect({ minDHSize: 2048, port: this.address().port, rejectUnauthorized: false diff --git a/test/parallel/test-tls-client-resume.js b/test/parallel/test-tls-client-resume.js index 75524a3a189b3e..96109d7656dd19 100644 --- a/test/parallel/test-tls-client-resume.js +++ b/test/parallel/test-tls-client-resume.js @@ -3,32 +3,32 @@ // Cache session and close connection. Use session on second connection. // ASSERT resumption. -var common = require('../common'); -var assert = require('assert'); +const common = require('../common'); +const assert = require('assert'); if (!common.hasCrypto) { common.skip('missing crypto'); return; } -var tls = require('tls'); +const tls = require('tls'); -var fs = require('fs'); +const fs = require('fs'); -var options = { +const options = { key: fs.readFileSync(common.fixturesDir + '/keys/agent2-key.pem'), cert: fs.readFileSync(common.fixturesDir + '/keys/agent2-cert.pem') }; // create server -var server = tls.Server(options, common.mustCall(function(socket) { +const server = tls.Server(options, common.mustCall(function(socket) { socket.end('Goodbye'); }, 2)); // start listening server.listen(0, function() { - var session1 = null; - var client1 = tls.connect({ + let session1 = null; + const client1 = tls.connect({ port: this.address().port, rejectUnauthorized: false }, function() { @@ -40,13 +40,13 @@ server.listen(0, function() { client1.on('close', function() { console.log('close1'); - var opts = { + const opts = { port: server.address().port, rejectUnauthorized: false, session: session1 }; - var client2 = tls.connect(opts, function() { + const client2 = tls.connect(opts, function() { console.log('connect2'); assert.ok(client2.isSessionReused(), 'Session *should* be reused.'); }); diff --git a/test/parallel/test-tls-client-verify.js b/test/parallel/test-tls-client-verify.js index a1fa35acf3c124..70d96ef1545ede 100644 --- a/test/parallel/test-tls-client-verify.js +++ b/test/parallel/test-tls-client-verify.js @@ -106,7 +106,7 @@ function testServers(index, servers, clientOptions, cb) { function runTest(testIndex) { - var tcase = testCases[testIndex]; + const tcase = testCases[testIndex]; if (!tcase) return; const clientOptions = { diff --git a/test/parallel/test-tls-close-error.js b/test/parallel/test-tls-close-error.js index 2da7a192c30ebc..6172be813e97ce 100644 --- a/test/parallel/test-tls-close-error.js +++ b/test/parallel/test-tls-close-error.js @@ -1,22 +1,22 @@ 'use strict'; const common = require('../common'); -var assert = require('assert'); +const assert = require('assert'); if (!common.hasCrypto) { common.skip('missing crypto'); return; } -var tls = require('tls'); +const tls = require('tls'); -var fs = require('fs'); +const fs = require('fs'); -var server = tls.createServer({ +const server = tls.createServer({ key: fs.readFileSync(common.fixturesDir + '/keys/agent1-key.pem'), cert: fs.readFileSync(common.fixturesDir + '/keys/agent1-cert.pem') }, function(c) { }).listen(0, common.mustCall(function() { - var c = tls.connect(this.address().port, function() { + const c = tls.connect(this.address().port, function() { assert(false, 'should not be called'); }); diff --git a/test/parallel/test-tls-close-notify.js b/test/parallel/test-tls-close-notify.js index 51b16746e30533..5d5bc1007749a7 100644 --- a/test/parallel/test-tls-close-notify.js +++ b/test/parallel/test-tls-close-notify.js @@ -1,15 +1,15 @@ 'use strict'; -var common = require('../common'); +const common = require('../common'); if (!common.hasCrypto) { common.skip('missing crypto'); return; } -var tls = require('tls'); +const tls = require('tls'); -var fs = require('fs'); +const fs = require('fs'); -var server = tls.createServer({ +const server = tls.createServer({ key: fs.readFileSync(common.fixturesDir + '/keys/agent1-key.pem'), cert: fs.readFileSync(common.fixturesDir + '/keys/agent1-cert.pem') }, function(c) { @@ -17,7 +17,7 @@ var server = tls.createServer({ if (c._handle.shutdownSSL() !== 1) c._handle.shutdownSSL(); }).listen(0, common.mustCall(function() { - var c = tls.connect(this.address().port, { + const c = tls.connect(this.address().port, { rejectUnauthorized: false }, common.mustCall(function() { // Ensure that we receive 'end' event anyway diff --git a/test/parallel/test-tls-connect-no-host.js b/test/parallel/test-tls-connect-no-host.js index e2e0238ff8d0ad..2e4bcfbc6d4787 100644 --- a/test/parallel/test-tls-connect-no-host.js +++ b/test/parallel/test-tls-connect-no-host.js @@ -1,18 +1,18 @@ 'use strict'; -var common = require('../common'); +const common = require('../common'); if (!common.hasCrypto) { common.skip('missing crypto'); return; } -var tls = require('tls'); +const tls = require('tls'); -var assert = require('assert'); -var fs = require('fs'); -var path = require('path'); +const assert = require('assert'); +const fs = require('fs'); +const path = require('path'); -var cert = fs.readFileSync(path.join(common.fixturesDir, 'test_cert.pem')); -var key = fs.readFileSync(path.join(common.fixturesDir, 'test_key.pem')); +const cert = fs.readFileSync(path.join(common.fixturesDir, 'test_cert.pem')); +const key = fs.readFileSync(path.join(common.fixturesDir, 'test_key.pem')); // https://github.com/nodejs/node/issues/1489 // tls.connect(options) with no options.host should accept a cert with @@ -21,7 +21,7 @@ tls.createServer({ key: key, cert: cert }).listen(0, function() { - var socket = tls.connect({ + const socket = tls.connect({ port: this.address().port, ca: cert, // No host set here. 'localhost' is the default, diff --git a/test/parallel/test-tls-connect-pipe.js b/test/parallel/test-tls-connect-pipe.js index 6ec218e00366f6..de60ae084624cf 100644 --- a/test/parallel/test-tls-connect-pipe.js +++ b/test/parallel/test-tls-connect-pipe.js @@ -1,27 +1,27 @@ 'use strict'; -var common = require('../common'); +const common = require('../common'); if (!common.hasCrypto) { common.skip('missing crypto'); return; } -var tls = require('tls'); +const tls = require('tls'); -var fs = require('fs'); +const fs = require('fs'); -var options = { +const options = { key: fs.readFileSync(common.fixturesDir + '/keys/agent1-key.pem'), cert: fs.readFileSync(common.fixturesDir + '/keys/agent1-cert.pem') }; common.refreshTmpDir(); -var server = tls.Server(options, common.mustCall(function(socket) { +const server = tls.Server(options, common.mustCall(function(socket) { server.close(); })); server.listen(common.PIPE, common.mustCall(function() { - var options = { rejectUnauthorized: false }; - var client = tls.connect(common.PIPE, options, common.mustCall(function() { + const options = { rejectUnauthorized: false }; + const client = tls.connect(common.PIPE, options, common.mustCall(function() { client.end(); })); })); diff --git a/test/parallel/test-tls-connect-stream-writes.js b/test/parallel/test-tls-connect-stream-writes.js index 8631ec575aae9b..2db130bc4b749e 100644 --- a/test/parallel/test-tls-connect-stream-writes.js +++ b/test/parallel/test-tls-connect-stream-writes.js @@ -6,34 +6,33 @@ const tls = require('tls'); const stream = require('stream'); const net = require('net'); -var server; -var cert_dir = common.fixturesDir; -var options = { key: fs.readFileSync(cert_dir + '/test_key.pem'), - cert: fs.readFileSync(cert_dir + '/test_cert.pem'), - ca: [ fs.readFileSync(cert_dir + '/test_ca.pem') ], - ciphers: 'AES256-GCM-SHA384' }; -var content = 'hello world'; -var recv_bufs = []; -var send_data = ''; -server = tls.createServer(options, function(s) { +const cert_dir = common.fixturesDir; +const options = { key: fs.readFileSync(cert_dir + '/test_key.pem'), + cert: fs.readFileSync(cert_dir + '/test_cert.pem'), + ca: [ fs.readFileSync(cert_dir + '/test_ca.pem') ], + ciphers: 'AES256-GCM-SHA384' }; +const content = 'hello world'; +const recv_bufs = []; +let send_data = ''; +const server = tls.createServer(options, function(s) { s.on('data', function(c) { recv_bufs.push(c); }); }); server.listen(0, function() { - var raw = net.connect(this.address().port); + const raw = net.connect(this.address().port); - var pending = false; + let pending = false; raw.on('readable', function() { if (pending) p._read(); }); - var p = new stream.Duplex({ + let p = new stream.Duplex({ read: function read() { pending = false; - var chunk = raw.read(); + const chunk = raw.read(); if (chunk) { this.push(chunk); } else { @@ -45,11 +44,11 @@ server.listen(0, function() { } }); - var socket = tls.connect({ + const socket = tls.connect({ socket: p, rejectUnauthorized: false }, function() { - for (var i = 0; i < 50; ++i) { + for (let i = 0; i < 50; ++i) { socket.write(content); send_data += content; } @@ -59,6 +58,6 @@ server.listen(0, function() { }); process.on('exit', function() { - var recv_data = (Buffer.concat(recv_bufs)).toString(); + const recv_data = (Buffer.concat(recv_bufs)).toString(); assert.strictEqual(send_data, recv_data); }); diff --git a/test/parallel/test-tls-connect.js b/test/parallel/test-tls-connect.js index cd4edd89f7b483..082e2e48a9dcc0 100644 --- a/test/parallel/test-tls-connect.js +++ b/test/parallel/test-tls-connect.js @@ -1,15 +1,15 @@ 'use strict'; -var common = require('../common'); -var assert = require('assert'); +const common = require('../common'); +const assert = require('assert'); if (!common.hasCrypto) { common.skip('missing crypto'); return; } -var tls = require('tls'); +const tls = require('tls'); -var fs = require('fs'); -var path = require('path'); +const fs = require('fs'); +const path = require('path'); // https://github.com/joyent/node/issues/1218 // uncatchable exception on TLS connection error diff --git a/test/parallel/test-tls-delayed-attach-error.js b/test/parallel/test-tls-delayed-attach-error.js index a5fa91383d7d75..47be3f201b463e 100644 --- a/test/parallel/test-tls-delayed-attach-error.js +++ b/test/parallel/test-tls-delayed-attach-error.js @@ -1,24 +1,24 @@ 'use strict'; -var common = require('../common'); +const common = require('../common'); if (!common.hasCrypto) { common.skip('missing crypto'); return; } -var tls = require('tls'); -var fs = require('fs'); -var net = require('net'); +const tls = require('tls'); +const fs = require('fs'); +const net = require('net'); -var bonkers = Buffer.alloc(1024, 42); +const bonkers = Buffer.alloc(1024, 42); -var options = { +const options = { key: fs.readFileSync(common.fixturesDir + '/keys/agent1-key.pem'), cert: fs.readFileSync(common.fixturesDir + '/keys/agent1-cert.pem') }; -var server = net.createServer(common.mustCall(function(c) { +const server = net.createServer(common.mustCall(function(c) { setTimeout(common.mustCall(function() { - var s = new tls.TLSSocket(c, { + const s = new tls.TLSSocket(c, { isServer: true, secureContext: tls.createSecureContext(options) }); @@ -31,7 +31,7 @@ var server = net.createServer(common.mustCall(function(c) { }); }), 200); })).listen(0, function() { - var c = net.connect({port: this.address().port}, function() { + const c = net.connect({port: this.address().port}, function() { c.write(bonkers); }); }); diff --git a/test/parallel/test-tls-delayed-attach.js b/test/parallel/test-tls-delayed-attach.js index b1e4beb2313c9a..d757ca756c3a09 100644 --- a/test/parallel/test-tls-delayed-attach.js +++ b/test/parallel/test-tls-delayed-attach.js @@ -1,27 +1,27 @@ 'use strict'; -var common = require('../common'); -var assert = require('assert'); +const common = require('../common'); +const assert = require('assert'); if (!common.hasCrypto) { common.skip('missing crypto'); return; } -var tls = require('tls'); +const tls = require('tls'); -var fs = require('fs'); -var net = require('net'); +const fs = require('fs'); +const net = require('net'); -var sent = 'hello world'; -var received = ''; +const sent = 'hello world'; +let received = ''; -var options = { +const options = { key: fs.readFileSync(common.fixturesDir + '/keys/agent1-key.pem'), cert: fs.readFileSync(common.fixturesDir + '/keys/agent1-cert.pem') }; -var server = net.createServer(function(c) { +const server = net.createServer(function(c) { setTimeout(function() { - var s = new tls.TLSSocket(c, { + const s = new tls.TLSSocket(c, { isServer: true, secureContext: tls.createSecureContext(options) }); @@ -36,7 +36,7 @@ var server = net.createServer(function(c) { }); }, 200); }).listen(0, function() { - var c = tls.connect(this.address().port, { + const c = tls.connect(this.address().port, { rejectUnauthorized: false }, function() { c.end(sent); diff --git a/test/parallel/test-tls-dhe.js b/test/parallel/test-tls-dhe.js index 92ab415e3ba0a6..34f403ffed3254 100644 --- a/test/parallel/test-tls-dhe.js +++ b/test/parallel/test-tls-dhe.js @@ -1,37 +1,37 @@ 'use strict'; -var common = require('../common'); -var assert = require('assert'); +const common = require('../common'); +const assert = require('assert'); if (!common.hasCrypto) { common.skip('missing crypto'); return; } -var tls = require('tls'); +const tls = require('tls'); -var spawn = require('child_process').spawn; -var fs = require('fs'); -var key = fs.readFileSync(common.fixturesDir + '/keys/agent2-key.pem'); -var cert = fs.readFileSync(common.fixturesDir + '/keys/agent2-cert.pem'); -var nsuccess = 0; -var ntests = 0; -var ciphers = 'DHE-RSA-AES128-SHA256:ECDHE-RSA-AES128-SHA256'; +const spawn = require('child_process').spawn; +const fs = require('fs'); +const key = fs.readFileSync(common.fixturesDir + '/keys/agent2-key.pem'); +const cert = fs.readFileSync(common.fixturesDir + '/keys/agent2-cert.pem'); +let nsuccess = 0; +let ntests = 0; +const ciphers = 'DHE-RSA-AES128-SHA256:ECDHE-RSA-AES128-SHA256'; function loadDHParam(n) { - var path = common.fixturesDir; + let path = common.fixturesDir; if (n !== 'error') path += '/keys'; return fs.readFileSync(path + '/dh' + n + '.pem'); } function test(keylen, expectedCipher, cb) { - var options = { + const options = { key: key, cert: cert, ciphers: ciphers, dhparam: loadDHParam(keylen) }; - var server = tls.createServer(options, function(conn) { + const server = tls.createServer(options, function(conn) { conn.end(); }); @@ -41,15 +41,15 @@ function test(keylen, expectedCipher, cb) { }); server.listen(0, '127.0.0.1', function() { - var args = ['s_client', '-connect', `127.0.0.1:${this.address().port}`, - '-cipher', ciphers]; + const args = ['s_client', '-connect', `127.0.0.1:${this.address().port}`, + '-cipher', ciphers]; // for the performance and stability issue in s_client on Windows if (common.isWindows) args.push('-no_rand_screen'); - var client = spawn(common.opensslCli, args); - var out = ''; + const client = spawn(common.opensslCli, args); + let out = ''; client.stdout.setEncoding('utf8'); client.stdout.on('data', function(d) { out += d; @@ -57,7 +57,7 @@ function test(keylen, expectedCipher, cb) { client.stdout.on('end', function() { // DHE key length can be checked -brief option in s_client but it // is only supported in openssl 1.0.2 so we cannot check it. - var reg = new RegExp('Cipher : ' + expectedCipher); + const reg = new RegExp('Cipher : ' + expectedCipher); if (reg.test(out)) { nsuccess++; server.close(); diff --git a/test/parallel/test-tls-ecdh-disable.js b/test/parallel/test-tls-ecdh-disable.js index c2a7440a686a10..a0555e87781f59 100644 --- a/test/parallel/test-tls-ecdh-disable.js +++ b/test/parallel/test-tls-ecdh-disable.js @@ -1,27 +1,27 @@ 'use strict'; -var common = require('../common'); -var assert = require('assert'); +const common = require('../common'); +const assert = require('assert'); if (!common.hasCrypto) { common.skip('missing crypto'); return; } -var tls = require('tls'); +const tls = require('tls'); -var exec = require('child_process').exec; -var fs = require('fs'); +const exec = require('child_process').exec; +const fs = require('fs'); -var options = { +const options = { key: fs.readFileSync(common.fixturesDir + '/keys/agent2-key.pem'), cert: fs.readFileSync(common.fixturesDir + '/keys/agent2-cert.pem'), ciphers: 'ECDHE-RSA-RC4-SHA', ecdhCurve: false }; -var server = tls.createServer(options, common.fail); +const server = tls.createServer(options, common.fail); server.listen(0, '127.0.0.1', common.mustCall(function() { - var cmd = '"' + common.opensslCli + '" s_client -cipher ' + options.ciphers + + let cmd = '"' + common.opensslCli + '" s_client -cipher ' + options.ciphers + ` -connect 127.0.0.1:${this.address().port}`; // for the performance and stability issue in s_client on Windows diff --git a/test/parallel/test-tls-econnreset.js b/test/parallel/test-tls-econnreset.js index d9f6fffd326409..0ec7264c4147e4 100644 --- a/test/parallel/test-tls-econnreset.js +++ b/test/parallel/test-tls-econnreset.js @@ -1,14 +1,14 @@ 'use strict'; -var common = require('../common'); -var assert = require('assert'); +const common = require('../common'); +const assert = require('assert'); if (!common.hasCrypto) { common.skip('missing crypto'); return; } -var tls = require('tls'); +const tls = require('tls'); -var cacert = +const cacert = `-----BEGIN CERTIFICATE----- MIIBxTCCAX8CAnXnMA0GCSqGSIb3DQEBBQUAMH0xCzAJBgNVBAYTAlVTMQswCQYD VQQIEwJDQTEWMBQGA1UEBxMNU2FuIEZyYW5jaXNjbzEZMBcGA1UEChMQU3Ryb25n @@ -22,7 +22,7 @@ AVkCAwEAATANBgkqhkiG9w0BAQUFAAMxALA1uS4CqQXRSAyYTfio5oyLGz71a+NM +0AFLBwh5AQjhGd0FcenU4OfHxyDEOJT/Q== -----END CERTIFICATE-----`; -var cert = +const cert = `-----BEGIN CERTIFICATE----- MIIBfDCCATYCAgQaMA0GCSqGSIb3DQEBBQUAMH0xCzAJBgNVBAYTAlVTMQswCQYD VQQIEwJDQTEWMBQGA1UEBxMNU2FuIEZyYW5jaXNjbzEZMBcGA1UEChMQU3Ryb25n @@ -34,7 +34,7 @@ AQABoxkwFzAVBgNVHREEDjAMhwQAAAAAhwR/AAABMA0GCSqGSIb3DQEBBQUAAzEA cGpYrhkrb7mIh9DNhV0qp7pGjqBzlHqB7KQXw2luLDp//6dyHBMexDCQznkhZKRU -----END CERTIFICATE-----`; -var key = +const key = `-----BEGIN RSA PRIVATE KEY----- MIH0AgEAAjEAx+QjQtZTXmk9TAhA0ydFWGE6JuLRNCYBq7wUG2DAR8YrTVal8ZRo mvVrjUrxSrvHAgMBAAECMBCGccvSwC2r8Z9Zh1JtirQVxaL1WWpAQfmVwLe0bAgg @@ -44,30 +44,31 @@ pQIZAMMwxuS3XiO7two2sQF6W+JTYyX1DPCwAQIZAOYg1TvEGT38k8e8jygv8E8w YqrWTeQFNQ== -----END RSA PRIVATE KEY-----`; -var ca = [ cert, cacert ]; +const ca = [ cert, cacert ]; -var clientError = null; -var connectError = null; +let clientError = null; +let connectError = null; -var server = tls.createServer({ ca: ca, cert: cert, key: key }, function(conn) { - throw 'unreachable'; -}).on('tlsClientError', function(err, conn) { - assert(!clientError && conn); - clientError = err; -}).listen(0, function() { - var options = { +const server = + tls.createServer({ ca: ca, cert: cert, key: key }, function(conn) { + throw 'unreachable'; + }).on('tlsClientError', function(err, conn) { + assert(!clientError && conn); + clientError = err; + }).listen(0, function() { + const options = { ciphers: 'AES128-GCM-SHA256', port: this.address().port, ca: ca - }; - tls.connect(options).on('error', function(err) { - assert(!connectError); + }; + tls.connect(options).on('error', function(err) { + assert(!connectError); - connectError = err; - this.destroy(); - server.close(); - }).write('123'); -}); + connectError = err; + this.destroy(); + server.close(); + }).write('123'); + }); process.on('exit', function() { assert(clientError); diff --git a/test/parallel/test-tls-env-bad-extra-ca.js b/test/parallel/test-tls-env-bad-extra-ca.js index 1862366e013af0..cb6c4ba489fcd6 100644 --- a/test/parallel/test-tls-env-bad-extra-ca.js +++ b/test/parallel/test-tls-env-bad-extra-ca.js @@ -22,11 +22,11 @@ const env = { NODE_EXTRA_CA_CERTS: common.fixturesDir + '/no-such-file-exists', }; -var opts = { +const opts = { env: env, silent: true, }; -var stderr = ''; +let stderr = ''; fork(__filename, opts) .on('exit', common.mustCall(function(status) { diff --git a/test/parallel/test-tls-fast-writing.js b/test/parallel/test-tls-fast-writing.js index 034a6296659bdd..b2d6fe6eee88a3 100644 --- a/test/parallel/test-tls-fast-writing.js +++ b/test/parallel/test-tls-fast-writing.js @@ -1,23 +1,23 @@ 'use strict'; -var common = require('../common'); -var assert = require('assert'); +const common = require('../common'); +const assert = require('assert'); if (!common.hasCrypto) { common.skip('missing crypto'); return; } -var tls = require('tls'); +const tls = require('tls'); -var fs = require('fs'); +const fs = require('fs'); -var dir = common.fixturesDir; -var options = { key: fs.readFileSync(dir + '/test_key.pem'), - cert: fs.readFileSync(dir + '/test_cert.pem'), - ca: [ fs.readFileSync(dir + '/test_ca.pem') ] }; +const dir = common.fixturesDir; +const options = { key: fs.readFileSync(dir + '/test_key.pem'), + cert: fs.readFileSync(dir + '/test_cert.pem'), + ca: [ fs.readFileSync(dir + '/test_ca.pem') ] }; -var server = tls.createServer(options, onconnection); -var gotChunk = false; -var gotDrain = false; +const server = tls.createServer(options, onconnection); +let gotChunk = false; +let gotDrain = false; setTimeout(function() { console.log('not ok - timed out'); @@ -41,9 +41,9 @@ function onconnection(conn) { } server.listen(0, function() { - var chunk = Buffer.alloc(1024, 'x'); - var opt = { port: this.address().port, rejectUnauthorized: false }; - var conn = tls.connect(opt, function() { + const chunk = Buffer.alloc(1024, 'x'); + const opt = { port: this.address().port, rejectUnauthorized: false }; + const conn = tls.connect(opt, function() { conn.on('drain', ondrain); write(); }); diff --git a/test/parallel/test-tls-friendly-error-message.js b/test/parallel/test-tls-friendly-error-message.js index 9ae69f4016e319..3f3bfe9133fcd6 100644 --- a/test/parallel/test-tls-friendly-error-message.js +++ b/test/parallel/test-tls-friendly-error-message.js @@ -17,7 +17,7 @@ tls.createServer({ key: key, cert: cert }, common.mustCall(function(conn) { conn.end(); this.close(); })).listen(0, common.mustCall(function() { - var options = { port: this.address().port, rejectUnauthorized: true }; + const options = { port: this.address().port, rejectUnauthorized: true }; tls.connect(options).on('error', common.mustCall(function(err) { assert.strictEqual(err.code, 'UNABLE_TO_VERIFY_LEAF_SIGNATURE'); assert.strictEqual(err.message, 'unable to verify the first certificate'); diff --git a/test/parallel/test-tls-handshake-error.js b/test/parallel/test-tls-handshake-error.js index e76a0961fb7ad6..39ea3a517247a0 100644 --- a/test/parallel/test-tls-handshake-error.js +++ b/test/parallel/test-tls-handshake-error.js @@ -1,23 +1,23 @@ 'use strict'; const common = require('../common'); -var assert = require('assert'); +const assert = require('assert'); if (!common.hasCrypto) { common.skip('missing crypto'); return; } -var tls = require('tls'); +const tls = require('tls'); -var fs = require('fs'); +const fs = require('fs'); -var server = tls.createServer({ +const server = tls.createServer({ key: fs.readFileSync(common.fixturesDir + '/keys/agent1-key.pem'), cert: fs.readFileSync(common.fixturesDir + '/keys/agent1-cert.pem'), rejectUnauthorized: true }, function(c) { }).listen(0, common.mustCall(function() { - var c = tls.connect({ + const c = tls.connect({ port: this.address().port, ciphers: 'RC4' }, function() { diff --git a/test/parallel/test-tls-handshake-nohang.js b/test/parallel/test-tls-handshake-nohang.js index 052833a50e3462..039c55b486d6a2 100644 --- a/test/parallel/test-tls-handshake-nohang.js +++ b/test/parallel/test-tls-handshake-nohang.js @@ -1,11 +1,11 @@ 'use strict'; -var common = require('../common'); +const common = require('../common'); if (!common.hasCrypto) { common.skip('missing crypto'); return; } -var tls = require('tls'); +const tls = require('tls'); // neither should hang tls.createSecurePair(null, false, false, false); diff --git a/test/parallel/test-tls-honorcipherorder.js b/test/parallel/test-tls-honorcipherorder.js index 81c2440fe26d23..f7894e46706da9 100644 --- a/test/parallel/test-tls-honorcipherorder.js +++ b/test/parallel/test-tls-honorcipherorder.js @@ -1,27 +1,27 @@ 'use strict'; -var common = require('../common'); -var assert = require('assert'); +const common = require('../common'); +const assert = require('assert'); if (!common.hasCrypto) { common.skip('missing crypto'); return; } -var tls = require('tls'); +const tls = require('tls'); -var fs = require('fs'); -var nconns = 0; +const fs = require('fs'); +let nconns = 0; // We explicitly set TLS version to 1.2 so as to be safe when the // default method is updated in the future -var SSL_Method = 'TLSv1_2_method'; -var localhost = '127.0.0.1'; +const SSL_Method = 'TLSv1_2_method'; +const localhost = '127.0.0.1'; process.on('exit', function() { assert.equal(nconns, 6); }); function test(honorCipherOrder, clientCipher, expectedCipher, cb) { - var soptions = { + const soptions = { secureProtocol: SSL_Method, key: fs.readFileSync(common.fixturesDir + '/keys/agent2-key.pem'), cert: fs.readFileSync(common.fixturesDir + '/keys/agent2-cert.pem'), @@ -30,7 +30,7 @@ function test(honorCipherOrder, clientCipher, expectedCipher, cb) { honorCipherOrder: !!honorCipherOrder }; - var server = tls.createServer(soptions, function(cleartextStream) { + const server = tls.createServer(soptions, function(cleartextStream) { nconns++; // End socket to send CLOSE_NOTIFY and TCP FIN packet, otherwise @@ -38,7 +38,7 @@ function test(honorCipherOrder, clientCipher, expectedCipher, cb) { cleartextStream.end(); }); server.listen(0, localhost, function() { - var coptions = { + const coptions = { rejectUnauthorized: false, secureProtocol: SSL_Method }; @@ -46,8 +46,8 @@ function test(honorCipherOrder, clientCipher, expectedCipher, cb) { coptions.ciphers = clientCipher; } const port = this.address().port; - var client = tls.connect(port, localhost, coptions, function() { - var cipher = client.getCipher(); + const client = tls.connect(port, localhost, coptions, function() { + const cipher = client.getCipher(); client.end(); server.close(); assert.equal(cipher.name, expectedCipher); diff --git a/test/parallel/test-tls-inception.js b/test/parallel/test-tls-inception.js index 760887d9f25264..183fbe587b366c 100644 --- a/test/parallel/test-tls-inception.js +++ b/test/parallel/test-tls-inception.js @@ -54,7 +54,7 @@ a.listen(0, function() { rejectUnauthorized: false }); ssl.setEncoding('utf8'); - var buf = ''; + let buf = ''; ssl.on('data', function(data) { buf += data; }); diff --git a/test/parallel/test-tls-invoke-queued.js b/test/parallel/test-tls-invoke-queued.js index 4008e5f099e4bc..bd3ad43fe653e5 100644 --- a/test/parallel/test-tls-invoke-queued.js +++ b/test/parallel/test-tls-invoke-queued.js @@ -1,19 +1,19 @@ 'use strict'; -var common = require('../common'); -var assert = require('assert'); +const common = require('../common'); +const assert = require('assert'); if (!common.hasCrypto) { common.skip('missing crypto'); return; } -var tls = require('tls'); +const tls = require('tls'); -var fs = require('fs'); +const fs = require('fs'); -var received = ''; +let received = ''; -var server = tls.createServer({ +const server = tls.createServer({ key: fs.readFileSync(common.fixturesDir + '/keys/agent1-key.pem'), cert: fs.readFileSync(common.fixturesDir + '/keys/agent1-cert.pem') }, function(c) { @@ -26,7 +26,7 @@ var server = tls.createServer({ server.close(); }).listen(0, common.mustCall(function() { - var c = tls.connect(this.address().port, { + const c = tls.connect(this.address().port, { rejectUnauthorized: false }, common.mustCall(function() { c.on('data', function(chunk) { diff --git a/test/parallel/test-tls-js-stream.js b/test/parallel/test-tls-js-stream.js index 08095fa99538cf..b8e14cb30ed8e6 100644 --- a/test/parallel/test-tls-js-stream.js +++ b/test/parallel/test-tls-js-stream.js @@ -1,23 +1,23 @@ 'use strict'; -var common = require('../common'); -var assert = require('assert'); +const common = require('../common'); +const assert = require('assert'); if (!common.hasCrypto) { common.skip('missing crypto'); return; } -var tls = require('tls'); +const tls = require('tls'); -var stream = require('stream'); -var fs = require('fs'); -var net = require('net'); +const stream = require('stream'); +const fs = require('fs'); +const net = require('net'); -var connected = { +const connected = { client: 0, server: 0 }; -var server = tls.createServer({ +const server = tls.createServer({ key: fs.readFileSync(common.fixturesDir + '/keys/agent1-key.pem'), cert: fs.readFileSync(common.fixturesDir + '/keys/agent1-cert.pem') }, function(c) { @@ -25,19 +25,19 @@ var server = tls.createServer({ connected.server++; c.end('ohai'); }).listen(0, function() { - var raw = net.connect(this.address().port); + const raw = net.connect(this.address().port); - var pending = false; + let pending = false; raw.on('readable', function() { if (pending) p._read(); }); - var p = new stream.Duplex({ + let p = new stream.Duplex({ read: function read() { pending = false; - var chunk = raw.read(); + const chunk = raw.read(); if (chunk) { console.log('read', chunk); this.push(chunk); @@ -51,7 +51,7 @@ var server = tls.createServer({ } }); - var socket = tls.connect({ + const socket = tls.connect({ socket: p, rejectUnauthorized: false }, function() { diff --git a/test/parallel/test-tls-legacy-onselect.js b/test/parallel/test-tls-legacy-onselect.js index 72c748248e448d..9af65c43a0661c 100644 --- a/test/parallel/test-tls-legacy-onselect.js +++ b/test/parallel/test-tls-legacy-onselect.js @@ -1,15 +1,15 @@ 'use strict'; -var common = require('../common'); +const common = require('../common'); if (!common.hasCrypto) { common.skip('missing crypto'); return; } -var tls = require('tls'); -var net = require('net'); +const tls = require('tls'); +const net = require('net'); -var server = net.Server(common.mustCall(function(raw) { - var pair = tls.createSecurePair(null, true, false, false); +const server = net.Server(common.mustCall(function(raw) { + const pair = tls.createSecurePair(null, true, false, false); pair.on('error', function() {}); pair.ssl.setSNICallback(common.mustCall(function() { raw.destroy(); diff --git a/test/parallel/test-tls-max-send-fragment.js b/test/parallel/test-tls-max-send-fragment.js index 64dd14698916c8..4b81be35e34522 100644 --- a/test/parallel/test-tls-max-send-fragment.js +++ b/test/parallel/test-tls-max-send-fragment.js @@ -1,20 +1,20 @@ 'use strict'; -var common = require('../common'); -var assert = require('assert'); +const common = require('../common'); +const assert = require('assert'); if (!common.hasCrypto) { common.skip('missing crypto'); return; } -var tls = require('tls'); +const tls = require('tls'); -var fs = require('fs'); +const fs = require('fs'); -var buf = Buffer.allocUnsafe(10000); -var received = 0; -var maxChunk = 768; +const buf = Buffer.allocUnsafe(10000); +let received = 0; +const maxChunk = 768; -var server = tls.createServer({ +const server = tls.createServer({ key: fs.readFileSync(common.fixturesDir + '/keys/agent1-key.pem'), cert: fs.readFileSync(common.fixturesDir + '/keys/agent1-cert.pem') }, function(c) { @@ -27,7 +27,7 @@ var server = tls.createServer({ c.end(buf); }).listen(0, common.mustCall(function() { - var c = tls.connect(this.address().port, { + const c = tls.connect(this.address().port, { rejectUnauthorized: false }, common.mustCall(function() { c.on('data', function(chunk) { diff --git a/test/parallel/test-tls-multi-key.js b/test/parallel/test-tls-multi-key.js index e29f5ee522829e..e3d5d661a799a7 100644 --- a/test/parallel/test-tls-multi-key.js +++ b/test/parallel/test-tls-multi-key.js @@ -1,15 +1,15 @@ 'use strict'; -var common = require('../common'); -var assert = require('assert'); +const common = require('../common'); +const assert = require('assert'); if (!common.hasCrypto) { common.skip('missing crypto'); return; } -var tls = require('tls'); -var fs = require('fs'); +const tls = require('tls'); +const fs = require('fs'); -var options = { +const options = { key: [ fs.readFileSync(common.fixturesDir + '/keys/ec-key.pem'), fs.readFileSync(common.fixturesDir + '/keys/agent1-key.pem'), @@ -20,17 +20,17 @@ var options = { ] }; -var ciphers = []; +const ciphers = []; -var server = tls.createServer(options, function(conn) { +const server = tls.createServer(options, function(conn) { conn.end('ok'); }).listen(0, function() { - var ecdsa = tls.connect(this.address().port, { + const ecdsa = tls.connect(this.address().port, { ciphers: 'ECDHE-ECDSA-AES256-GCM-SHA384', rejectUnauthorized: false }, function() { ciphers.push(ecdsa.getCipher()); - var rsa = tls.connect(server.address().port, { + const rsa = tls.connect(server.address().port, { ciphers: 'ECDHE-RSA-AES256-GCM-SHA384', rejectUnauthorized: false }, function() { diff --git a/test/parallel/test-tls-no-rsa-key.js b/test/parallel/test-tls-no-rsa-key.js index cc04534bf91973..233d8453db1318 100644 --- a/test/parallel/test-tls-no-rsa-key.js +++ b/test/parallel/test-tls-no-rsa-key.js @@ -1,24 +1,24 @@ 'use strict'; -var common = require('../common'); -var assert = require('assert'); +const common = require('../common'); +const assert = require('assert'); if (!common.hasCrypto) { common.skip('missing crypto'); return; } -var tls = require('tls'); +const tls = require('tls'); -var fs = require('fs'); +const fs = require('fs'); -var options = { +const options = { key: fs.readFileSync(common.fixturesDir + '/keys/ec-key.pem'), cert: fs.readFileSync(common.fixturesDir + '/keys/ec-cert.pem') }; -var server = tls.createServer(options, function(conn) { +const server = tls.createServer(options, function(conn) { conn.end('ok'); }).listen(0, common.mustCall(function() { - var c = tls.connect(this.address().port, { + const c = tls.connect(this.address().port, { rejectUnauthorized: false }, common.mustCall(function() { c.on('end', common.mustCall(function() { diff --git a/test/parallel/test-tls-no-sslv23.js b/test/parallel/test-tls-no-sslv23.js index 0db61afe0e97ec..ff1214d167e6a0 100644 --- a/test/parallel/test-tls-no-sslv23.js +++ b/test/parallel/test-tls-no-sslv23.js @@ -1,12 +1,12 @@ 'use strict'; -var common = require('../common'); -var assert = require('assert'); +const common = require('../common'); +const assert = require('assert'); if (!common.hasCrypto) { common.skip('missing crypto'); return; } -var tls = require('tls'); +const tls = require('tls'); assert.throws(function() { tls.createSecureContext({ secureProtocol: 'blargh' }); diff --git a/test/parallel/test-tls-npn-server-client.js b/test/parallel/test-tls-npn-server-client.js index c203d950051112..54d20cec6e78b8 100644 --- a/test/parallel/test-tls-npn-server-client.js +++ b/test/parallel/test-tls-npn-server-client.js @@ -13,7 +13,7 @@ if (!common.hasCrypto) { common.skip('missing crypto'); return; } -var tls = require('tls'); +const tls = require('tls'); function filenamePEM(n) { @@ -24,7 +24,7 @@ function loadPEM(n) { return fs.readFileSync(filenamePEM(n)); } -var serverOptions = { +const serverOptions = { key: loadPEM('agent2-key'), cert: loadPEM('agent2-cert'), crl: loadPEM('ca2-crl'), @@ -38,7 +38,7 @@ var serverOptions = { NPNProtocols: ['a', 'b', 'c'] }; -var clientsOptions = [{ +const clientsOptions = [{ port: undefined, key: serverOptions.key, cert: serverOptions.cert, @@ -70,7 +70,7 @@ var clientsOptions = [{ const serverResults = []; const clientsResults = []; -var server = tls.createServer(serverOptions, function(c) { +const server = tls.createServer(serverOptions, function(c) { serverResults.push(c.npnProtocol); }); server.listen(0, startTest); @@ -78,7 +78,7 @@ server.listen(0, startTest); function startTest() { function connectClient(options, callback) { options.port = server.address().port; - var client = tls.connect(options, function() { + const client = tls.connect(options, function() { clientsResults.push(client.npnProtocol); client.destroy(); diff --git a/test/parallel/test-tls-over-http-tunnel.js b/test/parallel/test-tls-over-http-tunnel.js index c030c7482ff6dd..4e03bcaf537f26 100644 --- a/test/parallel/test-tls-over-http-tunnel.js +++ b/test/parallel/test-tls-over-http-tunnel.js @@ -1,28 +1,28 @@ 'use strict'; -var common = require('../common'); -var assert = require('assert'); +const common = require('../common'); +const assert = require('assert'); if (!common.hasCrypto) { common.skip('missing crypto'); return; } -var https = require('https'); +const https = require('https'); -var fs = require('fs'); -var net = require('net'); -var http = require('http'); +const fs = require('fs'); +const net = require('net'); +const http = require('http'); -var gotRequest = false; +let gotRequest = false; -var key = fs.readFileSync(common.fixturesDir + '/keys/agent1-key.pem'); -var cert = fs.readFileSync(common.fixturesDir + '/keys/agent1-cert.pem'); +const key = fs.readFileSync(common.fixturesDir + '/keys/agent1-key.pem'); +const cert = fs.readFileSync(common.fixturesDir + '/keys/agent1-cert.pem'); -var options = { +const options = { key: key, cert: cert }; -var server = https.createServer(options, function(req, res) { +const server = https.createServer(options, function(req, res) { console.log('SERVER: got request'); res.writeHead(200, { 'content-type': 'text/plain' @@ -31,10 +31,10 @@ var server = https.createServer(options, function(req, res) { res.end('hello world\n'); }); -var proxy = net.createServer(function(clientSocket) { +const proxy = net.createServer(function(clientSocket) { console.log('PROXY: got a client connection'); - var serverSocket = null; + let serverSocket = null; clientSocket.on('data', function(chunk) { if (!serverSocket) { @@ -80,7 +80,7 @@ server.listen(0); proxy.listen(0, function() { console.log('CLIENT: Making CONNECT request'); - var req = http.request({ + const req = http.request({ port: this.address().port, method: 'CONNECT', path: `localhost:${server.address().port}`, diff --git a/test/parallel/test-tls-pause.js b/test/parallel/test-tls-pause.js index 7f4e02a1bfa96d..911ea7097b1e70 100644 --- a/test/parallel/test-tls-pause.js +++ b/test/parallel/test-tls-pause.js @@ -1,26 +1,26 @@ 'use strict'; -var common = require('../common'); -var assert = require('assert'); +const common = require('../common'); +const assert = require('assert'); if (!common.hasCrypto) { common.skip('missing crypto'); return; } -var tls = require('tls'); +const tls = require('tls'); -var fs = require('fs'); -var path = require('path'); +const fs = require('fs'); +const path = require('path'); -var options = { +const options = { key: fs.readFileSync(path.join(common.fixturesDir, 'test_key.pem')), cert: fs.readFileSync(path.join(common.fixturesDir, 'test_cert.pem')) }; -var bufSize = 1024 * 1024; -var sent = 0; -var received = 0; +const bufSize = 1024 * 1024; +let sent = 0; +let received = 0; -var server = tls.Server(options, function(socket) { +const server = tls.Server(options, function(socket) { socket.pipe(socket); socket.on('data', function(c) { console.error('data', c.length); @@ -28,8 +28,8 @@ var server = tls.Server(options, function(socket) { }); server.listen(0, function() { - var resumed = false; - var client = tls.connect({ + let resumed = false; + const client = tls.connect({ port: this.address().port, rejectUnauthorized: false }, function() { @@ -39,7 +39,7 @@ server.listen(0, function() { send(); function send() { console.error('sending'); - var ret = client.write(Buffer.allocUnsafe(bufSize)); + const ret = client.write(Buffer.allocUnsafe(bufSize)); console.error('write => %j', ret); if (false !== ret) { console.error('write again'); diff --git a/test/parallel/test-tls-peer-certificate-encoding.js b/test/parallel/test-tls-peer-certificate-encoding.js index b59d10faa78bc1..545caf403e103c 100644 --- a/test/parallel/test-tls-peer-certificate-encoding.js +++ b/test/parallel/test-tls-peer-certificate-encoding.js @@ -1,32 +1,32 @@ 'use strict'; -var common = require('../common'); -var assert = require('assert'); +const common = require('../common'); +const assert = require('assert'); if (!common.hasCrypto) { common.skip('missing crypto'); return; } -var tls = require('tls'); +const tls = require('tls'); -var fs = require('fs'); -var util = require('util'); -var join = require('path').join; +const fs = require('fs'); +const util = require('util'); +const join = require('path').join; -var options = { +const options = { key: fs.readFileSync(join(common.fixturesDir, 'keys', 'agent5-key.pem')), cert: fs.readFileSync(join(common.fixturesDir, 'keys', 'agent5-cert.pem')), ca: [ fs.readFileSync(join(common.fixturesDir, 'keys', 'ca2-cert.pem')) ] }; -var server = tls.createServer(options, function(cleartext) { +const server = tls.createServer(options, function(cleartext) { cleartext.end('World'); }); server.listen(0, common.mustCall(function() { - var socket = tls.connect({ + const socket = tls.connect({ port: this.address().port, rejectUnauthorized: false }, common.mustCall(function() { - var peerCert = socket.getPeerCertificate(); + const peerCert = socket.getPeerCertificate(); console.error(util.inspect(peerCert)); assert.equal(peerCert.subject.CN, 'Ádám Lippai'); diff --git a/test/parallel/test-tls-peer-certificate-multi-keys.js b/test/parallel/test-tls-peer-certificate-multi-keys.js index 55bc9f40d3a240..693bb4cb3fa812 100644 --- a/test/parallel/test-tls-peer-certificate-multi-keys.js +++ b/test/parallel/test-tls-peer-certificate-multi-keys.js @@ -1,31 +1,31 @@ 'use strict'; -var common = require('../common'); -var assert = require('assert'); +const common = require('../common'); +const assert = require('assert'); if (!common.hasCrypto) { common.skip('missing crypto'); return; } -var tls = require('tls'); +const tls = require('tls'); -var fs = require('fs'); -var util = require('util'); -var join = require('path').join; +const fs = require('fs'); +const util = require('util'); +const join = require('path').join; -var options = { +const options = { key: fs.readFileSync(join(common.fixturesDir, 'agent.key')), cert: fs.readFileSync(join(common.fixturesDir, 'multi-alice.crt')) }; -var server = tls.createServer(options, function(cleartext) { +const server = tls.createServer(options, function(cleartext) { cleartext.end('World'); }); server.listen(0, common.mustCall(function() { - var socket = tls.connect({ + const socket = tls.connect({ port: this.address().port, rejectUnauthorized: false }, common.mustCall(function() { - var peerCert = socket.getPeerCertificate(); + const peerCert = socket.getPeerCertificate(); console.error(util.inspect(peerCert)); assert.deepStrictEqual( peerCert.subject.OU, diff --git a/test/parallel/test-tls-pfx-gh-5100-regr.js b/test/parallel/test-tls-pfx-gh-5100-regr.js index 4670d9ea3da740..142a7de10b841a 100644 --- a/test/parallel/test-tls-pfx-gh-5100-regr.js +++ b/test/parallel/test-tls-pfx-gh-5100-regr.js @@ -28,7 +28,7 @@ const server = tls.createServer({ ); c.end(); })).listen(0, function() { - var client = tls.connect({ + const client = tls.connect({ port: this.address().port, pfx: pfx, passphrase: 'sample', diff --git a/test/parallel/test-tls-request-timeout.js b/test/parallel/test-tls-request-timeout.js index fc793def177f3a..4873a3c696458f 100644 --- a/test/parallel/test-tls-request-timeout.js +++ b/test/parallel/test-tls-request-timeout.js @@ -1,22 +1,22 @@ 'use strict'; -var common = require('../common'); -var assert = require('assert'); +const common = require('../common'); +const assert = require('assert'); if (!common.hasCrypto) { common.skip('missing crypto'); return; } -var tls = require('tls'); +const tls = require('tls'); -var fs = require('fs'); +const fs = require('fs'); -var options = { +const options = { key: fs.readFileSync(common.fixturesDir + '/keys/agent1-key.pem'), cert: fs.readFileSync(common.fixturesDir + '/keys/agent1-cert.pem') }; -var server = tls.Server(options, common.mustCall(function(socket) { - var s = socket.setTimeout(100); +const server = tls.Server(options, common.mustCall(function(socket) { + const s = socket.setTimeout(100); assert.ok(s instanceof tls.TLSSocket); socket.on('timeout', common.mustCall(function(err) { diff --git a/test/parallel/test-tls-securepair-fiftharg.js b/test/parallel/test-tls-securepair-fiftharg.js index b4610117889cc2..06b29b8736826d 100644 --- a/test/parallel/test-tls-securepair-fiftharg.js +++ b/test/parallel/test-tls-securepair-fiftharg.js @@ -10,7 +10,7 @@ const sslcontext = tls.createSecureContext({ key: fs.readFileSync(common.fixturesDir + '/test_key.pem') }); -var catchedServername; +let catchedServername; const pair = tls.createSecurePair(sslcontext, true, false, false, { SNICallback: common.mustCall(function(servername, cb) { catchedServername = servername; diff --git a/test/parallel/test-tls-securepair-server.js b/test/parallel/test-tls-securepair-server.js index 24ac2177c54536..65a7d91a0ca606 100644 --- a/test/parallel/test-tls-securepair-server.js +++ b/test/parallel/test-tls-securepair-server.js @@ -1,31 +1,31 @@ 'use strict'; -var common = require('../common'); -var assert = require('assert'); +const common = require('../common'); +const assert = require('assert'); if (!common.hasCrypto) { common.skip('missing crypto'); return; } -var tls = require('tls'); +const tls = require('tls'); -var join = require('path').join; -var net = require('net'); -var fs = require('fs'); -var spawn = require('child_process').spawn; +const join = require('path').join; +const net = require('net'); +const fs = require('fs'); +const spawn = require('child_process').spawn; -var key = fs.readFileSync(join(common.fixturesDir, 'agent.key')).toString(); -var cert = fs.readFileSync(join(common.fixturesDir, 'agent.crt')).toString(); +const key = fs.readFileSync(join(common.fixturesDir, 'agent.key')).toString(); +const cert = fs.readFileSync(join(common.fixturesDir, 'agent.crt')).toString(); function log(a) { console.error('***server*** ' + a); } -var server = net.createServer(common.mustCall(function(socket) { +const server = net.createServer(common.mustCall(function(socket) { log('connection fd=' + socket.fd); - var sslcontext = tls.createSecureContext({key: key, cert: cert}); + const sslcontext = tls.createSecureContext({key: key, cert: cert}); sslcontext.context.setCiphers('RC4-SHA:AES128-SHA:AES256-SHA'); - var pair = tls.createSecurePair(sslcontext, true); + const pair = tls.createSecurePair(sslcontext, true); assert.ok(pair.encrypted.writable); assert.ok(pair.cleartext.writable); @@ -84,23 +84,23 @@ var server = net.createServer(common.mustCall(function(socket) { }); })); -var gotHello = false; -var sentWorld = false; -var gotWorld = false; +let gotHello = false; +let sentWorld = false; +let gotWorld = false; server.listen(0, common.mustCall(function() { // To test use: openssl s_client -connect localhost:8000 - var args = ['s_client', '-connect', `127.0.0.1:${this.address().port}`]; + const args = ['s_client', '-connect', `127.0.0.1:${this.address().port}`]; // for the performance and stability issue in s_client on Windows if (common.isWindows) args.push('-no_rand_screen'); - var client = spawn(common.opensslCli, args); + const client = spawn(common.opensslCli, args); - var out = ''; + let out = ''; client.stdout.setEncoding('utf8'); client.stdout.on('data', function(d) { diff --git a/test/parallel/test-tls-session-cache.js b/test/parallel/test-tls-session-cache.js index 60a85701796d72..5e3ae5128ecfaf 100644 --- a/test/parallel/test-tls-session-cache.js +++ b/test/parallel/test-tls-session-cache.js @@ -34,9 +34,9 @@ function doTest(testOptions, callback) { ca: [cert], requestCert: true }; - var requestCount = 0; - var resumeCount = 0; - var session; + let requestCount = 0; + let resumeCount = 0; + let session; const server = tls.createServer(options, function(cleartext) { cleartext.on('error', function(er) { @@ -90,7 +90,7 @@ function doTest(testOptions, callback) { const client = spawn(common.opensslCli, args, { stdio: [ 0, 1, 'pipe' ] }); - var err = ''; + let err = ''; client.stderr.setEncoding('utf8'); client.stderr.on('data', function(chunk) { err += chunk; diff --git a/test/parallel/test-tls-set-ciphers.js b/test/parallel/test-tls-set-ciphers.js index 5a85e3b22e4c62..91eb1bea6e2f2f 100644 --- a/test/parallel/test-tls-set-ciphers.js +++ b/test/parallel/test-tls-set-ciphers.js @@ -34,7 +34,7 @@ const server = tls.createServer(options, common.mustCall(function(conn) { })); server.listen(0, '127.0.0.1', function() { - var cmd = '"' + common.opensslCli + '" s_client -cipher ' + options.ciphers + + let cmd = '"' + common.opensslCli + '" s_client -cipher ' + options.ciphers + ` -connect 127.0.0.1:${this.address().port}`; // for the performance and stability issue in s_client on Windows diff --git a/test/parallel/test-tls-sni-option.js b/test/parallel/test-tls-sni-option.js index 42d6a9068b00d5..f1613d2e9fbdce 100644 --- a/test/parallel/test-tls-sni-option.js +++ b/test/parallel/test-tls-sni-option.js @@ -13,7 +13,7 @@ if (!common.hasCrypto) { common.skip('missing crypto'); return; } -var tls = require('tls'); +const tls = require('tls'); function filenamePEM(n) { return require('path').join(common.fixturesDir, 'keys', n + '.pem'); @@ -23,13 +23,13 @@ function loadPEM(n) { return fs.readFileSync(filenamePEM(n)); } -var serverOptions = { +const serverOptions = { key: loadPEM('agent2-key'), cert: loadPEM('agent2-cert'), requestCert: true, rejectUnauthorized: false, SNICallback: function(servername, callback) { - var context = SNIContexts[servername]; + const context = SNIContexts[servername]; // Just to test asynchronous callback setTimeout(function() { @@ -45,7 +45,7 @@ var serverOptions = { } }; -var SNIContexts = { +let SNIContexts = { 'a.example.com': { key: loadPEM('agent1-key'), cert: loadPEM('agent1-cert'), @@ -60,7 +60,7 @@ var SNIContexts = { } }; -var clientsOptions = [{ +const clientsOptions = [{ port: undefined, key: loadPEM('agent1-key'), cert: loadPEM('agent1-cert'), @@ -104,7 +104,7 @@ const clientErrors = []; let serverError; let clientError; -var server = tls.createServer(serverOptions, function(c) { +const server = tls.createServer(serverOptions, function(c) { serverResults.push({ sni: c.servername, authorized: c.authorized }); }); @@ -117,12 +117,12 @@ server.listen(0, startTest); function startTest() { function connectClient(i, callback) { - var options = clientsOptions[i]; + const options = clientsOptions[i]; clientError = null; serverError = null; options.port = server.address().port; - var client = tls.connect(options, function() { + const client = tls.connect(options, function() { clientResults.push( /Hostname\/IP doesn't/.test(client.authorizationError || '')); client.destroy(); diff --git a/test/parallel/test-tls-sni-server-client.js b/test/parallel/test-tls-sni-server-client.js index e743078bca789e..dad4ef20619cc7 100644 --- a/test/parallel/test-tls-sni-server-client.js +++ b/test/parallel/test-tls-sni-server-client.js @@ -13,7 +13,7 @@ if (!common.hasCrypto) { common.skip('missing crypto'); return; } -var tls = require('tls'); +const tls = require('tls'); function filenamePEM(n) { return require('path').join(common.fixturesDir, 'keys', n + '.pem'); @@ -23,12 +23,12 @@ function loadPEM(n) { return fs.readFileSync(filenamePEM(n)); } -var serverOptions = { +const serverOptions = { key: loadPEM('agent2-key'), cert: loadPEM('agent2-cert') }; -var SNIContexts = { +const SNIContexts = { 'a.example.com': { key: loadPEM('agent1-key'), cert: loadPEM('agent1-cert') @@ -44,7 +44,7 @@ var SNIContexts = { } }; -var clientsOptions = [{ +const clientsOptions = [{ port: undefined, ca: [loadPEM('ca1-cert')], servername: 'a.example.com', @@ -74,7 +74,7 @@ var clientsOptions = [{ const serverResults = []; const clientResults = []; -var server = tls.createServer(serverOptions, function(c) { +const server = tls.createServer(serverOptions, function(c) { serverResults.push(c.servername); }); @@ -85,15 +85,15 @@ server.addContext('chain.example.com', SNIContexts['chain.example.com']); server.listen(0, startTest); function startTest() { - var i = 0; + let i = 0; function start() { // No options left if (i === clientsOptions.length) return server.close(); - var options = clientsOptions[i++]; + const options = clientsOptions[i++]; options.port = server.address().port; - var client = tls.connect(options, function() { + const client = tls.connect(options, function() { clientResults.push( client.authorizationError && /Hostname\/IP doesn't/.test(client.authorizationError)); diff --git a/test/parallel/test-tls-wrap-timeout.js b/test/parallel/test-tls-wrap-timeout.js index 0454242d92ecb6..d66e1f2d680f77 100644 --- a/test/parallel/test-tls-wrap-timeout.js +++ b/test/parallel/test-tls-wrap-timeout.js @@ -27,8 +27,8 @@ const server = tls.createServer(options, common.mustCall((c) => { }); })); -var socket; -var lastIdleStart; +let socket; +let lastIdleStart; server.listen(0, () => { socket = net.connect(server.address().port, function() { diff --git a/test/parallel/test-umask.js b/test/parallel/test-umask.js index 62f9d82b3312ef..1c870893a3bced 100644 --- a/test/parallel/test-umask.js +++ b/test/parallel/test-umask.js @@ -1,16 +1,16 @@ 'use strict'; -var common = require('../common'); -var assert = require('assert'); +const common = require('../common'); +const assert = require('assert'); // Note in Windows one can only set the "user" bits. -var mask; +let mask; if (common.isWindows) { mask = '0600'; } else { mask = '0664'; } -var old = process.umask(mask); +const old = process.umask(mask); assert.equal(parseInt(mask, 8), process.umask(old)); diff --git a/test/parallel/test-url.js b/test/parallel/test-url.js index 5a5fd476ebfb05..d8ee2127f946d3 100644 --- a/test/parallel/test-url.js +++ b/test/parallel/test-url.js @@ -1,13 +1,13 @@ /* eslint-disable max-len */ 'use strict'; require('../common'); -var assert = require('assert'); +const assert = require('assert'); -var url = require('url'); +const url = require('url'); // URLs to parse, and expected data // { url : parsed } -var parseTests = { +const parseTests = { '//some_path': { href: '//some_path', pathname: '//some_path', @@ -944,7 +944,7 @@ function check(actual, expected) { }); } -var parseTestsWithQueryString = { +const parseTestsWithQueryString = { '/foo/bar?baz=quux#frag': { href: '/foo/bar?baz=quux#frag', hash: '#frag', @@ -1015,7 +1015,7 @@ for (const u in parseTestsWithQueryString) { // some extra formatting tests, just to verify // that it'll format slightly wonky content to a valid url. -var formatTests = { +const formatTests = { 'http://example.com?': { href: 'http://example.com/?', protocol: 'http:', @@ -1244,7 +1244,7 @@ for (const u in formatTests) { /* [from, path, expected] */ -var relativeTests = [ +const relativeTests = [ ['/foo/bar/baz', 'quux', '/foo/bar/quux'], ['/foo/bar/baz', 'quux/asdf', '/foo/bar/quux/asdf'], ['/foo/bar/baz', 'quux/baz', '/foo/bar/quux/baz'], @@ -1323,7 +1323,7 @@ relativeTests.forEach(function(relativeTest) { // // Changes marked with @isaacs -var bases = [ +const bases = [ 'http://a/b/c/d;p?q', 'http://a/b/c/d;p?q=1/2', 'http://a/b/c/d;p=1/2?q', @@ -1332,7 +1332,7 @@ var bases = [ ]; //[to, from, result] -var relativeTests2 = [ +const relativeTests2 = [ // http://lists.w3.org/Archives/Public/uri/2004Feb/0114.html ['../c', 'foo:a/b', 'foo:c'], ['foo:.', 'foo:a', 'foo:'], @@ -1635,8 +1635,8 @@ relativeTests2.forEach(function(relativeTest) { //format: [from, path, expected] relativeTests.forEach(function(relativeTest) { - var actual = url.resolveObject(url.parse(relativeTest[0]), relativeTest[1]); - var expected = url.parse(relativeTest[2]); + let actual = url.resolveObject(url.parse(relativeTest[0]), relativeTest[1]); + let expected = url.parse(relativeTest[2]); assert.deepStrictEqual(actual, expected); @@ -1663,8 +1663,8 @@ if (relativeTests2[181][0] === './/g' && relativeTests2.splice(181, 1); } relativeTests2.forEach(function(relativeTest) { - var actual = url.resolveObject(url.parse(relativeTest[1]), relativeTest[0]); - var expected = url.parse(relativeTest[2]); + let actual = url.resolveObject(url.parse(relativeTest[1]), relativeTest[0]); + let expected = url.parse(relativeTest[2]); assert.deepStrictEqual(actual, expected); @@ -1678,7 +1678,7 @@ relativeTests2.forEach(function(relativeTest) { // https://github.com/nodejs/node/pull/1036 -var throws = [ +const throws = [ undefined, null, true, diff --git a/test/parallel/test-utf8-scripts.js b/test/parallel/test-utf8-scripts.js index 98c26594bb6540..484d3bdefe5eda 100644 --- a/test/parallel/test-utf8-scripts.js +++ b/test/parallel/test-utf8-scripts.js @@ -1,6 +1,6 @@ 'use strict'; require('../common'); -var assert = require('assert'); +const assert = require('assert'); // üäö diff --git a/test/parallel/test-util-inspect.js b/test/parallel/test-util-inspect.js index b0f89333d25a9b..af1f0fe9c3d6d0 100644 --- a/test/parallel/test-util-inspect.js +++ b/test/parallel/test-util-inspect.js @@ -233,7 +233,7 @@ assert.strictEqual(util.inspect({get readwrite() {}, set readwrite(val) {}}), assert.strictEqual(util.inspect({set writeonly(val) {}}), '{ writeonly: [Setter] }'); -var value = {}; +let value = {}; value['a'] = value; assert.strictEqual(util.inspect(value), '{ a: [Circular] }'); @@ -271,11 +271,11 @@ assert.strictEqual(util.inspect(value), '{ 2010-02-14T11:48:40.000Z aprop: 42 }' ); // test the internal isDate implementation -var Date2 = require('vm').runInNewContext('Date'); -var d = new Date2(); -var orig = util.inspect(d); +const Date2 = require('vm').runInNewContext('Date'); +const d = new Date2(); +const orig = util.inspect(d); Date2.prototype.foo = 'bar'; -var after = util.inspect(d); +const after = util.inspect(d); assert.strictEqual(orig, after); // test positive/negative zero @@ -283,7 +283,7 @@ assert.strictEqual(util.inspect(0), '0'); assert.strictEqual(util.inspect(-0), '-0'); // test for sparse array -var a = ['foo', 'bar', 'baz']; +const a = ['foo', 'bar', 'baz']; assert.strictEqual(util.inspect(a), '[ \'foo\', \'bar\', \'baz\' ]'); delete a[1]; assert.strictEqual(util.inspect(a), '[ \'foo\', , \'baz\' ]'); @@ -309,27 +309,27 @@ assert.strictEqual(util.inspect(new Array(5)), '[ , , , , ]'); } // test for other constructors in different context -var obj = require('vm').runInNewContext('(function(){return {}})()', {}); +let obj = require('vm').runInNewContext('(function(){return {}})()', {}); assert.strictEqual(util.inspect(obj), '{}'); -obj = require('vm').runInNewContext('var m=new Map();m.set(1,2);m', {}); +obj = require('vm').runInNewContext('let m=new Map();m.set(1,2);m', {}); assert.strictEqual(util.inspect(obj), 'Map { 1 => 2 }'); -obj = require('vm').runInNewContext('var s=new Set();s.add(1);s.add(2);s', {}); +obj = require('vm').runInNewContext('let s=new Set();s.add(1);s.add(2);s', {}); assert.strictEqual(util.inspect(obj), 'Set { 1, 2 }'); obj = require('vm').runInNewContext('fn=function(){};new Promise(fn,fn)', {}); assert.strictEqual(util.inspect(obj), 'Promise { }'); // test for property descriptors -var getter = Object.create(null, { +const getter = Object.create(null, { a: { get: function() { return 'aaa'; } } }); -var setter = Object.create(null, { +const setter = Object.create(null, { b: { set: function() {} } }); -var getterAndSetter = Object.create(null, { +const getterAndSetter = Object.create(null, { c: { get: function() { return 'ccc'; }, set: function() {} @@ -356,7 +356,7 @@ try { } catch (e) { assert.strictEqual(util.inspect(e), e.stack); } -var ex = util.inspect(new Error('FAIL'), true); +const ex = util.inspect(new Error('FAIL'), true); assert(ex.includes('Error: FAIL')); assert(ex.includes('[stack]')); assert(ex.includes('[message]')); @@ -380,19 +380,19 @@ assert.strictEqual(util.inspect(Object.create(Date.prototype)), 'Date {}'); // GH-1944 assert.doesNotThrow(function() { - var d = new Date(); + const d = new Date(); d.toUTCString = null; util.inspect(d); }); assert.doesNotThrow(function() { - var d = new Date(); + const d = new Date(); d.toISOString = null; util.inspect(d); }); assert.doesNotThrow(function() { - var r = /regexp/; + const r = /regexp/; r.toString = null; util.inspect(r); }); @@ -411,14 +411,14 @@ assert.doesNotThrow(function() { } // util.inspect should not display the escaped value of a key. -var w = { +const w = { '\\': 1, '\\\\': 2, '\\\\\\': 3, '\\\\\\\\': 4, }; -var y = ['a', 'b', 'c']; +const y = ['a', 'b', 'c']; y['\\\\\\'] = 'd'; assert.strictEqual( @@ -432,15 +432,15 @@ assert.strictEqual( // util.inspect.styles and util.inspect.colors function test_color_style(style, input, implicit) { - var color_name = util.inspect.styles[style]; - var color = ['', '']; + const color_name = util.inspect.styles[style]; + let color = ['', '']; if (util.inspect.colors[color_name]) color = util.inspect.colors[color_name]; - var without_color = util.inspect(input, false, 0, false); - var with_color = util.inspect(input, false, 0, true); - var expect = '\u001b[' + color[0] + 'm' + without_color + - '\u001b[' + color[1] + 'm'; + const without_color = util.inspect(input, false, 0, false); + const with_color = util.inspect(input, false, 0, true); + const expect = '\u001b[' + color[0] + 'm' + without_color + + '\u001b[' + color[1] + 'm'; assert.strictEqual( with_color, expect, @@ -593,19 +593,19 @@ assert.doesNotThrow(function() { // util.inspect with "colors" option should produce as many lines as without it function test_lines(input) { - var count_lines = function(str) { + const count_lines = function(str) { return (str.match(/\n/g) || []).length; }; - var without_color = util.inspect(input); - var with_color = util.inspect(input, {colors: true}); + const without_color = util.inspect(input); + const with_color = util.inspect(input, {colors: true}); assert.strictEqual(count_lines(without_color), count_lines(with_color)); } test_lines([1, 2, 3, 4, 5, 6, 7]); test_lines(function() { - var big_array = []; - for (var i = 0; i < 100; i++) { + const big_array = []; + for (let i = 0; i < 100; i++) { big_array.push(i); } return big_array; @@ -633,15 +633,15 @@ assert.strictEqual(util.inspect(new Number(-1.1)), '[Number: -1.1]'); assert.strictEqual(util.inspect(new Number(13.37)), '[Number: 13.37]'); // test boxed primitives with own properties -var str = new String('baz'); +const str = new String('baz'); str.foo = 'bar'; assert.strictEqual(util.inspect(str), '{ [String: \'baz\'] foo: \'bar\' }'); -var bool = new Boolean(true); +const bool = new Boolean(true); bool.foo = 'bar'; assert.strictEqual(util.inspect(bool), '{ [Boolean: true] foo: \'bar\' }'); -var num = new Number(13.37); +const num = new Number(13.37); num.foo = 'bar'; assert.strictEqual(util.inspect(num), '{ [Number: 13.37] foo: \'bar\' }'); @@ -675,7 +675,7 @@ if (typeof Symbol !== 'undefined') { // test Set assert.strictEqual(util.inspect(new Set()), 'Set {}'); assert.strictEqual(util.inspect(new Set([1, 2, 3])), 'Set { 1, 2, 3 }'); -var set = new Set(['foo']); +const set = new Set(['foo']); set.bar = 42; assert.strictEqual( util.inspect(set, true), @@ -707,30 +707,30 @@ assert.strictEqual( util.inspect(new Promise(function() {})), 'Promise { }' ); -var promise = Promise.resolve('foo'); +const promise = Promise.resolve('foo'); promise.bar = 42; assert.strictEqual(util.inspect(promise), 'Promise { \'foo\', bar: 42 }'); // Make sure it doesn't choke on polyfills. Unlike Set/Map, there is no standard // interface to synchronously inspect a Promise, so our techniques only work on // a bonafide native Promise. -var oldPromise = Promise; +const oldPromise = Promise; global.Promise = function() { this.bar = 42; }; assert.strictEqual(util.inspect(new Promise()), '{ bar: 42 }'); global.Promise = oldPromise; // Map/Set Iterators -var m = new Map([['foo', 'bar']]); +const m = new Map([['foo', 'bar']]); assert.strictEqual(util.inspect(m.keys()), 'MapIterator { \'foo\' }'); assert.strictEqual(util.inspect(m.values()), 'MapIterator { \'bar\' }'); assert.strictEqual(util.inspect(m.entries()), 'MapIterator { [ \'foo\', \'bar\' ] }'); // make sure the iterator doesn't get consumed -var keys = m.keys(); +let keys = m.keys(); assert.strictEqual(util.inspect(keys), 'MapIterator { \'foo\' }'); assert.strictEqual(util.inspect(keys), 'MapIterator { \'foo\' }'); -var s = new Set([1, 3]); +const s = new Set([1, 3]); assert.strictEqual(util.inspect(s.keys()), 'SetIterator { 1, 3 }'); assert.strictEqual(util.inspect(s.values()), 'SetIterator { 1, 3 }'); assert.strictEqual(util.inspect(s.entries()), @@ -744,10 +744,10 @@ assert.strictEqual(util.inspect(keys), 'SetIterator { 1, 3 }'); // Assumes that the first numeric character is the start of an item. function checkAlignment(container) { - var lines = util.inspect(container).split('\n'); - var pos; + const lines = util.inspect(container).split('\n'); + let pos; lines.forEach(function(line) { - var npos = line.search(/\d/); + const npos = line.search(/\d/); if (npos !== -1) { if (pos !== undefined) assert.strictEqual(pos, npos, 'container items not aligned'); @@ -756,14 +756,14 @@ function checkAlignment(container) { }); } -var big_array = []; -for (var i = 0; i < 100; i++) { +const big_array = []; +for (let i = 0; i < 100; i++) { big_array.push(i); } checkAlignment(big_array); checkAlignment(function() { - var obj = {}; + const obj = {}; big_array.forEach(function(v) { obj[v] = null; }); diff --git a/test/parallel/test-util-log.js b/test/parallel/test-util-log.js index 91f77d994da847..d45ebf2fc0b729 100644 --- a/test/parallel/test-util-log.js +++ b/test/parallel/test-util-log.js @@ -1,19 +1,19 @@ 'use strict'; require('../common'); -var assert = require('assert'); -var util = require('util'); +const assert = require('assert'); +const util = require('util'); assert.ok(process.stdout.writable); assert.ok(process.stderr.writable); -var stdout_write = global.process.stdout.write; -var strings = []; +const stdout_write = global.process.stdout.write; +const strings = []; global.process.stdout.write = function(string) { strings.push(string); }; console._stderr = process.stdout; -var tests = [ +const tests = [ {input: 'foo', output: 'foo'}, {input: undefined, output: 'undefined'}, {input: null, output: 'null'}, diff --git a/test/parallel/test-v8-flag-type-check.js b/test/parallel/test-v8-flag-type-check.js index 986f37314d605f..b5d4d7c2f12665 100644 --- a/test/parallel/test-v8-flag-type-check.js +++ b/test/parallel/test-v8-flag-type-check.js @@ -1,7 +1,7 @@ 'use strict'; require('../common'); -var assert = require('assert'); -var v8 = require('v8'); +const assert = require('assert'); +const v8 = require('v8'); assert.throws(function() { v8.setFlagsFromString(1); }, TypeError); assert.throws(function() { v8.setFlagsFromString(); }, TypeError); diff --git a/test/parallel/test-v8-flags.js b/test/parallel/test-v8-flags.js index 50cff9ecefceac..99384080516bb2 100644 --- a/test/parallel/test-v8-flags.js +++ b/test/parallel/test-v8-flags.js @@ -1,8 +1,8 @@ 'use strict'; require('../common'); -var assert = require('assert'); -var v8 = require('v8'); -var vm = require('vm'); +const assert = require('assert'); +const v8 = require('v8'); +const vm = require('vm'); // Note: changing V8 flags after an isolate started is not guaranteed to work. // Specifically here, V8 may cache compiled scripts between the flip of the diff --git a/test/parallel/test-v8-stats.js b/test/parallel/test-v8-stats.js index b4e16ad90009a8..5187432484846b 100644 --- a/test/parallel/test-v8-stats.js +++ b/test/parallel/test-v8-stats.js @@ -1,10 +1,10 @@ 'use strict'; require('../common'); -var assert = require('assert'); -var v8 = require('v8'); +const assert = require('assert'); +const v8 = require('v8'); -var s = v8.getHeapStatistics(); -var keys = [ +const s = v8.getHeapStatistics(); +const keys = [ 'heap_size_limit', 'total_available_size', 'total_heap_size', diff --git a/test/parallel/test-vm-basic.js b/test/parallel/test-vm-basic.js index b2b280c21bd173..2d57cc0d4ba328 100644 --- a/test/parallel/test-vm-basic.js +++ b/test/parallel/test-vm-basic.js @@ -1,11 +1,11 @@ 'use strict'; require('../common'); -var assert = require('assert'); -var vm = require('vm'); +const assert = require('assert'); +const vm = require('vm'); // Test 1: vm.runInNewContext -var sandbox = {}; -var result = vm.runInNewContext( +const sandbox = {}; +let result = vm.runInNewContext( 'foo = "bar"; this.typeofProcess = typeof process; typeof Object;', sandbox ); @@ -16,8 +16,8 @@ assert.deepStrictEqual(sandbox, { assert.strictEqual(result, 'function'); // Test 2: vm.runInContext -var sandbox2 = { foo: 'bar' }; -var context = vm.createContext(sandbox2); +const sandbox2 = { foo: 'bar' }; +const context = vm.createContext(sandbox2); result = vm.runInContext( 'baz = foo; this.typeofProcess = typeof process; typeof Object;', context @@ -45,6 +45,6 @@ assert.strictEqual(global.vmResult, undefined); assert.strictEqual(result, 'undefined'); // Test 5: vm.createContext -var sandbox3 = {}; -var context2 = vm.createContext(sandbox3); +const sandbox3 = {}; +const context2 = vm.createContext(sandbox3); assert.strictEqual(sandbox3, context2); diff --git a/test/parallel/test-vm-context-async-script.js b/test/parallel/test-vm-context-async-script.js index b09eda85209807..1e9ed629fb114f 100644 --- a/test/parallel/test-vm-context-async-script.js +++ b/test/parallel/test-vm-context-async-script.js @@ -1,11 +1,11 @@ 'use strict'; require('../common'); -var assert = require('assert'); -var vm = require('vm'); +const assert = require('assert'); +const vm = require('vm'); -var sandbox = { setTimeout: setTimeout }; +const sandbox = { setTimeout: setTimeout }; -var ctx = vm.createContext(sandbox); +const ctx = vm.createContext(sandbox); vm.runInContext('setTimeout(function() { x = 3; }, 0);', ctx); setTimeout(function() { diff --git a/test/parallel/test-vm-context-property-forwarding.js b/test/parallel/test-vm-context-property-forwarding.js index 4034441615ca9e..b77fc45217039f 100644 --- a/test/parallel/test-vm-context-property-forwarding.js +++ b/test/parallel/test-vm-context-property-forwarding.js @@ -1,11 +1,11 @@ 'use strict'; require('../common'); -var assert = require('assert'); -var vm = require('vm'); +const assert = require('assert'); +const vm = require('vm'); -var sandbox = { x: 3 }; +const sandbox = { x: 3 }; -var ctx = vm.createContext(sandbox); +const ctx = vm.createContext(sandbox); assert.strictEqual(vm.runInContext('x;', ctx), 3); vm.runInContext('y = 4;', ctx); diff --git a/test/parallel/test-vm-context.js b/test/parallel/test-vm-context.js index 659a092eb3e6c0..933d975c2c5542 100644 --- a/test/parallel/test-vm-context.js +++ b/test/parallel/test-vm-context.js @@ -1,14 +1,14 @@ 'use strict'; require('../common'); -var assert = require('assert'); +const assert = require('assert'); -var vm = require('vm'); -var Script = vm.Script; -var script = new Script('"passed";'); +const vm = require('vm'); +const Script = vm.Script; +let script = new Script('"passed";'); console.error('run in a new empty context'); -var context = vm.createContext(); -var result = script.runInContext(context); +let context = vm.createContext(); +let result = script.runInContext(context); assert.equal('passed', result); console.error('create a new pre-populated context'); @@ -29,7 +29,7 @@ assert.throws(function() { // Issue GH-1140: console.error('test runInContext signature'); -var gh1140Exception; +let gh1140Exception; try { vm.runInContext('throw new Error()', context, 'expected-filename.js'); } catch (e) { @@ -55,7 +55,7 @@ script.runInNewContext({ require: require }); // Issue GH-7529 script = vm.createScript('delete b'); -var ctx = {}; +let ctx = {}; Object.defineProperty(ctx, 'b', { configurable: false }); ctx = vm.createContext(ctx); assert.equal(script.runInContext(ctx), false); diff --git a/test/parallel/test-vm-create-and-run-in-context.js b/test/parallel/test-vm-create-and-run-in-context.js index fc92cf2f6cb6eb..a0026102b578f8 100644 --- a/test/parallel/test-vm-create-and-run-in-context.js +++ b/test/parallel/test-vm-create-and-run-in-context.js @@ -1,13 +1,13 @@ 'use strict'; // Flags: --expose-gc require('../common'); -var assert = require('assert'); +const assert = require('assert'); -var vm = require('vm'); +const vm = require('vm'); console.error('run in a new empty context'); -var context = vm.createContext(); -var result = vm.runInContext('"passed";', context); +let context = vm.createContext(); +let result = vm.runInContext('"passed";', context); assert.equal('passed', result); console.error('create a new pre-populated context'); @@ -22,7 +22,7 @@ assert.equal('lala', context.thing); // https://github.com/nodejs/node/issues/5768 console.error('run in contextified sandbox without referencing the context'); -var sandbox = {x: 1}; +const sandbox = {x: 1}; vm.createContext(sandbox); global.gc(); vm.runInContext('x = 2', sandbox); diff --git a/test/parallel/test-vm-create-context-accessors.js b/test/parallel/test-vm-create-context-accessors.js index 497bab1a57225f..27d7e6d7fc0274 100644 --- a/test/parallel/test-vm-create-context-accessors.js +++ b/test/parallel/test-vm-create-context-accessors.js @@ -1,9 +1,9 @@ 'use strict'; require('../common'); -var assert = require('assert'); -var vm = require('vm'); +const assert = require('assert'); +const vm = require('vm'); -var ctx = {}; +let ctx = {}; Object.defineProperty(ctx, 'getter', { get: function() { @@ -11,7 +11,7 @@ Object.defineProperty(ctx, 'getter', { } }); -var val; +let val; Object.defineProperty(ctx, 'setter', { set: function(_val) { val = _val; @@ -23,6 +23,6 @@ Object.defineProperty(ctx, 'setter', { ctx = vm.createContext(ctx); -var result = vm.runInContext('setter = "test";[getter,setter]', ctx); +const result = vm.runInContext('setter = "test";[getter,setter]', ctx); assert.strictEqual(result[0], 'ok'); assert.strictEqual(result[1], 'ok=test'); diff --git a/test/parallel/test-vm-create-context-arg.js b/test/parallel/test-vm-create-context-arg.js index a0c29762330133..91bbbc3b7793bc 100644 --- a/test/parallel/test-vm-create-context-arg.js +++ b/test/parallel/test-vm-create-context-arg.js @@ -1,7 +1,7 @@ 'use strict'; require('../common'); -var assert = require('assert'); -var vm = require('vm'); +const assert = require('assert'); +const vm = require('vm'); assert.throws(function() { vm.createContext('string is not supported'); @@ -13,7 +13,7 @@ assert.doesNotThrow(function() { }); assert.doesNotThrow(function() { - var sandbox = {}; + const sandbox = {}; vm.createContext(sandbox); vm.createContext(sandbox); }); diff --git a/test/parallel/test-vm-create-context-circular-reference.js b/test/parallel/test-vm-create-context-circular-reference.js index 248ef24f69ca07..13680c4c4e11ef 100644 --- a/test/parallel/test-vm-create-context-circular-reference.js +++ b/test/parallel/test-vm-create-context-circular-reference.js @@ -1,9 +1,9 @@ 'use strict'; require('../common'); -var assert = require('assert'); -var vm = require('vm'); +const assert = require('assert'); +const vm = require('vm'); -var sbx = {}; +let sbx = {}; sbx.window = sbx; sbx = vm.createContext(sbx); diff --git a/test/parallel/test-vm-cross-context.js b/test/parallel/test-vm-cross-context.js index 5674f582426f1f..bafb32accb6a0e 100644 --- a/test/parallel/test-vm-cross-context.js +++ b/test/parallel/test-vm-cross-context.js @@ -1,9 +1,9 @@ 'use strict'; require('../common'); -var assert = require('assert'); +const assert = require('assert'); -var vm = require('vm'); -var ctx = vm.createContext(global); +const vm = require('vm'); +const ctx = vm.createContext(global); assert.doesNotThrow(function() { vm.runInContext('!function() { var x = console.log; }()', ctx); diff --git a/test/parallel/test-vm-function-declaration.js b/test/parallel/test-vm-function-declaration.js index fd41be7564aab0..9f27723a0421a9 100644 --- a/test/parallel/test-vm-function-declaration.js +++ b/test/parallel/test-vm-function-declaration.js @@ -1,12 +1,12 @@ 'use strict'; require('../common'); -var assert = require('assert'); +const assert = require('assert'); -var vm = require('vm'); -var o = vm.createContext({ console: console }); +const vm = require('vm'); +const o = vm.createContext({ console: console }); // This triggers the setter callback in node_contextify.cc -var code = 'var a = function() {};\n'; +let code = 'var a = function() {};\n'; // but this does not, since function decls are defineProperties, // not simple sets. @@ -16,7 +16,7 @@ code += 'function b(){}\n'; // we are getting the global function, and not some other thing code += '(function(){return this})().b;\n'; -var res = vm.runInContext(code, o, 'test'); +const res = vm.runInContext(code, o, 'test'); assert.equal(typeof res, 'function', 'result should be function'); assert.equal(res.name, 'b', 'res should be named b'); diff --git a/test/parallel/test-vm-global-define-property.js b/test/parallel/test-vm-global-define-property.js index 73d1520e0dad69..62a714615ddc31 100644 --- a/test/parallel/test-vm-global-define-property.js +++ b/test/parallel/test-vm-global-define-property.js @@ -1,10 +1,10 @@ 'use strict'; require('../common'); -var assert = require('assert'); +const assert = require('assert'); -var vm = require('vm'); +const vm = require('vm'); -var code = +const code = 'Object.defineProperty(this, "f", {\n' + ' get: function() { return x; },\n' + ' set: function(k) { x = k; },\n' + @@ -14,10 +14,10 @@ var code = 'g = f;\n' + 'f;\n'; -var x = {}; -var o = vm.createContext({ console: console, x: x }); +const x = {}; +const o = vm.createContext({ console: console, x: x }); -var res = vm.runInContext(code, o, 'test'); +const res = vm.runInContext(code, o, 'test'); assert(res); assert.equal(typeof res, 'object'); diff --git a/test/parallel/test-vm-global-identity.js b/test/parallel/test-vm-global-identity.js index 7d90408b64c2c7..ae9fd71b3109ee 100644 --- a/test/parallel/test-vm-global-identity.js +++ b/test/parallel/test-vm-global-identity.js @@ -1,11 +1,11 @@ 'use strict'; require('../common'); -var assert = require('assert'); -var vm = require('vm'); +const assert = require('assert'); +const vm = require('vm'); -var ctx = vm.createContext(); +const ctx = vm.createContext(); ctx.window = ctx; -var thisVal = vm.runInContext('this;', ctx); -var windowVal = vm.runInContext('window;', ctx); +const thisVal = vm.runInContext('this;', ctx); +const windowVal = vm.runInContext('window;', ctx); assert.strictEqual(thisVal, windowVal); diff --git a/test/parallel/test-vm-harmony-symbols.js b/test/parallel/test-vm-harmony-symbols.js index 1c1274ef3543f6..80c1a2127f918c 100644 --- a/test/parallel/test-vm-harmony-symbols.js +++ b/test/parallel/test-vm-harmony-symbols.js @@ -1,10 +1,10 @@ 'use strict'; require('../common'); -var assert = require('assert'); -var vm = require('vm'); +const assert = require('assert'); +const vm = require('vm'); // The sandbox should have its own Symbol constructor. -var sandbox = {}; +let sandbox = {}; vm.runInNewContext('this.Symbol = Symbol', sandbox); assert.strictEqual(typeof sandbox.Symbol, 'function'); assert.notStrictEqual(sandbox.Symbol, Symbol); diff --git a/test/parallel/test-vm-is-context.js b/test/parallel/test-vm-is-context.js index cc106a15fbfc61..e58b896fccaa43 100644 --- a/test/parallel/test-vm-is-context.js +++ b/test/parallel/test-vm-is-context.js @@ -1,7 +1,7 @@ 'use strict'; require('../common'); -var assert = require('assert'); -var vm = require('vm'); +const assert = require('assert'); +const vm = require('vm'); assert.throws(function() { vm.isContext('string is not supported'); @@ -13,6 +13,6 @@ assert.strictEqual(vm.isContext([]), false); assert.strictEqual(vm.isContext(vm.createContext()), true); assert.strictEqual(vm.isContext(vm.createContext([])), true); -var sandbox = { foo: 'bar' }; +const sandbox = { foo: 'bar' }; vm.createContext(sandbox); assert.strictEqual(vm.isContext(sandbox), true); diff --git a/test/parallel/test-vm-new-script-new-context.js b/test/parallel/test-vm-new-script-new-context.js index 2af8f05f1c5236..a02627668f6db7 100644 --- a/test/parallel/test-vm-new-script-new-context.js +++ b/test/parallel/test-vm-new-script-new-context.js @@ -6,7 +6,7 @@ const Script = require('vm').Script; common.globalCheck = false; console.error('run a string'); -var script = new Script('\'passed\';'); +let script = new Script('\'passed\';'); console.error('script created'); const result1 = script.runInNewContext(); const result2 = script.runInNewContext(); @@ -41,7 +41,7 @@ global.foo = 2; global.obj = { foo: 0, baz: 3 }; script = new Script(global.code); /* eslint-disable no-unused-vars */ -var baz = script.runInNewContext(global.obj); +const baz = script.runInNewContext(global.obj); /* eslint-enable no-unused-vars */ assert.equal(1, global.obj.foo); assert.equal(2, global.obj.bar); @@ -55,7 +55,7 @@ assert.equal(global.foo, 100); console.error('modify an object by reference'); script = new Script('f.a = 2'); -var f = { a: 1 }; +const f = { a: 1 }; script.runInNewContext({ f: f }); assert.equal(f.a, 2); diff --git a/test/parallel/test-vm-new-script-this-context.js b/test/parallel/test-vm-new-script-this-context.js index d225fb0d4025d0..fb7e2719855174 100644 --- a/test/parallel/test-vm-new-script-this-context.js +++ b/test/parallel/test-vm-new-script-this-context.js @@ -6,7 +6,7 @@ const Script = require('vm').Script; common.globalCheck = false; console.error('run a string'); -var script = new Script('\'passed\';'); +let script = new Script('\'passed\';'); const result = script.runInThisContext(script); assert.equal('passed', result); diff --git a/test/parallel/test-vm-proxies.js b/test/parallel/test-vm-proxies.js index d908d713748f7f..25e16e8f5ccc55 100644 --- a/test/parallel/test-vm-proxies.js +++ b/test/parallel/test-vm-proxies.js @@ -1,12 +1,12 @@ 'use strict'; require('../common'); -var assert = require('assert'); -var vm = require('vm'); +const assert = require('assert'); +const vm = require('vm'); // src/node_contextify.cc filters out the Proxy object from the parent // context. Make sure that the new context has a Proxy object of its own. -var sandbox = {}; +let sandbox = {}; vm.runInNewContext('this.Proxy = Proxy', sandbox); assert.strictEqual(typeof sandbox.Proxy, 'function'); assert.notStrictEqual(sandbox.Proxy, Proxy); diff --git a/test/parallel/test-vm-run-in-new-context.js b/test/parallel/test-vm-run-in-new-context.js index 956e02306d4fb8..b00e5a973e0d25 100644 --- a/test/parallel/test-vm-run-in-new-context.js +++ b/test/parallel/test-vm-run-in-new-context.js @@ -30,7 +30,7 @@ global.code = 'foo = 1;' + global.foo = 2; global.obj = { foo: 0, baz: 3 }; /* eslint-disable no-unused-vars */ -var baz = vm.runInNewContext(global.code, global.obj); +const baz = vm.runInNewContext(global.code, global.obj); /* eslint-enable no-unused-vars */ assert.equal(1, global.obj.foo); assert.equal(2, global.obj.bar); @@ -42,12 +42,12 @@ vm.runInNewContext('f()', { f: changeFoo }); assert.equal(global.foo, 100); console.error('modify an object by reference'); -var f = { a: 1 }; +const f = { a: 1 }; vm.runInNewContext('f.a = 2', { f: f }); assert.equal(f.a, 2); console.error('use function in context without referencing context'); -var fn = vm.runInNewContext('(function() { obj.p = {}; })', { obj: {} }); +const fn = vm.runInNewContext('(function() { obj.p = {}; })', { obj: {} }); global.gc(); fn(); // Should not crash diff --git a/test/parallel/test-vm-static-this.js b/test/parallel/test-vm-static-this.js index c4f10c183b6ef2..8968f52d1b6f19 100644 --- a/test/parallel/test-vm-static-this.js +++ b/test/parallel/test-vm-static-this.js @@ -1,12 +1,12 @@ /* eslint-disable strict */ -var common = require('../common'); -var assert = require('assert'); -var vm = require('vm'); +const common = require('../common'); +const assert = require('assert'); +const vm = require('vm'); common.globalCheck = false; // Run a string -var result = vm.runInThisContext('\'passed\';'); +const result = vm.runInThisContext('\'passed\';'); assert.strictEqual('passed', result); // thrown error @@ -20,13 +20,14 @@ assert.strictEqual(2, global.hello); // pass values -var code = 'foo = 1;' + - 'bar = 2;' + - 'if (typeof baz !== \'undefined\') throw new Error(\'test fail\');'; +const code = 'foo = 1;' + + 'bar = 2;' + + 'if (typeof baz !== \'undefined\') ' + + 'throw new Error(\'test fail\');'; global.foo = 2; global.obj = { foo: 0, baz: 3 }; /* eslint-disable no-unused-vars */ -var baz = vm.runInThisContext(code); +const baz = vm.runInThisContext(code); /* eslint-enable no-unused-vars */ assert.strictEqual(0, global.obj.foo); assert.strictEqual(2, global.bar); diff --git a/test/parallel/test-vm-syntax-error-message.js b/test/parallel/test-vm-syntax-error-message.js index 75748b24e193ee..1a97393d6d97a7 100644 --- a/test/parallel/test-vm-syntax-error-message.js +++ b/test/parallel/test-vm-syntax-error-message.js @@ -1,9 +1,9 @@ 'use strict'; require('../common'); -var assert = require('assert'); -var child_process = require('child_process'); +const assert = require('assert'); +const child_process = require('child_process'); -var p = child_process.spawn(process.execPath, [ +const p = child_process.spawn(process.execPath, [ '-e', 'vm = require("vm");' + 'context = vm.createContext({});' + @@ -15,7 +15,7 @@ p.stderr.on('data', function(data) { assert(false, 'Unexpected stderr data: ' + data); }); -var output = ''; +let output = ''; p.stdout.on('data', function(data) { output += data; diff --git a/test/parallel/test-vm-timeout.js b/test/parallel/test-vm-timeout.js index 0536ae37a1b489..5260ca7dc28572 100644 --- a/test/parallel/test-vm-timeout.js +++ b/test/parallel/test-vm-timeout.js @@ -1,7 +1,7 @@ 'use strict'; require('../common'); -var assert = require('assert'); -var vm = require('vm'); +const assert = require('assert'); +const vm = require('vm'); // Test 1: Timeout of 100ms executing endless loop assert.throws(function() { @@ -23,7 +23,7 @@ vm.runInThisContext('', { timeout: 1000 }); // Test 5: Nested vm timeouts, inner timeout propagates out assert.throws(function() { - var context = { + const context = { log: console.log, runInVM: function(timeout) { vm.runInNewContext('while(true) {}', context, { timeout: timeout }); diff --git a/test/parallel/test-writedouble.js b/test/parallel/test-writedouble.js index 107bf521342ef3..935f9e7ae08ffd 100644 --- a/test/parallel/test-writedouble.js +++ b/test/parallel/test-writedouble.js @@ -6,7 +6,7 @@ require('../common'); const assert = require('assert'); function test(clazz) { - var buffer = new clazz(16); + const buffer = new clazz(16); buffer.writeDoubleBE(2.225073858507201e-308, 0); buffer.writeDoubleLE(2.225073858507201e-308, 8); diff --git a/test/parallel/test-writefloat.js b/test/parallel/test-writefloat.js index 2f76dd57c7b077..113e97c6d333b7 100644 --- a/test/parallel/test-writefloat.js +++ b/test/parallel/test-writefloat.js @@ -6,7 +6,7 @@ require('../common'); const assert = require('assert'); function test(clazz) { - var buffer = new clazz(8); + const buffer = new clazz(8); buffer.writeFloatBE(1, 0); buffer.writeFloatLE(1, 4); diff --git a/test/parallel/test-writeint.js b/test/parallel/test-writeint.js index 9fce2bc410e1be..838b1ce4798b75 100644 --- a/test/parallel/test-writeint.js +++ b/test/parallel/test-writeint.js @@ -7,7 +7,7 @@ const assert = require('assert'); const errorOutOfBounds = /^TypeError: "value" argument is out of bounds$/; function test8(clazz) { - var buffer = new clazz(2); + const buffer = new clazz(2); buffer.writeInt8(0x23, 0); buffer.writeInt8(-5, 1); @@ -39,7 +39,7 @@ function test8(clazz) { function test16(clazz) { - var buffer = new clazz(6); + const buffer = new clazz(6); buffer.writeInt16BE(0x0023, 0); buffer.writeInt16LE(0x0023, 2); @@ -92,7 +92,7 @@ function test16(clazz) { function test32(clazz) { - var buffer = new clazz(8); + const buffer = new clazz(8); buffer.writeInt32BE(0x23, 0); buffer.writeInt32LE(0x23, 4); diff --git a/test/parallel/test-writeuint.js b/test/parallel/test-writeuint.js index 0cccd4bc150436..bddb954d248633 100644 --- a/test/parallel/test-writeuint.js +++ b/test/parallel/test-writeuint.js @@ -13,7 +13,7 @@ const assert = require('assert'); * - Correctly interpreting values that are beyond the signed range as unsigned */ function test8(clazz) { - var data = new clazz(4); + const data = new clazz(4); data.writeUInt8(23, 0); data.writeUInt8(23, 1); @@ -42,8 +42,8 @@ function test8(clazz) { function test16(clazz) { - var value = 0x2343; - var data = new clazz(4); + let value = 0x2343; + const data = new clazz(4); data.writeUInt16BE(value, 0); assert.equal(0x23, data[0]); @@ -81,8 +81,8 @@ function test16(clazz) { function test32(clazz) { - var data = new clazz(6); - var value = 0xe7f90a6d; + const data = new clazz(6); + const value = 0xe7f90a6d; data.writeUInt32BE(value, 0); assert.equal(0xe7, data[0]); @@ -124,10 +124,10 @@ function test32(clazz) { function testUint(clazz) { const data = new clazz(8); - var val = 1; + let val = 1; // Test 0 to 5 bytes. - for (var i = 0; i <= 5; i++) { + for (let i = 0; i <= 5; i++) { const errmsg = `byteLength: ${i}`; assert.throws(function() { data.writeUIntBE(val, 0, i); diff --git a/test/parallel/test-zerolengthbufferbug.js b/test/parallel/test-zerolengthbufferbug.js index 056fc725ff5593..42e6994e1b6389 100644 --- a/test/parallel/test-zerolengthbufferbug.js +++ b/test/parallel/test-zerolengthbufferbug.js @@ -2,10 +2,10 @@ // Serving up a zero-length buffer should work. const common = require('../common'); -var http = require('http'); +const http = require('http'); -var server = http.createServer(function(req, res) { - var buffer = Buffer.alloc(0); +const server = http.createServer(function(req, res) { + const buffer = Buffer.alloc(0); // FIXME: WTF gjslint want this? res.writeHead(200, {'Content-Type': 'text/html', 'Content-Length': buffer.length}); diff --git a/test/parallel/test-zlib-convenience-methods.js b/test/parallel/test-zlib-convenience-methods.js index 3aac0142b55d66..b67b65d7d0b689 100644 --- a/test/parallel/test-zlib-convenience-methods.js +++ b/test/parallel/test-zlib-convenience-methods.js @@ -5,7 +5,7 @@ require('../common'); const assert = require('assert'); const zlib = require('zlib'); -var hadRun = 0; +let hadRun = 0; const expect = 'blahblahblahblahblahblah'; const opts = { @@ -38,7 +38,7 @@ const opts = { }); }); - var result = zlib[method[0] + 'Sync'](expect, opts); + let result = zlib[method[0] + 'Sync'](expect, opts); result = zlib[method[1] + 'Sync'](result, opts); assert.equal(result, expect, 'Should get original string after ' + diff --git a/test/parallel/test-zlib-flush-drain.js b/test/parallel/test-zlib-flush-drain.js index 45cca584858322..afa4194ac6d453 100644 --- a/test/parallel/test-zlib-flush-drain.js +++ b/test/parallel/test-zlib-flush-drain.js @@ -13,8 +13,8 @@ const opts = { const deflater = zlib.createDeflate(opts); // shim deflater.flush so we can count times executed -var flushCount = 0; -var drainCount = 0; +let flushCount = 0; +let drainCount = 0; const flush = deflater.flush; deflater.flush = function(kind, callback) { @@ -26,7 +26,7 @@ deflater.write(bigData); const ws = deflater._writableState; const beforeFlush = ws.needDrain; -var afterFlush = ws.needDrain; +let afterFlush = ws.needDrain; deflater.flush(function(err) { afterFlush = ws.needDrain; diff --git a/test/parallel/test-zlib-flush.js b/test/parallel/test-zlib-flush.js index abaa9ed2953d49..f4f8d75dee3ec0 100644 --- a/test/parallel/test-zlib-flush.js +++ b/test/parallel/test-zlib-flush.js @@ -22,7 +22,8 @@ deflater.write(chunk, function() { deflater.flush(zlib.Z_NO_FLUSH, function() { actualNone = deflater.read(); deflater.flush(function() { - var bufs = [], buf; + const bufs = []; + let buf; while (buf = deflater.read()) bufs.push(buf); actualFull = Buffer.concat(bufs); diff --git a/test/parallel/test-zlib-from-gzip.js b/test/parallel/test-zlib-from-gzip.js index 3739d8f9b48b28..3c7e96cef92a0a 100644 --- a/test/parallel/test-zlib-from-gzip.js +++ b/test/parallel/test-zlib-from-gzip.js @@ -24,7 +24,7 @@ inp.pipe(gunzip).pipe(out); out.on('close', function() { const actual = fs.readFileSync(outputFile); assert.equal(actual.length, expect.length, 'length should match'); - for (var i = 0, l = actual.length; i < l; i++) { + for (let i = 0, l = actual.length; i < l; i++) { assert.equal(actual[i], expect[i], 'byte[' + i + ']'); } }); diff --git a/test/parallel/test-zlib-from-string.js b/test/parallel/test-zlib-from-string.js index f3b8426eb4d862..0f885ac80ecbe6 100644 --- a/test/parallel/test-zlib-from-string.js +++ b/test/parallel/test-zlib-from-string.js @@ -51,7 +51,7 @@ zlib.gzip(inputString, function(err, buffer) { }); }); -var buffer = Buffer.from(expectedBase64Deflate, 'base64'); +let buffer = Buffer.from(expectedBase64Deflate, 'base64'); zlib.unzip(buffer, function(err, buffer) { assert.equal(buffer.toString(), inputString, 'decoded inflated string should match'); diff --git a/test/parallel/test-zlib-invalid-input.js b/test/parallel/test-zlib-invalid-input.js index eb9cd334c11b84..7b0e1fcaae8ce6 100644 --- a/test/parallel/test-zlib-invalid-input.js +++ b/test/parallel/test-zlib-invalid-input.js @@ -24,7 +24,7 @@ const unzips = [ zlib.Unzip(), zlib.Gunzip(), zlib.Inflate(), zlib.InflateRaw() ]; -var hadError = []; +const hadError = []; unzips.forEach(function(uz, i) { console.error('Error for ' + uz.constructor.name); uz.on('error', function(er) { diff --git a/test/parallel/test-zlib-params.js b/test/parallel/test-zlib-params.js index fc5888b32ac60d..93e06ea1b7c083 100644 --- a/test/parallel/test-zlib-params.js +++ b/test/parallel/test-zlib-params.js @@ -21,7 +21,7 @@ deflater.write(chunk1, function() { while (deflater.read()); deflater.end(chunk2, function() { const bufs = []; - var buf; + let buf; while (buf = deflater.read()) bufs.push(buf); actual = Buffer.concat(bufs); diff --git a/test/parallel/test-zlib-random-byte-pipes.js b/test/parallel/test-zlib-random-byte-pipes.js index 6037703f7bf2ca..83855ebd1f2c0a 100644 --- a/test/parallel/test-zlib-random-byte-pipes.js +++ b/test/parallel/test-zlib-random-byte-pipes.js @@ -72,14 +72,14 @@ RandomReadStream.prototype._process = function() { // figure out how many bytes to output // if finished, then just emit end. - var block = this._opt.block; + let block = this._opt.block; const jitter = this._opt.jitter; if (jitter) { block += Math.ceil(Math.random() * jitter - (jitter / 2)); } block = Math.min(block, this._remaining); const buf = Buffer.allocUnsafe(block); - for (var i = 0; i < block; i++) { + for (let i = 0; i < block; i++) { buf[i] = Math.random() * 256; } @@ -129,10 +129,10 @@ HashStream.prototype.end = function(c) { }; -var inp = new RandomReadStream({ total: 1024, block: 256, jitter: 16 }); -var out = new HashStream(); -var gzip = zlib.createGzip(); -var gunz = zlib.createGunzip(); +const inp = new RandomReadStream({ total: 1024, block: 256, jitter: 16 }); +const out = new HashStream(); +const gzip = zlib.createGzip(); +const gunz = zlib.createGunzip(); inp.pipe(gzip).pipe(gunz).pipe(out); diff --git a/test/parallel/test-zlib-write-after-flush.js b/test/parallel/test-zlib-write-after-flush.js index 9409558a3dee69..f5ad7c6f0e5c91 100644 --- a/test/parallel/test-zlib-write-after-flush.js +++ b/test/parallel/test-zlib-write-after-flush.js @@ -8,7 +8,7 @@ const gunz = zlib.createUnzip(); gzip.pipe(gunz); -var output = ''; +let output = ''; const input = 'A line of data\n'; gunz.setEncoding('utf8'); gunz.on('data', function(c) { diff --git a/test/parallel/test-zlib-zero-byte.js b/test/parallel/test-zlib-zero-byte.js index ca58d06ff272ba..cd4cf41f98ac07 100644 --- a/test/parallel/test-zlib-zero-byte.js +++ b/test/parallel/test-zlib-zero-byte.js @@ -5,7 +5,7 @@ const assert = require('assert'); const zlib = require('zlib'); const gz = zlib.Gzip(); const emptyBuffer = Buffer.alloc(0); -var received = 0; +let received = 0; gz.on('data', function(c) { received += c.length; }); diff --git a/test/parallel/test-zlib.js b/test/parallel/test-zlib.js index 54a4bc473631a0..fdd5d0a9400f25 100644 --- a/test/parallel/test-zlib.js +++ b/test/parallel/test-zlib.js @@ -7,7 +7,7 @@ const fs = require('fs'); const util = require('util'); const stream = require('stream'); -var zlibPairs = [ +let zlibPairs = [ [zlib.Deflate, zlib.Inflate], [zlib.Gzip, zlib.Gunzip], [zlib.Deflate, zlib.Unzip], @@ -16,18 +16,18 @@ var zlibPairs = [ ]; // how fast to trickle through the slowstream -var trickle = [128, 1024, 1024 * 1024]; +let trickle = [128, 1024, 1024 * 1024]; // tunable options for zlib classes. // several different chunk sizes -var chunkSize = [128, 1024, 1024 * 16, 1024 * 1024]; +let chunkSize = [128, 1024, 1024 * 16, 1024 * 1024]; // this is every possible value. -var level = [-1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9]; -var windowBits = [8, 9, 10, 11, 12, 13, 14, 15]; -var memLevel = [1, 2, 3, 4, 5, 6, 7, 8, 9]; -var strategy = [0, 1, 2, 3, 4]; +let level = [-1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9]; +let windowBits = [8, 9, 10, 11, 12, 13, 14, 15]; +let memLevel = [1, 2, 3, 4, 5, 6, 7, 8, 9]; +let strategy = [0, 1, 2, 3, 4]; // it's nice in theory to test every combination, but it // takes WAY too long. Maybe a pummel test could do this? @@ -40,7 +40,7 @@ if (!process.env.PUMMEL) { strategy = [0]; } -var testFiles = ['person.jpg', 'elipses.txt', 'empty.txt']; +let testFiles = ['person.jpg', 'elipses.txt', 'empty.txt']; if (process.env.FAST) { zlibPairs = [[zlib.Gzip, zlib.Unzip]]; @@ -72,8 +72,8 @@ BufferStream.prototype.write = function(c) { BufferStream.prototype.end = function(c) { if (c) this.write(c); // flatten - var buf = Buffer.allocUnsafe(this.length); - var i = 0; + const buf = Buffer.allocUnsafe(this.length); + let i = 0; this.chunks.forEach(function(c) { c.copy(buf, i); i += c.length; @@ -108,8 +108,8 @@ SlowStream.prototype.resume = function() { this.ended = true; return this.emit('end'); } - var end = Math.min(this.offset + this.trickle, this.length); - var c = this.chunk.slice(this.offset, end); + const end = Math.min(this.offset + this.trickle, this.length); + const c = this.chunk.slice(this.offset, end); this.offset += c.length; this.emit('data', c); process.nextTick(emit); @@ -134,12 +134,12 @@ SlowStream.prototype.end = function(chunk) { // for each of the files, make sure that compressing and // decompressing results in the same data, for every combination // of the options set above. -var failures = 0; -var total = 0; -var done = 0; +let failures = 0; +let total = 0; +let done = 0; Object.keys(tests).forEach(function(file) { - var test = tests[file]; + const test = tests[file]; chunkSize.forEach(function(chunkSize) { trickle.forEach(function(trickle) { windowBits.forEach(function(windowBits) { @@ -147,29 +147,30 @@ Object.keys(tests).forEach(function(file) { memLevel.forEach(function(memLevel) { strategy.forEach(function(strategy) { zlibPairs.forEach(function(pair) { - var Def = pair[0]; - var Inf = pair[1]; - var opts = { level: level, - windowBits: windowBits, - memLevel: memLevel, - strategy: strategy }; + const Def = pair[0]; + const Inf = pair[1]; + const opts = { level: level, + windowBits: windowBits, + memLevel: memLevel, + strategy: strategy }; total++; - var def = new Def(opts); - var inf = new Inf(opts); - var ss = new SlowStream(trickle); - var buf = new BufferStream(); + const def = new Def(opts); + const inf = new Inf(opts); + const ss = new SlowStream(trickle); + const buf = new BufferStream(); // verify that the same exact buffer comes out the other end. buf.on('data', function(c) { - var msg = file + ' ' + - chunkSize + ' ' + - JSON.stringify(opts) + ' ' + - Def.name + ' -> ' + Inf.name; - var ok = true; - var testNum = ++done; - for (var i = 0; i < Math.max(c.length, test.length); i++) { + const msg = file + ' ' + + chunkSize + ' ' + + JSON.stringify(opts) + ' ' + + Def.name + ' -> ' + Inf.name; + let ok = true; + const testNum = ++done; + let i; + for (i = 0; i < Math.max(c.length, test.length); i++) { if (c[i] !== test[i]) { ok = false; failures++; diff --git a/test/pseudo-tty/no_dropped_stdio.js b/test/pseudo-tty/no_dropped_stdio.js index 1a20889073ce06..b24d234a38b2b7 100644 --- a/test/pseudo-tty/no_dropped_stdio.js +++ b/test/pseudo-tty/no_dropped_stdio.js @@ -6,7 +6,7 @@ require('../common'); // 1000 bytes wrapped at 50 columns // \n turns into a double-byte character // (48 + {2}) * 20 = 1000 -var out = ('o'.repeat(48) + '\n').repeat(20); +let out = ('o'.repeat(48) + '\n').repeat(20); // Add the remaining 24 bytes and terminate with an 'O'. // This results in 1025 bytes, just enough to overflow the 1kb OS X TTY buffer. out += 'o'.repeat(24) + 'O'; diff --git a/test/pseudo-tty/no_interleaved_stdio.js b/test/pseudo-tty/no_interleaved_stdio.js index 778b2c09583b90..ff3ed8594a0baa 100644 --- a/test/pseudo-tty/no_interleaved_stdio.js +++ b/test/pseudo-tty/no_interleaved_stdio.js @@ -6,7 +6,7 @@ require('../common'); // 1000 bytes wrapped at 50 columns // \n turns into a double-byte character // (48 + {2}) * 20 = 1000 -var out = ('o'.repeat(48) + '\n').repeat(20); +let out = ('o'.repeat(48) + '\n').repeat(20); // Add the remaining 24 bytes and terminate with an 'O'. // This results in 1025 bytes, just enough to overflow the 1kb OS X TTY buffer. out += 'o'.repeat(24) + 'O'; diff --git a/test/pummel/test-abort-fatal-error.js b/test/pummel/test-abort-fatal-error.js index 0bb2cb2c39998e..d1a8d3daa65e4c 100644 --- a/test/pummel/test-abort-fatal-error.js +++ b/test/pummel/test-abort-fatal-error.js @@ -1,15 +1,15 @@ 'use strict'; const common = require('../common'); -var assert = require('assert'); +const assert = require('assert'); if (common.isWindows) { common.skip('no RLIMIT_NOFILE on Windows'); return; } -var exec = require('child_process').exec; +const exec = require('child_process').exec; -var cmdline = 'ulimit -c 0; ' + process.execPath; +let cmdline = 'ulimit -c 0; ' + process.execPath; cmdline += ' --max-old-space-size=4 --max-semi-space-size=1'; cmdline += ' -e "a = []; for (i = 0; i < 1e9; i++) { a.push({}) }"'; diff --git a/test/pummel/test-child-process-spawn-loop.js b/test/pummel/test-child-process-spawn-loop.js index 7a3cf114b4e8e9..41d9ff1e49c17b 100644 --- a/test/pummel/test-child-process-spawn-loop.js +++ b/test/pummel/test-child-process-spawn-loop.js @@ -1,8 +1,8 @@ 'use strict'; -var common = require('../common'); -var assert = require('assert'); +const common = require('../common'); +const assert = require('assert'); -var spawn = require('child_process').spawn; +const spawn = require('child_process').spawn; const SIZE = 1000 * 1024; const N = 40; diff --git a/test/pummel/test-crypto-dh.js b/test/pummel/test-crypto-dh.js index a19e583c516398..30c06b8795db41 100644 --- a/test/pummel/test-crypto-dh.js +++ b/test/pummel/test-crypto-dh.js @@ -35,7 +35,7 @@ assert.throws( 'failed to throw the expected error.' ); -var hashes = { +const hashes = { modp1: '630e9acd2cc63f7e80d8507624ba60ac0757201a', modp2: '18f7aa964484137f57bca64b21917a385b6a0b60', modp5: 'c0a8eec0c2c8a5ec2f9c26f9661eb339a010ec61', @@ -47,10 +47,10 @@ var hashes = { }; for (const name in hashes) { - var group = crypto.getDiffieHellman(name); - var private_key = group.getPrime('hex'); - var hash1 = hashes[name]; - var hash2 = crypto.createHash('sha1') + const group = crypto.getDiffieHellman(name); + const private_key = group.getPrime('hex'); + const hash1 = hashes[name]; + const hash2 = crypto.createHash('sha1') .update(private_key.toUpperCase()).digest('hex'); assert.equal(hash1, hash2); assert.equal(group.getGenerator('hex'), '02'); @@ -60,11 +60,11 @@ for (const name in hashes) { // modp1 is 768 bits, FIPS requires >= 1024 if (name === 'modp1' && common.hasFipsCrypto) continue; - var group1 = crypto.getDiffieHellman(name); - var group2 = crypto.getDiffieHellman(name); + const group1 = crypto.getDiffieHellman(name); + const group2 = crypto.getDiffieHellman(name); group1.generateKeys(); group2.generateKeys(); - var key1 = group1.computeSecret(group2.getPublicKey()); - var key2 = group2.computeSecret(group1.getPublicKey()); + const key1 = group1.computeSecret(group2.getPublicKey()); + const key2 = group2.computeSecret(group1.getPublicKey()); assert.deepStrictEqual(key1, key2); } diff --git a/test/pummel/test-dh-regr.js b/test/pummel/test-dh-regr.js index 448319318b44a4..5be6abb9a8b29c 100644 --- a/test/pummel/test-dh-regr.js +++ b/test/pummel/test-dh-regr.js @@ -1,16 +1,16 @@ 'use strict'; -var common = require('../common'); -var assert = require('assert'); +const common = require('../common'); +const assert = require('assert'); if (!common.hasCrypto) { common.skip('missing crypto'); return; } -var crypto = require('crypto'); +const crypto = require('crypto'); -var p = crypto.createDiffieHellman(1024).getPrime(); +const p = crypto.createDiffieHellman(1024).getPrime(); -for (var i = 0; i < 2000; i++) { +for (let i = 0; i < 2000; i++) { const a = crypto.createDiffieHellman(p); const b = crypto.createDiffieHellman(p); diff --git a/test/pummel/test-dtrace-jsstack.js b/test/pummel/test-dtrace-jsstack.js index 1949045888c138..d1615a3855af43 100644 --- a/test/pummel/test-dtrace-jsstack.js +++ b/test/pummel/test-dtrace-jsstack.js @@ -1,7 +1,7 @@ 'use strict'; const common = require('../common'); -var assert = require('assert'); -var os = require('os'); +const assert = require('assert'); +const os = require('os'); if (!common.isSunOS) { common.skip('no DTRACE support'); @@ -11,37 +11,37 @@ if (!common.isSunOS) { /* * Some functions to create a recognizable stack. */ -var frames = [ 'stalloogle', 'bagnoogle', 'doogle' ]; +const frames = [ 'stalloogle', 'bagnoogle', 'doogle' ]; -var stalloogle = function(str) { +const stalloogle = function(str) { global.expected = str; os.loadavg(); }; -var bagnoogle = function(arg0, arg1) { +const bagnoogle = function(arg0, arg1) { stalloogle(arg0 + ' is ' + arg1 + ' except that it is read-only'); }; -var done = false; +let done = false; -var doogle = function() { +const doogle = function() { if (!done) setTimeout(doogle, 10); bagnoogle('The bfs command', '(almost) like ed(1)'); }; -var spawn = require('child_process').spawn; +const spawn = require('child_process').spawn; /* * We're going to use DTrace to stop us, gcore us, and set us running again * when we call getloadavg() -- with the implicit assumption that our * deepest function is the only caller of os.loadavg(). */ -var dtrace = spawn('dtrace', [ '-qwn', 'syscall::getloadavg:entry/pid == ' + +const dtrace = spawn('dtrace', [ '-qwn', 'syscall::getloadavg:entry/pid == ' + process.pid + '/{ustack(100, 8192); exit(0); }' ]); -var output = ''; +let output = ''; dtrace.stderr.on('data', function(data) { console.log('dtrace: ' + data); @@ -59,17 +59,17 @@ dtrace.on('exit', function(code) { done = true; - var sentinel = '(anon) as '; - var lines = output.split('\n'); + const sentinel = '(anon) as '; + const lines = output.split('\n'); - for (var i = 0; i < lines.length; i++) { - var line = lines[i]; + for (let i = 0; i < lines.length; i++) { + const line = lines[i]; if (line.indexOf(sentinel) === -1 || frames.length === 0) continue; - var frame = line.substr(line.indexOf(sentinel) + sentinel.length); - var top = frames.shift(); + const frame = line.substr(line.indexOf(sentinel) + sentinel.length); + const top = frames.shift(); assert.equal(frame.indexOf(top), 0, 'unexpected frame where ' + top + ' was expected'); diff --git a/test/pummel/test-exec.js b/test/pummel/test-exec.js index 18404373318917..131b214fc53f42 100644 --- a/test/pummel/test-exec.js +++ b/test/pummel/test-exec.js @@ -1,9 +1,9 @@ 'use strict'; -var common = require('../common'); -var assert = require('assert'); -var exec = require('child_process').exec; +const common = require('../common'); +const assert = require('assert'); +const exec = require('child_process').exec; -var SLEEP3_COMMAND; +let SLEEP3_COMMAND; if (!common.isWindows) { // Unix. SLEEP3_COMMAND = 'sleep 3'; @@ -14,8 +14,8 @@ if (!common.isWindows) { } -var success_count = 0; -var error_count = 0; +let success_count = 0; +let error_count = 0; exec( @@ -55,9 +55,9 @@ exec('thisisnotavalidcommand', function(err, stdout, stderr) { }); -var sleeperStart = new Date(); +const sleeperStart = new Date(); exec(SLEEP3_COMMAND, { timeout: 50 }, function(err, stdout, stderr) { - var diff = (new Date()) - sleeperStart; + const diff = (new Date()) - sleeperStart; console.log('\'sleep 3\' with timeout 50 took %d ms', diff); assert.ok(diff < 500); assert.ok(err); @@ -68,8 +68,8 @@ exec(SLEEP3_COMMAND, { timeout: 50 }, function(err, stdout, stderr) { }); -var startSleep3 = new Date(); -var killMeTwice = exec(SLEEP3_COMMAND, {timeout: 1000}, killMeTwiceCallback); +const startSleep3 = new Date(); +const killMeTwice = exec(SLEEP3_COMMAND, {timeout: 1000}, killMeTwiceCallback); process.nextTick(function() { console.log('kill pid %d', killMeTwice.pid); @@ -81,7 +81,7 @@ process.nextTick(function() { }); function killMeTwiceCallback(err, stdout, stderr) { - var diff = (new Date()) - startSleep3; + const diff = (new Date()) - startSleep3; // We should have already killed this process. Assert that the timeout still // works and that we are getting the proper callback parameters. assert.ok(err); diff --git a/test/pummel/test-fs-watch-file-slow.js b/test/pummel/test-fs-watch-file-slow.js index 508de487f6dc23..78c36152ecd315 100644 --- a/test/pummel/test-fs-watch-file-slow.js +++ b/test/pummel/test-fs-watch-file-slow.js @@ -1,13 +1,13 @@ 'use strict'; -var common = require('../common'); -var assert = require('assert'); -var path = require('path'); -var fs = require('fs'); +const common = require('../common'); +const assert = require('assert'); +const path = require('path'); +const fs = require('fs'); -var FILENAME = path.join(common.tmpDir, 'watch-me'); -var TIMEOUT = 1300; +const FILENAME = path.join(common.tmpDir, 'watch-me'); +const TIMEOUT = 1300; -var nevents = 0; +let nevents = 0; try { fs.unlinkSync(FILENAME); diff --git a/test/pummel/test-fs-watch-file.js b/test/pummel/test-fs-watch-file.js index fc291cfe64c618..7713fe74ed99aa 100644 --- a/test/pummel/test-fs-watch-file.js +++ b/test/pummel/test-fs-watch-file.js @@ -1,26 +1,26 @@ 'use strict'; -var common = require('../common'); -var assert = require('assert'); -var path = require('path'); -var fs = require('fs'); +const common = require('../common'); +const assert = require('assert'); +const path = require('path'); +const fs = require('fs'); -var watchSeenOne = 0; -var watchSeenTwo = 0; -var watchSeenThree = 0; -var watchSeenFour = 0; +let watchSeenOne = 0; +let watchSeenTwo = 0; +let watchSeenThree = 0; +let watchSeenFour = 0; -var testDir = common.tmpDir; +const testDir = common.tmpDir; -var filenameOne = 'watch.txt'; -var filepathOne = path.join(testDir, filenameOne); +const filenameOne = 'watch.txt'; +const filepathOne = path.join(testDir, filenameOne); -var filenameTwo = 'hasOwnProperty'; -var filepathTwo = filenameTwo; -var filepathTwoAbs = path.join(testDir, filenameTwo); +const filenameTwo = 'hasOwnProperty'; +const filepathTwo = filenameTwo; +const filepathTwoAbs = path.join(testDir, filenameTwo); -var filenameThree = 'charm'; // because the third time is +const filenameThree = 'charm'; // because the third time is -var filenameFour = 'get'; +const filenameFour = 'get'; process.on('exit', function() { fs.unlinkSync(filepathOne); diff --git a/test/pummel/test-fs-watch-non-recursive.js b/test/pummel/test-fs-watch-non-recursive.js index ead7de9e28dc47..b7c19b9c360818 100644 --- a/test/pummel/test-fs-watch-non-recursive.js +++ b/test/pummel/test-fs-watch-non-recursive.js @@ -1,11 +1,11 @@ 'use strict'; -var common = require('../common'); -var path = require('path'); -var fs = require('fs'); +const common = require('../common'); +const path = require('path'); +const fs = require('fs'); -var testDir = common.tmpDir; -var testsubdir = path.join(testDir, 'testsubdir'); -var filepath = path.join(testsubdir, 'watch.txt'); +const testDir = common.tmpDir; +const testsubdir = path.join(testDir, 'testsubdir'); +const filepath = path.join(testsubdir, 'watch.txt'); function cleanup() { try { fs.unlinkSync(filepath); } catch (e) { } @@ -18,7 +18,7 @@ try { fs.mkdirSync(testsubdir, 0o700); } catch (e) {} // Need a grace period, else the mkdirSync() above fires off an event. setTimeout(function() { - var watcher = fs.watch(testDir, { persistent: true }, common.fail); + const watcher = fs.watch(testDir, { persistent: true }, common.fail); setTimeout(function() { fs.writeFileSync(filepath, 'test'); }, 100); diff --git a/test/pummel/test-http-client-reconnect-bug.js b/test/pummel/test-http-client-reconnect-bug.js index 395a538178fe79..98d21c5cba7bc5 100644 --- a/test/pummel/test-http-client-reconnect-bug.js +++ b/test/pummel/test-http-client-reconnect-bug.js @@ -3,17 +3,17 @@ const common = require('../common'); const net = require('net'); const http = require('http'); -var server = net.createServer(function(socket) { +const server = net.createServer(function(socket) { socket.end(); }); server.on('listening', common.mustCall(function() { - var client = http.createClient(common.PORT); + const client = http.createClient(common.PORT); client.on('error', common.mustCall(function(err) {})); client.on('end', common.mustCall(function() {})); - var request = client.request('GET', '/', {'host': 'localhost'}); + const request = client.request('GET', '/', {'host': 'localhost'}); request.end(); request.on('response', function(response) { console.log('STATUS: ' + response.statusCode); diff --git a/test/pummel/test-http-many-keep-alive-connections.js b/test/pummel/test-http-many-keep-alive-connections.js index 293c6ab748e9c2..e465c02a90161c 100644 --- a/test/pummel/test-http-many-keep-alive-connections.js +++ b/test/pummel/test-http-many-keep-alive-connections.js @@ -1,14 +1,14 @@ 'use strict'; -var common = require('../common'); -var assert = require('assert'); -var http = require('http'); +const common = require('../common'); +const assert = require('assert'); +const http = require('http'); -var expected = 10000; -var responses = 0; -var requests = 0; -var connection; +const expected = 10000; +let responses = 0; +let requests = 0; +let connection; -var server = http.Server(function(req, res) { +const server = http.Server(function(req, res) { requests++; assert.equal(req.connection, connection); res.writeHead(200); @@ -20,7 +20,7 @@ server.once('connection', function(c) { }); server.listen(common.PORT, function connect() { - var request = http.get({ + const request = http.get({ port: common.PORT, path: '/', headers: { diff --git a/test/pummel/test-http-upload-timeout.js b/test/pummel/test-http-upload-timeout.js index 15bc267ff61947..da91ab3f0909e7 100644 --- a/test/pummel/test-http-upload-timeout.js +++ b/test/pummel/test-http-upload-timeout.js @@ -24,18 +24,18 @@ server.on('request', function(req, res) { }); server.listen(common.PORT, '127.0.0.1', function() { - for (var i = 0; i < 10; i++) { + for (let i = 0; i < 10; i++) { connections++; setTimeout(function() { - var request = http.request({ + const request = http.request({ port: common.PORT, method: 'POST', path: '/' }); function ping() { - var nextPing = (Math.random() * 900).toFixed(); + const nextPing = (Math.random() * 900).toFixed(); if (nextPing > 600) { request.end(); return; diff --git a/test/pummel/test-https-ci-reneg-attack.js b/test/pummel/test-https-ci-reneg-attack.js index 8bda7cc10286e9..850e0949c4a64a 100644 --- a/test/pummel/test-https-ci-reneg-attack.js +++ b/test/pummel/test-https-ci-reneg-attack.js @@ -1,16 +1,16 @@ 'use strict'; -var common = require('../common'); -var assert = require('assert'); -var spawn = require('child_process').spawn; +const common = require('../common'); +const assert = require('assert'); +const spawn = require('child_process').spawn; if (!common.hasCrypto) { common.skip('missing crypto'); return; } -var tls = require('tls'); -var https = require('https'); +const tls = require('tls'); +const https = require('https'); -var fs = require('fs'); +const fs = require('fs'); if (!common.opensslCli) { common.skip('node compiled without OpenSSL CLI.'); @@ -18,7 +18,7 @@ if (!common.opensslCli) { } // renegotiation limits to test -var LIMITS = [0, 1, 2, 3, 5, 10, 16]; +const LIMITS = [0, 1, 2, 3, 5, 10, 16]; { let n = 0; @@ -31,15 +31,15 @@ var LIMITS = [0, 1, 2, 3, 5, 10, 16]; } function test(next) { - var options = { + const options = { cert: fs.readFileSync(common.fixturesDir + '/test_cert.pem'), key: fs.readFileSync(common.fixturesDir + '/test_key.pem') }; - var seenError = false; + let seenError = false; - var server = https.createServer(options, function(req, res) { - var conn = req.connection; + const server = https.createServer(options, function(req, res) { + const conn = req.connection; conn.on('error', function(err) { console.error('Caught exception: ' + err); assert(/TLS session renegotiation attack/.test(err)); @@ -50,8 +50,8 @@ function test(next) { }); server.listen(common.PORT, function() { - var args = ('s_client -connect 127.0.0.1:' + common.PORT).split(' '); - var child = spawn(common.opensslCli, args); + const args = ('s_client -connect 127.0.0.1:' + common.PORT).split(' '); + const child = spawn(common.opensslCli, args); //child.stdout.pipe(process.stdout); //child.stderr.pipe(process.stderr); @@ -60,8 +60,8 @@ function test(next) { child.stderr.resume(); // count handshakes, start the attack after the initial handshake is done - var handshakes = 0; - var renegs = 0; + let handshakes = 0; + let renegs = 0; child.stderr.on('data', function(data) { if (seenError) return; @@ -76,7 +76,7 @@ function test(next) { process.nextTick(next); }); - var closed = false; + let closed = false; child.stdin.on('error', function(err) { switch (err.code) { case 'ECONNRESET': diff --git a/test/pummel/test-https-large-response.js b/test/pummel/test-https-large-response.js index a122e47bc57a57..39256aa6304b74 100644 --- a/test/pummel/test-https-large-response.js +++ b/test/pummel/test-https-large-response.js @@ -1,25 +1,25 @@ 'use strict'; -var common = require('../common'); -var assert = require('assert'); +const common = require('../common'); +const assert = require('assert'); -var fs = require('fs'); +const fs = require('fs'); if (!common.hasCrypto) { common.skip('missing crypto'); return; } -var https = require('https'); +const https = require('https'); -var options = { +const options = { key: fs.readFileSync(common.fixturesDir + '/keys/agent1-key.pem'), cert: fs.readFileSync(common.fixturesDir + '/keys/agent1-cert.pem') }; process.stdout.write('build body...'); -var body = 'hello world\n'.repeat(1024 * 1024); +const body = 'hello world\n'.repeat(1024 * 1024); process.stdout.write('done\n'); -var server = https.createServer(options, common.mustCall(function(req, res) { +const server = https.createServer(options, common.mustCall(function(req, res) { console.log('got request'); res.writeHead(200, { 'content-type': 'text/plain' }); res.end(body); @@ -32,7 +32,7 @@ server.listen(common.PORT, common.mustCall(function() { }, common.mustCall(function(res) { console.log('response!'); - var count = 0; + let count = 0; res.on('data', function(d) { process.stdout.write('.'); diff --git a/test/pummel/test-https-no-reader.js b/test/pummel/test-https-no-reader.js index fab59591993a69..a08676277af6ce 100644 --- a/test/pummel/test-https-no-reader.js +++ b/test/pummel/test-https-no-reader.js @@ -1,34 +1,34 @@ 'use strict'; -var common = require('../common'); -var assert = require('assert'); +const common = require('../common'); +const assert = require('assert'); if (!common.hasCrypto) { common.skip('missing crypto'); return; } -var https = require('https'); +const https = require('https'); -var Buffer = require('buffer').Buffer; -var fs = require('fs'); -var path = require('path'); +const Buffer = require('buffer').Buffer; +const fs = require('fs'); +const path = require('path'); -var options = { +const options = { key: fs.readFileSync(path.join(common.fixturesDir, 'test_key.pem')), cert: fs.readFileSync(path.join(common.fixturesDir, 'test_cert.pem')) }; -var buf = Buffer.allocUnsafe(1024 * 1024); +const buf = Buffer.allocUnsafe(1024 * 1024); -var server = https.createServer(options, function(req, res) { +const server = https.createServer(options, function(req, res) { res.writeHead(200); - for (var i = 0; i < 50; i++) { + for (let i = 0; i < 50; i++) { res.write(buf); } res.end(); }); server.listen(common.PORT, function() { - var req = https.request({ + const req = https.request({ method: 'POST', port: common.PORT, rejectUnauthorized: false diff --git a/test/pummel/test-keep-alive.js b/test/pummel/test-keep-alive.js index 47d529b64082fa..a9e91e201bb19b 100644 --- a/test/pummel/test-keep-alive.js +++ b/test/pummel/test-keep-alive.js @@ -1,11 +1,11 @@ 'use strict'; // This test requires the program 'wrk' -var common = require('../common'); -var assert = require('assert'); -var spawn = require('child_process').spawn; -var http = require('http'); -var url = require('url'); +const common = require('../common'); +const assert = require('assert'); +const spawn = require('child_process').spawn; +const http = require('http'); +const url = require('url'); if (common.isWindows) { common.skip('no `wrk` on windows'); diff --git a/test/pummel/test-net-connect-econnrefused.js b/test/pummel/test-net-connect-econnrefused.js index 2b6dc84f37195c..30da36d983e4f7 100644 --- a/test/pummel/test-net-connect-econnrefused.js +++ b/test/pummel/test-net-connect-econnrefused.js @@ -1,21 +1,22 @@ 'use strict'; // verify that connect reqs are properly cleaned up -var common = require('../common'); -var assert = require('assert'); -var net = require('net'); +const common = require('../common'); +const assert = require('assert'); +const net = require('net'); -var ROUNDS = 10; -var ATTEMPTS_PER_ROUND = 100; -var rounds = 1; -var reqs = 0; +const ROUNDS = 10; +const ATTEMPTS_PER_ROUND = 100; +let rounds = 1; +let reqs = 0; pummel(); function pummel() { console.log('Round', rounds, '/', ROUNDS); - for (var pending = 0; pending < ATTEMPTS_PER_ROUND; pending++) { + let pending; + for (pending = 0; pending < ATTEMPTS_PER_ROUND; pending++) { net.createConnection(common.PORT).on('error', function(err) { assert.equal(err.code, 'ECONNREFUSED'); if (--pending > 0) return; @@ -34,7 +35,7 @@ function check() { check_called = true; }, 0); } -var check_called = false; +let check_called = false; process.on('exit', function() { assert.equal(rounds, ROUNDS); diff --git a/test/pummel/test-net-connect-memleak.js b/test/pummel/test-net-connect-memleak.js index 3b91a110eaa585..f16034e4773510 100644 --- a/test/pummel/test-net-connect-memleak.js +++ b/test/pummel/test-net-connect-memleak.js @@ -1,9 +1,9 @@ 'use strict'; // Flags: --expose-gc -var common = require('../common'); -var assert = require('assert'); -var net = require('net'); +const common = require('../common'); +const assert = require('assert'); +const net = require('net'); assert.strictEqual( typeof global.gc, @@ -12,7 +12,7 @@ assert.strictEqual( ); net.createServer(function() {}).listen(common.PORT); -var before = 0; +let before = 0; { // 2**26 == 64M entries global.gc(); @@ -29,8 +29,8 @@ var before = 0; function done() { global.gc(); - var after = process.memoryUsage().rss; - var reclaimed = (before - after) / 1024; + const after = process.memoryUsage().rss; + const reclaimed = (before - after) / 1024; console.log('%d kB reclaimed', reclaimed); assert(reclaimed > 128 * 1024); // It's around 256 MB on x64. process.exit(); diff --git a/test/pummel/test-net-many-clients.js b/test/pummel/test-net-many-clients.js index 52d05b35cbe2c4..a92ae033a09a17 100644 --- a/test/pummel/test-net-many-clients.js +++ b/test/pummel/test-net-many-clients.js @@ -1,19 +1,19 @@ 'use strict'; -var common = require('../common'); -var assert = require('assert'); -var net = require('net'); +const common = require('../common'); +const assert = require('assert'); +const net = require('net'); // settings -var bytes = 1024 * 40; -var concurrency = 100; -var connections_per_client = 5; +const bytes = 1024 * 40; +const concurrency = 100; +const connections_per_client = 5; // measured -var total_connections = 0; +let total_connections = 0; -var body = 'C'.repeat(bytes); +const body = 'C'.repeat(bytes); -var server = net.createServer(function(c) { +const server = net.createServer(function(c) { console.log('connected'); total_connections++; console.log('#'); @@ -22,7 +22,7 @@ var server = net.createServer(function(c) { }); function runClient(callback) { - var client = net.createConnection(common.PORT); + const client = net.createConnection(common.PORT); client.connections = 0; @@ -66,8 +66,8 @@ function runClient(callback) { } server.listen(common.PORT, function() { - var finished_clients = 0; - for (var i = 0; i < concurrency; i++) { + let finished_clients = 0; + for (let i = 0; i < concurrency; i++) { runClient(function() { if (++finished_clients === concurrency) server.close(); }); diff --git a/test/pummel/test-net-pause.js b/test/pummel/test-net-pause.js index b0c51260436e0c..db426edbe9c507 100644 --- a/test/pummel/test-net-pause.js +++ b/test/pummel/test-net-pause.js @@ -1,12 +1,12 @@ 'use strict'; -var common = require('../common'); -var assert = require('assert'); -var net = require('net'); +const common = require('../common'); +const assert = require('assert'); +const net = require('net'); -var N = 200; -var recv = '', chars_recved = 0; +const N = 200; +let recv = '', chars_recved = 0; -var server = net.createServer(function(connection) { +const server = net.createServer(function(connection) { function write(j) { if (j >= N) { connection.end(); @@ -21,7 +21,7 @@ var server = net.createServer(function(connection) { }); server.on('listening', function() { - var client = net.createConnection(common.PORT); + const client = net.createConnection(common.PORT); client.setEncoding('ascii'); client.on('data', function(d) { console.log(d); diff --git a/test/pummel/test-net-pingpong-delay.js b/test/pummel/test-net-pingpong-delay.js index c9cac778d59f4e..9a598435d1bd28 100644 --- a/test/pummel/test-net-pingpong-delay.js +++ b/test/pummel/test-net-pingpong-delay.js @@ -1,15 +1,15 @@ 'use strict'; -var common = require('../common'); -var assert = require('assert'); -var net = require('net'); +const common = require('../common'); +const assert = require('assert'); +const net = require('net'); function pingPongTest(port, host, on_complete) { - var N = 100; - var DELAY = 1; - var count = 0; - var client_ended = false; + const N = 100; + const DELAY = 1; + let count = 0; + let client_ended = false; - var server = net.createServer({ allowHalfOpen: true }, function(socket) { + const server = net.createServer({ allowHalfOpen: true }, function(socket) { socket.setEncoding('utf8'); socket.on('data', function(data) { @@ -43,7 +43,7 @@ function pingPongTest(port, host, on_complete) { }); server.listen(port, host, common.mustCall(function() { - var client = net.createConnection(port, host); + const client = net.createConnection(port, host); client.setEncoding('utf8'); diff --git a/test/pummel/test-net-pingpong.js b/test/pummel/test-net-pingpong.js index 85dce02b6cf635..6ede6f9fcb2763 100644 --- a/test/pummel/test-net-pingpong.js +++ b/test/pummel/test-net-pingpong.js @@ -1,19 +1,19 @@ 'use strict'; -var common = require('../common'); -var assert = require('assert'); -var net = require('net'); +const common = require('../common'); +const assert = require('assert'); +const net = require('net'); -var tests_run = 0; +let tests_run = 0; function pingPongTest(port, host, on_complete) { - var N = 1000; - var count = 0; - var sent_final_ping = false; + const N = 1000; + let count = 0; + let sent_final_ping = false; - var server = net.createServer({ allowHalfOpen: true }, function(socket) { + const server = net.createServer({ allowHalfOpen: true }, function(socket) { assert.equal(true, socket.remoteAddress !== null); assert.equal(true, socket.remoteAddress !== undefined); - var address = socket.remoteAddress; + const address = socket.remoteAddress; if (host === '127.0.0.1') { assert.equal(address, '127.0.0.1'); } else if (host == null || host === 'localhost') { @@ -49,7 +49,7 @@ function pingPongTest(port, host, on_complete) { }); server.listen(port, host, function() { - var client = net.createConnection(port, host); + const client = net.createConnection(port, host); client.setEncoding('utf8'); diff --git a/test/pummel/test-net-throttle.js b/test/pummel/test-net-throttle.js index d2f32ec25b6ff2..23f05f4d5eaeaa 100644 --- a/test/pummel/test-net-throttle.js +++ b/test/pummel/test-net-throttle.js @@ -5,15 +5,15 @@ const net = require('net'); const N = 1024 * 1024; const part_N = N / 3; -var chars_recved = 0; -var npauses = 0; +let chars_recved = 0; +let npauses = 0; console.log('build big string'); const body = 'C'.repeat(N); console.log('start server on port ' + common.PORT); -var server = net.createServer(function(connection) { +const server = net.createServer(function(connection) { connection.write(body.slice(0, part_N)); connection.write(body.slice(part_N, 2 * part_N)); assert.equal(false, connection.write(body.slice(2 * part_N, N))); @@ -24,8 +24,8 @@ var server = net.createServer(function(connection) { }); server.listen(common.PORT, function() { - var paused = false; - var client = net.createConnection(common.PORT); + let paused = false; + const client = net.createConnection(common.PORT); client.setEncoding('ascii'); client.on('data', function(d) { chars_recved += d.length; @@ -35,7 +35,7 @@ server.listen(common.PORT, function() { npauses += 1; paused = true; console.log('pause'); - var x = chars_recved; + const x = chars_recved; setTimeout(function() { assert.equal(chars_recved, x); client.resume(); diff --git a/test/pummel/test-net-timeout.js b/test/pummel/test-net-timeout.js index 415523763eef3c..d6dd8e489cc116 100644 --- a/test/pummel/test-net-timeout.js +++ b/test/pummel/test-net-timeout.js @@ -1,14 +1,14 @@ 'use strict'; -var common = require('../common'); -var assert = require('assert'); -var net = require('net'); +const common = require('../common'); +const assert = require('assert'); +const net = require('net'); -var exchanges = 0; -var starttime = null; -var timeouttime = null; -var timeout = 1000; +let exchanges = 0; +let starttime = null; +let timeouttime = null; +const timeout = 1000; -var echo_server = net.createServer(function(socket) { +const echo_server = net.createServer(function(socket) { socket.setTimeout(timeout); socket.on('timeout', function() { @@ -36,7 +36,7 @@ var echo_server = net.createServer(function(socket) { echo_server.listen(common.PORT, function() { console.log('server listening at ' + common.PORT); - var client = net.createConnection(common.PORT); + const client = net.createConnection(common.PORT); client.setEncoding('UTF8'); client.setTimeout(0); // disable the timeout for client client.on('connect', function() { @@ -79,7 +79,7 @@ process.on('exit', function() { assert.ok(starttime != null); assert.ok(timeouttime != null); - var diff = timeouttime - starttime; + const diff = timeouttime - starttime; console.log('diff = ' + diff); assert.ok(timeout < diff); diff --git a/test/pummel/test-net-timeout2.js b/test/pummel/test-net-timeout2.js index 7af47a47a8b634..a3d0abceb6c765 100644 --- a/test/pummel/test-net-timeout2.js +++ b/test/pummel/test-net-timeout2.js @@ -2,16 +2,16 @@ // socket.write was not resetting the timeout timer. See // https://github.com/joyent/node/issues/2002 -var common = require('../common'); -var net = require('net'); +const common = require('../common'); +const net = require('net'); -var seconds = 5; -var counter = 0; +const seconds = 5; +let counter = 0; -var server = net.createServer(function(socket) { +const server = net.createServer(function(socket) { socket.setTimeout((seconds / 2) * 1000, common.fail); - var interval = setInterval(function() { + const interval = setInterval(function() { counter++; if (counter === seconds) { @@ -28,6 +28,6 @@ var server = net.createServer(function(socket) { server.listen(common.PORT, function() { - var s = net.connect(common.PORT); + const s = net.connect(common.PORT); s.pipe(process.stdout); }); diff --git a/test/pummel/test-net-write-callbacks.js b/test/pummel/test-net-write-callbacks.js index 21eae0f5ab72d0..6c3c1f202a81c3 100644 --- a/test/pummel/test-net-write-callbacks.js +++ b/test/pummel/test-net-write-callbacks.js @@ -1,12 +1,12 @@ 'use strict'; -var common = require('../common'); -var net = require('net'); -var assert = require('assert'); +const common = require('../common'); +const net = require('net'); +const assert = require('assert'); -var cbcount = 0; -var N = 500000; +let cbcount = 0; +const N = 500000; -var server = net.Server(function(socket) { +const server = net.Server(function(socket) { socket.on('data', function(d) { console.error('got %d bytes', d.length); }); @@ -18,9 +18,9 @@ var server = net.Server(function(socket) { }); }); -var lastCalled = -1; +let lastCalled = -1; function makeCallback(c) { - var called = false; + let called = false; return function() { if (called) throw new Error('called callback #' + c + ' more than once'); @@ -34,10 +34,10 @@ function makeCallback(c) { } server.listen(common.PORT, function() { - var client = net.createConnection(common.PORT); + const client = net.createConnection(common.PORT); client.on('connect', function() { - for (var i = 0; i < N; i++) { + for (let i = 0; i < N; i++) { client.write('hello world', makeCallback(i)); } client.end(); diff --git a/test/pummel/test-next-tick-infinite-calls.js b/test/pummel/test-next-tick-infinite-calls.js index 18223885d6cc19..afce6ef846b10f 100644 --- a/test/pummel/test-next-tick-infinite-calls.js +++ b/test/pummel/test-next-tick-infinite-calls.js @@ -1,7 +1,7 @@ 'use strict'; require('../common'); -var complete = 0; +let complete = 0; // This will fail with: // FATAL ERROR: JS Allocation failed - process out of memory diff --git a/test/pummel/test-process-hrtime.js b/test/pummel/test-process-hrtime.js index 04225bae421b1a..d02b9c79822a88 100644 --- a/test/pummel/test-process-hrtime.js +++ b/test/pummel/test-process-hrtime.js @@ -1,18 +1,18 @@ 'use strict'; require('../common'); -var assert = require('assert'); +const assert = require('assert'); -var start = process.hrtime(); +const start = process.hrtime(); // process.hrtime() should return an Array assert(Array.isArray(start)); // busy-loop for 2 seconds -var now = Date.now(); +const now = Date.now(); while (Date.now() - now < 2000); // get a diff reading -var diff = process.hrtime(start); +const diff = process.hrtime(start); // should be at least 1 second, at most 2 seconds later // (the while loop will usually exit a few nanoseconds before 2) diff --git a/test/pummel/test-process-uptime.js b/test/pummel/test-process-uptime.js index 8d2d88b74f736f..5c09d59b06d55c 100644 --- a/test/pummel/test-process-uptime.js +++ b/test/pummel/test-process-uptime.js @@ -1,14 +1,14 @@ 'use strict'; require('../common'); -var assert = require('assert'); +const assert = require('assert'); console.error(process.uptime()); assert.ok(process.uptime() <= 2); -var original = process.uptime(); +const original = process.uptime(); setTimeout(function() { - var uptime = process.uptime(); + const uptime = process.uptime(); // some wiggle room to account for timer // granularity, processor speed, and scheduling assert.ok(uptime >= original + 2); diff --git a/test/pummel/test-regress-GH-814.js b/test/pummel/test-regress-GH-814.js index 7bbd13dd196457..a3700c500b4f53 100644 --- a/test/pummel/test-regress-GH-814.js +++ b/test/pummel/test-regress-GH-814.js @@ -4,7 +4,7 @@ const common = require('../common'); function newBuffer(size, value) { - var buffer = Buffer.allocUnsafe(size); + const buffer = Buffer.allocUnsafe(size); while (size--) { buffer[size] = value; } @@ -13,19 +13,19 @@ function newBuffer(size, value) { return buffer; } -var fs = require('fs'); -var testFileName = require('path').join(common.tmpDir, 'GH-814_testFile.txt'); -var testFileFD = fs.openSync(testFileName, 'w'); +const fs = require('fs'); +const testFileName = require('path').join(common.tmpDir, 'GH-814_testFile.txt'); +const testFileFD = fs.openSync(testFileName, 'w'); console.log(testFileName); -var kBufSize = 128 * 1024; -var PASS = true; -var neverWrittenBuffer = newBuffer(kBufSize, 0x2e); //0x2e === '.' -var bufPool = []; +const kBufSize = 128 * 1024; +let PASS = true; +const neverWrittenBuffer = newBuffer(kBufSize, 0x2e); //0x2e === '.' +const bufPool = []; -var tail = require('child_process').spawn('tail', ['-f', testFileName]); +const tail = require('child_process').spawn('tail', ['-f', testFileName]); tail.stdout.on('data', tailCB); function tailCB(data) { @@ -33,13 +33,13 @@ function tailCB(data) { } -var timeToQuit = Date.now() + 8e3; //Test during no more than this seconds. +const timeToQuit = Date.now() + 8e3; //Test during no more than this seconds. (function main() { if (PASS) { fs.write(testFileFD, newBuffer(kBufSize, 0x61), 0, kBufSize, -1, cb); global.gc(); - var nuBuf = Buffer.allocUnsafe(kBufSize); + const nuBuf = Buffer.allocUnsafe(kBufSize); neverWrittenBuffer.copy(nuBuf); if (bufPool.push(nuBuf) > 100) { bufPool.length = 0; diff --git a/test/pummel/test-regress-GH-814_2.js b/test/pummel/test-regress-GH-814_2.js index 7909a461f37956..ba7d45124bf9fa 100644 --- a/test/pummel/test-regress-GH-814_2.js +++ b/test/pummel/test-regress-GH-814_2.js @@ -1,15 +1,15 @@ 'use strict'; // Flags: --expose_gc -var common = require('../common'); +const common = require('../common'); -var fs = require('fs'); -var testFileName = require('path').join(common.tmpDir, 'GH-814_test.txt'); -var testFD = fs.openSync(testFileName, 'w'); +const fs = require('fs'); +const testFileName = require('path').join(common.tmpDir, 'GH-814_test.txt'); +const testFD = fs.openSync(testFileName, 'w'); console.error(testFileName + '\n'); -var tailProc = require('child_process').spawn('tail', ['-f', testFileName]); +const tailProc = require('child_process').spawn('tail', ['-f', testFileName]); tailProc.stdout.on('data', tailCB); function tailCB(data) { @@ -26,12 +26,12 @@ function tailCB(data) { } -var PASS = true; -var bufPool = []; -var kBufSize = 16 * 1024 * 1024; -var neverWrittenBuffer = newBuffer(kBufSize, 0x2e); //0x2e === '.' +let PASS = true; +const bufPool = []; +const kBufSize = 16 * 1024 * 1024; +const neverWrittenBuffer = newBuffer(kBufSize, 0x2e); //0x2e === '.' -var timeToQuit = Date.now() + 5e3; //Test should last no more than this. +const timeToQuit = Date.now() + 5e3; //Test should last no more than this. writer(); function writer() { @@ -50,7 +50,7 @@ function writer() { global.gc(); global.gc(); global.gc(); - var nuBuf = Buffer.allocUnsafe(kBufSize); + const nuBuf = Buffer.allocUnsafe(kBufSize); neverWrittenBuffer.copy(nuBuf); if (bufPool.push(nuBuf) > 100) { bufPool.length = 0; @@ -74,7 +74,7 @@ function writerCB(err, written) { function newBuffer(size, value) { - var buffer = Buffer.allocUnsafe(size); + const buffer = Buffer.allocUnsafe(size); while (size--) { buffer[size] = value; } diff --git a/test/pummel/test-regress-GH-892.js b/test/pummel/test-regress-GH-892.js index 8bbf3c8f1a0ff4..0619fd84de3b5e 100644 --- a/test/pummel/test-regress-GH-892.js +++ b/test/pummel/test-regress-GH-892.js @@ -5,39 +5,40 @@ // to POST a 32mb file to us. A bug in the pause/resume functionality of the // TLS server causes the child process to exit cleanly before having sent // the entire buffer. -var common = require('../common'); -var assert = require('assert'); -var spawn = require('child_process').spawn; +const common = require('../common'); +const assert = require('assert'); +const spawn = require('child_process').spawn; if (!common.hasCrypto) { common.skip('missing crypto'); return; } -var https = require('https'); +const https = require('https'); -var fs = require('fs'); +const fs = require('fs'); -var bytesExpected = 1024 * 1024 * 32; +const bytesExpected = 1024 * 1024 * 32; -var started = false; +let started = false; -var childScript = require('path').join(common.fixturesDir, 'GH-892-request.js'); +const childScript = require('path').join(common.fixturesDir, + 'GH-892-request.js'); function makeRequest() { if (started) return; started = true; - var stderrBuffer = ''; + let stderrBuffer = ''; // Pass along --trace-deprecation/--throw-deprecation in // process.execArgv to track down nextTick recursion errors // more easily. Also, this is handy when using this test to // view V8 opt/deopt behavior. - var args = process.execArgv.concat([ childScript, - common.PORT, - bytesExpected ]); + const args = process.execArgv.concat([ childScript, + common.PORT, + bytesExpected ]); - var child = spawn(process.execPath, args); + const child = spawn(process.execPath, args); child.on('exit', function(code) { assert.ok(/DONE/.test(stderrBuffer)); @@ -58,14 +59,14 @@ function makeRequest() { } -var serverOptions = { +const serverOptions = { key: fs.readFileSync(common.fixturesDir + '/keys/agent1-key.pem'), cert: fs.readFileSync(common.fixturesDir + '/keys/agent1-cert.pem') }; -var uploadCount = 0; +let uploadCount = 0; -var server = https.Server(serverOptions, function(req, res) { +const server = https.Server(serverOptions, function(req, res) { // Close the server immediately. This test is only doing a single upload. // We need to make sure the server isn't keeping the event loop alive // while the upload is in progress. diff --git a/test/pummel/test-stream-pipe-multi.js b/test/pummel/test-stream-pipe-multi.js index 897b9d6dc27d46..e1e5e011020fe2 100644 --- a/test/pummel/test-stream-pipe-multi.js +++ b/test/pummel/test-stream-pipe-multi.js @@ -3,16 +3,16 @@ // doesn't break anything. require('../common'); -var assert = require('assert'); -var Stream = require('stream').Stream; -var rr = []; -var ww = []; -var cnt = 100; -var chunks = 1000; -var chunkSize = 250; -var data = Buffer.allocUnsafe(chunkSize); -var wclosed = 0; -var rclosed = 0; +const assert = require('assert'); +const Stream = require('stream').Stream; +const rr = []; +const ww = []; +const cnt = 100; +const chunks = 1000; +const chunkSize = 250; +const data = Buffer.allocUnsafe(chunkSize); +let wclosed = 0; +let rclosed = 0; function FakeStream() { Stream.apply(this); @@ -54,14 +54,14 @@ for (let i = 0; i < chunkSize; i++) { } for (let i = 0; i < cnt; i++) { - var r = new FakeStream(); + const r = new FakeStream(); r.on('close', function() { console.error(this.ID, 'read close'); rclosed++; }); rr.push(r); - var w = new FakeStream(); + const w = new FakeStream(); w.on('close', function() { console.error(this.ID, 'write close'); wclosed++; @@ -75,8 +75,8 @@ for (let i = 0; i < cnt; i++) { // now start passing through data // simulate a relatively fast async stream. rr.forEach(function(r) { - var cnt = chunks; - var paused = false; + let cnt = chunks; + let paused = false; r.on('pause', function() { paused = true; diff --git a/test/pummel/test-stream2-basic.js b/test/pummel/test-stream2-basic.js index 6bb2386b0b17dc..67ee4eb7a812a6 100644 --- a/test/pummel/test-stream2-basic.js +++ b/test/pummel/test-stream2-basic.js @@ -1,10 +1,10 @@ 'use strict'; require('../common'); -var R = require('_stream_readable'); -var assert = require('assert'); +const R = require('_stream_readable'); +const assert = require('assert'); -var util = require('util'); -var EE = require('events').EventEmitter; +const util = require('util'); +const EE = require('events').EventEmitter; function TestReader(n) { R.apply(this); @@ -16,9 +16,9 @@ function TestReader(n) { util.inherits(TestReader, R); TestReader.prototype._read = function(n) { - var max = this._buffer.length - this._pos; + const max = this._buffer.length - this._pos; n = Math.max(n, 0); - var toRead = Math.min(n, max); + const toRead = Math.min(n, max); if (toRead === 0) { // simulate the read buffer filling up with some more bytes some time // in the future. @@ -39,7 +39,7 @@ TestReader.prototype._read = function(n) { return; } - var ret = this._buffer.slice(this._pos, this._pos + toRead); + const ret = this._buffer.slice(this._pos, this._pos + toRead); this._pos += toRead; this.push(ret); }; @@ -68,8 +68,8 @@ TestWriter.prototype.end = function(c) { //////// // tiny node-tap lookalike. -var tests = []; -var count = 0; +const tests = []; +let count = 0; function test(name, fn) { count++; @@ -77,12 +77,12 @@ function test(name, fn) { } function run() { - var next = tests.shift(); + const next = tests.shift(); if (!next) return console.error('ok'); - var name = next[0]; - var fn = next[1]; + const name = next[0]; + const fn = next[1]; console.log('# %s', name); fn({ same: assert.deepStrictEqual, @@ -104,34 +104,34 @@ process.nextTick(run); test('a most basic test', function(t) { - var r = new TestReader(20); - - var reads = []; - var expect = [ 'x', - 'xx', - 'xxx', - 'xxxx', - 'xxxxx', - 'xxxxxxxxx', - 'xxxxxxxxxx', - 'xxxxxxxxxxxx', - 'xxxxxxxxxxxxx', - 'xxxxxxxxxxxxxxx', - 'xxxxxxxxxxxxxxxxx', - 'xxxxxxxxxxxxxxxxxxx', - 'xxxxxxxxxxxxxxxxxxxxx', - 'xxxxxxxxxxxxxxxxxxxxxxx', - 'xxxxxxxxxxxxxxxxxxxxxxxxx', - 'xxxxxxxxxxxxxxxxxxxxx' ]; + const r = new TestReader(20); + + const reads = []; + const expect = [ 'x', + 'xx', + 'xxx', + 'xxxx', + 'xxxxx', + 'xxxxxxxxx', + 'xxxxxxxxxx', + 'xxxxxxxxxxxx', + 'xxxxxxxxxxxxx', + 'xxxxxxxxxxxxxxx', + 'xxxxxxxxxxxxxxxxx', + 'xxxxxxxxxxxxxxxxxxx', + 'xxxxxxxxxxxxxxxxxxxxx', + 'xxxxxxxxxxxxxxxxxxxxxxx', + 'xxxxxxxxxxxxxxxxxxxxxxxxx', + 'xxxxxxxxxxxxxxxxxxxxx' ]; r.on('end', function() { t.same(reads, expect); t.end(); }); - var readSize = 1; + let readSize = 1; function flow() { - var res; + let res; while (null !== (res = r.read(readSize++))) { reads.push(res.toString()); } @@ -142,20 +142,20 @@ test('a most basic test', function(t) { }); test('pipe', function(t) { - var r = new TestReader(5); + const r = new TestReader(5); - var expect = [ 'xxxxx', - 'xxxxx', - 'xxxxx', - 'xxxxx', - 'xxxxx', - 'xxxxx', - 'xxxxx', - 'xxxxx', - 'xxxxx', - 'xxxxx' ]; + const expect = [ 'xxxxx', + 'xxxxx', + 'xxxxx', + 'xxxxx', + 'xxxxx', + 'xxxxx', + 'xxxxx', + 'xxxxx', + 'xxxxx', + 'xxxxx' ]; - var w = new TestWriter(); + const w = new TestWriter(); w.on('end', function(received) { t.same(received, expect); @@ -168,10 +168,10 @@ test('pipe', function(t) { [1, 2, 3, 4, 5, 6, 7, 8, 9].forEach(function(SPLIT) { test('unpipe', function(t) { - var r = new TestReader(5); + const r = new TestReader(5); // unpipe after 3 writes, then write to another stream instead. - var expect = [ 'xxxxx', + let expect = [ 'xxxxx', 'xxxxx', 'xxxxx', 'xxxxx', @@ -183,9 +183,9 @@ test('pipe', function(t) { 'xxxxx' ]; expect = [ expect.slice(0, SPLIT), expect.slice(SPLIT) ]; - var w = [ new TestWriter(), new TestWriter() ]; + const w = [ new TestWriter(), new TestWriter() ]; - var writes = SPLIT; + let writes = SPLIT; w[0].on('write', function() { if (--writes === 0) { r.unpipe(); @@ -196,10 +196,10 @@ test('pipe', function(t) { } }); - var ended = 0; + let ended = 0; - var ended0 = false; - var ended1 = false; + let ended0 = false; + let ended1 = false; w[0].on('end', function(results) { t.equal(ended0, false); ended0 = true; @@ -223,21 +223,21 @@ test('pipe', function(t) { // both writers should get the same exact data. test('multipipe', function(t) { - var r = new TestReader(5); - var w = [ new TestWriter(), new TestWriter() ]; - - var expect = [ 'xxxxx', - 'xxxxx', - 'xxxxx', - 'xxxxx', - 'xxxxx', - 'xxxxx', - 'xxxxx', - 'xxxxx', - 'xxxxx', - 'xxxxx' ]; - - var c = 2; + const r = new TestReader(5); + const w = [ new TestWriter(), new TestWriter() ]; + + const expect = [ 'xxxxx', + 'xxxxx', + 'xxxxx', + 'xxxxx', + 'xxxxx', + 'xxxxx', + 'xxxxx', + 'xxxxx', + 'xxxxx', + 'xxxxx' ]; + + let c = 2; w[0].on('end', function(received) { t.same(received, expect, 'first'); if (--c === 0) t.end(); @@ -254,10 +254,10 @@ test('multipipe', function(t) { [1, 2, 3, 4, 5, 6, 7, 8, 9].forEach(function(SPLIT) { test('multi-unpipe', function(t) { - var r = new TestReader(5); + const r = new TestReader(5); // unpipe after 3 writes, then write to another stream instead. - var expect = [ 'xxxxx', + let expect = [ 'xxxxx', 'xxxxx', 'xxxxx', 'xxxxx', @@ -269,9 +269,9 @@ test('multipipe', function(t) { 'xxxxx' ]; expect = [ expect.slice(0, SPLIT), expect.slice(SPLIT) ]; - var w = [ new TestWriter(), new TestWriter(), new TestWriter() ]; + const w = [ new TestWriter(), new TestWriter(), new TestWriter() ]; - var writes = SPLIT; + let writes = SPLIT; w[0].on('write', function() { if (--writes === 0) { r.unpipe(); @@ -280,7 +280,7 @@ test('multipipe', function(t) { } }); - var ended = 0; + let ended = 0; w[0].on('end', function(results) { ended++; @@ -302,16 +302,16 @@ test('multipipe', function(t) { test('back pressure respected', function(t) { function noop() {} - var r = new R({ objectMode: true }); + const r = new R({ objectMode: true }); r._read = noop; - var counter = 0; + let counter = 0; r.push(['one']); r.push(['two']); r.push(['three']); r.push(['four']); r.push(null); - var w1 = new R(); + const w1 = new R(); w1.write = function(chunk) { console.error('w1.emit("close")'); assert.equal(chunk[0], 'one'); @@ -325,9 +325,9 @@ test('back pressure respected', function(t) { r.pipe(w1); - var expected = ['two', 'two', 'three', 'three', 'four', 'four']; + const expected = ['two', 'two', 'three', 'three', 'four', 'four']; - var w2 = new R(); + let w2 = new R(); w2.write = function(chunk) { console.error('w2 write', chunk, counter); assert.equal(chunk[0], expected.shift()); @@ -349,7 +349,7 @@ test('back pressure respected', function(t) { }; w2.end = noop; - var w3 = new R(); + let w3 = new R(); w3.write = function(chunk) { console.error('w3 write', chunk, counter); assert.equal(chunk[0], expected.shift()); @@ -377,19 +377,19 @@ test('back pressure respected', function(t) { }); test('read(0) for ended streams', function(t) { - var r = new R(); - var written = false; - var ended = false; + const r = new R(); + let written = false; + let ended = false; r._read = function(n) {}; r.push(Buffer.from('foo')); r.push(null); - var v = r.read(0); + const v = r.read(0); assert.equal(v, null); - var w = new R(); + const w = new R(); w.write = function(buffer) { written = true; @@ -407,8 +407,8 @@ test('read(0) for ended streams', function(t) { }); test('sync _read ending', function(t) { - var r = new R(); - var called = false; + const r = new R(); + let called = false; r._read = function(n) { r.push(null); }; @@ -426,9 +426,9 @@ test('sync _read ending', function(t) { }); test('adding readable triggers data flow', function(t) { - var r = new R({ highWaterMark: 5 }); - var onReadable = false; - var readCalled = 0; + const r = new R({ highWaterMark: 5 }); + let onReadable = false; + let readCalled = 0; r._read = function(n) { if (readCalled++ === 2) @@ -450,9 +450,9 @@ test('adding readable triggers data flow', function(t) { }); test('chainable', function(t) { - var r = new R(); + const r = new R(); r._read = function() {}; - var r2 = r.setEncoding('utf8').pause().resume().pause(); + const r2 = r.setEncoding('utf8').pause().resume().pause(); t.equal(r, r2); t.end(); }); diff --git a/test/pummel/test-timer-wrap.js b/test/pummel/test-timer-wrap.js index 659912d1fc28ce..d30661716bd2b2 100644 --- a/test/pummel/test-timer-wrap.js +++ b/test/pummel/test-timer-wrap.js @@ -1,10 +1,10 @@ 'use strict'; const common = require('../common'); -var Timer = process.binding('timer_wrap').Timer; -var kOnTimeout = Timer.kOnTimeout; +const Timer = process.binding('timer_wrap').Timer; +const kOnTimeout = Timer.kOnTimeout; -var t = new Timer(); +const t = new Timer(); t.start(1000); diff --git a/test/pummel/test-timer-wrap2.js b/test/pummel/test-timer-wrap2.js index 87497b2685f5d3..4bae86f8cefb0c 100644 --- a/test/pummel/test-timer-wrap2.js +++ b/test/pummel/test-timer-wrap2.js @@ -4,5 +4,5 @@ require('../common'); // Test that allocating a timer does not increase the loop's reference // count. -var Timer = process.binding('timer_wrap').Timer; +const Timer = process.binding('timer_wrap').Timer; new Timer(); diff --git a/test/pummel/test-timers.js b/test/pummel/test-timers.js index 588d2327ff37dd..4555582371b9ff 100644 --- a/test/pummel/test-timers.js +++ b/test/pummel/test-timers.js @@ -1,21 +1,21 @@ 'use strict'; const common = require('../common'); -var assert = require('assert'); +const assert = require('assert'); -var WINDOW = 200; // why is does this need to be so big? +const WINDOW = 200; // why is does this need to be so big? -var interval_count = 0; +let interval_count = 0; // check that these don't blow up. clearTimeout(null); clearInterval(null); assert.equal(true, setTimeout instanceof Function); -var starttime = new Date(); +const starttime = new Date(); setTimeout(common.mustCall(function() { - var endtime = new Date(); + const endtime = new Date(); - var diff = endtime - starttime; + const diff = endtime - starttime; assert.ok(diff > 0); console.error('diff: ' + diff); @@ -23,18 +23,18 @@ setTimeout(common.mustCall(function() { }), 1000); // this timer shouldn't execute -var id = setTimeout(function() { assert.equal(true, false); }, 500); +const id = setTimeout(function() { assert.equal(true, false); }, 500); clearTimeout(id); setInterval(function() { interval_count += 1; - var endtime = new Date(); + const endtime = new Date(); - var diff = endtime - starttime; + const diff = endtime - starttime; assert.ok(diff > 0); console.error('diff: ' + diff); - var t = interval_count * 1000; + const t = interval_count * 1000; assert.equal(true, t - WINDOW < diff && diff < t + WINDOW); @@ -49,7 +49,7 @@ setTimeout(function(param) { assert.equal('test param', param); }, 1000, 'test param'); -var interval_count2 = 0; +let interval_count2 = 0; setInterval(function(param) { ++interval_count2; assert.equal('test param', param); @@ -65,7 +65,7 @@ setTimeout(function(param1, param2) { assert.equal('param2', param2); }, 1000, 'param1', 'param2'); -var interval_count3 = 0; +let interval_count3 = 0; setInterval(function(param1, param2) { ++interval_count3; assert.equal('param1', param1); @@ -76,14 +76,14 @@ setInterval(function(param1, param2) { }, 1000, 'param1', 'param2'); // setInterval(cb, 0) should be called multiple times. -var count4 = 0; -var interval4 = setInterval(function() { +let count4 = 0; +const interval4 = setInterval(function() { if (++count4 > 10) clearInterval(interval4); }, 0); // we should be able to clearTimeout multiple times without breakage. -var expectedTimeouts = 3; +let expectedTimeouts = 3; function t() { expectedTimeouts--; @@ -91,7 +91,7 @@ function t() { setTimeout(t, 200); setTimeout(t, 200); -var y = setTimeout(t, 200); +const y = setTimeout(t, 200); clearTimeout(y); setTimeout(t, 200); diff --git a/test/pummel/test-tls-ci-reneg-attack.js b/test/pummel/test-tls-ci-reneg-attack.js index 5075806c1085b6..dd2b43ed60278f 100644 --- a/test/pummel/test-tls-ci-reneg-attack.js +++ b/test/pummel/test-tls-ci-reneg-attack.js @@ -1,15 +1,15 @@ 'use strict'; -var common = require('../common'); -var assert = require('assert'); -var spawn = require('child_process').spawn; +const common = require('../common'); +const assert = require('assert'); +const spawn = require('child_process').spawn; if (!common.hasCrypto) { common.skip('missing crypto'); return; } -var tls = require('tls'); +const tls = require('tls'); -var fs = require('fs'); +const fs = require('fs'); if (!common.opensslCli) { common.skip('node compiled without OpenSSL CLI.'); @@ -17,7 +17,7 @@ if (!common.opensslCli) { } // renegotiation limits to test -var LIMITS = [0, 1, 2, 3, 5, 10, 16]; +const LIMITS = [0, 1, 2, 3, 5, 10, 16]; { let n = 0; @@ -30,14 +30,14 @@ var LIMITS = [0, 1, 2, 3, 5, 10, 16]; } function test(next) { - var options = { + const options = { cert: fs.readFileSync(common.fixturesDir + '/test_cert.pem'), key: fs.readFileSync(common.fixturesDir + '/test_key.pem') }; - var seenError = false; + let seenError = false; - var server = tls.createServer(options, function(conn) { + const server = tls.createServer(options, function(conn) { conn.on('error', function(err) { console.error('Caught exception: ' + err); assert(/TLS session renegotiation attack/.test(err)); @@ -48,8 +48,8 @@ function test(next) { }); server.listen(common.PORT, function() { - var args = ('s_client -connect 127.0.0.1:' + common.PORT).split(' '); - var child = spawn(common.opensslCli, args); + const args = ('s_client -connect 127.0.0.1:' + common.PORT).split(' '); + const child = spawn(common.opensslCli, args); //child.stdout.pipe(process.stdout); //child.stderr.pipe(process.stderr); @@ -58,8 +58,8 @@ function test(next) { child.stderr.resume(); // count handshakes, start the attack after the initial handshake is done - var handshakes = 0; - var renegs = 0; + let handshakes = 0; + let renegs = 0; child.stderr.on('data', function(data) { if (seenError) return; @@ -74,7 +74,7 @@ function test(next) { process.nextTick(next); }); - var closed = false; + let closed = false; child.stdin.on('error', function(err) { switch (err.code) { case 'ECONNRESET': diff --git a/test/pummel/test-tls-connect-memleak.js b/test/pummel/test-tls-connect-memleak.js index b55e33cee0afc4..b1d1f05190c39d 100644 --- a/test/pummel/test-tls-connect-memleak.js +++ b/test/pummel/test-tls-connect-memleak.js @@ -1,16 +1,16 @@ 'use strict'; // Flags: --expose-gc -var common = require('../common'); -var assert = require('assert'); +const common = require('../common'); +const assert = require('assert'); if (!common.hasCrypto) { common.skip('missing crypto'); return; } -var tls = require('tls'); +const tls = require('tls'); -var fs = require('fs'); +const fs = require('fs'); assert.strictEqual( typeof global.gc, @@ -38,10 +38,10 @@ tls.createServer({ } function done() { - var before = process.memoryUsage().rss; + const before = process.memoryUsage().rss; global.gc(); - var after = process.memoryUsage().rss; - var reclaimed = (before - after) / 1024; + const after = process.memoryUsage().rss; + const reclaimed = (before - after) / 1024; console.log('%d kB reclaimed', reclaimed); assert(reclaimed > 256 * 1024); // it's more like 512M on x64 process.exit(); diff --git a/test/pummel/test-tls-securepair-client.js b/test/pummel/test-tls-securepair-client.js index 7a1b8770132e96..75e7b400592191 100644 --- a/test/pummel/test-tls-securepair-client.js +++ b/test/pummel/test-tls-securepair-client.js @@ -1,7 +1,7 @@ 'use strict'; // -var common = require('../common'); +const common = require('../common'); if (!common.opensslCli) { common.skip('node compiled without OpenSSL CLI.'); @@ -13,12 +13,12 @@ if (!common.hasCrypto) { return; } -var join = require('path').join; -var net = require('net'); -var assert = require('assert'); -var fs = require('fs'); -var tls = require('tls'); -var spawn = require('child_process').spawn; +const join = require('path').join; +const net = require('net'); +const assert = require('assert'); +const fs = require('fs'); +const tls = require('tls'); +const spawn = require('child_process').spawn; test1(); @@ -40,22 +40,22 @@ function test2() { function test(keyfn, certfn, check, next) { keyfn = join(common.fixturesDir, keyfn); - var key = fs.readFileSync(keyfn).toString(); + const key = fs.readFileSync(keyfn).toString(); certfn = join(common.fixturesDir, certfn); - var cert = fs.readFileSync(certfn).toString(); + const cert = fs.readFileSync(certfn).toString(); - var server = spawn(common.opensslCli, ['s_server', - '-accept', common.PORT, - '-cert', certfn, - '-key', keyfn]); + const server = spawn(common.opensslCli, ['s_server', + '-accept', common.PORT, + '-cert', certfn, + '-key', keyfn]); server.stdout.pipe(process.stdout); server.stderr.pipe(process.stdout); - var state = 'WAIT-ACCEPT'; + let state = 'WAIT-ACCEPT'; - var serverStdoutBuffer = ''; + let serverStdoutBuffer = ''; server.stdout.setEncoding('utf8'); server.stdout.on('data', function(s) { serverStdoutBuffer += s; @@ -86,13 +86,13 @@ function test(keyfn, certfn, check, next) { }); - var timeout = setTimeout(function() { + const timeout = setTimeout(function() { server.kill(); process.exit(1); }, 5000); - var gotWriteCallback = false; - var serverExitCode = -1; + let gotWriteCallback = false; + let serverExitCode = -1; server.on('exit', function(code) { serverExitCode = code; @@ -102,12 +102,12 @@ function test(keyfn, certfn, check, next) { function startClient() { - var s = new net.Stream(); + const s = new net.Stream(); - var sslcontext = tls.createSecureContext({key: key, cert: cert}); + const sslcontext = tls.createSecureContext({key: key, cert: cert}); sslcontext.context.setCiphers('RC4-SHA:AES128-SHA:AES256-SHA'); - var pair = tls.createSecurePair(sslcontext, false); + const pair = tls.createSecurePair(sslcontext, false); assert.ok(pair.encrypted.writable); assert.ok(pair.cleartext.writable); diff --git a/test/pummel/test-tls-server-large-request.js b/test/pummel/test-tls-server-large-request.js index 66d700ae4bc6a9..f79c4d95cfa031 100644 --- a/test/pummel/test-tls-server-large-request.js +++ b/test/pummel/test-tls-server-large-request.js @@ -1,20 +1,20 @@ 'use strict'; -var common = require('../common'); -var assert = require('assert'); +const common = require('../common'); +const assert = require('assert'); if (!common.hasCrypto) { common.skip('missing crypto'); return; } -var tls = require('tls'); +const tls = require('tls'); -var fs = require('fs'); -var stream = require('stream'); -var util = require('util'); +const fs = require('fs'); +const stream = require('stream'); +const util = require('util'); -var request = Buffer.from(new Array(1024 * 256).join('ABCD')); // 1mb +const request = Buffer.from(new Array(1024 * 256).join('ABCD')); // 1mb -var options = { +const options = { key: fs.readFileSync(common.fixturesDir + '/keys/agent1-key.pem'), cert: fs.readFileSync(common.fixturesDir + '/keys/agent1-cert.pem') }; @@ -35,14 +35,14 @@ Mediator.prototype._write = function _write(data, enc, cb) { } }; -var mediator = new Mediator(); +const mediator = new Mediator(); -var server = tls.Server(options, common.mustCall(function(socket) { +let server = tls.Server(options, common.mustCall(function(socket) { socket.pipe(mediator); })); server.listen(common.PORT, common.mustCall(function() { - var client1 = tls.connect({ + const client1 = tls.connect({ port: common.PORT, rejectUnauthorized: false }, common.mustCall(function() { diff --git a/test/pummel/test-tls-session-timeout.js b/test/pummel/test-tls-session-timeout.js index c23a8afcf7fe9a..c194188b3682a9 100644 --- a/test/pummel/test-tls-session-timeout.js +++ b/test/pummel/test-tls-session-timeout.js @@ -1,5 +1,5 @@ 'use strict'; -var common = require('../common'); +const common = require('../common'); if (!common.opensslCli) { common.skip('node compiled without OpenSSL CLI.'); @@ -22,19 +22,19 @@ doTest(); // that we used has expired by now. function doTest() { - var assert = require('assert'); - var tls = require('tls'); - var fs = require('fs'); - var join = require('path').join; - var spawn = require('child_process').spawn; + const assert = require('assert'); + const tls = require('tls'); + const fs = require('fs'); + const join = require('path').join; + const spawn = require('child_process').spawn; - var SESSION_TIMEOUT = 1; + const SESSION_TIMEOUT = 1; - var keyFile = join(common.fixturesDir, 'agent.key'); - var certFile = join(common.fixturesDir, 'agent.crt'); - var key = fs.readFileSync(keyFile); - var cert = fs.readFileSync(certFile); - var options = { + const keyFile = join(common.fixturesDir, 'agent.key'); + const certFile = join(common.fixturesDir, 'agent.crt'); + const key = fs.readFileSync(keyFile); + const cert = fs.readFileSync(certFile); + const options = { key: key, cert: cert, ca: [cert], @@ -47,41 +47,41 @@ function doTest() { // file containing a proper serialization of a session ticket. // To avoid a source control diff, we copy the ticket to a temporary file. - var sessionFileName = (function() { - var ticketFileName = 'tls-session-ticket.txt'; - var fixturesPath = join(common.fixturesDir, ticketFileName); - var tmpPath = join(common.tmpDir, ticketFileName); + const sessionFileName = (function() { + const ticketFileName = 'tls-session-ticket.txt'; + const fixturesPath = join(common.fixturesDir, ticketFileName); + const tmpPath = join(common.tmpDir, ticketFileName); fs.writeFileSync(tmpPath, fs.readFileSync(fixturesPath)); return tmpPath; }()); // Expects a callback -- cb(connectionType : enum ['New'|'Reused']) - var Client = function(cb) { - var flags = [ + const Client = function(cb) { + const flags = [ 's_client', '-connect', 'localhost:' + common.PORT, '-sess_in', sessionFileName, '-sess_out', sessionFileName ]; - var client = spawn(common.opensslCli, flags, { + const client = spawn(common.opensslCli, flags, { stdio: ['ignore', 'pipe', 'ignore'] }); - var clientOutput = ''; + let clientOutput = ''; client.stdout.on('data', function(data) { clientOutput += data.toString(); }); client.on('exit', function(code) { - var connectionType; - var grepConnectionType = function(line) { - var matches = line.match(/(New|Reused), /); + let connectionType; + const grepConnectionType = function(line) { + const matches = line.match(/(New|Reused), /); if (matches) { connectionType = matches[1]; return true; } }; - var lines = clientOutput.split('\n'); + const lines = clientOutput.split('\n'); if (!lines.some(grepConnectionType)) { throw new Error('unexpected output from openssl client'); } @@ -89,7 +89,7 @@ function doTest() { }); }; - var server = tls.createServer(options, function(cleartext) { + const server = tls.createServer(options, function(cleartext) { cleartext.on('error', function(er) { if (er.code !== 'ECONNRESET') throw er; diff --git a/test/pummel/test-tls-throttle.js b/test/pummel/test-tls-throttle.js index a93793989f0b2b..939a9fc3b0fe8a 100644 --- a/test/pummel/test-tls-throttle.js +++ b/test/pummel/test-tls-throttle.js @@ -2,33 +2,33 @@ // Server sends a large string. Client counts bytes and pauses every few // seconds. Makes sure that pause and resume work properly. -var common = require('../common'); -var assert = require('assert'); +const common = require('../common'); +const assert = require('assert'); if (!common.hasCrypto) { common.skip('missing crypto'); return; } -var tls = require('tls'); -var fs = require('fs'); +const tls = require('tls'); +const fs = require('fs'); process.stdout.write('build body...'); -var body = 'hello world\n'.repeat(1024 * 1024); +const body = 'hello world\n'.repeat(1024 * 1024); process.stdout.write('done\n'); -var options = { +const options = { key: fs.readFileSync(common.fixturesDir + '/keys/agent2-key.pem'), cert: fs.readFileSync(common.fixturesDir + '/keys/agent2-cert.pem') }; -var server = tls.Server(options, common.mustCall(function(socket) { +const server = tls.Server(options, common.mustCall(function(socket) { socket.end(body); })); -var recvCount = 0; +let recvCount = 0; server.listen(common.PORT, function() { - var client = tls.connect({ + const client = tls.connect({ port: common.PORT, rejectUnauthorized: false }); @@ -58,7 +58,7 @@ function displayCounts() { } -var timeout = setTimeout(displayCounts, 10 * 1000); +let timeout = setTimeout(displayCounts, 10 * 1000); process.on('exit', function() { diff --git a/test/pummel/test-vm-memleak.js b/test/pummel/test-vm-memleak.js index c6623991922da9..8503e2389b44a7 100644 --- a/test/pummel/test-vm-memleak.js +++ b/test/pummel/test-vm-memleak.js @@ -2,23 +2,23 @@ // Flags: --max_old_space_size=32 require('../common'); -var assert = require('assert'); +const assert = require('assert'); -var start = Date.now(); -var maxMem = 0; +const start = Date.now(); +let maxMem = 0; -var ok = process.execArgv.some(function(arg) { +const ok = process.execArgv.some(function(arg) { return arg === '--max_old_space_size=32'; }); assert(ok, 'Run this test with --max_old_space_size=32.'); -var interval = setInterval(function() { +const interval = setInterval(function() { try { require('vm').runInNewContext('throw 1;'); } catch (e) { } - var rss = process.memoryUsage().rss; + const rss = process.memoryUsage().rss; maxMem = Math.max(rss, maxMem); if (Date.now() - start > 5 * 1000) { @@ -30,7 +30,7 @@ var interval = setInterval(function() { }, 1); function testContextLeak() { - for (var i = 0; i < 1000; i++) + for (let i = 0; i < 1000; i++) require('vm').createContext({}); } diff --git a/test/pummel/test-watch-file.js b/test/pummel/test-watch-file.js index 8b79ef8ede4a63..90909875d74a15 100644 --- a/test/pummel/test-watch-file.js +++ b/test/pummel/test-watch-file.js @@ -1,9 +1,9 @@ 'use strict'; -var common = require('../common'); -var assert = require('assert'); +const common = require('../common'); +const assert = require('assert'); -var fs = require('fs'); -var path = require('path'); +const fs = require('fs'); +const path = require('path'); const f = path.join(common.fixturesDir, 'x.txt'); diff --git a/test/sequential/test-child-process-execsync.js b/test/sequential/test-child-process-execsync.js index 137ddbda425f2c..20a35b98b36c6f 100644 --- a/test/sequential/test-child-process-execsync.js +++ b/test/sequential/test-child-process-execsync.js @@ -1,16 +1,16 @@ 'use strict'; -var common = require('../common'); -var assert = require('assert'); +const common = require('../common'); +const assert = require('assert'); -var execSync = require('child_process').execSync; -var execFileSync = require('child_process').execFileSync; +const execSync = require('child_process').execSync; +const execFileSync = require('child_process').execFileSync; -var TIMER = 200; -var SLEEP = 2000; +const TIMER = 200; +const SLEEP = 2000; -var start = Date.now(); -var err; -var caught = false; +const start = Date.now(); +let err; +let caught = false; // Verify that stderr is not accessed when a bad shell is used assert.throws( @@ -24,9 +24,10 @@ assert.throws( 'execFileSync did not throw the expected exception!' ); +let cmd, ret; try { - var cmd = `"${process.execPath}" -e "setTimeout(function(){}, ${SLEEP});"`; - var ret = execSync(cmd, {timeout: TIMER}); + cmd = `"${process.execPath}" -e "setTimeout(function(){}, ${SLEEP});"`; + ret = execSync(cmd, {timeout: TIMER}); } catch (e) { caught = true; assert.strictEqual(e.errno, 'ETIMEDOUT'); @@ -34,7 +35,7 @@ try { } finally { assert.strictEqual(ret, undefined, 'we should not have a return value'); assert.strictEqual(caught, true, 'execSync should throw'); - var end = Date.now() - start; + const end = Date.now() - start; assert(end < SLEEP); assert(err.status > 128 || err.signal); } @@ -43,8 +44,8 @@ assert.throws(function() { execSync('iamabadcommand'); }, /Command failed: iamabadcommand/); -var msg = 'foobar'; -var msgBuf = Buffer.from(msg + '\n'); +const msg = 'foobar'; +const msgBuf = Buffer.from(msg + '\n'); // console.log ends every line with just '\n', even on Windows. @@ -59,7 +60,7 @@ ret = execSync(cmd, { encoding: 'utf8' }); assert.strictEqual(ret, msg + '\n', 'execSync encoding result should match'); -var args = [ +const args = [ '-e', `console.log("${msg}");` ]; diff --git a/test/sequential/test-debugger-debug-brk.js b/test/sequential/test-debugger-debug-brk.js index 3b54f853bc8de3..26c3418171e8df 100644 --- a/test/sequential/test-debugger-debug-brk.js +++ b/test/sequential/test-debugger-debug-brk.js @@ -1,16 +1,16 @@ 'use strict'; -var common = require('../common'); -var assert = require('assert'); -var spawn = require('child_process').spawn; +const common = require('../common'); +const assert = require('assert'); +const spawn = require('child_process').spawn; -var script = common.fixturesDir + '/empty.js'; +const script = common.fixturesDir + '/empty.js'; function fail() { assert(0); // `node --debug-brk script.js` should not quit } function test(arg) { - var child = spawn(process.execPath, [arg, script]); + const child = spawn(process.execPath, [arg, script]); child.on('exit', fail); // give node time to start up the debugger diff --git a/test/sequential/test-deprecation-flags.js b/test/sequential/test-deprecation-flags.js index e9f5ee673d23bd..eb5c1a3ae6261f 100644 --- a/test/sequential/test-deprecation-flags.js +++ b/test/sequential/test-deprecation-flags.js @@ -38,7 +38,7 @@ execFile(node, traceDep, function(er, stdout, stderr) { console.error('--trace-deprecation: show stack'); assert.equal(er, null); assert.equal(stdout, ''); - var stack = stderr.trim().split('\n'); + const stack = stderr.trim().split('\n'); // just check the top and bottom. assert(/util.debug is deprecated. Use console.error instead./.test(stack[1])); assert(/DEBUG: This is deprecated/.test(stack[0])); diff --git a/test/sequential/test-fs-readfile-tostring-fail.js b/test/sequential/test-fs-readfile-tostring-fail.js index 8ed9658a25889a..593b8da0fd8afa 100644 --- a/test/sequential/test-fs-readfile-tostring-fail.js +++ b/test/sequential/test-fs-readfile-tostring-fail.js @@ -23,7 +23,7 @@ const stream = fs.createWriteStream(file, { const size = kStringMaxLength / 200; const a = Buffer.alloc(size, 'a'); -for (var i = 0; i < 201; i++) { +for (let i = 0; i < 201; i++) { stream.write(a); } diff --git a/test/sequential/test-http-regr-gh-2928.js b/test/sequential/test-http-regr-gh-2928.js index b4ae7054d72bb9..190966083e3f97 100644 --- a/test/sequential/test-http-regr-gh-2928.js +++ b/test/sequential/test-http-regr-gh-2928.js @@ -11,11 +11,11 @@ const net = require('net'); const COUNT = httpCommon.parsers.max + 1; const parsers = new Array(COUNT); -for (var i = 0; i < parsers.length; i++) +for (let i = 0; i < parsers.length; i++) parsers[i] = httpCommon.parsers.alloc(); -var gotRequests = 0; -var gotResponses = 0; +let gotRequests = 0; +let gotResponses = 0; function execAndClose() { if (parsers.length === 0) @@ -50,7 +50,7 @@ function execAndClose() { }; } -var server = net.createServer(function(c) { +const server = net.createServer(function(c) { if (++gotRequests === COUNT) server.close(); c.end('HTTP/1.1 200 OK\r\n\r\n', function() { diff --git a/test/sequential/test-module-loading.js b/test/sequential/test-module-loading.js index 5e9c6e1bd4b787..5a4332b471c5ee 100644 --- a/test/sequential/test-module-loading.js +++ b/test/sequential/test-module-loading.js @@ -1,8 +1,8 @@ 'use strict'; require('../common'); -var assert = require('assert'); -var path = require('path'); -var fs = require('fs'); +const assert = require('assert'); +const path = require('path'); +const fs = require('fs'); console.error('load test-module-loading.js'); @@ -15,21 +15,21 @@ assert.strictEqual(process.mainModule, module, require('../fixtures/not-main-module.js'); // require a file with a request that includes the extension -var a_js = require('../fixtures/a.js'); +const a_js = require('../fixtures/a.js'); assert.strictEqual(42, a_js.number); // require a file without any extensions -var foo_no_ext = require('../fixtures/foo'); +const foo_no_ext = require('../fixtures/foo'); assert.strictEqual('ok', foo_no_ext.foo); -var a = require('../fixtures/a'); -var c = require('../fixtures/b/c'); -var d = require('../fixtures/b/d'); -var d2 = require('../fixtures/b/d'); +const a = require('../fixtures/a'); +const c = require('../fixtures/b/c'); +const d = require('../fixtures/b/d'); +const d2 = require('../fixtures/b/d'); // Absolute -var d3 = require(path.join(__dirname, '../fixtures/b/d')); +const d3 = require(path.join(__dirname, '../fixtures/b/d')); // Relative -var d4 = require('../fixtures/b/d'); +const d4 = require('../fixtures/b/d'); assert.strictEqual(false, false, 'testing the test program.'); @@ -94,13 +94,13 @@ require('../fixtures/node_modules/foo'); console.error('test name clashes'); // this one exists and should import the local module -var my_path = require('../fixtures/path'); +const my_path = require('../fixtures/path'); assert.ok(my_path.path_func instanceof Function); // this one does not exist and should throw assert.throws(function() { require('./utils'); }, /^Error: Cannot find module '.\/utils'$/); -var errorThrown = false; +let errorThrown = false; try { require('../fixtures/throws_error'); } catch (e) { @@ -112,7 +112,7 @@ assert.strictEqual(require('path').dirname(__filename), __dirname); console.error('load custom file types with extensions'); require.extensions['.test'] = function(module, filename) { - var content = fs.readFileSync(filename).toString(); + let content = fs.readFileSync(filename).toString(); assert.strictEqual('this is custom source\n', content); content = content.replace('this is custom source', 'exports.test = \'passed\''); @@ -174,13 +174,13 @@ assert.strictEqual(require(loadOrder + 'file9').file9, 'file9/index.reg2', msg); // make sure that module.require() is the same as // doing require() inside of that module. -var parent = require('../fixtures/module-require/parent/'); -var child = require('../fixtures/module-require/child/'); +const parent = require('../fixtures/module-require/parent/'); +const child = require('../fixtures/module-require/child/'); assert.strictEqual(child.loaded, parent.loaded); // #1357 Loading JSON files with require() -var json = require('../fixtures/packages/main/package.json'); +const json = require('../fixtures/packages/main/package.json'); assert.deepStrictEqual(json, { name: 'package-name', version: '1.2.3', @@ -192,8 +192,8 @@ assert.deepStrictEqual(json, { // modules that we've required, and that all of them contain // the appropriate children, and so on. -var children = module.children.reduce(function red(set, child) { - var id = path.relative(path.dirname(__dirname), child.id); +const children = module.children.reduce(function red(set, child) { + let id = path.relative(path.dirname(__dirname), child.id); id = id.replace(/\\/g, '/'); set[id] = child.children.reduce(red, {}); return set; diff --git a/test/sequential/test-net-GH-5504.js b/test/sequential/test-net-GH-5504.js index 3ebf9db548d4db..a7f64c2e73da10 100644 --- a/test/sequential/test-net-GH-5504.js +++ b/test/sequential/test-net-GH-5504.js @@ -1,5 +1,5 @@ 'use strict'; -var common = require('../common'); +const common = require('../common'); // this test only fails with CentOS 6.3 using kernel version 2.6.32 // On other linuxes and darwin, the `read` call gets an ECONNRESET in @@ -18,8 +18,8 @@ switch (process.argv[2]) { } function server() { - var net = require('net'); - var content = Buffer.alloc(64 * 1024 * 1024, '#'); + const net = require('net'); + const content = Buffer.alloc(64 * 1024 * 1024, '#'); net.createServer(function(socket) { this.close(); socket.on('end', function() { @@ -35,8 +35,8 @@ function server() { } function client() { - var net = require('net'); - var client = net.connect({ + const net = require('net'); + const client = net.connect({ host: common.localhostIPv4, port: common.PORT }, function() { @@ -45,15 +45,15 @@ function client() { } function parent() { - var spawn = require('child_process').spawn; - var node = process.execPath; + const spawn = require('child_process').spawn; + const node = process.execPath; - var s = spawn(node, [__filename, 'server'], { + const s = spawn(node, [__filename, 'server'], { env: Object.assign(process.env, { NODE_DEBUG: 'net' }) }); - var c; + let c; wrap(s.stderr, process.stderr, 'SERVER 2>'); wrap(s.stdout, process.stdout, 'SERVER 1>'); diff --git a/test/sequential/test-regress-GH-1697.js b/test/sequential/test-regress-GH-1697.js index 1511cfd1cfcf6b..d99acf9e468bb3 100644 --- a/test/sequential/test-regress-GH-1697.js +++ b/test/sequential/test-regress-GH-1697.js @@ -6,7 +6,7 @@ const cp = require('child_process'); if (process.argv[2] === 'server') { // Server - var server = net.createServer(function(conn) { + const server = net.createServer(function(conn) { conn.on('data', function(data) { console.log('server received ' + data.length + ' bytes'); }); @@ -23,22 +23,22 @@ if (process.argv[2] === 'server') { } else { // Client - var serverProcess = cp.spawn(process.execPath, [process.argv[1], 'server']); + const serverProcess = cp.spawn(process.execPath, [process.argv[1], 'server']); serverProcess.stdout.pipe(process.stdout); serverProcess.stderr.pipe(process.stdout); serverProcess.stdout.once('data', function() { - var client = net.createConnection(common.PORT, '127.0.0.1'); + const client = net.createConnection(common.PORT, '127.0.0.1'); client.on('connect', function() { const alot = Buffer.allocUnsafe(1024); const alittle = Buffer.allocUnsafe(1); - for (var i = 0; i < 100; i++) { + for (let i = 0; i < 100; i++) { client.write(alot); } // Block the event loop for 1 second - var start = (new Date()).getTime(); + const start = (new Date()).getTime(); while ((new Date()).getTime() < start + 1000) {} client.write(alittle); diff --git a/test/sequential/test-regress-GH-1726.js b/test/sequential/test-regress-GH-1726.js index c5f0bba1335264..c464193b23f3e4 100644 --- a/test/sequential/test-regress-GH-1726.js +++ b/test/sequential/test-regress-GH-1726.js @@ -5,11 +5,11 @@ // https://github.com/joyent/node/issues/1726 require('../common'); -var assert = require('assert'); -var ch = require('child_process'); +const assert = require('assert'); +const ch = require('child_process'); -var gen = +(process.argv[2] || 0); -var maxGen = 5; +const gen = +(process.argv[2] || 0); +const maxGen = 5; if (gen === maxGen) { @@ -17,7 +17,7 @@ if (gen === maxGen) { return; } -var child = ch.spawn(process.execPath, [__filename, gen + 1], { +const child = ch.spawn(process.execPath, [__filename, gen + 1], { stdio: [ 'ignore', 'pipe', 'ignore' ] }); assert.ok(!child.stdin); diff --git a/test/sequential/test-regress-GH-4015.js b/test/sequential/test-regress-GH-4015.js index 7f0e03f9ac08e1..249817de1d2068 100644 --- a/test/sequential/test-regress-GH-4015.js +++ b/test/sequential/test-regress-GH-4015.js @@ -1,10 +1,10 @@ 'use strict'; -var common = require('../common'); -var assert = require('assert'); -var exec = require('child_process').exec; +const common = require('../common'); +const assert = require('assert'); +const exec = require('child_process').exec; -var cmd = '"' + process.execPath + '" ' + - '"' + common.fixturesDir + '/test-regress-GH-4015.js"'; +const cmd = '"' + process.execPath + '" ' + + '"' + common.fixturesDir + '/test-regress-GH-4015.js"'; exec(cmd, function(err, stdout, stderr) { assert(/RangeError: Maximum call stack size exceeded/.test(stderr)); diff --git a/test/sequential/test-regress-GH-4027.js b/test/sequential/test-regress-GH-4027.js index aa1ec12c30f609..87a8861ac35477 100644 --- a/test/sequential/test-regress-GH-4027.js +++ b/test/sequential/test-regress-GH-4027.js @@ -1,12 +1,12 @@ 'use strict'; -var common = require('../common'); -var assert = require('assert'); -var path = require('path'); -var fs = require('fs'); +const common = require('../common'); +const assert = require('assert'); +const path = require('path'); +const fs = require('fs'); common.refreshTmpDir(); -var filename = path.join(common.tmpDir, 'watched'); +const filename = path.join(common.tmpDir, 'watched'); fs.writeFileSync(filename, 'quis custodiet ipsos custodes'); setTimeout(fs.unlinkSync, 100, filename); diff --git a/test/sequential/test-regress-GH-784.js b/test/sequential/test-regress-GH-784.js index 0c70337de7f146..c9b630b0c81755 100644 --- a/test/sequential/test-regress-GH-784.js +++ b/test/sequential/test-regress-GH-784.js @@ -7,13 +7,13 @@ // The next two are made with server on - they should come back successful. // The next two are made with the server off - and so on. Without the fix // we were experiencing parse errors and instead of ECONNREFUSED. -var common = require('../common'); -var http = require('http'); -var assert = require('assert'); +const common = require('../common'); +const http = require('http'); +const assert = require('assert'); -var server = http.createServer(function(req, res) { - var body = ''; +const server = http.createServer(function(req, res) { + let body = ''; req.setEncoding('utf8'); req.on('data', function(chunk) { @@ -43,7 +43,7 @@ function serverOff() { pingping(); } -var responses = []; +const responses = []; function afterPing(result) { @@ -81,14 +81,14 @@ function afterPing(result) { function ping() { console.error('making req'); - var opt = { + const opt = { port: common.PORT, path: '/ping', method: 'POST' }; - var req = http.request(opt, function(res) { - var body = ''; + const req = http.request(opt, function(res) { + let body = ''; res.setEncoding('utf8'); res.on('data', function(chunk) { @@ -105,8 +105,8 @@ function ping() { req.end('PING'); - var gotEnd = false; - var hadError = false; + let gotEnd = false; + let hadError = false; req.on('error', function(error) { console.log('Error making ping req: ' + error); diff --git a/test/sequential/test-regress-GH-877.js b/test/sequential/test-regress-GH-877.js index 5b0aac802e16a3..06c839aa483fa8 100644 --- a/test/sequential/test-regress-GH-877.js +++ b/test/sequential/test-regress-GH-877.js @@ -1,30 +1,30 @@ 'use strict'; -var common = require('../common'); -var http = require('http'); -var assert = require('assert'); +const common = require('../common'); +const http = require('http'); +const assert = require('assert'); -var N = 20; -var responses = 0; -var maxQueued = 0; +const N = 20; +let responses = 0; +let maxQueued = 0; -var agent = http.globalAgent; +const agent = http.globalAgent; agent.maxSockets = 10; -var server = http.createServer(function(req, res) { +const server = http.createServer(function(req, res) { res.writeHead(200); res.end('Hello World\n'); }); -var addrString = agent.getName({ host: '127.0.0.1', port: common.PORT }); +const addrString = agent.getName({ host: '127.0.0.1', port: common.PORT }); server.listen(common.PORT, '127.0.0.1', function() { - for (var i = 0; i < N; i++) { - var options = { + for (let i = 0; i < N; i++) { + const options = { host: '127.0.0.1', port: common.PORT }; - var req = http.get(options, function(res) { + const req = http.get(options, function(res) { if (++responses === N) { server.close(); } @@ -37,7 +37,7 @@ server.listen(common.PORT, '127.0.0.1', function() { agent.maxSockets + ' queued: ' + (agent.requests[addrString] ? agent.requests[addrString].length : 0)); - var agentRequests = agent.requests[addrString] ? + const agentRequests = agent.requests[addrString] ? agent.requests[addrString].length : 0; if (maxQueued < agentRequests) { diff --git a/test/sequential/test-repl-timeout-throw.js b/test/sequential/test-repl-timeout-throw.js index 0188b3b8c502d8..fbe593230cf1ba 100644 --- a/test/sequential/test-repl-timeout-throw.js +++ b/test/sequential/test-repl-timeout-throw.js @@ -8,7 +8,7 @@ const child = spawn(process.execPath, [ '-i' ], { stdio: [null, null, 2] }); -var stdout = ''; +let stdout = ''; child.stdout.setEncoding('utf8'); child.stdout.on('data', function(c) { process.stdout.write(c); @@ -30,7 +30,7 @@ child.stdout.once('data', function() { setTimeout(fsTest, 50); function fsTest() { - var f = JSON.stringify(__filename); + const f = JSON.stringify(__filename); child.stdin.write('fs.readFile(' + f + ', thrower);\n'); setTimeout(eeTest, 50); } @@ -54,6 +54,6 @@ child.stdout.once('data', function() { child.on('close', function(c) { assert.strictEqual(c, 0); // make sure we got 3 throws, in the end. - var lastLine = stdout.trim().split(/\r?\n/).pop(); + const lastLine = stdout.trim().split(/\r?\n/).pop(); assert.strictEqual(lastLine, '> 3'); }); diff --git a/test/sequential/test-require-cache-without-stat.js b/test/sequential/test-require-cache-without-stat.js index 2571583f7690b5..b591f1746b62d4 100644 --- a/test/sequential/test-require-cache-without-stat.js +++ b/test/sequential/test-require-cache-without-stat.js @@ -2,17 +2,17 @@ // We've experienced a regression where the module loader stats a bunch of // directories on require() even if it's been called before. The require() // should caching the request. -var common = require('../common'); -var fs = require('fs'); -var assert = require('assert'); +const common = require('../common'); +const fs = require('fs'); +const assert = require('assert'); -var counter = 0; +let counter = 0; // Switch out the two stat implementations so that they increase a counter // each time they are called. -var _statSync = fs.statSync; -var _stat = fs.stat; +const _statSync = fs.statSync; +const _stat = fs.stat; fs.statSync = function() { counter++; @@ -31,7 +31,7 @@ require('./../fixtures/a.js'); require('http'); console.log('counterBefore = %d', counter); -var counterBefore = counter; +const counterBefore = counter; // Now load the module a bunch of times with equivalent paths. // stat should not be called. @@ -47,6 +47,6 @@ for (let i = 0; i < 100; i++) { } console.log('counterAfter = %d', counter); -var counterAfter = counter; +const counterAfter = counter; assert.equal(counterBefore, counterAfter); diff --git a/test/sequential/test-stream2-fs.js b/test/sequential/test-stream2-fs.js index 7baba6e63b81b0..2891335c813562 100644 --- a/test/sequential/test-stream2-fs.js +++ b/test/sequential/test-stream2-fs.js @@ -1,19 +1,19 @@ 'use strict'; -var common = require('../common'); -var assert = require('assert'); +const common = require('../common'); +const assert = require('assert'); -var fs = require('fs'); -var FSReadable = fs.ReadStream; +const fs = require('fs'); +const FSReadable = fs.ReadStream; -var path = require('path'); -var file = path.resolve(common.fixturesDir, 'x1024.txt'); +const path = require('path'); +const file = path.resolve(common.fixturesDir, 'x1024.txt'); -var size = fs.statSync(file).size; +const size = fs.statSync(file).size; -var expectLengths = [1024]; +const expectLengths = [1024]; -var util = require('util'); -var Stream = require('stream'); +const util = require('util'); +const Stream = require('stream'); util.inherits(TestWriter, Stream); @@ -34,8 +34,8 @@ TestWriter.prototype.end = function(c) { this.emit('results', this.buffer); }; -var r = new FSReadable(file); -var w = new TestWriter(); +const r = new FSReadable(file); +const w = new TestWriter(); w.on('results', function(res) { console.error(res, w.length); diff --git a/test/sequential/test-stream2-stderr-sync.js b/test/sequential/test-stream2-stderr-sync.js index c7daaa6b083205..0b86790d62058d 100644 --- a/test/sequential/test-stream2-stderr-sync.js +++ b/test/sequential/test-stream2-stderr-sync.js @@ -4,12 +4,12 @@ require('../common'); function parent() { - var spawn = require('child_process').spawn; - var assert = require('assert'); - var i = 0; + const spawn = require('child_process').spawn; + const assert = require('assert'); + let i = 0; children.forEach(function(_, c) { - var child = spawn(process.execPath, [__filename, '' + c]); - var err = ''; + const child = spawn(process.execPath, [__filename, '' + c]); + let err = ''; child.stderr.on('data', function(c) { err += c; @@ -42,8 +42,8 @@ function child1() { // using a net socket function child2() { - var net = require('net'); - var socket = new net.Socket({ + const net = require('net'); + const socket = new net.Socket({ fd: 2, readable: false, writable: true}); @@ -62,7 +62,7 @@ function child4() { process.stderr.write('child 4\nfoo\nbar\nbaz\n'); } -var children = [ child0, child1, child2, child3, child4 ]; +let children = [ child0, child1, child2, child3, child4 ]; if (!process.argv[2]) { parent(); diff --git a/test/sequential/test-timers-blocking-callback.js b/test/sequential/test-timers-blocking-callback.js index e4e85cddc6302d..73b0f13997716d 100644 --- a/test/sequential/test-timers-blocking-callback.js +++ b/test/sequential/test-timers-blocking-callback.js @@ -28,9 +28,9 @@ const Timer = process.binding('timer_wrap').Timer; const TIMEOUT = 100; -var nbBlockingCallbackCalls = 0; -var latestDelay = 0; -var timeCallbackScheduled = 0; +let nbBlockingCallbackCalls = 0; +let latestDelay = 0; +let timeCallbackScheduled = 0; function initTest() { nbBlockingCallbackCalls = 0; diff --git a/test/sequential/test-util-debug.js b/test/sequential/test-util-debug.js index 1159278efa475d..515f6e32692c5b 100644 --- a/test/sequential/test-util-debug.js +++ b/test/sequential/test-util-debug.js @@ -1,6 +1,6 @@ 'use strict'; const common = require('../common'); -var assert = require('assert'); +const assert = require('assert'); if (process.argv[2] === 'child') child(); @@ -17,27 +17,27 @@ function parent() { } function test(environ, shouldWrite) { - var expectErr = ''; + let expectErr = ''; if (shouldWrite) { expectErr = 'TUD %PID%: this { is: \'a\' } /debugging/\n' + 'TUD %PID%: number=1234 string=asdf obj={"foo":"bar"}\n'; } - var expectOut = 'ok\n'; + const expectOut = 'ok\n'; - var spawn = require('child_process').spawn; - var child = spawn(process.execPath, [__filename, 'child'], { + const spawn = require('child_process').spawn; + const child = spawn(process.execPath, [__filename, 'child'], { env: Object.assign(process.env, { NODE_DEBUG: environ }) }); expectErr = expectErr.split('%PID%').join(child.pid); - var err = ''; + let err = ''; child.stderr.setEncoding('utf8'); child.stderr.on('data', function(c) { err += c; }); - var out = ''; + let out = ''; child.stdout.setEncoding('utf8'); child.stdout.on('data', function(c) { out += c; @@ -53,8 +53,8 @@ function test(environ, shouldWrite) { function child() { - var util = require('util'); - var debug = util.debuglog('tud'); + const util = require('util'); + const debug = util.debuglog('tud'); debug('this', { is: 'a' }, /debugging/); debug('number=%d string=%s obj=%j', 1234, 'asdf', { foo: 'bar' }); console.log('ok'); diff --git a/test/sequential/test-vm-timeout-rethrow.js b/test/sequential/test-vm-timeout-rethrow.js index 7e148bd4d0b94f..54ffee1ff976f5 100644 --- a/test/sequential/test-vm-timeout-rethrow.js +++ b/test/sequential/test-vm-timeout-rethrow.js @@ -1,8 +1,8 @@ 'use strict'; require('../common'); -var assert = require('assert'); -var vm = require('vm'); -var spawn = require('child_process').spawn; +const assert = require('assert'); +const vm = require('vm'); +const spawn = require('child_process').spawn; if (process.argv[2] === 'child') { const code = 'while(true);'; @@ -11,8 +11,8 @@ if (process.argv[2] === 'child') { vm.runInContext(code, ctx, { timeout: 1 }); } else { - var proc = spawn(process.execPath, process.argv.slice(1).concat('child')); - var err = ''; + const proc = spawn(process.execPath, process.argv.slice(1).concat('child')); + let err = ''; proc.stderr.on('data', function(data) { err += data; }); diff --git a/test/timers/test-timers-reliability.js b/test/timers/test-timers-reliability.js index 0626c45826781b..9a9834aefecc7f 100644 --- a/test/timers/test-timers-reliability.js +++ b/test/timers/test-timers-reliability.js @@ -3,11 +3,11 @@ require('../common'); -var Timer = process.binding('timer_wrap').Timer; -var assert = require('assert'); +const Timer = process.binding('timer_wrap').Timer; +const assert = require('assert'); -var timerFired = false; -var intervalFired = false; +let timerFired = false; +let intervalFired = false; /* * This test case aims at making sure that timing utilities such @@ -31,7 +31,7 @@ var intervalFired = false; * is vulnerable to time drift or inconsistent time changes. */ -var monoTimer = new Timer(); +const monoTimer = new Timer(); monoTimer[Timer.kOnTimeout] = function() { /* * Make sure that setTimeout's and setInterval's callbacks have @@ -48,7 +48,7 @@ setTimeout(function() { timerFired = true; }, 200); -var interval = setInterval(function() { +const interval = setInterval(function() { intervalFired = true; clearInterval(interval); }, 200); From 16048480e762f10251c96e37084cad75f7da58c0 Mon Sep 17 00:00:00 2001 From: Alexey Orlenko Date: Fri, 10 Mar 2017 12:07:15 +0200 Subject: [PATCH 007/151] doc: fix stylistic issues in api/net.md * Change var to const in an example of server creation. * Add missing semicolons. * Use `console` syntax highlighting in `telnet` and `nc` invocation examples and add shell prompt symbols to be consistent with the rest of the documentation. Backport-PR-URL: https://github.com/nodejs/node/pull/11969/ PR-URL: https://github.com/nodejs/node/pull/11786 Reviewed-By: Luigi Pinca Reviewed-By: Joyee Cheung Reviewed-By: Colin Ihrig Reviewed-By: Anna Henningsen Reviewed-By: James M Snell --- doc/api/net.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/doc/api/net.md b/doc/api/net.md index cd7532c409878b..8b055b448f4a3d 100644 --- a/doc/api/net.md +++ b/doc/api/net.md @@ -66,7 +66,7 @@ Returns an object with `port`, `family`, and `address` properties: Example: ```js -var server = net.createServer((socket) => { +const server = net.createServer((socket) => { socket.end('goodbye\n'); }).on('error', (err) => { // handle errors here @@ -211,7 +211,7 @@ double-backslashes, such as: ```js net.createServer().listen( - path.join('\\\\?\\pipe', process.cwd(), 'myctl')) + path.join('\\\\?\\pipe', process.cwd(), 'myctl')); ``` The parameter `backlog` behaves the same as in @@ -874,8 +874,8 @@ server.listen(8124, () => { Test this by using `telnet`: -```sh -telnet localhost 8124 +```console +$ telnet localhost 8124 ``` To listen on the socket `/tmp/echo.sock` the third line from the last would @@ -889,8 +889,8 @@ server.listen('/tmp/echo.sock', () => { Use `nc` to connect to a UNIX domain socket server: -```js -nc -U /tmp/echo.sock +```console +$ nc -U /tmp/echo.sock ``` ## net.isIP(input) From 9162316ef5997ec672339260c068f3f239f08292 Mon Sep 17 00:00:00 2001 From: Alexey Orlenko Date: Fri, 10 Mar 2017 05:00:04 +0200 Subject: [PATCH 008/151] test: add arrow functions to test-util-inspect MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Even though arrow functions and ES5 anonymous functions are technically the same for util.js, it won't hurt to test both. Backport-PR-URL: https://github.com/nodejs/node/pull/11970 PR-URL: https://github.com/nodejs/node/pull/11781 Reviewed-By: James M Snell Reviewed-By: Rich Trott Reviewed-By: Michaël Zasso Reviewed-By: Daniel Bevenius Reviewed-By: Luigi Pinca Reviewed-By: Michael Dawson Reviewed-By: Colin Ihrig Reviewed-By: Timothy Gu --- test/parallel/test-util-inspect.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test/parallel/test-util-inspect.js b/test/parallel/test-util-inspect.js index af1f0fe9c3d6d0..18f734d24df64f 100644 --- a/test/parallel/test-util-inspect.js +++ b/test/parallel/test-util-inspect.js @@ -9,6 +9,7 @@ assert.strictEqual(util.inspect(false), 'false'); assert.strictEqual(util.inspect(''), "''"); assert.strictEqual(util.inspect('hello'), "'hello'"); assert.strictEqual(util.inspect(function() {}), '[Function]'); +assert.strictEqual(util.inspect(() => {}), '[Function]'); assert.strictEqual(util.inspect(undefined), 'undefined'); assert.strictEqual(util.inspect(null), 'null'); assert.strictEqual(util.inspect(/foo(bar\n)?/gi), '/foo(bar\\n)?/gi'); @@ -28,6 +29,7 @@ assert.strictEqual(util.inspect([1, [2, 3]]), '[ 1, [ 2, 3 ] ]'); assert.strictEqual(util.inspect({}), '{}'); assert.strictEqual(util.inspect({a: 1}), '{ a: 1 }'); assert.strictEqual(util.inspect({a: function() {}}), '{ a: [Function: a] }'); +assert.strictEqual(util.inspect({a: () => {}}), '{ a: [Function: a] }'); assert.strictEqual(util.inspect({a: 1, b: 2}), '{ a: 1, b: 2 }'); assert.strictEqual(util.inspect({'a': {}}), '{ a: {} }'); assert.strictEqual(util.inspect({'a': {'b': 2}}), '{ a: { b: 2 } }'); From f874256aaedfaad4a8d563ab8449661b8f038c29 Mon Sep 17 00:00:00 2001 From: Sota Yamashita Date: Wed, 1 Feb 2017 13:52:24 +0900 Subject: [PATCH 009/151] test: skip when openssl CLI doesn't exist Backport-PR-URL: https://github.com/nodejs/node/pull/12173 PR-URL: https://github.com/nodejs/node/pull/11095 Reviewed-By: James M Snell Reviewed-By: Yuta Hiroto Reviewed-By: Gibson Fahnestock Reviewed-By: Michael Dawson Reviewed-By: Anna Henningsen Reviewed-By: Sakthipriyan Vairamani Reviewed-By: Sam Roberts --- test/parallel/test-tls-dhe.js | 6 ++++++ test/parallel/test-tls-ecdh-disable.js | 6 ++++++ test/parallel/test-tls-ecdh.js | 6 ++++++ test/parallel/test-tls-securepair-server.js | 6 ++++++ 4 files changed, 24 insertions(+) diff --git a/test/parallel/test-tls-dhe.js b/test/parallel/test-tls-dhe.js index 34f403ffed3254..eb2d1b52b136aa 100644 --- a/test/parallel/test-tls-dhe.js +++ b/test/parallel/test-tls-dhe.js @@ -6,6 +6,12 @@ if (!common.hasCrypto) { common.skip('missing crypto'); return; } + +if (!common.opensslCli) { + common.skip('missing openssl-cli'); + return; +} + const tls = require('tls'); const spawn = require('child_process').spawn; diff --git a/test/parallel/test-tls-ecdh-disable.js b/test/parallel/test-tls-ecdh-disable.js index a0555e87781f59..d309102368aaa4 100644 --- a/test/parallel/test-tls-ecdh-disable.js +++ b/test/parallel/test-tls-ecdh-disable.js @@ -6,6 +6,12 @@ if (!common.hasCrypto) { common.skip('missing crypto'); return; } + +if (!common.opensslCli) { + common.skip('missing openssl-cli'); + return; +} + const tls = require('tls'); const exec = require('child_process').exec; diff --git a/test/parallel/test-tls-ecdh.js b/test/parallel/test-tls-ecdh.js index 99c6e108ab736a..56348d5d8e557e 100644 --- a/test/parallel/test-tls-ecdh.js +++ b/test/parallel/test-tls-ecdh.js @@ -5,6 +5,12 @@ if (!common.hasCrypto) { common.skip('missing crypto'); return; } + +if (!common.opensslCli) { + common.skip('missing openssl-cli'); + return; +} + const assert = require('assert'); const tls = require('tls'); diff --git a/test/parallel/test-tls-securepair-server.js b/test/parallel/test-tls-securepair-server.js index 65a7d91a0ca606..76d2f88ac6b8d4 100644 --- a/test/parallel/test-tls-securepair-server.js +++ b/test/parallel/test-tls-securepair-server.js @@ -6,6 +6,12 @@ if (!common.hasCrypto) { common.skip('missing crypto'); return; } + +if (!common.opensslCli) { + common.skip('missing openssl-cli'); + return; +} + const tls = require('tls'); const join = require('path').join; From ba23506419a0c8f58507b4219fbaea06f448f79f Mon Sep 17 00:00:00 2001 From: Ben Noordhuis Date: Tue, 4 Apr 2017 09:40:32 +0200 Subject: [PATCH 010/151] build: --without-ssl implies --without-inspector This cherry-picks the changes to `configure` from commit 8f00455c5 ("inspector: switch to new inspector APIs") from the master branch and should unbreak `--without-ssl` builds. Refs: https://github.com/nodejs/node/issues/12155 PR-URL: https://github.com/nodejs/node/pull/12200 Reviewed-By: Sakthipriyan Vairamani Reviewed-By: James M Snell Reviewed-By: Colin Ihrig --- configure | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/configure b/configure index 74229bf1120998..e7fa06fe87f6f6 100755 --- a/configure +++ b/configure @@ -894,7 +894,6 @@ def configure_node(o): o['variables']['library_files'] = options.linked_module o['variables']['asan'] = int(options.enable_asan or 0) - o['variables']['v8_inspector'] = b(not options.without_inspector) o['variables']['debug_devtools'] = 'node' if options.use_xcode and options.use_ninja: @@ -1268,6 +1267,12 @@ def configure_intl(o): pprint.pformat(icu_config, indent=2) + '\n') return # end of configure_intl +def configure_inspector(o): + disable_inspector = (options.without_inspector or + options.with_intl in (None, 'none') or + options.without_ssl) + o['variables']['v8_inspector'] = b(not disable_inspector) + output = { 'variables': {}, 'include_dirs': [], @@ -1298,6 +1303,7 @@ configure_v8(output) configure_openssl(output) configure_intl(output) configure_static(output) +configure_inspector(output) # variables should be a root level element, # move everything else to target_defaults From c138ba3684722c78c4c776a3ba551d9a9a0872fa Mon Sep 17 00:00:00 2001 From: Sam Roberts Date: Fri, 30 Dec 2016 09:14:10 -0800 Subject: [PATCH 011/151] doc: new TLSSocket has no secure context options Unlike all the other tls APIs, if any secure context configuration is required, the caller is responsible for creating the context. Corrects a doc regression introduced in caa7fa982affddcc. PR-URL: https://github.com/nodejs/node/pull/10545 Reviewed-By: Benjamin Gruenbaum Reviewed-By: James M Snell Reviewed-By: Michael Dawson Reviewed-By: Fedor Indutny Reviewed-By: Anna Henningsen --- doc/api/tls.md | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/doc/api/tls.md b/doc/api/tls.md index 3c8c31a8f11e22..5b0cef22f02641 100644 --- a/doc/api/tls.md +++ b/doc/api/tls.md @@ -483,12 +483,8 @@ added: v0.11.4 will be emitted on the socket before establishing a secure communication * `secureContext`: Optional TLS context object created with [`tls.createSecureContext()`][]. If a `secureContext` is _not_ provided, one - will be created by passing the entire `options` object to - `tls.createSecureContext()`. *Note*: In effect, all - [`tls.createSecureContext()`][] options can be provided, but they will be - _completely ignored_ unless the `secureContext` option is missing. - * ...: Optional [`tls.createSecureContext()`][] options can be provided, see - the `secureContext` option for more information. + will be created by calling [`tls.createSecureContext()`][] with no options. + Construct a new `tls.TLSSocket` object from an existing TCP socket. ### Event: 'OCSPResponse' From 4fd765eec8e6153b9a20c7a6756986d2d9c12784 Mon Sep 17 00:00:00 2001 From: Zach Bjornson Date: Thu, 12 Jan 2017 16:29:22 -0800 Subject: [PATCH 012/151] doc: clarify memory sharing behavior of buffer ctor * Clarify that memory is always shared and never copied. * Fix wording that sounded like ArrayBuffer has a buffer property. PR-URL: https://github.com/nodejs/node/pull/10778 Ref: https://github.com/nodejs/node/issues/10770 Reviewed-By: Luigi Pinca Reviewed-By: James M Snell --- doc/api/buffer.md | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/doc/api/buffer.md b/doc/api/buffer.md index a33c214daeff29..44e274760d30cd 100644 --- a/doc/api/buffer.md +++ b/doc/api/buffer.md @@ -348,15 +348,16 @@ deprecated: v6.0.0 > [`Buffer.from(arrayBuffer[, byteOffset [, length]])`][`Buffer.from(arrayBuffer)`] > instead. -* `arrayBuffer` {ArrayBuffer} The `.buffer` property of a [`TypedArray`] or - [`ArrayBuffer`] -* `byteOffset` {Integer} Where to start copying from `arrayBuffer`. **Default:** `0` -* `length` {Integer} How many bytes to copy from `arrayBuffer`. +* `arrayBuffer` {ArrayBuffer} An [`ArrayBuffer`] or the `.buffer` property of a + [`TypedArray`]. +* `byteOffset` {Integer} Index of first byte to expose. **Default:** `0` +* `length` {Integer} Number of bytes to expose. **Default:** `arrayBuffer.length - byteOffset` -When passed a reference to the `.buffer` property of a [`TypedArray`] instance, -the newly created `Buffer` will share the same allocated memory as the -[`TypedArray`]. +This creates a view of the [`ArrayBuffer`] without copying the underlying +memory. For example, when passed a reference to the `.buffer` property of a +[`TypedArray`] instance, the newly created `Buffer` will share the same +allocated memory as the [`TypedArray`]. The optional `byteOffset` and `length` arguments specify a memory range within the `arrayBuffer` that will be shared by the `Buffer`. @@ -726,15 +727,16 @@ A `TypeError` will be thrown if `array` is not an `Array`. added: v5.10.0 --> -* `arrayBuffer` {ArrayBuffer} The `.buffer` property of a [`TypedArray`] or - [`ArrayBuffer`] -* `byteOffset` {Integer} Where to start copying from `arrayBuffer`. **Default:** `0` -* `length` {Integer} How many bytes to copy from `arrayBuffer`. +* `arrayBuffer` {ArrayBuffer} An [`ArrayBuffer`] or the `.buffer` property of a + [`TypedArray`]. +* `byteOffset` {Integer} Index of first byte to expose. **Default:** `0` +* `length` {Integer} Number of bytes to expose. **Default:** `arrayBuffer.length - byteOffset` -When passed a reference to the `.buffer` property of a [`TypedArray`] instance, -the newly created `Buffer` will share the same allocated memory as the -[`TypedArray`]. +This creates a view of the [`ArrayBuffer`] without copying the underlying +memory. For example, when passed a reference to the `.buffer` property of a +[`TypedArray`] instance, the newly created `Buffer` will share the same +allocated memory as the [`TypedArray`]. Example: From f0645200aa6131817f51975236da9f946b2859e9 Mon Sep 17 00:00:00 2001 From: Adrian Estrada Date: Mon, 2 Jan 2017 22:10:40 -0500 Subject: [PATCH 013/151] test: improve test-fs-access * use const and let instead of var * use common.mustCall to control functions execution * use assert.ifError instead of assert.strictEqual for errors * use arrow functions PR-URL: https://github.com/nodejs/node/pull/10542 Reviewed-By: James M Snell Reviewed-By: Colin Ihrig Reviewed-By: Luigi Pinca --- test/parallel/test-fs-access.js | 44 ++++++++++++++++----------------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/test/parallel/test-fs-access.js b/test/parallel/test-fs-access.js index ad4023ea74ac83..80f63ac6128ce7 100644 --- a/test/parallel/test-fs-access.js +++ b/test/parallel/test-fs-access.js @@ -63,46 +63,46 @@ assert.strictEqual(typeof fs.R_OK, 'number'); assert.strictEqual(typeof fs.W_OK, 'number'); assert.strictEqual(typeof fs.X_OK, 'number'); -fs.access(__filename, function(err) { - assert.strictEqual(err, null, 'error should not exist'); -}); +fs.access(__filename, common.mustCall((err) => { + assert.ifError(err); +})); -fs.access(__filename, fs.R_OK, function(err) { - assert.strictEqual(err, null, 'error should not exist'); -}); +fs.access(__filename, fs.R_OK, common.mustCall((err) => { + assert.ifError(err); +})); -fs.access(doesNotExist, function(err) { +fs.access(doesNotExist, common.mustCall((err) => { assert.notEqual(err, null, 'error should exist'); assert.strictEqual(err.code, 'ENOENT'); assert.strictEqual(err.path, doesNotExist); -}); +})); -fs.access(readOnlyFile, fs.F_OK | fs.R_OK, function(err) { - assert.strictEqual(err, null, 'error should not exist'); -}); +fs.access(readOnlyFile, fs.F_OK | fs.R_OK, common.mustCall((err) => { + assert.ifError(err); +})); -fs.access(readOnlyFile, fs.W_OK, function(err) { +fs.access(readOnlyFile, fs.W_OK, common.mustCall((err) => { if (hasWriteAccessForReadonlyFile) { - assert.equal(err, null, 'error should not exist'); + assert.ifError(err); } else { assert.notEqual(err, null, 'error should exist'); assert.strictEqual(err.path, readOnlyFile); } -}); +})); -assert.throws(function() { - fs.access(100, fs.F_OK, function(err) {}); +assert.throws(() => { + fs.access(100, fs.F_OK, (err) => {}); }, /path must be a string or Buffer/); -assert.throws(function() { +assert.throws(() => { fs.access(__filename, fs.F_OK); }, /"callback" argument must be a function/); -assert.throws(function() { +assert.throws(() => { fs.access(__filename, fs.F_OK, {}); }, /"callback" argument must be a function/); -assert.doesNotThrow(function() { +assert.doesNotThrow(() => { fs.accessSync(__filename); }); @@ -112,13 +112,13 @@ assert.doesNotThrow(function() { fs.accessSync(readWriteFile, mode); }); -assert.throws(function() { +assert.throws(() => { fs.accessSync(doesNotExist); -}, function(err) { +}, (err) => { return err.code === 'ENOENT' && err.path === doesNotExist; }); -process.on('exit', function() { +process.on('exit', () => { removeFile(readOnlyFile); removeFile(readWriteFile); }); From afea1d041e2817551ead3e7703142d7567fbb58b Mon Sep 17 00:00:00 2001 From: cjihrig Date: Mon, 2 Jan 2017 12:41:18 -0500 Subject: [PATCH 014/151] test: refactor test-beforeexit-event-exit.js PR-URL: https://github.com/nodejs/node/pull/10577 Reviewed-By: Italo A. Casas Reviewed-By: Gibson Fahnestock Reviewed-By: Sakthipriyan Vairamani Reviewed-By: James M Snell --- test/parallel/test-beforeexit-event-exit.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/test/parallel/test-beforeexit-event-exit.js b/test/parallel/test-beforeexit-event-exit.js index 6878135ce4d6d3..bd6162a46804bf 100644 --- a/test/parallel/test-beforeexit-event-exit.js +++ b/test/parallel/test-beforeexit-event-exit.js @@ -1,9 +1,8 @@ 'use strict'; -require('../common'); -const assert = require('assert'); +const common = require('../common'); process.on('beforeExit', function() { - assert(false, 'exit should not allow this to occur'); + common.fail('exit should not allow this to occur'); }); process.exit(); From 6f85c81f0dc9e40511e98bd034c0a841ed764d3c Mon Sep 17 00:00:00 2001 From: Gibson Fahnestock Date: Sun, 8 Jan 2017 15:36:25 +0000 Subject: [PATCH 015/151] test: s/assert.equal/assert.strictEqual/ Use assert.strictEqual instead of assert.equal in tests, manually convert types where necessary. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Backport-PR-URL: https://github.com/nodejs/node/pull/11795 PR-URL: https://github.com/nodejs/node/pull/10698 Reviewed-By: James M Snell Reviewed-By: Colin Ihrig Reviewed-By: Michael Dawson Reviewed-By: Sakthipriyan Vairamani Reviewed-By: Michaël Zasso Reviewed-By: Teddy Katz --- test/addons/load-long-path/test.js | 2 +- test/disabled/test-fs-largefile.js | 8 +- test/disabled/test-http-abort-stream-end.js | 2 +- test/disabled/test-readline.js | 14 +- test/disabled/test-sendfd.js | 10 +- test/disabled/test-setuidgid.js | 2 +- test/fixtures/GH-892-request.js | 2 +- test/fixtures/b/c.js | 2 +- test/fixtures/node_modules/baz/index.js | 6 +- test/fixtures/node_modules/foo.js | 4 +- test/internet/test-dns-txt-sigsegv.js | 4 +- test/message/error_exit.js | 2 +- test/message/error_exit.out | 2 +- test/parallel/test-assert.js | 38 +- test/parallel/test-buffer-alloc.js | 6 +- test/parallel/test-buffer-indexof.js | 238 +++--- test/parallel/test-buffer.js | 731 +++++++++--------- test/parallel/test-child-process-fork-net.js | 2 +- test/parallel/test-child-process-fork-net2.js | 4 +- test/parallel/test-child-process-fork-ref.js | 2 +- test/parallel/test-child-process-ipc.js | 2 +- .../test-child-process-set-blocking.js | 2 +- .../test-child-process-spawn-shell.js | 2 +- .../test-child-process-spawnsync-env.js | 2 +- .../test-child-process-spawnsync-shell.js | 2 +- test/parallel/test-console.js | 2 +- test/parallel/test-crypto-dh.js | 66 +- test/parallel/test-crypto-domains.js | 2 +- test/parallel/test-crypto-fips.js | 4 +- test/parallel/test-crypto-hash.js | 6 +- test/parallel/test-crypto-rsa-dsa.js | 10 +- test/parallel/test-debug-signal-cluster.js | 2 +- test/parallel/test-dh-padding.js | 2 +- test/parallel/test-domain-nested.js | 2 +- ...n-throw-from-uncaught-exception-handler.js | 6 +- test/parallel/test-event-emitter-prepend.js | 7 +- ...test-event-emitter-remove-all-listeners.js | 4 +- test/parallel/test-event-emitter-subclass.js | 2 +- test/parallel/test-fs-access.js | 4 +- test/parallel/test-fs-error-messages.js | 6 +- test/parallel/test-fs-mkdir-rmdir.js | 4 +- test/parallel/test-fs-mkdir.js | 4 +- test/parallel/test-fs-mkdtemp.js | 4 +- test/parallel/test-fs-open-flags.js | 38 +- .../test-fs-read-buffer-zero-length.js | 4 +- test/parallel/test-fs-read-buffer.js | 4 +- test/parallel/test-fs-read-stream-fd.js | 2 +- test/parallel/test-fs-read-stream.js | 2 +- test/parallel/test-fs-read-zero-length.js | 8 +- test/parallel/test-fs-readdir-ucs2.js | 2 +- test/parallel/test-fs-readdir.js | 2 +- test/parallel/test-fs-realpath.js | 4 +- test/parallel/test-fs-stat.js | 14 +- test/parallel/test-fs-sync-fd-leak.js | 8 +- test/parallel/test-fs-watch-enoent.js | 4 +- test/parallel/test-fs-write-buffer.js | 2 +- .../test-fs-write-stream-change-open.js | 2 +- test/parallel/test-fs-write-stream-err.js | 8 +- test/parallel/test-fs-write-string-coerce.js | 2 +- test/parallel/test-fs-write-sync.js | 2 +- test/parallel/test-http-abort-queued.js | 22 +- .../parallel/test-http-agent-error-on-idle.js | 10 +- test/parallel/test-http-agent-keepalive.js | 50 +- test/parallel/test-http-agent-maxsockets.js | 8 +- test/parallel/test-http-agent.js | 2 +- test/parallel/test-http-automatic-headers.js | 12 +- test/parallel/test-http-blank-header.js | 4 +- test/parallel/test-http-buffer-sanity.js | 6 +- .../test-http-catch-uncaughtexception.js | 2 +- test/parallel/test-http-chunk-problem.js | 4 +- test/parallel/test-http-chunked.js | 4 +- test/parallel/test-http-client-abort.js | 2 +- test/parallel/test-http-client-agent.js | 4 +- test/parallel/test-http-client-get-url.js | 4 +- test/parallel/test-http-client-parse-error.js | 6 +- test/parallel/test-http-client-race-2.js | 6 +- test/parallel/test-http-client-race.js | 4 +- ...ient-reject-chunked-with-content-length.js | 2 +- .../test-http-client-reject-cr-no-lf.js | 2 +- .../test-http-client-response-domain.js | 2 +- test/parallel/test-http-client-upload-buf.js | 2 +- test/parallel/test-http-client-upload.js | 2 +- test/parallel/test-http-conn-reset.js | 2 +- test/parallel/test-http-connect-req-res.js | 12 +- test/parallel/test-http-createConnection.js | 2 +- test/parallel/test-http-default-encoding.js | 2 +- test/parallel/test-http-default-port.js | 8 +- .../test-http-destroyed-socket-write2.js | 4 +- .../test-http-double-content-length.js | 2 +- test/parallel/test-http-expect-continue.js | 13 +- test/parallel/test-http-expect-handling.js | 6 +- test/parallel/test-http-extra-response.js | 4 +- test/parallel/test-http-flush-headers.js | 2 +- .../test-http-flush-response-headers.js | 2 +- test/parallel/test-http-full-response.js | 4 +- .../test-http-get-pipeline-problem.js | 8 +- test/parallel/test-http-header-read.js | 2 +- test/parallel/test-http-host-headers.js | 6 +- .../test-http-keep-alive-close-on-header.js | 8 +- test/parallel/test-http-keepalive-client.js | 8 +- .../test-http-keepalive-maxsockets.js | 14 +- test/parallel/test-http-keepalive-request.js | 8 +- test/parallel/test-http-legacy.js | 26 +- test/parallel/test-http-localaddress.js | 2 +- test/parallel/test-http-malformed-request.js | 2 +- test/parallel/test-http-max-headers-count.js | 8 +- test/parallel/test-http-multi-line-headers.js | 4 +- test/parallel/test-http-mutable-headers.js | 36 +- test/parallel/test-http-parser-bad-ref.js | 4 +- test/parallel/test-http-parser-free.js | 2 +- test/parallel/test-http-parser.js | 12 +- test/parallel/test-http-pause.js | 4 +- test/parallel/test-http-pipeline-regr-2639.js | 2 +- test/parallel/test-http-pipeline-regr-3332.js | 2 +- test/parallel/test-http-proxy.js | 12 +- .../test-http-remove-header-stays-removed.js | 4 +- ...test-http-request-dont-override-options.js | 2 +- .../parallel/test-http-res-write-after-end.js | 2 +- ...test-http-response-multi-content-length.js | 4 +- .../test-http-response-multiheaders.js | 4 +- .../parallel/test-http-response-no-headers.js | 2 +- test/parallel/test-http-response-readable.js | 5 +- .../test-http-response-status-message.js | 4 +- .../parallel/test-http-server-client-error.js | 4 +- .../parallel/test-http-server-multiheaders.js | 19 +- .../test-http-server-multiheaders2.js | 8 +- ...rver-reject-chunked-with-content-length.js | 2 +- .../test-http-server-reject-cr-no-lf.js | 2 +- test/parallel/test-http-server-unconsume.js | 2 +- test/parallel/test-http-set-cookies.js | 6 +- test/parallel/test-http-set-timeout-server.js | 2 +- test/parallel/test-http-should-keep-alive.js | 8 +- test/parallel/test-http-status-code.js | 6 +- test/parallel/test-http-status-message.js | 2 +- test/parallel/test-http-timeout-overflow.js | 4 +- test/parallel/test-http-upgrade-advertise.js | 2 +- test/parallel/test-http-upgrade-agent.js | 2 +- test/parallel/test-http-upgrade-server.js | 18 +- test/parallel/test-http-upgrade-server2.js | 2 +- test/parallel/test-http-write-callbacks.js | 6 +- test/parallel/test-http-write-empty-string.js | 2 +- test/parallel/test-http-write-head.js | 3 +- test/parallel/test-http-zero-length-write.js | 4 +- test/parallel/test-http.js | 2 +- .../test-https-agent-disable-session-reuse.js | 8 +- .../test-https-agent-session-reuse.js | 16 +- test/parallel/test-https-agent-sni.js | 2 +- test/parallel/test-https-client-get-url.js | 4 +- test/parallel/test-https-drain.js | 2 +- test/parallel/test-https-eof-for-eom.js | 2 +- test/parallel/test-https-foafssl.js | 2 +- test/parallel/test-https-host-headers.js | 6 +- test/parallel/test-https-localaddress.js | 2 +- test/parallel/test-https-pfx.js | 5 +- .../parallel/test-https-set-timeout-server.js | 2 +- test/parallel/test-https-simple.js | 6 +- test/parallel/test-https-strict.js | 10 +- test/parallel/test-internal-modules-expose.js | 2 +- test/parallel/test-listen-fd-cluster.js | 4 +- .../test-listen-fd-detached-inherit.js | 4 +- test/parallel/test-listen-fd-detached.js | 4 +- test/parallel/test-listen-fd-server.js | 4 +- test/parallel/test-memory-usage-emfile.js | 2 +- ...test-microtask-queue-integration-domain.js | 2 +- .../test-microtask-queue-integration.js | 2 +- .../test-microtask-queue-run-domain.js | 2 +- ...st-microtask-queue-run-immediate-domain.js | 2 +- .../test-microtask-queue-run-immediate.js | 2 +- test/parallel/test-microtask-queue-run.js | 2 +- test/parallel/test-module-loading-error.js | 4 +- .../test-net-better-error-messages-path.js | 4 +- test/parallel/test-net-binary.js | 2 +- test/parallel/test-net-bind-twice.js | 2 +- test/parallel/test-net-bytes-read.js | 8 +- test/parallel/test-net-bytes-stats.js | 4 +- test/parallel/test-net-connect-buffer.js | 12 +- test/parallel/test-net-create-connection.js | 2 +- test/parallel/test-net-dns-error.js | 8 +- test/parallel/test-net-dns-lookup.js | 8 +- test/parallel/test-net-eaddrinuse.js | 2 +- test/parallel/test-net-error-twice.js | 2 +- test/parallel/test-net-isip.js | 120 +-- test/parallel/test-net-keepalive.js | 2 +- .../test-net-listen-exclusive-random-ports.js | 6 +- test/parallel/test-net-listen-shared-ports.js | 4 +- .../parallel/test-net-persistent-keepalive.js | 6 +- test/parallel/test-net-persistent-nodelay.js | 2 +- .../parallel/test-net-persistent-ref-unref.js | 6 +- test/parallel/test-net-reconnect.js | 12 +- test/parallel/test-net-remote-address-port.js | 37 +- test/parallel/test-net-server-bind.js | 10 +- test/parallel/test-net-server-close.js | 8 +- test/parallel/test-net-server-connections.js | 2 +- .../test-net-server-listen-remove-callback.js | 2 +- ...-connections-close-makes-more-available.js | 2 +- .../test-net-server-pause-on-connect.js | 9 +- test/parallel/test-net-stream.js | 8 +- test/parallel/test-net-sync-cork.js | 4 +- test/parallel/test-next-tick-ordering.js | 4 +- test/parallel/test-next-tick.js | 4 +- test/parallel/test-os-homedir-no-envvar.js | 2 +- test/parallel/test-path-makelong.js | 27 +- test/parallel/test-path-parse-format.js | 2 +- .../parallel/test-path-zero-length-strings.js | 32 +- test/parallel/test-path.js | 2 +- test/parallel/test-pipe-stream.js | 4 +- test/parallel/test-process-argv-0.js | 2 +- test/parallel/test-process-before-exit.js | 2 +- test/parallel/test-process-cpuUsage.js | 2 +- test/parallel/test-process-env.js | 4 +- test/parallel/test-process-exit-code.js | 10 +- test/parallel/test-process-exit-recursive.js | 4 +- test/parallel/test-process-exit.js | 4 +- .../test-process-getactiverequests.js | 2 +- test/parallel/test-process-getgroups.js | 2 +- test/parallel/test-process-kill-pid.js | 4 +- test/parallel/test-process-raw-debug.js | 2 +- test/parallel/test-process-release.js | 6 +- ...est-process-remove-all-signal-listeners.js | 2 +- test/parallel/test-process-wrap.js | 4 +- .../test-promises-unhandled-rejections.js | 2 +- .../test-querystring-maxKeys-non-finite.js | 8 +- test/parallel/test-querystring.js | 56 +- test/parallel/test-readdouble.js | 56 +- test/parallel/test-readfloat.js | 34 +- test/parallel/test-readint.js | 60 +- test/parallel/test-readline-interface.js | 107 +-- test/parallel/test-readline-set-raw-mode.js | 4 +- test/parallel/test-readuint.js | 38 +- test/parallel/test-regress-GH-1899.js | 4 +- test/parallel/test-regress-GH-5051.js | 8 +- test/parallel/test-regress-GH-5727.js | 2 +- test/parallel/test-regress-GH-7511.js | 2 +- test/parallel/test-regress-GH-node-9326.js | 2 +- test/parallel/test-repl-.save.load.js | 10 +- test/parallel/test-repl-autolibs.js | 9 +- test/parallel/test-repl-end-emits-exit.js | 4 +- test/parallel/test-repl-envvars.js | 8 +- test/parallel/test-repl-options.js | 66 +- test/parallel/test-repl-require-cache.js | 4 +- .../test-repl-syntax-error-handling.js | 2 +- test/parallel/test-repl-tab.js | 2 +- ...ons-same-filename-as-dir-trailing-slash.js | 4 +- test/parallel/test-require-unicode.js | 4 +- .../test-socket-write-after-fin-error.js | 8 +- test/parallel/test-stdin-child-proc.js | 2 +- test/parallel/test-stdin-pipe-resume.js | 2 +- ...out-cannot-be-closed-child-process-pipe.js | 2 +- test/parallel/test-stdout-stderr-reading.js | 4 +- test/parallel/test-stream-base-no-abort.js | 8 +- test/parallel/test-stream-push-strings.js | 2 +- ...stream-readable-constructor-set-methods.js | 2 +- .../test-stream-readable-flow-recursion.js | 8 +- ...tream-transform-constructor-set-methods.js | 4 +- ...stream-writable-change-default-encoding.js | 6 +- ...stream-writable-constructor-set-methods.js | 6 +- ...ableState-uncorked-bufferedRequestCount.js | 2 +- test/parallel/test-stream-writev.js | 2 +- ...est-stream2-base64-single-char-read-end.js | 2 +- test/parallel/test-stream2-compatibility.js | 2 +- test/parallel/test-stream2-objects.js | 2 +- .../test-stream2-readable-from-list.js | 4 +- .../test-stream2-readable-non-empty-end.js | 4 +- test/parallel/test-stream2-readable-wrap.js | 4 +- test/parallel/test-stream2-set-encoding.js | 4 +- test/parallel/test-stream2-transform.js | 4 +- test/parallel/test-stream2-unpipe-leak.js | 16 +- test/parallel/test-stream3-cork-end.js | 8 +- test/parallel/test-stream3-cork-uncork.js | 8 +- test/parallel/test-stream3-pause-then-read.js | 8 +- test/parallel/test-string-decoder-end.js | 4 +- test/parallel/test-stringbytes-external.js | 30 +- test/parallel/test-sync-io-option.js | 8 +- test/parallel/test-tcp-wrap.js | 4 +- test/parallel/test-timer-close.js | 2 +- test/parallel/test-timers-ordering.js | 2 +- ...st-timers-reset-process-domain-on-throw.js | 2 +- .../test-timers-uncaught-exception.js | 10 +- test/parallel/test-timers-unref-active.js | 2 +- test/parallel/test-timers-unref-leak.js | 4 +- ...emove-other-unref-timers-only-one-fires.js | 2 +- test/parallel/test-timers.js | 4 +- test/parallel/test-tls-cipher-list.js | 2 +- .../test-tls-client-default-ciphers.js | 2 +- .../test-tls-client-getephemeralkeyinfo.js | 4 +- test/parallel/test-tls-client-mindhsize.js | 4 +- test/parallel/test-tls-client-verify.js | 2 +- test/parallel/test-tls-delayed-attach.js | 2 +- test/parallel/test-tls-dhe.js | 4 +- test/parallel/test-tls-env-bad-extra-ca.js | 2 +- test/parallel/test-tls-env-extra-ca.js | 2 +- test/parallel/test-tls-handshake-error.js | 2 +- test/parallel/test-tls-honorcipherorder.js | 4 +- test/parallel/test-tls-js-stream.js | 4 +- test/parallel/test-tls-no-rsa-key.js | 2 +- test/parallel/test-tls-npn-server-client.js | 12 +- test/parallel/test-tls-over-http-tunnel.js | 17 +- test/parallel/test-tls-pause.js | 2 +- .../test-tls-peer-certificate-encoding.js | 2 +- test/parallel/test-tls-server-verify.js | 2 +- test/parallel/test-tls-session-cache.js | 12 +- test/parallel/test-tls-set-ciphers.js | 2 +- .../test-tls-socket-default-options.js | 2 +- test/parallel/test-umask.js | 6 +- test/parallel/test-url.js | 28 +- test/parallel/test-utf8-scripts.js | 2 +- test/parallel/test-util-log.js | 2 +- test/parallel/test-util.js | 112 +-- test/parallel/test-v8-stats.js | 2 +- test/parallel/test-vm-cached-data.js | 6 +- test/parallel/test-vm-context.js | 12 +- .../test-vm-create-and-run-in-context.js | 10 +- ...st-vm-create-context-circular-reference.js | 2 +- test/parallel/test-vm-function-declaration.js | 10 +- .../test-vm-global-define-property.js | 6 +- .../test-vm-new-script-new-context.js | 16 +- .../test-vm-new-script-this-context.js | 12 +- test/parallel/test-vm-run-in-new-context.js | 17 +- test/parallel/test-vm-syntax-error-message.js | 2 +- test/parallel/test-writedouble.js | 232 +++--- test/parallel/test-writefloat.js | 118 +-- test/parallel/test-writeint.js | 128 +-- test/parallel/test-writeuint.js | 100 +-- test/parallel/test-zlib-const.js | 10 +- .../parallel/test-zlib-convenience-methods.js | 18 +- test/parallel/test-zlib-flush-drain.js | 16 +- .../test-zlib-from-concatenated-gzip.js | 11 +- test/parallel/test-zlib-from-gzip.js | 4 +- test/parallel/test-zlib-from-string.js | 16 +- test/parallel/test-zlib-random-byte-pipes.js | 2 +- test/parallel/test-zlib-sync-no-event.js | 2 +- test/parallel/test-zlib-write-after-flush.js | 4 +- test/pummel/test-crypto-dh.js | 4 +- test/pummel/test-dtrace-jsstack.js | 5 +- test/pummel/test-fs-watch-file-slow.js | 8 +- test/pummel/test-fs-watch-file.js | 10 +- .../test-http-many-keep-alive-connections.js | 6 +- test/pummel/test-https-ci-reneg-attack.js | 4 +- test/pummel/test-net-connect-econnrefused.js | 10 +- test/pummel/test-net-many-clients.js | 6 +- test/pummel/test-net-pause.js | 8 +- test/pummel/test-net-pingpong-delay.js | 28 +- test/pummel/test-net-pingpong.js | 32 +- test/pummel/test-net-throttle.js | 8 +- test/pummel/test-net-timeout.js | 2 +- test/pummel/test-net-write-callbacks.js | 2 +- test/pummel/test-regress-GH-892.js | 6 +- test/pummel/test-stream-pipe-multi.js | 4 +- test/pummel/test-stream2-basic.js | 28 +- test/pummel/test-timers.js | 29 +- test/pummel/test-tls-ci-reneg-attack.js | 4 +- test/pummel/test-tls-securepair-client.js | 11 +- test/pummel/test-tls-server-large-request.js | 2 +- test/pummel/test-tls-throttle.js | 2 +- .../test-child-process-fork-getconnections.js | 6 +- test/sequential/test-deprecation-flags.js | 18 +- test/sequential/test-http-regr-gh-2928.js | 2 +- test/sequential/test-process-warnings.js | 12 +- test/sequential/test-regress-GH-4027.js | 4 +- test/sequential/test-regress-GH-784.js | 6 +- test/sequential/test-regress-GH-877.js | 2 +- .../test-require-cache-without-stat.js | 2 +- test/sequential/test-stream2-fs.js | 2 +- test/sequential/test-stream2-stderr-sync.js | 2 +- test/sequential/test-util-debug.js | 4 +- 365 files changed, 2205 insertions(+), 2147 deletions(-) diff --git a/test/addons/load-long-path/test.js b/test/addons/load-long-path/test.js index ff612b66488f75..73d85a75a097a2 100644 --- a/test/addons/load-long-path/test.js +++ b/test/addons/load-long-path/test.js @@ -33,5 +33,5 @@ fs.writeFileSync(addonDestinationPath, contents); // Attempt to load at long path destination const addon = require(addonDestinationPath); -assert.notEqual(addon, null); +assert.notStrictEqual(addon, null); assert.strictEqual(addon.hello(), 'world'); diff --git a/test/disabled/test-fs-largefile.js b/test/disabled/test-fs-largefile.js index fb0058b358a5c3..d1d51a88de9813 100644 --- a/test/disabled/test-fs-largefile.js +++ b/test/disabled/test-fs-largefile.js @@ -9,14 +9,14 @@ var path = require('path'), message = 'Large File'; fs.truncateSync(fd, offset); -assert.equal(fs.statSync(filepath).size, offset); +assert.strictEqual(fs.statSync(filepath).size, offset); var writeBuf = Buffer.from(message); fs.writeSync(fd, writeBuf, 0, writeBuf.length, offset); var readBuf = Buffer.allocUnsafe(writeBuf.length); fs.readSync(fd, readBuf, 0, readBuf.length, offset); -assert.equal(readBuf.toString(), message); +assert.strictEqual(readBuf.toString(), message); fs.readSync(fd, readBuf, 0, 1, 0); -assert.equal(readBuf[0], 0); +assert.strictEqual(readBuf[0], 0); var exceptionRaised = false; try { @@ -24,7 +24,7 @@ try { } catch (err) { console.log(err); exceptionRaised = true; - assert.equal(err.message, 'Not an integer'); + assert.strictEqual(err.message, 'Not an integer'); } assert.ok(exceptionRaised); fs.close(fd); diff --git a/test/disabled/test-http-abort-stream-end.js b/test/disabled/test-http-abort-stream-end.js index cfa531cedf5523..b0a1a921bdd1dd 100644 --- a/test/disabled/test-http-abort-stream-end.js +++ b/test/disabled/test-http-abort-stream-end.js @@ -36,6 +36,6 @@ s.listen(common.PORT, function() { process.on('exit', function() { assert(aborted); - assert.equal(size, maxSize); + assert.strictEqual(size, maxSize); console.log('ok'); }); diff --git a/test/disabled/test-readline.js b/test/disabled/test-readline.js index 9bb9943bd2a403..b3819f3bbd6f04 100644 --- a/test/disabled/test-readline.js +++ b/test/disabled/test-readline.js @@ -49,12 +49,12 @@ var rl = readlineFakeStream(); var written_bytes_length, refreshed; rl.write('foo'); -assert.equal(3, rl.cursor); +assert.strictEqual(3, rl.cursor); [key.xterm, key.rxvt, key.gnome, key.putty].forEach(function(key) { rl.write.apply(rl, key.home); - assert.equal(0, rl.cursor); + assert.strictEqual(0, rl.cursor); rl.write.apply(rl, key.end); - assert.equal(3, rl.cursor); + assert.strictEqual(3, rl.cursor); }); rl = readlineFakeStream(); @@ -76,9 +76,9 @@ rl.write.apply(rl, key.xterm.home); ].forEach(function(action) { written_bytes_length = rl.written_bytes.length; rl.write.apply(rl, action.key); - assert.equal(action.cursor, rl.cursor); + assert.strictEqual(action.cursor, rl.cursor); refreshed = written_bytes_length !== rl.written_bytes.length; - assert.equal(true, refreshed); + assert.strictEqual(true, refreshed); }); rl = readlineFakeStream(); @@ -93,7 +93,7 @@ rl.write.apply(rl, key.xterm.home); '' ].forEach(function(expectedLine) { rl.write.apply(rl, key.xterm.metad); - assert.equal(0, rl.cursor); - assert.equal(expectedLine, rl.line); + assert.strictEqual(0, rl.cursor); + assert.strictEqual(expectedLine, rl.line); }); rl.close(); diff --git a/test/disabled/test-sendfd.js b/test/disabled/test-sendfd.js index d473cd93c33153..9e3a01733f69a7 100644 --- a/test/disabled/test-sendfd.js +++ b/test/disabled/test-sendfd.js @@ -63,7 +63,7 @@ var logChild = function(d) { // validate any data sent back by the child. We send the write end of the // pipe to the child and close it off in our process. var pipeFDs = netBinding.pipe(); -assert.equal(pipeFDs.length, 2); +assert.strictEqual(pipeFDs.length, 2); var seenOrdinals = []; @@ -72,8 +72,8 @@ pipeReadStream.on('data', function(data) { data.toString('utf8').trim().split('\n').forEach(function(d) { var rd = JSON.parse(d); - assert.equal(rd.pid, cpp); - assert.equal(seenOrdinals.indexOf(rd.ord), -1); + assert.strictEqual(rd.pid, cpp); + assert.strictEqual(seenOrdinals.indexOf(rd.ord), -1); seenOrdinals.unshift(rd.ord); }); @@ -119,8 +119,8 @@ cp.on('exit', function(code, signal) { srv.close(); // fs.unlinkSync(SOCK_PATH); - assert.equal(code, 0); - assert.equal(seenOrdinals.length, 2); + assert.strictEqual(code, 0); + assert.strictEqual(seenOrdinals.length, 2); }); // vim:ts=2 sw=2 et diff --git a/test/disabled/test-setuidgid.js b/test/disabled/test-setuidgid.js index bf3726ab006d36..ff674f869039d2 100644 --- a/test/disabled/test-setuidgid.js +++ b/test/disabled/test-setuidgid.js @@ -16,7 +16,7 @@ assert.notEqual(newuid, olduid, 'uids expected to be different'); try { process.setuid('nobody1234'); } catch (e) { - assert.equal(e.message, + assert.strictEqual(e.message, 'failed to resolve group', 'unexpected error message' ); diff --git a/test/fixtures/GH-892-request.js b/test/fixtures/GH-892-request.js index 96c355857fea4c..d3f920cccaebd2 100644 --- a/test/fixtures/GH-892-request.js +++ b/test/fixtures/GH-892-request.js @@ -16,7 +16,7 @@ var options = { }; var req = https.request(options, function(res) { - assert.equal(200, res.statusCode); + assert.strictEqual(200, res.statusCode); gotResponse = true; console.error('DONE'); res.resume(); diff --git a/test/fixtures/b/c.js b/test/fixtures/b/c.js index 1b568c2fc9a66e..e606c71f776ac9 100644 --- a/test/fixtures/b/c.js +++ b/test/fixtures/b/c.js @@ -4,7 +4,7 @@ var assert = require('assert'); var package = require('./package'); -assert.equal('world', package.hello); +assert.strictEqual('world', package.hello); console.error('load fixtures/b/c.js'); diff --git a/test/fixtures/node_modules/baz/index.js b/test/fixtures/node_modules/baz/index.js index 859ea0924d6fb7..939f0351699195 100644 --- a/test/fixtures/node_modules/baz/index.js +++ b/test/fixtures/node_modules/baz/index.js @@ -1,10 +1,10 @@ console.error(__filename); console.error(module.paths.join('\n') + '\n'); // this should work, and get the one that doesn't throw -var assert = require('assert'); -assert.equal(require('bar'), require('../bar.js')); +const assert = require('assert'); +assert.strictEqual(require('bar'), require('../bar.js')); // this should work, and get the one in ./node_modules/asdf.js -assert.equal(require('asdf'), require('./node_modules/asdf.js')); +assert.strictEqual(require('asdf'), require('./node_modules/asdf.js')); module.exports = 'eye catcher'; diff --git a/test/fixtures/node_modules/foo.js b/test/fixtures/node_modules/foo.js index f69ac7b00e5a4b..4d4cc9fe12fbc8 100644 --- a/test/fixtures/node_modules/foo.js +++ b/test/fixtures/node_modules/foo.js @@ -1,4 +1,4 @@ console.error(__filename); console.error(module.paths.join('\n') + '\n'); -var assert = require('assert'); -assert.equal(require('baz'), require('./baz/index.js')); +const assert = require('assert'); +assert.strictEqual(require('baz'), require('./baz/index.js')); diff --git a/test/internet/test-dns-txt-sigsegv.js b/test/internet/test-dns-txt-sigsegv.js index 3c85d546cfcddd..54cc4648510ed7 100644 --- a/test/internet/test-dns-txt-sigsegv.js +++ b/test/internet/test-dns-txt-sigsegv.js @@ -4,6 +4,6 @@ const assert = require('assert'); const dns = require('dns'); dns.resolveTxt('www.microsoft.com', function(err, records) { - assert.equal(err, null); - assert.equal(records.length, 0); + assert.strictEqual(err, null); + assert.strictEqual(records.length, 0); }); diff --git a/test/message/error_exit.js b/test/message/error_exit.js index 7235801514dd45..1cb785a1b543a6 100644 --- a/test/message/error_exit.js +++ b/test/message/error_exit.js @@ -6,4 +6,4 @@ process.on('exit', function(code) { console.error('Exiting with code=%d', code); }); -assert.equal(1, 2); +assert.strictEqual(1, 2); diff --git a/test/message/error_exit.out b/test/message/error_exit.out index e25af05861b5ce..e2a29ab42dbbd2 100644 --- a/test/message/error_exit.out +++ b/test/message/error_exit.out @@ -3,7 +3,7 @@ Exiting with code=1 assert.js:* throw new assert.AssertionError({ ^ -AssertionError: 1 == 2 +AssertionError: 1 === 2 at Object. (*test*message*error_exit.js:*:*) at Module._compile (module.js:*:*) at Object.Module._extensions..js (module.js:*:*) diff --git a/test/parallel/test-assert.js b/test/parallel/test-assert.js index 44723ef45bb964..ca25c9965d0640 100644 --- a/test/parallel/test-assert.js +++ b/test/parallel/test-assert.js @@ -355,9 +355,9 @@ try { threw = true; assert.ok(e instanceof TypeError, 'type'); } -assert.equal(true, threw, - 'a.throws with an explicit error is eating extra errors', - a.AssertionError); +assert.strictEqual(true, threw, + 'a.throws with an explicit error is eating extra errors', + a.AssertionError); threw = false; // doesNotThrow should pass through all errors @@ -367,8 +367,8 @@ try { threw = true; assert.ok(e instanceof TypeError); } -assert.equal(true, threw, - 'a.doesNotThrow with an explicit error is eating extra errors'); +assert.strictEqual(true, threw, 'a.doesNotThrow with an explicit error is ' + + 'eating extra errors'); // key difference is that throwing our correct error makes an assertion error try { @@ -377,8 +377,8 @@ try { threw = true; assert.ok(e instanceof a.AssertionError); } -assert.equal(true, threw, - 'a.doesNotThrow is not catching type matching errors'); +assert.strictEqual(true, threw, + 'a.doesNotThrow is not catching type matching errors'); assert.throws(function() { assert.ifError(new Error('test error')); }, /^Error: test error$/); @@ -484,10 +484,10 @@ circular.x = circular; function testAssertionMessage(actual, expected) { try { - assert.equal(actual, ''); + assert.strictEqual(actual, ''); } catch (e) { - assert.equal(e.toString(), - ['AssertionError:', expected, '==', '\'\''].join(' ')); + assert.strictEqual(e.toString(), + ['AssertionError:', expected, '===', '\'\''].join(' ')); assert.ok(e.generatedMessage, 'Message not marked as generated'); } } @@ -522,24 +522,24 @@ try { }); } catch (e) { threw = true; - assert.equal(e.message, 'Missing expected exception..'); + assert.strictEqual(e.message, 'Missing expected exception..'); } assert.ok(threw); // #5292 try { - assert.equal(1, 2); + assert.strictEqual(1, 2); } catch (e) { - assert.equal(e.toString().split('\n')[0], 'AssertionError: 1 == 2'); + assert.strictEqual(e.toString().split('\n')[0], 'AssertionError: 1 === 2'); assert.ok(e.generatedMessage, 'Message not marked as generated'); } try { - assert.equal(1, 2, 'oh no'); + assert.strictEqual(1, 2, 'oh no'); } catch (e) { - assert.equal(e.toString().split('\n')[0], 'AssertionError: oh no'); - assert.equal(e.generatedMessage, false, - 'Message incorrectly marked as generated'); + assert.strictEqual(e.toString().split('\n')[0], 'AssertionError: oh no'); + assert.strictEqual(e.generatedMessage, false, + 'Message incorrectly marked as generated'); } // Verify that throws() and doesNotThrow() throw on non-function block @@ -550,8 +550,8 @@ function testBlockTypeError(method, block) { method(block); threw = false; } catch (e) { - assert.equal(e.toString(), - 'TypeError: "block" argument must be a function'); + assert.strictEqual(e.toString(), + 'TypeError: "block" argument must be a function'); } assert.ok(threw); diff --git a/test/parallel/test-buffer-alloc.js b/test/parallel/test-buffer-alloc.js index 1332a16a3cc807..1a907ba62732db 100644 --- a/test/parallel/test-buffer-alloc.js +++ b/test/parallel/test-buffer-alloc.js @@ -742,7 +742,7 @@ assert.strictEqual('', x.inspect()); Buffer.allocUnsafe(3.3).fill().toString(); // throws bad argument error in commit 43cb4ec Buffer.alloc(3.3).fill().toString(); -assert.equal(Buffer.allocUnsafe(-1).length, 0); +assert.strictEqual(Buffer.allocUnsafe(-1).length, 0); assert.strictEqual(Buffer.allocUnsafe(NaN).length, 0); assert.strictEqual(Buffer.allocUnsafe(3.3).length, 3); assert.strictEqual(Buffer.from({length: 3.3}).length, 3); @@ -779,7 +779,7 @@ Buffer.from(Buffer.allocUnsafe(0), 0, 0); 'ucs-2', 'utf16le', 'utf-16le' ].forEach(function(enc) { - assert.equal(Buffer.isEncoding(enc), true); + assert.strictEqual(Buffer.isEncoding(enc), true); }); [ 'utf9', @@ -794,7 +794,7 @@ Buffer.from(Buffer.allocUnsafe(0), 0, 0); 1, 0, -1 ].forEach(function(enc) { - assert.equal(Buffer.isEncoding(enc), false); + assert.strictEqual(Buffer.isEncoding(enc), false); }); // GH-5110 diff --git a/test/parallel/test-buffer-indexof.js b/test/parallel/test-buffer-indexof.js index 5bb7424581bc6a..f4eba91b8abded 100644 --- a/test/parallel/test-buffer-indexof.js +++ b/test/parallel/test-buffer-indexof.js @@ -73,12 +73,12 @@ assert.strictEqual(b.indexOf('f', 5), 5); assert.strictEqual(b.indexOf('f', -1), 5); assert.strictEqual(b.indexOf('f', 6), -1); -assert.equal(b.indexOf(Buffer.from('d'), 2), 3); -assert.equal(b.indexOf(Buffer.from('f'), 5), 5); -assert.equal(b.indexOf(Buffer.from('f'), -1), 5); -assert.equal(b.indexOf(Buffer.from('f'), 6), -1); +assert.strictEqual(b.indexOf(Buffer.from('d'), 2), 3); +assert.strictEqual(b.indexOf(Buffer.from('f'), 5), 5); +assert.strictEqual(b.indexOf(Buffer.from('f'), -1), 5); +assert.strictEqual(b.indexOf(Buffer.from('f'), 6), -1); -assert.equal(Buffer.from('ff').indexOf(Buffer.from('f'), 1, 'ucs2'), -1); +assert.strictEqual(Buffer.from('ff').indexOf(Buffer.from('f'), 1, 'ucs2'), -1); // test invalid and uppercase encoding assert.strictEqual(b.indexOf('b', 'utf8'), 1); @@ -178,62 +178,67 @@ assert.strictEqual( // test optional offset with passed encoding -assert.equal(Buffer.from('aaaa0').indexOf('30', 'hex'), 4); -assert.equal(Buffer.from('aaaa00a').indexOf('3030', 'hex'), 4); +assert.strictEqual(Buffer.from('aaaa0').indexOf('30', 'hex'), 4); +assert.strictEqual(Buffer.from('aaaa00a').indexOf('3030', 'hex'), 4); { // test usc2 encoding const twoByteString = Buffer.from('\u039a\u0391\u03a3\u03a3\u0395', 'ucs2'); - assert.equal(8, twoByteString.indexOf('\u0395', 4, 'ucs2')); - assert.equal(6, twoByteString.indexOf('\u03a3', -4, 'ucs2')); - assert.equal(4, twoByteString.indexOf('\u03a3', -6, 'ucs2')); - assert.equal(4, twoByteString.indexOf( + assert.strictEqual(8, twoByteString.indexOf('\u0395', 4, 'ucs2')); + assert.strictEqual(6, twoByteString.indexOf('\u03a3', -4, 'ucs2')); + assert.strictEqual(4, twoByteString.indexOf('\u03a3', -6, 'ucs2')); + assert.strictEqual(4, twoByteString.indexOf( Buffer.from('\u03a3', 'ucs2'), -6, 'ucs2')); - assert.equal(-1, twoByteString.indexOf('\u03a3', -2, 'ucs2')); + assert.strictEqual(-1, twoByteString.indexOf('\u03a3', -2, 'ucs2')); } const mixedByteStringUcs2 = Buffer.from('\u039a\u0391abc\u03a3\u03a3\u0395', 'ucs2'); -assert.equal(6, mixedByteStringUcs2.indexOf('bc', 0, 'ucs2')); -assert.equal(10, mixedByteStringUcs2.indexOf('\u03a3', 0, 'ucs2')); -assert.equal(-1, mixedByteStringUcs2.indexOf('\u0396', 0, 'ucs2')); +assert.strictEqual(6, mixedByteStringUcs2.indexOf('bc', 0, 'ucs2')); +assert.strictEqual(10, mixedByteStringUcs2.indexOf('\u03a3', 0, 'ucs2')); +assert.strictEqual(-1, mixedByteStringUcs2.indexOf('\u0396', 0, 'ucs2')); -assert.equal( +assert.strictEqual( 6, mixedByteStringUcs2.indexOf(Buffer.from('bc', 'ucs2'), 0, 'ucs2')); -assert.equal( +assert.strictEqual( 10, mixedByteStringUcs2.indexOf(Buffer.from('\u03a3', 'ucs2'), 0, 'ucs2')); -assert.equal( +assert.strictEqual( -1, mixedByteStringUcs2.indexOf(Buffer.from('\u0396', 'ucs2'), 0, 'ucs2')); { const twoByteString = Buffer.from('\u039a\u0391\u03a3\u03a3\u0395', 'ucs2'); // Test single char pattern - assert.equal(0, twoByteString.indexOf('\u039a', 0, 'ucs2')); - assert.equal(2, twoByteString.indexOf('\u0391', 0, 'ucs2'), 'Alpha'); - assert.equal(4, twoByteString.indexOf('\u03a3', 0, 'ucs2'), 'First Sigma'); - assert.equal(6, twoByteString.indexOf('\u03a3', 6, 'ucs2'), 'Second Sigma'); - assert.equal(8, twoByteString.indexOf('\u0395', 0, 'ucs2'), 'Epsilon'); - assert.equal(-1, twoByteString.indexOf('\u0392', 0, 'ucs2'), 'Not beta'); + assert.strictEqual(0, twoByteString.indexOf('\u039a', 0, 'ucs2')); + assert.strictEqual(2, twoByteString.indexOf('\u0391', 0, 'ucs2'), + 'Alpha'); + assert.strictEqual(4, twoByteString.indexOf('\u03a3', 0, 'ucs2'), + 'First Sigma'); + assert.strictEqual(6, twoByteString.indexOf('\u03a3', 6, 'ucs2'), + 'Second Sigma'); + assert.strictEqual(8, twoByteString.indexOf('\u0395', 0, 'ucs2'), + 'Epsilon'); + assert.strictEqual(-1, twoByteString.indexOf('\u0392', 0, 'ucs2'), + 'Not beta'); // Test multi-char pattern - assert.equal( + assert.strictEqual( 0, twoByteString.indexOf('\u039a\u0391', 0, 'ucs2'), 'Lambda Alpha'); - assert.equal( + assert.strictEqual( 2, twoByteString.indexOf('\u0391\u03a3', 0, 'ucs2'), 'Alpha Sigma'); - assert.equal( + assert.strictEqual( 4, twoByteString.indexOf('\u03a3\u03a3', 0, 'ucs2'), 'Sigma Sigma'); - assert.equal( + assert.strictEqual( 6, twoByteString.indexOf('\u03a3\u0395', 0, 'ucs2'), 'Sigma Epsilon'); } const mixedByteStringUtf8 = Buffer.from('\u039a\u0391abc\u03a3\u03a3\u0395'); -assert.equal(5, mixedByteStringUtf8.indexOf('bc')); -assert.equal(5, mixedByteStringUtf8.indexOf('bc', 5)); -assert.equal(5, mixedByteStringUtf8.indexOf('bc', -8)); -assert.equal(7, mixedByteStringUtf8.indexOf('\u03a3')); -assert.equal(-1, mixedByteStringUtf8.indexOf('\u0396')); +assert.strictEqual(5, mixedByteStringUtf8.indexOf('bc')); +assert.strictEqual(5, mixedByteStringUtf8.indexOf('bc', 5)); +assert.strictEqual(5, mixedByteStringUtf8.indexOf('bc', -8)); +assert.strictEqual(7, mixedByteStringUtf8.indexOf('\u03a3')); +assert.strictEqual(-1, mixedByteStringUtf8.indexOf('\u0396')); // Test complex string indexOf algorithms. Only trigger for long strings. @@ -249,23 +254,25 @@ const longBufferString = Buffer.from(longString); let pattern = 'ABACABADABACABA'; for (let i = 0; i < longBufferString.length - pattern.length; i += 7) { const index = longBufferString.indexOf(pattern, i); - assert.equal((i + 15) & ~0xf, index, 'Long ABACABA...-string at index ' + i); + assert.strictEqual((i + 15) & ~0xf, index, + 'Long ABACABA...-string at index ' + i); } -assert.equal(510, longBufferString.indexOf('AJABACA'), 'Long AJABACA, First J'); -assert.equal( +assert.strictEqual(510, longBufferString.indexOf('AJABACA'), + 'Long AJABACA, First J'); +assert.strictEqual( 1534, longBufferString.indexOf('AJABACA', 511), 'Long AJABACA, Second J'); pattern = 'JABACABADABACABA'; -assert.equal( +assert.strictEqual( 511, longBufferString.indexOf(pattern), 'Long JABACABA..., First J'); -assert.equal( +assert.strictEqual( 1535, longBufferString.indexOf(pattern, 512), 'Long JABACABA..., Second J'); // Search for a non-ASCII string in a pure ASCII string. const asciiString = Buffer.from( 'arglebargleglopglyfarglebargleglopglyfarglebargleglopglyf'); -assert.equal(-1, asciiString.indexOf('\x2061')); -assert.equal(3, asciiString.indexOf('leb', 0)); +assert.strictEqual(-1, asciiString.indexOf('\x2061')); +assert.strictEqual(3, asciiString.indexOf('leb', 0)); // Search in string containing many non-ASCII chars. const allCodePoints = []; @@ -276,8 +283,8 @@ const allCharsBufferUcs2 = Buffer.from(allCharsString, 'ucs2'); // Search for string long enough to trigger complex search with ASCII pattern // and UC16 subject. -assert.equal(-1, allCharsBufferUtf8.indexOf('notfound')); -assert.equal(-1, allCharsBufferUcs2.indexOf('notfound')); +assert.strictEqual(-1, allCharsBufferUtf8.indexOf('notfound')); +assert.strictEqual(-1, allCharsBufferUcs2.indexOf('notfound')); // Needle is longer than haystack, but only because it's encoded as UTF-16 assert.strictEqual(Buffer.from('aaaa').indexOf('a'.repeat(4), 'ucs2'), -1); @@ -310,10 +317,10 @@ assert.strictEqual(Buffer.from('aaaaa').indexOf('b', 'ucs2'), -1); } const patternBufferUtf8 = allCharsBufferUtf8.slice(index, index + length); - assert.equal(index, allCharsBufferUtf8.indexOf(patternBufferUtf8)); + assert.strictEqual(index, allCharsBufferUtf8.indexOf(patternBufferUtf8)); const patternStringUtf8 = patternBufferUtf8.toString(); - assert.equal(index, allCharsBufferUtf8.indexOf(patternStringUtf8)); + assert.strictEqual(index, allCharsBufferUtf8.indexOf(patternStringUtf8)); } } } @@ -329,11 +336,11 @@ assert.strictEqual(Buffer.from('aaaaa').indexOf('b', 'ucs2'), -1); const patternBufferUcs2 = allCharsBufferUcs2.slice(index, index + length); - assert.equal( + assert.strictEqual( index, allCharsBufferUcs2.indexOf(patternBufferUcs2, 0, 'ucs2')); const patternStringUcs2 = patternBufferUcs2.toString('ucs2'); - assert.equal( + assert.strictEqual( index, allCharsBufferUcs2.indexOf(patternStringUcs2, 0, 'ucs2')); } } @@ -385,53 +392,53 @@ assert.strictEqual( // Test lastIndexOf basic functionality; Buffer b contains 'abcdef'. // lastIndexOf string: -assert.equal(b.lastIndexOf('a'), 0); -assert.equal(b.lastIndexOf('a', 1), 0); -assert.equal(b.lastIndexOf('b', 1), 1); -assert.equal(b.lastIndexOf('c', 1), -1); -assert.equal(b.lastIndexOf('a', -1), 0); -assert.equal(b.lastIndexOf('a', -4), 0); -assert.equal(b.lastIndexOf('a', -b.length), 0); -assert.equal(b.lastIndexOf('a', -b.length - 1), -1); -assert.equal(b.lastIndexOf('a', NaN), 0); -assert.equal(b.lastIndexOf('a', -Infinity), -1); -assert.equal(b.lastIndexOf('a', Infinity), 0); +assert.strictEqual(b.lastIndexOf('a'), 0); +assert.strictEqual(b.lastIndexOf('a', 1), 0); +assert.strictEqual(b.lastIndexOf('b', 1), 1); +assert.strictEqual(b.lastIndexOf('c', 1), -1); +assert.strictEqual(b.lastIndexOf('a', -1), 0); +assert.strictEqual(b.lastIndexOf('a', -4), 0); +assert.strictEqual(b.lastIndexOf('a', -b.length), 0); +assert.strictEqual(b.lastIndexOf('a', -b.length - 1), -1); +assert.strictEqual(b.lastIndexOf('a', NaN), 0); +assert.strictEqual(b.lastIndexOf('a', -Infinity), -1); +assert.strictEqual(b.lastIndexOf('a', Infinity), 0); // lastIndexOf Buffer: -assert.equal(b.lastIndexOf(buf_a), 0); -assert.equal(b.lastIndexOf(buf_a, 1), 0); -assert.equal(b.lastIndexOf(buf_a, -1), 0); -assert.equal(b.lastIndexOf(buf_a, -4), 0); -assert.equal(b.lastIndexOf(buf_a, -b.length), 0); -assert.equal(b.lastIndexOf(buf_a, -b.length - 1), -1); -assert.equal(b.lastIndexOf(buf_a, NaN), 0); -assert.equal(b.lastIndexOf(buf_a, -Infinity), -1); -assert.equal(b.lastIndexOf(buf_a, Infinity), 0); -assert.equal(b.lastIndexOf(buf_bc), 1); -assert.equal(b.lastIndexOf(buf_bc, 2), 1); -assert.equal(b.lastIndexOf(buf_bc, -1), 1); -assert.equal(b.lastIndexOf(buf_bc, -3), 1); -assert.equal(b.lastIndexOf(buf_bc, -5), 1); -assert.equal(b.lastIndexOf(buf_bc, -6), -1); -assert.equal(b.lastIndexOf(buf_bc, NaN), 1); -assert.equal(b.lastIndexOf(buf_bc, -Infinity), -1); -assert.equal(b.lastIndexOf(buf_bc, Infinity), 1); -assert.equal(b.lastIndexOf(buf_f), b.length - 1); -assert.equal(b.lastIndexOf(buf_z), -1); -assert.equal(b.lastIndexOf(buf_empty), -1); -assert.equal(b.lastIndexOf(buf_empty, 1), -1); -assert.equal(b.lastIndexOf(buf_empty, b.length + 1), -1); -assert.equal(b.lastIndexOf(buf_empty, Infinity), -1); +assert.strictEqual(b.lastIndexOf(buf_a), 0); +assert.strictEqual(b.lastIndexOf(buf_a, 1), 0); +assert.strictEqual(b.lastIndexOf(buf_a, -1), 0); +assert.strictEqual(b.lastIndexOf(buf_a, -4), 0); +assert.strictEqual(b.lastIndexOf(buf_a, -b.length), 0); +assert.strictEqual(b.lastIndexOf(buf_a, -b.length - 1), -1); +assert.strictEqual(b.lastIndexOf(buf_a, NaN), 0); +assert.strictEqual(b.lastIndexOf(buf_a, -Infinity), -1); +assert.strictEqual(b.lastIndexOf(buf_a, Infinity), 0); +assert.strictEqual(b.lastIndexOf(buf_bc), 1); +assert.strictEqual(b.lastIndexOf(buf_bc, 2), 1); +assert.strictEqual(b.lastIndexOf(buf_bc, -1), 1); +assert.strictEqual(b.lastIndexOf(buf_bc, -3), 1); +assert.strictEqual(b.lastIndexOf(buf_bc, -5), 1); +assert.strictEqual(b.lastIndexOf(buf_bc, -6), -1); +assert.strictEqual(b.lastIndexOf(buf_bc, NaN), 1); +assert.strictEqual(b.lastIndexOf(buf_bc, -Infinity), -1); +assert.strictEqual(b.lastIndexOf(buf_bc, Infinity), 1); +assert.strictEqual(b.lastIndexOf(buf_f), b.length - 1); +assert.strictEqual(b.lastIndexOf(buf_z), -1); +assert.strictEqual(b.lastIndexOf(buf_empty), -1); +assert.strictEqual(b.lastIndexOf(buf_empty, 1), -1); +assert.strictEqual(b.lastIndexOf(buf_empty, b.length + 1), -1); +assert.strictEqual(b.lastIndexOf(buf_empty, Infinity), -1); // lastIndexOf number: -assert.equal(b.lastIndexOf(0x61), 0); -assert.equal(b.lastIndexOf(0x61, 1), 0); -assert.equal(b.lastIndexOf(0x61, -1), 0); -assert.equal(b.lastIndexOf(0x61, -4), 0); -assert.equal(b.lastIndexOf(0x61, -b.length), 0); -assert.equal(b.lastIndexOf(0x61, -b.length - 1), -1); -assert.equal(b.lastIndexOf(0x61, NaN), 0); -assert.equal(b.lastIndexOf(0x61, -Infinity), -1); -assert.equal(b.lastIndexOf(0x61, Infinity), 0); -assert.equal(b.lastIndexOf(0x0), -1); +assert.strictEqual(b.lastIndexOf(0x61), 0); +assert.strictEqual(b.lastIndexOf(0x61, 1), 0); +assert.strictEqual(b.lastIndexOf(0x61, -1), 0); +assert.strictEqual(b.lastIndexOf(0x61, -4), 0); +assert.strictEqual(b.lastIndexOf(0x61, -b.length), 0); +assert.strictEqual(b.lastIndexOf(0x61, -b.length - 1), -1); +assert.strictEqual(b.lastIndexOf(0x61, NaN), 0); +assert.strictEqual(b.lastIndexOf(0x61, -Infinity), -1); +assert.strictEqual(b.lastIndexOf(0x61, Infinity), 0); +assert.strictEqual(b.lastIndexOf(0x0), -1); // Test weird offset arguments. // The following offsets coerce to NaN, searching the whole Buffer @@ -492,20 +499,21 @@ assert.strictEqual(buf_bc.lastIndexOf(Buffer.from('你好'), 7), -1); // Test lastIndexOf on a longer buffer: const bufferString = new Buffer('a man a plan a canal panama'); -assert.equal(15, bufferString.lastIndexOf('canal')); -assert.equal(21, bufferString.lastIndexOf('panama')); -assert.equal(0, bufferString.lastIndexOf('a man a plan a canal panama')); -assert.equal(-1, bufferString.lastIndexOf('a man a plan a canal mexico')); -assert.equal(-1, bufferString.lastIndexOf('a man a plan a canal mexico city')); -assert.equal(-1, bufferString.lastIndexOf(Buffer.from('a'.repeat(1000)))); -assert.equal(0, bufferString.lastIndexOf('a man a plan', 4)); -assert.equal(13, bufferString.lastIndexOf('a ')); -assert.equal(13, bufferString.lastIndexOf('a ', 13)); -assert.equal(6, bufferString.lastIndexOf('a ', 12)); -assert.equal(0, bufferString.lastIndexOf('a ', 5)); -assert.equal(13, bufferString.lastIndexOf('a ', -1)); -assert.equal(0, bufferString.lastIndexOf('a ', -27)); -assert.equal(-1, bufferString.lastIndexOf('a ', -28)); +assert.strictEqual(15, bufferString.lastIndexOf('canal')); +assert.strictEqual(21, bufferString.lastIndexOf('panama')); +assert.strictEqual(0, bufferString.lastIndexOf('a man a plan a canal panama')); +assert.strictEqual(-1, bufferString.lastIndexOf('a man a plan a canal mexico')); +assert.strictEqual(-1, bufferString + .lastIndexOf('a man a plan a canal mexico city')); +assert.strictEqual(-1, bufferString.lastIndexOf(Buffer.from('a'.repeat(1000)))); +assert.strictEqual(0, bufferString.lastIndexOf('a man a plan', 4)); +assert.strictEqual(13, bufferString.lastIndexOf('a ')); +assert.strictEqual(13, bufferString.lastIndexOf('a ', 13)); +assert.strictEqual(6, bufferString.lastIndexOf('a ', 12)); +assert.strictEqual(0, bufferString.lastIndexOf('a ', 5)); +assert.strictEqual(13, bufferString.lastIndexOf('a ', -1)); +assert.strictEqual(0, bufferString.lastIndexOf('a ', -27)); +assert.strictEqual(-1, bufferString.lastIndexOf('a ', -28)); // Test lastIndexOf for the case that the first character can be found, // but in a part of the buffer that does not make search to search @@ -529,9 +537,9 @@ assert.strictEqual(0, Buffer.from('abc').lastIndexOf('ab', 3)); // Now, we test the BOYER-MOORE-HORSPOOL strategy. // Test lastIndexOf on a long buffer w multiple matches: pattern = 'JABACABADABACABA'; -assert.equal(1535, longBufferString.lastIndexOf(pattern)); -assert.equal(1535, longBufferString.lastIndexOf(pattern, 1535)); -assert.equal(511, longBufferString.lastIndexOf(pattern, 1534)); +assert.strictEqual(1535, longBufferString.lastIndexOf(pattern)); +assert.strictEqual(1535, longBufferString.lastIndexOf(pattern, 1535)); +assert.strictEqual(511, longBufferString.lastIndexOf(pattern, 1534)); // Finally, give it a really long input to trigger fallback from BMH to // regular BOYER-MOORE (which has better worst-case complexity). @@ -553,19 +561,19 @@ for (let i = 0; i < 1000000; i++) { parts.push((countBits(i) % 2 === 0) ? 'yolo' : 'swag'); } const reallyLong = new Buffer(parts.join(' ')); -assert.equal('yolo swag swag yolo', reallyLong.slice(0, 19).toString()); +assert.strictEqual('yolo swag swag yolo', reallyLong.slice(0, 19).toString()); // Expensive reverse searches. Stress test lastIndexOf: pattern = reallyLong.slice(0, 100000); // First 1/50th of the pattern. -assert.equal(4751360, reallyLong.lastIndexOf(pattern)); -assert.equal(3932160, reallyLong.lastIndexOf(pattern, 4000000)); -assert.equal(2949120, reallyLong.lastIndexOf(pattern, 3000000)); +assert.strictEqual(4751360, reallyLong.lastIndexOf(pattern)); +assert.strictEqual(3932160, reallyLong.lastIndexOf(pattern, 4000000)); +assert.strictEqual(2949120, reallyLong.lastIndexOf(pattern, 3000000)); pattern = reallyLong.slice(100000, 200000); // Second 1/50th. -assert.equal(4728480, reallyLong.lastIndexOf(pattern)); +assert.strictEqual(4728480, reallyLong.lastIndexOf(pattern)); pattern = reallyLong.slice(0, 1000000); // First 1/5th. -assert.equal(3932160, reallyLong.lastIndexOf(pattern)); +assert.strictEqual(3932160, reallyLong.lastIndexOf(pattern)); pattern = reallyLong.slice(0, 2000000); // first 2/5ths. -assert.equal(0, reallyLong.lastIndexOf(pattern)); +assert.strictEqual(0, reallyLong.lastIndexOf(pattern)); // test truncation of Number arguments to uint8 { diff --git a/test/parallel/test-buffer.js b/test/parallel/test-buffer.js index d07ccc3550aece..805c8b9e7ac347 100644 --- a/test/parallel/test-buffer.js +++ b/test/parallel/test-buffer.js @@ -54,41 +54,41 @@ Buffer(8).fill(''); const buf = new Buffer(64); buf.fill(10); for (let i = 0; i < buf.length; i++) - assert.equal(buf[i], 10); + assert.strictEqual(buf[i], 10); buf.fill(11, 0, buf.length >> 1); for (let i = 0; i < buf.length >> 1; i++) - assert.equal(buf[i], 11); + assert.strictEqual(buf[i], 11); for (let i = (buf.length >> 1) + 1; i < buf.length; i++) - assert.equal(buf[i], 10); + assert.strictEqual(buf[i], 10); buf.fill('h'); for (let i = 0; i < buf.length; i++) - assert.equal('h'.charCodeAt(0), buf[i]); + assert.strictEqual('h'.charCodeAt(0), buf[i]); buf.fill(0); for (let i = 0; i < buf.length; i++) - assert.equal(0, buf[i]); + assert.strictEqual(0, buf[i]); buf.fill(null); for (let i = 0; i < buf.length; i++) - assert.equal(0, buf[i]); + assert.strictEqual(0, buf[i]); buf.fill(1, 16, 32); for (let i = 0; i < 16; i++) - assert.equal(0, buf[i]); + assert.strictEqual(0, buf[i]); for (let i = 16; i < 32; i++) - assert.equal(1, buf[i]); + assert.strictEqual(1, buf[i]); for (let i = 32; i < buf.length; i++) - assert.equal(0, buf[i]); + assert.strictEqual(0, buf[i]); } { const buf = new Buffer(10); buf.fill('abc'); - assert.equal(buf.toString(), 'abcabcabca'); + assert.strictEqual(buf.toString(), 'abcabcabca'); buf.fill('է'); - assert.equal(buf.toString(), 'էէէէէ'); + assert.strictEqual(buf.toString(), 'էէէէէ'); } { @@ -209,10 +209,10 @@ assert.throws(function() { }, RangeError); // when sourceStart is greater than sourceEnd, zero copied -assert.equal(b.copy(c, 0, 100, 10), 0); +assert.strictEqual(b.copy(c, 0, 100, 10), 0); // when targetStart > targetLength, zero copied -assert.equal(b.copy(c, 512, 0, 10), 0); +assert.strictEqual(b.copy(c, 512, 0, 10), 0); let caught_error; @@ -274,80 +274,80 @@ b.copy(Buffer(1), 0, 2048, 2048); const rangeBuffer = new Buffer('abc'); // if start >= buffer's length, empty string will be returned -assert.equal(rangeBuffer.toString('ascii', 3), ''); -assert.equal(rangeBuffer.toString('ascii', +Infinity), ''); -assert.equal(rangeBuffer.toString('ascii', 3.14, 3), ''); -assert.equal(rangeBuffer.toString('ascii', 'Infinity', 3), ''); +assert.strictEqual(rangeBuffer.toString('ascii', 3), ''); +assert.strictEqual(rangeBuffer.toString('ascii', +Infinity), ''); +assert.strictEqual(rangeBuffer.toString('ascii', 3.14, 3), ''); +assert.strictEqual(rangeBuffer.toString('ascii', 'Infinity', 3), ''); // if end <= 0, empty string will be returned -assert.equal(rangeBuffer.toString('ascii', 1, 0), ''); -assert.equal(rangeBuffer.toString('ascii', 1, -1.2), ''); -assert.equal(rangeBuffer.toString('ascii', 1, -100), ''); -assert.equal(rangeBuffer.toString('ascii', 1, -Infinity), ''); +assert.strictEqual(rangeBuffer.toString('ascii', 1, 0), ''); +assert.strictEqual(rangeBuffer.toString('ascii', 1, -1.2), ''); +assert.strictEqual(rangeBuffer.toString('ascii', 1, -100), ''); +assert.strictEqual(rangeBuffer.toString('ascii', 1, -Infinity), ''); // if start < 0, start will be taken as zero -assert.equal(rangeBuffer.toString('ascii', -1, 3), 'abc'); -assert.equal(rangeBuffer.toString('ascii', -1.99, 3), 'abc'); -assert.equal(rangeBuffer.toString('ascii', -Infinity, 3), 'abc'); -assert.equal(rangeBuffer.toString('ascii', '-1', 3), 'abc'); -assert.equal(rangeBuffer.toString('ascii', '-1.99', 3), 'abc'); -assert.equal(rangeBuffer.toString('ascii', '-Infinity', 3), 'abc'); +assert.strictEqual(rangeBuffer.toString('ascii', -1, 3), 'abc'); +assert.strictEqual(rangeBuffer.toString('ascii', -1.99, 3), 'abc'); +assert.strictEqual(rangeBuffer.toString('ascii', -Infinity, 3), 'abc'); +assert.strictEqual(rangeBuffer.toString('ascii', '-1', 3), 'abc'); +assert.strictEqual(rangeBuffer.toString('ascii', '-1.99', 3), 'abc'); +assert.strictEqual(rangeBuffer.toString('ascii', '-Infinity', 3), 'abc'); // if start is an invalid integer, start will be taken as zero -assert.equal(rangeBuffer.toString('ascii', 'node.js', 3), 'abc'); -assert.equal(rangeBuffer.toString('ascii', {}, 3), 'abc'); -assert.equal(rangeBuffer.toString('ascii', [], 3), 'abc'); -assert.equal(rangeBuffer.toString('ascii', NaN, 3), 'abc'); -assert.equal(rangeBuffer.toString('ascii', null, 3), 'abc'); -assert.equal(rangeBuffer.toString('ascii', undefined, 3), 'abc'); -assert.equal(rangeBuffer.toString('ascii', false, 3), 'abc'); -assert.equal(rangeBuffer.toString('ascii', '', 3), 'abc'); +assert.strictEqual(rangeBuffer.toString('ascii', 'node.js', 3), 'abc'); +assert.strictEqual(rangeBuffer.toString('ascii', {}, 3), 'abc'); +assert.strictEqual(rangeBuffer.toString('ascii', [], 3), 'abc'); +assert.strictEqual(rangeBuffer.toString('ascii', NaN, 3), 'abc'); +assert.strictEqual(rangeBuffer.toString('ascii', null, 3), 'abc'); +assert.strictEqual(rangeBuffer.toString('ascii', undefined, 3), 'abc'); +assert.strictEqual(rangeBuffer.toString('ascii', false, 3), 'abc'); +assert.strictEqual(rangeBuffer.toString('ascii', '', 3), 'abc'); // but, if start is an integer when coerced, then it will be coerced and used. -assert.equal(rangeBuffer.toString('ascii', '-1', 3), 'abc'); -assert.equal(rangeBuffer.toString('ascii', '1', 3), 'bc'); -assert.equal(rangeBuffer.toString('ascii', '-Infinity', 3), 'abc'); -assert.equal(rangeBuffer.toString('ascii', '3', 3), ''); -assert.equal(rangeBuffer.toString('ascii', Number(3), 3), ''); -assert.equal(rangeBuffer.toString('ascii', '3.14', 3), ''); -assert.equal(rangeBuffer.toString('ascii', '1.99', 3), 'bc'); -assert.equal(rangeBuffer.toString('ascii', '-1.99', 3), 'abc'); -assert.equal(rangeBuffer.toString('ascii', 1.99, 3), 'bc'); -assert.equal(rangeBuffer.toString('ascii', true, 3), 'bc'); +assert.strictEqual(rangeBuffer.toString('ascii', '-1', 3), 'abc'); +assert.strictEqual(rangeBuffer.toString('ascii', '1', 3), 'bc'); +assert.strictEqual(rangeBuffer.toString('ascii', '-Infinity', 3), 'abc'); +assert.strictEqual(rangeBuffer.toString('ascii', '3', 3), ''); +assert.strictEqual(rangeBuffer.toString('ascii', Number(3), 3), ''); +assert.strictEqual(rangeBuffer.toString('ascii', '3.14', 3), ''); +assert.strictEqual(rangeBuffer.toString('ascii', '1.99', 3), 'bc'); +assert.strictEqual(rangeBuffer.toString('ascii', '-1.99', 3), 'abc'); +assert.strictEqual(rangeBuffer.toString('ascii', 1.99, 3), 'bc'); +assert.strictEqual(rangeBuffer.toString('ascii', true, 3), 'bc'); // if end > buffer's length, end will be taken as buffer's length -assert.equal(rangeBuffer.toString('ascii', 0, 5), 'abc'); -assert.equal(rangeBuffer.toString('ascii', 0, 6.99), 'abc'); -assert.equal(rangeBuffer.toString('ascii', 0, Infinity), 'abc'); -assert.equal(rangeBuffer.toString('ascii', 0, '5'), 'abc'); -assert.equal(rangeBuffer.toString('ascii', 0, '6.99'), 'abc'); -assert.equal(rangeBuffer.toString('ascii', 0, 'Infinity'), 'abc'); +assert.strictEqual(rangeBuffer.toString('ascii', 0, 5), 'abc'); +assert.strictEqual(rangeBuffer.toString('ascii', 0, 6.99), 'abc'); +assert.strictEqual(rangeBuffer.toString('ascii', 0, Infinity), 'abc'); +assert.strictEqual(rangeBuffer.toString('ascii', 0, '5'), 'abc'); +assert.strictEqual(rangeBuffer.toString('ascii', 0, '6.99'), 'abc'); +assert.strictEqual(rangeBuffer.toString('ascii', 0, 'Infinity'), 'abc'); // if end is an invalid integer, end will be taken as buffer's length -assert.equal(rangeBuffer.toString('ascii', 0, 'node.js'), ''); -assert.equal(rangeBuffer.toString('ascii', 0, {}), ''); -assert.equal(rangeBuffer.toString('ascii', 0, NaN), ''); -assert.equal(rangeBuffer.toString('ascii', 0, undefined), 'abc'); -assert.equal(rangeBuffer.toString('ascii', 0), 'abc'); -assert.equal(rangeBuffer.toString('ascii', 0, null), ''); -assert.equal(rangeBuffer.toString('ascii', 0, []), ''); -assert.equal(rangeBuffer.toString('ascii', 0, false), ''); -assert.equal(rangeBuffer.toString('ascii', 0, ''), ''); +assert.strictEqual(rangeBuffer.toString('ascii', 0, 'node.js'), ''); +assert.strictEqual(rangeBuffer.toString('ascii', 0, {}), ''); +assert.strictEqual(rangeBuffer.toString('ascii', 0, NaN), ''); +assert.strictEqual(rangeBuffer.toString('ascii', 0, undefined), 'abc'); +assert.strictEqual(rangeBuffer.toString('ascii', 0), 'abc'); +assert.strictEqual(rangeBuffer.toString('ascii', 0, null), ''); +assert.strictEqual(rangeBuffer.toString('ascii', 0, []), ''); +assert.strictEqual(rangeBuffer.toString('ascii', 0, false), ''); +assert.strictEqual(rangeBuffer.toString('ascii', 0, ''), ''); // but, if end is an integer when coerced, then it will be coerced and used. -assert.equal(rangeBuffer.toString('ascii', 0, '-1'), ''); -assert.equal(rangeBuffer.toString('ascii', 0, '1'), 'a'); -assert.equal(rangeBuffer.toString('ascii', 0, '-Infinity'), ''); -assert.equal(rangeBuffer.toString('ascii', 0, '3'), 'abc'); -assert.equal(rangeBuffer.toString('ascii', 0, Number(3)), 'abc'); -assert.equal(rangeBuffer.toString('ascii', 0, '3.14'), 'abc'); -assert.equal(rangeBuffer.toString('ascii', 0, '1.99'), 'a'); -assert.equal(rangeBuffer.toString('ascii', 0, '-1.99'), ''); -assert.equal(rangeBuffer.toString('ascii', 0, 1.99), 'a'); -assert.equal(rangeBuffer.toString('ascii', 0, true), 'a'); +assert.strictEqual(rangeBuffer.toString('ascii', 0, '-1'), ''); +assert.strictEqual(rangeBuffer.toString('ascii', 0, '1'), 'a'); +assert.strictEqual(rangeBuffer.toString('ascii', 0, '-Infinity'), ''); +assert.strictEqual(rangeBuffer.toString('ascii', 0, '3'), 'abc'); +assert.strictEqual(rangeBuffer.toString('ascii', 0, Number(3)), 'abc'); +assert.strictEqual(rangeBuffer.toString('ascii', 0, '3.14'), 'abc'); +assert.strictEqual(rangeBuffer.toString('ascii', 0, '1.99'), 'a'); +assert.strictEqual(rangeBuffer.toString('ascii', 0, '-1.99'), ''); +assert.strictEqual(rangeBuffer.toString('ascii', 0, 1.99), 'a'); +assert.strictEqual(rangeBuffer.toString('ascii', 0, true), 'a'); // try toString() with a object as a encoding -assert.equal(rangeBuffer.toString({toString: function() { +assert.strictEqual(rangeBuffer.toString({toString: function() { return 'ascii'; }}), 'abc'); @@ -358,7 +358,7 @@ writeTest.write('o', '1', 'ascii'); writeTest.write('d', '2', 'ascii'); writeTest.write('e', 3, 'ascii'); writeTest.write('j', 4, 'ascii'); -assert.equal(writeTest.toString(), 'nodejs'); +assert.strictEqual(writeTest.toString(), 'nodejs'); // ASCII slice test { @@ -368,7 +368,7 @@ assert.equal(writeTest.toString(), 'nodejs'); b[i] = asciiString.charCodeAt(i); } const asciiSlice = b.toString('ascii', 0, asciiString.length); - assert.equal(asciiString, asciiSlice); + assert.strictEqual(asciiString, asciiSlice); } { @@ -376,9 +376,9 @@ assert.equal(writeTest.toString(), 'nodejs'); const offset = 100; const written = b.write(asciiString, offset, 'ascii'); - assert.equal(asciiString.length, written); + assert.strictEqual(asciiString.length, written); const asciiSlice = b.toString('ascii', offset, offset + asciiString.length); - assert.equal(asciiString, asciiSlice); + assert.strictEqual(asciiString, asciiSlice); } { @@ -388,7 +388,7 @@ assert.equal(writeTest.toString(), 'nodejs'); const sliceA = b.slice(offset, offset + asciiString.length); const sliceB = b.slice(offset, offset + asciiString.length); for (let i = 0; i < asciiString.length; i++) { - assert.equal(sliceA[i], sliceB[i]); + assert.strictEqual(sliceA[i], sliceB[i]); } } @@ -399,24 +399,24 @@ const offset = 100; b.write(utf8String, 0, Buffer.byteLength(utf8String), 'utf8'); let utf8Slice = b.toString('utf8', 0, Buffer.byteLength(utf8String)); -assert.equal(utf8String, utf8Slice); +assert.strictEqual(utf8String, utf8Slice); let written = b.write(utf8String, offset, 'utf8'); -assert.equal(Buffer.byteLength(utf8String), written); +assert.strictEqual(Buffer.byteLength(utf8String), written); utf8Slice = b.toString('utf8', offset, offset + Buffer.byteLength(utf8String)); -assert.equal(utf8String, utf8Slice); +assert.strictEqual(utf8String, utf8Slice); const sliceA = b.slice(offset, offset + Buffer.byteLength(utf8String)); const sliceB = b.slice(offset, offset + Buffer.byteLength(utf8String)); for (let i = 0; i < Buffer.byteLength(utf8String); i++) { - assert.equal(sliceA[i], sliceB[i]); + assert.strictEqual(sliceA[i], sliceB[i]); } { const slice = b.slice(100, 150); - assert.equal(50, slice.length); + assert.strictEqual(50, slice.length); for (let i = 0; i < 50; i++) { - assert.equal(b[100 + i], slice[i]); + assert.strictEqual(b[100 + i], slice[i]); } } @@ -425,8 +425,8 @@ for (let i = 0; i < Buffer.byteLength(utf8String); i++) { const b = new Buffer(5); const c = b.slice(0, 4); const d = c.slice(0, 2); - assert.equal(b.parent, c.parent); - assert.equal(b.parent, d.parent); + assert.strictEqual(b.parent, c.parent); + assert.strictEqual(b.parent, d.parent); } { @@ -434,7 +434,7 @@ for (let i = 0; i < Buffer.byteLength(utf8String); i++) { const b = new SlowBuffer(5); const c = b.slice(0, 4); const d = c.slice(0, 2); - assert.equal(c.parent, d.parent); + assert.strictEqual(c.parent, d.parent); } { @@ -444,7 +444,7 @@ for (let i = 0; i < Buffer.byteLength(utf8String); i++) { const size = buffer.write(testValue, 0, 'utf8'); console.log('bytes written to buffer: ' + size); const slice = buffer.toString('utf8', 0, size); - assert.equal(slice, testValue); + assert.strictEqual(slice, testValue); } { @@ -452,21 +452,21 @@ for (let i = 0; i < Buffer.byteLength(utf8String); i++) { const a = new Buffer(8); for (let i = 0; i < 8; i++) a[i] = i; const b = a.slice(4, 8); - assert.equal(4, b[0]); - assert.equal(5, b[1]); - assert.equal(6, b[2]); - assert.equal(7, b[3]); + assert.strictEqual(4, b[0]); + assert.strictEqual(5, b[1]); + assert.strictEqual(6, b[2]); + assert.strictEqual(7, b[3]); const c = b.slice(2, 4); - assert.equal(6, c[0]); - assert.equal(7, c[1]); + assert.strictEqual(6, c[0]); + assert.strictEqual(7, c[1]); } { const d = new Buffer([23, 42, 255]); - assert.equal(d.length, 3); - assert.equal(d[0], 23); - assert.equal(d[1], 42); - assert.equal(d[2], 255); + assert.strictEqual(d.length, 3); + assert.strictEqual(d[0], 23); + assert.strictEqual(d[1], 42); + assert.strictEqual(d[2], 255); assert.deepStrictEqual(d, new Buffer(d)); } @@ -494,22 +494,22 @@ for (let i = 0; i < Buffer.byteLength(utf8String); i++) { console.error('f.length: %d (should be 12)', f.length); const expected = new Buffer([63, 4, 64, 4, 56, 4, 50, 4, 53, 4, 66, 4]); assert.deepStrictEqual(f, expected); - assert.equal(f.toString(encoding), 'привет'); + assert.strictEqual(f.toString(encoding), 'привет'); } { const f = new Buffer([0, 0, 0, 0, 0]); - assert.equal(f.length, 5); + assert.strictEqual(f.length, 5); const size = f.write('あいうえお', encoding); console.error('bytes written to buffer: %d (should be 4)', size); - assert.equal(size, 4); + assert.strictEqual(size, 4); assert.deepStrictEqual(f, new Buffer([0x42, 0x30, 0x44, 0x30, 0x00])); } }); { const f = new Buffer('\uD83D\uDC4D', 'utf-16le'); // THUMBS UP SIGN (U+1F44D) - assert.equal(f.length, 4); + assert.strictEqual(f.length, 4); assert.deepStrictEqual(f, new Buffer('3DD84DDC', 'hex')); } @@ -525,7 +525,7 @@ assert.deepStrictEqual(g, new Buffer([0, 1, 2, 3])); // // Test toString('base64') // -assert.equal('TWFu', (new Buffer('Man')).toString('base64')); +assert.strictEqual('TWFu', (new Buffer('Man')).toString('base64')); { // test that regular and URL-safe base64 both work @@ -548,12 +548,12 @@ assert.equal('TWFu', (new Buffer('Man')).toString('base64')); 'dWVkIGFuZCBpbmRlZmF0aWdhYmxlIGdlbmVyYXRpb24gb2Yga25vd2xlZ' + 'GdlLCBleGNlZWRzIHRoZSBzaG9ydCB2ZWhlbWVuY2Ugb2YgYW55IGNhcm' + '5hbCBwbGVhc3VyZS4='; - assert.equal(expected, (new Buffer(quote)).toString('base64')); + assert.strictEqual(expected, (new Buffer(quote)).toString('base64')); let b = new Buffer(1024); let bytesWritten = b.write(expected, 0, 'base64'); - assert.equal(quote.length, bytesWritten); - assert.equal(quote, b.toString('ascii', 0, quote.length)); + assert.strictEqual(quote.length, bytesWritten); + assert.strictEqual(quote, b.toString('ascii', 0, quote.length)); // check that the base64 decoder ignores whitespace const expectedWhite = expected.slice(0, 60) + ' \n' + @@ -564,14 +564,14 @@ assert.equal('TWFu', (new Buffer('Man')).toString('base64')); expected.slice(300, 360) + '\n'; b = new Buffer(1024); bytesWritten = b.write(expectedWhite, 0, 'base64'); - assert.equal(quote.length, bytesWritten); - assert.equal(quote, b.toString('ascii', 0, quote.length)); + assert.strictEqual(quote.length, bytesWritten); + assert.strictEqual(quote, b.toString('ascii', 0, quote.length)); // check that the base64 decoder on the constructor works // even in the presence of whitespace. b = new Buffer(expectedWhite, 'base64'); - assert.equal(quote.length, b.length); - assert.equal(quote, b.toString('ascii', 0, quote.length)); + assert.strictEqual(quote.length, b.length); + assert.strictEqual(quote, b.toString('ascii', 0, quote.length)); // check that the base64 decoder ignores illegal chars const expectedIllegal = expected.slice(0, 60) + ' \x80' + @@ -581,101 +581,104 @@ assert.equal('TWFu', (new Buffer('Man')).toString('base64')); expected.slice(240, 300) + '\x03' + expected.slice(300, 360); b = new Buffer(expectedIllegal, 'base64'); - assert.equal(quote.length, b.length); - assert.equal(quote, b.toString('ascii', 0, quote.length)); + assert.strictEqual(quote.length, b.length); + assert.strictEqual(quote, b.toString('ascii', 0, quote.length)); } -assert.equal(new Buffer('', 'base64').toString(), ''); -assert.equal(new Buffer('K', 'base64').toString(), ''); +assert.strictEqual(new Buffer('', 'base64').toString(), ''); +assert.strictEqual(new Buffer('K', 'base64').toString(), ''); // multiple-of-4 with padding -assert.equal(new Buffer('Kg==', 'base64').toString(), '*'); -assert.equal(new Buffer('Kio=', 'base64').toString(), '**'); -assert.equal(new Buffer('Kioq', 'base64').toString(), '***'); -assert.equal(new Buffer('KioqKg==', 'base64').toString(), '****'); -assert.equal(new Buffer('KioqKio=', 'base64').toString(), '*****'); -assert.equal(new Buffer('KioqKioq', 'base64').toString(), '******'); -assert.equal(new Buffer('KioqKioqKg==', 'base64').toString(), '*******'); -assert.equal(new Buffer('KioqKioqKio=', 'base64').toString(), '********'); -assert.equal(new Buffer('KioqKioqKioq', 'base64').toString(), '*********'); -assert.equal(new Buffer('KioqKioqKioqKg==', 'base64').toString(), - '**********'); -assert.equal(new Buffer('KioqKioqKioqKio=', 'base64').toString(), - '***********'); -assert.equal(new Buffer('KioqKioqKioqKioq', 'base64').toString(), - '************'); -assert.equal(new Buffer('KioqKioqKioqKioqKg==', 'base64').toString(), - '*************'); -assert.equal(new Buffer('KioqKioqKioqKioqKio=', 'base64').toString(), - '**************'); -assert.equal(new Buffer('KioqKioqKioqKioqKioq', 'base64').toString(), - '***************'); -assert.equal(new Buffer('KioqKioqKioqKioqKioqKg==', 'base64').toString(), - '****************'); -assert.equal(new Buffer('KioqKioqKioqKioqKioqKio=', 'base64').toString(), - '*****************'); -assert.equal(new Buffer('KioqKioqKioqKioqKioqKioq', 'base64').toString(), - '******************'); -assert.equal(new Buffer('KioqKioqKioqKioqKioqKioqKg==', 'base64').toString(), - '*******************'); -assert.equal(new Buffer('KioqKioqKioqKioqKioqKioqKio=', 'base64').toString(), - '********************'); +assert.strictEqual(new Buffer('Kg==', 'base64').toString(), '*'); +assert.strictEqual(new Buffer('Kio=', 'base64').toString(), '**'); +assert.strictEqual(new Buffer('Kioq', 'base64').toString(), '***'); +assert.strictEqual(new Buffer('KioqKg==', 'base64').toString(), '****'); +assert.strictEqual(new Buffer('KioqKio=', 'base64').toString(), '*****'); +assert.strictEqual(new Buffer('KioqKioq', 'base64').toString(), '******'); +assert.strictEqual(new Buffer('KioqKioqKg==', 'base64').toString(), '*******'); +assert.strictEqual(new Buffer('KioqKioqKio=', 'base64').toString(), '********'); +assert.strictEqual(new Buffer('KioqKioqKioq', 'base64').toString(), + '*********'); +assert.strictEqual(new Buffer('KioqKioqKioqKg==', 'base64').toString(), + '**********'); +assert.strictEqual(new Buffer('KioqKioqKioqKio=', 'base64').toString(), + '***********'); +assert.strictEqual(new Buffer('KioqKioqKioqKioq', 'base64').toString(), + '************'); +assert.strictEqual(new Buffer('KioqKioqKioqKioqKg==', 'base64').toString(), + '*************'); +assert.strictEqual(new Buffer('KioqKioqKioqKioqKio=', 'base64').toString(), + '**************'); +assert.strictEqual(new Buffer('KioqKioqKioqKioqKioq', 'base64').toString(), + '***************'); +assert.strictEqual(new Buffer('KioqKioqKioqKioqKioqKg==', 'base64').toString(), + '****************'); +assert.strictEqual(new Buffer('KioqKioqKioqKioqKioqKio=', 'base64').toString(), + '*****************'); +assert.strictEqual(new Buffer('KioqKioqKioqKioqKioqKioq', 'base64').toString(), + '******************'); +assert.strictEqual(new Buffer('KioqKioqKioqKioqKioqKioqKg==', 'base64') + .toString(), '*******************'); +assert.strictEqual(new Buffer('KioqKioqKioqKioqKioqKioqKio=', 'base64') + .toString(), '********************'); // no padding, not a multiple of 4 -assert.equal(new Buffer('Kg', 'base64').toString(), '*'); -assert.equal(new Buffer('Kio', 'base64').toString(), '**'); -assert.equal(new Buffer('KioqKg', 'base64').toString(), '****'); -assert.equal(new Buffer('KioqKio', 'base64').toString(), '*****'); -assert.equal(new Buffer('KioqKioqKg', 'base64').toString(), '*******'); -assert.equal(new Buffer('KioqKioqKio', 'base64').toString(), '********'); -assert.equal(new Buffer('KioqKioqKioqKg', 'base64').toString(), '**********'); -assert.equal(new Buffer('KioqKioqKioqKio', 'base64').toString(), '***********'); -assert.equal(new Buffer('KioqKioqKioqKioqKg', 'base64').toString(), - '*************'); -assert.equal(new Buffer('KioqKioqKioqKioqKio', 'base64').toString(), - '**************'); -assert.equal(new Buffer('KioqKioqKioqKioqKioqKg', 'base64').toString(), - '****************'); -assert.equal(new Buffer('KioqKioqKioqKioqKioqKio', 'base64').toString(), - '*****************'); -assert.equal(new Buffer('KioqKioqKioqKioqKioqKioqKg', 'base64').toString(), - '*******************'); -assert.equal(new Buffer('KioqKioqKioqKioqKioqKioqKio', 'base64').toString(), - '********************'); +assert.strictEqual(new Buffer('Kg', 'base64').toString(), '*'); +assert.strictEqual(new Buffer('Kio', 'base64').toString(), '**'); +assert.strictEqual(new Buffer('KioqKg', 'base64').toString(), '****'); +assert.strictEqual(new Buffer('KioqKio', 'base64').toString(), '*****'); +assert.strictEqual(new Buffer('KioqKioqKg', 'base64').toString(), '*******'); +assert.strictEqual(new Buffer('KioqKioqKio', 'base64').toString(), '********'); +assert.strictEqual(new Buffer('KioqKioqKioqKg', 'base64').toString(), + '**********'); +assert.strictEqual(new Buffer('KioqKioqKioqKio', 'base64').toString(), + '***********'); +assert.strictEqual(new Buffer('KioqKioqKioqKioqKg', 'base64').toString(), + '*************'); +assert.strictEqual(new Buffer('KioqKioqKioqKioqKio', 'base64').toString(), + '**************'); +assert.strictEqual(new Buffer('KioqKioqKioqKioqKioqKg', 'base64').toString(), + '****************'); +assert.strictEqual(new Buffer('KioqKioqKioqKioqKioqKio', 'base64').toString(), + '*****************'); +assert.strictEqual(new Buffer('KioqKioqKioqKioqKioqKioqKg', 'base64') + .toString(), '*******************'); +assert.strictEqual(new Buffer('KioqKioqKioqKioqKioqKioqKio', 'base64') + .toString(), '********************'); // handle padding graciously, multiple-of-4 or not -assert.equal( +assert.strictEqual( new Buffer('72INjkR5fchcxk9+VgdGPFJDxUBFR5/rMFsghgxADiw==', 'base64').length, 32 ); -assert.equal( +assert.strictEqual( new Buffer('72INjkR5fchcxk9+VgdGPFJDxUBFR5/rMFsghgxADiw=', 'base64').length, 32 ); -assert.equal( +assert.strictEqual( new Buffer('72INjkR5fchcxk9+VgdGPFJDxUBFR5/rMFsghgxADiw', 'base64').length, 32 ); -assert.equal( +assert.strictEqual( new Buffer('w69jACy6BgZmaFvv96HG6MYksWytuZu3T1FvGnulPg==', 'base64').length, 31 ); -assert.equal( +assert.strictEqual( new Buffer('w69jACy6BgZmaFvv96HG6MYksWytuZu3T1FvGnulPg=', 'base64').length, 31 ); -assert.equal( +assert.strictEqual( new Buffer('w69jACy6BgZmaFvv96HG6MYksWytuZu3T1FvGnulPg', 'base64').length, 31 ); // This string encodes single '.' character in UTF-16 const dot = new Buffer('//4uAA==', 'base64'); -assert.equal(dot[0], 0xff); -assert.equal(dot[1], 0xfe); -assert.equal(dot[2], 0x2e); -assert.equal(dot[3], 0x00); -assert.equal(dot.toString('base64'), '//4uAA=='); +assert.strictEqual(dot[0], 0xff); +assert.strictEqual(dot[1], 0xfe); +assert.strictEqual(dot[2], 0x2e); +assert.strictEqual(dot[3], 0x00); +assert.strictEqual(dot.toString('base64'), '//4uAA=='); { // Writing base64 at a position > 0 should not mangle the result. @@ -688,12 +691,14 @@ assert.equal(dot.toString('base64'), '//4uAA=='); for (let i = 0; i < segments.length; ++i) { pos += b.write(segments[i], pos, 'base64'); } - assert.equal(b.toString('latin1', 0, pos), 'Madness?! This is node.js!'); - assert.equal(b.toString('binary', 0, pos), 'Madness?! This is node.js!'); + assert.strictEqual(b.toString('latin1', 0, pos), + 'Madness?! This is node.js!'); + assert.strictEqual(b.toString('binary', 0, pos), + 'Madness?! This is node.js!'); } // Regression test for https://github.com/nodejs/node/issues/3496. -assert.equal(Buffer('=bad'.repeat(1e4), 'base64').length, 0); +assert.strictEqual(Buffer('=bad'.repeat(1e4), 'base64').length, 0); { // Creating buffers larger than pool size. @@ -703,22 +708,22 @@ assert.equal(Buffer('=bad'.repeat(1e4), 'base64').length, 0); const b = new Buffer(s); for (let i = 0; i < l; i++) { - assert.equal('h'.charCodeAt(0), b[i]); + assert.strictEqual('h'.charCodeAt(0), b[i]); } const sb = b.toString(); - assert.equal(sb.length, s.length); - assert.equal(sb, s); + assert.strictEqual(sb.length, s.length); + assert.strictEqual(sb, s); } { // Single argument slice const b = new Buffer('abcde'); - assert.equal('bcde', b.slice(1).toString()); + assert.strictEqual('bcde', b.slice(1).toString()); } // slice(0,0).length === 0 -assert.equal(0, Buffer('hello').slice(0, 0).length); +assert.strictEqual(0, Buffer('hello').slice(0, 0).length); // test hex toString console.log('Create hex string from buffer'); @@ -727,8 +732,8 @@ for (let i = 0; i < 256; i++) { hexb[i] = i; } const hexStr = hexb.toString('hex'); -assert.equal(hexStr, - '000102030405060708090a0b0c0d0e0f' + +assert.strictEqual(hexStr, + '000102030405060708090a0b0c0d0e0f' + '101112131415161718191a1b1c1d1e1f' + '202122232425262728292a2b2c2d2e2f' + '303132333435363738393a3b3c3d3e3f' + @@ -748,7 +753,7 @@ assert.equal(hexStr, console.log('Create buffer from hex string'); const hexb2 = new Buffer(hexStr, 'hex'); for (let i = 0; i < 256; i++) { - assert.equal(hexb2[i], hexb[i]); + assert.strictEqual(hexb2[i], hexb[i]); } // Test single hex character throws TypeError @@ -767,8 +772,8 @@ assert.strictEqual(Buffer.from('A', 'base64').length, 0); const b2 = b.toString('hex', 1, 10000); const b3 = b.toString('hex', 1, 5); const b4 = b.toString('hex', 1); - assert.equal(b2, b3); - assert.equal(b2, b4); + assert.strictEqual(b2, b3); + assert.strictEqual(b2, b4); } function buildBuffer(data) { @@ -785,66 +790,66 @@ function buildBuffer(data) { const x = buildBuffer([0x81, 0xa3, 0x66, 0x6f, 0x6f, 0xa3, 0x62, 0x61, 0x72]); console.log(x.inspect()); -assert.equal('', x.inspect()); +assert.strictEqual('', x.inspect()); { const z = x.slice(4); console.log(z.inspect()); console.log(z.length); - assert.equal(5, z.length); - assert.equal(0x6f, z[0]); - assert.equal(0xa3, z[1]); - assert.equal(0x62, z[2]); - assert.equal(0x61, z[3]); - assert.equal(0x72, z[4]); + assert.strictEqual(5, z.length); + assert.strictEqual(0x6f, z[0]); + assert.strictEqual(0xa3, z[1]); + assert.strictEqual(0x62, z[2]); + assert.strictEqual(0x61, z[3]); + assert.strictEqual(0x72, z[4]); } { const z = x.slice(0); console.log(z.inspect()); console.log(z.length); - assert.equal(z.length, x.length); + assert.strictEqual(z.length, x.length); } { const z = x.slice(0, 4); console.log(z.inspect()); console.log(z.length); - assert.equal(4, z.length); - assert.equal(0x81, z[0]); - assert.equal(0xa3, z[1]); + assert.strictEqual(4, z.length); + assert.strictEqual(0x81, z[0]); + assert.strictEqual(0xa3, z[1]); } { const z = x.slice(0, 9); console.log(z.inspect()); console.log(z.length); - assert.equal(9, z.length); + assert.strictEqual(9, z.length); } { const z = x.slice(1, 4); console.log(z.inspect()); console.log(z.length); - assert.equal(3, z.length); - assert.equal(0xa3, z[0]); + assert.strictEqual(3, z.length); + assert.strictEqual(0xa3, z[0]); } { const z = x.slice(2, 4); console.log(z.inspect()); console.log(z.length); - assert.equal(2, z.length); - assert.equal(0x66, z[0]); - assert.equal(0x6f, z[1]); + assert.strictEqual(2, z.length); + assert.strictEqual(0x66, z[0]); + assert.strictEqual(0x6f, z[1]); } -assert.equal(0, Buffer('hello').slice(0, 0).length); +assert.strictEqual(0, Buffer('hello').slice(0, 0).length); ['ucs2', 'ucs-2', 'utf16le', 'utf-16le'].forEach(function(encoding) { const b = new Buffer(10); b.write('あいうえお', encoding); - assert.equal(b.toString(encoding), 'あいうえお'); + assert.strictEqual(b.toString(encoding), 'あいうえお'); }); { @@ -852,16 +857,16 @@ assert.equal(0, Buffer('hello').slice(0, 0).length); const b = Buffer([0xde, 0xad, 0xbe, 0xef]); let s = String.fromCharCode(0xffff); b.write(s, 0, 'latin1'); - assert.equal(0xff, b[0]); - assert.equal(0xad, b[1]); - assert.equal(0xbe, b[2]); - assert.equal(0xef, b[3]); + assert.strictEqual(0xff, b[0]); + assert.strictEqual(0xad, b[1]); + assert.strictEqual(0xbe, b[2]); + assert.strictEqual(0xef, b[3]); s = String.fromCharCode(0xaaee); b.write(s, 0, 'latin1'); - assert.equal(0xee, b[0]); - assert.equal(0xad, b[1]); - assert.equal(0xbe, b[2]); - assert.equal(0xef, b[3]); + assert.strictEqual(0xee, b[0]); + assert.strictEqual(0xad, b[1]); + assert.strictEqual(0xbe, b[2]); + assert.strictEqual(0xef, b[3]); } { @@ -869,48 +874,48 @@ assert.equal(0, Buffer('hello').slice(0, 0).length); const b = Buffer([0xde, 0xad, 0xbe, 0xef]); let s = String.fromCharCode(0xffff); b.write(s, 0, 'binary'); - assert.equal(0xff, b[0]); - assert.equal(0xad, b[1]); - assert.equal(0xbe, b[2]); - assert.equal(0xef, b[3]); + assert.strictEqual(0xff, b[0]); + assert.strictEqual(0xad, b[1]); + assert.strictEqual(0xbe, b[2]); + assert.strictEqual(0xef, b[3]); s = String.fromCharCode(0xaaee); b.write(s, 0, 'binary'); - assert.equal(0xee, b[0]); - assert.equal(0xad, b[1]); - assert.equal(0xbe, b[2]); - assert.equal(0xef, b[3]); + assert.strictEqual(0xee, b[0]); + assert.strictEqual(0xad, b[1]); + assert.strictEqual(0xbe, b[2]); + assert.strictEqual(0xef, b[3]); } { // #1210 Test UTF-8 string includes null character let buf = new Buffer('\0'); - assert.equal(buf.length, 1); + assert.strictEqual(buf.length, 1); buf = new Buffer('\0\0'); - assert.equal(buf.length, 2); + assert.strictEqual(buf.length, 2); } { const buf = new Buffer(2); let written = buf.write(''); // 0byte - assert.equal(written, 0); + assert.strictEqual(written, 0); written = buf.write('\0'); // 1byte (v8 adds null terminator) - assert.equal(written, 1); + assert.strictEqual(written, 1); written = buf.write('a\0'); // 1byte * 2 - assert.equal(written, 2); + assert.strictEqual(written, 2); written = buf.write('あ'); // 3bytes - assert.equal(written, 0); + assert.strictEqual(written, 0); written = buf.write('\0あ'); // 1byte + 3bytes - assert.equal(written, 1); + assert.strictEqual(written, 1); written = buf.write('\0\0あ'); // 1byte * 2 + 3bytes - assert.equal(written, 2); + assert.strictEqual(written, 2); } { const buf = new Buffer(10); written = buf.write('あいう'); // 3bytes * 3 (v8 adds null terminator) - assert.equal(written, 9); + assert.strictEqual(written, 9); written = buf.write('あいう\0'); // 3bytes * 3 + 1byte - assert.equal(written, 10); + assert.strictEqual(written, 10); } { @@ -919,59 +924,59 @@ assert.equal(0, Buffer('hello').slice(0, 0).length); buf.fill(0xFF); let written = buf.write('abcd', 1, 2, 'utf8'); console.log(buf); - assert.equal(written, 2); - assert.equal(buf[0], 0xFF); - assert.equal(buf[1], 0x61); - assert.equal(buf[2], 0x62); - assert.equal(buf[3], 0xFF); + assert.strictEqual(written, 2); + assert.strictEqual(buf[0], 0xFF); + assert.strictEqual(buf[1], 0x61); + assert.strictEqual(buf[2], 0x62); + assert.strictEqual(buf[3], 0xFF); buf.fill(0xFF); written = buf.write('abcd', 1, 4); console.log(buf); - assert.equal(written, 3); - assert.equal(buf[0], 0xFF); - assert.equal(buf[1], 0x61); - assert.equal(buf[2], 0x62); - assert.equal(buf[3], 0x63); + assert.strictEqual(written, 3); + assert.strictEqual(buf[0], 0xFF); + assert.strictEqual(buf[1], 0x61); + assert.strictEqual(buf[2], 0x62); + assert.strictEqual(buf[3], 0x63); buf.fill(0xFF); written = buf.write('abcd', 1, 2, 'utf8'); console.log(buf); - assert.equal(written, 2); - assert.equal(buf[0], 0xFF); - assert.equal(buf[1], 0x61); - assert.equal(buf[2], 0x62); - assert.equal(buf[3], 0xFF); + assert.strictEqual(written, 2); + assert.strictEqual(buf[0], 0xFF); + assert.strictEqual(buf[1], 0x61); + assert.strictEqual(buf[2], 0x62); + assert.strictEqual(buf[3], 0xFF); buf.fill(0xFF); written = buf.write('abcdef', 1, 2, 'hex'); console.log(buf); - assert.equal(written, 2); - assert.equal(buf[0], 0xFF); - assert.equal(buf[1], 0xAB); - assert.equal(buf[2], 0xCD); - assert.equal(buf[3], 0xFF); + assert.strictEqual(written, 2); + assert.strictEqual(buf[0], 0xFF); + assert.strictEqual(buf[1], 0xAB); + assert.strictEqual(buf[2], 0xCD); + assert.strictEqual(buf[3], 0xFF); ['ucs2', 'ucs-2', 'utf16le', 'utf-16le'].forEach(function(encoding) { buf.fill(0xFF); written = buf.write('abcd', 0, 2, encoding); console.log(buf); - assert.equal(written, 2); - assert.equal(buf[0], 0x61); - assert.equal(buf[1], 0x00); - assert.equal(buf[2], 0xFF); - assert.equal(buf[3], 0xFF); + assert.strictEqual(written, 2); + assert.strictEqual(buf[0], 0x61); + assert.strictEqual(buf[1], 0x00); + assert.strictEqual(buf[2], 0xFF); + assert.strictEqual(buf[3], 0xFF); }); } { // test offset returns are correct const b = new Buffer(16); - assert.equal(4, b.writeUInt32LE(0, 0)); - assert.equal(6, b.writeUInt16LE(0, 4)); - assert.equal(7, b.writeUInt8(0, 6)); - assert.equal(8, b.writeInt8(0, 7)); - assert.equal(16, b.writeDoubleLE(0, 8)); + assert.strictEqual(4, b.writeUInt32LE(0, 0)); + assert.strictEqual(6, b.writeUInt16LE(0, 4)); + assert.strictEqual(7, b.writeUInt8(0, 6)); + assert.strictEqual(8, b.writeInt8(0, 7)); + assert.strictEqual(16, b.writeDoubleLE(0, 8)); } { @@ -979,13 +984,13 @@ assert.equal(0, Buffer('hello').slice(0, 0).length); // ef bf bd = utf-8 representation of unicode replacement character // see https://codereview.chromium.org/121173009/ const buf = new Buffer('ab\ud800cd', 'utf8'); - assert.equal(buf[0], 0x61); - assert.equal(buf[1], 0x62); - assert.equal(buf[2], 0xef); - assert.equal(buf[3], 0xbf); - assert.equal(buf[4], 0xbd); - assert.equal(buf[5], 0x63); - assert.equal(buf[6], 0x64); + assert.strictEqual(buf[0], 0x61); + assert.strictEqual(buf[1], 0x62); + assert.strictEqual(buf[2], 0xef); + assert.strictEqual(buf[3], 0xbf); + assert.strictEqual(buf[4], 0xbd); + assert.strictEqual(buf[5], 0x63); + assert.strictEqual(buf[6], 0x64); } { @@ -993,11 +998,11 @@ assert.equal(0, Buffer('hello').slice(0, 0).length); const buf = new Buffer([0, 0, 0, 0, 0]); // length: 5 const sub = buf.slice(0, 4); // length: 4 written = sub.write('12345', 'latin1'); - assert.equal(written, 4); - assert.equal(buf[4], 0); + assert.strictEqual(written, 4); + assert.strictEqual(buf[4], 0); written = sub.write('12345', 'binary'); - assert.equal(written, 4); - assert.equal(buf[4], 0); + assert.strictEqual(written, 4); + assert.strictEqual(buf[4], 0); } // Check for fractional length args, junk length args, etc. @@ -1005,19 +1010,19 @@ assert.equal(0, Buffer('hello').slice(0, 0).length); // Call .fill() first, stops valgrind warning about uninitialized memory reads. Buffer(3.3).fill().toString(); // throws bad argument error in commit 43cb4ec -assert.equal(Buffer(-1).length, 0); -assert.equal(Buffer(NaN).length, 0); -assert.equal(Buffer(3.3).length, 3); -assert.equal(Buffer({length: 3.3}).length, 3); -assert.equal(Buffer({length: 'BAM'}).length, 0); +assert.strictEqual(Buffer(-1).length, 0); +assert.strictEqual(Buffer(NaN).length, 0); +assert.strictEqual(Buffer(3.3).length, 3); +assert.strictEqual(Buffer({length: 3.3}).length, 3); +assert.strictEqual(Buffer({length: 'BAM'}).length, 0); // Make sure that strings are not coerced to numbers. -assert.equal(Buffer('99').length, 2); -assert.equal(Buffer('13.37').length, 5); +assert.strictEqual(Buffer('99').length, 2); +assert.strictEqual(Buffer('13.37').length, 5); // Ensure that the length argument is respected. 'ascii utf8 hex base64 latin1 binary'.split(' ').forEach(function(enc) { - assert.equal(Buffer(1).write('aaaaaa', 0, 1, enc), 1); + assert.strictEqual(Buffer(1).write('aaaaaa', 0, 1, enc), 1); }); { @@ -1025,7 +1030,7 @@ assert.equal(Buffer('13.37').length, 5); const a = Buffer(3); const b = Buffer('xxx'); a.write('aaaaaaaa', 'base64'); - assert.equal(b.toString(), 'xxx'); + assert.strictEqual(b.toString(), 'xxx'); } // issue GH-3416 @@ -1042,14 +1047,14 @@ Buffer(Buffer(0), 0, 0); 'ucs-2', 'utf16le', 'utf-16le' ].forEach(function(enc) { - assert.equal(Buffer.isEncoding(enc), true); + assert.strictEqual(Buffer.isEncoding(enc), true); }); [ 'utf9', 'utf-7', 'Unicode-FTW', 'new gnu gun' ].forEach(function(enc) { - assert.equal(Buffer.isEncoding(enc), false); + assert.strictEqual(Buffer.isEncoding(enc), false); }); @@ -1150,8 +1155,8 @@ assert.throws(function() { { const buf = new Buffer([0xFF]); - assert.equal(buf.readUInt8(0), 255); - assert.equal(buf.readInt8(0), -1); + assert.strictEqual(buf.readUInt8(0), 255); + assert.strictEqual(buf.readInt8(0), -1); } [16, 32].forEach(function(bits) { @@ -1177,16 +1182,16 @@ assert.throws(function() { [16, 32].forEach(function(bits) { const buf = new Buffer([0xFF, 0xFF, 0xFF, 0xFF]); - assert.equal(buf['readUInt' + bits + 'BE'](0), + assert.strictEqual(buf['readUInt' + bits + 'BE'](0), (0xFFFFFFFF >>> (32 - bits))); - assert.equal(buf['readUInt' + bits + 'LE'](0), + assert.strictEqual(buf['readUInt' + bits + 'LE'](0), (0xFFFFFFFF >>> (32 - bits))); - assert.equal(buf['readInt' + bits + 'BE'](0), + assert.strictEqual(buf['readInt' + bits + 'BE'](0), (0xFFFFFFFF >> (32 - bits))); - assert.equal(buf['readInt' + bits + 'LE'](0), + assert.strictEqual(buf['readInt' + bits + 'LE'](0), (0xFFFFFFFF >> (32 - bits))); }); @@ -1217,139 +1222,139 @@ assert.throws(function() { let buf = Buffer(3); buf.writeUIntLE(0x123456, 0, 3); assert.deepStrictEqual(buf.toJSON().data, [0x56, 0x34, 0x12]); - assert.equal(buf.readUIntLE(0, 3), 0x123456); + assert.strictEqual(buf.readUIntLE(0, 3), 0x123456); buf = Buffer(3); buf.writeUIntBE(0x123456, 0, 3); assert.deepStrictEqual(buf.toJSON().data, [0x12, 0x34, 0x56]); - assert.equal(buf.readUIntBE(0, 3), 0x123456); + assert.strictEqual(buf.readUIntBE(0, 3), 0x123456); buf = Buffer(3); buf.writeIntLE(0x123456, 0, 3); assert.deepStrictEqual(buf.toJSON().data, [0x56, 0x34, 0x12]); - assert.equal(buf.readIntLE(0, 3), 0x123456); + assert.strictEqual(buf.readIntLE(0, 3), 0x123456); buf = Buffer(3); buf.writeIntBE(0x123456, 0, 3); assert.deepStrictEqual(buf.toJSON().data, [0x12, 0x34, 0x56]); - assert.equal(buf.readIntBE(0, 3), 0x123456); + assert.strictEqual(buf.readIntBE(0, 3), 0x123456); buf = Buffer(3); buf.writeIntLE(-0x123456, 0, 3); assert.deepStrictEqual(buf.toJSON().data, [0xaa, 0xcb, 0xed]); - assert.equal(buf.readIntLE(0, 3), -0x123456); + assert.strictEqual(buf.readIntLE(0, 3), -0x123456); buf = Buffer(3); buf.writeIntBE(-0x123456, 0, 3); assert.deepStrictEqual(buf.toJSON().data, [0xed, 0xcb, 0xaa]); - assert.equal(buf.readIntBE(0, 3), -0x123456); + assert.strictEqual(buf.readIntBE(0, 3), -0x123456); buf = Buffer(3); buf.writeIntLE(-0x123400, 0, 3); assert.deepStrictEqual(buf.toJSON().data, [0x00, 0xcc, 0xed]); - assert.equal(buf.readIntLE(0, 3), -0x123400); + assert.strictEqual(buf.readIntLE(0, 3), -0x123400); buf = Buffer(3); buf.writeIntBE(-0x123400, 0, 3); assert.deepStrictEqual(buf.toJSON().data, [0xed, 0xcc, 0x00]); - assert.equal(buf.readIntBE(0, 3), -0x123400); + assert.strictEqual(buf.readIntBE(0, 3), -0x123400); buf = Buffer(3); buf.writeIntLE(-0x120000, 0, 3); assert.deepStrictEqual(buf.toJSON().data, [0x00, 0x00, 0xee]); - assert.equal(buf.readIntLE(0, 3), -0x120000); + assert.strictEqual(buf.readIntLE(0, 3), -0x120000); buf = Buffer(3); buf.writeIntBE(-0x120000, 0, 3); assert.deepStrictEqual(buf.toJSON().data, [0xee, 0x00, 0x00]); - assert.equal(buf.readIntBE(0, 3), -0x120000); + assert.strictEqual(buf.readIntBE(0, 3), -0x120000); buf = Buffer(5); buf.writeUIntLE(0x1234567890, 0, 5); assert.deepStrictEqual(buf.toJSON().data, [0x90, 0x78, 0x56, 0x34, 0x12]); - assert.equal(buf.readUIntLE(0, 5), 0x1234567890); + assert.strictEqual(buf.readUIntLE(0, 5), 0x1234567890); buf = Buffer(5); buf.writeUIntBE(0x1234567890, 0, 5); assert.deepStrictEqual(buf.toJSON().data, [0x12, 0x34, 0x56, 0x78, 0x90]); - assert.equal(buf.readUIntBE(0, 5), 0x1234567890); + assert.strictEqual(buf.readUIntBE(0, 5), 0x1234567890); buf = Buffer(5); buf.writeIntLE(0x1234567890, 0, 5); assert.deepStrictEqual(buf.toJSON().data, [0x90, 0x78, 0x56, 0x34, 0x12]); - assert.equal(buf.readIntLE(0, 5), 0x1234567890); + assert.strictEqual(buf.readIntLE(0, 5), 0x1234567890); buf = Buffer(5); buf.writeIntBE(0x1234567890, 0, 5); assert.deepStrictEqual(buf.toJSON().data, [0x12, 0x34, 0x56, 0x78, 0x90]); - assert.equal(buf.readIntBE(0, 5), 0x1234567890); + assert.strictEqual(buf.readIntBE(0, 5), 0x1234567890); buf = Buffer(5); buf.writeIntLE(-0x1234567890, 0, 5); assert.deepStrictEqual(buf.toJSON().data, [0x70, 0x87, 0xa9, 0xcb, 0xed]); - assert.equal(buf.readIntLE(0, 5), -0x1234567890); + assert.strictEqual(buf.readIntLE(0, 5), -0x1234567890); buf = Buffer(5); buf.writeIntBE(-0x1234567890, 0, 5); assert.deepStrictEqual(buf.toJSON().data, [0xed, 0xcb, 0xa9, 0x87, 0x70]); - assert.equal(buf.readIntBE(0, 5), -0x1234567890); + assert.strictEqual(buf.readIntBE(0, 5), -0x1234567890); buf = Buffer(5); buf.writeIntLE(-0x0012000000, 0, 5); assert.deepStrictEqual(buf.toJSON().data, [0x00, 0x00, 0x00, 0xee, 0xff]); - assert.equal(buf.readIntLE(0, 5), -0x0012000000); + assert.strictEqual(buf.readIntLE(0, 5), -0x0012000000); buf = Buffer(5); buf.writeIntBE(-0x0012000000, 0, 5); assert.deepStrictEqual(buf.toJSON().data, [0xff, 0xee, 0x00, 0x00, 0x00]); - assert.equal(buf.readIntBE(0, 5), -0x0012000000); + assert.strictEqual(buf.readIntBE(0, 5), -0x0012000000); } // test Buffer slice { const buf = new Buffer('0123456789'); - assert.equal(buf.slice(-10, 10), '0123456789'); - assert.equal(buf.slice(-20, 10), '0123456789'); - assert.equal(buf.slice(-20, -10), ''); - assert.equal(buf.slice(), '0123456789'); - assert.equal(buf.slice(0), '0123456789'); - assert.equal(buf.slice(0, 0), ''); - assert.equal(buf.slice(undefined), '0123456789'); - assert.equal(buf.slice('foobar'), '0123456789'); - assert.equal(buf.slice(undefined, undefined), '0123456789'); - - assert.equal(buf.slice(2), '23456789'); - assert.equal(buf.slice(5), '56789'); - assert.equal(buf.slice(10), ''); - assert.equal(buf.slice(5, 8), '567'); - assert.equal(buf.slice(8, -1), '8'); - assert.equal(buf.slice(-10), '0123456789'); - assert.equal(buf.slice(0, -9), '0'); - assert.equal(buf.slice(0, -10), ''); - assert.equal(buf.slice(0, -1), '012345678'); - assert.equal(buf.slice(2, -2), '234567'); - assert.equal(buf.slice(0, 65536), '0123456789'); - assert.equal(buf.slice(65536, 0), ''); - assert.equal(buf.slice(-5, -8), ''); - assert.equal(buf.slice(-5, -3), '56'); - assert.equal(buf.slice(-10, 10), '0123456789'); + assert.strictEqual(buf.slice(-10, 10).toString(), '0123456789'); + assert.strictEqual(buf.slice(-20, 10).toString(), '0123456789'); + assert.strictEqual(buf.slice(-20, -10).toString(), ''); + assert.strictEqual(buf.slice().toString(), '0123456789'); + assert.strictEqual(buf.slice(0).toString(), '0123456789'); + assert.strictEqual(buf.slice(0, 0).toString(), ''); + assert.strictEqual(buf.slice(undefined).toString(), '0123456789'); + assert.strictEqual(buf.slice('foobar').toString(), '0123456789'); + assert.strictEqual(buf.slice(undefined, undefined).toString(), '0123456789'); + + assert.strictEqual(buf.slice(2).toString(), '23456789'); + assert.strictEqual(buf.slice(5).toString(), '56789'); + assert.strictEqual(buf.slice(10).toString(), ''); + assert.strictEqual(buf.slice(5, 8).toString(), '567'); + assert.strictEqual(buf.slice(8, -1).toString(), '8'); + assert.strictEqual(buf.slice(-10).toString(), '0123456789'); + assert.strictEqual(buf.slice(0, -9).toString(), '0'); + assert.strictEqual(buf.slice(0, -10).toString(), ''); + assert.strictEqual(buf.slice(0, -1).toString(), '012345678'); + assert.strictEqual(buf.slice(2, -2).toString(), '234567'); + assert.strictEqual(buf.slice(0, 65536).toString(), '0123456789'); + assert.strictEqual(buf.slice(65536, 0).toString(), ''); + assert.strictEqual(buf.slice(-5, -8).toString(), ''); + assert.strictEqual(buf.slice(-5, -3).toString(), '56'); + assert.strictEqual(buf.slice(-10, 10).toString(), '0123456789'); for (let i = 0, s = buf.toString(); i < buf.length; ++i) { - assert.equal(buf.slice(i), s.slice(i)); - assert.equal(buf.slice(0, i), s.slice(0, i)); - assert.equal(buf.slice(-i), s.slice(-i)); - assert.equal(buf.slice(0, -i), s.slice(0, -i)); + assert.strictEqual(buf.slice(i).toString(), s.slice(i)); + assert.strictEqual(buf.slice(0, i).toString(), s.slice(0, i)); + assert.strictEqual(buf.slice(-i).toString(), s.slice(-i)); + assert.strictEqual(buf.slice(0, -i).toString(), s.slice(0, -i)); } const utf16Buf = new Buffer('0123456789', 'utf16le'); assert.deepStrictEqual(utf16Buf.slice(0, 6), Buffer('012', 'utf16le')); - assert.equal(buf.slice('0', '1'), '0'); - assert.equal(buf.slice('-5', '10'), '56789'); - assert.equal(buf.slice('-10', '10'), '0123456789'); - assert.equal(buf.slice('-10', '-5'), '01234'); - assert.equal(buf.slice('-10', '-0'), ''); - assert.equal(buf.slice('111'), ''); - assert.equal(buf.slice('0', '-111'), ''); + assert.strictEqual(buf.slice('0', '1').toString(), '0'); + assert.strictEqual(buf.slice('-5', '10').toString(), '56789'); + assert.strictEqual(buf.slice('-10', '10').toString(), '0123456789'); + assert.strictEqual(buf.slice('-10', '-5').toString(), '01234'); + assert.strictEqual(buf.slice('-10', '-0').toString(), ''); + assert.strictEqual(buf.slice('111').toString(), ''); + assert.strictEqual(buf.slice('0', '-111').toString(), ''); // try to slice a zero length Buffer // see https://github.com/joyent/node/issues/5881 @@ -1394,7 +1399,7 @@ if (common.hasCrypto) { const b1 = new Buffer('YW55=======', 'base64'); const b2 = new Buffer('YW55', 'base64'); - assert.equal( + assert.strictEqual( crypto.createHash('sha1').update(b1).digest('hex'), crypto.createHash('sha1').update(b2).digest('hex') ); @@ -1408,21 +1413,21 @@ if (common.hasCrypto) { const c = new Buffer(1).fill('c'); const d = new Buffer(2).fill('aa'); - assert.equal(b.compare(c), -1); - assert.equal(c.compare(d), 1); - assert.equal(d.compare(b), 1); - assert.equal(b.compare(d), -1); - assert.equal(b.compare(b), 0); + assert.strictEqual(b.compare(c), -1); + assert.strictEqual(c.compare(d), 1); + assert.strictEqual(d.compare(b), 1); + assert.strictEqual(b.compare(d), -1); + assert.strictEqual(b.compare(b), 0); - assert.equal(Buffer.compare(b, c), -1); - assert.equal(Buffer.compare(c, d), 1); - assert.equal(Buffer.compare(d, b), 1); - assert.equal(Buffer.compare(b, d), -1); - assert.equal(Buffer.compare(c, c), 0); + assert.strictEqual(Buffer.compare(b, c), -1); + assert.strictEqual(Buffer.compare(c, d), 1); + assert.strictEqual(Buffer.compare(d, b), 1); + assert.strictEqual(Buffer.compare(b, d), -1); + assert.strictEqual(Buffer.compare(c, c), 0); - assert.equal(Buffer.compare(Buffer(0), Buffer(0)), 0); - assert.equal(Buffer.compare(Buffer(0), Buffer(1)), -1); - assert.equal(Buffer.compare(Buffer(1), Buffer(0)), 1); + assert.strictEqual(Buffer.compare(Buffer(0), Buffer(0)), 0); + assert.strictEqual(Buffer.compare(Buffer(0), Buffer(1)), -1); + assert.strictEqual(Buffer.compare(Buffer(1), Buffer(0)), 1); } assert.throws(function() { @@ -1463,7 +1468,7 @@ assert.throws(function() { Buffer(1422561062959).toString('utf8'); }); const ps = Buffer.poolSize; Buffer.poolSize = 0; -assert.equal(Buffer(1).parent, undefined); +assert.strictEqual(Buffer(1).parent, undefined); Buffer.poolSize = ps; // Test Buffer.copy() segfault @@ -1484,10 +1489,10 @@ assert.throws(function() { // Test prototype getters don't throw -assert.equal(Buffer.prototype.parent, undefined); -assert.equal(Buffer.prototype.offset, undefined); -assert.equal(SlowBuffer.prototype.parent, undefined); -assert.equal(SlowBuffer.prototype.offset, undefined); +assert.strictEqual(Buffer.prototype.parent, undefined); +assert.strictEqual(Buffer.prototype.offset, undefined); +assert.strictEqual(SlowBuffer.prototype.parent, undefined); +assert.strictEqual(SlowBuffer.prototype.offset, undefined); { // Test that large negative Buffer length inputs don't affect the pool offset. diff --git a/test/parallel/test-child-process-fork-net.js b/test/parallel/test-child-process-fork-net.js index 063028e8280582..c17dba94953b9e 100644 --- a/test/parallel/test-child-process-fork-net.js +++ b/test/parallel/test-child-process-fork-net.js @@ -153,7 +153,7 @@ if (process.argv[2] === 'child') { }); connect.on('close', function() { console.log('CLIENT: closed'); - assert.equal(store, 'echo'); + assert.strictEqual(store, 'echo'); server.close(); }); }); diff --git a/test/parallel/test-child-process-fork-net2.js b/test/parallel/test-child-process-fork-net2.js index 760645932069bb..f5c7a7d8ac5519 100644 --- a/test/parallel/test-child-process-fork-net2.js +++ b/test/parallel/test-child-process-fork-net2.js @@ -135,7 +135,7 @@ if (process.argv[2] === 'child') { }; process.on('exit', function() { - assert.equal(disconnected, count); - assert.equal(connected, count); + assert.strictEqual(disconnected, count); + assert.strictEqual(connected, count); }); } diff --git a/test/parallel/test-child-process-fork-ref.js b/test/parallel/test-child-process-fork-ref.js index 1f8816c0cfaf1c..a7ff8c04cbab25 100644 --- a/test/parallel/test-child-process-fork-ref.js +++ b/test/parallel/test-child-process-fork-ref.js @@ -33,6 +33,6 @@ if (process.argv[2] === 'child') { child.once('exit', function() { assert.deepStrictEqual(ipc, ['1', '2']); - assert.equal(stdout, '3'); + assert.strictEqual(stdout, '3'); }); } diff --git a/test/parallel/test-child-process-ipc.js b/test/parallel/test-child-process-ipc.js index cbaa270f5e8440..da952e6c9bf1ae 100644 --- a/test/parallel/test-child-process-ipc.js +++ b/test/parallel/test-child-process-ipc.js @@ -30,7 +30,7 @@ child.stdout.on('data', function(data) { child.stdin.write('echo me\r\n'); } else { console.error('testing for echo me'); - assert.equal('echo me\r\n', data); + assert.strictEqual('echo me\r\n', data); gotEcho = true; child.stdin.end(); } diff --git a/test/parallel/test-child-process-set-blocking.js b/test/parallel/test-child-process-set-blocking.js index 54037aea69feb2..d6a044619b6479 100644 --- a/test/parallel/test-child-process-set-blocking.js +++ b/test/parallel/test-child-process-set-blocking.js @@ -10,5 +10,5 @@ const cp = ch.spawn('python', ['-c', 'print ' + SIZE + ' * "C"'], { }); cp.on('exit', common.mustCall(function(code) { - assert.equal(0, code); + assert.strictEqual(0, code); })); diff --git a/test/parallel/test-child-process-spawn-shell.js b/test/parallel/test-child-process-spawn-shell.js index 591fb409cb4cea..01411144bdc48f 100644 --- a/test/parallel/test-child-process-spawn-shell.js +++ b/test/parallel/test-child-process-spawn-shell.js @@ -6,7 +6,7 @@ const cp = require('child_process'); // Verify that a shell is, in fact, executed const doesNotExist = cp.spawn('does-not-exist', {shell: true}); -assert.notEqual(doesNotExist.spawnfile, 'does-not-exist'); +assert.notStrictEqual(doesNotExist.spawnfile, 'does-not-exist'); doesNotExist.on('error', common.fail); doesNotExist.on('exit', common.mustCall((code, signal) => { assert.strictEqual(signal, null); diff --git a/test/parallel/test-child-process-spawnsync-env.js b/test/parallel/test-child-process-spawnsync-env.js index 6f5ea3dc83d107..b5a1c723660faa 100644 --- a/test/parallel/test-child-process-spawnsync-env.js +++ b/test/parallel/test-child-process-spawnsync-env.js @@ -11,5 +11,5 @@ if (process.argv[2] === 'child') { env: Object.assign(process.env, { foo: expected }) }); - assert.equal(child.stdout.toString().trim(), expected); + assert.strictEqual(child.stdout.toString().trim(), expected); } diff --git a/test/parallel/test-child-process-spawnsync-shell.js b/test/parallel/test-child-process-spawnsync-shell.js index 620a01c4532203..70483089245c74 100644 --- a/test/parallel/test-child-process-spawnsync-shell.js +++ b/test/parallel/test-child-process-spawnsync-shell.js @@ -6,7 +6,7 @@ const cp = require('child_process'); // Verify that a shell is, in fact, executed const doesNotExist = cp.spawnSync('does-not-exist', {shell: true}); -assert.notEqual(doesNotExist.file, 'does-not-exist'); +assert.notStrictEqual(doesNotExist.file, 'does-not-exist'); assert.strictEqual(doesNotExist.error, undefined); assert.strictEqual(doesNotExist.signal, null); diff --git a/test/parallel/test-console.js b/test/parallel/test-console.js index aaa0e8259a1d22..64dc75caa02e01 100644 --- a/test/parallel/test-console.js +++ b/test/parallel/test-console.js @@ -115,7 +115,7 @@ assert.strictEqual("{ foo: 'bar', inspect: [Function: inspect] }\n", strings.shift()); assert.strictEqual("{ foo: 'bar', inspect: [Function: inspect] }\n", strings.shift()); -assert.notEqual(-1, strings.shift().indexOf('foo: [Object]')); +assert.notStrictEqual(-1, strings.shift().indexOf('foo: [Object]')); assert.strictEqual(-1, strings.shift().indexOf('baz')); assert.ok(/^label: \d+\.\d{3}ms$/.test(strings.shift().trim())); assert.ok(/^__proto__: \d+\.\d{3}ms$/.test(strings.shift().trim())); diff --git a/test/parallel/test-crypto-dh.js b/test/parallel/test-crypto-dh.js index b26ac78f3146a0..cfe896026f6af5 100644 --- a/test/parallel/test-crypto-dh.js +++ b/test/parallel/test-crypto-dh.js @@ -19,9 +19,9 @@ let key2 = dh2.generateKeys('hex'); let secret1 = dh1.computeSecret(key2, 'hex', 'base64'); let secret2 = dh2.computeSecret(key1, 'latin1', 'buffer'); -assert.equal(secret1, secret2.toString('base64')); -assert.equal(dh1.verifyError, 0); -assert.equal(dh2.verifyError, 0); +assert.strictEqual(secret1, secret2.toString('base64')); +assert.strictEqual(dh1.verifyError, 0); +assert.strictEqual(dh2.verifyError, 0); assert.throws(function() { crypto.createDiffieHellman([0x1, 0x2]); @@ -50,11 +50,11 @@ assert.deepStrictEqual(dh1.getPrime(), dh3.getPrime()); assert.deepStrictEqual(dh1.getGenerator(), dh3.getGenerator()); assert.deepStrictEqual(dh1.getPublicKey(), dh3.getPublicKey()); assert.deepStrictEqual(dh1.getPrivateKey(), dh3.getPrivateKey()); -assert.equal(dh3.verifyError, 0); +assert.strictEqual(dh3.verifyError, 0); const secret3 = dh3.computeSecret(key2, 'hex', 'base64'); -assert.equal(secret1, secret3); +assert.strictEqual(secret1, secret3); // Run this one twice to make sure that the dh3 clears its error properly { @@ -78,9 +78,9 @@ alice.generateKeys(); bob.generateKeys(); const aSecret = alice.computeSecret(bob.getPublicKey()).toString('hex'); const bSecret = bob.computeSecret(alice.getPublicKey()).toString('hex'); -assert.equal(aSecret, bSecret); -assert.equal(alice.verifyError, DH_NOT_SUITABLE_GENERATOR); -assert.equal(bob.verifyError, DH_NOT_SUITABLE_GENERATOR); +assert.strictEqual(aSecret, bSecret); +assert.strictEqual(alice.verifyError, DH_NOT_SUITABLE_GENERATOR); +assert.strictEqual(bob.verifyError, DH_NOT_SUITABLE_GENERATOR); /* Ensure specific generator (buffer) works as expected. * The values below (modp2/modp2buf) are for a 1024 bits long prime from @@ -107,9 +107,9 @@ exmodp2.generateKeys(); let modp2Secret = modp2.computeSecret(exmodp2.getPublicKey()).toString('hex'); const exmodp2Secret = exmodp2.computeSecret(modp2.getPublicKey()) .toString('hex'); -assert.equal(modp2Secret, exmodp2Secret); -assert.equal(modp2.verifyError, DH_NOT_SUITABLE_GENERATOR); -assert.equal(exmodp2.verifyError, DH_NOT_SUITABLE_GENERATOR); +assert.strictEqual(modp2Secret, exmodp2Secret); +assert.strictEqual(modp2.verifyError, DH_NOT_SUITABLE_GENERATOR); +assert.strictEqual(exmodp2.verifyError, DH_NOT_SUITABLE_GENERATOR); // Ensure specific generator (string with encoding) works as expected. @@ -118,8 +118,8 @@ exmodp2_2.generateKeys(); modp2Secret = modp2.computeSecret(exmodp2_2.getPublicKey()).toString('hex'); const exmodp2_2Secret = exmodp2_2.computeSecret(modp2.getPublicKey()) .toString('hex'); -assert.equal(modp2Secret, exmodp2_2Secret); -assert.equal(exmodp2_2.verifyError, DH_NOT_SUITABLE_GENERATOR); +assert.strictEqual(modp2Secret, exmodp2_2Secret); +assert.strictEqual(exmodp2_2.verifyError, DH_NOT_SUITABLE_GENERATOR); // Ensure specific generator (string without encoding) works as expected. @@ -128,8 +128,8 @@ exmodp2_3.generateKeys(); modp2Secret = modp2.computeSecret(exmodp2_3.getPublicKey()).toString('hex'); const exmodp2_3Secret = exmodp2_3.computeSecret(modp2.getPublicKey()) .toString('hex'); -assert.equal(modp2Secret, exmodp2_3Secret); -assert.equal(exmodp2_3.verifyError, DH_NOT_SUITABLE_GENERATOR); +assert.strictEqual(modp2Secret, exmodp2_3Secret); +assert.strictEqual(exmodp2_3.verifyError, DH_NOT_SUITABLE_GENERATOR); // Ensure specific generator (numeric) works as expected. @@ -138,8 +138,8 @@ exmodp2_4.generateKeys(); modp2Secret = modp2.computeSecret(exmodp2_4.getPublicKey()).toString('hex'); const exmodp2_4Secret = exmodp2_4.computeSecret(modp2.getPublicKey()) .toString('hex'); -assert.equal(modp2Secret, exmodp2_4Secret); -assert.equal(exmodp2_4.verifyError, DH_NOT_SUITABLE_GENERATOR); +assert.strictEqual(modp2Secret, exmodp2_4Secret); +assert.strictEqual(exmodp2_4.verifyError, DH_NOT_SUITABLE_GENERATOR); const p = 'FFFFFFFFFFFFFFFFC90FDAA22168C234C4C6628B80DC1CD129024E088A67CC74' + @@ -147,7 +147,7 @@ const p = 'FFFFFFFFFFFFFFFFC90FDAA22168C234C4C6628B80DC1CD129024E088A67CC74' + '4FE1356D6D51C245E485B576625E7EC6F44C42E9A637ED6B0BFF5CB6F406B7ED' + 'EE386BFB5A899FA5AE9F24117C4B1FE649286651ECE65381FFFFFFFFFFFFFFFF'; const bad_dh = crypto.createDiffieHellman(p, 'hex'); -assert.equal(bad_dh.verifyError, DH_NOT_SUITABLE_GENERATOR); +assert.strictEqual(bad_dh.verifyError, DH_NOT_SUITABLE_GENERATOR); // Test ECDH @@ -158,7 +158,7 @@ key2 = ecdh2.generateKeys('hex'); secret1 = ecdh1.computeSecret(key2, 'hex', 'base64'); secret2 = ecdh2.computeSecret(key1, 'latin1', 'buffer'); -assert.equal(secret1, secret2.toString('base64')); +assert.strictEqual(secret1, secret2.toString('base64')); // Oakley curves do not clean up ERR stack, it was causing unexpected failure // when accessing other OpenSSL APIs afterwards. @@ -166,7 +166,7 @@ crypto.createECDH('Oakley-EC2N-3'); crypto.createHash('sha256'); // Point formats -assert.equal(ecdh1.getPublicKey('buffer', 'uncompressed')[0], 4); +assert.strictEqual(ecdh1.getPublicKey('buffer', 'uncompressed')[0], 4); let firstByte = ecdh1.getPublicKey('buffer', 'compressed')[0]; assert(firstByte === 2 || firstByte === 3); firstByte = ecdh1.getPublicKey('buffer', 'hybrid')[0]; @@ -214,9 +214,9 @@ const cafebabePubPtUnComp = '04672a31bfc59d3f04548ec9b7daeeba2f61814e8ccc40448045007f5479f693a3' + '2e02c7f93d13dc2732b760ca377a5897b9dd41a1c1b29dc0442fdce6d0a04d1d'; ecdh5.setPrivateKey(cafebabeKey, 'hex'); -assert.equal(ecdh5.getPrivateKey('hex'), cafebabeKey); +assert.strictEqual(ecdh5.getPrivateKey('hex'), cafebabeKey); // Show that the public point (key) is generated while setting the private key. -assert.equal(ecdh5.getPublicKey('hex'), cafebabePubPtUnComp); +assert.strictEqual(ecdh5.getPublicKey('hex'), cafebabePubPtUnComp); // Compressed and uncompressed public points/keys for other party's private key // 0xDEADBEEFDEADBEEFDEADBEEFDEADBEEFDEADBEEFDEADBEEFDEADBEEFDEADBEEF @@ -229,24 +229,26 @@ const peerPubPtUnComp = const sharedSecret = '1da220b5329bbe8bfd19ceef5a5898593f411a6f12ea40f2a8eead9a5cf59970'; -assert.equal(ecdh5.computeSecret(peerPubPtComp, 'hex', 'hex'), sharedSecret); -assert.equal(ecdh5.computeSecret(peerPubPtUnComp, 'hex', 'hex'), sharedSecret); +assert.strictEqual(ecdh5.computeSecret(peerPubPtComp, 'hex', 'hex'), + sharedSecret); +assert.strictEqual(ecdh5.computeSecret(peerPubPtUnComp, 'hex', 'hex'), + sharedSecret); // Verify that we still have the same key pair as before the computation. -assert.equal(ecdh5.getPrivateKey('hex'), cafebabeKey); -assert.equal(ecdh5.getPublicKey('hex'), cafebabePubPtUnComp); +assert.strictEqual(ecdh5.getPrivateKey('hex'), cafebabeKey); +assert.strictEqual(ecdh5.getPublicKey('hex'), cafebabePubPtUnComp); // Verify setting and getting compressed and non-compressed serializations. ecdh5.setPublicKey(cafebabePubPtComp, 'hex'); -assert.equal(ecdh5.getPublicKey('hex'), cafebabePubPtUnComp); -assert.equal(ecdh5.getPublicKey('hex', 'compressed'), cafebabePubPtComp); +assert.strictEqual(ecdh5.getPublicKey('hex'), cafebabePubPtUnComp); +assert.strictEqual(ecdh5.getPublicKey('hex', 'compressed'), cafebabePubPtComp); ecdh5.setPublicKey(cafebabePubPtUnComp, 'hex'); -assert.equal(ecdh5.getPublicKey('hex'), cafebabePubPtUnComp); -assert.equal(ecdh5.getPublicKey('hex', 'compressed'), cafebabePubPtComp); +assert.strictEqual(ecdh5.getPublicKey('hex'), cafebabePubPtUnComp); +assert.strictEqual(ecdh5.getPublicKey('hex', 'compressed'), cafebabePubPtComp); // Show why allowing the public key to be set on this type does not make sense. ecdh5.setPublicKey(peerPubPtComp, 'hex'); -assert.equal(ecdh5.getPublicKey('hex'), peerPubPtUnComp); +assert.strictEqual(ecdh5.getPublicKey('hex'), peerPubPtUnComp); assert.throws(function() { // Error because the public key does not match the private key anymore. ecdh5.computeSecret(peerPubPtComp, 'hex', 'hex'); @@ -265,7 +267,7 @@ ecdh5.setPrivateKey(cafebabeKey, 'hex'); ecdh5.setPrivateKey(element, 'hex'); }, /Private key is not valid for specified curve/); // Verify object state did not change. - assert.equal(ecdh5.getPrivateKey('hex'), cafebabeKey); + assert.strictEqual(ecdh5.getPrivateKey('hex'), cafebabeKey); }); // invalid test: curve argument is undefined diff --git a/test/parallel/test-crypto-domains.js b/test/parallel/test-crypto-domains.js index 2749382fa5c780..d0dcf7f2107f77 100644 --- a/test/parallel/test-crypto-domains.js +++ b/test/parallel/test-crypto-domains.js @@ -12,7 +12,7 @@ if (!common.hasCrypto) { const crypto = require('crypto'); d.on('error', common.mustCall(function(e) { - assert.equal(e.message, expect.shift()); + assert.strictEqual(e.message, expect.shift()); }, 3)); d.run(function() { diff --git a/test/parallel/test-crypto-fips.js b/test/parallel/test-crypto-fips.js index 60263cb01b6809..147ccb443817c6 100644 --- a/test/parallel/test-crypto-fips.js +++ b/test/parallel/test-crypto-fips.js @@ -47,10 +47,10 @@ function testHelper(stream, args, expectedOutput, cmd, env) { function responseHandler(buffer, expectedOutput) { const response = buffer.toString(); - assert.notEqual(0, response.length); + assert.notStrictEqual(0, response.length); if (FIPS_ENABLED !== expectedOutput && FIPS_DISABLED !== expectedOutput) { // In the case of expected errors just look for a substring. - assert.notEqual(-1, response.indexOf(expectedOutput)); + assert.notStrictEqual(-1, response.indexOf(expectedOutput)); } else { // Normal path where we expect either FIPS enabled or disabled. assert.strictEqual(expectedOutput, Number(response)); diff --git a/test/parallel/test-crypto-hash.js b/test/parallel/test-crypto-hash.js index 9008b8f9b1614c..0d55d4236a656e 100644 --- a/test/parallel/test-crypto-hash.js +++ b/test/parallel/test-crypto-hash.js @@ -67,8 +67,8 @@ assert.deepStrictEqual( // stream interface should produce the same result. assert.deepStrictEqual(a5, a3, 'stream interface is consistent'); assert.deepStrictEqual(a6, a3, 'stream interface is consistent'); -assert.notEqual(a7, undefined, 'no data should return data'); -assert.notEqual(a8, undefined, 'empty string should generate data'); +assert.notStrictEqual(a7, undefined, 'no data should return data'); +assert.notStrictEqual(a8, undefined, 'empty string should generate data'); // Test multiple updates to same hash const h1 = crypto.createHash('sha1').update('Test123').digest('hex'); @@ -100,7 +100,7 @@ assert.strictEqual( '4b21bbd1a68e690a730ddcb5a8bc94ead9879ffe82580767ad7ec6fa8ba2dea6' + '43a821af66afa9a45b6a78c712fecf0e56dc7f43aef4bcfc8eb5b4d8dca6ea5b'); -assert.notEqual( +assert.notStrictEqual( hutf8, crypto.createHash('sha512').update('УТФ-8 text', 'latin1').digest('hex')); diff --git a/test/parallel/test-crypto-rsa-dsa.js b/test/parallel/test-crypto-rsa-dsa.js index eadb948491f19c..e15efe1a73cd3c 100644 --- a/test/parallel/test-crypto-rsa-dsa.js +++ b/test/parallel/test-crypto-rsa-dsa.js @@ -124,7 +124,7 @@ function test_rsa(padding) { key: rsaKeyPem, padding: padding }, encryptedBuffer); - assert.equal(input, decryptedBuffer.toString()); + assert.strictEqual(input.toString(), decryptedBuffer.toString()); } test_rsa('RSA_NO_PADDING'); @@ -139,8 +139,8 @@ assert.ok(rsaVerify); rsaSign.update(rsaPubPem); let rsaSignature = rsaSign.sign(rsaKeyPem, 'hex'); -assert.equal(rsaSignature, - '5c50e3145c4e2497aadb0eabc83b342d0b0021ece0d4c4a064b7c' + +assert.strictEqual(rsaSignature, + '5c50e3145c4e2497aadb0eabc83b342d0b0021ece0d4c4a064b7c' + '8f020d7e2688b122bfb54c724ac9ee169f83f66d2fe90abeb95e8' + 'e1290e7e177152a4de3d944cf7d4883114a20ed0f78e70e25ef0f' + '60f06b858e6af42a2f276ede95bbc6bc9a9bbdda15bd663186a6f' + @@ -156,8 +156,8 @@ assert.doesNotThrow(function() { const signOptions = { key: rsaKeyPemEncrypted, passphrase: 'password' }; rsaSignature = rsaSign.sign(signOptions, 'hex'); }); -assert.equal(rsaSignature, - '5c50e3145c4e2497aadb0eabc83b342d0b0021ece0d4c4a064b7c' + +assert.strictEqual(rsaSignature, + '5c50e3145c4e2497aadb0eabc83b342d0b0021ece0d4c4a064b7c' + '8f020d7e2688b122bfb54c724ac9ee169f83f66d2fe90abeb95e8' + 'e1290e7e177152a4de3d944cf7d4883114a20ed0f78e70e25ef0f' + '60f06b858e6af42a2f276ede95bbc6bc9a9bbdda15bd663186a6f' + diff --git a/test/parallel/test-debug-signal-cluster.js b/test/parallel/test-debug-signal-cluster.js index 22bfdfb09dbdc5..7981621fd2787a 100644 --- a/test/parallel/test-debug-signal-cluster.js +++ b/test/parallel/test-debug-signal-cluster.js @@ -75,7 +75,7 @@ function assertOutputLines() { outputLines.sort(); expectedLines.sort(); - assert.equal(outputLines.length, expectedLines.length); + assert.strictEqual(outputLines.length, expectedLines.length); for (let i = 0; i < expectedLines.length; i++) assert(RegExp(expectedLines[i]).test(outputLines[i])); } diff --git a/test/parallel/test-dh-padding.js b/test/parallel/test-dh-padding.js index 72d54798d79da0..f0b7bfd95354ca 100644 --- a/test/parallel/test-dh-padding.js +++ b/test/parallel/test-dh-padding.js @@ -86,7 +86,7 @@ const p = crypto.createDiffieHellman( p.setPublicKey(apub, 'hex'); p.setPrivateKey(apriv, 'hex'); -assert.equal( +assert.strictEqual( p.computeSecret(bpub, 'hex', 'hex').toString('hex'), secret ); diff --git a/test/parallel/test-domain-nested.js b/test/parallel/test-domain-nested.js index d0618b5bad724b..6d673adc7e6387 100644 --- a/test/parallel/test-domain-nested.js +++ b/test/parallel/test-domain-nested.js @@ -6,7 +6,7 @@ const assert = require('assert'); const domain = require('domain'); process.on('exit', function(c) { - assert.equal(domain._stack.length, 0); + assert.strictEqual(domain._stack.length, 0); }); domain.create().run(function() { diff --git a/test/parallel/test-domain-throw-error-then-throw-from-uncaught-exception-handler.js b/test/parallel/test-domain-throw-error-then-throw-from-uncaught-exception-handler.js index 135877ebae44ff..c106e40e27b2d3 100644 --- a/test/parallel/test-domain-throw-error-then-throw-from-uncaught-exception-handler.js +++ b/test/parallel/test-domain-throw-error-then-throw-from-uncaught-exception-handler.js @@ -73,9 +73,9 @@ function runTestWithAbortOnUncaughtException() { child_process.exec(createTestCmdLine({ withAbortOnUncaughtException: true }), function onTestDone(err, stdout, stderr) { - assert.notEqual(err.code, RAN_UNCAUGHT_EXCEPTION_HANDLER_EXIT_CODE, - 'child process should not have run its uncaughtException ' + - 'event handler'); + assert.notStrictEqual(err.code, RAN_UNCAUGHT_EXCEPTION_HANDLER_EXIT_CODE, + 'child process should not have run its ' + + 'uncaughtException event handler'); assert(common.nodeProcessAborted(err.code, err.signal), 'process should have aborted, but did not'); }); diff --git a/test/parallel/test-event-emitter-prepend.js b/test/parallel/test-event-emitter-prepend.js index 5a3b66b0cb3250..b511af9ae3691d 100644 --- a/test/parallel/test-event-emitter-prepend.js +++ b/test/parallel/test-event-emitter-prepend.js @@ -7,13 +7,14 @@ const assert = require('assert'); const myEE = new EventEmitter(); let m = 0; // This one comes last. -myEE.on('foo', common.mustCall(() => assert.equal(m, 2))); +myEE.on('foo', common.mustCall(() => assert.strictEqual(m, 2))); // This one comes second. -myEE.prependListener('foo', common.mustCall(() => assert.equal(m++, 1))); +myEE.prependListener('foo', common.mustCall(() => assert.strictEqual(m++, 1))); // This one comes first. -myEE.prependOnceListener('foo', common.mustCall(() => assert.equal(m++, 0))); +myEE.prependOnceListener('foo', + common.mustCall(() => assert.strictEqual(m++, 0))); myEE.emit('foo'); diff --git a/test/parallel/test-event-emitter-remove-all-listeners.js b/test/parallel/test-event-emitter-remove-all-listeners.js index 9cf08369f82986..e793cedb0dd4cf 100644 --- a/test/parallel/test-event-emitter-remove-all-listeners.js +++ b/test/parallel/test-event-emitter-remove-all-listeners.js @@ -39,8 +39,8 @@ function listener() {} assert.deepStrictEqual(bazListeners, [listener, listener]); // After calling removeAllListeners(), // new listeners arrays is different from the old. - assert.notEqual(ee.listeners('bar'), barListeners); - assert.notEqual(ee.listeners('baz'), bazListeners); + assert.notStrictEqual(ee.listeners('bar'), barListeners); + assert.notStrictEqual(ee.listeners('baz'), bazListeners); } { diff --git a/test/parallel/test-event-emitter-subclass.js b/test/parallel/test-event-emitter-subclass.js index d35802b413136b..eb2018e78e4b85 100644 --- a/test/parallel/test-event-emitter-subclass.js +++ b/test/parallel/test-event-emitter-subclass.js @@ -43,4 +43,4 @@ const ee2 = new MyEE2(); ee1.on('x', function() {}); -assert.equal(ee2.listenerCount('x'), 0); +assert.strictEqual(ee2.listenerCount('x'), 0); diff --git a/test/parallel/test-fs-access.js b/test/parallel/test-fs-access.js index 80f63ac6128ce7..514c62939e8bda 100644 --- a/test/parallel/test-fs-access.js +++ b/test/parallel/test-fs-access.js @@ -72,7 +72,7 @@ fs.access(__filename, fs.R_OK, common.mustCall((err) => { })); fs.access(doesNotExist, common.mustCall((err) => { - assert.notEqual(err, null, 'error should exist'); + assert.notStrictEqual(err, null, 'error should exist'); assert.strictEqual(err.code, 'ENOENT'); assert.strictEqual(err.path, doesNotExist); })); @@ -85,7 +85,7 @@ fs.access(readOnlyFile, fs.W_OK, common.mustCall((err) => { if (hasWriteAccessForReadonlyFile) { assert.ifError(err); } else { - assert.notEqual(err, null, 'error should exist'); + assert.notStrictEqual(err, null, 'error should exist'); assert.strictEqual(err.path, readOnlyFile); } })); diff --git a/test/parallel/test-fs-error-messages.js b/test/parallel/test-fs-error-messages.js index 1a05ef80a44a5c..f2ea85531bf463 100644 --- a/test/parallel/test-fs-error-messages.js +++ b/test/parallel/test-fs-error-messages.js @@ -12,7 +12,7 @@ const existingDir2 = path.join(common.fixturesDir, 'keys'); // ASYNC_CALL fs.stat(fn, function(err) { - assert.equal(fn, err.path); + assert.strictEqual(fn, err.path); assert.ok(0 <= err.message.indexOf(fn)); }); @@ -204,7 +204,7 @@ try { } process.on('exit', function() { - assert.equal(expected, errors.length, - 'Test fs sync exceptions raised, got ' + errors.length + + assert.strictEqual(expected, errors.length, + 'Test fs sync exceptions raised, got ' + errors.length + ' expected ' + expected); }); diff --git a/test/parallel/test-fs-mkdir-rmdir.js b/test/parallel/test-fs-mkdir-rmdir.js index 0bddf673ecb107..bac18fc027931d 100644 --- a/test/parallel/test-fs-mkdir-rmdir.js +++ b/test/parallel/test-fs-mkdir-rmdir.js @@ -29,8 +29,8 @@ fs.mkdir(d, 0o666, function(err) { fs.mkdir(d, 0o666, function(err) { assert.ok(err.message.match(/^EEXIST/), 'got EEXIST message'); - assert.equal(err.code, 'EEXIST', 'got EEXIST code'); - assert.equal(err.path, d, 'got proper path for EEXIST'); + assert.strictEqual(err.code, 'EEXIST', 'got EEXIST code'); + assert.strictEqual(err.path, d, 'got proper path for EEXIST'); fs.rmdir(d, assert.ifError); }); diff --git a/test/parallel/test-fs-mkdir.js b/test/parallel/test-fs-mkdir.js index 620231102273e3..73fc899ce57597 100644 --- a/test/parallel/test-fs-mkdir.js +++ b/test/parallel/test-fs-mkdir.js @@ -33,8 +33,8 @@ common.refreshTmpDir(); unlink(pathname); fs.mkdir(pathname, 0o777, common.mustCall(function(err) { - assert.equal(err, null); - assert.equal(common.fileExists(pathname), true); + assert.strictEqual(err, null); + assert.strictEqual(common.fileExists(pathname), true); })); process.on('exit', function() { diff --git a/test/parallel/test-fs-mkdtemp.js b/test/parallel/test-fs-mkdtemp.js index c387090989c882..d4773aa37b7bf5 100644 --- a/test/parallel/test-fs-mkdtemp.js +++ b/test/parallel/test-fs-mkdtemp.js @@ -14,8 +14,8 @@ assert.strictEqual(path.basename(tmpFolder).length, 'foo.XXXXXX'.length); assert(common.fileExists(tmpFolder)); const utf8 = fs.mkdtempSync(path.join(common.tmpDir, '\u0222abc.')); -assert.equal(Buffer.byteLength(path.basename(utf8)), - Buffer.byteLength('\u0222abc.XXXXXX')); +assert.strictEqual(Buffer.byteLength(path.basename(utf8)), + Buffer.byteLength('\u0222abc.XXXXXX')); assert(common.fileExists(utf8)); function handler(err, folder) { diff --git a/test/parallel/test-fs-open-flags.js b/test/parallel/test-fs-open-flags.js index f07da13569b56a..2c8eceb4095ceb 100644 --- a/test/parallel/test-fs-open-flags.js +++ b/test/parallel/test-fs-open-flags.js @@ -12,21 +12,29 @@ const O_RDWR = fs.constants.O_RDWR || 0; const O_TRUNC = fs.constants.O_TRUNC || 0; const O_WRONLY = fs.constants.O_WRONLY || 0; -assert.equal(fs._stringToFlags('r'), O_RDONLY); -assert.equal(fs._stringToFlags('r+'), O_RDWR); -assert.equal(fs._stringToFlags('w'), O_TRUNC | O_CREAT | O_WRONLY); -assert.equal(fs._stringToFlags('w+'), O_TRUNC | O_CREAT | O_RDWR); -assert.equal(fs._stringToFlags('a'), O_APPEND | O_CREAT | O_WRONLY); -assert.equal(fs._stringToFlags('a+'), O_APPEND | O_CREAT | O_RDWR); - -assert.equal(fs._stringToFlags('wx'), O_TRUNC | O_CREAT | O_WRONLY | O_EXCL); -assert.equal(fs._stringToFlags('xw'), O_TRUNC | O_CREAT | O_WRONLY | O_EXCL); -assert.equal(fs._stringToFlags('wx+'), O_TRUNC | O_CREAT | O_RDWR | O_EXCL); -assert.equal(fs._stringToFlags('xw+'), O_TRUNC | O_CREAT | O_RDWR | O_EXCL); -assert.equal(fs._stringToFlags('ax'), O_APPEND | O_CREAT | O_WRONLY | O_EXCL); -assert.equal(fs._stringToFlags('xa'), O_APPEND | O_CREAT | O_WRONLY | O_EXCL); -assert.equal(fs._stringToFlags('ax+'), O_APPEND | O_CREAT | O_RDWR | O_EXCL); -assert.equal(fs._stringToFlags('xa+'), O_APPEND | O_CREAT | O_RDWR | O_EXCL); +assert.strictEqual(fs._stringToFlags('r'), O_RDONLY); +assert.strictEqual(fs._stringToFlags('r+'), O_RDWR); +assert.strictEqual(fs._stringToFlags('w'), O_TRUNC | O_CREAT | O_WRONLY); +assert.strictEqual(fs._stringToFlags('w+'), O_TRUNC | O_CREAT | O_RDWR); +assert.strictEqual(fs._stringToFlags('a'), O_APPEND | O_CREAT | O_WRONLY); +assert.strictEqual(fs._stringToFlags('a+'), O_APPEND | O_CREAT | O_RDWR); + +assert.strictEqual(fs._stringToFlags('wx'), + O_TRUNC | O_CREAT | O_WRONLY | O_EXCL); +assert.strictEqual(fs._stringToFlags('xw'), + O_TRUNC | O_CREAT | O_WRONLY | O_EXCL); +assert.strictEqual(fs._stringToFlags('wx+'), + O_TRUNC | O_CREAT | O_RDWR | O_EXCL); +assert.strictEqual(fs._stringToFlags('xw+'), + O_TRUNC | O_CREAT | O_RDWR | O_EXCL); +assert.strictEqual(fs._stringToFlags('ax'), + O_APPEND | O_CREAT | O_WRONLY | O_EXCL); +assert.strictEqual(fs._stringToFlags('xa'), + O_APPEND | O_CREAT | O_WRONLY | O_EXCL); +assert.strictEqual(fs._stringToFlags('ax+'), + O_APPEND | O_CREAT | O_RDWR | O_EXCL); +assert.strictEqual(fs._stringToFlags('xa+'), + O_APPEND | O_CREAT | O_RDWR | O_EXCL); ('+ +a +r +w rw wa war raw r++ a++ w++ x +x x+ rx rx+ wxx wax xwx xxx') .split(' ') diff --git a/test/parallel/test-fs-read-buffer-zero-length.js b/test/parallel/test-fs-read-buffer-zero-length.js index 35b1f7b566f685..4c7dd73f60ebb1 100644 --- a/test/parallel/test-fs-read-buffer-zero-length.js +++ b/test/parallel/test-fs-read-buffer-zero-length.js @@ -10,10 +10,10 @@ const bufferAsync = Buffer.alloc(0); const bufferSync = Buffer.alloc(0); fs.read(fd, bufferAsync, 0, 0, 0, common.mustCall(function(err, bytesRead) { - assert.equal(bytesRead, 0); + assert.strictEqual(bytesRead, 0); assert.deepStrictEqual(bufferAsync, Buffer.alloc(0)); })); const r = fs.readSync(fd, bufferSync, 0, 0, 0); assert.deepStrictEqual(bufferSync, Buffer.alloc(0)); -assert.equal(r, 0); +assert.strictEqual(r, 0); diff --git a/test/parallel/test-fs-read-buffer.js b/test/parallel/test-fs-read-buffer.js index cc1d1052351849..1242f7eb529c43 100644 --- a/test/parallel/test-fs-read-buffer.js +++ b/test/parallel/test-fs-read-buffer.js @@ -16,10 +16,10 @@ fs.read(fd, expected.length, 0, common.mustCall(function(err, bytesRead) { - assert.equal(bytesRead, expected.length); + assert.strictEqual(bytesRead, expected.length); assert.deepStrictEqual(bufferAsync, Buffer.from(expected)); })); const r = fs.readSync(fd, bufferSync, 0, expected.length, 0); assert.deepStrictEqual(bufferSync, Buffer.from(expected)); -assert.equal(r, expected.length); +assert.strictEqual(r, expected.length); diff --git a/test/parallel/test-fs-read-stream-fd.js b/test/parallel/test-fs-read-stream-fd.js index 93b93085159ac6..16084401ced4bf 100644 --- a/test/parallel/test-fs-read-stream-fd.js +++ b/test/parallel/test-fs-read-stream-fd.js @@ -18,5 +18,5 @@ stream.on('data', function(data) { process.on('exit', function() { fs.unlinkSync(file); - assert.equal(output, input); + assert.strictEqual(output, input); }); diff --git a/test/parallel/test-fs-read-stream.js b/test/parallel/test-fs-read-stream.js index d4fad6e6f79c07..d17703fabe6a27 100644 --- a/test/parallel/test-fs-read-stream.js +++ b/test/parallel/test-fs-read-stream.js @@ -61,7 +61,7 @@ file.on('close', function() { assert.strictEqual(file.bytesRead, fileSize); callbacks.close++; - //assert.equal(fs.readFileSync(fn), fileContent); + //assert.strictEqual(fs.readFileSync(fn), fileContent); }); const file3 = fs.createReadStream(fn, {encoding: 'utf8'}); diff --git a/test/parallel/test-fs-read-zero-length.js b/test/parallel/test-fs-read-zero-length.js index 71c6385c6024f7..a3e98f540a4151 100644 --- a/test/parallel/test-fs-read-zero-length.js +++ b/test/parallel/test-fs-read-zero-length.js @@ -9,10 +9,10 @@ const expected = ''; fs.read(fd, 0, 0, 'utf-8', common.mustCall((err, str, bytesRead) => { assert.ok(!err); - assert.equal(str, expected); - assert.equal(bytesRead, 0); + assert.strictEqual(str, expected); + assert.strictEqual(bytesRead, 0); })); const r = fs.readSync(fd, 0, 0, 'utf-8'); -assert.equal(r[0], expected); -assert.equal(r[1], 0); +assert.strictEqual(r[0], expected); +assert.strictEqual(r[1], 0); diff --git a/test/parallel/test-fs-readdir-ucs2.js b/test/parallel/test-fs-readdir-ucs2.js index 916758fe943f86..de8fe5d536d7d5 100644 --- a/test/parallel/test-fs-readdir-ucs2.js +++ b/test/parallel/test-fs-readdir-ucs2.js @@ -20,7 +20,7 @@ fs.closeSync(fs.openSync(fullpath, 'w+')); fs.readdir(common.tmpDir, 'ucs2', (err, list) => { if (err) throw err; - assert.equal(1, list.length); + assert.strictEqual(1, list.length); const fn = list[0]; assert.deepStrictEqual(filebuff, Buffer.from(fn, 'ucs2')); assert.strictEqual(fn, filename); diff --git a/test/parallel/test-fs-readdir.js b/test/parallel/test-fs-readdir.js index f38ae49c90a18f..57612f3e26b183 100644 --- a/test/parallel/test-fs-readdir.js +++ b/test/parallel/test-fs-readdir.js @@ -31,5 +31,5 @@ assert.throws(function() { }, /Error: ENOTDIR: not a directory/); fs.readdir(__filename, common.mustCall(function(e) { - assert.equal(e.code, 'ENOTDIR'); + assert.strictEqual(e.code, 'ENOTDIR'); })); diff --git a/test/parallel/test-fs-realpath.js b/test/parallel/test-fs-realpath.js index 54c509d55e1fed..3152ff80a38688 100644 --- a/test/parallel/test-fs-realpath.js +++ b/test/parallel/test-fs-realpath.js @@ -508,6 +508,6 @@ function runTest() { process.on('exit', function() { - assert.equal(numtests, testsRun); - assert.equal(async_completed, async_expected); + assert.strictEqual(numtests, testsRun); + assert.strictEqual(async_completed, async_expected); }); diff --git a/test/parallel/test-fs-stat.js b/test/parallel/test-fs-stat.js index 32ba47c2fe0c1e..00fcc1df21c586 100644 --- a/test/parallel/test-fs-stat.js +++ b/test/parallel/test-fs-stat.js @@ -57,25 +57,25 @@ fs.stat(__filename, common.mustCall(function(err, s) { console.dir(s); console.log('isDirectory: ' + JSON.stringify(s.isDirectory())); - assert.equal(false, s.isDirectory()); + assert.strictEqual(false, s.isDirectory()); console.log('isFile: ' + JSON.stringify(s.isFile())); - assert.equal(true, s.isFile()); + assert.strictEqual(true, s.isFile()); console.log('isSocket: ' + JSON.stringify(s.isSocket())); - assert.equal(false, s.isSocket()); + assert.strictEqual(false, s.isSocket()); console.log('isBlockDevice: ' + JSON.stringify(s.isBlockDevice())); - assert.equal(false, s.isBlockDevice()); + assert.strictEqual(false, s.isBlockDevice()); console.log('isCharacterDevice: ' + JSON.stringify(s.isCharacterDevice())); - assert.equal(false, s.isCharacterDevice()); + assert.strictEqual(false, s.isCharacterDevice()); console.log('isFIFO: ' + JSON.stringify(s.isFIFO())); - assert.equal(false, s.isFIFO()); + assert.strictEqual(false, s.isFIFO()); console.log('isSymbolicLink: ' + JSON.stringify(s.isSymbolicLink())); - assert.equal(false, s.isSymbolicLink()); + assert.strictEqual(false, s.isSymbolicLink()); assert.ok(s.mtime instanceof Date); })); diff --git a/test/parallel/test-fs-sync-fd-leak.js b/test/parallel/test-fs-sync-fd-leak.js index 0adf407d25d7a4..8982e319d6f4e6 100644 --- a/test/parallel/test-fs-sync-fd-leak.js +++ b/test/parallel/test-fs-sync-fd-leak.js @@ -10,7 +10,7 @@ fs.openSync = function() { let close_called = 0; fs.closeSync = function(fd) { - assert.equal(fd, 42); + assert.strictEqual(fd, 42); close_called++; }; fs.readSync = function() { @@ -41,10 +41,10 @@ function ensureThrows(cb) { try { cb(); } catch (e) { - assert.equal(e.message, 'BAM'); + assert.strictEqual(e.message, 'BAM'); got_exception = true; } - assert.equal(close_called, 1); - assert.equal(got_exception, true); + assert.strictEqual(close_called, 1); + assert.strictEqual(got_exception, true); } diff --git a/test/parallel/test-fs-watch-enoent.js b/test/parallel/test-fs-watch-enoent.js index f9aa58c3d522cc..38f10e1430a360 100644 --- a/test/parallel/test-fs-watch-enoent.js +++ b/test/parallel/test-fs-watch-enoent.js @@ -8,7 +8,7 @@ assert.throws(function() { }, function(err) { assert(err); assert(/non-existent-file/.test(err)); - assert.equal(err.filename, 'non-existent-file'); + assert.strictEqual(err.filename, 'non-existent-file'); return true; }); @@ -16,6 +16,6 @@ const watcher = fs.watch(__filename); watcher.on('error', common.mustCall(function(err) { assert(err); assert(/non-existent-file/.test(err)); - assert.equal(err.filename, 'non-existent-file'); + assert.strictEqual(err.filename, 'non-existent-file'); })); watcher._handle.onchange(-1, 'ENOENT', 'non-existent-file'); diff --git a/test/parallel/test-fs-write-buffer.js b/test/parallel/test-fs-write-buffer.js index 7b4081010fd6d7..61b00c9baba452 100644 --- a/test/parallel/test-fs-write-buffer.js +++ b/test/parallel/test-fs-write-buffer.js @@ -20,7 +20,7 @@ fs.open(filename, 'w', 0o644, common.mustCall(function(err, fd) { common.mustCall(function(err, written) { if (err) throw err; - assert.equal(expected.length, written); + assert.strictEqual(expected.length, written); fs.closeSync(fd); const found = fs.readFileSync(filename, 'utf8'); diff --git a/test/parallel/test-fs-write-stream-change-open.js b/test/parallel/test-fs-write-stream-change-open.js index f68cc0a6d386e2..146b507a48ac61 100644 --- a/test/parallel/test-fs-write-stream-change-open.js +++ b/test/parallel/test-fs-write-stream-change-open.js @@ -29,5 +29,5 @@ stream.write('foo'); stream.end(); process.on('exit', function() { - assert.equal(fs.open, _fs_open); + assert.strictEqual(fs.open, _fs_open); }); diff --git a/test/parallel/test-fs-write-stream-err.js b/test/parallel/test-fs-write-stream-err.js index d50fd07103222e..4a2b3cd130b4c4 100644 --- a/test/parallel/test-fs-write-stream-err.js +++ b/test/parallel/test-fs-write-stream-err.js @@ -33,14 +33,14 @@ fs.write = function() { fs.close = common.mustCall(function(fd_, cb) { console.error('fs.close', fd_, stream.fd); - assert.equal(fd_, stream.fd); + assert.strictEqual(fd_, stream.fd); process.nextTick(cb); }); stream.on('error', common.mustCall(function(err_) { console.error('error handler'); - assert.equal(stream.fd, null); - assert.equal(err_, err); + assert.strictEqual(stream.fd, null); + assert.strictEqual(err_, err); })); @@ -48,6 +48,6 @@ stream.write(Buffer.allocUnsafe(256), function() { console.error('first cb'); stream.write(Buffer.allocUnsafe(256), common.mustCall(function(err_) { console.error('second cb'); - assert.equal(err_, err); + assert.strictEqual(err_, err); })); }); diff --git a/test/parallel/test-fs-write-string-coerce.js b/test/parallel/test-fs-write-string-coerce.js index 9daae645822acb..df19de1378d0f4 100644 --- a/test/parallel/test-fs-write-string-coerce.js +++ b/test/parallel/test-fs-write-string-coerce.js @@ -17,7 +17,7 @@ fs.open(fn, 'w', 0o644, common.mustCall(function(err, fd) { fs.write(fd, data, 0, 'utf8', common.mustCall(function(err, written) { console.log('write done'); if (err) throw err; - assert.equal(Buffer.byteLength(expected), written); + assert.strictEqual(Buffer.byteLength(expected), written); fs.closeSync(fd); const found = fs.readFileSync(fn, 'utf8'); console.log('expected: "%s"', expected); diff --git a/test/parallel/test-fs-write-sync.js b/test/parallel/test-fs-write-sync.js index 8f1a8f75c5dac0..fb97deb268f093 100644 --- a/test/parallel/test-fs-write-sync.js +++ b/test/parallel/test-fs-write-sync.js @@ -20,4 +20,4 @@ written = fs.writeSync(fd, Buffer.from(bar), 0, Buffer.byteLength(bar)); assert.ok(written > 3); fs.closeSync(fd); -assert.equal(fs.readFileSync(fn), 'foobár'); +assert.strictEqual(fs.readFileSync(fn, 'utf8'), 'foobár'); diff --git a/test/parallel/test-http-abort-queued.js b/test/parallel/test-http-abort-queued.js index 8e8339aa82d3dd..60dde248df542c 100644 --- a/test/parallel/test-http-abort-queued.js +++ b/test/parallel/test-http-abort-queued.js @@ -8,7 +8,7 @@ let complete; const server = http.createServer(function(req, res) { // We should not see the queued /thatotherone request within the server // as it should be aborted before it is sent. - assert.equal(req.url, '/'); + assert.strictEqual(req.url, '/'); res.writeHead(200); res.write('foo'); @@ -23,7 +23,7 @@ server.listen(0, function() { console.log('listen', server.address().port); const agent = new http.Agent({maxSockets: 1}); - assert.equal(Object.keys(agent.sockets).length, 0); + assert.strictEqual(Object.keys(agent.sockets).length, 0); const options = { hostname: 'localhost', @@ -35,8 +35,8 @@ server.listen(0, function() { const req1 = http.request(options); req1.on('response', function(res1) { - assert.equal(Object.keys(agent.sockets).length, 1); - assert.equal(Object.keys(agent.requests).length, 0); + assert.strictEqual(Object.keys(agent.sockets).length, 1); + assert.strictEqual(Object.keys(agent.requests).length, 0); const req2 = http.request({ method: 'GET', @@ -45,19 +45,19 @@ server.listen(0, function() { path: '/thatotherone', agent: agent }); - assert.equal(Object.keys(agent.sockets).length, 1); - assert.equal(Object.keys(agent.requests).length, 1); + assert.strictEqual(Object.keys(agent.sockets).length, 1); + assert.strictEqual(Object.keys(agent.requests).length, 1); req2.on('error', function(err) { // This is expected in response to our explicit abort call - assert.equal(err.code, 'ECONNRESET'); + assert.strictEqual(err.code, 'ECONNRESET'); }); req2.end(); req2.abort(); - assert.equal(Object.keys(agent.sockets).length, 1); - assert.equal(Object.keys(agent.requests).length, 1); + assert.strictEqual(Object.keys(agent.sockets).length, 1); + assert.strictEqual(Object.keys(agent.requests).length, 1); console.log('Got res: ' + res1.statusCode); console.dir(res1.headers); @@ -72,8 +72,8 @@ server.listen(0, function() { console.log('Response ended.'); setTimeout(function() { - assert.equal(Object.keys(agent.sockets).length, 0); - assert.equal(Object.keys(agent.requests).length, 0); + assert.strictEqual(Object.keys(agent.sockets).length, 0); + assert.strictEqual(Object.keys(agent.requests).length, 0); server.close(); }, 100); diff --git a/test/parallel/test-http-agent-error-on-idle.js b/test/parallel/test-http-agent-error-on-idle.js index b2bf6334dcbc1b..23fa4dddfab57c 100644 --- a/test/parallel/test-http-agent-error-on-idle.js +++ b/test/parallel/test-http-agent-error-on-idle.js @@ -23,13 +23,13 @@ server.listen(0, function() { const socketKey = agent.getName(requestParams); get(function(res) { - assert.equal(res.statusCode, 200); + assert.strictEqual(res.statusCode, 200); res.resume(); res.on('end', function() { process.nextTick(function() { const freeSockets = agent.freeSockets[socketKey]; - assert.equal(freeSockets.length, 1, - 'expect a free socket on ' + socketKey); + assert.strictEqual(freeSockets.length, 1, + 'expect a free socket on ' + socketKey); //generate a random error on the free socket const freeSocket = freeSockets[0]; @@ -45,8 +45,8 @@ server.listen(0, function() { } function done() { - assert.equal(Object.keys(agent.freeSockets).length, 0, - 'expect the freeSockets pool to be empty'); + assert.strictEqual(Object.keys(agent.freeSockets).length, 0, + 'expect the freeSockets pool to be empty'); agent.destroy(); server.close(); diff --git a/test/parallel/test-http-agent-keepalive.js b/test/parallel/test-http-agent-keepalive.js index a78f97edec1fdc..9ea3fd7677aebe 100644 --- a/test/parallel/test-http-agent-keepalive.js +++ b/test/parallel/test-http-agent-keepalive.js @@ -37,22 +37,22 @@ function get(path, callback) { } function checkDataAndSockets(body) { - assert.equal(body.toString(), 'hello world'); - assert.equal(agent.sockets[name].length, 1); - assert.equal(agent.freeSockets[name], undefined); + assert.strictEqual(body.toString(), 'hello world'); + assert.strictEqual(agent.sockets[name].length, 1); + assert.strictEqual(agent.freeSockets[name], undefined); } function second() { // request second, use the same socket get('/second', function(res) { - assert.equal(res.statusCode, 200); + assert.strictEqual(res.statusCode, 200); res.on('data', checkDataAndSockets); res.on('end', function() { - assert.equal(agent.sockets[name].length, 1); - assert.equal(agent.freeSockets[name], undefined); + assert.strictEqual(agent.sockets[name].length, 1); + assert.strictEqual(agent.freeSockets[name], undefined); process.nextTick(function() { - assert.equal(agent.sockets[name], undefined); - assert.equal(agent.freeSockets[name].length, 1); + assert.strictEqual(agent.sockets[name], undefined); + assert.strictEqual(agent.freeSockets[name].length, 1); remoteClose(); }); }); @@ -65,16 +65,16 @@ function remoteClose() { assert.deepStrictEqual(res.statusCode, 200); res.on('data', checkDataAndSockets); res.on('end', function() { - assert.equal(agent.sockets[name].length, 1); - assert.equal(agent.freeSockets[name], undefined); + assert.strictEqual(agent.sockets[name].length, 1); + assert.strictEqual(agent.freeSockets[name], undefined); process.nextTick(function() { - assert.equal(agent.sockets[name], undefined); - assert.equal(agent.freeSockets[name].length, 1); + assert.strictEqual(agent.sockets[name], undefined); + assert.strictEqual(agent.freeSockets[name].length, 1); // waitting remote server close the socket setTimeout(function() { - assert.equal(agent.sockets[name], undefined); - assert.equal(agent.freeSockets[name], undefined, - 'freeSockets is not empty'); + assert.strictEqual(agent.sockets[name], undefined); + assert.strictEqual(agent.freeSockets[name], undefined, + 'freeSockets is not empty'); remoteError(); }, common.platformTimeout(200)); }); @@ -89,13 +89,13 @@ function remoteError() { }); req.on('error', function(err) { assert.ok(err); - assert.equal(err.message, 'socket hang up'); - assert.equal(agent.sockets[name].length, 1); - assert.equal(agent.freeSockets[name], undefined); + assert.strictEqual(err.message, 'socket hang up'); + assert.strictEqual(agent.sockets[name].length, 1); + assert.strictEqual(agent.freeSockets[name], undefined); // Wait socket 'close' event emit setTimeout(function() { - assert.equal(agent.sockets[name], undefined); - assert.equal(agent.freeSockets[name], undefined); + assert.strictEqual(agent.sockets[name], undefined); + assert.strictEqual(agent.freeSockets[name], undefined); done(); }, common.platformTimeout(1)); }); @@ -110,14 +110,14 @@ server.listen(0, function() { name = `localhost:${server.address().port}:`; // request first, and keep alive get('/first', function(res) { - assert.equal(res.statusCode, 200); + assert.strictEqual(res.statusCode, 200); res.on('data', checkDataAndSockets); res.on('end', function() { - assert.equal(agent.sockets[name].length, 1); - assert.equal(agent.freeSockets[name], undefined); + assert.strictEqual(agent.sockets[name].length, 1); + assert.strictEqual(agent.freeSockets[name], undefined); process.nextTick(function() { - assert.equal(agent.sockets[name], undefined); - assert.equal(agent.freeSockets[name].length, 1); + assert.strictEqual(agent.sockets[name], undefined); + assert.strictEqual(agent.freeSockets[name].length, 1); second(); }); }); diff --git a/test/parallel/test-http-agent-maxsockets.js b/test/parallel/test-http-agent-maxsockets.js index 6814aca3e76fbc..fc7618c5c02fe7 100644 --- a/test/parallel/test-http-agent-maxsockets.js +++ b/test/parallel/test-http-agent-maxsockets.js @@ -29,15 +29,15 @@ function done() { return; } const freepool = agent.freeSockets[Object.keys(agent.freeSockets)[0]]; - assert.equal(freepool.length, 2, - 'expect keep 2 free sockets, but got ' + freepool.length); + assert.strictEqual(freepool.length, 2, + 'expect keep 2 free sockets, but got ' + freepool.length); agent.destroy(); server.close(); } server.listen(0, function() { get('/1', function(res) { - assert.equal(res.statusCode, 200); + assert.strictEqual(res.statusCode, 200); res.resume(); res.on('end', function() { process.nextTick(done); @@ -45,7 +45,7 @@ server.listen(0, function() { }); get('/2', function(res) { - assert.equal(res.statusCode, 200); + assert.strictEqual(res.statusCode, 200); res.resume(); res.on('end', function() { process.nextTick(done); diff --git a/test/parallel/test-http-agent.js b/test/parallel/test-http-agent.js index 85975979cb3265..cfb37539ede878 100644 --- a/test/parallel/test-http-agent.js +++ b/test/parallel/test-http-agent.js @@ -35,5 +35,5 @@ server.listen(0, function() { process.on('exit', function() { - assert.equal(N * M, responses); + assert.strictEqual(N * M, responses); }); diff --git a/test/parallel/test-http-automatic-headers.js b/test/parallel/test-http-automatic-headers.js index 5fc8d780af9396..37a5c43901c33d 100644 --- a/test/parallel/test-http-automatic-headers.js +++ b/test/parallel/test-http-automatic-headers.js @@ -18,13 +18,13 @@ server.on('listening', function() { path: '/hello', agent: agent }, function(res) { - assert.equal(res.statusCode, 200); - assert.equal(res.headers['x-date'], 'foo'); - assert.equal(res.headers['x-connection'], 'bar'); - assert.equal(res.headers['x-content-length'], 'baz'); + assert.strictEqual(res.statusCode, 200); + assert.strictEqual(res.headers['x-date'], 'foo'); + assert.strictEqual(res.headers['x-connection'], 'bar'); + assert.strictEqual(res.headers['x-content-length'], 'baz'); assert(res.headers['date']); - assert.equal(res.headers['connection'], 'keep-alive'); - assert.equal(res.headers['content-length'], '0'); + assert.strictEqual(res.headers['connection'], 'keep-alive'); + assert.strictEqual(res.headers['content-length'], '0'); server.close(); agent.destroy(); }); diff --git a/test/parallel/test-http-blank-header.js b/test/parallel/test-http-blank-header.js index 2a6bf482077166..edd8923fa8e2f7 100644 --- a/test/parallel/test-http-blank-header.js +++ b/test/parallel/test-http-blank-header.js @@ -5,8 +5,8 @@ const http = require('http'); const net = require('net'); const server = http.createServer(common.mustCall(function(req, res) { - assert.equal('GET', req.method); - assert.equal('/blah', req.url); + assert.strictEqual('GET', req.method); + assert.strictEqual('/blah', req.url); assert.deepStrictEqual({ host: 'mapdevel.trolologames.ru:443', origin: 'http://mapdevel.trolologames.ru', diff --git a/test/parallel/test-http-buffer-sanity.js b/test/parallel/test-http-buffer-sanity.js index c240cd13b1825c..4226f1c65237fa 100644 --- a/test/parallel/test-http-buffer-sanity.js +++ b/test/parallel/test-http-buffer-sanity.js @@ -23,7 +23,7 @@ const web = http.Server(function(req, res) { process.stdout.write(','); measuredSize += d.length; for (let j = 0; j < d.length; j++) { - assert.equal(buffer[i], d[j]); + assert.strictEqual(buffer[i], d[j]); i++; } }); @@ -54,7 +54,7 @@ web.listen(0, common.mustCall(function() { console.log('Got response'); res.setEncoding('utf8'); res.on('data', common.mustCall(function(string) { - assert.equal('thanks', string); + assert.strictEqual('thanks', string); })); })); req.end(buffer); @@ -62,5 +62,5 @@ web.listen(0, common.mustCall(function() { process.on('exit', function() { - assert.equal(bufferSize, measuredSize); + assert.strictEqual(bufferSize, measuredSize); }); diff --git a/test/parallel/test-http-catch-uncaughtexception.js b/test/parallel/test-http-catch-uncaughtexception.js index 06d9b9a6e5d4e0..1366b6e26ea37f 100644 --- a/test/parallel/test-http-catch-uncaughtexception.js +++ b/test/parallel/test-http-catch-uncaughtexception.js @@ -5,7 +5,7 @@ const assert = require('assert'); const http = require('http'); const uncaughtCallback = common.mustCall(function(er) { - assert.equal(er.message, 'get did fail'); + assert.strictEqual(er.message, 'get did fail'); }); process.on('uncaughtException', uncaughtCallback); diff --git a/test/parallel/test-http-chunk-problem.js b/test/parallel/test-http-chunk-problem.js index 9bb004dc973f5c..13f7a5cfc00411 100644 --- a/test/parallel/test-http-chunk-problem.js +++ b/test/parallel/test-http-chunk-problem.js @@ -52,8 +52,8 @@ function executeRequest(cb) { 'shasum' ].join(' '), (err, stdout, stderr) => { if (err) throw err; - assert.equal('8c206a1a87599f532ce68675536f0b1546900d7a', - stdout.slice(0, 40)); + assert.strictEqual('8c206a1a87599f532ce68675536f0b1546900d7a', + stdout.slice(0, 40)); cb(); } ); diff --git a/test/parallel/test-http-chunked.js b/test/parallel/test-http-chunked.js index 516523221133ec..b70a704bb7fce4 100644 --- a/test/parallel/test-http-chunked.js +++ b/test/parallel/test-http-chunked.js @@ -30,9 +30,9 @@ server.listen(0, function() { throw e; }); x.on('end', function() { - assert.equal('string', typeof data); + assert.strictEqual('string', typeof data); console.log('here is the response:'); - assert.equal(UTF8_STRING, data); + assert.strictEqual(UTF8_STRING, data); console.log(data); server.close(); }); diff --git a/test/parallel/test-http-client-abort.js b/test/parallel/test-http-client-abort.js index 738c620815a21a..5c5b319bfa4f5f 100644 --- a/test/parallel/test-http-client-abort.js +++ b/test/parallel/test-http-client-abort.js @@ -51,5 +51,5 @@ server.listen(0, function() { }); process.on('exit', function() { - assert.equal(N, clientAborts); + assert.strictEqual(N, clientAborts); }); diff --git a/test/parallel/test-http-client-agent.js b/test/parallel/test-http-client-agent.js index 3c2b9c89727467..277c7a33ae586a 100644 --- a/test/parallel/test-http-client-agent.js +++ b/test/parallel/test-http-client-agent.js @@ -34,7 +34,7 @@ function request(i) { socket.on('close', function() { ++count; if (count < max) { - assert.equal(http.globalAgent.sockets[name].indexOf(socket), -1); + assert.strictEqual(http.globalAgent.sockets[name].indexOf(socket), -1); } else { assert(!http.globalAgent.sockets.hasOwnProperty(name)); assert(!http.globalAgent.requests.hasOwnProperty(name)); @@ -46,5 +46,5 @@ function request(i) { } process.on('exit', function() { - assert.equal(count, max); + assert.strictEqual(count, max); }); diff --git a/test/parallel/test-http-client-get-url.js b/test/parallel/test-http-client-get-url.js index d666fdd8354e71..ea44537cd08e72 100644 --- a/test/parallel/test-http-client-get-url.js +++ b/test/parallel/test-http-client-get-url.js @@ -4,8 +4,8 @@ const assert = require('assert'); const http = require('http'); const server = http.createServer(common.mustCall(function(req, res) { - assert.equal('GET', req.method); - assert.equal('/foo?bar', req.url); + assert.strictEqual('GET', req.method); + assert.strictEqual('/foo?bar', req.url); res.writeHead(200, {'Content-Type': 'text/plain'}); res.write('hello\n'); res.end(); diff --git a/test/parallel/test-http-client-parse-error.js b/test/parallel/test-http-client-parse-error.js index 0d8f577a78566c..e649f983a51626 100644 --- a/test/parallel/test-http-client-parse-error.js +++ b/test/parallel/test-http-client-parse-error.js @@ -27,13 +27,13 @@ net.createServer(function(c) { }).on('error', function(e) { console.log('got error from client'); assert.ok(e.message.indexOf('Parse Error') >= 0); - assert.equal(e.code, 'HPE_INVALID_CONSTANT'); + assert.strictEqual(e.code, 'HPE_INVALID_CONSTANT'); parseErrors++; }).end(); } }); process.on('exit', function() { - assert.equal(connects, 2); - assert.equal(parseErrors, 2); + assert.strictEqual(connects, 2); + assert.strictEqual(parseErrors, 2); }); diff --git a/test/parallel/test-http-client-race-2.js b/test/parallel/test-http-client-race-2.js index a6ccc7297967a5..fd8f5c50ccec13 100644 --- a/test/parallel/test-http-client-race-2.js +++ b/test/parallel/test-http-client-race-2.js @@ -91,7 +91,7 @@ server.on('listening', function() { }); process.on('exit', function() { - assert.equal(body1_s, body1); - assert.equal(body2_s, body2); - assert.equal(body3_s, body3); + assert.strictEqual(body1_s, body1); + assert.strictEqual(body2_s, body2); + assert.strictEqual(body3_s, body3); }); diff --git a/test/parallel/test-http-client-race.js b/test/parallel/test-http-client-race.js index 14e3300f20a436..f7610507378921 100644 --- a/test/parallel/test-http-client-race.js +++ b/test/parallel/test-http-client-race.js @@ -41,6 +41,6 @@ server.on('listening', function() { }); process.on('exit', function() { - assert.equal(body1_s, body1); - assert.equal(body2_s, body2); + assert.strictEqual(body1_s, body1); + assert.strictEqual(body2_s, body2); }); diff --git a/test/parallel/test-http-client-reject-chunked-with-content-length.js b/test/parallel/test-http-client-reject-chunked-with-content-length.js index daa0591cd75506..3d99f6ef406b1b 100644 --- a/test/parallel/test-http-client-reject-chunked-with-content-length.js +++ b/test/parallel/test-http-client-reject-chunked-with-content-length.js @@ -22,7 +22,7 @@ server.listen(0, () => { }); req.on('error', common.mustCall((err) => { assert(/^Parse Error/.test(err.message)); - assert.equal(err.code, 'HPE_UNEXPECTED_CONTENT_LENGTH'); + assert.strictEqual(err.code, 'HPE_UNEXPECTED_CONTENT_LENGTH'); server.close(); })); }); diff --git a/test/parallel/test-http-client-reject-cr-no-lf.js b/test/parallel/test-http-client-reject-cr-no-lf.js index 4cabfa0107bbc8..23530cbc7ae74c 100644 --- a/test/parallel/test-http-client-reject-cr-no-lf.js +++ b/test/parallel/test-http-client-reject-cr-no-lf.js @@ -21,7 +21,7 @@ server.listen(0, () => { }); req.on('error', common.mustCall((err) => { assert(/^Parse Error/.test(err.message)); - assert.equal(err.code, 'HPE_LF_EXPECTED'); + assert.strictEqual(err.code, 'HPE_LF_EXPECTED'); server.close(); })); }); diff --git a/test/parallel/test-http-client-response-domain.js b/test/parallel/test-http-client-response-domain.js index eb8b226acef169..20babf51a9178a 100644 --- a/test/parallel/test-http-client-response-domain.js +++ b/test/parallel/test-http-client-response-domain.js @@ -23,7 +23,7 @@ server.listen(common.PIPE, function() { function test() { d.on('error', common.mustCall(function(err) { - assert.equal('should be caught by domain', err.message); + assert.strictEqual('should be caught by domain', err.message); })); const req = http.get({ diff --git a/test/parallel/test-http-client-upload-buf.js b/test/parallel/test-http-client-upload-buf.js index 338aab9cc59ba0..208de06e8ebcd5 100644 --- a/test/parallel/test-http-client-upload-buf.js +++ b/test/parallel/test-http-client-upload-buf.js @@ -6,7 +6,7 @@ const http = require('http'); const N = 1024; const server = http.createServer(common.mustCall(function(req, res) { - assert.equal('POST', req.method); + assert.strictEqual('POST', req.method); let bytesReceived = 0; diff --git a/test/parallel/test-http-client-upload.js b/test/parallel/test-http-client-upload.js index ba60681776ba49..474dc333d142cd 100644 --- a/test/parallel/test-http-client-upload.js +++ b/test/parallel/test-http-client-upload.js @@ -4,7 +4,7 @@ const assert = require('assert'); const http = require('http'); const server = http.createServer(common.mustCall(function(req, res) { - assert.equal('POST', req.method); + assert.strictEqual('POST', req.method); req.setEncoding('utf8'); let sent_body = ''; diff --git a/test/parallel/test-http-conn-reset.js b/test/parallel/test-http-conn-reset.js index f7f08a6bf42c81..ae04c41aff5181 100644 --- a/test/parallel/test-http-conn-reset.js +++ b/test/parallel/test-http-conn-reset.js @@ -23,7 +23,7 @@ function onListen() { assert.ok(false, 'this should never run'); }); req.on('error', common.mustCall(function(err) { - assert.equal(err.code, 'ECONNRESET'); + assert.strictEqual(err.code, 'ECONNRESET'); })); req.end(); } diff --git a/test/parallel/test-http-connect-req-res.js b/test/parallel/test-http-connect-req-res.js index 0b1ca4630a562e..45881f0d7d7395 100644 --- a/test/parallel/test-http-connect-req-res.js +++ b/test/parallel/test-http-connect-req-res.js @@ -5,8 +5,8 @@ const http = require('http'); const server = http.createServer(common.fail); server.on('connect', common.mustCall(function(req, socket, firstBodyChunk) { - assert.equal(req.method, 'CONNECT'); - assert.equal(req.url, 'example.com:443'); + assert.strictEqual(req.method, 'CONNECT'); + assert.strictEqual(req.url, 'example.com:443'); console.error('Server got CONNECT request'); // It is legal for the server to send some data intended for the client @@ -46,19 +46,19 @@ server.listen(0, common.mustCall(function() { // Make sure this socket has detached. assert(!socket.ondata); assert(!socket.onend); - assert.equal(socket.listeners('connect').length, 0); - assert.equal(socket.listeners('data').length, 0); + assert.strictEqual(socket.listeners('connect').length, 0); + assert.strictEqual(socket.listeners('data').length, 0); let data = firstBodyChunk.toString(); // test that the firstBodyChunk was not parsed as HTTP - assert.equal(data, 'Head'); + assert.strictEqual(data, 'Head'); socket.on('data', function(buf) { data += buf.toString(); }); socket.on('end', function() { - assert.equal(data, 'HeadRequestEnd'); + assert.strictEqual(data, 'HeadRequestEnd'); server.close(); }); socket.end('End'); diff --git a/test/parallel/test-http-createConnection.js b/test/parallel/test-http-createConnection.js index 69592eb09ff487..279d7022795318 100644 --- a/test/parallel/test-http-createConnection.js +++ b/test/parallel/test-http-createConnection.js @@ -23,7 +23,7 @@ const server = http.createServer(common.mustCall(function(req, res) { http.get({ createConnection: fn }, function(res) { common.fail('Unexpected response callback'); }).on('error', common.mustCall(function(err) { - assert.equal(err.message, 'Could not create socket'); + assert.strictEqual(err.message, 'Could not create socket'); server.close(); })); }); diff --git a/test/parallel/test-http-default-encoding.js b/test/parallel/test-http-default-encoding.js index 46327085184069..2c41328749f027 100644 --- a/test/parallel/test-http-default-encoding.js +++ b/test/parallel/test-http-default-encoding.js @@ -33,5 +33,5 @@ server.listen(0, function() { }); process.on('exit', function() { - assert.equal(expected, result); + assert.strictEqual(expected, result); }); diff --git a/test/parallel/test-http-default-port.js b/test/parallel/test-http-default-port.js index dbe1a44c6a2c1b..c939282a43af3e 100644 --- a/test/parallel/test-http-default-port.js +++ b/test/parallel/test-http-default-port.js @@ -29,8 +29,8 @@ process.on('exit', function() { }); http.createServer(function(req, res) { - assert.equal(req.headers.host, hostExpect); - assert.equal(req.headers['x-port'], this.address().port); + assert.strictEqual(req.headers.host, hostExpect); + assert.strictEqual(req.headers['x-port'], this.address().port.toString()); res.writeHead(200); res.end('ok'); this.close(); @@ -49,8 +49,8 @@ http.createServer(function(req, res) { if (common.hasCrypto) { https.createServer(options, function(req, res) { - assert.equal(req.headers.host, hostExpect); - assert.equal(req.headers['x-port'], this.address().port); + assert.strictEqual(req.headers.host, hostExpect); + assert.strictEqual(req.headers['x-port'], this.address().port.toString()); res.writeHead(200); res.end('ok'); this.close(); diff --git a/test/parallel/test-http-destroyed-socket-write2.js b/test/parallel/test-http-destroyed-socket-write2.js index 01023a088576ef..59e0eeecfc8a7a 100644 --- a/test/parallel/test-http-destroyed-socket-write2.js +++ b/test/parallel/test-http-destroyed-socket-write2.js @@ -47,8 +47,8 @@ server.listen(0, function() { break; } - assert.equal(req.output.length, 0); - assert.equal(req.outputEncodings.length, 0); + assert.strictEqual(req.output.length, 0); + assert.strictEqual(req.outputEncodings.length, 0); server.close(); })); diff --git a/test/parallel/test-http-double-content-length.js b/test/parallel/test-http-double-content-length.js index f6c13becfd83dd..fdc79fb74ec5c2 100644 --- a/test/parallel/test-http-double-content-length.js +++ b/test/parallel/test-http-double-content-length.js @@ -13,7 +13,7 @@ const server = http.createServer((req, res) => { }); server.on('clientError', common.mustCall((err, socket) => { assert(/^Parse Error/.test(err.message)); - assert.equal(err.code, 'HPE_UNEXPECTED_CONTENT_LENGTH'); + assert.strictEqual(err.code, 'HPE_UNEXPECTED_CONTENT_LENGTH'); socket.destroy(); })); diff --git a/test/parallel/test-http-expect-continue.js b/test/parallel/test-http-expect-continue.js index 0cf90e3b115e60..01f285d29e54fb 100644 --- a/test/parallel/test-http-expect-continue.js +++ b/test/parallel/test-http-expect-continue.js @@ -10,7 +10,8 @@ let sent_continue = false; let got_continue = false; function handler(req, res) { - assert.equal(sent_continue, true, 'Full response sent before 100 Continue'); + assert.strictEqual(sent_continue, true, 'Full response sent before ' + + '100 Continue'); console.error('Server sending full response...'); res.writeHead(200, { 'Content-Type': 'text/plain', @@ -47,15 +48,15 @@ server.on('listening', function() { req.end(test_req_body); }); req.on('response', function(res) { - assert.equal(got_continue, true, - 'Full response received before 100 Continue'); - assert.equal(200, res.statusCode, - 'Final status code was ' + res.statusCode + ', not 200.'); + assert.strictEqual(got_continue, true, + 'Full response received before 100 Continue'); + assert.strictEqual(200, res.statusCode, 'Final status code was ' + + res.statusCode + ', not 200.'); res.setEncoding('utf8'); res.on('data', function(chunk) { body += chunk; }); res.on('end', function() { console.error('Got full response.'); - assert.equal(body, test_res_body, 'Response body doesn\'t match.'); + assert.strictEqual(body, test_res_body, 'Response body doesn\'t match.'); assert.ok('abcd' in res.headers, 'Response headers missing.'); outstanding_reqs--; if (outstanding_reqs === 0) { diff --git a/test/parallel/test-http-expect-handling.js b/test/parallel/test-http-expect-handling.js index f1f12847315a22..fed715bc2ace7d 100644 --- a/test/parallel/test-http-expect-handling.js +++ b/test/parallel/test-http-expect-handling.js @@ -37,8 +37,8 @@ function nextTest() { http.get(options, function(response) { console.log('client: expected status: ' + test); console.log('client: statusCode: ' + response.statusCode); - assert.equal(response.statusCode, test); - assert.equal(response.statusMessage, 'Expectation Failed'); + assert.strictEqual(response.statusCode, test); + assert.strictEqual(response.statusMessage, 'Expectation Failed'); response.on('end', function() { testsComplete++; @@ -51,5 +51,5 @@ function nextTest() { process.on('exit', function() { - assert.equal(2, testsComplete); + assert.strictEqual(2, testsComplete); }); diff --git a/test/parallel/test-http-extra-response.js b/test/parallel/test-http-extra-response.js index 6ebecaad1300de..5e994134c2e2ad 100644 --- a/test/parallel/test-http-extra-response.js +++ b/test/parallel/test-http-extra-response.js @@ -36,7 +36,7 @@ const server = net.createServer(function(socket) { }); socket.on('error', function(err) { - assert.equal(err.code, 'ECONNRESET'); + assert.strictEqual(err.code, 'ECONNRESET'); }); }); @@ -53,7 +53,7 @@ server.listen(0, common.mustCall(function() { res.on('end', common.mustCall(function() { console.log('Response ended, read ' + buffer.length + ' bytes'); - assert.equal(body, buffer); + assert.strictEqual(body, buffer); server.close(); })); })); diff --git a/test/parallel/test-http-flush-headers.js b/test/parallel/test-http-flush-headers.js index c2b382188a14c1..8ca5e92e5e02bc 100644 --- a/test/parallel/test-http-flush-headers.js +++ b/test/parallel/test-http-flush-headers.js @@ -5,7 +5,7 @@ const http = require('http'); const server = http.createServer(); server.on('request', function(req, res) { - assert.equal(req.headers['foo'], 'bar'); + assert.strictEqual(req.headers['foo'], 'bar'); res.end('ok'); server.close(); }); diff --git a/test/parallel/test-http-flush-response-headers.js b/test/parallel/test-http-flush-response-headers.js index ea7d2d97b4dc7a..bfc43a602b7018 100644 --- a/test/parallel/test-http-flush-response-headers.js +++ b/test/parallel/test-http-flush-response-headers.js @@ -20,7 +20,7 @@ server.listen(0, common.localhostIPv4, function() { req.end(); function onResponse(res) { - assert.equal(res.headers['foo'], 'bar'); + assert.strictEqual(res.headers['foo'], 'bar'); res.destroy(); server.close(); } diff --git a/test/parallel/test-http-full-response.js b/test/parallel/test-http-full-response.js index c834c6e6545320..881734ceb1af6f 100644 --- a/test/parallel/test-http-full-response.js +++ b/test/parallel/test-http-full-response.js @@ -38,8 +38,8 @@ function runAb(opts, callback) { m = /HTML transferred:\s*(\d+) bytes/mi.exec(stdout); const htmlTransfered = parseInt(m[1]); - assert.equal(bodyLength, documentLength); - assert.equal(completeRequests * documentLength, htmlTransfered); + assert.strictEqual(bodyLength, documentLength); + assert.strictEqual(completeRequests * documentLength, htmlTransfered); if (callback) callback(); }); diff --git a/test/parallel/test-http-get-pipeline-problem.js b/test/parallel/test-http-get-pipeline-problem.js index 15c96a9a4e12ea..56bfb33456dff7 100644 --- a/test/parallel/test-http-get-pipeline-problem.js +++ b/test/parallel/test-http-get-pipeline-problem.js @@ -74,8 +74,8 @@ function checkFiles() { const fn = i + '.jpg'; assert.ok(files.indexOf(fn) >= 0, "couldn't find '" + fn + "'"); const stat = fs.statSync(common.tmpDir + '/' + fn); - assert.equal(image.length, stat.size, - "size doesn't match on '" + fn + + assert.strictEqual(image.length, stat.size, + "size doesn't match on '" + fn + "'. Got " + stat.size + ' bytes'); } @@ -84,7 +84,7 @@ function checkFiles() { process.on('exit', function() { - assert.equal(total, requests); - assert.equal(total, responses); + assert.strictEqual(total, requests); + assert.strictEqual(total, responses); assert.ok(checkedFiles); }); diff --git a/test/parallel/test-http-header-read.js b/test/parallel/test-http-header-read.js index 3d9e756d505238..5465fd30f272be 100644 --- a/test/parallel/test-http-header-read.js +++ b/test/parallel/test-http-header-read.js @@ -18,7 +18,7 @@ const s = http.createServer(function(req, res) { // and does not throw an exception (Issue 752) assert.doesNotThrow( function() { - assert.equal(plain, res.getHeader(contentType)); + assert.strictEqual(plain, res.getHeader(contentType)); } ); }); diff --git a/test/parallel/test-http-host-headers.js b/test/parallel/test-http-host-headers.js index b7a916816ffe1d..79a2833f7df148 100644 --- a/test/parallel/test-http-host-headers.js +++ b/test/parallel/test-http-host-headers.js @@ -6,10 +6,10 @@ const httpServer = http.createServer(reqHandler); function reqHandler(req, res) { if (req.url === '/setHostFalse5') { - assert.equal(req.headers.host, undefined); + assert.strictEqual(req.headers.host, undefined); } else { - assert.equal(req.headers.host, `localhost:${this.address().port}`, - 'Wrong host header for req[' + req.url + ']: ' + + assert.strictEqual(req.headers.host, `localhost:${this.address().port}`, + 'Wrong host header for req[' + req.url + ']: ' + req.headers.host); } res.writeHead(200, {}); diff --git a/test/parallel/test-http-keep-alive-close-on-header.js b/test/parallel/test-http-keep-alive-close-on-header.js index 15d5d62d429658..b36fb2e8db9a5a 100644 --- a/test/parallel/test-http-keep-alive-close-on-header.js +++ b/test/parallel/test-http-keep-alive-close-on-header.js @@ -25,7 +25,7 @@ server.listen(0, function() { port: this.address().port, agent: agent }, function(res) { - assert.equal(1, agent.sockets[name].length); + assert.strictEqual(1, agent.sockets[name].length); res.resume(); }); request.on('socket', function(s) { @@ -42,7 +42,7 @@ server.listen(0, function() { port: this.address().port, agent: agent }, function(res) { - assert.equal(1, agent.sockets[name].length); + assert.strictEqual(1, agent.sockets[name].length); res.resume(); }); request.on('socket', function(s) { @@ -59,7 +59,7 @@ server.listen(0, function() { agent: agent }, function(response) { response.on('end', function() { - assert.equal(1, agent.sockets[name].length); + assert.strictEqual(1, agent.sockets[name].length); server.close(); }); response.resume(); @@ -73,5 +73,5 @@ server.listen(0, function() { }); process.on('exit', function() { - assert.equal(3, connectCount); + assert.strictEqual(3, connectCount); }); diff --git a/test/parallel/test-http-keepalive-client.js b/test/parallel/test-http-keepalive-client.js index 1fcf12b0dbcddf..daa55d64a97c92 100644 --- a/test/parallel/test-http-keepalive-client.js +++ b/test/parallel/test-http-keepalive-client.js @@ -9,7 +9,7 @@ let serverSocket = null; const server = http.createServer(function(req, res) { // They should all come in on the same server socket. if (serverSocket) { - assert.equal(req.socket, serverSocket); + assert.strictEqual(req.socket, serverSocket); } else { serverSocket = req.socket; } @@ -45,7 +45,7 @@ function makeRequest(n) { req.on('socket', function(sock) { if (clientSocket) { - assert.equal(sock, clientSocket); + assert.strictEqual(sock, clientSocket); } else { clientSocket = sock; } @@ -58,7 +58,7 @@ function makeRequest(n) { data += c; }); res.on('end', function() { - assert.equal(data, '/' + n); + assert.strictEqual(data, '/' + n); setTimeout(function() { actualRequests++; makeRequest(n - 1); @@ -68,6 +68,6 @@ function makeRequest(n) { } process.on('exit', function() { - assert.equal(actualRequests, expectRequests); + assert.strictEqual(actualRequests, expectRequests); console.log('ok'); }); diff --git a/test/parallel/test-http-keepalive-maxsockets.js b/test/parallel/test-http-keepalive-maxsockets.js index 14e9e88ef7fd09..0d684a43f778f9 100644 --- a/test/parallel/test-http-keepalive-maxsockets.js +++ b/test/parallel/test-http-keepalive-maxsockets.js @@ -22,17 +22,17 @@ server.listen(0, function() { let closed = false; makeReqs(10, function(er) { assert.ifError(er); - assert.equal(count(agent.freeSockets), 2); - assert.equal(count(agent.sockets), 0); - assert.equal(serverSockets.length, 5); + assert.strictEqual(count(agent.freeSockets), 2); + assert.strictEqual(count(agent.sockets), 0); + assert.strictEqual(serverSockets.length, 5); // now make 10 more reqs. // should use the 2 free reqs from the pool first. makeReqs(10, function(er) { assert.ifError(er); - assert.equal(count(agent.freeSockets), 2); - assert.equal(count(agent.sockets), 0); - assert.equal(serverSockets.length, 8); + assert.strictEqual(count(agent.freeSockets), 2); + assert.strictEqual(count(agent.sockets), 0); + assert.strictEqual(serverSockets.length, 8); agent.destroy(); server.close(function() { @@ -72,7 +72,7 @@ server.listen(0, function() { data += c; }); res.on('end', function() { - assert.equal(data, '/' + i); + assert.strictEqual(data, '/' + i); cb(); }); }).end(); diff --git a/test/parallel/test-http-keepalive-request.js b/test/parallel/test-http-keepalive-request.js index b9e9f1e9798cfc..cce6dc1786c8ea 100644 --- a/test/parallel/test-http-keepalive-request.js +++ b/test/parallel/test-http-keepalive-request.js @@ -9,7 +9,7 @@ let serverSocket = null; const server = http.createServer(function(req, res) { // They should all come in on the same server socket. if (serverSocket) { - assert.equal(req.socket, serverSocket); + assert.strictEqual(req.socket, serverSocket); } else { serverSocket = req.socket; } @@ -45,7 +45,7 @@ function makeRequest(n) { req.on('socket', function(sock) { if (clientSocket) { - assert.equal(sock, clientSocket); + assert.strictEqual(sock, clientSocket); } else { clientSocket = sock; } @@ -58,7 +58,7 @@ function makeRequest(n) { data += c; }); res.on('end', function() { - assert.equal(data, '/' + n); + assert.strictEqual(data, '/' + n); setTimeout(function() { actualRequests++; makeRequest(n - 1); @@ -68,6 +68,6 @@ function makeRequest(n) { } process.on('exit', function() { - assert.equal(actualRequests, expectRequests); + assert.strictEqual(actualRequests, expectRequests); console.log('ok'); }); diff --git a/test/parallel/test-http-legacy.js b/test/parallel/test-http-legacy.js index bf2f83d71bbc2a..e2fed3135d40f1 100644 --- a/test/parallel/test-http-legacy.js +++ b/test/parallel/test-http-legacy.js @@ -10,20 +10,20 @@ let body1 = ''; const server = http.createServer(function(req, res) { if (responses_sent === 0) { - assert.equal('GET', req.method); - assert.equal('/hello', url.parse(req.url).pathname); + assert.strictEqual('GET', req.method); + assert.strictEqual('/hello', url.parse(req.url).pathname); console.dir(req.headers); - assert.equal(true, 'accept' in req.headers); - assert.equal('*/*', req.headers['accept']); + assert.strictEqual(true, 'accept' in req.headers); + assert.strictEqual('*/*', req.headers['accept']); - assert.equal(true, 'foo' in req.headers); - assert.equal('bar', req.headers['foo']); + assert.strictEqual(true, 'foo' in req.headers); + assert.strictEqual('bar', req.headers['foo']); } if (responses_sent === 1) { - assert.equal('POST', req.method); - assert.equal('/world', url.parse(req.url).pathname); + assert.strictEqual('POST', req.method); + assert.strictEqual('/world', url.parse(req.url).pathname); this.close(); } @@ -43,7 +43,7 @@ server.listen(0, common.mustCall(function() { req.end(); }, 100); req.on('response', common.mustCall(function(res) { - assert.equal(200, res.statusCode); + assert.strictEqual(200, res.statusCode); res.setEncoding('utf8'); res.on('data', function(chunk) { body0 += chunk; }); console.error('Got /hello response'); @@ -53,7 +53,7 @@ server.listen(0, common.mustCall(function() { const req = client.request('POST', '/world'); req.end(); req.on('response', common.mustCall(function(res) { - assert.equal(200, res.statusCode); + assert.strictEqual(200, res.statusCode); res.setEncoding('utf8'); res.on('data', function(chunk) { body1 += chunk; }); console.error('Got /world response'); @@ -63,8 +63,8 @@ server.listen(0, common.mustCall(function() { process.on('exit', function() { console.error('responses_sent: ' + responses_sent); - assert.equal(2, responses_sent); + assert.strictEqual(2, responses_sent); - assert.equal('The path was /hello', body0); - assert.equal('The path was /world', body1); + assert.strictEqual('The path was /hello', body0); + assert.strictEqual('The path was /world', body1); }); diff --git a/test/parallel/test-http-localaddress.js b/test/parallel/test-http-localaddress.js index e8df6888866f9c..d48a4ec8f5b0ee 100644 --- a/test/parallel/test-http-localaddress.js +++ b/test/parallel/test-http-localaddress.js @@ -10,7 +10,7 @@ if (!common.hasMultiLocalhost()) { const server = http.createServer(function(req, res) { console.log('Connect from: ' + req.connection.remoteAddress); - assert.equal('127.0.0.2', req.connection.remoteAddress); + assert.strictEqual('127.0.0.2', req.connection.remoteAddress); req.on('end', function() { res.writeHead(200, { 'Content-Type': 'text/plain' }); diff --git a/test/parallel/test-http-malformed-request.js b/test/parallel/test-http-malformed-request.js index a36c9fdbe29451..93aff802c7afbd 100644 --- a/test/parallel/test-http-malformed-request.js +++ b/test/parallel/test-http-malformed-request.js @@ -31,5 +31,5 @@ server.on('listening', function() { }); process.on('exit', function() { - assert.equal(nrequests_expected, nrequests_completed); + assert.strictEqual(nrequests_expected, nrequests_completed); }); diff --git a/test/parallel/test-http-max-headers-count.js b/test/parallel/test-http-max-headers-count.js index 018ed33c1b9e49..fd92637f7ac10b 100644 --- a/test/parallel/test-http-max-headers-count.js +++ b/test/parallel/test-http-max-headers-count.js @@ -21,7 +21,7 @@ let max = maxAndExpected[requests][0]; let expected = maxAndExpected[requests][1]; const server = http.createServer(function(req, res) { - assert.equal(Object.keys(req.headers).length, expected); + assert.strictEqual(Object.keys(req.headers).length, expected); if (++requests < maxAndExpected.length) { max = maxAndExpected[requests][0]; expected = maxAndExpected[requests][1]; @@ -47,7 +47,7 @@ server.listen(0, function() { port: server.address().port, headers: headers }, function(res) { - assert.equal(Object.keys(res.headers).length, expected); + assert.strictEqual(Object.keys(res.headers).length, expected); res.on('end', function() { if (++responses < maxAndExpected.length) { doRequest(); @@ -63,6 +63,6 @@ server.listen(0, function() { }); process.on('exit', function() { - assert.equal(requests, maxAndExpected.length); - assert.equal(responses, maxAndExpected.length); + assert.strictEqual(requests, maxAndExpected.length); + assert.strictEqual(responses, maxAndExpected.length); }); diff --git a/test/parallel/test-http-multi-line-headers.js b/test/parallel/test-http-multi-line-headers.js index 2096f533a196d1..f7998c254870d5 100644 --- a/test/parallel/test-http-multi-line-headers.js +++ b/test/parallel/test-http-multi-line-headers.js @@ -27,8 +27,8 @@ server.listen(0, common.mustCall(function() { host: '127.0.0.1', port: this.address().port }, common.mustCall(function(res) { - assert.equal(res.headers['content-type'], - 'text/plain; x-unix-mode=0600; name="hello.txt"'); + assert.strictEqual(res.headers['content-type'], + 'text/plain; x-unix-mode=0600; name="hello.txt"'); res.destroy(); })); })); diff --git a/test/parallel/test-http-mutable-headers.js b/test/parallel/test-http-mutable-headers.js index fcff395cffe9bb..8f9d597efbec92 100644 --- a/test/parallel/test-http-mutable-headers.js +++ b/test/parallel/test-http-mutable-headers.js @@ -34,20 +34,20 @@ const s = http.createServer(function(req, res) { const val1 = res.getHeader('x-test-header'); const val2 = res.getHeader('x-test-header2'); - assert.equal(val1, 'testing'); - assert.equal(val2, 'testing'); + assert.strictEqual(val1, 'testing'); + assert.strictEqual(val2, 'testing'); res.removeHeader('x-test-header2'); break; case 'contentLength': res.setHeader('content-length', content.length); - assert.equal(content.length, res.getHeader('Content-Length')); + assert.strictEqual(content.length, res.getHeader('Content-Length')); break; case 'transferEncoding': res.setHeader('transfer-encoding', 'chunked'); - assert.equal(res.getHeader('Transfer-Encoding'), 'chunked'); + assert.strictEqual(res.getHeader('Transfer-Encoding'), 'chunked'); break; case 'writeHead': @@ -79,33 +79,35 @@ function nextTest() { switch (test) { case 'headers': - assert.equal(response.statusCode, 201); - assert.equal(response.headers['x-test-header'], - 'testing'); - assert.equal(response.headers['x-test-array-header'], - [1, 2, 3].join(', ')); + assert.strictEqual(response.statusCode, 201); + assert.strictEqual(response.headers['x-test-header'], + 'testing'); + assert.strictEqual(response.headers['x-test-array-header'], + [1, 2, 3].join(', ')); assert.deepStrictEqual(cookies, response.headers['set-cookie']); - assert.equal(response.headers['x-test-header2'] !== undefined, false); + assert.strictEqual(response.headers['x-test-header2'] !== undefined, + false); // Make the next request test = 'contentLength'; console.log('foobar'); break; case 'contentLength': - assert.equal(response.headers['content-length'], content.length); + assert.strictEqual(response.headers['content-length'], + content.length.toString()); test = 'transferEncoding'; break; case 'transferEncoding': - assert.equal(response.headers['transfer-encoding'], 'chunked'); + assert.strictEqual(response.headers['transfer-encoding'], 'chunked'); test = 'writeHead'; break; case 'writeHead': - assert.equal(response.headers['x-foo'], 'bar'); - assert.equal(response.headers['x-bar'], 'baz'); - assert.equal(200, response.statusCode); + assert.strictEqual(response.headers['x-foo'], 'bar'); + assert.strictEqual(response.headers['x-bar'], 'baz'); + assert.strictEqual(200, response.statusCode); test = 'end'; break; @@ -119,7 +121,7 @@ function nextTest() { }); response.on('end', function() { - assert.equal(content, bufferedResponse); + assert.strictEqual(content, bufferedResponse); testsComplete++; nextTest(); }); @@ -128,5 +130,5 @@ function nextTest() { process.on('exit', function() { - assert.equal(4, testsComplete); + assert.strictEqual(4, testsComplete); }); diff --git a/test/parallel/test-http-parser-bad-ref.js b/test/parallel/test-http-parser-bad-ref.js index 69682128fadbdf..97b4685e18382b 100644 --- a/test/parallel/test-http-parser-bad-ref.js +++ b/test/parallel/test-http-parser-bad-ref.js @@ -83,7 +83,7 @@ demoBug('POST /1/22 HTTP/1.1\r\n' + /* eslint-enable align-function-arguments */ process.on('exit', function() { - assert.equal(2, headersComplete); - assert.equal(2, messagesComplete); + assert.strictEqual(2, headersComplete); + assert.strictEqual(2, messagesComplete); console.log('done!'); }); diff --git a/test/parallel/test-http-parser-free.js b/test/parallel/test-http-parser-free.js index 80cc3cc64ee5b3..aff0fa6198ef44 100644 --- a/test/parallel/test-http-parser-free.js +++ b/test/parallel/test-http-parser-free.js @@ -31,5 +31,5 @@ server.listen(0, function() { }); process.on('exit', function() { - assert.equal(responses, N); + assert.strictEqual(responses, N); }); diff --git a/test/parallel/test-http-parser.js b/test/parallel/test-http-parser.js index e1215fbd13ae40..de7302e60d91ba 100644 --- a/test/parallel/test-http-parser.js +++ b/test/parallel/test-http-parser.js @@ -51,7 +51,7 @@ function mustCall(f, times) { process.setMaxListeners(256); process.on('exit', function() { - assert.equal(actual, times || 1); + assert.strictEqual(actual, times || 1); }); return function() { @@ -64,7 +64,7 @@ function mustCall(f, times) { function expectBody(expected) { return mustCall(function(buf, start, len) { const body = '' + buf.slice(start, start + len); - assert.equal(body, expected); + assert.strictEqual(body, expected); }); } @@ -535,10 +535,10 @@ function expectBody(expected) { const onHeadersComplete1 = function(versionMajor, versionMinor, headers, method, url, statusCode, statusMessage, upgrade, shouldKeepAlive) { - assert.equal(method, methods.indexOf('PUT')); - assert.equal(url, '/this'); - assert.equal(versionMajor, 1); - assert.equal(versionMinor, 1); + assert.strictEqual(method, methods.indexOf('PUT')); + assert.strictEqual(url, '/this'); + assert.strictEqual(versionMajor, 1); + assert.strictEqual(versionMinor, 1); assert.deepStrictEqual( headers, ['Content-Type', 'text/plain', 'Transfer-Encoding', 'chunked']); diff --git a/test/parallel/test-http-pause.js b/test/parallel/test-http-pause.js index 8bb8dd4b5da25c..440cab413c50a5 100644 --- a/test/parallel/test-http-pause.js +++ b/test/parallel/test-http-pause.js @@ -50,6 +50,6 @@ server.listen(0, function() { }); process.on('exit', function() { - assert.equal(expectedServer, resultServer); - assert.equal(expectedClient, resultClient); + assert.strictEqual(expectedServer, resultServer); + assert.strictEqual(expectedClient, resultClient); }); diff --git a/test/parallel/test-http-pipeline-regr-2639.js b/test/parallel/test-http-pipeline-regr-2639.js index 7933e419d324f7..133e4126683d9b 100644 --- a/test/parallel/test-http-pipeline-regr-2639.js +++ b/test/parallel/test-http-pipeline-regr-2639.js @@ -29,5 +29,5 @@ const server = http.createServer(function(req, res) { }); process.on('exit', function() { - assert.equal(received, COUNT); + assert.strictEqual(received, COUNT); }); diff --git a/test/parallel/test-http-pipeline-regr-3332.js b/test/parallel/test-http-pipeline-regr-3332.js index 3ab9e6104c9848..b34ad499850b70 100644 --- a/test/parallel/test-http-pipeline-regr-3332.js +++ b/test/parallel/test-http-pipeline-regr-3332.js @@ -36,5 +36,5 @@ process.on('exit', function() { // The server should pause connection on pipeline flood, but it shoul still // resume it and finish processing the requests, when its output queue will // be empty again. - assert.equal(received, COUNT); + assert.strictEqual(received, COUNT); }); diff --git a/test/parallel/test-http-proxy.js b/test/parallel/test-http-proxy.js index 8e7fd55a0ed6ea..91dce932dc576b 100644 --- a/test/parallel/test-http-proxy.js +++ b/test/parallel/test-http-proxy.js @@ -29,8 +29,8 @@ const proxy = http.createServer(function(req, res) { console.error('proxy res headers: ' + JSON.stringify(proxy_res.headers)); - assert.equal('world', proxy_res.headers['hello']); - assert.equal('text/plain', proxy_res.headers['content-type']); + assert.strictEqual('world', proxy_res.headers['hello']); + assert.strictEqual('text/plain', proxy_res.headers['content-type']); assert.deepStrictEqual(cookies, proxy_res.headers['set-cookie']); res.writeHead(proxy_res.statusCode, proxy_res.headers); @@ -58,10 +58,10 @@ function startReq() { path: '/test' }, function(res) { console.error('got res'); - assert.equal(200, res.statusCode); + assert.strictEqual(200, res.statusCode); - assert.equal('world', res.headers['hello']); - assert.equal('text/plain', res.headers['content-type']); + assert.strictEqual('world', res.headers['hello']); + assert.strictEqual('text/plain', res.headers['content-type']); assert.deepStrictEqual(cookies, res.headers['set-cookie']); res.setEncoding('utf8'); @@ -82,5 +82,5 @@ console.error('listen backend'); backend.listen(0, startReq); process.on('exit', function() { - assert.equal(body, 'hello world\n'); + assert.strictEqual(body, 'hello world\n'); }); diff --git a/test/parallel/test-http-remove-header-stays-removed.js b/test/parallel/test-http-remove-header-stays-removed.js index 077ff0f5b33f40..c38a042283dbb9 100644 --- a/test/parallel/test-http-remove-header-stays-removed.js +++ b/test/parallel/test-http-remove-header-stays-removed.js @@ -23,13 +23,13 @@ const server = http.createServer(function(request, response) { let response = ''; process.on('exit', function() { - assert.equal('beep boop\n', response); + assert.strictEqual('beep boop\n', response); console.log('ok'); }); server.listen(0, function() { http.get({ port: this.address().port }, function(res) { - assert.equal(200, res.statusCode); + assert.strictEqual(200, res.statusCode); assert.deepStrictEqual(res.headers, { date: 'coffee o clock' }); res.setEncoding('ascii'); diff --git a/test/parallel/test-http-request-dont-override-options.js b/test/parallel/test-http-request-dont-override-options.js index 04235fd0e42b4e..33ed2ed6c0070d 100644 --- a/test/parallel/test-http-request-dont-override-options.js +++ b/test/parallel/test-http-request-dont-override-options.js @@ -33,7 +33,7 @@ http.createServer(function(req, res) { }).end(); process.on('exit', function() { - assert.equal(requests, 1); + assert.strictEqual(requests, 1); assert.strictEqual(options.host, undefined); assert.strictEqual(options.hostname, common.localhostIPv4); diff --git a/test/parallel/test-http-res-write-after-end.js b/test/parallel/test-http-res-write-after-end.js index 2ee0e4e29d95e4..45db9fe13f7655 100644 --- a/test/parallel/test-http-res-write-after-end.js +++ b/test/parallel/test-http-res-write-after-end.js @@ -12,7 +12,7 @@ const server = http.Server(common.mustCall(function(req, res) { res.end(); const r = res.write('This should raise an error.'); - assert.equal(r, true, 'write after end should return true'); + assert.strictEqual(r, true, 'write after end should return true'); })); server.listen(0, function() { diff --git a/test/parallel/test-http-response-multi-content-length.js b/test/parallel/test-http-response-multi-content-length.js index 7cd802a74aa80c..f3dce208756f74 100644 --- a/test/parallel/test-http-response-multi-content-length.js +++ b/test/parallel/test-http-response-multi-content-length.js @@ -39,7 +39,7 @@ server.listen(0, common.mustCall(() => { } ).on('error', common.mustCall((err) => { assert(/^Parse Error/.test(err.message)); - assert.equal(err.code, 'HPE_UNEXPECTED_CONTENT_LENGTH'); + assert.strictEqual(err.code, 'HPE_UNEXPECTED_CONTENT_LENGTH'); count++; if (count === MAX_COUNT) server.close(); @@ -48,5 +48,5 @@ server.listen(0, common.mustCall(() => { })); process.on('exit', () => { - assert.equal(count, MAX_COUNT); + assert.strictEqual(count, MAX_COUNT); }); diff --git a/test/parallel/test-http-response-multiheaders.js b/test/parallel/test-http-response-multiheaders.js index 8f48dc2377f3c3..5739dac31d690b 100644 --- a/test/parallel/test-http-response-multiheaders.js +++ b/test/parallel/test-http-response-multiheaders.js @@ -60,9 +60,9 @@ server.listen(0, common.mustCall(function() { common.mustCall(function(res) { if (++count === 2) server.close(); for (const name of norepeat) { - assert.equal(res.headers[name], 'A'); + assert.strictEqual(res.headers[name], 'A'); } - assert.equal(res.headers['x-a'], 'A, B'); + assert.strictEqual(res.headers['x-a'], 'A, B'); }) ); } diff --git a/test/parallel/test-http-response-no-headers.js b/test/parallel/test-http-response-no-headers.js index 3f44b4ef5fde0b..e10571af4ccf25 100644 --- a/test/parallel/test-http-response-no-headers.js +++ b/test/parallel/test-http-response-no-headers.js @@ -32,7 +32,7 @@ function test(httpVersion, callback) { }); res.on('end', common.mustCall(function() { - assert.equal(body, expected[httpVersion]); + assert.strictEqual(body, expected[httpVersion]); server.close(); if (callback) process.nextTick(callback); })); diff --git a/test/parallel/test-http-response-readable.js b/test/parallel/test-http-response-readable.js index 07c0a40e4bf1a8..a4906643d3d35b 100644 --- a/test/parallel/test-http-response-readable.js +++ b/test/parallel/test-http-response-readable.js @@ -10,9 +10,10 @@ const testServer = new http.Server(function(req, res) { testServer.listen(0, function() { http.get({ port: this.address().port }, function(res) { - assert.equal(res.readable, true, 'res.readable initially true'); + assert.strictEqual(res.readable, true, 'res.readable initially true'); res.on('end', function() { - assert.equal(res.readable, false, 'res.readable set to false after end'); + assert.strictEqual(res.readable, false, + 'res.readable set to false after end'); testServer.close(); }); res.resume(); diff --git a/test/parallel/test-http-response-status-message.js b/test/parallel/test-http-response-status-message.js index d17dfb24c6b4c8..95859634ac394a 100644 --- a/test/parallel/test-http-response-status-message.js +++ b/test/parallel/test-http-response-status-message.js @@ -47,7 +47,7 @@ const runTest = function(testCaseIndex) { }, function(response) { console.log('client: expected status message: ' + testCase.statusMessage); console.log('client: actual status message: ' + response.statusMessage); - assert.equal(testCase.statusMessage, response.statusMessage); + assert.strictEqual(testCase.statusMessage, response.statusMessage); response.on('end', function() { testsComplete++; @@ -66,5 +66,5 @@ const runTest = function(testCaseIndex) { server.listen(0, function() { runTest(0); }); process.on('exit', function() { - assert.equal(testCases.length, testsComplete); + assert.strictEqual(testCases.length, testsComplete); }); diff --git a/test/parallel/test-http-server-client-error.js b/test/parallel/test-http-server-client-error.js index 260963dc24daaa..88c224f8374145 100644 --- a/test/parallel/test-http-server-client-error.js +++ b/test/parallel/test-http-server-client-error.js @@ -26,13 +26,13 @@ server.listen(0, function() { chunks += chunk; }); client.once('end', function() { - assert.equal(chunks, 'HTTP/1.1 400 Bad Request\r\n\r\n'); + assert.strictEqual(chunks, 'HTTP/1.1 400 Bad Request\r\n\r\n'); }); } // Normal request http.get({ port: this.address().port, path: '/' }, function(res) { - assert.equal(res.statusCode, 200); + assert.strictEqual(res.statusCode, 200); res.resume(); res.once('end', next); }); diff --git a/test/parallel/test-http-server-multiheaders.js b/test/parallel/test-http-server-multiheaders.js index 189ab0657bacb0..a89d45fd6c6195 100644 --- a/test/parallel/test-http-server-multiheaders.js +++ b/test/parallel/test-http-server-multiheaders.js @@ -8,15 +8,16 @@ const assert = require('assert'); const http = require('http'); const srv = http.createServer(function(req, res) { - assert.equal(req.headers.accept, 'abc, def, ghijklmnopqrst'); - assert.equal(req.headers.host, 'foo'); - assert.equal(req.headers['www-authenticate'], 'foo, bar, baz'); - assert.equal(req.headers['proxy-authenticate'], 'foo, bar, baz'); - assert.equal(req.headers['x-foo'], 'bingo'); - assert.equal(req.headers['x-bar'], 'banjo, bango'); - assert.equal(req.headers['sec-websocket-protocol'], 'chat, share'); - assert.equal(req.headers['sec-websocket-extensions'], 'foo; 1, bar; 2, baz'); - assert.equal(req.headers['constructor'], 'foo, bar, baz'); + assert.strictEqual(req.headers.accept, 'abc, def, ghijklmnopqrst'); + assert.strictEqual(req.headers.host, 'foo'); + assert.strictEqual(req.headers['www-authenticate'], 'foo, bar, baz'); + assert.strictEqual(req.headers['proxy-authenticate'], 'foo, bar, baz'); + assert.strictEqual(req.headers['x-foo'], 'bingo'); + assert.strictEqual(req.headers['x-bar'], 'banjo, bango'); + assert.strictEqual(req.headers['sec-websocket-protocol'], 'chat, share'); + assert.strictEqual(req.headers['sec-websocket-extensions'], + 'foo; 1, bar; 2, baz'); + assert.strictEqual(req.headers['constructor'], 'foo, bar, baz'); res.writeHead(200, {'Content-Type': 'text/plain'}); res.end('EOF'); diff --git a/test/parallel/test-http-server-multiheaders2.js b/test/parallel/test-http-server-multiheaders2.js index 82cc9960329a11..53e68e6f0d3e74 100644 --- a/test/parallel/test-http-server-multiheaders2.js +++ b/test/parallel/test-http-server-multiheaders2.js @@ -50,12 +50,12 @@ const multipleForbidden = [ const srv = http.createServer(function(req, res) { multipleForbidden.forEach(function(header) { - assert.equal(req.headers[header.toLowerCase()], - 'foo', 'header parsed incorrectly: ' + header); + assert.strictEqual(req.headers[header.toLowerCase()], + 'foo', 'header parsed incorrectly: ' + header); }); multipleAllowed.forEach(function(header) { - assert.equal(req.headers[header.toLowerCase()], - 'foo, bar', 'header parsed incorrectly: ' + header); + assert.strictEqual(req.headers[header.toLowerCase()], + 'foo, bar', 'header parsed incorrectly: ' + header); }); res.writeHead(200, {'Content-Type': 'text/plain'}); diff --git a/test/parallel/test-http-server-reject-chunked-with-content-length.js b/test/parallel/test-http-server-reject-chunked-with-content-length.js index d8697cd38cde72..b158fda75c5846 100644 --- a/test/parallel/test-http-server-reject-chunked-with-content-length.js +++ b/test/parallel/test-http-server-reject-chunked-with-content-length.js @@ -14,7 +14,7 @@ const server = http.createServer((req, res) => { }); server.on('clientError', common.mustCall((err) => { assert(/^Parse Error/.test(err.message)); - assert.equal(err.code, 'HPE_UNEXPECTED_CONTENT_LENGTH'); + assert.strictEqual(err.code, 'HPE_UNEXPECTED_CONTENT_LENGTH'); server.close(); })); server.listen(0, () => { diff --git a/test/parallel/test-http-server-reject-cr-no-lf.js b/test/parallel/test-http-server-reject-cr-no-lf.js index 81a7208d982334..73508cf08e9b7a 100644 --- a/test/parallel/test-http-server-reject-cr-no-lf.js +++ b/test/parallel/test-http-server-reject-cr-no-lf.js @@ -16,7 +16,7 @@ const server = http.createServer((req, res) => { }); server.on('clientError', common.mustCall((err) => { assert(/^Parse Error/.test(err.message)); - assert.equal(err.code, 'HPE_LF_EXPECTED'); + assert.strictEqual(err.code, 'HPE_LF_EXPECTED'); server.close(); })); server.listen(0, () => { diff --git a/test/parallel/test-http-server-unconsume.js b/test/parallel/test-http-server-unconsume.js index fca2691aacc25d..9f80e9ea82de48 100644 --- a/test/parallel/test-http-server-unconsume.js +++ b/test/parallel/test-http-server-unconsume.js @@ -26,5 +26,5 @@ const server = http.createServer(function(req, res) { }); process.on('exit', function() { - assert.equal(received, 'hello world'); + assert.strictEqual(received, 'hello world'); }); diff --git a/test/parallel/test-http-set-cookies.js b/test/parallel/test-http-set-cookies.js index cb06352b3ca85d..7be28b04034fb0 100644 --- a/test/parallel/test-http-set-cookies.js +++ b/test/parallel/test-http-set-cookies.js @@ -27,7 +27,7 @@ server.on('listening', function() { // set-cookie headers are always return in an array. // even if there is only one. assert.deepStrictEqual(['A'], res.headers['set-cookie']); - assert.equal('text/plain', res.headers['content-type']); + assert.strictEqual('text/plain', res.headers['content-type']); res.on('data', function(chunk) { console.log(chunk.toString()); @@ -44,7 +44,7 @@ server.on('listening', function() { http.get({ port: this.address().port, path: '/two' }, function(res) { assert.deepStrictEqual(['A', 'B'], res.headers['set-cookie']); - assert.equal('text/plain', res.headers['content-type']); + assert.strictEqual('text/plain', res.headers['content-type']); res.on('data', function(chunk) { console.log(chunk.toString()); @@ -60,5 +60,5 @@ server.on('listening', function() { }); process.on('exit', function() { - assert.equal(2, nresponses); + assert.strictEqual(2, nresponses); }); diff --git a/test/parallel/test-http-set-timeout-server.js b/test/parallel/test-http-set-timeout-server.js index 7a2447763e4cf9..097aeb260bdc5e 100644 --- a/test/parallel/test-http-set-timeout-server.js +++ b/test/parallel/test-http-set-timeout-server.js @@ -118,7 +118,7 @@ test(function serverRequestNotTimeoutAfterEnd(cb) { test(function serverResponseTimeoutWithPipeline(cb) { let caughtTimeout = ''; process.on('exit', function() { - assert.equal(caughtTimeout, '/2'); + assert.strictEqual(caughtTimeout, '/2'); }); const server = http.createServer(function(req, res) { const s = res.setTimeout(50, function() { diff --git a/test/parallel/test-http-should-keep-alive.js b/test/parallel/test-http-should-keep-alive.js index 77a3c3922a20f0..190c8c8d8843ad 100644 --- a/test/parallel/test-http-should-keep-alive.js +++ b/test/parallel/test-http-should-keep-alive.js @@ -30,8 +30,8 @@ const server = net.createServer(function(socket) { }).listen(0, function() { function makeRequest() { const req = http.get({port: server.address().port}, function(res) { - assert.equal(req.shouldKeepAlive, SHOULD_KEEP_ALIVE[responses], - SERVER_RESPONSES[responses] + ' should ' + + assert.strictEqual(req.shouldKeepAlive, SHOULD_KEEP_ALIVE[responses], + SERVER_RESPONSES[responses] + ' should ' + (SHOULD_KEEP_ALIVE[responses] ? '' : 'not ') + 'Keep-Alive'); ++responses; @@ -48,6 +48,6 @@ const server = net.createServer(function(socket) { }); process.on('exit', function() { - assert.equal(requests, SERVER_RESPONSES.length); - assert.equal(responses, SHOULD_KEEP_ALIVE.length); + assert.strictEqual(requests, SERVER_RESPONSES.length); + assert.strictEqual(responses, SHOULD_KEEP_ALIVE.length); }); diff --git a/test/parallel/test-http-status-code.js b/test/parallel/test-http-status-code.js index b5060109bf4985..111b5db16daecb 100644 --- a/test/parallel/test-http-status-code.js +++ b/test/parallel/test-http-status-code.js @@ -14,7 +14,7 @@ const s = http.createServer(function(req, res) { const t = tests[testIdx]; res.writeHead(t, {'Content-Type': 'text/plain'}); console.log('--\nserver: statusCode after writeHead: ' + res.statusCode); - assert.equal(res.statusCode, t); + assert.strictEqual(res.statusCode, t); res.end('hello world\n'); }); @@ -30,7 +30,7 @@ function nextTest() { http.get({ port: s.address().port }, function(response) { console.log('client: expected status: ' + test); console.log('client: statusCode: ' + response.statusCode); - assert.equal(response.statusCode, test); + assert.strictEqual(response.statusCode, test); response.on('end', function() { testsComplete++; testIdx += 1; @@ -42,5 +42,5 @@ function nextTest() { process.on('exit', function() { - assert.equal(5, testsComplete); + assert.strictEqual(5, testsComplete); }); diff --git a/test/parallel/test-http-status-message.js b/test/parallel/test-http-status-message.js index 668b02ee0780b4..54c683212b8ff1 100644 --- a/test/parallel/test-http-status-message.js +++ b/test/parallel/test-http-status-message.js @@ -23,7 +23,7 @@ function test() { }); client.on('end', function() { const head = Buffer.concat(bufs).toString('latin1').split('\r\n')[0]; - assert.equal('HTTP/1.1 200 Custom Message', head); + assert.strictEqual('HTTP/1.1 200 Custom Message', head); console.log('ok'); s.close(); }); diff --git a/test/parallel/test-http-timeout-overflow.js b/test/parallel/test-http-timeout-overflow.js index 39b4550d57e529..755859ddc9992d 100644 --- a/test/parallel/test-http-timeout-overflow.js +++ b/test/parallel/test-http-timeout-overflow.js @@ -37,6 +37,6 @@ server.listen(0, function() { }); process.once('exit', function() { - assert.equal(clientRequests, 1); - assert.equal(serverRequests, 1); + assert.strictEqual(clientRequests, 1); + assert.strictEqual(serverRequests, 1); }); diff --git a/test/parallel/test-http-upgrade-advertise.js b/test/parallel/test-http-upgrade-advertise.js index 3deb71fbea1b75..99a3e8fd353015 100644 --- a/test/parallel/test-http-upgrade-advertise.js +++ b/test/parallel/test-http-upgrade-advertise.js @@ -18,7 +18,7 @@ function fire() { const test = tests.shift(); const done = common.mustCall(function done(result) { - assert.equal(result, test.expected); + assert.strictEqual(result, test.expected); fire(); }); diff --git a/test/parallel/test-http-upgrade-agent.js b/test/parallel/test-http-upgrade-agent.js index a196ba904905a3..e0e1c6d1f3fb6d 100644 --- a/test/parallel/test-http-upgrade-agent.js +++ b/test/parallel/test-http-upgrade-agent.js @@ -47,7 +47,7 @@ srv.listen(0, '127.0.0.1', common.mustCall(function() { }); socket.on('close', common.mustCall(function() { - assert.equal(recvData, 'nurtzo'); + assert.strictEqual(recvData.toString(), 'nurtzo'); })); console.log(res.headers); diff --git a/test/parallel/test-http-upgrade-server.js b/test/parallel/test-http-upgrade-server.js index 6c5a62c2ffcc33..c641f1576e8703 100644 --- a/test/parallel/test-http-upgrade-server.js +++ b/test/parallel/test-http-upgrade-server.js @@ -76,20 +76,20 @@ function test_upgrade_with_listener() { conn.on('data', function(data) { state++; - assert.equal('string', typeof data); + assert.strictEqual('string', typeof data); if (state === 1) { - assert.equal('HTTP/1.1 101', data.substr(0, 12)); - assert.equal('WjN}|M(6', request_upgradeHead.toString('utf8')); + assert.strictEqual('HTTP/1.1 101', data.substr(0, 12)); + assert.strictEqual('WjN}|M(6', request_upgradeHead.toString('utf8')); conn.write('test', 'utf8'); } else if (state === 2) { - assert.equal('test', data); + assert.strictEqual('test', data); conn.write('kill', 'utf8'); } }); conn.on('end', function() { - assert.equal(2, state); + assert.strictEqual(2, state); conn.end(); server.removeAllListeners('upgrade'); test_upgrade_no_listener(); @@ -135,8 +135,8 @@ function test_standard_http() { }); conn.once('data', function(data) { - assert.equal('string', typeof data); - assert.equal('HTTP/1.1 200', data.substr(0, 12)); + assert.strictEqual('string', typeof data); + assert.strictEqual('HTTP/1.1 200', data.substr(0, 12)); conn.end(); }); @@ -158,7 +158,7 @@ server.listen(0, function() { Fin. -----------------------------------------------*/ process.on('exit', function() { - assert.equal(3, requests_recv); - assert.equal(3, requests_sent); + assert.strictEqual(3, requests_recv); + assert.strictEqual(3, requests_sent); assert.ok(test_upgrade_no_listener_ended); }); diff --git a/test/parallel/test-http-upgrade-server2.js b/test/parallel/test-http-upgrade-server2.js index c64b2e843637af..3ff33a9c794c25 100644 --- a/test/parallel/test-http-upgrade-server2.js +++ b/test/parallel/test-http-upgrade-server2.js @@ -15,7 +15,7 @@ server.on('upgrade', function(req, socket, upgradeHead) { }); process.on('uncaughtException', common.mustCall(function(e) { - assert.equal('upgrade error', e.message); + assert.strictEqual('upgrade error', e.message); process.exit(0); })); diff --git a/test/parallel/test-http-write-callbacks.js b/test/parallel/test-http-write-callbacks.js index 3783dc305e39a7..03250a0030ceff 100644 --- a/test/parallel/test-http-write-callbacks.js +++ b/test/parallel/test-http-write-callbacks.js @@ -14,9 +14,9 @@ const clientIncomingExpect = 'asdffoobar'; process.on('exit', function() { assert(serverEndCb); - assert.equal(serverIncoming, serverIncomingExpect); + assert.strictEqual(serverIncoming, serverIncomingExpect); assert(clientEndCb); - assert.equal(clientIncoming, clientIncomingExpect); + assert.strictEqual(clientIncoming, clientIncomingExpect); console.log('ok'); }); @@ -28,7 +28,7 @@ const server = http.createServer(function(req, res) { server.on('checkContinue', function(req, res) { server.close(); - assert.equal(req.method, 'PUT'); + assert.strictEqual(req.method, 'PUT'); res.writeContinue(function() { // continue has been written req.on('end', function() { diff --git a/test/parallel/test-http-write-empty-string.js b/test/parallel/test-http-write-empty-string.js index 69463fb3a50852..81ebc61eef2af4 100644 --- a/test/parallel/test-http-write-empty-string.js +++ b/test/parallel/test-http-write-empty-string.js @@ -21,7 +21,7 @@ server.listen(0, common.mustCall(function() { http.get({ port: this.address().port }, common.mustCall(function(res) { let response = ''; - assert.equal(200, res.statusCode); + assert.strictEqual(200, res.statusCode); res.setEncoding('ascii'); res.on('data', function(chunk) { response += chunk; diff --git a/test/parallel/test-http-write-head.js b/test/parallel/test-http-write-head.js index 8ebc2695c82178..2ceba8965c0ea4 100644 --- a/test/parallel/test-http-write-head.js +++ b/test/parallel/test-http-write-head.js @@ -25,7 +25,8 @@ const s = http.createServer(common.mustCall((req, res) => { res.setHeader('foo', undefined); } catch (e) { assert.ok(e instanceof Error); - assert.equal(e.message, '"value" required in setHeader("foo", value)'); + assert.strictEqual(e.message, + '"value" required in setHeader("foo", value)'); threw = true; } assert.ok(threw, 'Undefined value should throw'); diff --git a/test/parallel/test-http-zero-length-write.js b/test/parallel/test-http-zero-length-write.js index 63446e460471e4..11db6b1aa17f45 100644 --- a/test/parallel/test-http-zero-length-write.js +++ b/test/parallel/test-http-zero-length-write.js @@ -47,7 +47,7 @@ const server = http.createServer(function(req, res) { actual += c; }); req.on('end', function() { - assert.equal(actual, expect); + assert.strictEqual(actual, expect); getSrc().pipe(res); }); server.close(); @@ -62,7 +62,7 @@ server.listen(0, function() { actual += c; }); res.on('end', function() { - assert.equal(actual, expect); + assert.strictEqual(actual, expect); }); }); getSrc().pipe(req); diff --git a/test/parallel/test-http.js b/test/parallel/test-http.js index a80a2b8856558b..1178c745e1e12a 100644 --- a/test/parallel/test-http.js +++ b/test/parallel/test-http.js @@ -36,7 +36,7 @@ const server = http.Server(function(req, res) { }); req.resume(); - //assert.equal('127.0.0.1', res.connection.remoteAddress); + //assert.strictEqual('127.0.0.1', res.connection.remoteAddress); }); server.listen(0); diff --git a/test/parallel/test-https-agent-disable-session-reuse.js b/test/parallel/test-https-agent-disable-session-reuse.js index 72f6d068822338..7cca9c713ae011 100644 --- a/test/parallel/test-https-agent-disable-session-reuse.js +++ b/test/parallel/test-https-agent-disable-session-reuse.js @@ -52,8 +52,8 @@ const server = https.createServer(options, function(req, res) { }); process.on('exit', function() { - assert.equal(serverRequests, TOTAL_REQS); - assert.equal(clientSessions.length, TOTAL_REQS); - assert.notEqual(clientSessions[0].toString('hex'), - clientSessions[1].toString('hex')); + assert.strictEqual(serverRequests, TOTAL_REQS); + assert.strictEqual(clientSessions.length, TOTAL_REQS); + assert.notStrictEqual(clientSessions[0].toString('hex'), + clientSessions[1].toString('hex')); }); diff --git a/test/parallel/test-https-agent-session-reuse.js b/test/parallel/test-https-agent-session-reuse.js index 73465aa5a98fb9..3f06d1699f2cde 100644 --- a/test/parallel/test-https-agent-session-reuse.js +++ b/test/parallel/test-https-agent-session-reuse.js @@ -117,14 +117,14 @@ process.on('exit', function() { assert.strictEqual(serverRequests, 6); assert.strictEqual(clientSessions['first'].toString('hex'), clientSessions['first-reuse'].toString('hex')); - assert.notEqual(clientSessions['first'].toString('hex'), - clientSessions['cipher-change'].toString('hex')); - assert.notEqual(clientSessions['first'].toString('hex'), - clientSessions['before-drop'].toString('hex')); - assert.notEqual(clientSessions['cipher-change'].toString('hex'), - clientSessions['before-drop'].toString('hex')); - assert.notEqual(clientSessions['before-drop'].toString('hex'), - clientSessions['after-drop'].toString('hex')); + assert.notStrictEqual(clientSessions['first'].toString('hex'), + clientSessions['cipher-change'].toString('hex')); + assert.notStrictEqual(clientSessions['first'].toString('hex'), + clientSessions['before-drop'].toString('hex')); + assert.notStrictEqual(clientSessions['cipher-change'].toString('hex'), + clientSessions['before-drop'].toString('hex')); + assert.notStrictEqual(clientSessions['before-drop'].toString('hex'), + clientSessions['after-drop'].toString('hex')); assert.strictEqual(clientSessions['after-drop'].toString('hex'), clientSessions['after-drop-reuse'].toString('hex')); }); diff --git a/test/parallel/test-https-agent-sni.js b/test/parallel/test-https-agent-sni.js index ca15dc3db3a88d..9bfbe3d5c6525d 100644 --- a/test/parallel/test-https-agent-sni.js +++ b/test/parallel/test-https-agent-sni.js @@ -31,7 +31,7 @@ server.listen(0, function() { function expectResponse(id) { return common.mustCall(function(res) { res.resume(); - assert.equal(res.headers['x-sni'], 'sni.' + id); + assert.strictEqual(res.headers['x-sni'], 'sni.' + id); }); } diff --git a/test/parallel/test-https-client-get-url.js b/test/parallel/test-https-client-get-url.js index e098f32d7c9794..043e21bf7e3b5f 100644 --- a/test/parallel/test-https-client-get-url.js +++ b/test/parallel/test-https-client-get-url.js @@ -19,8 +19,8 @@ const options = { }; const server = https.createServer(options, common.mustCall(function(req, res) { - assert.equal('GET', req.method); - assert.equal('/foo?bar', req.url); + assert.strictEqual('GET', req.method); + assert.strictEqual('/foo?bar', req.url); res.writeHead(200, {'Content-Type': 'text/plain'}); res.write('hello\n'); res.end(); diff --git a/test/parallel/test-https-drain.js b/test/parallel/test-https-drain.js index 0b18795078fd1f..8e85ca70b97c47 100644 --- a/test/parallel/test-https-drain.js +++ b/test/parallel/test-https-drain.js @@ -71,5 +71,5 @@ server.listen(0, function() { }); process.on('exit', function() { - assert.equal(sent, received); + assert.strictEqual(sent, received); }); diff --git a/test/parallel/test-https-eof-for-eom.js b/test/parallel/test-https-eof-for-eom.js index d5e896c7695cfd..cb48f71e51a226 100644 --- a/test/parallel/test-https-eof-for-eom.js +++ b/test/parallel/test-https-eof-for-eom.js @@ -57,7 +57,7 @@ server.listen(0, common.mustCall(function() { server.close(); console.log('3) Client got response headers.'); - assert.equal('gws', res.headers.server); + assert.strictEqual('gws', res.headers.server); res.setEncoding('utf8'); res.on('data', function(s) { diff --git a/test/parallel/test-https-foafssl.js b/test/parallel/test-https-foafssl.js index f1b8d442e27893..5a9b8eb832cae3 100644 --- a/test/parallel/test-https-foafssl.js +++ b/test/parallel/test-https-foafssl.js @@ -66,7 +66,7 @@ server.listen(0, function() { client.stdout.on('data', function(data) { const message = data.toString(); const contents = message.split(CRLF + CRLF).pop(); - assert.equal(body, contents); + assert.strictEqual(body, contents); server.close(); }); diff --git a/test/parallel/test-https-host-headers.js b/test/parallel/test-https-host-headers.js index d16afa16006576..cc5047bea7f488 100644 --- a/test/parallel/test-https-host-headers.js +++ b/test/parallel/test-https-host-headers.js @@ -18,10 +18,10 @@ const httpsServer = https.createServer(options, reqHandler); function reqHandler(req, res) { console.log('Got request: ' + req.headers.host + ' ' + req.url); if (req.url === '/setHostFalse5') { - assert.equal(req.headers.host, undefined); + assert.strictEqual(req.headers.host, undefined); } else { - assert.equal(req.headers.host, `localhost:${this.address().port}`, - 'Wrong host header for req[' + req.url + ']: ' + + assert.strictEqual(req.headers.host, `localhost:${this.address().port}`, + 'Wrong host header for req[' + req.url + ']: ' + req.headers.host); } res.writeHead(200, {}); diff --git a/test/parallel/test-https-localaddress.js b/test/parallel/test-https-localaddress.js index 78583b38ecf1cf..1c796f5843c63c 100644 --- a/test/parallel/test-https-localaddress.js +++ b/test/parallel/test-https-localaddress.js @@ -21,7 +21,7 @@ const options = { const server = https.createServer(options, function(req, res) { console.log('Connect from: ' + req.connection.remoteAddress); - assert.equal('127.0.0.2', req.connection.remoteAddress); + assert.strictEqual('127.0.0.2', req.connection.remoteAddress); req.on('end', function() { res.writeHead(200, { 'Content-Type': 'text/plain' }); diff --git a/test/parallel/test-https-pfx.js b/test/parallel/test-https-pfx.js index c30bbc0848d137..0e3a2ba3cd2663 100644 --- a/test/parallel/test-https-pfx.js +++ b/test/parallel/test-https-pfx.js @@ -22,8 +22,9 @@ const options = { }; const server = https.createServer(options, function(req, res) { - assert.equal(req.socket.authorized, false); // not a client cert - assert.equal(req.socket.authorizationError, 'DEPTH_ZERO_SELF_SIGNED_CERT'); + assert.strictEqual(req.socket.authorized, false); // not a client cert + assert.strictEqual(req.socket.authorizationError, + 'DEPTH_ZERO_SELF_SIGNED_CERT'); res.writeHead(200); res.end('OK'); }); diff --git a/test/parallel/test-https-set-timeout-server.js b/test/parallel/test-https-set-timeout-server.js index 99457fea5cbec4..336e3c353c60da 100644 --- a/test/parallel/test-https-set-timeout-server.js +++ b/test/parallel/test-https-set-timeout-server.js @@ -117,7 +117,7 @@ test(function serverRequestNotTimeoutAfterEnd(cb) { test(function serverResponseTimeoutWithPipeline(cb) { let caughtTimeout = ''; process.on('exit', function() { - assert.equal(caughtTimeout, '/2'); + assert.strictEqual(caughtTimeout, '/2'); }); const server = https.createServer(serverOptions, function(req, res) { res.setTimeout(50, function() { diff --git a/test/parallel/test-https-simple.js b/test/parallel/test-https-simple.js index 0040b9dd054058..8616e6c710c463 100644 --- a/test/parallel/test-https-simple.js +++ b/test/parallel/test-https-simple.js @@ -52,7 +52,7 @@ server.listen(0, function() { }); res.on('end', function() { - assert.equal(responseBody, body); + assert.strictEqual(responseBody, body); testSucceeded(); }); }); @@ -82,11 +82,11 @@ server.listen(0, function() { checkCertReq.end(); checkCertReq.on('error', function(e) { - assert.equal(e.code, 'UNABLE_TO_VERIFY_LEAF_SIGNATURE'); + assert.strictEqual(e.code, 'UNABLE_TO_VERIFY_LEAF_SIGNATURE'); testSucceeded(); }); }); process.on('exit', function() { - assert.equal(successful, tests); + assert.strictEqual(successful, tests); }); diff --git a/test/parallel/test-https-strict.js b/test/parallel/test-https-strict.js index f4cff31bdf3538..d36b413021643f 100644 --- a/test/parallel/test-https-strict.js +++ b/test/parallel/test-https-strict.js @@ -137,7 +137,7 @@ function makeReq(path, port, error, host, ca) { req.on('response', function(res) { responseCount++; - assert.equal(res.connection.authorizationError, error); + assert.strictEqual(res.connection.authorizationError, error); responseErrors[path] = res.connection.authorizationError; pending--; if (pending === 0) { @@ -197,8 +197,8 @@ function allListening() { process.on('exit', function() { console.error(responseErrors); - assert.equal(server1.requests.length, server1.expectCount); - assert.equal(server2.requests.length, server2.expectCount); - assert.equal(server3.requests.length, server3.expectCount); - assert.equal(responseCount, expectResponseCount); + assert.strictEqual(server1.requests.length, server1.expectCount); + assert.strictEqual(server2.requests.length, server2.expectCount); + assert.strictEqual(server3.requests.length, server3.expectCount); + assert.strictEqual(responseCount, expectResponseCount); }); diff --git a/test/parallel/test-internal-modules-expose.js b/test/parallel/test-internal-modules-expose.js index dd3a7f7a3cd0b7..02ddfd87c363fc 100644 --- a/test/parallel/test-internal-modules-expose.js +++ b/test/parallel/test-internal-modules-expose.js @@ -4,4 +4,4 @@ require('../common'); const assert = require('assert'); -assert.equal(typeof require('internal/freelist').FreeList, 'function'); +assert.strictEqual(typeof require('internal/freelist').FreeList, 'function'); diff --git a/test/parallel/test-listen-fd-cluster.js b/test/parallel/test-listen-fd-cluster.js index de1fbed7b56aff..98810a39335acc 100644 --- a/test/parallel/test-listen-fd-cluster.js +++ b/test/parallel/test-listen-fd-cluster.js @@ -50,8 +50,8 @@ test(function(parent, port) { // it's really annoying when tests leave orphans! parent.kill(); parent.on('exit', function() { - assert.equal(s, 'hello from worker\n'); - assert.equal(res.statusCode, 200); + assert.strictEqual(s, 'hello from worker\n'); + assert.strictEqual(res.statusCode, 200); console.log('ok'); ok = true; }); diff --git a/test/parallel/test-listen-fd-detached-inherit.js b/test/parallel/test-listen-fd-detached-inherit.js index 2ac4d83dba6691..36e4df28897383 100644 --- a/test/parallel/test-listen-fd-detached-inherit.js +++ b/test/parallel/test-listen-fd-detached-inherit.js @@ -52,8 +52,8 @@ function test() { parent.kill(); } catch (e) {} - assert.equal(s, 'hello from child\n'); - assert.equal(res.statusCode, 200); + assert.strictEqual(s, 'hello from child\n'); + assert.strictEqual(res.statusCode, 200); }); }); } diff --git a/test/parallel/test-listen-fd-detached.js b/test/parallel/test-listen-fd-detached.js index 1194d001610fce..ec9d039e96e3f2 100644 --- a/test/parallel/test-listen-fd-detached.js +++ b/test/parallel/test-listen-fd-detached.js @@ -52,8 +52,8 @@ function test() { parent.kill(); } catch (e) {} - assert.equal(s, 'hello from child\n'); - assert.equal(res.statusCode, 200); + assert.strictEqual(s, 'hello from child\n'); + assert.strictEqual(res.statusCode, 200); }); }); } diff --git a/test/parallel/test-listen-fd-server.js b/test/parallel/test-listen-fd-server.js index 60aa8717a8c24e..5a1ffbb989cf8d 100644 --- a/test/parallel/test-listen-fd-server.js +++ b/test/parallel/test-listen-fd-server.js @@ -38,8 +38,8 @@ test(function(child, port) { res.on('end', function() { child.kill(); child.on('exit', function() { - assert.equal(s, 'hello from child\n'); - assert.equal(res.statusCode, 200); + assert.strictEqual(s, 'hello from child\n'); + assert.strictEqual(res.statusCode, 200); console.log('ok'); ok = true; }); diff --git a/test/parallel/test-memory-usage-emfile.js b/test/parallel/test-memory-usage-emfile.js index 09ab270b70fa21..c5345079a7f47b 100644 --- a/test/parallel/test-memory-usage-emfile.js +++ b/test/parallel/test-memory-usage-emfile.js @@ -10,4 +10,4 @@ while (files.length < 256) files.push(fs.openSync(__filename, 'r')); const r = process.memoryUsage(); -assert.equal(true, r['rss'] > 0); +assert.strictEqual(true, r['rss'] > 0); diff --git a/test/parallel/test-microtask-queue-integration-domain.js b/test/parallel/test-microtask-queue-integration-domain.js index 7110af7648ae8a..df90b6d3a372da 100644 --- a/test/parallel/test-microtask-queue-integration-domain.js +++ b/test/parallel/test-microtask-queue-integration-domain.js @@ -19,7 +19,7 @@ let expected = 0; let done = 0; process.on('exit', function() { - assert.equal(done, expected); + assert.strictEqual(done, expected); }); function test(scheduleMicrotask) { diff --git a/test/parallel/test-microtask-queue-integration.js b/test/parallel/test-microtask-queue-integration.js index d212bbae96b001..22704ab4a51d49 100644 --- a/test/parallel/test-microtask-queue-integration.js +++ b/test/parallel/test-microtask-queue-integration.js @@ -12,7 +12,7 @@ let expected = 0; let done = 0; process.on('exit', function() { - assert.equal(done, expected); + assert.strictEqual(done, expected); }); function test(scheduleMicrotask) { diff --git a/test/parallel/test-microtask-queue-run-domain.js b/test/parallel/test-microtask-queue-run-domain.js index 7d34ec829a003c..8ce2f6cd992648 100644 --- a/test/parallel/test-microtask-queue-run-domain.js +++ b/test/parallel/test-microtask-queue-run-domain.js @@ -16,7 +16,7 @@ function enqueueMicrotask(fn) { let done = 0; process.on('exit', function() { - assert.equal(done, 2); + assert.strictEqual(done, 2); }); // no nextTick, microtask diff --git a/test/parallel/test-microtask-queue-run-immediate-domain.js b/test/parallel/test-microtask-queue-run-immediate-domain.js index e09087f74e32a9..8c4d4d40d46d6b 100644 --- a/test/parallel/test-microtask-queue-run-immediate-domain.js +++ b/test/parallel/test-microtask-queue-run-immediate-domain.js @@ -16,7 +16,7 @@ function enqueueMicrotask(fn) { let done = 0; process.on('exit', function() { - assert.equal(done, 2); + assert.strictEqual(done, 2); }); // no nextTick, microtask diff --git a/test/parallel/test-microtask-queue-run-immediate.js b/test/parallel/test-microtask-queue-run-immediate.js index c5ed6c6dcbc1ae..9fee54b2d741cf 100644 --- a/test/parallel/test-microtask-queue-run-immediate.js +++ b/test/parallel/test-microtask-queue-run-immediate.js @@ -9,7 +9,7 @@ function enqueueMicrotask(fn) { let done = 0; process.on('exit', function() { - assert.equal(done, 2); + assert.strictEqual(done, 2); }); // no nextTick, microtask diff --git a/test/parallel/test-microtask-queue-run.js b/test/parallel/test-microtask-queue-run.js index 71e1fbedbaecbd..1a8f8e2ba32bc0 100644 --- a/test/parallel/test-microtask-queue-run.js +++ b/test/parallel/test-microtask-queue-run.js @@ -9,7 +9,7 @@ function enqueueMicrotask(fn) { let done = 0; process.on('exit', function() { - assert.equal(done, 2); + assert.strictEqual(done, 2); }); // no nextTick, microtask diff --git a/test/parallel/test-module-loading-error.js b/test/parallel/test-module-loading-error.js index 03481b690f79f4..44806fceb7904b 100644 --- a/test/parallel/test-module-loading-error.js +++ b/test/parallel/test-module-loading-error.js @@ -28,11 +28,11 @@ try { try { require(); } catch (e) { - assert.notEqual(e.toString().indexOf('missing path'), -1); + assert.notStrictEqual(e.toString().indexOf('missing path'), -1); } try { require({}); } catch (e) { - assert.notEqual(e.toString().indexOf('path must be a string'), -1); + assert.notStrictEqual(e.toString().indexOf('path must be a string'), -1); } diff --git a/test/parallel/test-net-better-error-messages-path.js b/test/parallel/test-net-better-error-messages-path.js index 2f821ef5d703be..7cdc14b9bd4333 100644 --- a/test/parallel/test-net-better-error-messages-path.js +++ b/test/parallel/test-net-better-error-messages-path.js @@ -8,6 +8,6 @@ const c = net.connect(fp); c.on('connect', common.fail); c.on('error', common.mustCall(function(e) { - assert.equal(e.code, 'ENOENT'); - assert.equal(e.message, 'connect ENOENT ' + fp); + assert.strictEqual(e.code, 'ENOENT'); + assert.strictEqual(e.message, 'connect ENOENT ' + fp); })); diff --git a/test/parallel/test-net-binary.js b/test/parallel/test-net-binary.js index bcc554ac4024f6..0c5cac1c37290b 100644 --- a/test/parallel/test-net-binary.js +++ b/test/parallel/test-net-binary.js @@ -55,7 +55,7 @@ echoServer.on('listening', function() { }); process.on('exit', function() { - assert.equal(2 * 256, recv.length); + assert.strictEqual(2 * 256, recv.length); const a = recv.split(''); diff --git a/test/parallel/test-net-bind-twice.js b/test/parallel/test-net-bind-twice.js index 17fdc90cb3742b..c10b4019e4b95f 100644 --- a/test/parallel/test-net-bind-twice.js +++ b/test/parallel/test-net-bind-twice.js @@ -9,7 +9,7 @@ server1.listen(0, '127.0.0.1', common.mustCall(function() { server2.listen(this.address().port, '127.0.0.1', common.fail); server2.on('error', common.mustCall(function(e) { - assert.equal(e.code, 'EADDRINUSE'); + assert.strictEqual(e.code, 'EADDRINUSE'); server1.close(); })); })); diff --git a/test/parallel/test-net-bytes-read.js b/test/parallel/test-net-bytes-read.js index 52fb577b9e7830..aed14fe279eb5b 100644 --- a/test/parallel/test-net-bytes-read.js +++ b/test/parallel/test-net-bytes-read.js @@ -23,14 +23,14 @@ const server = net.createServer((socket) => { }); socket.on('end', common.mustCall(() => { - assert.equal(socket.bytesRead, prev); - assert.equal(big.length, prev); + assert.strictEqual(socket.bytesRead, prev); + assert.strictEqual(big.length, prev); })); socket.on('close', common.mustCall(() => { assert(!socket._handle); - assert.equal(socket.bytesRead, prev); - assert.equal(big.length, prev); + assert.strictEqual(socket.bytesRead, prev); + assert.strictEqual(big.length, prev); })); }); socket.end(); diff --git a/test/parallel/test-net-bytes-stats.js b/test/parallel/test-net-bytes-stats.js index 4cc6eee8373e86..33e089da50880a 100644 --- a/test/parallel/test-net-bytes-stats.js +++ b/test/parallel/test-net-bytes-stats.js @@ -52,6 +52,6 @@ tcp.listen(0, function doTest() { }); process.on('exit', function() { - assert.equal(bytesRead, 12); - assert.equal(bytesWritten, 12); + assert.strictEqual(bytesRead, 12); + assert.strictEqual(bytesWritten, 12); }); diff --git a/test/parallel/test-net-connect-buffer.js b/test/parallel/test-net-connect-buffer.js index c43ee1abd0e305..1e296675879130 100644 --- a/test/parallel/test-net-connect-buffer.js +++ b/test/parallel/test-net-connect-buffer.js @@ -18,7 +18,7 @@ const tcp = net.Server(function(s) { s.on('end', function() { console.error('SERVER: end', buf.toString()); - assert.equal(buf, "L'État, c'est moi"); + assert.strictEqual(buf, "L'État, c'est moi"); console.log('tcp socket disconnect'); s.end(); }); @@ -41,7 +41,7 @@ tcp.listen(0, function() { console.log('connecting = ' + socket.connecting); - assert.equal('opening', socket.readyState); + assert.strictEqual('opening', socket.readyState); // Make sure that anything besides a buffer or a string throws. [null, @@ -76,18 +76,18 @@ tcp.listen(0, function() { dataWritten = true; assert.ok(connectHappened); console.error('socket.bytesWritten', socket.bytesWritten); - //assert.equal(socket.bytesWritten, Buffer.from(a + b).length); + //assert.strictEqual(socket.bytesWritten, Buffer.from(a + b).length); console.error('data written'); }); console.error('socket.bytesWritten', socket.bytesWritten); console.error('write returned', r); - assert.equal(socket.bytesWritten, Buffer.from(a).length); + assert.strictEqual(socket.bytesWritten, Buffer.from(a).length); - assert.equal(false, r); + assert.strictEqual(false, r); socket.end(b); - assert.equal('opening', socket.readyState); + assert.strictEqual('opening', socket.readyState); }); process.on('exit', function() { diff --git a/test/parallel/test-net-create-connection.js b/test/parallel/test-net-create-connection.js index a5d8cd101d974d..dc5981ecd20221 100644 --- a/test/parallel/test-net-create-connection.js +++ b/test/parallel/test-net-create-connection.js @@ -102,5 +102,5 @@ server.on('close', function() { }); process.on('exit', function() { - assert.equal(clientConnected, expectedConnections); + assert.strictEqual(clientConnected, expectedConnections); }); diff --git a/test/parallel/test-net-dns-error.js b/test/parallel/test-net-dns-error.js index aa288c5fde1ffa..5ca02313686589 100644 --- a/test/parallel/test-net-dns-error.js +++ b/test/parallel/test-net-dns-error.js @@ -12,11 +12,11 @@ function do_not_call() { const socket = net.connect(42, host, do_not_call); socket.on('error', common.mustCall(function(err) { - assert.equal(err.code, 'ENOTFOUND'); + assert.strictEqual(err.code, 'ENOTFOUND'); })); socket.on('lookup', function(err, ip, type) { assert(err instanceof Error); - assert.equal(err.code, 'ENOTFOUND'); - assert.equal(ip, undefined); - assert.equal(type, undefined); + assert.strictEqual(err.code, 'ENOTFOUND'); + assert.strictEqual(ip, undefined); + assert.strictEqual(type, undefined); }); diff --git a/test/parallel/test-net-dns-lookup.js b/test/parallel/test-net-dns-lookup.js index 8d9930f4b7a366..166029f31c482f 100644 --- a/test/parallel/test-net-dns-lookup.js +++ b/test/parallel/test-net-dns-lookup.js @@ -11,9 +11,9 @@ const server = net.createServer(function(client) { server.listen(0, '127.0.0.1', common.mustCall(function() { net.connect(this.address().port, 'localhost') .on('lookup', common.mustCall(function(err, ip, type, host) { - assert.equal(err, null); - assert.equal(ip, '127.0.0.1'); - assert.equal(type, '4'); - assert.equal(host, 'localhost'); + assert.strictEqual(err, null); + assert.strictEqual(ip, '127.0.0.1'); + assert.strictEqual(type, 4); + assert.strictEqual(host, 'localhost'); })); })); diff --git a/test/parallel/test-net-eaddrinuse.js b/test/parallel/test-net-eaddrinuse.js index 3d7ceb8d5e38f7..cf4293e8230875 100644 --- a/test/parallel/test-net-eaddrinuse.js +++ b/test/parallel/test-net-eaddrinuse.js @@ -9,7 +9,7 @@ const server2 = net.createServer(function(socket) { }); server1.listen(0, function() { server2.on('error', function(error) { - assert.equal(true, error.message.indexOf('EADDRINUSE') >= 0); + assert.strictEqual(true, error.message.indexOf('EADDRINUSE') >= 0); server1.close(); }); server2.listen(this.address().port); diff --git a/test/parallel/test-net-error-twice.js b/test/parallel/test-net-error-twice.js index 98a2c337559b06..3c25d1c98ed346 100644 --- a/test/parallel/test-net-error-twice.js +++ b/test/parallel/test-net-error-twice.js @@ -38,5 +38,5 @@ const srv = net.createServer(function onConnection(conn) { process.on('exit', function() { console.log(errs); - assert.equal(errs.length, 1); + assert.strictEqual(errs.length, 1); }); diff --git a/test/parallel/test-net-isip.js b/test/parallel/test-net-isip.js index 65d88523fe930e..626f29488b67ea 100644 --- a/test/parallel/test-net-isip.js +++ b/test/parallel/test-net-isip.js @@ -3,68 +3,70 @@ require('../common'); const assert = require('assert'); const net = require('net'); -assert.equal(net.isIP('127.0.0.1'), 4); -assert.equal(net.isIP('x127.0.0.1'), 0); -assert.equal(net.isIP('example.com'), 0); -assert.equal(net.isIP('0000:0000:0000:0000:0000:0000:0000:0000'), 6); -assert.equal(net.isIP('0000:0000:0000:0000:0000:0000:0000:0000::0000'), 0); -assert.equal(net.isIP('1050:0:0:0:5:600:300c:326b'), 6); -assert.equal(net.isIP('2001:252:0:1::2008:6'), 6); -assert.equal(net.isIP('2001:dead:beef:1::2008:6'), 6); -assert.equal(net.isIP('2001::'), 6); -assert.equal(net.isIP('2001:dead::'), 6); -assert.equal(net.isIP('2001:dead:beef::'), 6); -assert.equal(net.isIP('2001:dead:beef:1::'), 6); -assert.equal(net.isIP('ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff'), 6); -assert.equal(net.isIP(':2001:252:0:1::2008:6:'), 0); -assert.equal(net.isIP(':2001:252:0:1::2008:6'), 0); -assert.equal(net.isIP('2001:252:0:1::2008:6:'), 0); -assert.equal(net.isIP('2001:252::1::2008:6'), 0); -assert.equal(net.isIP('::2001:252:1:2008:6'), 6); -assert.equal(net.isIP('::2001:252:1:1.1.1.1'), 6); -assert.equal(net.isIP('::2001:252:1:255.255.255.255'), 6); -assert.equal(net.isIP('::2001:252:1:255.255.255.255.76'), 0); -assert.equal(net.isIP('::anything'), 0); -assert.equal(net.isIP('::1'), 6); -assert.equal(net.isIP('::'), 6); -assert.equal(net.isIP('0000:0000:0000:0000:0000:0000:12345:0000'), 0); -assert.equal(net.isIP('0'), 0); -assert.equal(net.isIP(), 0); -assert.equal(net.isIP(''), 0); -assert.equal(net.isIP(null), 0); -assert.equal(net.isIP(123), 0); -assert.equal(net.isIP(true), 0); -assert.equal(net.isIP({}), 0); -assert.equal(net.isIP({ toString: () => '::2001:252:1:255.255.255.255' }), 6); -assert.equal(net.isIP({ toString: () => '127.0.0.1' }), 4); -assert.equal(net.isIP({ toString: () => 'bla' }), 0); +assert.strictEqual(net.isIP('127.0.0.1'), 4); +assert.strictEqual(net.isIP('x127.0.0.1'), 0); +assert.strictEqual(net.isIP('example.com'), 0); +assert.strictEqual(net.isIP('0000:0000:0000:0000:0000:0000:0000:0000'), 6); +assert.strictEqual(net.isIP('0000:0000:0000:0000:0000:0000:0000:0000::0000'), + 0); +assert.strictEqual(net.isIP('1050:0:0:0:5:600:300c:326b'), 6); +assert.strictEqual(net.isIP('2001:252:0:1::2008:6'), 6); +assert.strictEqual(net.isIP('2001:dead:beef:1::2008:6'), 6); +assert.strictEqual(net.isIP('2001::'), 6); +assert.strictEqual(net.isIP('2001:dead::'), 6); +assert.strictEqual(net.isIP('2001:dead:beef::'), 6); +assert.strictEqual(net.isIP('2001:dead:beef:1::'), 6); +assert.strictEqual(net.isIP('ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff'), 6); +assert.strictEqual(net.isIP(':2001:252:0:1::2008:6:'), 0); +assert.strictEqual(net.isIP(':2001:252:0:1::2008:6'), 0); +assert.strictEqual(net.isIP('2001:252:0:1::2008:6:'), 0); +assert.strictEqual(net.isIP('2001:252::1::2008:6'), 0); +assert.strictEqual(net.isIP('::2001:252:1:2008:6'), 6); +assert.strictEqual(net.isIP('::2001:252:1:1.1.1.1'), 6); +assert.strictEqual(net.isIP('::2001:252:1:255.255.255.255'), 6); +assert.strictEqual(net.isIP('::2001:252:1:255.255.255.255.76'), 0); +assert.strictEqual(net.isIP('::anything'), 0); +assert.strictEqual(net.isIP('::1'), 6); +assert.strictEqual(net.isIP('::'), 6); +assert.strictEqual(net.isIP('0000:0000:0000:0000:0000:0000:12345:0000'), 0); +assert.strictEqual(net.isIP('0'), 0); +assert.strictEqual(net.isIP(), 0); +assert.strictEqual(net.isIP(''), 0); +assert.strictEqual(net.isIP(null), 0); +assert.strictEqual(net.isIP(123), 0); +assert.strictEqual(net.isIP(true), 0); +assert.strictEqual(net.isIP({}), 0); +assert.strictEqual(net.isIP({ toString: () => '::2001:252:1:255.255.255.255' }), + 6); +assert.strictEqual(net.isIP({ toString: () => '127.0.0.1' }), 4); +assert.strictEqual(net.isIP({ toString: () => 'bla' }), 0); -assert.equal(net.isIPv4('127.0.0.1'), true); -assert.equal(net.isIPv4('example.com'), false); -assert.equal(net.isIPv4('2001:252:0:1::2008:6'), false); -assert.equal(net.isIPv4(), false); -assert.equal(net.isIPv4(''), false); -assert.equal(net.isIPv4(null), false); -assert.equal(net.isIPv4(123), false); -assert.equal(net.isIPv4(true), false); -assert.equal(net.isIPv4({}), false); -assert.equal(net.isIPv4({ +assert.strictEqual(net.isIPv4('127.0.0.1'), true); +assert.strictEqual(net.isIPv4('example.com'), false); +assert.strictEqual(net.isIPv4('2001:252:0:1::2008:6'), false); +assert.strictEqual(net.isIPv4(), false); +assert.strictEqual(net.isIPv4(''), false); +assert.strictEqual(net.isIPv4(null), false); +assert.strictEqual(net.isIPv4(123), false); +assert.strictEqual(net.isIPv4(true), false); +assert.strictEqual(net.isIPv4({}), false); +assert.strictEqual(net.isIPv4({ toString: () => '::2001:252:1:255.255.255.255' }), false); -assert.equal(net.isIPv4({ toString: () => '127.0.0.1' }), true); -assert.equal(net.isIPv4({ toString: () => 'bla' }), false); +assert.strictEqual(net.isIPv4({ toString: () => '127.0.0.1' }), true); +assert.strictEqual(net.isIPv4({ toString: () => 'bla' }), false); -assert.equal(net.isIPv6('127.0.0.1'), false); -assert.equal(net.isIPv6('example.com'), false); -assert.equal(net.isIPv6('2001:252:0:1::2008:6'), true); -assert.equal(net.isIPv6(), false); -assert.equal(net.isIPv6(''), false); -assert.equal(net.isIPv6(null), false); -assert.equal(net.isIPv6(123), false); -assert.equal(net.isIPv6(true), false); -assert.equal(net.isIPv6({}), false); -assert.equal(net.isIPv6({ +assert.strictEqual(net.isIPv6('127.0.0.1'), false); +assert.strictEqual(net.isIPv6('example.com'), false); +assert.strictEqual(net.isIPv6('2001:252:0:1::2008:6'), true); +assert.strictEqual(net.isIPv6(), false); +assert.strictEqual(net.isIPv6(''), false); +assert.strictEqual(net.isIPv6(null), false); +assert.strictEqual(net.isIPv6(123), false); +assert.strictEqual(net.isIPv6(true), false); +assert.strictEqual(net.isIPv6({}), false); +assert.strictEqual(net.isIPv6({ toString: () => '::2001:252:1:255.255.255.255' }), true); -assert.equal(net.isIPv6({ toString: () => '127.0.0.1' }), false); -assert.equal(net.isIPv6({ toString: () => 'bla' }), false); +assert.strictEqual(net.isIPv6({ toString: () => '127.0.0.1' }), false); +assert.strictEqual(net.isIPv6({ toString: () => 'bla' }), false); diff --git a/test/parallel/test-net-keepalive.js b/test/parallel/test-net-keepalive.js index 950a005addecdf..68ed5f842ff13b 100644 --- a/test/parallel/test-net-keepalive.js +++ b/test/parallel/test-net-keepalive.js @@ -16,7 +16,7 @@ const echoServer = net.createServer(function(connection) { echoServer.close(); }, 1), common.platformTimeout(100)); connection.setTimeout(0); - assert.notEqual(connection.setKeepAlive, undefined); + assert.notStrictEqual(connection.setKeepAlive, undefined); // send a keepalive packet after 50 ms connection.setKeepAlive(true, common.platformTimeout(50)); connection.on('end', function() { diff --git a/test/parallel/test-net-listen-exclusive-random-ports.js b/test/parallel/test-net-listen-exclusive-random-ports.js index 6b9c750f55ea69..1909af067ce4d7 100644 --- a/test/parallel/test-net-listen-exclusive-random-ports.js +++ b/test/parallel/test-net-listen-exclusive-random-ports.js @@ -10,12 +10,12 @@ if (cluster.isMaster) { const worker1 = cluster.fork(); worker1.on('message', function(port1) { - assert.equal(port1, port1 | 0, 'first worker could not listen'); + assert.strictEqual(port1, port1 | 0, 'first worker could not listen'); const worker2 = cluster.fork(); worker2.on('message', function(port2) { - assert.equal(port2, port2 | 0, 'second worker could not listen'); - assert.notEqual(port1, port2, 'ports should not be equal'); + assert.strictEqual(port2, port2 | 0, 'second worker could not listen'); + assert.notStrictEqual(port1, port2, 'ports should not be equal'); worker1.kill(); worker2.kill(); }); diff --git a/test/parallel/test-net-listen-shared-ports.js b/test/parallel/test-net-listen-shared-ports.js index ce344be4a6f492..e7bc036ff3986c 100644 --- a/test/parallel/test-net-listen-shared-ports.js +++ b/test/parallel/test-net-listen-shared-ports.js @@ -10,11 +10,11 @@ if (cluster.isMaster) { const worker1 = cluster.fork(); worker1.on('message', function(msg) { - assert.equal(msg, 'success'); + assert.strictEqual(msg, 'success'); const worker2 = cluster.fork(); worker2.on('message', function(msg) { - assert.equal(msg, 'server2:EADDRINUSE'); + assert.strictEqual(msg, 'server2:EADDRINUSE'); worker1.kill(); worker2.kill(); }); diff --git a/test/parallel/test-net-persistent-keepalive.js b/test/parallel/test-net-persistent-keepalive.js index 6338b5932de1fa..8756cd7d1b2960 100644 --- a/test/parallel/test-net-persistent-keepalive.js +++ b/test/parallel/test-net-persistent-keepalive.js @@ -9,14 +9,14 @@ const echoServer = net.createServer(function(connection) { serverConnection = connection; setTimeout(function() { // make sure both connections are still open - assert.equal(serverConnection.readyState, 'open'); - assert.equal(clientConnection.readyState, 'open'); + assert.strictEqual(serverConnection.readyState, 'open'); + assert.strictEqual(clientConnection.readyState, 'open'); serverConnection.end(); clientConnection.end(); echoServer.close(); }, 600); connection.setTimeout(0); - assert.equal(typeof connection.setKeepAlive, 'function'); + assert.strictEqual(typeof connection.setKeepAlive, 'function'); connection.on('end', function() { connection.end(); }); diff --git a/test/parallel/test-net-persistent-nodelay.js b/test/parallel/test-net-persistent-nodelay.js index 3f94424b0e1197..bb2a9dfd22e5cc 100644 --- a/test/parallel/test-net-persistent-nodelay.js +++ b/test/parallel/test-net-persistent-nodelay.js @@ -28,7 +28,7 @@ echoServer.on('listening', function() { assert.ok(s instanceof net.Socket); sock1.connect(this.address().port); sock1.on('end', function() { - assert.equal(callCount, 1); + assert.strictEqual(callCount, 1); echoServer.close(); }); }); diff --git a/test/parallel/test-net-persistent-ref-unref.js b/test/parallel/test-net-persistent-ref-unref.js index 1d3cbc6ffaef18..d8de7ba3f2877a 100644 --- a/test/parallel/test-net-persistent-ref-unref.js +++ b/test/parallel/test-net-persistent-ref-unref.js @@ -16,13 +16,13 @@ let refCount = 0; TCPWrap.prototype.ref = function() { ref.call(this); refCount++; - assert.equal(refCount, 0); + assert.strictEqual(refCount, 0); }; TCPWrap.prototype.unref = function() { unref.call(this); refCount--; - assert.equal(refCount, -1); + assert.strictEqual(refCount, -1); }; echoServer.listen(0); @@ -33,7 +33,7 @@ echoServer.on('listening', function() { sock.ref(); sock.connect(this.address().port); sock.on('end', function() { - assert.equal(refCount, 0); + assert.strictEqual(refCount, 0); echoServer.close(); }); }); diff --git a/test/parallel/test-net-reconnect.js b/test/parallel/test-net-reconnect.js index 47171093ca13f9..c970ad7fc5c135 100644 --- a/test/parallel/test-net-reconnect.js +++ b/test/parallel/test-net-reconnect.js @@ -23,7 +23,7 @@ const server = net.createServer(function(socket) { socket.on('close', function(had_error) { console.log('SERVER had_error: ' + JSON.stringify(had_error)); - assert.equal(false, had_error); + assert.strictEqual(false, had_error); }); }); @@ -40,7 +40,7 @@ server.listen(0, function() { client.on('data', function(chunk) { client_recv_count += 1; console.log('client_recv_count ' + client_recv_count); - assert.equal('hello\r\n', chunk); + assert.strictEqual('hello\r\n', chunk); console.error('CLIENT: calling end', client._writableState); client.end(); }); @@ -52,7 +52,7 @@ server.listen(0, function() { client.on('close', function(had_error) { console.log('CLIENT disconnect'); - assert.equal(false, had_error); + assert.strictEqual(false, had_error); if (disconnect_count++ < N) client.connect(server.address().port); // reconnect else @@ -61,7 +61,7 @@ server.listen(0, function() { }); process.on('exit', function() { - assert.equal(N + 1, disconnect_count); - assert.equal(N + 1, client_recv_count); - assert.equal(N + 1, client_end_count); + assert.strictEqual(N + 1, disconnect_count); + assert.strictEqual(N + 1, client_recv_count); + assert.strictEqual(N + 1, client_end_count); }); diff --git a/test/parallel/test-net-remote-address-port.js b/test/parallel/test-net-remote-address-port.js index 96e2049f9e32fa..7f4b4d0e023a3a 100644 --- a/test/parallel/test-net-remote-address-port.js +++ b/test/parallel/test-net-remote-address-port.js @@ -13,16 +13,19 @@ const remoteFamilyCandidates = ['IPv4']; if (common.hasIPv6) remoteFamilyCandidates.push('IPv6'); const server = net.createServer(common.mustCall(function(socket) { - assert.notEqual(-1, remoteAddrCandidates.indexOf(socket.remoteAddress)); - assert.notEqual(-1, remoteFamilyCandidates.indexOf(socket.remoteFamily)); + assert.notStrictEqual(-1, remoteAddrCandidates.indexOf(socket.remoteAddress)); + assert.notStrictEqual(-1, + remoteFamilyCandidates.indexOf(socket.remoteFamily)); assert.ok(socket.remotePort); - assert.notEqual(socket.remotePort, this.address().port); + assert.notStrictEqual(socket.remotePort, this.address().port); socket.on('end', function() { if (++conns_closed === 2) server.close(); }); socket.on('close', function() { - assert.notEqual(-1, remoteAddrCandidates.indexOf(socket.remoteAddress)); - assert.notEqual(-1, remoteFamilyCandidates.indexOf(socket.remoteFamily)); + assert.notStrictEqual(-1, + remoteAddrCandidates.indexOf(socket.remoteAddress)); + assert.notStrictEqual(-1, + remoteFamilyCandidates.indexOf(socket.remoteFamily)); }); socket.resume(); }, 2)); @@ -31,23 +34,31 @@ server.listen(0, 'localhost', function() { const client = net.createConnection(this.address().port, 'localhost'); const client2 = net.createConnection(this.address().port); client.on('connect', function() { - assert.notEqual(-1, remoteAddrCandidates.indexOf(client.remoteAddress)); - assert.notEqual(-1, remoteFamilyCandidates.indexOf(client.remoteFamily)); + assert.notStrictEqual(-1, + remoteAddrCandidates.indexOf(client.remoteAddress)); + assert.notStrictEqual(-1, + remoteFamilyCandidates.indexOf(client.remoteFamily)); assert.strictEqual(client.remotePort, server.address().port); client.end(); }); client.on('close', function() { - assert.notEqual(-1, remoteAddrCandidates.indexOf(client.remoteAddress)); - assert.notEqual(-1, remoteFamilyCandidates.indexOf(client.remoteFamily)); + assert.notStrictEqual(-1, + remoteAddrCandidates.indexOf(client.remoteAddress)); + assert.notStrictEqual(-1, + remoteFamilyCandidates.indexOf(client.remoteFamily)); }); client2.on('connect', function() { - assert.notEqual(-1, remoteAddrCandidates.indexOf(client2.remoteAddress)); - assert.notEqual(-1, remoteFamilyCandidates.indexOf(client2.remoteFamily)); + assert.notStrictEqual(-1, + remoteAddrCandidates.indexOf(client2.remoteAddress)); + assert.notStrictEqual(-1, + remoteFamilyCandidates.indexOf(client2.remoteFamily)); assert.strictEqual(client2.remotePort, server.address().port); client2.end(); }); client2.on('close', function() { - assert.notEqual(-1, remoteAddrCandidates.indexOf(client2.remoteAddress)); - assert.notEqual(-1, remoteFamilyCandidates.indexOf(client2.remoteFamily)); + assert.notStrictEqual(-1, + remoteAddrCandidates.indexOf(client2.remoteAddress)); + assert.notStrictEqual(-1, + remoteFamilyCandidates.indexOf(client2.remoteFamily)); }); }); diff --git a/test/parallel/test-net-server-bind.js b/test/parallel/test-net-server-bind.js index e4dc64216441cf..0332b364df1ca2 100644 --- a/test/parallel/test-net-server-bind.js +++ b/test/parallel/test-net-server-bind.js @@ -70,7 +70,7 @@ server4.listen(common.PORT + 3, 127, function() { process.on('exit', function() { assert.ok(address0.port > 100); - assert.equal(common.PORT, address1.port); + assert.strictEqual(common.PORT, address1.port); let expectedConnectionKey1; @@ -79,8 +79,8 @@ process.on('exit', function() { else expectedConnectionKey1 = '4:0.0.0.0:' + address1.port; - assert.equal(connectionKey1, expectedConnectionKey1); - assert.equal(common.PORT + 1, address2.port); - assert.equal(common.PORT + 2, address3.port); - assert.equal(common.PORT + 3, address4.port); + assert.strictEqual(connectionKey1, expectedConnectionKey1); + assert.strictEqual(common.PORT + 1, address2.port); + assert.strictEqual(common.PORT + 2, address3.port); + assert.strictEqual(common.PORT + 3, address4.port); }); diff --git a/test/parallel/test-net-server-close.js b/test/parallel/test-net-server-close.js index c44dc230c90662..28519fdafdbc9c 100644 --- a/test/parallel/test-net-server-close.js +++ b/test/parallel/test-net-server-close.js @@ -7,12 +7,12 @@ const events = []; const sockets = []; process.on('exit', function() { - assert.equal(server.connections, 0); - assert.equal(events.length, 3); + assert.strictEqual(server.connections, 0); + assert.strictEqual(events.length, 3); // Expect to see one server event and two client events. The order of the // events is undefined because they arrive on the same event loop tick. - assert.equal(events.join(' ').match(/server/g).length, 1); - assert.equal(events.join(' ').match(/client/g).length, 2); + assert.strictEqual(events.join(' ').match(/server/g).length, 1); + assert.strictEqual(events.join(' ').match(/client/g).length, 2); }); let server = net.createServer(function(c) { diff --git a/test/parallel/test-net-server-connections.js b/test/parallel/test-net-server-connections.js index 4e41d29a505199..7ee1df1a544b95 100644 --- a/test/parallel/test-net-server-connections.js +++ b/test/parallel/test-net-server-connections.js @@ -9,4 +9,4 @@ const net = require('net'); const server = new net.Server(); -assert.equal(Object.keys(server).indexOf('connections'), -1); +assert.strictEqual(Object.keys(server).indexOf('connections'), -1); diff --git a/test/parallel/test-net-server-listen-remove-callback.js b/test/parallel/test-net-server-listen-remove-callback.js index a678922683eeb1..cd47f325a9580f 100644 --- a/test/parallel/test-net-server-listen-remove-callback.js +++ b/test/parallel/test-net-server-listen-remove-callback.js @@ -9,7 +9,7 @@ const server = net.createServer(); server.on('close', function() { const listeners = server.listeners('listening'); console.log('Closed, listeners:', listeners.length); - assert.equal(0, listeners.length); + assert.strictEqual(0, listeners.length); }); server.listen(0, function() { diff --git a/test/parallel/test-net-server-max-connections-close-makes-more-available.js b/test/parallel/test-net-server-max-connections-close-makes-more-available.js index 06233f6c8633ed..60f7c304a9ff6b 100644 --- a/test/parallel/test-net-server-max-connections-close-makes-more-available.js +++ b/test/parallel/test-net-server-max-connections-close-makes-more-available.js @@ -29,7 +29,7 @@ const createConnection = function(index) { }); connection.on('error', function(err) { - assert.equal(err.code, 'ECONNRESET'); + assert.strictEqual(err.code, 'ECONNRESET'); resolve(); }); diff --git a/test/parallel/test-net-server-pause-on-connect.js b/test/parallel/test-net-server-pause-on-connect.js index ee5ac4e2807b0a..5b42876e6d652e 100644 --- a/test/parallel/test-net-server-pause-on-connect.js +++ b/test/parallel/test-net-server-pause-on-connect.js @@ -13,7 +13,7 @@ const server1ConnHandler = function(socket) { common.fail('data event should not have happened yet'); } - assert.equal(data.toString(), msg, 'invalid data received'); + assert.strictEqual(data.toString(), msg, 'invalid data received'); socket.end(); server1.close(); }); @@ -25,11 +25,12 @@ const server1 = net.createServer({pauseOnConnect: true}, server1ConnHandler); const server2ConnHandler = function(socket) { socket.on('data', function(data) { - assert.equal(data.toString(), msg, 'invalid data received'); + assert.strictEqual(data.toString(), msg, 'invalid data received'); socket.end(); server2.close(); - assert.equal(server1Sock.bytesRead, 0, 'no data should have been read yet'); + assert.strictEqual(server1Sock.bytesRead, 0, + 'no data should have been read yet'); server1Sock.resume(); stopped = false; }); @@ -47,5 +48,5 @@ server1.listen(0, function() { }); process.on('exit', function() { - assert.equal(stopped, false); + assert.strictEqual(stopped, false); }); diff --git a/test/parallel/test-net-stream.js b/test/parallel/test-net-stream.js index 9d091bd66f3a1e..9e1ca670e1e145 100644 --- a/test/parallel/test-net-stream.js +++ b/test/parallel/test-net-stream.js @@ -12,11 +12,11 @@ s.server = new net.Server(); s.server.connections = 10; s._server = s.server; -assert.equal(10, s.server.connections); +assert.strictEqual(10, s.server.connections); s.destroy(); -assert.equal(9, s.server.connections); +assert.strictEqual(9, s.server.connections); s.destroy(); -assert.equal(9, s.server.connections); +assert.strictEqual(9, s.server.connections); const SIZE = 2E6; const N = 10; @@ -47,5 +47,5 @@ const server = net.createServer(function(socket) { }); process.on('exit', function() { - assert.equal(server.connections, 0); + assert.strictEqual(server.connections, 0); }); diff --git a/test/parallel/test-net-sync-cork.js b/test/parallel/test-net-sync-cork.js index 4dff309cb97816..3872f5f96944fc 100644 --- a/test/parallel/test-net-sync-cork.js +++ b/test/parallel/test-net-sync-cork.js @@ -21,13 +21,13 @@ server.listen(0, function() { res = conn.write(buf); conn.uncork(); } - assert.equal(i, N); + assert.strictEqual(i, N); conn.end(); }); }); process.on('exit', function() { - assert.equal(server.connections, 0); + assert.strictEqual(server.connections, 0); }); function handle(socket) { diff --git a/test/parallel/test-next-tick-ordering.js b/test/parallel/test-next-tick-ordering.js index 2f13147d8ed733..ea019facdd8fa0 100644 --- a/test/parallel/test-next-tick-ordering.js +++ b/test/parallel/test-next-tick-ordering.js @@ -26,10 +26,10 @@ console.log('Running from main.'); process.on('exit', function() { - assert.equal('nextTick', done[0]); + assert.strictEqual('nextTick', done[0]); /* Disabling this test. I don't think we can ensure the order for (i = 0; i < N; i += 1) { - assert.equal(i, done[i + 1]); + assert.strictEqual(i, done[i + 1]); } */ }); diff --git a/test/parallel/test-next-tick.js b/test/parallel/test-next-tick.js index 3001ad0e561a77..9d2b1917fae2f7 100644 --- a/test/parallel/test-next-tick.js +++ b/test/parallel/test-next-tick.js @@ -17,8 +17,8 @@ process.nextTick(common.mustCall(function() {})); const obj = {}; process.nextTick(function(a, b) { - assert.equal(a, 42); - assert.equal(b, obj); + assert.strictEqual(a, 42); + assert.strictEqual(b, obj); }, 42, obj); process.on('exit', function() { diff --git a/test/parallel/test-os-homedir-no-envvar.js b/test/parallel/test-os-homedir-no-envvar.js index 94d8ab5a08fa14..2f9b1b47a70477 100644 --- a/test/parallel/test-os-homedir-no-envvar.js +++ b/test/parallel/test-os-homedir-no-envvar.js @@ -26,5 +26,5 @@ if (process.argv[2] === 'child') { env: process.env }); - assert.equal(child.status, 0); + assert.strictEqual(child.status, 0); } diff --git a/test/parallel/test-path-makelong.js b/test/parallel/test-path-makelong.js index 293d6284f173bc..1284f625160ebe 100644 --- a/test/parallel/test-path-makelong.js +++ b/test/parallel/test-path-makelong.js @@ -7,18 +7,19 @@ if (common.isWindows) { const file = path.join(common.fixturesDir, 'a.js'); const resolvedFile = path.resolve(file); - assert.equal('\\\\?\\' + resolvedFile, path._makeLong(file)); - assert.equal('\\\\?\\' + resolvedFile, path._makeLong('\\\\?\\' + file)); - assert.equal('\\\\?\\UNC\\someserver\\someshare\\somefile', - path._makeLong('\\\\someserver\\someshare\\somefile')); - assert.equal('\\\\?\\UNC\\someserver\\someshare\\somefile', - path._makeLong('\\\\?\\UNC\\someserver\\someshare\\somefile')); - assert.equal('\\\\.\\pipe\\somepipe', - path._makeLong('\\\\.\\pipe\\somepipe')); + assert.strictEqual('\\\\?\\' + resolvedFile, path._makeLong(file)); + assert.strictEqual('\\\\?\\' + resolvedFile, path._makeLong('\\\\?\\' + + file)); + assert.strictEqual('\\\\?\\UNC\\someserver\\someshare\\somefile', + path._makeLong('\\\\someserver\\someshare\\somefile')); + assert.strictEqual('\\\\?\\UNC\\someserver\\someshare\\somefile', path + ._makeLong('\\\\?\\UNC\\someserver\\someshare\\somefile')); + assert.strictEqual('\\\\.\\pipe\\somepipe', + path._makeLong('\\\\.\\pipe\\somepipe')); } -assert.equal(path._makeLong(null), null); -assert.equal(path._makeLong(100), 100); -assert.equal(path._makeLong(path), path); -assert.equal(path._makeLong(false), false); -assert.equal(path._makeLong(true), true); +assert.strictEqual(path._makeLong(null), null); +assert.strictEqual(path._makeLong(100), 100); +assert.strictEqual(path._makeLong(path), path); +assert.strictEqual(path._makeLong(false), false); +assert.strictEqual(path._makeLong(true), true); diff --git a/test/parallel/test-path-parse-format.js b/test/parallel/test-path-parse-format.js index b316dc5e754a8b..9d5c149924ff4c 100644 --- a/test/parallel/test-path-parse-format.js +++ b/test/parallel/test-path-parse-format.js @@ -158,7 +158,7 @@ trailingTests.forEach(function(test) { failures.push('\n' + message); }); }); -assert.equal(failures.length, 0, failures.join('')); +assert.strictEqual(failures.length, 0, failures.join('')); function checkErrors(path) { errors.forEach(function(errorCase) { diff --git a/test/parallel/test-path-zero-length-strings.js b/test/parallel/test-path-zero-length-strings.js index b08ef4809201eb..ec9585fafaa169 100644 --- a/test/parallel/test-path-zero-length-strings.js +++ b/test/parallel/test-path-zero-length-strings.js @@ -12,28 +12,28 @@ const pwd = process.cwd(); // join will internally ignore all the zero-length strings and it will return // '.' if the joined string is a zero-length string. -assert.equal(path.posix.join(''), '.'); -assert.equal(path.posix.join('', ''), '.'); -assert.equal(path.win32.join(''), '.'); -assert.equal(path.win32.join('', ''), '.'); -assert.equal(path.join(pwd), pwd); -assert.equal(path.join(pwd, ''), pwd); +assert.strictEqual(path.posix.join(''), '.'); +assert.strictEqual(path.posix.join('', ''), '.'); +assert.strictEqual(path.win32.join(''), '.'); +assert.strictEqual(path.win32.join('', ''), '.'); +assert.strictEqual(path.join(pwd), pwd); +assert.strictEqual(path.join(pwd, ''), pwd); // normalize will return '.' if the input is a zero-length string -assert.equal(path.posix.normalize(''), '.'); -assert.equal(path.win32.normalize(''), '.'); -assert.equal(path.normalize(pwd), pwd); +assert.strictEqual(path.posix.normalize(''), '.'); +assert.strictEqual(path.win32.normalize(''), '.'); +assert.strictEqual(path.normalize(pwd), pwd); // Since '' is not a valid path in any of the common environments, return false -assert.equal(path.posix.isAbsolute(''), false); -assert.equal(path.win32.isAbsolute(''), false); +assert.strictEqual(path.posix.isAbsolute(''), false); +assert.strictEqual(path.win32.isAbsolute(''), false); // resolve, internally ignores all the zero-length strings and returns the // current working directory -assert.equal(path.resolve(''), pwd); -assert.equal(path.resolve('', ''), pwd); +assert.strictEqual(path.resolve(''), pwd); +assert.strictEqual(path.resolve('', ''), pwd); // relative, internally calls resolve. So, '' is actually the current directory -assert.equal(path.relative('', pwd), ''); -assert.equal(path.relative(pwd, ''), ''); -assert.equal(path.relative(pwd, pwd), ''); +assert.strictEqual(path.relative('', pwd), ''); +assert.strictEqual(path.relative(pwd, ''), ''); +assert.strictEqual(path.relative(pwd, pwd), ''); diff --git a/test/parallel/test-path.js b/test/parallel/test-path.js index 6f2ea3fd48ad55..3c5374175abd8e 100644 --- a/test/parallel/test-path.js +++ b/test/parallel/test-path.js @@ -456,7 +456,7 @@ if (common.isWindows) { const spawnResult = child.spawnSync( process.argv[0], [resolveFixture, currentDriveLetter]); const resolvedPath = spawnResult.stdout.toString().trim(); - assert.equal(resolvedPath.toLowerCase(), process.cwd().toLowerCase()); + assert.strictEqual(resolvedPath.toLowerCase(), process.cwd().toLowerCase()); } diff --git a/test/parallel/test-pipe-stream.js b/test/parallel/test-pipe-stream.js index 2776ba868e6963..669ad6aa62ff9a 100644 --- a/test/parallel/test-pipe-stream.js +++ b/test/parallel/test-pipe-stream.js @@ -26,7 +26,7 @@ function test(clazz, cb) { }); conn.on('data', function(data) { - assert.equal(data.toString(), 'PONG'); + assert.strictEqual(data.toString(), 'PONG'); have_pong = true; conn.destroy(); }); @@ -38,7 +38,7 @@ function test(clazz, cb) { }); conn.on('data', function(data) { - assert.equal(data.toString(), 'PING'); + assert.strictEqual(data.toString(), 'PING'); have_ping = true; conn.write('PONG', 'utf-8'); }); diff --git a/test/parallel/test-process-argv-0.js b/test/parallel/test-process-argv-0.js index d6b4bfe232323e..8e4f0e695ec6a1 100644 --- a/test/parallel/test-process-argv-0.js +++ b/test/parallel/test-process-argv-0.js @@ -14,7 +14,7 @@ if (process.argv[2] !== 'child') { childArgv0 += chunk; }); process.on('exit', function() { - assert.equal(childArgv0, process.execPath); + assert.strictEqual(childArgv0, process.execPath); }); } else { process.stdout.write(process.argv[0]); diff --git a/test/parallel/test-process-before-exit.js b/test/parallel/test-process-before-exit.js index ec7a7f76e57ef9..a0931180102291 100644 --- a/test/parallel/test-process-before-exit.js +++ b/test/parallel/test-process-before-exit.js @@ -10,5 +10,5 @@ function f() { } process.on('beforeExit', f); process.on('exit', function() { - assert.equal(n, N + 1); // The sixth time we let it through. + assert.strictEqual(n, N + 1); // The sixth time we let it through. }); diff --git a/test/parallel/test-process-cpuUsage.js b/test/parallel/test-process-cpuUsage.js index 0c553c576a1f25..062dac31cf7b5e 100644 --- a/test/parallel/test-process-cpuUsage.js +++ b/test/parallel/test-process-cpuUsage.js @@ -87,7 +87,7 @@ assert.throws(() => { // Ensure that the return value is the expected shape. function validateResult(result) { - assert.notEqual(result, null); + assert.notStrictEqual(result, null); assert(Number.isFinite(result.user)); assert(Number.isFinite(result.system)); diff --git a/test/parallel/test-process-env.js b/test/parallel/test-process-env.js index 21898d19425ca3..5ea0a4a57efc68 100644 --- a/test/parallel/test-process-env.js +++ b/test/parallel/test-process-env.js @@ -63,8 +63,8 @@ process.env.TZ = 'Europe/Amsterdam'; // time difference between Greenwich and Amsterdam is +2 hours in the summer date = new Date('Fri, 10 Sep 1982 03:15:00 GMT'); -assert.equal(3, date.getUTCHours()); -assert.equal(5, date.getHours()); +assert.strictEqual(3, date.getUTCHours()); +assert.strictEqual(5, date.getHours()); */ /* eslint-enable max-len */ diff --git a/test/parallel/test-process-exit-code.js b/test/parallel/test-process-exit-code.js index 337502ffcb30e8..8d0ed1b33bae76 100644 --- a/test/parallel/test-process-exit-code.js +++ b/test/parallel/test-process-exit-code.js @@ -22,14 +22,14 @@ switch (process.argv[2]) { function child1() { process.exitCode = 42; process.on('exit', function(code) { - assert.equal(code, 42); + assert.strictEqual(code, 42); }); } function child2() { process.exitCode = 99; process.on('exit', function(code) { - assert.equal(code, 42); + assert.strictEqual(code, 42); }); process.exit(42); } @@ -37,7 +37,7 @@ function child2() { function child3() { process.exitCode = 99; process.on('exit', function(code) { - assert.equal(code, 0); + assert.strictEqual(code, 0); }); process.exit(0); } @@ -56,7 +56,7 @@ function child4() { function child5() { process.exitCode = 95; process.on('exit', function(code) { - assert.equal(code, 95); + assert.strictEqual(code, 95); process.exitCode = 99; }); } @@ -75,7 +75,7 @@ function test(arg, exit) { const f = __filename; const option = { stdio: [ 0, 1, 'ignore' ] }; spawn(node, [f, arg], option).on('exit', function(code) { - assert.equal(code, exit, 'wrong exit for ' + + assert.strictEqual(code, exit, 'wrong exit for ' + arg + '\nexpected:' + exit + ' but got:' + code); console.log('ok - %s exited with %d', arg, exit); diff --git a/test/parallel/test-process-exit-recursive.js b/test/parallel/test-process-exit-recursive.js index 1634aad15497f5..48ad8259168a90 100644 --- a/test/parallel/test-process-exit-recursive.js +++ b/test/parallel/test-process-exit-recursive.js @@ -6,8 +6,8 @@ const assert = require('assert'); let nexits = 0; process.on('exit', function(code) { - assert.equal(nexits++, 0); - assert.equal(code, 1); + assert.strictEqual(nexits++, 0); + assert.strictEqual(code, 1); // now override the exit code of 1 with 0 so that the test passes process.exit(0); diff --git a/test/parallel/test-process-exit.js b/test/parallel/test-process-exit.js index f7df7737ed1531..a4ea2bf51b53f5 100644 --- a/test/parallel/test-process-exit.js +++ b/test/parallel/test-process-exit.js @@ -6,8 +6,8 @@ const assert = require('assert'); let nexits = 0; process.on('exit', function(code) { - assert.equal(nexits++, 0); - assert.equal(code, 0); + assert.strictEqual(nexits++, 0); + assert.strictEqual(code, 0); process.exit(); }); diff --git a/test/parallel/test-process-getactiverequests.js b/test/parallel/test-process-getactiverequests.js index 30773f8f11380a..f1874e4ad09a86 100644 --- a/test/parallel/test-process-getactiverequests.js +++ b/test/parallel/test-process-getactiverequests.js @@ -7,4 +7,4 @@ const fs = require('fs'); for (let i = 0; i < 12; i++) fs.open(__filename, 'r', function() { }); -assert.equal(12, process._getActiveRequests().length); +assert.strictEqual(12, process._getActiveRequests().length); diff --git a/test/parallel/test-process-getgroups.js b/test/parallel/test-process-getgroups.js index 87b5a29863f2ed..497da2be1235f8 100644 --- a/test/parallel/test-process-getgroups.js +++ b/test/parallel/test-process-getgroups.js @@ -15,7 +15,7 @@ if (typeof process.getgroups === 'function') { exec('id -G', function(err, stdout) { if (err) throw err; const real_groups = stdout.match(/\d+/g).map(Number); - assert.equal(groups.length, real_groups.length); + assert.strictEqual(groups.length, real_groups.length); check(groups, real_groups); check(real_groups, groups); }); diff --git a/test/parallel/test-process-kill-pid.js b/test/parallel/test-process-kill-pid.js index 2c6ef37fc120df..79dc00163b78f8 100644 --- a/test/parallel/test-process-kill-pid.js +++ b/test/parallel/test-process-kill-pid.js @@ -47,8 +47,8 @@ function kill(tryPid, trySig, expectPid, expectSig) { process.kill(tryPid, trySig); - assert.equal(getPid, expectPid); - assert.equal(getSig, expectSig); + assert.strictEqual(getPid.toString(), expectPid.toString()); + assert.strictEqual(getSig, expectSig); } // Note that SIGHUP and SIGTERM map to 1 and 15 respectively, even on Windows diff --git a/test/parallel/test-process-raw-debug.js b/test/parallel/test-process-raw-debug.js index 74c99b1f8f8058..dc31c3737ae1cb 100644 --- a/test/parallel/test-process-raw-debug.js +++ b/test/parallel/test-process-raw-debug.js @@ -25,7 +25,7 @@ function parent() { child.stderr.setEncoding('utf8'); child.stderr.on('end', function() { - assert.equal(output, 'I can still debug!' + os.EOL); + assert.strictEqual(output, 'I can still debug!' + os.EOL); console.log('ok - got expected message'); }); diff --git a/test/parallel/test-process-release.js b/test/parallel/test-process-release.js index 5d5228af72b599..0f4955d4ab1640 100644 --- a/test/parallel/test-process-release.js +++ b/test/parallel/test-process-release.js @@ -3,14 +3,14 @@ require('../common'); const assert = require('assert'); const versionParts = process.versions.node.split('.'); -assert.equal(process.release.name, 'node'); +assert.strictEqual(process.release.name, 'node'); // it's expected that future LTS release lines will have additional // branches in here if (versionParts[0] === '4' && versionParts[1] >= 2) { - assert.equal(process.release.lts, 'Argon'); + assert.strictEqual(process.release.lts, 'Argon'); } else if (versionParts[0] === '6' && versionParts[1] >= 9) { - assert.equal(process.release.lts, 'Boron'); + assert.strictEqual(process.release.lts, 'Boron'); } else { assert.strictEqual(process.release.lts, undefined); } diff --git a/test/parallel/test-process-remove-all-signal-listeners.js b/test/parallel/test-process-remove-all-signal-listeners.js index 76a96f7683e452..85db45ff88c7c8 100644 --- a/test/parallel/test-process-remove-all-signal-listeners.js +++ b/test/parallel/test-process-remove-all-signal-listeners.js @@ -17,7 +17,7 @@ if (process.argv[2] !== '--do-test') { const child = spawn(process.execPath, [__filename, '--do-test']); child.once('exit', common.mustCall(function(code, signal) { - assert.equal(signal, 'SIGINT'); + assert.strictEqual(signal, 'SIGINT'); })); return; diff --git a/test/parallel/test-process-wrap.js b/test/parallel/test-process-wrap.js index 326854e98335df..fee40a84167023 100644 --- a/test/parallel/test-process-wrap.js +++ b/test/parallel/test-process-wrap.js @@ -15,8 +15,8 @@ p.onexit = function(exitCode, signal) { p.close(); pipe.readStart(); - assert.equal(0, exitCode); - assert.equal(0, signal); + assert.strictEqual(0, exitCode); + assert.strictEqual('', signal); processExited = true; }; diff --git a/test/parallel/test-promises-unhandled-rejections.js b/test/parallel/test-promises-unhandled-rejections.js index e2453c915a4a24..31afa09a6c3d95 100644 --- a/test/parallel/test-promises-unhandled-rejections.js +++ b/test/parallel/test-promises-unhandled-rejections.js @@ -672,7 +672,7 @@ asyncTest('Throwing an error inside a rejectionHandled handler goes to' + const e = new Error(); const e2 = new Error(); const tearDownException = setupException(function(err) { - assert.equal(e2, err); + assert.strictEqual(e2, err); tearDownException(); done(); }); diff --git a/test/parallel/test-querystring-maxKeys-non-finite.js b/test/parallel/test-querystring-maxKeys-non-finite.js index 8aa47f7de0e2dc..3df381405d650a 100644 --- a/test/parallel/test-querystring-maxKeys-non-finite.js +++ b/test/parallel/test-querystring-maxKeys-non-finite.js @@ -47,9 +47,9 @@ const resultInfinityString = parse(params, undefined, undefined, { const resultNaNString = parse(params, undefined, undefined, {maxKeys: 'NaN'}); // Non Finite maxKeys should return the length of input -assert.equal(Object.keys(resultInfinity).length, count); -assert.equal(Object.keys(resultNaN).length, count); +assert.strictEqual(Object.keys(resultInfinity).length, count); +assert.strictEqual(Object.keys(resultNaN).length, count); // Strings maxKeys should return the maxLength // defined by parses internals -assert.equal(Object.keys(resultInfinityString).length, originalMaxLength); -assert.equal(Object.keys(resultNaNString).length, originalMaxLength); +assert.strictEqual(Object.keys(resultInfinityString).length, originalMaxLength); +assert.strictEqual(Object.keys(resultNaNString).length, originalMaxLength); diff --git a/test/parallel/test-querystring.js b/test/parallel/test-querystring.js index fed9eb9b8506ac..2c8e756efda0de 100644 --- a/test/parallel/test-querystring.js +++ b/test/parallel/test-querystring.js @@ -183,15 +183,15 @@ qsNoMungeTestCases.forEach(function(testCase) { // basic qsTestCases.forEach(function(testCase) { - assert.equal(testCase[1], qs.stringify(testCase[2])); + assert.strictEqual(testCase[1], qs.stringify(testCase[2])); }); qsColonTestCases.forEach(function(testCase) { - assert.equal(testCase[1], qs.stringify(testCase[2], ';', ':')); + assert.strictEqual(testCase[1], qs.stringify(testCase[2], ';', ':')); }); qsWeirdObjects.forEach(function(testCase) { - assert.equal(testCase[1], qs.stringify(testCase[0])); + assert.strictEqual(testCase[1], qs.stringify(testCase[0])); }); // invalid surrogate pair throws URIError @@ -216,7 +216,7 @@ assert.strictEqual('foo=', qs.stringify({ foo: Infinity })); y: 'z' }) }); - assert.equal(f, 'a=b&q=x%3Dy%26y%3Dz'); + assert.strictEqual(f, 'a=b&q=x%3Dy%26y%3Dz'); } assert.doesNotThrow(function() { @@ -232,7 +232,7 @@ assert.doesNotThrow(function() { y: 'z' }, ';', ':') }, ';', ':'); - assert.equal(f, 'a:b;q:x%3Ay%3By%3Az'); + assert.strictEqual(f, 'a:b;q:x%3Ay%3By%3Az'); } // empty string @@ -251,7 +251,7 @@ check(qs.parse('a', []), { a: '' }); check(qs.parse('a', null, []), { '': 'a' }); // Test limiting -assert.equal( +assert.strictEqual( Object.keys(qs.parse('a=1&b=1&c=1', null, null, { maxKeys: 1 })).length, 1); @@ -263,7 +263,7 @@ function testUnlimitedKeys() { const url = qs.stringify(query); - assert.equal( + assert.strictEqual( Object.keys(qs.parse(url, null, null, { maxKeys: 0 })).length, 2000); } @@ -273,26 +273,26 @@ testUnlimitedKeys(); const b = qs.unescapeBuffer('%d3%f2Ug%1f6v%24%5e%98%cb' + '%0d%ac%a2%2f%9d%eb%d8%a2%e6'); // -assert.equal(0xd3, b[0]); -assert.equal(0xf2, b[1]); -assert.equal(0x55, b[2]); -assert.equal(0x67, b[3]); -assert.equal(0x1f, b[4]); -assert.equal(0x36, b[5]); -assert.equal(0x76, b[6]); -assert.equal(0x24, b[7]); -assert.equal(0x5e, b[8]); -assert.equal(0x98, b[9]); -assert.equal(0xcb, b[10]); -assert.equal(0x0d, b[11]); -assert.equal(0xac, b[12]); -assert.equal(0xa2, b[13]); -assert.equal(0x2f, b[14]); -assert.equal(0x9d, b[15]); -assert.equal(0xeb, b[16]); -assert.equal(0xd8, b[17]); -assert.equal(0xa2, b[18]); -assert.equal(0xe6, b[19]); +assert.strictEqual(0xd3, b[0]); +assert.strictEqual(0xf2, b[1]); +assert.strictEqual(0x55, b[2]); +assert.strictEqual(0x67, b[3]); +assert.strictEqual(0x1f, b[4]); +assert.strictEqual(0x36, b[5]); +assert.strictEqual(0x76, b[6]); +assert.strictEqual(0x24, b[7]); +assert.strictEqual(0x5e, b[8]); +assert.strictEqual(0x98, b[9]); +assert.strictEqual(0xcb, b[10]); +assert.strictEqual(0x0d, b[11]); +assert.strictEqual(0xac, b[12]); +assert.strictEqual(0xa2, b[13]); +assert.strictEqual(0x2f, b[14]); +assert.strictEqual(0x9d, b[15]); +assert.strictEqual(0xeb, b[16]); +assert.strictEqual(0xd8, b[17]); +assert.strictEqual(0xa2, b[18]); +assert.strictEqual(0xe6, b[19]); assert.strictEqual(qs.unescapeBuffer('a+b', true).toString(), 'a b'); assert.strictEqual(qs.unescapeBuffer('a%').toString(), 'a%'); @@ -321,7 +321,7 @@ function demoEncode(str) { return str[0]; } const obj = { aa: 'aa', bb: 'bb', cc: 'cc' }; -assert.equal( +assert.strictEqual( qs.stringify(obj, null, null, { encodeURIComponent: demoEncode }), 'a=a&b=b&c=c'); diff --git a/test/parallel/test-readdouble.js b/test/parallel/test-readdouble.js index 728a2b4605d9ff..00340a39e631c0 100644 --- a/test/parallel/test-readdouble.js +++ b/test/parallel/test-readdouble.js @@ -19,8 +19,8 @@ function test(clazz) { buffer[5] = 0x55; buffer[6] = 0xd5; buffer[7] = 0x3f; - assert.equal(1.1945305291680097e+103, buffer.readDoubleBE(0)); - assert.equal(0.3333333333333333, buffer.readDoubleLE(0)); + assert.strictEqual(1.1945305291680097e+103, buffer.readDoubleBE(0)); + assert.strictEqual(0.3333333333333333, buffer.readDoubleLE(0)); buffer[0] = 1; buffer[1] = 0; @@ -30,18 +30,18 @@ function test(clazz) { buffer[5] = 0; buffer[6] = 0xf0; buffer[7] = 0x3f; - assert.equal(7.291122019655968e-304, buffer.readDoubleBE(0)); - assert.equal(1.0000000000000002, buffer.readDoubleLE(0)); + assert.strictEqual(7.291122019655968e-304, buffer.readDoubleBE(0)); + assert.strictEqual(1.0000000000000002, buffer.readDoubleLE(0)); buffer[0] = 2; - assert.equal(4.778309726801735e-299, buffer.readDoubleBE(0)); - assert.equal(1.0000000000000004, buffer.readDoubleLE(0)); + assert.strictEqual(4.778309726801735e-299, buffer.readDoubleBE(0)); + assert.strictEqual(1.0000000000000004, buffer.readDoubleLE(0)); buffer[0] = 1; buffer[6] = 0; buffer[7] = 0; - assert.equal(7.291122019556398e-304, buffer.readDoubleBE(0)); - assert.equal(5e-324, buffer.readDoubleLE(0)); + assert.strictEqual(7.291122019556398e-304, buffer.readDoubleBE(0)); + assert.strictEqual(5e-324, buffer.readDoubleLE(0)); buffer[0] = 0xff; buffer[1] = 0xff; @@ -52,12 +52,12 @@ function test(clazz) { buffer[6] = 0x0f; buffer[7] = 0x00; assert.ok(isNaN(buffer.readDoubleBE(0))); - assert.equal(2.225073858507201e-308, buffer.readDoubleLE(0)); + assert.strictEqual(2.225073858507201e-308, buffer.readDoubleLE(0)); buffer[6] = 0xef; buffer[7] = 0x7f; assert.ok(isNaN(buffer.readDoubleBE(0))); - assert.equal(1.7976931348623157e+308, buffer.readDoubleLE(0)); + assert.strictEqual(1.7976931348623157e+308, buffer.readDoubleLE(0)); buffer[0] = 0; buffer[1] = 0; @@ -67,42 +67,42 @@ function test(clazz) { buffer[5] = 0; buffer[6] = 0xf0; buffer[7] = 0x3f; - assert.equal(3.03865e-319, buffer.readDoubleBE(0)); - assert.equal(1, buffer.readDoubleLE(0)); + assert.strictEqual(3.03865e-319, buffer.readDoubleBE(0)); + assert.strictEqual(1, buffer.readDoubleLE(0)); buffer[6] = 0; buffer[7] = 0x40; - assert.equal(3.16e-322, buffer.readDoubleBE(0)); - assert.equal(2, buffer.readDoubleLE(0)); + assert.strictEqual(3.16e-322, buffer.readDoubleBE(0)); + assert.strictEqual(2, buffer.readDoubleLE(0)); buffer[7] = 0xc0; - assert.equal(9.5e-322, buffer.readDoubleBE(0)); - assert.equal(-2, buffer.readDoubleLE(0)); + assert.strictEqual(9.5e-322, buffer.readDoubleBE(0)); + assert.strictEqual(-2, buffer.readDoubleLE(0)); buffer[6] = 0x10; buffer[7] = 0; - assert.equal(2.0237e-320, buffer.readDoubleBE(0)); - assert.equal(2.2250738585072014e-308, buffer.readDoubleLE(0)); + assert.strictEqual(2.0237e-320, buffer.readDoubleBE(0)); + assert.strictEqual(2.2250738585072014e-308, buffer.readDoubleLE(0)); buffer[6] = 0; - assert.equal(0, buffer.readDoubleBE(0)); - assert.equal(0, buffer.readDoubleLE(0)); - assert.equal(false, 1 / buffer.readDoubleLE(0) < 0); + assert.strictEqual(0, buffer.readDoubleBE(0)); + assert.strictEqual(0, buffer.readDoubleLE(0)); + assert.strictEqual(false, 1 / buffer.readDoubleLE(0) < 0); buffer[7] = 0x80; - assert.equal(6.3e-322, buffer.readDoubleBE(0)); - assert.equal(0, buffer.readDoubleLE(0)); - assert.equal(true, 1 / buffer.readDoubleLE(0) < 0); + assert.strictEqual(6.3e-322, buffer.readDoubleBE(0)); + assert.strictEqual(0, buffer.readDoubleLE(0)); + assert.strictEqual(true, 1 / buffer.readDoubleLE(0) < 0); buffer[6] = 0xf0; buffer[7] = 0x7f; - assert.equal(3.0418e-319, buffer.readDoubleBE(0)); - assert.equal(Infinity, buffer.readDoubleLE(0)); + assert.strictEqual(3.0418e-319, buffer.readDoubleBE(0)); + assert.strictEqual(Infinity, buffer.readDoubleLE(0)); buffer[6] = 0xf0; buffer[7] = 0xff; - assert.equal(3.04814e-319, buffer.readDoubleBE(0)); - assert.equal(-Infinity, buffer.readDoubleLE(0)); + assert.strictEqual(3.04814e-319, buffer.readDoubleBE(0)); + assert.strictEqual(-Infinity, buffer.readDoubleLE(0)); } diff --git a/test/parallel/test-readfloat.js b/test/parallel/test-readfloat.js index 437e4778671bd2..0175c195b8ec22 100644 --- a/test/parallel/test-readfloat.js +++ b/test/parallel/test-readfloat.js @@ -15,56 +15,56 @@ function test(clazz) { buffer[1] = 0; buffer[2] = 0x80; buffer[3] = 0x3f; - assert.equal(4.600602988224807e-41, buffer.readFloatBE(0)); - assert.equal(1, buffer.readFloatLE(0)); + assert.strictEqual(4.600602988224807e-41, buffer.readFloatBE(0)); + assert.strictEqual(1, buffer.readFloatLE(0)); buffer[0] = 0; buffer[1] = 0; buffer[2] = 0; buffer[3] = 0xc0; - assert.equal(2.6904930515036488e-43, buffer.readFloatBE(0)); - assert.equal(-2, buffer.readFloatLE(0)); + assert.strictEqual(2.6904930515036488e-43, buffer.readFloatBE(0)); + assert.strictEqual(-2, buffer.readFloatLE(0)); buffer[0] = 0xff; buffer[1] = 0xff; buffer[2] = 0x7f; buffer[3] = 0x7f; assert.ok(isNaN(buffer.readFloatBE(0))); - assert.equal(3.4028234663852886e+38, buffer.readFloatLE(0)); + assert.strictEqual(3.4028234663852886e+38, buffer.readFloatLE(0)); buffer[0] = 0xab; buffer[1] = 0xaa; buffer[2] = 0xaa; buffer[3] = 0x3e; - assert.equal(-1.2126478207002966e-12, buffer.readFloatBE(0)); - assert.equal(0.3333333432674408, buffer.readFloatLE(0)); + assert.strictEqual(-1.2126478207002966e-12, buffer.readFloatBE(0)); + assert.strictEqual(0.3333333432674408, buffer.readFloatLE(0)); buffer[0] = 0; buffer[1] = 0; buffer[2] = 0; buffer[3] = 0; - assert.equal(0, buffer.readFloatBE(0)); - assert.equal(0, buffer.readFloatLE(0)); - assert.equal(false, 1 / buffer.readFloatLE(0) < 0); + assert.strictEqual(0, buffer.readFloatBE(0)); + assert.strictEqual(0, buffer.readFloatLE(0)); + assert.strictEqual(false, 1 / buffer.readFloatLE(0) < 0); buffer[3] = 0x80; - assert.equal(1.793662034335766e-43, buffer.readFloatBE(0)); - assert.equal(0, buffer.readFloatLE(0)); - assert.equal(true, 1 / buffer.readFloatLE(0) < 0); + assert.strictEqual(1.793662034335766e-43, buffer.readFloatBE(0)); + assert.strictEqual(0, buffer.readFloatLE(0)); + assert.strictEqual(true, 1 / buffer.readFloatLE(0) < 0); buffer[0] = 0; buffer[1] = 0; buffer[2] = 0x80; buffer[3] = 0x7f; - assert.equal(4.609571298396486e-41, buffer.readFloatBE(0)); - assert.equal(Infinity, buffer.readFloatLE(0)); + assert.strictEqual(4.609571298396486e-41, buffer.readFloatBE(0)); + assert.strictEqual(Infinity, buffer.readFloatLE(0)); buffer[0] = 0; buffer[1] = 0; buffer[2] = 0x80; buffer[3] = 0xff; - assert.equal(4.627507918739843e-41, buffer.readFloatBE(0)); - assert.equal(-Infinity, buffer.readFloatLE(0)); + assert.strictEqual(4.627507918739843e-41, buffer.readFloatBE(0)); + assert.strictEqual(-Infinity, buffer.readFloatLE(0)); } diff --git a/test/parallel/test-readint.js b/test/parallel/test-readint.js index 086dd4e3aa0d1a..97faa1e7d58d77 100644 --- a/test/parallel/test-readint.js +++ b/test/parallel/test-readint.js @@ -12,19 +12,19 @@ function test8(clazz) { const data = new clazz(4); data[0] = 0x23; - assert.equal(0x23, data.readInt8(0)); + assert.strictEqual(0x23, data.readInt8(0)); data[0] = 0xff; - assert.equal(-1, data.readInt8(0)); + assert.strictEqual(-1, data.readInt8(0)); data[0] = 0x87; data[1] = 0xab; data[2] = 0x7c; data[3] = 0xef; - assert.equal(-121, data.readInt8(0)); - assert.equal(-85, data.readInt8(1)); - assert.equal(124, data.readInt8(2)); - assert.equal(-17, data.readInt8(3)); + assert.strictEqual(-121, data.readInt8(0)); + assert.strictEqual(-85, data.readInt8(1)); + assert.strictEqual(124, data.readInt8(2)); + assert.strictEqual(-17, data.readInt8(3)); } @@ -33,13 +33,13 @@ function test16(clazz) { buffer[0] = 0x16; buffer[1] = 0x79; - assert.equal(0x1679, buffer.readInt16BE(0)); - assert.equal(0x7916, buffer.readInt16LE(0)); + assert.strictEqual(0x1679, buffer.readInt16BE(0)); + assert.strictEqual(0x7916, buffer.readInt16LE(0)); buffer[0] = 0xff; buffer[1] = 0x80; - assert.equal(-128, buffer.readInt16BE(0)); - assert.equal(-32513, buffer.readInt16LE(0)); + assert.strictEqual(-128, buffer.readInt16BE(0)); + assert.strictEqual(-32513, buffer.readInt16LE(0)); /* test offset with weenix */ buffer[0] = 0x77; @@ -48,16 +48,16 @@ function test16(clazz) { buffer[3] = 0x6e; buffer[4] = 0x69; buffer[5] = 0x78; - assert.equal(0x7765, buffer.readInt16BE(0)); - assert.equal(0x6565, buffer.readInt16BE(1)); - assert.equal(0x656e, buffer.readInt16BE(2)); - assert.equal(0x6e69, buffer.readInt16BE(3)); - assert.equal(0x6978, buffer.readInt16BE(4)); - assert.equal(0x6577, buffer.readInt16LE(0)); - assert.equal(0x6565, buffer.readInt16LE(1)); - assert.equal(0x6e65, buffer.readInt16LE(2)); - assert.equal(0x696e, buffer.readInt16LE(3)); - assert.equal(0x7869, buffer.readInt16LE(4)); + assert.strictEqual(0x7765, buffer.readInt16BE(0)); + assert.strictEqual(0x6565, buffer.readInt16BE(1)); + assert.strictEqual(0x656e, buffer.readInt16BE(2)); + assert.strictEqual(0x6e69, buffer.readInt16BE(3)); + assert.strictEqual(0x6978, buffer.readInt16BE(4)); + assert.strictEqual(0x6577, buffer.readInt16LE(0)); + assert.strictEqual(0x6565, buffer.readInt16LE(1)); + assert.strictEqual(0x6e65, buffer.readInt16LE(2)); + assert.strictEqual(0x696e, buffer.readInt16LE(3)); + assert.strictEqual(0x7869, buffer.readInt16LE(4)); } @@ -68,15 +68,15 @@ function test32(clazz) { buffer[1] = 0x53; buffer[2] = 0x16; buffer[3] = 0x79; - assert.equal(0x43531679, buffer.readInt32BE(0)); - assert.equal(0x79165343, buffer.readInt32LE(0)); + assert.strictEqual(0x43531679, buffer.readInt32BE(0)); + assert.strictEqual(0x79165343, buffer.readInt32LE(0)); buffer[0] = 0xff; buffer[1] = 0xfe; buffer[2] = 0xef; buffer[3] = 0xfa; - assert.equal(-69638, buffer.readInt32BE(0)); - assert.equal(-84934913, buffer.readInt32LE(0)); + assert.strictEqual(-69638, buffer.readInt32BE(0)); + assert.strictEqual(-84934913, buffer.readInt32LE(0)); buffer[0] = 0x42; buffer[1] = 0xc3; @@ -84,12 +84,12 @@ function test32(clazz) { buffer[3] = 0xa9; buffer[4] = 0x36; buffer[5] = 0x17; - assert.equal(0x42c395a9, buffer.readInt32BE(0)); - assert.equal(-1013601994, buffer.readInt32BE(1)); - assert.equal(-1784072681, buffer.readInt32BE(2)); - assert.equal(-1449802942, buffer.readInt32LE(0)); - assert.equal(917083587, buffer.readInt32LE(1)); - assert.equal(389458325, buffer.readInt32LE(2)); + assert.strictEqual(0x42c395a9, buffer.readInt32BE(0)); + assert.strictEqual(-1013601994, buffer.readInt32BE(1)); + assert.strictEqual(-1784072681, buffer.readInt32BE(2)); + assert.strictEqual(-1449802942, buffer.readInt32LE(0)); + assert.strictEqual(917083587, buffer.readInt32LE(1)); + assert.strictEqual(389458325, buffer.readInt32LE(2)); } diff --git a/test/parallel/test-readline-interface.js b/test/parallel/test-readline-interface.js index 49809dda81a3a2..0542f83d494b86 100644 --- a/test/parallel/test-readline-interface.js +++ b/test/parallel/test-readline-interface.js @@ -82,7 +82,7 @@ function isWarned(emitter) { called = false; rli.on('line', function(line) { called = true; - assert.equal(line, 'asdf'); + assert.strictEqual(line, 'asdf'); }); fi.emit('data', 'asdf\n'); assert.ok(called); @@ -93,7 +93,7 @@ function isWarned(emitter) { called = false; rli.on('line', function(line) { called = true; - assert.equal(line, ''); + assert.strictEqual(line, ''); }); fi.emit('data', '\n'); assert.ok(called); @@ -115,7 +115,7 @@ function isWarned(emitter) { called = false; rli.on('line', function(line) { called = true; - assert.equal(line, 'a'); + assert.strictEqual(line, 'a'); }); fi.emit('data', 'a'); assert.ok(!called); @@ -129,11 +129,11 @@ function isWarned(emitter) { let expectedLines = ['foo', 'bar', 'baz']; let callCount = 0; rli.on('line', function(line) { - assert.equal(line, expectedLines[callCount]); + assert.strictEqual(line, expectedLines[callCount]); callCount++; }); fi.emit('data', expectedLines.join('\n') + '\n'); - assert.equal(callCount, expectedLines.length); + assert.strictEqual(callCount, expectedLines.length); rli.close(); // sending multiple newlines at once that does not end with a new line @@ -142,11 +142,11 @@ function isWarned(emitter) { expectedLines = ['foo', 'bar', 'baz', 'bat']; callCount = 0; rli.on('line', function(line) { - assert.equal(line, expectedLines[callCount]); + assert.strictEqual(line, expectedLines[callCount]); callCount++; }); fi.emit('data', expectedLines.join('\n')); - assert.equal(callCount, expectedLines.length - 1); + assert.strictEqual(callCount, expectedLines.length - 1); rli.close(); // sending multiple newlines at once that does not end with a new(empty) @@ -156,7 +156,7 @@ function isWarned(emitter) { expectedLines = ['foo', 'bar', 'baz', '']; callCount = 0; rli.on('line', function(line) { - assert.equal(line, expectedLines[callCount]); + assert.strictEqual(line, expectedLines[callCount]); callCount++; }); rli.on('close', function() { @@ -164,7 +164,7 @@ function isWarned(emitter) { }); fi.emit('data', expectedLines.join('\n')); fi.emit('end'); - assert.equal(callCount, expectedLines.length); + assert.strictEqual(callCount, expectedLines.length); rli.close(); // sending multiple newlines at once that does not end with a new line @@ -176,11 +176,11 @@ function isWarned(emitter) { expectedLines = ['foo', 'bar', 'baz', 'bat']; callCount = 0; rli.on('line', function(line) { - assert.equal(line, expectedLines[callCount]); + assert.strictEqual(line, expectedLines[callCount]); callCount++; }); fi.emit('data', expectedLines.join('\r\n')); - assert.equal(callCount, expectedLines.length - 1); + assert.strictEqual(callCount, expectedLines.length - 1); rli.close(); // \r\n should emit one line event when split across multiple writes. @@ -189,14 +189,14 @@ function isWarned(emitter) { expectedLines = ['foo', 'bar', 'baz', 'bat']; callCount = 0; rli.on('line', function(line) { - assert.equal(line, expectedLines[callCount]); + assert.strictEqual(line, expectedLines[callCount]); callCount++; }); expectedLines.forEach(function(line) { fi.emit('data', line + '\r'); fi.emit('data', '\n'); }); - assert.equal(callCount, expectedLines.length); + assert.strictEqual(callCount, expectedLines.length); rli.close(); // \r should behave like \n when alone @@ -205,11 +205,11 @@ function isWarned(emitter) { expectedLines = ['foo', 'bar', 'baz', 'bat']; callCount = 0; rli.on('line', function(line) { - assert.equal(line, expectedLines[callCount]); + assert.strictEqual(line, expectedLines[callCount]); callCount++; }); fi.emit('data', expectedLines.join('\r')); - assert.equal(callCount, expectedLines.length - 1); + assert.strictEqual(callCount, expectedLines.length - 1); rli.close(); // \r at start of input should output blank line @@ -218,11 +218,11 @@ function isWarned(emitter) { expectedLines = ['', 'foo' ]; callCount = 0; rli.on('line', function(line) { - assert.equal(line, expectedLines[callCount]); + assert.strictEqual(line, expectedLines[callCount]); callCount++; }); fi.emit('data', '\rfoo\r'); - assert.equal(callCount, expectedLines.length); + assert.strictEqual(callCount, expectedLines.length); rli.close(); // Emit two line events when the delay @@ -243,7 +243,7 @@ function isWarned(emitter) { fi.emit('data', '\r'); setTimeout(common.mustCall(() => { fi.emit('data', '\n'); - assert.equal(callCount, 2); + assert.strictEqual(callCount, 2); rli.close(); }), delay * 2); } @@ -254,7 +254,7 @@ function isWarned(emitter) { rli = new readline.Interface({ input: fi, output: fi, terminal: true }); called = false; rli.on('line', function(line) { - assert.equal(line, '\t'); + assert.strictEqual(line, '\t'); assert.strictEqual(called, false); called = true; }); @@ -276,7 +276,7 @@ function isWarned(emitter) { }); called = false; rli.on('line', function(line) { - assert.equal(line, 'foo'); + assert.strictEqual(line, 'foo'); assert.strictEqual(called, false); called = true; }); @@ -310,14 +310,14 @@ function isWarned(emitter) { callCount = 0; rli.on('line', function(line) { callCount++; - assert.equal(line, buf.toString('utf8')); + assert.strictEqual(line, buf.toString('utf8')); }); [].forEach.call(buf, function(i) { fi.emit('data', Buffer.from([i])); }); - assert.equal(callCount, 0); + assert.strictEqual(callCount, 0); fi.emit('data', '\n'); - assert.equal(callCount, 1); + assert.strictEqual(callCount, 1); rli.close(); // Regression test for repl freeze, #1968: @@ -335,7 +335,7 @@ function isWarned(emitter) { fi.emit('data', 'fooX'); } catch (e) { } fi.emit('data', 'bar'); - assert.equal(keys.join(''), 'fooXbar'); + assert.strictEqual(keys.join(''), 'fooXbar'); rli.close(); // calling readline without `new` @@ -344,7 +344,7 @@ function isWarned(emitter) { called = false; rli.on('line', function(line) { called = true; - assert.equal(line, 'asdf'); + assert.strictEqual(line, 'asdf'); }); fi.emit('data', 'asdf\n'); assert.ok(called); @@ -359,8 +359,8 @@ function isWarned(emitter) { rli.close(); }); let cursorPos = rli._getCursorPos(); - assert.equal(cursorPos.rows, 0); - assert.equal(cursorPos.cols, expectedLines[0].length); + assert.strictEqual(cursorPos.rows, 0); + assert.strictEqual(cursorPos.cols, expectedLines[0].length); rli.close(); // sending a multi-line question @@ -371,8 +371,8 @@ function isWarned(emitter) { rli.close(); }); cursorPos = rli._getCursorPos(); - assert.equal(cursorPos.rows, expectedLines.length - 1); - assert.equal(cursorPos.cols, expectedLines.slice(-1)[0].length); + assert.strictEqual(cursorPos.rows, expectedLines.length - 1); + assert.strictEqual(cursorPos.cols, expectedLines.slice(-1)[0].length); rli.close(); } @@ -382,23 +382,24 @@ function isWarned(emitter) { }); // wide characters should be treated as two columns. - assert.equal(readline.isFullWidthCodePoint('a'.charCodeAt(0)), false); - assert.equal(readline.isFullWidthCodePoint('あ'.charCodeAt(0)), true); - assert.equal(readline.isFullWidthCodePoint('谢'.charCodeAt(0)), true); - assert.equal(readline.isFullWidthCodePoint('고'.charCodeAt(0)), true); - assert.equal(readline.isFullWidthCodePoint(0x1f251), true); // surrogate - assert.equal(readline.codePointAt('ABC', 0), 0x41); - assert.equal(readline.codePointAt('あいう', 1), 0x3044); - assert.equal(readline.codePointAt('\ud800\udc00', 0), // surrogate - 0x10000); - assert.equal(readline.codePointAt('\ud800\udc00A', 2), // surrogate - 0x41); - assert.equal(readline.getStringWidth('abcde'), 5); - assert.equal(readline.getStringWidth('古池や'), 6); - assert.equal(readline.getStringWidth('ノード.js'), 9); - assert.equal(readline.getStringWidth('你好'), 4); - assert.equal(readline.getStringWidth('안녕하세요'), 10); - assert.equal(readline.getStringWidth('A\ud83c\ude00BC'), 5); // surrogate + assert.strictEqual(readline.isFullWidthCodePoint('a'.charCodeAt(0)), false); + assert.strictEqual(readline.isFullWidthCodePoint('あ'.charCodeAt(0)), true); + assert.strictEqual(readline.isFullWidthCodePoint('谢'.charCodeAt(0)), true); + assert.strictEqual(readline.isFullWidthCodePoint('고'.charCodeAt(0)), true); + assert.strictEqual(readline.isFullWidthCodePoint(0x1f251), true); // surrogate + assert.strictEqual(readline.codePointAt('ABC', 0), 0x41); + assert.strictEqual(readline.codePointAt('あいう', 1), 0x3044); + assert.strictEqual(readline.codePointAt('\ud800\udc00', 0), // surrogate + 0x10000); + assert.strictEqual(readline.codePointAt('\ud800\udc00A', 2), // surrogate + 0x41); + assert.strictEqual(readline.getStringWidth('abcde'), 5); + assert.strictEqual(readline.getStringWidth('古池や'), 6); + assert.strictEqual(readline.getStringWidth('ノード.js'), 9); + assert.strictEqual(readline.getStringWidth('你好'), 4); + assert.strictEqual(readline.getStringWidth('안녕하세요'), 10); + assert.strictEqual(readline.getStringWidth('A\ud83c\ude00BC'), + 5); // surrogate // check if vt control chars are stripped assert.strictEqual( @@ -417,10 +418,10 @@ function isWarned(emitter) { readline.stripVTControlCharacters('> '), '> ' ); - assert.equal(readline.getStringWidth('\u001b[31m> \u001b[39m'), 2); - assert.equal(readline.getStringWidth('\u001b[31m> \u001b[39m> '), 4); - assert.equal(readline.getStringWidth('\u001b[31m\u001b[39m'), 0); - assert.equal(readline.getStringWidth('> '), 2); + assert.strictEqual(readline.getStringWidth('\u001b[31m> \u001b[39m'), 2); + assert.strictEqual(readline.getStringWidth('\u001b[31m> \u001b[39m> '), 4); + assert.strictEqual(readline.getStringWidth('\u001b[31m\u001b[39m'), 0); + assert.strictEqual(readline.getStringWidth('> '), 2); assert.deepStrictEqual(fi.listeners(terminal ? 'keypress' : 'data'), []); @@ -431,8 +432,8 @@ function isWarned(emitter) { output: process.stdout }); rl.close(); - assert.equal(isWarned(process.stdin._events), false); - assert.equal(isWarned(process.stdout._events), false); + assert.strictEqual(isWarned(process.stdin._events), false); + assert.strictEqual(isWarned(process.stdout._events), false); } //can create a new readline Interface with a null output arugument @@ -442,7 +443,7 @@ function isWarned(emitter) { called = false; rli.on('line', function(line) { called = true; - assert.equal(line, 'asdf'); + assert.strictEqual(line, 'asdf'); }); fi.emit('data', 'asdf\n'); assert.ok(called); diff --git a/test/parallel/test-readline-set-raw-mode.js b/test/parallel/test-readline-set-raw-mode.js index 78c42f5f5f627d..389f014bc3e19a 100644 --- a/test/parallel/test-readline-set-raw-mode.js +++ b/test/parallel/test-readline-set-raw-mode.js @@ -12,7 +12,7 @@ let pauseCalled = false; stream.setRawMode = function(mode) { rawModeCalled = true; - assert.equal(mode, expectedRawMode); + assert.strictEqual(mode, expectedRawMode); }; stream.resume = function() { resumeCalled = true; @@ -66,4 +66,4 @@ assert(pauseCalled); assert.deepStrictEqual(stream.listeners('keypress'), []); // one data listener for the keypress events. -assert.equal(stream.listeners('data').length, 1); +assert.strictEqual(stream.listeners('data').length, 1); diff --git a/test/parallel/test-readuint.js b/test/parallel/test-readuint.js index 0d1f79b12eabd4..d1507a81b5188a 100644 --- a/test/parallel/test-readuint.js +++ b/test/parallel/test-readuint.js @@ -20,13 +20,13 @@ function test8(clazz) { data[1] = 23; data[2] = 23; data[3] = 23; - assert.equal(23, data.readUInt8(0)); - assert.equal(23, data.readUInt8(1)); - assert.equal(23, data.readUInt8(2)); - assert.equal(23, data.readUInt8(3)); + assert.strictEqual(23, data.readUInt8(0)); + assert.strictEqual(23, data.readUInt8(1)); + assert.strictEqual(23, data.readUInt8(2)); + assert.strictEqual(23, data.readUInt8(3)); data[0] = 255; /* If it became a signed int, would be -1 */ - assert.equal(255, data.readUInt8(0)); + assert.strictEqual(255, data.readUInt8(0)); } @@ -45,17 +45,17 @@ function test16(clazz) { data[1] = 0x23; data[2] = 0x42; data[3] = 0x3f; - assert.equal(0x23, data.readUInt16BE(0)); - assert.equal(0x2342, data.readUInt16BE(1)); - assert.equal(0x423f, data.readUInt16BE(2)); - assert.equal(0x2300, data.readUInt16LE(0)); - assert.equal(0x4223, data.readUInt16LE(1)); - assert.equal(0x3f42, data.readUInt16LE(2)); + assert.strictEqual(0x23, data.readUInt16BE(0)); + assert.strictEqual(0x2342, data.readUInt16BE(1)); + assert.strictEqual(0x423f, data.readUInt16BE(2)); + assert.strictEqual(0x2300, data.readUInt16LE(0)); + assert.strictEqual(0x4223, data.readUInt16LE(1)); + assert.strictEqual(0x3f42, data.readUInt16LE(2)); data[0] = 0xfe; data[1] = 0xfe; - assert.equal(0xfefe, data.readUInt16BE(0)); - assert.equal(0xfefe, data.readUInt16LE(0)); + assert.strictEqual(0xfefe, data.readUInt16BE(0)); + assert.strictEqual(0xfefe, data.readUInt16LE(0)); } @@ -75,12 +75,12 @@ function test32(clazz) { data[3] = 0x56; data[4] = 0x23; data[5] = 0xff; - assert.equal(0x32654256, data.readUInt32BE(0)); - assert.equal(0x65425623, data.readUInt32BE(1)); - assert.equal(0x425623ff, data.readUInt32BE(2)); - assert.equal(0x56426532, data.readUInt32LE(0)); - assert.equal(0x23564265, data.readUInt32LE(1)); - assert.equal(0xff235642, data.readUInt32LE(2)); + assert.strictEqual(0x32654256, data.readUInt32BE(0)); + assert.strictEqual(0x65425623, data.readUInt32BE(1)); + assert.strictEqual(0x425623ff, data.readUInt32BE(2)); + assert.strictEqual(0x56426532, data.readUInt32LE(0)); + assert.strictEqual(0x23564265, data.readUInt32LE(1)); + assert.strictEqual(0xff235642, data.readUInt32LE(2)); } diff --git a/test/parallel/test-regress-GH-1899.js b/test/parallel/test-regress-GH-1899.js index 838391acd23b5f..a072bc551a5c4f 100644 --- a/test/parallel/test-regress-GH-1899.js +++ b/test/parallel/test-regress-GH-1899.js @@ -14,6 +14,6 @@ child.stdout.on('data', function(data) { }); child.on('exit', function(code, signal) { - assert.equal(code, 0); - assert.equal(output, 'hello, world!\n'); + assert.strictEqual(code, 0); + assert.strictEqual(output, 'hello, world!\n'); }); diff --git a/test/parallel/test-regress-GH-5051.js b/test/parallel/test-regress-GH-5051.js index a86d0943d313fe..f2562bd7eb8020 100644 --- a/test/parallel/test-regress-GH-5051.js +++ b/test/parallel/test-regress-GH-5051.js @@ -13,8 +13,8 @@ agent.maxSockets = 0; // localAddress is used when naming requests / sockets // while using the Legacy API agent.addRequest(req, 'localhost', common.PORT, '127.0.0.1'); -assert.equal(Object.keys(agent.requests).length, 1); -assert.equal( +assert.strictEqual(Object.keys(agent.requests).length, 1); +assert.strictEqual( Object.keys(agent.requests)[0], 'localhost:' + common.PORT + ':127.0.0.1'); @@ -25,7 +25,7 @@ agent.addRequest(req, { localAddress: '127.0.0.1', path: '/foo' }); -assert.equal(Object.keys(agent.requests).length, 1); -assert.equal( +assert.strictEqual(Object.keys(agent.requests).length, 1); +assert.strictEqual( Object.keys(agent.requests)[0], 'localhost:' + common.PORT + ':127.0.0.1'); diff --git a/test/parallel/test-regress-GH-5727.js b/test/parallel/test-regress-GH-5727.js index 3f52c55e7aaca6..5fe9776d9b30fc 100644 --- a/test/parallel/test-regress-GH-5727.js +++ b/test/parallel/test-regress-GH-5727.js @@ -10,7 +10,7 @@ net.Server().listen(common.PORT, function() { const address = this.address(); const key = `${address.family.slice(-1)}:${address.address}:${common.PORT}`; - assert.equal(this._connectionKey, key); + assert.strictEqual(this._connectionKey, key); this.close(); }); diff --git a/test/parallel/test-regress-GH-7511.js b/test/parallel/test-regress-GH-7511.js index 11bb5bfd4cb170..a7ce8311d7237f 100644 --- a/test/parallel/test-regress-GH-7511.js +++ b/test/parallel/test-regress-GH-7511.js @@ -6,5 +6,5 @@ const vm = require('vm'); assert.doesNotThrow(function() { const context = vm.createContext({ process: process }); const result = vm.runInContext('process.env["PATH"]', context); - assert.notEqual(undefined, result); + assert.notStrictEqual(undefined, result); }); diff --git a/test/parallel/test-regress-GH-node-9326.js b/test/parallel/test-regress-GH-node-9326.js index f32f45cbd02943..78565e3f596594 100644 --- a/test/parallel/test-regress-GH-node-9326.js +++ b/test/parallel/test-regress-GH-node-9326.js @@ -10,5 +10,5 @@ const cp = child_process.spawn(process.execPath, [ ]); cp.on('exit', function(code) { - assert.notEqual(code, 0); + assert.notStrictEqual(code, 0); }); diff --git a/test/parallel/test-repl-.save.load.js b/test/parallel/test-repl-.save.load.js index 00d5f6791d54a5..449dd28e90d59e 100644 --- a/test/parallel/test-repl-.save.load.js +++ b/test/parallel/test-repl-.save.load.js @@ -27,7 +27,8 @@ putIn.run(testFile); putIn.run(['.save ' + saveFileName]); // the file should have what I wrote -assert.equal(fs.readFileSync(saveFileName, 'utf8'), testFile.join('\n') + '\n'); +assert.strictEqual(fs.readFileSync(saveFileName, 'utf8'), testFile.join('\n') + + '\n'); { // save .editor mode code @@ -74,7 +75,7 @@ let loadFile = join(common.tmpDir, 'file.does.not.exist'); // should not break putIn.write = function(data) { // make sure I get a failed to load message and not some crazy error - assert.equal(data, 'Failed to load:' + loadFile + '\n'); + assert.strictEqual(data, 'Failed to load:' + loadFile + '\n'); // eat me to avoid work putIn.write = function() {}; }; @@ -83,7 +84,8 @@ putIn.run(['.load ' + loadFile]); // throw error on loading directory loadFile = common.tmpDir; putIn.write = function(data) { - assert.equal(data, 'Failed to load:' + loadFile + ' is not a valid file\n'); + assert.strictEqual(data, 'Failed to load:' + loadFile + + ' is not a valid file\n'); putIn.write = function() {}; }; putIn.run(['.load ' + loadFile]); @@ -98,7 +100,7 @@ const invalidFileName = join(common.tmpDir, '\0\0\0\0\0'); // should not break putIn.write = function(data) { // make sure I get a failed to save message and not some other error - assert.equal(data, 'Failed to save:' + invalidFileName + '\n'); + assert.strictEqual(data, 'Failed to save:' + invalidFileName + '\n'); // reset to no-op putIn.write = function() {}; }; diff --git a/test/parallel/test-repl-autolibs.js b/test/parallel/test-repl-autolibs.js index 859ff5c3c9652a..74d400e2e226c6 100644 --- a/test/parallel/test-repl-autolibs.js +++ b/test/parallel/test-repl-autolibs.js @@ -19,9 +19,10 @@ function test1() { if (data.length) { // inspect output matches repl output - assert.equal(data, util.inspect(require('fs'), null, 2, false) + '\n'); + assert.strictEqual(data, util.inspect(require('fs'), null, 2, false) + + '\n'); // globally added lib matches required lib - assert.equal(global.fs, require('fs')); + assert.strictEqual(global.fs, require('fs')); test2(); } }; @@ -36,9 +37,9 @@ function test2() { gotWrite = true; if (data.length) { // repl response error message - assert.equal(data, '{}\n'); + assert.strictEqual(data, '{}\n'); // original value wasn't overwritten - assert.equal(val, global.url); + assert.strictEqual(val, global.url); } }; let val = {}; diff --git a/test/parallel/test-repl-end-emits-exit.js b/test/parallel/test-repl-end-emits-exit.js index 661f9f0ad0e3a4..c62a51c9626e24 100644 --- a/test/parallel/test-repl-end-emits-exit.js +++ b/test/parallel/test-repl-end-emits-exit.js @@ -45,8 +45,8 @@ function testRegularMode() { } process.on('exit', function() { - assert.equal(terminalExit, 1); - assert.equal(regularExit, 1); + assert.strictEqual(terminalExit, 1); + assert.strictEqual(regularExit, 1); }); diff --git a/test/parallel/test-repl-envvars.js b/test/parallel/test-repl-envvars.js index b08f6cbaf621e6..a5e48a66454758 100644 --- a/test/parallel/test-repl-envvars.js +++ b/test/parallel/test-repl-envvars.js @@ -50,10 +50,10 @@ function run(test) { // The REPL registers 'module' and 'require' globals common.allowGlobals(repl.context.module, repl.context.require); - assert.equal(expected.terminal, repl.terminal, - 'Expected ' + inspect(expected) + ' with ' + inspect(env)); - assert.equal(expected.useColors, repl.useColors, - 'Expected ' + inspect(expected) + ' with ' + inspect(env)); + assert.strictEqual(expected.terminal, repl.terminal, 'Expected ' + + inspect(expected) + ' with ' + inspect(env)); + assert.strictEqual(expected.useColors, repl.useColors, 'Expected ' + + inspect(expected) + ' with ' + inspect(env)); repl.close(); }); } diff --git a/test/parallel/test-repl-options.js b/test/parallel/test-repl-options.js index 79994c66d148c0..03db110aca6dbc 100644 --- a/test/parallel/test-repl-options.js +++ b/test/parallel/test-repl-options.js @@ -15,24 +15,24 @@ const r1 = repl.start({ terminal: true }); -assert.equal(r1.input, stream); -assert.equal(r1.output, stream); -assert.equal(r1.input, r1.inputStream); -assert.equal(r1.output, r1.outputStream); -assert.equal(r1.terminal, true); -assert.equal(r1.useColors, r1.terminal); -assert.equal(r1.useGlobal, false); -assert.equal(r1.ignoreUndefined, false); -assert.equal(r1.replMode, repl.REPL_MODE_SLOPPY); -assert.equal(r1.historySize, 30); +assert.strictEqual(r1.input, stream); +assert.strictEqual(r1.output, stream); +assert.strictEqual(r1.input, r1.inputStream); +assert.strictEqual(r1.output, r1.outputStream); +assert.strictEqual(r1.terminal, true); +assert.strictEqual(r1.useColors, r1.terminal); +assert.strictEqual(r1.useGlobal, false); +assert.strictEqual(r1.ignoreUndefined, false); +assert.strictEqual(r1.replMode, repl.REPL_MODE_SLOPPY); +assert.strictEqual(r1.historySize, 30); // test r1 for backwards compact -assert.equal(r1.rli.input, stream); -assert.equal(r1.rli.output, stream); -assert.equal(r1.rli.input, r1.inputStream); -assert.equal(r1.rli.output, r1.outputStream); -assert.equal(r1.rli.terminal, true); -assert.equal(r1.useColors, r1.rli.terminal); +assert.strictEqual(r1.rli.input, stream); +assert.strictEqual(r1.rli.output, stream); +assert.strictEqual(r1.rli.input, r1.inputStream); +assert.strictEqual(r1.rli.output, r1.outputStream); +assert.strictEqual(r1.rli.terminal, true); +assert.strictEqual(r1.useColors, r1.rli.terminal); // 2 function writer() {} @@ -48,23 +48,23 @@ const r2 = repl.start({ writer: writer, replMode: repl.REPL_MODE_STRICT }); -assert.equal(r2.input, stream); -assert.equal(r2.output, stream); -assert.equal(r2.input, r2.inputStream); -assert.equal(r2.output, r2.outputStream); -assert.equal(r2.terminal, false); -assert.equal(r2.useColors, true); -assert.equal(r2.useGlobal, true); -assert.equal(r2.ignoreUndefined, true); -assert.equal(r2.writer, writer); -assert.equal(r2.replMode, repl.REPL_MODE_STRICT); +assert.strictEqual(r2.input, stream); +assert.strictEqual(r2.output, stream); +assert.strictEqual(r2.input, r2.inputStream); +assert.strictEqual(r2.output, r2.outputStream); +assert.strictEqual(r2.terminal, false); +assert.strictEqual(r2.useColors, true); +assert.strictEqual(r2.useGlobal, true); +assert.strictEqual(r2.ignoreUndefined, true); +assert.strictEqual(r2.writer, writer); +assert.strictEqual(r2.replMode, repl.REPL_MODE_STRICT); // test r2 for backwards compact -assert.equal(r2.rli.input, stream); -assert.equal(r2.rli.output, stream); -assert.equal(r2.rli.input, r2.inputStream); -assert.equal(r2.rli.output, r2.outputStream); -assert.equal(r2.rli.terminal, false); +assert.strictEqual(r2.rli.input, stream); +assert.strictEqual(r2.rli.output, stream); +assert.strictEqual(r2.rli.input, r2.inputStream); +assert.strictEqual(r2.rli.output, r2.outputStream); +assert.strictEqual(r2.rli.terminal, false); // testing out "magic" replMode const r3 = repl.start({ @@ -75,8 +75,8 @@ const r3 = repl.start({ historySize: 50 }); -assert.equal(r3.replMode, repl.REPL_MODE_MAGIC); -assert.equal(r3.historySize, 50); +assert.strictEqual(r3.replMode, repl.REPL_MODE_MAGIC); +assert.strictEqual(r3.historySize, 50); // Verify that defaults are used when no arguments are provided const r4 = repl.start(); diff --git a/test/parallel/test-repl-require-cache.js b/test/parallel/test-repl-require-cache.js index 8a5d384935efd4..4ccabe473cdbe8 100644 --- a/test/parallel/test-repl-require-cache.js +++ b/test/parallel/test-repl-require-cache.js @@ -6,8 +6,8 @@ const repl = require('repl'); // https://github.com/joyent/node/issues/3226 require.cache.something = 1; -assert.equal(require.cache.something, 1); +assert.strictEqual(require.cache.something, 1); repl.start({ useGlobal: false }).close(); -assert.equal(require.cache.something, 1); +assert.strictEqual(require.cache.something, 1); diff --git a/test/parallel/test-repl-syntax-error-handling.js b/test/parallel/test-repl-syntax-error-handling.js index 6a65d53a029379..9014f9a02f22be 100644 --- a/test/parallel/test-repl-syntax-error-handling.js +++ b/test/parallel/test-repl-syntax-error-handling.js @@ -27,7 +27,7 @@ function parent() { out += c; }); child.stdout.on('end', function() { - assert.equal(out, '10\n'); + assert.strictEqual(out, '10\n'); console.log('ok - got expected output'); }); diff --git a/test/parallel/test-repl-tab.js b/test/parallel/test-repl-tab.js index a381d603fbeb84..2cdf7b9e0ae75e 100644 --- a/test/parallel/test-repl-tab.js +++ b/test/parallel/test-repl-tab.js @@ -14,5 +14,5 @@ const testMe = repl.start('', putIn, function(cmd, context, testMe._domain.on('error', common.fail); testMe.complete('', function(err, results) { - assert.equal(err, null); + assert.strictEqual(err, null); }); diff --git a/test/parallel/test-require-extensions-same-filename-as-dir-trailing-slash.js b/test/parallel/test-require-extensions-same-filename-as-dir-trailing-slash.js index 0a80a860388de9..85fc7ec913482d 100644 --- a/test/parallel/test-require-extensions-same-filename-as-dir-trailing-slash.js +++ b/test/parallel/test-require-extensions-same-filename-as-dir-trailing-slash.js @@ -6,5 +6,5 @@ const assert = require('assert'); const content = require(common.fixturesDir + '/json-with-directory-name-module/module-stub/one-trailing-slash/two/three.js'); -assert.notEqual(content.rocko, 'artischocko'); -assert.equal(content, 'hello from module-stub!'); +assert.notStrictEqual(content.rocko, 'artischocko'); +assert.strictEqual(content, 'hello from module-stub!'); diff --git a/test/parallel/test-require-unicode.js b/test/parallel/test-require-unicode.js index 0bccf06916c326..93a8787cdfe7c8 100644 --- a/test/parallel/test-require-unicode.js +++ b/test/parallel/test-require-unicode.js @@ -12,5 +12,5 @@ fs.mkdirSync(dirname); fs.writeFileSync(path.join(dirname, 'file.js'), 'module.exports = 42;'); fs.writeFileSync(path.join(dirname, 'package.json'), JSON.stringify({ name: 'test', main: 'file.js' })); -assert.equal(require(dirname), 42); -assert.equal(require(path.join(dirname, 'file.js')), 42); +assert.strictEqual(require(dirname), 42); +assert.strictEqual(require(path.join(dirname, 'file.js')), 42); diff --git a/test/parallel/test-socket-write-after-fin-error.js b/test/parallel/test-socket-write-after-fin-error.js index 58ae1d62b2f172..37d042b4c6031a 100644 --- a/test/parallel/test-socket-write-after-fin-error.js +++ b/test/parallel/test-socket-write-after-fin-error.js @@ -43,13 +43,13 @@ server.listen(0, function() { }); process.on('exit', function() { - assert.equal(clientData, ''); - assert.equal(serverData, 'hello1hello2hello3\nTHUNDERMUSCLE!'); + assert.strictEqual(clientData, ''); + assert.strictEqual(serverData, 'hello1hello2hello3\nTHUNDERMUSCLE!'); assert(gotClientEnd); assert(gotServerEnd); assert(gotServerError); - assert.equal(gotServerError.code, 'EPIPE'); - assert.notEqual(gotServerError.message, 'write after end'); + assert.strictEqual(gotServerError.code, 'EPIPE'); + assert.notStrictEqual(gotServerError.message, 'write after end'); console.log('ok'); }); diff --git a/test/parallel/test-stdin-child-proc.js b/test/parallel/test-stdin-child-proc.js index 35ae0c99d3c8ff..5359edc53a42ba 100644 --- a/test/parallel/test-stdin-child-proc.js +++ b/test/parallel/test-stdin-child-proc.js @@ -9,5 +9,5 @@ const cp = child_process.spawn(process.execPath, [path.resolve(__dirname, 'test-stdin-pause-resume.js')]); cp.on('exit', common.mustCall((code) => { - assert.equal(code, 0); + assert.strictEqual(code, 0); })); diff --git a/test/parallel/test-stdin-pipe-resume.js b/test/parallel/test-stdin-pipe-resume.js index 06cce3edfe403f..e9000933a37cfa 100644 --- a/test/parallel/test-stdin-pipe-resume.js +++ b/test/parallel/test-stdin-pipe-resume.js @@ -14,7 +14,7 @@ if (process.argv[2] === 'child') { }); child.stdout.on('close', function() { const b = Buffer.concat(buffers).toString(); - assert.equal(b, 'Hello, world\n'); + assert.strictEqual(b, 'Hello, world\n'); console.log('ok'); }); child.stdin.write('Hel'); diff --git a/test/parallel/test-stdout-cannot-be-closed-child-process-pipe.js b/test/parallel/test-stdout-cannot-be-closed-child-process-pipe.js index aa1939ebe2c334..d19b522e290ba9 100644 --- a/test/parallel/test-stdout-cannot-be-closed-child-process-pipe.js +++ b/test/parallel/test-stdout-cannot-be-closed-child-process-pipe.js @@ -25,7 +25,7 @@ function parent() { child.on('close', function(code, signal) { assert(code); - assert.equal(out, 'foo'); + assert.strictEqual(out, 'foo'); assert(/process\.stdout cannot be closed/.test(err)); console.log('ok'); }); diff --git a/test/parallel/test-stdout-stderr-reading.js b/test/parallel/test-stdout-stderr-reading.js index 6aa961301349fc..11cdcc390768a3 100644 --- a/test/parallel/test-stdout-stderr-reading.js +++ b/test/parallel/test-stdout-stderr-reading.js @@ -36,7 +36,7 @@ function parent() { c1.on('close', common.mustCall(function(code, signal) { assert(!code); assert(!signal); - assert.equal(c1out, 'ok\n'); + assert.strictEqual(c1out, 'ok\n'); console.log('ok'); })); @@ -53,7 +53,7 @@ function parent() { c2.on('close', common.mustCall(function(code, signal) { assert(!code); assert(!signal); - assert.equal(c2out, 'ok\n'); + assert.strictEqual(c2out, 'ok\n'); console.log('ok'); })); } diff --git a/test/parallel/test-stream-base-no-abort.js b/test/parallel/test-stream-base-no-abort.js index 87c8f963485ab8..5a26f04e5567b2 100644 --- a/test/parallel/test-stream-base-no-abort.js +++ b/test/parallel/test-stream-base-no-abort.js @@ -12,21 +12,21 @@ const providers = Object.keys(async_wrap.Providers); let flags = 0; // Make sure all asserts have run at least once. -process.on('exit', () => assert.equal(flags, 0b111)); +process.on('exit', () => assert.strictEqual(flags, 0b111)); function init(id, provider) { this._external; // Test will abort if nullptr isn't properly checked. switch (providers[provider]) { case 'TCPWRAP': - assert.equal(this.fd, uv.UV_EINVAL); + assert.strictEqual(this.fd, uv.UV_EINVAL); flags |= 0b1; break; case 'TLSWRAP': - assert.equal(this.fd, uv.UV_EINVAL); + assert.strictEqual(this.fd, uv.UV_EINVAL); flags |= 0b10; break; case 'UDPWRAP': - assert.equal(this.fd, uv.UV_EBADF); + assert.strictEqual(this.fd, uv.UV_EBADF); flags |= 0b100; break; } diff --git a/test/parallel/test-stream-push-strings.js b/test/parallel/test-stream-push-strings.js index 7bce493bbd33ce..e77d8a48c679ef 100644 --- a/test/parallel/test-stream-push-strings.js +++ b/test/parallel/test-stream-push-strings.js @@ -40,7 +40,7 @@ ms.on('readable', function() { const expect = [ 'first chunksecond to last chunk', 'last chunk' ]; process.on('exit', function() { - assert.equal(ms._chunks, -1); + assert.strictEqual(ms._chunks, -1); assert.deepStrictEqual(results, expect); console.log('ok'); }); diff --git a/test/parallel/test-stream-readable-constructor-set-methods.js b/test/parallel/test-stream-readable-constructor-set-methods.js index a5d7e48bfb3fa9..e5e3114de456db 100644 --- a/test/parallel/test-stream-readable-constructor-set-methods.js +++ b/test/parallel/test-stream-readable-constructor-set-methods.js @@ -14,6 +14,6 @@ const r = new Readable({ read: _read }); r.resume(); process.on('exit', function() { - assert.equal(r._read, _read); + assert.strictEqual(r._read, _read); assert(_readCalled); }); diff --git a/test/parallel/test-stream-readable-flow-recursion.js b/test/parallel/test-stream-readable-flow-recursion.js index b1e421a71fd15b..e29553900511c3 100644 --- a/test/parallel/test-stream-readable-flow-recursion.js +++ b/test/parallel/test-stream-readable-flow-recursion.js @@ -45,12 +45,12 @@ flow(stream, 5000, function() { }); process.on('exit', function(code) { - assert.equal(reads, 2); + assert.strictEqual(reads, 2); // we pushed up the high water mark - assert.equal(stream._readableState.highWaterMark, 8192); + assert.strictEqual(stream._readableState.highWaterMark, 8192); // length is 0 right now, because we pulled it all out. - assert.equal(stream._readableState.length, 0); + assert.strictEqual(stream._readableState.length, 0); assert(!code); - assert.equal(depth, 0); + assert.strictEqual(depth, 0); console.log('ok'); }); diff --git a/test/parallel/test-stream-transform-constructor-set-methods.js b/test/parallel/test-stream-transform-constructor-set-methods.js index 7be673c517b30b..02ef9f55cb4460 100644 --- a/test/parallel/test-stream-transform-constructor-set-methods.js +++ b/test/parallel/test-stream-transform-constructor-set-methods.js @@ -25,8 +25,8 @@ t.end(Buffer.from('blerg')); t.resume(); process.on('exit', function() { - assert.equal(t._transform, _transform); - assert.equal(t._flush, _flush); + assert.strictEqual(t._transform, _transform); + assert.strictEqual(t._flush, _flush); assert(_transformCalled); assert(_flushCalled); }); diff --git a/test/parallel/test-stream-writable-change-default-encoding.js b/test/parallel/test-stream-writable-change-default-encoding.js index 9eac52bc1aea44..c3af66ce83701c 100644 --- a/test/parallel/test-stream-writable-change-default-encoding.js +++ b/test/parallel/test-stream-writable-change-default-encoding.js @@ -19,7 +19,7 @@ MyWritable.prototype._write = function(chunk, encoding, callback) { (function defaultCondingIsUtf8() { const m = new MyWritable(function(isBuffer, type, enc) { - assert.equal(enc, 'utf8'); + assert.strictEqual(enc, 'utf8'); }, { decodeStrings: false }); m.write('foo'); m.end(); @@ -27,7 +27,7 @@ MyWritable.prototype._write = function(chunk, encoding, callback) { (function changeDefaultEncodingToAscii() { const m = new MyWritable(function(isBuffer, type, enc) { - assert.equal(enc, 'ascii'); + assert.strictEqual(enc, 'ascii'); }, { decodeStrings: false }); m.setDefaultEncoding('ascii'); m.write('bar'); @@ -44,7 +44,7 @@ assert.throws(function changeDefaultEncodingToInvalidValue() { (function checkVairableCaseEncoding() { const m = new MyWritable(function(isBuffer, type, enc) { - assert.equal(enc, 'ascii'); + assert.strictEqual(enc, 'ascii'); }, { decodeStrings: false }); m.setDefaultEncoding('AsCii'); m.write('bar'); diff --git a/test/parallel/test-stream-writable-constructor-set-methods.js b/test/parallel/test-stream-writable-constructor-set-methods.js index 9b344487f61580..a12112d1ecc266 100644 --- a/test/parallel/test-stream-writable-constructor-set-methods.js +++ b/test/parallel/test-stream-writable-constructor-set-methods.js @@ -27,9 +27,9 @@ w2.write(Buffer.from('blerg')); w2.end(); process.on('exit', function() { - assert.equal(w._write, _write); + assert.strictEqual(w._write, _write); assert(_writeCalled); - assert.equal(w2._writev, _writev); - assert.equal(dLength, 2); + assert.strictEqual(w2._writev, _writev); + assert.strictEqual(dLength, 2); assert(_writevCalled); }); diff --git a/test/parallel/test-stream-writableState-uncorked-bufferedRequestCount.js b/test/parallel/test-stream-writableState-uncorked-bufferedRequestCount.js index 3751cd9de6461d..dbd306c53f9ccb 100644 --- a/test/parallel/test-stream-writableState-uncorked-bufferedRequestCount.js +++ b/test/parallel/test-stream-writableState-uncorked-bufferedRequestCount.js @@ -7,7 +7,7 @@ const stream = require('stream'); const writable = new stream.Writable(); writable._writev = common.mustCall((chunks, cb) => { - assert.equal(chunks.length, 2, 'two chunks to write'); + assert.strictEqual(chunks.length, 2, 'two chunks to write'); cb(); }, 1); diff --git a/test/parallel/test-stream-writev.js b/test/parallel/test-stream-writev.js index 91c064c102b490..7ca0c4b8957575 100644 --- a/test/parallel/test-stream-writev.js +++ b/test/parallel/test-stream-writev.js @@ -34,7 +34,7 @@ function test(decode, uncork, multi, next) { if (er) throw er; counter++; - assert.equal(counter, expect); + assert.strictEqual(counter, expect); }; } diff --git a/test/parallel/test-stream2-base64-single-char-read-end.js b/test/parallel/test-stream2-base64-single-char-read-end.js index 1b14b7f6b4517c..975ef2262490d5 100644 --- a/test/parallel/test-stream2-base64-single-char-read-end.js +++ b/test/parallel/test-stream2-base64-single-char-read-end.js @@ -26,7 +26,7 @@ dst._write = function(chunk, enc, cb) { }; src.on('end', function() { - assert.equal(Buffer.concat(accum) + '', 'MQ=='); + assert.strictEqual(Buffer.concat(accum) + '', 'MQ=='); clearTimeout(timeout); }); diff --git a/test/parallel/test-stream2-compatibility.js b/test/parallel/test-stream2-compatibility.js index f7c980791311da..a353da8dede305 100644 --- a/test/parallel/test-stream2-compatibility.js +++ b/test/parallel/test-stream2-compatibility.js @@ -26,7 +26,7 @@ TestReader.prototype._read = function(n) { const reader = new TestReader(); setImmediate(function() { - assert.equal(ondataCalled, 1); + assert.strictEqual(ondataCalled, 1); console.log('ok'); reader.push(null); }); diff --git a/test/parallel/test-stream2-objects.js b/test/parallel/test-stream2-objects.js index 6c00f1b8691364..cab838fbfc9acb 100644 --- a/test/parallel/test-stream2-objects.js +++ b/test/parallel/test-stream2-objects.js @@ -23,7 +23,7 @@ function run() { console.log('# %s', name); fn({ same: assert.deepStrictEqual, - equal: assert.equal, + equal: assert.strictEqual, end: function() { count--; run(); diff --git a/test/parallel/test-stream2-readable-from-list.js b/test/parallel/test-stream2-readable-from-list.js index f3f39507e89dab..54db1d1c182526 100644 --- a/test/parallel/test-stream2-readable-from-list.js +++ b/test/parallel/test-stream2-readable-from-list.js @@ -24,7 +24,7 @@ function run() { console.log('# %s', name); fn({ same: assert.deepStrictEqual, - equal: assert.equal, + equal: assert.strictEqual, end: function() { count--; run(); @@ -41,7 +41,7 @@ function bufferListFromArray(arr) { // ensure all tests have run process.on('exit', function() { - assert.equal(count, 0); + assert.strictEqual(count, 0); }); process.nextTick(run); diff --git a/test/parallel/test-stream2-readable-non-empty-end.js b/test/parallel/test-stream2-readable-non-empty-end.js index 66fae8274ecf3c..46481fe1dcda4c 100644 --- a/test/parallel/test-stream2-readable-non-empty-end.js +++ b/test/parallel/test-stream2-readable-non-empty-end.js @@ -45,7 +45,7 @@ function next() { // one to get the last byte let r = test.read(); assert(r); - assert.equal(r.length, 1); + assert.strictEqual(r.length, 1); r = test.read(); - assert.equal(r, null); + assert.strictEqual(r, null); } diff --git a/test/parallel/test-stream2-readable-wrap.js b/test/parallel/test-stream2-readable-wrap.js index 4c736c6f369514..3d680706049303 100644 --- a/test/parallel/test-stream2-readable-wrap.js +++ b/test/parallel/test-stream2-readable-wrap.js @@ -13,7 +13,7 @@ function runTest(highWaterMark, objectMode, produce) { const old = new EE(); const r = new Readable({ highWaterMark: highWaterMark, objectMode: objectMode }); - assert.equal(r, r.wrap(old)); + assert.strictEqual(r, r.wrap(old)); let ended = false; r.on('end', function() { @@ -85,6 +85,6 @@ const objectChunks = [ 5, 'a', false, 0, '', 'xyz', { x: 4 }, 7, [], 555 ]; runTest(1, true, function() { return objectChunks.shift(); }); process.on('exit', function() { - assert.equal(testRuns, completedRuns); + assert.strictEqual(testRuns, completedRuns); console.log('ok'); }); diff --git a/test/parallel/test-stream2-set-encoding.js b/test/parallel/test-stream2-set-encoding.js index fdbd81e61332b1..a207168f39a97e 100644 --- a/test/parallel/test-stream2-set-encoding.js +++ b/test/parallel/test-stream2-set-encoding.js @@ -23,7 +23,7 @@ function run() { console.log('# %s', name); fn({ same: assert.deepStrictEqual, - equal: assert.equal, + equal: assert.strictEqual, end: function() { count--; run(); @@ -33,7 +33,7 @@ function run() { // ensure all tests have run process.on('exit', function() { - assert.equal(count, 0); + assert.strictEqual(count, 0); }); process.nextTick(run); diff --git a/test/parallel/test-stream2-transform.js b/test/parallel/test-stream2-transform.js index d66f1f064375e4..2695ac21b752c4 100644 --- a/test/parallel/test-stream2-transform.js +++ b/test/parallel/test-stream2-transform.js @@ -23,7 +23,7 @@ function run() { console.log('# %s', name); fn({ same: assert.deepStrictEqual, - equal: assert.equal, + equal: assert.strictEqual, ok: assert, end: function() { count--; @@ -34,7 +34,7 @@ function run() { // ensure all tests have run process.on('exit', function() { - assert.equal(count, 0); + assert.strictEqual(count, 0); }); process.nextTick(run); diff --git a/test/parallel/test-stream2-unpipe-leak.js b/test/parallel/test-stream2-unpipe-leak.js index 1a1599ca32b4c7..8800a2bbc68e45 100644 --- a/test/parallel/test-stream2-unpipe-leak.js +++ b/test/parallel/test-stream2-unpipe-leak.js @@ -36,14 +36,14 @@ for (let i = 0; i < 10; i++) { src.unpipe(dest); } -assert.equal(src.listeners('end').length, 0); -assert.equal(src.listeners('readable').length, 0); - -assert.equal(dest.listeners('unpipe').length, 0); -assert.equal(dest.listeners('drain').length, 0); -assert.equal(dest.listeners('error').length, 0); -assert.equal(dest.listeners('close').length, 0); -assert.equal(dest.listeners('finish').length, 0); +assert.strictEqual(src.listeners('end').length, 0); +assert.strictEqual(src.listeners('readable').length, 0); + +assert.strictEqual(dest.listeners('unpipe').length, 0); +assert.strictEqual(dest.listeners('drain').length, 0); +assert.strictEqual(dest.listeners('error').length, 0); +assert.strictEqual(dest.listeners('close').length, 0); +assert.strictEqual(dest.listeners('finish').length, 0); console.error(src._readableState); process.on('exit', function() { diff --git a/test/parallel/test-stream3-cork-end.js b/test/parallel/test-stream3-cork-end.js index 230227e0b13ddb..7227f87ada7fa1 100644 --- a/test/parallel/test-stream3-cork-end.js +++ b/test/parallel/test-stream3-cork-end.js @@ -22,7 +22,7 @@ w._write = function(chunk, encoding, cb) { // stream end event is not seen before the last write assert.ok(!seenEnd); // default encoding given none was specified - assert.equal(encoding, 'buffer'); + assert.strictEqual(encoding, 'buffer'); seenChunks.push(chunk); cb(); @@ -52,7 +52,7 @@ function writeChunks(remainingChunks, callback) { // do an initial write w.write('stuff'); // the write was immediate -assert.equal(seenChunks.length, 1); +assert.strictEqual(seenChunks.length, 1); // reset the seen chunks seenChunks = []; @@ -62,7 +62,7 @@ w.cork(); // write the bufferedChunks writeChunks(inputChunks, () => { // should not have seen anything yet - assert.equal(seenChunks.length, 0); + assert.strictEqual(seenChunks.length, 0); // trigger flush and ending the stream w.end(); @@ -71,7 +71,7 @@ writeChunks(inputChunks, () => { assert.ok(!seenEnd); // buffered bytes should be seen in current tick - assert.equal(seenChunks.length, 4); + assert.strictEqual(seenChunks.length, 4); // did the chunks match for (let i = 0, l = expectedChunks.length; i < l; i++) { diff --git a/test/parallel/test-stream3-cork-uncork.js b/test/parallel/test-stream3-cork-uncork.js index 821fd22bf8b8a3..98f74a45c6624e 100644 --- a/test/parallel/test-stream3-cork-uncork.js +++ b/test/parallel/test-stream3-cork-uncork.js @@ -20,7 +20,7 @@ const w = new Writable(); // lets arrange to store the chunks w._write = function(chunk, encoding, cb) { // default encoding given none was specified - assert.equal(encoding, 'buffer'); + assert.strictEqual(encoding, 'buffer'); seenChunks.push(chunk); cb(); @@ -50,7 +50,7 @@ function writeChunks(remainingChunks, callback) { // do an initial write w.write('stuff'); // the write was immediate -assert.equal(seenChunks.length, 1); +assert.strictEqual(seenChunks.length, 1); // reset the chunks seen so far seenChunks = []; @@ -60,13 +60,13 @@ w.cork(); // write the bufferedChunks writeChunks(inputChunks, () => { // should not have seen anything yet - assert.equal(seenChunks.length, 0); + assert.strictEqual(seenChunks.length, 0); // trigger writing out the buffer w.uncork(); // buffered bytes shoud be seen in current tick - assert.equal(seenChunks.length, 4); + assert.strictEqual(seenChunks.length, 4); // did the chunks match for (let i = 0, l = expectedChunks.length; i < l; i++) { diff --git a/test/parallel/test-stream3-pause-then-read.js b/test/parallel/test-stream3-pause-then-read.js index 5a9550bcd41d7f..a1be563683c0a2 100644 --- a/test/parallel/test-stream3-pause-then-read.js +++ b/test/parallel/test-stream3-pause-then-read.js @@ -46,7 +46,7 @@ function readn(n, then) { if (!c) r.once('readable', read); else { - assert.equal(c.length, n); + assert.strictEqual(c.length, n); assert(!r._readableState.flowing); then(); } @@ -85,7 +85,7 @@ function pipeLittle() { const w = new Writable(); let written = 0; w.on('finish', function() { - assert.equal(written, 200); + assert.strictEqual(written, 200); setImmediate(read1234); }); w._write = function(chunk, encoding, cb) { @@ -138,8 +138,8 @@ function pipe() { }; w.on('finish', function() { console.error('written', written, totalPushed); - assert.equal(written, expectEndingData); - assert.equal(totalPushed, expectTotalData); + assert.strictEqual(written, expectEndingData); + assert.strictEqual(totalPushed, expectTotalData); console.log('ok'); }); r.pipe(w); diff --git a/test/parallel/test-string-decoder-end.js b/test/parallel/test-string-decoder-end.js index 16f605d2dd8198..6e9eea3193e163 100644 --- a/test/parallel/test-string-decoder-end.js +++ b/test/parallel/test-string-decoder-end.js @@ -49,6 +49,6 @@ function testBuf(encoding, buf) { console.log('expect=%j', res3); console.log('res1=%j', res1); console.log('res2=%j', res2); - assert.equal(res1, res3, 'one byte at a time should match toString'); - assert.equal(res2, res3, 'all bytes at once should match toString'); + assert.strictEqual(res1, res3, 'one byte at a time should match toString'); + assert.strictEqual(res2, res3, 'all bytes at once should match toString'); } diff --git a/test/parallel/test-stringbytes-external.js b/test/parallel/test-stringbytes-external.js index a242b943c91a4d..94b58d9c6eadf0 100644 --- a/test/parallel/test-stringbytes-external.js +++ b/test/parallel/test-stringbytes-external.js @@ -13,14 +13,14 @@ let write_str = 'a'; let b = Buffer.from(write_str, 'ucs2'); // first check latin1 let c = b.toString('latin1'); -assert.equal(b[0], 0x61); -assert.equal(b[1], 0); -assert.equal(ucs2_control, c); +assert.strictEqual(b[0], 0x61); +assert.strictEqual(b[1], 0); +assert.strictEqual(ucs2_control, c); // now check binary c = b.toString('binary'); -assert.equal(b[0], 0x61); -assert.equal(b[1], 0); -assert.equal(ucs2_control, c); +assert.strictEqual(b[0], 0x61); +assert.strictEqual(b[1], 0); +assert.strictEqual(ucs2_control, c); // now create big strings const size = 1 + (1 << 20); @@ -31,8 +31,8 @@ ucs2_control = Array(size).join(ucs2_control); b = Buffer.from(write_str, 'ucs2'); // check fist Buffer created from write string for (let i = 0; i < b.length; i += 2) { - assert.equal(b[i], 0x61); - assert.equal(b[i + 1], 0); + assert.strictEqual(b[i], 0x61); + assert.strictEqual(b[i + 1], 0); } // create another string to create an external string @@ -40,25 +40,25 @@ const b_ucs = b.toString('ucs2'); // check control against external binary string const l_bin = b.toString('latin1'); -assert.equal(ucs2_control, l_bin); +assert.strictEqual(ucs2_control, l_bin); // check control against external binary string const b_bin = b.toString('binary'); -assert.equal(ucs2_control, b_bin); +assert.strictEqual(ucs2_control, b_bin); // create buffer copy from external const c_bin = Buffer.from(l_bin, 'latin1'); const c_ucs = Buffer.from(b_ucs, 'ucs2'); // make sure they're the same length -assert.equal(c_bin.length, c_ucs.length); +assert.strictEqual(c_bin.length, c_ucs.length); // make sure Buffers from externals are the same for (let i = 0; i < c_bin.length; i++) { - assert.equal(c_bin[i], c_ucs[i]); + assert.strictEqual(c_bin[i], c_ucs[i]); } // check resultant strings -assert.equal(c_bin.toString('ucs2'), c_ucs.toString('ucs2')); -assert.equal(c_bin.toString('latin1'), ucs2_control); -assert.equal(c_ucs.toString('latin1'), ucs2_control); +assert.strictEqual(c_bin.toString('ucs2'), c_ucs.toString('ucs2')); +assert.strictEqual(c_bin.toString('latin1'), ucs2_control); +assert.strictEqual(c_ucs.toString('latin1'), ucs2_control); // now let's test BASE64 and HEX ecoding/decoding diff --git a/test/parallel/test-sync-io-option.js b/test/parallel/test-sync-io-option.js index 6166bffc0bd68c..fb0b2333e82e4c 100644 --- a/test/parallel/test-sync-io-option.js +++ b/test/parallel/test-sync-io-option.js @@ -18,14 +18,14 @@ if (process.argv[2] === 'child') { args = execArgv.concat(args); if (!args[0]) args.shift(); execFile(process.execPath, args, function(err, stdout, stderr) { - assert.equal(err, null); - assert.equal(stdout, ''); + assert.strictEqual(err, null); + assert.strictEqual(stdout, ''); if (/WARNING[\s\S]*fs\.readFileSync/.test(stderr)) cntr++; if (args[0] === '--trace-sync-io') { - assert.equal(cntr, 1); + assert.strictEqual(cntr, 1); } else if (args[0] === __filename) { - assert.equal(cntr, 0); + assert.strictEqual(cntr, 0); } else { throw new Error('UNREACHABLE'); } diff --git a/test/parallel/test-tcp-wrap.js b/test/parallel/test-tcp-wrap.js index 6b9dbd90a4c113..aee0bcc8509fdf 100644 --- a/test/parallel/test-tcp-wrap.js +++ b/test/parallel/test-tcp-wrap.js @@ -9,12 +9,12 @@ const handle = new TCP(); // Should be able to bind to the port let err = handle.bind('0.0.0.0', 0); -assert.equal(err, 0); +assert.strictEqual(err, 0); // Should not be able to bind to the same port again const out = {}; handle.getsockname(out); err = handle.bind('0.0.0.0', out.port); -assert.equal(err, uv.UV_EINVAL); +assert.strictEqual(err, uv.UV_EINVAL); handle.close(); diff --git a/test/parallel/test-timer-close.js b/test/parallel/test-timer-close.js index 158b082cf3167a..63ca46754f6182 100644 --- a/test/parallel/test-timer-close.js +++ b/test/parallel/test-timer-close.js @@ -12,5 +12,5 @@ t.close(onclose); t.close(onclose); process.on('exit', function() { - assert.equal(1, called); + assert.strictEqual(1, called); }); diff --git a/test/parallel/test-timers-ordering.js b/test/parallel/test-timers-ordering.js index 55fb141cb272ce..a426bd75c9abcd 100644 --- a/test/parallel/test-timers-ordering.js +++ b/test/parallel/test-timers-ordering.js @@ -11,7 +11,7 @@ let last_ts = 0; const f = function(i) { if (i <= N) { // check order - assert.equal(i, last_i + 1, 'order is broken: ' + i + ' != ' + + assert.strictEqual(i, last_i + 1, 'order is broken: ' + i + ' != ' + last_i + ' + 1'); last_i = i; diff --git a/test/parallel/test-timers-reset-process-domain-on-throw.js b/test/parallel/test-timers-reset-process-domain-on-throw.js index 55e7ef57dcafc4..946ae715b0e193 100644 --- a/test/parallel/test-timers-reset-process-domain-on-throw.js +++ b/test/parallel/test-timers-reset-process-domain-on-throw.js @@ -28,7 +28,7 @@ function err() { function handleDomainError(e) { // In the domain's error handler, the current active domain should be the // domain within which the error was thrown. - assert.equal(process.domain, d); + assert.strictEqual(process.domain, d); } } diff --git a/test/parallel/test-timers-uncaught-exception.js b/test/parallel/test-timers-uncaught-exception.js index 87fd880de4bf89..e5ec037ff89066 100644 --- a/test/parallel/test-timers-uncaught-exception.js +++ b/test/parallel/test-timers-uncaught-exception.js @@ -18,13 +18,13 @@ setTimeout(function() { console.error('set second timer'); setTimeout(function() { console.error('second timer'); - assert.equal(timer1, 1); + assert.strictEqual(timer1, 1); timer2++; }, 100); function uncaughtException(err) { console.error('uncaught handler'); - assert.equal(err.message, 'BAM!'); + assert.strictEqual(err.message, 'BAM!'); exceptions++; } process.on('uncaughtException', uncaughtException); @@ -34,7 +34,7 @@ process.on('exit', function() { assert(!exited); exited = true; process.removeListener('uncaughtException', uncaughtException); - assert.equal(exceptions, 1); - assert.equal(timer1, 1); - assert.equal(timer2, 1); + assert.strictEqual(exceptions, 1); + assert.strictEqual(timer1, 1); + assert.strictEqual(timer2, 1); }); diff --git a/test/parallel/test-timers-unref-active.js b/test/parallel/test-timers-unref-active.js index 8b1c89673bc35f..69f6d4e9f1bce4 100644 --- a/test/parallel/test-timers-unref-active.js +++ b/test/parallel/test-timers-unref-active.js @@ -47,5 +47,5 @@ someObject._onTimeout = function _onTimeout() { timers._unrefActive(someObject); setTimeout(function() { - assert.equal(nbTimeouts, N); + assert.strictEqual(nbTimeouts, N); }, TEST_DURATION); diff --git a/test/parallel/test-timers-unref-leak.js b/test/parallel/test-timers-unref-leak.js index d970910b24abe6..8eef00dd4ffe92 100644 --- a/test/parallel/test-timers-unref-leak.js +++ b/test/parallel/test-timers-unref-leak.js @@ -22,6 +22,6 @@ setTimeout(function() { }, 50); process.on('exit', function() { - assert.equal(called, 1); - assert.equal(closed, 1); + assert.strictEqual(called, 1); + assert.strictEqual(closed, 1); }); diff --git a/test/parallel/test-timers-unref-remove-other-unref-timers-only-one-fires.js b/test/parallel/test-timers-unref-remove-other-unref-timers-only-one-fires.js index 1dcc3e68de9eaa..ce63ad8d2968e7 100644 --- a/test/parallel/test-timers-unref-remove-other-unref-timers-only-one-fires.js +++ b/test/parallel/test-timers-unref-remove-other-unref-timers-only-one-fires.js @@ -37,5 +37,5 @@ timers.enroll(foo, 1); timers._unrefActive(foo); setTimeout(function() { - assert.notEqual(nbTimersFired, 2); + assert.notStrictEqual(nbTimersFired, 2); }, 20); diff --git a/test/parallel/test-timers.js b/test/parallel/test-timers.js index df2240d2c444af..7ace816c2ceaeb 100644 --- a/test/parallel/test-timers.js +++ b/test/parallel/test-timers.js @@ -50,8 +50,8 @@ inputs.forEach(function(value, index) { setTimeout(common.mustCall(function() { // assert that all other timers have run inputs.forEach(function(value, index) { - assert(timeouts[index]); - assert(intervals[index]); + assert.strictEqual(true, timeouts[index]); + assert.strictEqual(true, intervals[index]); }); }), 2); diff --git a/test/parallel/test-tls-cipher-list.js b/test/parallel/test-tls-cipher-list.js index 4acb30bc1c74bf..1533900f861177 100644 --- a/test/parallel/test-tls-cipher-list.js +++ b/test/parallel/test-tls-cipher-list.js @@ -21,7 +21,7 @@ function doCheck(arg, check) { .stdout.on('data', function(chunk) { out += chunk; }).on('end', function() { - assert.equal(out.trim(), check); + assert.strictEqual(out.trim(), check); }).on('error', common.fail); } diff --git a/test/parallel/test-tls-client-default-ciphers.js b/test/parallel/test-tls-client-default-ciphers.js index 618178d4a497ad..30095197b1c807 100644 --- a/test/parallel/test-tls-client-default-ciphers.js +++ b/test/parallel/test-tls-client-default-ciphers.js @@ -23,6 +23,6 @@ function test1() { } catch (e) { assert(e instanceof Done); } - assert.equal(ciphers, tls.DEFAULT_CIPHERS); + assert.strictEqual(ciphers, tls.DEFAULT_CIPHERS); } test1(); diff --git a/test/parallel/test-tls-client-getephemeralkeyinfo.js b/test/parallel/test-tls-client-getephemeralkeyinfo.js index fd7dca4b6b7076..0fd0912d3d9cbc 100644 --- a/test/parallel/test-tls-client-getephemeralkeyinfo.js +++ b/test/parallel/test-tls-client-getephemeralkeyinfo.js @@ -93,6 +93,6 @@ function testECDHE512() { testNOT_PFS(); process.on('exit', function() { - assert.equal(ntests, nsuccess); - assert.equal(ntests, 5); + assert.strictEqual(ntests, nsuccess); + assert.strictEqual(ntests, 5); }); diff --git a/test/parallel/test-tls-client-mindhsize.js b/test/parallel/test-tls-client-mindhsize.js index 76e1034621f031..6bbf90030e85c2 100644 --- a/test/parallel/test-tls-client-mindhsize.js +++ b/test/parallel/test-tls-client-mindhsize.js @@ -88,6 +88,6 @@ assert.throws(() => test(512, true, common.fail), }); process.on('exit', function() { - assert.equal(nsuccess, 1); - assert.equal(nerror, 1); + assert.strictEqual(nsuccess, 1); + assert.strictEqual(nerror, 1); }); diff --git a/test/parallel/test-tls-client-verify.js b/test/parallel/test-tls-client-verify.js index 70d96ef1545ede..33d6c95fde50d3 100644 --- a/test/parallel/test-tls-client-verify.js +++ b/test/parallel/test-tls-client-verify.js @@ -130,5 +130,5 @@ runTest(0); process.on('exit', function() { console.log('successful tests: %d', successfulTests); - assert.equal(successfulTests, testCases.length); + assert.strictEqual(successfulTests, testCases.length); }); diff --git a/test/parallel/test-tls-delayed-attach.js b/test/parallel/test-tls-delayed-attach.js index d757ca756c3a09..9d2aca6a7d6c6f 100644 --- a/test/parallel/test-tls-delayed-attach.js +++ b/test/parallel/test-tls-delayed-attach.js @@ -44,5 +44,5 @@ const server = net.createServer(function(c) { }); process.on('exit', function() { - assert.equal(received, sent); + assert.strictEqual(received, sent); }); diff --git a/test/parallel/test-tls-dhe.js b/test/parallel/test-tls-dhe.js index eb2d1b52b136aa..80a2d78501c308 100644 --- a/test/parallel/test-tls-dhe.js +++ b/test/parallel/test-tls-dhe.js @@ -96,6 +96,6 @@ function testError() { test1024(); process.on('exit', function() { - assert.equal(ntests, nsuccess); - assert.equal(ntests, 3); + assert.strictEqual(ntests, nsuccess); + assert.strictEqual(ntests, 3); }); diff --git a/test/parallel/test-tls-env-bad-extra-ca.js b/test/parallel/test-tls-env-bad-extra-ca.js index cb6c4ba489fcd6..9b42bbbbd5558e 100644 --- a/test/parallel/test-tls-env-bad-extra-ca.js +++ b/test/parallel/test-tls-env-bad-extra-ca.js @@ -30,7 +30,7 @@ let stderr = ''; fork(__filename, opts) .on('exit', common.mustCall(function(status) { - assert.equal(status, 0, 'client did not succeed in connecting'); + assert.strictEqual(status, 0, 'client did not succeed in connecting'); })) .on('close', common.mustCall(function() { assert(stderr.match(new RegExp( diff --git a/test/parallel/test-tls-env-extra-ca.js b/test/parallel/test-tls-env-extra-ca.js index 12e3272bd401a2..89f1b3a6c040d1 100644 --- a/test/parallel/test-tls-env-extra-ca.js +++ b/test/parallel/test-tls-env-extra-ca.js @@ -40,6 +40,6 @@ const server = tls.createServer(options, function(s) { }; fork(__filename, {env: env}).on('exit', common.mustCall(function(status) { - assert.equal(status, 0, 'client did not succeed in connecting'); + assert.strictEqual(status, 0, 'client did not succeed in connecting'); })); })); diff --git a/test/parallel/test-tls-handshake-error.js b/test/parallel/test-tls-handshake-error.js index 39ea3a517247a0..4909fa45e160fb 100644 --- a/test/parallel/test-tls-handshake-error.js +++ b/test/parallel/test-tls-handshake-error.js @@ -25,7 +25,7 @@ const server = tls.createServer({ }); c.on('error', common.mustCall(function(err) { - assert.notEqual(err.code, 'ECONNRESET'); + assert.notStrictEqual(err.code, 'ECONNRESET'); })); c.on('close', common.mustCall(function(err) { diff --git a/test/parallel/test-tls-honorcipherorder.js b/test/parallel/test-tls-honorcipherorder.js index f7894e46706da9..fdfc303146c1fa 100644 --- a/test/parallel/test-tls-honorcipherorder.js +++ b/test/parallel/test-tls-honorcipherorder.js @@ -17,7 +17,7 @@ const SSL_Method = 'TLSv1_2_method'; const localhost = '127.0.0.1'; process.on('exit', function() { - assert.equal(nconns, 6); + assert.strictEqual(nconns, 6); }); function test(honorCipherOrder, clientCipher, expectedCipher, cb) { @@ -50,7 +50,7 @@ function test(honorCipherOrder, clientCipher, expectedCipher, cb) { const cipher = client.getCipher(); client.end(); server.close(); - assert.equal(cipher.name, expectedCipher); + assert.strictEqual(cipher.name, expectedCipher); if (cb) cb(); }); }); diff --git a/test/parallel/test-tls-js-stream.js b/test/parallel/test-tls-js-stream.js index b8e14cb30ed8e6..5945a1fc0318cd 100644 --- a/test/parallel/test-tls-js-stream.js +++ b/test/parallel/test-tls-js-stream.js @@ -71,6 +71,6 @@ const server = tls.createServer({ }); process.once('exit', function() { - assert.equal(connected.client, 1); - assert.equal(connected.server, 1); + assert.strictEqual(connected.client, 1); + assert.strictEqual(connected.server, 1); }); diff --git a/test/parallel/test-tls-no-rsa-key.js b/test/parallel/test-tls-no-rsa-key.js index 233d8453db1318..ed5c941b2d33ba 100644 --- a/test/parallel/test-tls-no-rsa-key.js +++ b/test/parallel/test-tls-no-rsa-key.js @@ -27,7 +27,7 @@ const server = tls.createServer(options, function(conn) { })); c.on('data', function(data) { - assert.equal(data, 'ok'); + assert.strictEqual(data.toString(), 'ok'); }); const cert = c.getPeerCertificate(); diff --git a/test/parallel/test-tls-npn-server-client.js b/test/parallel/test-tls-npn-server-client.js index 54d20cec6e78b8..fdc42dab6968d9 100644 --- a/test/parallel/test-tls-npn-server-client.js +++ b/test/parallel/test-tls-npn-server-client.js @@ -98,10 +98,10 @@ function startTest() { } process.on('exit', function() { - assert.equal(serverResults[0], clientsResults[0]); - assert.equal(serverResults[1], clientsResults[1]); - assert.equal(serverResults[2], 'http/1.1'); - assert.equal(clientsResults[2], false); - assert.equal(serverResults[3], 'first-priority-unsupported'); - assert.equal(clientsResults[3], false); + assert.strictEqual(serverResults[0], clientsResults[0]); + assert.strictEqual(serverResults[1], clientsResults[1]); + assert.strictEqual(serverResults[2], 'http/1.1'); + assert.strictEqual(clientsResults[2], false); + assert.strictEqual(serverResults[3], 'first-priority-unsupported'); + assert.strictEqual(clientsResults[3], false); }); diff --git a/test/parallel/test-tls-over-http-tunnel.js b/test/parallel/test-tls-over-http-tunnel.js index 4e03bcaf537f26..a37913907b5b19 100644 --- a/test/parallel/test-tls-over-http-tunnel.js +++ b/test/parallel/test-tls-over-http-tunnel.js @@ -39,11 +39,12 @@ const proxy = net.createServer(function(clientSocket) { clientSocket.on('data', function(chunk) { if (!serverSocket) { // Verify the CONNECT request - assert.equal(`CONNECT localhost:${server.address().port} HTTP/1.1\r\n` + - 'Proxy-Connections: keep-alive\r\n' + - `Host: localhost:${proxy.address().port}\r\n` + - 'Connection: close\r\n\r\n', - chunk); + assert.strictEqual(`CONNECT localhost:${server.address().port} ` + + 'HTTP/1.1\r\n' + + 'Proxy-Connections: keep-alive\r\n' + + `Host: localhost:${proxy.address().port}\r\n` + + 'Connection: close\r\n\r\n', + chunk.toString()); console.log('PROXY: got CONNECT request'); console.log('PROXY: creating a tunnel'); @@ -107,7 +108,7 @@ proxy.listen(0, function() { } function onConnect(res, socket, header) { - assert.equal(200, res.statusCode); + assert.strictEqual(200, res.statusCode); console.log('CLIENT: got CONNECT response'); // detach the socket @@ -130,10 +131,10 @@ proxy.listen(0, function() { agent: false, rejectUnauthorized: false }, function(res) { - assert.equal(200, res.statusCode); + assert.strictEqual(200, res.statusCode); res.on('data', function(chunk) { - assert.equal('hello world\n', chunk); + assert.strictEqual('hello world\n', chunk.toString()); console.log('CLIENT: got HTTPS response'); gotRequest = true; }); diff --git a/test/parallel/test-tls-pause.js b/test/parallel/test-tls-pause.js index 911ea7097b1e70..c5b96b96dd675f 100644 --- a/test/parallel/test-tls-pause.js +++ b/test/parallel/test-tls-pause.js @@ -69,5 +69,5 @@ server.listen(0, function() { }); process.on('exit', function() { - assert.equal(sent, received); + assert.strictEqual(sent, received); }); diff --git a/test/parallel/test-tls-peer-certificate-encoding.js b/test/parallel/test-tls-peer-certificate-encoding.js index 545caf403e103c..1ae30974aeda83 100644 --- a/test/parallel/test-tls-peer-certificate-encoding.js +++ b/test/parallel/test-tls-peer-certificate-encoding.js @@ -29,7 +29,7 @@ server.listen(0, common.mustCall(function() { const peerCert = socket.getPeerCertificate(); console.error(util.inspect(peerCert)); - assert.equal(peerCert.subject.CN, 'Ádám Lippai'); + assert.strictEqual(peerCert.subject.CN, 'Ádám Lippai'); server.close(); })); socket.end('Hello'); diff --git a/test/parallel/test-tls-server-verify.js b/test/parallel/test-tls-server-verify.js index 60678032a3efcf..61330e2ba2e543 100644 --- a/test/parallel/test-tls-server-verify.js +++ b/test/parallel/test-tls-server-verify.js @@ -216,7 +216,7 @@ function runClient(prefix, port, options, cb) { //client.stdout.pipe(process.stdout); client.on('exit', function(code) { - //assert.equal(0, code, prefix + options.name + + //assert.strictEqual(0, code, prefix + options.name + // ": s_client exited with error code " + code); if (options.shouldReject) { assert.strictEqual(true, rejected, prefix + options.name + diff --git a/test/parallel/test-tls-session-cache.js b/test/parallel/test-tls-session-cache.js index 5e3ae5128ecfaf..0b2942215141e3 100644 --- a/test/parallel/test-tls-session-cache.js +++ b/test/parallel/test-tls-session-cache.js @@ -63,7 +63,7 @@ function doTest(testOptions, callback) { server.on('resumeSession', function(id, callback) { ++resumeCount; assert.ok(session); - assert.equal(session.id.toString('hex'), id.toString('hex')); + assert.strictEqual(session.id.toString('hex'), id.toString('hex')); // Just to check that async really works there setTimeout(function() { @@ -107,7 +107,7 @@ function doTest(testOptions, callback) { } common.fail(`code: ${code}, signal: ${signal}, output: ${err}`); } - assert.equal(code, 0); + assert.strictEqual(code, 0); server.close(common.mustCall(function() { setTimeout(callback, 100); })); @@ -119,13 +119,13 @@ function doTest(testOptions, callback) { process.on('exit', function() { if (testOptions.tickets) { - assert.equal(requestCount, 6); - assert.equal(resumeCount, 0); + assert.strictEqual(requestCount, 6); + assert.strictEqual(resumeCount, 0); } else { // initial request + reconnect requests (5 times) assert.ok(session); - assert.equal(requestCount, 6); - assert.equal(resumeCount, 5); + assert.strictEqual(requestCount, 6); + assert.strictEqual(resumeCount, 5); } }); } diff --git a/test/parallel/test-tls-set-ciphers.js b/test/parallel/test-tls-set-ciphers.js index 91eb1bea6e2f2f..83dcc1ff741922 100644 --- a/test/parallel/test-tls-set-ciphers.js +++ b/test/parallel/test-tls-set-ciphers.js @@ -26,7 +26,7 @@ const reply = 'I AM THE WALRUS'; // something recognizable let response = ''; process.on('exit', function() { - assert.notEqual(response.indexOf(reply), -1); + assert.notStrictEqual(response.indexOf(reply), -1); }); const server = tls.createServer(options, common.mustCall(function(conn) { diff --git a/test/parallel/test-tls-socket-default-options.js b/test/parallel/test-tls-socket-default-options.js index 5c325570643225..dd62a41090c88e 100644 --- a/test/parallel/test-tls-socket-default-options.js +++ b/test/parallel/test-tls-socket-default-options.js @@ -28,7 +28,7 @@ function testSocketOptions(socket, socketOptions) { s.on('end', function() { server.close(); s.destroy(); - assert.equal(received, sent); + assert.strictEqual(received, sent); setImmediate(runTests); }); }).listen(0, function() { diff --git a/test/parallel/test-umask.js b/test/parallel/test-umask.js index 1c870893a3bced..7e4827a4cfc47d 100644 --- a/test/parallel/test-umask.js +++ b/test/parallel/test-umask.js @@ -12,10 +12,10 @@ if (common.isWindows) { const old = process.umask(mask); -assert.equal(parseInt(mask, 8), process.umask(old)); +assert.strictEqual(parseInt(mask, 8), process.umask(old)); // confirm reading the umask does not modify it. // 1. If the test fails, this call will succeed, but the mask will be set to 0 -assert.equal(old, process.umask()); +assert.strictEqual(old, process.umask()); // 2. If the test fails, process.umask() will return 0 -assert.equal(old, process.umask()); +assert.strictEqual(old, process.umask()); diff --git a/test/parallel/test-url.js b/test/parallel/test-url.js index d8ee2127f946d3..4e123305b5fddb 100644 --- a/test/parallel/test-url.js +++ b/test/parallel/test-url.js @@ -923,8 +923,8 @@ for (const u in parseTests) { expected = parseTests[u].href; actual = url.format(parseTests[u]); - assert.equal(actual, expected, - 'format(' + u + ') == ' + u + '\nactual:' + actual); + assert.strictEqual(actual, expected, + 'format(' + u + ') == ' + u + '\nactual:' + actual); } function createWithNoPrototype(properties = []) { @@ -1232,11 +1232,11 @@ for (const u in formatTests) { delete formatTests[u].href; const actual = url.format(u); const actualObj = url.format(formatTests[u]); - assert.equal(actual, expect, - 'wonky format(' + u + ') == ' + expect + + assert.strictEqual(actual, expect, + 'wonky format(' + u + ') == ' + expect + '\nactual:' + actual); - assert.equal(actualObj, expect, - 'wonky format(' + JSON.stringify(formatTests[u]) + + assert.strictEqual(actualObj, expect, + 'wonky format(' + JSON.stringify(formatTests[u]) + ') == ' + expect + '\nactual: ' + actualObj); } @@ -1293,8 +1293,8 @@ const relativeTests = [ relativeTests.forEach(function(relativeTest) { const a = url.resolve(relativeTest[0], relativeTest[1]); const e = relativeTest[2]; - assert.equal(a, e, - 'resolve(' + [relativeTest[0], relativeTest[1]] + ') == ' + e + + assert.strictEqual(a, e, + 'resolve(' + [relativeTest[0], relativeTest[1]] + ') == ' + e + '\n actual=' + a); }); @@ -1625,8 +1625,8 @@ const relativeTests2 = [ relativeTests2.forEach(function(relativeTest) { const a = url.resolve(relativeTest[1], relativeTest[0]); const e = relativeTest[2]; - assert.equal(a, e, - 'resolve(' + [relativeTest[1], relativeTest[0]] + ') == ' + e + + assert.strictEqual(a, e, + 'resolve(' + [relativeTest[1], relativeTest[0]] + ') == ' + e + '\n actual=' + a); }); @@ -1644,8 +1644,8 @@ relativeTests.forEach(function(relativeTest) { expected = relativeTest[2]; actual = url.format(actual); - assert.equal(actual, expected, - 'format(' + actual + ') == ' + expected + '\nactual:' + actual); + assert.strictEqual(actual, expected, + 'format(' + actual + ') == ' + expected + '\nactual:' + actual); }); //format: [to, from, result] @@ -1671,8 +1671,8 @@ relativeTests2.forEach(function(relativeTest) { expected = relativeTest[2]; actual = url.format(actual); - assert.equal(actual, expected, - 'format(' + relativeTest[1] + ') == ' + expected + + assert.strictEqual(actual, expected, + 'format(' + relativeTest[1] + ') == ' + expected + '\nactual:' + actual); }); diff --git a/test/parallel/test-utf8-scripts.js b/test/parallel/test-utf8-scripts.js index 484d3bdefe5eda..e9d141d58abab0 100644 --- a/test/parallel/test-utf8-scripts.js +++ b/test/parallel/test-utf8-scripts.js @@ -6,4 +6,4 @@ const assert = require('assert'); console.log('Σὲ γνωρίζω ἀπὸ τὴν κόψη'); -assert.equal(true, /Hellö Wörld/.test('Hellö Wörld')); +assert.strictEqual(true, /Hellö Wörld/.test('Hellö Wörld')); diff --git a/test/parallel/test-util-log.js b/test/parallel/test-util-log.js index d45ebf2fc0b729..3604b42820063e 100644 --- a/test/parallel/test-util-log.js +++ b/test/parallel/test-util-log.js @@ -32,7 +32,7 @@ tests.forEach(function(test) { const re = (/[0-9]{1,2} [A-Z][a-z]{2} [0-9]{2}:[0-9]{2}:[0-9]{2} - (.+)$/); const match = re.exec(result); assert.ok(match); - assert.equal(match[1], test.output); + assert.strictEqual(match[1], test.output); }); global.process.stdout.write = stdout_write; diff --git a/test/parallel/test-util.js b/test/parallel/test-util.js index 0f5ee28e37b59c..3b7e78ea1e464e 100644 --- a/test/parallel/test-util.js +++ b/test/parallel/test-util.js @@ -5,78 +5,78 @@ const util = require('util'); const context = require('vm').runInNewContext; // isArray -assert.equal(true, util.isArray([])); -assert.equal(true, util.isArray(Array())); -assert.equal(true, util.isArray(new Array())); -assert.equal(true, util.isArray(new Array(5))); -assert.equal(true, util.isArray(new Array('with', 'some', 'entries'))); -assert.equal(true, util.isArray(context('Array')())); -assert.equal(false, util.isArray({})); -assert.equal(false, util.isArray({ push: function() {} })); -assert.equal(false, util.isArray(/regexp/)); -assert.equal(false, util.isArray(new Error())); -assert.equal(false, util.isArray(Object.create(Array.prototype))); +assert.strictEqual(true, util.isArray([])); +assert.strictEqual(true, util.isArray(Array())); +assert.strictEqual(true, util.isArray(new Array())); +assert.strictEqual(true, util.isArray(new Array(5))); +assert.strictEqual(true, util.isArray(new Array('with', 'some', 'entries'))); +assert.strictEqual(true, util.isArray(context('Array')())); +assert.strictEqual(false, util.isArray({})); +assert.strictEqual(false, util.isArray({ push: function() {} })); +assert.strictEqual(false, util.isArray(/regexp/)); +assert.strictEqual(false, util.isArray(new Error())); +assert.strictEqual(false, util.isArray(Object.create(Array.prototype))); // isRegExp -assert.equal(true, util.isRegExp(/regexp/)); -assert.equal(true, util.isRegExp(RegExp())); -assert.equal(true, util.isRegExp(new RegExp())); -assert.equal(true, util.isRegExp(context('RegExp')())); -assert.equal(false, util.isRegExp({})); -assert.equal(false, util.isRegExp([])); -assert.equal(false, util.isRegExp(new Date())); -assert.equal(false, util.isRegExp(Object.create(RegExp.prototype))); +assert.strictEqual(true, util.isRegExp(/regexp/)); +assert.strictEqual(true, util.isRegExp(RegExp())); +assert.strictEqual(true, util.isRegExp(new RegExp())); +assert.strictEqual(true, util.isRegExp(context('RegExp')())); +assert.strictEqual(false, util.isRegExp({})); +assert.strictEqual(false, util.isRegExp([])); +assert.strictEqual(false, util.isRegExp(new Date())); +assert.strictEqual(false, util.isRegExp(Object.create(RegExp.prototype))); // isDate -assert.equal(true, util.isDate(new Date())); -assert.equal(true, util.isDate(new Date(0))); +assert.strictEqual(true, util.isDate(new Date())); +assert.strictEqual(true, util.isDate(new Date(0))); // eslint-disable-next-line new-parens -assert.equal(true, util.isDate(new (context('Date')))); -assert.equal(false, util.isDate(Date())); -assert.equal(false, util.isDate({})); -assert.equal(false, util.isDate([])); -assert.equal(false, util.isDate(new Error())); -assert.equal(false, util.isDate(Object.create(Date.prototype))); +assert.strictEqual(true, util.isDate(new (context('Date')))); +assert.strictEqual(false, util.isDate(Date())); +assert.strictEqual(false, util.isDate({})); +assert.strictEqual(false, util.isDate([])); +assert.strictEqual(false, util.isDate(new Error())); +assert.strictEqual(false, util.isDate(Object.create(Date.prototype))); // isError -assert.equal(true, util.isError(new Error())); -assert.equal(true, util.isError(new TypeError())); -assert.equal(true, util.isError(new SyntaxError())); +assert.strictEqual(true, util.isError(new Error())); +assert.strictEqual(true, util.isError(new TypeError())); +assert.strictEqual(true, util.isError(new SyntaxError())); /* eslint-disable new-parens */ -assert.equal(true, util.isError(new (context('Error')))); -assert.equal(true, util.isError(new (context('TypeError')))); -assert.equal(true, util.isError(new (context('SyntaxError')))); +assert.strictEqual(true, util.isError(new (context('Error')))); +assert.strictEqual(true, util.isError(new (context('TypeError')))); +assert.strictEqual(true, util.isError(new (context('SyntaxError')))); /* eslint-enable */ -assert.equal(false, util.isError({})); -assert.equal(false, util.isError({ name: 'Error', message: '' })); -assert.equal(false, util.isError([])); -assert.equal(true, util.isError(Object.create(Error.prototype))); +assert.strictEqual(false, util.isError({})); +assert.strictEqual(false, util.isError({ name: 'Error', message: '' })); +assert.strictEqual(false, util.isError([])); +assert.strictEqual(true, util.isError(Object.create(Error.prototype))); // isObject assert.ok(util.isObject({}) === true); // isPrimitive -assert.equal(false, util.isPrimitive({})); -assert.equal(false, util.isPrimitive(new Error())); -assert.equal(false, util.isPrimitive(new Date())); -assert.equal(false, util.isPrimitive([])); -assert.equal(false, util.isPrimitive(/regexp/)); -assert.equal(false, util.isPrimitive(function() {})); -assert.equal(false, util.isPrimitive(new Number(1))); -assert.equal(false, util.isPrimitive(new String('bla'))); -assert.equal(false, util.isPrimitive(new Boolean(true))); -assert.equal(true, util.isPrimitive(1)); -assert.equal(true, util.isPrimitive('bla')); -assert.equal(true, util.isPrimitive(true)); -assert.equal(true, util.isPrimitive(undefined)); -assert.equal(true, util.isPrimitive(null)); -assert.equal(true, util.isPrimitive(Infinity)); -assert.equal(true, util.isPrimitive(NaN)); -assert.equal(true, util.isPrimitive(Symbol('symbol'))); +assert.strictEqual(false, util.isPrimitive({})); +assert.strictEqual(false, util.isPrimitive(new Error())); +assert.strictEqual(false, util.isPrimitive(new Date())); +assert.strictEqual(false, util.isPrimitive([])); +assert.strictEqual(false, util.isPrimitive(/regexp/)); +assert.strictEqual(false, util.isPrimitive(function() {})); +assert.strictEqual(false, util.isPrimitive(new Number(1))); +assert.strictEqual(false, util.isPrimitive(new String('bla'))); +assert.strictEqual(false, util.isPrimitive(new Boolean(true))); +assert.strictEqual(true, util.isPrimitive(1)); +assert.strictEqual(true, util.isPrimitive('bla')); +assert.strictEqual(true, util.isPrimitive(true)); +assert.strictEqual(true, util.isPrimitive(undefined)); +assert.strictEqual(true, util.isPrimitive(null)); +assert.strictEqual(true, util.isPrimitive(Infinity)); +assert.strictEqual(true, util.isPrimitive(NaN)); +assert.strictEqual(true, util.isPrimitive(Symbol('symbol'))); // isBuffer -assert.equal(false, util.isBuffer('foo')); -assert.equal(true, util.isBuffer(Buffer.from('foo'))); +assert.strictEqual(false, util.isBuffer('foo')); +assert.strictEqual(true, util.isBuffer(Buffer.from('foo'))); // _extend assert.deepStrictEqual(util._extend({a: 1}), {a: 1}); diff --git a/test/parallel/test-v8-stats.js b/test/parallel/test-v8-stats.js index 5187432484846b..1e4ae1b7cdcf9e 100644 --- a/test/parallel/test-v8-stats.js +++ b/test/parallel/test-v8-stats.js @@ -13,7 +13,7 @@ const keys = [ 'used_heap_size']; assert.deepStrictEqual(Object.keys(s).sort(), keys); keys.forEach(function(key) { - assert.equal(typeof s[key], 'number'); + assert.strictEqual(typeof s[key], 'number'); }); diff --git a/test/parallel/test-vm-cached-data.js b/test/parallel/test-vm-cached-data.js index aa2dd26ad5a8b7..e2b684bf1d2c31 100644 --- a/test/parallel/test-vm-cached-data.js +++ b/test/parallel/test-vm-cached-data.js @@ -32,7 +32,7 @@ function produce(source, count) { console.log(data); `, source]); - assert.equal(out.status, 0, out.stderr + ''); + assert.strictEqual(out.status, 0, out.stderr + ''); return Buffer.from(out.stdout.toString(), 'base64'); } @@ -47,7 +47,7 @@ function testProduceConsume() { cachedData: data }); assert(!script.cachedDataRejected); - assert.equal(script.runInThisContext()(), 'original'); + assert.strictEqual(script.runInThisContext()(), 'original'); } testProduceConsume(); @@ -68,7 +68,7 @@ function testRejectInvalid() { cachedData: data }); assert(script.cachedDataRejected); - assert.equal(script.runInThisContext()(), 'invalid_1'); + assert.strictEqual(script.runInThisContext()(), 'invalid_1'); } testRejectInvalid(); diff --git a/test/parallel/test-vm-context.js b/test/parallel/test-vm-context.js index 933d975c2c5542..81c86e93705465 100644 --- a/test/parallel/test-vm-context.js +++ b/test/parallel/test-vm-context.js @@ -9,18 +9,18 @@ let script = new Script('"passed";'); console.error('run in a new empty context'); let context = vm.createContext(); let result = script.runInContext(context); -assert.equal('passed', result); +assert.strictEqual('passed', result); console.error('create a new pre-populated context'); context = vm.createContext({'foo': 'bar', 'thing': 'lala'}); -assert.equal('bar', context.foo); -assert.equal('lala', context.thing); +assert.strictEqual('bar', context.foo); +assert.strictEqual('lala', context.thing); console.error('test updating context'); script = new Script('foo = 3;'); result = script.runInContext(context); -assert.equal(3, context.foo); -assert.equal('lala', context.thing); +assert.strictEqual(3, context.foo); +assert.strictEqual('lala', context.thing); // Issue GH-227: assert.throws(function() { @@ -58,7 +58,7 @@ script = vm.createScript('delete b'); let ctx = {}; Object.defineProperty(ctx, 'b', { configurable: false }); ctx = vm.createContext(ctx); -assert.equal(script.runInContext(ctx), false); +assert.strictEqual(script.runInContext(ctx), false); // Error on the first line of a module should // have the correct line and column number diff --git a/test/parallel/test-vm-create-and-run-in-context.js b/test/parallel/test-vm-create-and-run-in-context.js index a0026102b578f8..7fd3f1d70436ad 100644 --- a/test/parallel/test-vm-create-and-run-in-context.js +++ b/test/parallel/test-vm-create-and-run-in-context.js @@ -8,17 +8,17 @@ const vm = require('vm'); console.error('run in a new empty context'); let context = vm.createContext(); let result = vm.runInContext('"passed";', context); -assert.equal('passed', result); +assert.strictEqual('passed', result); console.error('create a new pre-populated context'); context = vm.createContext({'foo': 'bar', 'thing': 'lala'}); -assert.equal('bar', context.foo); -assert.equal('lala', context.thing); +assert.strictEqual('bar', context.foo); +assert.strictEqual('lala', context.thing); console.error('test updating context'); result = vm.runInContext('var foo = 3;', context); -assert.equal(3, context.foo); -assert.equal('lala', context.thing); +assert.strictEqual(3, context.foo); +assert.strictEqual('lala', context.thing); // https://github.com/nodejs/node/issues/5768 console.error('run in contextified sandbox without referencing the context'); diff --git a/test/parallel/test-vm-create-context-circular-reference.js b/test/parallel/test-vm-create-context-circular-reference.js index 13680c4c4e11ef..1d7be0db9fdaf4 100644 --- a/test/parallel/test-vm-create-context-circular-reference.js +++ b/test/parallel/test-vm-create-context-circular-reference.js @@ -10,4 +10,4 @@ sbx = vm.createContext(sbx); sbx.test = 123; -assert.equal(sbx.window.window.window.window.window.test, 123); +assert.strictEqual(sbx.window.window.window.window.window.test, 123); diff --git a/test/parallel/test-vm-function-declaration.js b/test/parallel/test-vm-function-declaration.js index 9f27723a0421a9..668b29885c44cf 100644 --- a/test/parallel/test-vm-function-declaration.js +++ b/test/parallel/test-vm-function-declaration.js @@ -18,10 +18,10 @@ code += '(function(){return this})().b;\n'; const res = vm.runInContext(code, o, 'test'); -assert.equal(typeof res, 'function', 'result should be function'); -assert.equal(res.name, 'b', 'res should be named b'); -assert.equal(typeof o.a, 'function', 'a should be function'); -assert.equal(typeof o.b, 'function', 'b should be function'); -assert.equal(res, o.b, 'result should be global b function'); +assert.strictEqual(typeof res, 'function', 'result should be function'); +assert.strictEqual(res.name, 'b', 'res should be named b'); +assert.strictEqual(typeof o.a, 'function', 'a should be function'); +assert.strictEqual(typeof o.b, 'function', 'b should be function'); +assert.strictEqual(res, o.b, 'result should be global b function'); console.log('ok'); diff --git a/test/parallel/test-vm-global-define-property.js b/test/parallel/test-vm-global-define-property.js index 62a714615ddc31..83f6073d1ceaf1 100644 --- a/test/parallel/test-vm-global-define-property.js +++ b/test/parallel/test-vm-global-define-property.js @@ -20,7 +20,7 @@ const o = vm.createContext({ console: console, x: x }); const res = vm.runInContext(code, o, 'test'); assert(res); -assert.equal(typeof res, 'object'); -assert.equal(res, x); -assert.equal(o.f, res); +assert.strictEqual(typeof res, 'object'); +assert.strictEqual(res, x); +assert.strictEqual(o.f, res); assert.deepStrictEqual(Object.keys(o), ['console', 'x', 'g', 'f']); diff --git a/test/parallel/test-vm-new-script-new-context.js b/test/parallel/test-vm-new-script-new-context.js index a02627668f6db7..693a041138602f 100644 --- a/test/parallel/test-vm-new-script-new-context.js +++ b/test/parallel/test-vm-new-script-new-context.js @@ -10,8 +10,8 @@ let script = new Script('\'passed\';'); console.error('script created'); const result1 = script.runInNewContext(); const result2 = script.runInNewContext(); -assert.equal('passed', result1); -assert.equal('passed', result2); +assert.strictEqual('passed', result1); +assert.strictEqual('passed', result2); console.error('thrown error'); script = new Script('throw new Error(\'test\');'); @@ -30,7 +30,7 @@ assert.throws(function() { global.hello = 5; script = new Script('hello = 2'); script.runInNewContext(); -assert.equal(5, global.hello); +assert.strictEqual(5, global.hello); console.error('pass values in and out'); @@ -43,21 +43,21 @@ script = new Script(global.code); /* eslint-disable no-unused-vars */ const baz = script.runInNewContext(global.obj); /* eslint-enable no-unused-vars */ -assert.equal(1, global.obj.foo); -assert.equal(2, global.obj.bar); -assert.equal(2, global.foo); +assert.strictEqual(1, global.obj.foo); +assert.strictEqual(2, global.obj.bar); +assert.strictEqual(2, global.foo); console.error('call a function by reference'); script = new Script('f()'); function changeFoo() { global.foo = 100; } script.runInNewContext({ f: changeFoo }); -assert.equal(global.foo, 100); +assert.strictEqual(global.foo, 100); console.error('modify an object by reference'); script = new Script('f.a = 2'); const f = { a: 1 }; script.runInNewContext({ f: f }); -assert.equal(f.a, 2); +assert.strictEqual(f.a, 2); assert.throws(function() { script.runInNewContext(); diff --git a/test/parallel/test-vm-new-script-this-context.js b/test/parallel/test-vm-new-script-this-context.js index fb7e2719855174..3df5dc1b5020d5 100644 --- a/test/parallel/test-vm-new-script-this-context.js +++ b/test/parallel/test-vm-new-script-this-context.js @@ -8,7 +8,7 @@ common.globalCheck = false; console.error('run a string'); let script = new Script('\'passed\';'); const result = script.runInThisContext(script); -assert.equal('passed', result); +assert.strictEqual('passed', result); console.error('thrown error'); script = new Script('throw new Error(\'test\');'); @@ -19,7 +19,7 @@ assert.throws(function() { global.hello = 5; script = new Script('hello = 2'); script.runInThisContext(script); -assert.equal(2, global.hello); +assert.strictEqual(2, global.hello); console.error('pass values'); @@ -30,12 +30,12 @@ global.foo = 2; global.obj = { foo: 0, baz: 3 }; script = new Script(global.code); script.runInThisContext(script); -assert.equal(0, global.obj.foo); -assert.equal(2, global.bar); -assert.equal(1, global.foo); +assert.strictEqual(0, global.obj.foo); +assert.strictEqual(2, global.bar); +assert.strictEqual(1, global.foo); console.error('call a function'); global.f = function() { global.foo = 100; }; script = new Script('f()'); script.runInThisContext(script); -assert.equal(100, global.foo); +assert.strictEqual(100, global.foo); diff --git a/test/parallel/test-vm-run-in-new-context.js b/test/parallel/test-vm-run-in-new-context.js index b00e5a973e0d25..7b096ffc3fdc5f 100644 --- a/test/parallel/test-vm-run-in-new-context.js +++ b/test/parallel/test-vm-run-in-new-context.js @@ -5,13 +5,14 @@ const common = require('../common'); const assert = require('assert'); const vm = require('vm'); -assert.equal(typeof global.gc, 'function', 'Run this test with --expose-gc'); +assert.strictEqual(typeof global.gc, 'function', + 'Run this test with --expose-gc'); common.globalCheck = false; console.error('run a string'); const result = vm.runInNewContext('\'passed\';'); -assert.equal('passed', result); +assert.strictEqual('passed', result); console.error('thrown error'); assert.throws(function() { @@ -20,7 +21,7 @@ assert.throws(function() { global.hello = 5; vm.runInNewContext('hello = 2'); -assert.equal(5, global.hello); +assert.strictEqual(5, global.hello); console.error('pass values in and out'); @@ -32,19 +33,19 @@ global.obj = { foo: 0, baz: 3 }; /* eslint-disable no-unused-vars */ const baz = vm.runInNewContext(global.code, global.obj); /* eslint-enable no-unused-vars */ -assert.equal(1, global.obj.foo); -assert.equal(2, global.obj.bar); -assert.equal(2, global.foo); +assert.strictEqual(1, global.obj.foo); +assert.strictEqual(2, global.obj.bar); +assert.strictEqual(2, global.foo); console.error('call a function by reference'); function changeFoo() { global.foo = 100; } vm.runInNewContext('f()', { f: changeFoo }); -assert.equal(global.foo, 100); +assert.strictEqual(global.foo, 100); console.error('modify an object by reference'); const f = { a: 1 }; vm.runInNewContext('f.a = 2', { f: f }); -assert.equal(f.a, 2); +assert.strictEqual(f.a, 2); console.error('use function in context without referencing context'); const fn = vm.runInNewContext('(function() { obj.p = {}; })', { obj: {} }); diff --git a/test/parallel/test-vm-syntax-error-message.js b/test/parallel/test-vm-syntax-error-message.js index 1a97393d6d97a7..c0a00d06aa54f8 100644 --- a/test/parallel/test-vm-syntax-error-message.js +++ b/test/parallel/test-vm-syntax-error-message.js @@ -22,5 +22,5 @@ p.stdout.on('data', function(data) { }); process.on('exit', function() { - assert.equal(output.replace(/[\r\n]+/g, ''), 'boo'); + assert.strictEqual(output.replace(/[\r\n]+/g, ''), 'boo'); }); diff --git a/test/parallel/test-writedouble.js b/test/parallel/test-writedouble.js index 935f9e7ae08ffd..fa9c94022d419b 100644 --- a/test/parallel/test-writedouble.js +++ b/test/parallel/test-writedouble.js @@ -10,140 +10,140 @@ function test(clazz) { buffer.writeDoubleBE(2.225073858507201e-308, 0); buffer.writeDoubleLE(2.225073858507201e-308, 8); - assert.equal(0x00, buffer[0]); - assert.equal(0x0f, buffer[1]); - assert.equal(0xff, buffer[2]); - assert.equal(0xff, buffer[3]); - assert.equal(0xff, buffer[4]); - assert.equal(0xff, buffer[5]); - assert.equal(0xff, buffer[6]); - assert.equal(0xff, buffer[7]); - assert.equal(0xff, buffer[8]); - assert.equal(0xff, buffer[9]); - assert.equal(0xff, buffer[10]); - assert.equal(0xff, buffer[11]); - assert.equal(0xff, buffer[12]); - assert.equal(0xff, buffer[13]); - assert.equal(0x0f, buffer[14]); - assert.equal(0x00, buffer[15]); + assert.strictEqual(0x00, buffer[0]); + assert.strictEqual(0x0f, buffer[1]); + assert.strictEqual(0xff, buffer[2]); + assert.strictEqual(0xff, buffer[3]); + assert.strictEqual(0xff, buffer[4]); + assert.strictEqual(0xff, buffer[5]); + assert.strictEqual(0xff, buffer[6]); + assert.strictEqual(0xff, buffer[7]); + assert.strictEqual(0xff, buffer[8]); + assert.strictEqual(0xff, buffer[9]); + assert.strictEqual(0xff, buffer[10]); + assert.strictEqual(0xff, buffer[11]); + assert.strictEqual(0xff, buffer[12]); + assert.strictEqual(0xff, buffer[13]); + assert.strictEqual(0x0f, buffer[14]); + assert.strictEqual(0x00, buffer[15]); buffer.writeDoubleBE(1.0000000000000004, 0); buffer.writeDoubleLE(1.0000000000000004, 8); - assert.equal(0x3f, buffer[0]); - assert.equal(0xf0, buffer[1]); - assert.equal(0x00, buffer[2]); - assert.equal(0x00, buffer[3]); - assert.equal(0x00, buffer[4]); - assert.equal(0x00, buffer[5]); - assert.equal(0x00, buffer[6]); - assert.equal(0x02, buffer[7]); - assert.equal(0x02, buffer[8]); - assert.equal(0x00, buffer[9]); - assert.equal(0x00, buffer[10]); - assert.equal(0x00, buffer[11]); - assert.equal(0x00, buffer[12]); - assert.equal(0x00, buffer[13]); - assert.equal(0xf0, buffer[14]); - assert.equal(0x3f, buffer[15]); + assert.strictEqual(0x3f, buffer[0]); + assert.strictEqual(0xf0, buffer[1]); + assert.strictEqual(0x00, buffer[2]); + assert.strictEqual(0x00, buffer[3]); + assert.strictEqual(0x00, buffer[4]); + assert.strictEqual(0x00, buffer[5]); + assert.strictEqual(0x00, buffer[6]); + assert.strictEqual(0x02, buffer[7]); + assert.strictEqual(0x02, buffer[8]); + assert.strictEqual(0x00, buffer[9]); + assert.strictEqual(0x00, buffer[10]); + assert.strictEqual(0x00, buffer[11]); + assert.strictEqual(0x00, buffer[12]); + assert.strictEqual(0x00, buffer[13]); + assert.strictEqual(0xf0, buffer[14]); + assert.strictEqual(0x3f, buffer[15]); buffer.writeDoubleBE(-2, 0); buffer.writeDoubleLE(-2, 8); - assert.equal(0xc0, buffer[0]); - assert.equal(0x00, buffer[1]); - assert.equal(0x00, buffer[2]); - assert.equal(0x00, buffer[3]); - assert.equal(0x00, buffer[4]); - assert.equal(0x00, buffer[5]); - assert.equal(0x00, buffer[6]); - assert.equal(0x00, buffer[7]); - assert.equal(0x00, buffer[8]); - assert.equal(0x00, buffer[9]); - assert.equal(0x00, buffer[10]); - assert.equal(0x00, buffer[11]); - assert.equal(0x00, buffer[12]); - assert.equal(0x00, buffer[13]); - assert.equal(0x00, buffer[14]); - assert.equal(0xc0, buffer[15]); + assert.strictEqual(0xc0, buffer[0]); + assert.strictEqual(0x00, buffer[1]); + assert.strictEqual(0x00, buffer[2]); + assert.strictEqual(0x00, buffer[3]); + assert.strictEqual(0x00, buffer[4]); + assert.strictEqual(0x00, buffer[5]); + assert.strictEqual(0x00, buffer[6]); + assert.strictEqual(0x00, buffer[7]); + assert.strictEqual(0x00, buffer[8]); + assert.strictEqual(0x00, buffer[9]); + assert.strictEqual(0x00, buffer[10]); + assert.strictEqual(0x00, buffer[11]); + assert.strictEqual(0x00, buffer[12]); + assert.strictEqual(0x00, buffer[13]); + assert.strictEqual(0x00, buffer[14]); + assert.strictEqual(0xc0, buffer[15]); buffer.writeDoubleBE(1.7976931348623157e+308, 0); buffer.writeDoubleLE(1.7976931348623157e+308, 8); - assert.equal(0x7f, buffer[0]); - assert.equal(0xef, buffer[1]); - assert.equal(0xff, buffer[2]); - assert.equal(0xff, buffer[3]); - assert.equal(0xff, buffer[4]); - assert.equal(0xff, buffer[5]); - assert.equal(0xff, buffer[6]); - assert.equal(0xff, buffer[7]); - assert.equal(0xff, buffer[8]); - assert.equal(0xff, buffer[9]); - assert.equal(0xff, buffer[10]); - assert.equal(0xff, buffer[11]); - assert.equal(0xff, buffer[12]); - assert.equal(0xff, buffer[13]); - assert.equal(0xef, buffer[14]); - assert.equal(0x7f, buffer[15]); + assert.strictEqual(0x7f, buffer[0]); + assert.strictEqual(0xef, buffer[1]); + assert.strictEqual(0xff, buffer[2]); + assert.strictEqual(0xff, buffer[3]); + assert.strictEqual(0xff, buffer[4]); + assert.strictEqual(0xff, buffer[5]); + assert.strictEqual(0xff, buffer[6]); + assert.strictEqual(0xff, buffer[7]); + assert.strictEqual(0xff, buffer[8]); + assert.strictEqual(0xff, buffer[9]); + assert.strictEqual(0xff, buffer[10]); + assert.strictEqual(0xff, buffer[11]); + assert.strictEqual(0xff, buffer[12]); + assert.strictEqual(0xff, buffer[13]); + assert.strictEqual(0xef, buffer[14]); + assert.strictEqual(0x7f, buffer[15]); buffer.writeDoubleBE(0 * -1, 0); buffer.writeDoubleLE(0 * -1, 8); - assert.equal(0x80, buffer[0]); - assert.equal(0x00, buffer[1]); - assert.equal(0x00, buffer[2]); - assert.equal(0x00, buffer[3]); - assert.equal(0x00, buffer[4]); - assert.equal(0x00, buffer[5]); - assert.equal(0x00, buffer[6]); - assert.equal(0x00, buffer[7]); - assert.equal(0x00, buffer[8]); - assert.equal(0x00, buffer[9]); - assert.equal(0x00, buffer[10]); - assert.equal(0x00, buffer[11]); - assert.equal(0x00, buffer[12]); - assert.equal(0x00, buffer[13]); - assert.equal(0x00, buffer[14]); - assert.equal(0x80, buffer[15]); + assert.strictEqual(0x80, buffer[0]); + assert.strictEqual(0x00, buffer[1]); + assert.strictEqual(0x00, buffer[2]); + assert.strictEqual(0x00, buffer[3]); + assert.strictEqual(0x00, buffer[4]); + assert.strictEqual(0x00, buffer[5]); + assert.strictEqual(0x00, buffer[6]); + assert.strictEqual(0x00, buffer[7]); + assert.strictEqual(0x00, buffer[8]); + assert.strictEqual(0x00, buffer[9]); + assert.strictEqual(0x00, buffer[10]); + assert.strictEqual(0x00, buffer[11]); + assert.strictEqual(0x00, buffer[12]); + assert.strictEqual(0x00, buffer[13]); + assert.strictEqual(0x00, buffer[14]); + assert.strictEqual(0x80, buffer[15]); buffer.writeDoubleBE(Infinity, 0); buffer.writeDoubleLE(Infinity, 8); - assert.equal(0x7F, buffer[0]); - assert.equal(0xF0, buffer[1]); - assert.equal(0x00, buffer[2]); - assert.equal(0x00, buffer[3]); - assert.equal(0x00, buffer[4]); - assert.equal(0x00, buffer[5]); - assert.equal(0x00, buffer[6]); - assert.equal(0x00, buffer[7]); - assert.equal(0x00, buffer[8]); - assert.equal(0x00, buffer[9]); - assert.equal(0x00, buffer[10]); - assert.equal(0x00, buffer[11]); - assert.equal(0x00, buffer[12]); - assert.equal(0x00, buffer[13]); - assert.equal(0xF0, buffer[14]); - assert.equal(0x7F, buffer[15]); - assert.equal(Infinity, buffer.readDoubleBE(0)); - assert.equal(Infinity, buffer.readDoubleLE(8)); + assert.strictEqual(0x7F, buffer[0]); + assert.strictEqual(0xF0, buffer[1]); + assert.strictEqual(0x00, buffer[2]); + assert.strictEqual(0x00, buffer[3]); + assert.strictEqual(0x00, buffer[4]); + assert.strictEqual(0x00, buffer[5]); + assert.strictEqual(0x00, buffer[6]); + assert.strictEqual(0x00, buffer[7]); + assert.strictEqual(0x00, buffer[8]); + assert.strictEqual(0x00, buffer[9]); + assert.strictEqual(0x00, buffer[10]); + assert.strictEqual(0x00, buffer[11]); + assert.strictEqual(0x00, buffer[12]); + assert.strictEqual(0x00, buffer[13]); + assert.strictEqual(0xF0, buffer[14]); + assert.strictEqual(0x7F, buffer[15]); + assert.strictEqual(Infinity, buffer.readDoubleBE(0)); + assert.strictEqual(Infinity, buffer.readDoubleLE(8)); buffer.writeDoubleBE(-Infinity, 0); buffer.writeDoubleLE(-Infinity, 8); - assert.equal(0xFF, buffer[0]); - assert.equal(0xF0, buffer[1]); - assert.equal(0x00, buffer[2]); - assert.equal(0x00, buffer[3]); - assert.equal(0x00, buffer[4]); - assert.equal(0x00, buffer[5]); - assert.equal(0x00, buffer[6]); - assert.equal(0x00, buffer[7]); - assert.equal(0x00, buffer[8]); - assert.equal(0x00, buffer[9]); - assert.equal(0x00, buffer[10]); - assert.equal(0x00, buffer[11]); - assert.equal(0x00, buffer[12]); - assert.equal(0x00, buffer[13]); - assert.equal(0xF0, buffer[14]); - assert.equal(0xFF, buffer[15]); - assert.equal(-Infinity, buffer.readDoubleBE(0)); - assert.equal(-Infinity, buffer.readDoubleLE(8)); + assert.strictEqual(0xFF, buffer[0]); + assert.strictEqual(0xF0, buffer[1]); + assert.strictEqual(0x00, buffer[2]); + assert.strictEqual(0x00, buffer[3]); + assert.strictEqual(0x00, buffer[4]); + assert.strictEqual(0x00, buffer[5]); + assert.strictEqual(0x00, buffer[6]); + assert.strictEqual(0x00, buffer[7]); + assert.strictEqual(0x00, buffer[8]); + assert.strictEqual(0x00, buffer[9]); + assert.strictEqual(0x00, buffer[10]); + assert.strictEqual(0x00, buffer[11]); + assert.strictEqual(0x00, buffer[12]); + assert.strictEqual(0x00, buffer[13]); + assert.strictEqual(0xF0, buffer[14]); + assert.strictEqual(0xFF, buffer[15]); + assert.strictEqual(-Infinity, buffer.readDoubleBE(0)); + assert.strictEqual(-Infinity, buffer.readDoubleLE(8)); buffer.writeDoubleBE(NaN, 0); buffer.writeDoubleLE(NaN, 8); diff --git a/test/parallel/test-writefloat.js b/test/parallel/test-writefloat.js index 113e97c6d333b7..aeb62c8c022484 100644 --- a/test/parallel/test-writefloat.js +++ b/test/parallel/test-writefloat.js @@ -10,86 +10,86 @@ function test(clazz) { buffer.writeFloatBE(1, 0); buffer.writeFloatLE(1, 4); - assert.equal(0x3f, buffer[0]); - assert.equal(0x80, buffer[1]); - assert.equal(0x00, buffer[2]); - assert.equal(0x00, buffer[3]); - assert.equal(0x00, buffer[4]); - assert.equal(0x00, buffer[5]); - assert.equal(0x80, buffer[6]); - assert.equal(0x3f, buffer[7]); + assert.strictEqual(0x3f, buffer[0]); + assert.strictEqual(0x80, buffer[1]); + assert.strictEqual(0x00, buffer[2]); + assert.strictEqual(0x00, buffer[3]); + assert.strictEqual(0x00, buffer[4]); + assert.strictEqual(0x00, buffer[5]); + assert.strictEqual(0x80, buffer[6]); + assert.strictEqual(0x3f, buffer[7]); buffer.writeFloatBE(1 / 3, 0); buffer.writeFloatLE(1 / 3, 4); - assert.equal(0x3e, buffer[0]); - assert.equal(0xaa, buffer[1]); - assert.equal(0xaa, buffer[2]); - assert.equal(0xab, buffer[3]); - assert.equal(0xab, buffer[4]); - assert.equal(0xaa, buffer[5]); - assert.equal(0xaa, buffer[6]); - assert.equal(0x3e, buffer[7]); + assert.strictEqual(0x3e, buffer[0]); + assert.strictEqual(0xaa, buffer[1]); + assert.strictEqual(0xaa, buffer[2]); + assert.strictEqual(0xab, buffer[3]); + assert.strictEqual(0xab, buffer[4]); + assert.strictEqual(0xaa, buffer[5]); + assert.strictEqual(0xaa, buffer[6]); + assert.strictEqual(0x3e, buffer[7]); buffer.writeFloatBE(3.4028234663852886e+38, 0); buffer.writeFloatLE(3.4028234663852886e+38, 4); - assert.equal(0x7f, buffer[0]); - assert.equal(0x7f, buffer[1]); - assert.equal(0xff, buffer[2]); - assert.equal(0xff, buffer[3]); - assert.equal(0xff, buffer[4]); - assert.equal(0xff, buffer[5]); - assert.equal(0x7f, buffer[6]); - assert.equal(0x7f, buffer[7]); + assert.strictEqual(0x7f, buffer[0]); + assert.strictEqual(0x7f, buffer[1]); + assert.strictEqual(0xff, buffer[2]); + assert.strictEqual(0xff, buffer[3]); + assert.strictEqual(0xff, buffer[4]); + assert.strictEqual(0xff, buffer[5]); + assert.strictEqual(0x7f, buffer[6]); + assert.strictEqual(0x7f, buffer[7]); buffer.writeFloatLE(1.1754943508222875e-38, 0); buffer.writeFloatBE(1.1754943508222875e-38, 4); - assert.equal(0x00, buffer[0]); - assert.equal(0x00, buffer[1]); - assert.equal(0x80, buffer[2]); - assert.equal(0x00, buffer[3]); - assert.equal(0x00, buffer[4]); - assert.equal(0x80, buffer[5]); - assert.equal(0x00, buffer[6]); - assert.equal(0x00, buffer[7]); + assert.strictEqual(0x00, buffer[0]); + assert.strictEqual(0x00, buffer[1]); + assert.strictEqual(0x80, buffer[2]); + assert.strictEqual(0x00, buffer[3]); + assert.strictEqual(0x00, buffer[4]); + assert.strictEqual(0x80, buffer[5]); + assert.strictEqual(0x00, buffer[6]); + assert.strictEqual(0x00, buffer[7]); buffer.writeFloatBE(0 * -1, 0); buffer.writeFloatLE(0 * -1, 4); - assert.equal(0x80, buffer[0]); - assert.equal(0x00, buffer[1]); - assert.equal(0x00, buffer[2]); - assert.equal(0x00, buffer[3]); - assert.equal(0x00, buffer[4]); - assert.equal(0x00, buffer[5]); - assert.equal(0x00, buffer[6]); - assert.equal(0x80, buffer[7]); + assert.strictEqual(0x80, buffer[0]); + assert.strictEqual(0x00, buffer[1]); + assert.strictEqual(0x00, buffer[2]); + assert.strictEqual(0x00, buffer[3]); + assert.strictEqual(0x00, buffer[4]); + assert.strictEqual(0x00, buffer[5]); + assert.strictEqual(0x00, buffer[6]); + assert.strictEqual(0x80, buffer[7]); buffer.writeFloatBE(Infinity, 0); buffer.writeFloatLE(Infinity, 4); - assert.equal(0x7F, buffer[0]); - assert.equal(0x80, buffer[1]); - assert.equal(0x00, buffer[2]); - assert.equal(0x00, buffer[3]); - assert.equal(0x00, buffer[4]); - assert.equal(0x00, buffer[5]); - assert.equal(0x80, buffer[6]); - assert.equal(0x7F, buffer[7]); - assert.equal(Infinity, buffer.readFloatBE(0)); - assert.equal(Infinity, buffer.readFloatLE(4)); + assert.strictEqual(0x7F, buffer[0]); + assert.strictEqual(0x80, buffer[1]); + assert.strictEqual(0x00, buffer[2]); + assert.strictEqual(0x00, buffer[3]); + assert.strictEqual(0x00, buffer[4]); + assert.strictEqual(0x00, buffer[5]); + assert.strictEqual(0x80, buffer[6]); + assert.strictEqual(0x7F, buffer[7]); + assert.strictEqual(Infinity, buffer.readFloatBE(0)); + assert.strictEqual(Infinity, buffer.readFloatLE(4)); buffer.writeFloatBE(-Infinity, 0); buffer.writeFloatLE(-Infinity, 4); // Darwin ia32 does the other kind of NaN. // Compiler bug. No one really cares. assert(0xFF === buffer[0] || 0x7F === buffer[0]); - assert.equal(0x80, buffer[1]); - assert.equal(0x00, buffer[2]); - assert.equal(0x00, buffer[3]); - assert.equal(0x00, buffer[4]); - assert.equal(0x00, buffer[5]); - assert.equal(0x80, buffer[6]); - assert.equal(0xFF, buffer[7]); - assert.equal(-Infinity, buffer.readFloatBE(0)); - assert.equal(-Infinity, buffer.readFloatLE(4)); + assert.strictEqual(0x80, buffer[1]); + assert.strictEqual(0x00, buffer[2]); + assert.strictEqual(0x00, buffer[3]); + assert.strictEqual(0x00, buffer[4]); + assert.strictEqual(0x00, buffer[5]); + assert.strictEqual(0x80, buffer[6]); + assert.strictEqual(0xFF, buffer[7]); + assert.strictEqual(-Infinity, buffer.readFloatBE(0)); + assert.strictEqual(-Infinity, buffer.readFloatLE(4)); buffer.writeFloatBE(NaN, 0); buffer.writeFloatLE(NaN, 4); diff --git a/test/parallel/test-writeint.js b/test/parallel/test-writeint.js index 838b1ce4798b75..70599dc17750d7 100644 --- a/test/parallel/test-writeint.js +++ b/test/parallel/test-writeint.js @@ -12,8 +12,8 @@ function test8(clazz) { buffer.writeInt8(0x23, 0); buffer.writeInt8(-5, 1); - assert.equal(0x23, buffer[0]); - assert.equal(0xfb, buffer[1]); + assert.strictEqual(0x23, buffer[0]); + assert.strictEqual(0xfb, buffer[1]); /* Make sure we handle truncation correctly */ assert.throws(function() { @@ -27,8 +27,8 @@ function test8(clazz) { buffer.writeInt8(0x7f, 0); buffer.writeInt8(-0x80, 1); - assert.equal(0x7f, buffer[0]); - assert.equal(0x80, buffer[1]); + assert.strictEqual(0x7f, buffer[0]); + assert.strictEqual(0x80, buffer[1]); assert.throws(function() { buffer.writeInt8(0x7f + 1, 0); }, errorOutOfBounds); @@ -43,32 +43,32 @@ function test16(clazz) { buffer.writeInt16BE(0x0023, 0); buffer.writeInt16LE(0x0023, 2); - assert.equal(0x00, buffer[0]); - assert.equal(0x23, buffer[1]); - assert.equal(0x23, buffer[2]); - assert.equal(0x00, buffer[3]); + assert.strictEqual(0x00, buffer[0]); + assert.strictEqual(0x23, buffer[1]); + assert.strictEqual(0x23, buffer[2]); + assert.strictEqual(0x00, buffer[3]); buffer.writeInt16BE(-5, 0); buffer.writeInt16LE(-5, 2); - assert.equal(0xff, buffer[0]); - assert.equal(0xfb, buffer[1]); - assert.equal(0xfb, buffer[2]); - assert.equal(0xff, buffer[3]); + assert.strictEqual(0xff, buffer[0]); + assert.strictEqual(0xfb, buffer[1]); + assert.strictEqual(0xfb, buffer[2]); + assert.strictEqual(0xff, buffer[3]); buffer.writeInt16BE(-1679, 1); buffer.writeInt16LE(-1679, 3); - assert.equal(0xf9, buffer[1]); - assert.equal(0x71, buffer[2]); - assert.equal(0x71, buffer[3]); - assert.equal(0xf9, buffer[4]); + assert.strictEqual(0xf9, buffer[1]); + assert.strictEqual(0x71, buffer[2]); + assert.strictEqual(0x71, buffer[3]); + assert.strictEqual(0xf9, buffer[4]); /* Make sure we handle min/max correctly */ buffer.writeInt16BE(0x7fff, 0); buffer.writeInt16BE(-0x8000, 2); - assert.equal(0x7f, buffer[0]); - assert.equal(0xff, buffer[1]); - assert.equal(0x80, buffer[2]); - assert.equal(0x00, buffer[3]); + assert.strictEqual(0x7f, buffer[0]); + assert.strictEqual(0xff, buffer[1]); + assert.strictEqual(0x80, buffer[2]); + assert.strictEqual(0x00, buffer[3]); assert.throws(function() { buffer.writeInt16BE(0x7fff + 1, 0); }, errorOutOfBounds); @@ -78,10 +78,10 @@ function test16(clazz) { buffer.writeInt16LE(0x7fff, 0); buffer.writeInt16LE(-0x8000, 2); - assert.equal(0xff, buffer[0]); - assert.equal(0x7f, buffer[1]); - assert.equal(0x00, buffer[2]); - assert.equal(0x80, buffer[3]); + assert.strictEqual(0xff, buffer[0]); + assert.strictEqual(0x7f, buffer[1]); + assert.strictEqual(0x00, buffer[2]); + assert.strictEqual(0x80, buffer[3]); assert.throws(function() { buffer.writeInt16LE(0x7fff + 1, 0); }, errorOutOfBounds); @@ -96,48 +96,48 @@ function test32(clazz) { buffer.writeInt32BE(0x23, 0); buffer.writeInt32LE(0x23, 4); - assert.equal(0x00, buffer[0]); - assert.equal(0x00, buffer[1]); - assert.equal(0x00, buffer[2]); - assert.equal(0x23, buffer[3]); - assert.equal(0x23, buffer[4]); - assert.equal(0x00, buffer[5]); - assert.equal(0x00, buffer[6]); - assert.equal(0x00, buffer[7]); + assert.strictEqual(0x00, buffer[0]); + assert.strictEqual(0x00, buffer[1]); + assert.strictEqual(0x00, buffer[2]); + assert.strictEqual(0x23, buffer[3]); + assert.strictEqual(0x23, buffer[4]); + assert.strictEqual(0x00, buffer[5]); + assert.strictEqual(0x00, buffer[6]); + assert.strictEqual(0x00, buffer[7]); buffer.writeInt32BE(-5, 0); buffer.writeInt32LE(-5, 4); - assert.equal(0xff, buffer[0]); - assert.equal(0xff, buffer[1]); - assert.equal(0xff, buffer[2]); - assert.equal(0xfb, buffer[3]); - assert.equal(0xfb, buffer[4]); - assert.equal(0xff, buffer[5]); - assert.equal(0xff, buffer[6]); - assert.equal(0xff, buffer[7]); + assert.strictEqual(0xff, buffer[0]); + assert.strictEqual(0xff, buffer[1]); + assert.strictEqual(0xff, buffer[2]); + assert.strictEqual(0xfb, buffer[3]); + assert.strictEqual(0xfb, buffer[4]); + assert.strictEqual(0xff, buffer[5]); + assert.strictEqual(0xff, buffer[6]); + assert.strictEqual(0xff, buffer[7]); buffer.writeInt32BE(-805306713, 0); buffer.writeInt32LE(-805306713, 4); - assert.equal(0xcf, buffer[0]); - assert.equal(0xff, buffer[1]); - assert.equal(0xfe, buffer[2]); - assert.equal(0xa7, buffer[3]); - assert.equal(0xa7, buffer[4]); - assert.equal(0xfe, buffer[5]); - assert.equal(0xff, buffer[6]); - assert.equal(0xcf, buffer[7]); + assert.strictEqual(0xcf, buffer[0]); + assert.strictEqual(0xff, buffer[1]); + assert.strictEqual(0xfe, buffer[2]); + assert.strictEqual(0xa7, buffer[3]); + assert.strictEqual(0xa7, buffer[4]); + assert.strictEqual(0xfe, buffer[5]); + assert.strictEqual(0xff, buffer[6]); + assert.strictEqual(0xcf, buffer[7]); /* Make sure we handle min/max correctly */ buffer.writeInt32BE(0x7fffffff, 0); buffer.writeInt32BE(-0x80000000, 4); - assert.equal(0x7f, buffer[0]); - assert.equal(0xff, buffer[1]); - assert.equal(0xff, buffer[2]); - assert.equal(0xff, buffer[3]); - assert.equal(0x80, buffer[4]); - assert.equal(0x00, buffer[5]); - assert.equal(0x00, buffer[6]); - assert.equal(0x00, buffer[7]); + assert.strictEqual(0x7f, buffer[0]); + assert.strictEqual(0xff, buffer[1]); + assert.strictEqual(0xff, buffer[2]); + assert.strictEqual(0xff, buffer[3]); + assert.strictEqual(0x80, buffer[4]); + assert.strictEqual(0x00, buffer[5]); + assert.strictEqual(0x00, buffer[6]); + assert.strictEqual(0x00, buffer[7]); assert.throws(function() { buffer.writeInt32BE(0x7fffffff + 1, 0); }, errorOutOfBounds); @@ -147,14 +147,14 @@ function test32(clazz) { buffer.writeInt32LE(0x7fffffff, 0); buffer.writeInt32LE(-0x80000000, 4); - assert.equal(0xff, buffer[0]); - assert.equal(0xff, buffer[1]); - assert.equal(0xff, buffer[2]); - assert.equal(0x7f, buffer[3]); - assert.equal(0x00, buffer[4]); - assert.equal(0x00, buffer[5]); - assert.equal(0x00, buffer[6]); - assert.equal(0x80, buffer[7]); + assert.strictEqual(0xff, buffer[0]); + assert.strictEqual(0xff, buffer[1]); + assert.strictEqual(0xff, buffer[2]); + assert.strictEqual(0x7f, buffer[3]); + assert.strictEqual(0x00, buffer[4]); + assert.strictEqual(0x00, buffer[5]); + assert.strictEqual(0x00, buffer[6]); + assert.strictEqual(0x80, buffer[7]); assert.throws(function() { buffer.writeInt32LE(0x7fffffff + 1, 0); }, errorOutOfBounds); diff --git a/test/parallel/test-writeuint.js b/test/parallel/test-writeuint.js index bddb954d248633..e91e1d256d0261 100644 --- a/test/parallel/test-writeuint.js +++ b/test/parallel/test-writeuint.js @@ -19,25 +19,25 @@ function test8(clazz) { data.writeUInt8(23, 1); data.writeUInt8(23, 2); data.writeUInt8(23, 3); - assert.equal(23, data[0]); - assert.equal(23, data[1]); - assert.equal(23, data[2]); - assert.equal(23, data[3]); + assert.strictEqual(23, data[0]); + assert.strictEqual(23, data[1]); + assert.strictEqual(23, data[2]); + assert.strictEqual(23, data[3]); data.writeUInt8(23, 0); data.writeUInt8(23, 1); data.writeUInt8(23, 2); data.writeUInt8(23, 3); - assert.equal(23, data[0]); - assert.equal(23, data[1]); - assert.equal(23, data[2]); - assert.equal(23, data[3]); + assert.strictEqual(23, data[0]); + assert.strictEqual(23, data[1]); + assert.strictEqual(23, data[2]); + assert.strictEqual(23, data[3]); data.writeUInt8(255, 0); - assert.equal(255, data[0]); + assert.strictEqual(255, data[0]); data.writeUInt8(255, 0); - assert.equal(255, data[0]); + assert.strictEqual(255, data[0]); } @@ -46,37 +46,37 @@ function test16(clazz) { const data = new clazz(4); data.writeUInt16BE(value, 0); - assert.equal(0x23, data[0]); - assert.equal(0x43, data[1]); + assert.strictEqual(0x23, data[0]); + assert.strictEqual(0x43, data[1]); data.writeUInt16BE(value, 1); - assert.equal(0x23, data[1]); - assert.equal(0x43, data[2]); + assert.strictEqual(0x23, data[1]); + assert.strictEqual(0x43, data[2]); data.writeUInt16BE(value, 2); - assert.equal(0x23, data[2]); - assert.equal(0x43, data[3]); + assert.strictEqual(0x23, data[2]); + assert.strictEqual(0x43, data[3]); data.writeUInt16LE(value, 0); - assert.equal(0x23, data[1]); - assert.equal(0x43, data[0]); + assert.strictEqual(0x23, data[1]); + assert.strictEqual(0x43, data[0]); data.writeUInt16LE(value, 1); - assert.equal(0x23, data[2]); - assert.equal(0x43, data[1]); + assert.strictEqual(0x23, data[2]); + assert.strictEqual(0x43, data[1]); data.writeUInt16LE(value, 2); - assert.equal(0x23, data[3]); - assert.equal(0x43, data[2]); + assert.strictEqual(0x23, data[3]); + assert.strictEqual(0x43, data[2]); value = 0xff80; data.writeUInt16LE(value, 0); - assert.equal(0xff, data[1]); - assert.equal(0x80, data[0]); + assert.strictEqual(0xff, data[1]); + assert.strictEqual(0x80, data[0]); data.writeUInt16BE(value, 0); - assert.equal(0xff, data[0]); - assert.equal(0x80, data[1]); + assert.strictEqual(0xff, data[0]); + assert.strictEqual(0x80, data[1]); } @@ -85,40 +85,40 @@ function test32(clazz) { const value = 0xe7f90a6d; data.writeUInt32BE(value, 0); - assert.equal(0xe7, data[0]); - assert.equal(0xf9, data[1]); - assert.equal(0x0a, data[2]); - assert.equal(0x6d, data[3]); + assert.strictEqual(0xe7, data[0]); + assert.strictEqual(0xf9, data[1]); + assert.strictEqual(0x0a, data[2]); + assert.strictEqual(0x6d, data[3]); data.writeUInt32BE(value, 1); - assert.equal(0xe7, data[1]); - assert.equal(0xf9, data[2]); - assert.equal(0x0a, data[3]); - assert.equal(0x6d, data[4]); + assert.strictEqual(0xe7, data[1]); + assert.strictEqual(0xf9, data[2]); + assert.strictEqual(0x0a, data[3]); + assert.strictEqual(0x6d, data[4]); data.writeUInt32BE(value, 2); - assert.equal(0xe7, data[2]); - assert.equal(0xf9, data[3]); - assert.equal(0x0a, data[4]); - assert.equal(0x6d, data[5]); + assert.strictEqual(0xe7, data[2]); + assert.strictEqual(0xf9, data[3]); + assert.strictEqual(0x0a, data[4]); + assert.strictEqual(0x6d, data[5]); data.writeUInt32LE(value, 0); - assert.equal(0xe7, data[3]); - assert.equal(0xf9, data[2]); - assert.equal(0x0a, data[1]); - assert.equal(0x6d, data[0]); + assert.strictEqual(0xe7, data[3]); + assert.strictEqual(0xf9, data[2]); + assert.strictEqual(0x0a, data[1]); + assert.strictEqual(0x6d, data[0]); data.writeUInt32LE(value, 1); - assert.equal(0xe7, data[4]); - assert.equal(0xf9, data[3]); - assert.equal(0x0a, data[2]); - assert.equal(0x6d, data[1]); + assert.strictEqual(0xe7, data[4]); + assert.strictEqual(0xf9, data[3]); + assert.strictEqual(0x0a, data[2]); + assert.strictEqual(0x6d, data[1]); data.writeUInt32LE(value, 2); - assert.equal(0xe7, data[5]); - assert.equal(0xf9, data[4]); - assert.equal(0x0a, data[3]); - assert.equal(0x6d, data[2]); + assert.strictEqual(0xe7, data[5]); + assert.strictEqual(0xf9, data[4]); + assert.strictEqual(0x0a, data[3]); + assert.strictEqual(0x6d, data[2]); } diff --git a/test/parallel/test-zlib-const.js b/test/parallel/test-zlib-const.js index 22852b297e7ed0..8cb88f66df182f 100644 --- a/test/parallel/test-zlib-const.js +++ b/test/parallel/test-zlib-const.js @@ -4,14 +4,14 @@ const assert = require('assert'); const zlib = require('zlib'); -assert.equal(zlib.Z_OK, 0, 'Z_OK should be 0'); +assert.strictEqual(zlib.Z_OK, 0, 'Z_OK should be 0'); zlib.Z_OK = 1; -assert.equal(zlib.Z_OK, 0, 'Z_OK should be 0'); +assert.strictEqual(zlib.Z_OK, 0, 'Z_OK should be 0'); -assert.equal(zlib.codes.Z_OK, 0, 'Z_OK should be 0'); +assert.strictEqual(zlib.codes.Z_OK, 0, 'Z_OK should be 0'); zlib.codes.Z_OK = 1; -assert.equal(zlib.codes.Z_OK, 0, 'zlib.codes.Z_OK should be 0'); +assert.strictEqual(zlib.codes.Z_OK, 0, 'zlib.codes.Z_OK should be 0'); zlib.codes = {Z_OK: 1}; -assert.equal(zlib.codes.Z_OK, 0, 'zlib.codes.Z_OK should be 0'); +assert.strictEqual(zlib.codes.Z_OK, 0, 'zlib.codes.Z_OK should be 0'); assert.ok(Object.isFrozen(zlib.codes), 'zlib.codes should be frozen'); diff --git a/test/parallel/test-zlib-convenience-methods.js b/test/parallel/test-zlib-convenience-methods.js index b67b65d7d0b689..9b9419c7bfaf47 100644 --- a/test/parallel/test-zlib-convenience-methods.js +++ b/test/parallel/test-zlib-convenience-methods.js @@ -22,8 +22,8 @@ const opts = { zlib[method[0]](expect, opts, function(err, result) { zlib[method[1]](result, opts, function(err, result) { - assert.equal(result, expect, - 'Should get original string after ' + + assert.strictEqual(result.toString(), expect, + 'Should get original string after ' + method[0] + '/' + method[1] + ' with options.'); hadRun++; }); @@ -31,8 +31,8 @@ const opts = { zlib[method[0]](expect, function(err, result) { zlib[method[1]](result, function(err, result) { - assert.equal(result, expect, - 'Should get original string after ' + + assert.strictEqual(result.toString(), expect, + 'Should get original string after ' + method[0] + '/' + method[1] + ' without options.'); hadRun++; }); @@ -40,20 +40,20 @@ const opts = { let result = zlib[method[0] + 'Sync'](expect, opts); result = zlib[method[1] + 'Sync'](result, opts); - assert.equal(result, expect, - 'Should get original string after ' + + assert.strictEqual(result.toString(), expect, + 'Should get original string after ' + method[0] + '/' + method[1] + ' with options.'); hadRun++; result = zlib[method[0] + 'Sync'](expect); result = zlib[method[1] + 'Sync'](result); - assert.equal(result, expect, - 'Should get original string after ' + + assert.strictEqual(result.toString(), expect, + 'Should get original string after ' + method[0] + '/' + method[1] + ' without options.'); hadRun++; }); process.on('exit', function() { - assert.equal(hadRun, 16, 'expect 16 compressions'); + assert.strictEqual(hadRun, 16, 'expect 16 compressions'); }); diff --git a/test/parallel/test-zlib-flush-drain.js b/test/parallel/test-zlib-flush-drain.js index afa4194ac6d453..d446f048b06586 100644 --- a/test/parallel/test-zlib-flush-drain.js +++ b/test/parallel/test-zlib-flush-drain.js @@ -37,12 +37,12 @@ deflater.on('drain', function() { }); process.once('exit', function() { - assert.equal(beforeFlush, true, - 'before calling flush, writable stream should need to drain'); - assert.equal(afterFlush, false, - 'after calling flush, writable stream should not need to drain'); - assert.equal(drainCount, 1, - 'the deflater should have emitted a single drain event'); - assert.equal(flushCount, 2, - 'flush should be called twice'); + assert.strictEqual(beforeFlush, true, 'before calling flush, writable ' + + 'stream should need to drain'); + assert.strictEqual(afterFlush, false, 'after calling flush, writable ' + + 'stream should not need to drain'); + assert.strictEqual(drainCount, 1, + 'the deflater should have emitted a single drain event'); + assert.strictEqual(flushCount, 2, + 'flush should be called twice'); }); diff --git a/test/parallel/test-zlib-from-concatenated-gzip.js b/test/parallel/test-zlib-from-concatenated-gzip.js index 998a086eb76514..f59b6796357e3b 100644 --- a/test/parallel/test-zlib-from-concatenated-gzip.js +++ b/test/parallel/test-zlib-from-concatenated-gzip.js @@ -15,16 +15,18 @@ const data = Buffer.concat([ defEncoded ]); -assert.equal(zlib.gunzipSync(data).toString(), 'abcdef'); +assert.strictEqual(zlib.gunzipSync(data).toString(), 'abcdef'); zlib.gunzip(data, common.mustCall((err, result) => { assert.ifError(err); - assert.equal(result, 'abcdef', 'result should match original string'); + assert.strictEqual(result.toString(), 'abcdef', + 'result should match original string'); })); zlib.unzip(data, common.mustCall((err, result) => { assert.ifError(err); - assert.equal(result, 'abcdef', 'result should match original string'); + assert.strictEqual(result.toString(), 'abcdef', + 'result should match original string'); })); // Multi-member support does not apply to zlib inflate/deflate. @@ -33,7 +35,8 @@ zlib.unzip(Buffer.concat([ zlib.deflateSync('def') ]), common.mustCall((err, result) => { assert.ifError(err); - assert.equal(result, 'abc', 'result should match contents of first "member"'); + assert.strictEqual(result.toString(), 'abc', + 'result should match contents of first "member"'); })); // files that have the "right" magic bytes for starting a new gzip member diff --git a/test/parallel/test-zlib-from-gzip.js b/test/parallel/test-zlib-from-gzip.js index 3c7e96cef92a0a..ac01fc03d11c6f 100644 --- a/test/parallel/test-zlib-from-gzip.js +++ b/test/parallel/test-zlib-from-gzip.js @@ -23,8 +23,8 @@ const out = fs.createWriteStream(outputFile); inp.pipe(gunzip).pipe(out); out.on('close', function() { const actual = fs.readFileSync(outputFile); - assert.equal(actual.length, expect.length, 'length should match'); + assert.strictEqual(actual.length, expect.length, 'length should match'); for (let i = 0, l = actual.length; i < l; i++) { - assert.equal(actual[i], expect[i], 'byte[' + i + ']'); + assert.strictEqual(actual[i], expect[i], 'byte[' + i + ']'); } }); diff --git a/test/parallel/test-zlib-from-string.js b/test/parallel/test-zlib-from-string.js index 0f885ac80ecbe6..ab2f7d023d8bc8 100644 --- a/test/parallel/test-zlib-from-string.js +++ b/test/parallel/test-zlib-from-string.js @@ -34,8 +34,8 @@ const expectedBase64Gzip = 'H4sIAAAAAAAAA11RS05DMQy8yhzg6d2BPSAkJPZu4laWkjiN4' + 'sHnHNzRtagj5AQAA'; zlib.deflate(inputString, function(err, buffer) { - assert.equal(buffer.toString('base64'), expectedBase64Deflate, - 'deflate encoded string should match'); + assert.strictEqual(buffer.toString('base64'), expectedBase64Deflate, + 'deflate encoded string should match'); }); zlib.gzip(inputString, function(err, buffer) { @@ -46,19 +46,19 @@ zlib.gzip(inputString, function(err, buffer) { // result that we're expecting, and this should match what we get // from inflating the known valid deflate data. zlib.gunzip(buffer, function(err, gunzipped) { - assert.equal(gunzipped.toString(), inputString, - 'Should get original string after gzip/gunzip'); + assert.strictEqual(gunzipped.toString(), inputString, + 'Should get original string after gzip/gunzip'); }); }); let buffer = Buffer.from(expectedBase64Deflate, 'base64'); zlib.unzip(buffer, function(err, buffer) { - assert.equal(buffer.toString(), inputString, - 'decoded inflated string should match'); + assert.strictEqual(buffer.toString(), inputString, + 'decoded inflated string should match'); }); buffer = Buffer.from(expectedBase64Gzip, 'base64'); zlib.unzip(buffer, function(err, buffer) { - assert.equal(buffer.toString(), inputString, - 'decoded gunzipped string should match'); + assert.strictEqual(buffer.toString(), inputString, + 'decoded gunzipped string should match'); }); diff --git a/test/parallel/test-zlib-random-byte-pipes.js b/test/parallel/test-zlib-random-byte-pipes.js index 83855ebd1f2c0a..d4cd4319f93c21 100644 --- a/test/parallel/test-zlib-random-byte-pipes.js +++ b/test/parallel/test-zlib-random-byte-pipes.js @@ -154,5 +154,5 @@ out.on('data', function(c) { out.on('data', common.mustCall(function(c) { console.error('hash=%s', c); - assert.equal(c, inp._hash, 'hashes should match'); + assert.strictEqual(c, inp._hash, 'hashes should match'); })); diff --git a/test/parallel/test-zlib-sync-no-event.js b/test/parallel/test-zlib-sync-no-event.js index 81d1ad530de27c..ce9b43a902ecb7 100644 --- a/test/parallel/test-zlib-sync-no-event.js +++ b/test/parallel/test-zlib-sync-no-event.js @@ -17,5 +17,5 @@ const unzipper = new zlib.Gunzip(); unzipper.on('close', shouldNotBeCalled); const unzipped = unzipper._processChunk(zipped, zlib.Z_FINISH); -assert.notEqual(zipped.toString(), message); +assert.notStrictEqual(zipped.toString(), message); assert.strictEqual(unzipped.toString(), message); diff --git a/test/parallel/test-zlib-write-after-flush.js b/test/parallel/test-zlib-write-after-flush.js index f5ad7c6f0e5c91..caacc976e51a46 100644 --- a/test/parallel/test-zlib-write-after-flush.js +++ b/test/parallel/test-zlib-write-after-flush.js @@ -16,10 +16,10 @@ gunz.on('data', function(c) { }); process.on('exit', function() { - assert.equal(output, input); + assert.strictEqual(output, input); // Make sure that the flush flag was set back to normal - assert.equal(gzip._flushFlag, zlib.Z_NO_FLUSH); + assert.strictEqual(gzip._flushFlag, zlib.Z_NO_FLUSH); console.log('ok'); }); diff --git a/test/pummel/test-crypto-dh.js b/test/pummel/test-crypto-dh.js index 30c06b8795db41..03be3ab7ad48e2 100644 --- a/test/pummel/test-crypto-dh.js +++ b/test/pummel/test-crypto-dh.js @@ -52,8 +52,8 @@ for (const name in hashes) { const hash1 = hashes[name]; const hash2 = crypto.createHash('sha1') .update(private_key.toUpperCase()).digest('hex'); - assert.equal(hash1, hash2); - assert.equal(group.getGenerator('hex'), '02'); + assert.strictEqual(hash1, hash2); + assert.strictEqual(group.getGenerator('hex'), '02'); } for (const name in hashes) { diff --git a/test/pummel/test-dtrace-jsstack.js b/test/pummel/test-dtrace-jsstack.js index d1615a3855af43..6c8423c2c9c83b 100644 --- a/test/pummel/test-dtrace-jsstack.js +++ b/test/pummel/test-dtrace-jsstack.js @@ -71,11 +71,12 @@ dtrace.on('exit', function(code) { const frame = line.substr(line.indexOf(sentinel) + sentinel.length); const top = frames.shift(); - assert.equal(frame.indexOf(top), 0, 'unexpected frame where ' + + assert.strictEqual(frame.indexOf(top), 0, 'unexpected frame where ' + top + ' was expected'); } - assert.equal(frames.length, 0, 'did not find expected frame ' + frames[0]); + assert.strictEqual(frames.length, 0, + 'did not find expected frame ' + frames[0]); process.exit(0); }); diff --git a/test/pummel/test-fs-watch-file-slow.js b/test/pummel/test-fs-watch-file-slow.js index 78c36152ecd315..1e9b5eb1f219ff 100644 --- a/test/pummel/test-fs-watch-file-slow.js +++ b/test/pummel/test-fs-watch-file-slow.js @@ -19,14 +19,14 @@ fs.watchFile(FILENAME, {interval: TIMEOUT - 250}, function(curr, prev) { console.log([curr, prev]); switch (++nevents) { case 1: - assert.equal(common.fileExists(FILENAME), false); + assert.strictEqual(common.fileExists(FILENAME), false); break; case 2: case 3: - assert.equal(common.fileExists(FILENAME), true); + assert.strictEqual(common.fileExists(FILENAME), true); break; case 4: - assert.equal(common.fileExists(FILENAME), false); + assert.strictEqual(common.fileExists(FILENAME), false); fs.unwatchFile(FILENAME); break; default: @@ -35,7 +35,7 @@ fs.watchFile(FILENAME, {interval: TIMEOUT - 250}, function(curr, prev) { }); process.on('exit', function() { - assert.equal(nevents, 4); + assert.strictEqual(nevents, 4); }); setTimeout(createFile, TIMEOUT); diff --git a/test/pummel/test-fs-watch-file.js b/test/pummel/test-fs-watch-file.js index 7713fe74ed99aa..3fda41040486df 100644 --- a/test/pummel/test-fs-watch-file.js +++ b/test/pummel/test-fs-watch-file.js @@ -27,10 +27,10 @@ process.on('exit', function() { fs.unlinkSync(filepathTwoAbs); fs.unlinkSync(filenameThree); fs.unlinkSync(filenameFour); - assert.equal(1, watchSeenOne); - assert.equal(2, watchSeenTwo); - assert.equal(1, watchSeenThree); - assert.equal(1, watchSeenFour); + assert.strictEqual(1, watchSeenOne); + assert.strictEqual(2, watchSeenTwo); + assert.strictEqual(1, watchSeenThree); + assert.strictEqual(1, watchSeenFour); }); @@ -122,7 +122,7 @@ assert.doesNotThrow( function() { function a() { ++watchSeenFour; - assert.equal(1, watchSeenFour); + assert.strictEqual(1, watchSeenFour); fs.unwatchFile('.' + path.sep + filenameFour, a); } fs.watchFile(filenameFour, a); diff --git a/test/pummel/test-http-many-keep-alive-connections.js b/test/pummel/test-http-many-keep-alive-connections.js index e465c02a90161c..ee616e1d918e66 100644 --- a/test/pummel/test-http-many-keep-alive-connections.js +++ b/test/pummel/test-http-many-keep-alive-connections.js @@ -10,7 +10,7 @@ let connection; const server = http.Server(function(req, res) { requests++; - assert.equal(req.connection, connection); + assert.strictEqual(req.connection, connection); res.writeHead(200); res.end('hello world\n'); }); @@ -43,6 +43,6 @@ server.listen(common.PORT, function connect() { }); process.on('exit', function() { - assert.equal(expected, responses); - assert.equal(expected, requests); + assert.strictEqual(expected, responses); + assert.strictEqual(expected, requests); }); diff --git a/test/pummel/test-https-ci-reneg-attack.js b/test/pummel/test-https-ci-reneg-attack.js index 850e0949c4a64a..6113ee54ce904b 100644 --- a/test/pummel/test-https-ci-reneg-attack.js +++ b/test/pummel/test-https-ci-reneg-attack.js @@ -71,7 +71,7 @@ function test(next) { }); child.on('exit', function() { - assert.equal(renegs, tls.CLIENT_RENEG_LIMIT + 1); + assert.strictEqual(renegs, tls.CLIENT_RENEG_LIMIT + 1); server.close(); process.nextTick(next); }); @@ -83,7 +83,7 @@ function test(next) { case 'EPIPE': break; default: - assert.equal(err.code, 'ECONNRESET'); + assert.strictEqual(err.code, 'ECONNRESET'); break; } closed = true; diff --git a/test/pummel/test-net-connect-econnrefused.js b/test/pummel/test-net-connect-econnrefused.js index 30da36d983e4f7..4ac55da40553e0 100644 --- a/test/pummel/test-net-connect-econnrefused.js +++ b/test/pummel/test-net-connect-econnrefused.js @@ -18,7 +18,7 @@ function pummel() { let pending; for (pending = 0; pending < ATTEMPTS_PER_ROUND; pending++) { net.createConnection(common.PORT).on('error', function(err) { - assert.equal(err.code, 'ECONNREFUSED'); + assert.strictEqual(err.code, 'ECONNREFUSED'); if (--pending > 0) return; if (rounds === ROUNDS) return check(); rounds++; @@ -30,15 +30,15 @@ function pummel() { function check() { setTimeout(function() { - assert.equal(process._getActiveRequests().length, 0); - assert.equal(process._getActiveHandles().length, 1); // the timer + assert.strictEqual(process._getActiveRequests().length, 0); + assert.strictEqual(process._getActiveHandles().length, 1); // the timer check_called = true; }, 0); } let check_called = false; process.on('exit', function() { - assert.equal(rounds, ROUNDS); - assert.equal(reqs, ROUNDS * ATTEMPTS_PER_ROUND); + assert.strictEqual(rounds, ROUNDS); + assert.strictEqual(reqs, ROUNDS * ATTEMPTS_PER_ROUND); assert(check_called); }); diff --git a/test/pummel/test-net-many-clients.js b/test/pummel/test-net-many-clients.js index a92ae033a09a17..fdcdf1198f8df2 100644 --- a/test/pummel/test-net-many-clients.js +++ b/test/pummel/test-net-many-clients.js @@ -49,8 +49,8 @@ function runClient(callback) { client.on('close', function(had_error) { console.log('.'); - assert.equal(false, had_error); - assert.equal(bytes, client.recved.length); + assert.strictEqual(false, had_error); + assert.strictEqual(bytes, client.recved.length); if (client.fd) { console.log(client.fd); @@ -75,6 +75,6 @@ server.listen(common.PORT, function() { }); process.on('exit', function() { - assert.equal(connections_per_client * concurrency, total_connections); + assert.strictEqual(connections_per_client * concurrency, total_connections); console.log('\nokay!'); }); diff --git a/test/pummel/test-net-pause.js b/test/pummel/test-net-pause.js index db426edbe9c507..6a701d56869afb 100644 --- a/test/pummel/test-net-pause.js +++ b/test/pummel/test-net-pause.js @@ -31,11 +31,11 @@ server.on('listening', function() { setTimeout(function() { chars_recved = recv.length; console.log('pause at: ' + chars_recved); - assert.equal(true, chars_recved > 1); + assert.strictEqual(true, chars_recved > 1); client.pause(); setTimeout(function() { console.log('resume at: ' + chars_recved); - assert.equal(chars_recved, recv.length); + assert.strictEqual(chars_recved, recv.length); client.resume(); setTimeout(function() { @@ -45,7 +45,7 @@ server.on('listening', function() { setTimeout(function() { console.log('resume at: ' + chars_recved); - assert.equal(chars_recved, recv.length); + assert.strictEqual(chars_recved, recv.length); client.resume(); }, 500); @@ -64,6 +64,6 @@ server.on('listening', function() { server.listen(common.PORT); process.on('exit', function() { - assert.equal(N, recv.length); + assert.strictEqual(N, recv.length); console.error('Exit'); }); diff --git a/test/pummel/test-net-pingpong-delay.js b/test/pummel/test-net-pingpong-delay.js index 9a598435d1bd28..2236ba83a88f02 100644 --- a/test/pummel/test-net-pingpong-delay.js +++ b/test/pummel/test-net-pingpong-delay.js @@ -14,30 +14,30 @@ function pingPongTest(port, host, on_complete) { socket.on('data', function(data) { console.log(data); - assert.equal('PING', data); - assert.equal('open', socket.readyState); - assert.equal(true, count <= N); + assert.strictEqual('PING', data); + assert.strictEqual('open', socket.readyState); + assert.strictEqual(true, count <= N); setTimeout(function() { - assert.equal('open', socket.readyState); + assert.strictEqual('open', socket.readyState); socket.write('PONG'); }, DELAY); }); socket.on('timeout', function() { console.error('server-side timeout!!'); - assert.equal(false, true); + assert.strictEqual(false, true); }); socket.on('end', function() { console.log('server-side socket EOF'); - assert.equal('writeOnly', socket.readyState); + assert.strictEqual('writeOnly', socket.readyState); socket.end(); }); socket.on('close', function(had_error) { console.log('server-side socket.end'); - assert.equal(false, had_error); - assert.equal('closed', socket.readyState); + assert.strictEqual(false, had_error); + assert.strictEqual('closed', socket.readyState); socket.server.close(); }); }); @@ -48,17 +48,17 @@ function pingPongTest(port, host, on_complete) { client.setEncoding('utf8'); client.on('connect', function() { - assert.equal('open', client.readyState); + assert.strictEqual('open', client.readyState); client.write('PING'); }); client.on('data', function(data) { console.log(data); - assert.equal('PONG', data); - assert.equal('open', client.readyState); + assert.strictEqual('PONG', data); + assert.strictEqual('open', client.readyState); setTimeout(function() { - assert.equal('open', client.readyState); + assert.strictEqual('open', client.readyState); if (count++ < N) { client.write('PING'); } else { @@ -71,12 +71,12 @@ function pingPongTest(port, host, on_complete) { client.on('timeout', function() { console.error('client-side timeout!!'); - assert.equal(false, true); + assert.strictEqual(false, true); }); client.on('close', common.mustCall(function() { console.log('client.end'); - assert.equal(N + 1, count); + assert.strictEqual(N + 1, count); assert.ok(client_ended); if (on_complete) on_complete(); })); diff --git a/test/pummel/test-net-pingpong.js b/test/pummel/test-net-pingpong.js index 6ede6f9fcb2763..5e0950285739a1 100644 --- a/test/pummel/test-net-pingpong.js +++ b/test/pummel/test-net-pingpong.js @@ -11,16 +11,16 @@ function pingPongTest(port, host, on_complete) { let sent_final_ping = false; const server = net.createServer({ allowHalfOpen: true }, function(socket) { - assert.equal(true, socket.remoteAddress !== null); - assert.equal(true, socket.remoteAddress !== undefined); + assert.strictEqual(true, socket.remoteAddress !== null); + assert.strictEqual(true, socket.remoteAddress !== undefined); const address = socket.remoteAddress; if (host === '127.0.0.1') { - assert.equal(address, '127.0.0.1'); + assert.strictEqual(address, '127.0.0.1'); } else if (host == null || host === 'localhost') { assert(address === '127.0.0.1' || address === '::ffff:127.0.0.1'); } else { console.log('host = ' + host + ', remoteAddress = ' + address); - assert.equal(address, '::1'); + assert.strictEqual(address, '::1'); } socket.setEncoding('utf8'); @@ -29,21 +29,21 @@ function pingPongTest(port, host, on_complete) { socket.on('data', function(data) { console.log('server got: ' + JSON.stringify(data)); - assert.equal('open', socket.readyState); - assert.equal(true, count <= N); + assert.strictEqual('open', socket.readyState); + assert.strictEqual(true, count <= N); if (/PING/.exec(data)) { socket.write('PONG'); } }); socket.on('end', function() { - assert.equal('writeOnly', socket.readyState); + assert.strictEqual('writeOnly', socket.readyState); socket.end(); }); socket.on('close', function(had_error) { - assert.equal(false, had_error); - assert.equal('closed', socket.readyState); + assert.strictEqual(false, had_error); + assert.strictEqual('closed', socket.readyState); socket.server.close(); }); }); @@ -54,21 +54,21 @@ function pingPongTest(port, host, on_complete) { client.setEncoding('utf8'); client.on('connect', function() { - assert.equal('open', client.readyState); + assert.strictEqual('open', client.readyState); client.write('PING'); }); client.on('data', function(data) { console.log('client got: ' + data); - assert.equal('PONG', data); + assert.strictEqual('PONG', data); count += 1; if (sent_final_ping) { - assert.equal('readOnly', client.readyState); + assert.strictEqual('readOnly', client.readyState); return; } else { - assert.equal('open', client.readyState); + assert.strictEqual('open', client.readyState); } if (count < N) { @@ -81,8 +81,8 @@ function pingPongTest(port, host, on_complete) { }); client.on('close', function() { - assert.equal(N + 1, count); - assert.equal(true, sent_final_ping); + assert.strictEqual(N + 1, count); + assert.strictEqual(true, sent_final_ping); if (on_complete) on_complete(); tests_run += 1; }); @@ -97,5 +97,5 @@ pingPongTest(common.PORT + 1, null); if (!common.isSunOS) pingPongTest(common.PORT + 2, '::1'); process.on('exit', function() { - assert.equal(common.isSunOS ? 2 : 3, tests_run); + assert.strictEqual(common.isSunOS ? 2 : 3, tests_run); }); diff --git a/test/pummel/test-net-throttle.js b/test/pummel/test-net-throttle.js index 23f05f4d5eaeaa..c222d0bb17ccfa 100644 --- a/test/pummel/test-net-throttle.js +++ b/test/pummel/test-net-throttle.js @@ -16,7 +16,7 @@ console.log('start server on port ' + common.PORT); const server = net.createServer(function(connection) { connection.write(body.slice(0, part_N)); connection.write(body.slice(part_N, 2 * part_N)); - assert.equal(false, connection.write(body.slice(2 * part_N, N))); + assert.strictEqual(false, connection.write(body.slice(2 * part_N, N))); console.log('bufferSize: ' + connection.bufferSize, 'expecting', N); assert.ok(0 <= connection.bufferSize && connection._writableState.length <= N); @@ -37,7 +37,7 @@ server.listen(common.PORT, function() { console.log('pause'); const x = chars_recved; setTimeout(function() { - assert.equal(chars_recved, x); + assert.strictEqual(chars_recved, x); client.resume(); console.log('resume'); paused = false; @@ -53,6 +53,6 @@ server.listen(common.PORT, function() { process.on('exit', function() { - assert.equal(N, chars_recved); - assert.equal(true, npauses > 2); + assert.strictEqual(N, chars_recved); + assert.strictEqual(true, npauses > 2); }); diff --git a/test/pummel/test-net-timeout.js b/test/pummel/test-net-timeout.js index d6dd8e489cc116..faec443a007f20 100644 --- a/test/pummel/test-net-timeout.js +++ b/test/pummel/test-net-timeout.js @@ -45,7 +45,7 @@ echo_server.listen(common.PORT, function() { }); client.on('data', function(chunk) { - assert.equal('hello\r\n', chunk); + assert.strictEqual('hello\r\n', chunk); if (exchanges++ < 5) { setTimeout(function() { console.log('client write "hello"'); diff --git a/test/pummel/test-net-write-callbacks.js b/test/pummel/test-net-write-callbacks.js index 6c3c1f202a81c3..b29ae6ef808292 100644 --- a/test/pummel/test-net-write-callbacks.js +++ b/test/pummel/test-net-write-callbacks.js @@ -45,5 +45,5 @@ server.listen(common.PORT, function() { }); process.on('exit', function() { - assert.equal(N, cbcount); + assert.strictEqual(N, cbcount); }); diff --git a/test/pummel/test-regress-GH-892.js b/test/pummel/test-regress-GH-892.js index 0619fd84de3b5e..3ec44dfa12bb5b 100644 --- a/test/pummel/test-regress-GH-892.js +++ b/test/pummel/test-regress-GH-892.js @@ -42,7 +42,7 @@ function makeRequest() { child.on('exit', function(code) { assert.ok(/DONE/.test(stderrBuffer)); - assert.equal(0, code); + assert.strictEqual(0, code); }); // The following two lines forward the stdio from the child @@ -78,7 +78,7 @@ const server = https.Server(serverOptions, function(req, res) { }); req.on('end', function() { - assert.equal(bytesExpected, uploadCount); + assert.strictEqual(bytesExpected, uploadCount); res.writeHead(200, {'content-type': 'text/plain'}); res.end('successful upload\n'); }); @@ -91,5 +91,5 @@ server.listen(common.PORT, function() { process.on('exit', function() { console.error('got %d bytes', uploadCount); - assert.equal(uploadCount, bytesExpected); + assert.strictEqual(uploadCount, bytesExpected); }); diff --git a/test/pummel/test-stream-pipe-multi.js b/test/pummel/test-stream-pipe-multi.js index e1e5e011020fe2..478b61c822d4e0 100644 --- a/test/pummel/test-stream-pipe-multi.js +++ b/test/pummel/test-stream-pipe-multi.js @@ -45,8 +45,8 @@ FakeStream.prototype.close = function() { // expect all streams to close properly. process.on('exit', function() { - assert.equal(cnt, wclosed, 'writable streams closed'); - assert.equal(cnt, rclosed, 'readable streams closed'); + assert.strictEqual(cnt, wclosed, 'writable streams closed'); + assert.strictEqual(cnt, rclosed, 'readable streams closed'); }); for (let i = 0; i < chunkSize; i++) { diff --git a/test/pummel/test-stream2-basic.js b/test/pummel/test-stream2-basic.js index 67ee4eb7a812a6..46cc2f63086fbe 100644 --- a/test/pummel/test-stream2-basic.js +++ b/test/pummel/test-stream2-basic.js @@ -87,7 +87,7 @@ function run() { fn({ same: assert.deepStrictEqual, ok: assert, - equal: assert.equal, + equal: assert.strictEqual, end: function() { count--; run(); @@ -97,7 +97,7 @@ function run() { // ensure all tests have run process.on('exit', function() { - assert.equal(count, 0); + assert.strictEqual(count, 0); }); process.nextTick(run); @@ -314,7 +314,7 @@ test('back pressure respected', function(t) { const w1 = new R(); w1.write = function(chunk) { console.error('w1.emit("close")'); - assert.equal(chunk[0], 'one'); + assert.strictEqual(chunk[0], 'one'); w1.emit('close'); process.nextTick(function() { r.pipe(w2); @@ -330,8 +330,8 @@ test('back pressure respected', function(t) { let w2 = new R(); w2.write = function(chunk) { console.error('w2 write', chunk, counter); - assert.equal(chunk[0], expected.shift()); - assert.equal(counter, 0); + assert.strictEqual(chunk[0], expected.shift()); + assert.strictEqual(counter, 0); counter++; @@ -352,8 +352,8 @@ test('back pressure respected', function(t) { let w3 = new R(); w3.write = function(chunk) { console.error('w3 write', chunk, counter); - assert.equal(chunk[0], expected.shift()); - assert.equal(counter, 1); + assert.strictEqual(chunk[0], expected.shift()); + assert.strictEqual(counter, 1); counter++; @@ -370,8 +370,8 @@ test('back pressure respected', function(t) { return false; }; w3.end = function() { - assert.equal(counter, 2); - assert.equal(expected.length, 0); + assert.strictEqual(counter, 2); + assert.strictEqual(expected.length, 0); t.end(); }; }); @@ -387,19 +387,19 @@ test('read(0) for ended streams', function(t) { const v = r.read(0); - assert.equal(v, null); + assert.strictEqual(v, null); const w = new R(); w.write = function(buffer) { written = true; - assert.equal(ended, false); - assert.equal(buffer.toString(), 'foo'); + assert.strictEqual(ended, false); + assert.strictEqual(buffer.toString(), 'foo'); }; w.end = function() { ended = true; - assert.equal(written, true); + assert.strictEqual(written, true); t.end(); }; @@ -420,7 +420,7 @@ test('sync _read ending', function(t) { r.read(); process.nextTick(function() { - assert.equal(called, true); + assert.strictEqual(called, true); t.end(); }); }); diff --git a/test/pummel/test-timers.js b/test/pummel/test-timers.js index 4555582371b9ff..600b7ce35b0913 100644 --- a/test/pummel/test-timers.js +++ b/test/pummel/test-timers.js @@ -10,7 +10,7 @@ let interval_count = 0; clearTimeout(null); clearInterval(null); -assert.equal(true, setTimeout instanceof Function); +assert.strictEqual(true, setTimeout instanceof Function); const starttime = new Date(); setTimeout(common.mustCall(function() { const endtime = new Date(); @@ -19,11 +19,11 @@ setTimeout(common.mustCall(function() { assert.ok(diff > 0); console.error('diff: ' + diff); - assert.equal(true, 1000 - WINDOW < diff && diff < 1000 + WINDOW); + assert.strictEqual(true, 1000 - WINDOW < diff && diff < 1000 + WINDOW); }), 1000); // this timer shouldn't execute -const id = setTimeout(function() { assert.equal(true, false); }, 500); +const id = setTimeout(function() { assert.strictEqual(true, false); }, 500); clearTimeout(id); setInterval(function() { @@ -36,9 +36,9 @@ setInterval(function() { const t = interval_count * 1000; - assert.equal(true, t - WINDOW < diff && diff < t + WINDOW); + assert.strictEqual(true, t - WINDOW < diff && diff < t + WINDOW); - assert.equal(true, interval_count <= 3); + assert.strictEqual(true, interval_count <= 3); if (interval_count === 3) clearInterval(this); }, 1000); @@ -46,13 +46,13 @@ setInterval(function() { // Single param: setTimeout(function(param) { - assert.equal('test param', param); + assert.strictEqual('test param', param); }, 1000, 'test param'); let interval_count2 = 0; setInterval(function(param) { ++interval_count2; - assert.equal('test param', param); + assert.strictEqual('test param', param); if (interval_count2 === 3) clearInterval(this); @@ -61,15 +61,15 @@ setInterval(function(param) { // Multiple param setTimeout(function(param1, param2) { - assert.equal('param1', param1); - assert.equal('param2', param2); + assert.strictEqual('param1', param1); + assert.strictEqual('param2', param2); }, 1000, 'param1', 'param2'); let interval_count3 = 0; setInterval(function(param1, param2) { ++interval_count3; - assert.equal('param1', param1); - assert.equal('param2', param2); + assert.strictEqual('param1', param1); + assert.strictEqual('param2', param2); if (interval_count3 === 3) clearInterval(this); @@ -99,7 +99,8 @@ clearTimeout(y); process.on('exit', function() { - assert.equal(3, interval_count); - assert.equal(11, count4); - assert.equal(0, expectedTimeouts, 'clearTimeout cleared too many timeouts'); + assert.strictEqual(3, interval_count); + assert.strictEqual(11, count4); + assert.strictEqual(0, expectedTimeouts, + 'clearTimeout cleared too many timeouts'); }); diff --git a/test/pummel/test-tls-ci-reneg-attack.js b/test/pummel/test-tls-ci-reneg-attack.js index dd2b43ed60278f..9c2d3da5c3f6b1 100644 --- a/test/pummel/test-tls-ci-reneg-attack.js +++ b/test/pummel/test-tls-ci-reneg-attack.js @@ -69,7 +69,7 @@ function test(next) { }); child.on('exit', function() { - assert.equal(renegs, tls.CLIENT_RENEG_LIMIT + 1); + assert.strictEqual(renegs, tls.CLIENT_RENEG_LIMIT + 1); server.close(); process.nextTick(next); }); @@ -81,7 +81,7 @@ function test(next) { case 'EPIPE': break; default: - assert.equal(err.code, 'ECONNRESET'); + assert.strictEqual(err.code, 'ECONNRESET'); break; } closed = true; diff --git a/test/pummel/test-tls-securepair-client.js b/test/pummel/test-tls-securepair-client.js index 75e7b400592191..cd9299cb790958 100644 --- a/test/pummel/test-tls-securepair-client.js +++ b/test/pummel/test-tls-securepair-client.js @@ -31,9 +31,10 @@ function test1() { function test2() { function check(pair) { // "TLS Web Client Authentication" - assert.equal(pair.cleartext.getPeerCertificate().ext_key_usage.length, 1); - assert.equal(pair.cleartext.getPeerCertificate().ext_key_usage[0], - '1.3.6.1.5.5.7.3.2'); + assert.strictEqual(pair.cleartext.getPeerCertificate().ext_key_usage.length, + 1); + assert.strictEqual(pair.cleartext.getPeerCertificate().ext_key_usage[0], + '1.3.6.1.5.5.7.3.2'); } test('keys/agent4-key.pem', 'keys/agent4-cert.pem', check); } @@ -158,8 +159,8 @@ function test(keyfn, certfn, check, next) { process.on('exit', function() { - assert.equal(0, serverExitCode); - assert.equal('WAIT-SERVER-CLOSE', state); + assert.strictEqual(0, serverExitCode); + assert.strictEqual('WAIT-SERVER-CLOSE', state); assert.ok(gotWriteCallback); }); } diff --git a/test/pummel/test-tls-server-large-request.js b/test/pummel/test-tls-server-large-request.js index f79c4d95cfa031..0569dd47cfd4da 100644 --- a/test/pummel/test-tls-server-large-request.js +++ b/test/pummel/test-tls-server-large-request.js @@ -30,7 +30,7 @@ Mediator.prototype._write = function _write(data, enc, cb) { setTimeout(cb, 0); if (this.buf.length >= request.length) { - assert.equal(this.buf, request.toString()); + assert.strictEqual(this.buf, request.toString()); server.close(); } }; diff --git a/test/pummel/test-tls-throttle.js b/test/pummel/test-tls-throttle.js index 939a9fc3b0fe8a..1df8e5c157046f 100644 --- a/test/pummel/test-tls-throttle.js +++ b/test/pummel/test-tls-throttle.js @@ -63,5 +63,5 @@ let timeout = setTimeout(displayCounts, 10 * 1000); process.on('exit', function() { displayCounts(); - assert.equal(body.length, recvCount); + assert.strictEqual(body.length, recvCount); }); diff --git a/test/sequential/test-child-process-fork-getconnections.js b/test/sequential/test-child-process-fork-getconnections.js index 4d6b1a25ef16cc..355a45913c8699 100644 --- a/test/sequential/test-child-process-fork-getconnections.js +++ b/test/sequential/test-child-process-fork-getconnections.js @@ -20,7 +20,7 @@ if (process.argv[2] === 'child') { } if (m.cmd === 'close') { - assert.equal(socket, undefined); + assert.strictEqual(socket, undefined); if (sockets[m.id].destroyed) { // Workaround for https://github.com/nodejs/node/issues/2610 sendClosed(m.id); @@ -92,8 +92,8 @@ if (process.argv[2] === 'child') { server.listen(common.PORT, '127.0.0.1'); process.on('exit', function() { - assert.equal(sent, count); - assert.equal(disconnected, count); + assert.strictEqual(sent, count); + assert.strictEqual(disconnected, count); assert.ok(closeEmitted); console.log('ok'); }); diff --git a/test/sequential/test-deprecation-flags.js b/test/sequential/test-deprecation-flags.js index eb5c1a3ae6261f..3bd2e99033beb1 100644 --- a/test/sequential/test-deprecation-flags.js +++ b/test/sequential/test-deprecation-flags.js @@ -20,24 +20,24 @@ const traceDep = ['--trace-deprecation', depmod]; execFile(node, normal, function(er, stdout, stderr) { console.error('normal: show deprecation warning'); - assert.equal(er, null); - assert.equal(stdout, ''); + assert.strictEqual(er, null); + assert.strictEqual(stdout, ''); assert(/util\.debug is deprecated/.test(stderr)); console.log('normal ok'); }); execFile(node, noDep, function(er, stdout, stderr) { console.error('--no-deprecation: silence deprecations'); - assert.equal(er, null); - assert.equal(stdout, ''); - assert.equal(stderr, 'DEBUG: This is deprecated\n'); + assert.strictEqual(er, null); + assert.strictEqual(stdout, ''); + assert.strictEqual(stderr, 'DEBUG: This is deprecated\n'); console.log('silent ok'); }); execFile(node, traceDep, function(er, stdout, stderr) { console.error('--trace-deprecation: show stack'); - assert.equal(er, null); - assert.equal(stdout, ''); + assert.strictEqual(er, null); + assert.strictEqual(stdout, ''); const stack = stderr.trim().split('\n'); // just check the top and bottom. assert(/util.debug is deprecated. Use console.error instead./.test(stack[1])); @@ -47,8 +47,8 @@ execFile(node, traceDep, function(er, stdout, stderr) { execFile(node, [depUserlandFunction], function(er, stdout, stderr) { console.error('normal: testing deprecated userland function'); - assert.equal(er, null); - assert.equal(stdout, ''); + assert.strictEqual(er, null); + assert.strictEqual(stdout, ''); assert(/deprecatedFunction is deprecated/.test(stderr)); console.error('normal: ok'); }); diff --git a/test/sequential/test-http-regr-gh-2928.js b/test/sequential/test-http-regr-gh-2928.js index 190966083e3f97..55e3a93bc98eaa 100644 --- a/test/sequential/test-http-regr-gh-2928.js +++ b/test/sequential/test-http-regr-gh-2928.js @@ -59,5 +59,5 @@ const server = net.createServer(function(c) { }).listen(common.PORT, execAndClose); process.on('exit', function() { - assert.equal(gotResponses, COUNT); + assert.strictEqual(gotResponses, COUNT); }); diff --git a/test/sequential/test-process-warnings.js b/test/sequential/test-process-warnings.js index 1e8b2b13a20a78..d4894f8bffeb36 100644 --- a/test/sequential/test-process-warnings.js +++ b/test/sequential/test-process-warnings.js @@ -12,22 +12,22 @@ const traceWarn = ['--trace-warnings', warnmod]; execFile(node, normal, function(er, stdout, stderr) { // Show Process Warnings - assert.equal(er, null); - assert.equal(stdout, ''); + assert.strictEqual(er, null); + assert.strictEqual(stdout, ''); assert(/^\(.+\)\sWarning: a bad practice warning/.test(stderr)); }); execFile(node, noWarn, function(er, stdout, stderr) { // Hide Process Warnings - assert.equal(er, null); - assert.equal(stdout, ''); + assert.strictEqual(er, null); + assert.strictEqual(stdout, ''); assert(!/^\(.+\)\sWarning: a bad practice warning/.test(stderr)); }); execFile(node, traceWarn, function(er, stdout, stderr) { // Show Warning Trace - assert.equal(er, null); - assert.equal(stdout, ''); + assert.strictEqual(er, null); + assert.strictEqual(stdout, ''); assert(/^\(.+\)\sWarning: a bad practice warning/.test(stderr)); assert(/at Object\.\s\(.+warnings.js:3:9\)/.test(stderr)); }); diff --git a/test/sequential/test-regress-GH-4027.js b/test/sequential/test-regress-GH-4027.js index 87a8861ac35477..8d9c6bb1ad795a 100644 --- a/test/sequential/test-regress-GH-4027.js +++ b/test/sequential/test-regress-GH-4027.js @@ -11,7 +11,7 @@ fs.writeFileSync(filename, 'quis custodiet ipsos custodes'); setTimeout(fs.unlinkSync, 100, filename); fs.watchFile(filename, { interval: 50 }, common.mustCall(function(curr, prev) { - assert.equal(prev.nlink, 1); - assert.equal(curr.nlink, 0); + assert.strictEqual(prev.nlink, 1); + assert.strictEqual(curr.nlink, 0); fs.unwatchFile(filename); })); diff --git a/test/sequential/test-regress-GH-784.js b/test/sequential/test-regress-GH-784.js index c9b630b0c81755..0bfa407ec10dc3 100644 --- a/test/sequential/test-regress-GH-784.js +++ b/test/sequential/test-regress-GH-784.js @@ -21,7 +21,7 @@ const server = http.createServer(function(req, res) { }); req.on('end', function() { - assert.equal('PING', body); + assert.strictEqual('PING', body); res.writeHead(200); res.end('PONG'); }); @@ -96,7 +96,7 @@ function ping() { }); res.on('end', function() { - assert.equal('PONG', body); + assert.strictEqual('PONG', body); assert.ok(!hadError); gotEnd = true; afterPing('success'); @@ -128,5 +128,5 @@ process.on('exit', function() { console.error("process.on('exit')"); console.error(responses); - assert.equal(8, responses.length); + assert.strictEqual(8, responses.length); }); diff --git a/test/sequential/test-regress-GH-877.js b/test/sequential/test-regress-GH-877.js index 06c839aa483fa8..1a0d7a48e5758c 100644 --- a/test/sequential/test-regress-GH-877.js +++ b/test/sequential/test-regress-GH-877.js @@ -31,7 +31,7 @@ server.listen(common.PORT, '127.0.0.1', function() { res.resume(); }); - assert.equal(req.agent, agent); + assert.strictEqual(req.agent, agent); console.log('Socket: ' + agent.sockets[addrString].length + '/' + agent.maxSockets + ' queued: ' + (agent.requests[addrString] ? diff --git a/test/sequential/test-require-cache-without-stat.js b/test/sequential/test-require-cache-without-stat.js index b591f1746b62d4..d90bbd2b7bb71f 100644 --- a/test/sequential/test-require-cache-without-stat.js +++ b/test/sequential/test-require-cache-without-stat.js @@ -49,4 +49,4 @@ for (let i = 0; i < 100; i++) { console.log('counterAfter = %d', counter); const counterAfter = counter; -assert.equal(counterBefore, counterAfter); +assert.strictEqual(counterBefore, counterAfter); diff --git a/test/sequential/test-stream2-fs.js b/test/sequential/test-stream2-fs.js index 2891335c813562..58a66ef99df9cf 100644 --- a/test/sequential/test-stream2-fs.js +++ b/test/sequential/test-stream2-fs.js @@ -39,7 +39,7 @@ const w = new TestWriter(); w.on('results', function(res) { console.error(res, w.length); - assert.equal(w.length, size); + assert.strictEqual(w.length, size); assert.deepStrictEqual(res.map(function(c) { return c.length; }), expectLengths); diff --git a/test/sequential/test-stream2-stderr-sync.js b/test/sequential/test-stream2-stderr-sync.js index 0b86790d62058d..9f453f656f7cb9 100644 --- a/test/sequential/test-stream2-stderr-sync.js +++ b/test/sequential/test-stream2-stderr-sync.js @@ -16,7 +16,7 @@ function parent() { }); child.on('close', function() { - assert.equal(err, 'child ' + c + '\nfoo\nbar\nbaz\n'); + assert.strictEqual(err, 'child ' + c + '\nfoo\nbar\nbaz\n'); console.log('ok %d child #%d', ++i, c); if (i === children.length) console.log('1..' + i); diff --git a/test/sequential/test-util-debug.js b/test/sequential/test-util-debug.js index 515f6e32692c5b..96f754c71adab9 100644 --- a/test/sequential/test-util-debug.js +++ b/test/sequential/test-util-debug.js @@ -45,8 +45,8 @@ function test(environ, shouldWrite) { child.on('close', common.mustCall(function(c) { assert(!c); - assert.equal(err, expectErr); - assert.equal(out, expectOut); + assert.strictEqual(err, expectErr); + assert.strictEqual(out, expectOut); console.log('ok %j %j', environ, shouldWrite); })); } From 12c0ce749f3b4038b1847dfd18710655e565a5f4 Mon Sep 17 00:00:00 2001 From: Gibson Fahnestock Date: Sun, 8 Jan 2017 23:23:34 +0000 Subject: [PATCH 016/151] assert, tools: enforce strict (not)equal in eslint MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Extend no-restricted-properties to catch use of assert.equal() and assert.notEqual() and require assert.strictEqual() or assert.notStrictEqual() instead. Also update the eslint-ignore in lib/assert.js to avoid assert.equal/notEqual linter errors in their definitions. Backport-PR-URL: https://github.com/nodejs/node/pull/11795 PR-URL: https://github.com/nodejs/node/pull/10698 Reviewed-By: James M Snell Reviewed-By: Colin Ihrig Reviewed-By: Michael Dawson Reviewed-By: Sakthipriyan Vairamani Reviewed-By: Michaël Zasso Reviewed-By: Teddy Katz --- .eslintrc.yaml | 26 +++++++++++++++----------- lib/assert.js | 3 +-- 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/.eslintrc.yaml b/.eslintrc.yaml index 713e2f1c93d08d..7db9a842792212 100644 --- a/.eslintrc.yaml +++ b/.eslintrc.yaml @@ -62,17 +62,21 @@ rules: no-new-require: 2 no-path-concat: 2 no-restricted-modules: [2, sys, _linklist] - no-restricted-properties: [2, { - object: assert, - property: deepEqual, - message: Please use assert.deepStrictEqual(). - }, { - property: __defineGetter__, - message: __defineGetter__ is deprecated. - }, { - property: __defineSetter__, - message: __defineSetter__ is deprecated. - }] + no-restricted-properties: + - 2 + - object: assert + property: deepEqual + message: Use assert.deepStrictEqual(). + - object: assert + property: equal + message: Use assert.strictEqual() rather than assert.equal(). + - object: assert + property: notEqual + message: Use assert.notStrictEqual() rather than assert.notEqual(). + - property: __defineGetter__ + message: __defineGetter__ is deprecated. + - property: __defineSetter__, + message: __defineSetter__ is deprecated. # Stylistic Issues # http://eslint.org/docs/rules/#stylistic-issues diff --git a/lib/assert.js b/lib/assert.js index f18cc45fc3fe2f..219842f953a12c 100644 --- a/lib/assert.js +++ b/lib/assert.js @@ -105,7 +105,7 @@ assert.ok = ok; // The equality assertion tests shallow, coercive equality with // ==. // assert.equal(actual, expected, message_opt); - +/* eslint-disable no-restricted-properties */ assert.equal = function equal(actual, expected, message) { if (actual != expected) fail(actual, expected, message, '==', assert.equal); }; @@ -123,7 +123,6 @@ assert.notEqual = function notEqual(actual, expected, message) { // The equivalence assertion tests a deep equality relation. // assert.deepEqual(actual, expected, message_opt); -/* eslint-disable no-restricted-properties */ assert.deepEqual = function deepEqual(actual, expected, message) { if (!_deepEqual(actual, expected, false)) { fail(actual, expected, message, 'deepEqual', assert.deepEqual); From eb47897f524fdbec0c8a89378caf4f92031182eb Mon Sep 17 00:00:00 2001 From: dpg5000 Date: Sat, 31 Dec 2016 00:04:54 -0800 Subject: [PATCH 017/151] test: refactor test-stream2-readable-wrap.js Use common.mustCall() where appropriate, var to const/let, assert.equal() -> assert.strictEqual(), explicit time provided to setTimeout() Backport-PR-URL: https://github.com/nodejs/node/pull/11797 PR-URL: https://github.com/nodejs/node/pull/10551 Reviewed-By: Rich Trott Reviewed-By: Gibson Fahnestock --- test/parallel/test-stream2-readable-wrap.js | 27 +++------------------ 1 file changed, 4 insertions(+), 23 deletions(-) diff --git a/test/parallel/test-stream2-readable-wrap.js b/test/parallel/test-stream2-readable-wrap.js index 3d680706049303..aa091dc3d806f0 100644 --- a/test/parallel/test-stream2-readable-wrap.js +++ b/test/parallel/test-stream2-readable-wrap.js @@ -1,33 +1,25 @@ 'use strict'; -require('../common'); +const common = require('../common'); const assert = require('assert'); - const Readable = require('_stream_readable'); const Writable = require('_stream_writable'); const EE = require('events').EventEmitter; -let testRuns = 0, completedRuns = 0; function runTest(highWaterMark, objectMode, produce) { - testRuns++; const old = new EE(); const r = new Readable({ highWaterMark: highWaterMark, objectMode: objectMode }); assert.strictEqual(r, r.wrap(old)); - let ended = false; - r.on('end', function() { - ended = true; - }); + r.on('end', common.mustCall(function() {})); old.pause = function() { - console.error('old.pause()'); old.emit('pause'); flowing = false; }; old.resume = function() { - console.error('old.resume()'); old.emit('resume'); flow(); }; @@ -41,13 +33,10 @@ function runTest(highWaterMark, objectMode, produce) { while (flowing && chunks-- > 0) { const item = produce(); expected.push(item); - console.log('old.emit', chunks, flowing); old.emit('data', item); - console.log('after emit', chunks, flowing); } if (chunks <= 0) { oldEnded = true; - console.log('old end', chunks, flowing); old.emit('end'); } } @@ -56,22 +45,19 @@ function runTest(highWaterMark, objectMode, produce) { objectMode: objectMode }); const written = []; w._write = function(chunk, encoding, cb) { - console.log('_write', chunk); written.push(chunk); setTimeout(cb, 1); }; - w.on('finish', function() { - completedRuns++; + w.on('finish', common.mustCall(function() { performAsserts(); - }); + })); r.pipe(w); flow(); function performAsserts() { - assert(ended); assert(oldEnded); assert.deepStrictEqual(written, expected); } @@ -83,8 +69,3 @@ runTest(1, true, function() { return { foo: 'bar' }; }); const objectChunks = [ 5, 'a', false, 0, '', 'xyz', { x: 4 }, 7, [], 555 ]; runTest(1, true, function() { return objectChunks.shift(); }); - -process.on('exit', function() { - assert.strictEqual(testRuns, completedRuns); - console.log('ok'); -}); From a1cb6992d9dd933fb92f451d21fa712e9ffedb3f Mon Sep 17 00:00:00 2001 From: Sam Roberts Date: Wed, 21 Dec 2016 10:16:19 -0800 Subject: [PATCH 018/151] test: getgroups() may contain duplicate GIDs Some systems may have multiple group names with the same group ID, in which case getgroups() returns duplicate values, where `id -G` will filter the duplicates. Unique and sort the arrays so they can be compared. Backport-PR-URL: https://github.com/nodejs/node/pull/12468 PR-URL: https://github.com/nodejs/node/pull/10389 Reviewed-By: James M Snell Reviewed-By: Gibson Fahnestock Reviewed-By: Michael Dawson --- test/parallel/test-process-getgroups.js | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/test/parallel/test-process-getgroups.js b/test/parallel/test-process-getgroups.js index 497da2be1235f8..390f188cf5bf4d 100644 --- a/test/parallel/test-process-getgroups.js +++ b/test/parallel/test-process-getgroups.js @@ -1,21 +1,23 @@ 'use strict'; const common = require('../common'); -const assert = require('assert'); -const exec = require('child_process').exec; + +// Check `id -G` and `process.getgroups()` return same groups. if (common.isOSX) { common.skip('Output of `id -G` is unreliable on Darwin.'); return; } +const assert = require('assert'); +const exec = require('child_process').exec; if (typeof process.getgroups === 'function') { - const groups = process.getgroups(); + const groups = unique(process.getgroups()); assert(Array.isArray(groups)); assert(groups.length > 0); exec('id -G', function(err, stdout) { - if (err) throw err; - const real_groups = stdout.match(/\d+/g).map(Number); - assert.strictEqual(groups.length, real_groups.length); + assert.ifError(err); + const real_groups = unique(stdout.match(/\d+/g).map(Number)); + assert.deepStrictEqual(groups, real_groups); check(groups, real_groups); check(real_groups, groups); }); @@ -24,3 +26,7 @@ if (typeof process.getgroups === 'function') { function check(a, b) { for (let i = 0; i < a.length; ++i) assert.notStrictEqual(b.indexOf(a[i]), -1); } + +function unique(groups) { + return [...new Set(groups)].sort(); +} From f1c2f2675c90b02265071eb90f6942fa2f913316 Mon Sep 17 00:00:00 2001 From: Sam Roberts Date: Wed, 21 Dec 2016 09:33:13 -0800 Subject: [PATCH 019/151] doc,test: tls .ca option supports multi-PEM files Backport-PR-URL: https://github.com/nodejs/node/pull/12468 PR-URL: https://github.com/nodejs/node/pull/10389 Reviewed-By: James M Snell Reviewed-By: Gibson Fahnestock Reviewed-By: Michael Dawson --- doc/api/tls.md | 19 +++++++++++++++---- test/parallel/test-tls-ca-concat.js | 24 ++++++++++++++++++++++++ 2 files changed, 39 insertions(+), 4 deletions(-) create mode 100644 test/parallel/test-tls-ca-concat.js diff --git a/doc/api/tls.md b/doc/api/tls.md index 5b0cef22f02641..ee3d37d6a43df2 100644 --- a/doc/api/tls.md +++ b/doc/api/tls.md @@ -906,10 +906,21 @@ added: v0.11.13 the same order as their private keys in `key`. If the intermediate certificates are not provided, the peer will not be able to validate the certificate, and the handshake will fail. - * `ca`{string|string[]|Buffer|Buffer[]} Optional CA certificates to trust. - Default is the well-known CAs from Mozilla. When connecting to peers that - use certificates issued privately, or self-signed, the private root CA or - self-signed certificate must be provided to verify the peer. + * `ca` {string|string[]|Buffer|Buffer[]} Optionally override the trusted CA + certificates. Default is to trust the well-known CAs curated by Mozilla. + Mozilla's CAs are completely replaced when CAs are explicitly specified + using this option. The value can be a string or Buffer, or an Array of + strings and/or Buffers. Any string or Buffer can contain multiple PEM CAs + concatenated together. The peer's certificate must be chainable to a CA + trusted by the server for the connection to be authenticated. When using + certificates that are not chainable to a well-known CA, the certificate's CA + must be explicitly specified as a trusted or the connection will fail to + authenticate. + If the peer uses a certificate that doesn't match or chain to one of the + default CAs, use the `ca` option to provide a CA certificate that the peer's + certificate can match or chain to. + For self-signed certificates, the certificate is its own CA, and must be + provided. * `crl` {string|string[]|Buffer|Buffer[]} Optional PEM formatted CRLs (Certificate Revocation Lists). * `ciphers` {string} Optional cipher suite specification, replacing the diff --git a/test/parallel/test-tls-ca-concat.js b/test/parallel/test-tls-ca-concat.js new file mode 100644 index 00000000000000..65c837bed9dc37 --- /dev/null +++ b/test/parallel/test-tls-ca-concat.js @@ -0,0 +1,24 @@ +'use strict'; +const common = require('../common'); + +// Check ca option can contain concatenated certs by prepending an unrelated +// non-CA cert and showing that agent6's CA root is still found. + +const join = require('path').join; +const { + assert, connect, keys +} = require(join(common.fixturesDir, 'tls-connect'))(); + +connect({ + client: { + checkServerIdentity: (servername, cert) => { }, + ca: keys.agent1.cert + '\n' + keys.agent6.ca, + }, + server: { + cert: keys.agent6.cert, + key: keys.agent6.key, + }, +}, function(err, pair, cleanup) { + assert.ifError(err); + return cleanup(); +}); From 1d7fab37406d288e38a7db31310546d260b1eb08 Mon Sep 17 00:00:00 2001 From: Sam Roberts Date: Tue, 20 Dec 2016 14:16:29 -0800 Subject: [PATCH 020/151] test: tls cert chain completion scenarios Backport-PR-URL: https://github.com/nodejs/node/pull/12468 PR-URL: https://github.com/nodejs/node/pull/10389 Reviewed-By: James M Snell Reviewed-By: Gibson Fahnestock Reviewed-By: Michael Dawson --- test/parallel/test-tls-cert-chains-concat.js | 50 ++++++++++++++++++++ test/parallel/test-tls-cert-chains-in-ca.js | 46 ++++++++++++++++++ 2 files changed, 96 insertions(+) create mode 100644 test/parallel/test-tls-cert-chains-concat.js create mode 100644 test/parallel/test-tls-cert-chains-in-ca.js diff --git a/test/parallel/test-tls-cert-chains-concat.js b/test/parallel/test-tls-cert-chains-concat.js new file mode 100644 index 00000000000000..d53edef89842b9 --- /dev/null +++ b/test/parallel/test-tls-cert-chains-concat.js @@ -0,0 +1,50 @@ +'use strict'; +const common = require('../common'); + +// Check cert chain is received by client, and is completed with the ca cert +// known to the client. + +const join = require('path').join; +const { + assert, connect, debug, keys +} = require(join(common.fixturesDir, 'tls-connect'))(); + +// agent6-cert.pem includes cert for agent6 and ca3 +connect({ + client: { + checkServerIdentity: (servername, cert) => { }, + ca: keys.agent6.ca, + }, + server: { + cert: keys.agent6.cert, + key: keys.agent6.key, + }, +}, function(err, pair, cleanup) { + assert.ifError(err); + + const peer = pair.client.conn.getPeerCertificate(); + debug('peer:\n', peer); + assert.strictEqual(peer.subject.emailAddress, 'adam.lippai@tresorit.com'); + assert.strictEqual(peer.subject.CN, 'Ádám Lippai'), + assert.strictEqual(peer.issuer.CN, 'ca3'); + assert.strictEqual(peer.serialNumber, 'C4CD893EF9A75DCC'); + + const next = pair.client.conn.getPeerCertificate(true).issuerCertificate; + const root = next.issuerCertificate; + delete next.issuerCertificate; + debug('next:\n', next); + assert.strictEqual(next.subject.CN, 'ca3'); + assert.strictEqual(next.issuer.CN, 'ca1'); + assert.strictEqual(next.serialNumber, '9A84ABCFB8A72ABF'); + + debug('root:\n', root); + assert.strictEqual(root.subject.CN, 'ca1'); + assert.strictEqual(root.issuer.CN, 'ca1'); + assert.strictEqual(root.serialNumber, '8DF21C01468AF393'); + + // No client cert, so empty object returned. + assert.deepStrictEqual(pair.server.conn.getPeerCertificate(), {}); + assert.deepStrictEqual(pair.server.conn.getPeerCertificate(true), {}); + + return cleanup(); +}); diff --git a/test/parallel/test-tls-cert-chains-in-ca.js b/test/parallel/test-tls-cert-chains-in-ca.js new file mode 100644 index 00000000000000..69f62c3f72d859 --- /dev/null +++ b/test/parallel/test-tls-cert-chains-in-ca.js @@ -0,0 +1,46 @@ +'use strict'; +const common = require('../common'); + +// Check cert chain is received by client, and is completed with the ca cert +// known to the client. + +const join = require('path').join; +const { + assert, connect, debug, keys +} = require(join(common.fixturesDir, 'tls-connect'))(); + + +// agent6-cert.pem includes cert for agent6 and ca3, split it apart and +// provide ca3 in the .ca property. +const agent6Chain = keys.agent6.cert.split('-----END CERTIFICATE-----') + .map((c) => { return c + '-----END CERTIFICATE-----'; }); +const agent6End = agent6Chain[0]; +const agent6Middle = agent6Chain[1]; +connect({ + client: { + checkServerIdentity: (servername, cert) => { }, + ca: keys.agent6.ca, + }, + server: { + cert: agent6End, + key: keys.agent6.key, + ca: agent6Middle, + }, +}, function(err, pair, cleanup) { + assert.ifError(err); + + const peer = pair.client.conn.getPeerCertificate(); + debug('peer:\n', peer); + assert.strictEqual(peer.serialNumber, 'C4CD893EF9A75DCC'); + + const next = pair.client.conn.getPeerCertificate(true).issuerCertificate; + const root = next.issuerCertificate; + delete next.issuerCertificate; + debug('next:\n', next); + assert.strictEqual(next.serialNumber, '9A84ABCFB8A72ABF'); + + debug('root:\n', root); + assert.strictEqual(root.serialNumber, '8DF21C01468AF393'); + + return cleanup(); +}); From cbfc3fcd9dfbae4d1215199d503f30cb2b9bda7c Mon Sep 17 00:00:00 2001 From: Sam Roberts Date: Tue, 20 Dec 2016 14:16:18 -0800 Subject: [PATCH 021/151] doc: use correct tls certificate property name Docs referred to an `issuer` property being optionally present, when it should have referred to the `issuerCertificate` property. Backport-PR-URL: https://github.com/nodejs/node/pull/12468 PR-URL: https://github.com/nodejs/node/pull/10389 Reviewed-By: James M Snell Reviewed-By: Gibson Fahnestock Reviewed-By: Michael Dawson --- doc/api/tls.md | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/doc/api/tls.md b/doc/api/tls.md index ee3d37d6a43df2..0e47ddac0391be 100644 --- a/doc/api/tls.md +++ b/doc/api/tls.md @@ -583,13 +583,16 @@ For Example: `{ type: 'ECDH', name: 'prime256v1', size: 256 }` added: v0.11.4 --> -* `detailed` {boolean} Specify `true` to request that the full certificate - chain with the `issuer` property be returned; `false` to return only the - top certificate without the `issuer` property. +* `detailed` {boolean} Include the full certificate chain if `true`, otherwise + include just the peer's certificate. Returns an object representing the peer's certificate. The returned object has some properties corresponding to the fields of the certificate. +If the full certificate chain was requested, each certificate will include a +`issuerCertificate` property containing an object representing its issuer's +certificate. + For example: ```text @@ -600,15 +603,15 @@ For example: O: 'node.js', OU: 'Test TLS Certificate', CN: 'localhost' }, - issuerInfo: + issuer: { C: 'UK', ST: 'Acknack Ltd', L: 'Rhys Jones', O: 'node.js', OU: 'Test TLS Certificate', CN: 'localhost' }, - issuer: - { ... another certificate ... }, + issuerCertificate: + { ... another certificate, possibly with a .issuerCertificate ... }, raw: < RAW DER buffer >, valid_from: 'Nov 11 09:52:22 2009 GMT', valid_to: 'Nov 6 09:52:22 2029 GMT', @@ -616,8 +619,7 @@ For example: serialNumber: 'B9B0D332A1AA5635' } ``` -If the peer does not provide a certificate, `null` or an empty object will be -returned. +If the peer does not provide a certificate, an empty object will be returned. ### tlsSocket.getProtocol() +* Returns: {String} + The `os.arch()` method returns a string identifying the operating system CPU architecture *for which the Node.js binary was compiled*. @@ -36,6 +38,9 @@ The current possible values are: `'arm'`, `'arm64'`, `'ia32'`, `'mips'`, Equivalent to [`process.arch`][]. ## os.constants + * {Object} From 6c3b10454858724d4da6f7a94e0bfad6e22549e0 Mon Sep 17 00:00:00 2001 From: Nikolai Vavilov Date: Tue, 28 Feb 2017 19:59:59 +0200 Subject: [PATCH 025/151] doc: fix typo in STYLE_GUIDE.md PR-URL: https://github.com/nodejs/node/pull/11615 Reviewed-By: Anna Henningsen Reviewed-By: Colin Ihrig --- doc/STYLE_GUIDE.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/STYLE_GUIDE.md b/doc/STYLE_GUIDE.md index 10f26421a4ceb5..f087718a6754fd 100644 --- a/doc/STYLE_GUIDE.md +++ b/doc/STYLE_GUIDE.md @@ -57,7 +57,7 @@ * When using underscores, asterisks and backticks please use proper escaping (**\\\_**, **\\\*** and **\\\`** instead of **\_**, **\*** and **\`**) * References to constructor functions should use PascalCase * References to constructor instances should be camelCased -* References to methods should be used with parenthesis: `socket.end()` instead of `socket.end` +* References to methods should be used with parentheses: `socket.end()` instead of `socket.end` [plugin]: http://editorconfig.org/#download [Oxford comma]: https://en.wikipedia.org/wiki/Serial_comma From 109fd72f11506c71b667d45b67eb73cda6157059 Mon Sep 17 00:00:00 2001 From: James Sumners Date: Thu, 23 Feb 2017 11:02:39 -0500 Subject: [PATCH 026/151] doc: use common malformed instead of misformatted PR-URL: https://github.com/nodejs/node/pull/11518 Reviewed-By: James M Snell Reviewed-By: Timothy Gu Reviewed-By: Colin Ihrig --- doc/api/cli.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/api/cli.md b/doc/api/cli.md index 34b2c7aff6adcc..53cfe5a96b4dd6 100644 --- a/doc/api/cli.md +++ b/doc/api/cli.md @@ -314,7 +314,7 @@ When set, the well known "root" CAs (like VeriSign) will be extended with the extra certificates in `file`. The file should consist of one or more trusted certificates in PEM format. A message will be emitted (once) with [`process.emitWarning()`][emit_warning] if the file is missing or -misformatted, but any errors are otherwise ignored. +malformed, but any errors are otherwise ignored. Note that neither the well known nor extra certificates are used when the `ca` options property is explicitly specified for a TLS or HTTPS client or server. From 0aab0503be1f3108778005cad48a91a95082e187 Mon Sep 17 00:00:00 2001 From: Joyee Cheung Date: Wed, 1 Mar 2017 11:35:23 +0800 Subject: [PATCH 027/151] doc: add link to references in net.Socket PR-URL: https://github.com/nodejs/node/pull/11625 Reviewed-By: Rich Trott Reviewed-By: James M Snell Reviewed-By: Colin Ihrig --- doc/api/net.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/doc/api/net.md b/doc/api/net.md index 8b055b448f4a3d..1f161ebded63bf 100644 --- a/doc/api/net.md +++ b/doc/api/net.md @@ -334,7 +334,7 @@ Construct a new socket object. `fd` allows you to specify the existing file descriptor of socket. Set `readable` and/or `writable` to `true` to allow reads and/or writes on this socket (NOTE: Works only when `fd` is passed). -About `allowHalfOpen`, refer to `createServer()` and `'end'` event. +About `allowHalfOpen`, refer to [`net.createServer()`][] and [`'end'`][] event. `net.Socket` instances are [`EventEmitter`][] with the following events: @@ -933,6 +933,7 @@ Returns true if input is a version 6 IP address, otherwise returns false. [`dns.lookup()` hints]: dns.html#dns_supported_getaddrinfo_flags [`end()`]: #net_socket_end_data_encoding [`EventEmitter`]: events.html#events_class_eventemitter +[`net.createServer()`]: #net_net_createserver_options_connectionlistener [`net.Socket`]: #net_class_net_socket [`pause()`]: #net_socket_pause [`resume()`]: #net_socket_resume From 0322d3b8d5369b3316bd632fd4d23bc12e548c41 Mon Sep 17 00:00:00 2001 From: "Sakthipriyan Vairamani (thefourtheye)" Date: Tue, 28 Feb 2017 00:24:03 +0530 Subject: [PATCH 028/151] test: skip tests with common.skip The `common.skip` function adds proper message in TAP format to skipped tests. It is better not to have the message rewritten in the tests. PR-URL: https://github.com/nodejs/node/pull/11585 Reviewed-By: Colin Ihrig Reviewed-By: James M Snell Reviewed-By: Gibson Fahnestock Reviewed-By: Luigi Pinca Reviewed-By: Yuta Hiroto --- test/parallel/test-crypto-authenticated.js | 2 +- test/parallel/test-tls-empty-sni-context.js | 6 ++---- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/test/parallel/test-crypto-authenticated.js b/test/parallel/test-crypto-authenticated.js index 245783fb1b4275..1a628023b5c46e 100644 --- a/test/parallel/test-crypto-authenticated.js +++ b/test/parallel/test-crypto-authenticated.js @@ -318,7 +318,7 @@ for (const i in TEST_CASES) { } if (common.hasFipsCrypto && test.iv.length < 24) { - console.log('1..0 # Skipped: IV len < 12 bytes unsupported in FIPS mode'); + common.skip('IV len < 12 bytes unsupported in FIPS mode'); continue; } diff --git a/test/parallel/test-tls-empty-sni-context.js b/test/parallel/test-tls-empty-sni-context.js index 52e9f14b64d91a..9e022c9c6a8804 100644 --- a/test/parallel/test-tls-empty-sni-context.js +++ b/test/parallel/test-tls-empty-sni-context.js @@ -3,16 +3,14 @@ const common = require('../common'); if (!process.features.tls_sni) { - console.log('1..0 # Skipped: node compiled without OpenSSL or ' + - 'with old OpenSSL version.'); + common.skip('node compiled without OpenSSL or with old OpenSSL version.'); return; } const assert = require('assert'); if (!common.hasCrypto) { - console.log('1..0 # Skipped: missing crypto'); - return; + return common.skip('missing crypto'); } const tls = require('tls'); From c0663e51d11874e53fec72cda198d56596158066 Mon Sep 17 00:00:00 2001 From: Vse Mozhet Byt Date: Sun, 26 Feb 2017 17:49:25 +0200 Subject: [PATCH 029/151] doc: fixup errors.md * add semicolons in examples * fix indentation in code example * add spaces in code examples * console.log() -> console.error() * fix level of headings * update comment code example * delete obsolete info and example Fixes: https://github.com/nodejs/node/issues/11558 PR-URL: https://github.com/nodejs/node/pull/11566 Reviewed-By: Joyee Cheung Reviewed-By: Colin Ihrig Reviewed-By: James M Snell Reviewed-By: Luigi Pinca --- doc/api/errors.md | 45 ++++++++++++++++----------------------------- 1 file changed, 16 insertions(+), 29 deletions(-) diff --git a/doc/api/errors.md b/doc/api/errors.md index 640935da35e460..e0e0f06ac5900f 100644 --- a/doc/api/errors.md +++ b/doc/api/errors.md @@ -141,15 +141,15 @@ the first argument will be passed as `null`. const fs = require('fs'); function nodeStyleCallback(err, data) { - if (err) { - console.error('There was an error', err); - return; - } - console.log(data); + if (err) { + console.error('There was an error', err); + return; + } + console.log(data); } fs.readFile('/some/file/that/does-not-exist', nodeStyleCallback); -fs.readFile('/some/file/that/does-exist', nodeStyleCallback) +fs.readFile('/some/file/that/does-exist', nodeStyleCallback); ``` The JavaScript `try / catch` mechanism **cannot** be used to intercept errors @@ -167,15 +167,15 @@ try { throw err; } }); -} catch(err) { +} catch (err) { // This will not catch the throw! - console.log(err); + console.error(err); } ``` This will not work because the callback function passed to `fs.readFile()` is called asynchronously. By the time the callback has been called, the -surrounding code (including the `try { } catch(err) { }` block will have +surrounding code (including the `try { } catch (err) { }` block will have already exited. Throwing an error inside the callback **can crash the Node.js process** in most cases. If [domains][] are enabled, or a handler has been registered with `process.on('uncaughtException')`, such errors can be @@ -217,7 +217,7 @@ a string representing the location in the code at which ```js const myObject = {}; Error.captureStackTrace(myObject); -myObject.stack // similar to `new Error().stack` +myObject.stack; // similar to `new Error().stack` ``` The first line of the trace, instead of being prefixed with `ErrorType: @@ -238,7 +238,7 @@ function MyError() { // Without passing MyError to captureStackTrace, the MyError // frame would show up in the .stack property. By passing // the constructor, we omit that frame and all frames above it. -new MyError().stack +new MyError().stack; ``` ### Error.stackTraceLimit @@ -255,7 +255,7 @@ will affect any stack trace captured *after* the value has been changed. If set to a non-number value, or set to a negative number, stack traces will not capture any frames. -#### error.message +### error.message * {String} @@ -267,11 +267,11 @@ the stack trace of the `Error`, however changing this property after the ```js const err = new Error('The message'); -console.log(err.message); +console.error(err.message); // Prints: The message ``` -#### error.stack +### error.stack * {String} @@ -359,7 +359,7 @@ For example: ```js require('net').connect(-1); - // throws RangeError, port should be > 0 && < 65536 + // throws "RangeError: "port" option should be >= 0 and < 65536: -1" ``` Node.js will generate and throw `RangeError` instances *immediately* as a form @@ -379,19 +379,6 @@ doesNotExist; // throws ReferenceError, doesNotExist is not a variable in this program. ``` -`ReferenceError` instances will have an `error.arguments` property whose value -is an array containing a single element: a string representing the variable -that was not defined. - -```js -const assert = require('assert'); -try { - doesNotExist; -} catch(err) { - assert(err.arguments[0], 'doesNotExist'); -} -``` - Unless an application is dynamically generating and running code, `ReferenceError` instances should always be considered a bug in the code or its dependencies. @@ -407,7 +394,7 @@ program. ```js try { require('vm').runInThisContext('binary ! isNotOk'); -} catch(err) { +} catch (err) { // err will be a SyntaxError } ``` From 06752d1fc004adf4e638541099236c31f0fb1400 Mon Sep 17 00:00:00 2001 From: Ben Noordhuis Date: Mon, 27 Feb 2017 05:24:11 +0100 Subject: [PATCH 030/151] net: remove misleading comment The allowHalfOpen comment was added in commit 8a3befa ("net: Refactor to use streams2") from 2012 but it wasn't true even then as far as I can tell: Node.js simply always does a shutdown(2) first. It is true that streams2 withholds the 'end' event when allowHalfOpen is true but the comment is about a callback that hangs off the 'finish' event that is emitted after calling `socket.end()`. PR-URL: https://github.com/nodejs/node/pull/11573 Reviewed-By: James M Snell Reviewed-By: Colin Ihrig --- lib/net.js | 4 ---- 1 file changed, 4 deletions(-) diff --git a/lib/net.js b/lib/net.js index 44b95073cf1445..b04c65abd6fab6 100644 --- a/lib/net.js +++ b/lib/net.js @@ -205,10 +205,6 @@ Socket.prototype._unrefTimer = function _unrefTimer() { // the user has called .end(), and all the bytes have been // sent out to the other side. -// If allowHalfOpen is false, or if the readable side has -// ended already, then destroy. -// If allowHalfOpen is true, then we need to do a shutdown, -// so that only the writable side will be cleaned up. function onSocketFinish() { // If still connecting - defer handling 'finish' until 'connect' will happen if (this.connecting) { From d4f2ef7a59fc0f93770c59b88e3877dabf025834 Mon Sep 17 00:00:00 2001 From: Rich Trott Date: Sun, 26 Feb 2017 22:39:55 -0800 Subject: [PATCH 031/151] test: apply strict mode in test-repl Strict mode for the test will not automatically enable strict mode in the REPL object. Enable strict mode in the test. PR-URL: https://github.com/nodejs/node/pull/11575 Reviewed-By: James M Snell Reviewed-By: Colin Ihrig Reviewed-By: Evan Lucas Reviewed-By: Sakthipriyan Vairamani Reviewed-By: Anna Henningsen Reviewed-By: Santiago Gimeno --- test/parallel/test-repl.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/test/parallel/test-repl.js b/test/parallel/test-repl.js index 70aac915f6b594..420010e1a3d6c9 100644 --- a/test/parallel/test-repl.js +++ b/test/parallel/test-repl.js @@ -1,4 +1,6 @@ -/* eslint-disable max-len, strict */ +/* eslint-disable max-len */ +'use strict'; + const common = require('../common'); const assert = require('assert'); From a042c8a0ef3a41aa6b1a11b70209c7d0670a9122 Mon Sep 17 00:00:00 2001 From: Bradley Curran Date: Sun, 26 Feb 2017 00:33:13 +0000 Subject: [PATCH 032/151] doc: fix typo in stream doc Use the plural instead of the possessive for developers PR-URL: https://github.com/nodejs/node/pull/11560 Reviewed-By: James M Snell Reviewed-By: Anna Henningsen Reviewed-By: Luigi Pinca Reviewed-By: Timothy Gu Reviewed-By: Colin Ihrig Reviewed-By: Michael Dawson --- doc/api/stream.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/api/stream.md b/doc/api/stream.md index d9a2f47db4271f..d7af669422b900 100644 --- a/doc/api/stream.md +++ b/doc/api/stream.md @@ -21,7 +21,7 @@ const stream = require('stream'); While it is important for all Node.js users to understand how streams work, the `stream` module itself is most useful for developers that are creating new -types of stream instances. Developer's who are primarily *consuming* stream +types of stream instances. Developers who are primarily *consuming* stream objects will rarely (if ever) have need to use the `stream` module directly. ## Organization of this Document From f0288f3969c2bf5da1315aba67c3a6a5e304011d Mon Sep 17 00:00:00 2001 From: James M Snell Date: Sat, 25 Feb 2017 11:23:41 -0800 Subject: [PATCH 033/151] meta: remove out of date ROADMAP.md file The ROADMAP.md file has not been updated in a while. It serves no useful purpose that cannot be handled better in other docs (contrib guidelines, etc). Just remove it. PR-URL: https://github.com/nodejs/node/pull/11556 Reviewed-By: Ben Noordhuis Reviewed-By: Anna Henningsen Reviewed-By: Jeremiah Senkpiel Reviewed-By: Luigi Pinca Reviewed-By: Colin Ihrig --- ROADMAP.md | 84 ------------------------------------------------------ 1 file changed, 84 deletions(-) delete mode 100644 ROADMAP.md diff --git a/ROADMAP.md b/ROADMAP.md deleted file mode 100644 index da8e47941916cc..00000000000000 --- a/ROADMAP.md +++ /dev/null @@ -1,84 +0,0 @@ -# Node.js Roadmap - -***This is a living document, it describes the policy and priorities as they exist today but can evolve over time.*** - -## Stability Policy - -The most important consideration in every code change is the impact it will have, positive or negative, on the ecosystem (modules and applications). - -Node.js does not remove stdlib JS API. - -Shipping with current and well supported dependencies is the best way to ensure long term stability of the platform. - -Node.js will continue to adopt new V8 releases. -* When V8 ships a breaking change to their C++ API that can be handled by [`nan`](https://github.com/nodejs/nan) -the *minor* version of Node.js will be increased. -* When V8 ships a breaking change to their C++ API that can NOT be handled by [`nan`](https://github.com/nodejs/nan) -the *major* version of Node.js will be increased. -* When new features in the JavaScript language are introduced by V8 the -*minor* version number will be increased. TC39 has stated clearly that no -backwards incompatible changes will be made to the language so it is -appropriate to increase the minor rather than major. - -No new API will be added in *patch* releases. - -Any API addition will cause an increase in the *minor* version. - -## Channels - -Channels are points of collaboration with the broader community and are not strictly scoped to a repository or branch. - -* Release - Stable production ready builds. Unique version numbers following semver. -* Canary - Nightly builds w/ V8 version in Chrome Canary + changes landing to Node.js. No version designation. -* NG - "Next Generation." No version designation. - -## NG (Next Generation) - -In order for Node.js to stay competitive we need to work on the next generation of the platform which will more accurately integrate and reflect the advancements in the language and the ecosystem. - -While this constitutes a great leap forward for the platform we will be making this leap without breaking backwards compatibility with the existing ecosystem of modules. - -## Immediate Priorities - -### Debugging and Tracing - -Debugging is one of the first things from everyone's mouth, both developer and enterprise, when describing trouble they've had with Node.js. - -The goal of Node.js' effort is to build a healthy debugging and tracing ecosystem and not to try and build any "silver bullet" features for core (like the domains debacle). - -The [Tracing WG](https://github.com/nodejs/tracing-wg) is driving this effort: - -* AsyncWrap improvements - basically just iterations based on feedback from people using it. -* async-listener - userland module that will dogfood AsyncWrap as well as provide many often requested debugging features. -* Tracing - * Add tracing support for more platforms (LTTng, etc). - * [Unify the Tracing endpoint](https://github.com/nodejs/node/issues/729). - * New Chrome Debugger - Google is working on a version of Chrome's debugger that is without Chrome and can be used with Node.js. - -### Ecosystem Automation - -In order to maintain a good release cadence without harming compatibility we must do a better job of understanding exactly what impact a particular change or release will have on the ecosystem. This requires new automation. - -The initial goals for this automation are relatively simple but will create a baseline toolchain we can continue to improve upon. - -* Produce a list of modules that no longer build between two release versions. -* Produce a list of modules that use a particular core API. -* Produce detailed code coverage data for the tests in core. - -### Improve Installation and Upgrades - -* Host and maintain registry endpoints (Homebrew, apt, etc). -* Document installation and upgrade procedures with an emphasis on using nvm or nave for development and our registry endpoints for traditional package managers and production. - -### Streams - -* Fix all existing compatibility issues. -* Simplify stream creation to avoid user error. -* Explore and identify compatibility issues with [WHATWG Streams](https://github.com/whatwg/streams). -* Improve stream performance. - -### Internationalization / Localization - -* Build documentation tooling with localization support built in. -* Reduce size of ICU and ship with it by default. -* Continue growth of our i18n community. From 678e225d56098ce22055ffca686d729aa74d5f30 Mon Sep 17 00:00:00 2001 From: chiaki-yokoo Date: Fri, 17 Feb 2017 12:55:27 +0900 Subject: [PATCH 034/151] test: improve https coverage to check create connection PR-URL: https://github.com/nodejs/node/pull/11435 Reviewed-By: James M Snell Reviewed-By: Yuta Hiroto --- .../test-https-agent-create-connection.js | 124 ++++++++++++++++++ 1 file changed, 124 insertions(+) create mode 100644 test/parallel/test-https-agent-create-connection.js diff --git a/test/parallel/test-https-agent-create-connection.js b/test/parallel/test-https-agent-create-connection.js new file mode 100644 index 00000000000000..f593700081a88f --- /dev/null +++ b/test/parallel/test-https-agent-create-connection.js @@ -0,0 +1,124 @@ +'use strict'; + +const common = require('../common'); +if (!common.hasCrypto) { + common.skip('missing crypto'); + return; +} + +const assert = require('assert'); +const https = require('https'); + +const agent = new https.Agent(); + +const fs = require('fs'); + +const options = { + key: fs.readFileSync(common.fixturesDir + '/keys/agent1-key.pem'), + cert: fs.readFileSync(common.fixturesDir + '/keys/agent1-cert.pem'), +}; + +const server = https.createServer(options, (req, res) => { + res.end('hello world\n'); +}); + +const expectedHeader = /^HTTP\/1.1 200 OK/; +const expectedBody = /hello world\n/; +const expectCertError = /^Error: unable to verify the first certificate$/; + +const checkRequest = (socket, server) => { + let result = ''; + socket.on('connect', common.mustCall((data) => { + socket.write('GET / HTTP/1.1\r\n\r\n'); + socket.end(); + })); + socket.on('data', common.mustCall((chunk) => { + result += chunk; + })); + socket.on('end', common.mustCall(() => { + assert(expectedHeader.test(result)); + assert(expectedBody.test(result)); + server.close(); + })); +}; + +// use option connect +server.listen(0, common.mustCall(() => { + const port = server.address().port; + const host = 'localhost'; + const options = { + port: port, + host: host, + rejectUnauthorized: false, + _agentKey: agent.getName({ + port: port, + host: host, + }), + }; + + const socket = agent.createConnection(options); + checkRequest(socket, server); +})); + +// use port and option connect +server.listen(0, common.mustCall(() => { + const port = server.address().port; + const host = 'localhost'; + const options = { + rejectUnauthorized: false, + _agentKey: agent.getName({ + port: port, + host: host, + }), + }; + const socket = agent.createConnection(port, options); + checkRequest(socket, server); +})); + +// use port and host and option connect +server.listen(0, common.mustCall(() => { + const port = server.address().port; + const host = 'localhost'; + const options = { + rejectUnauthorized: false, + _agentKey: agent.getName({ + port: port, + host: host, + }), + }; + const socket = agent.createConnection(port, host, options); + checkRequest(socket, server); +})); + +// use port and host and option does not have agentKey +server.listen(0, common.mustCall(() => { + const port = server.address().port; + const host = 'localhost'; + const options = { + rejectUnauthorized: false, + }; + const socket = agent.createConnection(port, host, options); + checkRequest(socket, server); +})); + +// options is null +server.listen(0, common.mustCall(() => { + const port = server.address().port; + const host = 'localhost'; + const options = null; + const socket = agent.createConnection(port, host, options); + socket.on('error', common.mustCall((e) => { + assert(expectCertError.test(e.toString())); + })); +})); + +// options is undefined +server.listen(0, common.mustCall(() => { + const port = server.address().port; + const host = 'localhost'; + const options = undefined; + const socket = agent.createConnection(port, host, options); + socket.on('error', common.mustCall((e) => { + assert(expectCertError.test(e.toString())); + })); +})); From 640b72e27dc44f21ccbc123ef6c6f4b1b7fb3f93 Mon Sep 17 00:00:00 2001 From: Santiago Gimeno Date: Thu, 2 Mar 2017 12:34:07 +0100 Subject: [PATCH 035/151] test: fix flaky test-https-agent-create-connection Use a different server instance for every test to avoid that they reuse the same port. PR-URL: https://github.com/nodejs/node/pull/11649 Fixes: https://github.com/nodejs/node/issues/11644 Reviewed-By: Colin Ihrig Reviewed-By: Michael Dawson Reviewed-By: Rich Trott Reviewed-By: Gibson Fahnestock --- .../test-https-agent-create-connection.js | 158 ++++++++++-------- 1 file changed, 90 insertions(+), 68 deletions(-) diff --git a/test/parallel/test-https-agent-create-connection.js b/test/parallel/test-https-agent-create-connection.js index f593700081a88f..6bd86fe166d3f2 100644 --- a/test/parallel/test-https-agent-create-connection.js +++ b/test/parallel/test-https-agent-create-connection.js @@ -18,10 +18,6 @@ const options = { cert: fs.readFileSync(common.fixturesDir + '/keys/agent1-cert.pem'), }; -const server = https.createServer(options, (req, res) => { - res.end('hello world\n'); -}); - const expectedHeader = /^HTTP\/1.1 200 OK/; const expectedBody = /hello world\n/; const expectCertError = /^Error: unable to verify the first certificate$/; @@ -42,83 +38,109 @@ const checkRequest = (socket, server) => { })); }; +function createServer() { + return https.createServer(options, (req, res) => { + res.end('hello world\n'); + }); +} + // use option connect -server.listen(0, common.mustCall(() => { - const port = server.address().port; - const host = 'localhost'; - const options = { - port: port, - host: host, - rejectUnauthorized: false, - _agentKey: agent.getName({ +{ + const server = createServer(); + server.listen(0, common.mustCall(() => { + const port = server.address().port; + const host = 'localhost'; + const options = { port: port, host: host, - }), - }; + rejectUnauthorized: false, + _agentKey: agent.getName({ + port: port, + host: host, + }), + }; - const socket = agent.createConnection(options); - checkRequest(socket, server); -})); + const socket = agent.createConnection(options); + checkRequest(socket, server); + })); +} // use port and option connect -server.listen(0, common.mustCall(() => { - const port = server.address().port; - const host = 'localhost'; - const options = { - rejectUnauthorized: false, - _agentKey: agent.getName({ - port: port, - host: host, - }), - }; - const socket = agent.createConnection(port, options); - checkRequest(socket, server); -})); +{ + const server = createServer(); + server.listen(0, common.mustCall(() => { + const port = server.address().port; + const host = 'localhost'; + const options = { + rejectUnauthorized: false, + _agentKey: agent.getName({ + port: port, + host: host, + }), + }; + const socket = agent.createConnection(port, options); + checkRequest(socket, server); + })); +} // use port and host and option connect -server.listen(0, common.mustCall(() => { - const port = server.address().port; - const host = 'localhost'; - const options = { - rejectUnauthorized: false, - _agentKey: agent.getName({ - port: port, - host: host, - }), - }; - const socket = agent.createConnection(port, host, options); - checkRequest(socket, server); -})); +{ + const server = createServer(); + server.listen(0, common.mustCall(() => { + const port = server.address().port; + const host = 'localhost'; + const options = { + rejectUnauthorized: false, + _agentKey: agent.getName({ + port: port, + host: host, + }), + }; + const socket = agent.createConnection(port, host, options); + checkRequest(socket, server); + })); +} // use port and host and option does not have agentKey -server.listen(0, common.mustCall(() => { - const port = server.address().port; - const host = 'localhost'; - const options = { - rejectUnauthorized: false, - }; - const socket = agent.createConnection(port, host, options); - checkRequest(socket, server); -})); +{ + const server = createServer(); + server.listen(0, common.mustCall(() => { + const port = server.address().port; + const host = 'localhost'; + const options = { + rejectUnauthorized: false, + }; + const socket = agent.createConnection(port, host, options); + checkRequest(socket, server); + })); +} // options is null -server.listen(0, common.mustCall(() => { - const port = server.address().port; - const host = 'localhost'; - const options = null; - const socket = agent.createConnection(port, host, options); - socket.on('error', common.mustCall((e) => { - assert(expectCertError.test(e.toString())); +{ + const server = createServer(); + server.listen(0, common.mustCall(() => { + const port = server.address().port; + const host = 'localhost'; + const options = null; + const socket = agent.createConnection(port, host, options); + socket.on('error', common.mustCall((e) => { + assert(expectCertError.test(e.toString())); + server.close(); + })); })); -})); +} // options is undefined -server.listen(0, common.mustCall(() => { - const port = server.address().port; - const host = 'localhost'; - const options = undefined; - const socket = agent.createConnection(port, host, options); - socket.on('error', common.mustCall((e) => { - assert(expectCertError.test(e.toString())); +{ + const server = createServer(); + server.listen(0, common.mustCall(() => { + const port = server.address().port; + const host = 'localhost'; + const options = undefined; + const socket = agent.createConnection(port, host, options); + socket.on('error', common.mustCall((e) => { + assert(expectCertError.test(e.toString())); + server.close(); + })); })); -})); +} From 39f7aaa2902709907495793d4f594ac205251be3 Mon Sep 17 00:00:00 2001 From: Rich Trott Date: Mon, 27 Feb 2017 07:32:23 -0800 Subject: [PATCH 036/151] timers: unlock the timers API MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change the Stability Index on timers from Locked to Stable. Note that this is not intended to encourage changes to the timers API, but to allow it when its useful for Node.js (as has happened in violation of the documented stability level), and possibly to simplify the stability levels by removing Locked altogether. PR-URL: https://github.com/nodejs/node/pull/11580 Ref: https://github.com/nodejs/node/issues/11200 Reviewed-By: Sam Roberts Reviewed-By: Gibson Fahnestock Reviewed-By: Сковорода Никита Андреевич Reviewed-By: James M Snell Reviewed-By: Michaël Zasso Reviewed-By: Colin Ihrig --- doc/api/timers.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/api/timers.md b/doc/api/timers.md index aa99d619dbd284..df48905001e19b 100644 --- a/doc/api/timers.md +++ b/doc/api/timers.md @@ -1,6 +1,6 @@ # Timers -> Stability: 3 - Locked +> Stability: 2 - Stable The `timer` module exposes a global API for scheduling functions to be called at some future period of time. Because the timer functions are From a27098d92164f3f57dfd569d9adfd4f0fb3c432c Mon Sep 17 00:00:00 2001 From: Rich Trott Date: Sat, 25 Feb 2017 16:23:49 -0800 Subject: [PATCH 037/151] test: enable max-len for test-repl Instead of disabling max-len (ESLint's line-length rule) for the entire file, reformat to avoid exceeding length restrictions in most cases and disable the rule only on specific lines where exceeding the length restriction may be a better choice than conforming to it. PR-URL: https://github.com/nodejs/node/pull/11559 Reviewed-By: James M Snell Reviewed-By: Yuta Hiroto --- test/parallel/test-repl.js | 69 +++++++++++++++++++++++++------------- 1 file changed, 46 insertions(+), 23 deletions(-) diff --git a/test/parallel/test-repl.js b/test/parallel/test-repl.js index 420010e1a3d6c9..3cf1b52e6179f2 100644 --- a/test/parallel/test-repl.js +++ b/test/parallel/test-repl.js @@ -1,4 +1,3 @@ -/* eslint-disable max-len */ 'use strict'; const common = require('../common'); @@ -168,18 +167,32 @@ function error_test() { { client: client_unix, send: 'new RegExp("foo", "wrong modifier");', expect: /\bSyntaxError: Invalid flags supplied to RegExp constructor/ }, // strict mode syntax errors should be caught (GH-5178) - { client: client_unix, send: '(function() { "use strict"; return 0755; })()', + { client: client_unix, + send: '(function() { "use strict"; return 0755; })()', expect: /\bSyntaxError: Octal literals are not allowed in strict mode/ }, - { client: client_unix, send: '(function(a, a, b) { "use strict"; return a + b + c; })()', - expect: /\bSyntaxError: Duplicate parameter name not allowed in this context/ }, - { client: client_unix, send: '(function() { "use strict"; with (this) {} })()', - expect: /\bSyntaxError: Strict mode code may not include a with statement/ }, - { client: client_unix, send: '(function() { "use strict"; var x; delete x; })()', - expect: /\bSyntaxError: Delete of an unqualified identifier in strict mode/ }, - { client: client_unix, send: '(function() { "use strict"; eval = 17; })()', + { + client: client_unix, + send: '(function(a, a, b) { "use strict"; return a + b + c; })()', + expect: /\bSyntaxError: Duplicate parameter name not allowed in this context/ // eslint-disable-line max-len + }, + { + client: client_unix, + send: '(function() { "use strict"; with (this) {} })()', + expect: /\bSyntaxError: Strict mode code may not include a with statement/ + }, + { + client: client_unix, + send: '(function() { "use strict"; var x; delete x; })()', + expect: /\bSyntaxError: Delete of an unqualified identifier in strict mode/ // eslint-disable-line max-len + }, + { client: client_unix, + send: '(function() { "use strict"; eval = 17; })()', expect: /\bSyntaxError: Unexpected eval or arguments in strict mode/ }, - { client: client_unix, send: '(function() { "use strict"; if (true) function f() { } })()', - expect: /\bSyntaxError: In strict mode code, functions can only be declared at top level or inside a block./ }, + { + client: client_unix, + send: '(function() { "use strict"; if (true) function f() { } })()', + expect: /\bSyntaxError: In strict mode code, functions can only be declared at top level or inside a block./ // eslint-disable-line max-len + }, // Named functions can be used: { client: client_unix, send: 'function blah() { return 1; }', expect: prompt_unix }, @@ -312,16 +325,20 @@ function error_test() { { client: client_unix, send: 'require("internal/repl")', expect: /^Error: Cannot find module 'internal\/repl'/ }, // REPL should handle quotes within regexp literal in multiline mode - { client: client_unix, send: "function x(s) {\nreturn s.replace(/'/,'');\n}", + { client: client_unix, + send: "function x(s) {\nreturn s.replace(/'/,'');\n}", expect: prompt_multiline + prompt_multiline + 'undefined\n' + prompt_unix }, - { client: client_unix, send: "function x(s) {\nreturn s.replace(/'/,'');\n}", + { client: client_unix, + send: "function x(s) {\nreturn s.replace(/'/,'');\n}", expect: prompt_multiline + prompt_multiline + 'undefined\n' + prompt_unix }, - { client: client_unix, send: 'function x(s) {\nreturn s.replace(/"/,"");\n}', + { client: client_unix, + send: 'function x(s) {\nreturn s.replace(/"/,"");\n}', expect: prompt_multiline + prompt_multiline + 'undefined\n' + prompt_unix }, - { client: client_unix, send: 'function x(s) {\nreturn s.replace(/.*/,"");\n}', + { client: client_unix, + send: 'function x(s) {\nreturn s.replace(/.*/,"");\n}', expect: prompt_multiline + prompt_multiline + 'undefined\n' + prompt_unix }, { client: client_unix, send: '{ var x = 4; }', @@ -356,14 +373,20 @@ function error_test() { expect: '{ value: undefined, done: true }' }, // https://github.com/nodejs/node/issues/9300 - { client: client_unix, send: 'function foo() {\nvar bar = 1 / 1; // "/"\n}', - expect: prompt_multiline + prompt_multiline + 'undefined\n' + prompt_unix }, - - { client: client_unix, send: '(function() {\nreturn /foo/ / /bar/;\n}())', - expect: prompt_multiline + prompt_multiline + 'NaN\n' + prompt_unix }, - - { client: client_unix, send: '(function() {\nif (false) {} /bar"/;\n}())', - expect: prompt_multiline + prompt_multiline + 'undefined\n' + prompt_unix } + { + client: client_unix, send: 'function foo() {\nvar bar = 1 / 1; // "/"\n}', + expect: `${prompt_multiline}${prompt_multiline}undefined\n${prompt_unix}` + }, + + { + client: client_unix, send: '(function() {\nreturn /foo/ / /bar/;\n}())', + expect: prompt_multiline + prompt_multiline + 'NaN\n' + prompt_unix + }, + + { + client: client_unix, send: '(function() {\nif (false) {} /bar"/;\n}())', + expect: prompt_multiline + prompt_multiline + 'undefined\n' + prompt_unix + } ]); } From 96924ed8f5019e05163ce0d43617660761680986 Mon Sep 17 00:00:00 2001 From: Rich Trott Date: Mon, 27 Feb 2017 23:56:39 -0800 Subject: [PATCH 038/151] test: add test-buffer-prototype-inspect lib/buffer.js defines Buffer.prototype.inspect() to override how buffers are presented by util.inspect(). Add basic tests for it. PR-URL: https://github.com/nodejs/node/pull/11600 Reviewed-By: Anna Henningsen Reviewed-By: James M Snell Reviewed-By: Colin Ihrig Reviewed-By: Yuta Hiroto Reviewed-By: Luigi Pinca --- .../parallel/test-buffer-prototype-inspect.js | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 test/parallel/test-buffer-prototype-inspect.js diff --git a/test/parallel/test-buffer-prototype-inspect.js b/test/parallel/test-buffer-prototype-inspect.js new file mode 100644 index 00000000000000..5f65a9bb288f16 --- /dev/null +++ b/test/parallel/test-buffer-prototype-inspect.js @@ -0,0 +1,23 @@ +'use strict'; +require('../common'); + +// lib/buffer.js defines Buffer.prototype.inspect() to override how buffers are +// presented by util.inspect(). + +const assert = require('assert'); +const util = require('util'); + +{ + const buf = Buffer.from('fhqwhgads'); + assert.strictEqual(util.inspect(buf), ''); +} + +{ + const buf = Buffer.from(''); + assert.strictEqual(util.inspect(buf), ''); +} + +{ + const buf = Buffer.from('x'.repeat(51)); + assert.ok(/^$/.test(util.inspect(buf))); +} From 5d74c9e749076ceb20eb57dc98e281727e3bb726 Mon Sep 17 00:00:00 2001 From: Rich Trott Date: Tue, 28 Feb 2017 00:15:07 -0800 Subject: [PATCH 039/151] buffer: refactor Buffer.prototype.inspect() Replace toString().match().join() with toString().replace().trim(). This enables the elimination of a length check becuase replace() will return empty string if Buffer is empty whereas match() returns null. PR-URL: https://github.com/nodejs/node/pull/11600 Reviewed-By: Anna Henningsen Reviewed-By: James M Snell Reviewed-By: Colin Ihrig Reviewed-By: Yuta Hiroto Reviewed-By: Luigi Pinca --- lib/buffer.js | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/lib/buffer.js b/lib/buffer.js index 7c29af3353d474..8c4f8620e55c9d 100644 --- a/lib/buffer.js +++ b/lib/buffer.js @@ -513,12 +513,10 @@ Buffer.prototype.equals = function equals(b) { Buffer.prototype[internalUtil.customInspectSymbol] = function inspect() { var str = ''; var max = exports.INSPECT_MAX_BYTES; - if (this.length > 0) { - str = this.toString('hex', 0, max).match(/.{2}/g).join(' '); - if (this.length > max) - str += ' ... '; - } - return '<' + this.constructor.name + ' ' + str + '>'; + str = this.toString('hex', 0, max).replace(/(.{2})/g, '$1 ').trim(); + if (this.length > max) + str += ' ... '; + return `<${this.constructor.name} ${str}>`; }; Buffer.prototype.inspect = Buffer.prototype[internalUtil.customInspectSymbol]; From 3e6d9922b91762f07cad3c5ecdf2c78f5b56caac Mon Sep 17 00:00:00 2001 From: Rich Trott Date: Tue, 28 Feb 2017 07:46:52 -0800 Subject: [PATCH 040/151] tools: remove NODE_PATH from environment for tests Unset NODE_PATH environment variable when running tests. On Ubuntu 16.04, some users experience test failures due to internal libraries being installed in /usr/lib/nodejs/internal and NODE_PATH including /usr/lib/nodejs. Tests that expect internal libraries to be off limits without the --expose-internals flag will fail in this situation. Currently, those tests are test/parallel/test-repl.js and test/parallel/test-internal-modules.js. This situation seems to (probably) be caused by some not-entirely-uncommon package that gets installed. Regardless, tests should ignore the user's NODE_PATH. (NODE_PATH is tested in test/parallel/test-module-globalpaths-nodepath.js and test/parallel/test-require-dot.js.) PR-URL: https://github.com/nodejs/node/pull/11612 Reviewed-By: James M Snell Reviewed-By: Bryan English Reviewed-By: Santiago Gimeno Refs: https://twitter.com/trott/status/835729396900061184 --- tools/test.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/tools/test.py b/tools/test.py index f46b13fa30a66a..d6715937b60da3 100755 --- a/tools/test.py +++ b/tools/test.py @@ -702,8 +702,13 @@ def Execute(args, context, timeout=None, env={}, faketty=False): fd_in = 0 pty_out = None - # Extend environment env_copy = os.environ.copy() + + # Remove NODE_PATH + if "NODE_PATH" in env_copy: + del env_copy["NODE_PATH"] + + # Extend environment for key, value in env.iteritems(): env_copy[key] = value From b1ddf11c1428f7807e103edb30ab8c203781c107 Mon Sep 17 00:00:00 2001 From: Shigeki Ohtsu Date: Thu, 2 Mar 2017 23:13:19 +0900 Subject: [PATCH 041/151] tls: fix macro to check NPN feature In order to check if NPN feature is enabled, use `#ifndef OPENSSL_NO_NEXTPROTONEG` rather than `#ifdef OPENSSL_NPN_NEGOTIATED` because the former is used in ssl.h. Fixes: https://github.com/nodejs/node/issues/11650 PR-URL: https://github.com/nodejs/node/pull/11655 Reviewed-By: James M Snell Reviewed-By: Michael Dawson Reviewed-By: Ben Noordhuis Reviewed-By: Fedor Indutny --- src/node.cc | 2 +- src/node_constants.cc | 2 +- src/node_crypto.cc | 16 ++++++++-------- src/node_crypto.h | 6 +++--- 4 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/node.cc b/src/node.cc index fe2fc2a6a4eda6..41aeb1934aee74 100644 --- a/src/node.cc +++ b/src/node.cc @@ -2925,7 +2925,7 @@ static Local GetFeatures(Environment* env) { // TODO(bnoordhuis) ping libuv obj->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "ipv6"), True(env->isolate())); -#ifdef OPENSSL_NPN_NEGOTIATED +#ifndef OPENSSL_NO_NEXTPROTONEG Local tls_npn = True(env->isolate()); #else Local tls_npn = False(env->isolate()); diff --git a/src/node_constants.cc b/src/node_constants.cc index 2e6be8df37c345..750df9c669bad3 100644 --- a/src/node_constants.cc +++ b/src/node_constants.cc @@ -940,7 +940,7 @@ void DefineOpenSSLConstants(Local target) { NODE_DEFINE_CONSTANT(target, DH_NOT_SUITABLE_GENERATOR); #endif -#ifdef OPENSSL_NPN_NEGOTIATED +#ifndef OPENSSL_NO_NEXTPROTONEG #define NPN_ENABLED 1 NODE_DEFINE_CONSTANT(target, NPN_ENABLED); #endif diff --git a/src/node_crypto.cc b/src/node_crypto.cc index eb23d787c238e2..28057e774f3802 100644 --- a/src/node_crypto.cc +++ b/src/node_crypto.cc @@ -147,7 +147,7 @@ template void SSLWrap::OnClientHello( void* arg, const ClientHelloParser::ClientHello& hello); -#ifdef OPENSSL_NPN_NEGOTIATED +#ifndef OPENSSL_NO_NEXTPROTONEG template int SSLWrap::AdvertiseNextProtoCallback( SSL* s, const unsigned char** data, @@ -1309,11 +1309,11 @@ void SSLWrap::AddMethods(Environment* env, Local t) { env->SetProtoMethod(t, "setMaxSendFragment", SetMaxSendFragment); #endif // SSL_set_max_send_fragment -#ifdef OPENSSL_NPN_NEGOTIATED +#ifndef OPENSSL_NO_NEXTPROTONEG env->SetProtoMethod(t, "getNegotiatedProtocol", GetNegotiatedProto); -#endif // OPENSSL_NPN_NEGOTIATED +#endif // OPENSSL_NO_NEXTPROTONEG -#ifdef OPENSSL_NPN_NEGOTIATED +#ifndef OPENSSL_NO_NEXTPROTONEG env->SetProtoMethod(t, "setNPNProtocols", SetNPNProtocols); #endif @@ -1333,7 +1333,7 @@ void SSLWrap::AddMethods(Environment* env, Local t) { template void SSLWrap::InitNPN(SecureContext* sc) { -#ifdef OPENSSL_NPN_NEGOTIATED +#ifndef OPENSSL_NO_NEXTPROTONEG // Server should advertise NPN protocols SSL_CTX_set_next_protos_advertised_cb(sc->ctx_, AdvertiseNextProtoCallback, @@ -1341,7 +1341,7 @@ void SSLWrap::InitNPN(SecureContext* sc) { // Client should select protocol from list of advertised // If server supports NPN SSL_CTX_set_next_proto_select_cb(sc->ctx_, SelectNextProtoCallback, nullptr); -#endif // OPENSSL_NPN_NEGOTIATED +#endif // OPENSSL_NO_NEXTPROTONEG #ifdef NODE__HAVE_TLSEXT_STATUS_CB // OCSP stapling @@ -2098,7 +2098,7 @@ void SSLWrap::GetProtocol(const FunctionCallbackInfo& args) { } -#ifdef OPENSSL_NPN_NEGOTIATED +#ifndef OPENSSL_NO_NEXTPROTONEG template int SSLWrap::AdvertiseNextProtoCallback(SSL* s, const unsigned char** data, @@ -2238,7 +2238,7 @@ void SSLWrap::SetNPNProtocols(const FunctionCallbackInfo& args) { env->npn_buffer_private_symbol(), args[0]).FromJust()); } -#endif // OPENSSL_NPN_NEGOTIATED +#endif // OPENSSL_NO_NEXTPROTONEG #ifdef TLSEXT_TYPE_application_layer_protocol_negotiation template diff --git a/src/node_crypto.h b/src/node_crypto.h index 175206c40df586..38f49ba5a05063 100644 --- a/src/node_crypto.h +++ b/src/node_crypto.h @@ -249,7 +249,7 @@ class SSLWrap { const v8::FunctionCallbackInfo& args); #endif // SSL_set_max_send_fragment -#ifdef OPENSSL_NPN_NEGOTIATED +#ifndef OPENSSL_NO_NEXTPROTONEG static void GetNegotiatedProto( const v8::FunctionCallbackInfo& args); static void SetNPNProtocols(const v8::FunctionCallbackInfo& args); @@ -263,7 +263,7 @@ class SSLWrap { const unsigned char* in, unsigned int inlen, void* arg); -#endif // OPENSSL_NPN_NEGOTIATED +#endif // OPENSSL_NO_NEXTPROTONEG static void GetALPNNegotiatedProto( const v8::FunctionCallbackInfo& args); @@ -328,7 +328,7 @@ class Connection : public AsyncWrap, public SSLWrap { static void Initialize(Environment* env, v8::Local target); void NewSessionDoneCb(); -#ifdef OPENSSL_NPN_NEGOTIATED +#ifndef OPENSSL_NO_NEXTPROTONEG v8::Persistent npnProtos_; v8::Persistent selectedNPNProto_; #endif From 7cc4645b701608e7fd067cd2be0f9c474284a384 Mon Sep 17 00:00:00 2001 From: Shigeki Ohtsu Date: Thu, 2 Mar 2017 23:19:49 +0900 Subject: [PATCH 042/151] test: fix tests when npn feature is disabled. ALPN test needs NPN feature to run. It also change the messages when ALPN and NPN tests are skipped. Fixes: https://github.com/nodejs/node/issues/11650 PR-URL: https://github.com/nodejs/node/pull/11655 Reviewed-By: James M Snell Reviewed-By: Michael Dawson Reviewed-By: Ben Noordhuis Reviewed-By: Fedor Indutny --- test/parallel/test-tls-alpn-server-client.js | 8 ++++---- test/parallel/test-tls-npn-server-client.js | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/test/parallel/test-tls-alpn-server-client.js b/test/parallel/test-tls-alpn-server-client.js index ca5785b09ac05a..9199d946791084 100644 --- a/test/parallel/test-tls-alpn-server-client.js +++ b/test/parallel/test-tls-alpn-server-client.js @@ -6,10 +6,10 @@ if (!common.hasCrypto) { return; } -if (!process.features.tls_alpn) { - console.error('Skipping because node compiled without OpenSSL or ' + - 'with old OpenSSL version.'); - process.exit(0); +if (!process.features.tls_alpn || !process.features.tls_npn) { + common.skip('Skipping because node compiled without NPN or ALPN' + + ' feature of OpenSSL.'); + return; } const assert = require('assert'); diff --git a/test/parallel/test-tls-npn-server-client.js b/test/parallel/test-tls-npn-server-client.js index fdc42dab6968d9..2369673073c6d7 100644 --- a/test/parallel/test-tls-npn-server-client.js +++ b/test/parallel/test-tls-npn-server-client.js @@ -1,7 +1,7 @@ 'use strict'; if (!process.features.tls_npn) { - common.skip('node compiled without OpenSSL or ' + - 'with old OpenSSL version.'); + common.skip('Skipping because node compiled without NPN feature of' + + ' OpenSSL.'); return; } From 3419b7a9d46930b62152b56cde6fe3179aa89a75 Mon Sep 17 00:00:00 2001 From: Daijiro Wachi Date: Fri, 3 Mar 2017 18:17:24 +0100 Subject: [PATCH 043/151] doc: add `Daijiro Wachi` to collaborators PR-URL: https://github.com/nodejs/node/pull/11676 Reviewed-By: Evan Lucas --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 77919134c3342c..4be3c788d7dc32 100644 --- a/README.md +++ b/README.md @@ -337,6 +337,8 @@ more information about the governance of the Node.js project, see **Mike Tunnicliffe** <m.j.tunnicliffe@gmail.com> * [vkurchatkin](https://github.com/vkurchatkin) - **Vladimir Kurchatkin** <vladimir.kurchatkin@gmail.com> +* [watilde](https://github.com/watilde) - +**Daijiro Wachi** <daijiro.wachi@gmail.com> (he/him) * [whitlockjc](https://github.com/whitlockjc) - **Jeremy Whitlock** <jwhitlock@apache.org> * [yorkie](https://github.com/yorkie) - From 63449972d13f8321bd754879660549eda00844de Mon Sep 17 00:00:00 2001 From: Daijiro Wachi Date: Tue, 28 Feb 2017 10:06:25 +0100 Subject: [PATCH 044/151] url: use `hasIntl` instead of `try-catch` Like the other internal modules, we should use `process.binding('config').hasIntl` instead of `try-catch` to make sure `icu` is bonded or not. PR-URL: https://github.com/nodejs/node/pull/11571 Reviewed-By: James M Snell Reviewed-By: Timothy Gu Reviewed-By: Colin Ihrig Reviewed-By: Luigi Pinca Reviewed-By: Anna Henningsen Reviewed-By: Jackson Tian --- lib/url.js | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/lib/url.js b/lib/url.js index 59821b67ca3bfc..8579f2656b9eac 100644 --- a/lib/url.js +++ b/lib/url.js @@ -1,14 +1,7 @@ 'use strict'; -function importPunycode() { - try { - return process.binding('icu'); - } catch (e) { - return require('punycode'); - } -} - -const { toASCII } = importPunycode(); +const { toASCII } = process.binding('config').hasIntl ? + process.binding('icu') : require('punycode'); exports.parse = urlParse; exports.resolve = urlResolve; From 1b4f69acae23ca57ead821a57c424d47a3a56544 Mon Sep 17 00:00:00 2001 From: Rich Trott Date: Wed, 1 Mar 2017 18:58:10 -0800 Subject: [PATCH 045/151] test: remove obsolete eslint-disable comment The align-function-arguments custom rule is obsolete and has been removed from the code base. Remove comment that used to disable it for one file. PR-URL: https://github.com/nodejs/node/pull/11643 Reviewed-By: Colin Ihrig Reviewed-By: James M Snell Reviewed-By: Yuta Hiroto Reviewed-By: Teddy Katz --- test/parallel/test-http-parser-bad-ref.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/test/parallel/test-http-parser-bad-ref.js b/test/parallel/test-http-parser-bad-ref.js index 97b4685e18382b..c4ab1db8659ef7 100644 --- a/test/parallel/test-http-parser-bad-ref.js +++ b/test/parallel/test-http-parser-bad-ref.js @@ -75,12 +75,10 @@ demoBug('POST /1', '/22 HTTP/1.1\r\n' + 'Content-Length: 4\r\n\r\n' + 'pong'); -/* eslint-disable align-function-arguments */ demoBug('POST /1/22 HTTP/1.1\r\n' + 'Content-Type: tex', 't/plain\r\n' + 'Content-Length: 4\r\n\r\n' + 'pong'); -/* eslint-enable align-function-arguments */ process.on('exit', function() { assert.strictEqual(2, headersComplete); From 103596798946abdb0bcbf0cccdb6185e59b192cd Mon Sep 17 00:00:00 2001 From: Daniel Bevenius Date: Fri, 3 Mar 2017 11:02:20 +0100 Subject: [PATCH 046/151] src: remove outdated FIXME in node_crypto.cc Issue 4641 contains a FIXME regarding the InitCrypto function. After discussing this with bnoordhuis it seems to be an outdated comment. Refs: https://github.com/nodejs/node/issues/4641 PR-URL: https://github.com/nodejs/node/pull/11669 Reviewed-By: Gibson Fahnestock Reviewed-By: Ben Noordhuis Reviewed-By: Colin Ihrig Reviewed-By: James M Snell --- src/node_crypto.cc | 1 - 1 file changed, 1 deletion(-) diff --git a/src/node_crypto.cc b/src/node_crypto.cc index 28057e774f3802..f612bf5dc47d21 100644 --- a/src/node_crypto.cc +++ b/src/node_crypto.cc @@ -6028,7 +6028,6 @@ void SetFipsCrypto(const FunctionCallbackInfo& args) { #endif /* NODE_FIPS_MODE */ } -// FIXME(bnoordhuis) Handle global init correctly. void InitCrypto(Local target, Local unused, Local context, From a43aa0eaa9f3c8979a02cd27f50ee60285ec18df Mon Sep 17 00:00:00 2001 From: maurice_hayward Date: Mon, 27 Feb 2017 16:37:05 -0500 Subject: [PATCH 047/151] test: changed test1 of test-vm-timeout.js test: changed test1 of test-vm-timeout.js so that entire error message would be matched in assert.throw. Before test 1 of test-vm-timeout.js would match any error, now it looks specifically for the error message "Script execution timed out." PR-URL: https://github.com/nodejs/node/pull/11590 Reviewed-By: James M Snell Reviewed-By: Rich Trott Reviewed-By: Anna Henningsen Reviewed-By: Luigi Pinca Reviewed-By: Colin Ihrig --- test/parallel/test-vm-timeout.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/parallel/test-vm-timeout.js b/test/parallel/test-vm-timeout.js index 5260ca7dc28572..6ed73f8b4ffd78 100644 --- a/test/parallel/test-vm-timeout.js +++ b/test/parallel/test-vm-timeout.js @@ -6,7 +6,7 @@ const vm = require('vm'); // Test 1: Timeout of 100ms executing endless loop assert.throws(function() { vm.runInThisContext('while(true) {}', { timeout: 100 }); -}); +}, /^Error: Script execution timed out\.$/); // Test 2: Timeout must be >= 0ms assert.throws(function() { From e02d72427332155615ba81e132a584699009abda Mon Sep 17 00:00:00 2001 From: Rahat Ahmed Date: Thu, 2 Mar 2017 09:22:12 -0600 Subject: [PATCH 048/151] doc: fix misleading ASCII comments PR-URL: https://github.com/nodejs/node/pull/11657 Reviewed-By: Anna Henningsen Reviewed-By: James M Snell Reviewed-By: Colin Ihrig Reviewed-By: Claudio Rodriguez --- doc/api/buffer.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/doc/api/buffer.md b/doc/api/buffer.md index 44e274760d30cd..4c7734e0968a33 100644 --- a/doc/api/buffer.md +++ b/doc/api/buffer.md @@ -38,11 +38,11 @@ const buf3 = Buffer.allocUnsafe(10); // Creates a Buffer containing [0x1, 0x2, 0x3]. const buf4 = Buffer.from([1, 2, 3]); -// Creates a Buffer containing ASCII bytes [0x74, 0x65, 0x73, 0x74]. -const buf5 = Buffer.from('test'); - // Creates a Buffer containing UTF-8 bytes [0x74, 0xc3, 0xa9, 0x73, 0x74]. -const buf6 = Buffer.from('tést', 'utf8'); +const buf5 = Buffer.from('tést'); + +// Creates a Buffer containing Latin-1 bytes [0x74, 0xe9, 0x73, 0x74]. +const buf6 = Buffer.from('tést', 'latin-1'); ``` ## `Buffer.from()`, `Buffer.alloc()`, and `Buffer.allocUnsafe()` @@ -309,7 +309,7 @@ Allocates a new `Buffer` using an `array` of octets. Example: ```js -// Creates a new Buffer containing the ASCII bytes of the string 'buffer' +// Creates a new Buffer containing the UTF-8 bytes of the string 'buffer' const buf = new Buffer([0x62, 0x75, 0x66, 0x66, 0x65, 0x72]); ``` @@ -716,7 +716,7 @@ Allocates a new `Buffer` using an `array` of octets. Example: ```js -// Creates a new Buffer containing ASCII bytes of the string 'buffer' +// Creates a new Buffer containing UTF-8 bytes of the string 'buffer' const buf = Buffer.from([0x62, 0x75, 0x66, 0x66, 0x65, 0x72]); ``` From 70a6a0a9187db8b97425f7a2802aeacfda236ddf Mon Sep 17 00:00:00 2001 From: Rich Trott Date: Thu, 2 Mar 2017 10:35:24 -0800 Subject: [PATCH 049/151] doc: unlock module MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Update documentation for `module` to reflect stability index 2 (Stable) rather than 3 (Locked). PR-URL: https://github.com/nodejs/node/pull/11661 Ref: https://github.com/nodejs/node/issues/11200 Reviewed-By: Anna Henningsen Reviewed-By: Sam Roberts Reviewed-By: Gibson Fahnestock Reviewed-By: Michael Dawson Reviewed-By: Michaël Zasso Reviewed-By: Сковорода Никита Андреевич Reviewed-By: James M Snell --- doc/api/modules.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/api/modules.md b/doc/api/modules.md index 43bddab4faa310..0aeab0ad14bbd2 100644 --- a/doc/api/modules.md +++ b/doc/api/modules.md @@ -1,6 +1,6 @@ # Modules -> Stability: 3 - Locked +> Stability: 2 - Stable From 40b27ba8bb45a10168adc1695046a34a7512d4ee Mon Sep 17 00:00:00 2001 From: Rich Trott Date: Thu, 2 Mar 2017 10:37:20 -0800 Subject: [PATCH 050/151] doc: remove Locked from stability index MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The stability index 3 (Locked) is unused and is being eliminated. Remove it from the documentation about the stability index. Remove mention of the Locked from CONTRIBUTING.md. The remaining text about the stability index is slight and not seemingly valuable. Removing it too. PR-URL: https://github.com/nodejs/node/pull/11661 Ref: https://github.com/nodejs/node/issues/11200 Reviewed-By: Anna Henningsen Reviewed-By: Sam Roberts Reviewed-By: Gibson Fahnestock Reviewed-By: Michael Dawson Reviewed-By: Michaël Zasso Reviewed-By: Сковорода Никита Андреевич Reviewed-By: James M Snell --- CONTRIBUTING.md | 9 --------- doc/api/documentation.md | 6 ------ 2 files changed, 15 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 144fc393b8ac98..ab8217494e080f 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -46,15 +46,6 @@ $ git remote add upstream git://github.com/nodejs/node.git For developing new features and bug fixes, the `master` branch should be pulled and built upon. -#### Respect the stability index - -The rules for the master branch are less strict; consult the -[stability index](./doc/api/documentation.md#stability-index) for details. - -In a nutshell, modules are at varying levels of API stability. Bug fixes are -always welcome but API or behavioral changes to modules at stability level 3 -(Locked) are off-limits. - #### Dependencies Node.js has several bundled dependencies in the *deps/* and the *tools/* diff --git a/doc/api/documentation.md b/doc/api/documentation.md index 947010d951bdab..5f45c9b56ed387 100644 --- a/doc/api/documentation.md +++ b/doc/api/documentation.md @@ -56,12 +56,6 @@ The API has proven satisfactory. Compatibility with the npm ecosystem is a high priority, and will not be broken unless absolutely necessary. ``` -```txt -Stability: 3 - Locked -Only bug fixes, security fixes, and performance improvements will be accepted. -Please do not suggest API changes in this area; they will be refused. -``` - ## JSON Output > Stability: 1 - Experimental From e8f0dba3af42b6e85aca66c5c7d08b9f3ce56a0f Mon Sep 17 00:00:00 2001 From: Laurent Fortin Date: Fri, 3 Mar 2017 12:44:28 -0500 Subject: [PATCH 051/151] doc: fixed readable.isPaused() version annotation readable.isPaused(): added a missing YAML placeholder so the 'Added to version' annotation is displayed in docs PR-URL: https://github.com/nodejs/node/pull/11677 Reviewed-By: James M Snell Reviewed-By: Anna Henningsen Reviewed-By: Luigi Pinca Reviewed-By: Colin Ihrig Reviewed-By: Yuta Hiroto --- doc/api/stream.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/api/stream.md b/doc/api/stream.md index d7af669422b900..e2db0b29ccb255 100644 --- a/doc/api/stream.md +++ b/doc/api/stream.md @@ -728,7 +728,7 @@ end preferred over the use of the `'readable'` event. ##### readable.isPaused() - From 91b8da67a533381296bf0b79249a349fd41c8112 Mon Sep 17 00:00:00 2001 From: "Sakthipriyan Vairamani (thefourtheye)" Date: Tue, 28 Feb 2017 00:15:58 +0530 Subject: [PATCH 052/151] test: skip the test with proper TAP message On Windows, the test simply returns which will be counted as passed. The test actually skips the rest of the test. So proper TAP message has to be included while skipping. This patch uses `common.skip` rather than `console.log` to print the skip messages. PR-URL: https://github.com/nodejs/node/pull/11584 Reviewed-By: James M Snell Reviewed-By: Colin Ihrig Reviewed-By: Gibson Fahnestock Reviewed-By: Luigi Pinca --- test/parallel/test-setproctitle.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/test/parallel/test-setproctitle.js b/test/parallel/test-setproctitle.js index 9dd603bfdc3327..d0bb54a9709709 100644 --- a/test/parallel/test-setproctitle.js +++ b/test/parallel/test-setproctitle.js @@ -4,8 +4,7 @@ const common = require('../common'); // FIXME add sunos support if (!(common.isFreeBSD || common.isOSX || common.isLinux)) { - console.log(`1..0 # Skipped: Unsupported platform [${process.platform}]`); - return; + return common.skip(`Unsupported platform [${process.platform}]`); } const assert = require('assert'); From a899b0b92bd778341b80720c9a67431ab04d0269 Mon Sep 17 00:00:00 2001 From: Shigeki Ohtsu Date: Fri, 3 Mar 2017 15:22:08 +0900 Subject: [PATCH 053/151] build: fix llvm version detection in freebsd-10 In FreeBSD-10, the banner of clang version is "FreeBSD clang version". Fix regex to detect it. PR-URL: https://github.com/nodejs/node/pull/11668 Reviewed-By: Colin Ihrig Reviewed-By: James M Snell Reviewed-By: Ben Noordhuis --- configure | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/configure b/configure index e7fa06fe87f6f6..0019b516819bb3 100755 --- a/configure +++ b/configure @@ -571,11 +571,11 @@ def get_version_helper(cc, regexp): def get_llvm_version(cc): return get_version_helper( - cc, r"(^clang version|based on LLVM) ([3-9]\.[0-9]+)") + cc, r"(^(?:FreeBSD )?clang version|based on LLVM) ([3-9]\.[0-9]+)") def get_xcode_version(cc): return get_version_helper( - cc, r"(^Apple LLVM version) ([5-9]\.[0-9]+)") + cc, r"(^Apple LLVM version) ([5-9]\.[0-9]+)") def get_gas_version(cc): try: From e3105cf50abb61af7ec7158e0bb80d367a775604 Mon Sep 17 00:00:00 2001 From: James M Snell Date: Sat, 25 Feb 2017 11:16:16 -0800 Subject: [PATCH 054/151] meta: move WORKING_GROUPS.md to CTC repo PR-URL: https://github.com/nodejs/node/pull/11555 Ref: https://github.com/nodejs/CTC/pull/73 Reviewed-By: Gibson Fahnestock Reviewed-By: Ben Noordhuis --- README.md | 5 + WORKING_GROUPS.md | 281 ---------------------------------------------- 2 files changed, 5 insertions(+), 281 deletions(-) delete mode 100644 WORKING_GROUPS.md diff --git a/README.md b/README.md index 4be3c788d7dc32..225f0c648d0b91 100644 --- a/README.md +++ b/README.md @@ -395,6 +395,11 @@ Previous releases may also have been signed with one of the following GPG keys: * **Timothy J Fontaine** <tjfontaine@gmail.com> `7937DFD2AB06298B2293C3187D33FF9D0246406D` +### Working Groups + +Information on the current Node.js Working Groups can be found in the +[CTC repository](https://github.com/nodejs/CTC/blob/master/WORKING_GROUPS.md). + [npm]: https://www.npmjs.com [Website]: https://nodejs.org/en/ [Contributing to the project]: CONTRIBUTING.md diff --git a/WORKING_GROUPS.md b/WORKING_GROUPS.md deleted file mode 100644 index 6390946f5d1899..00000000000000 --- a/WORKING_GROUPS.md +++ /dev/null @@ -1,281 +0,0 @@ -# Node.js Core Working Groups - -Node.js Core Working Groups are autonomous projects created by the -[Core Technical Committee (CTC)](https://github.com/nodejs/node/blob/master/GOVERNANCE.md#core-technical-committee). - -Working Groups can be formed at any time but must be ratified by the CTC. -Once formed the work defined in the Working Group charter is the -responsibility of the WG rather than the CTC. - -It is important that Working Groups are not formed pre-maturely. Working -Groups are not formed to *begin* a set of tasks but instead are formed -once that work is already underway and the contributors -think it would benefit from being done as an autonomous project. - -If the work defined in a Working Group's charter is complete, the charter -should be revoked. - -A Working Group's charter can be revoked either by consensus of the Working -Group's members or by a CTC vote. Once revoked, any future work that arises -becomes the responsibility of the CTC. - -## Joining a WG - -To find out how to join a working group, consult the GOVERNANCE.md in -the working group's repository, or in the working group's repository. - -## Starting A Core Working Group - -The process to start a Core Working Group is identical to [creating a -Top Level Working Group](https://github.com/nodejs/TSC/blob/master/WORKING_GROUPS.md#starting-a-wg). - -## Current Working Groups - -* [Website](#website) -* [Streams](#streams) -* [Build](#build) -* [Diagnostics](#diagnostics) -* [i18n](#i18n) -* [Evangelism](#evangelism) -* [Docker](#docker) -* [Addon API](#addon-api) -* [Benchmarking](#benchmarking) -* [Post-mortem](#post-mortem) -* [Intl](#intl) -* [Documentation](#documentation) -* [Testing](#testing) - - -### [Website](https://github.com/nodejs/nodejs.org) - -The website Working Group's purpose is to build and maintain a public -website for the Node.js project. - -Responsibilities include: -* Developing and maintaining a build and automation system for nodejs.org. -* Ensuring the site is regularly updated with changes made to Node.js, like - releases and features. -* Fostering and enabling a community of translators. - -### [Streams](https://github.com/nodejs/readable-stream) - -The Streams Working Group is dedicated to the support and improvement of the -Streams API as used in Node.js and the npm ecosystem. We seek to create a -composable API that solves the problem of representing multiple occurrences -of an event over time in a humane, low-overhead fashion. Improvements to the -API will be driven by the needs of the ecosystem; interoperability and -backwards compatibility with other solutions and prior versions are paramount -in importance. - -Responsibilities include: -* Addressing stream issues on the Node.js issue tracker. -* Authoring and editing stream documentation within the Node.js project. -* Reviewing changes to stream subclasses within the Node.js project. -* Redirecting changes to streams from the Node.js project to this project. -* Assisting in the implementation of stream providers within Node.js. -* Recommending versions of `readable-stream` to be included in Node.js. -* Messaging about the future of streams to give the community advance notice of - changes. - -### [Build](https://github.com/nodejs/build) - -The Build Working Group's purpose is to create and maintain a distributed -automation infrastructure. - -Responsibilities include: -* Producing packages for all target platforms. -* Running tests. -* Running performance testing and comparisons. -* Creating and managing build-containers. - -### [Diagnostics](https://github.com/nodejs/diagnostics) - -The Diagnostics Working Group's purpose is to surface a set of comprehensive, -documented, and extensible diagnostic interfaces for use by Node.js tools and -JavaScript VMs. - -Responsibilities include: -* Collaborating with V8 to integrate `v8_inspector` into Node.js. -* Collaborating with V8 to integrate `trace_event` into Node.js. -* Collaborating with Core to refine `async_wrap` and `async_hooks`. -* Maintaining and improving OS trace system integration (e.g. ETW, LTTNG, dtrace). -* Documenting diagnostic capabilities and APIs in Node.js and its components. -* Exploring opportunities and gaps, discussing feature requests, and addressing - conflicts in Node.js diagnostics. -* Fostering an ecosystem of diagnostics tools for Node.js. - -### i18n - -The i18n Working Groups handle more than just translations. They -are endpoints for community members to collaborate with each -other in their language of choice. - -Each team is organized around a common spoken language. Each -language community might then produce multiple localizations for -various project resources. - -Responsibilities include: -* Translating any Node.js materials they believe are relevant to their - community. -* Reviewing processes for keeping translations up to date and of high quality. -* Managing and monitoring social media channels in their language. -* Promoting Node.js speakers for meetups and conferences in their language. - -Note that the i18n Working Groups are distinct from the [Intl](#Intl) Working Group. - -Each language community maintains its own membership. - -* [nodejs-ar - Arabic (اللغة العربية)](https://github.com/nodejs/nodejs-ar) -* [nodejs-bg - Bulgarian (български език)](https://github.com/nodejs/nodejs-bg) -* [nodejs-bn - Bengali (বাংলা)](https://github.com/nodejs/nodejs-bn) -* [nodejs-zh-CN - Chinese (中文)](https://github.com/nodejs/nodejs-zh-CN) -* [nodejs-cs - Czech (Český Jazyk)](https://github.com/nodejs/nodejs-cs) -* [nodejs-da - Danish (Dansk)](https://github.com/nodejs/nodejs-da) -* [nodejs-de - German (Deutsch)](https://github.com/nodejs/nodejs-de) -* [nodejs-el - Greek (Ελληνικά)](https://github.com/nodejs/nodejs-el) -* [nodejs-es - Spanish (Español)](https://github.com/nodejs/nodejs-es) -* [nodejs-fa - Persian (فارسی)](https://github.com/nodejs/nodejs-fa) -* [nodejs-fi - Finnish (Suomi)](https://github.com/nodejs/nodejs-fi) -* [nodejs-fr - French (Français)](https://github.com/nodejs/nodejs-fr) -* [nodejs-he - Hebrew (עברית)](https://github.com/nodejs/nodejs-he) -* [nodejs-hi - Hindi (फिजी बात)](https://github.com/nodejs/nodejs-hi) -* [nodejs-hu - Hungarian (Magyar)](https://github.com/nodejs/nodejs-hu) -* [nodejs-id - Indonesian (Bahasa Indonesia)](https://github.com/nodejs/nodejs-id) -* [nodejs-it - Italian (Italiano)](https://github.com/nodejs/nodejs-it) -* [nodejs-ja - Japanese (日本語)](https://github.com/nodejs/nodejs-ja) -* [nodejs-ka - Georgian (ქართული)](https://github.com/nodejs/nodejs-ka) -* [nodejs-ko - Korean (조선말)](https://github.com/nodejs/nodejs-ko) -* [nodejs-mk - Macedonian (Mакедонски)](https://github.com/nodejs/nodejs-mk) -* [nodejs-ms - Malay (بهاس ملايو)](https://github.com/nodejs/nodejs-ms) -* [nodejs-nl - Dutch (Nederlands)](https://github.com/nodejs/nodejs-nl) -* [nodejs-no - Norwegian (Norsk)](https://github.com/nodejs/nodejs-no) -* [nodejs-pl - Polish (Język Polski)](https://github.com/nodejs/nodejs-pl) -* [nodejs-pt - Portuguese (Português)](https://github.com/nodejs/nodejs-pt) -* [nodejs-ro - Romanian (Română)](https://github.com/nodejs/nodejs-ro) -* [nodejs-ru - Russian (Русский)](https://github.com/nodejs/nodejs-ru) -* [nodejs-sv - Swedish (Svenska)](https://github.com/nodejs/nodejs-sv) -* [nodejs-ta - Tamil (தமிழ்)](https://github.com/nodejs/nodejs-ta) -* [nodejs-tr - Turkish (Türkçe)](https://github.com/nodejs/nodejs-tr) -* [nodejs-zh-TW - Taiwanese (Hō-ló)](https://github.com/nodejs/nodejs-zh-TW) -* [nodejs-uk - Ukrainian (Українська)](https://github.com/nodejs/nodejs-uk) -* [nodejs-vi - Vietnamese (Tiếng Việtnam)](https://github.com/nodejs/nodejs-vi) - -### [Intl](https://github.com/nodejs/Intl) - -The Intl Working Group is dedicated to support and improvement of -Internationalization (i18n) and Localization (l10n) in Node. - -Responsibilities include: -* Ensuring functionality & compliance (standards: ECMA, Unicode…) -* Supporting Globalization and Internationalization issues that come up - in the tracker -* Communicating guidance and best practices -* Refining the existing `Intl` implementation - -The Intl Working Group is not responsible for translation of content. That is the -responsibility of the specific [i18n](#i18n) group for each language. - -### [Evangelism](https://github.com/nodejs/evangelism) - -The Evangelism Working Group promotes the accomplishments -of Node.js and lets the community know how they can get involved. - -Responsibilities include: -* Facilitating project messaging. -* Managing official project social media. -* Handling the promotion of speakers for meetups and conferences. -* Handling the promotion of community events. -* Publishing regular update summaries and other promotional - content. - -### [Docker](https://github.com/nodejs/docker-iojs) - -The Docker Working Group's purpose is to build, maintain, and improve official -Docker images for the Node.js project. - -Responsibilities include: -* Keeping the official Docker images updated in line with new Node.js releases. -* Decide and implement image improvements and/or fixes. -* Maintain and improve the images' documentation. - -### [Addon API](https://github.com/nodejs/nan) - -The Addon API Working Group is responsible for maintaining the NAN project and -corresponding _nan_ package in npm. The NAN project makes available an -abstraction layer for native add-on authors for Node.js, -assisting in the writing of code that is compatible with many actively used -versions of Node.js, V8 and libuv. - -Responsibilities include: -* Maintaining the [NAN](https://github.com/nodejs/nan) GitHub repository, - including code, issues and documentation. -* Maintaining the [addon-examples](https://github.com/nodejs/node-addon-examples) - GitHub repository, including code, issues and documentation. -* Maintaining the C++ Addon API within the Node.js project, in subordination to - the Node.js CTC. -* Maintaining the Addon documentation within the Node.js project, in - subordination to the Node.js CTC. -* Maintaining the _nan_ package in npm, releasing new versions as appropriate. -* Messaging about the future of the Node.js and NAN interface to give the - community advance notice of changes. - -The current members can be found in their -[README](https://github.com/nodejs/nan#collaborators). - -### [Benchmarking](https://github.com/nodejs/benchmarking) - -The purpose of the Benchmark Working Group is to gain consensus -on an agreed set of benchmarks that can be used to: - -* track and evangelize performance gains made between Node.js releases -* avoid performance regressions between releases - -Responsibilities include: -* Identifying 1 or more benchmarks that reflect customer usage. - Likely will need more than one to cover typical Node.js use cases - including low-latency and high concurrency -* Working to get community consensus on the list chosen -* Adding regular execution of chosen benchmarks to Node.js builds -* Tracking/publicizing performance between builds/releases - -### [Post-mortem](https://github.com/nodejs/post-mortem) - -The Post-mortem Diagnostics Working Group is dedicated to the support -and improvement of postmortem debugging for Node.js. It seeks to -elevate the role of postmortem debugging for Node, to assist in the -development of techniques and tools, and to make techniques and tools -known and available to Node.js users. - -Responsibilities include: -* Defining and adding interfaces/APIs in order to allow dumps - to be generated when needed. -* Defining and adding common structures to the dumps generated - in order to support tools that want to introspect those dumps. - -### [Documentation](https://github.com/nodejs/docs) - -The Documentation Working Group exists to support the improvement of Node.js -documentation, both in the core API documentation, and elsewhere, such as the -Node.js website. Its intent is to work closely with the Evangelism, Website, and -Intl Working Groups to make excellent documentation available and accessible -to all. - -Responsibilities include: -* Defining and maintaining documentation style and content standards. -* Producing documentation in a format acceptable for the Website Working Group - to consume. -* Ensuring that Node's documentation addresses a wide variety of audiences. -* Creating and operating a process for documentation review that produces - quality documentation and avoids impeding the progress of Core work. - -### [Testing](https://github.com/nodejs/testing) - -The Node.js Testing Working Group's purpose is to extend and improve testing of -the Node.js source code. - -Responsibilities include: -* Coordinating an overall strategy for improving testing. -* Documenting guidelines around tests. -* Working with the Build Working Group to improve continuous integration. -* Improving tooling for testing. - From 38588614631cc37431d49bafacf52bf5889d6f3f Mon Sep 17 00:00:00 2001 From: Michael Cox Date: Thu, 2 Mar 2017 15:58:26 -0500 Subject: [PATCH 055/151] tools: add links to the stability index reference This modifies the script that generates the docs to create a static link from each Stability Index callout bar to the Stability Index explanations in documentation.html. PR-URL: https://github.com/nodejs/node/pull/11664 Reviewed-By: Sakthipriyan Vairamani Reviewed-By: James M Snell Reviewed-By: Franziska Hinkelmann --- tools/doc/html.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tools/doc/html.js b/tools/doc/html.js index 3dd6f83da503df..f7c7b46c540e66 100644 --- a/tools/doc/html.js +++ b/tools/doc/html.js @@ -322,9 +322,12 @@ function linkJsTypeDocs(text) { } function parseAPIHeader(text) { + const classNames = 'api_stability api_stability_$2'; + const docsUrl = 'documentation.html#documentation_stability_index'; + text = text.replace( STABILITY_TEXT_REG_EXP, - '
$1 $2$3
' + `
$1 $2$3
` ); return text; } From 4befdd1c1311270ca56a89649bdef3c492f4a69c Mon Sep 17 00:00:00 2001 From: Rich Trott Date: Mon, 6 Mar 2017 15:54:55 -0800 Subject: [PATCH 056/151] test: limit lint rule disabling in message test MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit nexttick_throw.js has a comment that disables all ESLint rules for a line. Change it to only disable the one ESLint rule that the line violates. PR-URL: https://github.com/nodejs/node/pull/11724 Reviewed-By: Teddy Katz Reviewed-By: Michaël Zasso Reviewed-By: Luigi Pinca Reviewed-By: Colin Ihrig Reviewed-By: James M Snell Reviewed-By: Yuta Hiroto --- test/message/nexttick_throw.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/message/nexttick_throw.js b/test/message/nexttick_throw.js index 49cd6dd0f7cbd6..0c655a8e2e4bf1 100644 --- a/test/message/nexttick_throw.js +++ b/test/message/nexttick_throw.js @@ -5,7 +5,7 @@ process.nextTick(function() { process.nextTick(function() { process.nextTick(function() { process.nextTick(function() { - // eslint-disable-next-line + // eslint-disable-next-line no-undef undefined_reference_error_maker; }); }); From 5a93eab30d7b816674d92110ea41ad338805f7ad Mon Sep 17 00:00:00 2001 From: DavidCai Date: Thu, 2 Mar 2017 21:26:28 +0800 Subject: [PATCH 057/151] test: increase coverage of console PR-URL: https://github.com/nodejs/node/pull/11653 Reviewed-By: Claudio Rodriguez Reviewed-By: Michael Dawson Reviewed-By: Sakthipriyan Vairamani Reviewed-By: James M Snell Reviewed-By: Yuta Hiroto Reviewed-By: Colin Ihrig Reviewed-By: Franziska Hinkelmann --- test/parallel/test-console-instance.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/test/parallel/test-console-instance.js b/test/parallel/test-console-instance.js index 328adfde0ed803..6b049f09b7d9e9 100644 --- a/test/parallel/test-console-instance.js +++ b/test/parallel/test-console-instance.js @@ -57,3 +57,13 @@ out.write = common.mustCall((d) => { assert.doesNotThrow(() => { Console(out, err); }); + +// Instance that does not ignore the stream errors. +const c2 = new Console(out, err, false); + +out.write = () => { throw new Error('out'); }; +err.write = () => { throw new Error('err'); }; + +assert.throws(() => c2.log('foo'), /^Error: out$/); +assert.throws(() => c2.warn('foo'), /^Error: err$/); +assert.throws(() => c2.dir('foo'), /^Error: out$/); From aa9815081d6374f7380bdbd6e8998a044f37d033 Mon Sep 17 00:00:00 2001 From: Shigeki Ohtsu Date: Mon, 27 Feb 2017 18:50:59 +0900 Subject: [PATCH 058/151] test: add script to create 0-dns-cert.pem 0-dns-cert.pem and 0-dns-key.pem were stored in `test/fixtures/key` directory, but the cert file cannot be created with the openssl command via Makefile. Added a script to create it with using `asn1.js` and `asn1.js-rfc5280` and moved them out of key directory and put into `test/fixtures/0-dns`. The domains listed in the cert were also changed into example.com and example.org to show the use for only testing. Fixes: https://github.com/nodejs/node/issues/10228 PR-URL: https://github.com/nodejs/node/pull/11579 Reviewed-By: James M Snell Reviewed-By: Sam Roberts --- test/fixtures/0-dns/0-dns-cert.pem | 19 ++++++ test/fixtures/0-dns/0-dns-key.pem | 27 +++++++++ test/fixtures/0-dns/0-dns-rsapub.der | Bin 0 -> 270 bytes test/fixtures/0-dns/README.md | 26 ++++++++ test/fixtures/0-dns/create-cert.js | 75 ++++++++++++++++++++++++ test/fixtures/0-dns/package.json | 16 +++++ test/fixtures/keys/0-dns-cert.pem | 19 ------ test/fixtures/keys/0-dns-key.pem | 27 --------- test/parallel/test-tls-0-dns-altname.js | 12 ++-- 9 files changed, 170 insertions(+), 51 deletions(-) create mode 100644 test/fixtures/0-dns/0-dns-cert.pem create mode 100644 test/fixtures/0-dns/0-dns-key.pem create mode 100644 test/fixtures/0-dns/0-dns-rsapub.der create mode 100644 test/fixtures/0-dns/README.md create mode 100644 test/fixtures/0-dns/create-cert.js create mode 100644 test/fixtures/0-dns/package.json delete mode 100644 test/fixtures/keys/0-dns-cert.pem delete mode 100644 test/fixtures/keys/0-dns-key.pem diff --git a/test/fixtures/0-dns/0-dns-cert.pem b/test/fixtures/0-dns/0-dns-cert.pem new file mode 100644 index 00000000000000..03a4db3e2d8501 --- /dev/null +++ b/test/fixtures/0-dns/0-dns-cert.pem @@ -0,0 +1,19 @@ +-----BEGIN CERTIFICATE----- +MIIDGDCCAgCgAwIBAgIBATANBgkqhkiG9w0BAQsFADAZMRcwFQYDVQQDEw5jYS5l +eGFtcGxlLmNvbTAeFw0xNzAzMDIwMTMxMjJaFw0yNzAyMjgwMTMxMjJaMBsxGTAX +BgNVBAMTEGV2aWwuZXhhbXBsZS5jb20wggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAw +ggEKAoIBAQDFyJT0kv2P9L6iNY6TL7IZonAR8R9ev7iD1tR5ycMEpM/y6WTefIco +civMcBGVZWtCgkoePHiveH9UIep7HFGB4gxCYDZFYB46yGS0YH2fB5GWXTLYObYa +zxuEhgFRG0DLIwNDRLW0+0FG3disp7YdRHBtdbL58F/qNORqPEjIpoQxOJc2UqX2 +/gfomJRdFW/PSgN7uH2QwMzRQRIrKmyAFzeuEWVP+UAV4853Yg66PmYpAASyt069 +sE8QNTNE75KrerMmYzH7AmTEGvY8bukrDuVQZce2/lcK2rAE+G6at2eBNMZKOnzR +y9kWIiJ3rR7+WK55EKelLz0doZFKteu1AgMBAAGjaTBnMGUGA1UdEQReMFyCImdv +b2QuZXhhbXBsZS5vcmcALmV2aWwuZXhhbXBsZS5jb22CGGp1c3QtYW5vdGhlci5l +eGFtcGxlLmNvbYcECAgICIcECAgEBIIQbGFzdC5leGFtcGxlLmNvbTANBgkqhkiG +9w0BAQsFAAOCAQEAvreVoOZO2gpM4Dmzp70D30XZjsK9i0BCsRHBvPLPw3y8B2xg +BRtOREOI69NU0WGpj5Lbqww5M8M1hjHshiGEu2aXfZ6qM3lENaIMCpKlF9jbm02/ +wmxNaAnS8bDSZyO5rbsGr2tJb4ds7DazmMEKWhOBEpJoOp9rG6SAey+a6MkZ7NEN +0p3THCqNf3lL1KblPrMvdsyhHPEzv4uT7+YAnLKHwGzbihcWJRsRo5oipWL8ZDhn +bd3SMWtfRTSWDmghJaHke2xIjDtTwSjHjjPTFsK+rl227W8r4/EQI/X6fTQV2j3T +7zqrJLF9h9F/v3mo57k6sxsQNZ12XvhuTHC2dA== +-----END CERTIFICATE----- diff --git a/test/fixtures/0-dns/0-dns-key.pem b/test/fixtures/0-dns/0-dns-key.pem new file mode 100644 index 00000000000000..4e2fdb5fc61e0e --- /dev/null +++ b/test/fixtures/0-dns/0-dns-key.pem @@ -0,0 +1,27 @@ +-----BEGIN RSA PRIVATE KEY----- +MIIEowIBAAKCAQEAxciU9JL9j/S+ojWOky+yGaJwEfEfXr+4g9bUecnDBKTP8ulk +3nyHKHIrzHARlWVrQoJKHjx4r3h/VCHqexxRgeIMQmA2RWAeOshktGB9nweRll0y +2Dm2Gs8bhIYBURtAyyMDQ0S1tPtBRt3YrKe2HURwbXWy+fBf6jTkajxIyKaEMTiX +NlKl9v4H6JiUXRVvz0oDe7h9kMDM0UESKypsgBc3rhFlT/lAFePOd2IOuj5mKQAE +srdOvbBPEDUzRO+Sq3qzJmMx+wJkxBr2PG7pKw7lUGXHtv5XCtqwBPhumrdngTTG +Sjp80cvZFiIid60e/liueRCnpS89HaGRSrXrtQIDAQABAoIBABcGA3j5B3VTi0F8 +tI0jtzrOsvcTt5AjB0qpnnBS8VXADcj8LFbN7jniGIEi5pkahkLmwdQFPBNJFqFn +lVEheceB1eWAJ7EpwDsdisOIm/cAPY1gagPLrAww4cYqh0q2vnMnL0EMZY6c1Pt3 +5borh8KebewAEIaR2ch8wb4wKFTbAM0DftYBFzHAF88OeCuIpdsk2Tz0sVQbA3/1 +XNLOVcJvDOVIRPEpo2l7RIN33KvDhzpMoV3qVzWxqdccPRZZFU5KmJ6DtouIPT3S +3WauIL5oVpAyYNJETTyxjBQE4DgFeNX1Wyycgk27EoLcn6Trcs0kNVrmXXblNAtJ +Nko6g10CgYEA+TjzNjyAXPrOpY88uiPVMAgepEQOnDYtMwasdDVaW3xK9KH1rrhU +dx1IDTMmOUfyU2qsj5txmJtReQz//1bpd7e73VO8mHQDUubhs2TivgGs+fqzAdmT +vJsjerfNsxf+4JENzzWmqT/Ybc976Tu55VH5mcRG9Q66fTxdAJ51+8MCgYEAyymF +gntRMBd9e/KIiqlvcxelo0ahyKEzaJC7/FkZotuSB+kAwpdJ5Unb0FeVQZxNhDPg +xgsrGOOOvHvfhv7DPU0TQ/vp6VDPdg+N6m/Ow2vr79A2v6s+7gZj3MLiLRFyEF6l +bxQNGe3qavnm3owUQQCY2RLBKYCFfv/cykYlGycCgYB6etKMRQ+QonIMS2i80f9j +q5njgM7tVnLAMPdv5QiTDXKI50+mnlBkea9/TTPr0r/03ugPa4VYSnyv0QO+qSfz +/ggFrbFx+xHnHDCvyVTlrE0mTV7L+fHxLw0wskQVUCWil6cBvow5gXcMAHwVE5U4 +biEMwLlele5wvcm3FClHoQKBgACV/RGUQ3atCqqZ13T26iBd2Bdxc7P9awWJLVGb +/CvxECm/rUXiY88qeFzQc9i9l6ei8qn/jD9FILtAbDOadnutxjly94i5t+9yOgmM +Cv+bRxHo+s9wsfzDvfP8B+TzYO3VKAr69tK1UfC/CcBojQJm+wndOPtiqH/mQv++ +VgsPAoGBAJ0aNJe3zb+blvAQ3W4iPSjhyxdMC00x46pr6ds+Y8WygbN6lzCvNDw6 +FFTINBckOs5Z/UWUNbExWYjBHZhLlhhxTezCzvIrwNvgUB8Y4sPk3S4KDsnkyy6f +/qMmEHlVyKjh2BCNs7PVnWDlfl3vECE7n8dBizFHgja76l1ia+0z +-----END RSA PRIVATE KEY----- diff --git a/test/fixtures/0-dns/0-dns-rsapub.der b/test/fixtures/0-dns/0-dns-rsapub.der new file mode 100644 index 0000000000000000000000000000000000000000..263a4b8293dd0ef752e74ae4b459bed5b0a88fca GIT binary patch literal 270 zcmV+p0rCDYf&mHwf&l>l#mJQOlKqeLzM?gblP|IvqHq!MA6~z>gVxk}$-@Ms&+_SH z-h78Bax2Vm5tU_YLV`*jJb15oe^eprdmK@L;tWDyHbr0_I>=0Z|)3%Oe9rM76a0K}Ox!tf#geL~w0&via~|>NMnPJV?llFXMr@vN;-Ve%h?tpB6qDG{#dSg U5T~UtJsqKuO10~?0s{d60X%Gbh5!Hn literal 0 HcmV?d00001 diff --git a/test/fixtures/0-dns/README.md b/test/fixtures/0-dns/README.md new file mode 100644 index 00000000000000..650970a2c5a5cf --- /dev/null +++ b/test/fixtures/0-dns/README.md @@ -0,0 +1,26 @@ +## Purpose +The test cert file for use `test/parallel/test-tls-0-dns-altname.js` +can be created by using `asn1.js` and `asn1.js-rfc5280`, + +## How to create a test cert. + +```sh +$ openssl genrsa -out 0-dns-key.pem 2048 +Generating RSA private key, 2048 bit long modulus +...................+++ +..............................................................................................+++ +e is 65537 (0x10001) +$ openssl rsa -in 0-dns-key.pem -RSAPublicKey_out -outform der -out 0-dns-rsapub.der +writing RSA key +$ npm install +0-dns@1.0.0 /home/github/node/test/fixtures/0-dns ++-- asn1.js@4.9.1 +| +-- bn.js@4.11.6 +| +-- inherits@2.0.3 +| `-- minimalistic-assert@1.0.0 +`-- asn1.js-rfc5280@1.2.2 + +$ node ./createCert.js +$ openssl x509 -text -in 0-dns-cert.pem +(You can not see evil.example.com in subjectAltName field) +``` diff --git a/test/fixtures/0-dns/create-cert.js b/test/fixtures/0-dns/create-cert.js new file mode 100644 index 00000000000000..7a353906e4bbec --- /dev/null +++ b/test/fixtures/0-dns/create-cert.js @@ -0,0 +1,75 @@ +'use strict'; +const asn1 = require('asn1.js'); +const crypto = require('crypto'); +const fs = require('fs'); +const rfc5280 = require('asn1.js-rfc5280'); +const BN = asn1.bignum; + +const id_at_commonName = [ 2, 5, 4, 3 ]; +const rsaEncryption = [1, 2, 840, 113549, 1, 1, 1]; +const sha256WithRSAEncryption = [1, 2, 840, 113549, 1, 1, 11]; +const sigalg = 'RSA-SHA256'; + +const private_key = fs.readFileSync('./0-dns-key.pem'); +// public key file can be generated from the private key with +// openssl rsa -in 0-dns-key.pem -RSAPublicKey_out -outform der +// -out 0-dns-rsapub.der +const public_key = fs.readFileSync('./0-dns-rsapub.der'); + +const now = Date.now(); +const days = 3650; + +const Null_ = asn1.define('Null_', function() { + this.null_(); +}); +const null_ = Null_.encode('der'); + +const PrintStr = asn1.define('PrintStr', function() { + this.printstr(); +}); +const issuer = PrintStr.encode('ca.example.com', 'der'); +const subject = PrintStr.encode('evil.example.com', 'der'); + +const tbs = { + version: 'v3', + serialNumber: new BN('01', 16), + signature: { algorithm: sha256WithRSAEncryption, parameters: null_}, + issuer: { type: 'rdnSequence', + value: [ [{type: id_at_commonName, value: issuer}] ] }, + validity: + { notBefore: { type: 'utcTime', value: now }, + notAfter: { type: 'utcTime', value: now + days * 86400000} }, + subject: { type: 'rdnSequence', + value: [ [{type: id_at_commonName, value: subject}] ] }, + subjectPublicKeyInfo: + { algorithm: { algorithm: rsaEncryption, parameters: null_}, + subjectPublicKey: { unused: 0, data: public_key} }, + extensions: + [ { extnID: 'subjectAlternativeName', + critical: false, + // subjectAltName which contains '\0' character to check CVE-2009-2408 + extnValue: [ + { type: 'dNSName', value: 'good.example.org\u0000.evil.example.com' }, + { type: 'dNSName', value: 'just-another.example.com' }, + { type: 'iPAddress', value: Buffer.from('08080808', 'hex') }, + { type: 'iPAddress', value: Buffer.from('08080404', 'hex') }, + { type: 'dNSName', value: 'last.example.com' } ] } + ] +}; + +const tbs_der = rfc5280.TBSCertificate.encode(tbs, 'der'); + +const sign = crypto.createSign(sigalg); +sign.update(tbs_der); +const signature = sign.sign(private_key); + +const cert = { + tbsCertificate: tbs, + signatureAlgorithm: { algorithm: sha256WithRSAEncryption, parameters: null_ }, + signature: + { unused: 0, + data: signature } +}; +const pem = rfc5280.Certificate.encode(cert, 'pem', {label: 'CERTIFICATE'}); + +fs.writeFileSync('./0-dns-cert.pem', pem + '\n'); diff --git a/test/fixtures/0-dns/package.json b/test/fixtures/0-dns/package.json new file mode 100644 index 00000000000000..667600c7d08521 --- /dev/null +++ b/test/fixtures/0-dns/package.json @@ -0,0 +1,16 @@ +{ + "name": "0-dns", + "version": "1.0.0", + "description": "create certificate for 0-dns test", + "main": "createCert.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "author": "", + "license": "SEE LICENSE IN ../../../LICENSE", + "private": true, + "dependencies": { + "asn1.js": "^4.9.1", + "asn1.js-rfc5280": "^1.2.2" + } +} diff --git a/test/fixtures/keys/0-dns-cert.pem b/test/fixtures/keys/0-dns-cert.pem deleted file mode 100644 index 6cfc6c43c460d7..00000000000000 --- a/test/fixtures/keys/0-dns-cert.pem +++ /dev/null @@ -1,19 +0,0 @@ ------BEGIN CERTIFICATE----- -MIIC/zCCAemgAwIBAgICJxEwCwYJKoZIhvcNAQEFMBUxEzARBgNVBAMWCm9oLm15 -Lmdvc2gwHhcNMTQxMjA4MTM0MTUzWhcNMzQxMjAzMTM0MTUzWjATMREwDwYDVQQD -FghldmlsLmNvbTCCASAwCwYJKoZIhvcNAQEBA4IBDwAwggEKAoIBAQCsFwwf1dsr -PdxyTHBreymbFGACLQtaOihGsSkYtIzUEF1aT90YDMzNdoLr4wkwWig5FPRMnjmX -7pXY9RVbWmwG/M2eku9S62LekUFkeY1W/QftV9LYgAg7wVDA+v3+zk/EMEqADYm6 -W735tzDIKtvx+/3Dd9puQ0TLFNHBxAmTz7YNaJdIUqzs3DWT4zeZQj0RCOyWCjQL -NfqQ80I7NYFYb4IJqiUY8iOTL5kPi7b5szem5EakQbhufDWun4xGTZk/URZHgYgp -REbOLTYs2hqbK76biW/Yvwd1l7RsptIvJvkuQ1R/dO1WPv6PLKLTuS1EOHM3YqNH -o7wDSplOJe5rAgMBAAGhCQMHADEyMzQ1NqIJAwcANzg5YWJjo0swSTBHBgNVHREE -QDA+ghRnb29nbGUuY29tAC5ldmlsLmNvbYIQanVzdC1hbm90aGVyLmNvbYcECAgI -CIcECAgEBIIIbGFzdC5jb20wCwYJKoZIhvcNAQEBA4IBAQBAC2n4CIXLnyONTjPc -qU0wu41wI+IQlb9mi0C7WEd9HumCbskahAp8vTs35DehnSxrl15FG0rABVtTROCv -eflBKuzwPjtnfZm37UIbQKQUtcxwMQ/zvA83w4GLrLvrFtaQRpXn/RtL/q4CIpQH -MGaPW1Gs24RVBHxI7OXf9UlUruB1yQLUbbtdBtxZ6pk/B32e3yWowbvG7OxuUL0F -1w4DD2m+GfbTyZSCfYKP/zMp3xhTxihVfZ2g07ufc51bNCftWKBLHM/QHJmn4pVo -rrz1vS9nMf/i16zrJ8Xmj61Eo4Aes37lAH5kUiT1VsNxSDcQCiqr1mcj6ByXKNCQ -wDzO ------END CERTIFICATE----- diff --git a/test/fixtures/keys/0-dns-key.pem b/test/fixtures/keys/0-dns-key.pem deleted file mode 100644 index d292789554d798..00000000000000 --- a/test/fixtures/keys/0-dns-key.pem +++ /dev/null @@ -1,27 +0,0 @@ ------BEGIN RSA PRIVATE KEY----- -MIIEowIBAAKCAQEArBcMH9XbKz3cckxwa3spmxRgAi0LWjooRrEpGLSM1BBdWk/d -GAzMzXaC6+MJMFooORT0TJ45l+6V2PUVW1psBvzNnpLvUuti3pFBZHmNVv0H7VfS -2IAIO8FQwPr9/s5PxDBKgA2Julu9+bcwyCrb8fv9w3fabkNEyxTRwcQJk8+2DWiX -SFKs7Nw1k+M3mUI9EQjslgo0CzX6kPNCOzWBWG+CCaolGPIjky+ZD4u2+bM3puRG -pEG4bnw1rp+MRk2ZP1EWR4GIKURGzi02LNoamyu+m4lv2L8HdZe0bKbSLyb5LkNU -f3TtVj7+jyyi07ktRDhzN2KjR6O8A0qZTiXuawIDAQABAoIBABUlW9sJlz3QAyeU -VvgOEUW6EjYSPOPgY5SULl2XyfpA7IetapiK8huJJXtA0Z88ZNbmyUIk6yTNL2KS -cwZfrQiKxeVnXrsMq4B3ztY+zWxT+UZj1Ue/K8PT9E1SSiWmSkzsNitX/oWEwmpN -5VOjWJV6hmsfbhrAb1KZA1FQ+nBMEQrkEFpmFD1nJE8dH5rWNo4YbM/boR/kC93G -CHOwd2TKNrBa8ZeMOjcyUK9fg15CMkj7uTzfIGkjCM/mXOxvsvTuZ0np7PL7aF+o -GfSHP/l+B5rxT1GTYjZtpSEgAoqYEFJnnZELklo7KRWB7p2rgyHPElSjQN3xIn5Z -apNPrBECgYEA26gZGBP+j1Hqrh3nAhOq/t6PMj+V8yz/i2TrraJ1z7GKRGoBUOX9 -ruJGJExfACzgrKl1hL4XRfLdHuooScUqrIxLX7eKHE2nBSd0M40zEKbgIMRhaMsf -lAFOkxJRHMT7edaVu3MkSfDgFXRbhr+jcdxspzhunHMJVUnC5LgAKHMCgYEAyJAw -6GF80Uud5oDHo2tGY9uYgMIUN9rmrrFjqstkVB6QMFlyyeI3MHUhiU7qH53yaRCi -FxuHU6usQFmduwZAKInoPMRhYTYbexe4CYB+C96trwoV7ltDE+a7ZTsEj5kSYvCO -KLcVTn4mcU0TSpE0MU1XQKP0Ev/mdZ5aYEopvCkCgYEAlkVa3YkYNq5g8btNRbN0 -4SYbKtIrYJChRpjFTyV8mZkpMYKf4dtmANWWDNEekP0iu5y25BgzzcvHkJW6+DTl -6+OS0Sm8V36cS79hFL99dt/jJyeSSGHl+ZgnTCBU02zDaefuya2M3vTmKGdREk9a -ntOglYnayjc85Fcw+M4UdZcCgYAFw/9j7smDysSzR6h1jjPr0vhDW1Dxeh1/kCHp -Wwd7U5WZjji6jQJBJlzccaRRXF0HoC7Is0Xkpd7BytG5+qgFglFmzc5u2PtZQolL -3KHC/ZfInGWdAIqhG9TvSA8Ngb0BkyDDEuBN7Vp1j12qmxoBANQtS4lMsoaRgwfe -FMO2YQKBgGv6Ndv+eHWSkqGFOSXU6dXAjOuAji3K1yRlxUg/RS/DCMK+8XQbuh47 -+p998LwvI70JIr4v2PAkO3/HaRILOTRLLvq8O/yqHwrVf+P7AQ8kPm7uUf7kTXat -DYcKIAp5ddZweyFCgwVm+JMd1E+cpL97RbHCbu7Ct6OD9uLGXCUh ------END RSA PRIVATE KEY----- diff --git a/test/parallel/test-tls-0-dns-altname.js b/test/parallel/test-tls-0-dns-altname.js index 874dc6b235d644..483d256564accd 100644 --- a/test/parallel/test-tls-0-dns-altname.js +++ b/test/parallel/test-tls-0-dns-altname.js @@ -2,6 +2,8 @@ const common = require('../common'); const assert = require('assert'); +// Check getPeerCertificate can properly handle '\0' for fix CVE-2009-2408. + if (!common.hasCrypto) { common.skip('missing crypto'); return; @@ -11,8 +13,8 @@ const tls = require('tls'); const fs = require('fs'); const server = tls.createServer({ - key: fs.readFileSync(common.fixturesDir + '/keys/0-dns-key.pem'), - cert: fs.readFileSync(common.fixturesDir + '/keys/0-dns-cert.pem') + key: fs.readFileSync(common.fixturesDir + '/0-dns/0-dns-key.pem'), + cert: fs.readFileSync(common.fixturesDir + '/0-dns/0-dns-cert.pem') }, function(c) { c.once('data', function() { c.destroy(); @@ -24,11 +26,11 @@ const server = tls.createServer({ }, common.mustCall(function() { const cert = c.getPeerCertificate(); assert.strictEqual(cert.subjectaltname, - 'DNS:google.com\0.evil.com, ' + - 'DNS:just-another.com, ' + + 'DNS:good.example.org\0.evil.example.com, ' + + 'DNS:just-another.example.com, ' + 'IP Address:8.8.8.8, ' + 'IP Address:8.8.4.4, ' + - 'DNS:last.com'); + 'DNS:last.example.com'); c.write('ok'); })); })); From 67b6d7d123e6b110cf73b01013c2154a4e281b88 Mon Sep 17 00:00:00 2001 From: Richard Lau Date: Thu, 20 Oct 2016 15:38:54 -0400 Subject: [PATCH 059/151] test: add test for loading from global folders MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Test executes with a copy of the node executable since $PREFIX/lib/node is relative to the executable location. PR-URL: https://github.com/nodejs/node/pull/9283 Reviewed-By: Sam Roberts Reviewed-By: Gibson Fahnestock Reviewed-By: João Reis Reviewed-By: Ben Noordhuis --- .../home-pkg-in-both/.node_libraries/foo.js | 1 + .../home-pkg-in-both/.node_modules/foo.js | 1 + .../.node_libraries/foo.js | 1 + .../.node_modules/foo.js | 1 + .../local-pkg/node_modules/foo.js | 1 + .../local-pkg/test.js | 2 + .../node_path/foo.js | 1 + .../test-module-loading-globalpaths.js | 101 ++++++++++++++++++ 8 files changed, 109 insertions(+) create mode 100644 test/fixtures/test-module-loading-globalpaths/home-pkg-in-both/.node_libraries/foo.js create mode 100644 test/fixtures/test-module-loading-globalpaths/home-pkg-in-both/.node_modules/foo.js create mode 100644 test/fixtures/test-module-loading-globalpaths/home-pkg-in-node_libraries/.node_libraries/foo.js create mode 100644 test/fixtures/test-module-loading-globalpaths/home-pkg-in-node_modules/.node_modules/foo.js create mode 100644 test/fixtures/test-module-loading-globalpaths/local-pkg/node_modules/foo.js create mode 100644 test/fixtures/test-module-loading-globalpaths/local-pkg/test.js create mode 100644 test/fixtures/test-module-loading-globalpaths/node_path/foo.js create mode 100644 test/parallel/test-module-loading-globalpaths.js diff --git a/test/fixtures/test-module-loading-globalpaths/home-pkg-in-both/.node_libraries/foo.js b/test/fixtures/test-module-loading-globalpaths/home-pkg-in-both/.node_libraries/foo.js new file mode 100644 index 00000000000000..eb278f95762215 --- /dev/null +++ b/test/fixtures/test-module-loading-globalpaths/home-pkg-in-both/.node_libraries/foo.js @@ -0,0 +1 @@ +exports.string = '$HOME/.node_libraries'; diff --git a/test/fixtures/test-module-loading-globalpaths/home-pkg-in-both/.node_modules/foo.js b/test/fixtures/test-module-loading-globalpaths/home-pkg-in-both/.node_modules/foo.js new file mode 100644 index 00000000000000..8a665b3e98cfe2 --- /dev/null +++ b/test/fixtures/test-module-loading-globalpaths/home-pkg-in-both/.node_modules/foo.js @@ -0,0 +1 @@ +exports.string = '$HOME/.node_modules'; diff --git a/test/fixtures/test-module-loading-globalpaths/home-pkg-in-node_libraries/.node_libraries/foo.js b/test/fixtures/test-module-loading-globalpaths/home-pkg-in-node_libraries/.node_libraries/foo.js new file mode 100644 index 00000000000000..eb278f95762215 --- /dev/null +++ b/test/fixtures/test-module-loading-globalpaths/home-pkg-in-node_libraries/.node_libraries/foo.js @@ -0,0 +1 @@ +exports.string = '$HOME/.node_libraries'; diff --git a/test/fixtures/test-module-loading-globalpaths/home-pkg-in-node_modules/.node_modules/foo.js b/test/fixtures/test-module-loading-globalpaths/home-pkg-in-node_modules/.node_modules/foo.js new file mode 100644 index 00000000000000..8a665b3e98cfe2 --- /dev/null +++ b/test/fixtures/test-module-loading-globalpaths/home-pkg-in-node_modules/.node_modules/foo.js @@ -0,0 +1 @@ +exports.string = '$HOME/.node_modules'; diff --git a/test/fixtures/test-module-loading-globalpaths/local-pkg/node_modules/foo.js b/test/fixtures/test-module-loading-globalpaths/local-pkg/node_modules/foo.js new file mode 100644 index 00000000000000..63e844e4d4060b --- /dev/null +++ b/test/fixtures/test-module-loading-globalpaths/local-pkg/node_modules/foo.js @@ -0,0 +1 @@ +exports.string = 'local'; diff --git a/test/fixtures/test-module-loading-globalpaths/local-pkg/test.js b/test/fixtures/test-module-loading-globalpaths/local-pkg/test.js new file mode 100644 index 00000000000000..8054983e992ce8 --- /dev/null +++ b/test/fixtures/test-module-loading-globalpaths/local-pkg/test.js @@ -0,0 +1,2 @@ +'use strict'; +console.log(require('foo').string); diff --git a/test/fixtures/test-module-loading-globalpaths/node_path/foo.js b/test/fixtures/test-module-loading-globalpaths/node_path/foo.js new file mode 100644 index 00000000000000..3ce43c49206f73 --- /dev/null +++ b/test/fixtures/test-module-loading-globalpaths/node_path/foo.js @@ -0,0 +1 @@ +exports.string = '$NODE_PATH'; diff --git a/test/parallel/test-module-loading-globalpaths.js b/test/parallel/test-module-loading-globalpaths.js new file mode 100644 index 00000000000000..d789f5409901ba --- /dev/null +++ b/test/parallel/test-module-loading-globalpaths.js @@ -0,0 +1,101 @@ +'use strict'; +const common = require('../common'); +const assert = require('assert'); +const path = require('path'); +const fs = require('fs'); +const child_process = require('child_process'); +const pkgName = 'foo'; + +if (process.argv[2] === 'child') { + console.log(require(pkgName).string); +} else { + common.refreshTmpDir(); + + // Copy node binary into a test $PREFIX directory. + const prefixPath = path.join(common.tmpDir, 'install'); + fs.mkdirSync(prefixPath); + let testExecPath; + if (common.isWindows) { + testExecPath = path.join(prefixPath, path.basename(process.execPath)); + } else { + const prefixBinPath = path.join(prefixPath, 'bin'); + fs.mkdirSync(prefixBinPath); + testExecPath = path.join(prefixBinPath, path.basename(process.execPath)); + } + const mode = fs.statSync(process.execPath).mode; + fs.writeFileSync(testExecPath, fs.readFileSync(process.execPath)); + fs.chmodSync(testExecPath, mode); + + const runTest = (expectedString, env) => { + const child = child_process.execFileSync(testExecPath, + [ __filename, 'child' ], + { encoding: 'utf8', env: env }); + assert.strictEqual(child.trim(), expectedString); + }; + + const testFixturesDir = path.join(common.fixturesDir, + path.basename(__filename, '.js')); + + const env = Object.assign({}, process.env); + // Turn on module debug to aid diagnosing failures. + env['NODE_DEBUG'] = 'module'; + // Unset NODE_PATH. + delete env['NODE_PATH']; + + // Test empty global path. + const noPkgHomeDir = path.join(common.tmpDir, 'home-no-pkg'); + fs.mkdirSync(noPkgHomeDir); + env['HOME'] = env['USERPROFILE'] = noPkgHomeDir; + assert.throws( + () => { + child_process.execFileSync(testExecPath, [ __filename, 'child' ], + { encoding: 'utf8', env: env }); + }, + new RegExp('Cannot find module \'' + pkgName + '\'')); + + // Test module in $HOME/.node_modules. + const modHomeDir = path.join(testFixturesDir, 'home-pkg-in-node_modules'); + env['HOME'] = env['USERPROFILE'] = modHomeDir; + runTest('$HOME/.node_modules', env); + + // Test module in $HOME/.node_libraries. + const libHomeDir = path.join(testFixturesDir, 'home-pkg-in-node_libraries'); + env['HOME'] = env['USERPROFILE'] = libHomeDir; + runTest('$HOME/.node_libraries', env); + + // Test module both $HOME/.node_modules and $HOME/.node_libraries. + const bothHomeDir = path.join(testFixturesDir, 'home-pkg-in-both'); + env['HOME'] = env['USERPROFILE'] = bothHomeDir; + runTest('$HOME/.node_modules', env); + + // Test module in $PREFIX/lib/node. + // Write module into $PREFIX/lib/node. + const expectedString = '$PREFIX/lib/node'; + const prefixLibPath = path.join(prefixPath, 'lib'); + fs.mkdirSync(prefixLibPath); + const prefixLibNodePath = path.join(prefixLibPath, 'node'); + fs.mkdirSync(prefixLibNodePath); + const pkgPath = path.join(prefixLibNodePath, pkgName + '.js'); + fs.writeFileSync(pkgPath, 'exports.string = \'' + expectedString + '\';'); + + env['HOME'] = env['USERPROFILE'] = noPkgHomeDir; + runTest(expectedString, env); + + // Test module in all global folders. + env['HOME'] = env['USERPROFILE'] = bothHomeDir; + runTest('$HOME/.node_modules', env); + + // Test module in NODE_PATH is loaded ahead of global folders. + env['HOME'] = env['USERPROFILE'] = bothHomeDir; + env['NODE_PATH'] = path.join(testFixturesDir, 'node_path'); + runTest('$NODE_PATH', env); + + // Test module in local folder is loaded ahead of global folders. + const localDir = path.join(testFixturesDir, 'local-pkg'); + env['HOME'] = env['USERPROFILE'] = bothHomeDir; + env['NODE_PATH'] = path.join(testFixturesDir, 'node_path'); + const child = child_process.execFileSync(testExecPath, + [ path.join(localDir, 'test.js') ], + { encoding: 'utf8', env: env }); + assert.strictEqual(child.trim(), 'local'); +} From 500d17b07198b9e042f9898e650a34b890de70a0 Mon Sep 17 00:00:00 2001 From: Richard Lau Date: Tue, 25 Oct 2016 23:58:06 +0100 Subject: [PATCH 060/151] module: fix loading from global folders on Windows MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Code was calculating $PREFIX/lib/node relative to process.execPath, but on Windows process.execPath is $PREFIX\node.exe whereas everywhere else process.execPath is $PREFIX/bin/node (where $PREFIX is the root of the installed Node.js). PR-URL: https://github.com/nodejs/node/pull/9283 Reviewed-By: Sam Roberts Reviewed-By: Gibson Fahnestock Reviewed-By: João Reis Reviewed-By: Ben Noordhuis --- lib/module.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/module.js b/lib/module.js index f0d149723d8a6c..ea7d61325772f0 100644 --- a/lib/module.js +++ b/lib/module.js @@ -616,7 +616,16 @@ Module._initPaths = function() { homeDir = process.env.HOME; } - var paths = [path.resolve(process.execPath, '..', '..', 'lib', 'node')]; + // $PREFIX/lib/node, where $PREFIX is the root of the Node.js installation. + var prefixDir; + // process.execPath is $PREFIX/bin/node except on Windows where it is + // $PREFIX\node.exe. + if (isWindows) { + prefixDir = path.resolve(process.execPath, '..'); + } else { + prefixDir = path.resolve(process.execPath, '..', '..'); + } + var paths = [path.resolve(prefixDir, 'lib', 'node')]; if (homeDir) { paths.unshift(path.resolve(homeDir, '.node_libraries')); From 12760339dcbc33a848cf6bc33e44d6b8bd0fdd2d Mon Sep 17 00:00:00 2001 From: Rod Vagg Date: Wed, 22 Feb 2017 11:32:38 +1100 Subject: [PATCH 061/151] doc: add Franziska Hinkelmann to the CTC MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit PR-URL: https://github.com/nodejs/node/pull/11488 Reviewed-By: Ben Noordhuis Reviewed-By: James M Snell Reviewed-By: Evan Lucas Reviewed-By: Anna Henningsen Reviewed-By: Rich Trott Reviewed-By: Julien Gilli Reviewed-By: Ali Ijaz Sheikh Reviewed-By: Sakthipriyan Vairamani Reviewed-By: Michaël Zasso Reviewed-By: Jeremiah Senkpiel Reviewed-By: Myles Borins Reviewed-By: Colin Ihrig Reviewed-By: Сковорода Никита Андреевич Reviewed-By: Michael Dawson --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 225f0c648d0b91..99c0fac0aff318 100644 --- a/README.md +++ b/README.md @@ -164,6 +164,8 @@ more information about the governance of the Node.js project, see **Colin Ihrig** <cjihrig@gmail.com> * [evanlucas](https://github.com/evanlucas) - **Evan Lucas** <evanlucas@me.com> (he/him) +* [fhinkel](https://github.com/fhinkel) - +**Franziska Hinkelmann** <franziska.hinkelmann@gmail.com> * [fishrock123](https://github.com/fishrock123) - **Jeremiah Senkpiel** <fishrock123@rocketmail.com> * [indutny](https://github.com/indutny) - @@ -229,8 +231,6 @@ more information about the governance of the Node.js project, see **Alexander Makarenko** <estliberitas@gmail.com> * [eugeneo](https://github.com/eugeneo) - **Eugene Ostroukhov** <eostroukhov@google.com> -* [fhinkel](https://github.com/fhinkel) - -**Franziska Hinkelmann** <franziska.hinkelmann@gmail.com> * [firedfox](https://github.com/firedfox) - **Daniel Wang** <wangyang0123@gmail.com> * [geek](https://github.com/geek) - From 8de856b19188bf50282954c751ad0d8abeaf6950 Mon Sep 17 00:00:00 2001 From: Sam Roberts Date: Mon, 6 Mar 2017 09:59:41 -0800 Subject: [PATCH 062/151] doc: fix process links to console.log/error MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixes: https://github.com/nodejs/node/issues/11717 PR-URL: https://github.com/nodejs/node/pull/11718 Reviewed-By: James M Snell Reviewed-By: Luigi Pinca Reviewed-By: Colin Ihrig Reviewed-By: Сковорода Никита Андреевич Reviewed-By: Franziska Hinkelmann Reviewed-By: Brian White --- doc/api/process.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/doc/api/process.md b/doc/api/process.md index e1beeac4cc6526..36930992f199b5 100644 --- a/doc/api/process.md +++ b/doc/api/process.md @@ -1771,6 +1771,8 @@ cases: [`Error`]: errors.html#errors_class_error [`EventEmitter`]: events.html#events_class_eventemitter [`JSON.stringify()`]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify +[`console.error()`]: console.html#console_console_error_data_args +[`console.log()`]: console.html#console_console_log_data_args [`net.Server`]: net.html#net_class_net_server [`net.Socket`]: net.html#net_class_net_socket [`process.argv`]: #process_process_argv From 0acebb985fb3d3e0be5aba2a6881e99dabb20dd4 Mon Sep 17 00:00:00 2001 From: Jeroen Mandersloot Date: Mon, 6 Mar 2017 11:32:45 +0100 Subject: [PATCH 063/151] doc: fix occurences of "the the" MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit I identified a number of files where it said "the the" in the comments of the source code and in general documentation texts. I replaced these occurences with a single instance of "the". PR-URL: https://github.com/nodejs/node/pull/11711 Reviewed-By: Anna Henningsen Reviewed-By: Luigi Pinca Reviewed-By: Colin Ihrig Reviewed-By: Michael Dawson Reviewed-By: James M Snell Reviewed-By: Michaël Zasso Reviewed-By: Franziska Hinkelmann --- doc/api/child_process.md | 2 +- doc/api/stream.md | 2 +- src/cares_wrap.cc | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/doc/api/child_process.md b/doc/api/child_process.md index a5482201091565..323e298fedc2a8 100644 --- a/doc/api/child_process.md +++ b/doc/api/child_process.md @@ -193,7 +193,7 @@ the process is spawned. The default options are: } ``` -If `timeout` is greater than `0`, the parent will send the the signal +If `timeout` is greater than `0`, the parent will send the signal identified by the `killSignal` property (the default is `'SIGTERM'`) if the child runs longer than `timeout` milliseconds. diff --git a/doc/api/stream.md b/doc/api/stream.md index e2db0b29ccb255..fb8e66dccbf795 100644 --- a/doc/api/stream.md +++ b/doc/api/stream.md @@ -471,7 +471,7 @@ If the data to be written can be generated or fetched on demand, it is recommended to encapsulate the logic into a [Readable][] and use [`stream.pipe()`][]. However, if calling `write()` is preferred, it is possible to respect backpressure and avoid memory issues using the -the [`'drain'`][] event: +[`'drain'`][] event: ```js function write (data, cb) { diff --git a/src/cares_wrap.cc b/src/cares_wrap.cc index 3aab61e1b360fc..0a0aff95e28b7c 100644 --- a/src/cares_wrap.cc +++ b/src/cares_wrap.cc @@ -221,8 +221,8 @@ static void ares_sockstate_cb(void* data, task = ares_task_create(env, sock); if (task == nullptr) { /* This should never happen unless we're out of memory or something */ - /* is seriously wrong. The socket won't be polled, but the the query */ - /* will eventually time out. */ + /* is seriously wrong. The socket won't be polled, but the query will */ + /* eventually time out. */ return; } From 0e13887421fde8358c1f94efdd7ca18bb14a5d77 Mon Sep 17 00:00:00 2001 From: Gibson Fahnestock Date: Sun, 5 Mar 2017 16:24:41 +0000 Subject: [PATCH 064/151] doc: reduce font size on smaller screens The font size for tablet sized screens (or half a laptop screen) is overly large, reduce it to a more readable size. Fixes: https://github.com/nodejs/nodejs.org/issues/919 PR-URL: https://github.com/nodejs/node/pull/11695 Fixes: https://github.com/nodejs/nodejs.org#919 Reviewed-By: Daijiro Wachi Reviewed-By: Luigi Pinca Reviewed-By: Franziska Hinkelmann --- doc/api_assets/style.css | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/api_assets/style.css b/doc/api_assets/style.css index c187079a26f98e..55dfbb187f18d0 100644 --- a/doc/api_assets/style.css +++ b/doc/api_assets/style.css @@ -476,7 +476,7 @@ th > *:last-child, td > *:last-child { @media only screen and (max-width: 1024px) { #content { - font-size: 2.5em; + font-size: 1.6em; overflow: visible; } #column1.interior { From cd98f5d3035be83e27332869000e38384bed57f5 Mon Sep 17 00:00:00 2001 From: Santiago Gimeno Date: Fri, 10 Mar 2017 12:13:49 +0100 Subject: [PATCH 065/151] test: fix flaky test-http-set-timeout-server It can happen that the connection and server is closed before the second reponse has been processed by server. In this case, the `res.setTimeout()` callback will never be called causing the test to fail. Fix this by only closing the connection and server when the 2nd has been received. PR-URL: https://github.com/nodejs/node/pull/11790 Fixes: https://github.com/nodejs/node/issues/11768 Reviewed-By: Rich Trott Reviewed-By: Colin Ihrig Reviewed-By: Gibson Fahnestock --- test/parallel/test-http-set-timeout-server.js | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/test/parallel/test-http-set-timeout-server.js b/test/parallel/test-http-set-timeout-server.js index 097aeb260bdc5e..8f301af5a9dcc4 100644 --- a/test/parallel/test-http-set-timeout-server.js +++ b/test/parallel/test-http-set-timeout-server.js @@ -117,10 +117,13 @@ test(function serverRequestNotTimeoutAfterEnd(cb) { test(function serverResponseTimeoutWithPipeline(cb) { let caughtTimeout = ''; + let secReceived = false; process.on('exit', function() { assert.strictEqual(caughtTimeout, '/2'); }); const server = http.createServer(function(req, res) { + if (req.url === '/2') + secReceived = true; const s = res.setTimeout(50, function() { caughtTimeout += req.url; }); @@ -128,9 +131,11 @@ test(function serverResponseTimeoutWithPipeline(cb) { if (req.url === '/1') res.end(); }); server.on('timeout', function(socket) { - socket.destroy(); - server.close(); - cb(); + if (secReceived) { + socket.destroy(); + server.close(); + cb(); + } }); server.listen(common.mustCall(function() { const port = server.address().port; From be537d0062732c7f953ad7d979b0358b1b2e6d5f Mon Sep 17 00:00:00 2001 From: Bradley Farias Date: Mon, 27 Feb 2017 12:01:18 -0600 Subject: [PATCH 066/151] doc: package main can be directory with an index This behavior dates back to 2011 but was not documented. PR-URL: https://github.com/nodejs/node/pull/11581 Reviewed-By: Bradley Farias Reviewed-By: James Snell --- doc/api/modules.md | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/doc/api/modules.md b/doc/api/modules.md index 0aeab0ad14bbd2..6e50ede32b32aa 100644 --- a/doc/api/modules.md +++ b/doc/api/modules.md @@ -161,14 +161,18 @@ LOAD_AS_FILE(X) 3. If X.json is a file, parse X.json to a JavaScript Object. STOP 4. If X.node is a file, load X.node as binary addon. STOP +LOAD_INDEX(X) +1. If X/index.js is a file, load X/index.js as JavaScript text. STOP +2. If X/index.json is a file, parse X/index.json to a JavaScript object. STOP +3. If X/index.node is a file, load X/index.node as binary addon. STOP + LOAD_AS_DIRECTORY(X) 1. If X/package.json is a file, a. Parse X/package.json, and look for "main" field. b. let M = X + (json main field) c. LOAD_AS_FILE(M) -2. If X/index.js is a file, load X/index.js as JavaScript text. STOP -3. If X/index.json is a file, parse X/index.json to a JavaScript object. STOP -4. If X/index.node is a file, load X/index.node as binary addon. STOP + d. LOAD_INDEX(M) +2. LOAD_INDEX(X) LOAD_NODE_MODULES(X, START) 1. let DIRS=NODE_MODULES_PATHS(START) From 82d2f13680e6cb00c7cf24ff955c77c26185db54 Mon Sep 17 00:00:00 2001 From: Franziska Hinkelmann Date: Fri, 10 Mar 2017 11:22:27 +0100 Subject: [PATCH 067/151] doc: update to current V8 versions Update the documentation to the correct V8 versions in the guide *Maintaining V8 in Node.js*. PR-URL: https://github.com/nodejs/node/pull/11787 Reviewed-By: James M Snell --- doc/guides/maintaining-V8.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/doc/guides/maintaining-V8.md b/doc/guides/maintaining-V8.md index 4bfed3790f5185..e57b73bcf91d3a 100644 --- a/doc/guides/maintaining-V8.md +++ b/doc/guides/maintaining-V8.md @@ -93,11 +93,11 @@ includes the following branches1: 2017-04-01 - 5.4 + 5.5 - 2016-10-18 + 2016-12-06 - ~2016-12-01 + 2017-01-24 @@ -107,11 +107,11 @@ includes the following branches1: N/A - 5.4 + 5.6 - 2016-10-18 + 2017-01-31 - ~2016-12-01 + 2017-03-07 From 2c2a6649c18a6ef2b0ea01f280b7467f35b4c081 Mon Sep 17 00:00:00 2001 From: Daniel Bevenius Date: Thu, 9 Mar 2017 10:31:54 +0100 Subject: [PATCH 068/151] build: add node_use_openssl check to install.py When configuring --without-ssl and then running make install openssl headers will be copied from deps/openssl to the target installation directory. This commit adds a check for is node_use_openssl is set in which case the headers are not copied. PR-URL: https://github.com/nodejs/node/pull/11766 Reviewed-By: Colin Ihrig Reviewed-By: Ben Noordhuis Reviewed-By: Brian White --- tools/install.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tools/install.py b/tools/install.py index 4f155376eaf534..d1100352c6a413 100755 --- a/tools/install.py +++ b/tools/install.py @@ -165,7 +165,8 @@ def headers(action): if 'false' == variables.get('node_shared_libuv'): subdir_files('deps/uv/include', 'include/node/', action) - if 'false' == variables.get('node_shared_openssl'): + if 'true' == variables.get('node_use_openssl') and \ + 'false' == variables.get('node_shared_openssl'): subdir_files('deps/openssl/openssl/include/openssl', 'include/node/openssl/', action) subdir_files('deps/openssl/config/archs', 'include/node/openssl/archs', action) action(['deps/openssl/config/opensslconf.h'], 'include/node/openssl/') From 1baee1829b5ead5bde582d3e146e0c2ee16734fa Mon Sep 17 00:00:00 2001 From: jBarz Date: Thu, 9 Mar 2017 08:33:59 -0500 Subject: [PATCH 069/151] tls: keep track of stream that is closed TLSWrap object keeps a pointer reference to the underlying TCPWrap object. This TCPWrap object could be closed and deleted by the event-loop which leaves us with a dangling pointer. So the TLSWrap object needs to track the "close" event on the TCPWrap object. PR-URL: https://github.com/nodejs/node/pull/11776 Reviewed-By: Fedor Indutny Reviewed-By: James M Snell Reviewed-By: Brian White --- lib/_tls_wrap.js | 6 ++++ src/tls_wrap.cc | 11 ++++++- src/tls_wrap.h | 1 + test/parallel/test-tls-socket-close.js | 43 ++++++++++++++++++++++++++ 4 files changed, 60 insertions(+), 1 deletion(-) create mode 100644 test/parallel/test-tls-socket-close.js diff --git a/lib/_tls_wrap.js b/lib/_tls_wrap.js index a4e3d6bd08b95e..b4b975b9d49bf4 100644 --- a/lib/_tls_wrap.js +++ b/lib/_tls_wrap.js @@ -378,6 +378,12 @@ TLSSocket.prototype._wrapHandle = function(wrap) { res = null; }); + if (wrap) { + wrap.on('close', function() { + res.onStreamClose(); + }); + } + return res; }; diff --git a/src/tls_wrap.cc b/src/tls_wrap.cc index d1b1aeccdd95b0..6a838c610b0ed1 100644 --- a/src/tls_wrap.cc +++ b/src/tls_wrap.cc @@ -522,7 +522,7 @@ int TLSWrap::GetFD() { bool TLSWrap::IsAlive() { - return ssl_ != nullptr && stream_->IsAlive(); + return ssl_ != nullptr && stream_ != nullptr && stream_->IsAlive(); } @@ -782,6 +782,14 @@ void TLSWrap::EnableSessionCallbacks( } +void TLSWrap::OnStreamClose(const FunctionCallbackInfo& args) { + TLSWrap* wrap; + ASSIGN_OR_RETURN_UNWRAP(&wrap, args.Holder()); + + wrap->stream_ = nullptr; +} + + void TLSWrap::DestroySSL(const FunctionCallbackInfo& args) { TLSWrap* wrap; ASSIGN_OR_RETURN_UNWRAP(&wrap, args.Holder()); @@ -912,6 +920,7 @@ void TLSWrap::Initialize(Local target, env->SetProtoMethod(t, "enableSessionCallbacks", EnableSessionCallbacks); env->SetProtoMethod(t, "destroySSL", DestroySSL); env->SetProtoMethod(t, "enableCertCb", EnableCertCb); + env->SetProtoMethod(t, "onStreamClose", OnStreamClose); StreamBase::AddMethods(env, t, StreamBase::kFlagHasWritev); SSLWrap::AddMethods(env, t); diff --git a/src/tls_wrap.h b/src/tls_wrap.h index f390c9fe9281f7..0efdbf0e3991d3 100644 --- a/src/tls_wrap.h +++ b/src/tls_wrap.h @@ -137,6 +137,7 @@ class TLSWrap : public AsyncWrap, static void EnableCertCb( const v8::FunctionCallbackInfo& args); static void DestroySSL(const v8::FunctionCallbackInfo& args); + static void OnStreamClose(const v8::FunctionCallbackInfo& args); #ifdef SSL_CTRL_SET_TLSEXT_SERVERNAME_CB static void GetServername(const v8::FunctionCallbackInfo& args); diff --git a/test/parallel/test-tls-socket-close.js b/test/parallel/test-tls-socket-close.js new file mode 100644 index 00000000000000..440c0c4ff7cde7 --- /dev/null +++ b/test/parallel/test-tls-socket-close.js @@ -0,0 +1,43 @@ +'use strict'; +const common = require('../common'); +const assert = require('assert'); + +const tls = require('tls'); +const fs = require('fs'); +const net = require('net'); + +const key = fs.readFileSync(common.fixturesDir + '/keys/agent2-key.pem'); +const cert = fs.readFileSync(common.fixturesDir + '/keys/agent2-cert.pem'); + +const T = 100; + +// tls server +const tlsServer = tls.createServer({ cert, key }, (socket) => { + setTimeout(() => { + socket.on('error', (error) => { + assert.strictEqual(error.code, 'EINVAL'); + tlsServer.close(); + netServer.close(); + }); + socket.write('bar'); + }, T * 2); +}); + +// plain tcp server +const netServer = net.createServer((socket) => { + // if client wants to use tls + tlsServer.emit('connection', socket); + + socket.setTimeout(T, () => { + // this breaks if TLSSocket is already managing the socket: + socket.destroy(); + }); +}).listen(0, common.mustCall(function() { + + // connect client + tls.connect({ + host: 'localhost', + port: this.address().port, + rejectUnauthorized: false + }).write('foo'); +})); From 457c47d85eb8a8bf0a527a770c188c8ecd40cbde Mon Sep 17 00:00:00 2001 From: Trevor Norris Date: Mon, 31 Oct 2016 16:48:14 -0600 Subject: [PATCH 070/151] stream_base,tls_wrap: notify on destruct The TLSWrap constructor is passed a StreamBase* which it stores as TLSWrap::stream_, and is used to receive/send data along the pipeline (e.g. tls -> tcp). Problem is the lifetime of the instance that stream_ points to is independent of the lifetime of the TLSWrap instance. So it's possible for stream_ to be delete'd while the TLSWrap instance is still alive, allowing potential access to a then invalid pointer. Fix by having the StreamBase destructor null out TLSWrap::stream_; allowing all TLSWrap methods that rely on stream_ to do a check to see if it's available. While the test provided is fixed by this commit, it was also previously fixed by 478fabf. Regardless, leave the test in for better testing. PR-URL: https://github.com/nodejs/node/pull/11947 Reviewed-By: Franziska Hinkelmann Reviewed-By: James M Snell Reviewed-By: Anna Henningsen --- src/stream_base.h | 9 +++- src/tls_wrap.cc | 7 ++++ src/tls_wrap.h | 3 ++ .../test-tls-retain-handle-no-abort.js | 42 +++++++++++++++++++ 4 files changed, 60 insertions(+), 1 deletion(-) create mode 100644 test/parallel/test-tls-retain-handle-no-abort.js diff --git a/src/stream_base.h b/src/stream_base.h index faddee88c82786..35929750bfbc54 100644 --- a/src/stream_base.h +++ b/src/stream_base.h @@ -146,10 +146,14 @@ class StreamResource { const uv_buf_t* buf, uv_handle_type pending, void* ctx); + typedef void (*DestructCb)(void* ctx); StreamResource() : bytes_read_(0) { } - virtual ~StreamResource() = default; + virtual ~StreamResource() { + if (!destruct_cb_.is_empty()) + destruct_cb_.fn(destruct_cb_.ctx); + } virtual int DoShutdown(ShutdownWrap* req_wrap) = 0; virtual int DoTryWrite(uv_buf_t** bufs, size_t* count); @@ -186,15 +190,18 @@ class StreamResource { inline void set_alloc_cb(Callback c) { alloc_cb_ = c; } inline void set_read_cb(Callback c) { read_cb_ = c; } + inline void set_destruct_cb(Callback c) { destruct_cb_ = c; } inline Callback after_write_cb() { return after_write_cb_; } inline Callback alloc_cb() { return alloc_cb_; } inline Callback read_cb() { return read_cb_; } + inline Callback destruct_cb() { return destruct_cb_; } private: Callback after_write_cb_; Callback alloc_cb_; Callback read_cb_; + Callback destruct_cb_; uint64_t bytes_read_; friend class StreamBase; diff --git a/src/tls_wrap.cc b/src/tls_wrap.cc index 6a838c610b0ed1..7e2f86e10e84e0 100644 --- a/src/tls_wrap.cc +++ b/src/tls_wrap.cc @@ -64,6 +64,7 @@ TLSWrap::TLSWrap(Environment* env, stream_->set_after_write_cb({ OnAfterWriteImpl, this }); stream_->set_alloc_cb({ OnAllocImpl, this }); stream_->set_read_cb({ OnReadImpl, this }); + stream_->set_destruct_cb({ OnDestructImpl, this }); set_alloc_cb({ OnAllocSelf, this }); set_read_cb({ OnReadSelf, this }); @@ -660,6 +661,12 @@ void TLSWrap::OnReadImpl(ssize_t nread, } +void TLSWrap::OnDestructImpl(void* ctx) { + TLSWrap* wrap = static_cast(ctx); + wrap->clear_stream(); +} + + void TLSWrap::OnAllocSelf(size_t suggested_size, uv_buf_t* buf, void* ctx) { buf->base = static_cast(node::Malloc(suggested_size)); CHECK_NE(buf->base, nullptr); diff --git a/src/tls_wrap.h b/src/tls_wrap.h index 0efdbf0e3991d3..8132d66876f26f 100644 --- a/src/tls_wrap.h +++ b/src/tls_wrap.h @@ -54,6 +54,8 @@ class TLSWrap : public AsyncWrap, size_t self_size() const override { return sizeof(*this); } + void clear_stream() { stream_ = nullptr; } + protected: static const int kClearOutChunkSize = 16384; @@ -121,6 +123,7 @@ class TLSWrap : public AsyncWrap, const uv_buf_t* buf, uv_handle_type pending, void* ctx); + static void OnDestructImpl(void* ctx); void DoRead(ssize_t nread, const uv_buf_t* buf, uv_handle_type pending); diff --git a/test/parallel/test-tls-retain-handle-no-abort.js b/test/parallel/test-tls-retain-handle-no-abort.js new file mode 100644 index 00000000000000..43b3709fd5f85b --- /dev/null +++ b/test/parallel/test-tls-retain-handle-no-abort.js @@ -0,0 +1,42 @@ +'use strict'; + +const common = require('../common'); +const assert = require('assert'); + +if (!common.hasCrypto) { + common.skip('missing crypto'); + return; +} +const tls = require('tls'); +const fs = require('fs'); +const util = require('util'); + +const sent = 'hello world'; +const serverOptions = { + isServer: true, + key: fs.readFileSync(common.fixturesDir + '/keys/agent1-key.pem'), + cert: fs.readFileSync(common.fixturesDir + '/keys/agent1-cert.pem') +}; + +let ssl = null; + +process.on('exit', function() { + assert.ok(ssl !== null); + // If the internal pointer to stream_ isn't cleared properly then this + // will abort. + util.inspect(ssl); +}); + +const server = tls.createServer(serverOptions, function(s) { + s.on('data', function() { }); + s.on('end', function() { + server.close(); + s.destroy(); + }); +}).listen(0, function() { + const c = new tls.TLSSocket(); + ssl = c.ssl; + c.connect(this.address().port, function() { + c.end(sent); + }); +}); From 858bbaa4aa8e7b06bb10a815b9c70547d1fcda51 Mon Sep 17 00:00:00 2001 From: Trevor Norris Date: Mon, 20 Mar 2017 16:26:10 -0600 Subject: [PATCH 071/151] Partial revert "tls: keep track of stream that is closed" This partually reverts commit 4cdb0e89d8daf7e1371c3b8d3f057940aa327d4a. A nullptr check in TSLWrap::IsAlive() and the added test were left. PR-URL: https://github.com/nodejs/node/pull/11947 Reviewed-By: Franziska Hinkelmann Reviewed-By: James M Snell Reviewed-By: Anna Henningsen --- lib/_tls_wrap.js | 6 ------ src/tls_wrap.cc | 9 --------- src/tls_wrap.h | 1 - 3 files changed, 16 deletions(-) diff --git a/lib/_tls_wrap.js b/lib/_tls_wrap.js index b4b975b9d49bf4..a4e3d6bd08b95e 100644 --- a/lib/_tls_wrap.js +++ b/lib/_tls_wrap.js @@ -378,12 +378,6 @@ TLSSocket.prototype._wrapHandle = function(wrap) { res = null; }); - if (wrap) { - wrap.on('close', function() { - res.onStreamClose(); - }); - } - return res; }; diff --git a/src/tls_wrap.cc b/src/tls_wrap.cc index 7e2f86e10e84e0..39642cf0680709 100644 --- a/src/tls_wrap.cc +++ b/src/tls_wrap.cc @@ -789,14 +789,6 @@ void TLSWrap::EnableSessionCallbacks( } -void TLSWrap::OnStreamClose(const FunctionCallbackInfo& args) { - TLSWrap* wrap; - ASSIGN_OR_RETURN_UNWRAP(&wrap, args.Holder()); - - wrap->stream_ = nullptr; -} - - void TLSWrap::DestroySSL(const FunctionCallbackInfo& args) { TLSWrap* wrap; ASSIGN_OR_RETURN_UNWRAP(&wrap, args.Holder()); @@ -927,7 +919,6 @@ void TLSWrap::Initialize(Local target, env->SetProtoMethod(t, "enableSessionCallbacks", EnableSessionCallbacks); env->SetProtoMethod(t, "destroySSL", DestroySSL); env->SetProtoMethod(t, "enableCertCb", EnableCertCb); - env->SetProtoMethod(t, "onStreamClose", OnStreamClose); StreamBase::AddMethods(env, t, StreamBase::kFlagHasWritev); SSLWrap::AddMethods(env, t); diff --git a/src/tls_wrap.h b/src/tls_wrap.h index 8132d66876f26f..fbf664edd530c0 100644 --- a/src/tls_wrap.h +++ b/src/tls_wrap.h @@ -140,7 +140,6 @@ class TLSWrap : public AsyncWrap, static void EnableCertCb( const v8::FunctionCallbackInfo& args); static void DestroySSL(const v8::FunctionCallbackInfo& args); - static void OnStreamClose(const v8::FunctionCallbackInfo& args); #ifdef SSL_CTRL_SET_TLSEXT_SERVERNAME_CB static void GetServername(const v8::FunctionCallbackInfo& args); From 7d4941f01a3419cbbbd815495386a846db191acd Mon Sep 17 00:00:00 2001 From: Vse Mozhet Byt Date: Fri, 3 Mar 2017 16:09:43 +0200 Subject: [PATCH 072/151] test: fix args in parallel/test-fs-null-bytes.js MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The functions `fs.appendFile()` and `fs.writeFile()` were being called without the required `data` argument. Refs: https://github.com/nodejs/node/issues/11595 Backport-PR-URL: https://github.com/nodejs/node/pull/12477 PR-URL: https://github.com/nodejs/node/pull/11601 Reviewed-By: Michaël Zasso Reviewed-By: Nikolai Vavilov Reviewed-By: Colin Ihrig Reviewed-By: James M Snell Reviewed-By: Yuta Hiroto --- test/parallel/test-fs-null-bytes.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/parallel/test-fs-null-bytes.js b/test/parallel/test-fs-null-bytes.js index fa29e64c9b2382..24d5514eecde75 100644 --- a/test/parallel/test-fs-null-bytes.js +++ b/test/parallel/test-fs-null-bytes.js @@ -22,7 +22,7 @@ function check(async, sync) { check(fs.access, fs.accessSync, 'foo\u0000bar'); check(fs.access, fs.accessSync, 'foo\u0000bar', fs.F_OK); -check(fs.appendFile, fs.appendFileSync, 'foo\u0000bar'); +check(fs.appendFile, fs.appendFileSync, 'foo\u0000bar', 'abc'); check(fs.chmod, fs.chmodSync, 'foo\u0000bar', '0644'); check(fs.chown, fs.chownSync, 'foo\u0000bar', 12, 34); check(fs.link, fs.linkSync, 'foo\u0000bar', 'foobar'); @@ -46,7 +46,7 @@ check(null, fs.unwatchFile, 'foo\u0000bar', common.fail); check(fs.utimes, fs.utimesSync, 'foo\u0000bar', 0, 0); check(null, fs.watch, 'foo\u0000bar', common.fail); check(null, fs.watchFile, 'foo\u0000bar', common.fail); -check(fs.writeFile, fs.writeFileSync, 'foo\u0000bar'); +check(fs.writeFile, fs.writeFileSync, 'foo\u0000bar', 'abc'); // an 'error' for exists means that it doesn't exist. // one of many reasons why this file is the absolute worst. From 1158f44599ece58276196cf298e1f4ba1023a195 Mon Sep 17 00:00:00 2001 From: jseagull Date: Mon, 10 Oct 2016 18:47:07 +0800 Subject: [PATCH 073/151] events,test: fix TypeError in EventEmitter warning Allows Symbol to be converted to String so it can be included in the error. Conflicts: lib/events.js Fixes: #9003 Backport-PR-URL: https://github.com/nodejs/node/pull/12459 PR-URL: https://github.com/nodejs/node/pull/9021 Reviewed-By: Rich Trott Reviewed-By: Luigi Pinca Reviewed-By: Anna Henningsen Reviewed-By: James M Snell Reviewed-By: Sakthipriyan Vairamani Reviewed-By: Santiago Gimeno --- lib/events.js | 5 ++-- ...test-event-emitter-check-listener-leaks.js | 8 +++++++ ...-emitter-max-listeners-warning-for-null.js | 22 +++++++++++++++++ ...mitter-max-listeners-warning-for-symbol.js | 24 +++++++++++++++++++ ...est-event-emitter-max-listeners-warning.js | 1 + 5 files changed, 58 insertions(+), 2 deletions(-) create mode 100644 test/parallel/test-event-emitter-max-listeners-warning-for-null.js create mode 100644 test/parallel/test-event-emitter-max-listeners-warning-for-symbol.js diff --git a/lib/events.js b/lib/events.js index ac18327ef147f6..5cb837cc6c3877 100644 --- a/lib/events.js +++ b/lib/events.js @@ -257,8 +257,9 @@ function _addListener(target, type, listener, prepend) { if (m && m > 0 && existing.length > m) { existing.warned = true; const w = new Error('Possible EventEmitter memory leak detected. ' + - `${existing.length} ${type} listeners added. ` + - 'Use emitter.setMaxListeners() to increase limit'); + `${existing.length} ${String(type)} listeners ` + + 'added. Use emitter.setMaxListeners() to ' + + 'increase limit'); w.name = 'Warning'; w.emitter = target; w.type = type; diff --git a/test/parallel/test-event-emitter-check-listener-leaks.js b/test/parallel/test-event-emitter-check-listener-leaks.js index 244bfa97bfa86a..5b9787f1b83bba 100644 --- a/test/parallel/test-event-emitter-check-listener-leaks.js +++ b/test/parallel/test-event-emitter-check-listener-leaks.js @@ -13,6 +13,14 @@ assert.ok(!e._events['default'].hasOwnProperty('warned')); e.on('default', function() {}); assert.ok(e._events['default'].warned); +// symbol +const symbol = Symbol('symbol'); +e.setMaxListeners(1); +e.on(symbol, function() {}); +assert.ok(!e._events[symbol].hasOwnProperty('warned')); +e.on(symbol, function() {}); +assert.ok(e._events[symbol].hasOwnProperty('warned')); + // specific e.setMaxListeners(5); for (let i = 0; i < 5; i++) { diff --git a/test/parallel/test-event-emitter-max-listeners-warning-for-null.js b/test/parallel/test-event-emitter-max-listeners-warning-for-null.js new file mode 100644 index 00000000000000..62b06f67d92f28 --- /dev/null +++ b/test/parallel/test-event-emitter-max-listeners-warning-for-null.js @@ -0,0 +1,22 @@ +// 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, 'Warning'); + assert.strictEqual(warning.emitter, e); + assert.strictEqual(warning.count, 2); + assert.strictEqual(warning.type, null); + assert.ok(warning.message.includes('2 null listeners added.')); +})); + +e.on(null, function() {}); +e.on(null, function() {}); diff --git a/test/parallel/test-event-emitter-max-listeners-warning-for-symbol.js b/test/parallel/test-event-emitter-max-listeners-warning-for-symbol.js new file mode 100644 index 00000000000000..97bf189270395b --- /dev/null +++ b/test/parallel/test-event-emitter-max-listeners-warning-for-symbol.js @@ -0,0 +1,24 @@ +// 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, 'Warning'); + 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.')); +})); + +e.on(symbol, function() {}); +e.on(symbol, function() {}); diff --git a/test/parallel/test-event-emitter-max-listeners-warning.js b/test/parallel/test-event-emitter-max-listeners-warning.js index bcbb583265805c..df363e43d9cbb7 100644 --- a/test/parallel/test-event-emitter-max-listeners-warning.js +++ b/test/parallel/test-event-emitter-max-listeners-warning.js @@ -15,6 +15,7 @@ process.on('warning', common.mustCall((warning) => { 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.')); })); e.on('event-type', function() {}); From 4d916da0d7138fa52e0ec6cc5d05899d195bd47a Mon Sep 17 00:00:00 2001 From: Joyee Cheung Date: Sat, 4 Mar 2017 18:54:48 +0800 Subject: [PATCH 074/151] test: fail when child dies in fork-net Previously when the child dies with errors in this test, the parent will just hang and timeout, the errors in the child would be swallowed. This makes it fail so at least there is more information about why this test fails. Also removes the unnecessary child.kill() call. PR-URL: https://github.com/nodejs/node/pull/11684 Ref: https://github.com/nodejs/node/pull/11667 Reviewed-By: Colin Ihrig Reviewed-By: James M Snell --- test/parallel/test-child-process-fork-net.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/test/parallel/test-child-process-fork-net.js b/test/parallel/test-child-process-fork-net.js index c17dba94953b9e..d224643184733f 100644 --- a/test/parallel/test-child-process-fork-net.js +++ b/test/parallel/test-child-process-fork-net.js @@ -1,5 +1,5 @@ 'use strict'; -require('../common'); +const common = require('../common'); const assert = require('assert'); const fork = require('child_process').fork; const net = require('net'); @@ -60,9 +60,10 @@ if (process.argv[2] === 'child') { const child = fork(process.argv[1], ['child']); - child.on('exit', function() { - console.log('CHILD: died'); - }); + child.on('exit', common.mustCall(function(code, signal) { + const message = `CHILD: died with ${code}, ${signal}`; + assert.strictEqual(code, 0, message); + })); // send net.Server to child and test by connecting const testServer = function(callback) { @@ -171,7 +172,6 @@ if (process.argv[2] === 'child') { testSocket(function() { socketSuccess = true; - child.kill(); }); }); From a3f327fd2129240e30cb1202bb62ab6ae9201846 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matej=20Kraj=C4=8Dovi=C4=8D?= Date: Sun, 12 Mar 2017 16:09:32 +0100 Subject: [PATCH 075/151] test: add regex to assert.throws Make sure test matches this specific error message. PR-URL: https://github.com/nodejs/node/pull/11815 Reviewed-By: Anna Henningsen Reviewed-By: Luigi Pinca Reviewed-By: Colin Ihrig Reviewed-By: Yuta Hiroto Reviewed-By: James M Snell --- test/parallel/test-vm-run-in-new-context.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/parallel/test-vm-run-in-new-context.js b/test/parallel/test-vm-run-in-new-context.js index 7b096ffc3fdc5f..3f8c632859db0f 100644 --- a/test/parallel/test-vm-run-in-new-context.js +++ b/test/parallel/test-vm-run-in-new-context.js @@ -17,7 +17,7 @@ assert.strictEqual('passed', result); console.error('thrown error'); assert.throws(function() { vm.runInNewContext('throw new Error(\'test\');'); -}); +}, /^Error: test$/); global.hello = 5; vm.runInNewContext('hello = 2'); From 46b2e45b40ea03490495372be2dd27f3cefb1bf2 Mon Sep 17 00:00:00 2001 From: AnnaMag Date: Thu, 9 Mar 2017 14:00:34 +0000 Subject: [PATCH 076/151] test: added test for indexed properties MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Currently, indexed properties are correctly copied onto the sandbox by CopyProperties(). This will break when CopyProperties() is removed after adjusting NamedPropertyHandlerConfiguration config() to use property callbacks from the new V8 API. To fix it, we will set a config for indexed properties. This test is a preparation step for the patch that removes CopyProperties(). PR-URL: https://github.com/nodejs/node/pull/11769 Reviewed-By: Franziska Hinkelmann Reviewed-By: Michaël Zasso Reviewed-By: James M Snell Reviewed-By: Colin Ihrig Reviewed-By: Brian White --- test/parallel/test-vm-indexed-properties.js | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 test/parallel/test-vm-indexed-properties.js diff --git a/test/parallel/test-vm-indexed-properties.js b/test/parallel/test-vm-indexed-properties.js new file mode 100644 index 00000000000000..34ef8d020b2181 --- /dev/null +++ b/test/parallel/test-vm-indexed-properties.js @@ -0,0 +1,17 @@ +'use strict'; + +require('../common'); +const assert = require('assert'); +const vm = require('vm'); + +const code = `Object.defineProperty(this, 99, { + value: 20, + enumerable: true + });`; + + +const sandbox = {}; +const ctx = vm.createContext(sandbox); +vm.runInContext(code, ctx); + +assert.strictEqual(sandbox[99], 20); From 72710d05b9a1ecc3dc87ee8f0e5baa8d071e6d7d Mon Sep 17 00:00:00 2001 From: Rich Trott Date: Sun, 12 Mar 2017 09:10:50 -0700 Subject: [PATCH 077/151] test: fix flaky test-domain-abort-on-uncaught test-domain-abort-on-uncaught is flaky under load. Move it to sequential so it is not competing with other tests for resources. PR-URL: https://github.com/nodejs/node/pull/11817 Fixes: https://github.com/nodejs/node/issues/11814 Reviewed-By: Colin Ihrig Reviewed-By: Gibson Fahnestock Reviewed-By: Daijiro Wachi Reviewed-By: Santiago Gimeno Reviewed-By: Yuta Hiroto Reviewed-By: James M Snell --- test/{parallel => sequential}/test-domain-abort-on-uncaught.js | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename test/{parallel => sequential}/test-domain-abort-on-uncaught.js (100%) diff --git a/test/parallel/test-domain-abort-on-uncaught.js b/test/sequential/test-domain-abort-on-uncaught.js similarity index 100% rename from test/parallel/test-domain-abort-on-uncaught.js rename to test/sequential/test-domain-abort-on-uncaught.js From 8e5c8a3ac10feb52f84834107059ddbcbe4badb4 Mon Sep 17 00:00:00 2001 From: AnnaMag Date: Thu, 2 Mar 2017 16:03:54 +0000 Subject: [PATCH 078/151] test: failing behaviour on sandboxed Proxy CopyProperties() causes sandboxed Proxy to throw error when in fact no code has been run. The function will be removed with the updates to the V8 API. Here, failing Proxy test case is moved to known_issues. PR-URL: https://github.com/nodejs/node/pull/11671 Reviewed-By: James M Snell Reviewed-By: Franziska Hinkelmann --- test/known_issues/test-vm-proxy-failure-CP.js | 20 +++++++++++++++++++ test/parallel/test-vm-proxies.js | 13 ------------ 2 files changed, 20 insertions(+), 13 deletions(-) create mode 100644 test/known_issues/test-vm-proxy-failure-CP.js diff --git a/test/known_issues/test-vm-proxy-failure-CP.js b/test/known_issues/test-vm-proxy-failure-CP.js new file mode 100644 index 00000000000000..de644599b233b8 --- /dev/null +++ b/test/known_issues/test-vm-proxy-failure-CP.js @@ -0,0 +1,20 @@ +'use strict'; + +// Sandbox throws in CopyProperties() despite no code being run +// Issue: https://github.com/nodejs/node/issues/11902 + + +require('../common'); +const assert = require('assert'); +const vm = require('vm'); + +const handler = { + getOwnPropertyDescriptor: (target, prop) => { + throw new Error('whoops'); + } +}; +const sandbox = new Proxy({foo: 'bar'}, handler); +const context = vm.createContext(sandbox); + + +assert.doesNotThrow(() => vm.runInContext('', context)); diff --git a/test/parallel/test-vm-proxies.js b/test/parallel/test-vm-proxies.js index 25e16e8f5ccc55..266b212fb827b8 100644 --- a/test/parallel/test-vm-proxies.js +++ b/test/parallel/test-vm-proxies.js @@ -16,16 +16,3 @@ sandbox = { Proxy: Proxy }; vm.runInNewContext('this.Proxy = Proxy', sandbox); assert.strictEqual(typeof sandbox.Proxy, 'function'); assert.strictEqual(sandbox.Proxy, Proxy); - -// Handle a sandbox that throws while copying properties -assert.throws(() => { - const handler = { - getOwnPropertyDescriptor: (target, prop) => { - throw new Error('whoops'); - } - }; - const sandbox = new Proxy({foo: 'bar'}, handler); - const context = vm.createContext(sandbox); - - vm.runInContext('', context); -}, /whoops/); From 9dd918b0ab849ac5875187506348e0f8838c8d0f Mon Sep 17 00:00:00 2001 From: AnnaMag Date: Tue, 14 Mar 2017 22:53:13 +0000 Subject: [PATCH 079/151] test: fix assertion in vm test Prototypes are not strict equal when they are from different contexts. Therefore, assert.strictEqual() fails for objects that are created in different contexts, e.g., in vm.runInContext(). Instead of expecting the prototypes to be equal, only check the properties of the objects for equality. PR-URL: https://github.com/nodejs/node/pull/11862 Reviewed-By: Anna Henningsen Reviewed-By: James M Snell Reviewed-By: Colin Ihrig Reviewed-By: Franziska Hinkelmann --- test/known_issues/test-vm-getters.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/test/known_issues/test-vm-getters.js b/test/known_issues/test-vm-getters.js index f815e6d658351d..af27eeee644032 100644 --- a/test/known_issues/test-vm-getters.js +++ b/test/known_issues/test-vm-getters.js @@ -16,4 +16,9 @@ const context = vm.createContext(sandbox); const code = 'Object.getOwnPropertyDescriptor(this, "prop");'; const result = vm.runInContext(code, context); -assert.strictEqual(result, descriptor); +// Ref: https://github.com/nodejs/node/issues/11803 + +assert.deepStrictEqual(Object.keys(result), Object.keys(descriptor)); +for (const prop of Object.keys(result)) { + assert.strictEqual(result[prop], descriptor[prop]); +} From f8426d9177dea0c0f5bc377b58add082820f9574 Mon Sep 17 00:00:00 2001 From: mr-spd Date: Mon, 13 Mar 2017 17:38:32 +0100 Subject: [PATCH 080/151] lib: remove unused msg parameter in debug_agent Removed the msg parameter in the Client function of _debug_agent.js, because it is unused. PR-URL: https://github.com/nodejs/node/pull/11833 Reviewed-By: James M Snell Reviewed-By: Daniel Bevenius Reviewed-By: Gibson Fahnestock Reviewed-By: Colin Ihrig Reviewed-By: Yuta Hiroto Reviewed-By: Franziska Hinkelmann Reviewed-By: Jackson Tian --- lib/_debug_agent.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/_debug_agent.js b/lib/_debug_agent.js index eedca7ef5843bb..2eed3b60af22cc 100644 --- a/lib/_debug_agent.js +++ b/lib/_debug_agent.js @@ -103,7 +103,7 @@ function Client(agent, socket) { } util.inherits(Client, Transform); -Client.prototype.destroy = function destroy(msg) { +Client.prototype.destroy = function destroy() { this.socket.destroy(); this.emit('close'); From 331c0a8a26f8d94a8d7d9468b7f2e6055ee4a587 Mon Sep 17 00:00:00 2001 From: Vse Mozhet Byt Date: Sun, 12 Mar 2017 13:14:00 +0200 Subject: [PATCH 081/151] doc: console.log() -> console.error() in events.md MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit PR-URL: https://github.com/nodejs/node/pull/11810 Reviewed-By: Luigi Pinca Reviewed-By: Michaël Zasso Reviewed-By: Anna Henningsen Reviewed-By: Colin Ihrig Reviewed-By: Gibson Fahnestock Reviewed-By: James M Snell --- doc/api/events.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/api/events.md b/doc/api/events.md index aefcaec1a55f83..db35b0600f1ece 100644 --- a/doc/api/events.md +++ b/doc/api/events.md @@ -148,7 +148,7 @@ can be used. (_Note, however, that the `domain` module has been deprecated_) const myEmitter = new MyEmitter(); process.on('uncaughtException', (err) => { - console.log('whoops! there was an error'); + console.error('whoops! there was an error'); }); myEmitter.emit('error', new Error('whoops!')); @@ -160,7 +160,7 @@ As a best practice, listeners should always be added for the `'error'` events. ```js const myEmitter = new MyEmitter(); myEmitter.on('error', (err) => { - console.log('whoops! there was an error'); + console.error('whoops! there was an error'); }); myEmitter.emit('error', new Error('whoops!')); // Prints: whoops! there was an error From 8a521fe0dc37b9bacafa4d75ad538123b833ed35 Mon Sep 17 00:00:00 2001 From: Vse Mozhet Byt Date: Sun, 12 Mar 2017 13:11:13 +0200 Subject: [PATCH 082/151] doc: var -> let / const in events.md MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit PR-URL: https://github.com/nodejs/node/pull/11810 Reviewed-By: Luigi Pinca Reviewed-By: Michaël Zasso Reviewed-By: Anna Henningsen Reviewed-By: Colin Ihrig Reviewed-By: Gibson Fahnestock Reviewed-By: James M Snell --- doc/api/events.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/doc/api/events.md b/doc/api/events.md index db35b0600f1ece..8864e78d9fc4c7 100644 --- a/doc/api/events.md +++ b/doc/api/events.md @@ -98,7 +98,7 @@ listener will be invoked _every time_ the named event is emitted. ```js const myEmitter = new MyEmitter(); -var m = 0; +let m = 0; myEmitter.on('event', () => { console.log(++m); }); @@ -114,7 +114,7 @@ the listener is unregistered and *then* called. ```js const myEmitter = new MyEmitter(); -var m = 0; +let m = 0; myEmitter.once('event', () => { console.log(++m); }); @@ -491,7 +491,7 @@ Removes the specified `listener` from the listener array for the event named `eventName`. ```js -var callback = (stream) => { +const callback = (stream) => { console.log('someone connected!'); }; server.on('connection', callback); @@ -513,12 +513,12 @@ events will behave as expected. ```js const myEmitter = new MyEmitter(); -var callbackA = () => { +const callbackA = () => { console.log('A'); myEmitter.removeListener('event', callbackB); }; -var callbackB = () => { +const callbackB = () => { console.log('B'); }; From 463f29413b56d85d27dad0ac02f20e7f10333866 Mon Sep 17 00:00:00 2001 From: Alexander Date: Sat, 11 Mar 2017 23:26:50 +0300 Subject: [PATCH 083/151] doc: correct comment error in stream.md MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fix comment about remove listener (not setting) PR-URL: https://github.com/nodejs/node/pull/11804 Reviewed-By: Anna Henningsen Reviewed-By: James M Snell Reviewed-By: Luigi Pinca Reviewed-By: Colin Ihrig Reviewed-By: Michaël Zasso Reviewed-By: Brian White --- doc/api/stream.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/api/stream.md b/doc/api/stream.md index fb8e66dccbf795..c0628aa62572cb 100644 --- a/doc/api/stream.md +++ b/doc/api/stream.md @@ -1007,7 +1007,7 @@ function parseHeader(stream, callback) { const remaining = split.join('\n\n'); const buf = Buffer.from(remaining, 'utf8'); stream.removeListener('error', callback); - // set the readable listener before unshifting + // remove the readable listener before unshifting stream.removeListener('readable', onReadable); if (buf.length) stream.unshift(buf); From b8e3a5f1097f914800e8285f45a3a0588962d2b8 Mon Sep 17 00:00:00 2001 From: Gaara Date: Fri, 10 Mar 2017 10:52:43 +0800 Subject: [PATCH 084/151] doc: fix a typo in api/process.md Fix a mistyped module name in example REPL sessions found in the description of the 'warning' event: it should be `events` instead of `event`. PR-URL: https://github.com/nodejs/node/pull/11780 Reviewed-By: James M Snell Reviewed-By: Rich Trott Reviewed-By: Luigi Pinca Reviewed-By: Colin Ihrig --- doc/api/process.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/api/process.md b/doc/api/process.md index 36930992f199b5..808f71a3112e06 100644 --- a/doc/api/process.md +++ b/doc/api/process.md @@ -290,7 +290,7 @@ too many listeners have been added to an event ```txt $ node -> event.defaultMaxListeners = 1; +> events.defaultMaxListeners = 1; > process.on('foo', () => {}); > process.on('foo', () => {}); > (node:38638) Warning: Possible EventEmitter memory leak detected. 2 foo @@ -303,7 +303,7 @@ adds a custom handler to the `'warning'` event: ```txt $ node --no-warnings > var p = process.on('warning', (warning) => console.warn('Do not do that!')); -> event.defaultMaxListeners = 1; +> events.defaultMaxListeners = 1; > process.on('foo', () => {}); > process.on('foo', () => {}); > Do not do that! From c10a4a2a7a170ccbbe36ded21f38cc67e2eebaac Mon Sep 17 00:00:00 2001 From: Ruslan Bekenev Date: Sat, 25 Feb 2017 23:11:50 +0300 Subject: [PATCH 085/151] doc: add note that vm module is not a security mechanism the text added in this commit should warn users about wrong idea that vm module can be secure to run unsafe scripts in sandboxes PR-URL: https://github.com/nodejs/node/pull/11557 Reviewed-By: James M Snell Reviewed-By: Evan Lucas Reviewed-By: Colin Ihrig Reviewed-By: Ben Noordhuis --- doc/api/vm.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/doc/api/vm.md b/doc/api/vm.md index ffa50be84612df..3a98f59677866a 100644 --- a/doc/api/vm.md +++ b/doc/api/vm.md @@ -14,6 +14,9 @@ const vm = require('vm'); JavaScript code can be compiled and run immediately or compiled, saved, and run later. +*Note*: The vm module is not a security mechanism. +**Do not use it to run untrusted code**. + ## Class: vm.Script