summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRuben Bridgewater <ruben@bridgewater.de>2019-12-25 18:02:16 +0100
committerRuben Bridgewater <ruben@bridgewater.de>2019-12-31 15:54:20 +0100
commite038d6a1cdb2ffbf666d360553c31786acaf70b2 (patch)
tree214bcc4550360f2497fe82e85154df0859ff35b4
parente66c4deda8c63ca6c1557eed7c09ba01c6284e57 (diff)
downloadnode-new-e038d6a1cdb2ffbf666d360553c31786acaf70b2.tar.gz
test: refactor common.expectsError
This completely refactors the `expectsError` behavior: so far it's almost identical to `assert.throws(fn, object)` in case it was used with a function as first argument. It had a magical property check that allowed to verify a functions `type` in case `type` was passed used in the validation object. This pattern is now completely removed and `assert.throws()` should be used instead. The main intent for `common.expectsError()` is to verify error cases for callback based APIs. This is now more flexible by accepting all validation possibilites that `assert.throws()` accepts as well. No magical properties exist anymore. This reduces surprising behavior for developers who are not used to the Node.js core code base. This has the side effect that `common` is used significantly less frequent. PR-URL: https://github.com/nodejs/node/pull/31092 Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
-rw-r--r--test/.eslintrc.yaml1
-rw-r--r--test/addons/stringbytes-external-exceed-max/test-stringbytes-external-exceed-max-by-1-ascii.js5
-rw-r--r--test/addons/stringbytes-external-exceed-max/test-stringbytes-external-exceed-max-by-1-base64.js5
-rw-r--r--test/addons/stringbytes-external-exceed-max/test-stringbytes-external-exceed-max-by-1-binary.js4
-rw-r--r--test/addons/stringbytes-external-exceed-max/test-stringbytes-external-exceed-max-by-1-hex.js5
-rw-r--r--test/addons/stringbytes-external-exceed-max/test-stringbytes-external-exceed-max-by-1-utf8.js6
-rw-r--r--test/addons/stringbytes-external-exceed-max/test-stringbytes-external-exceed-max.js5
-rw-r--r--test/async-hooks/test-embedder.api.async-resource-no-type.js4
-rw-r--r--test/async-hooks/test-embedder.api.async-resource.js8
-rw-r--r--test/common/README.md46
-rw-r--r--test/common/index.js84
-rw-r--r--test/es-module/test-esm-loader-modulemap.js19
-rw-r--r--test/es-module/test-esm-loader-search.js7
-rw-r--r--test/fixtures/require-resolve.js4
-rw-r--r--test/internet/test-dns-promises-resolve.js10
-rw-r--r--test/js-native-api/test_error/test.js6
-rw-r--r--test/js-native-api/test_general/test.js4
-rw-r--r--test/js-native-api/test_general/testFinalizer.js8
-rw-r--r--test/parallel/test-assert.js80
-rw-r--r--test/parallel/test-async-hooks-asyncresource-constructor.js19
-rw-r--r--test/parallel/test-async-hooks-constructor.js7
-rw-r--r--test/parallel/test-async-wrap-constructor.js7
-rw-r--r--test/parallel/test-buffer-alloc.js50
-rw-r--r--test/parallel/test-buffer-bytelength.js4
-rw-r--r--test/parallel/test-buffer-compare-offset.js6
-rw-r--r--test/parallel/test-buffer-compare.js6
-rw-r--r--test/parallel/test-buffer-copy.js10
-rw-r--r--test/parallel/test-buffer-equals.js6
-rw-r--r--test/parallel/test-buffer-fill.js34
-rw-r--r--test/parallel/test-buffer-includes.js4
-rw-r--r--test/parallel/test-buffer-indexof.js4
-rw-r--r--test/parallel/test-buffer-new.js7
-rw-r--r--test/parallel/test-buffer-no-negative-allocation.js8
-rw-r--r--test/parallel/test-buffer-over-max-length.js8
-rw-r--r--test/parallel/test-buffer-read.js4
-rw-r--r--test/parallel/test-buffer-tostring-range.js10
-rw-r--r--test/parallel/test-buffer-tostring-rangeerror.js8
-rw-r--r--test/parallel/test-buffer-tostring.js2
-rw-r--r--test/parallel/test-buffer-write.js2
-rw-r--r--test/parallel/test-buffer-writeint.js8
-rw-r--r--test/parallel/test-c-ares.js6
-rw-r--r--test/parallel/test-child-process-advanced-serialization.js2
-rw-r--r--test/parallel/test-child-process-constructor.js20
-rw-r--r--test/parallel/test-child-process-fork-args.js12
-rw-r--r--test/parallel/test-child-process-fork-stdio-string-variant.js4
-rw-r--r--test/parallel/test-child-process-fork-stdio.js4
-rw-r--r--test/parallel/test-child-process-send-after-close.js2
-rw-r--r--test/parallel/test-child-process-send-type-error.js4
-rw-r--r--test/parallel/test-child-process-spawn-typeerror.js14
-rw-r--r--test/parallel/test-child-process-spawnsync-input.js4
-rw-r--r--test/parallel/test-child-process-spawnsync-kill-signal.js4
-rw-r--r--test/parallel/test-child-process-spawnsync-validation-errors.js11
-rw-r--r--test/parallel/test-child-process-stdio.js4
-rw-r--r--test/parallel/test-child-process-validate-stdio.js16
-rw-r--r--test/parallel/test-common.js2
-rw-r--r--test/parallel/test-console-instance.js8
-rw-r--r--test/parallel/test-console-no-swallow-stack-overflow.js3
-rw-r--r--test/parallel/test-console-table.js4
-rw-r--r--test/parallel/test-crypto-authenticated.js36
-rw-r--r--test/parallel/test-crypto-binary-default.js4
-rw-r--r--test/parallel/test-crypto-cipher-decipher.js44
-rw-r--r--test/parallel/test-crypto-cipheriv-decipheriv.js24
-rw-r--r--test/parallel/test-crypto-dh.js20
-rw-r--r--test/parallel/test-crypto-ecdh-convert-key.js16
-rw-r--r--test/parallel/test-crypto-engine.js17
-rw-r--r--test/parallel/test-crypto-hash.js34
-rw-r--r--test/parallel/test-crypto-hmac.js12
-rw-r--r--test/parallel/test-crypto-key-objects.js44
-rw-r--r--test/parallel/test-crypto-keygen.js148
-rw-r--r--test/parallel/test-crypto-random.js16
-rw-r--r--test/parallel/test-crypto-rsa-dsa.js6
-rw-r--r--test/parallel/test-crypto-scrypt.js36
-rw-r--r--test/parallel/test-crypto-sign-verify.js24
-rw-r--r--test/parallel/test-crypto.js161
-rw-r--r--test/parallel/test-dgram-bind-fd-error.js8
-rw-r--r--test/parallel/test-dgram-bind.js4
-rw-r--r--test/parallel/test-dgram-createSocket-type.js4
-rw-r--r--test/parallel/test-dgram-custom-lookup.js5
-rw-r--r--test/parallel/test-dgram-membership.js16
-rw-r--r--test/parallel/test-dgram-multicast-setTTL.js4
-rw-r--r--test/parallel/test-dgram-send-bad-arguments.js28
-rw-r--r--test/parallel/test-dgram-setTTL.js4
-rw-r--r--test/parallel/test-dgram-socket-buffer-size.js21
-rw-r--r--test/parallel/test-dns-lookup.js26
-rw-r--r--test/parallel/test-dns-resolvens-typeerror.js15
-rw-r--r--test/parallel/test-dns-setserver-when-querying.js3
-rw-r--r--test/parallel/test-dns.js60
-rw-r--r--test/parallel/test-domain-load-after-set-uncaught-exception-capture.js5
-rw-r--r--test/parallel/test-domain-set-uncaught-exception-capture-after-load.js2
-rw-r--r--test/parallel/test-eslint-prefer-common-expectserror.js31
-rw-r--r--test/parallel/test-event-capture-rejections.js8
-rw-r--r--test/parallel/test-event-emitter-add-listeners.js4
-rw-r--r--test/parallel/test-event-emitter-error-monitor.js2
-rw-r--r--test/parallel/test-event-emitter-errors.js15
-rw-r--r--test/parallel/test-event-emitter-max-listeners.js9
-rw-r--r--test/parallel/test-event-emitter-once.js4
-rw-r--r--test/parallel/test-event-emitter-prepend.js4
-rw-r--r--test/parallel/test-event-emitter-remove-listeners.js4
-rw-r--r--test/parallel/test-file-write-stream.js6
-rw-r--r--test/parallel/test-file-write-stream3.js8
-rw-r--r--test/parallel/test-fs-access.js8
-rw-r--r--test/parallel/test-fs-assert-encoding-error.js6
-rw-r--r--test/parallel/test-fs-buffer.js4
-rw-r--r--test/parallel/test-fs-chmod.js4
-rw-r--r--test/parallel/test-fs-chown-type-check.js25
-rw-r--r--test/parallel/test-fs-copyfile.js20
-rw-r--r--test/parallel/test-fs-lchmod.js8
-rw-r--r--test/parallel/test-fs-lchown.js20
-rw-r--r--test/parallel/test-fs-link.js16
-rw-r--r--test/parallel/test-fs-make-callback.js7
-rw-r--r--test/parallel/test-fs-makeStatsCallback.js5
-rw-r--r--test/parallel/test-fs-mkdir.js16
-rw-r--r--test/parallel/test-fs-mkdtemp-prefix-check.js9
-rw-r--r--test/parallel/test-fs-non-number-arguments-throw.js12
-rw-r--r--test/parallel/test-fs-null-bytes.js8
-rw-r--r--test/parallel/test-fs-open-flags.js16
-rw-r--r--test/parallel/test-fs-open.js16
-rw-r--r--test/parallel/test-fs-opendir.js8
-rw-r--r--test/parallel/test-fs-promises.js6
-rw-r--r--test/parallel/test-fs-read-file-assert-encoding.js7
-rw-r--r--test/parallel/test-fs-read-stream-inherit.js4
-rw-r--r--test/parallel/test-fs-read-stream-throw-type-error.js9
-rw-r--r--test/parallel/test-fs-read-stream.js4
-rw-r--r--test/parallel/test-fs-readdir-stack-overflow.js7
-rw-r--r--test/parallel/test-fs-readdir.js8
-rw-r--r--test/parallel/test-fs-readfile-error.js4
-rw-r--r--test/parallel/test-fs-readlink-type-check.js9
-rw-r--r--test/parallel/test-fs-realpath.js4
-rw-r--r--test/parallel/test-fs-rmdir-recursive.js22
-rw-r--r--test/parallel/test-fs-rmdir-type-check.js9
-rw-r--r--test/parallel/test-fs-timestamp-parsing-error.js11
-rw-r--r--test/parallel/test-fs-unlink-type-check.js9
-rw-r--r--test/parallel/test-fs-util-validateoffsetlengthwrite.js11
-rw-r--r--test/parallel/test-fs-utimes.js20
-rw-r--r--test/parallel/test-fs-watch.js4
-rw-r--r--test/parallel/test-fs-watchfile.js12
-rw-r--r--test/parallel/test-fs-whatwg-url.js24
-rw-r--r--test/parallel/test-fs-write-stream-throw-type-error.js7
-rw-r--r--test/parallel/test-fs-write-stream.js4
-rw-r--r--test/parallel/test-fs-write.js8
-rw-r--r--test/parallel/test-fs-writev-sync.js10
-rw-r--r--test/parallel/test-fs-writev.js8
-rw-r--r--test/parallel/test-http-client-check-http-token.js5
-rw-r--r--test/parallel/test-http-client-invalid-path.js7
-rw-r--r--test/parallel/test-http-client-reject-unexpected-agent.js4
-rw-r--r--test/parallel/test-http-client-set-timeout.js2
-rw-r--r--test/parallel/test-http-client-unescaped-path.js5
-rw-r--r--test/parallel/test-http-header-overflow.js2
-rw-r--r--test/parallel/test-http-hostname-typechecking.js9
-rw-r--r--test/parallel/test-http-invalid-path-chars.js21
-rw-r--r--test/parallel/test-http-invalid-urls.js5
-rw-r--r--test/parallel/test-http-mutable-headers.js20
-rw-r--r--test/parallel/test-http-outgoing-proto.js38
-rw-r--r--test/parallel/test-http-outgoing-renderHeaders.js8
-rw-r--r--test/parallel/test-http-request-invalid-method-error.js7
-rw-r--r--test/parallel/test-http-res-write-after-end.js2
-rw-r--r--test/parallel/test-http-response-add-header-after-sent.js7
-rw-r--r--test/parallel/test-http-response-remove-header-after-sent.js7
-rw-r--r--test/parallel/test-http-response-splitting.js6
-rw-r--r--test/parallel/test-http-response-statuscode.js16
-rw-r--r--test/parallel/test-http-server-de-chunked-trailer.js6
-rw-r--r--test/parallel/test-http-server-destroy-socket-on-client-error.js2
-rw-r--r--test/parallel/test-http-server-write-after-end.js2
-rw-r--r--test/parallel/test-http-unix-socket.js2
-rw-r--r--test/parallel/test-http-url.parse-only-support-http-https-protocol.js7
-rw-r--r--test/parallel/test-http-write-head.js12
-rw-r--r--test/parallel/test-http2-client-destroy.js26
-rw-r--r--test/parallel/test-http2-client-http1-server.js4
-rw-r--r--test/parallel/test-http2-client-onconnect-errors.js6
-rw-r--r--test/parallel/test-http2-client-request-options-errors.js5
-rw-r--r--test/parallel/test-http2-client-rststream-before-connect.js6
-rw-r--r--test/parallel/test-http2-client-setNextStreamID-errors.js9
-rw-r--r--test/parallel/test-http2-client-settings-before-connect.js9
-rw-r--r--test/parallel/test-http2-client-stream-destroy-before-connect.js2
-rw-r--r--test/parallel/test-http2-client-unescaped-path.js2
-rw-r--r--test/parallel/test-http2-compat-serverresponse-createpushresponse.js4
-rw-r--r--test/parallel/test-http2-compat-serverresponse-destroy.js4
-rw-r--r--test/parallel/test-http2-compat-serverresponse-flushheaders.js2
-rw-r--r--test/parallel/test-http2-compat-serverresponse-headers.js36
-rw-r--r--test/parallel/test-http2-compat-serverresponse-statuscode.js12
-rw-r--r--test/parallel/test-http2-compat-serverresponse-trailers.js20
-rw-r--r--test/parallel/test-http2-compat-serverresponse-write.js5
-rw-r--r--test/parallel/test-http2-compat-serverresponse-writehead.js2
-rw-r--r--test/parallel/test-http2-compat-socket-set.js10
-rw-r--r--test/parallel/test-http2-compat-socket.js10
-rw-r--r--test/parallel/test-http2-connect-method.js6
-rw-r--r--test/parallel/test-http2-connect.js7
-rw-r--r--test/parallel/test-http2-getpackedsettings.js20
-rw-r--r--test/parallel/test-http2-head-request.js6
-rw-r--r--test/parallel/test-http2-info-headers-errors.js4
-rw-r--r--test/parallel/test-http2-info-headers.js44
-rw-r--r--test/parallel/test-http2-invalidargtypes-errors.js5
-rw-r--r--test/parallel/test-http2-max-concurrent-streams.js2
-rw-r--r--test/parallel/test-http2-misbehaving-flow-control-paused.js2
-rw-r--r--test/parallel/test-http2-misbehaving-flow-control.js2
-rw-r--r--test/parallel/test-http2-misbehaving-multiplex.js4
-rw-r--r--test/parallel/test-http2-misc-util.js12
-rw-r--r--test/parallel/test-http2-misused-pseudoheaders.js11
-rw-r--r--test/parallel/test-http2-multi-content-length.js7
-rw-r--r--test/parallel/test-http2-no-more-streams.js2
-rw-r--r--test/parallel/test-http2-options-max-headers-block-length.js2
-rw-r--r--test/parallel/test-http2-ping.js14
-rw-r--r--test/parallel/test-http2-respond-errors.js9
-rw-r--r--test/parallel/test-http2-respond-file-204.js5
-rw-r--r--test/parallel/test-http2-respond-file-404.js2
-rw-r--r--test/parallel/test-http2-respond-file-error-dir.js2
-rw-r--r--test/parallel/test-http2-respond-file-error-pipe-offset.js2
-rw-r--r--test/parallel/test-http2-respond-file-errors.js11
-rw-r--r--test/parallel/test-http2-respond-file-fd-errors.js21
-rw-r--r--test/parallel/test-http2-respond-file-fd-invalid.js6
-rw-r--r--test/parallel/test-http2-respond-nghttperrors.js4
-rw-r--r--test/parallel/test-http2-respond-with-fd-errors.js4
-rw-r--r--test/parallel/test-http2-server-http1-client.js2
-rw-r--r--test/parallel/test-http2-server-push-disabled.js4
-rw-r--r--test/parallel/test-http2-server-push-stream-errors-args.js4
-rw-r--r--test/parallel/test-http2-server-push-stream-errors.js6
-rw-r--r--test/parallel/test-http2-server-push-stream-head.js2
-rw-r--r--test/parallel/test-http2-server-push-stream.js4
-rw-r--r--test/parallel/test-http2-server-rst-before-respond.js2
-rw-r--r--test/parallel/test-http2-server-rst-stream.js2
-rw-r--r--test/parallel/test-http2-server-sessionerror.js2
-rw-r--r--test/parallel/test-http2-server-settimeout-no-callback.js4
-rw-r--r--test/parallel/test-http2-server-shutdown-options-errors.js13
-rw-r--r--test/parallel/test-http2-server-shutdown-redundant.js5
-rw-r--r--test/parallel/test-http2-server-stream-session-destroy.js16
-rw-r--r--test/parallel/test-http2-session-settings.js8
-rw-r--r--test/parallel/test-http2-single-headers.js9
-rw-r--r--test/parallel/test-http2-socket-proxy.js44
-rw-r--r--test/parallel/test-http2-status-code-invalid.js2
-rw-r--r--test/parallel/test-http2-timeouts.js13
-rw-r--r--test/parallel/test-http2-too-large-headers.js2
-rw-r--r--test/parallel/test-http2-too-many-headers.js2
-rw-r--r--test/parallel/test-http2-too-many-settings.js2
-rw-r--r--test/parallel/test-http2-trailers.js12
-rw-r--r--test/parallel/test-http2-unbound-socket-proxy.js7
-rw-r--r--test/parallel/test-http2-util-assert-valid-pseudoheader.js7
-rw-r--r--test/parallel/test-http2-util-asserts.js13
-rw-r--r--test/parallel/test-http2-util-headers-list.js12
-rw-r--r--test/parallel/test-http2-util-nghttp2error.js8
-rw-r--r--test/parallel/test-https-timeout.js2
-rw-r--r--test/parallel/test-icu-punycode.js4
-rw-r--r--test/parallel/test-icu-transcode.js4
-rw-r--r--test/parallel/test-internal-errors.js14
-rw-r--r--test/parallel/test-internal-fs.js6
-rw-r--r--test/parallel/test-internal-module-require.js2
-rw-r--r--test/parallel/test-internal-socket-list-send.js6
-rw-r--r--test/parallel/test-internal-util-assertCrypto.js2
-rw-r--r--test/parallel/test-loaders-hidden-from-users.js7
-rw-r--r--test/parallel/test-module-loading-error.js8
-rw-r--r--test/parallel/test-net-better-error-messages-path.js3
-rw-r--r--test/parallel/test-net-better-error-messages-port-hostname.js17
-rw-r--r--test/parallel/test-net-connect-immediate-finish.js21
-rw-r--r--test/parallel/test-net-connect-options-port.js16
-rw-r--r--test/parallel/test-net-listen-invalid-port.js12
-rw-r--r--test/parallel/test-net-localerror.js7
-rw-r--r--test/parallel/test-net-options-lookup.js5
-rw-r--r--test/parallel/test-net-server-call-listen-multiple-times.js5
-rw-r--r--test/parallel/test-net-server-listen-options.js26
-rw-r--r--test/parallel/test-net-server-options.js23
-rw-r--r--test/parallel/test-net-socket-constructor.js4
-rw-r--r--test/parallel/test-net-socket-destroy-send.js4
-rw-r--r--test/parallel/test-net-socket-timeout.js4
-rw-r--r--test/parallel/test-net-socket-write-after-close.js2
-rw-r--r--test/parallel/test-net-socket-write-error.js13
-rw-r--r--test/parallel/test-net-write-after-end-nt.js2
-rw-r--r--test/parallel/test-net-write-arguments.js15
-rw-r--r--test/parallel/test-next-tick-errors.js18
-rw-r--r--test/parallel/test-os-checked-function.js5
-rw-r--r--test/parallel/test-os-process-priority.js12
-rw-r--r--test/parallel/test-outgoing-message-pipe.js7
-rw-r--r--test/parallel/test-path-parse-format.js4
-rw-r--r--test/parallel/test-path.js4
-rw-r--r--test/parallel/test-performance-function.js12
-rw-r--r--test/parallel/test-performanceobserver.js20
-rw-r--r--test/parallel/test-pipe-outgoing-message-data-emitted-after-ended.js2
-rw-r--r--test/parallel/test-process-assert.js8
-rw-r--r--test/parallel/test-process-chdir-errormessage.js5
-rw-r--r--test/parallel/test-process-chdir.js4
-rw-r--r--test/parallel/test-process-emitwarning.js4
-rw-r--r--test/parallel/test-process-exception-capture-errors.js9
-rw-r--r--test/parallel/test-process-hrtime.js18
-rw-r--r--test/parallel/test-process-kill-pid.js8
-rw-r--r--test/parallel/test-process-next-tick.js5
-rw-r--r--test/parallel/test-querystring-escape.js6
-rw-r--r--test/parallel/test-querystring.js6
-rw-r--r--test/parallel/test-readline-csi.js4
-rw-r--r--test/parallel/test-readline-interface-escapecodetimeout.js6
-rw-r--r--test/parallel/test-readline-interface.js24
-rw-r--r--test/parallel/test-repl-options.js4
-rw-r--r--test/parallel/test-require-invalid-package.js7
-rw-r--r--test/parallel/test-require-resolve.js4
-rw-r--r--test/parallel/test-stream-base-typechecking.js5
-rw-r--r--test/parallel/test-stream-inheritance.js6
-rw-r--r--test/parallel/test-stream-readable-invalid-chunk.js4
-rw-r--r--test/parallel/test-stream-readable-with-unimplemented-_read.js2
-rw-r--r--test/parallel/test-stream-transform-callback-twice.js2
-rw-r--r--test/parallel/test-stream-transform-constructor-set-methods.js2
-rw-r--r--test/parallel/test-stream-transform-split-highwatermark.js10
-rw-r--r--test/parallel/test-stream-unshift-read-race.js4
-rw-r--r--test/parallel/test-stream-wrap-encoding.js4
-rw-r--r--test/parallel/test-stream-writable-callback-twice.js2
-rw-r--r--test/parallel/test-stream-writable-change-default-encoding.js12
-rw-r--r--test/parallel/test-stream-writable-constructor-set-methods.js2
-rw-r--r--test/parallel/test-stream-writable-destroy.js10
-rw-r--r--test/parallel/test-stream-writable-null.js10
-rw-r--r--test/parallel/test-stream-writable-write-cb-twice.js13
-rw-r--r--test/parallel/test-streams-highwatermark.js4
-rw-r--r--test/parallel/test-string-decoder.js12
-rw-r--r--test/parallel/test-timers-enroll-invalid-msecs.js11
-rw-r--r--test/parallel/test-timers-immediate-queue-throw.js2
-rw-r--r--test/parallel/test-timers-refresh.js4
-rw-r--r--test/parallel/test-timers-throw-when-cb-not-function.js8
-rw-r--r--test/parallel/test-tls-basic-validations.js34
-rw-r--r--test/parallel/test-tls-clientcertengine-invalid-arg-type.js3
-rw-r--r--test/parallel/test-tls-clientcertengine-unsupported.js3
-rw-r--r--test/parallel/test-tls-disable-renegotiation.js18
-rw-r--r--test/parallel/test-tls-error-servername.js5
-rw-r--r--test/parallel/test-tls-keyengine-invalid-arg-type.js5
-rw-r--r--test/parallel/test-tls-keyengine-unsupported.js3
-rw-r--r--test/parallel/test-tls-no-cert-required.js4
-rw-r--r--test/parallel/test-tls-options-boolean-check.js13
-rw-r--r--test/parallel/test-trace-events-api-worker-disabled.js2
-rw-r--r--test/parallel/test-trace-events-api.js12
-rw-r--r--test/parallel/test-url-format-invalid-input.js4
-rw-r--r--test/parallel/test-url-parse-invalid-input.js4
-rw-r--r--test/parallel/test-util-callbackify.js8
-rw-r--r--test/parallel/test-util-deprecate-invalid-code.js5
-rw-r--r--test/parallel/test-util-inherits.js14
-rw-r--r--test/parallel/test-util-inspect.js8
-rw-r--r--test/parallel/test-util-promisify.js8
-rw-r--r--test/parallel/test-uv-errno.js8
-rw-r--r--test/parallel/test-v8-flag-type-check.js5
-rw-r--r--test/parallel/test-validators.js9
-rw-r--r--test/parallel/test-vm-basic.js52
-rw-r--r--test/parallel/test-vm-cached-data.js4
-rw-r--r--test/parallel/test-vm-codegen.js10
-rw-r--r--test/parallel/test-vm-context.js14
-rw-r--r--test/parallel/test-vm-create-context-arg.js7
-rw-r--r--test/parallel/test-vm-is-context.js6
-rw-r--r--test/parallel/test-vm-module-basic.js16
-rw-r--r--test/parallel/test-vm-module-errors.js16
-rw-r--r--test/parallel/test-vm-module-import-meta.js4
-rw-r--r--test/parallel/test-vm-options-validation.js33
-rw-r--r--test/parallel/test-vm-sigint-existing-handler.js2
-rw-r--r--test/parallel/test-vm-sigint.js2
-rw-r--r--test/parallel/test-whatwg-encoding-custom-fatal-streaming.js13
-rw-r--r--test/parallel/test-whatwg-encoding-custom-interop.js10
-rw-r--r--test/parallel/test-whatwg-encoding-custom-textdecoder-api-invalid-label.js15
-rw-r--r--test/parallel/test-whatwg-encoding-custom-textdecoder-fatal.js6
-rw-r--r--test/parallel/test-whatwg-encoding-custom-textdecoder-invalid-arg.js7
-rw-r--r--test/parallel/test-whatwg-encoding-custom-textdecoder-utf16-surrogates.js6
-rw-r--r--test/parallel/test-whatwg-encoding-custom-textdecoder.js32
-rw-r--r--test/parallel/test-whatwg-url-custom-domainto.js3
-rw-r--r--test/parallel/test-whatwg-url-custom-href-side-effect.js6
-rw-r--r--test/parallel/test-whatwg-url-custom-parsing.js5
-rw-r--r--test/parallel/test-whatwg-url-custom-searchparams-append.js10
-rw-r--r--test/parallel/test-whatwg-url-custom-searchparams-constructor.js14
-rw-r--r--test/parallel/test-whatwg-url-custom-searchparams-delete.js10
-rw-r--r--test/parallel/test-whatwg-url-custom-searchparams-entries.js10
-rw-r--r--test/parallel/test-whatwg-url-custom-searchparams-foreach.js7
-rw-r--r--test/parallel/test-whatwg-url-custom-searchparams-get.js10
-rw-r--r--test/parallel/test-whatwg-url-custom-searchparams-getall.js10
-rw-r--r--test/parallel/test-whatwg-url-custom-searchparams-has.js10
-rw-r--r--test/parallel/test-whatwg-url-custom-searchparams-keys.js10
-rw-r--r--test/parallel/test-whatwg-url-custom-searchparams-set.js10
-rw-r--r--test/parallel/test-whatwg-url-custom-searchparams-stringifier.js7
-rw-r--r--test/parallel/test-whatwg-url-custom-searchparams-values.js10
-rw-r--r--test/parallel/test-whatwg-url-custom-searchparams.js8
-rw-r--r--test/parallel/test-worker-execargv-invalid.js14
-rw-r--r--test/parallel/test-worker-process-env.js4
-rw-r--r--test/parallel/test-worker-stack-overflow.js7
-rw-r--r--test/parallel/test-worker-type-check.js5
-rw-r--r--test/parallel/test-worker-unsupported-path.js14
-rw-r--r--test/parallel/test-wrap-js-stream-exceptions.js2
-rw-r--r--test/parallel/test-zlib-brotli.js14
-rw-r--r--test/parallel/test-zlib-convenience-methods.js4
-rw-r--r--test/parallel/test-zlib-deflate-constructors.js114
-rw-r--r--test/parallel/test-zlib-failed-init.js14
-rw-r--r--test/parallel/test-zlib-flush-flags.js19
-rw-r--r--test/parallel/test-zlib-from-gzip-with-trailing-garbage.js2
-rw-r--r--test/parallel/test-zlib-not-string-or-buffer.js5
-rw-r--r--test/parallel/test-zlib-write-after-close.js5
-rw-r--r--test/parallel/test-zlib-zero-windowBits.js6
-rw-r--r--test/pummel/test-fs-readfile-tostring-fail.js2
-rw-r--r--test/report/test-report-config.js16
-rw-r--r--test/report/test-report-getreport.js2
-rw-r--r--test/report/test-report-writereport.js4
-rw-r--r--test/root.status1
-rw-r--r--test/sequential/test-crypto-timing-safe-equal.js12
-rw-r--r--test/sequential/test-heapdump.js4
-rw-r--r--test/sequential/test-http2-max-session-memory.js2
-rw-r--r--test/sequential/test-inspector-module.js21
-rw-r--r--test/sequential/test-inspector-port-cluster.js14
-rw-r--r--test/sequential/test-perf-hooks.js4
-rw-r--r--test/sequential/test-performance-eventloopdelay.js20
-rw-r--r--test/sequential/test-tls-lookup.js5
396 files changed, 2122 insertions, 2172 deletions
diff --git a/test/.eslintrc.yaml b/test/.eslintrc.yaml
index 1dd006566a..81e4703220 100644
--- a/test/.eslintrc.yaml
+++ b/test/.eslintrc.yaml
@@ -14,7 +14,6 @@ rules:
# Custom rules in tools/eslint-rules
node-core/prefer-assert-iferror: error
node-core/prefer-assert-methods: error
- node-core/prefer-common-expectserror: error
node-core/prefer-common-mustnotcall: error
node-core/crypto-check: error
node-core/eslint-check: error
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 55f50f5249..024ba28aba 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
@@ -5,6 +5,7 @@ const skipMessage = 'intensive toString tests due to memory confinements';
if (!common.enoughTestMem)
common.skip(skipMessage);
+const assert = require('assert');
const binding = require(`./build/${common.buildType}/binding`);
// v8 fails silently if string length > v8::String::kMaxLength
@@ -25,11 +26,11 @@ if (!binding.ensureAllocation(2 * kStringMaxLength))
common.skip(skipMessage);
const stringLengthHex = kStringMaxLength.toString(16);
-common.expectsError(() => {
+assert.throws(() => {
buf.toString('ascii');
}, {
message: `Cannot create a string longer than 0x${stringLengthHex} ` +
'characters',
code: 'ERR_STRING_TOO_LONG',
- type: Error
+ name: 'Error'
});
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 20d968787b..2013763602 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
@@ -5,6 +5,7 @@ const skipMessage = 'intensive toString tests due to memory confinements';
if (!common.enoughTestMem)
common.skip(skipMessage);
+const assert = require('assert');
const binding = require(`./build/${common.buildType}/binding`);
// v8 fails silently if string length > v8::String::kMaxLength
@@ -25,11 +26,11 @@ if (!binding.ensureAllocation(2 * kStringMaxLength))
common.skip(skipMessage);
const stringLengthHex = kStringMaxLength.toString(16);
-common.expectsError(() => {
+assert.throws(() => {
buf.toString('base64');
}, {
message: `Cannot create a string longer than 0x${stringLengthHex} ` +
'characters',
code: 'ERR_STRING_TOO_LONG',
- type: Error
+ name: 'Error'
});
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 f6ae5217dd..1ad04dc652 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
@@ -27,13 +27,13 @@ if (!binding.ensureAllocation(2 * kStringMaxLength))
common.skip(skipMessage);
const stringLengthHex = kStringMaxLength.toString(16);
-common.expectsError(() => {
+assert.throws(() => {
buf.toString('latin1');
}, {
message: `Cannot create a string longer than 0x${stringLengthHex} ` +
'characters',
code: 'ERR_STRING_TOO_LONG',
- type: Error
+ name: 'Error'
});
// FIXME: Free the memory early to avoid OOM.
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 fa7a47cf18..7e3132af09 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
@@ -5,6 +5,7 @@ const skipMessage = 'intensive toString tests due to memory confinements';
if (!common.enoughTestMem)
common.skip(skipMessage);
+const assert = require('assert');
const binding = require(`./build/${common.buildType}/binding`);
// v8 fails silently if string length > v8::String::kMaxLength
@@ -25,11 +26,11 @@ if (!binding.ensureAllocation(2 * kStringMaxLength))
common.skip(skipMessage);
const stringLengthHex = kStringMaxLength.toString(16);
-common.expectsError(() => {
+assert.throws(() => {
buf.toString('hex');
}, {
message: `Cannot create a string longer than 0x${stringLengthHex} ` +
'characters',
code: 'ERR_STRING_TOO_LONG',
- type: Error
+ name: 'Error'
});
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 43c88bd49e..2ca7050d8a 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
@@ -35,7 +35,7 @@ assert.throws(() => {
message: `Cannot create a string longer than 0x${stringLengthHex} ` +
'characters',
code: 'ERR_STRING_TOO_LONG',
- type: Error
+ name: 'Error'
})(e);
return true;
} else {
@@ -43,11 +43,11 @@ assert.throws(() => {
}
});
-common.expectsError(() => {
+assert.throws(() => {
buf.toString('utf8');
}, {
message: `Cannot create a string longer than 0x${stringLengthHex} ` +
'characters',
code: 'ERR_STRING_TOO_LONG',
- type: Error
+ name: 'Error'
});
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 8b419eb436..7206b90d5f 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
@@ -5,6 +5,7 @@ const skipMessage = 'intensive toString tests due to memory confinements';
if (!common.enoughTestMem)
common.skip(skipMessage);
+const assert = require('assert');
const binding = require(`./build/${common.buildType}/binding`);
// v8 fails silently if string length > v8::String::kMaxLength
@@ -26,11 +27,11 @@ if (!binding.ensureAllocation(2 * kStringMaxLength))
const stringLengthHex = kStringMaxLength.toString(16);
-common.expectsError(() => {
+assert.throws(() => {
buf.toString('utf16le');
}, {
message: `Cannot create a string longer than 0x${stringLengthHex} ` +
'characters',
code: 'ERR_STRING_TOO_LONG',
- type: Error
+ name: 'Error'
});
diff --git a/test/async-hooks/test-embedder.api.async-resource-no-type.js b/test/async-hooks/test-embedder.api.async-resource-no-type.js
index 69b6667edb..2600325e1e 100644
--- a/test/async-hooks/test-embedder.api.async-resource-no-type.js
+++ b/test/async-hooks/test-embedder.api.async-resource-no-type.js
@@ -18,9 +18,9 @@ if (process.argv[2] === 'child') {
}
[null, undefined, 1, Date, {}, []].forEach((i) => {
- common.expectsError(() => new Foo(i), {
+ assert.throws(() => new Foo(i), {
code: 'ERR_INVALID_ARG_TYPE',
- type: TypeError
+ name: 'TypeError'
});
});
diff --git a/test/async-hooks/test-embedder.api.async-resource.js b/test/async-hooks/test-embedder.api.async-resource.js
index 19c1b7187a..c53590393a 100644
--- a/test/async-hooks/test-embedder.api.async-resource.js
+++ b/test/async-hooks/test-embedder.api.async-resource.js
@@ -12,16 +12,16 @@ const { checkInvocations } = require('./hook-checks');
const hooks = initHooks();
hooks.enable();
-common.expectsError(
+assert.throws(
() => new AsyncResource(), {
code: 'ERR_INVALID_ARG_TYPE',
- type: TypeError,
+ name: 'TypeError',
});
-common.expectsError(() => {
+assert.throws(() => {
new AsyncResource('invalid_trigger_id', { triggerAsyncId: null });
}, {
code: 'ERR_INVALID_ASYNC_ID',
- type: RangeError,
+ name: 'RangeError',
});
assert.strictEqual(
diff --git a/test/common/README.md b/test/common/README.md
index afd054eae1..effc458448 100644
--- a/test/common/README.md
+++ b/test/common/README.md
@@ -71,44 +71,17 @@ the `unhandledRejection` hook is directly used by the test.
Indicates if there is more than 1gb of total memory.
-### expectsError(\[fn, \]settings\[, exact\])
-* `fn` [&lt;Function>][] a function that should throw.
-* `settings` [&lt;Object>][]
- that must contain the `code` property plus any of the other following
- properties (some properties only apply for `AssertionError`):
- * `code` [&lt;string>][]
- expected error must have this value for its `code` property.
- * `type` [&lt;Function>][]
- expected error must be an instance of `type` and must be an Error subclass.
- * `message` [&lt;string>][] or [&lt;RegExp>][]
- if a string is provided for `message`, expected error must have it for its
- `message` property; if a regular expression is provided for `message`, the
- regular expression must match the `message` property of the expected error.
- * `name` [&lt;string>][]
- expected error must have this value for its `name` property.
- * `info` &lt;Object> expected error must have the same `info` property
- that is deeply equal to this value.
- * `generatedMessage` [&lt;string>][]
- (`AssertionError` only) expected error must have this value for its
- `generatedMessage` property.
- * `actual` &lt;any>
- (`AssertionError` only) expected error must have this value for its
- `actual` property.
- * `expected` &lt;any>
- (`AssertionError` only) expected error must have this value for its
- `expected` property.
- * `operator` &lt;any>
- (`AssertionError` only) expected error must have this value for its
- `operator` property.
+### expectsError(validator\[, exact\])
+* `validator` [&lt;Object>][] | [&lt;RegExp>][] | [&lt;Function>][] |
+ [&lt;Error>][] The validator behaves identical to
+ `assert.throws(fn, validator)`.
* `exact` [&lt;number>][] default = 1
-* return [&lt;Function>][]
+* return [&lt;Function>][] A callback function that expects an error.
- If `fn` is provided, it will be passed to `assert.throws` as first argument
- and `undefined` will be returned.
- Otherwise a function suitable as callback or for use as a validation function
- passed as the second argument to `assert.throws()` will be returned. If the
- returned function has not been called exactly `exact` number of times when the
- test is complete, then the test will fail.
+A function suitable as callback to validate callback based errors. The error is
+validated using `assert.throws(() => { throw error; }, validator)`. If the
+returned function has not been called exactly `exact` number of times when the
+test is complete, then the test will fail.
### expectWarning(name\[, expected\[, code\]\])
* `name` [&lt;string>][] | [&lt;Object>][]
@@ -929,6 +902,7 @@ See [the WPT tests README][] for details.
[&lt;ArrayBufferView>]: https://developer.mozilla.org/en-US/docs/Web/API/ArrayBufferView
[&lt;Buffer>]: https://nodejs.org/api/buffer.html#buffer_class_buffer
[&lt;BufferSource>]: https://developer.mozilla.org/en-US/docs/Web/API/BufferSource
+[&lt;Error>]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error
[&lt;Function>]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function
[&lt;Object>]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object
[&lt;RegExp>]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp
diff --git a/test/common/index.js b/test/common/index.js
index e93c73820a..a231c45e1e 100644
--- a/test/common/index.js
+++ b/test/common/index.js
@@ -525,92 +525,22 @@ function expectWarning(nameOrMap, expected, code) {
}
}
-class Comparison {
- constructor(obj, keys) {
- for (const key of keys) {
- if (key in obj)
- this[key] = obj[key];
- }
- }
-}
-
// Useful for testing expected internal/error objects
-function expectsError(fn, settings, exact) {
- if (typeof fn !== 'function') {
- exact = settings;
- settings = fn;
- fn = undefined;
- }
-
- function innerFn(error) {
- if (arguments.length !== 1) {
+function expectsError(validator, exact) {
+ return mustCall((...args) => {
+ if (args.length !== 1) {
// Do not use `assert.strictEqual()` to prevent `util.inspect` from
// always being called.
- assert.fail(`Expected one argument, got ${util.inspect(arguments)}`);
+ assert.fail(`Expected one argument, got ${util.inspect(args)}`);
}
+ const error = args.pop();
const descriptor = Object.getOwnPropertyDescriptor(error, 'message');
// The error message should be non-enumerable
assert.strictEqual(descriptor.enumerable, false);
- let innerSettings = settings;
- if ('type' in settings) {
- const type = settings.type;
- if (type !== Error && !Error.isPrototypeOf(type)) {
- throw new TypeError('`settings.type` must inherit from `Error`');
- }
- let constructor = error.constructor;
- if (constructor.name === 'NodeError' && type.name !== 'NodeError') {
- constructor = Object.getPrototypeOf(error.constructor);
- }
- // Add the `type` to the error to properly compare and visualize it.
- if (!('type' in error))
- error.type = constructor;
- }
-
- if ('message' in settings &&
- typeof settings.message === 'object' &&
- settings.message.test(error.message)) {
- // Make a copy so we are able to modify the settings.
- innerSettings = Object.create(
- settings, Object.getOwnPropertyDescriptors(settings));
- // Visualize the message as identical in case of other errors.
- innerSettings.message = error.message;
- }
-
- // Check all error properties.
- const keys = Object.keys(settings);
- for (const key of keys) {
- if (!util.isDeepStrictEqual(error[key], innerSettings[key])) {
- // Create placeholder objects to create a nice output.
- const a = new Comparison(error, keys);
- const b = new Comparison(innerSettings, keys);
-
- const tmpLimit = Error.stackTraceLimit;
- Error.stackTraceLimit = 0;
- const err = new assert.AssertionError({
- actual: a,
- expected: b,
- operator: 'strictEqual',
- stackStartFn: assert.throws
- });
- Error.stackTraceLimit = tmpLimit;
-
- throw new assert.AssertionError({
- actual: error,
- expected: settings,
- operator: 'common.expectsError',
- message: err.message
- });
- }
-
- }
+ assert.throws(() => { throw error; }, validator);
return true;
- }
- if (fn) {
- assert.throws(fn, innerFn);
- return;
- }
- return mustCall(innerFn, exact);
+ }, exact);
}
const suffix = 'This is caused by either a bug in Node.js ' +
diff --git a/test/es-module/test-esm-loader-modulemap.js b/test/es-module/test-esm-loader-modulemap.js
index 1a9e6dea82..a4d56a2c2f 100644
--- a/test/es-module/test-esm-loader-modulemap.js
+++ b/test/es-module/test-esm-loader-modulemap.js
@@ -4,8 +4,9 @@
// This test ensures that the type checking of ModuleMap throws
// errors appropriately
-const common = require('../common');
+require('../common');
+const assert = require('assert');
const { URL } = require('url');
const { Loader } = require('internal/modules/esm/loader');
const ModuleMap = require('internal/modules/esm/module_map');
@@ -20,41 +21,41 @@ const moduleMap = new ModuleMap();
const moduleJob = new ModuleJob(loader, stubModule.module,
() => new Promise(() => {}));
-common.expectsError(
+assert.throws(
() => moduleMap.get(1),
{
code: 'ERR_INVALID_ARG_TYPE',
- type: TypeError,
+ name: 'TypeError',
message: 'The "url" argument must be of type string. Received type number' +
' (1)'
}
);
-common.expectsError(
+assert.throws(
() => moduleMap.set(1, moduleJob),
{
code: 'ERR_INVALID_ARG_TYPE',
- type: TypeError,
+ name: 'TypeError',
message: 'The "url" argument must be of type string. Received type number' +
' (1)'
}
);
-common.expectsError(
+assert.throws(
() => moduleMap.set('somestring', 'notamodulejob'),
{
code: 'ERR_INVALID_ARG_TYPE',
- type: TypeError,
+ name: 'TypeError',
message: 'The "job" argument must be an instance of ModuleJob. ' +
"Received type string ('notamodulejob')"
}
);
-common.expectsError(
+assert.throws(
() => moduleMap.has(1),
{
code: 'ERR_INVALID_ARG_TYPE',
- type: TypeError,
+ name: 'TypeError',
message: 'The "url" argument must be of type string. Received type number' +
' (1)'
}
diff --git a/test/es-module/test-esm-loader-search.js b/test/es-module/test-esm-loader-search.js
index b5e0d8d656..a7e675decc 100644
--- a/test/es-module/test-esm-loader-search.js
+++ b/test/es-module/test-esm-loader-search.js
@@ -3,15 +3,16 @@
// This test ensures that search throws errors appropriately
-const common = require('../common');
+require('../common');
+const assert = require('assert');
const resolve = require('internal/modules/esm/default_resolve');
-common.expectsError(
+assert.throws(
() => resolve('target', undefined),
{
code: 'ERR_MODULE_NOT_FOUND',
- type: Error,
+ name: 'Error',
message: /Cannot find package 'target'/
}
);
diff --git a/test/fixtures/require-resolve.js b/test/fixtures/require-resolve.js
index 66521d12e9..e3a4886bce 100644
--- a/test/fixtures/require-resolve.js
+++ b/test/fixtures/require-resolve.js
@@ -86,11 +86,11 @@ assert.throws(() => {
}
// Test paths option validation
-common.expectsError(() => {
+assert.throws(() => {
require.resolve('.\\three.js', { paths: 'foo' })
}, {
code: 'ERR_INVALID_OPT_VALUE',
- type: TypeError,
+ name: 'TypeError',
});
// Verify that the default require.resolve() is used for empty options.
diff --git a/test/internet/test-dns-promises-resolve.js b/test/internet/test-dns-promises-resolve.js
index b9e7fa4230..a482cba60a 100644
--- a/test/internet/test-dns-promises-resolve.js
+++ b/test/internet/test-dns-promises-resolve.js
@@ -1,5 +1,5 @@
'use strict';
-const common = require('../common');
+require('../common');
const assert = require('assert');
const dnsPromises = require('dns').promises;
@@ -7,11 +7,11 @@ const dnsPromises = require('dns').promises;
// Error when rrtype is invalid.
{
const rrtype = 'DUMMY';
- common.expectsError(
+ assert.throws(
() => dnsPromises.resolve('example.org', rrtype),
{
code: 'ERR_INVALID_OPT_VALUE',
- type: TypeError,
+ name: 'TypeError',
message: `The value "${rrtype}" is invalid for option "rrtype"`
}
);
@@ -20,11 +20,11 @@ const dnsPromises = require('dns').promises;
// Error when rrtype is a number.
{
const rrtype = 0;
- common.expectsError(
+ assert.throws(
() => dnsPromises.resolve('example.org', rrtype),
{
code: 'ERR_INVALID_ARG_TYPE',
- type: TypeError,
+ name: 'TypeError',
message: 'The "rrtype" argument must be of type string. ' +
`Received type ${typeof rrtype} (${rrtype})`
}
diff --git a/test/js-native-api/test_error/test.js b/test/js-native-api/test_error/test.js
index e39038e805..2dc6904c75 100644
--- a/test/js-native-api/test_error/test.js
+++ b/test/js-native-api/test_error/test.js
@@ -69,21 +69,21 @@ assert.throws(() => {
}
));
-common.expectsError(
+assert.throws(
() => test_error.throwErrorCode(),
{
code: 'ERR_TEST_CODE',
message: 'Error [error]'
});
-common.expectsError(
+assert.throws(
() => test_error.throwRangeErrorCode(),
{
code: 'ERR_TEST_CODE',
message: 'RangeError [range error]'
});
-common.expectsError(
+assert.throws(
() => test_error.throwTypeErrorCode(),
{
code: 'ERR_TEST_CODE',
diff --git a/test/js-native-api/test_general/test.js b/test/js-native-api/test_general/test.js
index 09c0300f85..9b847f4f33 100644
--- a/test/js-native-api/test_general/test.js
+++ b/test/js-native-api/test_general/test.js
@@ -67,8 +67,8 @@ assert.strictEqual(derefItemWasCalled, true,
// Assert that wrapping twice fails.
const x = {};
test_general.wrap(x);
-common.expectsError(() => test_general.wrap(x),
- { type: Error, message: 'Invalid argument' });
+assert.throws(() => test_general.wrap(x),
+ { name: 'Error', message: 'Invalid argument' });
// Ensure that wrapping, removing the wrap, and then wrapping again works.
const y = {};
diff --git a/test/js-native-api/test_general/testFinalizer.js b/test/js-native-api/test_general/testFinalizer.js
index b440ed5e50..d72a4a44a3 100644
--- a/test/js-native-api/test_general/testFinalizer.js
+++ b/test/js-native-api/test_general/testFinalizer.js
@@ -13,12 +13,12 @@ test_general.addFinalizerOnly(finalized, callback);
test_general.addFinalizerOnly(finalized, callback);
// Ensure attached items cannot be retrieved.
-common.expectsError(() => test_general.unwrap(finalized),
- { type: Error, message: 'Invalid argument' });
+assert.throws(() => test_general.unwrap(finalized),
+ { name: 'Error', message: 'Invalid argument' });
// Ensure attached items cannot be removed.
-common.expectsError(() => test_general.removeWrap(finalized),
- { type: Error, message: 'Invalid argument' });
+assert.throws(() => test_general.removeWrap(finalized),
+ { name: 'Error', message: 'Invalid argument' });
finalized = null;
global.gc();
diff --git a/test/parallel/test-assert.js b/test/parallel/test-assert.js
index 85eb1de5bf..db2838862b 100644
--- a/test/parallel/test-assert.js
+++ b/test/parallel/test-assert.js
@@ -409,11 +409,11 @@ assert.throws(
{
// Verify that throws() and doesNotThrow() throw on non-functions.
const testBlockTypeError = (method, fn) => {
- common.expectsError(
+ assert.throws(
() => method(fn),
{
code: 'ERR_INVALID_ARG_TYPE',
- type: TypeError,
+ name: 'TypeError',
message: 'The "fn" argument must be of type function.' +
common.invalidArgTypeHelper(fn)
}
@@ -542,7 +542,7 @@ a.throws(
// Test setting the limit to zero and that assert.strict works properly.
const tmpLimit = Error.stackTraceLimit;
Error.stackTraceLimit = 0;
- common.expectsError(
+ assert.throws(
() => {
assert.ok(
typeof 123 === 'string'
@@ -550,7 +550,7 @@ a.throws(
},
{
code: 'ERR_ASSERTION',
- type: assert.AssertionError,
+ constructor: assert.AssertionError,
message: 'The expression evaluated to a falsy value:\n\n ' +
"assert.ok(\n typeof 123 === 'string'\n )\n"
}
@@ -716,32 +716,32 @@ a.throws(
/* eslint-enable no-restricted-properties */
}
-common.expectsError(
+assert.throws(
() => assert.ok(null),
{
code: 'ERR_ASSERTION',
- type: assert.AssertionError,
+ constructor: assert.AssertionError,
generatedMessage: true,
message: 'The expression evaluated to a falsy value:\n\n ' +
'assert.ok(null)\n'
}
);
-common.expectsError(
+assert.throws(
() => assert(typeof 123n === 'string'),
{
code: 'ERR_ASSERTION',
- type: assert.AssertionError,
+ constructor: assert.AssertionError,
generatedMessage: true,
message: 'The expression evaluated to a falsy value:\n\n ' +
"assert(typeof 123n === 'string')\n"
}
);
-common.expectsError(
+assert.throws(
() => assert(false, Symbol('foo')),
{
code: 'ERR_ASSERTION',
- type: assert.AssertionError,
+ constructor: assert.AssertionError,
generatedMessage: false,
message: 'Symbol(foo)'
}
@@ -757,20 +757,20 @@ common.expectsError(
(Buffer.from('test') instanceof Error)
);
}
- common.expectsError(
+ assert.throws(
() => throwErr(),
{
code: 'ERR_ASSERTION',
- type: assert.AssertionError,
+ constructor: assert.AssertionError,
message: 'The expression evaluated to a falsy value:\n\n ' +
"assert(\n (Buffer.from('test') instanceof Error)\n )\n"
}
);
- common.expectsError(
+ assert.throws(
() => throwErr(),
{
code: 'ERR_ASSERTION',
- type: assert.AssertionError,
+ constructor: assert.AssertionError,
message: 'The expression evaluated to a falsy value:\n\n ' +
"assert(\n (Buffer.from('test') instanceof Error)\n )\n"
}
@@ -778,7 +778,7 @@ common.expectsError(
fs.close = tmp;
}
-common.expectsError(
+assert.throws(
() => {
a(
(() => 'string')()
@@ -790,7 +790,7 @@ common.expectsError(
},
{
code: 'ERR_ASSERTION',
- type: assert.AssertionError,
+ constructor: assert.AssertionError,
message: 'The expression evaluated to a falsy value:\n\n' +
' a(\n' +
' (() => \'string\')()\n' +
@@ -802,7 +802,7 @@ common.expectsError(
}
);
-common.expectsError(
+assert.throws(
() => {
a(
(() => 'string')()
@@ -814,7 +814,7 @@ common.expectsError(
},
{
code: 'ERR_ASSERTION',
- type: assert.AssertionError,
+ constructor: assert.AssertionError,
message: 'The expression evaluated to a falsy value:\n\n' +
' a(\n' +
' (() => \'string\')()\n' +
@@ -827,7 +827,7 @@ common.expectsError(
);
/* eslint-disable indent */
-common.expectsError(() => {
+assert.throws(() => {
a((
() => 'string')() ===
123 instanceof
@@ -835,7 +835,7 @@ Buffer
);
}, {
code: 'ERR_ASSERTION',
- type: assert.AssertionError,
+ constructor: assert.AssertionError,
message: 'The expression evaluated to a falsy value:\n\n' +
' a((\n' +
' () => \'string\')() ===\n' +
@@ -846,81 +846,81 @@ Buffer
);
/* eslint-enable indent */
-common.expectsError(
+assert.throws(
() => {
assert(true); assert(null, undefined);
},
{
code: 'ERR_ASSERTION',
- type: assert.AssertionError,
+ constructor: assert.AssertionError,
message: 'The expression evaluated to a falsy value:\n\n ' +
'assert(null, undefined)\n'
}
);
-common.expectsError(
+assert.throws(
() => {
assert
.ok(null, undefined);
},
{
code: 'ERR_ASSERTION',
- type: assert.AssertionError,
+ constructor: assert.AssertionError,
message: 'The expression evaluated to a falsy value:\n\n ' +
'ok(null, undefined)\n'
}
);
-common.expectsError(
+assert.throws(
// eslint-disable-next-line dot-notation, quotes
() => assert['ok']["apply"](null, [0]),
{
code: 'ERR_ASSERTION',
- type: assert.AssertionError,
+ constructor: assert.AssertionError,
message: 'The expression evaluated to a falsy value:\n\n ' +
'assert[\'ok\']["apply"](null, [0])\n'
}
);
-common.expectsError(
+assert.throws(
() => {
const wrapper = (fn, value) => fn(value);
wrapper(assert, false);
},
{
code: 'ERR_ASSERTION',
- type: assert.AssertionError,
+ constructor: assert.AssertionError,
message: 'The expression evaluated to a falsy value:\n\n fn(value)\n'
}
);
-common.expectsError(
+assert.throws(
() => assert.ok.call(null, 0),
{
code: 'ERR_ASSERTION',
- type: assert.AssertionError,
+ constructor: assert.AssertionError,
message: 'The expression evaluated to a falsy value:\n\n ' +
'assert.ok.call(null, 0)\n',
generatedMessage: true
}
);
-common.expectsError(
+assert.throws(
() => assert.ok.call(null, 0, 'test'),
{
code: 'ERR_ASSERTION',
- type: assert.AssertionError,
+ constructor: assert.AssertionError,
message: 'test',
generatedMessage: false
}
);
// Works in eval.
-common.expectsError(
+assert.throws(
() => new Function('assert', 'assert(1 === 2);')(assert),
{
code: 'ERR_ASSERTION',
- type: assert.AssertionError,
+ constructor: assert.AssertionError,
message: 'The expression evaluated to a falsy value:\n\n assert(1 === 2)\n'
}
);
@@ -932,11 +932,11 @@ assert.throws(
}
);
-common.expectsError(
+assert.throws(
() => assert.throws(() => {}, 'Error message', 'message'),
{
code: 'ERR_INVALID_ARG_TYPE',
- type: TypeError,
+ name: 'TypeError',
message: 'The "error" argument must be of type function or ' +
'an instance of Error, RegExp, or Object. Received type string ' +
"('Error message')"
@@ -1018,19 +1018,19 @@ common.expectsError(
}
);
- common.expectsError(
+ assert.throws(
() => assert.throws(() => { throw new Error(); }, { foo: 'bar' }, 'foobar'),
{
- type: assert.AssertionError,
+ constructor: assert.AssertionError,
code: 'ERR_ASSERTION',
message: 'foobar'
}
);
- common.expectsError(
+ assert.throws(
() => a.doesNotThrow(() => { throw new Error(); }, { foo: 'bar' }),
{
- type: TypeError,
+ name: 'TypeError',
code: 'ERR_INVALID_ARG_TYPE',
message: 'The "expected" argument must be of type function or an ' +
'instance of RegExp. Received an instance of Object'
diff --git a/test/parallel/test-async-hooks-asyncresource-constructor.js b/test/parallel/test-async-hooks-asyncresource-constructor.js
index ebd5a4cf64..8b504aa7a7 100644
--- a/test/parallel/test-async-hooks-asyncresource-constructor.js
+++ b/test/parallel/test-async-hooks-asyncresource-constructor.js
@@ -2,7 +2,8 @@
// This tests that AsyncResource throws an error if bad parameters are passed
-const common = require('../common');
+require('../common');
+const assert = require('assert');
const async_hooks = require('async_hooks');
const { AsyncResource } = async_hooks;
@@ -11,30 +12,30 @@ async_hooks.createHook({
init() {}
}).enable();
-common.expectsError(() => {
+assert.throws(() => {
return new AsyncResource();
}, {
code: 'ERR_INVALID_ARG_TYPE',
- type: TypeError,
+ name: 'TypeError',
});
-common.expectsError(() => {
+assert.throws(() => {
new AsyncResource('');
}, {
code: 'ERR_ASYNC_TYPE',
- type: TypeError,
+ name: 'TypeError',
});
-common.expectsError(() => {
+assert.throws(() => {
new AsyncResource('type', -4);
}, {
code: 'ERR_INVALID_ASYNC_ID',
- type: RangeError,
+ name: 'RangeError',
});
-common.expectsError(() => {
+assert.throws(() => {
new AsyncResource('type', Math.PI);
}, {
code: 'ERR_INVALID_ASYNC_ID',
- type: RangeError,
+ name: 'RangeError',
});
diff --git a/test/parallel/test-async-hooks-constructor.js b/test/parallel/test-async-hooks-constructor.js
index f2b4df6a9f..f6f5c45607 100644
--- a/test/parallel/test-async-hooks-constructor.js
+++ b/test/parallel/test-async-hooks-constructor.js
@@ -2,7 +2,8 @@
// This tests that AsyncHooks throws an error if bad parameters are passed.
-const common = require('../common');
+require('../common');
+const assert = require('assert');
const async_hooks = require('async_hooks');
const non_function = 10;
@@ -13,11 +14,11 @@ typeErrorForFunction('destroy');
typeErrorForFunction('promiseResolve');
function typeErrorForFunction(functionName) {
- common.expectsError(() => {
+ assert.throws(() => {
async_hooks.createHook({ [functionName]: non_function });
}, {
code: 'ERR_ASYNC_CALLBACK',
- type: TypeError,
+ name: 'TypeError',
message: `hook.${functionName} must be a function`
});
}
diff --git a/test/parallel/test-async-wrap-constructor.js b/test/parallel/test-async-wrap-constructor.js
index 6b17643371..8e96e9ce30 100644
--- a/test/parallel/test-async-wrap-constructor.js
+++ b/test/parallel/test-async-wrap-constructor.js
@@ -2,17 +2,18 @@
// This tests that using falsy values in createHook throws an error.
-const common = require('../common');
+require('../common');
+const assert = require('assert');
const async_hooks = require('async_hooks');
for (const badArg of [0, 1, false, true, null, 'hello']) {
const hookNames = ['init', 'before', 'after', 'destroy', 'promiseResolve'];
for (const field of hookNames) {
- common.expectsError(() => {
+ assert.throws(() => {
async_hooks.createHook({ [field]: badArg });
}, {
code: 'ERR_ASYNC_CALLBACK',
- type: TypeError,
+ name: 'TypeError',
});
}
}
diff --git a/test/parallel/test-buffer-alloc.js b/test/parallel/test-buffer-alloc.js
index 75bcb03d19..b54fd88cc2 100644
--- a/test/parallel/test-buffer-alloc.js
+++ b/test/parallel/test-buffer-alloc.js
@@ -81,20 +81,20 @@ Buffer(0);
const outOfRangeError = {
code: 'ERR_OUT_OF_RANGE',
- type: RangeError
+ name: 'RangeError'
};
// Try to write a 0-length string beyond the end of b
-common.expectsError(() => b.write('', 2048), outOfRangeError);
+assert.throws(() => b.write('', 2048), outOfRangeError);
// Throw when writing to negative offset
-common.expectsError(() => b.write('a', -1), outOfRangeError);
+assert.throws(() => b.write('a', -1), outOfRangeError);
// Throw when writing past bounds from the pool
-common.expectsError(() => b.write('a', 2048), outOfRangeError);
+assert.throws(() => b.write('a', 2048), outOfRangeError);
// Throw when writing to negative offset
-common.expectsError(() => b.write('a', -1), outOfRangeError);
+assert.throws(() => b.write('a', -1), outOfRangeError);
// Try to copy 0 bytes worth of data into an empty buffer
b.copy(Buffer.alloc(0), 0, 0, 0);
@@ -793,31 +793,31 @@ assert.strictEqual(Buffer.from('13.37').length, 5);
Buffer.from(Buffer.allocUnsafe(0), 0, 0);
// issue GH-5587
-common.expectsError(
+assert.throws(
() => Buffer.alloc(8).writeFloatLE(0, 5),
outOfRangeError
);
-common.expectsError(
+assert.throws(
() => Buffer.alloc(16).writeDoubleLE(0, 9),
outOfRangeError
);
// Attempt to overflow buffers, similar to previous bug in array buffers
-common.expectsError(
+assert.throws(
() => Buffer.allocUnsafe(8).writeFloatLE(0.0, 0xffffffff),
outOfRangeError
);
-common.expectsError(
+assert.throws(
() => Buffer.allocUnsafe(8).writeFloatLE(0.0, 0xffffffff),
outOfRangeError
);
// Ensure negative values can't get past offset
-common.expectsError(
+assert.throws(
() => Buffer.allocUnsafe(8).writeFloatLE(0.0, -1),
outOfRangeError
);
-common.expectsError(
+assert.throws(
() => Buffer.allocUnsafe(8).writeFloatLE(0.0, -1),
outOfRangeError
);
@@ -917,11 +917,11 @@ common.expectsError(
// Regression test for https://github.com/nodejs/node-v0.x-archive/issues/5482:
// should throw but not assert in C++ land.
-common.expectsError(
+assert.throws(
() => Buffer.from('', 'buffer'),
{
code: 'ERR_UNKNOWN_ENCODING',
- type: TypeError,
+ name: 'TypeError',
message: 'Unknown encoding: buffer'
}
);
@@ -962,11 +962,11 @@ Buffer.poolSize = 0;
assert(Buffer.allocUnsafe(1).parent instanceof ArrayBuffer);
Buffer.poolSize = ps;
-common.expectsError(
+assert.throws(
() => Buffer.allocUnsafe(10).copy(),
{
code: 'ERR_INVALID_ARG_TYPE',
- type: TypeError,
+ name: 'TypeError',
message: 'The "target" argument must be an instance of Buffer or ' +
'Uint8Array. Received undefined'
});
@@ -1007,14 +1007,14 @@ assert.strictEqual(SlowBuffer.prototype.offset, undefined);
{
const errMsg = common.expectsError({
code: 'ERR_BUFFER_OUT_OF_BOUNDS',
- type: RangeError,
+ name: 'RangeError',
message: '"offset" is outside of buffer bounds'
});
assert.throws(() => Buffer.from(new ArrayBuffer(0), -1 >>> 0), errMsg);
}
// ParseArrayIndex() should reject values that don't fit in a 32 bits size_t.
-common.expectsError(() => {
+assert.throws(() => {
const a = Buffer.alloc(1);
const b = Buffer.alloc(1);
a.copy(b, 0, 0x100000000, 0x100000001);
@@ -1047,30 +1047,30 @@ assert.strictEqual(Buffer.prototype.toLocaleString, Buffer.prototype.toString);
assert.strictEqual(buf.toLocaleString(), buf.toString());
}
-common.expectsError(() => {
+assert.throws(() => {
Buffer.alloc(0x1000, 'This is not correctly encoded', 'hex');
}, {
code: 'ERR_INVALID_ARG_VALUE',
- type: TypeError
+ name: 'TypeError'
});
-common.expectsError(() => {
+assert.throws(() => {
Buffer.alloc(0x1000, 'c', 'hex');
}, {
code: 'ERR_INVALID_ARG_VALUE',
- type: TypeError
+ name: 'TypeError'
});
-common.expectsError(() => {
+assert.throws(() => {
Buffer.alloc(1, Buffer.alloc(0));
}, {
code: 'ERR_INVALID_ARG_VALUE',
- type: TypeError
+ name: 'TypeError'
});
-common.expectsError(() => {
+assert.throws(() => {
Buffer.alloc(40, 'x', 20);
}, {
code: 'ERR_INVALID_ARG_TYPE',
- type: TypeError
+ name: 'TypeError'
});
diff --git a/test/parallel/test-buffer-bytelength.js b/test/parallel/test-buffer-bytelength.js
index 369e8cb191..b5264ba092 100644
--- a/test/parallel/test-buffer-bytelength.js
+++ b/test/parallel/test-buffer-bytelength.js
@@ -11,11 +11,11 @@ const vm = require('vm');
[{}, 'latin1'],
[]
].forEach((args) => {
- common.expectsError(
+ assert.throws(
() => Buffer.byteLength(...args),
{
code: 'ERR_INVALID_ARG_TYPE',
- type: TypeError,
+ name: 'TypeError',
message: 'The "string" argument must be of type string or an instance ' +
'of Buffer or ArrayBuffer.' +
common.invalidArgTypeHelper(args[0])
diff --git a/test/parallel/test-buffer-compare-offset.js b/test/parallel/test-buffer-compare-offset.js
index df3b429a03..9f6f733547 100644
--- a/test/parallel/test-buffer-compare-offset.js
+++ b/test/parallel/test-buffer-compare-offset.js
@@ -1,6 +1,6 @@
'use strict';
-const common = require('../common');
+require('../common');
const assert = require('assert');
const a = Buffer.from([1, 2, 3, 4, 5, 6, 7, 8, 9, 0]);
@@ -86,9 +86,9 @@ assert.throws(() => a.compare(b, -1), oor);
assert.throws(() => a.compare(b, 0, Infinity), oor);
assert.throws(() => a.compare(b, 0, 1, -1), oor);
assert.throws(() => a.compare(b, -Infinity, Infinity), oor);
-common.expectsError(() => a.compare(), {
+assert.throws(() => a.compare(), {
code: 'ERR_INVALID_ARG_TYPE',
- type: TypeError,
+ name: 'TypeError',
message: 'The "target" argument must be an instance of ' +
'Buffer or Uint8Array. Received undefined'
});
diff --git a/test/parallel/test-buffer-compare.js b/test/parallel/test-buffer-compare.js
index b790e461bc..4a1e1acccb 100644
--- a/test/parallel/test-buffer-compare.js
+++ b/test/parallel/test-buffer-compare.js
@@ -1,6 +1,6 @@
'use strict';
-const common = require('../common');
+require('../common');
const assert = require('assert');
const b = Buffer.alloc(1, 'a');
@@ -39,9 +39,9 @@ assert.throws(() => Buffer.compare('abc', Buffer.alloc(1)), {
"Received type string ('abc')"
});
-common.expectsError(() => Buffer.alloc(1).compare('abc'), {
+assert.throws(() => Buffer.alloc(1).compare('abc'), {
code: 'ERR_INVALID_ARG_TYPE',
- type: TypeError,
+ name: 'TypeError',
message: 'The "target" argument must be an instance of ' +
"Buffer or Uint8Array. Received type string ('abc')"
});
diff --git a/test/parallel/test-buffer-copy.js b/test/parallel/test-buffer-copy.js
index f668c26165..d6f7346144 100644
--- a/test/parallel/test-buffer-copy.js
+++ b/test/parallel/test-buffer-copy.js
@@ -1,6 +1,6 @@
'use strict';
-const common = require('../common');
+require('../common');
const assert = require('assert');
const b = Buffer.allocUnsafe(1024);
@@ -108,11 +108,11 @@ bb.fill('hello crazy world');
b.copy(c, 0, 100, 10);
// Copy throws at negative sourceStart
-common.expectsError(
+assert.throws(
() => Buffer.allocUnsafe(5).copy(Buffer.allocUnsafe(5), 0, -1),
{
code: 'ERR_OUT_OF_RANGE',
- type: RangeError,
+ name: 'RangeError',
message: 'The value of "sourceStart" is out of range. ' +
'It must be >= 0. Received -1'
}
@@ -129,11 +129,11 @@ common.expectsError(
}
// Throw with negative sourceEnd
-common.expectsError(
+assert.throws(
() => b.copy(c, 0, 0, -1),
{
code: 'ERR_OUT_OF_RANGE',
- type: RangeError,
+ name: 'RangeError',
message: 'The value of "sourceEnd" is out of range. ' +
'It must be >= 0. Received -1'
}
diff --git a/test/parallel/test-buffer-equals.js b/test/parallel/test-buffer-equals.js
index 055fe56de2..b6993246f8 100644
--- a/test/parallel/test-buffer-equals.js
+++ b/test/parallel/test-buffer-equals.js
@@ -1,6 +1,6 @@
'use strict';
-const common = require('../common');
+require('../common');
const assert = require('assert');
const b = Buffer.from('abcdf');
@@ -14,11 +14,11 @@ assert.ok(!d.equals(e));
assert.ok(d.equals(d));
assert.ok(d.equals(new Uint8Array([0x61, 0x62, 0x63, 0x64, 0x65])));
-common.expectsError(
+assert.throws(
() => Buffer.alloc(1).equals('abc'),
{
code: 'ERR_INVALID_ARG_TYPE',
- type: TypeError,
+ name: 'TypeError',
message: 'The "otherBuffer" argument must be an instance of ' +
"Buffer or Uint8Array. Received type string ('abc')"
}
diff --git a/test/parallel/test-buffer-fill.js b/test/parallel/test-buffer-fill.js
index aa5c701b54..4d50bfdd38 100644
--- a/test/parallel/test-buffer-fill.js
+++ b/test/parallel/test-buffer-fill.js
@@ -112,22 +112,22 @@ testBufs('c8a26161', 8, 1, 'hex');
testBufs('61c8b462c8b563c8b6', 4, 1, 'hex');
testBufs('61c8b462c8b563c8b6', 12, 1, 'hex');
-common.expectsError(() => {
+assert.throws(() => {
const buf = Buffer.allocUnsafe(SIZE);
buf.fill('yKJh', 'hex');
}, {
code: 'ERR_INVALID_ARG_VALUE',
- type: TypeError
+ name: 'TypeError'
});
-common.expectsError(() => {
+assert.throws(() => {
const buf = Buffer.allocUnsafe(SIZE);
buf.fill('\u0222', 'hex');
}, {
code: 'ERR_INVALID_ARG_VALUE',
- type: TypeError
+ name: 'TypeError'
});
// BASE64
@@ -172,17 +172,17 @@ deepStrictEqualValues(genBuffer(4, [hexBufFill, 1, 1]), [0, 0, 0, 0]);
['', 0, buf1.length + 1],
['', 1, -1],
].forEach((args) => {
- common.expectsError(
+ assert.throws(
() => buf1.fill(...args),
{ code: 'ERR_OUT_OF_RANGE' }
);
});
-common.expectsError(
+assert.throws(
() => buf1.fill('a', 0, buf1.length, 'node rocks!'),
{
code: 'ERR_UNKNOWN_ENCODING',
- type: TypeError,
+ name: 'TypeError',
message: 'Unknown encoding: node rocks!'
}
);
@@ -191,7 +191,7 @@ common.expectsError(
['a', 0, 0, NaN],
['a', 0, 0, false]
].forEach((args) => {
- common.expectsError(
+ assert.throws(
() => buf1.fill(...args),
{
code: 'ERR_INVALID_ARG_TYPE',
@@ -201,11 +201,11 @@ common.expectsError(
);
});
-common.expectsError(
+assert.throws(
() => buf1.fill('a', 0, 0, 'foo'),
{
code: 'ERR_UNKNOWN_ENCODING',
- type: TypeError,
+ name: 'TypeError',
message: 'Unknown encoding: foo'
}
);
@@ -275,10 +275,10 @@ function testBufs(string, offset, length, encoding) {
}
// Make sure these throw.
-common.expectsError(
+assert.throws(
() => Buffer.allocUnsafe(8).fill('a', -1),
{ code: 'ERR_OUT_OF_RANGE' });
-common.expectsError(
+assert.throws(
() => Buffer.allocUnsafe(8).fill('a', 0, 9),
{ code: 'ERR_OUT_OF_RANGE' });
@@ -333,7 +333,7 @@ assert.strictEqual(
// Make sure "end" is properly checked, even if it's magically mangled using
// Symbol.toPrimitive.
{
- common.expectsError(() => {
+ assert.throws(() => {
const end = {
[Symbol.toPrimitive]() {
return 1;
@@ -353,7 +353,7 @@ assert.strictEqual(
internalBinding('buffer').fill(Buffer.alloc(1), 1, 1, -2, 1), -2);
// Test that bypassing 'length' won't cause an abort.
-common.expectsError(() => {
+assert.throws(() => {
const buf = Buffer.from('w00t');
Object.defineProperty(buf, 'length', {
value: 1337,
@@ -362,7 +362,7 @@ common.expectsError(() => {
buf.fill('');
}, {
code: 'ERR_BUFFER_OUT_OF_BOUNDS',
- type: RangeError,
+ name: 'RangeError',
message: 'Attempt to access memory outside buffer bounds'
});
@@ -401,11 +401,11 @@ assert.strictEqual(
Buffer.allocUnsafeSlow(16).fill('Љ', 'utf8').toString('utf8'),
'Љ'.repeat(8));
-common.expectsError(() => {
+assert.throws(() => {
const buf = Buffer.from('a'.repeat(1000));
buf.fill('This is not correctly encoded', 'hex');
}, {
code: 'ERR_INVALID_ARG_VALUE',
- type: TypeError
+ name: 'TypeError'
});
diff --git a/test/parallel/test-buffer-includes.js b/test/parallel/test-buffer-includes.js
index 8e5ec8e926..5d74303fad 100644
--- a/test/parallel/test-buffer-includes.js
+++ b/test/parallel/test-buffer-includes.js
@@ -277,11 +277,11 @@ for (let lengthIndex = 0; lengthIndex < lengths.length; lengthIndex++) {
{},
[]
].forEach((val) => {
- common.expectsError(
+ assert.throws(
() => b.includes(val),
{
code: 'ERR_INVALID_ARG_TYPE',
- type: TypeError,
+ name: 'TypeError',
message: 'The "value" argument must be one of type number or string ' +
'or an instance of Buffer or Uint8Array.' +
common.invalidArgTypeHelper(val)
diff --git a/test/parallel/test-buffer-indexof.js b/test/parallel/test-buffer-indexof.js
index 4eb42ca5bf..d789c9b46c 100644
--- a/test/parallel/test-buffer-indexof.js
+++ b/test/parallel/test-buffer-indexof.js
@@ -352,11 +352,11 @@ assert.strictEqual(Buffer.from('aaaaa').indexOf('b', 'ucs2'), -1);
{},
[]
].forEach((val) => {
- common.expectsError(
+ assert.throws(
() => b.indexOf(val),
{
code: 'ERR_INVALID_ARG_TYPE',
- type: TypeError,
+ name: 'TypeError',
message: 'The "value" argument must be one of type number or string ' +
'or an instance of Buffer or Uint8Array.' +
common.invalidArgTypeHelper(val)
diff --git a/test/parallel/test-buffer-new.js b/test/parallel/test-buffer-new.js
index 45806359ad..0f8fa485f2 100644
--- a/test/parallel/test-buffer-new.js
+++ b/test/parallel/test-buffer-new.js
@@ -1,10 +1,11 @@
'use strict';
-const common = require('../common');
+require('../common');
+const assert = require('assert');
-common.expectsError(() => new Buffer(42, 'utf8'), {
+assert.throws(() => new Buffer(42, 'utf8'), {
code: 'ERR_INVALID_ARG_TYPE',
- type: TypeError,
+ name: 'TypeError',
message: 'The "string" argument must be of type string. Received type ' +
'number (42)'
});
diff --git a/test/parallel/test-buffer-no-negative-allocation.js b/test/parallel/test-buffer-no-negative-allocation.js
index d48d02cb9b..6829d6eca1 100644
--- a/test/parallel/test-buffer-no-negative-allocation.js
+++ b/test/parallel/test-buffer-no-negative-allocation.js
@@ -1,14 +1,14 @@
'use strict';
-const common = require('../common');
+require('../common');
const assert = require('assert');
const { SlowBuffer } = require('buffer');
-const msg = common.expectsError({
+const msg = {
code: 'ERR_INVALID_OPT_VALUE',
- type: RangeError,
+ name: 'RangeError',
message: /^The value "[^"]*" is invalid for option "size"$/
-}, 20);
+};
// Test that negative Buffer length inputs throw errors.
diff --git a/test/parallel/test-buffer-over-max-length.js b/test/parallel/test-buffer-over-max-length.js
index b1267b19ff..ac1f7cda8c 100644
--- a/test/parallel/test-buffer-over-max-length.js
+++ b/test/parallel/test-buffer-over-max-length.js
@@ -1,16 +1,16 @@
'use strict';
-const common = require('../common');
+require('../common');
const assert = require('assert');
const buffer = require('buffer');
const SlowBuffer = buffer.SlowBuffer;
const kMaxLength = buffer.kMaxLength;
-const bufferMaxSizeMsg = common.expectsError({
+const bufferMaxSizeMsg = {
code: 'ERR_INVALID_OPT_VALUE',
- type: RangeError,
+ name: 'RangeError',
message: /^The value "[^"]*" is invalid for option "size"$/
-}, 12);
+};
assert.throws(() => Buffer((-1 >>> 0) + 1), bufferMaxSizeMsg);
assert.throws(() => SlowBuffer((-1 >>> 0) + 1), bufferMaxSizeMsg);
diff --git a/test/parallel/test-buffer-read.js b/test/parallel/test-buffer-read.js
index 9718887e0f..8c266163f4 100644
--- a/test/parallel/test-buffer-read.js
+++ b/test/parallel/test-buffer-read.js
@@ -1,5 +1,5 @@
'use strict';
-const common = require('../common');
+require('../common');
const assert = require('assert');
// Testing basic buffer read functions
@@ -7,7 +7,7 @@ const buf = Buffer.from([0xa4, 0xfd, 0x48, 0xea, 0xcf, 0xff, 0xd9, 0x01, 0xde]);
function read(buff, funx, args, expected) {
assert.strictEqual(buff[funx](...args), expected);
- common.expectsError(
+ assert.throws(
() => buff[funx](-1, args[1]),
{ code: 'ERR_OUT_OF_RANGE' }
);
diff --git a/test/parallel/test-buffer-tostring-range.js b/test/parallel/test-buffer-tostring-range.js
index 9cda0d8335..f4adf64c8d 100644
--- a/test/parallel/test-buffer-tostring-range.js
+++ b/test/parallel/test-buffer-tostring-range.js
@@ -1,6 +1,6 @@
'use strict';
-const common = require('../common');
+require('../common');
const assert = require('assert');
const rangeBuffer = Buffer.from('abc');
@@ -84,17 +84,17 @@ assert.strictEqual(rangeBuffer.toString({ toString: function() {
} }), 'abc');
// Try toString() with 0 and null as the encoding
-common.expectsError(() => {
+assert.throws(() => {
rangeBuffer.toString(0, 1, 2);
}, {
code: 'ERR_UNKNOWN_ENCODING',
- type: TypeError,
+ name: 'TypeError',
message: 'Unknown encoding: 0'
});
-common.expectsError(() => {
+assert.throws(() => {
rangeBuffer.toString(null, 1, 2);
}, {
code: 'ERR_UNKNOWN_ENCODING',
- type: TypeError,
+ name: 'TypeError',
message: 'Unknown encoding: null'
});
diff --git a/test/parallel/test-buffer-tostring-rangeerror.js b/test/parallel/test-buffer-tostring-rangeerror.js
index ccfb40bee7..30528a2343 100644
--- a/test/parallel/test-buffer-tostring-rangeerror.js
+++ b/test/parallel/test-buffer-tostring-rangeerror.js
@@ -1,5 +1,5 @@
'use strict';
-const common = require('../common');
+require('../common');
// This test ensures that Node.js throws a RangeError when trying to convert a
// gigantic buffer into a string.
@@ -9,11 +9,11 @@ const assert = require('assert');
const SlowBuffer = require('buffer').SlowBuffer;
const len = 1422561062959;
-const message = common.expectsError({
+const message = {
code: 'ERR_INVALID_OPT_VALUE',
- type: RangeError,
+ name: 'RangeError',
message: /^The value "[^"]*" is invalid for option "size"$/
-}, 5);
+};
assert.throws(() => Buffer(len).toString('utf8'), message);
assert.throws(() => SlowBuffer(len).toString('utf8'), message);
assert.throws(() => Buffer.alloc(len).toString('utf8'), message);
diff --git a/test/parallel/test-buffer-tostring.js b/test/parallel/test-buffer-tostring.js
index 7ea7ce8539..4219649fa3 100644
--- a/test/parallel/test-buffer-tostring.js
+++ b/test/parallel/test-buffer-tostring.js
@@ -29,7 +29,7 @@ for (let i = 1; i < 10; i++) {
const encoding = String(i).repeat(i);
const error = common.expectsError({
code: 'ERR_UNKNOWN_ENCODING',
- type: TypeError,
+ name: 'TypeError',
message: `Unknown encoding: ${encoding}`
});
assert.ok(!Buffer.isEncoding(encoding));
diff --git a/test/parallel/test-buffer-write.js b/test/parallel/test-buffer-write.js
index e99cdb358a..1f080add08 100644
--- a/test/parallel/test-buffer-write.js
+++ b/test/parallel/test-buffer-write.js
@@ -66,7 +66,7 @@ for (let i = 1; i < 10; i++) {
const encoding = String(i).repeat(i);
const error = common.expectsError({
code: 'ERR_UNKNOWN_ENCODING',
- type: TypeError,
+ name: 'TypeError',
message: `Unknown encoding: ${encoding}`
});
diff --git a/test/parallel/test-buffer-writeint.js b/test/parallel/test-buffer-writeint.js
index 0e812cc888..4799fb33d7 100644
--- a/test/parallel/test-buffer-writeint.js
+++ b/test/parallel/test-buffer-writeint.js
@@ -2,14 +2,14 @@
// Tests to verify signed integers are correctly written
-const common = require('../common');
+require('../common');
const assert = require('assert');
-const errorOutOfBounds = common.expectsError({
+const errorOutOfBounds = {
code: 'ERR_OUT_OF_RANGE',
- type: RangeError,
+ name: 'RangeError',
message: new RegExp('^The value of "value" is out of range\\. ' +
'It must be >= -\\d+ and <= \\d+\\. Received .+$')
-}, 10);
+};
// Test 8 bit
{
diff --git a/test/parallel/test-c-ares.js b/test/parallel/test-c-ares.js
index 3b579bb790..110d28ecf8 100644
--- a/test/parallel/test-c-ares.js
+++ b/test/parallel/test-c-ares.js
@@ -70,16 +70,16 @@ dns.lookup('::1', common.mustCall((error, result, addressType) => {
].forEach((val) => {
const err = {
code: 'ERR_INVALID_OPT_VALUE',
- type: TypeError,
+ name: 'TypeError',
message: `The value "${val}" is invalid for option "rrtype"`
};
- common.expectsError(
+ assert.throws(
() => dns.resolve('www.google.com', val),
err
);
- common.expectsError(() => dnsPromises.resolve('www.google.com', val), err);
+ assert.throws(() => dnsPromises.resolve('www.google.com', val), err);
});
// Windows doesn't usually have an entry for localhost 127.0.0.1 in
diff --git a/test/parallel/test-child-process-advanced-serialization.js b/test/parallel/test-child-process-advanced-serialization.js
index 0424f14a06..0303fc719d 100644
--- a/test/parallel/test-child-process-advanced-serialization.js
+++ b/test/parallel/test-child-process-advanced-serialization.js
@@ -6,7 +6,7 @@ const { once } = require('events');
if (process.argv[2] !== 'child') {
for (const value of [null, 42, Infinity, 'foo']) {
- common.expectsError(() => {
+ assert.throws(() => {
child_process.spawn(process.execPath, [], { serialization: value });
}, {
code: 'ERR_INVALID_OPT_VALUE',
diff --git a/test/parallel/test-child-process-constructor.js b/test/parallel/test-child-process-constructor.js
index 9c5b09171c..0bd8dd85b0 100644
--- a/test/parallel/test-child-process-constructor.js
+++ b/test/parallel/test-child-process-constructor.js
@@ -10,11 +10,11 @@ assert.strictEqual(typeof ChildProcess, 'function');
const child = new ChildProcess();
[undefined, null, 'foo', 0, 1, NaN, true, false].forEach((options) => {
- common.expectsError(() => {
+ assert.throws(() => {
child.spawn(options);
}, {
code: 'ERR_INVALID_ARG_TYPE',
- type: TypeError,
+ name: 'TypeError',
message: 'The "options" argument must be of type object.' +
`${common.invalidArgTypeHelper(options)}`
});
@@ -26,11 +26,11 @@ assert.strictEqual(typeof ChildProcess, 'function');
const child = new ChildProcess();
[undefined, null, 0, 1, NaN, true, false, {}].forEach((file) => {
- common.expectsError(() => {
+ assert.throws(() => {
child.spawn({ file });
}, {
code: 'ERR_INVALID_ARG_TYPE',
- type: TypeError,
+ name: 'TypeError',
message: 'The "options.file" property must be of type string.' +
`${common.invalidArgTypeHelper(file)}`
});
@@ -42,11 +42,11 @@ assert.strictEqual(typeof ChildProcess, 'function');
const child = new ChildProcess();
[null, 0, 1, NaN, true, false, {}, 'foo'].forEach((envPairs) => {
- common.expectsError(() => {
+ assert.throws(() => {
child.spawn({ envPairs, stdio: ['ignore', 'ignore', 'ignore', 'ipc'] });
}, {
code: 'ERR_INVALID_ARG_TYPE',
- type: TypeError,
+ name: 'TypeError',
message: 'The "options.envPairs" property must be an instance of Array.' +
common.invalidArgTypeHelper(envPairs)
});
@@ -58,11 +58,11 @@ assert.strictEqual(typeof ChildProcess, 'function');
const child = new ChildProcess();
[null, 0, 1, NaN, true, false, {}, 'foo'].forEach((args) => {
- common.expectsError(() => {
+ assert.throws(() => {
child.spawn({ file: 'foo', args });
}, {
code: 'ERR_INVALID_ARG_TYPE',
- type: TypeError,
+ name: 'TypeError',
message: 'The "options.args" property must be an instance of Array.' +
common.invalidArgTypeHelper(args)
});
@@ -82,9 +82,9 @@ assert.strictEqual(child.hasOwnProperty('pid'), true);
assert(Number.isInteger(child.pid));
// Try killing with invalid signal
-common.expectsError(
+assert.throws(
() => { child.kill('foo'); },
- { code: 'ERR_UNKNOWN_SIGNAL', type: TypeError }
+ { code: 'ERR_UNKNOWN_SIGNAL', name: 'TypeError' }
);
assert.strictEqual(child.kill(), true);
diff --git a/test/parallel/test-child-process-fork-args.js b/test/parallel/test-child-process-fork-args.js
index f2f5689d64..02a8db5fa6 100644
--- a/test/parallel/test-child-process-fork-args.js
+++ b/test/parallel/test-child-process-fork-args.js
@@ -22,9 +22,9 @@ const expectedEnv = { foo: 'bar' };
Symbol('t')
];
invalidModulePath.forEach((modulePath) => {
- common.expectsError(() => fork(modulePath), {
+ assert.throws(() => fork(modulePath), {
code: 'ERR_INVALID_ARG_TYPE',
- type: TypeError,
+ name: 'TypeError',
message: /^The "modulePath" argument must be of type string/
});
});
@@ -49,13 +49,13 @@ const expectedEnv = { foo: 'bar' };
Symbol('t')
];
invalidSecondArgs.forEach((arg) => {
- common.expectsError(
+ assert.throws(
() => {
fork(fixtures.path('child-process-echo-options.js'), arg);
},
{
code: 'ERR_INVALID_ARG_VALUE',
- type: TypeError
+ name: 'TypeError'
}
);
});
@@ -92,13 +92,13 @@ const expectedEnv = { foo: 'bar' };
Symbol('t')
];
invalidThirdArgs.forEach((arg) => {
- common.expectsError(
+ assert.throws(
() => {
fork(fixtures.path('child-process-echo-options.js'), [], arg);
},
{
code: 'ERR_INVALID_ARG_VALUE',
- type: TypeError
+ name: 'TypeError'
}
);
});
diff --git a/test/parallel/test-child-process-fork-stdio-string-variant.js b/test/parallel/test-child-process-fork-stdio-string-variant.js
index 2bfcfc59e6..c3fc90f9b0 100644
--- a/test/parallel/test-child-process-fork-stdio-string-variant.js
+++ b/test/parallel/test-child-process-fork-stdio-string-variant.js
@@ -13,9 +13,9 @@ const childScript = fixtures.path('child-process-spawn-node');
const malFormedOpts = { stdio: '33' };
const payload = { hello: 'world' };
-common.expectsError(
+assert.throws(
() => fork(childScript, malFormedOpts),
- { code: 'ERR_INVALID_OPT_VALUE', type: TypeError });
+ { code: 'ERR_INVALID_OPT_VALUE', name: 'TypeError' });
function test(stringVariant) {
const child = fork(childScript, { stdio: stringVariant });
diff --git a/test/parallel/test-child-process-fork-stdio.js b/test/parallel/test-child-process-fork-stdio.js
index d8e7abfe28..e76ef27797 100644
--- a/test/parallel/test-child-process-fork-stdio.js
+++ b/test/parallel/test-child-process-fork-stdio.js
@@ -19,9 +19,9 @@ if (process.argv[2] === 'child') {
process.send(data);
});
} else {
- common.expectsError(
+ assert.throws(
() => cp.fork(__filename, { stdio: ['pipe', 'pipe', 'pipe', 'pipe'] }),
- { code: 'ERR_CHILD_PROCESS_IPC_REQUIRED', type: Error });
+ { code: 'ERR_CHILD_PROCESS_IPC_REQUIRED', name: 'Error' });
let ipc = '';
let stderr = '';
diff --git a/test/parallel/test-child-process-send-after-close.js b/test/parallel/test-child-process-send-after-close.js
index 4e26d12618..62128b7b1b 100644
--- a/test/parallel/test-child-process-send-after-close.js
+++ b/test/parallel/test-child-process-send-after-close.js
@@ -12,7 +12,7 @@ child.on('close', common.mustCall((code, signal) => {
assert.strictEqual(signal, null);
const testError = common.expectsError({
- type: Error,
+ name: 'Error',
message: 'Channel closed',
code: 'ERR_IPC_CHANNEL_CLOSED'
}, 2);
diff --git a/test/parallel/test-child-process-send-type-error.js b/test/parallel/test-child-process-send-type-error.js
index 9c3a502a49..65c620dd29 100644
--- a/test/parallel/test-child-process-send-type-error.js
+++ b/test/parallel/test-child-process-send-type-error.js
@@ -5,9 +5,9 @@ const assert = require('assert');
const cp = require('child_process');
function fail(proc, args) {
- common.expectsError(() => {
+ assert.throws(() => {
proc.send.apply(proc, args);
- }, { code: 'ERR_INVALID_ARG_TYPE', type: TypeError });
+ }, { code: 'ERR_INVALID_ARG_TYPE', name: 'TypeError' });
}
let target = process;
diff --git a/test/parallel/test-child-process-spawn-typeerror.js b/test/parallel/test-child-process-spawn-typeerror.js
index 738a6f36cf..25d1bafe45 100644
--- a/test/parallel/test-child-process-spawn-typeerror.js
+++ b/test/parallel/test-child-process-spawn-typeerror.js
@@ -29,11 +29,15 @@ const invalidcmd = 'hopefully_you_dont_have_this_on_your_machine';
const empty = fixtures.path('empty.js');
-const invalidArgValueError =
- common.expectsError({ code: 'ERR_INVALID_ARG_VALUE', type: TypeError }, 14);
-
-const invalidArgTypeError =
- common.expectsError({ code: 'ERR_INVALID_ARG_TYPE', type: TypeError }, 11);
+const invalidArgValueError = {
+ code: 'ERR_INVALID_ARG_VALUE',
+ name: 'TypeError'
+};
+
+const invalidArgTypeError = {
+ code: 'ERR_INVALID_ARG_TYPE',
+ name: 'TypeError'
+};
assert.throws(function() {
spawn(invalidcmd, 'this is not an array');
diff --git a/test/parallel/test-child-process-spawnsync-input.js b/test/parallel/test-child-process-spawnsync-input.js
index d1a602460e..4dce110316 100644
--- a/test/parallel/test-child-process-spawnsync-input.js
+++ b/test/parallel/test-child-process-spawnsync-input.js
@@ -76,9 +76,9 @@ let options = {
input: 1234
};
-common.expectsError(
+assert.throws(
() => spawnSync('cat', [], options),
- { code: 'ERR_INVALID_ARG_TYPE', type: TypeError });
+ { code: 'ERR_INVALID_ARG_TYPE', name: 'TypeError' });
options = {
input: 'hello world'
diff --git a/test/parallel/test-child-process-spawnsync-kill-signal.js b/test/parallel/test-child-process-spawnsync-kill-signal.js
index f2decf01b3..0c8f4a6d46 100644
--- a/test/parallel/test-child-process-spawnsync-kill-signal.js
+++ b/test/parallel/test-child-process-spawnsync-kill-signal.js
@@ -29,9 +29,9 @@ if (process.argv[2] === 'child') {
}
// Verify that an error is thrown for unknown signals.
- common.expectsError(() => {
+ assert.throws(() => {
spawn('SIG_NOT_A_REAL_SIGNAL');
- }, { code: 'ERR_UNKNOWN_SIGNAL', type: TypeError });
+ }, { code: 'ERR_UNKNOWN_SIGNAL', name: 'TypeError' });
// Verify that the default kill signal is SIGTERM.
{
diff --git a/test/parallel/test-child-process-spawnsync-validation-errors.js b/test/parallel/test-child-process-spawnsync-validation-errors.js
index 22116e27d1..a099ecfb63 100644
--- a/test/parallel/test-child-process-spawnsync-validation-errors.js
+++ b/test/parallel/test-child-process-spawnsync-validation-errors.js
@@ -6,12 +6,8 @@ const signals = require('os').constants.signals;
const rootUser = common.isWindows ? false :
common.isIBMi ? true : process.getuid() === 0;
-const invalidArgTypeError = common.expectsError(
- { code: 'ERR_INVALID_ARG_TYPE', type: TypeError },
- common.isWindows || rootUser ? 42 : 62);
-
-const invalidRangeError =
- common.expectsError({ code: 'ERR_OUT_OF_RANGE', type: RangeError }, 20);
+const invalidArgTypeError = { code: 'ERR_INVALID_ARG_TYPE', name: 'TypeError' };
+const invalidRangeError = { code: 'ERR_OUT_OF_RANGE', name: 'RangeError' };
function pass(option, value) {
// Run the command with the specified option. Since it's not a real command,
@@ -189,8 +185,7 @@ if (!common.isWindows) {
{
// Validate the killSignal option
- const unknownSignalErr =
- common.expectsError({ code: 'ERR_UNKNOWN_SIGNAL', type: TypeError }, 17);
+ const unknownSignalErr = { code: 'ERR_UNKNOWN_SIGNAL', name: 'TypeError' };
pass('killSignal', undefined);
pass('killSignal', null);
diff --git a/test/parallel/test-child-process-stdio.js b/test/parallel/test-child-process-stdio.js
index a5e5f95225..15c2770aa2 100644
--- a/test/parallel/test-child-process-stdio.js
+++ b/test/parallel/test-child-process-stdio.js
@@ -66,12 +66,12 @@ const { spawn } = require('child_process');
}
// Assert only one IPC pipe allowed.
-common.expectsError(
+assert.throws(
() => {
spawn(
...common.pwdCommand,
{ stdio: ['pipe', 'pipe', 'pipe', 'ipc', 'ipc'] }
);
},
- { code: 'ERR_IPC_ONE_PIPE', type: Error }
+ { code: 'ERR_IPC_ONE_PIPE', name: 'Error' }
);
diff --git a/test/parallel/test-child-process-validate-stdio.js b/test/parallel/test-child-process-validate-stdio.js
index 38d2f1c818..5b0259f19b 100644
--- a/test/parallel/test-child-process-validate-stdio.js
+++ b/test/parallel/test-child-process-validate-stdio.js
@@ -5,13 +5,13 @@ const common = require('../common');
const assert = require('assert');
const getValidStdio = require('internal/child_process').getValidStdio;
-const expectedError = { code: 'ERR_INVALID_OPT_VALUE', type: TypeError };
+const expectedError = { code: 'ERR_INVALID_OPT_VALUE', name: 'TypeError' };
// Should throw if string and not ignore, pipe, or inherit
-common.expectsError(() => getValidStdio('foo'), expectedError);
+assert.throws(() => getValidStdio('foo'), expectedError);
// Should throw if not a string or array
-common.expectsError(() => getValidStdio(600), expectedError);
+assert.throws(() => getValidStdio(600), expectedError);
// Should populate stdio with undefined if len < 3
{
@@ -25,22 +25,22 @@ common.expectsError(() => getValidStdio(600), expectedError);
// Should throw if stdio has ipc and sync is true
const stdio2 = ['ipc', 'ipc', 'ipc'];
-common.expectsError(() => getValidStdio(stdio2, true),
- { code: 'ERR_IPC_SYNC_FORK', type: Error }
+assert.throws(() => getValidStdio(stdio2, true),
+ { code: 'ERR_IPC_SYNC_FORK', name: 'Error' }
);
// Should throw if stdio is not a valid input
{
const stdio = ['foo'];
- common.expectsError(() => getValidStdio(stdio, false),
- { code: 'ERR_INVALID_SYNC_FORK_INPUT', type: TypeError }
+ assert.throws(() => getValidStdio(stdio, false),
+ { code: 'ERR_INVALID_SYNC_FORK_INPUT', name: 'TypeError' }
);
}
// Should throw if stdio is not a valid option
{
const stdio = [{ foo: 'bar' }];
- common.expectsError(() => getValidStdio(stdio), expectedError);
+ assert.throws(() => getValidStdio(stdio), expectedError);
}
if (common.isMainThread) {
diff --git a/test/parallel/test-common.js b/test/parallel/test-common.js
index 1521e153a9..3087cc035e 100644
--- a/test/parallel/test-common.js
+++ b/test/parallel/test-common.js
@@ -63,7 +63,7 @@ assert.throws(function() {
}, /^TypeError: Invalid minimum value: \/foo\/$/);
// assert.fail() tests
-common.expectsError(
+assert.throws(
() => { assert.fail('fhqwhgads'); },
{
code: 'ERR_ASSERTION',
diff --git a/test/parallel/test-console-instance.js b/test/parallel/test-console-instance.js
index 0356690a4d..19c4271d24 100644
--- a/test/parallel/test-console-instance.js
+++ b/test/parallel/test-console-instance.js
@@ -43,17 +43,17 @@ assert.ok(!({} instanceof Console));
// Make sure that the Console constructor throws
// when not given a writable stream instance.
-common.expectsError(
+assert.throws(
() => { new Console(); },
{
code: 'ERR_CONSOLE_WRITABLE_STREAM',
- type: TypeError,
+ name: 'TypeError',
message: /stdout/
}
);
// Console constructor should throw if stderr exists but is not writable.
-common.expectsError(
+assert.throws(
() => {
out.write = () => {};
err.write = undefined;
@@ -61,7 +61,7 @@ common.expectsError(
},
{
code: 'ERR_CONSOLE_WRITABLE_STREAM',
- type: TypeError,
+ name: 'TypeError',
message: /stderr/
}
);
diff --git a/test/parallel/test-console-no-swallow-stack-overflow.js b/test/parallel/test-console-no-swallow-stack-overflow.js
index f36ba4857e..c074342906 100644
--- a/test/parallel/test-console-no-swallow-stack-overflow.js
+++ b/test/parallel/test-console-no-swallow-stack-overflow.js
@@ -1,10 +1,11 @@
'use strict';
const common = require('../common');
+const assert = require('assert');
const { Console } = require('console');
const { Writable } = require('stream');
for (const method of ['dir', 'log', 'warn']) {
- common.expectsError(() => {
+ assert.throws(() => {
const out = new Writable({
write: common.mustCall(function write(...args) {
// Exceeds call stack.
diff --git a/test/parallel/test-console-table.js b/test/parallel/test-console-table.js
index 706cd20ad1..ac414918da 100644
--- a/test/parallel/test-console-table.js
+++ b/test/parallel/test-console-table.js
@@ -1,6 +1,6 @@
'use strict';
-const common = require('../common');
+require('../common');
const assert = require('assert');
const { Console } = require('console');
@@ -23,7 +23,7 @@ function test(data, only, expected) {
);
}
-common.expectsError(() => console.table([], false), {
+assert.throws(() => console.table([], false), {
code: 'ERR_INVALID_ARG_TYPE',
});
diff --git a/test/parallel/test-crypto-authenticated.js b/test/parallel/test-crypto-authenticated.js
index 8be7296c69..863907bafd 100644
--- a/test/parallel/test-crypto-authenticated.js
+++ b/test/parallel/test-crypto-authenticated.js
@@ -237,17 +237,17 @@ for (const test of TEST_CASES) {
// throw.
{
for (const length of [0, 1, 2, 6, 9, 10, 11, 17]) {
- common.expectsError(() => {
+ assert.throws(() => {
const decrypt = crypto.createDecipheriv('aes-128-gcm',
'FxLKsqdmv0E9xrQh',
'qkuZpJWCewa6Szih');
decrypt.setAuthTag(Buffer.from('1'.repeat(length)));
}, {
- type: Error,
+ name: 'Error',
message: `Invalid authentication tag length: ${length}`
});
- common.expectsError(() => {
+ assert.throws(() => {
crypto.createCipheriv('aes-256-gcm',
'FxLKsqdmv0E9xrQhp0b1ZgI0K7JFZJM8',
'qkuZpJWCewa6Szih',
@@ -255,11 +255,11 @@ for (const test of TEST_CASES) {
authTagLength: length
});
}, {
- type: Error,
+ name: 'Error',
message: `Invalid authentication tag length: ${length}`
});
- common.expectsError(() => {
+ assert.throws(() => {
crypto.createDecipheriv('aes-256-gcm',
'FxLKsqdmv0E9xrQhp0b1ZgI0K7JFZJM8',
'qkuZpJWCewa6Szih',
@@ -267,7 +267,7 @@ for (const test of TEST_CASES) {
authTagLength: length
});
}, {
- type: Error,
+ name: 'Error',
message: `Invalid authentication tag length: ${length}`
});
}
@@ -298,11 +298,11 @@ for (const test of TEST_CASES) {
authTagLength: 8
});
- common.expectsError(() => {
+ assert.throws(() => {
// This tag would normally be allowed.
decipher.setAuthTag(Buffer.from('1'.repeat(12)));
}, {
- type: Error,
+ name: 'Error',
message: 'Invalid authentication tag length: 12'
});
@@ -319,7 +319,7 @@ for (const test of TEST_CASES) {
// authentication tag length has been specified.
{
for (const authTagLength of [-1, true, false, NaN, 5.5]) {
- common.expectsError(() => {
+ assert.throws(() => {
crypto.createCipheriv('aes-256-ccm',
'FxLKsqdmv0E9xrQhp0b1ZgI0K7JFZJM8',
'qkuZpJWCewa6S',
@@ -327,13 +327,13 @@ for (const test of TEST_CASES) {
authTagLength
});
}, {
- type: TypeError,
+ name: 'TypeError',
code: 'ERR_INVALID_OPT_VALUE',
message: `The value "${authTagLength}" is invalid for option ` +
'"authTagLength"'
});
- common.expectsError(() => {
+ assert.throws(() => {
crypto.createDecipheriv('aes-256-ccm',
'FxLKsqdmv0E9xrQhp0b1ZgI0K7JFZJM8',
'qkuZpJWCewa6S',
@@ -341,26 +341,26 @@ for (const test of TEST_CASES) {
authTagLength
});
}, {
- type: TypeError,
+ name: 'TypeError',
code: 'ERR_INVALID_OPT_VALUE',
message: `The value "${authTagLength}" is invalid for option ` +
'"authTagLength"'
});
if (!common.hasFipsCrypto) {
- common.expectsError(() => {
+ assert.throws(() => {
crypto.createCipher('aes-256-ccm', 'bad password', { authTagLength });
}, {
- type: TypeError,
+ name: 'TypeError',
code: 'ERR_INVALID_OPT_VALUE',
message: `The value "${authTagLength}" is invalid for option ` +
'"authTagLength"'
});
- common.expectsError(() => {
+ assert.throws(() => {
crypto.createDecipher('aes-256-ccm', 'bad password', { authTagLength });
}, {
- type: TypeError,
+ name: 'TypeError',
code: 'ERR_INVALID_OPT_VALUE',
message: `The value "${authTagLength}" is invalid for option ` +
'"authTagLength"'
@@ -448,10 +448,10 @@ for (const test of TEST_CASES) {
});
for (const plaintextLength of [-1, true, false, NaN, 5.5]) {
- common.expectsError(() => {
+ assert.throws(() => {
cipher.setAAD(Buffer.from('0123456789', 'hex'), { plaintextLength });
}, {
- type: TypeError,
+ name: 'TypeError',
code: 'ERR_INVALID_OPT_VALUE',
message: `The value "${plaintextLength}" is invalid for option ` +
'"plaintextLength"'
diff --git a/test/parallel/test-crypto-binary-default.js b/test/parallel/test-crypto-binary-default.js
index 93ac0ef23e..a2fb2e8267 100644
--- a/test/parallel/test-crypto-binary-default.js
+++ b/test/parallel/test-crypto-binary-default.js
@@ -572,11 +572,11 @@ testCipher4(Buffer.from('0123456789abcd0123456789'), Buffer.from('12345678'));
// update() should only take buffers / strings
-common.expectsError(
+assert.throws(
() => crypto.createHash('sha1').update({ foo: 'bar' }),
{
code: 'ERR_INVALID_ARG_TYPE',
- type: TypeError
+ name: 'TypeError'
});
diff --git a/test/parallel/test-crypto-cipher-decipher.js b/test/parallel/test-crypto-cipher-decipher.js
index 45e4bd6ea7..4bb765d9ca 100644
--- a/test/parallel/test-crypto-cipher-decipher.js
+++ b/test/parallel/test-crypto-cipher-decipher.js
@@ -85,38 +85,38 @@ testCipher2(Buffer.from('0123456789abcdef'));
assert(instance instanceof Cipher, 'Cipher is expected to return a new ' +
'instance when called without `new`');
- common.expectsError(
+ assert.throws(
() => crypto.createCipher(null),
{
code: 'ERR_INVALID_ARG_TYPE',
- type: TypeError,
+ name: 'TypeError',
message: 'The "cipher" argument must be of type string. ' +
'Received null'
});
- common.expectsError(
+ assert.throws(
() => crypto.createCipher('aes-256-cbc', null),
{
code: 'ERR_INVALID_ARG_TYPE',
- type: TypeError,
+ name: 'TypeError',
message: 'The "password" argument must be of type string or an instance' +
' of Buffer, TypedArray, or DataView. Received null'
});
- common.expectsError(
+ assert.throws(
() => crypto.createCipher('aes-256-cbc', 'secret').update(null),
{
code: 'ERR_INVALID_ARG_TYPE',
- type: TypeError,
+ name: 'TypeError',
message: 'The "data" argument must be of type string or an instance' +
' of Buffer, TypedArray, or DataView. Received null'
});
- common.expectsError(
+ assert.throws(
() => crypto.createCipher('aes-256-cbc', 'secret').setAAD(null),
{
code: 'ERR_INVALID_ARG_TYPE',
- type: TypeError,
+ name: 'TypeError',
message: 'The "buffer" argument must be an instance' +
' of Buffer, TypedArray, or DataView. Received null'
});
@@ -128,29 +128,29 @@ testCipher2(Buffer.from('0123456789abcdef'));
assert(instance instanceof Decipher, 'Decipher is expected to return a new ' +
'instance when called without `new`');
- common.expectsError(
+ assert.throws(
() => crypto.createDecipher(null),
{
code: 'ERR_INVALID_ARG_TYPE',
- type: TypeError,
+ name: 'TypeError',
message: 'The "cipher" argument must be of type string. ' +
'Received null'
});
- common.expectsError(
+ assert.throws(
() => crypto.createDecipher('aes-256-cbc', 'secret').setAuthTag(null),
{
code: 'ERR_INVALID_ARG_TYPE',
- type: TypeError,
+ name: 'TypeError',
message: 'The "buffer" argument must be an instance of Buffer, ' +
'TypedArray, or DataView. Received null'
});
- common.expectsError(
+ assert.throws(
() => crypto.createDecipher('aes-256-cbc', null),
{
code: 'ERR_INVALID_ARG_TYPE',
- type: TypeError,
+ name: 'TypeError',
message: 'The "password" argument must be of type string or an ' +
'instance of Buffer, TypedArray, or DataView. Received null'
});
@@ -248,11 +248,11 @@ testCipher2(Buffer.from('0123456789abcdef'));
cipher.setAAD(aadbuf);
cipher.setAutoPadding();
- common.expectsError(
+ assert.throws(
() => cipher.getAuthTag(),
{
code: 'ERR_CRYPTO_INVALID_STATE',
- type: Error,
+ name: 'Error',
message: 'Invalid state for operation getAuthTag'
}
);
@@ -266,27 +266,27 @@ testCipher2(Buffer.from('0123456789abcdef'));
decipher.update(encrypted);
decipher.final();
- common.expectsError(
+ assert.throws(
() => decipher.setAAD(aadbuf),
{
code: 'ERR_CRYPTO_INVALID_STATE',
- type: Error,
+ name: 'Error',
message: 'Invalid state for operation setAAD'
});
- common.expectsError(
+ assert.throws(
() => decipher.setAuthTag(cipher.getAuthTag()),
{
code: 'ERR_CRYPTO_INVALID_STATE',
- type: Error,
+ name: 'Error',
message: 'Invalid state for operation setAuthTag'
});
- common.expectsError(
+ assert.throws(
() => decipher.setAutoPadding(),
{
code: 'ERR_CRYPTO_INVALID_STATE',
- type: Error,
+ name: 'Error',
message: 'Invalid state for operation setAutoPadding'
}
);
diff --git a/test/parallel/test-crypto-cipheriv-decipheriv.js b/test/parallel/test-crypto-cipheriv-decipheriv.js
index d4eda6bb1f..e2279a689c 100644
--- a/test/parallel/test-crypto-cipheriv-decipheriv.js
+++ b/test/parallel/test-crypto-cipheriv-decipheriv.js
@@ -87,29 +87,29 @@ function testCipher3(key, iv) {
assert(instance instanceof Cipheriv, 'Cipheriv is expected to return a new ' +
'instance when called without `new`');
- common.expectsError(
+ assert.throws(
() => crypto.createCipheriv(null),
{
code: 'ERR_INVALID_ARG_TYPE',
- type: TypeError,
+ name: 'TypeError',
message: 'The "cipher" argument must be of type string. ' +
'Received null'
});
- common.expectsError(
+ assert.throws(
() => crypto.createCipheriv('des-ede3-cbc', null),
{
code: 'ERR_INVALID_ARG_TYPE',
- type: TypeError,
+ name: 'TypeError',
message: 'The "key" argument must be of type string or an instance of ' +
'Buffer, TypedArray, DataView, or KeyObject. Received null'
});
- common.expectsError(
+ assert.throws(
() => crypto.createCipheriv('des-ede3-cbc', key, 10),
{
code: 'ERR_INVALID_ARG_TYPE',
- type: TypeError,
+ name: 'TypeError',
message: 'The "iv" argument must be of type string or an instance of ' +
'Buffer, TypedArray, or DataView. Received type number (10)'
});
@@ -124,29 +124,29 @@ function testCipher3(key, iv) {
assert(instance instanceof Decipheriv, 'Decipheriv expected to return a new' +
' instance when called without `new`');
- common.expectsError(
+ assert.throws(
() => crypto.createDecipheriv(null),
{
code: 'ERR_INVALID_ARG_TYPE',
- type: TypeError,
+ name: 'TypeError',
message: 'The "cipher" argument must be of type string. ' +
'Received null'
});
- common.expectsError(
+ assert.throws(
() => crypto.createDecipheriv('des-ede3-cbc', null),
{
code: 'ERR_INVALID_ARG_TYPE',
- type: TypeError,
+ name: 'TypeError',
message: 'The "key" argument must be of type string or an instance of ' +
'Buffer, TypedArray, DataView, or KeyObject. Received null'
});
- common.expectsError(
+ assert.throws(
() => crypto.createDecipheriv('des-ede3-cbc', key, 10),
{
code: 'ERR_INVALID_ARG_TYPE',
- type: TypeError,
+ name: 'TypeError',
message: 'The "iv" argument must be of type string or an instance of ' +
'Buffer, TypedArray, or DataView. Received type number (10)'
});
diff --git a/test/parallel/test-crypto-dh.js b/test/parallel/test-crypto-dh.js
index 027b58b826..855244a70b 100644
--- a/test/parallel/test-crypto-dh.js
+++ b/test/parallel/test-crypto-dh.js
@@ -48,11 +48,11 @@ assert.strictEqual(dh2.verifyError, 0);
/abc/,
{}
].forEach((input) => {
- common.expectsError(
+ assert.throws(
() => crypto.createDiffieHellman(input),
{
code: 'ERR_INVALID_ARG_TYPE',
- type: TypeError,
+ name: 'TypeError',
message: 'The "sizeOrKey" argument must be one of type number or string' +
' or an instance of Buffer, TypedArray, or DataView.' +
common.invalidArgTypeHelper(input)
@@ -233,11 +233,11 @@ if (availableCurves.has('prime256v1') && availableCurves.has('secp256k1')) {
assert(firstByte === 6 || firstByte === 7);
// Format value should be string
- common.expectsError(
+ assert.throws(
() => ecdh1.getPublicKey('buffer', 10),
{
code: 'ERR_CRYPTO_ECDH_INVALID_FORMAT',
- type: TypeError,
+ name: 'TypeError',
message: 'Invalid ECDH format: 10'
});
@@ -245,11 +245,11 @@ if (availableCurves.has('prime256v1') && availableCurves.has('secp256k1')) {
const ecdh3 = crypto.createECDH('secp256k1');
const key3 = ecdh3.generateKeys();
- common.expectsError(
+ assert.throws(
() => ecdh2.computeSecret(key3, 'latin1', 'buffer'),
{
code: 'ERR_CRYPTO_ECDH_INVALID_PUBLIC_KEY',
- type: Error,
+ name: 'Error',
message: 'Public key is not valid for specified curve'
});
@@ -358,11 +358,11 @@ if (availableCurves.has('prime256v1') && availableHashes.has('sha256')) {
const invalidKey = Buffer.alloc(65);
invalidKey.fill('\0');
curve.generateKeys();
- common.expectsError(
+ assert.throws(
() => curve.computeSecret(invalidKey),
{
code: 'ERR_CRYPTO_ECDH_INVALID_PUBLIC_KEY',
- type: Error,
+ name: 'Error',
message: 'Public key is not valid for specified curve'
});
// Check that signing operations are not impacted by the above error.
@@ -376,11 +376,11 @@ if (availableCurves.has('prime256v1') && availableHashes.has('sha256')) {
}
// Invalid test: curve argument is undefined
-common.expectsError(
+assert.throws(
() => crypto.createECDH(),
{
code: 'ERR_INVALID_ARG_TYPE',
- type: TypeError,
+ name: 'TypeError',
message: 'The "curve" argument must be of type string. ' +
'Received undefined'
});
diff --git a/test/parallel/test-crypto-ecdh-convert-key.js b/test/parallel/test-crypto-ecdh-convert-key.js
index 52d0fc2b7f..69ee339aa7 100644
--- a/test/parallel/test-crypto-ecdh-convert-key.js
+++ b/test/parallel/test-crypto-ecdh-convert-key.js
@@ -17,36 +17,36 @@ const cafebabePubPtUnComp =
'2e02c7f93d13dc2732b760ca377a5897b9dd41a1c1b29dc0442fdce6d0a04d1d';
// Invalid test: key argument is undefined.
-common.expectsError(
+assert.throws(
() => ECDH.convertKey(),
{
code: 'ERR_INVALID_ARG_TYPE',
- type: TypeError,
+ name: 'TypeError',
});
// Invalid test: curve argument is undefined.
-common.expectsError(
+assert.throws(
() => ECDH.convertKey(cafebabePubPtComp),
{
code: 'ERR_INVALID_ARG_TYPE',
- type: TypeError,
+ name: 'TypeError',
});
// Invalid test: curve argument is invalid.
-common.expectsError(
+assert.throws(
() => ECDH.convertKey(cafebabePubPtComp, 'badcurve'),
{
- type: TypeError,
+ name: 'TypeError',
message: 'Invalid ECDH curve name'
});
if (getCurves().includes('secp256k1')) {
// Invalid test: format argument is undefined.
- common.expectsError(
+ assert.throws(
() => ECDH.convertKey(cafebabePubPtComp, 'secp256k1', 'hex', 'hex', 10),
{
code: 'ERR_CRYPTO_ECDH_INVALID_FORMAT',
- type: TypeError,
+ name: 'TypeError',
message: 'Invalid ECDH format: 10'
});
diff --git a/test/parallel/test-crypto-engine.js b/test/parallel/test-crypto-engine.js
index e3ac270fef..8b33285b45 100644
--- a/test/parallel/test-crypto-engine.js
+++ b/test/parallel/test-crypto-engine.js
@@ -4,39 +4,40 @@ const common = require('../common');
if (!common.hasCrypto)
common.skip('missing crypto');
+const assert = require('assert');
const crypto = require('crypto');
const invalidEngineName = 'xxx';
-common.expectsError(
+assert.throws(
() => crypto.setEngine(true),
{
code: 'ERR_INVALID_ARG_TYPE',
- type: TypeError,
+ name: 'TypeError',
message: 'The "id" argument must be of type string. Received type boolean' +
' (true)'
});
-common.expectsError(
+assert.throws(
() => crypto.setEngine('/path/to/engine', 'notANumber'),
{
code: 'ERR_INVALID_ARG_TYPE',
- type: TypeError,
+ name: 'TypeError',
message: 'The "flags" argument must be of type number. Received type' +
" string ('notANumber')"
});
-common.expectsError(
+assert.throws(
() => crypto.setEngine(invalidEngineName),
{
code: 'ERR_CRYPTO_ENGINE_UNKNOWN',
- type: Error,
+ name: 'Error',
message: `Engine "${invalidEngineName}" was not found`
});
-common.expectsError(
+assert.throws(
() => crypto.setEngine(invalidEngineName, crypto.constants.ENGINE_METHOD_RSA),
{
code: 'ERR_CRYPTO_ENGINE_UNKNOWN',
- type: Error,
+ name: 'Error',
message: `Engine "${invalidEngineName}" was not found`
});
diff --git a/test/parallel/test-crypto-hash.js b/test/parallel/test-crypto-hash.js
index 0ccc300aa2..f3f4df928c 100644
--- a/test/parallel/test-crypto-hash.js
+++ b/test/parallel/test-crypto-hash.js
@@ -113,22 +113,22 @@ assert.throws(function() {
// Issue https://github.com/nodejs/node/issues/9819: throwing encoding used to
// segfault.
-common.expectsError(
+assert.throws(
() => crypto.createHash('sha256').digest({
toString: () => { throw new Error('boom'); },
}),
{
- type: Error,
+ name: 'Error',
message: 'boom'
});
// Issue https://github.com/nodejs/node/issues/25487: error message for invalid
// arg type to update method should include all possible types
-common.expectsError(
+assert.throws(
() => crypto.createHash('sha256').update(),
{
code: 'ERR_INVALID_ARG_TYPE',
- type: TypeError,
+ name: 'TypeError',
message: 'The "data" argument must be of type string or an instance of ' +
'Buffer, TypedArray, or DataView. Received undefined'
});
@@ -147,29 +147,29 @@ assert.notStrictEqual(
const h3 = crypto.createHash('sha256');
h3.digest();
-common.expectsError(
+assert.throws(
() => h3.digest(),
{
code: 'ERR_CRYPTO_HASH_FINALIZED',
- type: Error
+ name: 'Error'
});
-common.expectsError(
+assert.throws(
() => h3.update('foo'),
{
code: 'ERR_CRYPTO_HASH_FINALIZED',
- type: Error
+ name: 'Error'
});
assert.strictEqual(
crypto.createHash('sha256').update('test').digest('ucs2'),
crypto.createHash('sha256').update('test').digest().toString('ucs2'));
-common.expectsError(
+assert.throws(
() => crypto.createHash(),
{
code: 'ERR_INVALID_ARG_TYPE',
- type: TypeError,
+ name: 'TypeError',
message: 'The "algorithm" argument must be of type string. ' +
'Received undefined'
}
@@ -246,28 +246,28 @@ common.expectsError(
'15a2b01f828ea62ac5b3e42f');
// Passing invalid sizes should throw during creation.
- common.expectsError(() => {
+ assert.throws(() => {
crypto.createHash('sha256', { outputLength: 28 });
}, {
code: 'ERR_OSSL_EVP_NOT_XOF_OR_INVALID_LENGTH'
});
for (const outputLength of [null, {}, 'foo', false]) {
- common.expectsError(() => crypto.createHash('sha256', { outputLength }),
- { code: 'ERR_INVALID_ARG_TYPE' });
+ assert.throws(() => crypto.createHash('sha256', { outputLength }),
+ { code: 'ERR_INVALID_ARG_TYPE' });
}
for (const outputLength of [-1, .5, Infinity, 2 ** 90]) {
- common.expectsError(() => crypto.createHash('sha256', { outputLength }),
- { code: 'ERR_OUT_OF_RANGE' });
+ assert.throws(() => crypto.createHash('sha256', { outputLength }),
+ { code: 'ERR_OUT_OF_RANGE' });
}
}
{
const h = crypto.createHash('sha512');
h.digest();
- common.expectsError(() => h.copy(), { code: 'ERR_CRYPTO_HASH_FINALIZED' });
- common.expectsError(() => h.digest(), { code: 'ERR_CRYPTO_HASH_FINALIZED' });
+ assert.throws(() => h.copy(), { code: 'ERR_CRYPTO_HASH_FINALIZED' });
+ assert.throws(() => h.digest(), { code: 'ERR_CRYPTO_HASH_FINALIZED' });
}
{
diff --git a/test/parallel/test-crypto-hmac.js b/test/parallel/test-crypto-hmac.js
index dd7b563104..160d09036d 100644
--- a/test/parallel/test-crypto-hmac.js
+++ b/test/parallel/test-crypto-hmac.js
@@ -13,29 +13,29 @@ const crypto = require('crypto');
' when called without `new`');
}
-common.expectsError(
+assert.throws(
() => crypto.createHmac(null),
{
code: 'ERR_INVALID_ARG_TYPE',
- type: TypeError,
+ name: 'TypeError',
message: 'The "hmac" argument must be of type string. Received null'
});
// This used to segfault. See: https://github.com/nodejs/node/issues/9819
-common.expectsError(
+assert.throws(
() => crypto.createHmac('sha256', 'key').digest({
toString: () => { throw new Error('boom'); },
}),
{
- type: Error,
+ name: 'Error',
message: 'boom'
});
-common.expectsError(
+assert.throws(
() => crypto.createHmac('sha1', null),
{
code: 'ERR_INVALID_ARG_TYPE',
- type: TypeError,
+ name: 'TypeError',
message: 'The "key" argument must be of type string or an instance of ' +
'Buffer, TypedArray, DataView, or KeyObject. Received null'
});
diff --git a/test/parallel/test-crypto-key-objects.js b/test/parallel/test-crypto-key-objects.js
index c8303431fb..d3011db79d 100644
--- a/test/parallel/test-crypto-key-objects.js
+++ b/test/parallel/test-crypto-key-objects.js
@@ -32,10 +32,10 @@ const privateDsa = fixtures.readKey('dsa_private_encrypted_1025.pem',
{
// Attempting to create an empty key should throw.
- common.expectsError(() => {
+ assert.throws(() => {
createSecretKey(Buffer.alloc(0));
}, {
- type: RangeError,
+ name: 'RangeError',
code: 'ERR_OUT_OF_RANGE',
message: 'The value of "key.byteLength" is out of range. ' +
'It must be > 0. Received 0'
@@ -46,8 +46,8 @@ const privateDsa = fixtures.readKey('dsa_private_encrypted_1025.pem',
// Attempting to create a key of a wrong type should throw
const TYPE = 'wrong_type';
- common.expectsError(() => new KeyObject(TYPE), {
- type: TypeError,
+ assert.throws(() => new KeyObject(TYPE), {
+ name: 'TypeError',
code: 'ERR_INVALID_ARG_VALUE',
message: `The argument 'type' is invalid. Received '${TYPE}'`
});
@@ -55,8 +55,8 @@ const privateDsa = fixtures.readKey('dsa_private_encrypted_1025.pem',
{
// Attempting to create a key with non-object handle should throw
- common.expectsError(() => new KeyObject('secret', ''), {
- type: TypeError,
+ assert.throws(() => new KeyObject('secret', ''), {
+ name: 'TypeError',
code: 'ERR_INVALID_ARG_TYPE',
message:
'The "handle" argument must be of type object. Received type ' +
@@ -92,16 +92,16 @@ const privateDsa = fixtures.readKey('dsa_private_encrypted_1025.pem',
{
// Passing an existing public key object to createPublicKey should throw.
const publicKey = createPublicKey(publicPem);
- common.expectsError(() => createPublicKey(publicKey), {
- type: TypeError,
+ assert.throws(() => createPublicKey(publicKey), {
+ name: 'TypeError',
code: 'ERR_CRYPTO_INVALID_KEY_OBJECT_TYPE',
message: 'Invalid key object type public, expected private.'
});
// Constructing a private key from a public key should be impossible, even
// if the public key was derived from a private key.
- common.expectsError(() => createPrivateKey(createPublicKey(privatePem)), {
- type: TypeError,
+ assert.throws(() => createPrivateKey(createPublicKey(privatePem)), {
+ name: 'TypeError',
code: 'ERR_INVALID_ARG_TYPE',
message: 'The "key" argument must be of type string or an instance of ' +
'Buffer, TypedArray, or DataView. Received an instance of ' +
@@ -111,8 +111,8 @@ const privateDsa = fixtures.readKey('dsa_private_encrypted_1025.pem',
// Similarly, passing an existing private key object to createPrivateKey
// should throw.
const privateKey = createPrivateKey(privatePem);
- common.expectsError(() => createPrivateKey(privateKey), {
- type: TypeError,
+ assert.throws(() => createPrivateKey(privateKey), {
+ name: 'TypeError',
code: 'ERR_INVALID_ARG_TYPE',
message: 'The "key" argument must be of type string or an instance of ' +
'Buffer, TypedArray, or DataView. Received an instance of ' +
@@ -139,8 +139,8 @@ const privateDsa = fixtures.readKey('dsa_private_encrypted_1025.pem',
// Test exporting with an invalid options object, this should throw.
for (const opt of [undefined, null, 'foo', 0, NaN]) {
- common.expectsError(() => publicKey.export(opt), {
- type: TypeError,
+ assert.throws(() => publicKey.export(opt), {
+ name: 'TypeError',
code: 'ERR_INVALID_ARG_TYPE',
message: /^The "options" argument must be of type object/
});
@@ -280,26 +280,26 @@ const privateDsa = fixtures.readKey('dsa_private_encrypted_1025.pem',
{
// Reading an encrypted key without a passphrase should fail.
- common.expectsError(() => createPrivateKey(privateDsa), {
- type: TypeError,
+ assert.throws(() => createPrivateKey(privateDsa), {
+ name: 'TypeError',
code: 'ERR_MISSING_PASSPHRASE',
message: 'Passphrase required for encrypted key'
});
// Reading an encrypted key with a passphrase that exceeds OpenSSL's buffer
// size limit should fail with an appropriate error code.
- common.expectsError(() => createPrivateKey({
+ assert.throws(() => createPrivateKey({
key: privateDsa,
format: 'pem',
passphrase: Buffer.alloc(1025, 'a')
}), {
code: 'ERR_OSSL_PEM_BAD_PASSWORD_READ',
- type: Error
+ name: 'Error'
});
// The buffer has a size of 1024 bytes, so this passphrase should be permitted
// (but will fail decryption).
- common.expectsError(() => createPrivateKey({
+ assert.throws(() => createPrivateKey({
key: privateDsa,
format: 'pem',
passphrase: Buffer.alloc(1024, 'a')
@@ -362,7 +362,7 @@ const privateDsa = fixtures.readKey('dsa_private_encrypted_1025.pem',
// Exporting the key using PKCS#1 should not work since this would discard
// any algorithm restrictions.
- common.expectsError(() => {
+ assert.throws(() => {
publicKey.export({ format: 'pem', type: 'pkcs1' });
}, {
code: 'ERR_CRYPTO_INCOMPATIBLE_KEY_OPTIONS'
@@ -465,12 +465,12 @@ const privateDsa = fixtures.readKey('dsa_private_encrypted_1025.pem',
{
// Exporting an encrypted private key requires a cipher
const privateKey = createPrivateKey(privatePem);
- common.expectsError(() => {
+ assert.throws(() => {
privateKey.export({
format: 'pem', type: 'pkcs8', passphrase: 'super-secret'
});
}, {
- type: TypeError,
+ name: 'TypeError',
code: 'ERR_INVALID_OPT_VALUE',
message: 'The value "undefined" is invalid for option "cipher"'
});
diff --git a/test/parallel/test-crypto-keygen.js b/test/parallel/test-crypto-keygen.js
index 605a374205..30b04e34d6 100644
--- a/test/parallel/test-crypto-keygen.js
+++ b/test/parallel/test-crypto-keygen.js
@@ -180,8 +180,8 @@ const sec1EncExp = (cipher) => getRegExpForPEM('EC PRIVATE KEY', cipher);
// Since the private key is encrypted, signing shouldn't work anymore.
const publicKey = { key: publicKeyDER, ...publicKeyEncoding };
- common.expectsError(() => testSignVerify(publicKey, privateKey), {
- type: TypeError,
+ assert.throws(() => testSignVerify(publicKey, privateKey), {
+ name: 'TypeError',
code: 'ERR_MISSING_PASSPHRASE',
message: 'Passphrase required for encrypted key'
});
@@ -212,14 +212,14 @@ const sec1EncExp = (cipher) => getRegExpForPEM('EC PRIVATE KEY', cipher);
// Since the private key is encrypted, signing shouldn't work anymore.
const publicKey = { key: publicKeyDER, ...publicKeyEncoding };
- common.expectsError(() => {
+ assert.throws(() => {
testSignVerify(publicKey, {
key: privateKeyDER,
format: 'der',
type: 'pkcs8'
});
}, {
- type: TypeError,
+ name: 'TypeError',
code: 'ERR_MISSING_PASSPHRASE',
message: 'Passphrase required for encrypted key'
});
@@ -333,13 +333,13 @@ const sec1EncExp = (cipher) => getRegExpForPEM('EC PRIVATE KEY', cipher);
assertApproximateSize(privateKeyDER, 336);
// Since the private key is encrypted, signing shouldn't work anymore.
- common.expectsError(() => {
+ assert.throws(() => {
return testSignVerify(publicKey, {
key: privateKeyDER,
...privateKeyEncoding
});
}, {
- type: TypeError,
+ name: 'TypeError',
code: 'ERR_MISSING_PASSPHRASE',
message: 'Passphrase required for encrypted key'
});
@@ -425,8 +425,8 @@ const sec1EncExp = (cipher) => getRegExpForPEM('EC PRIVATE KEY', cipher);
assert(sec1EncExp('AES-128-CBC').test(privateKey));
// Since the private key is encrypted, signing shouldn't work anymore.
- common.expectsError(() => testSignVerify(publicKey, privateKey), {
- type: TypeError,
+ assert.throws(() => testSignVerify(publicKey, privateKey), {
+ name: 'TypeError',
code: 'ERR_MISSING_PASSPHRASE',
message: 'Passphrase required for encrypted key'
});
@@ -457,8 +457,8 @@ const sec1EncExp = (cipher) => getRegExpForPEM('EC PRIVATE KEY', cipher);
assert(sec1EncExp('AES-128-CBC').test(privateKey));
// Since the private key is encrypted, signing shouldn't work anymore.
- common.expectsError(() => testSignVerify(publicKey, privateKey), {
- type: TypeError,
+ assert.throws(() => testSignVerify(publicKey, privateKey), {
+ name: 'TypeError',
code: 'ERR_MISSING_PASSPHRASE',
message: 'Passphrase required for encrypted key'
});
@@ -492,8 +492,8 @@ const sec1EncExp = (cipher) => getRegExpForPEM('EC PRIVATE KEY', cipher);
assert(pkcs8EncExp.test(privateKey));
// Since the private key is encrypted, signing shouldn't work anymore.
- common.expectsError(() => testSignVerify(publicKey, privateKey), {
- type: TypeError,
+ assert.throws(() => testSignVerify(publicKey, privateKey), {
+ name: 'TypeError',
code: 'ERR_MISSING_PASSPHRASE',
message: 'Passphrase required for encrypted key'
});
@@ -528,8 +528,8 @@ const sec1EncExp = (cipher) => getRegExpForPEM('EC PRIVATE KEY', cipher);
assert(pkcs8EncExp.test(privateKey));
// Since the private key is encrypted, signing shouldn't work anymore.
- common.expectsError(() => testSignVerify(publicKey, privateKey), {
- type: TypeError,
+ assert.throws(() => testSignVerify(publicKey, privateKey), {
+ name: 'TypeError',
code: 'ERR_MISSING_PASSPHRASE',
message: 'Passphrase required for encrypted key'
});
@@ -543,7 +543,7 @@ const sec1EncExp = (cipher) => getRegExpForPEM('EC PRIVATE KEY', cipher);
// Test invalid parameter encoding.
{
- common.expectsError(() => generateKeyPairSync('ec', {
+ assert.throws(() => generateKeyPairSync('ec', {
namedCurve: 'P-256',
paramEncoding: 'otherEncoding',
publicKeyEncoding: {
@@ -557,7 +557,7 @@ const sec1EncExp = (cipher) => getRegExpForPEM('EC PRIVATE KEY', cipher);
passphrase: 'top secret'
}
}), {
- type: TypeError,
+ name: 'TypeError',
code: 'ERR_INVALID_OPT_VALUE',
message: 'The value "otherEncoding" is invalid for ' +
'option "paramEncoding"'
@@ -595,16 +595,16 @@ const sec1EncExp = (cipher) => getRegExpForPEM('EC PRIVATE KEY', cipher);
{
// Test invalid key types.
for (const type of [undefined, null, 0]) {
- common.expectsError(() => generateKeyPairSync(type, {}), {
- type: TypeError,
+ assert.throws(() => generateKeyPairSync(type, {}), {
+ name: 'TypeError',
code: 'ERR_INVALID_ARG_TYPE',
message: 'The "type" argument must be of type string.' +
common.invalidArgTypeHelper(type)
});
}
- common.expectsError(() => generateKeyPairSync('rsa2', {}), {
- type: TypeError,
+ assert.throws(() => generateKeyPairSync('rsa2', {}), {
+ name: 'TypeError',
code: 'ERR_INVALID_ARG_VALUE',
message: "The argument 'type' must be a supported key type. Received 'rsa2'"
});
@@ -612,8 +612,8 @@ const sec1EncExp = (cipher) => getRegExpForPEM('EC PRIVATE KEY', cipher);
{
// Test keygen without options object.
- common.expectsError(() => generateKeyPair('rsa', common.mustNotCall()), {
- type: TypeError,
+ assert.throws(() => generateKeyPair('rsa', common.mustNotCall()), {
+ name: 'TypeError',
code: 'ERR_INVALID_ARG_TYPE',
message: 'The "options" argument must be of type object. ' +
'Received undefined'
@@ -621,8 +621,8 @@ const sec1EncExp = (cipher) => getRegExpForPEM('EC PRIVATE KEY', cipher);
// Even if no options are required, it should be impossible to pass anything
// but an object (or undefined).
- common.expectsError(() => generateKeyPair('ed448', 0, common.mustNotCall()), {
- type: TypeError,
+ assert.throws(() => generateKeyPair('ed448', 0, common.mustNotCall()), {
+ name: 'TypeError',
code: 'ERR_INVALID_ARG_TYPE',
message: 'The "options" argument must be of type object. ' +
'Received type number (0)'
@@ -676,7 +676,7 @@ const sec1EncExp = (cipher) => getRegExpForPEM('EC PRIVATE KEY', cipher);
{
// Invalid publicKeyEncoding.
for (const enc of [0, 'a', true]) {
- common.expectsError(() => generateKeyPairSync('rsa', {
+ assert.throws(() => generateKeyPairSync('rsa', {
modulusLength: 4096,
publicKeyEncoding: enc,
privateKeyEncoding: {
@@ -684,7 +684,7 @@ const sec1EncExp = (cipher) => getRegExpForPEM('EC PRIVATE KEY', cipher);
format: 'pem'
}
}), {
- type: TypeError,
+ name: 'TypeError',
code: 'ERR_INVALID_OPT_VALUE',
message: `The value "${enc}" is invalid for option "publicKeyEncoding"`
});
@@ -692,7 +692,7 @@ const sec1EncExp = (cipher) => getRegExpForPEM('EC PRIVATE KEY', cipher);
// Missing publicKeyEncoding.type.
for (const type of [undefined, null, 0, true, {}]) {
- common.expectsError(() => generateKeyPairSync('rsa', {
+ assert.throws(() => generateKeyPairSync('rsa', {
modulusLength: 4096,
publicKeyEncoding: {
type,
@@ -703,7 +703,7 @@ const sec1EncExp = (cipher) => getRegExpForPEM('EC PRIVATE KEY', cipher);
format: 'pem'
}
}), {
- type: TypeError,
+ name: 'TypeError',
code: 'ERR_INVALID_OPT_VALUE',
message: `The value "${type}" is invalid for option ` +
'"publicKeyEncoding.type"'
@@ -712,7 +712,7 @@ const sec1EncExp = (cipher) => getRegExpForPEM('EC PRIVATE KEY', cipher);
// Missing / invalid publicKeyEncoding.format.
for (const format of [undefined, null, 0, false, 'a', {}]) {
- common.expectsError(() => generateKeyPairSync('rsa', {
+ assert.throws(() => generateKeyPairSync('rsa', {
modulusLength: 4096,
publicKeyEncoding: {
type: 'pkcs1',
@@ -723,7 +723,7 @@ const sec1EncExp = (cipher) => getRegExpForPEM('EC PRIVATE KEY', cipher);
format: 'pem'
}
}), {
- type: TypeError,
+ name: 'TypeError',
code: 'ERR_INVALID_OPT_VALUE',
message: `The value "${format}" is invalid for option ` +
'"publicKeyEncoding.format"'
@@ -732,7 +732,7 @@ const sec1EncExp = (cipher) => getRegExpForPEM('EC PRIVATE KEY', cipher);
// Invalid privateKeyEncoding.
for (const enc of [0, 'a', true]) {
- common.expectsError(() => generateKeyPairSync('rsa', {
+ assert.throws(() => generateKeyPairSync('rsa', {
modulusLength: 4096,
publicKeyEncoding: {
type: 'pkcs1',
@@ -740,7 +740,7 @@ const sec1EncExp = (cipher) => getRegExpForPEM('EC PRIVATE KEY', cipher);
},
privateKeyEncoding: enc
}), {
- type: TypeError,
+ name: 'TypeError',
code: 'ERR_INVALID_OPT_VALUE',
message: `The value "${enc}" is invalid for option "privateKeyEncoding"`
});
@@ -748,7 +748,7 @@ const sec1EncExp = (cipher) => getRegExpForPEM('EC PRIVATE KEY', cipher);
// Missing / invalid privateKeyEncoding.type.
for (const type of [undefined, null, 0, true, {}]) {
- common.expectsError(() => generateKeyPairSync('rsa', {
+ assert.throws(() => generateKeyPairSync('rsa', {
modulusLength: 4096,
publicKeyEncoding: {
type: 'pkcs1',
@@ -759,7 +759,7 @@ const sec1EncExp = (cipher) => getRegExpForPEM('EC PRIVATE KEY', cipher);
format: 'pem'
}
}), {
- type: TypeError,
+ name: 'TypeError',
code: 'ERR_INVALID_OPT_VALUE',
message: `The value "${type}" is invalid for option ` +
'"privateKeyEncoding.type"'
@@ -768,7 +768,7 @@ const sec1EncExp = (cipher) => getRegExpForPEM('EC PRIVATE KEY', cipher);
// Missing / invalid privateKeyEncoding.format.
for (const format of [undefined, null, 0, false, 'a', {}]) {
- common.expectsError(() => generateKeyPairSync('rsa', {
+ assert.throws(() => generateKeyPairSync('rsa', {
modulusLength: 4096,
publicKeyEncoding: {
type: 'pkcs1',
@@ -779,7 +779,7 @@ const sec1EncExp = (cipher) => getRegExpForPEM('EC PRIVATE KEY', cipher);
format
}
}), {
- type: TypeError,
+ name: 'TypeError',
code: 'ERR_INVALID_OPT_VALUE',
message: `The value "${format}" is invalid for option ` +
'"privateKeyEncoding.format"'
@@ -788,7 +788,7 @@ const sec1EncExp = (cipher) => getRegExpForPEM('EC PRIVATE KEY', cipher);
// Cipher of invalid type.
for (const cipher of [0, true, {}]) {
- common.expectsError(() => generateKeyPairSync('rsa', {
+ assert.throws(() => generateKeyPairSync('rsa', {
modulusLength: 4096,
publicKeyEncoding: {
type: 'pkcs1',
@@ -800,7 +800,7 @@ const sec1EncExp = (cipher) => getRegExpForPEM('EC PRIVATE KEY', cipher);
cipher
}
}), {
- type: TypeError,
+ name: 'TypeError',
code: 'ERR_INVALID_OPT_VALUE',
message: `The value "${cipher}" is invalid for option ` +
'"privateKeyEncoding.cipher"'
@@ -808,7 +808,7 @@ const sec1EncExp = (cipher) => getRegExpForPEM('EC PRIVATE KEY', cipher);
}
// Invalid cipher.
- common.expectsError(() => generateKeyPairSync('rsa', {
+ assert.throws(() => generateKeyPairSync('rsa', {
modulusLength: 4096,
publicKeyEncoding: {
type: 'pkcs1',
@@ -821,13 +821,13 @@ const sec1EncExp = (cipher) => getRegExpForPEM('EC PRIVATE KEY', cipher);
passphrase: 'secret'
}
}), {
- type: Error,
+ name: 'Error',
message: 'Unknown cipher'
});
// Cipher, but no valid passphrase.
for (const passphrase of [undefined, null, 5, false, true]) {
- common.expectsError(() => generateKeyPairSync('rsa', {
+ assert.throws(() => generateKeyPairSync('rsa', {
modulusLength: 4096,
publicKeyEncoding: {
type: 'pkcs1',
@@ -840,7 +840,7 @@ const sec1EncExp = (cipher) => getRegExpForPEM('EC PRIVATE KEY', cipher);
passphrase
}
}), {
- type: TypeError,
+ name: 'TypeError',
code: 'ERR_INVALID_OPT_VALUE',
message: `The value "${passphrase}" is invalid for option ` +
'"privateKeyEncoding.passphrase"'
@@ -849,12 +849,12 @@ const sec1EncExp = (cipher) => getRegExpForPEM('EC PRIVATE KEY', cipher);
// Test invalid callbacks.
for (const cb of [undefined, null, 0, {}]) {
- common.expectsError(() => generateKeyPair('rsa', {
+ assert.throws(() => generateKeyPair('rsa', {
modulusLength: 512,
publicKeyEncoding: { type: 'pkcs1', format: 'pem' },
privateKeyEncoding: { type: 'pkcs1', format: 'pem' }
}, cb), {
- type: TypeError,
+ name: 'TypeError',
code: 'ERR_INVALID_CALLBACK'
});
}
@@ -864,10 +864,10 @@ const sec1EncExp = (cipher) => getRegExpForPEM('EC PRIVATE KEY', cipher);
{
// Test invalid modulus lengths.
for (const modulusLength of [undefined, null, 'a', true, {}, [], 512.1, -1]) {
- common.expectsError(() => generateKeyPair('rsa', {
+ assert.throws(() => generateKeyPair('rsa', {
modulusLength
}), {
- type: TypeError,
+ name: 'TypeError',
code: 'ERR_INVALID_OPT_VALUE',
message: `The value "${modulusLength}" is invalid for option ` +
'"modulusLength"'
@@ -876,11 +876,11 @@ const sec1EncExp = (cipher) => getRegExpForPEM('EC PRIVATE KEY', cipher);
// Test invalid exponents.
for (const publicExponent of ['a', true, {}, [], 3.5, -1]) {
- common.expectsError(() => generateKeyPair('rsa', {
+ assert.throws(() => generateKeyPair('rsa', {
modulusLength: 4096,
publicExponent
}), {
- type: TypeError,
+ name: 'TypeError',
code: 'ERR_INVALID_OPT_VALUE',
message: `The value "${publicExponent}" is invalid for option ` +
'"publicExponent"'
@@ -892,10 +892,10 @@ const sec1EncExp = (cipher) => getRegExpForPEM('EC PRIVATE KEY', cipher);
{
// Test invalid modulus lengths.
for (const modulusLength of [undefined, null, 'a', true, {}, [], 4096.1]) {
- common.expectsError(() => generateKeyPair('dsa', {
+ assert.throws(() => generateKeyPair('dsa', {
modulusLength
}), {
- type: TypeError,
+ name: 'TypeError',
code: 'ERR_INVALID_OPT_VALUE',
message: `The value "${modulusLength}" is invalid for option ` +
'"modulusLength"'
@@ -904,11 +904,11 @@ const sec1EncExp = (cipher) => getRegExpForPEM('EC PRIVATE KEY', cipher);
// Test invalid divisor lengths.
for (const divisorLength of ['a', true, {}, [], 4096.1]) {
- common.expectsError(() => generateKeyPair('dsa', {
+ assert.throws(() => generateKeyPair('dsa', {
modulusLength: 2048,
divisorLength
}), {
- type: TypeError,
+ name: 'TypeError',
code: 'ERR_INVALID_OPT_VALUE',
message: `The value "${divisorLength}" is invalid for option ` +
'"divisorLength"'
@@ -919,27 +919,27 @@ const sec1EncExp = (cipher) => getRegExpForPEM('EC PRIVATE KEY', cipher);
// Test EC parameters.
{
// Test invalid curves.
- common.expectsError(() => {
+ assert.throws(() => {
generateKeyPairSync('ec', {
namedCurve: 'abcdef',
publicKeyEncoding: { type: 'spki', format: 'pem' },
privateKeyEncoding: { type: 'sec1', format: 'pem' }
});
}, {
- type: TypeError,
+ name: 'TypeError',
message: 'Invalid ECDH curve name'
});
// Test error type when curve is not a string
for (const namedCurve of [true, {}, [], 123]) {
- common.expectsError(() => {
+ assert.throws(() => {
generateKeyPairSync('ec', {
namedCurve,
publicKeyEncoding: { type: 'spki', format: 'pem' },
privateKeyEncoding: { type: 'sec1', format: 'pem' }
});
}, {
- type: TypeError,
+ name: 'TypeError',
code: 'ERR_INVALID_OPT_VALUE',
message: `The value "${namedCurve}" is invalid for option ` +
'"namedCurve"'
@@ -985,14 +985,14 @@ const sec1EncExp = (cipher) => getRegExpForPEM('EC PRIVATE KEY', cipher);
{
// Invalid public key type.
for (const type of ['foo', 'pkcs8', 'sec1']) {
- common.expectsError(() => {
+ assert.throws(() => {
generateKeyPairSync('rsa', {
modulusLength: 4096,
publicKeyEncoding: { type, format: 'pem' },
privateKeyEncoding: { type: 'pkcs8', format: 'pem' }
});
}, {
- type: TypeError,
+ name: 'TypeError',
code: 'ERR_INVALID_OPT_VALUE',
message: `The value "${type}" is invalid for option ` +
'"publicKeyEncoding.type"'
@@ -1001,13 +1001,13 @@ const sec1EncExp = (cipher) => getRegExpForPEM('EC PRIVATE KEY', cipher);
// Invalid hash value.
for (const hashValue of [123, true, {}, []]) {
- common.expectsError(() => {
+ assert.throws(() => {
generateKeyPairSync('rsa-pss', {
modulusLength: 4096,
hash: hashValue
});
}, {
- type: TypeError,
+ name: 'TypeError',
code: 'ERR_INVALID_OPT_VALUE',
message: `The value "${hashValue}" is invalid for option "hash"`
});
@@ -1015,14 +1015,14 @@ const sec1EncExp = (cipher) => getRegExpForPEM('EC PRIVATE KEY', cipher);
// Invalid private key type.
for (const type of ['foo', 'spki']) {
- common.expectsError(() => {
+ assert.throws(() => {
generateKeyPairSync('rsa', {
modulusLength: 4096,
publicKeyEncoding: { type: 'spki', format: 'pem' },
privateKeyEncoding: { type, format: 'pem' }
});
}, {
- type: TypeError,
+ name: 'TypeError',
code: 'ERR_INVALID_OPT_VALUE',
message: `The value "${type}" is invalid for option ` +
'"privateKeyEncoding.type"'
@@ -1031,7 +1031,7 @@ const sec1EncExp = (cipher) => getRegExpForPEM('EC PRIVATE KEY', cipher);
// Key encoding doesn't match key type.
for (const type of ['dsa', 'ec']) {
- common.expectsError(() => {
+ assert.throws(() => {
generateKeyPairSync(type, {
modulusLength: 4096,
namedCurve: 'P-256',
@@ -1039,12 +1039,12 @@ const sec1EncExp = (cipher) => getRegExpForPEM('EC PRIVATE KEY', cipher);
privateKeyEncoding: { type: 'pkcs8', format: 'pem' }
});
}, {
- type: Error,
+ name: 'Error',
code: 'ERR_CRYPTO_INCOMPATIBLE_KEY_OPTIONS',
message: 'The selected key encoding pkcs1 can only be used for RSA keys.'
});
- common.expectsError(() => {
+ assert.throws(() => {
generateKeyPairSync(type, {
modulusLength: 4096,
namedCurve: 'P-256',
@@ -1052,21 +1052,21 @@ const sec1EncExp = (cipher) => getRegExpForPEM('EC PRIVATE KEY', cipher);
privateKeyEncoding: { type: 'pkcs1', format: 'pem' }
});
}, {
- type: Error,
+ name: 'Error',
code: 'ERR_CRYPTO_INCOMPATIBLE_KEY_OPTIONS',
message: 'The selected key encoding pkcs1 can only be used for RSA keys.'
});
}
for (const type of ['rsa', 'dsa']) {
- common.expectsError(() => {
+ assert.throws(() => {
generateKeyPairSync(type, {
modulusLength: 4096,
publicKeyEncoding: { type: 'spki', format: 'pem' },
privateKeyEncoding: { type: 'sec1', format: 'pem' }
});
}, {
- type: Error,
+ name: 'Error',
code: 'ERR_CRYPTO_INCOMPATIBLE_KEY_OPTIONS',
message: 'The selected key encoding sec1 can only be used for EC keys.'
});
@@ -1074,7 +1074,7 @@ const sec1EncExp = (cipher) => getRegExpForPEM('EC PRIVATE KEY', cipher);
// Attempting to encrypt a DER-encoded, non-PKCS#8 key.
for (const type of ['pkcs1', 'sec1']) {
- common.expectsError(() => {
+ assert.throws(() => {
generateKeyPairSync(type === 'pkcs1' ? 'rsa' : 'ec', {
modulusLength: 4096,
namedCurve: 'P-256',
@@ -1087,7 +1087,7 @@ const sec1EncExp = (cipher) => getRegExpForPEM('EC PRIVATE KEY', cipher);
}
});
}, {
- type: Error,
+ name: 'Error',
code: 'ERR_CRYPTO_INCOMPATIBLE_KEY_OPTIONS',
message: `The selected key encoding ${type} does not support encryption.`
});
@@ -1095,7 +1095,7 @@ const sec1EncExp = (cipher) => getRegExpForPEM('EC PRIVATE KEY', cipher);
}
{
// Test RSA-PSS.
- common.expectsError(
+ assert.throws(
() => {
generateKeyPair('rsa-pss', {
modulusLength: 512,
@@ -1105,14 +1105,14 @@ const sec1EncExp = (cipher) => getRegExpForPEM('EC PRIVATE KEY', cipher);
});
},
{
- type: TypeError,
+ name: 'TypeError',
code: 'ERR_INVALID_CALLBACK',
message: 'Callback must be a function. Received undefined'
}
);
for (const mgf1Hash of [null, 0, false, {}, []]) {
- common.expectsError(
+ assert.throws(
() => {
generateKeyPair('rsa-pss', {
modulusLength: 512,
@@ -1122,7 +1122,7 @@ const sec1EncExp = (cipher) => getRegExpForPEM('EC PRIVATE KEY', cipher);
});
},
{
- type: TypeError,
+ name: 'TypeError',
code: 'ERR_INVALID_OPT_VALUE',
message: `The value "${mgf1Hash}" is invalid for option "mgf1Hash"`
}
diff --git a/test/parallel/test-crypto-random.js b/test/parallel/test-crypto-random.js
index 4650b3c8bd..8a34f0ca22 100644
--- a/test/parallel/test-crypto-random.js
+++ b/test/parallel/test-crypto-random.js
@@ -273,35 +273,35 @@ assert.throws(
[1, true, NaN, null, undefined, {}, []].forEach((i) => {
const buf = Buffer.alloc(10);
- common.expectsError(
+ assert.throws(
() => crypto.randomFillSync(i),
{
code: 'ERR_INVALID_ARG_TYPE',
- type: TypeError
+ name: 'TypeError'
}
);
- common.expectsError(
+ assert.throws(
() => crypto.randomFill(i, common.mustNotCall()),
{
code: 'ERR_INVALID_ARG_TYPE',
- type: TypeError
+ name: 'TypeError'
}
);
- common.expectsError(
+ assert.throws(
() => crypto.randomFill(buf, 0, 10, i),
{
code: 'ERR_INVALID_CALLBACK',
- type: TypeError,
+ name: 'TypeError',
message: `Callback must be a function. Received ${inspect(i)}`
});
});
[1, true, NaN, null, {}, []].forEach((i) => {
- common.expectsError(
+ assert.throws(
() => crypto.randomBytes(1, i),
{
code: 'ERR_INVALID_CALLBACK',
- type: TypeError,
+ name: 'TypeError',
message: `Callback must be a function. Received ${inspect(i)}`
}
);
diff --git a/test/parallel/test-crypto-rsa-dsa.js b/test/parallel/test-crypto-rsa-dsa.js
index 30ef7ec6d1..9b8c3f67a2 100644
--- a/test/parallel/test-crypto-rsa-dsa.js
+++ b/test/parallel/test-crypto-rsa-dsa.js
@@ -193,7 +193,7 @@ test_rsa('RSA_PKCS1_OAEP_PADDING', undefined, 'sha1');
test_rsa('RSA_PKCS1_OAEP_PADDING', 'sha1', undefined);
test_rsa('RSA_PKCS1_OAEP_PADDING', 'sha256', 'sha256');
test_rsa('RSA_PKCS1_OAEP_PADDING', 'sha512', 'sha512');
-common.expectsError(() => {
+assert.throws(() => {
test_rsa('RSA_PKCS1_OAEP_PADDING', 'sha256', 'sha512');
}, {
code: 'ERR_OSSL_RSA_OAEP_DECODING_ERROR'
@@ -228,7 +228,7 @@ for (const fn of [crypto.publicEncrypt, crypto.privateDecrypt]) {
});
for (const oaepHash of [0, false, null, Symbol(), () => {}]) {
- common.expectsError(() => {
+ assert.throws(() => {
fn({
key: rsaPubPem,
oaepHash
@@ -239,7 +239,7 @@ for (const fn of [crypto.publicEncrypt, crypto.privateDecrypt]) {
}
for (const oaepLabel of [0, false, null, Symbol(), () => {}, {}, 'foo']) {
- common.expectsError(() => {
+ assert.throws(() => {
fn({
key: rsaPubPem,
oaepLabel
diff --git a/test/parallel/test-crypto-scrypt.js b/test/parallel/test-crypto-scrypt.js
index b5d6cbb4a8..ff074bba06 100644
--- a/test/parallel/test-crypto-scrypt.js
+++ b/test/parallel/test-crypto-scrypt.js
@@ -159,24 +159,24 @@ for (const options of bad) {
const expected = {
code: 'ERR_CRYPTO_SCRYPT_INVALID_PARAMETER',
message: 'Invalid scrypt parameter',
- type: Error,
+ name: 'Error',
};
- common.expectsError(() => crypto.scrypt('pass', 'salt', 1, options, () => {}),
- expected);
- common.expectsError(() => crypto.scryptSync('pass', 'salt', 1, options),
- expected);
+ assert.throws(() => crypto.scrypt('pass', 'salt', 1, options, () => {}),
+ expected);
+ assert.throws(() => crypto.scryptSync('pass', 'salt', 1, options),
+ expected);
}
for (const options of toobig) {
const expected = {
message: new RegExp('error:[^:]+:digital envelope routines:' +
'(?:EVP_PBE_scrypt|scrypt_alg):memory limit exceeded'),
- type: Error,
+ name: 'Error',
};
- common.expectsError(() => crypto.scrypt('pass', 'salt', 1, options, () => {}),
- expected);
- common.expectsError(() => crypto.scryptSync('pass', 'salt', 1, options),
- expected);
+ assert.throws(() => crypto.scrypt('pass', 'salt', 1, options, () => {}),
+ expected);
+ assert.throws(() => crypto.scryptSync('pass', 'salt', 1, options),
+ expected);
}
{
@@ -209,16 +209,16 @@ for (const options of toobig) {
}
for (const { args, expected } of badargs) {
- common.expectsError(() => crypto.scrypt(...args), expected);
- common.expectsError(() => crypto.scryptSync(...args), expected);
+ assert.throws(() => crypto.scrypt(...args), expected);
+ assert.throws(() => crypto.scryptSync(...args), expected);
}
{
const expected = { code: 'ERR_INVALID_CALLBACK' };
- common.expectsError(() => crypto.scrypt('', '', 42, null), expected);
- common.expectsError(() => crypto.scrypt('', '', 42, {}, null), expected);
- common.expectsError(() => crypto.scrypt('', '', 42, {}), expected);
- common.expectsError(() => crypto.scrypt('', '', 42, {}, {}), expected);
+ assert.throws(() => crypto.scrypt('', '', 42, null), expected);
+ assert.throws(() => crypto.scrypt('', '', 42, {}, null), expected);
+ assert.throws(() => crypto.scrypt('', '', 42, {}), expected);
+ assert.throws(() => crypto.scrypt('', '', 42, {}, {}), expected);
}
{
@@ -231,7 +231,7 @@ for (const { args, expected } of badargs) {
}));
// Values that exceed Number.isSafeInteger should not be allowed.
- common.expectsError(() => crypto.scryptSync('', '', 0, { maxmem: 2 ** 53 }), {
+ assert.throws(() => crypto.scryptSync('', '', 0, { maxmem: 2 ** 53 }), {
code: 'ERR_OUT_OF_RANGE'
});
}
@@ -251,7 +251,7 @@ for (const { args, expected } of badargs) {
});
// Try to crash the process on the last access.
- common.expectsError(() => {
+ assert.throws(() => {
crypto.scryptSync('', '', 1, {
get [name]() {
if (--accessCount === 0)
diff --git a/test/parallel/test-crypto-sign-verify.js b/test/parallel/test-crypto-sign-verify.js
index d98317a354..e3d3d818a1 100644
--- a/test/parallel/test-crypto-sign-verify.js
+++ b/test/parallel/test-crypto-sign-verify.js
@@ -68,25 +68,25 @@ const keySize = 2048;
delete Object.prototype.opensslErrorStack;
}
-common.expectsError(
+assert.throws(
() => crypto.createVerify('SHA256').verify({
key: certPem,
padding: null,
}, ''),
{
code: 'ERR_INVALID_OPT_VALUE',
- type: TypeError,
+ name: 'TypeError',
message: 'The value "null" is invalid for option "padding"'
});
-common.expectsError(
+assert.throws(
() => crypto.createVerify('SHA256').verify({
key: certPem,
saltLength: null,
}, ''),
{
code: 'ERR_INVALID_OPT_VALUE',
- type: TypeError,
+ name: 'TypeError',
message: 'The value "null" is invalid for option "saltLength"'
});
@@ -306,7 +306,7 @@ common.expectsError(
{
[null, NaN, 'boom', {}, [], true, false]
.forEach((invalidValue) => {
- common.expectsError(() => {
+ assert.throws(() => {
crypto.createSign('SHA256')
.update('Test123')
.sign({
@@ -315,10 +315,10 @@ common.expectsError(
});
}, {
code: 'ERR_INVALID_OPT_VALUE',
- type: TypeError
+ name: 'TypeError'
});
- common.expectsError(() => {
+ assert.throws(() => {
crypto.createSign('SHA256')
.update('Test123')
.sign({
@@ -328,7 +328,7 @@ common.expectsError(
});
}, {
code: 'ERR_INVALID_OPT_VALUE',
- type: TypeError
+ name: 'TypeError'
});
});
@@ -351,11 +351,11 @@ common.expectsError(
// Test throws exception when key options is null
{
- common.expectsError(() => {
+ assert.throws(() => {
crypto.createSign('SHA1').update('Test123').sign(null, 'base64');
}, {
code: 'ERR_CRYPTO_SIGN_KEY_REQUIRED',
- type: Error
+ name: 'Error'
});
}
@@ -531,7 +531,7 @@ common.expectsError(
// Test invalid signature lengths.
for (const i of [-2, -1, 1, 2, 4, 8]) {
sig = crypto.randomBytes(length + i);
- common.expectsError(() => {
+ assert.throws(() => {
crypto.verify('sha1', data, opts, sig);
}, {
message: 'Malformed signature'
@@ -577,7 +577,7 @@ common.expectsError(
);
for (const dsaEncoding of ['foo', null, {}, 5, true, NaN]) {
- common.expectsError(() => {
+ assert.throws(() => {
crypto.sign('sha1', data, {
key: certPem,
dsaEncoding
diff --git a/test/parallel/test-crypto.js b/test/parallel/test-crypto.js
index c029ab8c77..6b72dbd21c 100644
--- a/test/parallel/test-crypto.js
+++ b/test/parallel/test-crypto.js
@@ -41,7 +41,7 @@ const certPfx = fixtures.readKey('rsa_cert.pfx');
// 'this' safety
// https://github.com/joyent/node/issues/6690
-assert.throws(function() {
+assert.throws(() => {
const credentials = tls.createSecureContext();
const context = credentials.context;
const notcontext = { setOptions: context.setOptions };
@@ -52,56 +52,52 @@ assert.throws(function() {
notcontext.setOptions();
}, (err) => {
// Throws TypeError, so there is no opensslErrorStack property.
- if ((err instanceof Error) &&
- /^TypeError: Illegal invocation$/.test(err) &&
- err.opensslErrorStack === undefined) {
- return true;
- }
+ return err instanceof TypeError &&
+ err.name === 'TypeError' &&
+ /^TypeError: Illegal invocation$/.test(err) &&
+ !('opensslErrorStack' in err);
});
// PFX tests
tls.createSecureContext({ pfx: certPfx, passphrase: 'sample' });
-assert.throws(function() {
+assert.throws(() => {
tls.createSecureContext({ pfx: certPfx });
}, (err) => {
// Throws general Error, so there is no opensslErrorStack property.
- if ((err instanceof Error) &&
- /^Error: mac verify failure$/.test(err) &&
- err.opensslErrorStack === undefined) {
- return true;
- }
+ return err instanceof Error &&
+ err.name === 'Error' &&
+ /^Error: mac verify failure$/.test(err) &&
+ !('opensslErrorStack' in err);
});
-assert.throws(function() {
+assert.throws(() => {
tls.createSecureContext({ pfx: certPfx, passphrase: 'test' });
}, (err) => {
// Throws general Error, so there is no opensslErrorStack property.
- if ((err instanceof Error) &&
- /^Error: mac verify failure$/.test(err) &&
- err.opensslErrorStack === undefined) {
- return true;
- }
+ return err instanceof Error &&
+ err.name === 'Error' &&
+ /^Error: mac verify failure$/.test(err) &&
+ !('opensslErrorStack' in err);
});
-assert.throws(function() {
+assert.throws(() => {
tls.createSecureContext({ pfx: 'sample', passphrase: 'test' });
}, (err) => {
// Throws general Error, so there is no opensslErrorStack property.
- if ((err instanceof Error) &&
- /^Error: not enough data$/.test(err) &&
- err.opensslErrorStack === undefined) {
- return true;
- }
+ return err instanceof Error &&
+ err.name === 'Error' &&
+ /^Error: not enough data$/.test(err) &&
+ !('opensslErrorStack' in err);
});
// update() should only take buffers / strings
-common.expectsError(
+assert.throws(
() => crypto.createHash('sha1').update({ foo: 'bar' }),
{
code: 'ERR_INVALID_ARG_TYPE',
- type: TypeError
+ name: 'TypeError'
});
@@ -165,70 +161,50 @@ testImmutability(tls.getCiphers);
testImmutability(crypto.getHashes);
testImmutability(crypto.getCurves);
+const encodingError = {
+ code: 'ERR_INVALID_ARG_VALUE',
+ name: 'TypeError',
+ message: "The argument 'encoding' is invalid for data of length 1." +
+ " Received 'hex'",
+};
+
// Regression tests for https://github.com/nodejs/node-v0.x-archive/pull/5725:
// hex input that's not a power of two should throw, not assert in C++ land.
+['createCipher', 'createDecipher'].forEach((funcName) => {
+ assert.throws(
+ () => crypto[funcName]('aes192', 'test').update('0', 'hex'),
+ (error) => {
+ assert.ok(!('opensslErrorStack' in error));
+ if (common.hasFipsCrypto) {
+ return error instanceof Error &&
+ error.name === 'Error' &&
+ /^Error: not supported in FIPS mode$/.test(error);
+ }
+ assert.throws(() => { throw error; }, encodingError);
+ return true;
+ }
+ );
+});
-common.expectsError(
- () => crypto.createCipher('aes192', 'test').update('0', 'hex'),
- Object.assign(
- common.hasFipsCrypto ?
- {
- code: undefined,
- type: Error,
- message: /not supported in FIPS mode/,
- } :
- {
- code: 'ERR_INVALID_ARG_VALUE',
- type: TypeError,
- message: "The argument 'encoding' is invalid for data of length 1." +
- " Received 'hex'",
- },
- { opensslErrorStack: undefined }
- )
-);
-
-common.expectsError(
- () => crypto.createDecipher('aes192', 'test').update('0', 'hex'),
- Object.assign(
- common.hasFipsCrypto ?
- {
- code: undefined,
- type: Error,
- message: /not supported in FIPS mode/,
- } :
- {
- code: 'ERR_INVALID_ARG_VALUE',
- type: TypeError,
- message: "The argument 'encoding' is invalid for data of length 1." +
- " Received 'hex'",
- },
- { opensslErrorStack: undefined }
- )
-);
-
-common.expectsError(
+assert.throws(
() => crypto.createHash('sha1').update('0', 'hex'),
- {
- code: 'ERR_INVALID_ARG_VALUE',
- type: TypeError,
- message: "The argument 'encoding' is invalid for data of length 1." +
- " Received 'hex'",
- opensslErrorStack: undefined
+ (error) => {
+ assert.ok(!('opensslErrorStack' in error));
+ assert.throws(() => { throw error; }, encodingError);
+ return true;
}
);
-common.expectsError(
+assert.throws(
() => crypto.createHmac('sha256', 'a secret').update('0', 'hex'),
- {
- code: 'ERR_INVALID_ARG_VALUE',
- type: TypeError,
- message: "The argument 'encoding' is invalid for data of length 1." +
- " Received 'hex'",
- opensslErrorStack: undefined
+ (error) => {
+ assert.ok(!('opensslErrorStack' in error));
+ assert.throws(() => { throw error; }, encodingError);
+ return true;
}
);
-assert.throws(function() {
+assert.throws(() => {
const priv = [
'-----BEGIN RSA PRIVATE KEY-----',
'MIGrAgEAAiEA+3z+1QNF2/unumadiwEr+C5vfhezsb3hp4jAnCNRpPcCAwEAAQIgQNriSQK4',
@@ -240,14 +216,19 @@ assert.throws(function() {
].join('\n');
crypto.createSign('SHA256').update('test').sign(priv);
}, (err) => {
- if ((err instanceof Error) &&
- /digest too big for rsa key$/.test(err) &&
- err.opensslErrorStack === undefined) {
- return true;
- }
+ assert.ok(!('opensslErrorStack' in err));
+ assert.throws(() => { throw err; }, {
+ name: 'Error',
+ message: /routines:RSA_sign:digest too big for rsa key$/,
+ library: 'rsa routines',
+ function: 'RSA_sign',
+ reason: 'digest too big for rsa key',
+ code: 'ERR_OSSL_RSA_DIGEST_TOO_BIG_FOR_RSA_KEY'
+ });
+ return true;
});
-assert.throws(function() {
+assert.throws(() => {
// The correct header inside `rsa_private_pkcs8_bad.pem` should have been
// -----BEGIN PRIVATE KEY----- and -----END PRIVATE KEY-----
// instead of
@@ -275,15 +256,13 @@ assert.throws(function() {
// Make sure memory isn't released before being returned
console.log(crypto.randomBytes(16));
-assert.throws(function() {
+assert.throws(() => {
tls.createSecureContext({ crl: 'not a CRL' });
}, (err) => {
// Throws general error, so there is no opensslErrorStack property.
- if ((err instanceof Error) &&
- /^Error: Failed to parse CRL$/.test(err) &&
- err.opensslErrorStack === undefined) {
- return true;
- }
+ return err instanceof Error &&
+ /^Error: Failed to parse CRL$/.test(err) &&
+ !('opensslErrorStack' in err);
});
/**
diff --git a/test/parallel/test-dgram-bind-fd-error.js b/test/parallel/test-dgram-bind-fd-error.js
index 519855bacc..a8a95bd07f 100644
--- a/test/parallel/test-dgram-bind-fd-error.js
+++ b/test/parallel/test-dgram-bind-fd-error.js
@@ -19,13 +19,13 @@ const TYPE = 'udp4';
const anotherSocket = dgram.createSocket(TYPE);
const { handle } = socket[kStateSymbol];
- common.expectsError(() => {
+ assert.throws(() => {
anotherSocket.bind({
fd: handle.fd,
});
}, {
code: 'EEXIST',
- type: Error,
+ name: 'Error',
message: /^open EEXIST$/
});
@@ -42,13 +42,13 @@ const TYPE = 'udp4';
assert.notStrictEqual(fd, -1);
const socket = new dgram.createSocket(TYPE);
- common.expectsError(() => {
+ assert.throws(() => {
socket.bind({
fd,
});
}, {
code: 'ERR_INVALID_FD_TYPE',
- type: TypeError,
+ name: 'TypeError',
message: /^Unsupported fd type: TCP$/
});
diff --git a/test/parallel/test-dgram-bind.js b/test/parallel/test-dgram-bind.js
index e3b358bdd2..8ae1213c7f 100644
--- a/test/parallel/test-dgram-bind.js
+++ b/test/parallel/test-dgram-bind.js
@@ -27,11 +27,11 @@ const dgram = require('dgram');
const socket = dgram.createSocket('udp4');
socket.on('listening', common.mustCall(() => {
- common.expectsError(() => {
+ assert.throws(() => {
socket.bind();
}, {
code: 'ERR_SOCKET_ALREADY_BOUND',
- type: Error,
+ name: 'Error',
message: /^Socket is already bound$/
});
diff --git a/test/parallel/test-dgram-createSocket-type.js b/test/parallel/test-dgram-createSocket-type.js
index 9c5a20eaab..ae141d3c38 100644
--- a/test/parallel/test-dgram-createSocket-type.js
+++ b/test/parallel/test-dgram-createSocket-type.js
@@ -23,11 +23,11 @@ const errMessage = /^Bad socket type specified\. Valid types are: udp4, udp6$/;
// Error must be thrown with invalid types
invalidTypes.forEach((invalidType) => {
- common.expectsError(() => {
+ assert.throws(() => {
dgram.createSocket(invalidType);
}, {
code: 'ERR_SOCKET_BAD_TYPE',
- type: TypeError,
+ name: 'TypeError',
message: errMessage
});
});
diff --git a/test/parallel/test-dgram-custom-lookup.js b/test/parallel/test-dgram-custom-lookup.js
index b6dc52bd0b..4f80451c52 100644
--- a/test/parallel/test-dgram-custom-lookup.js
+++ b/test/parallel/test-dgram-custom-lookup.js
@@ -1,5 +1,6 @@
'use strict';
const common = require('../common');
+const assert = require('assert');
const dgram = require('dgram');
const dns = require('dns');
@@ -35,11 +36,11 @@ const dns = require('dns');
{
// Verify that non-functions throw.
[null, true, false, 0, 1, NaN, '', 'foo', {}, Symbol()].forEach((value) => {
- common.expectsError(() => {
+ assert.throws(() => {
dgram.createSocket({ type: 'udp4', lookup: value });
}, {
code: 'ERR_INVALID_ARG_TYPE',
- type: TypeError,
+ name: 'TypeError',
message: 'The "lookup" argument must be of type function.' +
common.invalidArgTypeHelper(value)
});
diff --git a/test/parallel/test-dgram-membership.js b/test/parallel/test-dgram-membership.js
index a852d618c7..ebfdaa9cb6 100644
--- a/test/parallel/test-dgram-membership.js
+++ b/test/parallel/test-dgram-membership.js
@@ -11,11 +11,11 @@ const setup = dgram.createSocket.bind(dgram, { type: 'udp4', reuseAddr: true });
{
const socket = setup();
socket.close(common.mustCall(() => {
- common.expectsError(() => {
+ assert.throws(() => {
socket.addMembership(multicastAddress);
}, {
code: 'ERR_SOCKET_DGRAM_NOT_RUNNING',
- type: Error,
+ name: 'Error',
message: /^Not running$/
});
}));
@@ -25,11 +25,11 @@ const setup = dgram.createSocket.bind(dgram, { type: 'udp4', reuseAddr: true });
{
const socket = setup();
socket.close(common.mustCall(() => {
- common.expectsError(() => {
+ assert.throws(() => {
socket.dropMembership(multicastAddress);
}, {
code: 'ERR_SOCKET_DGRAM_NOT_RUNNING',
- type: Error,
+ name: 'Error',
message: /^Not running$/
});
}));
@@ -38,11 +38,11 @@ const setup = dgram.createSocket.bind(dgram, { type: 'udp4', reuseAddr: true });
// addMembership() with no argument should throw
{
const socket = setup();
- common.expectsError(() => {
+ assert.throws(() => {
socket.addMembership();
}, {
code: 'ERR_MISSING_ARGS',
- type: TypeError,
+ name: 'TypeError',
message: /^The "multicastAddress" argument must be specified$/
});
socket.close();
@@ -51,11 +51,11 @@ const setup = dgram.createSocket.bind(dgram, { type: 'udp4', reuseAddr: true });
// dropMembership() with no argument should throw
{
const socket = setup();
- common.expectsError(() => {
+ assert.throws(() => {
socket.dropMembership();
}, {
code: 'ERR_MISSING_ARGS',
- type: TypeError,
+ name: 'TypeError',
message: /^The "multicastAddress" argument must be specified$/
});
socket.close();
diff --git a/test/parallel/test-dgram-multicast-setTTL.js b/test/parallel/test-dgram-multicast-setTTL.js
index 805b7e344b..756d63c890 100644
--- a/test/parallel/test-dgram-multicast-setTTL.js
+++ b/test/parallel/test-dgram-multicast-setTTL.js
@@ -35,11 +35,11 @@ socket.on('listening', common.mustCall(() => {
socket.setMulticastTTL(1000);
}, /^Error: setMulticastTTL EINVAL$/);
- common.expectsError(() => {
+ assert.throws(() => {
socket.setMulticastTTL('foo');
}, {
code: 'ERR_INVALID_ARG_TYPE',
- type: TypeError,
+ name: 'TypeError',
message: 'The "ttl" argument must be of type number. Received type string' +
" ('foo')"
});
diff --git a/test/parallel/test-dgram-send-bad-arguments.js b/test/parallel/test-dgram-send-bad-arguments.js
index 644ffb3327..ea51a4d165 100644
--- a/test/parallel/test-dgram-send-bad-arguments.js
+++ b/test/parallel/test-dgram-send-bad-arguments.js
@@ -30,11 +30,11 @@ const sock = dgram.createSocket('udp4');
function checkArgs(connected) {
// First argument should be a buffer.
- common.expectsError(
+ assert.throws(
() => { sock.send(); },
{
code: 'ERR_INVALID_ARG_TYPE',
- type: TypeError,
+ name: 'TypeError',
message: 'The "buffer" argument must be of type string or an instance ' +
'of Buffer or Uint8Array. Received undefined'
}
@@ -42,38 +42,38 @@ function checkArgs(connected) {
// send(buf, offset, length, port, host)
if (connected) {
- common.expectsError(
+ assert.throws(
() => { sock.send(buf, 1, 1, -1, host); },
{
code: 'ERR_SOCKET_DGRAM_IS_CONNECTED',
- type: Error,
+ name: 'Error',
message: 'Already connected'
}
);
- common.expectsError(
+ assert.throws(
() => { sock.send(buf, 1, 1, 0, host); },
{
code: 'ERR_SOCKET_DGRAM_IS_CONNECTED',
- type: Error,
+ name: 'Error',
message: 'Already connected'
}
);
- common.expectsError(
+ assert.throws(
() => { sock.send(buf, 1, 1, 65536, host); },
{
code: 'ERR_SOCKET_DGRAM_IS_CONNECTED',
- type: Error,
+ name: 'Error',
message: 'Already connected'
}
);
- common.expectsError(
+ assert.throws(
() => { sock.send(buf, 1234, '127.0.0.1', common.mustNotCall()); },
{
code: 'ERR_SOCKET_DGRAM_IS_CONNECTED',
- type: Error,
+ name: 'Error',
message: 'Already connected'
}
);
@@ -84,22 +84,22 @@ function checkArgs(connected) {
}
// send(buf, port, host)
- common.expectsError(
+ assert.throws(
() => { sock.send(23, 12345, host); },
{
code: 'ERR_INVALID_ARG_TYPE',
- type: TypeError,
+ name: 'TypeError',
message: 'The "buffer" argument must be of type string or an instance ' +
'of Buffer or Uint8Array. Received type number (23)'
}
);
// send([buf1, ..], port, host)
- common.expectsError(
+ assert.throws(
() => { sock.send([buf, 23], 12345, host); },
{
code: 'ERR_INVALID_ARG_TYPE',
- type: TypeError,
+ name: 'TypeError',
message: 'The "buffer list arguments" argument must be of type string ' +
'or an instance of Buffer. Received an instance of Array'
}
diff --git a/test/parallel/test-dgram-setTTL.js b/test/parallel/test-dgram-setTTL.js
index 36af63de10..4252f4b001 100644
--- a/test/parallel/test-dgram-setTTL.js
+++ b/test/parallel/test-dgram-setTTL.js
@@ -9,11 +9,11 @@ socket.on('listening', common.mustCall(() => {
const result = socket.setTTL(16);
assert.strictEqual(result, 16);
- common.expectsError(() => {
+ assert.throws(() => {
socket.setTTL('foo');
}, {
code: 'ERR_INVALID_ARG_TYPE',
- type: TypeError,
+ name: 'TypeError',
message: 'The "ttl" argument must be of type number. Received type string' +
" ('foo')"
});
diff --git a/test/parallel/test-dgram-socket-buffer-size.js b/test/parallel/test-dgram-socket-buffer-size.js
index d3317e85c3..c03b8bf48b 100644
--- a/test/parallel/test-dgram-socket-buffer-size.js
+++ b/test/parallel/test-dgram-socket-buffer-size.js
@@ -5,7 +5,6 @@ const common = require('../common');
const assert = require('assert');
const dgram = require('dgram');
const { inspect } = require('util');
-const { SystemError } = require('internal/errors');
const { internalBinding } = require('internal/test/binding');
const {
UV_EBADF,
@@ -61,7 +60,7 @@ function getExpectedError(type) {
return true;
});
- common.expectsError(() => {
+ assert.throws(() => {
socket.getSendBufferSize();
}, errorObj);
}
@@ -72,11 +71,11 @@ function getExpectedError(type) {
// Should throw error if the socket is never bound.
const errorObj = getExpectedError('recv');
- common.expectsError(() => {
+ assert.throws(() => {
socket.setRecvBufferSize(8192);
}, errorObj);
- common.expectsError(() => {
+ assert.throws(() => {
socket.getRecvBufferSize();
}, errorObj);
}
@@ -85,7 +84,7 @@ function getExpectedError(type) {
// Should throw error if invalid buffer size is specified
const errorObj = {
code: 'ERR_SOCKET_BAD_BUFFER_SIZE',
- type: TypeError,
+ name: 'TypeError',
message: /^Buffer size must be a positive integer$/
};
@@ -95,11 +94,11 @@ function getExpectedError(type) {
socket.bind(common.mustCall(() => {
badBufferSizes.forEach((badBufferSize) => {
- common.expectsError(() => {
+ assert.throws(() => {
socket.setRecvBufferSize(badBufferSize);
}, errorObj);
- common.expectsError(() => {
+ assert.throws(() => {
socket.setSendBufferSize(badBufferSize);
}, errorObj);
});
@@ -132,14 +131,14 @@ function getExpectedError(type) {
};
const errorObj = {
code: 'ERR_SOCKET_BUFFER_SIZE',
- type: SystemError,
+ name: 'SystemError',
message: 'Could not get or set buffer size: uv_recv_buffer_size ' +
'returned EINVAL (invalid argument)',
info
};
const socket = dgram.createSocket('udp4');
socket.bind(common.mustCall(() => {
- common.expectsError(() => {
+ assert.throws(() => {
socket.setRecvBufferSize(2147483648);
}, errorObj);
socket.close();
@@ -155,14 +154,14 @@ function getExpectedError(type) {
};
const errorObj = {
code: 'ERR_SOCKET_BUFFER_SIZE',
- type: SystemError,
+ name: 'SystemError',
message: 'Could not get or set buffer size: uv_send_buffer_size ' +
'returned EINVAL (invalid argument)',
info
};
const socket = dgram.createSocket('udp4');
socket.bind(common.mustCall(() => {
- common.expectsError(() => {
+ assert.throws(() => {
socket.setSendBufferSize(2147483648);
}, errorObj);
socket.close();
diff --git a/test/parallel/test-dns-lookup.js b/test/parallel/test-dns-lookup.js
index 92943fd818..80e13d308d 100644
--- a/test/parallel/test-dns-lookup.js
+++ b/test/parallel/test-dns-lookup.js
@@ -15,12 +15,12 @@ const dnsPromises = dns.promises;
{
const err = {
code: 'ERR_INVALID_ARG_TYPE',
- type: TypeError,
+ name: 'TypeError',
message: /^The "hostname" argument must be of type string\. Received type number/
};
- common.expectsError(() => dns.lookup(1, {}), err);
- common.expectsError(() => dnsPromises.lookup(1, {}), err);
+ assert.throws(() => dns.lookup(1, {}), err);
+ assert.throws(() => dnsPromises.lookup(1, {}), err);
}
// This also verifies different expectWarning notations.
@@ -36,24 +36,24 @@ common.expectWarning({
}
});
-common.expectsError(() => {
+assert.throws(() => {
dns.lookup(false, 'cb');
}, {
code: 'ERR_INVALID_CALLBACK',
- type: TypeError
+ name: 'TypeError'
});
-common.expectsError(() => {
+assert.throws(() => {
dns.lookup(false, 'options', 'cb');
}, {
code: 'ERR_INVALID_CALLBACK',
- type: TypeError
+ name: 'TypeError'
});
{
const err = {
code: 'ERR_INVALID_OPT_VALUE',
- type: TypeError,
+ name: 'TypeError',
message: 'The value "100" is invalid for option "hints"'
};
const options = {
@@ -62,8 +62,8 @@ common.expectsError(() => {
all: false
};
- common.expectsError(() => { dnsPromises.lookup(false, options); }, err);
- common.expectsError(() => {
+ assert.throws(() => { dnsPromises.lookup(false, options); }, err);
+ assert.throws(() => {
dns.lookup(false, options, common.mustNotCall());
}, err);
}
@@ -71,7 +71,7 @@ common.expectsError(() => {
{
const err = {
code: 'ERR_INVALID_OPT_VALUE',
- type: TypeError,
+ name: 'TypeError',
message: 'The value "20" is invalid for option "family"'
};
const options = {
@@ -80,8 +80,8 @@ common.expectsError(() => {
all: false
};
- common.expectsError(() => { dnsPromises.lookup(false, options); }, err);
- common.expectsError(() => {
+ assert.throws(() => { dnsPromises.lookup(false, options); }, err);
+ assert.throws(() => {
dns.lookup(false, options, common.mustNotCall());
}, err);
}
diff --git a/test/parallel/test-dns-resolvens-typeerror.js b/test/parallel/test-dns-resolvens-typeerror.js
index 5a72b54013..54e0da5760 100644
--- a/test/parallel/test-dns-resolvens-typeerror.js
+++ b/test/parallel/test-dns-resolvens-typeerror.js
@@ -20,35 +20,36 @@
// USE OR OTHER DEALINGS IN THE SOFTWARE.
'use strict';
-const common = require('../common');
+require('../common');
// This test ensures `dns.resolveNs()` does not raise a C++-land assertion error
// and throw a JavaScript TypeError instead.
// Issue https://github.com/nodejs/node-v0.x-archive/issues/7070
+const assert = require('assert');
const dns = require('dns');
const dnsPromises = dns.promises;
-common.expectsError(
+assert.throws(
() => dnsPromises.resolveNs([]), // bad name
{
code: 'ERR_INVALID_ARG_TYPE',
- type: TypeError,
+ name: 'TypeError',
message: /^The "name" argument must be of type string/
}
);
-common.expectsError(
+assert.throws(
() => dns.resolveNs([]), // bad name
{
code: 'ERR_INVALID_ARG_TYPE',
- type: TypeError,
+ name: 'TypeError',
message: /^The "name" argument must be of type string/
}
);
-common.expectsError(
+assert.throws(
() => dns.resolveNs(''), // bad callback
{
code: 'ERR_INVALID_CALLBACK',
- type: TypeError
+ name: 'TypeError'
}
);
diff --git a/test/parallel/test-dns-setserver-when-querying.js b/test/parallel/test-dns-setserver-when-querying.js
index 12cb1a1ca2..0432f2d465 100644
--- a/test/parallel/test-dns-setserver-when-querying.js
+++ b/test/parallel/test-dns-setserver-when-querying.js
@@ -2,6 +2,7 @@
const common = require('../common');
+const assert = require('assert');
const dns = require('dns');
const localhost = [ '127.0.0.1' ];
@@ -13,7 +14,7 @@ const localhost = [ '127.0.0.1' ];
const resolver = new dns.Resolver();
resolver.resolve('localhost', common.mustCall());
- common.expectsError(resolver.setServers.bind(resolver, localhost), {
+ assert.throws(resolver.setServers.bind(resolver, localhost), {
code: 'ERR_DNS_SET_SERVERS_FAILED',
message: /^c-ares failed to set servers: "There are pending queries\." \[.+\]$/g
});
diff --git a/test/parallel/test-dns.js b/test/parallel/test-dns.js
index d9143f52d3..0ce318bcd4 100644
--- a/test/parallel/test-dns.js
+++ b/test/parallel/test-dns.js
@@ -96,14 +96,14 @@ const goog = [
];
dns.setServers(goog);
assert.deepStrictEqual(dns.getServers(), goog);
-common.expectsError(() => dns.setServers(['foobar']), {
+assert.throws(() => dns.setServers(['foobar']), {
code: 'ERR_INVALID_IP_ADDRESS',
- type: TypeError,
+ name: 'TypeError',
message: 'Invalid IP address: foobar'
});
-common.expectsError(() => dns.setServers(['127.0.0.1:va']), {
+assert.throws(() => dns.setServers(['127.0.0.1:va']), {
code: 'ERR_INVALID_IP_ADDRESS',
- type: TypeError,
+ name: 'TypeError',
message: 'Invalid IP address: 127.0.0.1:va'
});
assert.deepStrictEqual(dns.getServers(), goog);
@@ -142,36 +142,36 @@ assert.deepStrictEqual(dns.getServers(), []);
{
const errObj = {
code: 'ERR_INVALID_ARG_TYPE',
- type: TypeError,
+ name: 'TypeError',
message: 'The "rrtype" argument must be of type string. ' +
'Received an instance of Array'
};
- common.expectsError(() => {
+ assert.throws(() => {
dns.resolve('example.com', [], common.mustNotCall());
}, errObj);
- common.expectsError(() => {
+ assert.throws(() => {
dnsPromises.resolve('example.com', []);
}, errObj);
}
{
const errObj = {
code: 'ERR_INVALID_ARG_TYPE',
- type: TypeError,
+ name: 'TypeError',
message: 'The "name" argument must be of type string. ' +
'Received undefined'
};
- common.expectsError(() => {
+ assert.throws(() => {
dnsPromises.resolve();
}, errObj);
}
// dns.lookup should accept only falsey and string values
{
- const errorReg = common.expectsError({
+ const errorReg = {
code: 'ERR_INVALID_ARG_TYPE',
- type: TypeError,
+ name: 'TypeError',
message: /^The "hostname" argument must be of type string\. Received .*/
- }, 10);
+ };
assert.throws(() => dns.lookup({}, common.mustNotCall()), errorReg);
@@ -219,26 +219,26 @@ assert.deepStrictEqual(dns.getServers(), []);
const hints = (dns.V4MAPPED | dns.ADDRCONFIG) + 1;
const err = {
code: 'ERR_INVALID_OPT_VALUE',
- type: TypeError,
+ name: 'TypeError',
message: /The value "\d+" is invalid for option "hints"/
};
- common.expectsError(() => {
+ assert.throws(() => {
dnsPromises.lookup('nodejs.org', { hints });
}, err);
- common.expectsError(() => {
+ assert.throws(() => {
dns.lookup('nodejs.org', { hints }, common.mustNotCall());
}, err);
}
-common.expectsError(() => dns.lookup('nodejs.org'), {
+assert.throws(() => dns.lookup('nodejs.org'), {
code: 'ERR_INVALID_CALLBACK',
- type: TypeError
+ name: 'TypeError'
});
-common.expectsError(() => dns.lookup('nodejs.org', 4), {
+assert.throws(() => dns.lookup('nodejs.org', 4), {
code: 'ERR_INVALID_CALLBACK',
- type: TypeError
+ name: 'TypeError'
});
dns.lookup('', { family: 4, hints: 0 }, common.mustCall());
@@ -264,29 +264,29 @@ dns.lookup('', {
{
const err = {
code: 'ERR_MISSING_ARGS',
- type: TypeError,
+ name: 'TypeError',
message: 'The "address", "port", and "callback" arguments must be ' +
'specified'
};
- common.expectsError(() => dns.lookupService('0.0.0.0'), err);
+ assert.throws(() => dns.lookupService('0.0.0.0'), err);
err.message = 'The "address" and "port" arguments must be specified';
- common.expectsError(() => dnsPromises.lookupService('0.0.0.0'), err);
+ assert.throws(() => dnsPromises.lookupService('0.0.0.0'), err);
}
{
const invalidAddress = 'fasdfdsaf';
const err = {
code: 'ERR_INVALID_OPT_VALUE',
- type: TypeError,
+ name: 'TypeError',
message: `The value "${invalidAddress}" is invalid for option "address"`
};
- common.expectsError(() => {
+ assert.throws(() => {
dnsPromises.lookupService(invalidAddress, 0);
}, err);
- common.expectsError(() => {
+ assert.throws(() => {
dns.lookupService(invalidAddress, 0, common.mustNotCall());
}, err);
}
@@ -296,14 +296,14 @@ const portErr = (port) => {
code: 'ERR_SOCKET_BAD_PORT',
message:
`Port should be >= 0 and < 65536. Received ${port}.`,
- type: RangeError
+ name: 'RangeError'
};
- common.expectsError(() => {
+ assert.throws(() => {
dnsPromises.lookupService('0.0.0.0', port);
}, err);
- common.expectsError(() => {
+ assert.throws(() => {
dns.lookupService('0.0.0.0', port, common.mustNotCall());
}, err);
};
@@ -312,11 +312,11 @@ portErr(undefined);
portErr(65538);
portErr('test');
-common.expectsError(() => {
+assert.throws(() => {
dns.lookupService('0.0.0.0', 80, null);
}, {
code: 'ERR_INVALID_CALLBACK',
- type: TypeError
+ name: 'TypeError'
});
{
diff --git a/test/parallel/test-domain-load-after-set-uncaught-exception-capture.js b/test/parallel/test-domain-load-after-set-uncaught-exception-capture.js
index 697d4d3080..4018220711 100644
--- a/test/parallel/test-domain-load-after-set-uncaught-exception-capture.js
+++ b/test/parallel/test-domain-load-after-set-uncaught-exception-capture.js
@@ -1,13 +1,14 @@
'use strict';
const common = require('../common');
+const assert = require('assert');
process.setUncaughtExceptionCaptureCallback(common.mustNotCall());
-common.expectsError(
+assert.throws(
() => require('domain'),
{
code: 'ERR_DOMAIN_CALLBACK_NOT_AVAILABLE',
- type: Error,
+ name: 'Error',
message: /^A callback was registered.*with using the `domain` module/
}
);
diff --git a/test/parallel/test-domain-set-uncaught-exception-capture-after-load.js b/test/parallel/test-domain-set-uncaught-exception-capture-after-load.js
index e7cbffd007..55e2e5368d 100644
--- a/test/parallel/test-domain-set-uncaught-exception-capture-after-load.js
+++ b/test/parallel/test-domain-set-uncaught-exception-capture-after-load.js
@@ -12,7 +12,7 @@ assert.throws(
common.expectsError(
{
code: 'ERR_DOMAIN_CANNOT_SET_UNCAUGHT_EXCEPTION_CAPTURE',
- type: Error,
+ name: 'Error',
message: /^The `domain` module is in use, which is mutually/
}
)(err);
diff --git a/test/parallel/test-eslint-prefer-common-expectserror.js b/test/parallel/test-eslint-prefer-common-expectserror.js
deleted file mode 100644
index 9829b2adb8..0000000000
--- a/test/parallel/test-eslint-prefer-common-expectserror.js
+++ /dev/null
@@ -1,31 +0,0 @@
-'use strict';
-
-const common = require('../common');
-if (!common.hasCrypto)
- common.skip('missing crypto');
-
-common.skipIfEslintMissing();
-
-const RuleTester = require('../../tools/node_modules/eslint').RuleTester;
-const rule = require('../../tools/eslint-rules/prefer-common-expectserror');
-
-const message = 'Please use common.expectsError(fn, err) instead of ' +
- 'assert.throws(fn, common.expectsError(err)).';
-
-new RuleTester().run('prefer-common-expectserror', rule, {
- valid: [
- 'assert.throws(fn, /[a-z]/)',
- 'assert.throws(function () {}, function() {})',
- 'common.expectsError(function() {}, err)'
- ],
- invalid: [
- {
- code: 'assert.throws(function() {}, common.expectsError(err))',
- errors: [{ message }]
- },
- {
- code: 'assert.throws(fn, common.expectsError(err))',
- errors: [{ message }]
- }
- ]
-});
diff --git a/test/parallel/test-event-capture-rejections.js b/test/parallel/test-event-capture-rejections.js
index 83da3184a6..dbe5deeefa 100644
--- a/test/parallel/test-event-capture-rejections.js
+++ b/test/parallel/test-event-capture-rejections.js
@@ -278,14 +278,14 @@ function resetCaptureOnThrowInError() {
function argValidation() {
function testType(obj) {
- common.expectsError(() => new EventEmitter({ captureRejections: obj }), {
+ assert.throws(() => new EventEmitter({ captureRejections: obj }), {
code: 'ERR_INVALID_ARG_TYPE',
- type: TypeError
+ name: 'TypeError'
});
- common.expectsError(() => EventEmitter.captureRejections = obj, {
+ assert.throws(() => EventEmitter.captureRejections = obj, {
code: 'ERR_INVALID_ARG_TYPE',
- type: TypeError
+ name: 'TypeError'
});
}
diff --git a/test/parallel/test-event-emitter-add-listeners.js b/test/parallel/test-event-emitter-add-listeners.js
index d7ebf42438..4b0305c176 100644
--- a/test/parallel/test-event-emitter-add-listeners.js
+++ b/test/parallel/test-event-emitter-add-listeners.js
@@ -86,12 +86,12 @@ const EventEmitter = require('events');
}
// Verify that the listener must be a function
-common.expectsError(() => {
+assert.throws(() => {
const ee = new EventEmitter();
ee.on('foo', null);
}, {
code: 'ERR_INVALID_ARG_TYPE',
- type: TypeError,
+ name: 'TypeError',
message: 'The "listener" argument must be of type function. ' +
'Received null'
});
diff --git a/test/parallel/test-event-emitter-error-monitor.js b/test/parallel/test-event-emitter-error-monitor.js
index ba02839a84..2b22b425b2 100644
--- a/test/parallel/test-event-emitter-error-monitor.js
+++ b/test/parallel/test-event-emitter-error-monitor.js
@@ -14,7 +14,7 @@ EE.on(
);
// Verify with no error listener
-common.expectsError(
+assert.throws(
() => EE.emit('error', theErr), theErr
);
diff --git a/test/parallel/test-event-emitter-errors.js b/test/parallel/test-event-emitter-errors.js
index 13d3a98d9c..0a5e707a61 100644
--- a/test/parallel/test-event-emitter-errors.js
+++ b/test/parallel/test-event-emitter-errors.js
@@ -1,36 +1,37 @@
'use strict';
-const common = require('../common');
+require('../common');
+const assert = require('assert');
const EventEmitter = require('events');
const util = require('util');
const EE = new EventEmitter();
-common.expectsError(
+assert.throws(
() => EE.emit('error', 'Accepts a string'),
{
code: 'ERR_UNHANDLED_ERROR',
- type: Error,
+ name: 'Error',
message: "Unhandled error. ('Accepts a string')"
}
);
-common.expectsError(
+assert.throws(
() => EE.emit('error', { message: 'Error!' }),
{
code: 'ERR_UNHANDLED_ERROR',
- type: Error,
+ name: 'Error',
message: "Unhandled error. ({ message: 'Error!' })"
}
);
-common.expectsError(
+assert.throws(
() => EE.emit('error', {
message: 'Error!',
[util.inspect.custom]() { throw new Error(); }
}),
{
code: 'ERR_UNHANDLED_ERROR',
- type: Error,
+ name: 'Error',
message: 'Unhandled error. ([object Object])'
}
);
diff --git a/test/parallel/test-event-emitter-max-listeners.js b/test/parallel/test-event-emitter-max-listeners.js
index 39b5737fde..d1ac013bfb 100644
--- a/test/parallel/test-event-emitter-max-listeners.js
+++ b/test/parallel/test-event-emitter-max-listeners.js
@@ -21,6 +21,7 @@
'use strict';
const common = require('../common');
+const assert = require('assert');
const events = require('events');
const { inspect } = require('util');
const e = new events.EventEmitter();
@@ -33,21 +34,21 @@ e.setMaxListeners(42);
const throwsObjs = [NaN, -1, 'and even this'];
for (const obj of throwsObjs) {
- common.expectsError(
+ assert.throws(
() => e.setMaxListeners(obj),
{
code: 'ERR_OUT_OF_RANGE',
- type: RangeError,
+ name: 'RangeError',
message: 'The value of "n" is out of range. ' +
`It must be a non-negative number. Received ${inspect(obj)}`
}
);
- common.expectsError(
+ assert.throws(
() => events.defaultMaxListeners = obj,
{
code: 'ERR_OUT_OF_RANGE',
- type: RangeError,
+ name: 'RangeError',
message: 'The value of "defaultMaxListeners" is out of range. ' +
`It must be a non-negative number. Received ${inspect(obj)}`
}
diff --git a/test/parallel/test-event-emitter-once.js b/test/parallel/test-event-emitter-once.js
index 5b74185b12..1ad2de1da5 100644
--- a/test/parallel/test-event-emitter-once.js
+++ b/test/parallel/test-event-emitter-once.js
@@ -50,12 +50,12 @@ e.once('e', common.mustCall());
e.emit('e');
// Verify that the listener must be a function
-common.expectsError(() => {
+assert.throws(() => {
const ee = new EventEmitter();
ee.once('foo', null);
}, {
code: 'ERR_INVALID_ARG_TYPE',
- type: TypeError,
+ name: 'TypeError',
message: 'The "listener" argument must be of type function. ' +
'Received null'
});
diff --git a/test/parallel/test-event-emitter-prepend.js b/test/parallel/test-event-emitter-prepend.js
index 21f381af85..c65b6b8f78 100644
--- a/test/parallel/test-event-emitter-prepend.js
+++ b/test/parallel/test-event-emitter-prepend.js
@@ -19,12 +19,12 @@ myEE.prependOnceListener('foo',
myEE.emit('foo');
// Verify that the listener must be a function
-common.expectsError(() => {
+assert.throws(() => {
const ee = new EventEmitter();
ee.prependOnceListener('foo', null);
}, {
code: 'ERR_INVALID_ARG_TYPE',
- type: TypeError,
+ name: 'TypeError',
message: 'The "listener" argument must be of type function. ' +
'Received null'
});
diff --git a/test/parallel/test-event-emitter-remove-listeners.js b/test/parallel/test-event-emitter-remove-listeners.js
index 97ae403ddd..91e1f07104 100644
--- a/test/parallel/test-event-emitter-remove-listeners.js
+++ b/test/parallel/test-event-emitter-remove-listeners.js
@@ -145,12 +145,12 @@ function listener2() {}
}
// Verify that the removed listener must be a function
-common.expectsError(() => {
+assert.throws(() => {
const ee = new EventEmitter();
ee.removeListener('foo', null);
}, {
code: 'ERR_INVALID_ARG_TYPE',
- type: TypeError,
+ name: 'TypeError',
message: 'The "listener" argument must be of type function. ' +
'Received null'
});
diff --git a/test/parallel/test-file-write-stream.js b/test/parallel/test-file-write-stream.js
index d66657d690..05a2d5432b 100644
--- a/test/parallel/test-file-write-stream.js
+++ b/test/parallel/test-file-write-stream.js
@@ -20,7 +20,7 @@
// USE OR OTHER DEALINGS IN THE SOFTWARE.
'use strict';
-const common = require('../common');
+require('../common');
const assert = require('assert');
const path = require('path');
@@ -65,14 +65,14 @@ file
assert.strictEqual(file.bytesWritten, EXPECTED.length * 2);
callbacks.close++;
- common.expectsError(
+ assert.throws(
() => {
console.error('write after end should not be allowed');
file.write('should not work anymore');
},
{
code: 'ERR_STREAM_WRITE_AFTER_END',
- type: Error,
+ name: 'Error',
message: 'write after end'
}
);
diff --git a/test/parallel/test-file-write-stream3.js b/test/parallel/test-file-write-stream3.js
index 45c431b5d5..c5af446198 100644
--- a/test/parallel/test-file-write-stream3.js
+++ b/test/parallel/test-file-write-stream3.js
@@ -186,9 +186,9 @@ const run_test_4 = common.mustCall(function() {
code: 'ERR_OUT_OF_RANGE',
message: 'The value of "start" is out of range. ' +
'It must be >= 0 and <= 2 ** 53 - 1. Received -5',
- type: RangeError
+ name: 'RangeError'
};
- common.expectsError(fn, err);
+ assert.throws(fn, err);
});
@@ -201,9 +201,9 @@ const run_test_5 = common.mustCall(function() {
code: 'ERR_OUT_OF_RANGE',
message: 'The value of "start" is out of range. It must be ' +
'>= 0 and <= 2 ** 53 - 1. Received 9_007_199_254_740_992',
- type: RangeError
+ name: 'RangeError'
};
- common.expectsError(fn, err);
+ assert.throws(fn, err);
});
run_test_1();
diff --git a/test/parallel/test-fs-access.js b/test/parallel/test-fs-access.js
index 1d281a7ca9..2a431134af 100644
--- a/test/parallel/test-fs-access.js
+++ b/test/parallel/test-fs-access.js
@@ -135,22 +135,22 @@ fs.promises.access(readOnlyFile, fs.F_OK | fs.R_OK)
.catch(throwNextTick);
}
-common.expectsError(
+assert.throws(
() => {
fs.access(__filename, fs.F_OK);
},
{
code: 'ERR_INVALID_CALLBACK',
- type: TypeError
+ name: 'TypeError'
});
-common.expectsError(
+assert.throws(
() => {
fs.access(__filename, fs.F_OK, {});
},
{
code: 'ERR_INVALID_CALLBACK',
- type: TypeError
+ name: 'TypeError'
});
// Regular access should not throw.
diff --git a/test/parallel/test-fs-assert-encoding-error.js b/test/parallel/test-fs-assert-encoding-error.js
index e50a99d751..a25d25852a 100644
--- a/test/parallel/test-fs-assert-encoding-error.js
+++ b/test/parallel/test-fs-assert-encoding-error.js
@@ -4,10 +4,10 @@ const assert = require('assert');
const fs = require('fs');
const options = 'test';
-const expectedError = common.expectsError({
+const expectedError = {
code: 'ERR_INVALID_OPT_VALUE_ENCODING',
- type: TypeError,
-}, 17);
+ name: 'TypeError',
+};
assert.throws(() => {
fs.readFile('path', options, common.mustNotCall());
diff --git a/test/parallel/test-fs-buffer.js b/test/parallel/test-fs-buffer.js
index bad5adea44..d9afbaf7fa 100644
--- a/test/parallel/test-fs-buffer.js
+++ b/test/parallel/test-fs-buffer.js
@@ -18,13 +18,13 @@ fs.open(buf, 'w+', common.mustCall((err, fd) => {
fs.close(fd, common.mustCall(assert.ifError));
}));
-common.expectsError(
+assert.throws(
() => {
fs.accessSync(true);
},
{
code: 'ERR_INVALID_ARG_TYPE',
- type: TypeError,
+ name: 'TypeError',
message: 'The "path" argument must be of type string or an instance of ' +
'Buffer or URL. Received type boolean (true)'
}
diff --git a/test/parallel/test-fs-chmod.js b/test/parallel/test-fs-chmod.js
index 8314c6f73d..36e417c6c4 100644
--- a/test/parallel/test-fs-chmod.js
+++ b/test/parallel/test-fs-chmod.js
@@ -109,11 +109,11 @@ fs.open(file2, 'w', common.mustCall((err, fd) => {
assert.strictEqual(fs.fstatSync(fd).mode & 0o777, mode_async);
}
- common.expectsError(
+ assert.throws(
() => fs.fchmod(fd, {}),
{
code: 'ERR_INVALID_ARG_VALUE',
- type: TypeError,
+ name: 'TypeError',
message: 'The argument \'mode\' must be a 32-bit unsigned integer ' +
'or an octal string. Received {}'
}
diff --git a/test/parallel/test-fs-chown-type-check.js b/test/parallel/test-fs-chown-type-check.js
index 897c3e1de2..0ca78aa86e 100644
--- a/test/parallel/test-fs-chown-type-check.js
+++ b/test/parallel/test-fs-chown-type-check.js
@@ -1,52 +1,53 @@
'use strict';
const common = require('../common');
+const assert = require('assert');
const fs = require('fs');
[false, 1, {}, [], null, undefined].forEach((i) => {
- common.expectsError(
+ assert.throws(
() => fs.chown(i, 1, 1, common.mustNotCall()),
{
code: 'ERR_INVALID_ARG_TYPE',
- type: TypeError
+ name: 'TypeError'
}
);
- common.expectsError(
+ assert.throws(
() => fs.chownSync(i, 1, 1),
{
code: 'ERR_INVALID_ARG_TYPE',
- type: TypeError
+ name: 'TypeError'
}
);
});
[false, 'test', {}, [], null, undefined].forEach((i) => {
- common.expectsError(
+ assert.throws(
() => fs.chown('not_a_file_that_exists', i, 1, common.mustNotCall()),
{
code: 'ERR_INVALID_ARG_TYPE',
- type: TypeError
+ name: 'TypeError'
}
);
- common.expectsError(
+ assert.throws(
() => fs.chown('not_a_file_that_exists', 1, i, common.mustNotCall()),
{
code: 'ERR_INVALID_ARG_TYPE',
- type: TypeError
+ name: 'TypeError'
}
);
- common.expectsError(
+ assert.throws(
() => fs.chownSync('not_a_file_that_exists', i, 1),
{
code: 'ERR_INVALID_ARG_TYPE',
- type: TypeError
+ name: 'TypeError'
}
);
- common.expectsError(
+ assert.throws(
() => fs.chownSync('not_a_file_that_exists', 1, i),
{
code: 'ERR_INVALID_ARG_TYPE',
- type: TypeError
+ name: 'TypeError'
}
);
});
diff --git a/test/parallel/test-fs-copyfile.js b/test/parallel/test-fs-copyfile.js
index 90e7c7009d..ab27ed6684 100644
--- a/test/parallel/test-fs-copyfile.js
+++ b/test/parallel/test-fs-copyfile.js
@@ -101,41 +101,41 @@ fs.copyFile(src, dest, common.mustCall((err) => {
}));
// Throws if callback is not a function.
-common.expectsError(() => {
+assert.throws(() => {
fs.copyFile(src, dest, 0, 0);
}, {
code: 'ERR_INVALID_CALLBACK',
- type: TypeError
+ name: 'TypeError'
});
// Throws if the source path is not a string.
[false, 1, {}, [], null, undefined].forEach((i) => {
- common.expectsError(
+ assert.throws(
() => fs.copyFile(i, dest, common.mustNotCall()),
{
code: 'ERR_INVALID_ARG_TYPE',
- type: TypeError
+ name: 'TypeError'
}
);
- common.expectsError(
+ assert.throws(
() => fs.copyFile(src, i, common.mustNotCall()),
{
code: 'ERR_INVALID_ARG_TYPE',
- type: TypeError
+ name: 'TypeError'
}
);
- common.expectsError(
+ assert.throws(
() => fs.copyFileSync(i, dest),
{
code: 'ERR_INVALID_ARG_TYPE',
- type: TypeError
+ name: 'TypeError'
}
);
- common.expectsError(
+ assert.throws(
() => fs.copyFileSync(src, i),
{
code: 'ERR_INVALID_ARG_TYPE',
- type: TypeError
+ name: 'TypeError'
}
);
});
diff --git a/test/parallel/test-fs-lchmod.js b/test/parallel/test-fs-lchmod.js
index 3b5a51becd..0a740b6504 100644
--- a/test/parallel/test-fs-lchmod.js
+++ b/test/parallel/test-fs-lchmod.js
@@ -21,18 +21,18 @@ assert.throws(() => fs.lchmod(f, {}), { code: 'ERR_INVALID_CALLBACK' });
// Check path
[false, 1, {}, [], null, undefined].forEach((i) => {
- common.expectsError(
+ assert.throws(
() => fs.lchmod(i, 0o777, common.mustNotCall()),
{
code: 'ERR_INVALID_ARG_TYPE',
- type: TypeError
+ name: 'TypeError'
}
);
- common.expectsError(
+ assert.throws(
() => fs.lchmodSync(i),
{
code: 'ERR_INVALID_ARG_TYPE',
- type: TypeError
+ name: 'TypeError'
}
);
});
diff --git a/test/parallel/test-fs-lchown.js b/test/parallel/test-fs-lchown.js
index bf8673c071..a554c8914b 100644
--- a/test/parallel/test-fs-lchown.js
+++ b/test/parallel/test-fs-lchown.js
@@ -9,10 +9,10 @@ const { promises } = fs;
// Validate the path argument.
[false, 1, {}, [], null, undefined].forEach((i) => {
- const err = { type: TypeError, code: 'ERR_INVALID_ARG_TYPE' };
+ const err = { name: 'TypeError', code: 'ERR_INVALID_ARG_TYPE' };
- common.expectsError(() => fs.lchown(i, 1, 1, common.mustNotCall()), err);
- common.expectsError(() => fs.lchownSync(i, 1, 1), err);
+ assert.throws(() => fs.lchown(i, 1, 1, common.mustNotCall()), err);
+ assert.throws(() => fs.lchownSync(i, 1, 1), err);
promises.lchown(false, 1, 1)
.then(common.mustNotCall())
.catch(common.expectsError(err));
@@ -20,18 +20,18 @@ const { promises } = fs;
// Validate the uid and gid arguments.
[false, 'test', {}, [], null, undefined].forEach((i) => {
- const err = { type: TypeError, code: 'ERR_INVALID_ARG_TYPE' };
+ const err = { name: 'TypeError', code: 'ERR_INVALID_ARG_TYPE' };
- common.expectsError(
+ assert.throws(
() => fs.lchown('not_a_file_that_exists', i, 1, common.mustNotCall()),
err
);
- common.expectsError(
+ assert.throws(
() => fs.lchown('not_a_file_that_exists', 1, i, common.mustNotCall()),
err
);
- common.expectsError(() => fs.lchownSync('not_a_file_that_exists', i, 1), err);
- common.expectsError(() => fs.lchownSync('not_a_file_that_exists', 1, i), err);
+ assert.throws(() => fs.lchownSync('not_a_file_that_exists', i, 1), err);
+ assert.throws(() => fs.lchownSync('not_a_file_that_exists', 1, i), err);
promises.lchown('not_a_file_that_exists', i, 1)
.then(common.mustNotCall())
@@ -44,8 +44,8 @@ const { promises } = fs;
// Validate the callback argument.
[false, 1, 'test', {}, [], null, undefined].forEach((i) => {
- common.expectsError(() => fs.lchown('not_a_file_that_exists', 1, 1, i), {
- type: TypeError,
+ assert.throws(() => fs.lchown('not_a_file_that_exists', 1, 1, i), {
+ name: 'TypeError',
code: 'ERR_INVALID_CALLBACK'
});
});
diff --git a/test/parallel/test-fs-link.js b/test/parallel/test-fs-link.js
index f4f3f787d7..ffa0e0bc63 100644
--- a/test/parallel/test-fs-link.js
+++ b/test/parallel/test-fs-link.js
@@ -23,32 +23,32 @@ fs.link(srcPath, dstPath, common.mustCall(callback));
// test error outputs
[false, 1, [], {}, null, undefined].forEach((i) => {
- common.expectsError(
+ assert.throws(
() => fs.link(i, '', common.mustNotCall()),
{
code: 'ERR_INVALID_ARG_TYPE',
- type: TypeError
+ name: 'TypeError'
}
);
- common.expectsError(
+ assert.throws(
() => fs.link('', i, common.mustNotCall()),
{
code: 'ERR_INVALID_ARG_TYPE',
- type: TypeError
+ name: 'TypeError'
}
);
- common.expectsError(
+ assert.throws(
() => fs.linkSync(i, ''),
{
code: 'ERR_INVALID_ARG_TYPE',
- type: TypeError
+ name: 'TypeError'
}
);
- common.expectsError(
+ assert.throws(
() => fs.linkSync('', i),
{
code: 'ERR_INVALID_ARG_TYPE',
- type: TypeError
+ name: 'TypeError'
}
);
});
diff --git a/test/parallel/test-fs-make-callback.js b/test/parallel/test-fs-make-callback.js
index d3ff165513..0cbc4a7fe3 100644
--- a/test/parallel/test-fs-make-callback.js
+++ b/test/parallel/test-fs-make-callback.js
@@ -1,5 +1,6 @@
'use strict';
-const common = require('../common');
+require('../common');
+const assert = require('assert');
const fs = require('fs');
const callbackThrowValues = [null, true, false, 0, 1, 'foo', /foo/, [], {}];
@@ -17,9 +18,9 @@ function testMakeCallback(cb) {
function invalidCallbackThrowsTests() {
callbackThrowValues.forEach((value) => {
- common.expectsError(testMakeCallback(value), {
+ assert.throws(testMakeCallback(value), {
code: 'ERR_INVALID_CALLBACK',
- type: TypeError
+ name: 'TypeError'
});
});
}
diff --git a/test/parallel/test-fs-makeStatsCallback.js b/test/parallel/test-fs-makeStatsCallback.js
index c8de29e407..52d129db2b 100644
--- a/test/parallel/test-fs-makeStatsCallback.js
+++ b/test/parallel/test-fs-makeStatsCallback.js
@@ -1,5 +1,6 @@
'use strict';
const common = require('../common');
+const assert = require('assert');
const fs = require('fs');
const callbackThrowValues = [null, true, false, 0, 1, 'foo', /foo/, [], {}];
@@ -15,9 +16,9 @@ testMakeStatsCallback(common.mustCall())();
function invalidCallbackThrowsTests() {
callbackThrowValues.forEach((value) => {
- common.expectsError(testMakeStatsCallback(value), {
+ assert.throws(testMakeStatsCallback(value), {
code: 'ERR_INVALID_CALLBACK',
- type: TypeError
+ name: 'TypeError'
});
});
}
diff --git a/test/parallel/test-fs-mkdir.js b/test/parallel/test-fs-mkdir.js
index 5e9a2bd75e..8bec37c189 100644
--- a/test/parallel/test-fs-mkdir.js
+++ b/test/parallel/test-fs-mkdir.js
@@ -66,18 +66,18 @@ function nextdir() {
// mkdirSync and mkdir require path to be a string, buffer or url.
// Anything else generates an error.
[false, 1, {}, [], null, undefined].forEach((i) => {
- common.expectsError(
+ assert.throws(
() => fs.mkdir(i, common.mustNotCall()),
{
code: 'ERR_INVALID_ARG_TYPE',
- type: TypeError
+ name: 'TypeError'
}
);
- common.expectsError(
+ assert.throws(
() => fs.mkdirSync(i),
{
code: 'ERR_INVALID_ARG_TYPE',
- type: TypeError
+ name: 'TypeError'
}
);
});
@@ -218,20 +218,20 @@ if (common.isMainThread && (common.isLinux || common.isOSX)) {
const pathname = path.join(tmpdir.path, nextdir());
['', 1, {}, [], null, Symbol('test'), () => {}].forEach((recursive) => {
const received = common.invalidArgTypeHelper(recursive);
- common.expectsError(
+ assert.throws(
() => fs.mkdir(pathname, { recursive }, common.mustNotCall()),
{
code: 'ERR_INVALID_ARG_TYPE',
- type: TypeError,
+ name: 'TypeError',
message: 'The "recursive" argument must be of type boolean.' +
received
}
);
- common.expectsError(
+ assert.throws(
() => fs.mkdirSync(pathname, { recursive }),
{
code: 'ERR_INVALID_ARG_TYPE',
- type: TypeError,
+ name: 'TypeError',
message: 'The "recursive" argument must be of type boolean.' +
received
}
diff --git a/test/parallel/test-fs-mkdtemp-prefix-check.js b/test/parallel/test-fs-mkdtemp-prefix-check.js
index 4573dbbaae..1d9d88232a 100644
--- a/test/parallel/test-fs-mkdtemp-prefix-check.js
+++ b/test/parallel/test-fs-mkdtemp-prefix-check.js
@@ -1,28 +1,29 @@
'use strict';
const common = require('../common');
+const assert = require('assert');
const fs = require('fs');
const prefixValues = [undefined, null, 0, true, false, 1, ''];
function fail(value) {
- common.expectsError(
+ assert.throws(
() => {
fs.mkdtempSync(value, {});
},
{
code: 'ERR_INVALID_ARG_TYPE',
- type: TypeError
+ name: 'TypeError'
});
}
function failAsync(value) {
- common.expectsError(
+ assert.throws(
() => {
fs.mkdtemp(value, common.mustNotCall());
},
{
code: 'ERR_INVALID_ARG_TYPE',
- type: TypeError
+ name: 'TypeError'
});
}
diff --git a/test/parallel/test-fs-non-number-arguments-throw.js b/test/parallel/test-fs-non-number-arguments-throw.js
index 4f85229cf5..a0d533667b 100644
--- a/test/parallel/test-fs-non-number-arguments-throw.js
+++ b/test/parallel/test-fs-non-number-arguments-throw.js
@@ -14,31 +14,31 @@ fs.writeFileSync(tempFile, 'abc\ndef');
const sanity = 'def';
const saneEmitter = fs.createReadStream(tempFile, { start: 4, end: 6 });
-common.expectsError(
+assert.throws(
() => {
fs.createReadStream(tempFile, { start: '4', end: 6 });
},
{
code: 'ERR_INVALID_ARG_TYPE',
- type: TypeError
+ name: 'TypeError'
});
-common.expectsError(
+assert.throws(
() => {
fs.createReadStream(tempFile, { start: 4, end: '6' });
},
{
code: 'ERR_INVALID_ARG_TYPE',
- type: TypeError
+ name: 'TypeError'
});
-common.expectsError(
+assert.throws(
() => {
fs.createWriteStream(tempFile, { start: '4' });
},
{
code: 'ERR_INVALID_ARG_TYPE',
- type: TypeError
+ name: 'TypeError'
});
saneEmitter.on('data', common.mustCall(function(data) {
diff --git a/test/parallel/test-fs-null-bytes.js b/test/parallel/test-fs-null-bytes.js
index 25f74d6e54..beaea00969 100644
--- a/test/parallel/test-fs-null-bytes.js
+++ b/test/parallel/test-fs-null-bytes.js
@@ -30,24 +30,24 @@ function check(async, sync) {
const argsAsync = argsSync.concat(common.mustNotCall());
if (sync) {
- common.expectsError(
+ assert.throws(
() => {
sync.apply(null, argsSync);
},
{
code: 'ERR_INVALID_ARG_VALUE',
- type: TypeError,
+ name: 'TypeError',
});
}
if (async) {
- common.expectsError(
+ assert.throws(
() => {
async.apply(null, argsAsync);
},
{
code: 'ERR_INVALID_ARG_VALUE',
- type: TypeError
+ name: 'TypeError'
});
}
}
diff --git a/test/parallel/test-fs-open-flags.js b/test/parallel/test-fs-open-flags.js
index 62866cfb1b..016363b802 100644
--- a/test/parallel/test-fs-open-flags.js
+++ b/test/parallel/test-fs-open-flags.js
@@ -68,25 +68,25 @@ assert.strictEqual(stringToFlags('sa+'), O_APPEND | O_CREAT | O_RDWR | O_SYNC);
('+ +a +r +w rw wa war raw r++ a++ w++ x +x x+ rx rx+ wxx wax xwx xxx')
.split(' ')
.forEach(function(flags) {
- common.expectsError(
+ assert.throws(
() => stringToFlags(flags),
- { code: 'ERR_INVALID_OPT_VALUE', type: TypeError }
+ { code: 'ERR_INVALID_OPT_VALUE', name: 'TypeError' }
);
});
-common.expectsError(
+assert.throws(
() => stringToFlags({}),
- { code: 'ERR_INVALID_OPT_VALUE', type: TypeError }
+ { code: 'ERR_INVALID_OPT_VALUE', name: 'TypeError' }
);
-common.expectsError(
+assert.throws(
() => stringToFlags(true),
- { code: 'ERR_INVALID_OPT_VALUE', type: TypeError }
+ { code: 'ERR_INVALID_OPT_VALUE', name: 'TypeError' }
);
-common.expectsError(
+assert.throws(
() => stringToFlags(null),
- { code: 'ERR_INVALID_OPT_VALUE', type: TypeError }
+ { code: 'ERR_INVALID_OPT_VALUE', name: 'TypeError' }
);
if (common.isLinux || common.isOSX) {
diff --git a/test/parallel/test-fs-open.js b/test/parallel/test-fs-open.js
index e33c4e9331..c96c435c6c 100644
--- a/test/parallel/test-fs-open.js
+++ b/test/parallel/test-fs-open.js
@@ -65,37 +65,37 @@ async function promise() {
promise().then(common.mustCall()).catch(common.mustNotCall());
-common.expectsError(
+assert.throws(
() => fs.open(__filename, 'r', 'boom', common.mustNotCall()),
{
code: 'ERR_INVALID_ARG_VALUE',
- type: TypeError
+ name: 'TypeError'
}
);
for (const extra of [[], ['r'], ['r', 0], ['r', 0, 'bad callback']]) {
- common.expectsError(
+ assert.throws(
() => fs.open(__filename, ...extra),
{
code: 'ERR_INVALID_CALLBACK',
- type: TypeError
+ name: 'TypeError'
}
);
}
[false, 1, [], {}, null, undefined].forEach((i) => {
- common.expectsError(
+ assert.throws(
() => fs.open(i, 'r', common.mustNotCall()),
{
code: 'ERR_INVALID_ARG_TYPE',
- type: TypeError
+ name: 'TypeError'
}
);
- common.expectsError(
+ assert.throws(
() => fs.openSync(i, 'r', common.mustNotCall()),
{
code: 'ERR_INVALID_ARG_TYPE',
- type: TypeError
+ name: 'TypeError'
}
);
assert.rejects(
diff --git a/test/parallel/test-fs-opendir.js b/test/parallel/test-fs-opendir.js
index abfbb2bb70..733d9c7f3e 100644
--- a/test/parallel/test-fs-opendir.js
+++ b/test/parallel/test-fs-opendir.js
@@ -100,18 +100,18 @@ fs.opendir(__filename, common.mustCall(function(e) {
}));
[false, 1, [], {}, null, undefined].forEach((i) => {
- common.expectsError(
+ assert.throws(
() => fs.opendir(i, common.mustNotCall()),
{
code: 'ERR_INVALID_ARG_TYPE',
- type: TypeError
+ name: 'TypeError'
}
);
- common.expectsError(
+ assert.throws(
() => fs.opendirSync(i),
{
code: 'ERR_INVALID_ARG_TYPE',
- type: TypeError
+ name: 'TypeError'
}
);
});
diff --git a/test/parallel/test-fs-promises.js b/test/parallel/test-fs-promises.js
index a5ced69705..b9d9b36ea8 100644
--- a/test/parallel/test-fs-promises.js
+++ b/test/parallel/test-fs-promises.js
@@ -54,7 +54,7 @@ assert.strictEqual(
.then(common.mustNotCall())
.catch(common.expectsError({
code: 'ENOENT',
- type: Error,
+ name: 'Error',
message:
/^ENOENT: no such file or directory, access/
}));
@@ -203,7 +203,7 @@ async function getHandle(dest) {
// expect it to be ENOSYS
common.expectsError({
code: 'ENOSYS',
- type: Error
+ name: 'Error'
})(err);
}
@@ -243,7 +243,7 @@ async function getHandle(dest) {
lchmod(newLink, newMode),
common.expectsError({
code: 'ERR_METHOD_NOT_IMPLEMENTED',
- type: Error,
+ name: 'Error',
message: 'The lchmod() method is not implemented'
})
)
diff --git a/test/parallel/test-fs-read-file-assert-encoding.js b/test/parallel/test-fs-read-file-assert-encoding.js
index 2640355b56..83aff1b3ac 100644
--- a/test/parallel/test-fs-read-file-assert-encoding.js
+++ b/test/parallel/test-fs-read-file-assert-encoding.js
@@ -1,11 +1,12 @@
'use strict';
const common = require('../common');
+const assert = require('assert');
const fs = require('fs');
const encoding = 'foo-8';
const filename = 'bar.txt';
-common.expectsError(
- fs.readFile.bind(fs, filename, { encoding }, common.mustNotCall()),
- { code: 'ERR_INVALID_OPT_VALUE_ENCODING', type: TypeError }
+assert.throws(
+ () => fs.readFile(filename, { encoding }, common.mustNotCall()),
+ { code: 'ERR_INVALID_OPT_VALUE_ENCODING', name: 'TypeError' }
);
diff --git a/test/parallel/test-fs-read-stream-inherit.js b/test/parallel/test-fs-read-stream-inherit.js
index ef965971dc..5c8bbef0e4 100644
--- a/test/parallel/test-fs-read-stream-inherit.js
+++ b/test/parallel/test-fs-read-stream-inherit.js
@@ -113,14 +113,14 @@ const rangeFile = fixtures.path('x.txt');
'The value of "start" is out of range. It must be <= "end" (here: 2).' +
' Received 10';
- common.expectsError(
+ assert.throws(
() => {
fs.createReadStream(rangeFile, Object.create({ start: 10, end: 2 }));
},
{
code: 'ERR_OUT_OF_RANGE',
message,
- type: RangeError
+ name: 'RangeError'
});
}
diff --git a/test/parallel/test-fs-read-stream-throw-type-error.js b/test/parallel/test-fs-read-stream-throw-type-error.js
index 458df4d347..83b9387cc3 100644
--- a/test/parallel/test-fs-read-stream-throw-type-error.js
+++ b/test/parallel/test-fs-read-stream-throw-type-error.js
@@ -1,6 +1,7 @@
'use strict';
-const common = require('../common');
+require('../common');
const fixtures = require('../common/fixtures');
+const assert = require('assert');
const fs = require('fs');
// This test ensures that appropriate TypeError is thrown by createReadStream
@@ -14,19 +15,19 @@ fs.createReadStream(example, 'utf8');
fs.createReadStream(example, { encoding: 'utf8' });
const createReadStreamErr = (path, opt, error) => {
- common.expectsError(() => {
+ assert.throws(() => {
fs.createReadStream(path, opt);
}, error);
};
const typeError = {
code: 'ERR_INVALID_ARG_TYPE',
- type: TypeError
+ name: 'TypeError'
};
const rangeError = {
code: 'ERR_OUT_OF_RANGE',
- type: RangeError
+ name: 'RangeError'
};
[123, 0, true, false].forEach((opts) =>
diff --git a/test/parallel/test-fs-read-stream.js b/test/parallel/test-fs-read-stream.js
index 05c86f7246..243fc78afc 100644
--- a/test/parallel/test-fs-read-stream.js
+++ b/test/parallel/test-fs-read-stream.js
@@ -152,7 +152,7 @@ test1({
}));
}
-common.expectsError(
+assert.throws(
() => {
fs.createReadStream(rangeFile, { start: 10, end: 2 });
},
@@ -160,7 +160,7 @@ common.expectsError(
code: 'ERR_OUT_OF_RANGE',
message: 'The value of "start" is out of range. It must be <= "end"' +
' (here: 2). Received 10',
- type: RangeError
+ name: 'RangeError'
});
{
diff --git a/test/parallel/test-fs-readdir-stack-overflow.js b/test/parallel/test-fs-readdir-stack-overflow.js
index b7dea52cc3..e35ad87363 100644
--- a/test/parallel/test-fs-readdir-stack-overflow.js
+++ b/test/parallel/test-fs-readdir-stack-overflow.js
@@ -1,7 +1,8 @@
'use strict';
-const common = require('../common');
+require('../common');
+const assert = require('assert');
const fs = require('fs');
function recurse() {
@@ -9,10 +10,10 @@ function recurse() {
recurse();
}
-common.expectsError(
+assert.throws(
() => recurse(),
{
- type: RangeError,
+ name: 'RangeError',
message: 'Maximum call stack size exceeded'
}
);
diff --git a/test/parallel/test-fs-readdir.js b/test/parallel/test-fs-readdir.js
index a24def6f12..bfb88ed93f 100644
--- a/test/parallel/test-fs-readdir.js
+++ b/test/parallel/test-fs-readdir.js
@@ -37,18 +37,18 @@ fs.readdir(__filename, common.mustCall(function(e) {
}));
[false, 1, [], {}, null, undefined].forEach((i) => {
- common.expectsError(
+ assert.throws(
() => fs.readdir(i, common.mustNotCall()),
{
code: 'ERR_INVALID_ARG_TYPE',
- type: TypeError
+ name: 'TypeError'
}
);
- common.expectsError(
+ assert.throws(
() => fs.readdirSync(i),
{
code: 'ERR_INVALID_ARG_TYPE',
- type: TypeError
+ name: 'TypeError'
}
);
});
diff --git a/test/parallel/test-fs-readfile-error.js b/test/parallel/test-fs-readfile-error.js
index 4f0aaf888d..e529ff0b85 100644
--- a/test/parallel/test-fs-readfile-error.js
+++ b/test/parallel/test-fs-readfile-error.js
@@ -56,12 +56,12 @@ test({ NODE_DEBUG: 'fs' }, common.mustCall((data) => {
assert(/test-fs-readfile-error/.test(data));
}));
-common.expectsError(
+assert.throws(
() => { fs.readFile(() => {}, common.mustNotCall()); },
{
code: 'ERR_INVALID_ARG_TYPE',
message: 'The "path" argument must be of type string or an instance of ' +
'Buffer or URL. Received type function ([Function (anonymous)])',
- type: TypeError
+ name: 'TypeError'
}
);
diff --git a/test/parallel/test-fs-readlink-type-check.js b/test/parallel/test-fs-readlink-type-check.js
index 914c1e55af..58d431308c 100644
--- a/test/parallel/test-fs-readlink-type-check.js
+++ b/test/parallel/test-fs-readlink-type-check.js
@@ -1,21 +1,22 @@
'use strict';
const common = require('../common');
+const assert = require('assert');
const fs = require('fs');
[false, 1, {}, [], null, undefined].forEach((i) => {
- common.expectsError(
+ assert.throws(
() => fs.readlink(i, common.mustNotCall()),
{
code: 'ERR_INVALID_ARG_TYPE',
- type: TypeError
+ name: 'TypeError'
}
);
- common.expectsError(
+ assert.throws(
() => fs.readlinkSync(i),
{
code: 'ERR_INVALID_ARG_TYPE',
- type: TypeError
+ name: 'TypeError'
}
);
});
diff --git a/test/parallel/test-fs-realpath.js b/test/parallel/test-fs-realpath.js
index 2642f51842..83b629ef0b 100644
--- a/test/parallel/test-fs-realpath.js
+++ b/test/parallel/test-fs-realpath.js
@@ -220,9 +220,9 @@ function test_cyclic_link_protection(realpath, realpathSync, callback) {
fs.symlinkSync(t[1], t[0], 'dir');
unlink.push(t[0]);
});
- common.expectsError(() => {
+ assert.throws(() => {
realpathSync(entry);
- }, { code: 'ELOOP', type: Error });
+ }, { code: 'ELOOP', name: 'Error' });
asynctest(
realpath, [entry], callback, common.mustCall(function(err, result) {
assert.strictEqual(err.path, entry);
diff --git a/test/parallel/test-fs-rmdir-recursive.js b/test/parallel/test-fs-rmdir-recursive.js
index 628bba5d6f..0d9b9f5707 100644
--- a/test/parallel/test-fs-rmdir-recursive.js
+++ b/test/parallel/test-fs-rmdir-recursive.js
@@ -113,10 +113,10 @@ function removeAsync(dir) {
makeNonEmptyDirectory(4, 10, 2, dir, true);
// Removal should fail without the recursive option set to true.
- common.expectsError(() => {
+ assert.throws(() => {
fs.rmdirSync(dir);
}, { syscall: 'rmdir' });
- common.expectsError(() => {
+ assert.throws(() => {
fs.rmdirSync(dir, { recursive: false });
}, { syscall: 'rmdir' });
@@ -127,7 +127,7 @@ function removeAsync(dir) {
fs.rmdirSync(dir, { recursive: true });
// Attempted removal should fail now because the directory is gone.
- common.expectsError(() => fs.rmdirSync(dir), { syscall: 'rmdir' });
+ assert.throws(() => fs.rmdirSync(dir), { syscall: 'rmdir' });
}
// Test the Promises based version.
@@ -177,38 +177,38 @@ function removeAsync(dir) {
});
[null, 'foo', 5, NaN].forEach((bad) => {
- common.expectsError(() => {
+ assert.throws(() => {
validateRmdirOptions(bad);
}, {
code: 'ERR_INVALID_ARG_TYPE',
- type: TypeError,
+ name: 'TypeError',
message: /^The "options" argument must be of type object\./
});
});
[undefined, null, 'foo', Infinity, function() {}].forEach((bad) => {
- common.expectsError(() => {
+ assert.throws(() => {
validateRmdirOptions({ recursive: bad });
}, {
code: 'ERR_INVALID_ARG_TYPE',
- type: TypeError,
+ name: 'TypeError',
message: /^The "recursive" argument must be of type boolean\./
});
});
- common.expectsError(() => {
+ assert.throws(() => {
validateRmdirOptions({ retryDelay: -1 });
}, {
code: 'ERR_OUT_OF_RANGE',
- type: RangeError,
+ name: 'RangeError',
message: /^The value of "retryDelay" is out of range\./
});
- common.expectsError(() => {
+ assert.throws(() => {
validateRmdirOptions({ maxRetries: -1 });
}, {
code: 'ERR_OUT_OF_RANGE',
- type: RangeError,
+ name: 'RangeError',
message: /^The value of "maxRetries" is out of range\./
});
}
diff --git a/test/parallel/test-fs-rmdir-type-check.js b/test/parallel/test-fs-rmdir-type-check.js
index fc2106b8ca..7014ce27f8 100644
--- a/test/parallel/test-fs-rmdir-type-check.js
+++ b/test/parallel/test-fs-rmdir-type-check.js
@@ -1,21 +1,22 @@
'use strict';
const common = require('../common');
+const assert = require('assert');
const fs = require('fs');
[false, 1, [], {}, null, undefined].forEach((i) => {
- common.expectsError(
+ assert.throws(
() => fs.rmdir(i, common.mustNotCall()),
{
code: 'ERR_INVALID_ARG_TYPE',
- type: TypeError
+ name: 'TypeError'
}
);
- common.expectsError(
+ assert.throws(
() => fs.rmdirSync(i),
{
code: 'ERR_INVALID_ARG_TYPE',
- type: TypeError
+ name: 'TypeError'
}
);
});
diff --git a/test/parallel/test-fs-timestamp-parsing-error.js b/test/parallel/test-fs-timestamp-parsing-error.js
index 4456a86830..1fe0294f68 100644
--- a/test/parallel/test-fs-timestamp-parsing-error.js
+++ b/test/parallel/test-fs-timestamp-parsing-error.js
@@ -1,25 +1,26 @@
'use strict';
-const common = require('../common');
+require('../common');
+const assert = require('assert');
const fs = require('fs');
[Infinity, -Infinity, NaN].forEach((input) => {
- common.expectsError(
+ assert.throws(
() => {
fs._toUnixTimestamp(input);
},
{
code: 'ERR_INVALID_ARG_TYPE',
- type: TypeError
+ name: 'TypeError'
});
});
-common.expectsError(
+assert.throws(
() => {
fs._toUnixTimestamp({});
},
{
code: 'ERR_INVALID_ARG_TYPE',
- type: TypeError
+ name: 'TypeError'
});
const okInputs = [1, -1, '1', '-1', Date.now()];
diff --git a/test/parallel/test-fs-unlink-type-check.js b/test/parallel/test-fs-unlink-type-check.js
index 7fe3ce946c..006e9ad734 100644
--- a/test/parallel/test-fs-unlink-type-check.js
+++ b/test/parallel/test-fs-unlink-type-check.js
@@ -1,21 +1,22 @@
'use strict';
const common = require('../common');
+const assert = require('assert');
const fs = require('fs');
[false, 1, {}, [], null, undefined].forEach((i) => {
- common.expectsError(
+ assert.throws(
() => fs.unlink(i, common.mustNotCall()),
{
code: 'ERR_INVALID_ARG_TYPE',
- type: TypeError
+ name: 'TypeError'
}
);
- common.expectsError(
+ assert.throws(
() => fs.unlinkSync(i),
{
code: 'ERR_INVALID_ARG_TYPE',
- type: TypeError
+ name: 'TypeError'
}
);
});
diff --git a/test/parallel/test-fs-util-validateoffsetlengthwrite.js b/test/parallel/test-fs-util-validateoffsetlengthwrite.js
index f2f80ebdaa..49746b0c5d 100644
--- a/test/parallel/test-fs-util-validateoffsetlengthwrite.js
+++ b/test/parallel/test-fs-util-validateoffsetlengthwrite.js
@@ -1,8 +1,9 @@
// Flags: --expose-internals
'use strict';
-const common = require('../common');
+require('../common');
+const assert = require('assert');
const { validateOffsetLengthWrite } = require('internal/fs/utils');
const { kMaxLength } = require('buffer');
@@ -11,11 +12,11 @@ const { kMaxLength } = require('buffer');
const offset = 100;
const length = 100;
const byteLength = 50;
- common.expectsError(
+ assert.throws(
() => validateOffsetLengthWrite(offset, length, byteLength),
{
code: 'ERR_OUT_OF_RANGE',
- type: RangeError,
+ name: 'RangeError',
message: 'The value of "offset" is out of range. ' +
`It must be <= ${byteLength}. Received ${offset}`
}
@@ -27,11 +28,11 @@ const { kMaxLength } = require('buffer');
const offset = kMaxLength - 150;
const length = 200;
const byteLength = kMaxLength - 100;
- common.expectsError(
+ assert.throws(
() => validateOffsetLengthWrite(offset, length, byteLength),
{
code: 'ERR_OUT_OF_RANGE',
- type: RangeError,
+ name: 'RangeError',
message: 'The value of "length" is out of range. ' +
`It must be <= ${byteLength - offset}. Received ${length}`
}
diff --git a/test/parallel/test-fs-utimes.js b/test/parallel/test-fs-utimes.js
index 0f07715052..fa2ddcbeed 100644
--- a/test/parallel/test-fs-utimes.js
+++ b/test/parallel/test-fs-utimes.js
@@ -173,15 +173,15 @@ if (common.isWindows) {
const expectTypeError = {
code: 'ERR_INVALID_ARG_TYPE',
- type: TypeError
+ name: 'TypeError'
};
// utimes-only error cases
{
- common.expectsError(
+ assert.throws(
() => fs.utimes(0, new Date(), new Date(), common.mustNotCall()),
expectTypeError
);
- common.expectsError(
+ assert.throws(
() => fs.utimesSync(0, new Date(), new Date()),
expectTypeError
);
@@ -189,19 +189,19 @@ const expectTypeError = {
// shared error cases
[false, {}, [], null, undefined].forEach((i) => {
- common.expectsError(
+ assert.throws(
() => fs.utimes(i, new Date(), new Date(), common.mustNotCall()),
expectTypeError
);
- common.expectsError(
+ assert.throws(
() => fs.utimesSync(i, new Date(), new Date()),
expectTypeError
);
- common.expectsError(
+ assert.throws(
() => fs.futimes(i, new Date(), new Date(), common.mustNotCall()),
expectTypeError
);
- common.expectsError(
+ assert.throws(
() => fs.futimesSync(i, new Date(), new Date()),
expectTypeError
);
@@ -209,17 +209,17 @@ const expectTypeError = {
const expectRangeError = {
code: 'ERR_OUT_OF_RANGE',
- type: RangeError,
+ name: 'RangeError',
message: 'The value of "fd" is out of range. ' +
'It must be >= 0 && <= 2147483647. Received -1'
};
// futimes-only error cases
{
- common.expectsError(
+ assert.throws(
() => fs.futimes(-1, new Date(), new Date(), common.mustNotCall()),
expectRangeError
);
- common.expectsError(
+ assert.throws(
() => fs.futimesSync(-1, new Date(), new Date()),
expectRangeError
);
diff --git a/test/parallel/test-fs-watch.js b/test/parallel/test-fs-watch.js
index abfb7be2d5..496cff90dc 100644
--- a/test/parallel/test-fs-watch.js
+++ b/test/parallel/test-fs-watch.js
@@ -88,11 +88,11 @@ for (const testCase of cases) {
}
[false, 1, {}, [], null, undefined].forEach((input) => {
- common.expectsError(
+ assert.throws(
() => fs.watch(input, common.mustNotCall()),
{
code: 'ERR_INVALID_ARG_TYPE',
- type: TypeError
+ name: 'TypeError'
}
);
});
diff --git a/test/parallel/test-fs-watchfile.js b/test/parallel/test-fs-watchfile.js
index 7b3ad4a26d..4e5af9d77b 100644
--- a/test/parallel/test-fs-watchfile.js
+++ b/test/parallel/test-fs-watchfile.js
@@ -8,27 +8,27 @@ const path = require('path');
const tmpdir = require('../common/tmpdir');
// Basic usage tests.
-common.expectsError(
+assert.throws(
() => {
fs.watchFile('./some-file');
},
{
code: 'ERR_INVALID_ARG_TYPE',
- type: TypeError
+ name: 'TypeError'
});
-common.expectsError(
+assert.throws(
() => {
fs.watchFile('./another-file', {}, 'bad listener');
},
{
code: 'ERR_INVALID_ARG_TYPE',
- type: TypeError
+ name: 'TypeError'
});
-common.expectsError(function() {
+assert.throws(() => {
fs.watchFile(new Object(), common.mustNotCall());
-}, { code: 'ERR_INVALID_ARG_TYPE', type: TypeError });
+}, { code: 'ERR_INVALID_ARG_TYPE', name: 'TypeError' });
const enoentFile = path.join(tmpdir.path, 'non-existent-file');
const expectedStatObject = new fs.Stats(
diff --git a/test/parallel/test-fs-whatwg-url.js b/test/parallel/test-fs-whatwg-url.js
index 377f6d010c..f12e3ae37e 100644
--- a/test/parallel/test-fs-whatwg-url.js
+++ b/test/parallel/test-fs-whatwg-url.js
@@ -30,13 +30,13 @@ fs.readFile(url, common.mustCall((err, data) => {
// Check that using a non file:// URL reports an error
const httpUrl = new URL('http://example.org');
-common.expectsError(
+assert.throws(
() => {
fs.readFile(httpUrl, common.mustNotCall());
},
{
code: 'ERR_INVALID_URL_SCHEME',
- type: TypeError,
+ name: 'TypeError',
message: 'The URL must be of scheme file'
});
@@ -44,24 +44,24 @@ common.expectsError(
if (common.isWindows) {
// Encoded back and forward slashes are not permitted on windows
['%2f', '%2F', '%5c', '%5C'].forEach((i) => {
- common.expectsError(
+ assert.throws(
() => {
fs.readFile(new URL(`file:///c:/tmp/${i}`), common.mustNotCall());
},
{
code: 'ERR_INVALID_FILE_URL_PATH',
- type: TypeError,
+ name: 'TypeError',
message: 'File URL path must not include encoded \\ or / characters'
}
);
});
- common.expectsError(
+ assert.throws(
() => {
fs.readFile(new URL('file:///c:/tmp/%00test'), common.mustNotCall());
},
{
code: 'ERR_INVALID_ARG_VALUE',
- type: TypeError,
+ name: 'TypeError',
message: 'The argument \'path\' must be a string or Uint8Array without ' +
"null bytes. Received 'c:\\\\tmp\\\\\\x00test'"
}
@@ -69,33 +69,33 @@ if (common.isWindows) {
} else {
// Encoded forward slashes are not permitted on other platforms
['%2f', '%2F'].forEach((i) => {
- common.expectsError(
+ assert.throws(
() => {
fs.readFile(new URL(`file:///c:/tmp/${i}`), common.mustNotCall());
},
{
code: 'ERR_INVALID_FILE_URL_PATH',
- type: TypeError,
+ name: 'TypeError',
message: 'File URL path must not include encoded / characters'
});
});
- common.expectsError(
+ assert.throws(
() => {
fs.readFile(new URL('file://hostname/a/b/c'), common.mustNotCall());
},
{
code: 'ERR_INVALID_FILE_URL_HOST',
- type: TypeError,
+ name: 'TypeError',
message: `File URL host must be "localhost" or empty on ${os.platform()}`
}
);
- common.expectsError(
+ assert.throws(
() => {
fs.readFile(new URL('file:///tmp/%00test'), common.mustNotCall());
},
{
code: 'ERR_INVALID_ARG_VALUE',
- type: TypeError,
+ name: 'TypeError',
message: "The argument 'path' must be a string or Uint8Array without " +
"null bytes. Received '/tmp/\\x00test'"
}
diff --git a/test/parallel/test-fs-write-stream-throw-type-error.js b/test/parallel/test-fs-write-stream-throw-type-error.js
index 9a3d1cf16d..77d546a61a 100644
--- a/test/parallel/test-fs-write-stream-throw-type-error.js
+++ b/test/parallel/test-fs-write-stream-throw-type-error.js
@@ -1,5 +1,6 @@
'use strict';
-const common = require('../common');
+require('../common');
+const assert = require('assert');
const fs = require('fs');
const path = require('path');
@@ -15,13 +16,13 @@ fs.createWriteStream(example, 'utf8').end();
fs.createWriteStream(example, { encoding: 'utf8' }).end();
const createWriteStreamErr = (path, opt) => {
- common.expectsError(
+ assert.throws(
() => {
fs.createWriteStream(path, opt);
},
{
code: 'ERR_INVALID_ARG_TYPE',
- type: TypeError
+ name: 'TypeError'
});
};
diff --git a/test/parallel/test-fs-write-stream.js b/test/parallel/test-fs-write-stream.js
index 18374f44eb..f84b727c86 100644
--- a/test/parallel/test-fs-write-stream.js
+++ b/test/parallel/test-fs-write-stream.js
@@ -58,11 +58,11 @@ tmpdir.refresh();
const stream = fs.createWriteStream(file);
stream.on('error', common.expectsError({
code: 'ERR_INVALID_ARG_TYPE',
- type: TypeError
+ name: 'TypeError'
}));
stream.write(42, null, common.expectsError({
code: 'ERR_INVALID_ARG_TYPE',
- type: TypeError
+ name: 'TypeError'
}));
stream.destroy();
}
diff --git a/test/parallel/test-fs-write.js b/test/parallel/test-fs-write.js
index d75974b58d..39a0f3720e 100644
--- a/test/parallel/test-fs-write.js
+++ b/test/parallel/test-fs-write.js
@@ -135,18 +135,18 @@ fs.open(fn3, 'w', 0o644, common.mustCall((err, fd) => {
}));
[false, 'test', {}, [], null, undefined].forEach((i) => {
- common.expectsError(
+ assert.throws(
() => fs.write(i, common.mustNotCall()),
{
code: 'ERR_INVALID_ARG_TYPE',
- type: TypeError
+ name: 'TypeError'
}
);
- common.expectsError(
+ assert.throws(
() => fs.writeSync(i),
{
code: 'ERR_INVALID_ARG_TYPE',
- type: TypeError
+ name: 'TypeError'
}
);
});
diff --git a/test/parallel/test-fs-writev-sync.js b/test/parallel/test-fs-writev-sync.js
index a60115113b..b01e85bcae 100644
--- a/test/parallel/test-fs-writev-sync.js
+++ b/test/parallel/test-fs-writev-sync.js
@@ -1,6 +1,6 @@
'use strict';
-const common = require('../common');
+require('../common');
const assert = require('assert');
const path = require('path');
const fs = require('fs');
@@ -64,10 +64,10 @@ const getFileName = (i) => path.join(tmpdir.path, `writev_sync_${i}.txt`);
const fd = fs.openSync(filename, 'w');
[false, 'test', {}, [{}], ['sdf'], null, undefined].forEach((i) => {
- common.expectsError(
+ assert.throws(
() => fs.writevSync(fd, i, null), {
code: 'ERR_INVALID_ARG_TYPE',
- type: TypeError
+ name: 'TypeError'
}
);
});
@@ -77,11 +77,11 @@ const getFileName = (i) => path.join(tmpdir.path, `writev_sync_${i}.txt`);
// fs.writevSync with wrong fd types
[false, 'test', {}, [{}], null, undefined].forEach((i) => {
- common.expectsError(
+ assert.throws(
() => fs.writevSync(i),
{
code: 'ERR_INVALID_ARG_TYPE',
- type: TypeError
+ name: 'TypeError'
}
);
});
diff --git a/test/parallel/test-fs-writev.js b/test/parallel/test-fs-writev.js
index 6a66c631f9..5a32bb7ac9 100644
--- a/test/parallel/test-fs-writev.js
+++ b/test/parallel/test-fs-writev.js
@@ -69,10 +69,10 @@ const getFileName = (i) => path.join(tmpdir.path, `writev_${i}.txt`);
const fd = fs.openSync(filename, 'w');
[false, 'test', {}, [{}], ['sdf'], null, undefined].forEach((i) => {
- common.expectsError(
+ assert.throws(
() => fs.writev(fd, i, null, common.mustNotCall()), {
code: 'ERR_INVALID_ARG_TYPE',
- type: TypeError
+ name: 'TypeError'
}
);
});
@@ -82,11 +82,11 @@ const getFileName = (i) => path.join(tmpdir.path, `writev_${i}.txt`);
// fs.writev with wrong fd types
[false, 'test', {}, [{}], null, undefined].forEach((i) => {
- common.expectsError(
+ assert.throws(
() => fs.writev(i, common.mustNotCall()),
{
code: 'ERR_INVALID_ARG_TYPE',
- type: TypeError
+ name: 'TypeError'
}
);
});
diff --git a/test/parallel/test-http-client-check-http-token.js b/test/parallel/test-http-client-check-http-token.js
index 5a5ec2fb95..d09fbe1b8e 100644
--- a/test/parallel/test-http-client-check-http-token.js
+++ b/test/parallel/test-http-client-check-http-token.js
@@ -1,5 +1,6 @@
'use strict';
const common = require('../common');
+const assert = require('assert');
const http = require('http');
const Countdown = require('../common/countdown');
@@ -17,11 +18,11 @@ const server = http.createServer(common.mustCall((req, res) => {
server.listen(0, common.mustCall(() => {
expectedFails.forEach((method) => {
- common.expectsError(() => {
+ assert.throws(() => {
http.request({ method, path: '/' }, common.mustNotCall());
}, {
code: 'ERR_INVALID_ARG_TYPE',
- type: TypeError,
+ name: 'TypeError',
message: 'The "method" argument must be of type string.' +
common.invalidArgTypeHelper(method)
});
diff --git a/test/parallel/test-http-client-invalid-path.js b/test/parallel/test-http-client-invalid-path.js
index c042d61eda..c8d1fec18f 100644
--- a/test/parallel/test-http-client-invalid-path.js
+++ b/test/parallel/test-http-client-invalid-path.js
@@ -1,12 +1,13 @@
'use strict';
-const common = require('../common');
+require('../common');
+const assert = require('assert');
const http = require('http');
-common.expectsError(() => {
+assert.throws(() => {
http.request({
path: '/thisisinvalid\uffe2'
}).end();
}, {
code: 'ERR_UNESCAPED_CHARACTERS',
- type: TypeError
+ name: 'TypeError'
});
diff --git a/test/parallel/test-http-client-reject-unexpected-agent.js b/test/parallel/test-http-client-reject-unexpected-agent.js
index 664fb49310..8ec6506888 100644
--- a/test/parallel/test-http-client-reject-unexpected-agent.js
+++ b/test/parallel/test-http-client-reject-unexpected-agent.js
@@ -47,11 +47,11 @@ server.listen(0, baseOptions.host, common.mustCall(function() {
baseOptions.port = this.address().port;
failingAgentOptions.forEach((agent) => {
- common.expectsError(
+ assert.throws(
() => createRequest(agent),
{
code: 'ERR_INVALID_ARG_TYPE',
- type: TypeError,
+ name: 'TypeError',
message: 'The "options.agent" property must be one of Agent-like ' +
'Object, undefined, or false.' +
common.invalidArgTypeHelper(agent)
diff --git a/test/parallel/test-http-client-set-timeout.js b/test/parallel/test-http-client-set-timeout.js
index 15aae7023b..7717b7d606 100644
--- a/test/parallel/test-http-client-set-timeout.js
+++ b/test/parallel/test-http-client-set-timeout.js
@@ -32,7 +32,7 @@ server.listen(0, mustCall(() => {
}));
req.on('error', expectsError({
- type: Error,
+ name: 'Error',
code: 'ECONNRESET',
message: 'socket hang up'
}));
diff --git a/test/parallel/test-http-client-unescaped-path.js b/test/parallel/test-http-client-unescaped-path.js
index 6d5a945dd5..93b2f540f1 100644
--- a/test/parallel/test-http-client-unescaped-path.js
+++ b/test/parallel/test-http-client-unescaped-path.js
@@ -21,15 +21,16 @@
'use strict';
const common = require('../common');
+const assert = require('assert');
const http = require('http');
for (let i = 0; i <= 32; i += 1) {
const path = `bad${String.fromCharCode(i)}path`;
- common.expectsError(
+ assert.throws(
() => http.get({ path }, common.mustNotCall()),
{
code: 'ERR_UNESCAPED_CHARACTERS',
- type: TypeError,
+ name: 'TypeError',
message: 'Request path contains unescaped characters'
}
);
diff --git a/test/parallel/test-http-header-overflow.js b/test/parallel/test-http-header-overflow.js
index 1d39a7fd8b..e53f5f05f8 100644
--- a/test/parallel/test-http-header-overflow.js
+++ b/test/parallel/test-http-header-overflow.js
@@ -25,7 +25,7 @@ server.on('connection', mustCall((socket) => {
// This discripancy is not fixed on purpose.
const legacy = getOptionValue('--http-parser') === 'legacy';
socket.on('error', expectsError({
- type: Error,
+ name: 'Error',
message: 'Parse Error: Header overflow',
code: 'HPE_HEADER_OVERFLOW',
bytesParsed: maxHeaderSize + PAYLOAD_GET.length - (legacy ? -1 : 0),
diff --git a/test/parallel/test-http-hostname-typechecking.js b/test/parallel/test-http-hostname-typechecking.js
index 6ec6b7d627..bcb175ee34 100644
--- a/test/parallel/test-http-hostname-typechecking.js
+++ b/test/parallel/test-http-hostname-typechecking.js
@@ -1,6 +1,7 @@
'use strict';
const common = require('../common');
+const assert = require('assert');
const http = require('http');
// All of these values should cause http.request() to throw synchronously
@@ -9,22 +10,22 @@ const vals = [{}, [], NaN, Infinity, -Infinity, true, false, 1, 0, new Date()];
vals.forEach((v) => {
const received = common.invalidArgTypeHelper(v);
- common.expectsError(
+ assert.throws(
() => http.request({ hostname: v }),
{
code: 'ERR_INVALID_ARG_TYPE',
- type: TypeError,
+ name: 'TypeError',
message: 'The "options.hostname" property must be of ' +
'type string or one of undefined or null.' +
received
}
);
- common.expectsError(
+ assert.throws(
() => http.request({ host: v }),
{
code: 'ERR_INVALID_ARG_TYPE',
- type: TypeError,
+ name: 'TypeError',
message: 'The "options.host" property must be of ' +
'type string or one of undefined or null.' +
received
diff --git a/test/parallel/test-http-invalid-path-chars.js b/test/parallel/test-http-invalid-path-chars.js
index c1d0baa62c..56755faa8c 100644
--- a/test/parallel/test-http-invalid-path-chars.js
+++ b/test/parallel/test-http-invalid-path-chars.js
@@ -1,25 +1,20 @@
'use strict';
-const common = require('../common');
+require('../common');
const assert = require('assert');
const http = require('http');
-const expectedError = common.expectsError({
- code: 'ERR_UNESCAPED_CHARACTERS',
- type: TypeError,
- message: 'Request path contains unescaped characters'
-}, 1320);
const theExperimentallyDeterminedNumber = 39;
-function fail(path) {
- assert.throws(() => {
- http.request({ path }, assert.fail);
- }, expectedError);
-}
-
for (let i = 0; i <= theExperimentallyDeterminedNumber; i++) {
const prefix = 'a'.repeat(i);
for (let i = 0; i <= 32; i++) {
- fail(prefix + String.fromCodePoint(i));
+ assert.throws(() => {
+ http.request({ path: prefix + String.fromCodePoint(i) }, assert.fail);
+ }, {
+ code: 'ERR_UNESCAPED_CHARACTERS',
+ name: 'TypeError',
+ message: 'Request path contains unescaped characters'
+ });
}
}
diff --git a/test/parallel/test-http-invalid-urls.js b/test/parallel/test-http-invalid-urls.js
index 7c9f67c473..a30c3eb5f6 100644
--- a/test/parallel/test-http-invalid-urls.js
+++ b/test/parallel/test-http-invalid-urls.js
@@ -4,6 +4,7 @@
const common = require('../common');
+const assert = require('assert');
const http = require('http');
const modules = { 'http': http };
@@ -19,8 +20,8 @@ function test(host) {
`${module}.${fn} should not connect to ${host}`
);
const throws = () => { modules[module][fn](host, doNotCall); };
- common.expectsError(throws, {
- type: TypeError,
+ assert.throws(throws, {
+ name: 'TypeError',
code: 'ERR_INVALID_URL'
});
});
diff --git a/test/parallel/test-http-mutable-headers.js b/test/parallel/test-http-mutable-headers.js
index b4e4018e1d..c9f63acf44 100644
--- a/test/parallel/test-http-mutable-headers.js
+++ b/test/parallel/test-http-mutable-headers.js
@@ -50,36 +50,36 @@ const s = http.createServer(common.mustCall((req, res) => {
assert.deepStrictEqual(res.hasHeader('Connection'), false);
assert.deepStrictEqual(res.getHeader('Connection'), undefined);
- common.expectsError(
+ assert.throws(
() => res.setHeader(),
{
code: 'ERR_INVALID_HTTP_TOKEN',
- type: TypeError,
+ name: 'TypeError',
message: 'Header name must be a valid HTTP token ["undefined"]'
}
);
- common.expectsError(
+ assert.throws(
() => res.setHeader('someHeader'),
{
code: 'ERR_HTTP_INVALID_HEADER_VALUE',
- type: TypeError,
+ name: 'TypeError',
message: 'Invalid value "undefined" for header "someHeader"'
}
);
- common.expectsError(
+ assert.throws(
() => res.getHeader(),
{
code: 'ERR_INVALID_ARG_TYPE',
- type: TypeError,
+ name: 'TypeError',
message: 'The "name" argument must be of type string. ' +
'Received undefined'
}
);
- common.expectsError(
+ assert.throws(
() => res.removeHeader(),
{
code: 'ERR_INVALID_ARG_TYPE',
- type: TypeError,
+ name: 'TypeError',
message: 'The "name" argument must be of type string. ' +
'Received undefined'
}
@@ -119,11 +119,11 @@ const s = http.createServer(common.mustCall((req, res) => {
{ toString: () => 'X-TEST-HEADER2' },
() => { }
].forEach((val) => {
- common.expectsError(
+ assert.throws(
() => res.hasHeader(val),
{
code: 'ERR_INVALID_ARG_TYPE',
- type: TypeError,
+ name: 'TypeError',
message: 'The "name" argument must be of type string.' +
common.invalidArgTypeHelper(val)
}
diff --git a/test/parallel/test-http-outgoing-proto.js b/test/parallel/test-http-outgoing-proto.js
index 0f428b9546..b037c88c68 100644
--- a/test/parallel/test-http-outgoing-proto.js
+++ b/test/parallel/test-http-outgoing-proto.js
@@ -13,48 +13,48 @@ assert.strictEqual(
typeof ServerResponse.prototype._implicitHeader, 'function');
// validateHeader
-common.expectsError(() => {
+assert.throws(() => {
const outgoingMessage = new OutgoingMessage();
outgoingMessage.setHeader();
}, {
code: 'ERR_INVALID_HTTP_TOKEN',
- type: TypeError,
+ name: 'TypeError',
message: 'Header name must be a valid HTTP token ["undefined"]'
});
-common.expectsError(() => {
+assert.throws(() => {
const outgoingMessage = new OutgoingMessage();
outgoingMessage.setHeader('test');
}, {
code: 'ERR_HTTP_INVALID_HEADER_VALUE',
- type: TypeError,
+ name: 'TypeError',
message: 'Invalid value "undefined" for header "test"'
});
-common.expectsError(() => {
+assert.throws(() => {
const outgoingMessage = new OutgoingMessage();
outgoingMessage.setHeader(404);
}, {
code: 'ERR_INVALID_HTTP_TOKEN',
- type: TypeError,
+ name: 'TypeError',
message: 'Header name must be a valid HTTP token ["404"]'
});
-common.expectsError(() => {
+assert.throws(() => {
const outgoingMessage = new OutgoingMessage();
outgoingMessage.setHeader.call({ _header: 'test' }, 'test', 'value');
}, {
code: 'ERR_HTTP_HEADERS_SENT',
- type: Error,
+ name: 'Error',
message: 'Cannot set headers after they are sent to the client'
});
-common.expectsError(() => {
+assert.throws(() => {
const outgoingMessage = new OutgoingMessage();
outgoingMessage.setHeader('200', 'あ');
}, {
code: 'ERR_INVALID_CHAR',
- type: TypeError,
+ name: 'TypeError',
message: 'Invalid character in header content ["200"]'
});
@@ -64,7 +64,7 @@ common.expectsError(() => {
outgoingMessage.on('error', common.expectsError({
code: 'ERR_METHOD_NOT_IMPLEMENTED',
- type: Error,
+ name: 'Error',
message: 'The _implicitHeader() method is not implemented'
}));
@@ -73,22 +73,22 @@ common.expectsError(() => {
assert(OutgoingMessage.prototype.write.call({ _header: 'test' }));
-common.expectsError(() => {
+assert.throws(() => {
const outgoingMessage = new OutgoingMessage();
outgoingMessage.write.call({ _header: 'test', _hasBody: 'test' });
}, {
code: 'ERR_INVALID_ARG_TYPE',
- type: TypeError,
+ name: 'TypeError',
message: 'The first argument must be of type string or an instance of ' +
'Buffer. Received undefined'
});
-common.expectsError(() => {
+assert.throws(() => {
const outgoingMessage = new OutgoingMessage();
outgoingMessage.write.call({ _header: 'test', _hasBody: 'test' }, 1);
}, {
code: 'ERR_INVALID_ARG_TYPE',
- type: TypeError,
+ name: 'TypeError',
message: 'The first argument must be of type string or an instance of ' +
'Buffer. Received type number (1)'
});
@@ -102,20 +102,20 @@ assert.throws(() => {
outgoingMessage.addTrailers();
}, TypeError);
-common.expectsError(() => {
+assert.throws(() => {
const outgoingMessage = new OutgoingMessage();
outgoingMessage.addTrailers({ 'あ': 'value' });
}, {
code: 'ERR_INVALID_HTTP_TOKEN',
- type: TypeError,
+ name: 'TypeError',
message: 'Trailer name must be a valid HTTP token ["あ"]'
});
-common.expectsError(() => {
+assert.throws(() => {
const outgoingMessage = new OutgoingMessage();
outgoingMessage.addTrailers({ 404: 'あ' });
}, {
code: 'ERR_INVALID_CHAR',
- type: TypeError,
+ name: 'TypeError',
message: 'Invalid character in trailer content ["404"]'
});
diff --git a/test/parallel/test-http-outgoing-renderHeaders.js b/test/parallel/test-http-outgoing-renderHeaders.js
index c3da1f240d..fa2de859cf 100644
--- a/test/parallel/test-http-outgoing-renderHeaders.js
+++ b/test/parallel/test-http-outgoing-renderHeaders.js
@@ -1,7 +1,7 @@
'use strict';
// Flags: --expose-internals
-const common = require('../common');
+require('../common');
const assert = require('assert');
const kOutHeaders = require('internal/http').kOutHeaders;
@@ -11,11 +11,11 @@ const OutgoingMessage = http.OutgoingMessage;
{
const outgoingMessage = new OutgoingMessage();
outgoingMessage._header = {};
- common.expectsError(
- outgoingMessage._renderHeaders.bind(outgoingMessage),
+ assert.throws(
+ () => outgoingMessage._renderHeaders(),
{
code: 'ERR_HTTP_HEADERS_SENT',
- type: Error,
+ name: 'Error',
message: 'Cannot render headers after they are sent to the client'
}
);
diff --git a/test/parallel/test-http-request-invalid-method-error.js b/test/parallel/test-http-request-invalid-method-error.js
index ae11985e12..20897f0891 100644
--- a/test/parallel/test-http-request-invalid-method-error.js
+++ b/test/parallel/test-http-request-invalid-method-error.js
@@ -1,12 +1,13 @@
'use strict';
-const common = require('../common');
+require('../common');
+const assert = require('assert');
const http = require('http');
-common.expectsError(
+assert.throws(
() => http.request({ method: '\0' }),
{
code: 'ERR_INVALID_HTTP_TOKEN',
- type: TypeError,
+ name: 'TypeError',
message: 'Method must be a valid HTTP token ["\u0000"]'
}
);
diff --git a/test/parallel/test-http-res-write-after-end.js b/test/parallel/test-http-res-write-after-end.js
index bf6b7a3842..70325975c4 100644
--- a/test/parallel/test-http-res-write-after-end.js
+++ b/test/parallel/test-http-res-write-after-end.js
@@ -27,7 +27,7 @@ const http = require('http');
const server = http.Server(common.mustCall(function(req, res) {
res.on('error', common.expectsError({
code: 'ERR_STREAM_WRITE_AFTER_END',
- type: Error
+ name: 'Error'
}));
res.write('This should write.');
diff --git a/test/parallel/test-http-response-add-header-after-sent.js b/test/parallel/test-http-response-add-header-after-sent.js
index a4d3f629e2..27dc47529f 100644
--- a/test/parallel/test-http-response-add-header-after-sent.js
+++ b/test/parallel/test-http-response-add-header-after-sent.js
@@ -1,15 +1,16 @@
'use strict';
-const common = require('../common');
+require('../common');
+const assert = require('assert');
const http = require('http');
const server = http.createServer((req, res) => {
res.setHeader('header1', 1);
res.write('abc');
- common.expectsError(
+ assert.throws(
() => res.setHeader('header2', 2),
{
code: 'ERR_HTTP_HEADERS_SENT',
- type: Error,
+ name: 'Error',
message: 'Cannot set headers after they are sent to the client'
}
);
diff --git a/test/parallel/test-http-response-remove-header-after-sent.js b/test/parallel/test-http-response-remove-header-after-sent.js
index 52acd3d105..b5c0defac9 100644
--- a/test/parallel/test-http-response-remove-header-after-sent.js
+++ b/test/parallel/test-http-response-remove-header-after-sent.js
@@ -1,15 +1,16 @@
'use strict';
-const common = require('../common');
+require('../common');
+const assert = require('assert');
const http = require('http');
const server = http.createServer((req, res) => {
res.removeHeader('header1', 1);
res.write('abc');
- common.expectsError(
+ assert.throws(
() => res.removeHeader('header2', 2),
{
code: 'ERR_HTTP_HEADERS_SENT',
- type: Error,
+ name: 'Error',
message: 'Cannot remove headers after they are sent to the client'
}
);
diff --git a/test/parallel/test-http-response-splitting.js b/test/parallel/test-http-response-splitting.js
index 2c75940b7a..2b3bf8d7fb 100644
--- a/test/parallel/test-http-response-splitting.js
+++ b/test/parallel/test-http-response-splitting.js
@@ -1,6 +1,6 @@
'use strict';
-const common = require('../common');
+require('../common');
const http = require('http');
const net = require('net');
const url = require('url');
@@ -23,11 +23,11 @@ const countdown = new Countdown(3, () => server.close());
function test(res, code, key, value) {
const header = { [key]: value };
- common.expectsError(
+ assert.throws(
() => res.writeHead(code, header),
{
code: 'ERR_INVALID_CHAR',
- type: TypeError,
+ name: 'TypeError',
message: `Invalid character in header content ["${key}"]`
}
);
diff --git a/test/parallel/test-http-response-statuscode.js b/test/parallel/test-http-response-statuscode.js
index 680fa37cf6..f552270407 100644
--- a/test/parallel/test-http-response-statuscode.js
+++ b/test/parallel/test-http-response-statuscode.js
@@ -8,11 +8,11 @@ const MAX_REQUESTS = 13;
let reqNum = 0;
function test(res, header, code) {
- common.expectsError(() => {
+ assert.throws(() => {
res.writeHead(header);
}, {
code: 'ERR_HTTP_INVALID_STATUS_CODE',
- type: RangeError,
+ name: 'RangeError',
message: `Invalid status code: ${code}`
});
}
@@ -56,12 +56,12 @@ const server = http.Server(common.mustCall(function(req, res) {
test(res, '404 this is not valid either', '404 this is not valid either');
break;
case 12:
- common.expectsError(() => { res.writeHead(); },
- {
- code: 'ERR_HTTP_INVALID_STATUS_CODE',
- type: RangeError,
- message: 'Invalid status code: undefined'
- });
+ assert.throws(() => { res.writeHead(); },
+ {
+ code: 'ERR_HTTP_INVALID_STATUS_CODE',
+ name: 'RangeError',
+ message: 'Invalid status code: undefined'
+ });
this.close();
break;
default:
diff --git a/test/parallel/test-http-server-de-chunked-trailer.js b/test/parallel/test-http-server-de-chunked-trailer.js
index dad744209e..96ce6b52ac 100644
--- a/test/parallel/test-http-server-de-chunked-trailer.js
+++ b/test/parallel/test-http-server-de-chunked-trailer.js
@@ -12,10 +12,10 @@ const server = http.createServer(common.mustCall(function(req, res) {
const trailerInvalidErr = {
code: 'ERR_HTTP_TRAILER_INVALID',
message: 'Trailers are invalid with this transfer encoding',
- type: Error
+ name: 'Error'
};
- common.expectsError(() => res.writeHead(200, { 'Content-Length': '2' }),
- trailerInvalidErr);
+ assert.throws(() => res.writeHead(200, { 'Content-Length': '2' }),
+ trailerInvalidErr);
res.removeHeader('Trailer');
res.end('ok');
}));
diff --git a/test/parallel/test-http-server-destroy-socket-on-client-error.js b/test/parallel/test-http-server-destroy-socket-on-client-error.js
index 75f795603d..da5c532d9e 100644
--- a/test/parallel/test-http-server-destroy-socket-on-client-error.js
+++ b/test/parallel/test-http-server-destroy-socket-on-client-error.js
@@ -13,7 +13,7 @@ const server = createServer();
server.on('connection', mustCall((socket) => {
socket.on('error', expectsError({
- type: Error,
+ name: 'Error',
message: 'Parse Error: Invalid method encountered',
code: 'HPE_INVALID_METHOD',
bytesParsed: 0,
diff --git a/test/parallel/test-http-server-write-after-end.js b/test/parallel/test-http-server-write-after-end.js
index a405844cfc..589b673282 100644
--- a/test/parallel/test-http-server-write-after-end.js
+++ b/test/parallel/test-http-server-write-after-end.js
@@ -11,7 +11,7 @@ function handle(req, res) {
res.on('error', common.mustCall((err) => {
common.expectsError({
code: 'ERR_STREAM_WRITE_AFTER_END',
- type: Error
+ name: 'Error'
})(err);
server.close();
}));
diff --git a/test/parallel/test-http-unix-socket.js b/test/parallel/test-http-unix-socket.js
index cfed45a43c..d6ce23bb19 100644
--- a/test/parallel/test-http-unix-socket.js
+++ b/test/parallel/test-http-unix-socket.js
@@ -62,7 +62,7 @@ server.listen(common.PIPE, common.mustCall(function() {
server.close(common.expectsError({
code: 'ERR_SERVER_NOT_RUNNING',
message: 'Server is not running.',
- type: Error
+ name: 'Error'
}));
}));
}));
diff --git a/test/parallel/test-http-url.parse-only-support-http-https-protocol.js b/test/parallel/test-http-url.parse-only-support-http-https-protocol.js
index 5df547594b..6dcb2a852e 100644
--- a/test/parallel/test-http-url.parse-only-support-http-https-protocol.js
+++ b/test/parallel/test-http-url.parse-only-support-http-https-protocol.js
@@ -20,7 +20,8 @@
// USE OR OTHER DEALINGS IN THE SOFTWARE.
'use strict';
-const common = require('../common');
+require('../common');
+const assert = require('assert');
const http = require('http');
const url = require('url');
@@ -34,11 +35,11 @@ const invalidUrls = [
];
invalidUrls.forEach((invalid) => {
- common.expectsError(
+ assert.throws(
() => { http.request(url.parse(invalid)); },
{
code: 'ERR_INVALID_PROTOCOL',
- type: TypeError
+ name: 'TypeError'
}
);
});
diff --git a/test/parallel/test-http-write-head.js b/test/parallel/test-http-write-head.js
index 320359e3ec..2199f11be6 100644
--- a/test/parallel/test-http-write-head.js
+++ b/test/parallel/test-http-write-head.js
@@ -32,32 +32,32 @@ const s = http.createServer(common.mustCall((req, res) => {
// toLowerCase() is used on the name argument, so it must be a string.
// Non-String header names should throw
- common.expectsError(
+ assert.throws(
() => res.setHeader(0xf00, 'bar'),
{
code: 'ERR_INVALID_HTTP_TOKEN',
- type: TypeError,
+ name: 'TypeError',
message: 'Header name must be a valid HTTP token ["3840"]'
}
);
// Undefined value should throw, via 979d0ca8
- common.expectsError(
+ assert.throws(
() => res.setHeader('foo', undefined),
{
code: 'ERR_HTTP_INVALID_HEADER_VALUE',
- type: TypeError,
+ name: 'TypeError',
message: 'Invalid value "undefined" for header "foo"'
}
);
res.writeHead(200, { Test: '2' });
- common.expectsError(() => {
+ assert.throws(() => {
res.writeHead(100, {});
}, {
code: 'ERR_HTTP_HEADERS_SENT',
- type: Error,
+ name: 'Error',
message: 'Cannot render headers after they are sent to the client'
});
diff --git a/test/parallel/test-http2-client-destroy.js b/test/parallel/test-http2-client-destroy.js
index c7a87b9c06..88850b9db5 100644
--- a/test/parallel/test-http2-client-destroy.js
+++ b/test/parallel/test-http2-client-destroy.js
@@ -62,7 +62,7 @@ const Countdown = require('../common/countdown');
const req = client.request();
req.on('error', common.expectsError({
code: 'ERR_HTTP2_STREAM_CANCEL',
- type: Error,
+ name: 'Error',
message: 'The pending stream has been canceled'
}));
@@ -71,26 +71,26 @@ const Countdown = require('../common/countdown');
req.on('response', common.mustNotCall());
const sessionError = {
- type: Error,
+ name: 'Error',
code: 'ERR_HTTP2_INVALID_SESSION',
message: 'The session has been destroyed'
};
- common.expectsError(() => client.setNextStreamID(), sessionError);
- common.expectsError(() => client.ping(), sessionError);
- common.expectsError(() => client.settings({}), sessionError);
- common.expectsError(() => client.goaway(), sessionError);
- common.expectsError(() => client.request(), sessionError);
+ assert.throws(() => client.setNextStreamID(), sessionError);
+ assert.throws(() => client.ping(), sessionError);
+ assert.throws(() => client.settings({}), sessionError);
+ assert.throws(() => client.goaway(), sessionError);
+ assert.throws(() => client.request(), sessionError);
client.close(); // Should be a non-op at this point
// Wait for setImmediate call from destroy() to complete
// so that state.destroyed is set to true
setImmediate(() => {
- common.expectsError(() => client.setNextStreamID(), sessionError);
- common.expectsError(() => client.ping(), sessionError);
- common.expectsError(() => client.settings({}), sessionError);
- common.expectsError(() => client.goaway(), sessionError);
- common.expectsError(() => client.request(), sessionError);
+ assert.throws(() => client.setNextStreamID(), sessionError);
+ assert.throws(() => client.ping(), sessionError);
+ assert.throws(() => client.settings({}), sessionError);
+ assert.throws(() => client.goaway(), sessionError);
+ assert.throws(() => client.request(), sessionError);
client.close(); // Should be a non-op at this point
});
@@ -155,7 +155,7 @@ const Countdown = require('../common/countdown');
// Should throw goaway error
req.on('error', common.expectsError({
code: 'ERR_HTTP2_GOAWAY_SESSION',
- type: Error,
+ name: 'Error',
message: 'New streams cannot be created after receiving a GOAWAY'
}));
diff --git a/test/parallel/test-http2-client-http1-server.js b/test/parallel/test-http2-client-http1-server.js
index 2728033d19..d570f5cbe8 100644
--- a/test/parallel/test-http2-client-http1-server.js
+++ b/test/parallel/test-http2-client-http1-server.js
@@ -20,13 +20,13 @@ server.listen(0, common.mustCall(() => {
req.on('error', common.expectsError({
code: 'ERR_HTTP2_ERROR',
- type: NghttpError,
+ constructor: NghttpError,
message: 'Protocol error'
}));
client.on('error', common.expectsError({
code: 'ERR_HTTP2_ERROR',
- type: NghttpError,
+ constructor: NghttpError,
name: 'Error',
message: 'Protocol error'
}));
diff --git a/test/parallel/test-http2-client-onconnect-errors.js b/test/parallel/test-http2-client-onconnect-errors.js
index b00c050724..788386ae86 100644
--- a/test/parallel/test-http2-client-onconnect-errors.js
+++ b/test/parallel/test-http2-client-onconnect-errors.js
@@ -29,7 +29,7 @@ const specificTests = [
ngError: constants.NGHTTP2_ERR_STREAM_ID_NOT_AVAILABLE,
error: {
code: 'ERR_HTTP2_OUT_OF_STREAMS',
- type: Error,
+ name: 'Error',
message: 'No stream ID is available because ' +
'maximum stream ID has been reached'
},
@@ -39,7 +39,7 @@ const specificTests = [
ngError: constants.NGHTTP2_ERR_INVALID_ARGUMENT,
error: {
code: 'ERR_HTTP2_STREAM_SELF_DEPENDENCY',
- type: Error,
+ name: 'Error',
message: 'A stream cannot depend on itself'
},
type: 'stream'
@@ -54,7 +54,7 @@ const genericTests = Object.getOwnPropertyNames(constants)
ngError: constants[key],
error: {
code: 'ERR_HTTP2_ERROR',
- type: NghttpError,
+ constructor: NghttpError,
name: 'Error',
message: nghttp2ErrorString(constants[key])
},
diff --git a/test/parallel/test-http2-client-request-options-errors.js b/test/parallel/test-http2-client-request-options-errors.js
index d170443f72..365381cc5a 100644
--- a/test/parallel/test-http2-client-request-options-errors.js
+++ b/test/parallel/test-http2-client-request-options-errors.js
@@ -3,6 +3,7 @@
const common = require('../common');
if (!common.hasCrypto)
common.skip('missing crypto');
+const assert = require('assert');
const http2 = require('http2');
// Check if correct errors are emitted when wrong type of data is passed
@@ -38,14 +39,14 @@ server.listen(0, common.mustCall(() => {
if (type === optionsToTest[option])
return;
- common.expectsError(
+ assert.throws(
() => client.request({
':method': 'CONNECT',
':authority': `localhost:${port}`
}, {
[option]: types[type]
}), {
- type: TypeError,
+ name: 'TypeError',
code: 'ERR_INVALID_OPT_VALUE',
message: `The value "${String(types[type])}" is invalid ` +
`for option "${option}"`
diff --git a/test/parallel/test-http2-client-rststream-before-connect.js b/test/parallel/test-http2-client-rststream-before-connect.js
index d186f418b5..2acdefdfbe 100644
--- a/test/parallel/test-http2-client-rststream-before-connect.js
+++ b/test/parallel/test-http2-client-rststream-before-connect.js
@@ -31,10 +31,10 @@ server.listen(0, common.mustCall(() => {
assert.strictEqual(req.closed, false);
[true, 1, {}, [], null, 'test'].forEach((notFunction) => {
- common.expectsError(
+ assert.throws(
() => req.close(closeCode, notFunction),
{
- type: TypeError,
+ name: 'TypeError',
code: 'ERR_INVALID_CALLBACK',
message: `Callback must be a function. Received ${inspect(notFunction)}`
}
@@ -60,7 +60,7 @@ server.listen(0, common.mustCall(() => {
req.on('error', common.expectsError({
code: 'ERR_HTTP2_STREAM_ERROR',
- type: Error,
+ name: 'Error',
message: 'Stream closed with error code NGHTTP2_PROTOCOL_ERROR'
}));
diff --git a/test/parallel/test-http2-client-setNextStreamID-errors.js b/test/parallel/test-http2-client-setNextStreamID-errors.js
index d13d685b3e..aace584525 100644
--- a/test/parallel/test-http2-client-setNextStreamID-errors.js
+++ b/test/parallel/test-http2-client-setNextStreamID-errors.js
@@ -4,6 +4,7 @@ const common = require('../common');
if (!common.hasCrypto)
common.skip('missing crypto');
+const assert = require('assert');
const http2 = require('http2');
const server = http2.createServer();
@@ -27,10 +28,10 @@ server.listen(0, common.mustCall(() => {
client.on('connect', () => {
const outOfRangeNum = 2 ** 32;
- common.expectsError(
+ assert.throws(
() => client.setNextStreamID(outOfRangeNum),
{
- type: RangeError,
+ name: 'RangeError',
code: 'ERR_OUT_OF_RANGE',
message: 'The value of "id" is out of range.' +
' It must be > 0 and <= 4294967295. Received ' + outOfRangeNum
@@ -43,10 +44,10 @@ server.listen(0, common.mustCall(() => {
return;
}
- common.expectsError(
+ assert.throws(
() => client.setNextStreamID(value),
{
- type: TypeError,
+ name: 'TypeError',
code: 'ERR_INVALID_ARG_TYPE',
message: 'The "id" argument must be of type number.' +
common.invalidArgTypeHelper(value)
diff --git a/test/parallel/test-http2-client-settings-before-connect.js b/test/parallel/test-http2-client-settings-before-connect.js
index 8bcdabe326..ed2b859ae2 100644
--- a/test/parallel/test-http2-client-settings-before-connect.js
+++ b/test/parallel/test-http2-client-settings-before-connect.js
@@ -3,6 +3,7 @@
const common = require('../common');
if (!common.hasCrypto)
common.skip('missing crypto');
+const assert = require('assert');
const h2 = require('http2');
const { inspect } = require('util');
@@ -37,20 +38,20 @@ server.listen(0, common.mustCall(() => {
['enablePush', null, TypeError],
['enablePush', {}, TypeError]
].forEach(([name, value, errorType]) =>
- common.expectsError(
+ assert.throws(
() => client.settings({ [name]: value }),
{
code: 'ERR_HTTP2_INVALID_SETTING_VALUE',
- type: errorType
+ name: errorType.name
}
)
);
[1, true, {}, []].forEach((invalidCallback) =>
- common.expectsError(
+ assert.throws(
() => client.settings({}, invalidCallback),
{
- type: TypeError,
+ name: 'TypeError',
code: 'ERR_INVALID_CALLBACK',
message:
`Callback must be a function. Received ${inspect(invalidCallback)}`
diff --git a/test/parallel/test-http2-client-stream-destroy-before-connect.js b/test/parallel/test-http2-client-stream-destroy-before-connect.js
index 3083b5a9d1..09667750ae 100644
--- a/test/parallel/test-http2-client-stream-destroy-before-connect.js
+++ b/test/parallel/test-http2-client-stream-destroy-before-connect.js
@@ -38,7 +38,7 @@ server.listen(0, common.mustCall(() => {
req.destroy(new Error('test'));
req.on('error', common.expectsError({
- type: Error,
+ name: 'Error',
message: 'test'
}));
diff --git a/test/parallel/test-http2-client-unescaped-path.js b/test/parallel/test-http2-client-unescaped-path.js
index ff122a02ca..ca061ccda4 100644
--- a/test/parallel/test-http2-client-unescaped-path.js
+++ b/test/parallel/test-http2-client-unescaped-path.js
@@ -26,7 +26,7 @@ server.listen(0, common.mustCall(() => {
const req = client.request({ ':path': `bad${String.fromCharCode(i)}path` });
req.on('error', common.expectsError({
code: 'ERR_HTTP2_STREAM_ERROR',
- type: Error,
+ name: 'Error',
message: 'Stream closed with error code NGHTTP2_PROTOCOL_ERROR'
}));
req.on('close', common.mustCall(() => countdown.dec()));
diff --git a/test/parallel/test-http2-compat-serverresponse-createpushresponse.js b/test/parallel/test-http2-compat-serverresponse-createpushresponse.js
index 1ec273a2a1..731c2f8709 100644
--- a/test/parallel/test-http2-compat-serverresponse-createpushresponse.js
+++ b/test/parallel/test-http2-compat-serverresponse-createpushresponse.js
@@ -16,14 +16,14 @@ const server = h2.createServer((request, response) => {
response.write(servExpect);
// Callback must be specified (and be a function)
- common.expectsError(
+ assert.throws(
() => response.createPushResponse({
':path': '/pushed',
':method': 'GET'
}, undefined),
{
code: 'ERR_INVALID_CALLBACK',
- type: TypeError,
+ name: 'TypeError',
message: 'Callback must be a function. Received undefined'
}
);
diff --git a/test/parallel/test-http2-compat-serverresponse-destroy.js b/test/parallel/test-http2-compat-serverresponse-destroy.js
index 9082ec2ab8..0d73c82c2d 100644
--- a/test/parallel/test-http2-compat-serverresponse-destroy.js
+++ b/test/parallel/test-http2-compat-serverresponse-destroy.js
@@ -56,7 +56,7 @@ server.listen(0, common.mustCall(() => {
req.on('response', common.mustNotCall());
req.on('error', common.expectsError({
code: 'ERR_HTTP2_STREAM_ERROR',
- type: Error,
+ name: 'Error',
message: 'Stream closed with error code NGHTTP2_INTERNAL_ERROR'
}));
req.on('close', common.mustCall(() => countdown.dec()));
@@ -71,7 +71,7 @@ server.listen(0, common.mustCall(() => {
req.on('response', common.mustNotCall());
req.on('error', common.expectsError({
code: 'ERR_HTTP2_STREAM_ERROR',
- type: Error,
+ name: 'Error',
message: 'Stream closed with error code NGHTTP2_INTERNAL_ERROR'
}));
req.on('close', common.mustCall(() => countdown.dec()));
diff --git a/test/parallel/test-http2-compat-serverresponse-flushheaders.js b/test/parallel/test-http2-compat-serverresponse-flushheaders.js
index 6927b3754b..7760bf8c7d 100644
--- a/test/parallel/test-http2-compat-serverresponse-flushheaders.js
+++ b/test/parallel/test-http2-compat-serverresponse-flushheaders.js
@@ -21,7 +21,7 @@ server.listen(0, common.mustCall(function() {
assert.strictEqual(response._header, true);
response.flushHeaders(); // Idempotent
- common.expectsError(() => {
+ assert.throws(() => {
response.writeHead(400, { 'foo-bar': 'abc123' });
}, {
code: 'ERR_HTTP2_HEADERS_SENT'
diff --git a/test/parallel/test-http2-compat-serverresponse-headers.js b/test/parallel/test-http2-compat-serverresponse-headers.js
index 82b81a3d3f..14e480f611 100644
--- a/test/parallel/test-http2-compat-serverresponse-headers.js
+++ b/test/parallel/test-http2-compat-serverresponse-headers.js
@@ -59,42 +59,42 @@ server.listen(0, common.mustCall(function() {
':path',
':authority',
':scheme'
- ].forEach((header) => common.expectsError(
+ ].forEach((header) => assert.throws(
() => response.setHeader(header, 'foobar'),
{
code: 'ERR_HTTP2_PSEUDOHEADER_NOT_ALLOWED',
- type: TypeError,
+ name: 'TypeError',
message: 'Cannot set HTTP/2 pseudo-headers'
})
);
- common.expectsError(function() {
+ assert.throws(() => {
response.setHeader(real, null);
}, {
code: 'ERR_HTTP2_INVALID_HEADER_VALUE',
- type: TypeError,
+ name: 'TypeError',
message: 'Invalid value "null" for header "foo-bar"'
});
- common.expectsError(function() {
+ assert.throws(() => {
response.setHeader(real, undefined);
}, {
code: 'ERR_HTTP2_INVALID_HEADER_VALUE',
- type: TypeError,
+ name: 'TypeError',
message: 'Invalid value "undefined" for header "foo-bar"'
});
- common.expectsError(
+ assert.throws(
() => response.setHeader(), // Header name undefined
{
code: 'ERR_INVALID_ARG_TYPE',
- type: TypeError,
+ name: 'TypeError',
message: 'The "name" argument must be of type string. Received ' +
'undefined'
}
);
- common.expectsError(
+ assert.throws(
() => response.setHeader(''),
{
code: 'ERR_INVALID_HTTP_TOKEN',
- type: TypeError,
+ name: 'TypeError',
message: 'Header name must be a valid HTTP token [""]'
}
);
@@ -115,37 +115,37 @@ server.listen(0, common.mustCall(function() {
response.on('finish', common.mustCall(function() {
assert.strictEqual(response.headersSent, true);
- common.expectsError(
+ assert.throws(
() => response.setHeader(real, expectedValue),
{
code: 'ERR_HTTP2_HEADERS_SENT',
- type: Error,
+ name: 'Error',
message: 'Response has already been initiated.'
}
);
- common.expectsError(
+ assert.throws(
() => response.removeHeader(real, expectedValue),
{
code: 'ERR_HTTP2_HEADERS_SENT',
- type: Error,
+ name: 'Error',
message: 'Response has already been initiated.'
}
);
process.nextTick(() => {
- common.expectsError(
+ assert.throws(
() => response.setHeader(real, expectedValue),
{
code: 'ERR_HTTP2_HEADERS_SENT',
- type: Error,
+ name: 'Error',
message: 'Response has already been initiated.'
}
);
- common.expectsError(
+ assert.throws(
() => response.removeHeader(real, expectedValue),
{
code: 'ERR_HTTP2_HEADERS_SENT',
- type: Error,
+ name: 'Error',
message: 'Response has already been initiated.'
}
);
diff --git a/test/parallel/test-http2-compat-serverresponse-statuscode.js b/test/parallel/test-http2-compat-serverresponse-statuscode.js
index dd92db8d96..6064a5936e 100644
--- a/test/parallel/test-http2-compat-serverresponse-statuscode.js
+++ b/test/parallel/test-http2-compat-serverresponse-statuscode.js
@@ -33,23 +33,23 @@ server.listen(0, common.mustCall(function() {
response.statusCode = realStatusCodes.badRequest;
response.statusCode = realStatusCodes.internalServerError;
- common.expectsError(function() {
+ assert.throws(() => {
response.statusCode = realStatusCodes.continue;
}, {
code: 'ERR_HTTP2_INFO_STATUS_NOT_ALLOWED',
- type: RangeError
+ name: 'RangeError'
});
- common.expectsError(function() {
+ assert.throws(() => {
response.statusCode = fakeStatusCodes.tooLow;
}, {
code: 'ERR_HTTP2_STATUS_INVALID',
- type: RangeError
+ name: 'RangeError'
});
- common.expectsError(function() {
+ assert.throws(() => {
response.statusCode = fakeStatusCodes.tooHigh;
}, {
code: 'ERR_HTTP2_STATUS_INVALID',
- type: RangeError
+ name: 'RangeError'
});
response.on('finish', common.mustCall(function() {
diff --git a/test/parallel/test-http2-compat-serverresponse-trailers.js b/test/parallel/test-http2-compat-serverresponse-trailers.js
index ca148ff007..4cfbae0bda 100644
--- a/test/parallel/test-http2-compat-serverresponse-trailers.js
+++ b/test/parallel/test-http2-compat-serverresponse-trailers.js
@@ -15,44 +15,44 @@ server.listen(0, common.mustCall(() => {
});
response.setTrailer('ABCD', 123);
- common.expectsError(
+ assert.throws(
() => response.addTrailers({ '': 'test' }),
{
code: 'ERR_INVALID_HTTP_TOKEN',
- type: TypeError,
+ name: 'TypeError',
message: 'Header name must be a valid HTTP token [""]'
}
);
- common.expectsError(
+ assert.throws(
() => response.setTrailer('test', undefined),
{
code: 'ERR_HTTP2_INVALID_HEADER_VALUE',
- type: TypeError,
+ name: 'TypeError',
message: 'Invalid value "undefined" for header "test"'
}
);
- common.expectsError(
+ assert.throws(
() => response.setTrailer('test', null),
{
code: 'ERR_HTTP2_INVALID_HEADER_VALUE',
- type: TypeError,
+ name: 'TypeError',
message: 'Invalid value "null" for header "test"'
}
);
- common.expectsError(
+ assert.throws(
() => response.setTrailer(), // Trailer name undefined
{
code: 'ERR_INVALID_ARG_TYPE',
- type: TypeError,
+ name: 'TypeError',
message: 'The "name" argument must be of type string. Received ' +
'undefined'
}
);
- common.expectsError(
+ assert.throws(
() => response.setTrailer(''),
{
code: 'ERR_INVALID_HTTP_TOKEN',
- type: TypeError,
+ name: 'TypeError',
message: 'Header name must be a valid HTTP token [""]'
}
);
diff --git a/test/parallel/test-http2-compat-serverresponse-write.js b/test/parallel/test-http2-compat-serverresponse-write.js
index af3029835e..6bec7c6c5e 100644
--- a/test/parallel/test-http2-compat-serverresponse-write.js
+++ b/test/parallel/test-http2-compat-serverresponse-write.js
@@ -3,7 +3,6 @@
const {
mustCall,
mustNotCall,
- expectsError,
hasCrypto,
skip
} = require('../common');
@@ -33,10 +32,10 @@ server.listen(0, mustCall(() => {
response.on('error', mustNotCall());
// response.write() without cb returns error
- expectsError(
+ assert.throws(
() => { response.write('muahaha'); },
{
- type: Error,
+ name: 'Error',
code: 'ERR_HTTP2_INVALID_STREAM',
message: 'The stream has been destroyed'
}
diff --git a/test/parallel/test-http2-compat-serverresponse-writehead.js b/test/parallel/test-http2-compat-serverresponse-writehead.js
index e66f5f79cd..8157dcbedd 100644
--- a/test/parallel/test-http2-compat-serverresponse-writehead.js
+++ b/test/parallel/test-http2-compat-serverresponse-writehead.js
@@ -19,7 +19,7 @@ server.listen(0, common.mustCall(function() {
assert.strictEqual(returnVal, response);
- common.expectsError(() => { response.writeHead(300); }, {
+ assert.throws(() => { response.writeHead(300); }, {
code: 'ERR_HTTP2_HEADERS_SENT'
});
diff --git a/test/parallel/test-http2-compat-socket-set.js b/test/parallel/test-http2-compat-socket-set.js
index 05beb09d54..b14a2f65d8 100644
--- a/test/parallel/test-http2-compat-socket-set.js
+++ b/test/parallel/test-http2-compat-socket-set.js
@@ -11,7 +11,7 @@ const h2 = require('http2');
const errMsg = {
code: 'ERR_HTTP2_NO_SOCKET_MANIPULATION',
- type: Error,
+ name: 'Error',
message: 'HTTP/2 sockets should not be directly manipulated ' +
'(e.g. read and written)'
};
@@ -68,10 +68,10 @@ server.on('request', common.mustCall(function(request, response) {
request.socket._isProcessing = true;
assert.strictEqual(request.stream.session.socket._isProcessing, true);
- common.expectsError(() => request.socket.read = noop, errMsg);
- common.expectsError(() => request.socket.write = noop, errMsg);
- common.expectsError(() => request.socket.pause = noop, errMsg);
- common.expectsError(() => request.socket.resume = noop, errMsg);
+ assert.throws(() => request.socket.read = noop, errMsg);
+ assert.throws(() => request.socket.write = noop, errMsg);
+ assert.throws(() => request.socket.pause = noop, errMsg);
+ assert.throws(() => request.socket.resume = noop, errMsg);
request.stream.on('finish', common.mustCall(() => {
setImmediate(() => {
diff --git a/test/parallel/test-http2-compat-socket.js b/test/parallel/test-http2-compat-socket.js
index 162d3af96f..0db2876738 100644
--- a/test/parallel/test-http2-compat-socket.js
+++ b/test/parallel/test-http2-compat-socket.js
@@ -17,7 +17,7 @@ const { kTimeout } = require('internal/timers');
const errMsg = {
code: 'ERR_HTTP2_NO_SOCKET_MANIPULATION',
- type: Error,
+ name: 'Error',
message: 'HTTP/2 sockets should not be directly manipulated ' +
'(e.g. read and written)'
};
@@ -38,10 +38,10 @@ server.on('request', common.mustCall(function(request, response) {
assert.strictEqual(request.stream.session[kTimeout]._idleTimeout, 987);
request.socket.setTimeout(0);
- common.expectsError(() => request.socket.read(), errMsg);
- common.expectsError(() => request.socket.write(), errMsg);
- common.expectsError(() => request.socket.pause(), errMsg);
- common.expectsError(() => request.socket.resume(), errMsg);
+ assert.throws(() => request.socket.read(), errMsg);
+ assert.throws(() => request.socket.write(), errMsg);
+ assert.throws(() => request.socket.pause(), errMsg);
+ assert.throws(() => request.socket.resume(), errMsg);
// Should have correct this context for socket methods & getters
assert.ok(request.socket.address() != null);
diff --git a/test/parallel/test-http2-connect-method.js b/test/parallel/test-http2-connect-method.js
index 46c5bf9795..d5b4c4bd27 100644
--- a/test/parallel/test-http2-connect-method.js
+++ b/test/parallel/test-http2-connect-method.js
@@ -56,7 +56,7 @@ server.listen(0, common.mustCall(() => {
const client = http2.connect(`http://localhost:${proxy.address().port}`);
// Confirm that :authority is required and :scheme & :path are forbidden
- common.expectsError(
+ assert.throws(
() => client.request({
[HTTP2_HEADER_METHOD]: 'CONNECT'
}),
@@ -65,7 +65,7 @@ server.listen(0, common.mustCall(() => {
message: ':authority header is required for CONNECT requests'
}
);
- common.expectsError(
+ assert.throws(
() => client.request({
[HTTP2_HEADER_METHOD]: 'CONNECT',
[HTTP2_HEADER_AUTHORITY]: `localhost:${port}`,
@@ -76,7 +76,7 @@ server.listen(0, common.mustCall(() => {
message: 'The :scheme header is forbidden for CONNECT requests'
}
);
- common.expectsError(
+ assert.throws(
() => client.request({
[HTTP2_HEADER_METHOD]: 'CONNECT',
[HTTP2_HEADER_AUTHORITY]: `localhost:${port}`,
diff --git a/test/parallel/test-http2-connect.js b/test/parallel/test-http2-connect.js
index 4569905eac..6f62f55a93 100644
--- a/test/parallel/test-http2-connect.js
+++ b/test/parallel/test-http2-connect.js
@@ -9,6 +9,7 @@ const {
} = require('../common');
if (!hasCrypto)
skip('missing crypto');
+const assert = require('assert');
const { createServer, connect } = require('http2');
const { connect: netConnect } = require('net');
@@ -78,7 +79,7 @@ const { connect: netConnect } = require('net');
}
}).on('error', expectsError({
code: 'ERR_HTTP2_INVALID_SETTING_VALUE',
- type: RangeError
+ name: 'RangeError'
}));
});
}
@@ -86,11 +87,11 @@ const { connect: netConnect } = require('net');
// Check for error for an invalid protocol (not http or https)
{
const authority = 'ssh://localhost';
- expectsError(() => {
+ assert.throws(() => {
connect(authority);
}, {
code: 'ERR_HTTP2_UNSUPPORTED_PROTOCOL',
- type: Error
+ name: 'Error'
});
}
diff --git a/test/parallel/test-http2-getpackedsettings.js b/test/parallel/test-http2-getpackedsettings.js
index 8eca10cf49..f9ca7da1e8 100644
--- a/test/parallel/test-http2-getpackedsettings.js
+++ b/test/parallel/test-http2-getpackedsettings.js
@@ -46,11 +46,11 @@ http2.getPackedSettings({ enablePush: false });
['maxHeaderListSize', -1],
['maxHeaderListSize', 2 ** 32]
].forEach((i) => {
- common.expectsError(() => {
+ assert.throws(() => {
http2.getPackedSettings({ [i[0]]: i[1] });
}, {
code: 'ERR_HTTP2_INVALID_SETTING_VALUE',
- type: RangeError,
+ name: 'RangeError',
message: `Invalid value for setting "${i[0]}": ${i[1]}`
});
});
@@ -58,11 +58,11 @@ http2.getPackedSettings({ enablePush: false });
[
1, null, '', Infinity, new Date(), {}, NaN, [false]
].forEach((i) => {
- common.expectsError(() => {
+ assert.throws(() => {
http2.getPackedSettings({ enablePush: i });
}, {
code: 'ERR_HTTP2_INVALID_SETTING_VALUE',
- type: TypeError,
+ name: 'TypeError',
message: `Invalid value for setting "enablePush": ${i}`
});
});
@@ -101,22 +101,22 @@ http2.getPackedSettings({ enablePush: false });
0x00, 0x02, 0x00, 0x00, 0x00, 0x01]);
[1, true, '', [], {}, NaN].forEach((input) => {
- common.expectsError(() => {
+ assert.throws(() => {
http2.getUnpackedSettings(input);
}, {
code: 'ERR_INVALID_ARG_TYPE',
- type: TypeError,
+ name: 'TypeError',
message:
'The "buf" argument must be an instance of Buffer, TypedArray, or ' +
`DataView.${common.invalidArgTypeHelper(input)}`
});
});
- common.expectsError(() => {
+ assert.throws(() => {
http2.getUnpackedSettings(packed.slice(5));
}, {
code: 'ERR_HTTP2_INVALID_PACKED_SETTINGS_LENGTH',
- type: RangeError,
+ name: 'RangeError',
message: 'Packed settings length must be a multiple of six'
});
@@ -161,11 +161,11 @@ http2.getPackedSettings({ enablePush: false });
{
const packed = Buffer.from([0x00, 0x05, 0x01, 0x00, 0x00, 0x00]);
- common.expectsError(() => {
+ assert.throws(() => {
http2.getUnpackedSettings(packed, { validate: true });
}, {
code: 'ERR_HTTP2_INVALID_SETTING_VALUE',
- type: RangeError,
+ name: 'RangeError',
message: 'Invalid value for setting "maxFrameSize": 16777216'
});
}
diff --git a/test/parallel/test-http2-head-request.js b/test/parallel/test-http2-head-request.js
index c8103e7190..9eaa737503 100644
--- a/test/parallel/test-http2-head-request.js
+++ b/test/parallel/test-http2-head-request.js
@@ -7,7 +7,7 @@ const assert = require('assert');
const http2 = require('http2');
const errCheck = common.expectsError({
- type: Error,
+ name: 'Error',
code: 'ERR_STREAM_WRITE_AFTER_END',
message: 'write after end'
}, 2);
@@ -27,7 +27,7 @@ server.on('stream', (stream, headers) => {
stream.respond({ [HTTP2_HEADER_STATUS]: 200 });
// Because this is a head request, the outbound stream is closed automatically
- stream.on('error', common.mustCall(errCheck));
+ stream.on('error', errCheck);
stream.write('data');
});
@@ -44,7 +44,7 @@ server.listen(0, () => {
// Because it is a HEAD request, the payload is meaningless. The
// option.endStream flag is set automatically making the stream
// non-writable.
- req.on('error', common.mustCall(errCheck));
+ req.on('error', errCheck);
req.write('data');
req.on('response', common.mustCall((headers, flags) => {
diff --git a/test/parallel/test-http2-info-headers-errors.js b/test/parallel/test-http2-info-headers-errors.js
index a2e17abd74..aa1e28222c 100644
--- a/test/parallel/test-http2-info-headers-errors.js
+++ b/test/parallel/test-http2-info-headers-errors.js
@@ -27,7 +27,7 @@ const genericTests = Object.getOwnPropertyNames(constants)
ngError: constants[key],
error: {
code: 'ERR_HTTP2_ERROR',
- type: NghttpError,
+ constructor: NghttpError,
name: 'Error',
message: nghttp2ErrorString(constants[key])
},
@@ -72,7 +72,7 @@ function runTest(test) {
req.on('error', common.expectsError({
code: 'ERR_HTTP2_STREAM_ERROR',
- type: Error,
+ name: 'Error',
message: 'Stream closed with error code NGHTTP2_INTERNAL_ERROR'
}));
diff --git a/test/parallel/test-http2-info-headers.js b/test/parallel/test-http2-info-headers.js
index ec95a9d3d9..3f2a500425 100644
--- a/test/parallel/test-http2-info-headers.js
+++ b/test/parallel/test-http2-info-headers.js
@@ -18,25 +18,25 @@ const afterRespondregex =
function onStream(stream, headers, flags) {
- common.expectsError(() => stream.additionalHeaders({ ':status': 201 }),
- {
- code: 'ERR_HTTP2_INVALID_INFO_STATUS',
- type: RangeError,
- message: /^Invalid informational status code: 201$/
- });
-
- common.expectsError(() => stream.additionalHeaders({ ':status': 101 }),
- {
- code: 'ERR_HTTP2_STATUS_101',
- type: Error,
- message: status101regex
- });
-
- common.expectsError(
+ assert.throws(() => stream.additionalHeaders({ ':status': 201 }),
+ {
+ code: 'ERR_HTTP2_INVALID_INFO_STATUS',
+ name: 'RangeError',
+ message: /^Invalid informational status code: 201$/
+ });
+
+ assert.throws(() => stream.additionalHeaders({ ':status': 101 }),
+ {
+ code: 'ERR_HTTP2_STATUS_101',
+ name: 'Error',
+ message: status101regex
+ });
+
+ assert.throws(
() => stream.additionalHeaders({ ':method': 'POST' }),
{
code: 'ERR_HTTP2_INVALID_PSEUDOHEADER',
- type: TypeError,
+ name: 'TypeError',
message: '":method" is an invalid pseudoheader or is used incorrectly'
}
);
@@ -50,12 +50,12 @@ function onStream(stream, headers, flags) {
':status': 200
});
- common.expectsError(() => stream.additionalHeaders({ abc: 123 }),
- {
- code: 'ERR_HTTP2_HEADERS_AFTER_RESPOND',
- type: Error,
- message: afterRespondregex
- });
+ assert.throws(() => stream.additionalHeaders({ abc: 123 }),
+ {
+ code: 'ERR_HTTP2_HEADERS_AFTER_RESPOND',
+ name: 'Error',
+ message: afterRespondregex
+ });
stream.end('hello world');
}
diff --git a/test/parallel/test-http2-invalidargtypes-errors.js b/test/parallel/test-http2-invalidargtypes-errors.js
index b94a670a1a..2230ba1d1f 100644
--- a/test/parallel/test-http2-invalidargtypes-errors.js
+++ b/test/parallel/test-http2-invalidargtypes-errors.js
@@ -3,16 +3,17 @@
const common = require('../common');
if (!common.hasCrypto)
common.skip('missing crypto');
+const assert = require('assert');
const http2 = require('http2');
const server = http2.createServer();
server.on('stream', common.mustCall((stream) => {
- common.expectsError(
+ assert.throws(
() => stream.close('string'),
{
code: 'ERR_INVALID_ARG_TYPE',
- type: TypeError,
+ name: 'TypeError',
message: 'The "code" argument must be of type number. ' +
"Received type string ('string')"
}
diff --git a/test/parallel/test-http2-max-concurrent-streams.js b/test/parallel/test-http2-max-concurrent-streams.js
index b270d6cc6a..a280d04a34 100644
--- a/test/parallel/test-http2-max-concurrent-streams.js
+++ b/test/parallel/test-http2-max-concurrent-streams.js
@@ -49,7 +49,7 @@ server.listen(0, common.mustCall(() => {
req.on('close', common.mustCall(() => countdown.dec()));
req.on('error', common.expectsError({
code: 'ERR_HTTP2_STREAM_ERROR',
- type: Error,
+ name: 'Error',
message: 'Stream closed with error code NGHTTP2_REFUSED_STREAM'
}));
}
diff --git a/test/parallel/test-http2-misbehaving-flow-control-paused.js b/test/parallel/test-http2-misbehaving-flow-control-paused.js
index 26d2ed5dd2..d8f37c4394 100644
--- a/test/parallel/test-http2-misbehaving-flow-control-paused.js
+++ b/test/parallel/test-http2-misbehaving-flow-control-paused.js
@@ -62,7 +62,7 @@ server.on('stream', (stream) => {
stream.pause();
stream.on('error', common.expectsError({
code: 'ERR_HTTP2_STREAM_ERROR',
- type: Error,
+ name: 'Error',
message: 'Stream closed with error code NGHTTP2_FLOW_CONTROL_ERROR'
}));
stream.on('close', common.mustCall(() => {
diff --git a/test/parallel/test-http2-misbehaving-flow-control.js b/test/parallel/test-http2-misbehaving-flow-control.js
index f2da0ba56c..97f8c17f4f 100644
--- a/test/parallel/test-http2-misbehaving-flow-control.js
+++ b/test/parallel/test-http2-misbehaving-flow-control.js
@@ -68,7 +68,7 @@ const server = h2.createServer({ settings: { initialWindowSize: 18 } });
server.on('stream', (stream) => {
stream.on('error', common.expectsError({
code: 'ERR_HTTP2_STREAM_ERROR',
- type: Error,
+ name: 'Error',
message: 'Stream closed with error code NGHTTP2_FLOW_CONTROL_ERROR'
}));
stream.on('close', common.mustCall(() => {
diff --git a/test/parallel/test-http2-misbehaving-multiplex.js b/test/parallel/test-http2-misbehaving-multiplex.js
index 3df3a6f893..fbd8add890 100644
--- a/test/parallel/test-http2-misbehaving-multiplex.js
+++ b/test/parallel/test-http2-misbehaving-multiplex.js
@@ -19,7 +19,7 @@ server.on('stream', common.mustCall((stream) => {
// The error will be emitted asynchronously
stream.on('error', common.expectsError({
- type: NghttpError,
+ constructor: NghttpError,
code: 'ERR_HTTP2_ERROR',
message: 'Stream was already closed or invalid'
}));
@@ -28,7 +28,7 @@ server.on('stream', common.mustCall((stream) => {
server.on('session', common.mustCall((session) => {
session.on('error', common.expectsError({
code: 'ERR_HTTP2_ERROR',
- type: NghttpError,
+ constructor: NghttpError,
message: 'Stream was already closed or invalid'
}));
}));
diff --git a/test/parallel/test-http2-misc-util.js b/test/parallel/test-http2-misc-util.js
index ec9c65ec08..53eed542e2 100644
--- a/test/parallel/test-http2-misc-util.js
+++ b/test/parallel/test-http2-misc-util.js
@@ -20,30 +20,30 @@ assert.strictEqual(sessionName(1), 'client');
});
// Code coverage for assertWithinRange function
-common.expectsError(
+assert.throws(
() => assertWithinRange('test', -1),
{
code: 'ERR_HTTP2_INVALID_SETTING_VALUE',
- type: RangeError,
+ name: 'RangeError',
message: 'Invalid value for setting "test": -1'
});
assertWithinRange('test', 1);
-common.expectsError(
+assert.throws(
() => assertIsObject('foo', 'test'),
{
code: 'ERR_INVALID_ARG_TYPE',
- type: TypeError,
+ name: 'TypeError',
message: 'The "test" argument must be of type object. Received ' +
"type string ('foo')"
});
-common.expectsError(
+assert.throws(
() => assertIsObject('foo', 'test', ['Date']),
{
code: 'ERR_INVALID_ARG_TYPE',
- type: TypeError,
+ name: 'TypeError',
message: 'The "test" argument must be an instance of Date. Received type ' +
"string ('foo')"
});
diff --git a/test/parallel/test-http2-misused-pseudoheaders.js b/test/parallel/test-http2-misused-pseudoheaders.js
index c1ae37b9a3..2ae3a1ddbf 100644
--- a/test/parallel/test-http2-misused-pseudoheaders.js
+++ b/test/parallel/test-http2-misused-pseudoheaders.js
@@ -3,6 +3,7 @@
const common = require('../common');
if (!common.hasCrypto)
common.skip('missing crypto');
+const assert = require('assert');
const h2 = require('http2');
const server = h2.createServer();
@@ -14,16 +15,16 @@ server.on('stream', common.mustCall((stream) => {
':method',
':scheme'
].forEach((i) => {
- common.expectsError(() => stream.respond({ [i]: '/' }),
- {
- code: 'ERR_HTTP2_INVALID_PSEUDOHEADER'
- });
+ assert.throws(() => stream.respond({ [i]: '/' }),
+ {
+ code: 'ERR_HTTP2_INVALID_PSEUDOHEADER'
+ });
});
stream.respond({}, { waitForTrailers: true });
stream.on('wantTrailers', () => {
- common.expectsError(() => {
+ assert.throws(() => {
stream.sendTrailers({ ':status': 'bar' });
}, {
code: 'ERR_HTTP2_INVALID_PSEUDOHEADER'
diff --git a/test/parallel/test-http2-multi-content-length.js b/test/parallel/test-http2-multi-content-length.js
index 7d8ff4858f..013dc8935c 100644
--- a/test/parallel/test-http2-multi-content-length.js
+++ b/test/parallel/test-http2-multi-content-length.js
@@ -3,6 +3,7 @@
const common = require('../common');
if (!common.hasCrypto)
common.skip('missing crypto');
+const assert = require('assert');
const http2 = require('http2');
const Countdown = require('../common/countdown');
@@ -22,7 +23,7 @@ server.listen(0, common.mustCall(() => {
});
// Request 1 will fail because there are two content-length header values
- common.expectsError(
+ assert.throws(
() => {
client.request({
':method': 'POST',
@@ -31,7 +32,7 @@ server.listen(0, common.mustCall(() => {
});
}, {
code: 'ERR_HTTP2_HEADER_SINGLE_VALUE',
- type: TypeError,
+ name: 'TypeError',
message: 'Header field "content-length" must only have a single value'
}
);
@@ -57,7 +58,7 @@ server.listen(0, common.mustCall(() => {
req.on('close', common.mustCall(() => countdown.dec()));
req.on('error', common.expectsError({
code: 'ERR_HTTP2_STREAM_ERROR',
- type: Error,
+ name: 'Error',
message: 'Stream closed with error code NGHTTP2_PROTOCOL_ERROR'
}));
}
diff --git a/test/parallel/test-http2-no-more-streams.js b/test/parallel/test-http2-no-more-streams.js
index ff0c8baa14..26ec5ab8ad 100644
--- a/test/parallel/test-http2-no-more-streams.js
+++ b/test/parallel/test-http2-no-more-streams.js
@@ -43,7 +43,7 @@ server.listen(0, common.mustCall(() => {
const req = client.request();
req.on('error', common.expectsError({
code: 'ERR_HTTP2_OUT_OF_STREAMS',
- type: Error,
+ name: 'Error',
message:
'No stream ID is available because maximum stream ID has been reached'
}));
diff --git a/test/parallel/test-http2-options-max-headers-block-length.js b/test/parallel/test-http2-options-max-headers-block-length.js
index 18f72bf1de..11632c6e82 100644
--- a/test/parallel/test-http2-options-max-headers-block-length.js
+++ b/test/parallel/test-http2-options-max-headers-block-length.js
@@ -37,7 +37,7 @@ server.listen(0, common.mustCall(() => {
req.on('error', common.expectsError({
code: 'ERR_HTTP2_STREAM_ERROR',
- type: Error,
+ name: 'Error',
message: 'Stream closed with error code NGHTTP2_REFUSED_STREAM'
}));
}));
diff --git a/test/parallel/test-http2-ping.js b/test/parallel/test-http2-ping.js
index 27bfd19c6f..d775e93333 100644
--- a/test/parallel/test-http2-ping.js
+++ b/test/parallel/test-http2-ping.js
@@ -76,17 +76,17 @@ server.listen(0, common.mustCall(() => {
// Only max 2 pings at a time based on the maxOutstandingPings option
assert(!client.ping(common.expectsError({
code: 'ERR_HTTP2_PING_CANCEL',
- type: Error,
+ name: 'Error',
message: 'HTTP2 ping cancelled'
})));
// Should throw if payload is not of type ArrayBufferView
{
[1, true, {}, []].forEach((payload) =>
- common.expectsError(
+ assert.throws(
() => client.ping(payload),
{
- type: TypeError,
+ name: 'TypeError',
code: 'ERR_INVALID_ARG_TYPE',
message: 'The "payload" argument must be an instance of Buffer, ' +
'TypedArray, or DataView.' +
@@ -101,10 +101,10 @@ server.listen(0, common.mustCall(() => {
const shortPayload = Buffer.from('abcdefg');
const longPayload = Buffer.from('abcdefghi');
[shortPayload, longPayload].forEach((payloadWithInvalidLength) =>
- common.expectsError(
+ assert.throws(
() => client.ping(payloadWithInvalidLength),
{
- type: RangeError,
+ name: 'RangeError',
code: 'ERR_HTTP2_PING_LENGTH',
message: 'HTTP2 ping payload must be 8 bytes'
}
@@ -116,10 +116,10 @@ server.listen(0, common.mustCall(() => {
{
const payload = Buffer.from('abcdefgh');
[1, true, {}, []].forEach((invalidCallback) =>
- common.expectsError(
+ assert.throws(
() => client.ping(payload, invalidCallback),
{
- type: TypeError,
+ name: 'TypeError',
code: 'ERR_INVALID_CALLBACK',
message: 'Callback must be a function. ' +
`Received ${inspect(invalidCallback)}`
diff --git a/test/parallel/test-http2-respond-errors.js b/test/parallel/test-http2-respond-errors.js
index 98f2558253..cc733b6994 100644
--- a/test/parallel/test-http2-respond-errors.js
+++ b/test/parallel/test-http2-respond-errors.js
@@ -4,6 +4,7 @@
const common = require('../common');
if (!common.hasCrypto)
common.skip('missing crypto');
+const assert = require('assert');
const http2 = require('http2');
const { internalBinding } = require('internal/test/binding');
const { Http2Stream } = internalBinding('http2');
@@ -17,10 +18,10 @@ server.on('stream', common.mustCall((stream) => {
stream.respond({ 'content-type': 'text/plain' });
// Should throw if headers already sent
- common.expectsError(
+ assert.throws(
() => stream.respond(),
{
- type: Error,
+ name: 'Error',
code: 'ERR_HTTP2_HEADERS_SENT',
message: 'Response has already been initiated.'
}
@@ -28,10 +29,10 @@ server.on('stream', common.mustCall((stream) => {
// Should throw if stream already destroyed
stream.destroy();
- common.expectsError(
+ assert.throws(
() => stream.respond(),
{
- type: Error,
+ name: 'Error',
code: 'ERR_HTTP2_INVALID_STREAM',
message: 'The stream has been destroyed'
}
diff --git a/test/parallel/test-http2-respond-file-204.js b/test/parallel/test-http2-respond-file-204.js
index b0ba634e67..0c59b0e729 100644
--- a/test/parallel/test-http2-respond-file-204.js
+++ b/test/parallel/test-http2-respond-file-204.js
@@ -4,6 +4,7 @@ const common = require('../common');
if (!common.hasCrypto)
common.skip('missing crypto');
const fixtures = require('../common/fixtures');
+const assert = require('assert');
const http2 = require('http2');
const {
@@ -15,14 +16,14 @@ const fname = fixtures.path('elipses.txt');
const server = http2.createServer();
server.on('stream', (stream) => {
- common.expectsError(() => {
+ assert.throws(() => {
stream.respondWithFile(fname, {
[HTTP2_HEADER_STATUS]: 204,
[HTTP2_HEADER_CONTENT_TYPE]: 'text/plain'
});
}, {
code: 'ERR_HTTP2_PAYLOAD_FORBIDDEN',
- type: Error,
+ name: 'Error',
message: 'Responses with 204 status must not have a payload'
});
stream.respond({});
diff --git a/test/parallel/test-http2-respond-file-404.js b/test/parallel/test-http2-respond-file-404.js
index 60bc21f185..1279fba102 100644
--- a/test/parallel/test-http2-respond-file-404.js
+++ b/test/parallel/test-http2-respond-file-404.js
@@ -20,7 +20,7 @@ server.on('stream', (stream) => {
onError(err) {
common.expectsError({
code: 'ENOENT',
- type: Error,
+ name: 'Error',
message: `ENOENT: no such file or directory, open '${file}'`
})(err);
diff --git a/test/parallel/test-http2-respond-file-error-dir.js b/test/parallel/test-http2-respond-file-error-dir.js
index 24a6d2dc96..155e005432 100644
--- a/test/parallel/test-http2-respond-file-error-dir.js
+++ b/test/parallel/test-http2-respond-file-error-dir.js
@@ -14,7 +14,7 @@ server.on('stream', (stream) => {
onError(err) {
common.expectsError({
code: 'ERR_HTTP2_SEND_FILE',
- type: Error,
+ name: 'Error',
message: 'Directories cannot be sent'
})(err);
diff --git a/test/parallel/test-http2-respond-file-error-pipe-offset.js b/test/parallel/test-http2-respond-file-error-pipe-offset.js
index 1f3b7163f2..b6bf4844c5 100644
--- a/test/parallel/test-http2-respond-file-error-pipe-offset.js
+++ b/test/parallel/test-http2-respond-file-error-pipe-offset.js
@@ -30,7 +30,7 @@ server.on('stream', (stream) => {
onError(err) {
common.expectsError({
code: 'ERR_HTTP2_SEND_FILE_NOSEEK',
- type: Error,
+ name: 'Error',
message: 'Offset or length can only be specified for regular files'
})(err);
diff --git a/test/parallel/test-http2-respond-file-errors.js b/test/parallel/test-http2-respond-file-errors.js
index 96dd579a15..1f2b227f1f 100644
--- a/test/parallel/test-http2-respond-file-errors.js
+++ b/test/parallel/test-http2-respond-file-errors.js
@@ -4,6 +4,7 @@ const common = require('../common');
if (!common.hasCrypto)
common.skip('missing crypto');
const fixtures = require('../common/fixtures');
+const assert = require('assert');
const http2 = require('http2');
const optionsWithTypeError = {
@@ -35,14 +36,14 @@ server.on('stream', common.mustCall((stream) => {
return;
}
- common.expectsError(
+ assert.throws(
() => stream.respondWithFile(fname, {
'content-type': 'text/plain'
}, {
[option]: types[type]
}),
{
- type: TypeError,
+ name: 'TypeError',
code: 'ERR_INVALID_OPT_VALUE',
message: `The value "${String(types[type])}" is invalid ` +
`for option "${option}"`
@@ -52,7 +53,7 @@ server.on('stream', common.mustCall((stream) => {
});
// Should throw if :status 204, 205 or 304
- [204, 205, 304].forEach((status) => common.expectsError(
+ [204, 205, 304].forEach((status) => assert.throws(
() => stream.respondWithFile(fname, {
'content-type': 'text/plain',
':status': status,
@@ -65,7 +66,7 @@ server.on('stream', common.mustCall((stream) => {
// Should throw if headers already sent
stream.respond({ ':status': 200 });
- common.expectsError(
+ assert.throws(
() => stream.respondWithFile(fname, {
'content-type': 'text/plain'
}),
@@ -77,7 +78,7 @@ server.on('stream', common.mustCall((stream) => {
// Should throw if stream already destroyed
stream.destroy();
- common.expectsError(
+ assert.throws(
() => stream.respondWithFile(fname, {
'content-type': 'text/plain'
}),
diff --git a/test/parallel/test-http2-respond-file-fd-errors.js b/test/parallel/test-http2-respond-file-fd-errors.js
index 06e5f6161d..750f762a53 100644
--- a/test/parallel/test-http2-respond-file-fd-errors.js
+++ b/test/parallel/test-http2-respond-file-fd-errors.js
@@ -4,6 +4,7 @@ const common = require('../common');
if (!common.hasCrypto)
common.skip('missing crypto');
const fixtures = require('../common/fixtures');
+const assert = require('assert');
const http2 = require('http2');
const fs = require('fs');
@@ -35,12 +36,12 @@ server.on('stream', common.mustCall((stream) => {
return;
}
- common.expectsError(
+ assert.throws(
() => stream.respondWithFD(types[type], {
'content-type': 'text/plain'
}),
{
- type: TypeError,
+ name: 'TypeError',
code: 'ERR_INVALID_ARG_TYPE',
message: 'The "fd" argument must be of type number or an instance of' +
` FileHandle.${common.invalidArgTypeHelper(types[type])}`
@@ -55,14 +56,14 @@ server.on('stream', common.mustCall((stream) => {
return;
}
- common.expectsError(
+ assert.throws(
() => stream.respondWithFD(fd, {
'content-type': 'text/plain'
}, {
[option]: types[type]
}),
{
- type: TypeError,
+ name: 'TypeError',
code: 'ERR_INVALID_OPT_VALUE',
message: `The value "${String(types[type])}" is invalid ` +
`for option "${option}"`
@@ -72,40 +73,40 @@ server.on('stream', common.mustCall((stream) => {
});
// Should throw if :status 204, 205 or 304
- [204, 205, 304].forEach((status) => common.expectsError(
+ [204, 205, 304].forEach((status) => assert.throws(
() => stream.respondWithFD(fd, {
'content-type': 'text/plain',
':status': status,
}),
{
code: 'ERR_HTTP2_PAYLOAD_FORBIDDEN',
- type: Error,
+ name: 'Error',
message: `Responses with ${status} status must not have a payload`
}
));
// Should throw if headers already sent
stream.respond();
- common.expectsError(
+ assert.throws(
() => stream.respondWithFD(fd, {
'content-type': 'text/plain'
}),
{
code: 'ERR_HTTP2_HEADERS_SENT',
- type: Error,
+ name: 'Error',
message: 'Response has already been initiated.'
}
);
// Should throw if stream already destroyed
stream.destroy();
- common.expectsError(
+ assert.throws(
() => stream.respondWithFD(fd, {
'content-type': 'text/plain'
}),
{
code: 'ERR_HTTP2_INVALID_STREAM',
- type: Error,
+ name: 'Error',
message: 'The stream has been destroyed'
}
);
diff --git a/test/parallel/test-http2-respond-file-fd-invalid.js b/test/parallel/test-http2-respond-file-fd-invalid.js
index 64c8ba541f..448258ef97 100644
--- a/test/parallel/test-http2-respond-file-fd-invalid.js
+++ b/test/parallel/test-http2-respond-file-fd-invalid.js
@@ -14,7 +14,7 @@ const {
const errorCheck = common.expectsError({
code: 'ERR_HTTP2_STREAM_ERROR',
- type: Error,
+ name: 'Error',
message: 'Stream closed with error code NGHTTP2_INTERNAL_ERROR'
}, 2);
@@ -30,7 +30,7 @@ server.on('stream', (stream) => {
}
stream.respondWithFD(fd);
- stream.on('error', common.mustCall(errorCheck));
+ stream.on('error', errorCheck);
});
server.listen(0, () => {
@@ -38,7 +38,7 @@ server.listen(0, () => {
const req = client.request();
req.on('response', common.mustCall());
- req.on('error', common.mustCall(errorCheck));
+ req.on('error', errorCheck);
req.on('data', common.mustNotCall());
req.on('end', common.mustCall(() => {
assert.strictEqual(req.rstCode, NGHTTP2_INTERNAL_ERROR);
diff --git a/test/parallel/test-http2-respond-nghttperrors.js b/test/parallel/test-http2-respond-nghttperrors.js
index 30d20d4b81..cce01ada92 100644
--- a/test/parallel/test-http2-respond-nghttperrors.js
+++ b/test/parallel/test-http2-respond-nghttperrors.js
@@ -28,7 +28,7 @@ const genericTests = Object.getOwnPropertyNames(constants)
ngError: constants[key],
error: {
code: 'ERR_HTTP2_ERROR',
- type: NghttpError,
+ constructor: NghttpError,
name: 'Error',
message: nghttp2ErrorString(constants[key])
},
@@ -80,7 +80,7 @@ function runTest(test) {
const req = client.request(headers);
req.on('error', common.expectsError({
code: 'ERR_HTTP2_STREAM_ERROR',
- type: Error,
+ name: 'Error',
message: 'Stream closed with error code NGHTTP2_INTERNAL_ERROR'
}));
diff --git a/test/parallel/test-http2-respond-with-fd-errors.js b/test/parallel/test-http2-respond-with-fd-errors.js
index 00ed777df5..03cda5d7e7 100644
--- a/test/parallel/test-http2-respond-with-fd-errors.js
+++ b/test/parallel/test-http2-respond-with-fd-errors.js
@@ -35,7 +35,7 @@ const genericTests = Object.getOwnPropertyNames(constants)
ngError: constants[key],
error: {
code: 'ERR_HTTP2_ERROR',
- type: NghttpError,
+ constructor: NghttpError,
name: 'Error',
message: nghttp2ErrorString(constants[key])
},
@@ -88,7 +88,7 @@ function runTest(test) {
req.on('error', common.expectsError({
code: 'ERR_HTTP2_STREAM_ERROR',
- type: Error,
+ name: 'Error',
message: 'Stream closed with error code NGHTTP2_INTERNAL_ERROR'
}));
diff --git a/test/parallel/test-http2-server-http1-client.js b/test/parallel/test-http2-server-http1-client.js
index 394993d4d7..40e97f04a4 100644
--- a/test/parallel/test-http2-server-http1-client.js
+++ b/test/parallel/test-http2-server-http1-client.js
@@ -16,7 +16,7 @@ server.on('session', common.mustCall((session) => {
session.on('close', common.mustCall());
session.on('error', common.expectsError({
code: 'ERR_HTTP2_ERROR',
- type: NghttpError,
+ constructor: NghttpError,
message: 'Received bad client magic byte string'
}));
}));
diff --git a/test/parallel/test-http2-server-push-disabled.js b/test/parallel/test-http2-server-push-disabled.js
index 78b3e26ad4..306c916497 100644
--- a/test/parallel/test-http2-server-push-disabled.js
+++ b/test/parallel/test-http2-server-push-disabled.js
@@ -21,7 +21,7 @@ server.on('stream', common.mustCall((stream) => {
// and pushStream() must throw.
assert.strictEqual(stream.pushAllowed, false);
- common.expectsError(() => {
+ assert.throws(() => {
stream.pushStream({
':scheme': 'http',
':path': '/foobar',
@@ -29,7 +29,7 @@ server.on('stream', common.mustCall((stream) => {
}, common.mustNotCall());
}, {
code: 'ERR_HTTP2_PUSH_DISABLED',
- type: Error
+ name: 'Error'
});
stream.respond({ ':status': 200 });
diff --git a/test/parallel/test-http2-server-push-stream-errors-args.js b/test/parallel/test-http2-server-push-stream-errors-args.js
index c9f9291c4d..ba0aabcf5c 100644
--- a/test/parallel/test-http2-server-push-stream-errors-args.js
+++ b/test/parallel/test-http2-server-push-stream-errors-args.js
@@ -14,7 +14,7 @@ server.on('stream', common.mustCall((stream, headers) => {
const port = server.address().port;
// Must receive a callback (function)
- common.expectsError(
+ assert.throws(
() => stream.pushStream({
':scheme': 'http',
':path': '/foobar',
@@ -27,7 +27,7 @@ server.on('stream', common.mustCall((stream, headers) => {
);
// Must validate headers
- common.expectsError(
+ assert.throws(
() => stream.pushStream({ 'connection': 'test' }, {}, () => {}),
{
code: 'ERR_HTTP2_INVALID_CONNECTION_HEADERS',
diff --git a/test/parallel/test-http2-server-push-stream-errors.js b/test/parallel/test-http2-server-push-stream-errors.js
index b1c5421310..8e4ca37b28 100644
--- a/test/parallel/test-http2-server-push-stream-errors.js
+++ b/test/parallel/test-http2-server-push-stream-errors.js
@@ -28,7 +28,7 @@ const specificTests = [
ngError: constants.NGHTTP2_ERR_STREAM_ID_NOT_AVAILABLE,
error: {
code: 'ERR_HTTP2_OUT_OF_STREAMS',
- type: Error,
+ name: 'Error',
message: 'No stream ID is available because ' +
'maximum stream ID has been reached'
},
@@ -38,7 +38,7 @@ const specificTests = [
ngError: constants.NGHTTP2_ERR_STREAM_CLOSED,
error: {
code: 'ERR_HTTP2_INVALID_STREAM',
- type: Error
+ name: 'Error'
},
type: 'stream'
},
@@ -52,7 +52,7 @@ const genericTests = Object.getOwnPropertyNames(constants)
ngError: constants[key],
error: {
code: 'ERR_HTTP2_ERROR',
- type: NghttpError,
+ constructor: NghttpError,
name: 'Error',
message: nghttp2ErrorString(constants[key])
},
diff --git a/test/parallel/test-http2-server-push-stream-head.js b/test/parallel/test-http2-server-push-stream-head.js
index c1db3ce81e..b87efffa0a 100644
--- a/test/parallel/test-http2-server-push-stream-head.js
+++ b/test/parallel/test-http2-server-push-stream-head.js
@@ -23,7 +23,7 @@ server.on('stream', common.mustCall((stream, headers) => {
push.respond();
// Cannot write to push() anymore
push.on('error', common.expectsError({
- type: Error,
+ name: 'Error',
code: 'ERR_STREAM_WRITE_AFTER_END',
message: 'write after end'
}));
diff --git a/test/parallel/test-http2-server-push-stream.js b/test/parallel/test-http2-server-push-stream.js
index 450d68f08a..43e0e8d932 100644
--- a/test/parallel/test-http2-server-push-stream.js
+++ b/test/parallel/test-http2-server-push-stream.js
@@ -23,11 +23,11 @@ server.on('stream', common.mustCall((stream, headers) => {
});
push.end('pushed by server data');
- common.expectsError(() => {
+ assert.throws(() => {
push.pushStream({}, common.mustNotCall());
}, {
code: 'ERR_HTTP2_NESTED_PUSH',
- type: Error
+ name: 'Error'
});
stream.end('test');
diff --git a/test/parallel/test-http2-server-rst-before-respond.js b/test/parallel/test-http2-server-rst-before-respond.js
index 78fca25a82..d551c7121f 100644
--- a/test/parallel/test-http2-server-rst-before-respond.js
+++ b/test/parallel/test-http2-server-rst-before-respond.js
@@ -14,7 +14,7 @@ server.on('stream', common.mustCall(onStream));
function onStream(stream, headers, flags) {
stream.close();
- common.expectsError(() => {
+ assert.throws(() => {
stream.additionalHeaders({
':status': 123,
'abc': 123
diff --git a/test/parallel/test-http2-server-rst-stream.js b/test/parallel/test-http2-server-rst-stream.js
index 132c32ead6..e76db1bf1a 100644
--- a/test/parallel/test-http2-server-rst-stream.js
+++ b/test/parallel/test-http2-server-rst-stream.js
@@ -29,7 +29,7 @@ server.on('stream', (stream, headers) => {
const test = tests.find((t) => t[0] === Number(headers.rstcode));
if (test[1]) {
stream.on('error', common.expectsError({
- type: Error,
+ name: 'Error',
code: 'ERR_HTTP2_STREAM_ERROR',
message: `Stream closed with error code ${test[2]}`
}));
diff --git a/test/parallel/test-http2-server-sessionerror.js b/test/parallel/test-http2-server-sessionerror.js
index c50352fcc3..bbd180937e 100644
--- a/test/parallel/test-http2-server-sessionerror.js
+++ b/test/parallel/test-http2-server-sessionerror.js
@@ -18,7 +18,7 @@ server.on('session', common.mustCall((session) => {
case 1:
server.on('error', common.mustNotCall());
session.on('error', common.expectsError({
- type: Error,
+ name: 'Error',
message: 'test'
}));
session[kSocket].emit('error', new Error('test'));
diff --git a/test/parallel/test-http2-server-settimeout-no-callback.js b/test/parallel/test-http2-server-settimeout-no-callback.js
index 5dff0fa8e7..31a64731f6 100644
--- a/test/parallel/test-http2-server-settimeout-no-callback.js
+++ b/test/parallel/test-http2-server-settimeout-no-callback.js
@@ -13,10 +13,10 @@ const verifyCallbacks = (server) => {
const testTimeout = 10;
[true, 1, {}, [], null, 'test'].forEach((notFunction) => {
- common.expectsError(
+ assert.throws(
() => server.setTimeout(testTimeout, notFunction),
{
- type: TypeError,
+ name: 'TypeError',
code: 'ERR_INVALID_CALLBACK',
message: 'Callback must be a function. ' +
`Received ${inspect(notFunction)}`
diff --git a/test/parallel/test-http2-server-shutdown-options-errors.js b/test/parallel/test-http2-server-shutdown-options-errors.js
index 0109a147aa..643d173f78 100644
--- a/test/parallel/test-http2-server-shutdown-options-errors.js
+++ b/test/parallel/test-http2-server-shutdown-options-errors.js
@@ -3,6 +3,7 @@
const common = require('../common');
if (!common.hasCrypto)
common.skip('missing crypto');
+const assert = require('assert');
const http2 = require('http2');
const server = http2.createServer();
@@ -20,29 +21,29 @@ server.on('stream', common.mustCall((stream) => {
types.forEach((input) => {
const received = common.invalidArgTypeHelper(input);
- common.expectsError(
+ assert.throws(
() => session.goaway(input),
{
code: 'ERR_INVALID_ARG_TYPE',
- type: TypeError,
+ name: 'TypeError',
message: 'The "code" argument must be of type number.' +
received
}
);
- common.expectsError(
+ assert.throws(
() => session.goaway(0, input),
{
code: 'ERR_INVALID_ARG_TYPE',
- type: TypeError,
+ name: 'TypeError',
message: 'The "lastStreamID" argument must be of type number.' +
received
}
);
- common.expectsError(
+ assert.throws(
() => session.goaway(0, 0, input),
{
code: 'ERR_INVALID_ARG_TYPE',
- type: TypeError,
+ name: 'TypeError',
message: 'The "opaqueData" argument must be an instance of Buffer, ' +
`TypedArray, or DataView.${received}`
}
diff --git a/test/parallel/test-http2-server-shutdown-redundant.js b/test/parallel/test-http2-server-shutdown-redundant.js
index f47a0d2c95..0f199bd68a 100644
--- a/test/parallel/test-http2-server-shutdown-redundant.js
+++ b/test/parallel/test-http2-server-shutdown-redundant.js
@@ -3,6 +3,7 @@
const common = require('../common');
if (!common.hasCrypto)
common.skip('missing crypto');
+const assert = require('assert');
const http2 = require('http2');
const server = http2.createServer();
@@ -12,11 +13,11 @@ server.on('stream', common.mustCall((stream) => {
session.goaway(1);
session.goaway(2);
stream.session.on('close', common.mustCall(() => {
- common.expectsError(
+ assert.throws(
() => session.goaway(3),
{
code: 'ERR_HTTP2_INVALID_SESSION',
- type: Error
+ name: 'Error'
}
);
}));
diff --git a/test/parallel/test-http2-server-stream-session-destroy.js b/test/parallel/test-http2-server-stream-session-destroy.js
index daa618d510..b25dfbb347 100644
--- a/test/parallel/test-http2-server-stream-session-destroy.js
+++ b/test/parallel/test-http2-server-stream-session-destroy.js
@@ -20,27 +20,27 @@ server.on('stream', common.mustCall((stream) => {
// Test that ERR_HTTP2_INVALID_STREAM is thrown while calling
// stream operations after the stream session has been destroyed
const invalidStreamError = {
- type: Error,
+ name: 'Error',
code: 'ERR_HTTP2_INVALID_STREAM',
message: 'The stream has been destroyed'
};
- common.expectsError(() => stream.additionalHeaders(), invalidStreamError);
- common.expectsError(() => stream.priority(), invalidStreamError);
- common.expectsError(() => stream.respond(), invalidStreamError);
- common.expectsError(
+ assert.throws(() => stream.additionalHeaders(), invalidStreamError);
+ assert.throws(() => stream.priority(), invalidStreamError);
+ assert.throws(() => stream.respond(), invalidStreamError);
+ assert.throws(
() => stream.pushStream({}, common.mustNotCall()),
{
code: 'ERR_HTTP2_PUSH_DISABLED',
- type: Error
+ name: 'Error'
}
);
stream.on('error', common.expectsError({
- type: Error,
+ name: 'Error',
code: 'ERR_STREAM_WRITE_AFTER_END',
message: 'write after end'
}));
assert.strictEqual(stream.write('data', common.expectsError({
- type: Error,
+ name: 'Error',
code: 'ERR_STREAM_WRITE_AFTER_END',
message: 'write after end'
})), false);
diff --git a/test/parallel/test-http2-session-settings.js b/test/parallel/test-http2-session-settings.js
index 35581d5f71..6ac6a1d4aa 100644
--- a/test/parallel/test-http2-session-settings.js
+++ b/test/parallel/test-http2-session-settings.js
@@ -104,10 +104,10 @@ server.listen(
].forEach((i) => {
const settings = {};
settings[i[0]] = i[1];
- common.expectsError(
+ assert.throws(
() => client.settings(settings),
{
- type: RangeError,
+ name: 'RangeError',
code: 'ERR_HTTP2_INVALID_SETTING_VALUE',
message: `Invalid value for setting "${i[0]}": ${i[1]}`
}
@@ -116,10 +116,10 @@ server.listen(
// Error checks for enablePush
[1, {}, 'test', [], null, Infinity, NaN].forEach((i) => {
- common.expectsError(
+ assert.throws(
() => client.settings({ enablePush: i }),
{
- type: TypeError,
+ name: 'TypeError',
code: 'ERR_HTTP2_INVALID_SETTING_VALUE',
message: `Invalid value for setting "enablePush": ${i}`
}
diff --git a/test/parallel/test-http2-single-headers.js b/test/parallel/test-http2-single-headers.js
index 37eaf8b17c..6f20c1b356 100644
--- a/test/parallel/test-http2-single-headers.js
+++ b/test/parallel/test-http2-single-headers.js
@@ -3,6 +3,7 @@
const common = require('../common');
if (!common.hasCrypto)
common.skip('missing crypto');
+const assert = require('assert');
const http2 = require('http2');
const server = http2.createServer();
@@ -27,20 +28,20 @@ server.listen(0, common.mustCall(() => {
const client = http2.connect(`http://localhost:${server.address().port}`);
singles.forEach((i) => {
- common.expectsError(
+ assert.throws(
() => client.request({ [i]: 'abc', [i.toUpperCase()]: 'xyz' }),
{
code: 'ERR_HTTP2_HEADER_SINGLE_VALUE',
- type: TypeError,
+ name: 'TypeError',
message: `Header field "${i}" must only have a single value`
}
);
- common.expectsError(
+ assert.throws(
() => client.request({ [i]: ['abc', 'xyz'] }),
{
code: 'ERR_HTTP2_HEADER_SINGLE_VALUE',
- type: TypeError,
+ name: 'TypeError',
message: `Header field "${i}" must only have a single value`
}
);
diff --git a/test/parallel/test-http2-socket-proxy.js b/test/parallel/test-http2-socket-proxy.js
index 600271fdef..7450068317 100644
--- a/test/parallel/test-http2-socket-proxy.js
+++ b/test/parallel/test-http2-socket-proxy.js
@@ -16,7 +16,7 @@ const { kTimeout } = require('internal/timers');
const errMsg = {
code: 'ERR_HTTP2_NO_SOCKET_MANIPULATION',
- type: Error,
+ name: 'Error',
message: 'HTTP/2 sockets should not be directly manipulated ' +
'(e.g. read and written)'
};
@@ -52,27 +52,27 @@ server.on('stream', common.mustCall(function(stream, headers) {
assert(inspectedTimersList.includes(' _idleNext: [Timeout]'));
assert(!inspectedTimersList.includes(' _idleNext: [Timeout]'));
- common.expectsError(() => socket.destroy, errMsg);
- common.expectsError(() => socket.emit, errMsg);
- common.expectsError(() => socket.end, errMsg);
- common.expectsError(() => socket.pause, errMsg);
- common.expectsError(() => socket.read, errMsg);
- common.expectsError(() => socket.resume, errMsg);
- common.expectsError(() => socket.write, errMsg);
- common.expectsError(() => socket.setEncoding, errMsg);
- common.expectsError(() => socket.setKeepAlive, errMsg);
- common.expectsError(() => socket.setNoDelay, errMsg);
-
- common.expectsError(() => (socket.destroy = undefined), errMsg);
- common.expectsError(() => (socket.emit = undefined), errMsg);
- common.expectsError(() => (socket.end = undefined), errMsg);
- common.expectsError(() => (socket.pause = undefined), errMsg);
- common.expectsError(() => (socket.read = undefined), errMsg);
- common.expectsError(() => (socket.resume = undefined), errMsg);
- common.expectsError(() => (socket.write = undefined), errMsg);
- common.expectsError(() => (socket.setEncoding = undefined), errMsg);
- common.expectsError(() => (socket.setKeepAlive = undefined), errMsg);
- common.expectsError(() => (socket.setNoDelay = undefined), errMsg);
+ assert.throws(() => socket.destroy, errMsg);
+ assert.throws(() => socket.emit, errMsg);
+ assert.throws(() => socket.end, errMsg);
+ assert.throws(() => socket.pause, errMsg);
+ assert.throws(() => socket.read, errMsg);
+ assert.throws(() => socket.resume, errMsg);
+ assert.throws(() => socket.write, errMsg);
+ assert.throws(() => socket.setEncoding, errMsg);
+ assert.throws(() => socket.setKeepAlive, errMsg);
+ assert.throws(() => socket.setNoDelay, errMsg);
+
+ assert.throws(() => (socket.destroy = undefined), errMsg);
+ assert.throws(() => (socket.emit = undefined), errMsg);
+ assert.throws(() => (socket.end = undefined), errMsg);
+ assert.throws(() => (socket.pause = undefined), errMsg);
+ assert.throws(() => (socket.read = undefined), errMsg);
+ assert.throws(() => (socket.resume = undefined), errMsg);
+ assert.throws(() => (socket.write = undefined), errMsg);
+ assert.throws(() => (socket.setEncoding = undefined), errMsg);
+ assert.throws(() => (socket.setKeepAlive = undefined), errMsg);
+ assert.throws(() => (socket.setNoDelay = undefined), errMsg);
// Resetting the socket listeners to their own value should not throw.
socket.on = socket.on; // eslint-disable-line no-self-assign
diff --git a/test/parallel/test-http2-status-code-invalid.js b/test/parallel/test-http2-status-code-invalid.js
index 3337aad32d..a906c706d7 100644
--- a/test/parallel/test-http2-status-code-invalid.js
+++ b/test/parallel/test-http2-status-code-invalid.js
@@ -11,7 +11,7 @@ const server = http2.createServer();
function expectsError(code) {
return common.expectsError({
code: 'ERR_HTTP2_STATUS_INVALID',
- type: RangeError,
+ name: 'RangeError',
message: `Invalid status code: ${code}`
});
}
diff --git a/test/parallel/test-http2-timeouts.js b/test/parallel/test-http2-timeouts.js
index be41f20202..a67b722715 100644
--- a/test/parallel/test-http2-timeouts.js
+++ b/test/parallel/test-http2-timeouts.js
@@ -3,6 +3,7 @@
const common = require('../common');
if (!common.hasCrypto)
common.skip('missing crypto');
+const assert = require('assert');
const h2 = require('http2');
const server = h2.createServer();
@@ -15,29 +16,29 @@ server.on('stream', common.mustCall((stream) => {
}));
// Check that expected errors are thrown with wrong args
- common.expectsError(
+ assert.throws(
() => stream.setTimeout('100'),
{
code: 'ERR_INVALID_ARG_TYPE',
- type: TypeError,
+ name: 'TypeError',
message:
'The "msecs" argument must be of type number. Received type string' +
" ('100')"
}
);
- common.expectsError(
+ assert.throws(
() => stream.setTimeout(0, Symbol('test')),
{
code: 'ERR_INVALID_CALLBACK',
- type: TypeError,
+ name: 'TypeError',
message: 'Callback must be a function. Received Symbol(test)'
}
);
- common.expectsError(
+ assert.throws(
() => stream.setTimeout(100, {}),
{
code: 'ERR_INVALID_CALLBACK',
- type: TypeError,
+ name: 'TypeError',
message: 'Callback must be a function. Received {}'
}
);
diff --git a/test/parallel/test-http2-too-large-headers.js b/test/parallel/test-http2-too-large-headers.js
index b62a41d05f..aad113deab 100644
--- a/test/parallel/test-http2-too-large-headers.js
+++ b/test/parallel/test-http2-too-large-headers.js
@@ -19,7 +19,7 @@ server.listen(0, common.mustCall(() => {
const req = client.request({ 'foo': 'a'.repeat(1000) });
req.on('error', common.expectsError({
code: 'ERR_HTTP2_STREAM_ERROR',
- type: Error,
+ name: 'Error',
message: 'Stream closed with error code NGHTTP2_ENHANCE_YOUR_CALM'
}));
req.on('close', common.mustCall(() => {
diff --git a/test/parallel/test-http2-too-many-headers.js b/test/parallel/test-http2-too-many-headers.js
index 6c8315c80e..f77e7679d7 100644
--- a/test/parallel/test-http2-too-many-headers.js
+++ b/test/parallel/test-http2-too-many-headers.js
@@ -22,7 +22,7 @@ server.listen(0, common.mustCall(() => {
const req = client.request({ foo: 'bar' });
req.on('error', common.expectsError({
code: 'ERR_HTTP2_STREAM_ERROR',
- type: Error,
+ name: 'Error',
message: 'Stream closed with error code NGHTTP2_ENHANCE_YOUR_CALM'
}));
req.on('close', common.mustCall(() => {
diff --git a/test/parallel/test-http2-too-many-settings.js b/test/parallel/test-http2-too-many-settings.js
index acfd73ada6..b87e921a91 100644
--- a/test/parallel/test-http2-too-many-settings.js
+++ b/test/parallel/test-http2-too-many-settings.js
@@ -14,7 +14,7 @@ const maxOutstandingSettings = 2;
function doTest(session) {
session.on('error', common.expectsError({
code: 'ERR_HTTP2_MAX_PENDING_SETTINGS_ACK',
- type: Error
+ name: 'Error'
}));
for (let n = 0; n < maxOutstandingSettings; n++) {
session.settings({ enablePush: false });
diff --git a/test/parallel/test-http2-trailers.js b/test/parallel/test-http2-trailers.js
index 98b9b5d4a0..dba9aac12d 100644
--- a/test/parallel/test-http2-trailers.js
+++ b/test/parallel/test-http2-trailers.js
@@ -26,20 +26,20 @@ function onStream(stream, headers, flags) {
}, { waitForTrailers: true });
stream.on('wantTrailers', () => {
stream.sendTrailers({ [trailerKey]: trailerValue });
- common.expectsError(
+ assert.throws(
() => stream.sendTrailers({}),
{
code: 'ERR_HTTP2_TRAILERS_ALREADY_SENT',
- type: Error
+ name: 'Error'
}
);
});
- common.expectsError(
+ assert.throws(
() => stream.sendTrailers({}),
{
code: 'ERR_HTTP2_TRAILERS_NOT_READY',
- type: Error
+ name: 'Error'
}
);
}
@@ -58,11 +58,11 @@ server.on('listening', common.mustCall(function() {
assert.strictEqual(headers[trailerKey], trailerValue);
}));
req.on('close', common.mustCall(() => {
- common.expectsError(
+ assert.throws(
() => req.sendTrailers({}),
{
code: 'ERR_HTTP2_INVALID_STREAM',
- type: Error
+ name: 'Error'
}
);
server.close();
diff --git a/test/parallel/test-http2-unbound-socket-proxy.js b/test/parallel/test-http2-unbound-socket-proxy.js
index 18881574f2..a5505c8509 100644
--- a/test/parallel/test-http2-unbound-socket-proxy.js
+++ b/test/parallel/test-http2-unbound-socket-proxy.js
@@ -3,6 +3,7 @@
const common = require('../common');
if (!common.hasCrypto)
common.skip('missing crypto');
+const assert = require('assert');
const http2 = require('http2');
const net = require('net');
@@ -24,17 +25,17 @@ server.listen(0, common.mustCall(() => {
// Tests to make sure accessing the socket proxy fails with an
// informative error.
setImmediate(common.mustCall(() => {
- common.expectsError(() => {
+ assert.throws(() => {
socket.example;
}, {
code: 'ERR_HTTP2_SOCKET_UNBOUND'
});
- common.expectsError(() => {
+ assert.throws(() => {
socket.example = 1;
}, {
code: 'ERR_HTTP2_SOCKET_UNBOUND'
});
- common.expectsError(() => {
+ assert.throws(() => {
socket instanceof net.Socket;
}, {
code: 'ERR_HTTP2_SOCKET_UNBOUND'
diff --git a/test/parallel/test-http2-util-assert-valid-pseudoheader.js b/test/parallel/test-http2-util-assert-valid-pseudoheader.js
index b0d7ac0e58..f86793c69e 100644
--- a/test/parallel/test-http2-util-assert-valid-pseudoheader.js
+++ b/test/parallel/test-http2-util-assert-valid-pseudoheader.js
@@ -1,7 +1,8 @@
// Flags: --expose-internals
'use strict';
-const common = require('../common');
+require('../common');
+const assert = require('assert');
// Tests the assertValidPseudoHeader function that is used within the
// mapToHeaders function. The assert function is not exported so we
@@ -16,8 +17,8 @@ mapToHeaders({ ':authority': 'a' });
mapToHeaders({ ':scheme': 'a' });
mapToHeaders({ ':method': 'a' });
-common.expectsError(() => mapToHeaders({ ':foo': 'a' }), {
+assert.throws(() => mapToHeaders({ ':foo': 'a' }), {
code: 'ERR_HTTP2_INVALID_PSEUDOHEADER',
- type: TypeError,
+ name: 'TypeError',
message: '":foo" is an invalid pseudoheader or is used incorrectly'
});
diff --git a/test/parallel/test-http2-util-asserts.js b/test/parallel/test-http2-util-asserts.js
index e80f712837..5bbc1cde43 100644
--- a/test/parallel/test-http2-util-asserts.js
+++ b/test/parallel/test-http2-util-asserts.js
@@ -2,6 +2,7 @@
'use strict';
const common = require('../common');
+const assert = require('assert');
const {
assertIsObject,
assertWithinRange,
@@ -26,7 +27,7 @@ const {
[],
[{}]
].forEach((input) => {
- common.expectsError(
+ assert.throws(
() => assertIsObject(input, 'foo', 'Object'),
{
code: 'ERR_INVALID_ARG_TYPE',
@@ -37,8 +38,8 @@ const {
assertWithinRange('foo', 1, 0, 2);
-common.expectsError(() => assertWithinRange('foo', 1, 2, 3),
- {
- code: 'ERR_HTTP2_INVALID_SETTING_VALUE',
- message: 'Invalid value for setting "foo": 1'
- });
+assert.throws(() => assertWithinRange('foo', 1, 2, 3),
+ {
+ code: 'ERR_HTTP2_INVALID_SETTING_VALUE',
+ message: 'Invalid value for setting "foo": 1'
+ });
diff --git a/test/parallel/test-http2-util-headers-list.js b/test/parallel/test-http2-util-headers-list.js
index 5045263b15..a964c361b7 100644
--- a/test/parallel/test-http2-util-headers-list.js
+++ b/test/parallel/test-http2-util-headers-list.js
@@ -175,9 +175,9 @@ const {
':statuS': 204,
};
- common.expectsError(() => mapToHeaders(headers), {
+ assert.throws(() => mapToHeaders(headers), {
code: 'ERR_HTTP2_HEADER_SINGLE_VALUE',
- type: TypeError,
+ name: 'TypeError',
message: 'Header field ":status" must only have a single value'
});
}
@@ -224,7 +224,7 @@ const {
HTTP2_HEADER_X_CONTENT_TYPE_OPTIONS
].forEach((name) => {
const msg = `Header field "${name}" must only have a single value`;
- common.expectsError(() => mapToHeaders({ [name]: [1, 2, 3] }), {
+ assert.throws(() => mapToHeaders({ [name]: [1, 2, 3] }), {
code: 'ERR_HTTP2_HEADER_SINGLE_VALUE',
message: msg
});
@@ -281,7 +281,7 @@ const {
'Proxy-Connection',
'Keep-Alive'
].forEach((name) => {
- common.expectsError(() => mapToHeaders({ [name]: 'abc' }), {
+ assert.throws(() => mapToHeaders({ [name]: 'abc' }), {
code: 'ERR_HTTP2_INVALID_CONNECTION_HEADERS',
name: 'TypeError',
message: 'HTTP/1 Connection specific headers are forbidden: ' +
@@ -289,14 +289,14 @@ const {
});
});
-common.expectsError(() => mapToHeaders({ [HTTP2_HEADER_TE]: ['abc'] }), {
+assert.throws(() => mapToHeaders({ [HTTP2_HEADER_TE]: ['abc'] }), {
code: 'ERR_HTTP2_INVALID_CONNECTION_HEADERS',
name: 'TypeError',
message: 'HTTP/1 Connection specific headers are forbidden: ' +
`"${HTTP2_HEADER_TE}"`
});
-common.expectsError(
+assert.throws(
() => mapToHeaders({ [HTTP2_HEADER_TE]: ['abc', 'trailers'] }), {
code: 'ERR_HTTP2_INVALID_CONNECTION_HEADERS',
name: 'TypeError',
diff --git a/test/parallel/test-http2-util-nghttp2error.js b/test/parallel/test-http2-util-nghttp2error.js
index 100ce2cb45..ae561204bc 100644
--- a/test/parallel/test-http2-util-nghttp2error.js
+++ b/test/parallel/test-http2-util-nghttp2error.js
@@ -1,17 +1,17 @@
// Flags: --expose-internals
'use strict';
-const common = require('../common');
-const { strictEqual } = require('assert');
+require('../common');
+const { strictEqual, throws } = require('assert');
const { NghttpError } = require('internal/http2/util');
-common.expectsError(() => {
+throws(() => {
const err = new NghttpError(-501);
strictEqual(err.errno, -501);
throw err;
}, {
code: 'ERR_HTTP2_ERROR',
- type: NghttpError,
+ constructor: NghttpError,
message: 'Invalid argument'
});
diff --git a/test/parallel/test-https-timeout.js b/test/parallel/test-https-timeout.js
index 6955ef0af1..d8f128db72 100644
--- a/test/parallel/test-https-timeout.js
+++ b/test/parallel/test-https-timeout.js
@@ -54,7 +54,7 @@ const server = https.createServer(options, function() {
req.on('error', common.expectsError({
message: 'socket hang up',
code: 'ECONNRESET',
- type: Error
+ name: 'Error'
}));
req.on('timeout', common.mustCall(function() {
diff --git a/test/parallel/test-icu-punycode.js b/test/parallel/test-icu-punycode.js
index 7706c1d837..bfb7dcd8e6 100644
--- a/test/parallel/test-icu-punycode.js
+++ b/test/parallel/test-icu-punycode.js
@@ -41,11 +41,11 @@ const wptToASCIITests = require(
if (comment)
caseComment += ` (${comment})`;
if (output === null) {
- common.expectsError(
+ assert.throws(
() => icu.toASCII(input),
{
code: 'ERR_INVALID_ARG_VALUE',
- type: TypeError,
+ name: 'TypeError',
message: 'Cannot convert name to ASCII'
}
);
diff --git a/test/parallel/test-icu-transcode.js b/test/parallel/test-icu-transcode.js
index ec28d37bf7..20ecab7213 100644
--- a/test/parallel/test-icu-transcode.js
+++ b/test/parallel/test-icu-transcode.js
@@ -41,10 +41,10 @@ for (const test in tests) {
utf8_to_ucs2.toString('ucs2'));
}
-common.expectsError(
+assert.throws(
() => buffer.transcode(null, 'utf8', 'ascii'),
{
- type: TypeError,
+ name: 'TypeError',
code: 'ERR_INVALID_ARG_TYPE',
message: 'The "source" argument must be an instance of Buffer ' +
'or Uint8Array. Received null'
diff --git a/test/parallel/test-internal-errors.js b/test/parallel/test-internal-errors.js
index a34218fd1d..fbb8a0a86a 100644
--- a/test/parallel/test-internal-errors.js
+++ b/test/parallel/test-internal-errors.js
@@ -58,22 +58,22 @@ errors.E('TEST_ERROR_2', (a, b) => `${a} ${b}`, Error);
}
// Tests for common.expectsError
-common.expectsError(() => {
+assert.throws(() => {
throw new errors.codes.TEST_ERROR_1.TypeError('a');
}, { code: 'TEST_ERROR_1' });
-common.expectsError(() => {
+assert.throws(() => {
throw new errors.codes.TEST_ERROR_1.TypeError('a');
}, { code: 'TEST_ERROR_1',
- type: TypeError,
+ name: 'TypeError',
message: /^Error for testing/ });
-common.expectsError(() => {
+assert.throws(() => {
throw new errors.codes.TEST_ERROR_1.TypeError('a');
-}, { code: 'TEST_ERROR_1', type: TypeError });
-common.expectsError(() => {
+}, { code: 'TEST_ERROR_1', name: 'TypeError' });
+assert.throws(() => {
throw new errors.codes.TEST_ERROR_1.TypeError('a');
}, {
code: 'TEST_ERROR_1',
- type: TypeError,
+ name: 'TypeError',
message: 'Error for testing purposes: a'
});
diff --git a/test/parallel/test-internal-fs.js b/test/parallel/test-internal-fs.js
index bfdf0022f4..955e35c573 100644
--- a/test/parallel/test-internal-fs.js
+++ b/test/parallel/test-internal-fs.js
@@ -1,7 +1,7 @@
// Flags: --expose-internals
'use strict';
-const common = require('../common');
+require('../common');
const assert = require('assert');
const fs = require('internal/fs/utils');
@@ -9,9 +9,9 @@ const fs = require('internal/fs/utils');
fs.assertEncoding();
fs.assertEncoding('utf8');
-common.expectsError(
+assert.throws(
() => fs.assertEncoding('foo'),
- { code: 'ERR_INVALID_OPT_VALUE_ENCODING', type: TypeError }
+ { code: 'ERR_INVALID_OPT_VALUE_ENCODING', name: 'TypeError' }
);
// Test junction symlinks
diff --git a/test/parallel/test-internal-module-require.js b/test/parallel/test-internal-module-require.js
index 17559d2287..5b20a83393 100644
--- a/test/parallel/test-internal-module-require.js
+++ b/test/parallel/test-internal-module-require.js
@@ -79,7 +79,7 @@ if (process.argv[2] === 'child') {
const publicModules = new Set();
for (const id of allBuiltins) {
if (id.startsWith('internal/')) {
- common.expectsError(() => {
+ assert.throws(() => {
require(id);
}, {
code: 'MODULE_NOT_FOUND',
diff --git a/test/parallel/test-internal-socket-list-send.js b/test/parallel/test-internal-socket-list-send.js
index 2e69edcedf..a4012c7cc3 100644
--- a/test/parallel/test-internal-socket-list-send.js
+++ b/test/parallel/test-internal-socket-list-send.js
@@ -19,7 +19,7 @@ const key = 'test-key';
list._request('msg', 'cmd', false, common.mustCall((err) => {
common.expectsError({
code: 'ERR_CHILD_CLOSED_BEFORE_REPLY',
- type: Error,
+ name: 'Error',
message: 'Child closed before reply received'
})(err);
assert.strictEqual(child.listenerCount('internalMessage'), 0);
@@ -61,7 +61,7 @@ const key = 'test-key';
list._request('msg', 'cmd', false, common.mustCall((err) => {
common.expectsError({
code: 'ERR_CHILD_CLOSED_BEFORE_REPLY',
- type: Error,
+ name: 'Error',
message: 'Child closed before reply received'
})(err);
assert.strictEqual(child.listenerCount('internalMessage'), 0);
@@ -140,7 +140,7 @@ const key = 'test-key';
list.getConnections(common.mustCall((err) => {
common.expectsError({
code: 'ERR_CHILD_CLOSED_BEFORE_REPLY',
- type: Error,
+ name: 'Error',
message: 'Child closed before reply received'
})(err);
assert.strictEqual(child.listenerCount('internalMessage'), 0);
diff --git a/test/parallel/test-internal-util-assertCrypto.js b/test/parallel/test-internal-util-assertCrypto.js
index 035519c9c9..a6a1610d45 100644
--- a/test/parallel/test-internal-util-assertCrypto.js
+++ b/test/parallel/test-internal-util-assertCrypto.js
@@ -7,7 +7,7 @@ const util = require('internal/util');
if (!process.versions.openssl) {
const expectedError = common.expectsError({
code: 'ERR_NO_CRYPTO',
- type: Error
+ name: 'Error'
});
assert.throws(() => util.assertCrypto(), expectedError);
} else {
diff --git a/test/parallel/test-loaders-hidden-from-users.js b/test/parallel/test-loaders-hidden-from-users.js
index ab9a997b50..96d1c44154 100644
--- a/test/parallel/test-loaders-hidden-from-users.js
+++ b/test/parallel/test-loaders-hidden-from-users.js
@@ -2,9 +2,10 @@
'use strict';
-const common = require('../common');
+require('../common');
+const assert = require('assert');
-common.expectsError(
+assert.throws(
() => {
require('internal/bootstrap/loaders');
}, {
@@ -13,7 +14,7 @@ common.expectsError(
}
);
-common.expectsError(
+assert.throws(
() => {
const source = 'module.exports = require("internal/bootstrap/loaders")';
const { internalBinding } = require('internal/test/binding');
diff --git a/test/parallel/test-module-loading-error.js b/test/parallel/test-module-loading-error.js
index 70921467ac..5bc01ce52d 100644
--- a/test/parallel/test-module-loading-error.js
+++ b/test/parallel/test-module-loading-error.js
@@ -66,20 +66,20 @@ assert.throws(
const re = /^The "id" argument must be of type string\. Received /;
[1, false, null, undefined, {}].forEach((value) => {
- common.expectsError(
+ assert.throws(
() => { require(value); },
{
- type: TypeError,
+ name: 'TypeError',
code: 'ERR_INVALID_ARG_TYPE',
message: re
});
});
-common.expectsError(
+assert.throws(
() => { require(''); },
{
- type: TypeError,
+ name: 'TypeError',
code: 'ERR_INVALID_ARG_VALUE',
message: 'The argument \'id\' must be a non-empty string. Received \'\''
});
diff --git a/test/parallel/test-net-better-error-messages-path.js b/test/parallel/test-net-better-error-messages-path.js
index 0d16894ff8..93a5e38fac 100644
--- a/test/parallel/test-net-better-error-messages-path.js
+++ b/test/parallel/test-net-better-error-messages-path.js
@@ -1,5 +1,6 @@
'use strict';
const common = require('../common');
+const assert = require('assert');
const net = require('net');
{
@@ -14,7 +15,7 @@ const net = require('net');
}
{
- common.expectsError(
+ assert.throws(
() => net.createConnection({ path: {} }),
{ code: 'ERR_INVALID_ARG_TYPE' }
);
diff --git a/test/parallel/test-net-better-error-messages-port-hostname.js b/test/parallel/test-net-better-error-messages-port-hostname.js
index f8e997db33..3cc9e58987 100644
--- a/test/parallel/test-net-better-error-messages-port-hostname.js
+++ b/test/parallel/test-net-better-error-messages-port-hostname.js
@@ -5,6 +5,7 @@
// See https://github.com/nodejs/node-v0.x-archive/issues/7005
const common = require('../common');
+const assert = require('assert');
const net = require('net');
const { addresses } = require('../common/internet');
@@ -22,9 +23,15 @@ const c = net.createConnection({
c.on('connect', common.mustNotCall());
-c.on('error', common.expectsError({
- code: mockedErrorCode,
- hostname: addresses.INVALID_HOST,
- port: undefined,
- host: undefined
+c.on('error', common.mustCall((error) => {
+ assert.ok(!('port' in error));
+ assert.ok(!('host' in error));
+ assert.throws(() => { throw error; }, {
+ errno: mockedErrorCode,
+ code: mockedErrorCode,
+ name: 'Error',
+ message: 'getaddrinfo ENOTFOUND something.invalid',
+ hostname: addresses.INVALID_HOST,
+ syscall: 'getaddrinfo'
+ });
}));
diff --git a/test/parallel/test-net-connect-immediate-finish.js b/test/parallel/test-net-connect-immediate-finish.js
index cb430a5a8c..1cc4fa4f4e 100644
--- a/test/parallel/test-net-connect-immediate-finish.js
+++ b/test/parallel/test-net-connect-immediate-finish.js
@@ -26,6 +26,7 @@
// 'connect' and defer the handling until the 'connect' event is handled.
const common = require('../common');
+const assert = require('assert');
const net = require('net');
const { addresses } = require('../common/internet');
@@ -41,14 +42,18 @@ const client = net.connect({
lookup: common.mustCall(errorLookupMock())
}, common.mustNotCall());
-client.once('error', common.expectsError({
- code: mockedErrorCode,
- errno: mockedErrorCode,
- syscall: mockedSysCall,
- hostname: addresses.INVALID_HOST,
- message: 'getaddrinfo ENOTFOUND something.invalid',
- port: undefined,
- host: undefined
+client.once('error', common.mustCall((error) => {
+ // TODO(BridgeAR): Add a better way to handle not defined properties using
+ // `assert.throws(fn, object)`.
+ assert.ok(!('port' in error));
+ assert.ok(!('host' in error));
+ assert.throws(() => { throw error; }, {
+ code: mockedErrorCode,
+ errno: mockedErrorCode,
+ syscall: mockedSysCall,
+ hostname: addresses.INVALID_HOST,
+ message: 'getaddrinfo ENOTFOUND something.invalid'
+ });
}));
client.end();
diff --git a/test/parallel/test-net-connect-options-port.js b/test/parallel/test-net-connect-options-port.js
index c22630d433..88e626354e 100644
--- a/test/parallel/test-net-connect-options-port.js
+++ b/test/parallel/test-net-connect-options-port.js
@@ -27,10 +27,10 @@ const net = require('net');
// Test wrong type of ports
{
- const portTypeError = common.expectsError({
+ const portTypeError = {
code: 'ERR_INVALID_ARG_TYPE',
- type: TypeError
- }, 96);
+ name: 'TypeError'
+ };
syncFailToConnect(true, portTypeError);
syncFailToConnect(false, portTypeError);
@@ -41,10 +41,10 @@ const net = require('net');
// Test out of range ports
{
- const portRangeError = common.expectsError({
+ const portRangeError = {
code: 'ERR_SOCKET_BAD_PORT',
- type: RangeError
- }, 168);
+ name: 'RangeError'
+ };
syncFailToConnect('', portRangeError);
syncFailToConnect(' ', portRangeError);
@@ -63,9 +63,9 @@ const net = require('net');
const hintOptBlocks = doConnect([{ hints }],
() => common.mustNotCall());
for (const fn of hintOptBlocks) {
- common.expectsError(fn, {
+ assert.throws(fn, {
code: 'ERR_INVALID_OPT_VALUE',
- type: TypeError,
+ name: 'TypeError',
message: /The value "\d+" is invalid for option "hints"/
});
}
diff --git a/test/parallel/test-net-listen-invalid-port.js b/test/parallel/test-net-listen-invalid-port.js
index d07bc9fafa..8448780366 100644
--- a/test/parallel/test-net-listen-invalid-port.js
+++ b/test/parallel/test-net-listen-invalid-port.js
@@ -19,25 +19,25 @@ net.Server().listen(0, function() {
});
// The first argument is a configuration object
-common.expectsError(() => {
+assert.throws(() => {
net.Server().listen({ port: invalidPort }, common.mustNotCall());
}, {
code: 'ERR_SOCKET_BAD_PORT',
- type: RangeError
+ name: 'RangeError'
});
// The first argument is the port, no IP given.
-common.expectsError(() => {
+assert.throws(() => {
net.Server().listen(invalidPort, common.mustNotCall());
}, {
code: 'ERR_SOCKET_BAD_PORT',
- type: RangeError
+ name: 'RangeError'
});
// The first argument is the port, the second an IP.
-common.expectsError(() => {
+assert.throws(() => {
net.Server().listen(invalidPort, '0.0.0.0', common.mustNotCall());
}, {
code: 'ERR_SOCKET_BAD_PORT',
- type: RangeError
+ name: 'RangeError'
});
diff --git a/test/parallel/test-net-localerror.js b/test/parallel/test-net-localerror.js
index 91a7b38c3e..9209534051 100644
--- a/test/parallel/test-net-localerror.js
+++ b/test/parallel/test-net-localerror.js
@@ -20,13 +20,14 @@
// USE OR OTHER DEALINGS IN THE SOFTWARE.
'use strict';
-const common = require('../common');
+require('../common');
+const assert = require('assert');
const net = require('net');
const connect = (opts, code, type) => {
- common.expectsError(
+ assert.throws(
() => net.connect(opts),
- { code, type }
+ { code, name: type.name }
);
};
diff --git a/test/parallel/test-net-options-lookup.js b/test/parallel/test-net-options-lookup.js
index 5661aee841..0341a9f8d5 100644
--- a/test/parallel/test-net-options-lookup.js
+++ b/test/parallel/test-net-options-lookup.js
@@ -1,5 +1,6 @@
'use strict';
const common = require('../common');
+const assert = require('assert');
const net = require('net');
['foobar', 1, {}, []].forEach((input) => connectThrows(input));
@@ -12,11 +13,11 @@ function connectThrows(input) {
lookup: input
};
- common.expectsError(() => {
+ assert.throws(() => {
net.connect(opts);
}, {
code: 'ERR_INVALID_ARG_TYPE',
- type: TypeError
+ name: 'TypeError'
});
}
diff --git a/test/parallel/test-net-server-call-listen-multiple-times.js b/test/parallel/test-net-server-call-listen-multiple-times.js
index 4b1a8d0733..e757c6c247 100644
--- a/test/parallel/test-net-server-call-listen-multiple-times.js
+++ b/test/parallel/test-net-server-call-listen-multiple-times.js
@@ -1,6 +1,7 @@
'use strict';
const common = require('../common');
+const assert = require('assert');
const net = require('net');
// First test. Check that after error event you can listen right away.
@@ -28,9 +29,9 @@ const net = require('net');
server.listen(common.mustCall(() => server.close()));
- common.expectsError(() => server.listen(), {
+ assert.throws(() => server.listen(), {
code: 'ERR_SERVER_ALREADY_LISTEN',
- type: Error
+ name: 'Error'
});
}
diff --git a/test/parallel/test-net-server-listen-options.js b/test/parallel/test-net-server-listen-options.js
index 6c783c95dc..035630468b 100644
--- a/test/parallel/test-net-server-listen-options.js
+++ b/test/parallel/test-net-server-listen-options.js
@@ -27,7 +27,7 @@ const listenOnPort = [
const assertPort = () => {
return common.expectsError({
code: 'ERR_SOCKET_BAD_PORT',
- type: RangeError
+ name: 'RangeError'
});
};
@@ -60,19 +60,19 @@ const listenOnPort = [
if (typeof options === 'object' &&
!(('port' in options) || ('path' in options))) {
- common.expectsError(fn,
- {
- code: 'ERR_INVALID_ARG_VALUE',
- type: TypeError,
- message: /^The argument 'options' must have the property "port" or "path"\. Received .+$/,
- });
+ assert.throws(fn,
+ {
+ code: 'ERR_INVALID_ARG_VALUE',
+ name: 'TypeError',
+ message: /^The argument 'options' must have the property "port" or "path"\. Received .+$/,
+ });
} else {
- common.expectsError(fn,
- {
- code: 'ERR_INVALID_OPT_VALUE',
- type: TypeError,
- message: /^The value "{.*}" is invalid for option "options"(?:\. .+)?$/,
- });
+ assert.throws(fn,
+ {
+ code: 'ERR_INVALID_OPT_VALUE',
+ name: 'TypeError',
+ message: /^The value "{.*}" is invalid for option "options"(?:\. .+)?$/,
+ });
}
}
diff --git a/test/parallel/test-net-server-options.js b/test/parallel/test-net-server-options.js
index 2275d9f859..8d2181171d 100644
--- a/test/parallel/test-net-server-options.js
+++ b/test/parallel/test-net-server-options.js
@@ -1,15 +1,16 @@
'use strict';
-const common = require('../common');
+require('../common');
+const assert = require('assert');
const net = require('net');
-common.expectsError(function() { net.createServer('path'); },
- {
- code: 'ERR_INVALID_ARG_TYPE',
- type: TypeError
- });
+assert.throws(() => net.createServer('path'),
+ {
+ code: 'ERR_INVALID_ARG_TYPE',
+ name: 'TypeError'
+ });
-common.expectsError(function() { net.createServer(0); },
- {
- code: 'ERR_INVALID_ARG_TYPE',
- type: TypeError
- });
+assert.throws(() => net.createServer(0),
+ {
+ code: 'ERR_INVALID_ARG_TYPE',
+ name: 'TypeError'
+ });
diff --git a/test/parallel/test-net-socket-constructor.js b/test/parallel/test-net-socket-constructor.js
index 90b0907f48..d1ac8b3512 100644
--- a/test/parallel/test-net-socket-constructor.js
+++ b/test/parallel/test-net-socket-constructor.js
@@ -5,11 +5,11 @@ const assert = require('assert');
const cluster = require('cluster');
const net = require('net');
-common.expectsError(() => {
+assert.throws(() => {
new net.Socket({ fd: -1 });
}, { code: 'ERR_OUT_OF_RANGE' });
-common.expectsError(() => {
+assert.throws(() => {
new net.Socket({ fd: 'foo' });
}, { code: 'ERR_INVALID_ARG_TYPE' });
diff --git a/test/parallel/test-net-socket-destroy-send.js b/test/parallel/test-net-socket-destroy-send.js
index aa587fc2e1..54dadd9486 100644
--- a/test/parallel/test-net-socket-destroy-send.js
+++ b/test/parallel/test-net-socket-destroy-send.js
@@ -15,13 +15,13 @@ server.listen(0, common.mustCall(function() {
conn.on('error', common.expectsError({
code: 'ERR_STREAM_DESTROYED',
message: 'Cannot call write after a stream was destroyed',
- type: Error
+ name: 'Error'
}));
conn.write(Buffer.from('kaboom'), common.expectsError({
code: 'ERR_STREAM_DESTROYED',
message: 'Cannot call write after a stream was destroyed',
- type: Error
+ name: 'Error'
}));
server.close();
}));
diff --git a/test/parallel/test-net-socket-timeout.js b/test/parallel/test-net-socket-timeout.js
index 2fe0e5a45d..8b197b44d6 100644
--- a/test/parallel/test-net-socket-timeout.js
+++ b/test/parallel/test-net-socket-timeout.js
@@ -55,11 +55,11 @@ for (let i = 0; i < validDelays.length; i++) {
for (let i = 0; i < invalidCallbacks.length; i++) {
[0, 1].forEach((mesc) =>
- common.expectsError(
+ assert.throws(
() => s.setTimeout(mesc, invalidCallbacks[i]),
{
code: 'ERR_INVALID_CALLBACK',
- type: TypeError,
+ name: 'TypeError',
message: 'Callback must be a function. ' +
`Received ${inspect(invalidCallbacks[i])}`
}
diff --git a/test/parallel/test-net-socket-write-after-close.js b/test/parallel/test-net-socket-write-after-close.js
index e3593a3a09..207f735fff 100644
--- a/test/parallel/test-net-socket-write-after-close.js
+++ b/test/parallel/test-net-socket-write-after-close.js
@@ -29,7 +29,7 @@ const net = require('net');
client.on('error', common.expectsError({
code: 'ERR_SOCKET_CLOSED',
message: 'Socket is closed',
- type: Error
+ name: 'Error'
}));
server.close();
diff --git a/test/parallel/test-net-socket-write-error.js b/test/parallel/test-net-socket-write-error.js
index 178cebe990..c324aea47a 100644
--- a/test/parallel/test-net-socket-write-error.js
+++ b/test/parallel/test-net-socket-write-error.js
@@ -1,17 +1,18 @@
'use strict';
-const common = require('../common');
+require('../common');
+const assert = require('assert');
const net = require('net');
const server = net.createServer().listen(0, connectToServer);
function connectToServer() {
const client = net.createConnection(this.address().port, () => {
- common.expectsError(() => client.write(1337),
- {
- code: 'ERR_INVALID_ARG_TYPE',
- type: TypeError
- });
+ assert.throws(() => client.write(1337),
+ {
+ code: 'ERR_INVALID_ARG_TYPE',
+ name: 'TypeError'
+ });
client.destroy();
})
diff --git a/test/parallel/test-net-write-after-end-nt.js b/test/parallel/test-net-write-after-end-nt.js
index d2f7c5c212..99edc1d72b 100644
--- a/test/parallel/test-net-write-after-end-nt.js
+++ b/test/parallel/test-net-write-after-end-nt.js
@@ -21,7 +21,7 @@ const server = net.createServer(mustCall((socket) => {
const ret = client.write('hello', expectsError({
code: 'EPIPE',
message: 'This socket has been ended by the other party',
- type: Error
+ name: 'Error'
}));
assert.strictEqual(ret, false);
diff --git a/test/parallel/test-net-write-arguments.js b/test/parallel/test-net-write-arguments.js
index cd502202ba..d3dde36b02 100644
--- a/test/parallel/test-net-write-arguments.js
+++ b/test/parallel/test-net-write-arguments.js
@@ -1,16 +1,17 @@
'use strict';
const common = require('../common');
+const assert = require('assert');
const net = require('net');
const socket = net.Stream({ highWaterMark: 0 });
// Make sure that anything besides a buffer or a string throws.
-common.expectsError(() => socket.write(null),
- {
- code: 'ERR_STREAM_NULL_VALUES',
- type: TypeError,
- message: 'May not write null values to stream'
- });
+assert.throws(() => socket.write(null),
+ {
+ code: 'ERR_STREAM_NULL_VALUES',
+ name: 'TypeError',
+ message: 'May not write null values to stream'
+ });
[
true,
false,
@@ -26,7 +27,7 @@ common.expectsError(() => socket.write(null),
// be emitted once per instance.
socket.write(value, common.expectsError({
code: 'ERR_INVALID_ARG_TYPE',
- type: TypeError,
+ name: 'TypeError',
message: 'The "chunk" argument must be of type string or an instance of ' +
`Buffer.${common.invalidArgTypeHelper(value)}`
}));
diff --git a/test/parallel/test-next-tick-errors.js b/test/parallel/test-next-tick-errors.js
index c561d555e1..56480adcf5 100644
--- a/test/parallel/test-next-tick-errors.js
+++ b/test/parallel/test-next-tick-errors.js
@@ -20,7 +20,7 @@
// USE OR OTHER DEALINGS IN THE SOFTWARE.
'use strict';
-const common = require('../common');
+require('../common');
const assert = require('assert');
const order = [];
@@ -42,16 +42,12 @@ process.nextTick(function() {
});
function testNextTickWith(val) {
- common.expectsError(
- function() {
- process.nextTick(val);
- },
- {
- code: 'ERR_INVALID_CALLBACK',
- name: 'TypeError',
- type: TypeError
- }
- );
+ assert.throws(() => {
+ process.nextTick(val);
+ }, {
+ code: 'ERR_INVALID_CALLBACK',
+ name: 'TypeError'
+ });
}
testNextTickWith(false);
diff --git a/test/parallel/test-os-checked-function.js b/test/parallel/test-os-checked-function.js
index 4a6c1cd0ca..e0758437fe 100644
--- a/test/parallel/test-os-checked-function.js
+++ b/test/parallel/test-os-checked-function.js
@@ -1,8 +1,9 @@
'use strict';
// Flags: --expose_internals
-const common = require('../common');
+require('../common');
const { internalBinding } = require('internal/test/binding');
+const assert = require('assert');
// Monkey patch the os binding before requiring any other modules, including
// common, which requires the os module.
@@ -14,6 +15,6 @@ internalBinding('os').getHomeDirectory = function(ctx) {
const os = require('os');
-common.expectsError(os.homedir, {
+assert.throws(os.homedir, {
message: /^A system error occurred: foo returned bar \(baz\)$/
});
diff --git a/test/parallel/test-os-process-priority.js b/test/parallel/test-os-process-priority.js
index ad73e022ef..d9adac58bf 100644
--- a/test/parallel/test-os-process-priority.js
+++ b/test/parallel/test-os-process-priority.js
@@ -30,11 +30,11 @@ assert.strictEqual(typeof PRIORITY_HIGHEST, 'number');
message: /The "pid" argument must be of type number\./
};
- common.expectsError(() => {
+ assert.throws(() => {
os.setPriority(pid, PRIORITY_NORMAL);
}, errObj);
- common.expectsError(() => {
+ assert.throws(() => {
os.getPriority(pid);
}, errObj);
});
@@ -46,18 +46,18 @@ assert.strictEqual(typeof PRIORITY_HIGHEST, 'number');
message: /The value of "pid" is out of range\./
};
- common.expectsError(() => {
+ assert.throws(() => {
os.setPriority(pid, PRIORITY_NORMAL);
}, errObj);
- common.expectsError(() => {
+ assert.throws(() => {
os.getPriority(pid);
}, errObj);
});
// Test priority type validation.
[null, true, false, 'foo', {}, [], /x/].forEach((priority) => {
- common.expectsError(() => {
+ assert.throws(() => {
os.setPriority(0, priority);
}, {
code: 'ERR_INVALID_ARG_TYPE',
@@ -75,7 +75,7 @@ assert.strictEqual(typeof PRIORITY_HIGHEST, 'number');
PRIORITY_HIGHEST - 1,
PRIORITY_LOW + 1
].forEach((priority) => {
- common.expectsError(() => {
+ assert.throws(() => {
os.setPriority(0, priority);
}, {
code: 'ERR_OUT_OF_RANGE',
diff --git a/test/parallel/test-outgoing-message-pipe.js b/test/parallel/test-outgoing-message-pipe.js
index 7cfe3687ec..049b41c9aa 100644
--- a/test/parallel/test-outgoing-message-pipe.js
+++ b/test/parallel/test-outgoing-message-pipe.js
@@ -1,14 +1,15 @@
'use strict';
-const common = require('../common');
+require('../common');
+const assert = require('assert');
const OutgoingMessage = require('_http_outgoing').OutgoingMessage;
// Verify that an error is thrown upon a call to `OutgoingMessage.pipe`.
const outgoingMessage = new OutgoingMessage();
-common.expectsError(
+assert.throws(
() => { outgoingMessage.pipe(outgoingMessage); },
{
code: 'ERR_STREAM_CANNOT_PIPE',
- type: Error
+ name: 'Error'
}
);
diff --git a/test/parallel/test-path-parse-format.js b/test/parallel/test-path-parse-format.js
index 9d616d0c13..97c7227ac7 100644
--- a/test/parallel/test-path-parse-format.js
+++ b/test/parallel/test-path-parse-format.js
@@ -215,11 +215,11 @@ function checkFormat(path, testCases) {
});
[null, undefined, 1, true, false, 'string'].forEach((pathObject) => {
- common.expectsError(() => {
+ assert.throws(() => {
path.format(pathObject);
}, {
code: 'ERR_INVALID_ARG_TYPE',
- type: TypeError,
+ name: 'TypeError',
message: 'The "pathObject" argument must be of type object.' +
common.invalidArgTypeHelper(pathObject)
});
diff --git a/test/parallel/test-path.js b/test/parallel/test-path.js
index 9672e82c7f..7a5f3d4715 100644
--- a/test/parallel/test-path.js
+++ b/test/parallel/test-path.js
@@ -30,9 +30,9 @@ const typeErrorTests = [true, false, 7, null, {}, undefined, [], NaN];
function fail(fn) {
const args = Array.from(arguments).slice(1);
- common.expectsError(() => {
+ assert.throws(() => {
fn.apply(null, args);
- }, { code: 'ERR_INVALID_ARG_TYPE', type: TypeError });
+ }, { code: 'ERR_INVALID_ARG_TYPE', name: 'TypeError' });
}
typeErrorTests.forEach((test) => {
diff --git a/test/parallel/test-performance-function.js b/test/parallel/test-performance-function.js
index 5271f419a3..883def6565 100644
--- a/test/parallel/test-performance-function.js
+++ b/test/parallel/test-performance-function.js
@@ -61,12 +61,12 @@ const {
{
[1, {}, [], null, undefined, Infinity].forEach((input) => {
- common.expectsError(() => performance.timerify(input),
- {
- code: 'ERR_INVALID_ARG_TYPE',
- type: TypeError,
- message: /The "fn" argument must be of type function/
- });
+ assert.throws(() => performance.timerify(input),
+ {
+ code: 'ERR_INVALID_ARG_TYPE',
+ name: 'TypeError',
+ message: /The "fn" argument must be of type function/
+ });
});
}
diff --git a/test/parallel/test-performanceobserver.js b/test/parallel/test-performanceobserver.js
index 6c28baa82f..01afbdc6aa 100644
--- a/test/parallel/test-performanceobserver.js
+++ b/test/parallel/test-performanceobserver.js
@@ -31,11 +31,11 @@ assert.strictEqual(counts[NODE_PERFORMANCE_ENTRY_TYPE_FUNCTION], 0);
{
[1, null, undefined, {}, [], Infinity].forEach((i) => {
- common.expectsError(
+ assert.throws(
() => new PerformanceObserver(i),
{
code: 'ERR_INVALID_CALLBACK',
- type: TypeError,
+ name: 'TypeError',
message: `Callback must be a function. Received ${inspect(i)}`
}
);
@@ -43,24 +43,24 @@ assert.strictEqual(counts[NODE_PERFORMANCE_ENTRY_TYPE_FUNCTION], 0);
const observer = new PerformanceObserver(common.mustNotCall());
[1, null, undefined].forEach((input) => {
- common.expectsError(
+ assert.throws(
() => observer.observe(input),
{
code: 'ERR_INVALID_ARG_TYPE',
- type: TypeError,
+ name: 'TypeError',
message: 'The "options" argument must be of type object.' +
common.invalidArgTypeHelper(input)
});
});
[1, undefined, null, {}, Infinity].forEach((i) => {
- common.expectsError(() => observer.observe({ entryTypes: i }),
- {
- code: 'ERR_INVALID_OPT_VALUE',
- type: TypeError,
- message: 'The value "[object Object]" is invalid ' +
+ assert.throws(() => observer.observe({ entryTypes: i }),
+ {
+ code: 'ERR_INVALID_OPT_VALUE',
+ name: 'TypeError',
+ message: 'The value "[object Object]" is invalid ' +
'for option "entryTypes"'
- });
+ });
});
const obs = new PerformanceObserver(common.mustNotCall());
diff --git a/test/parallel/test-pipe-outgoing-message-data-emitted-after-ended.js b/test/parallel/test-pipe-outgoing-message-data-emitted-after-ended.js
index c6191a906b..efd3d271e7 100644
--- a/test/parallel/test-pipe-outgoing-message-data-emitted-after-ended.js
+++ b/test/parallel/test-pipe-outgoing-message-data-emitted-after-ended.js
@@ -18,7 +18,7 @@ const server = http.createServer(common.mustCall(function(req, res) {
myStream.emit('data', 'some data');
res.on('error', common.expectsError({
code: 'ERR_STREAM_WRITE_AFTER_END',
- type: Error
+ name: 'Error'
}));
process.nextTick(common.mustCall(() => server.close()));
diff --git a/test/parallel/test-process-assert.js b/test/parallel/test-process-assert.js
index 74792eebb7..2f0c3fc943 100644
--- a/test/parallel/test-process-assert.js
+++ b/test/parallel/test-process-assert.js
@@ -9,17 +9,17 @@ common.expectWarning(
);
assert.strictEqual(process.assert(1, 'error'), undefined);
-common.expectsError(() => {
+assert.throws(() => {
process.assert(undefined, 'errorMessage');
}, {
code: 'ERR_ASSERTION',
- type: Error,
+ name: 'Error',
message: 'errorMessage'
});
-common.expectsError(() => {
+assert.throws(() => {
process.assert(false);
}, {
code: 'ERR_ASSERTION',
- type: Error,
+ name: 'Error',
message: 'assertion error'
});
diff --git a/test/parallel/test-process-chdir-errormessage.js b/test/parallel/test-process-chdir-errormessage.js
index 3dca040a2f..0ed368287b 100644
--- a/test/parallel/test-process-chdir-errormessage.js
+++ b/test/parallel/test-process-chdir-errormessage.js
@@ -3,13 +3,14 @@
const common = require('../common');
if (!common.isMainThread)
common.skip('process.chdir is not available in Workers');
+const assert = require('assert');
-common.expectsError(
+assert.throws(
() => {
process.chdir('does-not-exist');
},
{
- type: Error,
+ name: 'Error',
code: 'ENOENT',
message: /ENOENT: no such file or directory, chdir .+ -> 'does-not-exist'/,
path: process.cwd(),
diff --git a/test/parallel/test-process-chdir.js b/test/parallel/test-process-chdir.js
index e66d366fb7..8340f77204 100644
--- a/test/parallel/test-process-chdir.js
+++ b/test/parallel/test-process-chdir.js
@@ -40,5 +40,5 @@ const err = {
code: 'ERR_INVALID_ARG_TYPE',
message: /The "directory" argument must be of type string/
};
-common.expectsError(function() { process.chdir({}); }, err);
-common.expectsError(function() { process.chdir(); }, err);
+assert.throws(function() { process.chdir({}); }, err);
+assert.throws(function() { process.chdir(); }, err);
diff --git a/test/parallel/test-process-emitwarning.js b/test/parallel/test-process-emitwarning.js
index bba41c56e2..de0861140d 100644
--- a/test/parallel/test-process-emitwarning.js
+++ b/test/parallel/test-process-emitwarning.js
@@ -74,8 +74,8 @@ process.emitWarning(warningThrowToString);
[undefined, 'foo', 'bar'],
[undefined]
].forEach((args) => {
- common.expectsError(
+ assert.throws(
() => process.emitWarning(...args),
- { code: 'ERR_INVALID_ARG_TYPE', type: TypeError }
+ { code: 'ERR_INVALID_ARG_TYPE', name: 'TypeError' }
);
});
diff --git a/test/parallel/test-process-exception-capture-errors.js b/test/parallel/test-process-exception-capture-errors.js
index 5f89852b6e..8eb825267c 100644
--- a/test/parallel/test-process-exception-capture-errors.js
+++ b/test/parallel/test-process-exception-capture-errors.js
@@ -1,11 +1,12 @@
'use strict';
const common = require('../common');
+const assert = require('assert');
-common.expectsError(
+assert.throws(
() => process.setUncaughtExceptionCaptureCallback(42),
{
code: 'ERR_INVALID_ARG_TYPE',
- type: TypeError,
+ name: 'TypeError',
message: 'The "fn" argument must be of type function or null. ' +
'Received type number (42)'
}
@@ -13,11 +14,11 @@ common.expectsError(
process.setUncaughtExceptionCaptureCallback(common.mustNotCall());
-common.expectsError(
+assert.throws(
() => process.setUncaughtExceptionCaptureCallback(common.mustNotCall()),
{
code: 'ERR_UNCAUGHT_EXCEPTION_CAPTURE_ALREADY_SET',
- type: Error,
+ name: 'Error',
message: /setupUncaughtExceptionCapture.*called while a capture callback/
}
);
diff --git a/test/parallel/test-process-hrtime.js b/test/parallel/test-process-hrtime.js
index 8d469e1dcc..34ef514aac 100644
--- a/test/parallel/test-process-hrtime.js
+++ b/test/parallel/test-process-hrtime.js
@@ -20,7 +20,7 @@
// USE OR OTHER DEALINGS IN THE SOFTWARE.
'use strict';
-const common = require('../common');
+require('../common');
const assert = require('assert');
// The default behavior, return an Array "tuple" of numbers
@@ -33,33 +33,33 @@ validateTuple(tuple);
validateTuple(process.hrtime(tuple));
// Test that only an Array may be passed to process.hrtime()
-common.expectsError(() => {
+assert.throws(() => {
process.hrtime(1);
}, {
code: 'ERR_INVALID_ARG_TYPE',
- type: TypeError,
+ name: 'TypeError',
message: 'The "time" argument must be an instance of Array. Received type ' +
'number (1)'
});
-common.expectsError(() => {
+assert.throws(() => {
process.hrtime([]);
}, {
code: 'ERR_OUT_OF_RANGE',
- type: RangeError,
+ name: 'RangeError',
message: 'The value of "time" is out of range. It must be 2. Received 0'
});
-common.expectsError(() => {
+assert.throws(() => {
process.hrtime([1]);
}, {
code: 'ERR_OUT_OF_RANGE',
- type: RangeError,
+ name: 'RangeError',
message: 'The value of "time" is out of range. It must be 2. Received 1'
});
-common.expectsError(() => {
+assert.throws(() => {
process.hrtime([1, 2, 3]);
}, {
code: 'ERR_OUT_OF_RANGE',
- type: RangeError,
+ name: 'RangeError',
message: 'The value of "time" is out of range. It must be 2. Received 3'
});
diff --git a/test/parallel/test-process-kill-pid.js b/test/parallel/test-process-kill-pid.js
index a69961da6c..c4f172e61d 100644
--- a/test/parallel/test-process-kill-pid.js
+++ b/test/parallel/test-process-kill-pid.js
@@ -48,16 +48,16 @@ const assert = require('assert');
});
// Test that kill throws an error for unknown signal names
-common.expectsError(() => process.kill(0, 'test'), {
+assert.throws(() => process.kill(0, 'test'), {
code: 'ERR_UNKNOWN_SIGNAL',
- type: TypeError,
+ name: 'TypeError',
message: 'Unknown signal: test'
});
// Test that kill throws an error for invalid signal numbers
-common.expectsError(() => process.kill(0, 987), {
+assert.throws(() => process.kill(0, 987), {
code: 'EINVAL',
- type: Error,
+ name: 'Error',
message: 'kill EINVAL'
});
diff --git a/test/parallel/test-process-next-tick.js b/test/parallel/test-process-next-tick.js
index 6641e17c24..691bf57b37 100644
--- a/test/parallel/test-process-next-tick.js
+++ b/test/parallel/test-process-next-tick.js
@@ -21,6 +21,7 @@
'use strict';
const common = require('../common');
+const assert = require('assert');
const { inspect } = require('util');
const N = 2;
@@ -39,11 +40,11 @@ process.on('exit', function() {
});
[null, 1, 'test', {}, [], Infinity, true].forEach((i) => {
- common.expectsError(
+ assert.throws(
() => process.nextTick(i),
{
code: 'ERR_INVALID_CALLBACK',
- type: TypeError,
+ name: 'TypeError',
message: `Callback must be a function. Received ${inspect(i)}`
}
);
diff --git a/test/parallel/test-querystring-escape.js b/test/parallel/test-querystring-escape.js
index fedc098124..fdc62c7cdb 100644
--- a/test/parallel/test-querystring-escape.js
+++ b/test/parallel/test-querystring-escape.js
@@ -1,5 +1,5 @@
'use strict';
-const common = require('../common');
+require('../common');
const assert = require('assert');
const qs = require('querystring');
@@ -13,11 +13,11 @@ assert.deepStrictEqual(qs.escape('testŊōđĕ'), 'test%C5%8A%C5%8D%C4%91%C4%95'
assert.deepStrictEqual(qs.escape(`${String.fromCharCode(0xD800 + 1)}test`),
'%F0%90%91%B4est');
-common.expectsError(
+assert.throws(
() => qs.escape(String.fromCharCode(0xD800 + 1)),
{
code: 'ERR_INVALID_URI',
- type: URIError,
+ name: 'URIError',
message: 'URI malformed'
}
);
diff --git a/test/parallel/test-querystring.js b/test/parallel/test-querystring.js
index de1768103d..72d8e3315f 100644
--- a/test/parallel/test-querystring.js
+++ b/test/parallel/test-querystring.js
@@ -20,7 +20,7 @@
// USE OR OTHER DEALINGS IN THE SOFTWARE.
'use strict';
-const common = require('../common');
+require('../common');
const assert = require('assert');
const inspect = require('util').inspect;
@@ -270,11 +270,11 @@ qsWeirdObjects.forEach((testCase) => {
});
// Invalid surrogate pair throws URIError
-common.expectsError(
+assert.throws(
() => qs.stringify({ foo: '\udc00' }),
{
code: 'ERR_INVALID_URI',
- type: URIError,
+ name: 'URIError',
message: 'URI malformed'
}
);
diff --git a/test/parallel/test-readline-csi.js b/test/parallel/test-readline-csi.js
index 346f1cbad1..5c0080d3d4 100644
--- a/test/parallel/test-readline-csi.js
+++ b/test/parallel/test-readline-csi.js
@@ -128,10 +128,10 @@ assert.strictEqual(readline.cursorTo(writable, 'a', 'b'), true);
assert.strictEqual(writable.data, '');
writable.data = '';
-common.expectsError(
+assert.throws(
() => readline.cursorTo(writable, 'a', 1),
{
- type: TypeError,
+ name: 'TypeError',
code: 'ERR_INVALID_CURSOR_POS',
message: 'Cannot set cursor row without setting its column'
});
diff --git a/test/parallel/test-readline-interface-escapecodetimeout.js b/test/parallel/test-readline-interface-escapecodetimeout.js
index 0e25423e85..58f5fcb3cd 100644
--- a/test/parallel/test-readline-interface-escapecodetimeout.js
+++ b/test/parallel/test-readline-interface-escapecodetimeout.js
@@ -1,5 +1,5 @@
'use strict';
-const common = require('../common');
+require('../common');
// This test ensures that the escapeCodeTimeout option set correctly
@@ -31,7 +31,7 @@ class FakeInput extends EventEmitter {
NaN,
'50'
].forEach((invalidInput) => {
- common.expectsError(() => {
+ assert.throws(() => {
const fi = new FakeInput();
const rli = new readline.Interface({
input: fi,
@@ -40,7 +40,7 @@ class FakeInput extends EventEmitter {
});
rli.close();
}, {
- type: TypeError,
+ name: 'TypeError',
code: 'ERR_INVALID_OPT_VALUE'
});
});
diff --git a/test/parallel/test-readline-interface.js b/test/parallel/test-readline-interface.js
index 8adfa7ec31..3504a68ab9 100644
--- a/test/parallel/test-readline-interface.js
+++ b/test/parallel/test-readline-interface.js
@@ -357,33 +357,33 @@ function isWarned(emitter) {
// Constructor throws if completer is not a function or undefined
{
const fi = new FakeInput();
- common.expectsError(function() {
+ assert.throws(() => {
readline.createInterface({
input: fi,
completer: 'string is not valid'
});
}, {
- type: TypeError,
+ name: 'TypeError',
code: 'ERR_INVALID_OPT_VALUE'
});
- common.expectsError(function() {
+ assert.throws(() => {
readline.createInterface({
input: fi,
completer: ''
});
}, {
- type: TypeError,
+ name: 'TypeError',
code: 'ERR_INVALID_OPT_VALUE'
});
- common.expectsError(function() {
+ assert.throws(() => {
readline.createInterface({
input: fi,
completer: false
});
}, {
- type: TypeError,
+ name: 'TypeError',
code: 'ERR_INVALID_OPT_VALUE'
});
}
@@ -391,30 +391,30 @@ function isWarned(emitter) {
// Constructor throws if historySize is not a positive number
{
const fi = new FakeInput();
- common.expectsError(function() {
+ assert.throws(() => {
readline.createInterface({
input: fi, historySize: 'not a number'
});
}, {
- type: RangeError,
+ name: 'RangeError',
code: 'ERR_INVALID_OPT_VALUE'
});
- common.expectsError(function() {
+ assert.throws(() => {
readline.createInterface({
input: fi, historySize: -1
});
}, {
- type: RangeError,
+ name: 'RangeError',
code: 'ERR_INVALID_OPT_VALUE'
});
- common.expectsError(function() {
+ assert.throws(() => {
readline.createInterface({
input: fi, historySize: NaN
});
}, {
- type: RangeError,
+ name: 'RangeError',
code: 'ERR_INVALID_OPT_VALUE'
});
}
diff --git a/test/parallel/test-repl-options.js b/test/parallel/test-repl-options.js
index 9f40c6279b..43270e7412 100644
--- a/test/parallel/test-repl-options.js
+++ b/test/parallel/test-repl-options.js
@@ -101,9 +101,9 @@ const r3 = () => repl.start({
eval: true
});
-common.expectsError(r3, {
+assert.throws(r3, {
code: 'ERR_INVALID_REPL_EVAL_CONFIG',
- type: TypeError,
+ name: 'TypeError',
message: 'Cannot specify both "breakEvalOnSigint" and "eval" for REPL'
});
diff --git a/test/parallel/test-require-invalid-package.js b/test/parallel/test-require-invalid-package.js
index 669ea54e52..47e22ae939 100644
--- a/test/parallel/test-require-invalid-package.js
+++ b/test/parallel/test-require-invalid-package.js
@@ -1,8 +1,9 @@
'use strict';
-const common = require('../common');
+require('../common');
+const assert = require('assert');
// Should be an invalid package path.
-common.expectsError(() => require('package.json'),
- { code: 'MODULE_NOT_FOUND' }
+assert.throws(() => require('package.json'),
+ { code: 'MODULE_NOT_FOUND' }
);
diff --git a/test/parallel/test-require-resolve.js b/test/parallel/test-require-resolve.js
index c89b4d89b8..e7125e39fa 100644
--- a/test/parallel/test-require-resolve.js
+++ b/test/parallel/test-require-resolve.js
@@ -41,14 +41,14 @@ require(fixtures.path('resolve-paths', 'default', 'verify-paths.js'));
[1, false, null, undefined, {}].forEach((value) => {
const message = 'The "request" argument must be of type string.' +
common.invalidArgTypeHelper(value);
- common.expectsError(
+ assert.throws(
() => { require.resolve(value); },
{
code: 'ERR_INVALID_ARG_TYPE',
message
});
- common.expectsError(
+ assert.throws(
() => { require.resolve.paths(value); },
{
code: 'ERR_INVALID_ARG_TYPE',
diff --git a/test/parallel/test-stream-base-typechecking.js b/test/parallel/test-stream-base-typechecking.js
index a8652dc063..ae85826423 100644
--- a/test/parallel/test-stream-base-typechecking.js
+++ b/test/parallel/test-stream-base-typechecking.js
@@ -1,13 +1,14 @@
'use strict';
const common = require('../common');
+const assert = require('assert');
const net = require('net');
const server = net.createServer().listen(0, common.mustCall(() => {
const client = net.connect(server.address().port, common.mustCall(() => {
- common.expectsError(() => {
+ assert.throws(() => {
client.write('broken', 'buffer');
}, {
- type: TypeError,
+ name: 'TypeError',
code: 'ERR_INVALID_ARG_TYPE',
message: 'Second argument must be a buffer'
});
diff --git a/test/parallel/test-stream-inheritance.js b/test/parallel/test-stream-inheritance.js
index a687ea9da0..658bd2be33 100644
--- a/test/parallel/test-stream-inheritance.js
+++ b/test/parallel/test-stream-inheritance.js
@@ -1,5 +1,5 @@
'use strict';
-const common = require('../common');
+require('../common');
const assert = require('assert');
const { Readable, Writable, Duplex, Transform } = require('stream');
@@ -48,11 +48,11 @@ Object.setPrototypeOf(CustomWritable.prototype, Writable.prototype);
new CustomWritable();
-common.expectsError(
+assert.throws(
CustomWritable,
{
code: 'ERR_ASSERTION',
- type: assert.AssertionError,
+ constructor: assert.AssertionError,
message: 'undefined does not inherit from CustomWritable'
}
);
diff --git a/test/parallel/test-stream-readable-invalid-chunk.js b/test/parallel/test-stream-readable-invalid-chunk.js
index 3e147c065f..0fcc76ae73 100644
--- a/test/parallel/test-stream-readable-invalid-chunk.js
+++ b/test/parallel/test-stream-readable-invalid-chunk.js
@@ -9,7 +9,7 @@ function testPushArg(val) {
});
readable.on('error', common.expectsError({
code: 'ERR_INVALID_ARG_TYPE',
- type: TypeError
+ name: 'TypeError'
}));
readable.push(val);
}
@@ -24,7 +24,7 @@ function testUnshiftArg(val) {
});
readable.on('error', common.expectsError({
code: 'ERR_INVALID_ARG_TYPE',
- type: TypeError
+ name: 'TypeError'
}));
readable.unshift(val);
}
diff --git a/test/parallel/test-stream-readable-with-unimplemented-_read.js b/test/parallel/test-stream-readable-with-unimplemented-_read.js
index 973899b7a7..7d48c42253 100644
--- a/test/parallel/test-stream-readable-with-unimplemented-_read.js
+++ b/test/parallel/test-stream-readable-with-unimplemented-_read.js
@@ -7,7 +7,7 @@ const readable = new Readable();
readable.on('error', common.expectsError({
code: 'ERR_METHOD_NOT_IMPLEMENTED',
- type: Error,
+ name: 'Error',
message: 'The _read() method is not implemented'
}));
diff --git a/test/parallel/test-stream-transform-callback-twice.js b/test/parallel/test-stream-transform-callback-twice.js
index 83c799b92f..bf2ccdcde4 100644
--- a/test/parallel/test-stream-transform-callback-twice.js
+++ b/test/parallel/test-stream-transform-callback-twice.js
@@ -6,7 +6,7 @@ const stream = new Transform({
});
stream.on('error', common.expectsError({
- type: Error,
+ name: 'Error',
message: 'Callback called multiple times',
code: 'ERR_MULTIPLE_CALLBACK'
}));
diff --git a/test/parallel/test-stream-transform-constructor-set-methods.js b/test/parallel/test-stream-transform-constructor-set-methods.js
index d599e76838..8a4abd6860 100644
--- a/test/parallel/test-stream-transform-constructor-set-methods.js
+++ b/test/parallel/test-stream-transform-constructor-set-methods.js
@@ -7,7 +7,7 @@ const { Transform } = require('stream');
const t = new Transform();
t.on('error', common.expectsError({
- type: Error,
+ name: 'Error',
code: 'ERR_METHOD_NOT_IMPLEMENTED',
message: 'The _transform() method is not implemented'
}));
diff --git a/test/parallel/test-stream-transform-split-highwatermark.js b/test/parallel/test-stream-transform-split-highwatermark.js
index bcc33d26a6..b39c85e321 100644
--- a/test/parallel/test-stream-transform-split-highwatermark.js
+++ b/test/parallel/test-stream-transform-split-highwatermark.js
@@ -1,5 +1,5 @@
'use strict';
-const common = require('../common');
+require('../common');
const assert = require('assert');
const { Transform, Readable, Writable } = require('stream');
@@ -64,18 +64,18 @@ testTransform(0, 0, {
// test NaN
{
- common.expectsError(() => {
+ assert.throws(() => {
new Transform({ readableHighWaterMark: NaN });
}, {
- type: TypeError,
+ name: 'TypeError',
code: 'ERR_INVALID_OPT_VALUE',
message: 'The value "NaN" is invalid for option "readableHighWaterMark"'
});
- common.expectsError(() => {
+ assert.throws(() => {
new Transform({ writableHighWaterMark: NaN });
}, {
- type: TypeError,
+ name: 'TypeError',
code: 'ERR_INVALID_OPT_VALUE',
message: 'The value "NaN" is invalid for option "writableHighWaterMark"'
});
diff --git a/test/parallel/test-stream-unshift-read-race.js b/test/parallel/test-stream-unshift-read-race.js
index 562e10776e..66ba2298af 100644
--- a/test/parallel/test-stream-unshift-read-race.js
+++ b/test/parallel/test-stream-unshift-read-race.js
@@ -68,11 +68,11 @@ r._read = function(n) {
};
function pushError() {
- common.expectsError(function() {
+ assert.throws(() => {
r.push(Buffer.allocUnsafe(1));
}, {
code: 'ERR_STREAM_PUSH_AFTER_EOF',
- type: Error,
+ name: 'Error',
message: 'stream.push() after EOF'
});
}
diff --git a/test/parallel/test-stream-wrap-encoding.js b/test/parallel/test-stream-wrap-encoding.js
index 72804d77d6..6678aeb626 100644
--- a/test/parallel/test-stream-wrap-encoding.js
+++ b/test/parallel/test-stream-wrap-encoding.js
@@ -16,7 +16,7 @@ const Duplex = require('stream').Duplex;
const wrap = new StreamWrap(stream);
wrap.on('error', common.expectsError({
- type: Error,
+ name: 'Error',
code: 'ERR_STREAM_WRAP',
message: 'Stream has StringDecoder set or is in objectMode'
}));
@@ -34,7 +34,7 @@ const Duplex = require('stream').Duplex;
const wrap = new StreamWrap(stream);
wrap.on('error', common.expectsError({
- type: Error,
+ name: 'Error',
code: 'ERR_STREAM_WRAP',
message: 'Stream has StringDecoder set or is in objectMode'
}));
diff --git a/test/parallel/test-stream-writable-callback-twice.js b/test/parallel/test-stream-writable-callback-twice.js
index a420bc5c27..25e7579a2d 100644
--- a/test/parallel/test-stream-writable-callback-twice.js
+++ b/test/parallel/test-stream-writable-callback-twice.js
@@ -6,7 +6,7 @@ const stream = new Writable({
});
stream.on('error', common.expectsError({
- type: Error,
+ name: 'Error',
message: 'Callback called multiple times',
code: 'ERR_MULTIPLE_CALLBACK'
}));
diff --git a/test/parallel/test-stream-writable-change-default-encoding.js b/test/parallel/test-stream-writable-change-default-encoding.js
index d8b774134e..3fb9796251 100644
--- a/test/parallel/test-stream-writable-change-default-encoding.js
+++ b/test/parallel/test-stream-writable-change-default-encoding.js
@@ -20,7 +20,7 @@
// USE OR OTHER DEALINGS IN THE SOFTWARE.
'use strict';
-const common = require('../common');
+require('../common');
const assert = require('assert');
const stream = require('stream');
@@ -54,14 +54,16 @@ class MyWritable extends stream.Writable {
m.end();
}());
-common.expectsError(function changeDefaultEncodingToInvalidValue() {
- const m = new MyWritable(function(isBuffer, type, enc) {
- }, { decodeStrings: false });
+// Change default encoding to invalid value.
+assert.throws(() => {
+ const m = new MyWritable(
+ (isBuffer, type, enc) => {},
+ { decodeStrings: false });
m.setDefaultEncoding({});
m.write('bar');
m.end();
}, {
- type: TypeError,
+ name: 'TypeError',
code: 'ERR_UNKNOWN_ENCODING',
message: 'Unknown encoding: {}'
});
diff --git a/test/parallel/test-stream-writable-constructor-set-methods.js b/test/parallel/test-stream-writable-constructor-set-methods.js
index 41779d7e51..c326428210 100644
--- a/test/parallel/test-stream-writable-constructor-set-methods.js
+++ b/test/parallel/test-stream-writable-constructor-set-methods.js
@@ -7,7 +7,7 @@ const { Writable } = require('stream');
const w = new Writable();
w.on('error', common.expectsError({
- type: Error,
+ name: 'Error',
code: 'ERR_METHOD_NOT_IMPLEMENTED',
message: 'The _write() method is not implemented'
}));
diff --git a/test/parallel/test-stream-writable-destroy.js b/test/parallel/test-stream-writable-destroy.js
index ef591568f6..c93478c01c 100644
--- a/test/parallel/test-stream-writable-destroy.js
+++ b/test/parallel/test-stream-writable-destroy.js
@@ -272,12 +272,12 @@ const assert = require('assert');
write.destroy();
write.on('error', common.expectsError({
- type: Error,
+ name: 'Error',
code: 'ERR_STREAM_DESTROYED',
message: 'Cannot call write after a stream was destroyed'
}));
write.write('asd', common.expectsError({
- type: Error,
+ name: 'Error',
code: 'ERR_STREAM_DESTROYED',
message: 'Cannot call write after a stream was destroyed'
}));
@@ -289,7 +289,7 @@ const assert = require('assert');
});
write.on('error', common.expectsError({
- type: Error,
+ name: 'Error',
code: 'ERR_STREAM_DESTROYED',
message: 'Cannot call write after a stream was destroyed'
}));
@@ -300,13 +300,13 @@ const assert = require('assert');
write.cork();
write.write('asd', common.expectsError({
- type: Error,
+ name: 'Error',
code: 'ERR_STREAM_DESTROYED',
message: 'Cannot call write after a stream was destroyed'
}));
write.destroy();
write.write('asd', common.expectsError({
- type: Error,
+ name: 'Error',
code: 'ERR_STREAM_DESTROYED',
message: 'Cannot call write after a stream was destroyed'
}));
diff --git a/test/parallel/test-stream-writable-null.js b/test/parallel/test-stream-writable-null.js
index dc0f569ee6..506b1df3d0 100644
--- a/test/parallel/test-stream-writable-null.js
+++ b/test/parallel/test-stream-writable-null.js
@@ -1,5 +1,5 @@
'use strict';
-const common = require('../common');
+require('../common');
const assert = require('assert');
const stream = require('stream');
@@ -11,14 +11,14 @@ class MyWritable extends stream.Writable {
}
}
-common.expectsError(
+assert.throws(
() => {
const m = new MyWritable({ objectMode: true });
m.write(null, (err) => assert.ok(err));
},
{
code: 'ERR_STREAM_NULL_VALUES',
- type: TypeError,
+ name: 'TypeError',
message: 'May not write null values to stream'
}
);
@@ -28,14 +28,14 @@ common.expectsError(
m.write(null, assert);
}
-common.expectsError(
+assert.throws(
() => {
const m = new MyWritable();
m.write(false, (err) => assert.ok(err));
},
{
code: 'ERR_INVALID_ARG_TYPE',
- type: TypeError
+ name: 'TypeError'
}
);
diff --git a/test/parallel/test-stream-writable-write-cb-twice.js b/test/parallel/test-stream-writable-write-cb-twice.js
index f066a0ecc4..469712142d 100644
--- a/test/parallel/test-stream-writable-write-cb-twice.js
+++ b/test/parallel/test-stream-writable-write-cb-twice.js
@@ -1,15 +1,16 @@
'use strict';
const common = require('../common');
const { Writable } = require('stream');
+const assert = require('assert');
{
// Sync + Sync
const writable = new Writable({
write: common.mustCall((buf, enc, cb) => {
cb();
- common.expectsError(cb, {
+ assert.throws(cb, {
code: 'ERR_MULTIPLE_CALLBACK',
- type: Error
+ name: 'Error'
});
})
});
@@ -22,9 +23,9 @@ const { Writable } = require('stream');
write: common.mustCall((buf, enc, cb) => {
cb();
process.nextTick(() => {
- common.expectsError(cb, {
+ assert.throws(cb, {
code: 'ERR_MULTIPLE_CALLBACK',
- type: Error
+ name: 'Error'
});
});
})
@@ -38,9 +39,9 @@ const { Writable } = require('stream');
write: common.mustCall((buf, enc, cb) => {
process.nextTick(cb);
process.nextTick(() => {
- common.expectsError(cb, {
+ assert.throws(cb, {
code: 'ERR_MULTIPLE_CALLBACK',
- type: Error
+ name: 'Error'
});
});
})
diff --git a/test/parallel/test-streams-highwatermark.js b/test/parallel/test-streams-highwatermark.js
index 4dd9694a46..cd13f2af69 100644
--- a/test/parallel/test-streams-highwatermark.js
+++ b/test/parallel/test-streams-highwatermark.js
@@ -21,10 +21,10 @@ const stream = require('stream');
for (const invalidHwm of [true, false, '5', {}, -5, NaN]) {
for (const type of [stream.Readable, stream.Writable]) {
- common.expectsError(() => {
+ assert.throws(() => {
type({ highWaterMark: invalidHwm });
}, {
- type: TypeError,
+ name: 'TypeError',
code: 'ERR_INVALID_OPT_VALUE',
message:
`The value "${invalidHwm}" is invalid for option "highWaterMark"`
diff --git a/test/parallel/test-string-decoder.js b/test/parallel/test-string-decoder.js
index 77c7736be9..1fbf9b572c 100644
--- a/test/parallel/test-string-decoder.js
+++ b/test/parallel/test-string-decoder.js
@@ -173,29 +173,29 @@ assert.strictEqual(decoder.write(Buffer.from('f4', 'hex')), '');
assert.strictEqual(decoder.write(Buffer.from('bde5', 'hex')), '\ufffd\ufffd');
assert.strictEqual(decoder.end(), '\ufffd');
-common.expectsError(
+assert.throws(
() => new StringDecoder(1),
{
code: 'ERR_UNKNOWN_ENCODING',
- type: TypeError,
+ name: 'TypeError',
message: 'Unknown encoding: 1'
}
);
-common.expectsError(
+assert.throws(
() => new StringDecoder('test'),
{
code: 'ERR_UNKNOWN_ENCODING',
- type: TypeError,
+ name: 'TypeError',
message: 'Unknown encoding: test'
}
);
-common.expectsError(
+assert.throws(
() => new StringDecoder('utf8').write(null),
{
code: 'ERR_INVALID_ARG_TYPE',
- type: TypeError,
+ name: 'TypeError',
message: 'The "buf" argument must be an instance of Buffer, TypedArray,' +
' or DataView. Received null'
}
diff --git a/test/parallel/test-timers-enroll-invalid-msecs.js b/test/parallel/test-timers-enroll-invalid-msecs.js
index 384ab0ab25..f82bf29d74 100644
--- a/test/parallel/test-timers-enroll-invalid-msecs.js
+++ b/test/parallel/test-timers-enroll-invalid-msecs.js
@@ -1,6 +1,7 @@
'use strict';
-const common = require('../common');
+require('../common');
+const assert = require('assert');
const timers = require('timers');
[
@@ -10,11 +11,11 @@ const timers = require('timers');
() => { },
Symbol('foo')
].forEach((val) => {
- common.expectsError(
+ assert.throws(
() => timers.enroll({}, val),
{
code: 'ERR_INVALID_ARG_TYPE',
- type: TypeError
+ name: 'TypeError'
}
);
});
@@ -24,11 +25,11 @@ const timers = require('timers');
Infinity,
NaN
].forEach((val) => {
- common.expectsError(
+ assert.throws(
() => timers.enroll({}, val),
{
code: 'ERR_OUT_OF_RANGE',
- type: RangeError,
+ name: 'RangeError',
message: 'The value of "msecs" is out of range. ' +
'It must be a non-negative finite number. ' +
`Received ${val}`
diff --git a/test/parallel/test-timers-immediate-queue-throw.js b/test/parallel/test-timers-immediate-queue-throw.js
index 477f0388f6..e5aded86c5 100644
--- a/test/parallel/test-timers-immediate-queue-throw.js
+++ b/test/parallel/test-timers-immediate-queue-throw.js
@@ -19,7 +19,7 @@ let stage = -1;
const QUEUE = 10;
const errObj = {
- type: Error,
+ name: 'Error',
message: 'setImmediate Err'
};
diff --git a/test/parallel/test-timers-refresh.js b/test/parallel/test-timers-refresh.js
index a96f5ad536..17b3b34af5 100644
--- a/test/parallel/test-timers-refresh.js
+++ b/test/parallel/test-timers-refresh.js
@@ -4,7 +4,7 @@
const common = require('../common');
-const { strictEqual } = require('assert');
+const { strictEqual, throws } = require('assert');
const { setUnrefTimeout } = require('internal/timers');
const { inspect } = require('util');
@@ -34,7 +34,7 @@ const { inspect } = require('util');
// Should throw with non-functions
{
[null, true, false, 0, 1, NaN, '', 'foo', {}, Symbol()].forEach((cb) => {
- common.expectsError(
+ throws(
() => setUnrefTimeout(cb),
{
code: 'ERR_INVALID_CALLBACK',
diff --git a/test/parallel/test-timers-throw-when-cb-not-function.js b/test/parallel/test-timers-throw-when-cb-not-function.js
index 9f7f653d3d..75f49b0f3b 100644
--- a/test/parallel/test-timers-throw-when-cb-not-function.js
+++ b/test/parallel/test-timers-throw-when-cb-not-function.js
@@ -1,5 +1,5 @@
'use strict';
-const common = require('../common');
+require('../common');
const assert = require('assert');
function doSetTimeout(callback, after) {
@@ -8,10 +8,10 @@ function doSetTimeout(callback, after) {
};
}
-const errMessage = common.expectsError({
+const errMessage = {
code: 'ERR_INVALID_CALLBACK',
- type: TypeError
-}, 18);
+ name: 'TypeError'
+};
assert.throws(doSetTimeout('foo'), errMessage);
assert.throws(doSetTimeout({ foo: 'bar' }), errMessage);
diff --git a/test/parallel/test-tls-basic-validations.js b/test/parallel/test-tls-basic-validations.js
index f39d8553e7..5dbbeb60f3 100644
--- a/test/parallel/test-tls-basic-validations.js
+++ b/test/parallel/test-tls-basic-validations.js
@@ -7,71 +7,71 @@ if (!common.hasCrypto)
const assert = require('assert');
const tls = require('tls');
-common.expectsError(
+assert.throws(
() => tls.createSecureContext({ ciphers: 1 }),
{
code: 'ERR_INVALID_ARG_TYPE',
- type: TypeError,
+ name: 'TypeError',
message: 'The "options.ciphers" property must be of type string.' +
' Received type number (1)'
});
-common.expectsError(
+assert.throws(
() => tls.createServer({ ciphers: 1 }),
{
code: 'ERR_INVALID_ARG_TYPE',
- type: TypeError,
+ name: 'TypeError',
message: 'The "options.ciphers" property must be of type string.' +
' Received type number (1)'
});
-common.expectsError(
+assert.throws(
() => tls.createSecureContext({ key: 'dummykey', passphrase: 1 }),
{
code: 'ERR_INVALID_ARG_TYPE',
- type: TypeError,
+ name: 'TypeError',
message: 'Pass phrase must be a string'
});
-common.expectsError(
+assert.throws(
() => tls.createServer({ key: 'dummykey', passphrase: 1 }),
{
code: 'ERR_INVALID_ARG_TYPE',
- type: TypeError,
+ name: 'TypeError',
message: 'Pass phrase must be a string'
});
-common.expectsError(
+assert.throws(
() => tls.createServer({ ecdhCurve: 1 }),
{
code: 'ERR_INVALID_ARG_TYPE',
- type: TypeError,
+ name: 'TypeError',
message: 'ECDH curve name must be a string'
});
-common.expectsError(
+assert.throws(
() => tls.createServer({ handshakeTimeout: 'abcd' }),
{
code: 'ERR_INVALID_ARG_TYPE',
- type: TypeError,
+ name: 'TypeError',
message: 'The "options.handshakeTimeout" property must be of type number.' +
" Received type string ('abcd')"
}
);
-common.expectsError(
+assert.throws(
() => tls.createServer({ sessionTimeout: 'abcd' }),
{
code: 'ERR_INVALID_ARG_TYPE',
- type: TypeError,
+ name: 'TypeError',
message: 'Session timeout must be a 32-bit integer'
});
-common.expectsError(
+assert.throws(
() => tls.createServer({ ticketKeys: 'abcd' }),
{
code: 'ERR_INVALID_ARG_TYPE',
- type: TypeError,
+ name: 'TypeError',
message: 'Ticket keys must be a buffer'
});
@@ -109,7 +109,7 @@ assert.throws(
{
const protocols = [(new String('a')).repeat(500)];
const out = {};
- common.expectsError(
+ assert.throws(
() => tls.convertALPNProtocols(protocols, out),
{
code: 'ERR_OUT_OF_RANGE',
diff --git a/test/parallel/test-tls-clientcertengine-invalid-arg-type.js b/test/parallel/test-tls-clientcertengine-invalid-arg-type.js
index 5b77141aaa..811e320b07 100644
--- a/test/parallel/test-tls-clientcertengine-invalid-arg-type.js
+++ b/test/parallel/test-tls-clientcertengine-invalid-arg-type.js
@@ -4,10 +4,11 @@ const common = require('../common');
if (!common.hasCrypto)
common.skip('missing crypto');
+const assert = require('assert');
const tls = require('tls');
{
- common.expectsError(
+ assert.throws(
() => { tls.createSecureContext({ clientCertEngine: 0 }); },
{ code: 'ERR_INVALID_ARG_TYPE',
message: / Received type number \(0\)/ });
diff --git a/test/parallel/test-tls-clientcertengine-unsupported.js b/test/parallel/test-tls-clientcertengine-unsupported.js
index 34b4ea4921..0d24005dc0 100644
--- a/test/parallel/test-tls-clientcertengine-unsupported.js
+++ b/test/parallel/test-tls-clientcertengine-unsupported.js
@@ -5,6 +5,7 @@ const common = require('../common');
if (!common.hasCrypto)
common.skip('missing crypto');
+const assert = require('assert');
// Monkey-patch SecureContext
const { internalBinding } = require('internal/test/binding');
const binding = internalBinding('crypto');
@@ -19,7 +20,7 @@ binding.SecureContext = function() {
const tls = require('tls');
{
- common.expectsError(
+ assert.throws(
() => { tls.createSecureContext({ clientCertEngine: 'Cannonmouth' }); },
{
code: 'ERR_CRYPTO_CUSTOM_ENGINE_NOT_SUPPORTED',
diff --git a/test/parallel/test-tls-disable-renegotiation.js b/test/parallel/test-tls-disable-renegotiation.js
index 3fd6710622..926e2b8a03 100644
--- a/test/parallel/test-tls-disable-renegotiation.js
+++ b/test/parallel/test-tls-disable-renegotiation.js
@@ -21,7 +21,7 @@ const options = {
const server = tls.Server(options, common.mustCall((socket) => {
socket.on('error', common.mustCall((err) => {
common.expectsError({
- type: Error,
+ name: 'Error',
code: 'ERR_TLS_RENEGOTIATION_DISABLED',
message: 'TLS session renegotiation disabled for this socket'
})(err);
@@ -50,24 +50,24 @@ server.listen(0, common.mustCall(() => {
};
const client = tls.connect(options, common.mustCall(() => {
- common.expectsError(() => client.renegotiate(), {
+ assert.throws(() => client.renegotiate(), {
code: 'ERR_INVALID_ARG_TYPE',
- type: TypeError,
+ name: 'TypeError',
});
- common.expectsError(() => client.renegotiate(common.mustNotCall()), {
+ assert.throws(() => client.renegotiate(common.mustNotCall()), {
code: 'ERR_INVALID_ARG_TYPE',
- type: TypeError,
+ name: 'TypeError',
});
- common.expectsError(() => client.renegotiate({}, false), {
+ assert.throws(() => client.renegotiate({}, false), {
code: 'ERR_INVALID_CALLBACK',
- type: TypeError,
+ name: 'TypeError',
});
- common.expectsError(() => client.renegotiate({}, null), {
+ assert.throws(() => client.renegotiate({}, null), {
code: 'ERR_INVALID_CALLBACK',
- type: TypeError,
+ name: 'TypeError',
});
diff --git a/test/parallel/test-tls-error-servername.js b/test/parallel/test-tls-error-servername.js
index 034b2a5705..12e6f89e60 100644
--- a/test/parallel/test-tls-error-servername.js
+++ b/test/parallel/test-tls-error-servername.js
@@ -8,6 +8,7 @@ const fixtures = require('../common/fixtures');
if (!common.hasCrypto)
common.skip('missing crypto');
+const assert = require('assert');
const { connect, TLSSocket } = require('tls');
const makeDuplexPair = require('../common/duplexpair');
const { clientSide, serverSide } = makeDuplexPair();
@@ -23,7 +24,7 @@ const client = connect({
});
[undefined, null, 1, true, {}].forEach((value) => {
- common.expectsError(() => {
+ assert.throws(() => {
client.setServername(value);
}, {
code: 'ERR_INVALID_ARG_TYPE',
@@ -39,7 +40,7 @@ const server = new TLSSocket(serverSide, {
ca
});
-common.expectsError(() => {
+assert.throws(() => {
server.setServername('localhost');
}, {
code: 'ERR_TLS_SNI_FROM_SERVER',
diff --git a/test/parallel/test-tls-keyengine-invalid-arg-type.js b/test/parallel/test-tls-keyengine-invalid-arg-type.js
index d68b40cf0d..72fe526daf 100644
--- a/test/parallel/test-tls-keyengine-invalid-arg-type.js
+++ b/test/parallel/test-tls-keyengine-invalid-arg-type.js
@@ -4,9 +4,10 @@ const common = require('../common');
if (!common.hasCrypto)
common.skip('missing crypto');
+const assert = require('assert');
const tls = require('tls');
-common.expectsError(
+assert.throws(
() => {
tls.createSecureContext({ privateKeyEngine: 0,
privateKeyIdentifier: 'key' });
@@ -14,7 +15,7 @@ common.expectsError(
{ code: 'ERR_INVALID_ARG_TYPE',
message: / Received type number \(0\)$/ });
-common.expectsError(
+assert.throws(
() => {
tls.createSecureContext({ privateKeyEngine: 'engine',
privateKeyIdentifier: 0 });
diff --git a/test/parallel/test-tls-keyengine-unsupported.js b/test/parallel/test-tls-keyengine-unsupported.js
index 149fc4dc31..5fcfe495d5 100644
--- a/test/parallel/test-tls-keyengine-unsupported.js
+++ b/test/parallel/test-tls-keyengine-unsupported.js
@@ -5,6 +5,7 @@ const common = require('../common');
if (!common.hasCrypto)
common.skip('missing crypto');
+const assert = require('assert');
// Monkey-patch SecureContext
const { internalBinding } = require('internal/test/binding');
const binding = internalBinding('crypto');
@@ -19,7 +20,7 @@ binding.SecureContext = function() {
const tls = require('tls');
{
- common.expectsError(
+ assert.throws(
() => {
tls.createSecureContext({
privateKeyEngine: 'engine',
diff --git a/test/parallel/test-tls-no-cert-required.js b/test/parallel/test-tls-no-cert-required.js
index ed24863a2a..b3dcfa516a 100644
--- a/test/parallel/test-tls-no-cert-required.js
+++ b/test/parallel/test-tls-no-cert-required.js
@@ -39,11 +39,11 @@ tls.createServer(assert.fail)
tls.createServer({})
.listen(0, common.mustCall(close));
-common.expectsError(
+assert.throws(
() => tls.createServer('this is not valid'),
{
code: 'ERR_INVALID_ARG_TYPE',
- type: TypeError,
+ name: 'TypeError',
message: 'The "options" argument must be of type object. ' +
"Received type string ('this is not valid')"
}
diff --git a/test/parallel/test-tls-options-boolean-check.js b/test/parallel/test-tls-options-boolean-check.js
index 4caf621559..4dae8e47c8 100644
--- a/test/parallel/test-tls-options-boolean-check.js
+++ b/test/parallel/test-tls-options-boolean-check.js
@@ -6,6 +6,7 @@ const fixtures = require('../common/fixtures');
if (!common.hasCrypto)
common.skip('missing crypto');
+const assert = require('assert');
const tls = require('tls');
function toArrayBuffer(buf) {
@@ -81,11 +82,11 @@ const caArrDataView = toDataView(caCert);
[true, [certBuff, certBuff2]]
].forEach(([key, cert, index]) => {
const val = index === undefined ? key : key[index];
- common.expectsError(() => {
+ assert.throws(() => {
tls.createServer({ key, cert });
}, {
code: 'ERR_INVALID_ARG_TYPE',
- type: TypeError,
+ name: 'TypeError',
message: 'The "options.key" property must be of type string or an ' +
'instance of Buffer, TypedArray, or DataView.' +
common.invalidArgTypeHelper(val)
@@ -107,11 +108,11 @@ const caArrDataView = toDataView(caCert);
[[keyStr, keyStr2], true]
].forEach(([key, cert, index]) => {
const val = index === undefined ? cert : cert[index];
- common.expectsError(() => {
+ assert.throws(() => {
tls.createServer({ key, cert });
}, {
code: 'ERR_INVALID_ARG_TYPE',
- type: TypeError,
+ name: 'TypeError',
message: 'The "options.cert" property must be of type string or an ' +
'instance of Buffer, TypedArray, or DataView.' +
common.invalidArgTypeHelper(val)
@@ -142,11 +143,11 @@ const caArrDataView = toDataView(caCert);
[keyBuff, certBuff, [caCert, true], 1]
].forEach(([key, cert, ca, index]) => {
const val = index === undefined ? ca : ca[index];
- common.expectsError(() => {
+ assert.throws(() => {
tls.createServer({ key, cert, ca });
}, {
code: 'ERR_INVALID_ARG_TYPE',
- type: TypeError,
+ name: 'TypeError',
message: 'The "options.ca" property must be of type string or an instance' +
' of Buffer, TypedArray, or DataView.' +
common.invalidArgTypeHelper(val)
diff --git a/test/parallel/test-trace-events-api-worker-disabled.js b/test/parallel/test-trace-events-api-worker-disabled.js
index eb85a5c2ae..71a6cd2991 100644
--- a/test/parallel/test-trace-events-api-worker-disabled.js
+++ b/test/parallel/test-trace-events-api-worker-disabled.js
@@ -6,5 +6,5 @@ const { Worker } = require('worker_threads');
new Worker("require('trace_events')", { eval: true })
.on('error', common.expectsError({
code: 'ERR_TRACE_EVENTS_UNAVAILABLE',
- type: Error
+ name: 'Error'
}));
diff --git a/test/parallel/test-trace-events-api.js b/test/parallel/test-trace-events-api.js
index 40fc661879..676e7f31e1 100644
--- a/test/parallel/test-trace-events-api.js
+++ b/test/parallel/test-trace-events-api.js
@@ -35,21 +35,21 @@ const enabledCategories = getEnabledCategoriesFromCommandLine();
assert.strictEqual(getEnabledCategories(), enabledCategories);
[1, 'foo', true, false, null, undefined].forEach((i) => {
- common.expectsError(() => createTracing(i), {
+ assert.throws(() => createTracing(i), {
code: 'ERR_INVALID_ARG_TYPE',
- type: TypeError
+ name: 'TypeError'
});
- common.expectsError(() => createTracing({ categories: i }), {
+ assert.throws(() => createTracing({ categories: i }), {
code: 'ERR_INVALID_ARG_TYPE',
- type: TypeError
+ name: 'TypeError'
});
});
-common.expectsError(
+assert.throws(
() => createTracing({ categories: [] }),
{
code: 'ERR_TRACE_EVENTS_CATEGORY_REQUIRED',
- type: TypeError
+ name: 'TypeError'
}
);
diff --git a/test/parallel/test-url-format-invalid-input.js b/test/parallel/test-url-format-invalid-input.js
index 5ba3b0bb4b..99a35b76f0 100644
--- a/test/parallel/test-url-format-invalid-input.js
+++ b/test/parallel/test-url-format-invalid-input.js
@@ -14,11 +14,11 @@ const throwsObjsAndReportTypes = [
];
for (const urlObject of throwsObjsAndReportTypes) {
- common.expectsError(function() {
+ assert.throws(() => {
url.format(urlObject);
}, {
code: 'ERR_INVALID_ARG_TYPE',
- type: TypeError,
+ name: 'TypeError',
message: 'The "urlObject" argument must be one of type object or string.' +
common.invalidArgTypeHelper(urlObject)
});
diff --git a/test/parallel/test-url-parse-invalid-input.js b/test/parallel/test-url-parse-invalid-input.js
index bfbd663629..ff63e91ecd 100644
--- a/test/parallel/test-url-parse-invalid-input.js
+++ b/test/parallel/test-url-parse-invalid-input.js
@@ -16,11 +16,11 @@ const url = require('url');
[() => {}, 'function'],
[Symbol('foo'), 'symbol']
].forEach(([val, type]) => {
- common.expectsError(() => {
+ assert.throws(() => {
url.parse(val);
}, {
code: 'ERR_INVALID_ARG_TYPE',
- type: TypeError,
+ name: 'TypeError',
message: 'The "url" argument must be of type string.' +
common.invalidArgTypeHelper(val)
});
diff --git a/test/parallel/test-util-callbackify.js b/test/parallel/test-util-callbackify.js
index 7bb964b270..eb2b3a383b 100644
--- a/test/parallel/test-util-callbackify.js
+++ b/test/parallel/test-util-callbackify.js
@@ -255,11 +255,11 @@ const values = [
{
// Verify that non-function inputs throw.
['foo', null, undefined, false, 0, {}, Symbol(), []].forEach((value) => {
- common.expectsError(() => {
+ assert.throws(() => {
callbackify(value);
}, {
code: 'ERR_INVALID_ARG_TYPE',
- type: TypeError,
+ name: 'TypeError',
message: 'The "original" argument must be of type function.' +
common.invalidArgTypeHelper(value)
});
@@ -277,11 +277,11 @@ const values = [
// Verify that the last argument to the callbackified function is a function.
['foo', null, undefined, false, 0, {}, Symbol(), []].forEach((value) => {
args.push(value);
- common.expectsError(() => {
+ assert.throws(() => {
cb(...args);
}, {
code: 'ERR_INVALID_ARG_TYPE',
- type: TypeError,
+ name: 'TypeError',
message: 'The last argument must be of type function.' +
common.invalidArgTypeHelper(value)
});
diff --git a/test/parallel/test-util-deprecate-invalid-code.js b/test/parallel/test-util-deprecate-invalid-code.js
index 29758556f1..7e68c18817 100644
--- a/test/parallel/test-util-deprecate-invalid-code.js
+++ b/test/parallel/test-util-deprecate-invalid-code.js
@@ -1,12 +1,13 @@
'use strict';
const common = require('../common');
+const assert = require('assert');
const util = require('util');
[1, true, false, null, {}].forEach((notString) => {
- common.expectsError(() => util.deprecate(() => {}, 'message', notString), {
+ assert.throws(() => util.deprecate(() => {}, 'message', notString), {
code: 'ERR_INVALID_ARG_TYPE',
- type: TypeError,
+ name: 'TypeError',
message: 'The "code" argument must be of type string.' +
common.invalidArgTypeHelper(notString)
});
diff --git a/test/parallel/test-util-inherits.js b/test/parallel/test-util-inherits.js
index a190c8d886..1729b1734d 100644
--- a/test/parallel/test-util-inherits.js
+++ b/test/parallel/test-util-inherits.js
@@ -1,6 +1,6 @@
'use strict';
-const common = require('../common');
+require('../common');
const assert = require('assert');
const { inherits } = require('util');
@@ -83,28 +83,28 @@ assert.strictEqual(e.e(), 'e');
assert.strictEqual(e.constructor, E);
// Should throw with invalid arguments
-common.expectsError(function() {
+assert.throws(() => {
inherits(A, {});
}, {
code: 'ERR_INVALID_ARG_TYPE',
- type: TypeError,
+ name: 'TypeError',
message: 'The "superCtor.prototype" property must be of type object. ' +
'Received undefined'
});
-common.expectsError(function() {
+assert.throws(() => {
inherits(A, null);
}, {
code: 'ERR_INVALID_ARG_TYPE',
- type: TypeError,
+ name: 'TypeError',
message: 'The "superCtor" argument must be of type function. ' +
'Received null'
});
-common.expectsError(function() {
+assert.throws(() => {
inherits(null, A);
}, {
code: 'ERR_INVALID_ARG_TYPE',
- type: TypeError,
+ name: 'TypeError',
message: 'The "ctor" argument must be of type function. Received null'
});
diff --git a/test/parallel/test-util-inspect.js b/test/parallel/test-util-inspect.js
index 7795b1adff..b7c7623410 100644
--- a/test/parallel/test-util-inspect.js
+++ b/test/parallel/test-util-inspect.js
@@ -1451,21 +1451,21 @@ if (typeof Symbol !== 'undefined') {
JSON.stringify(oldOptions)
);
- common.expectsError(() => {
+ assert.throws(() => {
util.inspect.defaultOptions = null;
}, {
code: 'ERR_INVALID_ARG_TYPE',
- type: TypeError,
+ name: 'TypeError',
message: 'The "options" argument must be of type object. ' +
'Received null'
}
);
- common.expectsError(() => {
+ assert.throws(() => {
util.inspect.defaultOptions = 'bad';
}, {
code: 'ERR_INVALID_ARG_TYPE',
- type: TypeError,
+ name: 'TypeError',
message: 'The "options" argument must be of type object. ' +
"Received type string ('bad')"
}
diff --git a/test/parallel/test-util-promisify.js b/test/parallel/test-util-promisify.js
index 8b91deba3a..4ed1653984 100644
--- a/test/parallel/test-util-promisify.js
+++ b/test/parallel/test-util-promisify.js
@@ -36,9 +36,9 @@ const stat = promisify(fs.stat);
{
function fn() {}
fn[promisify.custom] = 42;
- common.expectsError(
+ assert.throws(
() => promisify(fn),
- { code: 'ERR_INVALID_ARG_TYPE', type: TypeError }
+ { code: 'ERR_INVALID_ARG_TYPE', name: 'TypeError' }
);
}
@@ -185,11 +185,11 @@ const stat = promisify(fs.stat);
}
[undefined, null, true, 0, 'str', {}, [], Symbol()].forEach((input) => {
- common.expectsError(
+ assert.throws(
() => promisify(input),
{
code: 'ERR_INVALID_ARG_TYPE',
- type: TypeError,
+ name: 'TypeError',
message: 'The "original" argument must be of type function.' +
common.invalidArgTypeHelper(input)
});
diff --git a/test/parallel/test-uv-errno.js b/test/parallel/test-uv-errno.js
index 4f97941f4b..e46b365e4b 100644
--- a/test/parallel/test-uv-errno.js
+++ b/test/parallel/test-uv-errno.js
@@ -26,22 +26,22 @@ keys.forEach((key) => {
function runTest(fn) {
['test', {}, []].forEach((err) => {
- common.expectsError(
+ assert.throws(
() => fn(err),
{
code: 'ERR_INVALID_ARG_TYPE',
- type: TypeError,
+ name: 'TypeError',
message: 'The "err" argument must be of type number.' +
common.invalidArgTypeHelper(err)
});
});
[0, 1, Infinity, -Infinity, NaN].forEach((err) => {
- common.expectsError(
+ assert.throws(
() => fn(err),
{
code: 'ERR_OUT_OF_RANGE',
- type: RangeError,
+ name: 'RangeError',
message: 'The value of "err" is out of range. ' +
'It must be a negative integer. ' +
`Received ${err}`
diff --git a/test/parallel/test-v8-flag-type-check.js b/test/parallel/test-v8-flag-type-check.js
index 51f485f543..e46c09b797 100644
--- a/test/parallel/test-v8-flag-type-check.js
+++ b/test/parallel/test-v8-flag-type-check.js
@@ -1,13 +1,14 @@
'use strict';
const common = require('../common');
+const assert = require('assert');
const v8 = require('v8');
[1, undefined].forEach((value) => {
- common.expectsError(
+ assert.throws(
() => v8.setFlagsFromString(value),
{
code: 'ERR_INVALID_ARG_TYPE',
- type: TypeError,
+ name: 'TypeError',
message: 'The "flags" argument must be of type string.' +
common.invalidArgTypeHelper(value)
}
diff --git a/test/parallel/test-validators.js b/test/parallel/test-validators.js
index caf547b77c..76b10a9abe 100644
--- a/test/parallel/test-validators.js
+++ b/test/parallel/test-validators.js
@@ -1,22 +1,23 @@
// Flags: --expose-internals
'use strict';
-const common = require('../common');
+require('../common');
+const assert = require('assert');
const {
validateInteger
} = require('internal/validators');
const { MAX_SAFE_INTEGER, MIN_SAFE_INTEGER } = Number;
const outOfRangeError = {
code: 'ERR_OUT_OF_RANGE',
- type: RangeError
+ name: 'RangeError'
};
// validateInteger() defaults to validating safe integers.
validateInteger(MAX_SAFE_INTEGER, 'foo');
validateInteger(MIN_SAFE_INTEGER, 'foo');
-common.expectsError(() => {
+assert.throws(() => {
validateInteger(MAX_SAFE_INTEGER + 1, 'foo');
}, outOfRangeError);
-common.expectsError(() => {
+assert.throws(() => {
validateInteger(MIN_SAFE_INTEGER - 1, 'foo');
}, outOfRangeError);
diff --git a/test/parallel/test-vm-basic.js b/test/parallel/test-vm-basic.js
index e530f67196..c6dadce9ad 100644
--- a/test/parallel/test-vm-basic.js
+++ b/test/parallel/test-vm-basic.js
@@ -97,33 +97,33 @@ const vm = require('vm');
// Invalid arguments
[null, 'string'].forEach((input) => {
- common.expectsError(() => {
+ assert.throws(() => {
vm.createContext({}, input);
}, {
code: 'ERR_INVALID_ARG_TYPE',
- type: TypeError,
+ name: 'TypeError',
message: 'The "options" argument must be of type object.' +
common.invalidArgTypeHelper(input)
});
});
['name', 'origin'].forEach((propertyName) => {
- common.expectsError(() => {
+ assert.throws(() => {
vm.createContext({}, { [propertyName]: null });
}, {
code: 'ERR_INVALID_ARG_TYPE',
- type: TypeError,
+ name: 'TypeError',
message: `The "options.${propertyName}" property must be of type string. ` +
'Received null'
});
});
['contextName', 'contextOrigin'].forEach((propertyName) => {
- common.expectsError(() => {
+ assert.throws(() => {
vm.runInNewContext('', {}, { [propertyName]: null });
}, {
code: 'ERR_INVALID_ARG_TYPE',
- type: TypeError,
+ name: 'TypeError',
message: `The "options.${propertyName}" property must be of type string. ` +
'Received null'
});
@@ -146,18 +146,18 @@ const vm = require('vm');
vm.compileFunction('return'); // Should not throw on 'return'
- common.expectsError(() => {
+ assert.throws(() => {
vm.compileFunction(
'});\n\n(function() {\nconsole.log(1);\n})();\n\n(function() {'
);
}, {
- type: SyntaxError,
+ name: 'SyntaxError',
message: "Unexpected token '}'"
});
// Tests for failed argument validation
- common.expectsError(() => vm.compileFunction(), {
- type: TypeError,
+ assert.throws(() => vm.compileFunction(), {
+ name: 'TypeError',
code: 'ERR_INVALID_ARG_TYPE',
message: 'The "code" argument must be of type string. ' +
'Received undefined'
@@ -165,8 +165,8 @@ const vm = require('vm');
vm.compileFunction(''); // Should pass without params or options
- common.expectsError(() => vm.compileFunction('', null), {
- type: TypeError,
+ assert.throws(() => vm.compileFunction('', null), {
+ name: 'TypeError',
code: 'ERR_INVALID_ARG_TYPE',
message: 'The "params" argument must be an instance of Array. ' +
'Received null'
@@ -185,10 +185,10 @@ const vm = require('vm');
for (const option in optionTypes) {
const typeErrorMessage = `The "options.${option}" property must be ` +
(option === 'cachedData' ? 'an instance of' : 'of type');
- common.expectsError(() => {
+ assert.throws(() => {
vm.compileFunction('', undefined, { [option]: null });
}, {
- type: TypeError,
+ name: 'TypeError',
code: 'ERR_INVALID_ARG_TYPE',
message: typeErrorMessage +
` ${optionTypes[option]}. Received null`
@@ -198,10 +198,10 @@ const vm = require('vm');
// Testing for context-based failures
[Boolean(), Number(), null, String(), Symbol(), {}].forEach(
(value) => {
- common.expectsError(() => {
+ assert.throws(() => {
vm.compileFunction('', undefined, { parsingContext: value });
}, {
- type: TypeError,
+ name: 'TypeError',
code: 'ERR_INVALID_ARG_TYPE',
message: 'The "options.parsingContext" property must be an instance ' +
`of Context.${common.invalidArgTypeHelper(value)}`
@@ -212,10 +212,10 @@ const vm = require('vm');
// Testing for non Array type-based failures
[Boolean(), Number(), null, Object(), Symbol(), {}].forEach(
(value) => {
- common.expectsError(() => {
+ assert.throws(() => {
vm.compileFunction('', value);
}, {
- type: TypeError,
+ name: 'TypeError',
code: 'ERR_INVALID_ARG_TYPE',
message: 'The "params" argument must be an instance of Array.' +
common.invalidArgTypeHelper(value)
@@ -232,19 +232,19 @@ const vm = require('vm');
5
);
- common.expectsError(() => {
+ assert.throws(() => {
vm.compileFunction('', undefined, { contextExtensions: null });
}, {
- type: TypeError,
+ name: 'TypeError',
code: 'ERR_INVALID_ARG_TYPE',
message: 'The "options.contextExtensions" property must be an instance of' +
' Array. Received null'
});
- common.expectsError(() => {
+ assert.throws(() => {
vm.compileFunction('', undefined, { contextExtensions: [0] });
}, {
- type: TypeError,
+ name: 'TypeError',
code: 'ERR_INVALID_ARG_TYPE',
message: 'The "options.contextExtensions[0]" property must be of type ' +
'object. Received type number (0)'
@@ -254,14 +254,14 @@ const vm = require('vm');
// Setting value to run the last three tests
Error.stackTraceLimit = 1;
- common.expectsError(() => {
+ assert.throws(() => {
vm.compileFunction('throw new Error("Sample Error")')();
}, {
message: 'Sample Error',
stack: 'Error: Sample Error\n at <anonymous>:1:7'
});
- common.expectsError(() => {
+ assert.throws(() => {
vm.compileFunction(
'throw new Error("Sample Error")',
[],
@@ -272,7 +272,7 @@ const vm = require('vm');
stack: 'Error: Sample Error\n at <anonymous>:4:7'
});
- common.expectsError(() => {
+ assert.throws(() => {
vm.compileFunction(
'throw new Error("Sample Error")',
[],
@@ -294,7 +294,7 @@ const vm = require('vm');
'abc'
);
- common.expectsError(() => {
+ assert.throws(() => {
vm.compileFunction(
'return varInContext',
[]
diff --git a/test/parallel/test-vm-cached-data.js b/test/parallel/test-vm-cached-data.js
index dbf369bf81..a9f1293647 100644
--- a/test/parallel/test-vm-cached-data.js
+++ b/test/parallel/test-vm-cached-data.js
@@ -86,12 +86,12 @@ function testRejectSlice() {
testRejectSlice();
// It should throw on non-Buffer cachedData
-common.expectsError(() => {
+assert.throws(() => {
new vm.Script('function abc() {}', {
cachedData: 'ohai'
});
}, {
code: 'ERR_INVALID_ARG_TYPE',
- type: TypeError,
+ name: 'TypeError',
message: /must be an instance of Buffer, TypedArray, or DataView/
});
diff --git a/test/parallel/test-vm-codegen.js b/test/parallel/test-vm-codegen.js
index 0136e143ab..90b37c741a 100644
--- a/test/parallel/test-vm-codegen.js
+++ b/test/parallel/test-vm-codegen.js
@@ -1,6 +1,6 @@
'use strict';
-const common = require('../common');
+require('../common');
const assert = require('assert');
const { createContext, runInContext, runInNewContext } = require('vm');
@@ -64,7 +64,7 @@ assert.throws(() => {
name: 'CompileError'
});
-common.expectsError(() => {
+assert.throws(() => {
createContext({}, {
codeGeneration: {
strings: 0,
@@ -74,7 +74,7 @@ common.expectsError(() => {
code: 'ERR_INVALID_ARG_TYPE',
});
-common.expectsError(() => {
+assert.throws(() => {
runInNewContext('eval("x")', {}, {
contextCodeGeneration: {
wasm: 1,
@@ -84,7 +84,7 @@ common.expectsError(() => {
code: 'ERR_INVALID_ARG_TYPE'
});
-common.expectsError(() => {
+assert.throws(() => {
createContext({}, {
codeGeneration: 1,
});
@@ -92,7 +92,7 @@ common.expectsError(() => {
code: 'ERR_INVALID_ARG_TYPE',
});
-common.expectsError(() => {
+assert.throws(() => {
createContext({}, {
codeGeneration: null,
});
diff --git a/test/parallel/test-vm-context.js b/test/parallel/test-vm-context.js
index edb66908f1..247b8a17cc 100644
--- a/test/parallel/test-vm-context.js
+++ b/test/parallel/test-vm-context.js
@@ -20,7 +20,7 @@
// USE OR OTHER DEALINGS IN THE SOFTWARE.
'use strict';
-const common = require('../common');
+require('../common');
const assert = require('assert');
const vm = require('vm');
@@ -44,11 +44,11 @@ assert.strictEqual(context.foo, 3);
assert.strictEqual(context.thing, 'lala');
// Issue GH-227:
-common.expectsError(() => {
+assert.throws(() => {
vm.runInNewContext('', null, 'some.js');
}, {
code: 'ERR_INVALID_ARG_TYPE',
- type: TypeError
+ name: 'TypeError'
});
// Issue GH-1140:
@@ -66,12 +66,12 @@ assert.strictEqual(gh1140Exception.toString(), 'Error');
const nonContextualObjectError = {
code: 'ERR_INVALID_ARG_TYPE',
- type: TypeError,
+ name: 'TypeError',
message: /must be of type object/
};
const contextifiedObjectError = {
code: 'ERR_INVALID_ARG_TYPE',
- type: TypeError,
+ name: 'TypeError',
message: /The "contextifiedObject" argument must be an vm\.Context/
};
@@ -84,8 +84,8 @@ const contextifiedObjectError = {
[{}, contextifiedObjectError],
[[], contextifiedObjectError]
].forEach((e) => {
- common.expectsError(() => { script.runInContext(e[0]); }, e[1]);
- common.expectsError(() => { vm.runInContext('', e[0]); }, e[1]);
+ assert.throws(() => { script.runInContext(e[0]); }, e[1]);
+ assert.throws(() => { vm.runInContext('', e[0]); }, e[1]);
});
// Issue GH-693:
diff --git a/test/parallel/test-vm-create-context-arg.js b/test/parallel/test-vm-create-context-arg.js
index d9e017d0f9..c07079cb6c 100644
--- a/test/parallel/test-vm-create-context-arg.js
+++ b/test/parallel/test-vm-create-context-arg.js
@@ -20,14 +20,15 @@
// USE OR OTHER DEALINGS IN THE SOFTWARE.
'use strict';
-const common = require('../common');
+require('../common');
+const assert = require('assert');
const vm = require('vm');
-common.expectsError(() => {
+assert.throws(() => {
vm.createContext('string is not supported');
}, {
code: 'ERR_INVALID_ARG_TYPE',
- type: TypeError
+ name: 'TypeError'
});
// Should not throw.
diff --git a/test/parallel/test-vm-is-context.js b/test/parallel/test-vm-is-context.js
index 2749a14834..a47bee7c59 100644
--- a/test/parallel/test-vm-is-context.js
+++ b/test/parallel/test-vm-is-context.js
@@ -20,18 +20,18 @@
// USE OR OTHER DEALINGS IN THE SOFTWARE.
'use strict';
-const common = require('../common');
+require('../common');
const assert = require('assert');
const vm = require('vm');
for (const valToTest of [
'string', null, undefined, 8.9, Symbol('sym'), true
]) {
- common.expectsError(() => {
+ assert.throws(() => {
vm.isContext(valToTest);
}, {
code: 'ERR_INVALID_ARG_TYPE',
- type: TypeError
+ name: 'TypeError'
});
}
diff --git a/test/parallel/test-vm-module-basic.js b/test/parallel/test-vm-module-basic.js
index d45147cefd..86e13f8b12 100644
--- a/test/parallel/test-vm-module-basic.js
+++ b/test/parallel/test-vm-module-basic.js
@@ -115,35 +115,35 @@ const util = require('util');
// Check the impossibility of creating an abstract instance of the Module.
{
- common.expectsError(() => new Module(), {
+ assert.throws(() => new Module(), {
message: 'Module is not a constructor',
- type: TypeError
+ name: 'TypeError'
});
}
// Check to throws invalid exportNames
{
- common.expectsError(() => new SyntheticModule(undefined, () => {}, {}), {
+ assert.throws(() => new SyntheticModule(undefined, () => {}, {}), {
message: 'The "exportNames" argument must be an Array of strings.' +
' Received undefined',
- type: TypeError
+ name: 'TypeError'
});
}
// Check to throws invalid evaluateCallback
{
- common.expectsError(() => new SyntheticModule([], undefined, {}), {
+ assert.throws(() => new SyntheticModule([], undefined, {}), {
message: 'The "evaluateCallback" argument must be of type function.' +
' Received undefined',
- type: TypeError
+ name: 'TypeError'
});
}
// Check to throws invalid options
{
- common.expectsError(() => new SyntheticModule([], () => {}, null), {
+ assert.throws(() => new SyntheticModule([], () => {}, null), {
message: 'The "options" argument must be of type object.' +
' Received null',
- type: TypeError
+ name: 'TypeError'
});
}
diff --git a/test/parallel/test-vm-module-errors.js b/test/parallel/test-vm-module-errors.js
index a76666c028..5f36f9339f 100644
--- a/test/parallel/test-vm-module-errors.js
+++ b/test/parallel/test-vm-module-errors.js
@@ -15,22 +15,22 @@ async function createEmptyLinkedModule() {
}
async function checkArgType() {
- common.expectsError(() => {
+ assert.throws(() => {
new SourceTextModule();
}, {
code: 'ERR_INVALID_ARG_TYPE',
- type: TypeError
+ name: 'TypeError'
});
for (const invalidOptions of [
0, 1, null, true, 'str', () => {}, { identifier: 0 }, Symbol.iterator,
{ context: null }, { context: 'hucairz' }, { context: {} }
]) {
- common.expectsError(() => {
+ assert.throws(() => {
new SourceTextModule('', invalidOptions);
}, {
code: 'ERR_INVALID_ARG_TYPE',
- type: TypeError
+ name: 'TypeError'
});
}
@@ -84,7 +84,7 @@ async function checkModuleState() {
'Received type boolean (false)'
});
- common.expectsError(() => {
+ assert.throws(() => {
const m = new SourceTextModule('');
m.error;
}, {
@@ -101,7 +101,7 @@ async function checkModuleState() {
message: 'Module status must be errored'
});
- common.expectsError(() => {
+ assert.throws(() => {
const m = new SourceTextModule('');
m.namespace;
}, {
@@ -156,13 +156,13 @@ async function checkLinking() {
});
}
-common.expectsError(() => {
+assert.throws(() => {
new SourceTextModule('', {
importModuleDynamically: 'hucairz'
});
}, {
code: 'ERR_INVALID_ARG_TYPE',
- type: TypeError,
+ name: 'TypeError',
message: 'The "options.importModuleDynamically" property must be of type ' +
"function. Received type string ('hucairz')"
});
diff --git a/test/parallel/test-vm-module-import-meta.js b/test/parallel/test-vm-module-import-meta.js
index 1db4467b08..0f86f2fa64 100644
--- a/test/parallel/test-vm-module-import-meta.js
+++ b/test/parallel/test-vm-module-import-meta.js
@@ -25,13 +25,13 @@ async function testInvalid() {
for (const invalidValue of [
null, {}, 0, Symbol.iterator, [], 'string', false
]) {
- common.expectsError(() => {
+ assert.throws(() => {
new SourceTextModule('', {
initializeImportMeta: invalidValue
});
}, {
code: 'ERR_INVALID_ARG_TYPE',
- type: TypeError
+ name: 'TypeError'
});
}
}
diff --git a/test/parallel/test-vm-options-validation.js b/test/parallel/test-vm-options-validation.js
index 67a27d58ff..1d02f8eb90 100644
--- a/test/parallel/test-vm-options-validation.js
+++ b/test/parallel/test-vm-options-validation.js
@@ -1,60 +1,61 @@
'use strict';
-const common = require('../common');
+require('../common');
+const assert = require('assert');
const vm = require('vm');
const invalidArgType = {
- type: TypeError,
+ name: 'TypeError',
code: 'ERR_INVALID_ARG_TYPE'
};
const outOfRange = {
- type: RangeError,
+ name: 'RangeError',
code: 'ERR_OUT_OF_RANGE'
};
-common.expectsError(() => {
+assert.throws(() => {
new vm.Script('void 0', 42);
}, invalidArgType);
[null, {}, [1], 'bad', true].forEach((value) => {
- common.expectsError(() => {
+ assert.throws(() => {
new vm.Script('void 0', { lineOffset: value });
}, invalidArgType);
- common.expectsError(() => {
+ assert.throws(() => {
new vm.Script('void 0', { columnOffset: value });
}, invalidArgType);
});
[0.1, 2 ** 32].forEach((value) => {
- common.expectsError(() => {
+ assert.throws(() => {
new vm.Script('void 0', { lineOffset: value });
}, outOfRange);
- common.expectsError(() => {
+ assert.throws(() => {
new vm.Script('void 0', { columnOffset: value });
}, outOfRange);
});
-common.expectsError(() => {
+assert.throws(() => {
new vm.Script('void 0', { lineOffset: Number.MAX_SAFE_INTEGER });
}, outOfRange);
-common.expectsError(() => {
+assert.throws(() => {
new vm.Script('void 0', { columnOffset: Number.MAX_SAFE_INTEGER });
}, outOfRange);
-common.expectsError(() => {
+assert.throws(() => {
new vm.Script('void 0', { filename: 123 });
}, invalidArgType);
-common.expectsError(() => {
+assert.throws(() => {
new vm.Script('void 0', { produceCachedData: 1 });
}, invalidArgType);
[[0], {}, true, 'bad', 42].forEach((value) => {
- common.expectsError(() => {
+ assert.throws(() => {
new vm.Script('void 0', { cachedData: value });
}, invalidArgType);
});
@@ -64,15 +65,15 @@ common.expectsError(() => {
const sandbox = vm.createContext();
function assertErrors(options, errCheck) {
- common.expectsError(() => {
+ assert.throws(() => {
script.runInThisContext(options);
}, errCheck);
- common.expectsError(() => {
+ assert.throws(() => {
script.runInContext(sandbox, options);
}, errCheck);
- common.expectsError(() => {
+ assert.throws(() => {
script.runInNewContext({}, options);
}, errCheck);
}
diff --git a/test/parallel/test-vm-sigint-existing-handler.js b/test/parallel/test-vm-sigint-existing-handler.js
index 13fccd9637..c6072d29d8 100644
--- a/test/parallel/test-vm-sigint-existing-handler.js
+++ b/test/parallel/test-vm-sigint-existing-handler.js
@@ -36,7 +36,7 @@ if (process.argv[2] === 'child') {
[];
const options = { breakOnSigint: true };
- common.expectsError(
+ assert.throws(
() => { vm[method](script, ...args, options); },
{
code: 'ERR_SCRIPT_EXECUTION_INTERRUPTED',
diff --git a/test/parallel/test-vm-sigint.js b/test/parallel/test-vm-sigint.js
index 0fecfbace6..66f22ba878 100644
--- a/test/parallel/test-vm-sigint.js
+++ b/test/parallel/test-vm-sigint.js
@@ -24,7 +24,7 @@ if (process.argv[2] === 'child') {
for (let i = 0; i < listeners; i++)
process.on('SIGINT', common.mustNotCall());
- common.expectsError(
+ assert.throws(
() => { vm[method](script, ...args, options); },
{
code: 'ERR_SCRIPT_EXECUTION_INTERRUPTED',
diff --git a/test/parallel/test-whatwg-encoding-custom-fatal-streaming.js b/test/parallel/test-whatwg-encoding-custom-fatal-streaming.js
index 50e054c08c..aed0f14ef7 100644
--- a/test/parallel/test-whatwg-encoding-custom-fatal-streaming.js
+++ b/test/parallel/test-whatwg-encoding-custom-fatal-streaming.js
@@ -4,6 +4,7 @@
// With the twist that we specifically test for Node.js error codes
const common = require('../common');
+const assert = require('assert');
if (!common.hasIntl)
common.skip('missing Intl');
@@ -15,13 +16,13 @@ if (!common.hasIntl)
{ encoding: 'utf-16be', sequence: [0x00] }
].forEach((testCase) => {
const data = new Uint8Array([testCase.sequence]);
- common.expectsError(
+ assert.throws(
() => {
const decoder = new TextDecoder(testCase.encoding, { fatal: true });
decoder.decode(data);
}, {
code: 'ERR_ENCODING_INVALID_ENCODED_DATA',
- type: TypeError,
+ name: 'TypeError',
message:
`The encoded data was not valid for encoding ${testCase.encoding}`
}
@@ -34,25 +35,25 @@ if (!common.hasIntl)
const odd = new Uint8Array([0x00]);
const even = new Uint8Array([0x00, 0x00]);
- common.expectsError(
+ assert.throws(
() => {
decoder.decode(even, { stream: true });
decoder.decode(odd);
}, {
code: 'ERR_ENCODING_INVALID_ENCODED_DATA',
- type: TypeError,
+ name: 'TypeError',
message:
'The encoded data was not valid for encoding utf-16le'
}
);
- common.expectsError(
+ assert.throws(
() => {
decoder.decode(odd, { stream: true });
decoder.decode(even);
}, {
code: 'ERR_ENCODING_INVALID_ENCODED_DATA',
- type: TypeError,
+ name: 'TypeError',
message:
'The encoded data was not valid for encoding utf-16le'
}
diff --git a/test/parallel/test-whatwg-encoding-custom-interop.js b/test/parallel/test-whatwg-encoding-custom-interop.js
index 0ea732a03d..592dcc8582 100644
--- a/test/parallel/test-whatwg-encoding-custom-interop.js
+++ b/test/parallel/test-whatwg-encoding-custom-interop.js
@@ -5,7 +5,7 @@
'use strict';
-const common = require('../common');
+require('../common');
const assert = require('assert');
const { customInspectSymbol: inspect } = require('internal/util');
@@ -47,7 +47,7 @@ assert(TextEncoder);
const expectedError = {
code: 'ERR_INVALID_THIS',
- type: TypeError,
+ name: 'TypeError',
message: 'Value of "this" must be of type TextEncoder'
};
@@ -57,8 +57,8 @@ assert(TextEncoder);
const invalidThisArgs = [{}, [], true, 1, '', new TextDecoder()];
invalidThisArgs.forEach((i) => {
- common.expectsError(() => inspectFn.call(i, Infinity, {}), expectedError);
- common.expectsError(() => encodeFn.call(i), expectedError);
- common.expectsError(() => encodingGetter.call(i), expectedError);
+ assert.throws(() => inspectFn.call(i, Infinity, {}), expectedError);
+ assert.throws(() => encodeFn.call(i), expectedError);
+ assert.throws(() => encodingGetter.call(i), expectedError);
});
}
diff --git a/test/parallel/test-whatwg-encoding-custom-textdecoder-api-invalid-label.js b/test/parallel/test-whatwg-encoding-custom-textdecoder-api-invalid-label.js
index aabd3fe5c4..3323f5b3d1 100644
--- a/test/parallel/test-whatwg-encoding-custom-textdecoder-api-invalid-label.js
+++ b/test/parallel/test-whatwg-encoding-custom-textdecoder-api-invalid-label.js
@@ -2,7 +2,8 @@
// From: https://github.com/w3c/web-platform-tests/blob/master/encoding/api-invalid-label.html
// With the twist that we specifically test for Node.js error codes
-const common = require('../common');
+require('../common');
+const assert = require('assert');
[
'utf-8',
@@ -13,27 +14,27 @@ const common = require('../common');
'utf-16'
].forEach((i) => {
['\u0000', '\u000b', '\u00a0', '\u2028', '\u2029'].forEach((ws) => {
- common.expectsError(
+ assert.throws(
() => new TextDecoder(`${ws}${i}`),
{
code: 'ERR_ENCODING_NOT_SUPPORTED',
- type: RangeError
+ name: 'RangeError'
}
);
- common.expectsError(
+ assert.throws(
() => new TextDecoder(`${i}${ws}`),
{
code: 'ERR_ENCODING_NOT_SUPPORTED',
- type: RangeError
+ name: 'RangeError'
}
);
- common.expectsError(
+ assert.throws(
() => new TextDecoder(`${ws}${i}${ws}`),
{
code: 'ERR_ENCODING_NOT_SUPPORTED',
- type: RangeError
+ name: 'RangeError'
}
);
});
diff --git a/test/parallel/test-whatwg-encoding-custom-textdecoder-fatal.js b/test/parallel/test-whatwg-encoding-custom-textdecoder-fatal.js
index 08406386a1..8778fa018e 100644
--- a/test/parallel/test-whatwg-encoding-custom-textdecoder-fatal.js
+++ b/test/parallel/test-whatwg-encoding-custom-textdecoder-fatal.js
@@ -8,6 +8,8 @@ const common = require('../common');
if (!common.hasIntl)
common.skip('missing Intl');
+const assert = require('assert');
+
const bad = [
{ encoding: 'utf-8', input: [0xFF], name: 'invalid code' },
{ encoding: 'utf-8', input: [0xC0], name: 'ends early' },
@@ -70,13 +72,13 @@ const bad = [
];
bad.forEach((t) => {
- common.expectsError(
+ assert.throws(
() => {
new TextDecoder(t.encoding, { fatal: true })
.decode(new Uint8Array(t.input));
}, {
code: 'ERR_ENCODING_INVALID_ENCODED_DATA',
- type: TypeError
+ name: 'TypeError'
}
);
});
diff --git a/test/parallel/test-whatwg-encoding-custom-textdecoder-invalid-arg.js b/test/parallel/test-whatwg-encoding-custom-textdecoder-invalid-arg.js
index a2b56ad957..5c8a9837f6 100644
--- a/test/parallel/test-whatwg-encoding-custom-textdecoder-invalid-arg.js
+++ b/test/parallel/test-whatwg-encoding-custom-textdecoder-invalid-arg.js
@@ -3,16 +3,17 @@
// This tests that ERR_INVALID_ARG_TYPE are thrown when
// invalid arguments are passed to TextDecoder.
-const common = require('../common');
+require('../common');
+const assert = require('assert');
{
const notArrayBufferViewExamples = [false, {}, 1, '', new Error()];
notArrayBufferViewExamples.forEach((invalidInputType) => {
- common.expectsError(() => {
+ assert.throws(() => {
new TextDecoder(undefined, null).decode(invalidInputType);
}, {
code: 'ERR_INVALID_ARG_TYPE',
- type: TypeError
+ name: 'TypeError'
});
});
}
diff --git a/test/parallel/test-whatwg-encoding-custom-textdecoder-utf16-surrogates.js b/test/parallel/test-whatwg-encoding-custom-textdecoder-utf16-surrogates.js
index bba10fbd22..f4d9ef8d42 100644
--- a/test/parallel/test-whatwg-encoding-custom-textdecoder-utf16-surrogates.js
+++ b/test/parallel/test-whatwg-encoding-custom-textdecoder-utf16-surrogates.js
@@ -8,6 +8,8 @@ const common = require('../common');
if (!common.hasIntl)
common.skip('missing Intl');
+const assert = require('assert');
+
const bad = [
{
encoding: 'utf-16le',
@@ -42,13 +44,13 @@ const bad = [
];
bad.forEach((t) => {
- common.expectsError(
+ assert.throws(
() => {
new TextDecoder(t.encoding, { fatal: true })
.decode(new Uint8Array(t.input));
}, {
code: 'ERR_ENCODING_INVALID_ENCODED_DATA',
- type: TypeError
+ name: 'TypeError'
}
);
});
diff --git a/test/parallel/test-whatwg-encoding-custom-textdecoder.js b/test/parallel/test-whatwg-encoding-custom-textdecoder.js
index c475d94dc7..1430a0daa8 100644
--- a/test/parallel/test-whatwg-encoding-custom-textdecoder.js
+++ b/test/parallel/test-whatwg-encoding-custom-textdecoder.js
@@ -55,13 +55,13 @@ assert(TextDecoder);
if (common.hasIntl) {
['unicode-1-1-utf-8', 'utf8', 'utf-8'].forEach((i) => {
const dec = new TextDecoder(i, { fatal: true });
- common.expectsError(() => dec.decode(buf.slice(0, 8)),
- {
- code: 'ERR_ENCODING_INVALID_ENCODED_DATA',
- type: TypeError,
- message: 'The encoded data was not valid ' +
+ assert.throws(() => dec.decode(buf.slice(0, 8)),
+ {
+ code: 'ERR_ENCODING_INVALID_ENCODED_DATA',
+ name: 'TypeError',
+ message: 'The encoded data was not valid ' +
'for encoding utf-8'
- });
+ });
});
['unicode-1-1-utf-8', 'utf8', 'utf-8'].forEach((i) => {
@@ -70,11 +70,11 @@ if (common.hasIntl) {
dec.decode(buf.slice(8));
});
} else {
- common.expectsError(
+ assert.throws(
() => new TextDecoder('utf-8', { fatal: true }),
{
code: 'ERR_NO_ICU',
- type: TypeError,
+ name: 'TypeError',
message: '"fatal" option is not supported on Node.js compiled without ICU'
});
}
@@ -159,7 +159,7 @@ if (common.hasIntl) {
const expectedError = {
code: 'ERR_INVALID_THIS',
- type: TypeError,
+ name: 'TypeError',
message: 'Value of "this" must be of type TextDecoder'
};
@@ -171,20 +171,20 @@ if (common.hasIntl) {
const invalidThisArgs = [{}, [], true, 1, '', new TextEncoder()];
invalidThisArgs.forEach((i) => {
- common.expectsError(() => inspectFn.call(i, Infinity, {}), expectedError);
- common.expectsError(() => decodeFn.call(i), expectedError);
- common.expectsError(() => encodingGetter.call(i), expectedError);
- common.expectsError(() => fatalGetter.call(i), expectedError);
- common.expectsError(() => ignoreBOMGetter.call(i), expectedError);
+ assert.throws(() => inspectFn.call(i, Infinity, {}), expectedError);
+ assert.throws(() => decodeFn.call(i), expectedError);
+ assert.throws(() => encodingGetter.call(i), expectedError);
+ assert.throws(() => fatalGetter.call(i), expectedError);
+ assert.throws(() => ignoreBOMGetter.call(i), expectedError);
});
}
{
- common.expectsError(
+ assert.throws(
() => new TextDecoder('utf-8', 1),
{
code: 'ERR_INVALID_ARG_TYPE',
- type: TypeError
+ name: 'TypeError'
}
);
}
diff --git a/test/parallel/test-whatwg-url-custom-domainto.js b/test/parallel/test-whatwg-url-custom-domainto.js
index 9677d84286..b7458d7a8e 100644
--- a/test/parallel/test-whatwg-url-custom-domainto.js
+++ b/test/parallel/test-whatwg-url-custom-domainto.js
@@ -17,8 +17,7 @@ const wptToASCIITests = require(
);
{
- const expectedError = common.expectsError(
- { code: 'ERR_MISSING_ARGS', type: TypeError }, 2);
+ const expectedError = { code: 'ERR_MISSING_ARGS', name: 'TypeError' };
assert.throws(() => domainToASCII(), expectedError);
assert.throws(() => domainToUnicode(), expectedError);
assert.strictEqual(domainToASCII(undefined), 'undefined');
diff --git a/test/parallel/test-whatwg-url-custom-href-side-effect.js b/test/parallel/test-whatwg-url-custom-href-side-effect.js
index f161f6bbe9..30967d9fea 100644
--- a/test/parallel/test-whatwg-url-custom-href-side-effect.js
+++ b/test/parallel/test-whatwg-url-custom-href-side-effect.js
@@ -1,15 +1,15 @@
'use strict';
// Tests below are not from WPT.
-const common = require('../common');
+require('../common');
const assert = require('assert');
const ref = new URL('http://example.com/path');
const url = new URL('http://example.com/path');
-common.expectsError(() => {
+assert.throws(() => {
url.href = '';
}, {
- type: TypeError
+ name: 'TypeError'
});
assert.deepStrictEqual(url, ref);
diff --git a/test/parallel/test-whatwg-url-custom-parsing.js b/test/parallel/test-whatwg-url-custom-parsing.js
index e83cc00536..2799a9caef 100644
--- a/test/parallel/test-whatwg-url-custom-parsing.js
+++ b/test/parallel/test-whatwg-url-custom-parsing.js
@@ -49,14 +49,13 @@ const failureTests = originalFailures
.concat(typeFailures)
.concat(aboutBlankFailures);
-const expectedError = common.expectsError(
- { code: 'ERR_INVALID_URL', type: TypeError }, failureTests.length);
+const expectedError = { code: 'ERR_INVALID_URL', name: 'TypeError' };
for (const test of failureTests) {
assert.throws(
() => new URL(test.input, test.base),
(error) => {
- expectedError(error);
+ assert.throws(() => { throw error; }, expectedError);
// The input could be processed, so we don't do strict matching here
let match;
diff --git a/test/parallel/test-whatwg-url-custom-searchparams-append.js b/test/parallel/test-whatwg-url-custom-searchparams-append.js
index e5d3f20358..cf93950ebd 100644
--- a/test/parallel/test-whatwg-url-custom-searchparams-append.js
+++ b/test/parallel/test-whatwg-url-custom-searchparams-append.js
@@ -2,24 +2,24 @@
// Tests below are not from WPT.
-const common = require('../common');
+require('../common');
const assert = require('assert');
const URLSearchParams = require('url').URLSearchParams;
{
const params = new URLSearchParams();
- common.expectsError(() => {
+ assert.throws(() => {
params.append.call(undefined);
}, {
code: 'ERR_INVALID_THIS',
- type: TypeError,
+ name: 'TypeError',
message: 'Value of "this" must be of type URLSearchParams'
});
- common.expectsError(() => {
+ assert.throws(() => {
params.append('a');
}, {
code: 'ERR_MISSING_ARGS',
- type: TypeError,
+ name: 'TypeError',
message: 'The "name" and "value" arguments must be specified'
});
diff --git a/test/parallel/test-whatwg-url-custom-searchparams-constructor.js b/test/parallel/test-whatwg-url-custom-searchparams-constructor.js
index fd7cc51127..ab06581417 100644
--- a/test/parallel/test-whatwg-url-custom-searchparams-constructor.js
+++ b/test/parallel/test-whatwg-url-custom-searchparams-constructor.js
@@ -2,7 +2,7 @@
// Tests below are not from WPT.
-const common = require('../common');
+require('../common');
const assert = require('assert');
const URLSearchParams = require('url').URLSearchParams;
@@ -15,16 +15,16 @@ function makeIterableFunc(array) {
}
{
- const iterableError = common.expectsError({
+ const iterableError = {
code: 'ERR_ARG_NOT_ITERABLE',
- type: TypeError,
+ name: 'TypeError',
message: 'Query pairs must be iterable'
- });
- const tupleError = common.expectsError({
+ };
+ const tupleError = {
code: 'ERR_INVALID_TUPLE',
- type: TypeError,
+ name: 'TypeError',
message: 'Each query pair must be an iterable [name, value] tuple'
- }, 6);
+ };
let params;
params = new URLSearchParams(undefined);
diff --git a/test/parallel/test-whatwg-url-custom-searchparams-delete.js b/test/parallel/test-whatwg-url-custom-searchparams-delete.js
index a22345cc6e..5c3088b036 100644
--- a/test/parallel/test-whatwg-url-custom-searchparams-delete.js
+++ b/test/parallel/test-whatwg-url-custom-searchparams-delete.js
@@ -2,24 +2,24 @@
// Tests below are not from WPT.
-const common = require('../common');
+require('../common');
const assert = require('assert');
const { URL, URLSearchParams } = require('url');
{
const params = new URLSearchParams();
- common.expectsError(() => {
+ assert.throws(() => {
params.delete.call(undefined);
}, {
code: 'ERR_INVALID_THIS',
- type: TypeError,
+ name: 'TypeError',
message: 'Value of "this" must be of type URLSearchParams'
});
- common.expectsError(() => {
+ assert.throws(() => {
params.delete();
}, {
code: 'ERR_MISSING_ARGS',
- type: TypeError,
+ name: 'TypeError',
message: 'The "name" argument must be specified'
});
diff --git a/test/parallel/test-whatwg-url-custom-searchparams-entries.js b/test/parallel/test-whatwg-url-custom-searchparams-entries.js
index fc30865458..b70717ff2b 100644
--- a/test/parallel/test-whatwg-url-custom-searchparams-entries.js
+++ b/test/parallel/test-whatwg-url-custom-searchparams-entries.js
@@ -1,6 +1,6 @@
'use strict';
-const common = require('../common');
+require('../common');
const assert = require('assert');
const URLSearchParams = require('url').URLSearchParams;
@@ -26,17 +26,17 @@ assert.deepStrictEqual(entries.next(), {
done: true
});
-common.expectsError(() => {
+assert.throws(() => {
entries.next.call(undefined);
}, {
code: 'ERR_INVALID_THIS',
- type: TypeError,
+ name: 'TypeError',
message: 'Value of "this" must be of type URLSearchParamsIterator'
});
-common.expectsError(() => {
+assert.throws(() => {
params.entries.call(undefined);
}, {
code: 'ERR_INVALID_THIS',
- type: TypeError,
+ name: 'TypeError',
message: 'Value of "this" must be of type URLSearchParams'
});
diff --git a/test/parallel/test-whatwg-url-custom-searchparams-foreach.js b/test/parallel/test-whatwg-url-custom-searchparams-foreach.js
index 3e729d2bcd..b796cff9bc 100644
--- a/test/parallel/test-whatwg-url-custom-searchparams-foreach.js
+++ b/test/parallel/test-whatwg-url-custom-searchparams-foreach.js
@@ -2,16 +2,17 @@
// Tests below are not from WPT.
-const common = require('../common');
+require('../common');
+const assert = require('assert');
const { URLSearchParams } = require('url');
{
const params = new URLSearchParams();
- common.expectsError(() => {
+ assert.throws(() => {
params.forEach.call(undefined);
}, {
code: 'ERR_INVALID_THIS',
- type: TypeError,
+ name: 'TypeError',
message: 'Value of "this" must be of type URLSearchParams'
});
}
diff --git a/test/parallel/test-whatwg-url-custom-searchparams-get.js b/test/parallel/test-whatwg-url-custom-searchparams-get.js
index b99a5fae97..1088fcc43d 100644
--- a/test/parallel/test-whatwg-url-custom-searchparams-get.js
+++ b/test/parallel/test-whatwg-url-custom-searchparams-get.js
@@ -2,24 +2,24 @@
// Tests below are not from WPT.
-const common = require('../common');
+require('../common');
const assert = require('assert');
const URLSearchParams = require('url').URLSearchParams;
{
const params = new URLSearchParams();
- common.expectsError(() => {
+ assert.throws(() => {
params.get.call(undefined);
}, {
code: 'ERR_INVALID_THIS',
- type: TypeError,
+ name: 'TypeError',
message: 'Value of "this" must be of type URLSearchParams'
});
- common.expectsError(() => {
+ assert.throws(() => {
params.get();
}, {
code: 'ERR_MISSING_ARGS',
- type: TypeError,
+ name: 'TypeError',
message: 'The "name" argument must be specified'
});
diff --git a/test/parallel/test-whatwg-url-custom-searchparams-getall.js b/test/parallel/test-whatwg-url-custom-searchparams-getall.js
index 7f3c7b7610..8d229a2597 100644
--- a/test/parallel/test-whatwg-url-custom-searchparams-getall.js
+++ b/test/parallel/test-whatwg-url-custom-searchparams-getall.js
@@ -2,24 +2,24 @@
// Tests below are not from WPT.
-const common = require('../common');
+require('../common');
const assert = require('assert');
const URLSearchParams = require('url').URLSearchParams;
{
const params = new URLSearchParams();
- common.expectsError(() => {
+ assert.throws(() => {
params.getAll.call(undefined);
}, {
code: 'ERR_INVALID_THIS',
- type: TypeError,
+ name: 'TypeError',
message: 'Value of "this" must be of type URLSearchParams'
});
- common.expectsError(() => {
+ assert.throws(() => {
params.getAll();
}, {
code: 'ERR_MISSING_ARGS',
- type: TypeError,
+ name: 'TypeError',
message: 'The "name" argument must be specified'
});
diff --git a/test/parallel/test-whatwg-url-custom-searchparams-has.js b/test/parallel/test-whatwg-url-custom-searchparams-has.js
index 2697f199bc..4a76dda6d3 100644
--- a/test/parallel/test-whatwg-url-custom-searchparams-has.js
+++ b/test/parallel/test-whatwg-url-custom-searchparams-has.js
@@ -2,24 +2,24 @@
// Tests below are not from WPT.
-const common = require('../common');
+require('../common');
const assert = require('assert');
const URLSearchParams = require('url').URLSearchParams;
{
const params = new URLSearchParams();
- common.expectsError(() => {
+ assert.throws(() => {
params.has.call(undefined);
}, {
code: 'ERR_INVALID_THIS',
- type: TypeError,
+ name: 'TypeError',
message: 'Value of "this" must be of type URLSearchParams'
});
- common.expectsError(() => {
+ assert.throws(() => {
params.has();
}, {
code: 'ERR_MISSING_ARGS',
- type: TypeError,
+ name: 'TypeError',
message: 'The "name" argument must be specified'
});
diff --git a/test/parallel/test-whatwg-url-custom-searchparams-keys.js b/test/parallel/test-whatwg-url-custom-searchparams-keys.js
index 00800cc79c..5a222c7428 100644
--- a/test/parallel/test-whatwg-url-custom-searchparams-keys.js
+++ b/test/parallel/test-whatwg-url-custom-searchparams-keys.js
@@ -2,7 +2,7 @@
// Tests below are not from WPT.
-const common = require('../common');
+require('../common');
const assert = require('assert');
const URLSearchParams = require('url').URLSearchParams;
@@ -28,17 +28,17 @@ assert.deepStrictEqual(keys.next(), {
done: true
});
-common.expectsError(() => {
+assert.throws(() => {
keys.next.call(undefined);
}, {
code: 'ERR_INVALID_THIS',
- type: TypeError,
+ name: 'TypeError',
message: 'Value of "this" must be of type URLSearchParamsIterator'
});
-common.expectsError(() => {
+assert.throws(() => {
params.keys.call(undefined);
}, {
code: 'ERR_INVALID_THIS',
- type: TypeError,
+ name: 'TypeError',
message: 'Value of "this" must be of type URLSearchParams'
});
diff --git a/test/parallel/test-whatwg-url-custom-searchparams-set.js b/test/parallel/test-whatwg-url-custom-searchparams-set.js
index ccd3353ecd..39462bf488 100644
--- a/test/parallel/test-whatwg-url-custom-searchparams-set.js
+++ b/test/parallel/test-whatwg-url-custom-searchparams-set.js
@@ -2,24 +2,24 @@
// Tests below are not from WPT.
-const common = require('../common');
+require('../common');
const assert = require('assert');
const URLSearchParams = require('url').URLSearchParams;
{
const params = new URLSearchParams();
- common.expectsError(() => {
+ assert.throws(() => {
params.set.call(undefined);
}, {
code: 'ERR_INVALID_THIS',
- type: TypeError,
+ name: 'TypeError',
message: 'Value of "this" must be of type URLSearchParams'
});
- common.expectsError(() => {
+ assert.throws(() => {
params.set('a');
}, {
code: 'ERR_MISSING_ARGS',
- type: TypeError,
+ name: 'TypeError',
message: 'The "name" and "value" arguments must be specified'
});
diff --git a/test/parallel/test-whatwg-url-custom-searchparams-stringifier.js b/test/parallel/test-whatwg-url-custom-searchparams-stringifier.js
index d2929ae557..1fe936f5e2 100644
--- a/test/parallel/test-whatwg-url-custom-searchparams-stringifier.js
+++ b/test/parallel/test-whatwg-url-custom-searchparams-stringifier.js
@@ -2,16 +2,17 @@
// Tests below are not from WPT.
-const common = require('../common');
+require('../common');
+const assert = require('assert');
const URLSearchParams = require('url').URLSearchParams;
{
const params = new URLSearchParams();
- common.expectsError(() => {
+ assert.throws(() => {
params.toString.call(undefined);
}, {
code: 'ERR_INVALID_THIS',
- type: TypeError,
+ name: 'TypeError',
message: 'Value of "this" must be of type URLSearchParams'
});
}
diff --git a/test/parallel/test-whatwg-url-custom-searchparams-values.js b/test/parallel/test-whatwg-url-custom-searchparams-values.js
index e10a9dc04f..eedad691fa 100644
--- a/test/parallel/test-whatwg-url-custom-searchparams-values.js
+++ b/test/parallel/test-whatwg-url-custom-searchparams-values.js
@@ -2,7 +2,7 @@
// Tests below are not from WPT.
-const common = require('../common');
+require('../common');
const assert = require('assert');
const URLSearchParams = require('url').URLSearchParams;
@@ -28,17 +28,17 @@ assert.deepStrictEqual(values.next(), {
done: true
});
-common.expectsError(() => {
+assert.throws(() => {
values.next.call(undefined);
}, {
code: 'ERR_INVALID_THIS',
- type: TypeError,
+ name: 'TypeError',
message: 'Value of "this" must be of type URLSearchParamsIterator'
});
-common.expectsError(() => {
+assert.throws(() => {
params.values.call(undefined);
}, {
code: 'ERR_INVALID_THIS',
- type: TypeError,
+ name: 'TypeError',
message: 'Value of "this" must be of type URLSearchParams'
});
diff --git a/test/parallel/test-whatwg-url-custom-searchparams.js b/test/parallel/test-whatwg-url-custom-searchparams.js
index f88c3b4a83..39c8d87b6a 100644
--- a/test/parallel/test-whatwg-url-custom-searchparams.js
+++ b/test/parallel/test-whatwg-url-custom-searchparams.js
@@ -2,7 +2,7 @@
// Tests below are not from WPT.
-const common = require('../common');
+require('../common');
const assert = require('assert');
const { URL, URLSearchParams } = require('url');
const fixtures = require('../common/fixtures');
@@ -74,10 +74,10 @@ sp.forEach(function() {
}, m);
{
- const callbackErr = common.expectsError({
+ const callbackErr = {
code: 'ERR_INVALID_CALLBACK',
- type: TypeError
- }, 2);
+ name: 'TypeError'
+ };
assert.throws(() => sp.forEach(), callbackErr);
assert.throws(() => sp.forEach(1), callbackErr);
}
diff --git a/test/parallel/test-worker-execargv-invalid.js b/test/parallel/test-worker-execargv-invalid.js
index e2deaf5464..bbad565c4f 100644
--- a/test/parallel/test-worker-execargv-invalid.js
+++ b/test/parallel/test-worker-execargv-invalid.js
@@ -1,14 +1,14 @@
'use strict';
-const common = require('../common');
+require('../common');
const assert = require('assert');
const { Worker } = require('worker_threads');
{
- const expectedErr = common.expectsError({
+ const expectedErr = {
code: 'ERR_INVALID_ARG_TYPE',
- type: TypeError
- }, 2);
+ name: 'TypeError'
+ };
assert.throws(() => {
new Worker(__filename, { execArgv: 'hello' });
@@ -19,10 +19,10 @@ const { Worker } = require('worker_threads');
}
{
- const expectedErr = common.expectsError({
+ const expectedErr = {
code: 'ERR_WORKER_INVALID_EXEC_ARGV',
- type: Error
- }, 3);
+ name: 'Error'
+ };
assert.throws(() => {
new Worker(__filename, { execArgv: ['--foo'] });
}, expectedErr);
diff --git a/test/parallel/test-worker-process-env.js b/test/parallel/test-worker-process-env.js
index 1316afd783..9680d68514 100644
--- a/test/parallel/test-worker-process-env.js
+++ b/test/parallel/test-worker-process-env.js
@@ -23,10 +23,10 @@ if (!workerData && process.argv[2] !== 'child') {
env: { 'MANUALLY_SET': true }
});
- common.expectsError(() => {
+ assert.throws(() => {
new Worker(__filename, { env: 42 });
}, {
- type: TypeError,
+ name: 'TypeError',
code: 'ERR_INVALID_ARG_TYPE',
message: 'The "options.env" property must be of type object or ' +
'one of undefined, null, or worker_threads.SHARE_ENV. Received type ' +
diff --git a/test/parallel/test-worker-stack-overflow.js b/test/parallel/test-worker-stack-overflow.js
index 99a34b5369..32351b7a4a 100644
--- a/test/parallel/test-worker-stack-overflow.js
+++ b/test/parallel/test-worker-stack-overflow.js
@@ -1,11 +1,10 @@
'use strict';
const common = require('../common');
-const assert = require('assert');
const { Worker } = require('worker_threads');
const worker = new Worker('function f() { f(); } f();', { eval: true });
-worker.on('error', common.mustCall((err) => {
- assert.strictEqual(err.constructor, RangeError);
- assert.strictEqual(err.message, 'Maximum call stack size exceeded');
+worker.on('error', common.expectsError({
+ constructor: RangeError,
+ message: 'Maximum call stack size exceeded'
}));
diff --git a/test/parallel/test-worker-type-check.js b/test/parallel/test-worker-type-check.js
index 2d18013039..2a67bfec40 100644
--- a/test/parallel/test-worker-type-check.js
+++ b/test/parallel/test-worker-type-check.js
@@ -1,6 +1,7 @@
'use strict';
const common = require('../common');
+const assert = require('assert');
const { Worker } = require('worker_threads');
{
@@ -14,11 +15,11 @@ const { Worker } = require('worker_threads');
[],
() => {}
].forEach((val) => {
- common.expectsError(
+ assert.throws(
() => new Worker(val),
{
code: 'ERR_INVALID_ARG_TYPE',
- type: TypeError,
+ name: 'TypeError',
message: 'The "filename" argument must be of type string.' +
common.invalidArgTypeHelper(val)
}
diff --git a/test/parallel/test-worker-unsupported-path.js b/test/parallel/test-worker-unsupported-path.js
index 0c86f2ead0..21ff406719 100644
--- a/test/parallel/test-worker-unsupported-path.js
+++ b/test/parallel/test-worker-unsupported-path.js
@@ -1,25 +1,25 @@
'use strict';
-const common = require('../common');
+require('../common');
const path = require('path');
const assert = require('assert');
const { Worker } = require('worker_threads');
{
- const expectedErr = common.expectsError({
+ const expectedErr = {
code: 'ERR_WORKER_UNSUPPORTED_EXTENSION',
- type: TypeError
- }, 3);
+ name: 'TypeError'
+ };
assert.throws(() => { new Worker('/b'); }, expectedErr);
assert.throws(() => { new Worker('/c.wasm'); }, expectedErr);
assert.throws(() => { new Worker('/d.txt'); }, expectedErr);
}
{
- const expectedErr = common.expectsError({
+ const expectedErr = {
code: 'ERR_WORKER_PATH',
- type: TypeError
- }, 4);
+ name: 'TypeError'
+ };
const existingRelPathNoDot = path.relative('.', __filename);
assert.throws(() => { new Worker(existingRelPathNoDot); }, expectedErr);
assert.throws(() => { new Worker('relative_no_dot'); }, expectedErr);
diff --git a/test/parallel/test-wrap-js-stream-exceptions.js b/test/parallel/test-wrap-js-stream-exceptions.js
index 2cc592a760..b90e46002c 100644
--- a/test/parallel/test-wrap-js-stream-exceptions.js
+++ b/test/parallel/test-wrap-js-stream-exceptions.js
@@ -18,6 +18,6 @@ const socket = new JSStreamWrap(new Duplex({
socket.end('foo');
socket.on('error', common.expectsError({
- type: Error,
+ name: 'Error',
message: 'write EPROTO'
}));
diff --git a/test/parallel/test-zlib-brotli.js b/test/parallel/test-zlib-brotli.js
index 2dc60aff40..772b655177 100644
--- a/test/parallel/test-zlib-brotli.js
+++ b/test/parallel/test-zlib-brotli.js
@@ -1,5 +1,5 @@
'use strict';
-const common = require('../common');
+require('../common');
const fixtures = require('../common/fixtures');
const assert = require('assert');
const zlib = require('zlib');
@@ -32,7 +32,7 @@ const sampleBuffer = fixtures.readSync('/pss-vectors.json');
{
// Test that setting out-of-bounds option values or keys fails.
- common.expectsError(() => {
+ assert.throws(() => {
zlib.createBrotliCompress({
params: {
10000: 0
@@ -40,12 +40,12 @@ const sampleBuffer = fixtures.readSync('/pss-vectors.json');
});
}, {
code: 'ERR_BROTLI_INVALID_PARAM',
- type: RangeError,
+ name: 'RangeError',
message: '10000 is not a valid Brotli parameter'
});
// Test that accidentally using duplicate keys fails.
- common.expectsError(() => {
+ assert.throws(() => {
zlib.createBrotliCompress({
params: {
'0': 0,
@@ -54,11 +54,11 @@ const sampleBuffer = fixtures.readSync('/pss-vectors.json');
});
}, {
code: 'ERR_BROTLI_INVALID_PARAM',
- type: RangeError,
+ name: 'RangeError',
message: '00 is not a valid Brotli parameter'
});
- common.expectsError(() => {
+ assert.throws(() => {
zlib.createBrotliCompress({
params: {
// This is a boolean flag
@@ -67,7 +67,7 @@ const sampleBuffer = fixtures.readSync('/pss-vectors.json');
});
}, {
code: 'ERR_ZLIB_INITIALIZATION_FAILED',
- type: Error,
+ name: 'Error',
message: 'Initialization failed'
});
}
diff --git a/test/parallel/test-zlib-convenience-methods.js b/test/parallel/test-zlib-convenience-methods.js
index 65c842b66a..4757eef42c 100644
--- a/test/parallel/test-zlib-convenience-methods.js
+++ b/test/parallel/test-zlib-convenience-methods.js
@@ -122,11 +122,11 @@ for (const [type, expect] of [
}
}
-common.expectsError(
+assert.throws(
() => zlib.gzip('abc'),
{
code: 'ERR_INVALID_ARG_TYPE',
- type: TypeError,
+ name: 'TypeError',
message: 'The "callback" argument must be of type function. ' +
'Received undefined'
}
diff --git a/test/parallel/test-zlib-deflate-constructors.js b/test/parallel/test-zlib-deflate-constructors.js
index 3cb4eca5ea..492048d3d0 100644
--- a/test/parallel/test-zlib-deflate-constructors.js
+++ b/test/parallel/test-zlib-deflate-constructors.js
@@ -1,6 +1,6 @@
'use strict';
-const common = require('../common');
+require('../common');
const zlib = require('zlib');
const assert = require('assert');
@@ -13,31 +13,31 @@ assert.ok(zlib.DeflateRaw() instanceof zlib.DeflateRaw);
assert.ok(new zlib.DeflateRaw() instanceof zlib.DeflateRaw);
// Throws if `options.chunkSize` is invalid
-common.expectsError(
+assert.throws(
() => new zlib.Deflate({ chunkSize: 'test' }),
{
code: 'ERR_INVALID_ARG_TYPE',
- type: TypeError,
+ name: 'TypeError',
message: 'The "options.chunkSize" property must be of type number. ' +
"Received type string ('test')"
}
);
-common.expectsError(
+assert.throws(
() => new zlib.Deflate({ chunkSize: -Infinity }),
{
code: 'ERR_OUT_OF_RANGE',
- type: RangeError,
+ name: 'RangeError',
message: 'The value of "options.chunkSize" is out of range. It must ' +
'be a finite number. Received -Infinity'
}
);
-common.expectsError(
+assert.throws(
() => new zlib.Deflate({ chunkSize: 0 }),
{
code: 'ERR_OUT_OF_RANGE',
- type: RangeError,
+ name: 'RangeError',
message: 'The value of "options.chunkSize" is out of range. It must ' +
'be >= 64. Received 0'
}
@@ -47,164 +47,164 @@ common.expectsError(
assert.strictEqual(zlib.constants.Z_MAX_CHUNK, Infinity);
// Throws if `options.windowBits` is invalid
-common.expectsError(
+assert.throws(
() => new zlib.Deflate({ windowBits: 'test' }),
{
code: 'ERR_INVALID_ARG_TYPE',
- type: TypeError,
+ name: 'TypeError',
message: 'The "options.windowBits" property must be of type number. ' +
"Received type string ('test')"
}
);
-common.expectsError(
+assert.throws(
() => new zlib.Deflate({ windowBits: -Infinity }),
{
code: 'ERR_OUT_OF_RANGE',
- type: RangeError,
+ name: 'RangeError',
message: 'The value of "options.windowBits" is out of range. It must ' +
'be a finite number. Received -Infinity'
}
);
-common.expectsError(
+assert.throws(
() => new zlib.Deflate({ windowBits: Infinity }),
{
code: 'ERR_OUT_OF_RANGE',
- type: RangeError,
+ name: 'RangeError',
message: 'The value of "options.windowBits" is out of range. It must ' +
'be a finite number. Received Infinity'
}
);
-common.expectsError(
+assert.throws(
() => new zlib.Deflate({ windowBits: 0 }),
{
code: 'ERR_OUT_OF_RANGE',
- type: RangeError,
+ name: 'RangeError',
message: 'The value of "options.windowBits" is out of range. It must ' +
'be >= 8 and <= 15. Received 0'
}
);
// Throws if `options.level` is invalid
-common.expectsError(
+assert.throws(
() => new zlib.Deflate({ level: 'test' }),
{
code: 'ERR_INVALID_ARG_TYPE',
- type: TypeError,
+ name: 'TypeError',
message: 'The "options.level" property must be of type number. ' +
"Received type string ('test')"
}
);
-common.expectsError(
+assert.throws(
() => new zlib.Deflate({ level: -Infinity }),
{
code: 'ERR_OUT_OF_RANGE',
- type: RangeError,
+ name: 'RangeError',
message: 'The value of "options.level" is out of range. It must ' +
'be a finite number. Received -Infinity'
}
);
-common.expectsError(
+assert.throws(
() => new zlib.Deflate({ level: Infinity }),
{
code: 'ERR_OUT_OF_RANGE',
- type: RangeError,
+ name: 'RangeError',
message: 'The value of "options.level" is out of range. It must ' +
'be a finite number. Received Infinity'
}
);
-common.expectsError(
+assert.throws(
() => new zlib.Deflate({ level: -2 }),
{
code: 'ERR_OUT_OF_RANGE',
- type: RangeError,
+ name: 'RangeError',
message: 'The value of "options.level" is out of range. It must ' +
'be >= -1 and <= 9. Received -2'
}
);
// Throws if `level` invalid in `Deflate.prototype.params()`
-common.expectsError(
+assert.throws(
() => new zlib.Deflate().params('test'),
{
code: 'ERR_INVALID_ARG_TYPE',
- type: TypeError,
+ name: 'TypeError',
message: 'The "level" argument must be of type number. ' +
"Received type string ('test')"
}
);
-common.expectsError(
+assert.throws(
() => new zlib.Deflate().params(-Infinity),
{
code: 'ERR_OUT_OF_RANGE',
- type: RangeError,
+ name: 'RangeError',
message: 'The value of "level" is out of range. It must ' +
'be a finite number. Received -Infinity'
}
);
-common.expectsError(
+assert.throws(
() => new zlib.Deflate().params(Infinity),
{
code: 'ERR_OUT_OF_RANGE',
- type: RangeError,
+ name: 'RangeError',
message: 'The value of "level" is out of range. It must ' +
'be a finite number. Received Infinity'
}
);
-common.expectsError(
+assert.throws(
() => new zlib.Deflate().params(-2),
{
code: 'ERR_OUT_OF_RANGE',
- type: RangeError,
+ name: 'RangeError',
message: 'The value of "level" is out of range. It must ' +
'be >= -1 and <= 9. Received -2'
}
);
// Throws if options.memLevel is invalid
-common.expectsError(
+assert.throws(
() => new zlib.Deflate({ memLevel: 'test' }),
{
code: 'ERR_INVALID_ARG_TYPE',
- type: TypeError,
+ name: 'TypeError',
message: 'The "options.memLevel" property must be of type number. ' +
"Received type string ('test')"
}
);
-common.expectsError(
+assert.throws(
() => new zlib.Deflate({ memLevel: -Infinity }),
{
code: 'ERR_OUT_OF_RANGE',
- type: RangeError,
+ name: 'RangeError',
message: 'The value of "options.memLevel" is out of range. It must ' +
'be a finite number. Received -Infinity'
}
);
-common.expectsError(
+assert.throws(
() => new zlib.Deflate({ memLevel: Infinity }),
{
code: 'ERR_OUT_OF_RANGE',
- type: RangeError,
+ name: 'RangeError',
message: 'The value of "options.memLevel" is out of range. It must ' +
'be a finite number. Received Infinity'
}
);
-common.expectsError(
+assert.throws(
() => new zlib.Deflate({ memLevel: -2 }),
{
code: 'ERR_OUT_OF_RANGE',
- type: RangeError,
+ name: 'RangeError',
message: 'The value of "options.memLevel" is out of range. It must ' +
'be >= 1 and <= 9. Received -2'
}
@@ -218,93 +218,93 @@ new zlib.Deflate({ strategy: zlib.constants.Z_FIXED });
new zlib.Deflate({ strategy: zlib.constants.Z_DEFAULT_STRATEGY });
// Throws if options.strategy is invalid
-common.expectsError(
+assert.throws(
() => new zlib.Deflate({ strategy: 'test' }),
{
code: 'ERR_INVALID_ARG_TYPE',
- type: TypeError,
+ name: 'TypeError',
message: 'The "options.strategy" property must be of type number. ' +
"Received type string ('test')"
}
);
-common.expectsError(
+assert.throws(
() => new zlib.Deflate({ strategy: -Infinity }),
{
code: 'ERR_OUT_OF_RANGE',
- type: RangeError,
+ name: 'RangeError',
message: 'The value of "options.strategy" is out of range. It must ' +
'be a finite number. Received -Infinity'
}
);
-common.expectsError(
+assert.throws(
() => new zlib.Deflate({ strategy: Infinity }),
{
code: 'ERR_OUT_OF_RANGE',
- type: RangeError,
+ name: 'RangeError',
message: 'The value of "options.strategy" is out of range. It must ' +
'be a finite number. Received Infinity'
}
);
-common.expectsError(
+assert.throws(
() => new zlib.Deflate({ strategy: -2 }),
{
code: 'ERR_OUT_OF_RANGE',
- type: RangeError,
+ name: 'RangeError',
message: 'The value of "options.strategy" is out of range. It must ' +
'be >= 0 and <= 4. Received -2'
}
);
// Throws TypeError if `strategy` is invalid in `Deflate.prototype.params()`
-common.expectsError(
+assert.throws(
() => new zlib.Deflate().params(0, 'test'),
{
code: 'ERR_INVALID_ARG_TYPE',
- type: TypeError,
+ name: 'TypeError',
message: 'The "strategy" argument must be of type number. ' +
"Received type string ('test')"
}
);
-common.expectsError(
+assert.throws(
() => new zlib.Deflate().params(0, -Infinity),
{
code: 'ERR_OUT_OF_RANGE',
- type: RangeError,
+ name: 'RangeError',
message: 'The value of "strategy" is out of range. It must ' +
'be a finite number. Received -Infinity'
}
);
-common.expectsError(
+assert.throws(
() => new zlib.Deflate().params(0, Infinity),
{
code: 'ERR_OUT_OF_RANGE',
- type: RangeError,
+ name: 'RangeError',
message: 'The value of "strategy" is out of range. It must ' +
'be a finite number. Received Infinity'
}
);
-common.expectsError(
+assert.throws(
() => new zlib.Deflate().params(0, -2),
{
code: 'ERR_OUT_OF_RANGE',
- type: RangeError,
+ name: 'RangeError',
message: 'The value of "strategy" is out of range. It must ' +
'be >= 0 and <= 4. Received -2'
}
);
// Throws if opts.dictionary is not a Buffer
-common.expectsError(
+assert.throws(
() => new zlib.Deflate({ dictionary: 'not a buffer' }),
{
code: 'ERR_INVALID_ARG_TYPE',
- type: TypeError,
+ name: 'TypeError',
message: 'The "options.dictionary" property must be an instance of Buffer' +
', TypedArray, DataView, or ArrayBuffer. Received type string ' +
"('not a buffer')"
diff --git a/test/parallel/test-zlib-failed-init.js b/test/parallel/test-zlib-failed-init.js
index 4834c82b7d..1f99a378fc 100644
--- a/test/parallel/test-zlib-failed-init.js
+++ b/test/parallel/test-zlib-failed-init.js
@@ -1,35 +1,35 @@
'use strict';
-const common = require('../common');
+require('../common');
const assert = require('assert');
const zlib = require('zlib');
-common.expectsError(
+assert.throws(
() => zlib.createGzip({ chunkSize: 0 }),
{
code: 'ERR_OUT_OF_RANGE',
- type: RangeError,
+ name: 'RangeError',
message: 'The value of "options.chunkSize" is out of range. It must ' +
'be >= 64. Received 0'
}
);
-common.expectsError(
+assert.throws(
() => zlib.createGzip({ windowBits: 0 }),
{
code: 'ERR_OUT_OF_RANGE',
- type: RangeError,
+ name: 'RangeError',
message: 'The value of "options.windowBits" is out of range. It must ' +
'be >= 8 and <= 15. Received 0'
}
);
-common.expectsError(
+assert.throws(
() => zlib.createGzip({ memLevel: 0 }),
{
code: 'ERR_OUT_OF_RANGE',
- type: RangeError,
+ name: 'RangeError',
message: 'The value of "options.memLevel" is out of range. It must ' +
'be >= 1 and <= 9. Received 0'
}
diff --git a/test/parallel/test-zlib-flush-flags.js b/test/parallel/test-zlib-flush-flags.js
index 64390a3137..3d8e609adb 100644
--- a/test/parallel/test-zlib-flush-flags.js
+++ b/test/parallel/test-zlib-flush-flags.js
@@ -1,24 +1,25 @@
'use strict';
-const common = require('../common');
+require('../common');
+const assert = require('assert');
const zlib = require('zlib');
zlib.createGzip({ flush: zlib.constants.Z_SYNC_FLUSH });
-common.expectsError(
+assert.throws(
() => zlib.createGzip({ flush: 'foobar' }),
{
code: 'ERR_INVALID_ARG_TYPE',
- type: TypeError,
+ name: 'TypeError',
message: 'The "options.flush" property must be of type number. ' +
"Received type string ('foobar')"
}
);
-common.expectsError(
+assert.throws(
() => zlib.createGzip({ flush: 10000 }),
{
code: 'ERR_OUT_OF_RANGE',
- type: RangeError,
+ name: 'RangeError',
message: 'The value of "options.flush" is out of range. It must ' +
'be >= 0 and <= 5. Received 10000'
}
@@ -26,21 +27,21 @@ common.expectsError(
zlib.createGzip({ finishFlush: zlib.constants.Z_SYNC_FLUSH });
-common.expectsError(
+assert.throws(
() => zlib.createGzip({ finishFlush: 'foobar' }),
{
code: 'ERR_INVALID_ARG_TYPE',
- type: TypeError,
+ name: 'TypeError',
message: 'The "options.finishFlush" property must be of type number. ' +
"Received type string ('foobar')"
}
);
-common.expectsError(
+assert.throws(
() => zlib.createGzip({ finishFlush: 10000 }),
{
code: 'ERR_OUT_OF_RANGE',
- type: RangeError,
+ name: 'RangeError',
message: 'The value of "options.finishFlush" is out of range. It must ' +
'be >= 0 and <= 5. Received 10000'
}
diff --git a/test/parallel/test-zlib-from-gzip-with-trailing-garbage.js b/test/parallel/test-zlib-from-gzip-with-trailing-garbage.js
index 7db3a8a27a..06fc2258a0 100644
--- a/test/parallel/test-zlib-from-gzip-with-trailing-garbage.js
+++ b/test/parallel/test-zlib-from-gzip-with-trailing-garbage.js
@@ -40,7 +40,7 @@ assert.throws(
zlib.gunzip(data, common.mustCall((err, result) => {
common.expectsError({
code: 'Z_DATA_ERROR',
- type: Error,
+ name: 'Error',
message: 'unknown compression method'
})(err);
assert.strictEqual(result, undefined);
diff --git a/test/parallel/test-zlib-not-string-or-buffer.js b/test/parallel/test-zlib-not-string-or-buffer.js
index 6a3b2b772f..b7b9a465cb 100644
--- a/test/parallel/test-zlib-not-string-or-buffer.js
+++ b/test/parallel/test-zlib-not-string-or-buffer.js
@@ -4,6 +4,7 @@
// or buffer.
const common = require('../common');
+const assert = require('assert');
const zlib = require('zlib');
[
@@ -16,11 +17,11 @@ const zlib = require('zlib');
[1, 2, 3],
{ foo: 'bar' }
].forEach((input) => {
- common.expectsError(
+ assert.throws(
() => zlib.deflateSync(input),
{
code: 'ERR_INVALID_ARG_TYPE',
- type: TypeError,
+ name: 'TypeError',
message: 'The "buffer" argument must be of type string or an instance ' +
'of Buffer, TypedArray, DataView, or ArrayBuffer.' +
common.invalidArgTypeHelper(input)
diff --git a/test/parallel/test-zlib-write-after-close.js b/test/parallel/test-zlib-write-after-close.js
index 160971b16b..06a7d3f191 100644
--- a/test/parallel/test-zlib-write-after-close.js
+++ b/test/parallel/test-zlib-write-after-close.js
@@ -21,16 +21,17 @@
'use strict';
const common = require('../common');
+const assert = require('assert');
const zlib = require('zlib');
zlib.gzip('hello', common.mustCall(function(err, out) {
const unzip = zlib.createGunzip();
unzip.close(common.mustCall());
- common.expectsError(
+ assert.throws(
() => unzip.write(out),
{
code: 'ERR_STREAM_DESTROYED',
- type: Error,
+ name: 'Error',
message: 'Cannot call write after a stream was destroyed'
}
);
diff --git a/test/parallel/test-zlib-zero-windowBits.js b/test/parallel/test-zlib-zero-windowBits.js
index a62e6148e3..730690a07c 100644
--- a/test/parallel/test-zlib-zero-windowBits.js
+++ b/test/parallel/test-zlib-zero-windowBits.js
@@ -1,6 +1,6 @@
'use strict';
-const common = require('../common');
+require('../common');
const assert = require('assert');
const zlib = require('zlib');
@@ -24,9 +24,9 @@ const zlib = require('zlib');
}
{
- common.expectsError(() => zlib.createGzip({ windowBits: 0 }), {
+ assert.throws(() => zlib.createGzip({ windowBits: 0 }), {
code: 'ERR_OUT_OF_RANGE',
- type: RangeError,
+ name: 'RangeError',
message: 'The value of "options.windowBits" is out of range. ' +
'It must be >= 8 and <= 15. Received 0'
});
diff --git a/test/pummel/test-fs-readfile-tostring-fail.js b/test/pummel/test-fs-readfile-tostring-fail.js
index a068b3af3b..1a1e7d6217 100644
--- a/test/pummel/test-fs-readfile-tostring-fail.js
+++ b/test/pummel/test-fs-readfile-tostring-fail.js
@@ -40,7 +40,7 @@ stream.on('finish', common.mustCall(function() {
message: 'Cannot create a string longer than ' +
`0x${stringLengthHex} characters`,
code: 'ERR_STRING_TOO_LONG',
- type: Error
+ name: 'Error'
})(err);
}
assert.strictEqual(buf, undefined);
diff --git a/test/report/test-report-config.js b/test/report/test-report-config.js
index b8cfd02992..4f6fdf2a80 100644
--- a/test/report/test-report-config.js
+++ b/test/report/test-report-config.js
@@ -12,7 +12,7 @@ common.expectWarning('ExperimentalWarning',
assert.strictEqual(process.report.directory, '');
process.report.directory = __dirname;
assert.strictEqual(process.report.directory, __dirname);
-common.expectsError(() => {
+assert.throws(() => {
process.report.directory = {};
}, { code: 'ERR_INVALID_ARG_TYPE' });
assert.strictEqual(process.report.directory, __dirname);
@@ -21,7 +21,7 @@ assert.strictEqual(process.report.directory, __dirname);
assert.strictEqual(process.report.filename, '');
process.report.filename = 'test-report.json';
assert.strictEqual(process.report.filename, 'test-report.json');
-common.expectsError(() => {
+assert.throws(() => {
process.report.filename = {};
}, { code: 'ERR_INVALID_ARG_TYPE' });
assert.strictEqual(process.report.filename, 'test-report.json');
@@ -32,7 +32,7 @@ process.report.reportOnFatalError = false;
assert.strictEqual(process.report.reportOnFatalError, false);
process.report.reportOnFatalError = true;
assert.strictEqual(process.report.reportOnFatalError, true);
-common.expectsError(() => {
+assert.throws(() => {
process.report.reportOnFatalError = {};
}, { code: 'ERR_INVALID_ARG_TYPE' });
assert.strictEqual(process.report.reportOnFatalError, true);
@@ -44,7 +44,7 @@ process.report.reportOnUncaughtException = false;
assert.strictEqual(process.report.reportOnUncaughtException, false);
process.report.reportOnUncaughtException = true;
assert.strictEqual(process.report.reportOnUncaughtException, true);
-common.expectsError(() => {
+assert.throws(() => {
process.report.reportOnUncaughtException = {};
}, { code: 'ERR_INVALID_ARG_TYPE' });
assert.strictEqual(process.report.reportOnUncaughtException, true);
@@ -55,7 +55,7 @@ process.report.reportOnSignal = false;
assert.strictEqual(process.report.reportOnSignal, false);
process.report.reportOnSignal = true;
assert.strictEqual(process.report.reportOnSignal, true);
-common.expectsError(() => {
+assert.throws(() => {
process.report.reportOnSignal = {};
}, { code: 'ERR_INVALID_ARG_TYPE' });
assert.strictEqual(process.report.reportOnSignal, true);
@@ -63,16 +63,16 @@ assert.strictEqual(process.report.reportOnSignal, true);
if (!common.isWindows) {
// Verify that process.report.signal behaves properly.
assert.strictEqual(process.report.signal, 'SIGUSR2');
- common.expectsError(() => {
+ assert.throws(() => {
process.report.signal = {};
}, { code: 'ERR_INVALID_ARG_TYPE' });
- common.expectsError(() => {
+ assert.throws(() => {
process.report.signal = 'foo';
}, {
code: 'ERR_UNKNOWN_SIGNAL',
message: 'Unknown signal: foo'
});
- common.expectsError(() => {
+ assert.throws(() => {
process.report.signal = 'sigusr1';
}, {
code: 'ERR_UNKNOWN_SIGNAL',
diff --git a/test/report/test-report-getreport.js b/test/report/test-report-getreport.js
index 1ee844fa92..ba645df69f 100644
--- a/test/report/test-report-getreport.js
+++ b/test/report/test-report-getreport.js
@@ -31,7 +31,7 @@ common.expectWarning('ExperimentalWarning',
// Test with an invalid error argument.
[null, 1, Symbol(), function() {}, 'foo'].forEach((error) => {
- common.expectsError(() => {
+ assert.throws(() => {
process.report.getReport(error);
}, { code: 'ERR_INVALID_ARG_TYPE' });
});
diff --git a/test/report/test-report-writereport.js b/test/report/test-report-writereport.js
index 5ab3af0e29..a72744fcd4 100644
--- a/test/report/test-report-writereport.js
+++ b/test/report/test-report-writereport.js
@@ -79,14 +79,14 @@ function validate() {
// Test with an invalid file argument.
[null, 1, Symbol(), function() {}].forEach((file) => {
- common.expectsError(() => {
+ assert.throws(() => {
process.report.writeReport(file);
}, { code: 'ERR_INVALID_ARG_TYPE' });
});
// Test with an invalid error argument.
[null, 1, Symbol(), function() {}, 'foo'].forEach((error) => {
- common.expectsError(() => {
+ assert.throws(() => {
process.report.writeReport('file', error);
}, { code: 'ERR_INVALID_ARG_TYPE' });
});
diff --git a/test/root.status b/test/root.status
index 6edb9ddec3..af4bc90e97 100644
--- a/test/root.status
+++ b/test/root.status
@@ -37,7 +37,6 @@ parallel/test-eslint-no-unescaped-regexp-dot: SLOW
parallel/test-eslint-number-isnan: SLOW
parallel/test-eslint-prefer-assert-iferror: SLOW
parallel/test-eslint-prefer-assert-methods: SLOW
-parallel/test-eslint-prefer-common-expectserror: SLOW
parallel/test-eslint-prefer-common-mustnotcall: SLOW
parallel/test-eslint-prefer-util-format-errors: SLOW
parallel/test-eslint-require-buffer: SLOW
diff --git a/test/sequential/test-crypto-timing-safe-equal.js b/test/sequential/test-crypto-timing-safe-equal.js
index 05d5a2a388..f9709ac966 100644
--- a/test/sequential/test-crypto-timing-safe-equal.js
+++ b/test/sequential/test-crypto-timing-safe-equal.js
@@ -32,31 +32,31 @@ assert.strictEqual(
}
}
-common.expectsError(
+assert.throws(
() => crypto.timingSafeEqual(Buffer.from([1, 2, 3]), Buffer.from([1, 2])),
{
code: 'ERR_CRYPTO_TIMING_SAFE_EQUAL_LENGTH',
- type: RangeError,
+ name: 'RangeError',
message: 'Input buffers must have the same byte length'
}
);
-common.expectsError(
+assert.throws(
() => crypto.timingSafeEqual('not a buffer', Buffer.from([1, 2])),
{
code: 'ERR_INVALID_ARG_TYPE',
- type: TypeError,
+ name: 'TypeError',
message:
'The "buf1" argument must be an instance of Buffer, TypedArray, or ' +
"DataView. Received type string ('not a buffer')"
}
);
-common.expectsError(
+assert.throws(
() => crypto.timingSafeEqual(Buffer.from([1, 2]), 'not a buffer'),
{
code: 'ERR_INVALID_ARG_TYPE',
- type: TypeError,
+ name: 'TypeError',
message:
'The "buf2" argument must be an instance of Buffer, TypedArray, or ' +
"DataView. Received type string ('not a buffer')"
diff --git a/test/sequential/test-heapdump.js b/test/sequential/test-heapdump.js
index 474979914a..61a089dc67 100644
--- a/test/sequential/test-heapdump.js
+++ b/test/sequential/test-heapdump.js
@@ -25,9 +25,9 @@ process.chdir(tmpdir.path);
}
[1, true, {}, [], null, Infinity, NaN].forEach((i) => {
- common.expectsError(() => writeHeapSnapshot(i), {
+ assert.throws(() => writeHeapSnapshot(i), {
code: 'ERR_INVALID_ARG_TYPE',
- type: TypeError,
+ name: 'TypeError',
message: 'The "path" argument must be of type string or an instance of ' +
'Buffer or URL.' +
common.invalidArgTypeHelper(i)
diff --git a/test/sequential/test-http2-max-session-memory.js b/test/sequential/test-http2-max-session-memory.js
index f770ee1139..9b77a45c32 100644
--- a/test/sequential/test-http2-max-session-memory.js
+++ b/test/sequential/test-http2-max-session-memory.js
@@ -33,7 +33,7 @@ server.listen(0, common.mustCall(() => {
const req = client.request();
req.on('error', common.expectsError({
code: 'ERR_HTTP2_STREAM_ERROR',
- type: Error,
+ name: 'Error',
message: 'Stream closed with error code NGHTTP2_ENHANCE_YOUR_CALM'
}));
req.on('close', common.mustCall(() => {
diff --git a/test/sequential/test-inspector-module.js b/test/sequential/test-inspector-module.js
index 166b726db4..5f5efe4cb8 100644
--- a/test/sequential/test-inspector-module.js
+++ b/test/sequential/test-inspector-module.js
@@ -4,16 +4,17 @@ const common = require('../common');
common.skipIfInspectorDisabled();
+const assert = require('assert');
const { Session } = require('inspector');
const { inspect } = require('util');
const session = new Session();
-common.expectsError(
+assert.throws(
() => session.post('Runtime.evaluate', { expression: '2 + 2' }),
{
code: 'ERR_INSPECTOR_NOT_CONNECTED',
- type: Error,
+ name: 'Error',
message: 'Session is not connected'
}
);
@@ -22,11 +23,11 @@ session.connect();
session.post('Runtime.evaluate', { expression: '2 + 2' });
[1, {}, [], true, Infinity, undefined].forEach((i) => {
- common.expectsError(
+ assert.throws(
() => session.post(i),
{
code: 'ERR_INVALID_ARG_TYPE',
- type: TypeError,
+ name: 'TypeError',
message:
'The "method" argument must be of type string.' +
common.invalidArgTypeHelper(i)
@@ -35,11 +36,11 @@ session.post('Runtime.evaluate', { expression: '2 + 2' });
});
[1, true, Infinity].forEach((i) => {
- common.expectsError(
+ assert.throws(
() => session.post('test', i),
{
code: 'ERR_INVALID_ARG_TYPE',
- type: TypeError,
+ name: 'TypeError',
message:
'The "params" argument must be of type object.' +
common.invalidArgTypeHelper(i)
@@ -48,21 +49,21 @@ session.post('Runtime.evaluate', { expression: '2 + 2' });
});
[1, 'a', {}, [], true, Infinity].forEach((i) => {
- common.expectsError(
+ assert.throws(
() => session.post('test', {}, i),
{
code: 'ERR_INVALID_CALLBACK',
- type: TypeError,
+ name: 'TypeError',
message: `Callback must be a function. Received ${inspect(i)}`
}
);
});
-common.expectsError(
+assert.throws(
() => session.connect(),
{
code: 'ERR_INSPECTOR_ALREADY_CONNECTED',
- type: Error,
+ name: 'Error',
message: 'The inspector session is already connected'
}
);
diff --git a/test/sequential/test-inspector-port-cluster.js b/test/sequential/test-inspector-port-cluster.js
index 55a0d14906..a6c9610843 100644
--- a/test/sequential/test-inspector-port-cluster.js
+++ b/test/sequential/test-inspector-port-cluster.js
@@ -209,7 +209,7 @@ function testRunnerMain() {
function masterProcessMain() {
const workers = JSON.parse(process.env.workers);
const clusterSettings = JSON.parse(process.env.clusterSettings) || {};
- const badPortError = { type: RangeError, code: 'ERR_SOCKET_BAD_PORT' };
+ const badPortError = { name: 'RangeError', code: 'ERR_SOCKET_BAD_PORT' };
let debugPort = process.debugPort;
for (const worker of workers) {
@@ -240,7 +240,7 @@ function masterProcessMain() {
clusterSettings.inspectPort = 'string';
cluster.setupMaster(clusterSettings);
- common.expectsError(() => {
+ assert.throws(() => {
cluster.fork(params).on('exit', common.mustCall(checkExitCode));
}, badPortError);
@@ -249,7 +249,7 @@ function masterProcessMain() {
clusterSettings.inspectPort = null;
cluster.setupMaster(clusterSettings);
- common.expectsError(() => {
+ assert.throws(() => {
cluster.fork(params).on('exit', common.mustCall(checkExitCode));
}, badPortError);
@@ -258,7 +258,7 @@ function masterProcessMain() {
clusterSettings.inspectPort = 1293812;
cluster.setupMaster(clusterSettings);
- common.expectsError(() => {
+ assert.throws(() => {
cluster.fork(params).on('exit', common.mustCall(checkExitCode));
}, badPortError);
@@ -267,7 +267,7 @@ function masterProcessMain() {
clusterSettings.inspectPort = -9776;
cluster.setupMaster(clusterSettings);
- common.expectsError(() => {
+ assert.throws(() => {
cluster.fork(params).on('exit', common.mustCall(checkExitCode));
}, badPortError);
@@ -280,7 +280,7 @@ function masterProcessMain() {
cluster.setupMaster(clusterSettings);
- common.expectsError(() => {
+ assert.throws(() => {
cluster.fork(params).on('exit', common.mustCall(checkExitCode));
}, badPortError);
@@ -293,7 +293,7 @@ function masterProcessMain() {
cluster.setupMaster(clusterSettings);
- common.expectsError(() => {
+ assert.throws(() => {
cluster.fork(params).on('exit', common.mustCall(checkExitCode));
}, badPortError);
diff --git a/test/sequential/test-perf-hooks.js b/test/sequential/test-perf-hooks.js
index 825cf85ef5..c9ac860d34 100644
--- a/test/sequential/test-perf-hooks.js
+++ b/test/sequential/test-perf-hooks.js
@@ -33,11 +33,11 @@ assert(inited < 15000);
});
[undefined, null, 'foo', 1].forEach((i) => {
- common.expectsError(
+ assert.throws(
() => performance.measure('test', 'A', i),
{
code: 'ERR_INVALID_PERFORMANCE_MARK',
- type: Error,
+ name: 'Error',
message: `The "${i}" performance mark has not been set`
});
});
diff --git a/test/sequential/test-performance-eventloopdelay.js b/test/sequential/test-performance-eventloopdelay.js
index 8e7ee4f0ad..47c54a2543 100644
--- a/test/sequential/test-performance-eventloopdelay.js
+++ b/test/sequential/test-performance-eventloopdelay.js
@@ -20,30 +20,30 @@ const { sleep } = require('internal/util');
{
[null, 'a', 1, false, Infinity].forEach((i) => {
- common.expectsError(
+ assert.throws(
() => monitorEventLoopDelay(i),
{
- type: TypeError,
+ name: 'TypeError',
code: 'ERR_INVALID_ARG_TYPE'
}
);
});
[null, 'a', false, {}, []].forEach((i) => {
- common.expectsError(
+ assert.throws(
() => monitorEventLoopDelay({ resolution: i }),
{
- type: TypeError,
+ name: 'TypeError',
code: 'ERR_INVALID_ARG_TYPE'
}
);
});
[-1, 0, Infinity].forEach((i) => {
- common.expectsError(
+ assert.throws(
() => monitorEventLoopDelay({ resolution: i }),
{
- type: RangeError,
+ name: 'RangeError',
code: 'ERR_INVALID_OPT_VALUE'
}
);
@@ -78,19 +78,19 @@ const { sleep } = require('internal/util');
assert.strictEqual(histogram.percentiles.size, 1);
['a', false, {}, []].forEach((i) => {
- common.expectsError(
+ assert.throws(
() => histogram.percentile(i),
{
- type: TypeError,
+ name: 'TypeError',
code: 'ERR_INVALID_ARG_TYPE'
}
);
});
[-1, 0, 101].forEach((i) => {
- common.expectsError(
+ assert.throws(
() => histogram.percentile(i),
{
- type: RangeError,
+ name: 'RangeError',
code: 'ERR_INVALID_ARG_VALUE'
}
);
diff --git a/test/sequential/test-tls-lookup.js b/test/sequential/test-tls-lookup.js
index 568ba13506..dcdd9724e3 100644
--- a/test/sequential/test-tls-lookup.js
+++ b/test/sequential/test-tls-lookup.js
@@ -3,6 +3,7 @@ const common = require('../common');
if (!common.hasCrypto)
common.skip('missing crypto');
+const assert = require('assert');
const tls = require('tls');
['foobar', 1, {}, []].forEach(function connectThrows(input) {
@@ -12,11 +13,11 @@ const tls = require('tls');
lookup: input
};
- common.expectsError(function() {
+ assert.throws(() => {
tls.connect(opts);
}, {
code: 'ERR_INVALID_ARG_TYPE',
- type: TypeError
+ name: 'TypeError'
});
});