From a6bd28772402e66f38d0a012ca9bdae96449f47e Mon Sep 17 00:00:00 2001 From: Gibson Fahnestock Date: Sun, 8 Jan 2017 13:19:00 +0000 Subject: [PATCH] test: use eslint to fix var->const/let Manually fix issues that eslint --fix couldn't do automatically. PR-URL: https://github.com/nodejs/node/pull/10685 Reviewed-By: Colin Ihrig Reviewed-By: James M Snell Reviewed-By: Roman Reiss --- test/addons/buffer-free-callback/test.js | 4 +- test/addons/load-long-path/test.js | 6 +- test/addons/make-callback-recurse/test.js | 2 +- test/addons/repl-domain-abort/test.js | 14 +- .../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 | 28 +-- test/debugger/test-debugger-repl-restart.js | 4 +- test/debugger/test-debugger-repl-term.js | 2 +- test/debugger/test-debugger-repl-utf8.js | 2 +- test/debugger/test-debugger-repl.js | 2 +- 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 | 7 +- test/inspector/inspector-helper.js | 4 +- .../test-dgram-multicast-multi-process.js | 19 +- .../test-dgram-send-cb-quelches-error.js | 6 +- test/internet/test-dns-cares-domains.js | 4 +- test/internet/test-dns.js | 96 +++++----- test/internet/test-net-connect-timeout.js | 8 +- test/internet/test-net-connect-unref.js | 5 +- .../internet/test-tls-connnect-melissadata.js | 2 +- .../test-url-parse-conformance.js | 8 +- test/message/eval_messages.js | 8 +- test/message/max_tick_depth.js | 2 +- test/message/stdin_messages.js | 8 +- .../test-assert-typedarray-deepequal.js | 2 +- test/parallel/test-assert.js | 31 ++-- .../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-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-child-process-constructor.js | 4 +- .../test-child-process-default-options.js | 4 +- .../test-child-process-double-pipe.js | 4 +- test/parallel/test-child-process-env.js | 6 +- 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 | 10 +- .../parallel/test-child-process-fork-close.js | 2 +- .../parallel/test-child-process-fork-dgram.js | 4 +- .../test-child-process-fork-exec-argv.js | 12 +- .../test-child-process-fork-exec-path.js | 8 +- test/parallel/test-child-process-fork-net.js | 32 ++-- test/parallel/test-child-process-fork-net2.js | 22 +-- test/parallel/test-child-process-fork-ref.js | 5 +- test/parallel/test-child-process-fork-ref2.js | 2 +- .../test-child-process-fork-regr-gh-2847.js | 6 +- test/parallel/test-child-process-fork.js | 4 +- test/parallel/test-child-process-internal.js | 8 +- ...test-child-process-send-returns-boolean.js | 2 +- .../test-child-process-set-blocking.js | 4 +- test/parallel/test-child-process-silent.js | 12 +- .../test-child-process-spawn-typeerror.js | 2 +- .../test-child-process-spawnsync-env.js | 4 +- .../test-child-process-spawnsync-input.js | 4 +- .../test-child-process-spawnsync-timeout.js | 10 +- test/parallel/test-child-process-stdin-ipc.js | 2 +- .../test-child-process-stdio-big-write-end.js | 3 +- .../test-child-process-stdio-inherit.js | 6 +- test/parallel/test-cli-eval.js | 4 +- test/parallel/test-cli-syntax.js | 20 +- test/parallel/test-cluster-basic.js | 5 +- .../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 | 2 +- test/parallel/test-cluster-disconnect.js | 16 +- test/parallel/test-cluster-eaccess.js | 2 +- test/parallel/test-cluster-eaddrinuse.js | 4 +- test/parallel/test-cluster-fork-env.js | 4 +- test/parallel/test-cluster-master-error.js | 10 +- test/parallel/test-cluster-master-kill.js | 4 +- test/parallel/test-cluster-message.js | 14 +- .../parallel/test-cluster-rr-domain-listen.js | 5 +- test/parallel/test-cluster-send-deadlock.js | 10 +- .../test-cluster-setup-master-argv.js | 4 +- .../test-cluster-setup-master-multiple.js | 4 +- test/parallel/test-cluster-setup-master.js | 12 +- test/parallel/test-cluster-shared-leak.js | 4 +- test/parallel/test-cluster-worker-death.js | 2 +- test/parallel/test-cluster-worker-destroy.js | 2 +- test/parallel/test-cluster-worker-events.js | 10 +- .../test-cluster-worker-forced-exit.js | 2 +- .../test-cluster-worker-isconnected.js | 2 +- test/parallel/test-cluster-worker-isdead.js | 2 +- test/parallel/test-cluster-worker-no-exit.js | 10 +- .../test-cluster-worker-wait-server-close.js | 8 +- test/parallel/test-console-instance.js | 4 +- .../test-console-not-call-toString.js | 4 +- test/parallel/test-crypto-binary-default.js | 118 ++++++------ test/parallel/test-crypto-certificate.js | 8 +- test/parallel/test-crypto-dh-odd-key.js | 4 +- test/parallel/test-crypto-dh.js | 63 +++---- test/parallel/test-crypto-domain.js | 6 +- test/parallel/test-crypto-domains.js | 4 +- test/parallel/test-crypto-fips.js | 4 +- test/parallel/test-crypto-from-binary.js | 6 +- test/parallel/test-crypto-hash.js | 32 ++-- test/parallel/test-crypto-hmac.js | 10 +- test/parallel/test-crypto-rsa-dsa.js | 4 +- test/parallel/test-crypto-sign-verify.js | 4 +- test/parallel/test-crypto-stream.js | 2 +- test/parallel/test-crypto-verify-failure.js | 6 +- test/parallel/test-cwd-enoent-repl.js | 4 +- test/parallel/test-cwd-enoent.js | 4 +- test/parallel/test-debug-brk.js | 14 +- test/parallel/test-debug-port-from-cmdline.js | 16 +- test/parallel/test-debug-signal-cluster.js | 8 +- .../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-dgram-address.js | 14 +- test/parallel/test-dgram-bind.js | 4 +- test/parallel/test-dgram-bytes-length.js | 4 +- .../test-dgram-close-is-not-callback.js | 4 +- test/parallel/test-dgram-close.js | 6 +- .../test-dgram-exclusive-implicit-bind.js | 7 +- test/parallel/test-dgram-implicit-bind.js | 6 +- test/parallel/test-dgram-listen-after-bind.js | 6 +- test/parallel/test-dgram-oob-buffer.js | 4 +- test/parallel/test-dgram-regress-4496.js | 2 +- .../parallel/test-dgram-send-bad-arguments.js | 6 +- test/parallel/test-dgram-send-empty-array.js | 2 +- test/parallel/test-dgram-send-empty-buffer.js | 2 +- test/parallel/test-dgram-setTTL.js | 2 +- test/parallel/test-dgram-unref.js | 2 +- test/parallel/test-dh-padding.js | 10 +- test/parallel/test-dns-lookup-cb-error.js | 2 +- .../parallel/test-domain-abort-on-uncaught.js | 6 +- test/parallel/test-domain-enter-exit.js | 6 +- .../test-domain-exit-dispose-again.js | 6 +- test/parallel/test-domain-exit-dispose.js | 4 +- test/parallel/test-domain-http-server.js | 22 +-- test/parallel/test-domain-implicit-fs.js | 2 +- test/parallel/test-domain-multi.js | 16 +- test/parallel/test-domain-nested-throw.js | 20 +- test/parallel/test-domain-safe-exit.js | 4 +- test/parallel/test-domain-stack.js | 6 +- ...n-throw-from-uncaught-exception-handler.js | 2 +- test/parallel/test-domain-timers.js | 8 +- ...st-domain-top-level-error-handler-throw.js | 10 +- ...domain-with-abort-on-uncaught-exception.js | 10 +- test/parallel/test-domain.js | 28 +-- test/parallel/test-dsa-fips-invalid-key.js | 6 +- test/parallel/test-error-reporting.js | 4 +- ...test-event-emitter-check-listener-leaks.js | 2 +- test/parallel/test-event-emitter-errors.js | 2 +- .../test-event-emitter-get-max-listeners.js | 4 +- ...st-event-emitter-listeners-side-effects.js | 4 +- .../test-event-emitter-method-names.js | 2 +- ...mitter-no-error-provided-to-error-event.js | 4 +- test/parallel/test-event-emitter-num-args.js | 2 +- 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 | 2 +- test/parallel/test-event-emitter-subclass.js | 6 +- test/parallel/test-exception-handler.js | 2 +- 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 | 2 +- test/parallel/test-fs-chmod.js | 2 +- test/parallel/test-fs-exists.js | 2 +- test/parallel/test-fs-long-path.js | 6 +- test/parallel/test-fs-open-flags.js | 14 +- .../test-fs-read-buffer-tostring-fail.js | 4 +- test/parallel/test-fs-read-stream-fd-leak.js | 6 +- 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-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 | 20 +- test/parallel/test-fs-stat.js | 2 +- .../test-fs-symlink-dir-junction-relative.js | 14 +- test/parallel/test-fs-symlink.js | 4 +- test/parallel/test-fs-sync-fd-leak.js | 4 +- test/parallel/test-fs-truncate-GH-6233.js | 2 +- 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 | 4 +- .../test-fs-write-stream-change-open.js | 2 +- test/parallel/test-fs-write-stream-err.js | 10 +- test/parallel/test-fs-write-stream.js | 2 +- test/parallel/test-fs-write-string-coerce.js | 6 +- test/parallel/test-global-console-exists.js | 2 +- test/parallel/test-http-1.0-keep-alive.js | 12 +- test/parallel/test-http-1.0.js | 10 +- test/parallel/test-http-abort-before-end.js | 4 +- test/parallel/test-http-abort-client.js | 2 +- test/parallel/test-http-abort-queued.js | 12 +- test/parallel/test-http-after-connect.js | 4 +- .../test-http-agent-destroyed-socket.js | 16 +- .../parallel/test-http-agent-error-on-idle.js | 14 +- test/parallel/test-http-agent-false.js | 6 +- ...test-http-agent-maxsockets-regress-4050.js | 4 +- test/parallel/test-http-agent-maxsockets.js | 8 +- test/parallel/test-http-agent-no-protocol.js | 4 +- test/parallel/test-http-agent-null.js | 4 +- test/parallel/test-http-agent.js | 12 +- test/parallel/test-http-automatic-headers.js | 4 +- test/parallel/test-http-blank-header.js | 4 +- test/parallel/test-http-buffer-sanity.js | 16 +- test/parallel/test-http-byteswritten.js | 10 +- test/parallel/test-http-chunked.js | 24 +-- test/parallel/test-http-client-abort-event.js | 4 +- test/parallel/test-http-client-abort.js | 10 +- test/parallel/test-http-client-abort2.js | 4 +- test/parallel/test-http-client-agent.js | 14 +- .../test-http-client-default-headers-exist.js | 10 +- test/parallel/test-http-client-get-url.js | 2 +- test/parallel/test-http-client-parse-error.js | 6 +- test/parallel/test-http-client-pipe-end.js | 4 +- test/parallel/test-http-client-race-2.js | 24 +-- test/parallel/test-http-client-race.js | 16 +- .../test-http-client-read-in-error.js | 6 +- test/parallel/test-http-client-readable.js | 4 +- .../test-http-client-response-domain.js | 6 +- .../test-http-client-timeout-agent.js | 10 +- .../test-http-client-timeout-option.js | 8 +- .../test-http-client-timeout-with-data.js | 2 +- test/parallel/test-http-client-timeout.js | 8 +- test/parallel/test-http-client-upload-buf.js | 8 +- test/parallel/test-http-client-upload.js | 6 +- test/parallel/test-http-conn-reset.js | 6 +- test/parallel/test-http-connect-req-res.js | 4 +- test/parallel/test-http-content-length.js | 14 +- test/parallel/test-http-contentLength0.js | 4 +- test/parallel/test-http-date-header.js | 8 +- test/parallel/test-http-default-encoding.js | 6 +- .../test-http-destroyed-socket-write2.js | 4 +- test/parallel/test-http-eof-on-connect.js | 2 +- test/parallel/test-http-exceptions.js | 6 +- test/parallel/test-http-expect-continue.js | 16 +- test/parallel/test-http-extra-response.js | 10 +- .../test-http-flush-response-headers.js | 2 +- test/parallel/test-http-flush.js | 2 +- test/parallel/test-http-full-response.js | 16 +- .../test-http-get-pipeline-problem.js | 26 +-- test/parallel/test-http-head-request.js | 6 +- ...test-http-head-response-has-no-body-end.js | 4 +- .../test-http-head-response-has-no-body.js | 4 +- test/parallel/test-http-header-read.js | 6 +- test/parallel/test-http-hex-write.js | 4 +- .../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 | 14 +- test/parallel/test-http-keepalive-client.js | 16 +- .../test-http-keepalive-maxsockets.js | 12 +- test/parallel/test-http-keepalive-request.js | 16 +- .../test-http-localaddress-bind-error.js | 4 +- test/parallel/test-http-localaddress.js | 14 +- test/parallel/test-http-malformed-request.js | 8 +- .../test-http-many-ended-pipelines.js | 13 +- test/parallel/test-http-max-headers-count.js | 26 +-- test/parallel/test-http-multi-line-headers.js | 6 +- test/parallel/test-http-no-content-length.js | 4 +- test/parallel/test-http-outgoing-finish.js | 10 +- test/parallel/test-http-parser-bad-ref.js | 20 +- test/parallel/test-http-parser-free.js | 12 +- test/parallel/test-http-parser.js | 32 ++-- test/parallel/test-http-pause.js | 12 +- test/parallel/test-http-pipe-fs.js | 10 +- 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 | 16 +- test/parallel/test-http-raw-headers.js | 18 +- .../test-http-remove-header-stays-removed.js | 4 +- ...test-http-request-dont-override-options.js | 6 +- test/parallel/test-http-request-end-twice.js | 4 +- test/parallel/test-http-request-end.js | 6 +- test/parallel/test-http-request-methods.js | 6 +- .../parallel/test-http-res-write-after-end.js | 4 +- ...test-http-res-write-end-dont-take-array.js | 4 +- test/parallel/test-http-response-close.js | 2 +- ...test-http-response-multi-content-length.js | 2 +- .../test-http-response-multiheaders.js | 4 +- .../parallel/test-http-response-no-headers.js | 14 +- test/parallel/test-http-response-readable.js | 2 +- test/parallel/test-http-response-splitting.js | 2 +- .../test-http-response-status-message.js | 16 +- .../parallel/test-http-response-statuscode.js | 2 +- .../parallel/test-http-server-client-error.js | 2 +- .../parallel/test-http-server-multiheaders.js | 2 +- .../test-http-server-multiheaders2.js | 8 +- test/parallel/test-http-server-stale-close.js | 4 +- test/parallel/test-http-server-unconsume.js | 6 +- test/parallel/test-http-server.js | 16 +- test/parallel/test-http-set-cookies.js | 4 +- test/parallel/test-http-set-timeout-server.js | 62 +++---- test/parallel/test-http-set-timeout.js | 6 +- test/parallel/test-http-set-trailers.js | 14 +- test/parallel/test-http-should-keep-alive.js | 12 +- test/parallel/test-http-status-code.js | 12 +- test/parallel/test-http-status-message.js | 8 +- test/parallel/test-http-timeout-overflow.js | 8 +- test/parallel/test-http-timeout.js | 8 +- test/parallel/test-http-unix-socket.js | 4 +- test/parallel/test-http-upgrade-agent.js | 16 +- test/parallel/test-http-upgrade-client.js | 10 +- test/parallel/test-http-upgrade-client2.js | 10 +- test/parallel/test-http-upgrade-server.js | 20 +- test/parallel/test-http-upgrade-server2.js | 4 +- ...p-url.parse-auth-with-header-in-request.js | 5 +- test/parallel/test-http-url.parse-auth.js | 4 +- test/parallel/test-http-url.parse-basic.js | 6 +- .../test-http-url.parse-https.request.js | 8 +- test/parallel/test-http-url.parse-path.js | 4 +- test/parallel/test-http-url.parse-post.js | 4 +- test/parallel/test-http-url.parse-search.js | 4 +- test/parallel/test-http-wget.js | 6 +- test/parallel/test-http-write-callbacks.js | 16 +- test/parallel/test-http-write-empty-string.js | 4 +- test/parallel/test-http-write-head.js | 4 +- test/parallel/test-http-zero-length-write.js | 20 +- test/parallel/test-http.js | 8 +- .../test-https-agent-disable-session-reuse.js | 4 +- test/parallel/test-https-agent-servername.js | 4 +- test/parallel/test-https-agent-sni.js | 6 +- test/parallel/test-https-agent.js | 6 +- test/parallel/test-https-byteswritten.js | 6 +- .../test-https-client-checkServerIdentity.js | 10 +- test/parallel/test-https-client-get-url.js | 4 +- test/parallel/test-https-client-reject.js | 14 +- test/parallel/test-https-client-resume.js | 12 +- test/parallel/test-https-close.js | 14 +- .../parallel/test-https-connecting-to-http.js | 4 +- test/parallel/test-https-drain.js | 16 +- test/parallel/test-https-eof-for-eom.js | 6 +- test/parallel/test-https-foafssl.js | 26 +-- test/parallel/test-https-host-headers.js | 2 +- .../test-https-localaddress-bind-error.js | 6 +- test/parallel/test-https-localaddress.js | 8 +- test/parallel/test-https-pfx.js | 8 +- test/parallel/test-https-req-split.js | 6 +- .../parallel/test-https-resume-after-renew.js | 15 +- .../parallel/test-https-set-timeout-server.js | 40 ++-- test/parallel/test-https-socket-options.js | 12 +- test/parallel/test-https-timeout-server-2.js | 6 +- test/parallel/test-icu-transcode.js | 2 +- test/parallel/test-listen-fd-cluster.js | 10 +- .../test-listen-fd-detached-inherit.js | 12 +- test/parallel/test-listen-fd-detached.js | 12 +- test/parallel/test-listen-fd-server.js | 8 +- test/parallel/test-memory-usage-emfile.js | 4 +- test/parallel/test-memory-usage.js | 2 +- ...test-microtask-queue-integration-domain.js | 8 +- .../test-microtask-queue-integration.js | 8 +- .../test-microtask-queue-run-domain.js | 4 +- ...st-microtask-queue-run-immediate-domain.js | 4 +- .../test-microtask-queue-run-immediate.js | 4 +- test/parallel/test-microtask-queue-run.js | 4 +- .../test-module-globalpaths-nodepath.js | 4 +- test/parallel/test-module-loading-error.js | 4 +- test/parallel/test-net-after-close.js | 4 +- .../test-net-better-error-messages-path.js | 4 +- test/parallel/test-net-binary.js | 10 +- test/parallel/test-net-bind-twice.js | 4 +- test/parallel/test-net-buffersize.js | 8 +- test/parallel/test-net-bytes-stats.js | 10 +- test/parallel/test-net-can-reset-timeout.js | 4 +- test/parallel/test-net-connect-buffer.js | 16 +- test/parallel/test-net-connect-local-error.js | 2 +- .../parallel/test-net-connect-options-ipv6.js | 6 +- test/parallel/test-net-connect-options.js | 4 +- test/parallel/test-net-create-connection.js | 4 +- test/parallel/test-net-dns-custom-lookup.js | 4 +- test/parallel/test-net-dns-error.js | 4 +- test/parallel/test-net-dns-lookup-skip.js | 4 +- test/parallel/test-net-dns-lookup.js | 2 +- test/parallel/test-net-during-close.js | 4 +- test/parallel/test-net-eaddrinuse.js | 4 +- test/parallel/test-net-end-without-connect.js | 2 +- test/parallel/test-net-error-twice.js | 8 +- test/parallel/test-net-internal.js | 2 +- test/parallel/test-net-keepalive.js | 6 +- test/parallel/test-net-large-string.js | 12 +- ...n-close-server-callback-is-not-function.js | 2 +- test/parallel/test-net-listen-close-server.js | 2 +- test/parallel/test-net-listen-error.js | 2 +- .../test-net-listen-exclusive-random-ports.js | 6 +- test/parallel/test-net-listen-shared-ports.js | 8 +- test/parallel/test-net-local-address-port.js | 5 +- test/parallel/test-net-localport.js | 4 +- .../test-net-pause-resume-connecting.js | 2 +- .../parallel/test-net-persistent-keepalive.js | 8 +- test/parallel/test-net-persistent-nodelay.js | 14 +- .../parallel/test-net-persistent-ref-unref.js | 12 +- test/parallel/test-net-pingpong.js | 6 +- test/parallel/test-net-pipe-connect-errors.js | 8 +- test/parallel/test-net-reconnect.js | 12 +- test/parallel/test-net-remote-address-port.js | 12 +- test/parallel/test-net-server-bind.js | 24 +-- test/parallel/test-net-server-close.js | 6 +- test/parallel/test-net-server-connections.js | 2 +- .../test-net-server-listen-remove-callback.js | 4 +- ...-connections-close-makes-more-available.js | 16 +- .../test-net-server-max-connections.js | 6 +- .../test-net-server-pause-on-connect.js | 4 +- .../test-net-server-unref-persistent.js | 2 +- test/parallel/test-net-server-unref.js | 2 +- .../parallel/test-net-socket-destroy-twice.js | 2 +- .../parallel/test-net-socket-local-address.js | 6 +- .../parallel/test-net-socket-timeout-unref.js | 2 +- test/parallel/test-net-stream.js | 14 +- test/parallel/test-net-write-after-close.js | 4 +- test/parallel/test-net-write-connect-write.js | 6 +- test/parallel/test-net-write-slow.js | 16 +- test/parallel/test-next-tick-domain.js | 2 +- .../test-next-tick-intentional-starvation.js | 10 +- test/parallel/test-next-tick-ordering.js | 6 +- test/parallel/test-next-tick-ordering2.js | 2 +- test/parallel/test-next-tick.js | 2 +- test/parallel/test-no-enter-tickcallback.js | 4 +- test/parallel/test-path-makelong.js | 4 +- test/parallel/test-path-parse-format.js | 2 +- test/parallel/test-path.js | 4 +- test/parallel/test-pipe-address.js | 2 +- test/parallel/test-pipe-return-val.js | 6 +- test/parallel/test-pipe-stream.js | 10 +- test/parallel/test-pipe-unref.js | 2 +- test/parallel/test-preload.js | 6 +- test/parallel/test-process-argv-0.js | 4 +- test/parallel/test-process-config.js | 4 +- test/parallel/test-process-exec-argv.js | 8 +- test/parallel/test-process-exit-code.js | 6 +- test/parallel/test-process-exit-recursive.js | 2 +- test/parallel/test-process-exit.js | 2 +- .../parallel/test-process-getactivehandles.js | 2 +- test/parallel/test-process-getgroups.js | 6 +- test/parallel/test-process-kill-null.js | 4 +- test/parallel/test-process-kill-pid.js | 6 +- test/parallel/test-process-next-tick.js | 4 +- test/parallel/test-process-raw-debug.js | 6 +- ...est-process-remove-all-signal-listeners.js | 2 +- test/parallel/test-process-versions.js | 4 +- test/parallel/test-process-wrap.js | 16 +- .../test-promises-unhandled-rejections.js | 161 ++++++++-------- ...promises-warning-on-unhandled-rejection.js | 2 +- .../test-querystring-maxKeys-non-finite.js | 6 +- test/parallel/test-querystring.js | 20 +- 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 | 12 +- .../test-readline-undefined-columns.js | 2 +- test/parallel/test-readuint.js | 6 +- test/parallel/test-regress-GH-1531.js | 4 +- test/parallel/test-regress-GH-1899.js | 4 +- test/parallel/test-regress-GH-2245.js | 2 +- test/parallel/test-regress-GH-3542.js | 2 +- test/parallel/test-regress-GH-3739.js | 4 +- test/parallel/test-regress-GH-4948.js | 10 +- test/parallel/test-regress-GH-5927.js | 8 +- test/parallel/test-regress-GH-746.js | 2 +- test/parallel/test-regress-GH-7511.js | 4 +- test/parallel/test-regress-GH-819.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 | 6 +- test/parallel/test-repl-console.js | 2 +- test/parallel/test-repl-definecommand.js | 2 +- test/parallel/test-repl-end-emits-exit.js | 4 +- test/parallel/test-repl-harmony.js | 10 +- 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 | 7 +- test/parallel/test-repl-tab-complete.js | 6 +- test/parallel/test-repl-tab.js | 5 +- .../test-repl-unexpected-token-recoverable.js | 10 +- test/parallel/test-sigint-infinite-loop.js | 4 +- test/parallel/test-signal-handler.js | 2 +- test/parallel/test-signal-safety.js | 6 +- .../test-socket-write-after-fin-error.js | 14 +- test/parallel/test-socket-write-after-fin.js | 8 +- test/parallel/test-stdin-pipe-resume.js | 6 +- test/parallel/test-stdin-script-child.js | 2 +- ...out-cannot-be-closed-child-process-pipe.js | 6 +- test/parallel/test-stdout-stderr-reading.js | 12 +- 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 | 6 +- test/parallel/test-stream-push-order.js | 8 +- test/parallel/test-stream-push-strings.js | 8 +- ...stream-readable-constructor-set-methods.js | 4 +- .../test-stream-readable-flow-recursion.js | 10 +- ...tream-transform-constructor-set-methods.js | 6 +- .../test-stream-transform-flush-data.js | 2 +- .../test-stream-transform-split-objectmode.js | 8 +- .../test-stream-unshift-empty-chunk.js | 16 +- test/parallel/test-stream-wrap.js | 6 +- ...stream-writable-change-default-encoding.js | 8 +- ...stream-writable-constructor-set-methods.js | 10 +- test/parallel/test-stream-writable-null.js | 12 +- test/parallel/test-stream-writev.js | 22 +-- ...est-stream2-base64-single-char-read-end.js | 11 +- test/parallel/test-stream2-compatibility.js | 6 +- test/parallel/test-stream2-decode-partial.js | 2 +- test/parallel/test-stream2-finish-pipe.js | 4 +- .../test-stream2-httpclient-response-end.js | 6 +- .../parallel/test-stream2-large-read-stall.js | 17 +- test/parallel/test-stream2-objects.js | 82 ++++----- .../test-stream2-pipe-error-once-listener.js | 8 +- test/parallel/test-stream2-push.js | 20 +- test/parallel/test-stream2-read-sync-stack.js | 8 +- ...st-stream2-readable-empty-buffer-no-eof.js | 8 +- .../test-stream2-readable-from-list.js | 20 +- .../test-stream2-readable-legacy-drain.js | 12 +- .../test-stream2-readable-non-empty-end.js | 20 +- .../test-stream2-readable-wrap-empty.js | 4 +- test/parallel/test-stream2-set-encoding.js | 78 ++++---- test/parallel/test-stream2-transform.js | 68 +++---- test/parallel/test-stream2-unpipe-leak.js | 8 +- test/parallel/test-stream2-writable.js | 89 ++++----- test/parallel/test-stream3-cork-end.js | 18 +- test/parallel/test-stream3-cork-uncork.js | 18 +- test/parallel/test-stream3-pause-then-read.js | 36 ++-- test/parallel/test-string-decoder-end.js | 18 +- test/parallel/test-string-decoder.js | 22 +-- test/parallel/test-stringbytes-external.js | 28 +-- test/parallel/test-sync-io-option.js | 6 +- test/parallel/test-tcp-wrap-connect.js | 22 +-- test/parallel/test-tcp-wrap.js | 10 +- test/parallel/test-timers-active.js | 4 +- test/parallel/test-timers-clearImmediate.js | 4 +- test/parallel/test-timers-immediate-queue.js | 2 +- test/parallel/test-timers-immediate.js | 3 +- test/parallel/test-timers-nested.js | 2 +- ...imeout-removes-other-socket-unref-timer.js | 2 +- test/parallel/test-timers-unref-active.js | 4 +- test/parallel/test-timers-unref-call.js | 6 +- test/parallel/test-timers-unref-leak.js | 8 +- ...emove-other-unref-timers-only-one-fires.js | 2 +- test/parallel/test-timers-unref.js | 4 +- ...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 | 12 +- test/parallel/test-tls-alpn-server-client.js | 76 ++++---- .../test-tls-async-cb-after-socket-end.js | 14 +- test/parallel/test-tls-cert-regression.js | 6 +- test/parallel/test-tls-cipher-list.js | 2 +- test/parallel/test-tls-client-abort.js | 6 +- test/parallel/test-tls-client-abort2.js | 2 +- .../test-tls-client-default-ciphers.js | 2 +- test/parallel/test-tls-client-destroy-soon.js | 12 +- .../test-tls-client-getephemeralkeyinfo.js | 18 +- test/parallel/test-tls-client-mindhsize.js | 16 +- test/parallel/test-tls-client-resume.js | 12 +- test/parallel/test-tls-client-verify.js | 2 +- test/parallel/test-tls-close-error.js | 4 +- test/parallel/test-tls-close-notify.js | 4 +- test/parallel/test-tls-connect-no-host.js | 6 +- test/parallel/test-tls-connect-pipe.js | 8 +- .../test-tls-connect-stream-writes.js | 33 ++-- .../parallel/test-tls-delayed-attach-error.js | 10 +- test/parallel/test-tls-delayed-attach.js | 12 +- test/parallel/test-tls-dhe.js | 26 +-- test/parallel/test-tls-ecdh-disable.js | 6 +- test/parallel/test-tls-econnreset.js | 16 +- test/parallel/test-tls-env-bad-extra-ca.js | 4 +- test/parallel/test-tls-fast-writing.js | 20 +- .../test-tls-friendly-error-message.js | 2 +- test/parallel/test-tls-handshake-error.js | 4 +- test/parallel/test-tls-honorcipherorder.js | 16 +- test/parallel/test-tls-inception.js | 2 +- test/parallel/test-tls-invoke-queued.js | 6 +- test/parallel/test-tls-js-stream.js | 14 +- test/parallel/test-tls-legacy-onselect.js | 4 +- test/parallel/test-tls-max-send-fragment.js | 10 +- test/parallel/test-tls-multi-key.js | 10 +- test/parallel/test-tls-no-rsa-key.js | 6 +- test/parallel/test-tls-npn-server-client.js | 8 +- test/parallel/test-tls-over-http-tunnel.js | 16 +- test/parallel/test-tls-pause.js | 16 +- .../test-tls-peer-certificate-encoding.js | 8 +- .../test-tls-peer-certificate-multi-keys.js | 8 +- test/parallel/test-tls-pfx-gh-5100-regr.js | 2 +- test/parallel/test-tls-request-timeout.js | 6 +- test/parallel/test-tls-securepair-fiftharg.js | 2 +- test/parallel/test-tls-securepair-server.js | 22 +-- test/parallel/test-tls-session-cache.js | 8 +- test/parallel/test-tls-set-ciphers.js | 2 +- test/parallel/test-tls-sni-option.js | 14 +- test/parallel/test-tls-sni-server-client.js | 14 +- test/parallel/test-tls-wrap-timeout.js | 4 +- test/parallel/test-umask.js | 4 +- test/parallel/test-url.js | 22 +-- test/parallel/test-util-inspect.js | 80 ++++---- test/parallel/test-util-log.js | 6 +- test/parallel/test-v8-stats.js | 4 +- test/parallel/test-vm-basic.js | 12 +- test/parallel/test-vm-context-async-script.js | 4 +- .../test-vm-context-property-forwarding.js | 4 +- test/parallel/test-vm-context.js | 12 +- .../test-vm-create-and-run-in-context.js | 6 +- .../test-vm-create-context-accessors.js | 6 +- test/parallel/test-vm-create-context-arg.js | 2 +- ...st-vm-create-context-circular-reference.js | 2 +- test/parallel/test-vm-cross-context.js | 2 +- test/parallel/test-vm-function-declaration.js | 6 +- .../test-vm-global-define-property.js | 8 +- test/parallel/test-vm-global-identity.js | 6 +- test/parallel/test-vm-harmony-symbols.js | 2 +- test/parallel/test-vm-is-context.js | 2 +- .../test-vm-new-script-new-context.js | 6 +- .../test-vm-new-script-this-context.js | 2 +- test/parallel/test-vm-proxies.js | 2 +- test/parallel/test-vm-run-in-new-context.js | 6 +- test/parallel/test-vm-static-this.js | 11 +- test/parallel/test-vm-syntax-error-message.js | 4 +- test/parallel/test-vm-timeout.js | 2 +- test/parallel/test-whatwg-url-searchparams.js | 2 +- test/parallel/test-whatwg-url-setters.js | 2 +- 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 | 4 +- .../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 | 2 +- test/pummel/test-crypto-dh.js | 18 +- test/pummel/test-dh-regr.js | 4 +- test/pummel/test-dtrace-jsstack.js | 26 +-- test/pummel/test-exec.js | 16 +- test/pummel/test-fs-watch-file-slow.js | 6 +- test/pummel/test-fs-watch-file.js | 24 +-- test/pummel/test-fs-watch-non-recursive.js | 8 +- test/pummel/test-http-client-reconnect-bug.js | 6 +- .../test-http-many-keep-alive-connections.js | 12 +- test/pummel/test-http-upload-timeout.js | 6 +- test/pummel/test-https-ci-reneg-attack.js | 20 +- test/pummel/test-https-large-response.js | 8 +- test/pummel/test-https-no-reader.js | 10 +- test/pummel/test-net-connect-econnrefused.js | 13 +- test/pummel/test-net-connect-memleak.js | 6 +- test/pummel/test-net-many-clients.js | 18 +- test/pummel/test-net-pause.js | 8 +- test/pummel/test-net-pingpong-delay.js | 12 +- test/pummel/test-net-pingpong.js | 14 +- test/pummel/test-net-throttle.js | 12 +- test/pummel/test-net-timeout.js | 14 +- test/pummel/test-net-timeout2.js | 10 +- test/pummel/test-net-write-callbacks.js | 14 +- test/pummel/test-next-tick-infinite-calls.js | 2 +- test/pummel/test-process-hrtime.js | 6 +- test/pummel/test-process-uptime.js | 4 +- test/pummel/test-regress-GH-814.js | 16 +- test/pummel/test-regress-GH-814_2.js | 16 +- test/pummel/test-regress-GH-892.js | 20 +- test/pummel/test-stream-pipe-multi.js | 24 +-- test/pummel/test-stream2-basic.js | 172 +++++++++--------- test/pummel/test-timer-wrap.js | 6 +- test/pummel/test-timer-wrap2.js | 2 +- test/pummel/test-timers.js | 30 +-- test/pummel/test-tls-ci-reneg-attack.js | 18 +- test/pummel/test-tls-connect-memleak.js | 6 +- test/pummel/test-tls-securepair-client.js | 28 +-- test/pummel/test-tls-server-large-request.js | 10 +- test/pummel/test-tls-session-timeout.js | 38 ++-- test/pummel/test-tls-throttle.js | 12 +- test/pummel/test-vm-memleak.js | 12 +- .../sequential/test-child-process-execsync.js | 23 +-- test/sequential/test-debugger-debug-brk.js | 4 +- 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 | 8 +- test/sequential/test-net-GH-5504.js | 10 +- test/sequential/test-regress-GH-1697.js | 10 +- test/sequential/test-regress-GH-1726.js | 6 +- test/sequential/test-regress-GH-4015.js | 4 +- test/sequential/test-regress-GH-4027.js | 2 +- test/sequential/test-regress-GH-784.js | 16 +- test/sequential/test-regress-GH-877.js | 20 +- test/sequential/test-repl-timeout-throw.js | 6 +- .../test-require-cache-without-stat.js | 10 +- test/sequential/test-stream2-fs.js | 12 +- test/sequential/test-stream2-stderr-sync.js | 10 +- .../test-timers-blocking-callback.js | 6 +- test/sequential/test-vm-timeout-rethrow.js | 12 +- test/timers/test-timers-reliability.js | 10 +- 732 files changed, 3393 insertions(+), 3374 deletions(-) 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/load-long-path/test.js b/test/addons/load-long-path/test.js index ea0783331b058f..73d85a75a097a2 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,7 +28,7 @@ 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 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 1f30f0f9beae54..95536f99711324 100644 --- a/test/addons/repl-domain-abort/test.js +++ b/test/addons/repl-domain-abort/test.js @@ -4,27 +4,27 @@ const assert = require('assert'); const repl = require('repl'); const stream = require('stream'); const path = require('path'); -var buildType = process.config.target_defaults.default_configuration; -var buildPath = path.join(__dirname, 'build', buildType, 'binding'); +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 5ee9a5ce314793..05ef4c9d682c0d 100644 --- a/test/common.js +++ b/test/common.js @@ -209,7 +209,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 d6c3e5ca9e609a..38c65a03fa590d 100644 --- a/test/debugger/helper-debugger-repl.js +++ b/test/debugger/helper-debugger-repl.js @@ -4,12 +4,12 @@ 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-repl-restart.js b/test/debugger/test-debugger-repl-restart.js index 7dbef4288a6f44..f5de9f5ee95778 100644 --- a/test/debugger/test-debugger-repl-restart.js +++ b/test/debugger/test-debugger-repl-restart.js @@ -3,13 +3,13 @@ require('../common'); 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 8c44372f681672..4932df12e713bb 100644 --- a/test/debugger/test-debugger-repl-term.js +++ b/test/debugger/test-debugger-repl-term.js @@ -6,7 +6,7 @@ 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 1af75840f5a6cf..90214158884371 100644 --- a/test/debugger/test-debugger-repl-utf8.js +++ b/test/debugger/test-debugger-repl-utf8.js @@ -1,6 +1,6 @@ 'use strict'; const common = require('../common'); -var script = common.fixturesDir + '/breakpoints_utf8.js'; +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 0725348e56e477..32dbfa22c0d3a9 100644 --- a/test/debugger/test-debugger-repl.js +++ b/test/debugger/test-debugger-repl.js @@ -4,7 +4,7 @@ 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..b8ea8e2089c439 100644 --- a/test/gc/test-net-timeout.js +++ b/test/gc/test-net-timeout.js @@ -7,14 +7,13 @@ require('../common'); function serverHandler(sock) { sock.setTimeout(120000); sock.resume(); - var timer; sock.on('close', function() { clearTimeout(timer); }); sock.on('error', function(err) { assert.strictEqual(err.code, 'ECONNRESET'); }); - timer = setTimeout(function() { + const timer = setTimeout(function() { sock.end('hello\n'); }, 100); } @@ -29,7 +28,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 +49,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 de6bf874ed874c..46f47a5982977e 100644 --- a/test/internet/test-dgram-multicast-multi-process.js +++ b/test/internet/test-dgram-multicast-multi-process.js @@ -13,6 +13,7 @@ const messages = [ ]; const workers = {}; const listeners = 3; +let listening, sendSocket, done, timer, dead; // Skip test in FreeBSD jails. @@ -76,10 +77,10 @@ function launchChildProcess(index) { 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 +111,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 +128,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 e20c8e107081cd..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'; const common = require('../common'); -var mustCall = common.mustCall; +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 61ac679274d8b3..5328d7e3d97925 100644 --- a/test/internet/test-dns-cares-domains.js +++ b/test/internet/test-dns-cares-domains.js @@ -4,7 +4,7 @@ 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.js b/test/internet/test-dns.js index be3f9b0469ed2e..8a857c030af39e 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() { @@ -61,12 +61,12 @@ TEST(function test_reverse_bogus(done) { }); TEST(function test_resolve4_ttl(done) { - var req = dns.resolve4('google.com', { ttl: true }, function(err, result) { + const req = dns.resolve4('google.com', { ttl: true }, function(err, result) { assert.ifError(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'); assert.strictEqual(typeof item.ttl, 'number'); @@ -82,12 +82,12 @@ TEST(function test_resolve4_ttl(done) { }); TEST(function test_resolve6_ttl(done) { - var req = dns.resolve6('google.com', { ttl: true }, function(err, result) { + const req = dns.resolve6('google.com', { ttl: true }, function(err, result) { assert.ifError(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'); assert.strictEqual(typeof item.ttl, 'number'); @@ -103,12 +103,12 @@ TEST(function test_resolve6_ttl(done) { }); TEST(function test_resolveMx(done) { - var req = dns.resolveMx('gmail.com', function(err, result) { + const req = dns.resolveMx('gmail.com', function(err, result) { assert.ifError(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'); @@ -125,7 +125,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'); @@ -138,12 +138,12 @@ 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) { assert.ifError(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'); } @@ -155,7 +155,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'); @@ -168,12 +168,12 @@ 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) { assert.ifError(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'); @@ -192,7 +192,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'); @@ -205,12 +205,12 @@ 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) { assert.ifError(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'); } @@ -222,7 +222,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'); @@ -235,12 +235,12 @@ 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) { assert.ifError(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'); @@ -259,7 +259,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'); @@ -272,7 +272,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) { assert.ifError(err); assert.ok(result); assert.strictEqual(typeof result, 'object'); @@ -305,7 +305,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'); @@ -318,12 +318,12 @@ 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) { assert.ifError(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'); } @@ -335,7 +335,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'); @@ -349,7 +349,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) { assert.ifError(err); assert.strictEqual(records.length, 1); assert.ok(util.isArray(records[0])); @@ -361,7 +361,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'); @@ -375,7 +375,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'); @@ -390,7 +390,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) { assert.ifError(err); assert.strictEqual(ip, null); assert.strictEqual(family, 4); @@ -403,7 +403,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) { assert.ifError(err); assert.ok(Array.isArray(ips)); assert.ok(ips.length > 0); @@ -418,7 +418,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) { assert.ifError(err); assert.ok(Array.isArray(ips)); assert.strictEqual(ips.length, 0); @@ -431,7 +431,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) { assert.ifError(err); assert.ok(Array.isArray(ips)); assert.ok(ips.length > 0); @@ -453,7 +453,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)); @@ -466,7 +466,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'); @@ -480,7 +480,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'); @@ -494,7 +494,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) { @@ -516,12 +516,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-net-connect-timeout.js b/test/internet/test-net-connect-timeout.js index e379f4146720b9..95e25614ffa2b7 100644 --- a/test/internet/test-net-connect-timeout.js +++ b/test/internet/test-net-connect-timeout.js @@ -7,21 +7,21 @@ const common = require('../common'); 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 fa45cc711e1016..f3be8409844702 100644 --- a/test/internet/test-net-connect-unref.js +++ b/test/internet/test-net-connect-unref.js @@ -2,10 +2,9 @@ const common = require('../common'); 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 3c6c205d6e4013..f57b897099fc2d 100644 --- a/test/internet/test-tls-connnect-melissadata.js +++ b/test/internet/test-tls-connnect-melissadata.js @@ -9,7 +9,7 @@ if (!common.hasCrypto) { } const tls = require('tls'); -var socket = tls.connect(443, 'address.melissadata.net', function() { +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/eval_messages.js b/test/message/eval_messages.js index 188311851c5163..d50df9081b2d25 100644 --- a/test/message/eval_messages.js +++ b/test/message/eval_messages.js @@ -5,16 +5,16 @@ require('../common'); 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 4759e2b0d51159..b32004c329dead 100644 --- a/test/message/stdin_messages.js +++ b/test/message/stdin_messages.js @@ -5,17 +5,17 @@ require('../common'); 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/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 06d328eea4c67b..346776ef5ed483 100644 --- a/test/parallel/test-assert.js +++ b/test/parallel/test-assert.js @@ -4,7 +4,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); }; @@ -125,8 +125,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; @@ -136,7 +136,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; } }; @@ -154,8 +154,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)); @@ -287,8 +287,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); @@ -305,7 +305,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)); @@ -346,7 +346,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) { @@ -414,10 +414,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'); @@ -456,7 +457,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, [])); @@ -475,7 +476,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) { @@ -540,7 +541,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 c574403eaecffa..354534a6b30a5a 100644 --- a/test/parallel/test-async-wrap-check-providers.js +++ b/test/parallel/test-async-wrap-check-providers.js @@ -28,7 +28,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 adc92c69d978d5..b1a51773e2348c 100644 --- a/test/parallel/test-async-wrap-throw-from-callback.js +++ b/test/parallel/test-async-wrap-throw-from-callback.js @@ -13,8 +13,8 @@ const domain = require('domain'); const spawn = require('child_process').spawn; const callbacks = [ 'init', 'pre', 'post', 'destroy' ]; const toCall = process.argv[2]; -var msgCalled = 0; -var msgReceived = 0; +let msgCalled = 0; +let msgReceived = 0; function init() { if (toCall === 'init') @@ -57,7 +57,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-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 e31e514ffa1182..c30e06cc73690d 100644 --- a/test/parallel/test-buffer-bytelength.js +++ b/test/parallel/test-buffer-bytelength.js @@ -24,37 +24,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 b29e00682c114b..5d558835b7db83 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 fef4acf7df286b..5737ed748058ef 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 27b71b1b17008a..503add948826ab 100644 --- a/test/parallel/test-buffer-indexof.js +++ b/test/parallel/test-buffer-indexof.js @@ -191,7 +191,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')); @@ -226,7 +226,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)); @@ -236,15 +236,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); @@ -260,17 +260,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. @@ -307,10 +307,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)); } } @@ -325,12 +325,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')); } @@ -439,7 +439,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')); @@ -490,16 +490,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-child-process-constructor.js b/test/parallel/test-child-process-constructor.js index 59277dcabe5ffa..d33c7ae3acf626 100644 --- a/test/parallel/test-child-process-constructor.js +++ b/test/parallel/test-child-process-constructor.js @@ -3,11 +3,11 @@ require('../common'); const assert = require('assert'); const child_process = require('child_process'); -var ChildProcess = child_process.ChildProcess; +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 2c60e274de51fa..37e7ea7494670e 100644 --- a/test/parallel/test-child-process-default-options.js +++ b/test/parallel/test-child-process-default-options.js @@ -6,14 +6,14 @@ 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 cac82b9952a4da..ad41f978e21768 100644 --- a/test/parallel/test-child-process-env.js +++ b/test/parallel/test-child-process-env.js @@ -4,14 +4,14 @@ const assert = require('assert'); 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 2bd1256fe273d8..9596a202223993 100644 --- a/test/parallel/test-child-process-exit-code.js +++ b/test/parallel/test-child-process-exit-code.js @@ -4,17 +4,17 @@ 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 b25cf07ef6ff81..4447c54cae8f0c 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 2daef37b669fc8..97d1e21a2f6d7a 100644 --- a/test/parallel/test-child-process-fork-exec-argv.js +++ b/test/parallel/test-child-process-fork-exec-argv.js @@ -2,8 +2,8 @@ require('../common'); const assert = require('assert'); const child_process = require('child_process'); -var spawn = child_process.spawn; -var fork = child_process.fork; +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 e9938d8ba12767..5af0184a21f55d 100644 --- a/test/parallel/test-child-process-fork-exec-path.js +++ b/test/parallel/test-child-process-fork-exec-path.js @@ -3,9 +3,9 @@ const common = require('../common'); const assert = require('assert'); const fs = require('fs'); const path = require('path'); -var msg = {test: 'this'}; -var nodePath = process.execPath; -var copyPath = path.join(common.tmpDir, 'node-copy.exe'); +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,7 +23,7 @@ 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'; const child = require('child_process').fork(__filename, { execPath: copyPath, diff --git a/test/parallel/test-child-process-fork-net.js b/test/parallel/test-child-process-fork-net.js index cbafcb13fbb068..c66b808ec0addf 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(); + const 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 cee5c0a4ca548b..6d20f419049c7b 100644 --- a/test/parallel/test-child-process-fork-net2.js +++ b/test/parallel/test-child-process-fork-net2.js @@ -3,11 +3,11 @@ const common = require('../common'); const assert = require('assert'); const fork = require('child_process').fork; const net = require('net'); -var count = 12; +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() { + const 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 46eaab584f5581..1f8816c0cfaf1c 100644 --- a/test/parallel/test-child-process-fork-ref.js +++ b/test/parallel/test-child-process-fork-ref.js @@ -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 6d6c56b6b3a93f..9f59aa344aa2c9 100644 --- a/test/parallel/test-child-process-fork-ref2.js +++ b/test/parallel/test-child-process-fork-ref2.js @@ -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 d985b8b4acaf19..0bcf4bf9a1c88f 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 a8548eff5809c5..bfc68e41dc95fb 100644 --- a/test/parallel/test-child-process-fork.js +++ b/test/parallel/test-child-process-fork.js @@ -2,9 +2,9 @@ const common = require('../common'); const assert = require('assert'); const fork = require('child_process').fork; -var args = ['foo', 'bar']; +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.strictEqual(n.channel, n._channel); assert.deepStrictEqual(args, ['foo', 'bar']); diff --git a/test/parallel/test-child-process-internal.js b/test/parallel/test-child-process-internal.js index 5d488f7839bd54..d795b69d7ee0e5 100644 --- a/test/parallel/test-child-process-internal.js +++ b/test/parallel/test-child-process-internal.js @@ -3,9 +3,9 @@ const common = require('../common'); 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 @@ -19,7 +19,7 @@ if (process.argv[2] === 'child') { } else { const fork = require('child_process').fork; - var child = fork(process.argv[1], ['child']); + 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 5a542fa97e2b5a..54037aea69feb2 100644 --- a/test/parallel/test-child-process-set-blocking.js +++ b/test/parallel/test-child-process-set-blocking.js @@ -3,9 +3,9 @@ const common = require('../common'); 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 e087ae1cdea14f..3bfa9f5f7d5235 100644 --- a/test/parallel/test-child-process-silent.js +++ b/test/parallel/test-child-process-silent.js @@ -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 7b98cedf8ba117..756d61931a68f3 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 05ef18bf7279a7..6f5ea3dc83d107 100644 --- a/test/parallel/test-child-process-spawnsync-env.js +++ b/test/parallel/test-child-process-spawnsync-env.js @@ -6,8 +6,8 @@ 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 207315c531afd0..abebe41e6e9640 100644 --- a/test/parallel/test-child-process-spawnsync-timeout.js +++ b/test/parallel/test-child-process-spawnsync-timeout.js @@ -4,8 +4,8 @@ const assert = require('assert'); const spawnSync = require('child_process').spawnSync; -var TIMER = 200; -var SLEEP = 5000; +const TIMER = 200; +const SLEEP = 5000; switch (process.argv[2]) { case 'child': @@ -15,12 +15,12 @@ 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'); console.log(ret); - var end = Date.now() - start; + const end = Date.now() - start; assert(end < SLEEP); assert(ret.status > 128 || ret.signal); break; diff --git a/test/parallel/test-child-process-stdin-ipc.js b/test/parallel/test-child-process-stdin-ipc.js index c4a8064680e69f..2623e2deeeee8a 100644 --- a/test/parallel/test-child-process-stdin-ipc.js +++ b/test/parallel/test-child-process-stdin-ipc.js @@ -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 f7b992e4e76c26..d2b64aeb30dd31 100644 --- a/test/parallel/test-child-process-stdio-inherit.js +++ b/test/parallel/test-child-process-stdio-inherit.js @@ -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 d00092186b8184..fdd0cc33f068d9 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', @@ -34,7 +34,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..92251b7324bf5f 100644 --- a/test/parallel/test-cluster-basic.js +++ b/test/parallel/test-cluster-basic.js @@ -56,7 +56,6 @@ if (cluster.isWorker) { } }; - var worker; const stateNames = Object.keys(checks.worker.states); //Check events, states, and emit arguments @@ -72,7 +71,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); })); }); @@ -86,7 +85,7 @@ if (cluster.isWorker) { cluster.on('exit', common.mustCall(() => {})); //Create worker - worker = cluster.fork(); + const worker = cluster.fork(); assert.strictEqual(worker.id, 1); assert(worker instanceof cluster.Worker, 'the worker is not a instance of the Worker constructor'); 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 4b38720d71e984..15c5898a7d6f69 100644 --- a/test/parallel/test-cluster-disconnect-with-no-workers.js +++ b/test/parallel/test-cluster-disconnect-with-no-workers.js @@ -3,7 +3,7 @@ require('../common'); 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 8b94845635f822..a0936ef4b9d471 100644 --- a/test/parallel/test-cluster-eaddrinuse.js +++ b/test/parallel/test-cluster-eaddrinuse.js @@ -8,12 +8,12 @@ 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 735ff73d2a5c16..55ea684f3b4ce3 100644 --- a/test/parallel/test-cluster-fork-env.js +++ b/test/parallel/test-cluster-fork-env.js @@ -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-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 a86b469e331dbe..5b537bbe73a755 100644 --- a/test/parallel/test-cluster-message.js +++ b/test/parallel/test-cluster-message.js @@ -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 0f39c47ed2e67d..10b0530b505a95 100644 --- a/test/parallel/test-cluster-rr-domain-listen.js +++ b/test/parallel/test-cluster-rr-domain-listen.js @@ -7,14 +7,13 @@ const domain = require('domain'); // cluster.schedulingPolicy = cluster.SCHED_RR; if (cluster.isWorker) { - var d = domain.create(); + const d = domain.create(); d.run(function() { }); const http = require('http'); http.Server(function() { }).listen(common.PORT, '127.0.0.1'); } else if (cluster.isMaster) { - var worker; //Kill worker when listening cluster.on('listening', function() { @@ -27,5 +26,5 @@ if (cluster.isWorker) { }); //Create worker - worker = cluster.fork(); + const worker = cluster.fork(); } diff --git a/test/parallel/test-cluster-send-deadlock.js b/test/parallel/test-cluster-send-deadlock.js index 062ebf2b131911..3fa64ac0b5d4d0 100644 --- a/test/parallel/test-cluster-send-deadlock.js +++ b/test/parallel/test-cluster-send-deadlock.js @@ -8,14 +8,14 @@ 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) { + const 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-multiple.js b/test/parallel/test-cluster-setup-master-multiple.js index a7611b3c23ad4d..25cff7cb33e0c1 100644 --- a/test/parallel/test-cluster-setup-master-multiple.js +++ b/test/parallel/test-cluster-setup-master-multiple.js @@ -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 4590309f936218..5a92b988e61e5e 100644 --- a/test/parallel/test-cluster-setup-master.js +++ b/test/parallel/test-cluster-setup-master.js @@ -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 6435232a8103af..7a33721a9aba17 100644 --- a/test/parallel/test-cluster-worker-death.js +++ b/test/parallel/test-cluster-worker-death.js @@ -6,7 +6,7 @@ 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 30da5954b23971..62000254247a1f 100644 --- a/test/parallel/test-cluster-worker-destroy.js +++ b/test/parallel/test-cluster-worker-destroy.js @@ -10,7 +10,7 @@ const common = require('../common'); const assert = require('assert'); const cluster = require('cluster'); -var worker1, worker2; +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 b77a32353b3ce6..6c2e278f5e4639 100644 --- a/test/parallel/test-cluster-worker-events.js +++ b/test/parallel/test-cluster-worker-events.js @@ -3,11 +3,11 @@ require('../common'); 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 1d553a9269b332..828188254724ae 100644 --- a/test/parallel/test-cluster-worker-forced-exit.js +++ b/test/parallel/test-cluster-worker-forced-exit.js @@ -3,7 +3,7 @@ const common = require('../common'); 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 3b17b53e8ae1ae..8b2ad865899c60 100644 --- a/test/parallel/test-cluster-worker-isconnected.js +++ b/test/parallel/test-cluster-worker-isconnected.js @@ -4,7 +4,7 @@ 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 a80f8410b11a4f..cd360ff248aa13 100644 --- a/test/parallel/test-cluster-worker-isdead.js +++ b/test/parallel/test-cluster-worker-isdead.js @@ -4,7 +4,7 @@ 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 9921256c4a74d0..9cfd8401a0c678 100644 --- a/test/parallel/test-cluster-worker-no-exit.js +++ b/test/parallel/test-cluster-worker-no-exit.js @@ -4,10 +4,10 @@ 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 cb925822a06f6b..d1a0d73678d67a 100644 --- a/test/parallel/test-cluster-worker-wait-server-close.js +++ b/test/parallel/test-cluster-worker-wait-server-close.js @@ -5,10 +5,10 @@ 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-console-instance.js b/test/parallel/test-console-instance.js index 4d2727d96b1a55..4488e893732751 100644 --- a/test/parallel/test-console-instance.js +++ b/test/parallel/test-console-instance.js @@ -3,7 +3,7 @@ require('../common'); const assert = require('assert'); const Stream = require('stream'); const Console = require('console').Console; -var called = false; +let called = false; const out = new Stream(); const err = new Stream(); @@ -32,7 +32,7 @@ assert.throws(function() { out.write = err.write = function(d) {}; -var c = new Console(out, err); +const c = new Console(out, err); out.write = err.write = function(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 bf8a59072f965b..0c1c209374ac17 100644 --- a/test/parallel/test-console-not-call-toString.js +++ b/test/parallel/test-console-not-call-toString.js @@ -2,8 +2,8 @@ require('../common'); 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 24c3163e3b2d90..ebd83b019ba146 100644 --- a/test/parallel/test-crypto-certificate.js +++ b/test/parallel/test-crypto-certificate.js @@ -13,11 +13,11 @@ crypto.DEFAULT_ENCODING = 'buffer'; 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 92fab2b8c2a178..f6bfcf72c0fd7e 100644 --- a/test/parallel/test-crypto-dh-odd-key.js +++ b/test/parallel/test-crypto-dh-odd-key.js @@ -9,9 +9,9 @@ if (!common.hasCrypto) { 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 6a067bef1be066..2a06fc6e7b86d6 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()) - .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); // 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 fcbbcb8e0524f2..6586f7d48a94ce 100644 --- a/test/parallel/test-crypto-domain.js +++ b/test/parallel/test-crypto-domain.js @@ -10,12 +10,12 @@ if (!common.hasCrypto) { 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 738ed15323ba01..2749382fa5c780 100644 --- a/test/parallel/test-crypto-domains.js +++ b/test/parallel/test-crypto-domains.js @@ -2,8 +2,8 @@ const common = require('../common'); const domain = require('domain'); const assert = require('assert'); -var d = domain.create(); -var expect = ['pbkdf2', 'randomBytes', 'pseudoRandomBytes']; +const d = domain.create(); +const expect = ['pbkdf2', 'randomBytes', 'pseudoRandomBytes']; if (!common.hasCrypto) { common.skip('missing crypto'); diff --git a/test/parallel/test-crypto-fips.js b/test/parallel/test-crypto-fips.js index f27c59624730d2..6fd3352740c8c3 100644 --- a/test/parallel/test-crypto-fips.js +++ b/test/parallel/test-crypto-fips.js @@ -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 ec39606506b7b7..485735e83ce5cc 100644 --- a/test/parallel/test-crypto-from-binary.js +++ b/test/parallel/test-crypto-from-binary.js @@ -12,10 +12,10 @@ if (!common.hasCrypto) { } 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 10135d2950c212..0d55d4236a656e 100644 --- a/test/parallel/test-crypto-hash.js +++ b/test/parallel/test-crypto-hash.js @@ -11,34 +11,34 @@ if (!common.hasCrypto) { 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.notStrictEqual(a7, undefined, 'no data should return data'); assert.notStrictEqual(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.notStrictEqual( 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 ef4e59a1dd944c..a3372bcb7242b9 100644 --- a/test/parallel/test-crypto-hmac.js +++ b/test/parallel/test-crypto-hmac.js @@ -17,14 +17,14 @@ const 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-rsa-dsa.js b/test/parallel/test-crypto-rsa-dsa.js index d894e0dcafd9eb..bb529f2454dbc8 100644 --- a/test/parallel/test-crypto-rsa-dsa.js +++ b/test/parallel/test-crypto-rsa-dsa.js @@ -158,7 +158,7 @@ assert.strictEqual(rsaVerify.verify(rsaPubPem, rsaSignature, 'hex'), true); rsaSign = crypto.createSign('RSA-SHA1'); rsaSign.update(rsaPubPem); assert.doesNotThrow(() => { - var signOptions = { key: rsaKeyPemEncrypted, passphrase: 'password' }; + const signOptions = { key: rsaKeyPemEncrypted, passphrase: 'password' }; rsaSignature = rsaSign.sign(signOptions, 'hex'); }); assert.strictEqual(rsaSignature, expectedSignature); @@ -170,7 +170,7 @@ assert.strictEqual(rsaVerify.verify(rsaPubPem, rsaSignature, 'hex'), true); rsaSign = crypto.createSign('RSA-SHA1'); rsaSign.update(rsaPubPem); assert.throws(() => { - var signOptions = { key: rsaKeyPemEncrypted, passphrase: 'wrong' }; + const signOptions = { key: rsaKeyPemEncrypted, passphrase: 'wrong' }; rsaSign.sign(signOptions, 'hex'); }, decryptError); diff --git a/test/parallel/test-crypto-sign-verify.js b/test/parallel/test-crypto-sign-verify.js index 05f29a710466ee..ae78cd9d8b3420 100644 --- a/test/parallel/test-crypto-sign-verify.js +++ b/test/parallel/test-crypto-sign-verify.js @@ -10,8 +10,8 @@ if (!common.hasCrypto) { 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 06b483b326279f..f558851b7940a0 100644 --- a/test/parallel/test-crypto-stream.js +++ b/test/parallel/test-crypto-stream.js @@ -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 f840c017b4b2d4..c171814dd3c3a6 100644 --- a/test/parallel/test-crypto-verify-failure.js +++ b/test/parallel/test-crypto-verify-failure.js @@ -12,14 +12,14 @@ crypto.DEFAULT_ENCODING = 'buffer'; 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') }; -var server = tls.Server(options, function(socket) { +const server = tls.Server(options, function(socket) { setImmediate(function() { console.log('sending'); verify(); diff --git a/test/parallel/test-cwd-enoent-repl.js b/test/parallel/test-cwd-enoent-repl.js index da7729b286519e..942fc07b64a90b 100644 --- a/test/parallel/test-cwd-enoent-repl.js +++ b/test/parallel/test-cwd-enoent-repl.js @@ -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 bb26a6e879784b..736121a7c89d6e 100644 --- a/test/parallel/test-cwd-enoent.js +++ b/test/parallel/test-cwd-enoent.js @@ -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 f0ff853b16df82..53f35877a2f382 100644 --- a/test/parallel/test-debug-port-from-cmdline.js +++ b/test/parallel/test-debug-port-from-cmdline.js @@ -3,15 +3,15 @@ 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 127.0.0.1:' + debugPort, ]; assert.strictEqual(outputLines.length, expectedLines.length); - for (var i = 0; i < expectedLines.length; i++) + for (let i = 0; i < expectedLines.length; i++) assert(expectedLines[i].includes(outputLines[i])); } diff --git a/test/parallel/test-debug-signal-cluster.js b/test/parallel/test-debug-signal-cluster.js index 24b362a687988a..89b3ca456d3248 100644 --- a/test/parallel/test-debug-signal-cluster.js +++ b/test/parallel/test-debug-signal-cluster.js @@ -12,7 +12,7 @@ const args = [`--debug-port=${port}`, serverPath]; const options = { stdio: ['inherit', 'inherit', 'pipe', 'ipc'] }; const child = spawn(process.execPath, args, options); -var expectedContent = [ +let expectedContent = [ 'Starting debugger agent.', 'Debugger listening on 127.0.0.1:' + (port + 0), 'Starting debugger agent.', @@ -22,10 +22,10 @@ var expectedContent = [ ].join(os.EOL); expectedContent += os.EOL; // the last line also contains an EOL character -var debuggerAgentsOutput = ''; -var debuggerAgentsStarted = false; +let debuggerAgentsOutput = ''; +let debuggerAgentsStarted = false; -var pids; +let pids; child.stderr.on('data', function(data) { const childStderrOutputString = data.toString(); 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 2b81da700f50a0..e8ba516bfc0f9e 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-dgram-address.js b/test/parallel/test-dgram-address.js index 03fcdf3446ac83..09c5ba31f6c5b5 100644 --- a/test/parallel/test-dgram-address.js +++ b/test/parallel/test-dgram-address.js @@ -4,11 +4,11 @@ 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 6df102b32d09e1..882f2e87bdd7ee 100644 --- a/test/parallel/test-dgram-bind.js +++ b/test/parallel/test-dgram-bind.js @@ -3,12 +3,12 @@ require('../common'); const assert = require('assert'); const dgram = require('dgram'); -var socket = dgram.createSocket('udp4'); +const socket = dgram.createSocket('udp4'); socket.on('listening', function() { 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 da686d850ee129..07a8bb0e43452b 100644 --- a/test/parallel/test-dgram-bytes-length.js +++ b/test/parallel/test-dgram-bytes-length.js @@ -3,8 +3,8 @@ require('../common'); 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 beccc2420d36bc..d0f23d5808c7b7 100644 --- a/test/parallel/test-dgram-close-is-not-callback.js +++ b/test/parallel/test-dgram-close-is-not-callback.js @@ -2,9 +2,9 @@ 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..927c9f815fc046 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,6 @@ if (cluster.isMaster) { } const source = dgram.createSocket('udp4'); -var interval; source.on('close', function() { clearInterval(interval); @@ -100,6 +99,6 @@ if (process.env.BOUND === 'y') { } const buf = Buffer.from(process.pid.toString()); -interval = setInterval(() => { +const interval = setInterval(() => { source.send(buf, common.PORT, '127.0.0.1'); }, 1).unref(); diff --git a/test/parallel/test-dgram-implicit-bind.js b/test/parallel/test-dgram-implicit-bind.js index 25c61903e884de..bfc86803b463f1 100644 --- a/test/parallel/test-dgram-implicit-bind.js +++ b/test/parallel/test-dgram-implicit-bind.js @@ -2,9 +2,9 @@ const common = require('../common'); 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 2060a4738012a2..e60687649cda30 100644 --- a/test/parallel/test-dgram-listen-after-bind.js +++ b/test/parallel/test-dgram-listen-after-bind.js @@ -3,12 +3,12 @@ require('../common'); 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 0bf302e7e3ce6e..247a35588c3ff7 100644 --- a/test/parallel/test-dgram-oob-buffer.js +++ b/test/parallel/test-dgram-oob-buffer.js @@ -6,8 +6,8 @@ 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 2b509d79076911..b4ec8195d7e7f0 100644 --- a/test/parallel/test-dgram-regress-4496.js +++ b/test/parallel/test-dgram-regress-4496.js @@ -6,7 +6,7 @@ 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 8505c8bb67e8c0..c7ec6b51eecfa8 100644 --- a/test/parallel/test-dgram-send-bad-arguments.js +++ b/test/parallel/test-dgram-send-bad-arguments.js @@ -3,9 +3,9 @@ require('../common'); 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..d612dbc7e56c83 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() { + const interval = setInterval(function() { client.send(buf, 0, 0, port, '127.0.0.1', common.mustCall(function() {})); }, 10); })); diff --git a/test/parallel/test-dgram-setTTL.js b/test/parallel/test-dgram-setTTL.js index 9393e53c7f1912..3985297217d8b7 100644 --- a/test/parallel/test-dgram-setTTL.js +++ b/test/parallel/test-dgram-setTTL.js @@ -6,7 +6,7 @@ const socket = dgram.createSocket('udp4'); socket.bind(0); socket.on('listening', function() { - var result = socket.setTTL(16); + const result = socket.setTTL(16); assert.strictEqual(result, 16); assert.throws(function() { diff --git a/test/parallel/test-dgram-unref.js b/test/parallel/test-dgram-unref.js index 1b95487a302cdb..ee463d7ab8da77 100644 --- a/test/parallel/test-dgram-unref.js +++ b/test/parallel/test-dgram-unref.js @@ -2,7 +2,7 @@ const common = require('../common'); const dgram = require('dgram'); -var s = dgram.createSocket('udp4'); +const s = dgram.createSocket('udp4'); s.bind(); s.unref(); diff --git a/test/parallel/test-dh-padding.js b/test/parallel/test-dh-padding.js index 35202f6a5191a8..1d9d47ec0e10a3 100644 --- a/test/parallel/test-dh-padding.js +++ b/test/parallel/test-dh-padding.js @@ -45,7 +45,7 @@ const crypto = require('crypto'); * } */ -var apub = +const apub = '5484455905d3eff34c70980e871f27f05448e66f5a6efbb97cbcba4e927196c2bd9ea272cded91\ 10a4977afa8d9b16c9139a444ed2d954a794650e5d7cb525204f385e1af81530518563822ecd0f9\ 524a958d02b3c269e79d6d69850f0968ad567a4404fbb0b19efc8bc73e267b6136b88cafb33299f\ @@ -53,7 +53,7 @@ f7c7cace3ffab1a88c2c9ee841f88b4c3679b4efc465f5c93cca11d487be57373e4c5926f634c4e\ efee6721d01db91cd66321615b2522f96368dbc818875d422140d0edf30bdb97d9721feddcb9ff6\ 453741a4f687ee46fc54bf1198801f1210ac789879a5ee123f79e2d2ce1209df2445d32166bc9e4\ 8f89e944ec9c3b2e16c8066cd8eebd4e33eb941'; -var bpub = +const bpub = '3fca64510e36bc7da8a3a901c7b74c2eabfa25deaf7cbe1d0c50235866136ad677317279e1fb0\ 06e9c0a07f63e14a3363c8e016fbbde2b2c7e79fed1cc3e08e95f7459f547a8cd0523ee9dc744d\ e5a956d92b937db4448917e1f6829437f05e408ee7aea70c0362b37370c7c75d14449d8b2d2133\ @@ -61,7 +61,7 @@ e5a956d92b937db4448917e1f6829437f05e408ee7aea70c0362b37370c7c75d14449d8b2d2133\ 788a1fdc6cdf17f5fffaf024ce8711a2ebde0b52e9f1cb56224483826d6e5ac6ecfaae07b75d20\ 6e8ac97f5be1a5b68f20382f2a7dac189cf169325c4cf845b26a0cd616c31fec905c5d9035e5f7\ 8e9880c812374ac0f3ca3d365f06e4be526b5affd4b79'; -var apriv = +const apriv = '62411e34704637d99c6c958a7db32ac22fcafafbe1c33d2cfdb76e12ded41f38fc16b792b9041\ 2e4c82755a3815ba52f780f0ee296ad46e348fc4d1dcd6b64f4eea1b231b2b7d95c5b1c2e26d34\ 83520558b9860a6eb668f01422a54e6604aa7702b4e67511397ef3ecb912bff1a83899c5a5bfb2\ @@ -69,7 +69,7 @@ var apriv = 08c3b3e6fc60668f7be81cce6784482af228dd7f489005253a165e292802cfd0399924f6c56827\ 7012f68255207722355634290acc7fddeefbba75650a85ece95b6a12de67eac016ba78960108dd\ 5dbadfaa43cc9fed515a1f307b7d90ae0623bc7b8cefb'; -var secret = +const secret = '00c37b1e06a436d6717816a40e6d72907a6f255638b93032267dcb9a5f0b4a9aa0236f3dce63b\ 1c418c60978a00acd1617dfeecf1661d8a3fafb4d0d8824386750f4853313400e7e4afd22847e4\ fa56bc9713872021265111906673b38db83d10cbfa1dea3b6b4c97c8655f4ae82125281af7f234\ @@ -79,7 +79,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-dns-lookup-cb-error.js b/test/parallel/test-dns-lookup-cb-error.js index 212f037868309e..d866a8a13bf622 100644 --- a/test/parallel/test-dns-lookup-cb-error.js +++ b/test/parallel/test-dns-lookup-cb-error.js @@ -11,7 +11,7 @@ cares.getaddrinfo = function() { }; assert.doesNotThrow(() => { - var tickValue = 0; + let tickValue = 0; dns.lookup('example.com', common.mustCall((error, result, addressType) => { assert(error); diff --git a/test/parallel/test-domain-abort-on-uncaught.js b/test/parallel/test-domain-abort-on-uncaught.js index d9183af60bc278..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() { @@ -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-enter-exit.js b/test/parallel/test-domain-enter-exit.js index 5f12a0bd4ca08c..4a11c3a206a5fe 100644 --- a/test/parallel/test-domain-enter-exit.js +++ b/test/parallel/test-domain-enter-exit.js @@ -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 2a4ffd655c3e52..542950f8af428e 100644 --- a/test/parallel/test-domain-exit-dispose-again.js +++ b/test/parallel/test-domain-exit-dispose-again.js @@ -8,20 +8,20 @@ require('../common'); const assert = require('assert'); const domain = require('domain'); -var disposalFailed = false; +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 c53b840bf556c3..e1797cb660a0c0 100644 --- a/test/parallel/test-domain-exit-dispose.js +++ b/test/parallel/test-domain-exit-dispose.js @@ -5,7 +5,7 @@ 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 ee0388b3cd7f88..d8bb5c843662b8 100644 --- a/test/parallel/test-domain-http-server.js +++ b/test/parallel/test-domain-http-server.js @@ -4,14 +4,14 @@ 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 }); + const 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 7773bc46d76137..265d291f61941b 100644 --- a/test/parallel/test-domain-implicit-fs.js +++ b/test/parallel/test-domain-implicit-fs.js @@ -5,7 +5,7 @@ const common = require('../common'); 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); diff --git a/test/parallel/test-domain-multi.js b/test/parallel/test-domain-multi.js index 2e541ab5e4dc3c..b8005726219519 100644 --- a/test/parallel/test-domain-multi.js +++ b/test/parallel/test-domain-multi.js @@ -5,12 +5,12 @@ require('../common'); const assert = require('assert'); const domain = require('domain'); -var caughtA = false; -var caughtB = false; -var caughtC = false; +let caughtA = false; +let caughtB = false; +let caughtC = false; -var a = domain.create(); +const a = domain.create(); a.enter(); // this will be our "root" domain a.on('error', function(er) { caughtA = true; @@ -20,9 +20,9 @@ a.on('error', function(er) { const http = require('http'); -var server = http.createServer(function(req, res) { +const server = http.createServer(function(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 @@ -50,8 +50,8 @@ var server = http.createServer(function(req, res) { })); }).listen(0, function() { - var c = domain.create(); - var req = http.get({ host: 'localhost', port: this.address().port }); + const c = domain.create(); + const req = http.get({ host: 'localhost', port: this.address().port }); // add the request to the C domain c.add(req); diff --git a/test/parallel/test-domain-nested-throw.js b/test/parallel/test-domain-nested-throw.js index 008eaaa5f7496f..39507446a3acfc 100644 --- a/test/parallel/test-domain-nested-throw.js +++ b/test/parallel/test-domain-nested-throw.js @@ -4,7 +4,7 @@ const assert = require('assert'); 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; + const node = process.execPath; const spawn = require('child_process').spawn; - var opt = { stdio: 'inherit' }; - var child = spawn(node, [__filename, 'true'], opt); + 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-safe-exit.js b/test/parallel/test-domain-safe-exit.js index c00aa306f10e7a..bbc3b2fe22cae8 100644 --- a/test/parallel/test-domain-safe-exit.js +++ b/test/parallel/test-domain-safe-exit.js @@ -5,8 +5,8 @@ require('../common'); 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 5772a56e39b77e..43152a4a3bb1c9 100644 --- a/test/parallel/test-domain-stack.js +++ b/test/parallel/test-domain-stack.js @@ -4,7 +4,7 @@ require('../common'); 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 d2277cfc0f74b7..e35d247c3a8a34 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 @@ -81,7 +81,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 6ddec404cd20ac..79bd300545bf96 100644 --- a/test/parallel/test-domain-timers.js +++ b/test/parallel/test-domain-timers.js @@ -3,9 +3,7 @@ const common = require('../common'); const domain = require('domain'); const assert = require('assert'); -var timeout; - -var timeoutd = domain.create(); +const timeoutd = domain.create(); timeoutd.on('error', common.mustCall(function(e) { assert.strictEqual(e.message, 'Timeout UNREFd', @@ -19,7 +17,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', @@ -32,4 +30,4 @@ immediated.run(function() { }); }); -timeout = setTimeout(function() {}, 10 * 1000); +const timeout = setTimeout(function() {}, 10 * 1000); 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 8062d107367dfe..53a73eac426232 100644 --- a/test/parallel/test-domain-top-level-error-handler-throw.js +++ b/test/parallel/test-domain-top-level-error-handler-throw.js @@ -14,7 +14,7 @@ const internalExMessage = 'You should NOT see me'; if (process.argv[2] === 'child') { const domain = require('domain'); - var d = domain.create(); + const d = domain.create(); d.on('error', function() { throw new Error(domainErrHandlerExMessage); @@ -29,8 +29,8 @@ if (process.argv[2] === 'child') { 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 e11935be68704e..0da8f1368f7c98 100644 --- a/test/parallel/test-domain-with-abort-on-uncaught-exception.js +++ b/test/parallel/test-domain-with-abort-on-uncaught-exception.js @@ -30,7 +30,7 @@ const domainErrHandlerExMessage = 'exception from domain error handler'; if (process.argv[2] === 'child') { const domain = require('domain'); - var d = domain.create(); + const d = domain.create(); process.on('uncaughtException', function onUncaughtException() { // The process' uncaughtException event must not be emitted when @@ -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..11c14f3c011eb7 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'); +const 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 d0716a3e21eb08..6055a9b4c47862 100644 --- a/test/parallel/test-dsa-fips-invalid-key.js +++ b/test/parallel/test-dsa-fips-invalid-key.js @@ -10,11 +10,11 @@ if (!common.hasFipsCrypto) { 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 058f99126a7d1b..fa7332a67a482b 100644 --- a/test/parallel/test-error-reporting.js +++ b/test/parallel/test-error-reporting.js @@ -5,8 +5,8 @@ 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 18d2d065b8b1f4..5b9787f1b83bba 100644 --- a/test/parallel/test-event-emitter-check-listener-leaks.js +++ b/test/parallel/test-event-emitter-check-listener-leaks.js @@ -3,7 +3,7 @@ require('../common'); 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 e2c9fa2a0c2c1e..2b4a93ae9808df 100644 --- a/test/parallel/test-event-emitter-errors.js +++ b/test/parallel/test-event-emitter-errors.js @@ -3,7 +3,7 @@ require('../common'); 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 13f1dcb97c39c3..9acc71fd7920e3 100644 --- a/test/parallel/test-event-emitter-get-max-listeners.js +++ b/test/parallel/test-event-emitter-get-max-listeners.js @@ -3,7 +3,7 @@ require('../common'); 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 60d64c6614df80..022750da406500 100644 --- a/test/parallel/test-event-emitter-listeners-side-effects.js +++ b/test/parallel/test-event-emitter-listeners-side-effects.js @@ -5,8 +5,8 @@ const assert = require('assert'); 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 27c01b2a0781c5..d0464b80a44fe1 100644 --- a/test/parallel/test-event-emitter-method-names.js +++ b/test/parallel/test-event-emitter-method-names.js @@ -3,7 +3,7 @@ require('../common'); 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 99bdeea79dc5bb..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 @@ -3,9 +3,9 @@ const common = require('../common'); const assert = require('assert'); const events = require('events'); const domain = require('domain'); -var e = new events.EventEmitter(); +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 a5660b259ef483..d1027befa3f4ad 100644 --- a/test/parallel/test-event-emitter-num-args.js +++ b/test/parallel/test-event-emitter-num-args.js @@ -7,7 +7,7 @@ const e = new events.EventEmitter(); const num_args_emited = []; e.on('numArgs', function() { - var numArgs = arguments.length; + const numArgs = arguments.length; console.log('numArgs: ' + numArgs); num_args_emited.push(numArgs); }); 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 076c1ea1d7b80f..38f9b7101eb775 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 64f7420fb2cfe6..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 @@ -3,7 +3,7 @@ require('../common'); 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 27532dae46e4e4..d35802b413136b 100644 --- a/test/parallel/test-event-emitter-subclass.js +++ b/test/parallel/test-event-emitter-subclass.js @@ -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 1e2b2b89010d4e..506fbaed0ebf63 100644 --- a/test/parallel/test-exception-handler.js +++ b/test/parallel/test-exception-handler.js @@ -2,7 +2,7 @@ const common = require('../common'); 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 a74ad9dccec271..4157f92f8b9021 100644 --- a/test/parallel/test-fs-access.js +++ b/test/parallel/test-fs-access.js @@ -107,7 +107,7 @@ assert.doesNotThrow(() => { }); assert.doesNotThrow(() => { - 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 5f9e9f50bf5d2f..14e1446f5a6d3d 100644 --- a/test/parallel/test-fs-exists.js +++ b/test/parallel/test-fs-exists.js @@ -2,7 +2,7 @@ const common = require('../common'); const assert = require('assert'); const fs = require('fs'); -var f = __filename; +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 dd091ae1b1a94c..8d22159e24bd79 100644 --- a/test/parallel/test-fs-long-path.js +++ b/test/parallel/test-fs-long-path.js @@ -10,9 +10,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-open-flags.js b/test/parallel/test-fs-open-flags.js index 6c2fa9d2806dde..c8d6dd5eee4783 100644 --- a/test/parallel/test-fs-open-flags.js +++ b/test/parallel/test-fs-open-flags.js @@ -5,13 +5,13 @@ const assert = require('assert'); 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; const { stringToFlags } = require('internal/fs'); 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-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-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 190a10fc538fd6..85fc6ebef5235d 100644 --- a/test/parallel/test-fs-readfile-fd.js +++ b/test/parallel/test-fs-readfile-fd.js @@ -39,7 +39,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-realpath-buffer-encoding.js b/test/parallel/test-fs-realpath-buffer-encoding.js index fd7b0d5c3d42f3..0ce6ec576dac69 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 ae2895553ed2f6..f8d9e86de5e618 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 986e2089b44ab9..a444bf49846b1e 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) { assert.ifError(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 85feac59dda321..7bf97ff1d5cba3 100644 --- a/test/parallel/test-fs-sir-writes-alot.js +++ b/test/parallel/test-fs-sir-writes-alot.js @@ -4,33 +4,35 @@ 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 48e59b884096f5..32ba47c2fe0c1e 100644 --- a/test/parallel/test-fs-stat.js +++ b/test/parallel/test-fs-stat.js @@ -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-symlink-dir-junction-relative.js b/test/parallel/test-fs-symlink-dir-junction-relative.js index 166894c97ed846..3a2ba1a06c78db 100644 --- a/test/parallel/test-fs-symlink-dir-junction-relative.js +++ b/test/parallel/test-fs-symlink-dir-junction-relative.js @@ -6,10 +6,10 @@ 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 69b78dad3d2797..c8c6fc933d367b 100644 --- a/test/parallel/test-fs-symlink.js +++ b/test/parallel/test-fs-symlink.js @@ -4,8 +4,8 @@ const assert = require('assert'); const path = require('path'); const fs = require('fs'); -var linkTime; -var fileTime; +let linkTime; +let fileTime; if (!common.canCreateSymLink()) { common.skip('insufficient privileges'); diff --git a/test/parallel/test-fs-sync-fd-leak.js b/test/parallel/test-fs-sync-fd-leak.js index 67150f637dd7cc..353519593e2c4e 100644 --- a/test/parallel/test-fs-sync-fd-leak.js +++ b/test/parallel/test-fs-sync-fd-leak.js @@ -22,6 +22,7 @@ fs.fstatSync = function() { throw new Error('BAM'); }; +let close_called = 0; ensureThrows(function() { fs.readFileSync('dummy'); }); @@ -32,9 +33,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 ee6ca1ca132b03..95eaf12cbb77f9 100644 --- a/test/parallel/test-fs-truncate-GH-6233.js +++ b/test/parallel/test-fs-truncate-GH-6233.js @@ -3,7 +3,7 @@ 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-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 927ebb15412bc8..89570314cc504c 100644 --- a/test/parallel/test-fs-write-buffer.js +++ b/test/parallel/test-fs-write-buffer.js @@ -19,7 +19,7 @@ common.refreshTmpDir(); assert.strictEqual(expected.length, written); fs.closeSync(fd); - var found = fs.readFileSync(filename, 'utf8'); + const found = fs.readFileSync(filename, 'utf8'); assert.strictEqual(expected.toString(), found); }); diff --git a/test/parallel/test-fs-write-file-buffer.js b/test/parallel/test-fs-write-file-buffer.js index e2c7b1d01e4241..409ddf1d51f557 100644 --- a/test/parallel/test-fs-write-file-buffer.js +++ b/test/parallel/test-fs-write-file-buffer.js @@ -4,7 +4,7 @@ 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-err.js b/test/parallel/test-fs-write-stream-err.js index 22137329bfa181..d50fd07103222e 100644 --- a/test/parallel/test-fs-write-stream-err.js +++ b/test/parallel/test-fs-write-stream-err.js @@ -5,13 +5,13 @@ 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 4179ba0332121f..2694312b863571 100644 --- a/test/parallel/test-fs-write-string-coerce.js +++ b/test/parallel/test-fs-write-string-coerce.js @@ -7,9 +7,9 @@ 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) { assert.ifError(err); 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-http-1.0-keep-alive.js b/test/parallel/test-http-1.0-keep-alive.js index 301c054fc9a246..dea5f65c54184d 100644 --- a/test/parallel/test-http-1.0-keep-alive.js +++ b/test/parallel/test-http-1.0-keep-alive.js @@ -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 926497d002e473..d98da182a9fee5 100644 --- a/test/parallel/test-http-1.0.js +++ b/test/parallel/test-http-1.0.js @@ -4,17 +4,17 @@ 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 5e0baf3cdfdbd6..046f439cb33195 100644 --- a/test/parallel/test-http-abort-before-end.js +++ b/test/parallel/test-http-abort-before-end.js @@ -3,10 +3,10 @@ const common = require('../common'); 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 9ee2974c46514d..6c00a1e6c64328 100644 --- a/test/parallel/test-http-abort-client.js +++ b/test/parallel/test-http-abort-client.js @@ -2,7 +2,7 @@ const common = require('../common'); 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 3a6cc5365812f0..d983d447934e41 100644 --- a/test/parallel/test-http-agent-destroyed-socket.js +++ b/test/parallel/test-http-agent-destroyed-socket.js @@ -3,26 +3,26 @@ require('../common'); 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) { + const 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 14a058a6f8f2d9..b2bf6334dcbc1b 100644 --- a/test/parallel/test-http-agent-error-on-idle.js +++ b/test/parallel/test-http-agent-error-on-idle.js @@ -2,37 +2,37 @@ require('../common'); const assert = require('assert'); const http = require('http'); -var Agent = http.Agent; +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 65da4b836a9fe1..5c9907bb706d32 100644 --- a/test/parallel/test-http-agent-false.js +++ b/test/parallel/test-http-agent-false.js @@ -6,7 +6,7 @@ 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 b71cbd95c4556c..6814aca3e76fbc 100644 --- a/test/parallel/test-http-agent-maxsockets.js +++ b/test/parallel/test-http-agent-maxsockets.js @@ -3,14 +3,14 @@ require('../common'); 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 e2c748b011f545..a11489b6c5bc2b 100644 --- a/test/parallel/test-http-agent-no-protocol.js +++ b/test/parallel/test-http-agent-no-protocol.js @@ -3,10 +3,10 @@ const common = require('../common'); 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 426ec3bb762909..9071b88b98997a 100644 --- a/test/parallel/test-http-agent-null.js +++ b/test/parallel/test-http-agent-null.js @@ -2,10 +2,10 @@ const common = require('../common'); 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 443af96215fd92..85975979cb3265 100644 --- a/test/parallel/test-http-agent.js +++ b/test/parallel/test-http-agent.js @@ -3,20 +3,20 @@ require('../common'); 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 b15330342ce0cb..5fc8d780af9396 100644 --- a/test/parallel/test-http-automatic-headers.js +++ b/test/parallel/test-http-automatic-headers.js @@ -3,7 +3,7 @@ require('../common'); 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 863cbed19d790b..2a6bf482077166 100644 --- a/test/parallel/test-http-blank-header.js +++ b/test/parallel/test-http-blank-header.js @@ -4,7 +4,7 @@ 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 d71f3bdb783267..c240cd13b1825c 100644 --- a/test/parallel/test-http-buffer-sanity.js +++ b/test/parallel/test-http-buffer-sanity.js @@ -3,26 +3,26 @@ const common = require('../common'); 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 1ef5f2398d77ed..3b295ebdcc1c49 100644 --- a/test/parallel/test-http-byteswritten.js +++ b/test/parallel/test-http-byteswritten.js @@ -3,9 +3,9 @@ const common = require('../common'); 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.js b/test/parallel/test-http-chunked.js index d8891db6c75aea..516523221133ec 100644 --- a/test/parallel/test-http-chunked.js +++ b/test/parallel/test-http-chunked.js @@ -3,23 +3,23 @@ require('../common'); 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 00c989ca919dc7..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'); const http = require('http'); -var server = http.createServer(function(req, res) { +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 346b781ef08dfd..7c7be9b530e2d2 100644 --- a/test/parallel/test-http-client-abort2.js +++ b/test/parallel/test-http-client-abort2.js @@ -2,12 +2,12 @@ require('../common'); 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 8093100fce2b88..3c2b9c89727467 100644 --- a/test/parallel/test-http-client-agent.js +++ b/test/parallel/test-http-client-agent.js @@ -3,11 +3,11 @@ require('../common'); 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 3a1f52819335b8..2271944773d9db 100644 --- a/test/parallel/test-http-client-default-headers-exist.js +++ b/test/parallel/test-http-client-default-headers-exist.js @@ -3,7 +3,7 @@ require('../common'); 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-get-url.js b/test/parallel/test-http-client-get-url.js index d9a5e9325699d2..9311110bdc041c 100644 --- a/test/parallel/test-http-client-get-url.js +++ b/test/parallel/test-http-client-get-url.js @@ -5,7 +5,7 @@ const http = require('http'); const url = require('url'); const URL = url.URL; -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 c7469c1562566a..0d8f577a78566c 100644 --- a/test/parallel/test-http-client-parse-error.js +++ b/test/parallel/test-http-client-parse-error.js @@ -5,8 +5,8 @@ const assert = require('assert'); 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 04f308e76d8cc5..d4ccba8d55b036 100644 --- a/test/parallel/test-http-client-pipe-end.js +++ b/test/parallel/test-http-client-pipe-end.js @@ -4,7 +4,7 @@ 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 80a8252528fb0b..d9e89b85eca1ed 100644 --- a/test/parallel/test-http-client-race-2.js +++ b/test/parallel/test-http-client-race-2.js @@ -9,14 +9,14 @@ const url = require('url'); // 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,15 +29,15 @@ 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() { // // Client #1 is assigned Parser #1 // - var req1 = http.get({ port: this.address().port, path: '/1' }); + const req1 = http.get({ port: this.address().port, path: '/1' }); req1.on('response', function(res1) { res1.setEncoding('utf8'); @@ -59,7 +59,7 @@ server.on('listening', function() { // 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 = http.get({ port: server.address().port, path: '/2' }); + const req2 = http.get({ port: server.address().port, path: '/2' }); req2.on('response', function(res2) { res2.setEncoding('utf8'); res2.on('data', function(chunk) { body2 += chunk; }); @@ -69,7 +69,7 @@ server.on('listening', function() { // Just to be really sure we've covered all our bases, execute a // request using client2. // - var req3 = http.get({ port: server.address().port, path: '/3' }); + const req3 = http.get({ port: server.address().port, path: '/3' }); req3.on('response', function(res3) { res3.setEncoding('utf8'); res3.on('data', function(chunk) { body3 += chunk; }); diff --git a/test/parallel/test-http-client-race.js b/test/parallel/test-http-client-race.js index af8e18686b83d7..14e3300f20a436 100644 --- a/test/parallel/test-http-client-race.js +++ b/test/parallel/test-http-client-race.js @@ -4,22 +4,22 @@ 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 96085ae51f22b6..69b24f73771d41 100644 --- a/test/parallel/test-http-client-read-in-error.js +++ b/test/parallel/test-http-client-read-in-error.js @@ -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 84db25f7b023c3..16a18342468f94 100644 --- a/test/parallel/test-http-client-timeout-agent.js +++ b/test/parallel/test-http-client-timeout-agent.js @@ -3,9 +3,9 @@ require('../common'); 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 e26c93fe0026a8..0caae0d04c333c 100644 --- a/test/parallel/test-http-client-timeout.js +++ b/test/parallel/test-http-client-timeout.js @@ -3,20 +3,20 @@ require('../common'); 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 e17a2c5ee5698b..338aab9cc59ba0 100644 --- a/test/parallel/test-http-client-upload-buf.js +++ b/test/parallel/test-http-client-upload-buf.js @@ -3,12 +3,12 @@ const common = require('../common'); 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 ce2608fcfde0f3..ba60681776ba49 100644 --- a/test/parallel/test-http-client-upload.js +++ b/test/parallel/test-http-client-upload.js @@ -3,11 +3,11 @@ const common = require('../common'); 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 f244838bc47013..f7f08a6bf42c81 100644 --- a/test/parallel/test-http-conn-reset.js +++ b/test/parallel/test-http-conn-reset.js @@ -4,13 +4,13 @@ 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 fd1c8004ffef2d..3d6882d92f04b3 100644 --- a/test/parallel/test-http-content-length.js +++ b/test/parallel/test-http-content-length.js @@ -3,25 +3,25 @@ require('../common'); 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 c4c8699df7fc47..46eec45ed2757f 100644 --- a/test/parallel/test-http-contentLength0.js +++ b/test/parallel/test-http-contentLength0.js @@ -7,13 +7,13 @@ const http = require('http'); // 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) { + const request = http.request({ port: this.address().port }, (response) => { console.log('STATUS: ' + response.statusCode); s.close(); response.resume(); diff --git a/test/parallel/test-http-date-header.js b/test/parallel/test-http-date-header.js index 5b9df4c1747bb0..e14a92b310f2d1 100644 --- a/test/parallel/test-http-date-header.js +++ b/test/parallel/test-http-date-header.js @@ -3,9 +3,9 @@ require('../common'); 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 0026540373c0aa..46327085184069 100644 --- a/test/parallel/test-http-default-encoding.js +++ b/test/parallel/test-http-default-encoding.js @@ -3,10 +3,10 @@ require('../common'); 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-destroyed-socket-write2.js b/test/parallel/test-http-destroyed-socket-write2.js index bb3f5d64cbca8b..01023a088576ef 100644 --- a/test/parallel/test-http-destroyed-socket-write2.js +++ b/test/parallel/test-http-destroyed-socket-write2.js @@ -6,14 +6,14 @@ const assert = require('assert'); // where the server has ended the socket. const http = require('http'); -var server = http.createServer(function(req, res) { +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-eof-on-connect.js b/test/parallel/test-http-eof-on-connect.js index 765d8b35e7cfd3..f67e45ed403225 100644 --- a/test/parallel/test-http-eof-on-connect.js +++ b/test/parallel/test-http-eof-on-connect.js @@ -7,7 +7,7 @@ const http = require('http'); // 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 8ee46316e98b23..c003db131065a3 100644 --- a/test/parallel/test-http-exceptions.js +++ b/test/parallel/test-http-exceptions.js @@ -2,7 +2,7 @@ require('../common'); 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 954d6b6211c27e..0cf90e3b115e60 100644 --- a/test/parallel/test-http-expect-continue.js +++ b/test/parallel/test-http-expect-continue.js @@ -3,11 +3,11 @@ require('../common'); 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 1866d88a33cbd5..6ebecaad1300de 100644 --- a/test/parallel/test-http-extra-response.js +++ b/test/parallel/test-http-extra-response.js @@ -8,8 +8,8 @@ const net = require('net'); // 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 524965d2d7af5f..e8f5782c2f7857 100644 --- a/test/parallel/test-http-flush.js +++ b/test/parallel/test-http-flush.js @@ -6,7 +6,7 @@ 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 be6749cc042f0d..c834c6e6545320 100644 --- a/test/parallel/test-http-full-response.js +++ b/test/parallel/test-http-full-response.js @@ -5,11 +5,11 @@ const assert = require('assert'); 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 d4e075d229184f..15c96a9a4e12ea 100644 --- a/test/parallel/test-http-get-pipeline-problem.js +++ b/test/parallel/test-http-get-pipeline-problem.js @@ -11,14 +11,14 @@ 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 eb31930a343c4d..de94dfb8b7d6e7 100644 --- a/test/parallel/test-http-head-request.js +++ b/test/parallel/test-http-head-request.js @@ -2,10 +2,10 @@ const common = require('../common'); 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 cd2c22c8fa1926..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 @@ -6,14 +6,14 @@ const http = require('http'); // 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 17107d3b6743a5..b2eb98b1eea06c 100644 --- a/test/parallel/test-http-head-response-has-no-body.js +++ b/test/parallel/test-http-head-response-has-no-body.js @@ -6,14 +6,14 @@ const http = require('http'); // 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 42d7e9af5f8566..3d9e756d505238 100644 --- a/test/parallel/test-http-header-read.js +++ b/test/parallel/test-http-header-read.js @@ -6,9 +6,9 @@ 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 2fcabb0691ec22..211f818e566699 100644 --- a/test/parallel/test-http-hex-write.js +++ b/test/parallel/test-http-hex-write.js @@ -4,7 +4,7 @@ const assert = require('assert'); 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 0adf5716b7e776..0f6233190ce875 100644 --- a/test/parallel/test-http-host-headers.js +++ b/test/parallel/test-http-host-headers.js @@ -26,7 +26,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 b69e90c03809f2..15d5d62d429658 100644 --- a/test/parallel/test-http-keep-alive-close-on-header.js +++ b/test/parallel/test-http-keep-alive-close-on-header.js @@ -3,22 +3,22 @@ require('../common'); 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 55c3342a115f90..c9cf7bba96a7db 100644 --- a/test/parallel/test-http-keepalive-client.js +++ b/test/parallel/test-http-keepalive-client.js @@ -5,8 +5,8 @@ const assert = require('assert'); 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; +const 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 ffe1472a3cba85..14e9e88ef7fd09 100644 --- a/test/parallel/test-http-keepalive-maxsockets.js +++ b/test/parallel/test-http-keepalive-maxsockets.js @@ -5,21 +5,21 @@ const assert = require('assert'); 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 102f65bb08526f..dc9bdefb333d13 100644 --- a/test/parallel/test-http-keepalive-request.js +++ b/test/parallel/test-http-keepalive-request.js @@ -5,8 +5,8 @@ const assert = require('assert'); 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; +const 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-localaddress-bind-error.js b/test/parallel/test-http-localaddress-bind-error.js index 0290c6a584c959..a23c6f2a4452a6 100644 --- a/test/parallel/test-http-localaddress-bind-error.js +++ b/test/parallel/test-http-localaddress-bind-error.js @@ -2,9 +2,9 @@ const common = require('../common'); 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 6739a44b6c82f9..a36c9fdbe29451 100644 --- a/test/parallel/test-http-malformed-request.js +++ b/test/parallel/test-http-malformed-request.js @@ -8,10 +8,10 @@ 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 5fa8e53e01d1d0..b4af99ef00a9d4 100644 --- a/test/parallel/test-http-many-ended-pipelines.js +++ b/test/parallel/test-http-many-ended-pipelines.js @@ -2,7 +2,7 @@ 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'); @@ -11,10 +11,10 @@ console.trace = function() { 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 0abddbd2cbf5c4..018ed33c1b9e49 100644 --- a/test/parallel/test-http-max-headers-count.js +++ b/test/parallel/test-http-max-headers-count.js @@ -3,24 +3,24 @@ require('../common'); 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-multi-line-headers.js b/test/parallel/test-http-multi-line-headers.js index 9c0d758ed571ad..2096f533a196d1 100644 --- a/test/parallel/test-http-multi-line-headers.js +++ b/test/parallel/test-http-multi-line-headers.js @@ -5,10 +5,10 @@ const assert = require('assert'); 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-no-content-length.js b/test/parallel/test-http-no-content-length.js index a393d58d57413f..a6cfad13aa2b44 100644 --- a/test/parallel/test-http-no-content-length.js +++ b/test/parallel/test-http-no-content-length.js @@ -4,12 +4,12 @@ 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 06630e61787e01..73654909d88e1b 100644 --- a/test/parallel/test-http-outgoing-finish.js +++ b/test/parallel/test-http-outgoing-finish.js @@ -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 9eddb2bb3bcd77..69682128fadbdf 100644 --- a/test/parallel/test-http-parser-bad-ref.js +++ b/test/parallel/test-http-parser-bad-ref.js @@ -6,15 +6,15 @@ require('../common'); const assert = require('assert'); -var HTTPParser = process.binding('http_parser').HTTPParser; +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 e9ddfa27e5a5c5..80cc3cc64ee5b3 100644 --- a/test/parallel/test-http-parser-free.js +++ b/test/parallel/test-http-parser-free.js @@ -2,19 +2,19 @@ require('../common'); const assert = require('assert'); const http = require('http'); -var N = 100; -var responses = 0; +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 8617a093fbd311..e1215fbd13ae40 100644 --- a/test/parallel/test-http-parser.js +++ b/test/parallel/test-http-parser.js @@ -6,14 +6,14 @@ 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 3c96dc6792fdad..8bb8dd4b5da25c 100644 --- a/test/parallel/test-http-pause.js +++ b/test/parallel/test-http-pause.js @@ -3,12 +3,12 @@ require('../common'); 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 5b3eb87a145a0f..5348637bd07145 100644 --- a/test/parallel/test-http-pipe-fs.js +++ b/test/parallel/test-http-pipe-fs.js @@ -6,10 +6,10 @@ 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 bfa928afb3de8b..8e7fd55a0ed6ea 100644 --- a/test/parallel/test-http-proxy.js +++ b/test/parallel/test-http-proxy.js @@ -4,23 +4,23 @@ 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 0c7cc18415e914..7ae0c35e3d8d11 100644 --- a/test/parallel/test-http-raw-headers.js +++ b/test/parallel/test-http-raw-headers.js @@ -5,7 +5,7 @@ const assert = require('assert'); 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 bf417597b18244..077ff0f5b33f40 100644 --- a/test/parallel/test-http-remove-header-stays-removed.js +++ b/test/parallel/test-http-remove-header-stays-removed.js @@ -4,7 +4,7 @@ const assert = require('assert'); 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 5dd21d06dee6a6..ab30c0a1eef8a1 100644 --- a/test/parallel/test-http-request-end-twice.js +++ b/test/parallel/test-http-request-end-twice.js @@ -3,12 +3,12 @@ require('../common'); 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 207c3564fb5519..dd4a8caf105329 100644 --- a/test/parallel/test-http-request-end.js +++ b/test/parallel/test-http-request-end.js @@ -3,10 +3,10 @@ require('../common'); 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 b24779adf8f1ab..e4579791ef301a 100644 --- a/test/parallel/test-http-request-methods.js +++ b/test/parallel/test-http-request-methods.js @@ -7,7 +7,7 @@ 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 @@ const 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 d01753b88a5da2..2ee0e4e29d95e4 100644 --- a/test/parallel/test-http-res-write-after-end.js +++ b/test/parallel/test-http-res-write-after-end.js @@ -3,7 +3,7 @@ const common = require('../common'); 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 cbae755b4fbc7f..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 @@ -3,9 +3,9 @@ require('../common'); 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 6b5966735a156e..de179c113e1db1 100644 --- a/test/parallel/test-http-response-close.js +++ b/test/parallel/test-http-response-close.js @@ -2,7 +2,7 @@ const common = require('../common'); 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 4c261fc2adc7d4..3f44b4ef5fde0b 100644 --- a/test/parallel/test-http-response-no-headers.js +++ b/test/parallel/test-http-response-no-headers.js @@ -4,28 +4,28 @@ 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 f8ecd5bab58e6c..07c0a40e4bf1a8 100644 --- a/test/parallel/test-http-response-readable.js +++ b/test/parallel/test-http-response-readable.js @@ -3,7 +3,7 @@ require('../common'); 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 e4021e78317759..f6c3a04064ec1c 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; const server = http.createServer((req, res) => { switch (count++) { diff --git a/test/parallel/test-http-response-status-message.js b/test/parallel/test-http-response-status-message.js index cfc9e6420905ad..d17dfb24c6b4c8 100644 --- a/test/parallel/test-http-response-status-message.js +++ b/test/parallel/test-http-response-status-message.js @@ -4,9 +4,9 @@ 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-response-statuscode.js b/test/parallel/test-http-response-statuscode.js index 57256db6032324..4bd75647aebea7 100644 --- a/test/parallel/test-http-response-statuscode.js +++ b/test/parallel/test-http-response-statuscode.js @@ -4,7 +4,7 @@ const assert = require('assert'); const http = require('http'); const MAX_REQUESTS = 12; -var reqNum = 0; +let reqNum = 0; const server = http.Server(common.mustCall(function(req, res) { switch (reqNum) { 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 b978cb3ad4aad9..189ab0657bacb0 100644 --- a/test/parallel/test-http-server-multiheaders.js +++ b/test/parallel/test-http-server-multiheaders.js @@ -7,7 +7,7 @@ require('../common'); 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 ba0710f70c839a..82cc9960329a11 100644 --- a/test/parallel/test-http-server-multiheaders2.js +++ b/test/parallel/test-http-server-multiheaders2.js @@ -7,7 +7,7 @@ require('../common'); 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 04e9635403614c..3728453c039447 100644 --- a/test/parallel/test-http-server-stale-close.js +++ b/test/parallel/test-http-server-stale-close.js @@ -5,7 +5,7 @@ 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 fd5486a289e590..fca2691aacc25d 100644 --- a/test/parallel/test-http-server-unconsume.js +++ b/test/parallel/test-http-server-unconsume.js @@ -4,9 +4,9 @@ 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 c915272af2b9bf..90c2709ebdbc5c 100644 --- a/test/parallel/test-http-server.js +++ b/test/parallel/test-http-server.js @@ -6,12 +6,12 @@ const http = require('http'); const url = require('url'); const qs = require('querystring'); -var request_number = 0; -var requests_sent = 0; -var server_response = ''; -var client_got_eof = false; +let request_number = 0; +let requests_sent = 0; +let server_response = ''; +let client_got_eof = false; -var server = http.createServer(function(req, res) { +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 3fa01655b4acdb..cb06352b3ca85d 100644 --- a/test/parallel/test-http-set-cookies.js +++ b/test/parallel/test-http-set-cookies.js @@ -3,9 +3,9 @@ require('../common'); 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 03fca8f219300b..7a2447763e4cf9 100644 --- a/test/parallel/test-http-set-timeout-server.js +++ b/test/parallel/test-http-set-timeout-server.js @@ -4,7 +4,7 @@ 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 e34ea889b0bed4..7b66933ecd12cd 100644 --- a/test/parallel/test-http-set-trailers.js +++ b/test/parallel/test-http-set-trailers.js @@ -4,9 +4,9 @@ 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 5cfbd51e76ac9e..77a3c3922a20f0 100644 --- a/test/parallel/test-http-should-keep-alive.js +++ b/test/parallel/test-http-should-keep-alive.js @@ -4,7 +4,7 @@ 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 0b3d204c435a2b..b5060109bf4985 100644 --- a/test/parallel/test-http-status-code.js +++ b/test/parallel/test-http-status-code.js @@ -6,12 +6,12 @@ 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 9a086dcd4673fd..668b02ee0780b4 100644 --- a/test/parallel/test-http-status-message.js +++ b/test/parallel/test-http-status-message.js @@ -4,7 +4,7 @@ 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 c045a28ce75df1..39b4550d57e529 100644 --- a/test/parallel/test-http-timeout-overflow.js +++ b/test/parallel/test-http-timeout-overflow.js @@ -4,10 +4,10 @@ const assert = require('assert'); 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 128ca148839b6b..63f87ed63089ee 100644 --- a/test/parallel/test-http-timeout.js +++ b/test/parallel/test-http-timeout.js @@ -3,22 +3,22 @@ require('../common'); 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 27f21649a7d508..a196ba904905a3 100644 --- a/test/parallel/test-http-upgrade-agent.js +++ b/test/parallel/test-http-upgrade-agent.js @@ -10,7 +10,7 @@ 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 f5c25f15d4136c..34e3e8f24158e7 100644 --- a/test/parallel/test-http-upgrade-client.js +++ b/test/parallel/test-http-upgrade-client.js @@ -10,7 +10,7 @@ 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 03cb36981ad6d7..fa14f8ca51f030 100644 --- a/test/parallel/test-http-upgrade-client2.js +++ b/test/parallel/test-http-upgrade-client2.js @@ -2,9 +2,9 @@ const common = require('../common'); 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 50183dffe18ae7..221263e98ce9cd 100644 --- a/test/parallel/test-http-upgrade-server.js +++ b/test/parallel/test-http-upgrade-server.js @@ -7,9 +7,9 @@ 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(); +const 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 e7533b194d0760..c64b2e843637af 100644 --- a/test/parallel/test-http-upgrade-server2.js +++ b/test/parallel/test-http-upgrade-server2.js @@ -4,7 +4,7 @@ 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 9781cefcbdb23a..d91ec75f60d767 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 @@ -9,7 +9,7 @@ function check(request) { 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 72e69b14a9a3b8..25913f4e49a12a 100644 --- a/test/parallel/test-http-url.parse-auth.js +++ b/test/parallel/test-http-url.parse-auth.js @@ -9,7 +9,7 @@ function check(request) { 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 0fa8f104653162..ac22b6e38d80e1 100644 --- a/test/parallel/test-http-url.parse-basic.js +++ b/test/parallel/test-http-url.parse-basic.js @@ -4,7 +4,7 @@ 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 ddd1d5147532b1..ad40e76debee90 100644 --- a/test/parallel/test-http-url.parse-https.request.js +++ b/test/parallel/test-http-url.parse-https.request.js @@ -12,7 +12,7 @@ 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-path.js b/test/parallel/test-http-url.parse-path.js index e5a1306f8ee077..6fab8bb0eb3b6b 100644 --- a/test/parallel/test-http-url.parse-path.js +++ b/test/parallel/test-http-url.parse-path.js @@ -9,7 +9,7 @@ function check(request) { 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 3ea40de6ecca5d..d63f404c5403dd 100644 --- a/test/parallel/test-http-url.parse-post.js +++ b/test/parallel/test-http-url.parse-post.js @@ -4,7 +4,7 @@ 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 47cc0c03a6cfc5..f2a5d1806d89a2 100644 --- a/test/parallel/test-http-url.parse-search.js +++ b/test/parallel/test-http-url.parse-search.js @@ -9,7 +9,7 @@ function check(request) { 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 795f1794777cef..a633873c8bb16f 100644 --- a/test/parallel/test-http-wget.js +++ b/test/parallel/test-http-wget.js @@ -19,7 +19,7 @@ const 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 59010256559144..3783dc305e39a7 100644 --- a/test/parallel/test-http-write-callbacks.js +++ b/test/parallel/test-http-write-callbacks.js @@ -4,13 +4,13 @@ const assert = require('assert'); 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 c659c47fa47bc6..69463fb3a50852 100644 --- a/test/parallel/test-http-write-empty-string.js +++ b/test/parallel/test-http-write-empty-string.js @@ -4,7 +4,7 @@ const assert = require('assert'); 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 9807dc6943f13c..12f5e00b0db493 100644 --- a/test/parallel/test-http-write-head.js +++ b/test/parallel/test-http-write-head.js @@ -6,11 +6,11 @@ const http = require('http'); // Verify that ServerResponse.writeHead() works as setHeader. // Issue 5036 on github. -var s = http.createServer(function(req, res) { +const s = http.createServer(function(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 b446fd77860e83..63446e460471e4 100644 --- a/test/parallel/test-http-zero-length-write.js +++ b/test/parallel/test-http-zero-length-write.js @@ -9,10 +9,10 @@ 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 2f59118e3673ea..8e694a61b72a03 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 09a0f6bdd6b701..a321f7140396a3 100644 --- a/test/parallel/test-https-agent-servername.js +++ b/test/parallel/test-https-agent-servername.js @@ -9,14 +9,14 @@ if (!common.hasCrypto) { 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 51f59bc311d0b1..cdea4d1ee930f3 100644 --- a/test/parallel/test-https-byteswritten.js +++ b/test/parallel/test-https-byteswritten.js @@ -9,14 +9,14 @@ if (!common.hasCrypto) { } 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 82f03320c4fb5c..688c7e22706e0e 100644 --- a/test/parallel/test-https-client-checkServerIdentity.js +++ b/test/parallel/test-https-client-checkServerIdentity.js @@ -11,12 +11,12 @@ const https = require('https'); 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 6852967848a16b..1f4f6ff748b410 100644 --- a/test/parallel/test-https-client-get-url.js +++ b/test/parallel/test-https-client-get-url.js @@ -15,12 +15,12 @@ const fs = require('fs'); const url = require('url'); const URL = url.URL; -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 32626b0a05f946..92bbabe8b3be90 100644 --- a/test/parallel/test-https-client-reject.js +++ b/test/parallel/test-https-client-reject.js @@ -11,12 +11,12 @@ const https = require('https'); 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 58a06c70e2a5da..79e1a716bd77cf 100644 --- a/test/parallel/test-https-client-resume.js +++ b/test/parallel/test-https-client-resume.js @@ -14,21 +14,21 @@ const https = require('https'); 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 3bfab5f626efd2..ae8507f99cbc00 100644 --- a/test/parallel/test-https-connecting-to-http.js +++ b/test/parallel/test-https-connecting-to-http.js @@ -10,10 +10,10 @@ if (!common.hasCrypto) { } 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 0f6501e8ef5603..0b18795078fd1f 100644 --- a/test/parallel/test-https-drain.js +++ b/test/parallel/test-https-drain.js @@ -11,28 +11,28 @@ const https = require('https'); 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 81d4e978a87672..d5e896c7695cfd 100644 --- a/test/parallel/test-https-eof-for-eom.js +++ b/test/parallel/test-https-eof-for-eom.js @@ -19,13 +19,13 @@ 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 = 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 6be850a11ed633..f1b8d442e27893 100644 --- a/test/parallel/test-https-foafssl.js +++ b/test/parallel/test-https-foafssl.js @@ -18,7 +18,7 @@ if (!common.hasCrypto) { } 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 25de4435ea3b28..190f15f29a8078 100644 --- a/test/parallel/test-https-host-headers.js +++ b/test/parallel/test-https-host-headers.js @@ -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 2382d59a7c36af..662d6f080a0fff 100644 --- a/test/parallel/test-https-localaddress-bind-error.js +++ b/test/parallel/test-https-localaddress-bind-error.js @@ -8,14 +8,14 @@ if (!common.hasCrypto) { } 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 22e96eb4675417..78583b38ecf1cf 100644 --- a/test/parallel/test-https-localaddress.js +++ b/test/parallel/test-https-localaddress.js @@ -14,12 +14,12 @@ if (!common.hasMultiLocalhost()) { 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 8d0f51b6a51c82..c30bbc0848d137 100644 --- a/test/parallel/test-https-pfx.js +++ b/test/parallel/test-https-pfx.js @@ -9,9 +9,9 @@ if (!common.hasCrypto) { } 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 d0d20a73ad16df..4298abe5eff43d 100644 --- a/test/parallel/test-https-req-split.js +++ b/test/parallel/test-https-req-split.js @@ -12,7 +12,7 @@ const https = require('https'); 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 72d77104255beb..cc712b312485b2 100644 --- a/test/parallel/test-https-resume-after-renew.js +++ b/test/parallel/test-https-resume-after-renew.js @@ -9,24 +9,25 @@ 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(); server._sharedCreds.context.onticketkeycallback = function(name, iv, enc) { + let newName, newIV; 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 ]; @@ -36,7 +37,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 fbf16a0ce32268..4cf999667d7384 100644 --- a/test/parallel/test-https-set-timeout-server.js +++ b/test/parallel/test-https-set-timeout-server.js @@ -11,9 +11,9 @@ const https = require('https'); 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)); + const 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)); + const 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 337cc264a2587c..05137b35c437ff 100644 --- a/test/parallel/test-https-socket-options.js +++ b/test/parallel/test-https-socket-options.js @@ -11,16 +11,16 @@ const fs = require('fs'); 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-timeout-server-2.js b/test/parallel/test-https-timeout-server-2.js index a17abec5398ada..8729af1ae8b4ba 100644 --- a/test/parallel/test-https-timeout-server-2.js +++ b/test/parallel/test-https-timeout-server-2.js @@ -12,15 +12,15 @@ const https = require('https'); 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-icu-transcode.js b/test/parallel/test-icu-transcode.js index 463b2fca9188ba..0766f8c6d460d8 100644 --- a/test/parallel/test-icu-transcode.js +++ b/test/parallel/test-icu-transcode.js @@ -23,7 +23,7 @@ const tests = { for (const test in tests) { const dest = buffer.transcode(orig, 'utf8', test); assert.strictEqual(dest.length, tests[test].length); - for (var n = 0; n < tests[test].length; n++) + for (let n = 0; n < tests[test].length; n++) assert.strictEqual(dest[n], tests[test][n]); } diff --git a/test/parallel/test-listen-fd-cluster.js b/test/parallel/test-listen-fd-cluster.js index 001eb007f2532c..de1fbed7b56aff 100644 --- a/test/parallel/test-listen-fd-cluster.js +++ b/test/parallel/test-listen-fd-cluster.js @@ -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,7 +61,7 @@ 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() { @@ -69,7 +69,7 @@ function test(cb) { console.error('server listening on %d', port); const spawn = require('child_process').spawn; - var master = spawn(process.execPath, [__filename, 'master'], { + 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 9699232d2e0088..2ac4d83dba6691 100644 --- a/test/parallel/test-listen-fd-detached-inherit.js +++ b/test/parallel/test-listen-fd-detached-inherit.js @@ -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 4ec3654a2166cf..1194d001610fce 100644 --- a/test/parallel/test-listen-fd-detached.js +++ b/test/parallel/test-listen-fd-detached.js @@ -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); const spawn = require('child_process').spawn; - var child = spawn(process.execPath, [__filename, 'child'], { + 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 87a624f7137562..60aa8717a8c24e 100644 --- a/test/parallel/test-listen-fd-server.js +++ b/test/parallel/test-listen-fd-server.js @@ -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,7 +67,7 @@ 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() { @@ -75,7 +75,7 @@ function test(cb) { console.error('server listening on %d', port); const spawn = require('child_process').spawn; - var child = spawn(process.execPath, [__filename, 'child'], { + 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 ce74dd3be3c4e5..09ab270b70fa21 100644 --- a/test/parallel/test-memory-usage-emfile.js +++ b/test/parallel/test-memory-usage-emfile.js @@ -4,10 +4,10 @@ const assert = require('assert'); 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 400e17aa008a90..cba3f9a5172a07 100644 --- a/test/parallel/test-memory-usage.js +++ b/test/parallel/test-memory-usage.js @@ -2,7 +2,7 @@ require('../common'); 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 2e865041dfc209..7110af7648ae8a 100644 --- a/test/parallel/test-microtask-queue-integration-domain.js +++ b/test/parallel/test-microtask-queue-integration-domain.js @@ -9,21 +9,21 @@ const 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 f4f518caa30c93..d212bbae96b001 100644 --- a/test/parallel/test-microtask-queue-integration.js +++ b/test/parallel/test-microtask-queue-integration.js @@ -2,21 +2,21 @@ require('../common'); 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 57ba4543a3f6cd..7d34ec829a003c 100644 --- a/test/parallel/test-microtask-queue-run-domain.js +++ b/test/parallel/test-microtask-queue-run-domain.js @@ -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 5241b6c4a91e9d..e09087f74e32a9 100644 --- a/test/parallel/test-microtask-queue-run-immediate-domain.js +++ b/test/parallel/test-microtask-queue-run-immediate-domain.js @@ -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 b21af670ffdb9d..c5ed6c6dcbc1ae 100644 --- a/test/parallel/test-microtask-queue-run-immediate.js +++ b/test/parallel/test-microtask-queue-run-immediate.js @@ -6,7 +6,7 @@ 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 3150c9ebda514a..71e1fbedbaecbd 100644 --- a/test/parallel/test-microtask-queue-run.js +++ b/test/parallel/test-microtask-queue-run.js @@ -6,7 +6,7 @@ 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 66511e51eddb11..ec90f1a3e2c868 100644 --- a/test/parallel/test-module-globalpaths-nodepath.js +++ b/test/parallel/test-module-globalpaths-nodepath.js @@ -3,8 +3,8 @@ const common = require('../common'); const assert = require('assert'); 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'; diff --git a/test/parallel/test-module-loading-error.js b/test/parallel/test-module-loading-error.js index b8454f2ae9ffb0..d78f61de60fa14 100644 --- a/test/parallel/test-module-loading-error.js +++ b/test/parallel/test-module-loading-error.js @@ -4,13 +4,13 @@ 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-net-after-close.js b/test/parallel/test-net-after-close.js index db658bcb03de06..d46f096116d02e 100644 --- a/test/parallel/test-net-after-close.js +++ b/test/parallel/test-net-after-close.js @@ -3,13 +3,13 @@ const common = require('../common'); 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 bf18e14898fbf0..2f821ef5d703be 100644 --- a/test/parallel/test-net-better-error-messages-path.js +++ b/test/parallel/test-net-better-error-messages-path.js @@ -2,8 +2,8 @@ const common = require('../common'); const net = require('net'); const assert = require('assert'); -var fp = '/tmp/fadagagsdfgsdf'; -var c = net.connect(fp); +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 68e93a75f0154a..17fdc90cb3742b 100644 --- a/test/parallel/test-net-bind-twice.js +++ b/test/parallel/test-net-bind-twice.js @@ -3,9 +3,9 @@ const common = require('../common'); 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 dfaf5dd50d6614..e8ba17a76e6c69 100644 --- a/test/parallel/test-net-buffersize.js +++ b/test/parallel/test-net-buffersize.js @@ -3,9 +3,9 @@ require('../common'); 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 518b2f10ba37d4..4cc6eee8373e86 100644 --- a/test/parallel/test-net-bytes-stats.js +++ b/test/parallel/test-net-bytes-stats.js @@ -3,11 +3,11 @@ require('../common'); 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 c5333e2522711e..faa460e847aa08 100644 --- a/test/parallel/test-net-can-reset-timeout.js +++ b/test/parallel/test-net-can-reset-timeout.js @@ -2,7 +2,7 @@ const common = require('../common'); 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 187cbf19426653..c43ee1abd0e305 100644 --- a/test/parallel/test-net-connect-buffer.js +++ b/test/parallel/test-net-connect-buffer.js @@ -3,15 +3,15 @@ require('../common'); 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 197b283bdf3621..8f1784565d38ee 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 727504b06fc7e2..e794c40859856a 100644 --- a/test/parallel/test-net-connect-options.js +++ b/test/parallel/test-net-connect-options.js @@ -3,7 +3,7 @@ const common = require('../common'); 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-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 d643910d62e0d4..c7a01f5fa6faec 100644 --- a/test/parallel/test-net-dns-custom-lookup.js +++ b/test/parallel/test-net-dns-custom-lookup.js @@ -4,13 +4,13 @@ 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 f5a1dcc6b1c2c5..aa288c5fde1ffa 100644 --- a/test/parallel/test-net-dns-error.js +++ b/test/parallel/test-net-dns-error.js @@ -4,13 +4,13 @@ const assert = require('assert'); 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 60674053f7a53c..0997e6cc6c1c5d 100644 --- a/test/parallel/test-net-dns-lookup-skip.js +++ b/test/parallel/test-net-dns-lookup-skip.js @@ -3,12 +3,12 @@ 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 c0aebf0ee919c3..8d9930f4b7a366 100644 --- a/test/parallel/test-net-dns-lookup.js +++ b/test/parallel/test-net-dns-lookup.js @@ -3,7 +3,7 @@ const common = require('../common'); 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 f6a5455ee7b0f1..e8723fb1a692a8 100644 --- a/test/parallel/test-net-during-close.js +++ b/test/parallel/test-net-during-close.js @@ -3,12 +3,12 @@ const common = require('../common'); 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 53ae1a0589262b..3d7ceb8d5e38f7 100644 --- a/test/parallel/test-net-eaddrinuse.js +++ b/test/parallel/test-net-eaddrinuse.js @@ -3,9 +3,9 @@ require('../common'); 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 0bbd2833626df7..99324b071d27d6 100644 --- a/test/parallel/test-net-end-without-connect.js +++ b/test/parallel/test-net-end-without-connect.js @@ -2,5 +2,5 @@ require('../common'); 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-keepalive.js b/test/parallel/test-net-keepalive.js index 8b6998fa831a78..68ed5f842ff13b 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 ba70275eb03e6f..83612111e2a0aa 100644 --- a/test/parallel/test-net-large-string.js +++ b/test/parallel/test-net-large-string.js @@ -3,12 +3,12 @@ const common = require('../common'); 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 18234a816e1b0d..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 @@ -2,7 +2,7 @@ const common = require('../common'); 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 b6ab99c60e2d51..0a45adecbe83e7 100644 --- a/test/parallel/test-net-listen-close-server.js +++ b/test/parallel/test-net-listen-close-server.js @@ -2,7 +2,7 @@ const common = require('../common'); 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 009d12b09e7aca..7b721d1004f37f 100644 --- a/test/parallel/test-net-listen-error.js +++ b/test/parallel/test-net-listen-error.js @@ -2,7 +2,7 @@ const common = require('../common'); 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 974af6aaa60438..cc1ab4d805994f 100644 --- a/test/parallel/test-net-listen-exclusive-random-ports.js +++ b/test/parallel/test-net-listen-exclusive-random-ports.js @@ -7,11 +7,11 @@ 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-shared-ports.js b/test/parallel/test-net-listen-shared-ports.js index 4cd26ac330a67c..ce344be4a6f492 100644 --- a/test/parallel/test-net-listen-shared-ports.js +++ b/test/parallel/test-net-listen-shared-ports.js @@ -7,11 +7,11 @@ 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..b256d93b5f8400 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 3c105ff2877544..b100e4ae768c29 100644 --- a/test/parallel/test-net-localport.js +++ b/test/parallel/test-net-localport.js @@ -3,7 +3,7 @@ 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 febdc688519ca8..6338b5932de1fa 100644 --- a/test/parallel/test-net-persistent-keepalive.js +++ b/test/parallel/test-net-persistent-keepalive.js @@ -3,9 +3,9 @@ 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(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 bd34d303264a64..3f94424b0e1197 100644 --- a/test/parallel/test-net-persistent-nodelay.js +++ b/test/parallel/test-net-persistent-nodelay.js @@ -2,17 +2,17 @@ require('../common'); const assert = require('assert'); const net = require('net'); -var TCPWrap = process.binding('tcp_wrap').TCP; +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 9034a16f9a2793..1d3cbc6ffaef18 100644 --- a/test/parallel/test-net-persistent-ref-unref.js +++ b/test/parallel/test-net-persistent-ref-unref.js @@ -2,16 +2,16 @@ require('../common'); const assert = require('assert'); const net = require('net'); -var TCPWrap = process.binding('tcp_wrap').TCP; +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 c0c5589b396ee4..47171093ca13f9 100644 --- a/test/parallel/test-net-reconnect.js +++ b/test/parallel/test-net-reconnect.js @@ -4,12 +4,12 @@ const assert = require('assert'); 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 9cdf4ff7f876b8..a9d02631be5194 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.ok(remoteAddrCandidates.includes(socket.remoteAddress)); assert.ok(remoteFamilyCandidates.includes(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.ok(remoteAddrCandidates.includes(client.remoteAddress)); assert.ok(remoteFamilyCandidates.includes(client.remoteFamily)); diff --git a/test/parallel/test-net-server-bind.js b/test/parallel/test-net-server-bind.js index 623962e3abddca..e4dc64216441cf 100644 --- a/test/parallel/test-net-server-bind.js +++ b/test/parallel/test-net-server-bind.js @@ -6,8 +6,8 @@ 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 9f920a6a69b194..d52cccaacfd8e6 100644 --- a/test/parallel/test-net-server-close.js +++ b/test/parallel/test-net-server-close.js @@ -3,8 +3,8 @@ require('../common'); 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) { +const 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 ce3087713c3ad7..4e41d29a505199 100644 --- a/test/parallel/test-net-server-connections.js +++ b/test/parallel/test-net-server-connections.js @@ -7,6 +7,6 @@ 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 4d2c12102c4448..a678922683eeb1 100644 --- a/test/parallel/test-net-server-listen-remove-callback.js +++ b/test/parallel/test-net-server-listen-remove-callback.js @@ -4,10 +4,10 @@ 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 14a27da8f8cc3d..c7fe7c74a77d37 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 @@ -13,16 +13,16 @@ const 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) { +const 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 e75a4d83052aab..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'); const net = require('net'); -var server = net.createServer(); +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 bf8a9ef43ab12c..60df9fc700ec64 100644 --- a/test/parallel/test-net-server-unref.js +++ b/test/parallel/test-net-server-unref.js @@ -2,7 +2,7 @@ const common = require('../common'); 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 be82d9f2a678b4..998ad05a1d6487 100644 --- a/test/parallel/test-net-socket-destroy-twice.js +++ b/test/parallel/test-net-socket-destroy-twice.js @@ -2,7 +2,7 @@ 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 12fcc25b0a9563..9d091bd66f3a1e 100644 --- a/test/parallel/test-net-stream.js +++ b/test/parallel/test-net-stream.js @@ -3,7 +3,7 @@ require('../common'); 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 d8213a9b863b7b..0a1dcd98b2b3c7 100644 --- a/test/parallel/test-net-write-after-close.js +++ b/test/parallel/test-net-write-after-close.js @@ -2,7 +2,7 @@ const common = require('../common'); 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 15a30b826e18d9..ee20ede49fb5a5 100644 --- a/test/parallel/test-net-write-connect-write.js +++ b/test/parallel/test-net-write-connect-write.js @@ -3,11 +3,11 @@ const common = require('../common'); 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 7e183068f174cf..c1b2c60e2e202a 100644 --- a/test/parallel/test-net-write-slow.js +++ b/test/parallel/test-net-write-slow.js @@ -3,20 +3,20 @@ const common = require('../common'); 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 634e311da7f67b..6edb7e3050c067 100644 --- a/test/parallel/test-next-tick-domain.js +++ b/test/parallel/test-next-tick-domain.js @@ -2,7 +2,7 @@ require('../common'); const assert = require('assert'); -var origNextTick = process.nextTick; +const origNextTick = process.nextTick; require('domain'); diff --git a/test/parallel/test-next-tick-intentional-starvation.js b/test/parallel/test-next-tick-intentional-starvation.js index 3da32b8ffae15d..ee829c94ab6929 100644 --- a/test/parallel/test-next-tick-intentional-starvation.js +++ b/test/parallel/test-next-tick-intentional-starvation.js @@ -9,14 +9,14 @@ const 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 316fdb9f9ae373..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'); const assert = require('assert'); -var i; +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 32c5bd8e8ece51..7cfec867f3ed01 100644 --- a/test/parallel/test-next-tick-ordering2.js +++ b/test/parallel/test-next-tick-ordering2.js @@ -2,7 +2,7 @@ require('../common'); 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 702d2308ae1f2e..3001ad0e561a77 100644 --- a/test/parallel/test-next-tick.js +++ b/test/parallel/test-next-tick.js @@ -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-no-enter-tickcallback.js b/test/parallel/test-no-enter-tickcallback.js index e06628628955be..aab22c5f3edc72 100644 --- a/test/parallel/test-no-enter-tickcallback.js +++ b/test/parallel/test-no-enter-tickcallback.js @@ -2,8 +2,8 @@ const common = require('../common'); const assert = require('assert'); -var allsGood = false; -var cntr = 0; +let allsGood = false; +let cntr = 0; process.on('exit', () => { assert.ok(cntr > 0, '_tickDomainCallback was never called'); diff --git a/test/parallel/test-path-makelong.js b/test/parallel/test-path-makelong.js index 9d3c3852cdbc61..293d6284f173bc 100644 --- a/test/parallel/test-path-makelong.js +++ b/test/parallel/test-path-makelong.js @@ -4,8 +4,8 @@ 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 2db4c27dce072a..f112bc0e4067cd 100644 --- a/test/parallel/test-path-parse-format.js +++ b/test/parallel/test-path-parse-format.js @@ -175,7 +175,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 0a12b5ce92ca75..3843088ebdc14b 100644 --- a/test/parallel/test-path.js +++ b/test/parallel/test-path.js @@ -450,9 +450,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 d4bb0ffbc5af81..49f6802d3f7c7a 100644 --- a/test/parallel/test-pipe-address.js +++ b/test/parallel/test-pipe-address.js @@ -2,7 +2,7 @@ const common = require('../common'); const assert = require('assert'); const net = require('net'); -var server = net.createServer(common.fail); +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 a5f2ff6dfa8fd6..5e6e83dbc7a952 100644 --- a/test/parallel/test-pipe-return-val.js +++ b/test/parallel/test-pipe-return-val.js @@ -5,8 +5,8 @@ require('../common'); 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 8392c8011002aa..5e3774fc99d535 100644 --- a/test/parallel/test-pipe-stream.js +++ b/test/parallel/test-pipe-stream.js @@ -6,8 +6,8 @@ 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(); + const 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 f926dab3e5c98b..34b5ef651bf6aa 100644 --- a/test/parallel/test-pipe-unref.js +++ b/test/parallel/test-pipe-unref.js @@ -4,7 +4,7 @@ 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 3413a2a6dc69c8..444c3a0a6d5e2b 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 ad078d02b41b03..d6b4bfe232323e 100644 --- a/test/parallel/test-process-argv-0.js +++ b/test/parallel/test-process-argv-0.js @@ -5,11 +5,11 @@ 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-config.js b/test/parallel/test-process-config.js index e692a7bf19ae47..a1767464fd5978 100644 --- a/test/parallel/test-process-config.js +++ b/test/parallel/test-process-config.js @@ -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 c7de82adae3e97..8125850b424d84 100644 --- a/test/parallel/test-process-exec-argv.js +++ b/test/parallel/test-process-exec-argv.js @@ -6,10 +6,10 @@ 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 b93ae443a73eae..337502ffcb30e8 100644 --- a/test/parallel/test-process-exit-code.js +++ b/test/parallel/test-process-exit-code.js @@ -71,9 +71,9 @@ function parent() { function test(arg, exit) { const spawn = require('child_process').spawn; - var node = process.execPath; - var f = __filename; - var option = { stdio: [ 0, 1, 'ignore' ] }; + 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-recursive.js b/test/parallel/test-process-exit-recursive.js index 252b282b04886c..1634aad15497f5 100644 --- a/test/parallel/test-process-exit-recursive.js +++ b/test/parallel/test-process-exit-recursive.js @@ -3,7 +3,7 @@ require('../common'); 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 9d48ea9eacfe6f..f7df7737ed1531 100644 --- a/test/parallel/test-process-exit.js +++ b/test/parallel/test-process-exit.js @@ -3,7 +3,7 @@ require('../common'); 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 9e08892b625f81..e92f04853976f7 100644 --- a/test/parallel/test-process-getgroups.js +++ b/test/parallel/test-process-getgroups.js @@ -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) { assert.ifError(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-kill-null.js b/test/parallel/test-process-kill-null.js index 406b2943625365..6c0ee8fa049a50 100644 --- a/test/parallel/test-process-kill-null.js +++ b/test/parallel/test-process-kill-null.js @@ -3,8 +3,8 @@ require('../common'); 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 9b4a5fa47a87cb..2c6ef37fc120df 100644 --- a/test/parallel/test-process-kill-pid.js +++ b/test/parallel/test-process-kill-pid.js @@ -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 41774cb87a989f..74c99b1f8f8058 100644 --- a/test/parallel/test-process-raw-debug.js +++ b/test/parallel/test-process-raw-debug.js @@ -14,9 +14,9 @@ switch (process.argv[2]) { function parent() { const spawn = require('child_process').spawn; - var child = spawn(process.execPath, [__filename, 'child']); + 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 181e3ecef2bdb0..8532b259e01092 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 08e1b152ed9e07..326854e98335df 100644 --- a/test/parallel/test-process-wrap.js +++ b/test/parallel/test-process-wrap.js @@ -1,14 +1,14 @@ 'use strict'; require('../common'); const 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 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 e275dac238cffc..27cb94bf704eb4 100644 --- a/test/parallel/test-promises-unhandled-rejections.js +++ b/test/parallel/test-promises-unhandled-rejections.js @@ -3,15 +3,15 @@ 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) { + const 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) { + const 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,13 +336,12 @@ 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(); onUnhandledSucceed(done, function(reason, promise) { assert.strictEqual(e, reason); assert.strictEqual(_promise, promise); }); - _promise = Promise.resolve().then(function() { + const _promise = Promise.resolve().then(function() { return new Promise(function(_, reject) { setTimeout(function() { reject(e); @@ -353,13 +352,12 @@ 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(); onUnhandledSucceed(done, function(reason, promise) { assert.strictEqual(e, reason); assert.strictEqual(_promise, promise); }); - _promise = Promise.resolve().then(function() { + const _promise = Promise.resolve().then(function() { throw e; }); }); @@ -368,13 +366,12 @@ 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(); onUnhandledSucceed(done, function(reason, promise) { assert.strictEqual(e, reason); assert.strictEqual(_promise, promise); }); - _promise = Promise.resolve().then(function() { + const _promise = Promise.resolve().then(function() { return Promise.reject(e); }); } @@ -383,7 +380,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 +389,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 +406,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)]); + const 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 +430,7 @@ asyncTest('Waiting setTimeout(, 10) to catch a promise causes an' + done(); }); - var thePromise = new Promise(function() { + const thePromise = new Promise(function() { throw e; }); setTimeout(function() { @@ -446,11 +443,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 +462,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 +482,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 +502,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 +523,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 +544,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 +564,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); + const p = Promise.reject(e); setImmediate(function() { Promise.resolve().then(function() { p.catch(function() {}); @@ -598,7 +595,7 @@ asyncTest('setImmediate + promise microtasks is too late to attach a catch' + }); }); }); - var p = Promise.reject(); + const p = Promise.reject(); }); asyncTest('setImmediate + promise microtasks is too late to attach a catch' + @@ -608,7 +605,7 @@ asyncTest('setImmediate + promise microtasks is too late to attach a catch' + assert.strictEqual(undefined, reason); assert.strictEqual(p, promise); }); - var p = Promise.reject(); + const p = Promise.reject(); setImmediate(function() { Promise.resolve().then(function() { Promise.resolve().then(function() { @@ -626,14 +623,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 +647,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 +666,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 +676,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 b50a5cae416942..10f95162a09597 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 7192ac6a1bbff0..8cc589944b0508 100644 --- a/test/parallel/test-querystring.js +++ b/test/parallel/test-querystring.js @@ -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': ''}], @@ -88,9 +88,9 @@ var qsWeirdObjects = [ // }}} const vm = require('vm'); -var foreignObject = vm.runInNewContext('({"foo": ["bar", "baz"]})'); +const foreignObject = vm.runInNewContext('({"foo": ["bar", "baz"]})'); -var qsNoMungeTestCases = [ +const qsNoMungeTestCases = [ ['', {}], ['foo=bar&foo=baz', {'foo': ['bar', 'baz']}], ['foo=bar&foo=baz', foreignObject], @@ -232,7 +232,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); @@ -243,7 +243,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]); @@ -280,13 +280,13 @@ check(qs.parse('a=a&b=b&c=c', null, null, { decodeURIComponent: demoDecode }), 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'); // 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 509995bc9ad619..e8fc92ad1c9e27 100644 --- a/test/parallel/test-readline-interface.js +++ b/test/parallel/test-readline-interface.js @@ -19,8 +19,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; @@ -55,9 +55,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(); @@ -128,8 +128,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++; @@ -267,7 +267,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({ @@ -282,7 +282,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'); @@ -306,7 +306,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; @@ -326,7 +326,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') { @@ -360,7 +360,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(); @@ -421,8 +421,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 eae4ba55b73e6e..258127655606f1 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 e9e0ff4b4d05f0..78c42f5f5f627d 100644 --- a/test/parallel/test-readline-set-raw-mode.js +++ b/test/parallel/test-readline-set-raw-mode.js @@ -4,11 +4,11 @@ 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 5f8a1c02d3a90b..14895ac637429c 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-regress-GH-1531.js b/test/parallel/test-regress-GH-1531.js index 0ca1186d019183..5189e50929105c 100644 --- a/test/parallel/test-regress-GH-1531.js +++ b/test/parallel/test-regress-GH-1531.js @@ -9,12 +9,12 @@ 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') }; -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 1c98b30a8d66fc..838391acd23b5f 100644 --- a/test/parallel/test-regress-GH-1899.js +++ b/test/parallel/test-regress-GH-1899.js @@ -4,10 +4,10 @@ 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 129b1428d367cf..c5b0ae4982d993 100644 --- a/test/parallel/test-regress-GH-2245.js +++ b/test/parallel/test-regress-GH-2245.js @@ -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 11caddae0847aa..b845a2b7f18f9a 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 69f4e4732470a5..196c973cd093e3 100644 --- a/test/parallel/test-regress-GH-4948.js +++ b/test/parallel/test-regress-GH-4948.js @@ -4,8 +4,8 @@ require('../common'); 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(); @@ -33,7 +33,7 @@ var server = http.createServer(function(serverReq, serverRes) { // simulate a client request that closes early 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 779a2c2c649ed3..7f55356a15e027 100644 --- a/test/parallel/test-regress-GH-5927.js +++ b/test/parallel/test-regress-GH-5927.js @@ -3,18 +3,18 @@ require('../common'); 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-746.js b/test/parallel/test-regress-GH-746.js index a5e0d9d447360e..9a6e0e8980f311 100644 --- a/test/parallel/test-regress-GH-746.js +++ b/test/parallel/test-regress-GH-746.js @@ -7,7 +7,7 @@ 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 97e2fdb8114193..a7ce8311d7237f 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.notStrictEqual(undefined, result); }); diff --git a/test/parallel/test-regress-GH-819.js b/test/parallel/test-regress-GH-819.js index bc2201b614974b..719d4398251eab 100644 --- a/test/parallel/test-regress-GH-819.js +++ b/test/parallel/test-regress-GH-819.js @@ -3,5 +3,5 @@ require('../common'); 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 3dbbe2958b8aef..78565e3f596594 100644 --- a/test/parallel/test-regress-GH-node-9326.js +++ b/test/parallel/test-regress-GH-node-9326.js @@ -4,7 +4,7 @@ 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 98417e0d063d57..00d5f6791d54a5 100644 --- a/test/parallel/test-repl-.save.load.js +++ b/test/parallel/test-repl-.save.load.js @@ -8,17 +8,17 @@ common.refreshTmpDir(); 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 3cc2ba4aa5988f..e0554831cdca50 100644 --- a/test/parallel/test-repl-autolibs.js +++ b/test/parallel/test-repl-autolibs.js @@ -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 = {}; + const 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-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 b3e25e62ab0a84..743bbe4fabfcd1 100644 --- a/test/parallel/test-repl-harmony.js +++ b/test/parallel/test-repl-harmony.js @@ -3,11 +3,11 @@ require('../common'); const assert = require('assert'); const spawn = require('child_process').spawn; -var args = ['-i']; -var child = spawn(process.execPath, args); +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 16732a44296f1d..25d2aa63ff0086 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 2728ffdfe92129..6a65d53a029379 100644 --- a/test/parallel/test-repl-syntax-error-handling.js +++ b/test/parallel/test-repl-syntax-error-handling.js @@ -13,7 +13,7 @@ switch (process.argv[2]) { function parent() { const spawn = require('child_process').spawn; - var child = spawn(process.execPath, [__filename, 'child']); + 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; }); @@ -39,10 +39,11 @@ function parent() { function child() { 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 4e05714ab5fc56..1a1a2a8628809c 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 b41f43c667f666..7baa7d0aace812 100644 --- a/test/parallel/test-repl-tab.js +++ b/test/parallel/test-repl-tab.js @@ -5,8 +5,9 @@ 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 7ace511d097ef8..0f783d3dcaf27b 100644 --- a/test/parallel/test-repl-unexpected-token-recoverable.js +++ b/test/parallel/test-repl-unexpected-token-recoverable.js @@ -7,12 +7,12 @@ const assert = require('assert'); 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-sigint-infinite-loop.js b/test/parallel/test-sigint-infinite-loop.js index aafcd9e41d7394..30eb98ecb8a265 100644 --- a/test/parallel/test-sigint-infinite-loop.js +++ b/test/parallel/test-sigint-infinite-loop.js @@ -8,9 +8,9 @@ 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 eb29554b8b29bb..34722b712f8889 100644 --- a/test/parallel/test-signal-safety.js +++ b/test/parallel/test-signal-safety.js @@ -1,12 +1,12 @@ 'use strict'; require('../common'); const assert = require('assert'); -var Signal = process.binding('signal_wrap').Signal; +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 0d280115a43653..f21b52d519b2ba 100644 --- a/test/parallel/test-socket-write-after-fin-error.js +++ b/test/parallel/test-socket-write-after-fin-error.js @@ -8,13 +8,13 @@ const assert = require('assert'); // message is too vague, and doesn't actually tell you what happens. const net = require('net'); -var serverData = ''; -var gotServerEnd = false; -var clientData = ''; -var gotClientEnd = false; -var gotServerError = false; +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 17847f973387f1..c8ff56871734af 100644 --- a/test/parallel/test-socket-write-after-fin.js +++ b/test/parallel/test-socket-write-after-fin.js @@ -4,10 +4,10 @@ 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 663649134fe397..06cce3edfe403f 100644 --- a/test/parallel/test-stdin-pipe-resume.js +++ b/test/parallel/test-stdin-pipe-resume.js @@ -7,13 +7,13 @@ if (process.argv[2] === 'child') { process.stdin.pipe(process.stdout); } else { const spawn = require('child_process').spawn; - var buffers = []; - var child = spawn(process.execPath, [__filename, 'child']); + 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-stdout-cannot-be-closed-child-process-pipe.js b/test/parallel/test-stdout-cannot-be-closed-child-process-pipe.js index bfc7a1ddf4dc8e..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 @@ -9,9 +9,9 @@ else function parent() { const spawn = require('child_process').spawn; - var child = spawn(process.execPath, [__filename, 'child']); - var out = ''; - var err = ''; + 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 b61edf194fc4ac..6aa961301349fc 100644 --- a/test/parallel/test-stdout-stderr-reading.js +++ b/test/parallel/test-stdout-stderr-reading.js @@ -4,7 +4,7 @@ const assert = require('assert'); // verify that stdout is never read from. const net = require('net'); -var read = net.Socket.prototype.read; +const read = net.Socket.prototype.read; net.Socket.prototype.read = function() { if (this.fd === 1) @@ -21,10 +21,10 @@ else function parent() { const spawn = require('child_process').spawn; - var node = process.execPath; + 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 80093160212f9a..914fe5673ed10c 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); @@ -31,7 +31,7 @@ function test(size, useBuffer, cb) { assert.ifError(err); 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 329948836a5f9f..6b1cc67ee7777e 100644 --- a/test/parallel/test-stream-base-no-abort.js +++ b/test/parallel/test-stream-base-no-abort.js @@ -14,7 +14,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 77cd5d26f9fc11..1b5447eaa21ff9 100644 --- a/test/parallel/test-stream-pipe-event.js +++ b/test/parallel/test-stream-pipe-event.js @@ -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 4be2ca4a9fbe00..5fc1f5e89cf156 100644 --- a/test/parallel/test-stream-push-order.js +++ b/test/parallel/test-stream-push-order.js @@ -3,19 +3,19 @@ require('../common'); 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 85f5a6bf27d4ad..7bce493bbd33ce 100644 --- a/test/parallel/test-stream-push-strings.js +++ b/test/parallel/test-stream-push-strings.js @@ -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 86fab5ae54b90c..a5d7e48bfb3fa9 100644 --- a/test/parallel/test-stream-readable-constructor-set-methods.js +++ b/test/parallel/test-stream-readable-constructor-set-methods.js @@ -4,13 +4,13 @@ const assert = require('assert'); 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 48615ed0a95414..b1e421a71fd15b 100644 --- a/test/parallel/test-stream-readable-flow-recursion.js +++ b/test/parallel/test-stream-readable-flow-recursion.js @@ -12,9 +12,9 @@ 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 c57a633c55441e..7be673c517b30b 100644 --- a/test/parallel/test-stream-transform-constructor-set-methods.js +++ b/test/parallel/test-stream-transform-constructor-set-methods.js @@ -4,19 +4,19 @@ const assert = require('assert'); 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-flush-data.js b/test/parallel/test-stream-transform-flush-data.js index dede64ba10f9da..6d6aedd3a72bf8 100644 --- a/test/parallel/test-stream-transform-flush-data.js +++ b/test/parallel/test-stream-transform-flush-data.js @@ -16,7 +16,7 @@ function _flush(n) { n(null, expected); } -var t = new Transform({ +const t = new Transform({ transform: _transform, flush: _flush }); diff --git a/test/parallel/test-stream-transform-split-objectmode.js b/test/parallel/test-stream-transform-split-objectmode.js index 10fae6573c5e8f..52185e18711090 100644 --- a/test/parallel/test-stream-transform-split-objectmode.js +++ b/test/parallel/test-stream-transform-split-objectmode.js @@ -4,7 +4,7 @@ const assert = require('assert'); 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 196a36e7ebdbf1..d555fd7cae2330 100644 --- a/test/parallel/test-stream-unshift-empty-chunk.js +++ b/test/parallel/test-stream-unshift-empty-chunk.js @@ -6,9 +6,9 @@ const assert = require('assert'); // stream.unshift('') does not set state.reading=false. 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 9d527fa9c5e764..9eac52bc1aea44 100644 --- a/test/parallel/test-stream-writable-change-default-encoding.js +++ b/test/parallel/test-stream-writable-change-default-encoding.js @@ -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 40f624f293b05e..9b344487f61580 100644 --- a/test/parallel/test-stream-writable-constructor-set-methods.js +++ b/test/parallel/test-stream-writable-constructor-set-methods.js @@ -4,22 +4,22 @@ const assert = require('assert'); 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-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 fc3b09985724d8..4e05d2ba8e70e8 100644 --- a/test/parallel/test-stream-writev.js +++ b/test/parallel/test-stream-writev.js @@ -4,10 +4,10 @@ const assert = require('assert'); 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) { assert.ifError(er); counter++; @@ -37,12 +37,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', @@ -61,7 +61,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 41075334241f7a..da63644de099a1 100644 --- a/test/parallel/test-stream2-base64-single-char-read-end.js +++ b/test/parallel/test-stream2-base64-single-char-read-end.js @@ -4,11 +4,10 @@ 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 = []; src._read = function(n) { if (!hasRead) { @@ -32,6 +31,6 @@ src.on('end', function() { src.pipe(dst); -timeout = setTimeout(function() { +const timeout = setTimeout(function() { common.fail('timed out waiting for _write'); }, 100); diff --git a/test/parallel/test-stream2-compatibility.js b/test/parallel/test-stream2-compatibility.js index d4bf32a19922d0..f7c980791311da 100644 --- a/test/parallel/test-stream2-compatibility.js +++ b/test/parallel/test-stream2-compatibility.js @@ -6,7 +6,7 @@ const assert = require('assert'); 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 ee9ee20bd5237d..87edf5a5fa6437 100644 --- a/test/parallel/test-stream2-finish-pipe.js +++ b/test/parallel/test-stream2-finish-pipe.js @@ -3,12 +3,12 @@ require('../common'); 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 c4570e8b02db43..6d3da191b06cb9 100644 --- a/test/parallel/test-stream2-httpclient-response-end.js +++ b/test/parallel/test-stream2-httpclient-response-end.js @@ -2,13 +2,13 @@ const common = require('../common'); const assert = require('assert'); const http = require('http'); -var msg = 'Hello'; -var server = http.createServer(function(req, res) { +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 60e4a2873a0945..88fef4f24b6c30 100644 --- a/test/parallel/test-stream2-large-read-stall.js +++ b/test/parallel/test-stream2-large-read-stall.js @@ -5,24 +5,25 @@ 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; const Readable = require('stream').Readable; -var r = new 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); @@ -34,7 +35,7 @@ r.on('readable', function() { r.on('end', common.mustCall(function() {})); -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 6b50ba8436bfa6..6c00f1b8691364 100644 --- a/test/parallel/test-stream2-objects.js +++ b/test/parallel/test-stream2-objects.js @@ -5,8 +5,8 @@ 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-once-listener.js b/test/parallel/test-stream2-pipe-error-once-listener.js index a2ddb7f5d6e720..908ac1bdb8e4ab 100644 --- a/test/parallel/test-stream2-pipe-error-once-listener.js +++ b/test/parallel/test-stream2-pipe-error-once-listener.js @@ -5,7 +5,7 @@ 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 26f27529071cbf..95a98450a3034e 100644 --- a/test/parallel/test-stream2-push.js +++ b/test/parallel/test-stream2-push.js @@ -14,20 +14,20 @@ const 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(); @@ -37,7 +37,7 @@ source.on('end', function() { stream.push(null); }); -var reading = false; +let reading = false; function readStart() { console.error('readStart'); @@ -48,19 +48,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({ +const writer = new Writable({ decodeStrings: false }); -var written = []; +const written = []; -var expectWritten = +const expectWritten = [ 'asdfgasdfgasdfgasdfg', 'asdfgasdfgasdfgasdfg', 'asdfgasdfgasdfgasdfg', @@ -79,9 +79,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 1ba31a4b31b725..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'); const Readable = require('stream').Readable; -var r = new Readable(); -var N = 256 * 1024; +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 e38200e9d6ab1f..f3f39507e89dab 100644 --- a/test/parallel/test-stream2-readable-from-list.js +++ b/test/parallel/test-stream2-readable-from-list.js @@ -6,8 +6,8 @@ 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 1b8a4ac1ffeca3..d6db6ba232c693 100644 --- a/test/parallel/test-stream2-readable-legacy-drain.js +++ b/test/parallel/test-stream2-readable-legacy-drain.js @@ -3,20 +3,20 @@ const common = require('../common'); const assert = require('assert'); const Stream = require('stream'); -var Readable = Stream.Readable; +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 0a4eb131c312ab..66fae8274ecf3c 100644 --- a/test/parallel/test-stream2-readable-non-empty-end.js +++ b/test/parallel/test-stream2-readable-non-empty-end.js @@ -3,17 +3,17 @@ const common = require('../common'); 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 aa48c20bb83703..5b2dae3c5327fa 100644 --- a/test/parallel/test-stream2-readable-wrap-empty.js +++ b/test/parallel/test-stream2-readable-wrap-empty.js @@ -4,11 +4,11 @@ const common = require('../common'); 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-set-encoding.js b/test/parallel/test-stream2-set-encoding.js index c7cc7c3c0bfb2f..fdbd81e61332b1 100644 --- a/test/parallel/test-stream2-set-encoding.js +++ b/test/parallel/test-stream2-set-encoding.js @@ -5,8 +5,8 @@ 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 0777ada97fb376..d66f1f064375e4 100644 --- a/test/parallel/test-stream2-transform.js +++ b/test/parallel/test-stream2-transform.js @@ -5,8 +5,8 @@ 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 2004a8194c7803..1a1599ca32b4c7 100644 --- a/test/parallel/test-stream2-unpipe-leak.js +++ b/test/parallel/test-stream2-unpipe-leak.js @@ -3,7 +3,7 @@ require('../common'); const assert = require('assert'); const stream = require('stream'); -var chunk = Buffer.from('hallo'); +const chunk = Buffer.from('hallo'); const util = require('util'); @@ -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 4d98457e7d6eaa..c377ce9a510caa 100644 --- a/test/parallel/test-stream2-writable.js +++ b/test/parallel/test-stream2-writable.js @@ -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 996f91cf79f9b4..5a9550bcd41d7f 100644 --- a/test/parallel/test-stream3-pause-then-read.js +++ b/test/parallel/test-stream3-pause-then-read.js @@ -3,16 +3,16 @@ require('../common'); const assert = require('assert'); const stream = require('stream'); -var Readable = stream.Readable; -var Writable = stream.Writable; +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 9b6696977c8267..2c187d60142bbf 100644 --- a/test/parallel/test-string-decoder-end.js +++ b/test/parallel/test-string-decoder-end.js @@ -6,15 +6,15 @@ require('../common'); const assert = require('assert'); const SD = require('string_decoder').StringDecoder; -var encodings = ['base64', 'hex', 'utf8', 'utf16le', 'ucs2']; +const encodings = ['base64', 'hex', 'utf8', 'utf16le', 'ucs2']; -var bufs = [ '☃💩', 'asdf' ].map(function(b) { +const bufs = [ '☃💩', 'asdf' ].map(function(b) { return Buffer.from(b); }); // also test just arbitrary bytes from 0-15. -for (var i = 1; i <= 16; i++) { - var bytes = new Array(i).join('.').split('.').map(function(_, j) { +for (let i = 1; i <= 16; i++) { + const bytes = new Array(i).join('.').split('.').map(function(_, j) { return j + 0x78; }); bufs.push(Buffer.from(bytes)); @@ -34,21 +34,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 97c0aafef237ed..77ffbfcc73b1e1 100644 --- a/test/parallel/test-string-decoder.js +++ b/test/parallel/test-string-decoder.js @@ -5,7 +5,7 @@ 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 '); @@ -110,22 +110,22 @@ assert.strictEqual(decoder.end(), '\ud83d'); // 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 { sequences = [singleSequence]; } sequences.forEach(function(sequence) { - var decoder = new StringDecoder(encoding); - var output = ''; + const decoder = new StringDecoder(encoding); + let output = ''; sequence.forEach(function(write) { output += decoder.write(input.slice(write[0], write[1])); }); 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' + @@ -138,8 +138,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; @@ -162,10 +162,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 e0d8c4552e02c7..a242b943c91a4d 100644 --- a/test/parallel/test-stringbytes-external.js +++ b/test/parallel/test-stringbytes-external.js @@ -2,17 +2,17 @@ require('../common'); 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-tcp-wrap-connect.js b/test/parallel/test-tcp-wrap-connect.js index 92114bad39dbcd..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'); const 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 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,9 +35,9 @@ function makeConnection() { ///// -var connectCount = 0; -var endCount = 0; -var shutdownCount = 0; +let connectCount = 0; +let endCount = 0; +let shutdownCount = 0; const server = require('net').Server(function(s) { connectCount++; diff --git a/test/parallel/test-tcp-wrap.js b/test/parallel/test-tcp-wrap.js index 0d023ebf8d6d0d..6b9dbd90a4c113 100644 --- a/test/parallel/test-tcp-wrap.js +++ b/test/parallel/test-tcp-wrap.js @@ -2,17 +2,17 @@ require('../common'); 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-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-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 f53f18140f46df..103cd964511a53 100644 --- a/test/parallel/test-timers-immediate-queue.js +++ b/test/parallel/test-timers-immediate-queue.js @@ -24,7 +24,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-immediate.js b/test/parallel/test-timers-immediate.js index 9632022917f152..4afc642a334101 100644 --- a/test/parallel/test-timers-immediate.js +++ b/test/parallel/test-timers-immediate.js @@ -2,7 +2,6 @@ const common = require('../common'); const assert = require('assert'); -let immediateB; let immediateC; let immediateD; @@ -13,7 +12,7 @@ setImmediate(common.mustCall(function() { clearImmediate(immediateB); })); -immediateB = setImmediate(function() { +const immediateB = setImmediate(function() { common.fail('this immediate should not run'); }); 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-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-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 6a1f275ae5dda3..d970910b24abe6 100644 --- a/test/parallel/test-timers-unref-leak.js +++ b/test/parallel/test-timers-unref-leak.js @@ -2,16 +2,16 @@ require('../common'); 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 03c6cf7fd333a7..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 @@ -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 c47931b965fd09..2bde08f914d790 100644 --- a/test/parallel/test-timers-unref.js +++ b/test/parallel/test-timers-unref.js @@ -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 38d8fd86b17cce..33f1706e3d399a 100644 --- a/test/parallel/test-timers.js +++ b/test/parallel/test-timers.js @@ -2,7 +2,7 @@ require('../common'); const assert = require('assert'); -var inputs = [ +const inputs = [ undefined, null, true, @@ -29,15 +29,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 59cd355f35a67a..a8c6016f6218b7 100644 --- a/test/parallel/test-tls-alert.js +++ b/test/parallel/test-tls-alert.js @@ -16,7 +16,7 @@ const tls = require('tls'); 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 dc03e74c652ab3..be499b84503472 100644 --- a/test/parallel/test-tls-async-cb-after-socket-end.js +++ b/test/parallel/test-tls-async-cb-after-socket-end.js @@ -12,17 +12,17 @@ const SSL_OP_NO_TICKET = require('crypto').constants.SSL_OP_NO_TICKET; 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(); @@ -35,18 +35,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 e74201bc2e35e5..ff5827bcf844ee 100644 --- a/test/parallel/test-tls-cert-regression.js +++ b/test/parallel/test-tls-cert-regression.js @@ -8,7 +8,7 @@ if (!common.hasCrypto) { 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 f48d22c4fc48cd..21ee41e927873b 100644 --- a/test/parallel/test-tls-client-abort.js +++ b/test/parallel/test-tls-client-abort.js @@ -11,10 +11,10 @@ const tls = require('tls'); 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 dd224be8741abd..3247a2899acdfb 100644 --- a/test/parallel/test-tls-client-abort2.js +++ b/test/parallel/test-tls-client-abort2.js @@ -8,7 +8,7 @@ if (!common.hasCrypto) { } 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 f8fdab1102a795..618178d4a497ad 100644 --- a/test/parallel/test-tls-client-default-ciphers.js +++ b/test/parallel/test-tls-client-default-ciphers.js @@ -11,7 +11,7 @@ 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 3e792305147de2..016fcfa4da6a95 100644 --- a/test/parallel/test-tls-client-destroy-soon.js +++ b/test/parallel/test-tls-client-destroy-soon.js @@ -14,29 +14,29 @@ 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') }; -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 fb42991e149548..b49d7131c47cf9 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 55a32ad6c2a469..76e1034621f031 100644 --- a/test/parallel/test-tls-client-mindhsize.js +++ b/test/parallel/test-tls-client-mindhsize.js @@ -9,27 +9,27 @@ if (!common.hasCrypto) { const tls = require('tls'); const fs = require('fs'); -var key = fs.readFileSync(common.fixturesDir + '/keys/agent2-key.pem'); -var cert = fs.readFileSync(common.fixturesDir + '/keys/agent2-cert.pem'); +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 029f10d449fe31..96109d7656dd19 100644 --- a/test/parallel/test-tls-client-resume.js +++ b/test/parallel/test-tls-client-resume.js @@ -14,21 +14,21 @@ 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 = 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 6b37d5c1cef00e..6172be813e97ce 100644 --- a/test/parallel/test-tls-close-error.js +++ b/test/parallel/test-tls-close-error.js @@ -11,12 +11,12 @@ const tls = require('tls'); 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 3dd2afbd6e5545..5d5bc1007749a7 100644 --- a/test/parallel/test-tls-close-notify.js +++ b/test/parallel/test-tls-close-notify.js @@ -9,7 +9,7 @@ const tls = require('tls'); 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 2b81698664c4ab..2e4bcfbc6d4787 100644 --- a/test/parallel/test-tls-connect-no-host.js +++ b/test/parallel/test-tls-connect-no-host.js @@ -11,8 +11,8 @@ 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 67a53c4ebf78a4..de60ae084624cf 100644 --- a/test/parallel/test-tls-connect-pipe.js +++ b/test/parallel/test-tls-connect-pipe.js @@ -9,19 +9,19 @@ 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') }; 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 7070f63f497df6..2f4eebf22978a5 100644 --- a/test/parallel/test-tls-connect-stream-writes.js +++ b/test/parallel/test-tls-connect-stream-writes.js @@ -11,34 +11,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({ + const p = new stream.Duplex({ read: function read() { pending = false; - var chunk = raw.read(); + const chunk = raw.read(); if (chunk) { this.push(chunk); } else { @@ -50,11 +49,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; } @@ -64,6 +63,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-delayed-attach-error.js b/test/parallel/test-tls-delayed-attach-error.js index e7cfd4fa6ab557..47be3f201b463e 100644 --- a/test/parallel/test-tls-delayed-attach-error.js +++ b/test/parallel/test-tls-delayed-attach-error.js @@ -9,16 +9,16 @@ 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 867fc5edb88b03..d757ca756c3a09 100644 --- a/test/parallel/test-tls-delayed-attach.js +++ b/test/parallel/test-tls-delayed-attach.js @@ -11,17 +11,17 @@ const tls = require('tls'); 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 6340833765cd41..4bc81af6e1f8a2 100644 --- a/test/parallel/test-tls-dhe.js +++ b/test/parallel/test-tls-dhe.js @@ -10,28 +10,28 @@ const tls = require('tls'); const spawn = require('child_process').spawn; const 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 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 df51c5d0855d65..a0555e87781f59 100644 --- a/test/parallel/test-tls-ecdh-disable.js +++ b/test/parallel/test-tls-ecdh-disable.js @@ -11,17 +11,17 @@ const tls = require('tls'); 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 51f178198f1a0a..c0df9948f489ea 100644 --- a/test/parallel/test-tls-econnreset.js +++ b/test/parallel/test-tls-econnreset.js @@ -8,7 +8,7 @@ if (!common.hasCrypto) { } 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,18 +44,18 @@ 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) { +const server = tls.createServer({ ca: ca, cert: cert, key: key }, (conn) => { throw 'unreachable'; }).on('tlsClientError', function(err, conn) { assert(!clientError && conn); clientError = err; }).listen(0, function() { - var options = { + const options = { ciphers: 'AES128-GCM-SHA256', port: this.address().port, ca: ca 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 33665536ba5bd0..b2d6fe6eee88a3 100644 --- a/test/parallel/test-tls-fast-writing.js +++ b/test/parallel/test-tls-fast-writing.js @@ -10,14 +10,14 @@ const tls = require('tls'); 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 7623f816f3be07..4909fa45e160fb 100644 --- a/test/parallel/test-tls-handshake-error.js +++ b/test/parallel/test-tls-handshake-error.js @@ -11,13 +11,13 @@ const tls = require('tls'); 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-honorcipherorder.js b/test/parallel/test-tls-honorcipherorder.js index 883abc199ee321..f7894e46706da9 100644 --- a/test/parallel/test-tls-honorcipherorder.js +++ b/test/parallel/test-tls-honorcipherorder.js @@ -9,19 +9,19 @@ if (!common.hasCrypto) { const tls = require('tls'); const fs = require('fs'); -var nconns = 0; +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 b37b900d77e300..bd3ad43fe653e5 100644 --- a/test/parallel/test-tls-invoke-queued.js +++ b/test/parallel/test-tls-invoke-queued.js @@ -11,9 +11,9 @@ const tls = require('tls'); 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 2f69a306cfdcec..e1b580da303f8d 100644 --- a/test/parallel/test-tls-js-stream.js +++ b/test/parallel/test-tls-js-stream.js @@ -12,12 +12,12 @@ 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({ + const 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 392df2e71588aa..9af65c43a0661c 100644 --- a/test/parallel/test-tls-legacy-onselect.js +++ b/test/parallel/test-tls-legacy-onselect.js @@ -8,8 +8,8 @@ if (!common.hasCrypto) { 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 d96f42e6a2e82f..4b81be35e34522 100644 --- a/test/parallel/test-tls-max-send-fragment.js +++ b/test/parallel/test-tls-max-send-fragment.js @@ -10,11 +10,11 @@ const tls = require('tls'); 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 840deb59d4bde6..e3d5d661a799a7 100644 --- a/test/parallel/test-tls-multi-key.js +++ b/test/parallel/test-tls-multi-key.js @@ -9,7 +9,7 @@ if (!common.hasCrypto) { 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 1e75b21eaba14c..233d8453db1318 100644 --- a/test/parallel/test-tls-no-rsa-key.js +++ b/test/parallel/test-tls-no-rsa-key.js @@ -10,15 +10,15 @@ const tls = require('tls'); 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-npn-server-client.js b/test/parallel/test-tls-npn-server-client.js index fdd9fcbb328cfb..1b622cc8f72c20 100644 --- a/test/parallel/test-tls-npn-server-client.js +++ b/test/parallel/test-tls-npn-server-client.js @@ -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 f55f1c0ac0c450..4e03bcaf537f26 100644 --- a/test/parallel/test-tls-over-http-tunnel.js +++ b/test/parallel/test-tls-over-http-tunnel.js @@ -12,17 +12,17 @@ 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 aa48c04866654a..911ea7097b1e70 100644 --- a/test/parallel/test-tls-pause.js +++ b/test/parallel/test-tls-pause.js @@ -11,16 +11,16 @@ const tls = require('tls'); 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 1062dab2af1d2e..545caf403e103c 100644 --- a/test/parallel/test-tls-peer-certificate-encoding.js +++ b/test/parallel/test-tls-peer-certificate-encoding.js @@ -12,21 +12,21 @@ 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 6176a34a716096..693bb4cb3fa812 100644 --- a/test/parallel/test-tls-peer-certificate-multi-keys.js +++ b/test/parallel/test-tls-peer-certificate-multi-keys.js @@ -12,20 +12,20 @@ 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 2d1ddf34b32032..4873a3c696458f 100644 --- a/test/parallel/test-tls-request-timeout.js +++ b/test/parallel/test-tls-request-timeout.js @@ -10,13 +10,13 @@ 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 = 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 99564055efb807..c79b5cbede8808 100644 --- a/test/parallel/test-tls-securepair-fiftharg.js +++ b/test/parallel/test-tls-securepair-fiftharg.js @@ -15,7 +15,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 afe76a0139a59d..65a7d91a0ca606 100644 --- a/test/parallel/test-tls-securepair-server.js +++ b/test/parallel/test-tls-securepair-server.js @@ -13,19 +13,19 @@ 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 ef08c56460c10d..a1af1a917eb826 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 436618379a78e9..2e7245336b8b98 100644 --- a/test/parallel/test-tls-sni-option.js +++ b/test/parallel/test-tls-sni-option.js @@ -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 = { +const 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 a22b6a9726a857..93fffd3888ffd1 100644 --- a/test/parallel/test-tls-sni-server-client.js +++ b/test/parallel/test-tls-sni-server-client.js @@ -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 397f26ce9013a5..1c870893a3bced 100644 --- a/test/parallel/test-umask.js +++ b/test/parallel/test-umask.js @@ -3,14 +3,14 @@ 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 c97caa36429a9c..3a8c06c3ee4637 100644 --- a/test/parallel/test-url.js +++ b/test/parallel/test-url.js @@ -8,7 +8,7 @@ const url = require('url'); // URLs to parse, and expected data // { url : parsed } -var parseTests = { +const parseTests = { '//some_path': { href: '//some_path', pathname: '//some_path', @@ -942,7 +942,7 @@ function check(actual, expected) { }); } -var parseTestsWithQueryString = { +const parseTestsWithQueryString = { '/foo/bar?baz=quux#frag': { href: '/foo/bar?baz=quux#frag', hash: '#frag', @@ -1013,7 +1013,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:', @@ -1250,7 +1250,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'], @@ -1329,7 +1329,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', @@ -1338,7 +1338,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:'], @@ -1641,8 +1641,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); @@ -1669,8 +1669,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, @@ -1688,7 +1688,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-util-inspect.js b/test/parallel/test-util-inspect.js index 7df3574a5a5736..62743ebd19d16a 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] }'); @@ -272,10 +272,10 @@ assert.strictEqual(util.inspect(value), '{ 2010-02-14T11:48:40.000Z aprop: 42 }' // test the internal isDate implementation const Date2 = vm.runInNewContext('Date'); -var d = new Date2(); -var orig = util.inspect(d); +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\' ]'); @@ -319,17 +319,17 @@ obj = 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 8480bf83eaf18c..d45ebf2fc0b729 100644 --- a/test/parallel/test-util-log.js +++ b/test/parallel/test-util-log.js @@ -6,14 +6,14 @@ 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-stats.js b/test/parallel/test-v8-stats.js index dc36beac131446..5b756f35962525 100644 --- a/test/parallel/test-v8-stats.js +++ b/test/parallel/test-v8-stats.js @@ -3,8 +3,8 @@ require('../common'); const assert = require('assert'); const v8 = require('v8'); -var s = v8.getHeapStatistics(); -var keys = [ +const s = v8.getHeapStatistics(); +const keys = [ 'does_zap_garbage', 'heap_size_limit', 'malloced_memory', diff --git a/test/parallel/test-vm-basic.js b/test/parallel/test-vm-basic.js index 75163d6cd3218a..2d57cc0d4ba328 100644 --- a/test/parallel/test-vm-basic.js +++ b/test/parallel/test-vm-basic.js @@ -4,8 +4,8 @@ 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 b4045fbfd3c246..1e9ed629fb114f 100644 --- a/test/parallel/test-vm-context-async-script.js +++ b/test/parallel/test-vm-context-async-script.js @@ -3,9 +3,9 @@ require('../common'); 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 03faef596f2872..b77fc45217039f 100644 --- a/test/parallel/test-vm-context-property-forwarding.js +++ b/test/parallel/test-vm-context-property-forwarding.js @@ -3,9 +3,9 @@ require('../common'); 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 48319be3a9fc58..e4f6960259abe2 100644 --- a/test/parallel/test-vm-context.js +++ b/test/parallel/test-vm-context.js @@ -3,12 +3,12 @@ require('../common'); const assert = require('assert'); const vm = require('vm'); -var Script = vm.Script; -var script = new Script('"passed";'); +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 b40491bb611260..a0026102b578f8 100644 --- a/test/parallel/test-vm-create-and-run-in-context.js +++ b/test/parallel/test-vm-create-and-run-in-context.js @@ -6,8 +6,8 @@ const assert = require('assert'); 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 3870b68247d480..27d7e6d7fc0274 100644 --- a/test/parallel/test-vm-create-context-accessors.js +++ b/test/parallel/test-vm-create-context-accessors.js @@ -3,7 +3,7 @@ require('../common'); 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 76634e5befc3cd..91bbbc3b7793bc 100644 --- a/test/parallel/test-vm-create-context-arg.js +++ b/test/parallel/test-vm-create-context-arg.js @@ -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 e6c1ab8b8566f0..13680c4c4e11ef 100644 --- a/test/parallel/test-vm-create-context-circular-reference.js +++ b/test/parallel/test-vm-create-context-circular-reference.js @@ -3,7 +3,7 @@ require('../common'); 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 c1d115b50beffa..bafb32accb6a0e 100644 --- a/test/parallel/test-vm-cross-context.js +++ b/test/parallel/test-vm-cross-context.js @@ -3,7 +3,7 @@ require('../common'); const assert = require('assert'); const vm = require('vm'); -var ctx = vm.createContext(global); +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 976313b5f66b9f..9f27723a0421a9 100644 --- a/test/parallel/test-vm-function-declaration.js +++ b/test/parallel/test-vm-function-declaration.js @@ -3,10 +3,10 @@ require('../common'); const assert = require('assert'); const vm = require('vm'); -var o = vm.createContext({ console: console }); +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 31842ced2ab19c..62a714615ddc31 100644 --- a/test/parallel/test-vm-global-define-property.js +++ b/test/parallel/test-vm-global-define-property.js @@ -4,7 +4,7 @@ const assert = require('assert'); 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 876318aecec7d9..ae9fd71b3109ee 100644 --- a/test/parallel/test-vm-global-identity.js +++ b/test/parallel/test-vm-global-identity.js @@ -3,9 +3,9 @@ require('../common'); 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 eeacdaed184562..80c1a2127f918c 100644 --- a/test/parallel/test-vm-harmony-symbols.js +++ b/test/parallel/test-vm-harmony-symbols.js @@ -4,7 +4,7 @@ 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 474c0686a870eb..e58b896fccaa43 100644 --- a/test/parallel/test-vm-is-context.js +++ b/test/parallel/test-vm-is-context.js @@ -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 6532345336fa19..25e16e8f5ccc55 100644 --- a/test/parallel/test-vm-proxies.js +++ b/test/parallel/test-vm-proxies.js @@ -6,7 +6,7 @@ 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 0f578ac5f8046c..076f81dbf6ff15 100644 --- a/test/parallel/test-vm-static-this.js +++ b/test/parallel/test-vm-static-this.js @@ -6,7 +6,7 @@ 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 b4c101d580c4af..1a97393d6d97a7 100644 --- a/test/parallel/test-vm-syntax-error-message.js +++ b/test/parallel/test-vm-syntax-error-message.js @@ -3,7 +3,7 @@ require('../common'); 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 5b78c891e876e1..5260ca7dc28572 100644 --- a/test/parallel/test-vm-timeout.js +++ b/test/parallel/test-vm-timeout.js @@ -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-whatwg-url-searchparams.js b/test/parallel/test-whatwg-url-searchparams.js index 9a9fbb0452155d..8b9e65123d9506 100644 --- a/test/parallel/test-whatwg-url-searchparams.js +++ b/test/parallel/test-whatwg-url-searchparams.js @@ -31,7 +31,7 @@ assert.strictEqual(m.search, `?${serialized}`); assert.strictEqual(sp[Symbol.iterator], sp.entries); -var key, val, n = 0; +let key, val, n = 0; for ([key, val] of sp) { assert.strictEqual(key, 'a'); assert.strictEqual(val, String(values[n++])); diff --git a/test/parallel/test-whatwg-url-setters.js b/test/parallel/test-whatwg-url-setters.js index 236737e18177fe..dfaeb6e4ac2fd0 100644 --- a/test/parallel/test-whatwg-url-setters.js +++ b/test/parallel/test-whatwg-url-setters.js @@ -17,7 +17,7 @@ for (const attr in attrs) { if (attr === 'comment') continue; const tests = attrs[attr]; - var n = 0; + let n = 0; for (const test of tests) { if (test.skip) continue; n++; 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 07113d1e257f65..42e6994e1b6389 100644 --- a/test/parallel/test-zerolengthbufferbug.js +++ b/test/parallel/test-zerolengthbufferbug.js @@ -4,8 +4,8 @@ const common = require('../common'); 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 7f0021434f4c18..0eec5da7dd835e 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.constants.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 0dce05be4d40f6..40799637ecdac7 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 89edaf93043d88..342c9143ba4643 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 1fed91d54a6526..d1a8d3daa65e4c 100644 --- a/test/pummel/test-abort-fatal-error.js +++ b/test/pummel/test-abort-fatal-error.js @@ -9,7 +9,7 @@ if (common.isWindows) { 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-crypto-dh.js b/test/pummel/test-crypto-dh.js index 7656d0ffa92e84..d441e80926df45 100644 --- a/test/pummel/test-crypto-dh.js +++ b/test/pummel/test-crypto-dh.js @@ -18,7 +18,7 @@ assert.throws(function() { crypto.getDiffieHellman('modp1').setPublicKey(''); }); -var hashes = { +const hashes = { modp1: '630e9acd2cc63f7e80d8507624ba60ac0757201a', modp2: '18f7aa964484137f57bca64b21917a385b6a0b60', modp5: 'c0a8eec0c2c8a5ec2f9c26f9661eb339a010ec61', @@ -30,10 +30,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'); @@ -43,11 +43,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 8228332e5dd8e9..5be6abb9a8b29c 100644 --- a/test/pummel/test-dh-regr.js +++ b/test/pummel/test-dh-regr.js @@ -8,9 +8,9 @@ if (!common.hasCrypto) { } 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 af9c83bb3ec3c4..d1615a3855af43 100644 --- a/test/pummel/test-dtrace-jsstack.js +++ b/test/pummel/test-dtrace-jsstack.js @@ -11,20 +11,20 @@ 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); @@ -38,10 +38,10 @@ const spawn = require('child_process').spawn; * 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 eee3d9286832b2..131b214fc53f42 100644 --- a/test/pummel/test-exec.js +++ b/test/pummel/test-exec.js @@ -3,7 +3,7 @@ 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 e64e00b32fa602..78c36152ecd315 100644 --- a/test/pummel/test-fs-watch-file-slow.js +++ b/test/pummel/test-fs-watch-file-slow.js @@ -4,10 +4,10 @@ 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 98199d1e841f4b..7713fe74ed99aa 100644 --- a/test/pummel/test-fs-watch-file.js +++ b/test/pummel/test-fs-watch-file.js @@ -4,23 +4,23 @@ 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 7b40ef75accc43..b7c19b9c360818 100644 --- a/test/pummel/test-fs-watch-non-recursive.js +++ b/test/pummel/test-fs-watch-non-recursive.js @@ -3,9 +3,9 @@ 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 a7654f4524835c..e465c02a90161c 100644 --- a/test/pummel/test-http-many-keep-alive-connections.js +++ b/test/pummel/test-http-many-keep-alive-connections.js @@ -3,12 +3,12 @@ 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 61e60c2673ed60..850e0949c4a64a 100644 --- a/test/pummel/test-https-ci-reneg-attack.js +++ b/test/pummel/test-https-ci-reneg-attack.js @@ -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 8a3aa022ea2089..39256aa6304b74 100644 --- a/test/pummel/test-https-large-response.js +++ b/test/pummel/test-https-large-response.js @@ -10,16 +10,16 @@ if (!common.hasCrypto) { } 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 b6cc32c999fa88..a08676277af6ce 100644 --- a/test/pummel/test-https-no-reader.js +++ b/test/pummel/test-https-no-reader.js @@ -12,23 +12,23 @@ 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-net-connect-econnrefused.js b/test/pummel/test-net-connect-econnrefused.js index bd61dabc6bb6a7..30da36d983e4f7 100644 --- a/test/pummel/test-net-connect-econnrefused.js +++ b/test/pummel/test-net-connect-econnrefused.js @@ -5,17 +5,18 @@ 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 a5d8ff47eb7e16..f16034e4773510 100644 --- a/test/pummel/test-net-connect-memleak.js +++ b/test/pummel/test-net-connect-memleak.js @@ -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 db98e55433753e..a92ae033a09a17 100644 --- a/test/pummel/test-net-many-clients.js +++ b/test/pummel/test-net-many-clients.js @@ -4,16 +4,16 @@ 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 59749e75fa4307..db426edbe9c507 100644 --- a/test/pummel/test-net-pause.js +++ b/test/pummel/test-net-pause.js @@ -3,10 +3,10 @@ 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 4e478c87a64132..9a598435d1bd28 100644 --- a/test/pummel/test-net-pingpong-delay.js +++ b/test/pummel/test-net-pingpong-delay.js @@ -4,12 +4,12 @@ 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 b65d5d4ff94224..6ede6f9fcb2763 100644 --- a/test/pummel/test-net-pingpong.js +++ b/test/pummel/test-net-pingpong.js @@ -3,17 +3,17 @@ 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 e4f8664657505e..d6dd8e489cc116 100644 --- a/test/pummel/test-net-timeout.js +++ b/test/pummel/test-net-timeout.js @@ -3,12 +3,12 @@ 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 5567b128c7697d..a3d0abceb6c765 100644 --- a/test/pummel/test-net-timeout2.js +++ b/test/pummel/test-net-timeout2.js @@ -5,13 +5,13 @@ 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 54f8a67abee3c6..6c3c1f202a81c3 100644 --- a/test/pummel/test-net-write-callbacks.js +++ b/test/pummel/test-net-write-callbacks.js @@ -3,10 +3,10 @@ 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 0149ef2bf501cc..d02b9c79822a88 100644 --- a/test/pummel/test-process-hrtime.js +++ b/test/pummel/test-process-hrtime.js @@ -2,17 +2,17 @@ require('../common'); 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 90343e91a1e09a..5c09d59b06d55c 100644 --- a/test/pummel/test-process-uptime.js +++ b/test/pummel/test-process-uptime.js @@ -5,10 +5,10 @@ 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 4c890e1705acc3..20323360debfe3 100644 --- a/test/pummel/test-regress-GH-814.js +++ b/test/pummel/test-regress-GH-814.js @@ -5,7 +5,7 @@ const common = require('../common'); const assert = require('assert'); function newBuffer(size, value) { - var buffer = Buffer.allocUnsafe(size); + const buffer = Buffer.allocUnsafe(size); while (size--) { buffer[size] = value; } @@ -16,14 +16,14 @@ function newBuffer(size, value) { const fs = require('fs'); const testFileName = require('path').join(common.tmpDir, 'GH-814_testFile.txt'); -var testFileFD = fs.openSync(testFileName, 'w'); +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 = []; const tail = require('child_process').spawn('tail', ['-f', testFileName]); @@ -34,13 +34,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 afba742e60bb7d..233e8530459545 100644 --- a/test/pummel/test-regress-GH-814_2.js +++ b/test/pummel/test-regress-GH-814_2.js @@ -6,7 +6,7 @@ const assert = require('assert'); const fs = require('fs'); const testFileName = require('path').join(common.tmpDir, 'GH-814_test.txt'); -var testFD = fs.openSync(testFileName, 'w'); +const testFD = fs.openSync(testFileName, 'w'); console.error(testFileName + '\n'); @@ -27,12 +27,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() { @@ -51,7 +51,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; @@ -73,7 +73,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 9a2fce08a7fe3b..0619fd84de3b5e 100644 --- a/test/pummel/test-regress-GH-892.js +++ b/test/pummel/test-regress-GH-892.js @@ -17,9 +17,9 @@ const https = require('https'); const fs = require('fs'); -var bytesExpected = 1024 * 1024 * 32; +const bytesExpected = 1024 * 1024 * 32; -var started = false; +let started = false; const childScript = require('path').join(common.fixturesDir, 'GH-892-request.js'); @@ -28,17 +28,17 @@ 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)); @@ -59,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 3c62548e5b81bb..e1e5e011020fe2 100644 --- a/test/pummel/test-stream-pipe-multi.js +++ b/test/pummel/test-stream-pipe-multi.js @@ -5,14 +5,14 @@ require('../common'); const assert = require('assert'); const 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 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 3659b267fad162..073c1d8e35ad36 100644 --- a/test/pummel/test-stream2-basic.js +++ b/test/pummel/test-stream2-basic.js @@ -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(); + const 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(); + const 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 83a8eeffeb43c3..4555582371b9ff 100644 --- a/test/pummel/test-timers.js +++ b/test/pummel/test-timers.js @@ -2,20 +2,20 @@ const common = require('../common'); 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 c8f78e0609acc6..dd2b43ed60278f 100644 --- a/test/pummel/test-tls-ci-reneg-attack.js +++ b/test/pummel/test-tls-ci-reneg-attack.js @@ -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 46e7f425df5aba..b1d1f05190c39d 100644 --- a/test/pummel/test-tls-connect-memleak.js +++ b/test/pummel/test-tls-connect-memleak.js @@ -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 c47cc60301380f..75e7b400592191 100644 --- a/test/pummel/test-tls-securepair-client.js +++ b/test/pummel/test-tls-securepair-client.js @@ -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 1b43a558353c0f..f02eb51a2f6742 100644 --- a/test/pummel/test-tls-server-large-request.js +++ b/test/pummel/test-tls-server-large-request.js @@ -12,9 +12,9 @@ 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) { +const 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 ffa44a97025002..c194188b3682a9 100644 --- a/test/pummel/test-tls-session-timeout.js +++ b/test/pummel/test-tls-session-timeout.js @@ -28,13 +28,13 @@ function doTest() { 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 581355d61b701a..574a83b18f2846 100644 --- a/test/pummel/test-tls-throttle.js +++ b/test/pummel/test-tls-throttle.js @@ -13,22 +13,22 @@ 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); +const 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 6f26c9a590c54d..8503e2389b44a7 100644 --- a/test/pummel/test-vm-memleak.js +++ b/test/pummel/test-vm-memleak.js @@ -4,21 +4,21 @@ require('../common'); 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/sequential/test-child-process-execsync.js b/test/sequential/test-child-process-execsync.js index 91529ff94de3da..20a35b98b36c6f 100644 --- a/test/sequential/test-child-process-execsync.js +++ b/test/sequential/test-child-process-execsync.js @@ -5,12 +5,12 @@ const assert = require('assert'); 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 85ebe2ad17b53d..26c3418171e8df 100644 --- a/test/sequential/test-debugger-debug-brk.js +++ b/test/sequential/test-debugger-debug-brk.js @@ -3,14 +3,14 @@ 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 54fcc5c06a7ef4..dd4e7ba76b611f 100644 --- a/test/sequential/test-module-loading.js +++ b/test/sequential/test-module-loading.js @@ -101,7 +101,7 @@ assert.ok(my_path.path_func instanceof Function); // this one does not exist and should throw assert.throws(function() { require('./utils'); }); -var errorThrown = false; +let errorThrown = false; try { require('../fixtures/throws_error'); } catch (e) { @@ -113,7 +113,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\''); @@ -193,8 +193,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 b40cfb400bf537..a7f64c2e73da10 100644 --- a/test/sequential/test-net-GH-5504.js +++ b/test/sequential/test-net-GH-5504.js @@ -19,7 +19,7 @@ switch (process.argv[2]) { function server() { const net = require('net'); - var content = Buffer.alloc(64 * 1024 * 1024, '#'); + const content = Buffer.alloc(64 * 1024 * 1024, '#'); net.createServer(function(socket) { this.close(); socket.on('end', function() { @@ -36,7 +36,7 @@ function server() { function client() { const net = require('net'); - var client = net.connect({ + const client = net.connect({ host: common.localhostIPv4, port: common.PORT }, function() { @@ -46,14 +46,14 @@ function client() { function parent() { const spawn = require('child_process').spawn; - var node = process.execPath; + 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 0097ed913dbd09..c464193b23f3e4 100644 --- a/test/sequential/test-regress-GH-1726.js +++ b/test/sequential/test-regress-GH-1726.js @@ -8,8 +8,8 @@ require('../common'); 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 87b2b8561d9389..249817de1d2068 100644 --- a/test/sequential/test-regress-GH-4015.js +++ b/test/sequential/test-regress-GH-4015.js @@ -3,8 +3,8 @@ 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 7653dda182fbe5..87a8861ac35477 100644 --- a/test/sequential/test-regress-GH-4027.js +++ b/test/sequential/test-regress-GH-4027.js @@ -6,7 +6,7 @@ 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 645ffeb6501c37..c9b630b0c81755 100644 --- a/test/sequential/test-regress-GH-784.js +++ b/test/sequential/test-regress-GH-784.js @@ -12,8 +12,8 @@ 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 82229524ceaa9d..06c839aa483fa8 100644 --- a/test/sequential/test-regress-GH-877.js +++ b/test/sequential/test-regress-GH-877.js @@ -3,28 +3,28 @@ 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 344845e0202f1a..69664195567882 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 0549e5f72ee0ba..b591f1746b62d4 100644 --- a/test/sequential/test-require-cache-without-stat.js +++ b/test/sequential/test-require-cache-without-stat.js @@ -6,13 +6,13 @@ 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 3640749179c539..2891335c813562 100644 --- a/test/sequential/test-stream2-fs.js +++ b/test/sequential/test-stream2-fs.js @@ -3,14 +3,14 @@ const common = require('../common'); const assert = require('assert'); const fs = require('fs'); -var FSReadable = fs.ReadStream; +const FSReadable = fs.ReadStream; const path = require('path'); -var file = path.resolve(common.fixturesDir, 'x1024.txt'); +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]; const util = require('util'); const Stream = require('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 2855a5f0970d41..e37a5f2cd1b38e 100644 --- a/test/sequential/test-stream2-stderr-sync.js +++ b/test/sequential/test-stream2-stderr-sync.js @@ -6,10 +6,10 @@ require('../common'); function parent() { const spawn = require('child_process').spawn; const assert = require('assert'); - var i = 0; + 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; @@ -43,7 +43,7 @@ function child1() { // using a net socket function child2() { const net = require('net'); - var socket = new net.Socket({ + 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 ]; +const 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-vm-timeout-rethrow.js b/test/sequential/test-vm-timeout-rethrow.js index d55a9b310c15a4..a434e2ae3e6978 100644 --- a/test/sequential/test-vm-timeout-rethrow.js +++ b/test/sequential/test-vm-timeout-rethrow.js @@ -5,11 +5,11 @@ const vm = require('vm'); const spawn = require('child_process').spawn; if (process.argv[2] === 'child') { - var code = 'var j = 0;\n' + - 'for (var i = 0; i < 1000000; i++) j += add(i, i + 1);\n' + - 'j;'; + const code = 'let j = 0;\n' + + 'for (let i = 0; i < 1000000; i++) j += add(i, i + 1);\n' + + 'j;'; - var ctx = vm.createContext({ + const ctx = vm.createContext({ add: function(x, y) { return x + y; } @@ -17,8 +17,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 11dd0a225d9e7f..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; +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);