aboutsummaryrefslogtreecommitdiff
path: root/test/parallel
diff options
context:
space:
mode:
authorRuben Bridgewater <ruben@bridgewater.de>2018-03-19 13:33:46 +0100
committerRuben Bridgewater <ruben@bridgewater.de>2018-03-25 01:45:37 +0100
commitc6b6c92185316e13738e6fa931fdd5303e381e46 (patch)
treec38af9cd1a0a8cd6eeb459af3adee4dfd390fdc6 /test/parallel
parenteeb57022e6bada13955a19b15232a9ee4fe9b465 (diff)
downloadandroid-node-v8-c6b6c92185316e13738e6fa931fdd5303e381e46.tar.gz
android-node-v8-c6b6c92185316e13738e6fa931fdd5303e381e46.tar.bz2
android-node-v8-c6b6c92185316e13738e6fa931fdd5303e381e46.zip
lib: always show ERR_INVALID_ARG_TYPE received part
This makes a effort to make sure all of these errors will actually also show the received input. On top of that it refactors a few tests for better maintainability. It will also change the returned type to always be a simple typeof instead of special handling null. PR-URL: https://github.com/nodejs/node/pull/19445 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net>
Diffstat (limited to 'test/parallel')
-rw-r--r--test/parallel/test-assert.js16
-rw-r--r--test/parallel/test-buffer-compare.js17
-rw-r--r--test/parallel/test-buffer-concat.js18
-rw-r--r--test/parallel/test-child-process-constructor.js2
-rw-r--r--test/parallel/test-crypto-certificate.js39
-rw-r--r--test/parallel/test-crypto-cipher-decipher.js16
-rw-r--r--test/parallel/test-crypto-cipheriv-decipheriv.js14
-rw-r--r--test/parallel/test-crypto-dh.js9
-rw-r--r--test/parallel/test-crypto-engine.js4
-rw-r--r--test/parallel/test-crypto-hash.js3
-rw-r--r--test/parallel/test-crypto-hmac.js4
-rw-r--r--test/parallel/test-crypto-pbkdf2.js37
-rw-r--r--test/parallel/test-crypto-sign-verify.js124
-rw-r--r--test/parallel/test-dgram-custom-lookup.js3
-rw-r--r--test/parallel/test-dgram-send-address-types.js50
-rw-r--r--test/parallel/test-dgram-sendto.js66
-rw-r--r--test/parallel/test-event-emitter-add-listeners.js3
-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-fs-access.js3
-rw-r--r--test/parallel/test-fs-buffer.js3
-rw-r--r--test/parallel/test-fs-chmod.js49
-rw-r--r--test/parallel/test-fs-close-errors.js28
-rw-r--r--test/parallel/test-fs-read-type.js20
-rw-r--r--test/parallel/test-fs-readfile-error.js3
-rw-r--r--test/parallel/test-fs-rename-type-check.js40
-rw-r--r--test/parallel/test-fs-stat.js54
-rw-r--r--test/parallel/test-fs-truncate.js36
-rw-r--r--test/parallel/test-fs-watch.js8
-rw-r--r--test/parallel/test-http-mutable-headers.js9
-rw-r--r--test/parallel/test-http-outgoing-proto.js6
-rw-r--r--test/parallel/test-http2-client-setNextStreamID-errors.js3
-rw-r--r--test/parallel/test-http2-compat-serverrequest-headers.js4
-rw-r--r--test/parallel/test-http2-compat-serverresponse-headers.js40
-rw-r--r--test/parallel/test-http2-compat-serverresponse-trailers.js5
-rw-r--r--test/parallel/test-http2-createsecureserver-nooptions.js18
-rw-r--r--test/parallel/test-http2-getpackedsettings.js7
-rw-r--r--test/parallel/test-http2-invalidargtypes-errors.js3
-rw-r--r--test/parallel/test-http2-misc-util.js4
-rw-r--r--test/parallel/test-http2-ping.js8
-rw-r--r--test/parallel/test-http2-respond-file-fd-errors.js3
-rw-r--r--test/parallel/test-http2-server-shutdown-options-errors.js16
-rw-r--r--test/parallel/test-http2-util-asserts.js7
-rw-r--r--test/parallel/test-https-options-boolean-check.js112
-rw-r--r--test/parallel/test-icu-transcode.js2
-rw-r--r--test/parallel/test-internal-errors.js30
-rw-r--r--test/parallel/test-net-connect-buffer.js8
-rw-r--r--test/parallel/test-path-parse-format.js6
-rw-r--r--test/parallel/test-performance-function.js7
-rw-r--r--test/parallel/test-performanceobserver.js8
-rw-r--r--test/parallel/test-process-exception-capture-errors.js3
-rw-r--r--test/parallel/test-process-kill-pid.js26
-rw-r--r--test/parallel/test-tls-basic-validations.js3
-rw-r--r--test/parallel/test-tls-error-servername.js3
-rw-r--r--test/parallel/test-tls-no-cert-required.js3
-rw-r--r--test/parallel/test-tls-options-boolean-check.js94
-rw-r--r--test/parallel/test-url-format-invalid-input.js2
-rw-r--r--test/parallel/test-url-format-whatwg.js20
-rw-r--r--test/parallel/test-url-parse-invalid-input.js2
-rw-r--r--test/parallel/test-util-callbackify.js6
-rw-r--r--test/parallel/test-util-deprecate-invalid-code.js3
-rw-r--r--test/parallel/test-util-inherits.js10
-rw-r--r--test/parallel/test-util-inspect.js6
-rw-r--r--test/parallel/test-util-promisify.js3
-rw-r--r--test/parallel/test-v8-flag-type-check.js7
-rw-r--r--test/parallel/test-vm-basic.js73
-rw-r--r--test/parallel/test-zlib-not-string-or-buffer.js16
68 files changed, 552 insertions, 715 deletions
diff --git a/test/parallel/test-assert.js b/test/parallel/test-assert.js
index 9964c393ed..ac56b409d0 100644
--- a/test/parallel/test-assert.js
+++ b/test/parallel/test-assert.js
@@ -317,10 +317,6 @@ try {
{
// Verify that throws() and doesNotThrow() throw on non-function block.
- function typeName(value) {
- return value === null ? 'null' : typeof value;
- }
-
const testBlockTypeError = (method, block) => {
common.expectsError(
() => method(block),
@@ -328,7 +324,7 @@ try {
code: 'ERR_INVALID_ARG_TYPE',
type: TypeError,
message: 'The "block" argument must be of type Function. Received ' +
- `type ${typeName(block)}`
+ `type ${typeof block}`
}
);
};
@@ -369,15 +365,15 @@ assert.throws(() => {
{
// Bad args to AssertionError constructor should throw TypeError.
const args = [1, true, false, '', null, Infinity, Symbol('test'), undefined];
- const re = /^The "options" argument must be of type Object$/;
args.forEach((input) => {
assert.throws(
() => new assert.AssertionError(input),
- common.expectsError({
+ {
code: 'ERR_INVALID_ARG_TYPE',
- type: TypeError,
- message: re
- }));
+ name: 'TypeError [ERR_INVALID_ARG_TYPE]',
+ message: 'The "options" argument must be of type Object. ' +
+ `Received type ${typeof input}`
+ });
});
}
diff --git a/test/parallel/test-buffer-compare.js b/test/parallel/test-buffer-compare.js
index 9ebd3a970b..e2bd1380d2 100644
--- a/test/parallel/test-buffer-compare.js
+++ b/test/parallel/test-buffer-compare.js
@@ -28,15 +28,16 @@ assert.strictEqual(Buffer.compare(Buffer.alloc(0), Buffer.alloc(0)), 0);
assert.strictEqual(Buffer.compare(Buffer.alloc(0), Buffer.alloc(1)), -1);
assert.strictEqual(Buffer.compare(Buffer.alloc(1), Buffer.alloc(0)), 1);
-const errMsg = common.expectsError({
+assert.throws(() => Buffer.compare(Buffer.alloc(1), 'abc'), {
code: 'ERR_INVALID_ARG_TYPE',
- type: TypeError,
- message: 'The "buf1", "buf2" arguments must be one of ' +
- 'type Buffer or Uint8Array'
-}, 2);
-assert.throws(() => Buffer.compare(Buffer.alloc(1), 'abc'), errMsg);
-
-assert.throws(() => Buffer.compare('abc', Buffer.alloc(1)), errMsg);
+ message: 'The "buf2" argument must be one of type Buffer or Uint8Array. ' +
+ 'Received type string'
+});
+assert.throws(() => Buffer.compare('abc', Buffer.alloc(1)), {
+ code: 'ERR_INVALID_ARG_TYPE',
+ message: 'The "buf1" argument must be one of type Buffer or Uint8Array. ' +
+ 'Received type string'
+});
common.expectsError(() => Buffer.alloc(1).compare('abc'), {
code: 'ERR_INVALID_ARG_TYPE',
diff --git a/test/parallel/test-buffer-concat.js b/test/parallel/test-buffer-concat.js
index 9d6c6c7d35..27a485ec9d 100644
--- a/test/parallel/test-buffer-concat.js
+++ b/test/parallel/test-buffer-concat.js
@@ -44,23 +44,15 @@ assert.notStrictEqual(flatOne, one[0]);
assert.strictEqual(flatLong.toString(), check);
assert.strictEqual(flatLongLen.toString(), check);
-assertWrongList();
-assertWrongList(null);
-assertWrongList(Buffer.from('hello'));
-assertWrongList([42]);
-assertWrongList(['hello', 'world']);
-assertWrongList(['hello', Buffer.from('world')]);
-
-function assertWrongList(value) {
- common.expectsError(() => {
+[undefined, null, Buffer.from('hello')].forEach((value) => {
+ assert.throws(() => {
Buffer.concat(value);
}, {
code: 'ERR_INVALID_ARG_TYPE',
- type: TypeError,
- message: 'The "list" argument must be one of type ' +
- 'Array, Buffer, or Uint8Array'
+ message: 'The "list" argument must be one of type Array, Buffer, ' +
+ `or Uint8Array. Received type ${typeof value}`
});
-}
+});
// eslint-disable-next-line node-core/crypto-check
const random10 = common.hasCrypto ?
diff --git a/test/parallel/test-child-process-constructor.js b/test/parallel/test-child-process-constructor.js
index 33bcdcb669..bf7fffd9c5 100644
--- a/test/parallel/test-child-process-constructor.js
+++ b/test/parallel/test-child-process-constructor.js
@@ -6,7 +6,7 @@ const { ChildProcess } = require('child_process');
assert.strictEqual(typeof ChildProcess, 'function');
function typeName(value) {
- return value === null ? 'null' : typeof value;
+ return typeof value;
}
{
diff --git a/test/parallel/test-crypto-certificate.js b/test/parallel/test-crypto-certificate.js
index 36742154ef..f94c82474e 100644
--- a/test/parallel/test-crypto-certificate.js
+++ b/test/parallel/test-crypto-certificate.js
@@ -78,39 +78,26 @@ function stripLineEndings(obj) {
return obj.replace(/\n/g, '');
}
-// direct call Certificate() should return instance
+// Direct call Certificate() should return instance
assert(Certificate() instanceof Certificate);
-[1, {}, [], Infinity, true, 'test', undefined, null].forEach((i) => {
- common.expectsError(
- () => Certificate.verifySpkac(i),
+[1, {}, [], Infinity, true, 'test', undefined, null].forEach((val) => {
+ assert.throws(
+ () => Certificate.verifySpkac(val),
{
code: 'ERR_INVALID_ARG_TYPE',
- type: TypeError,
message: 'The "spkac" argument must be one of type Buffer, TypedArray, ' +
- 'or DataView'
+ `or DataView. Received type ${typeof val}`
}
);
});
-[1, {}, [], Infinity, true, undefined, null].forEach((i) => {
- common.expectsError(
- () => Certificate.exportPublicKey(i),
- {
- code: 'ERR_INVALID_ARG_TYPE',
- type: TypeError,
- message: 'The "spkac" argument must be one of type string, Buffer,' +
- ' TypedArray, or DataView'
- }
- );
-
- common.expectsError(
- () => Certificate.exportChallenge(i),
- {
- code: 'ERR_INVALID_ARG_TYPE',
- type: TypeError,
- message: 'The "spkac" argument must be one of type string, Buffer,' +
- ' TypedArray, or DataView'
- }
- );
+[1, {}, [], Infinity, true, undefined, null].forEach((val) => {
+ const errObj = {
+ code: 'ERR_INVALID_ARG_TYPE',
+ message: 'The "spkac" argument must be one of type string, Buffer,' +
+ ` TypedArray, or DataView. Received type ${typeof val}`
+ };
+ assert.throws(() => Certificate.exportPublicKey(val), errObj);
+ assert.throws(() => Certificate.exportChallenge(val), errObj);
});
diff --git a/test/parallel/test-crypto-cipher-decipher.js b/test/parallel/test-crypto-cipher-decipher.js
index b34f43377c..75ed26c1ff 100644
--- a/test/parallel/test-crypto-cipher-decipher.js
+++ b/test/parallel/test-crypto-cipher-decipher.js
@@ -81,7 +81,8 @@ testCipher2(Buffer.from('0123456789abcdef'));
{
code: 'ERR_INVALID_ARG_TYPE',
type: TypeError,
- message: 'The "cipher" argument must be of type string'
+ message: 'The "cipher" argument must be of type string. ' +
+ 'Received type object'
});
common.expectsError(
@@ -90,7 +91,7 @@ testCipher2(Buffer.from('0123456789abcdef'));
code: 'ERR_INVALID_ARG_TYPE',
type: TypeError,
message: 'The "password" argument must be one of type string, Buffer, ' +
- 'TypedArray, or DataView'
+ 'TypedArray, or DataView. Received type object'
});
common.expectsError(
@@ -99,7 +100,7 @@ testCipher2(Buffer.from('0123456789abcdef'));
code: 'ERR_INVALID_ARG_TYPE',
type: TypeError,
message: 'The "data" argument must be one of type string, Buffer, ' +
- 'TypedArray, or DataView'
+ 'TypedArray, or DataView. Received type object'
});
common.expectsError(
@@ -108,7 +109,7 @@ testCipher2(Buffer.from('0123456789abcdef'));
code: 'ERR_INVALID_ARG_TYPE',
type: TypeError,
message: 'The "buffer" argument must be one of type Buffer, ' +
- 'TypedArray, or DataView'
+ 'TypedArray, or DataView. Received type object'
});
common.expectsError(
@@ -117,7 +118,7 @@ testCipher2(Buffer.from('0123456789abcdef'));
code: 'ERR_INVALID_ARG_TYPE',
type: TypeError,
message: 'The "buffer" argument must be one of type Buffer, ' +
- 'TypedArray, or DataView'
+ 'TypedArray, or DataView. Received type object'
});
}
@@ -132,7 +133,8 @@ testCipher2(Buffer.from('0123456789abcdef'));
{
code: 'ERR_INVALID_ARG_TYPE',
type: TypeError,
- message: 'The "cipher" argument must be of type string'
+ message: 'The "cipher" argument must be of type string. ' +
+ 'Received type object'
});
common.expectsError(
@@ -141,7 +143,7 @@ testCipher2(Buffer.from('0123456789abcdef'));
code: 'ERR_INVALID_ARG_TYPE',
type: TypeError,
message: 'The "password" argument must be one of type string, Buffer, ' +
- 'TypedArray, or DataView'
+ 'TypedArray, or DataView. Received type object'
});
}
diff --git a/test/parallel/test-crypto-cipheriv-decipheriv.js b/test/parallel/test-crypto-cipheriv-decipheriv.js
index dcdec728f1..c0073abcfd 100644
--- a/test/parallel/test-crypto-cipheriv-decipheriv.js
+++ b/test/parallel/test-crypto-cipheriv-decipheriv.js
@@ -92,7 +92,8 @@ function testCipher3(key, iv) {
{
code: 'ERR_INVALID_ARG_TYPE',
type: TypeError,
- message: 'The "cipher" argument must be of type string'
+ message: 'The "cipher" argument must be of type string. ' +
+ 'Received type object'
});
common.expectsError(
@@ -101,7 +102,7 @@ function testCipher3(key, iv) {
code: 'ERR_INVALID_ARG_TYPE',
type: TypeError,
message: 'The "key" argument must be one of type string, Buffer, ' +
- 'TypedArray, or DataView'
+ 'TypedArray, or DataView. Received type object'
});
common.expectsError(
@@ -110,7 +111,7 @@ function testCipher3(key, iv) {
code: 'ERR_INVALID_ARG_TYPE',
type: TypeError,
message: 'The "iv" argument must be one of type string, Buffer, ' +
- 'TypedArray, or DataView'
+ 'TypedArray, or DataView. Received type number'
});
}
@@ -128,7 +129,8 @@ function testCipher3(key, iv) {
{
code: 'ERR_INVALID_ARG_TYPE',
type: TypeError,
- message: 'The "cipher" argument must be of type string'
+ message: 'The "cipher" argument must be of type string. ' +
+ 'Received type object'
});
common.expectsError(
@@ -137,7 +139,7 @@ function testCipher3(key, iv) {
code: 'ERR_INVALID_ARG_TYPE',
type: TypeError,
message: 'The "key" argument must be one of type string, Buffer, ' +
- 'TypedArray, or DataView'
+ 'TypedArray, or DataView. Received type object'
});
common.expectsError(
@@ -146,7 +148,7 @@ function testCipher3(key, iv) {
code: 'ERR_INVALID_ARG_TYPE',
type: TypeError,
message: 'The "iv" argument must be one of type string, Buffer, ' +
- 'TypedArray, or DataView'
+ 'TypedArray, or DataView. Received type number'
});
}
diff --git a/test/parallel/test-crypto-dh.js b/test/parallel/test-crypto-dh.js
index 6b2b8faa36..8e584100d9 100644
--- a/test/parallel/test-crypto-dh.js
+++ b/test/parallel/test-crypto-dh.js
@@ -49,14 +49,14 @@ assert.strictEqual(dh2.verifyError, 0);
() => { },
/abc/,
{}
-].forEach((i) => {
+].forEach((input) => {
common.expectsError(
- () => crypto.createDiffieHellman(i),
+ () => crypto.createDiffieHellman(input),
{
code: 'ERR_INVALID_ARG_TYPE',
type: TypeError,
message: 'The "sizeOrKey" argument must be one of type number, string, ' +
- 'Buffer, TypedArray, or DataView'
+ `Buffer, TypedArray, or DataView. Received type ${typeof input}`
}
);
});
@@ -380,5 +380,6 @@ common.expectsError(
{
code: 'ERR_INVALID_ARG_TYPE',
type: TypeError,
- message: 'The "curve" argument must be of type string'
+ message: 'The "curve" argument must be of type string. ' +
+ 'Received type undefined'
});
diff --git a/test/parallel/test-crypto-engine.js b/test/parallel/test-crypto-engine.js
index 43f8b8084c..ca76672de8 100644
--- a/test/parallel/test-crypto-engine.js
+++ b/test/parallel/test-crypto-engine.js
@@ -12,7 +12,7 @@ common.expectsError(
{
code: 'ERR_INVALID_ARG_TYPE',
type: TypeError,
- message: 'The "id" argument must be of type string'
+ message: 'The "id" argument must be of type string. Received type boolean'
});
common.expectsError(
@@ -20,7 +20,7 @@ common.expectsError(
{
code: 'ERR_INVALID_ARG_TYPE',
type: TypeError,
- message: 'The "flags" argument must be of type number'
+ message: 'The "flags" argument must be of type number. Received type string'
});
common.expectsError(
diff --git a/test/parallel/test-crypto-hash.js b/test/parallel/test-crypto-hash.js
index e425e1fe4c..f4f7b0dfe5 100644
--- a/test/parallel/test-crypto-hash.js
+++ b/test/parallel/test-crypto-hash.js
@@ -152,7 +152,8 @@ common.expectsError(
{
code: 'ERR_INVALID_ARG_TYPE',
type: TypeError,
- message: 'The "algorithm" argument must be of type string'
+ message: 'The "algorithm" argument must be of type string. ' +
+ 'Received type undefined'
}
);
diff --git a/test/parallel/test-crypto-hmac.js b/test/parallel/test-crypto-hmac.js
index 0597891e00..223b5c3c07 100644
--- a/test/parallel/test-crypto-hmac.js
+++ b/test/parallel/test-crypto-hmac.js
@@ -18,7 +18,7 @@ common.expectsError(
{
code: 'ERR_INVALID_ARG_TYPE',
type: TypeError,
- message: 'The "hmac" argument must be of type string'
+ message: 'The "hmac" argument must be of type string. Received type object'
});
common.expectsError(
@@ -27,7 +27,7 @@ common.expectsError(
code: 'ERR_INVALID_ARG_TYPE',
type: TypeError,
message: 'The "key" argument must be one of type string, TypedArray, or ' +
- 'DataView'
+ 'DataView. Received type object'
});
{
diff --git a/test/parallel/test-crypto-pbkdf2.js b/test/parallel/test-crypto-pbkdf2.js
index c72551016d..d3f02cf8bd 100644
--- a/test/parallel/test-crypto-pbkdf2.js
+++ b/test/parallel/test-crypto-pbkdf2.js
@@ -82,7 +82,8 @@ common.expectsError(
}, {
code: 'ERR_INVALID_ARG_TYPE',
type: TypeError,
- message: 'The "keylen" argument must be of type number'
+ message: 'The "keylen" argument must be of type number. ' +
+ `Received type ${typeof notNumber}`
});
});
@@ -107,7 +108,8 @@ common.expectsError(
{
code: 'ERR_INVALID_ARG_TYPE',
type: TypeError,
- message: 'The "digest" argument must be one of type string or null'
+ message: 'The "digest" argument must be one of type string or null. ' +
+ 'Received type undefined'
});
common.expectsError(
@@ -115,58 +117,57 @@ common.expectsError(
{
code: 'ERR_INVALID_ARG_TYPE',
type: TypeError,
- message: 'The "digest" argument must be one of type string or null'
+ message: 'The "digest" argument must be one of type string or null. ' +
+ 'Received type undefined'
});
-[1, {}, [], true, undefined, null].forEach((i) => {
+[1, {}, [], true, undefined, null].forEach((input) => {
+ const msgPart2 = `Buffer, or TypedArray. Received type ${typeof input}`;
common.expectsError(
- () => crypto.pbkdf2(i, 'salt', 8, 8, 'sha256', common.mustNotCall()),
+ () => crypto.pbkdf2(input, 'salt', 8, 8, 'sha256', common.mustNotCall()),
{
code: 'ERR_INVALID_ARG_TYPE',
type: TypeError,
- message: 'The "password" argument must be one of type string, ' +
- 'Buffer, or TypedArray'
+ message: `The "password" argument must be one of type string, ${msgPart2}`
}
);
common.expectsError(
- () => crypto.pbkdf2('pass', i, 8, 8, 'sha256', common.mustNotCall()),
+ () => crypto.pbkdf2('pass', input, 8, 8, 'sha256', common.mustNotCall()),
{
code: 'ERR_INVALID_ARG_TYPE',
type: TypeError,
- message: 'The "salt" argument must be one of type string, ' +
- 'Buffer, or TypedArray'
+ message: `The "salt" argument must be one of type string, ${msgPart2}`
}
);
common.expectsError(
- () => crypto.pbkdf2Sync(i, 'salt', 8, 8, 'sha256'),
+ () => crypto.pbkdf2Sync(input, 'salt', 8, 8, 'sha256'),
{
code: 'ERR_INVALID_ARG_TYPE',
type: TypeError,
- message: 'The "password" argument must be one of type string, ' +
- 'Buffer, or TypedArray'
+ message: `The "password" argument must be one of type string, ${msgPart2}`
}
);
common.expectsError(
- () => crypto.pbkdf2Sync('pass', i, 8, 8, 'sha256'),
+ () => crypto.pbkdf2Sync('pass', input, 8, 8, 'sha256'),
{
code: 'ERR_INVALID_ARG_TYPE',
type: TypeError,
- message: 'The "salt" argument must be one of type string, ' +
- 'Buffer, or TypedArray'
+ message: `The "salt" argument must be one of type string, ${msgPart2}`
}
);
});
['test', {}, [], true, undefined, null].forEach((i) => {
+ const received = `Received type ${typeof i}`;
common.expectsError(
() => crypto.pbkdf2('pass', 'salt', i, 8, 'sha256', common.mustNotCall()),
{
code: 'ERR_INVALID_ARG_TYPE',
type: TypeError,
- message: 'The "iterations" argument must be of type number'
+ message: `The "iterations" argument must be of type number. ${received}`
}
);
@@ -175,7 +176,7 @@ common.expectsError(
{
code: 'ERR_INVALID_ARG_TYPE',
type: TypeError,
- message: 'The "iterations" argument must be of type number'
+ message: `The "iterations" argument must be of type number. ${received}`
}
);
});
diff --git a/test/parallel/test-crypto-sign-verify.js b/test/parallel/test-crypto-sign-verify.js
index 7619d91191..11cbdbc210 100644
--- a/test/parallel/test-crypto-sign-verify.js
+++ b/test/parallel/test-crypto-sign-verify.js
@@ -315,105 +315,51 @@ common.expectsError(
}));
}
-[1, [], {}, undefined, null, true, Infinity].forEach((i) => {
- common.expectsError(
- () => crypto.createSign(),
- {
- code: 'ERR_INVALID_ARG_TYPE',
- type: TypeError,
- message: 'The "algorithm" argument must be of type string'
- }
- );
- common.expectsError(
- () => crypto.createVerify(),
- {
- code: 'ERR_INVALID_ARG_TYPE',
- type: TypeError,
- message: 'The "algorithm" argument must be of type string'
- }
- );
-});
-
{
const sign = crypto.createSign('SHA1');
const verify = crypto.createVerify('SHA1');
- [1, [], {}, undefined, null, true, Infinity].forEach((i) => {
- common.expectsError(
- () => sign.update(i),
- {
- code: 'ERR_INVALID_ARG_TYPE',
- type: TypeError,
- message: 'The "data" argument must be one of type string, Buffer, ' +
- 'TypedArray, or DataView'
- }
- );
- common.expectsError(
- () => verify.update(i),
- {
- code: 'ERR_INVALID_ARG_TYPE',
- type: TypeError,
- message: 'The "data" argument must be one of type string, Buffer, ' +
- 'TypedArray, or DataView'
- }
- );
- common.expectsError(
- () => sign._write(i, 'utf8', () => {}),
- {
- code: 'ERR_INVALID_ARG_TYPE',
- type: TypeError,
- message: 'The "data" argument must be one of type string, Buffer, ' +
- 'TypedArray, or DataView'
- }
- );
- common.expectsError(
- () => verify._write(i, 'utf8', () => {}),
- {
- code: 'ERR_INVALID_ARG_TYPE',
- type: TypeError,
- message: 'The "data" argument must be one of type string, Buffer, ' +
- 'TypedArray, or DataView'
- }
- );
+ [1, [], {}, undefined, null, true, Infinity].forEach((input) => {
+ const type = typeof input;
+ const errObj = {
+ code: 'ERR_INVALID_ARG_TYPE',
+ name: 'TypeError [ERR_INVALID_ARG_TYPE]',
+ message: 'The "algorithm" argument must be of type string. ' +
+ `Received type ${type}`
+ };
+ assert.throws(() => crypto.createSign(input), errObj);
+ assert.throws(() => crypto.createVerify(input), errObj);
+
+ errObj.message = 'The "data" argument must be one of type string, ' +
+ `Buffer, TypedArray, or DataView. Received type ${type}`;
+ assert.throws(() => sign.update(input), errObj);
+ assert.throws(() => verify.update(input), errObj);
+ assert.throws(() => sign._write(input, 'utf8', () => {}), errObj);
+ assert.throws(() => verify._write(input, 'utf8', () => {}), errObj);
});
[
Uint8Array, Uint16Array, Uint32Array, Float32Array, Float64Array
- ].forEach((i) => {
+ ].forEach((clazz) => {
// These should all just work
- sign.update(new i());
- verify.update(new i());
+ sign.update(new clazz());
+ verify.update(new clazz());
});
- [1, {}, [], Infinity].forEach((i) => {
- common.expectsError(
- () => sign.sign(i),
- {
- code: 'ERR_INVALID_ARG_TYPE',
- type: TypeError,
- message: 'The "key" argument must be one of type string, Buffer, ' +
- 'TypedArray, or DataView'
- }
- );
-
- common.expectsError(
- () => verify.verify(i),
- {
- code: 'ERR_INVALID_ARG_TYPE',
- type: TypeError,
- message: 'The "key" argument must be one of type string, Buffer, ' +
- 'TypedArray, or DataView'
- }
- );
-
- common.expectsError(
- () => verify.verify('test', i),
- {
- code: 'ERR_INVALID_ARG_TYPE',
- type: TypeError,
- message: 'The "signature" argument must be one of type string, ' +
- 'Buffer, TypedArray, or DataView'
- }
- );
+ [1, {}, [], Infinity].forEach((input) => {
+ const type = typeof input;
+ const errObj = {
+ code: 'ERR_INVALID_ARG_TYPE',
+ name: 'TypeError [ERR_INVALID_ARG_TYPE]',
+ message: 'The "key" argument must be one of type string, Buffer, ' +
+ `TypedArray, or DataView. Received type ${type}`
+ };
+
+ assert.throws(() => sign.sign(input), errObj);
+ assert.throws(() => verify.verify(input), errObj);
+
+ errObj.message = 'The "signature" argument must be one of type string, ' +
+ `Buffer, TypedArray, or DataView. Received type ${type}`;
+ assert.throws(() => verify.verify('test', input), errObj);
});
}
diff --git a/test/parallel/test-dgram-custom-lookup.js b/test/parallel/test-dgram-custom-lookup.js
index df715f81d6..ae62328364 100644
--- a/test/parallel/test-dgram-custom-lookup.js
+++ b/test/parallel/test-dgram-custom-lookup.js
@@ -40,7 +40,8 @@ const dns = require('dns');
}, {
code: 'ERR_INVALID_ARG_TYPE',
type: TypeError,
- message: 'The "lookup" argument must be of type Function'
+ message: 'The "lookup" argument must be of type Function. ' +
+ `Received type ${typeof value}`
});
});
}
diff --git a/test/parallel/test-dgram-send-address-types.js b/test/parallel/test-dgram-send-address-types.js
index b3f4f3fcea..0d208cfdc8 100644
--- a/test/parallel/test-dgram-send-address-types.js
+++ b/test/parallel/test-dgram-send-address-types.js
@@ -10,47 +10,27 @@ const onMessage = common.mustCall((err, bytes) => {
assert.strictEqual(bytes, buf.length);
}, 6);
-const expectedError = { code: 'ERR_INVALID_ARG_TYPE',
- type: TypeError,
- message:
- /^The "address" argument must be one of type string or falsy$/
-};
-
const client = dgram.createSocket('udp4').bind(0, () => {
const port = client.address().port;
- // valid address: false
- client.send(buf, port, false, onMessage);
-
- // valid address: empty string
- client.send(buf, port, '', onMessage);
-
- // valid address: null
- client.send(buf, port, null, onMessage);
-
- // valid address: 0
- client.send(buf, port, 0, onMessage);
+ // Check valid addresses
+ [false, '', null, 0, undefined].forEach((address) => {
+ client.send(buf, port, address, onMessage);
+ });
- // valid address: undefined
- client.send(buf, port, undefined, onMessage);
-
- // valid address: not provided
+ // Valid address: not provided
client.send(buf, port, onMessage);
- // invalid address: object
- common.expectsError(() => {
- client.send(buf, port, []);
- }, expectedError);
-
- // invalid address: nonzero number
- common.expectsError(() => {
- client.send(buf, port, 1);
- }, expectedError);
-
- // invalid address: true
- common.expectsError(() => {
- client.send(buf, port, true);
- }, expectedError);
+ // Check invalid addresses
+ [[], 1, true].forEach((invalidInput) => {
+ const expectedError = {
+ code: 'ERR_INVALID_ARG_TYPE',
+ name: 'TypeError [ERR_INVALID_ARG_TYPE]',
+ message: 'The "address" argument must be one of type string or falsy. ' +
+ `Received type ${typeof invalidInput}`
+ };
+ assert.throws(() => client.send(buf, port, invalidInput), expectedError);
+ });
});
client.unref();
diff --git a/test/parallel/test-dgram-sendto.js b/test/parallel/test-dgram-sendto.js
index 782b2f692b..3922ccbb64 100644
--- a/test/parallel/test-dgram-sendto.js
+++ b/test/parallel/test-dgram-sendto.js
@@ -1,47 +1,37 @@
'use strict';
-const common = require('../common');
+require('../common');
+const assert = require('assert');
const dgram = require('dgram');
const socket = dgram.createSocket('udp4');
-const errorMessageOffset =
- /^The "offset" argument must be of type number$/;
-
-common.expectsError(() => {
- socket.sendto();
-}, {
+const errObj = {
code: 'ERR_INVALID_ARG_TYPE',
- type: TypeError,
- message: errorMessageOffset
-});
+ name: 'TypeError [ERR_INVALID_ARG_TYPE]',
+ message: 'The "offset" argument must be of type number. Received type ' +
+ 'undefined'
+};
+assert.throws(() => socket.sendto(), errObj);
-common.expectsError(() => {
- socket.sendto('buffer', 1, 'offset', 'port', 'address', 'cb');
-}, {
- code: 'ERR_INVALID_ARG_TYPE',
- type: TypeError,
- message: /^The "length" argument must be of type number$/
-});
+errObj.message = 'The "length" argument must be of type number. Received ' +
+ 'type string';
+assert.throws(
+ () => socket.sendto('buffer', 1, 'offset', 'port', 'address', 'cb'),
+ errObj);
-common.expectsError(() => {
- socket.sendto('buffer', 'offset', 1, 'port', 'address', 'cb');
-}, {
- code: 'ERR_INVALID_ARG_TYPE',
- type: TypeError,
- message: errorMessageOffset
-});
+errObj.message = 'The "offset" argument must be of type number. Received ' +
+ 'type string';
+assert.throws(
+ () => socket.sendto('buffer', 'offset', 1, 'port', 'address', 'cb'),
+ errObj);
-common.expectsError(() => {
- socket.sendto('buffer', 1, 1, 10, false, 'cb');
-}, {
- code: 'ERR_INVALID_ARG_TYPE',
- type: TypeError,
- message: /^The "address" argument must be of type string$/
-});
+errObj.message = 'The "address" argument must be of type string. Received ' +
+ 'type boolean';
+assert.throws(
+ () => socket.sendto('buffer', 1, 1, 10, false, 'cb'),
+ errObj);
-common.expectsError(() => {
- socket.sendto('buffer', 1, 1, false, 'address', 'cb');
-}, {
- code: 'ERR_INVALID_ARG_TYPE',
- type: TypeError,
- message: /^The "port" argument must be of type number$/
-});
+errObj.message = 'The "port" argument must be of type number. Received ' +
+ 'type boolean';
+assert.throws(
+ () => socket.sendto('buffer', 1, 1, false, 'address', 'cb'),
+ errObj);
diff --git a/test/parallel/test-event-emitter-add-listeners.js b/test/parallel/test-event-emitter-add-listeners.js
index 448db80516..45bfd3832c 100644
--- a/test/parallel/test-event-emitter-add-listeners.js
+++ b/test/parallel/test-event-emitter-add-listeners.js
@@ -92,5 +92,6 @@ common.expectsError(() => {
}, {
code: 'ERR_INVALID_ARG_TYPE',
type: TypeError,
- message: 'The "listener" argument must be of type Function'
+ message: 'The "listener" argument must be of type Function. ' +
+ 'Received type object'
});
diff --git a/test/parallel/test-event-emitter-once.js b/test/parallel/test-event-emitter-once.js
index fa99a1362a..1bdf0cbf12 100644
--- a/test/parallel/test-event-emitter-once.js
+++ b/test/parallel/test-event-emitter-once.js
@@ -52,12 +52,12 @@ e.emit('e');
// Verify that the listener must be a function
common.expectsError(() => {
const ee = new EventEmitter();
-
ee.once('foo', null);
}, {
code: 'ERR_INVALID_ARG_TYPE',
type: TypeError,
- message: 'The "listener" argument must be of type Function'
+ message: 'The "listener" argument must be of type Function. ' +
+ 'Received type object'
});
{
diff --git a/test/parallel/test-event-emitter-prepend.js b/test/parallel/test-event-emitter-prepend.js
index dd9a9bdfc5..3259ea47f9 100644
--- a/test/parallel/test-event-emitter-prepend.js
+++ b/test/parallel/test-event-emitter-prepend.js
@@ -21,12 +21,12 @@ myEE.emit('foo');
// Verify that the listener must be a function
common.expectsError(() => {
const ee = new EventEmitter();
-
ee.prependOnceListener('foo', null);
}, {
code: 'ERR_INVALID_ARG_TYPE',
type: TypeError,
- message: 'The "listener" argument must be of type Function'
+ message: 'The "listener" argument must be of type Function. ' +
+ 'Received type object'
});
// Test fallback if prependListener is undefined.
diff --git a/test/parallel/test-event-emitter-remove-listeners.js b/test/parallel/test-event-emitter-remove-listeners.js
index 75a4c87650..925f828f93 100644
--- a/test/parallel/test-event-emitter-remove-listeners.js
+++ b/test/parallel/test-event-emitter-remove-listeners.js
@@ -146,12 +146,12 @@ function listener2() {}
// Verify that the removed listener must be a function
common.expectsError(() => {
const ee = new EventEmitter();
-
ee.removeListener('foo', null);
}, {
code: 'ERR_INVALID_ARG_TYPE',
type: TypeError,
- message: 'The "listener" argument must be of type Function'
+ message: 'The "listener" argument must be of type Function. ' +
+ 'Received type object'
});
{
diff --git a/test/parallel/test-fs-access.js b/test/parallel/test-fs-access.js
index 81070286eb..054068def1 100644
--- a/test/parallel/test-fs-access.js
+++ b/test/parallel/test-fs-access.js
@@ -97,7 +97,8 @@ common.expectsError(
{
code: 'ERR_INVALID_ARG_TYPE',
type: TypeError,
- message: 'The "path" argument must be one of type string, Buffer, or URL'
+ message: 'The "path" argument must be one of type string, Buffer, or URL.' +
+ ' Received type number'
}
);
diff --git a/test/parallel/test-fs-buffer.js b/test/parallel/test-fs-buffer.js
index c4ab80a429..1e898d3891 100644
--- a/test/parallel/test-fs-buffer.js
+++ b/test/parallel/test-fs-buffer.js
@@ -25,7 +25,8 @@ common.expectsError(
{
code: 'ERR_INVALID_ARG_TYPE',
type: TypeError,
- message: 'The "path" argument must be one of type string, Buffer, or URL'
+ message: 'The "path" argument must be one of type string, Buffer, or URL.' +
+ ' Received type boolean'
}
);
diff --git a/test/parallel/test-fs-chmod.js b/test/parallel/test-fs-chmod.js
index 7c1b14ff24..a167fa49ba 100644
--- a/test/parallel/test-fs-chmod.js
+++ b/test/parallel/test-fs-chmod.js
@@ -146,40 +146,25 @@ if (fs.lchmod) {
}));
}
-['', false, null, undefined, {}, []].forEach((i) => {
- common.expectsError(
- () => fs.fchmod(i, 0o000),
- {
- code: 'ERR_INVALID_ARG_TYPE',
- type: TypeError,
- message: 'The "fd" argument must be of type integer'
- }
- );
- common.expectsError(
- () => fs.fchmodSync(i, 0o000),
- {
- code: 'ERR_INVALID_ARG_TYPE',
- type: TypeError,
- message: 'The "fd" argument must be of type integer'
- }
- );
+['', false, null, undefined, {}, []].forEach((input) => {
+ const errObj = {
+ code: 'ERR_INVALID_ARG_TYPE',
+ name: 'TypeError [ERR_INVALID_ARG_TYPE]',
+ message: 'The "fd" argument must be of type integer'
+ };
+ assert.throws(() => fs.fchmod(input, 0o000), errObj);
+ assert.throws(() => fs.fchmodSync(input, 0o000), errObj);
});
-[false, 1, {}, [], null, undefined].forEach((i) => {
- common.expectsError(
- () => fs.chmod(i, 1, common.mustNotCall()),
- {
- code: 'ERR_INVALID_ARG_TYPE',
- type: TypeError
- }
- );
- common.expectsError(
- () => fs.chmodSync(i, 1),
- {
- code: 'ERR_INVALID_ARG_TYPE',
- type: TypeError
- }
- );
+[false, 1, {}, [], null, undefined].forEach((input) => {
+ const errObj = {
+ code: 'ERR_INVALID_ARG_TYPE',
+ name: 'TypeError [ERR_INVALID_ARG_TYPE]',
+ message: 'The "path" argument must be one of type string, Buffer, or URL.' +
+ ` Received type ${typeof input}`
+ };
+ assert.throws(() => fs.chmod(input, 1, common.mustNotCall()), errObj);
+ assert.throws(() => fs.chmodSync(input, 1), errObj);
});
process.on('exit', function() {
diff --git a/test/parallel/test-fs-close-errors.js b/test/parallel/test-fs-close-errors.js
index f81d96c056..3be8b4ce33 100644
--- a/test/parallel/test-fs-close-errors.js
+++ b/test/parallel/test-fs-close-errors.js
@@ -3,24 +3,16 @@
// This tests that the errors thrown from fs.close and fs.closeSync
// include the desired properties
-const common = require('../common');
+require('../common');
+const assert = require('assert');
const fs = require('fs');
-['', false, null, undefined, {}, []].forEach((i) => {
- common.expectsError(
- () => fs.close(i),
- {
- code: 'ERR_INVALID_ARG_TYPE',
- type: TypeError,
- message: 'The "fd" argument must be of type integer'
- }
- );
- common.expectsError(
- () => fs.closeSync(i),
- {
- code: 'ERR_INVALID_ARG_TYPE',
- type: TypeError,
- message: 'The "fd" argument must be of type integer'
- }
- );
+['', false, null, undefined, {}, []].forEach((input) => {
+ const errObj = {
+ code: 'ERR_INVALID_ARG_TYPE',
+ name: 'TypeError [ERR_INVALID_ARG_TYPE]',
+ message: 'The "fd" argument must be of type integer'
+ };
+ assert.throws(() => fs.close(input), errObj);
+ assert.throws(() => fs.closeSync(input), errObj);
});
diff --git a/test/parallel/test-fs-read-type.js b/test/parallel/test-fs-read-type.js
index 3338410bec..b47a7be177 100644
--- a/test/parallel/test-fs-read-type.js
+++ b/test/parallel/test-fs-read-type.js
@@ -14,7 +14,8 @@ common.expectsError(
{
code: 'ERR_INVALID_ARG_TYPE',
type: TypeError,
- message: 'The "buffer" argument must be one of type Buffer or Uint8Array'
+ message: 'The "buffer" argument must be one of type Buffer or Uint8Array.' +
+ ' Received type number'
}
);
@@ -26,8 +27,11 @@ common.expectsError(
expected.length,
0,
common.mustNotCall());
- }, { code: 'ERR_INVALID_ARG_TYPE', type: TypeError,
- message: 'The "fd" argument must be of type integer' });
+ }, {
+ code: 'ERR_INVALID_ARG_TYPE',
+ type: TypeError,
+ message: 'The "fd" argument must be of type integer'
+ });
});
common.expectsError(() => {
@@ -56,7 +60,8 @@ common.expectsError(
{
code: 'ERR_INVALID_ARG_TYPE',
type: TypeError,
- message: 'The "buffer" argument must be one of type Buffer or Uint8Array'
+ message: 'The "buffer" argument must be one of type Buffer or Uint8Array.' +
+ ' Received type number'
}
);
@@ -67,8 +72,11 @@ common.expectsError(
0,
expected.length,
0);
- }, { code: 'ERR_INVALID_ARG_TYPE', type: TypeError,
- message: 'The "fd" argument must be of type integer' });
+ }, {
+ code: 'ERR_INVALID_ARG_TYPE',
+ type: TypeError,
+ message: 'The "fd" argument must be of type integer'
+ });
});
common.expectsError(() => {
diff --git a/test/parallel/test-fs-readfile-error.js b/test/parallel/test-fs-readfile-error.js
index 97633c9a88..fe6174c577 100644
--- a/test/parallel/test-fs-readfile-error.js
+++ b/test/parallel/test-fs-readfile-error.js
@@ -60,7 +60,8 @@ common.expectsError(
() => { fs.readFile(() => {}, common.mustNotCall()); },
{
code: 'ERR_INVALID_ARG_TYPE',
- message: 'The "path" argument must be one of type string, Buffer, or URL',
+ message: 'The "path" argument must be one of type string, Buffer, or URL.' +
+ ' Received type function',
type: TypeError
}
);
diff --git a/test/parallel/test-fs-rename-type-check.js b/test/parallel/test-fs-rename-type-check.js
index 68126e9f7e..b8f0549f0c 100644
--- a/test/parallel/test-fs-rename-type-check.js
+++ b/test/parallel/test-fs-rename-type-check.js
@@ -1,43 +1,41 @@
'use strict';
const common = require('../common');
+const assert = require('assert');
const fs = require('fs');
-[false, 1, [], {}, null, undefined].forEach((i) => {
- common.expectsError(
- () => fs.rename(i, 'does-not-exist', common.mustNotCall()),
+[false, 1, [], {}, null, undefined].forEach((input) => {
+ const type = `of type string, Buffer, or URL. Received type ${typeof input}`;
+ assert.throws(
+ () => fs.rename(input, 'does-not-exist', common.mustNotCall()),
{
code: 'ERR_INVALID_ARG_TYPE',
- type: TypeError,
- message:
- 'The "oldPath" argument must be one of type string, Buffer, or URL'
+ name: 'TypeError [ERR_INVALID_ARG_TYPE]',
+ message: `The "oldPath" argument must be one ${type}`
}
);
- common.expectsError(
- () => fs.rename('does-not-exist', i, common.mustNotCall()),
+ assert.throws(
+ () => fs.rename('does-not-exist', input, common.mustNotCall()),
{
code: 'ERR_INVALID_ARG_TYPE',
- type: TypeError,
- message:
- 'The "newPath" argument must be one of type string, Buffer, or URL'
+ name: 'TypeError [ERR_INVALID_ARG_TYPE]',
+ message: `The "newPath" argument must be one ${type}`
}
);
- common.expectsError(
- () => fs.renameSync(i, 'does-not-exist'),
+ assert.throws(
+ () => fs.renameSync(input, 'does-not-exist'),
{
code: 'ERR_INVALID_ARG_TYPE',
- type: TypeError,
- message:
- 'The "oldPath" argument must be one of type string, Buffer, or URL'
+ name: 'TypeError [ERR_INVALID_ARG_TYPE]',
+ message: `The "oldPath" argument must be one ${type}`
}
);
- common.expectsError(
- () => fs.renameSync('does-not-exist', i),
+ assert.throws(
+ () => fs.renameSync('does-not-exist', input),
{
code: 'ERR_INVALID_ARG_TYPE',
- type: TypeError,
- message:
- 'The "newPath" argument must be one of type string, Buffer, or URL'
+ name: 'TypeError [ERR_INVALID_ARG_TYPE]',
+ message: `The "newPath" argument must be one ${type}`
}
);
});
diff --git a/test/parallel/test-fs-stat.js b/test/parallel/test-fs-stat.js
index 7f0f535d0c..bbb3281187 100644
--- a/test/parallel/test-fs-stat.js
+++ b/test/parallel/test-fs-stat.js
@@ -131,52 +131,46 @@ fs.stat(__filename, common.mustCall(function(err, s) {
});
}));
-['', false, null, undefined, {}, []].forEach((i) => {
- common.expectsError(
- () => fs.fstat(i),
- {
- code: 'ERR_INVALID_ARG_TYPE',
- type: TypeError,
- message: 'The "fd" argument must be of type integer'
- }
- );
- common.expectsError(
- () => fs.fstatSync(i),
- {
- code: 'ERR_INVALID_ARG_TYPE',
- type: TypeError,
- message: 'The "fd" argument must be of type integer'
- }
- );
+['', false, null, undefined, {}, []].forEach((input) => {
+ ['fstat', 'fstatSync'].forEach((fnName) => {
+ assert.throws(
+ () => fs[fnName](input),
+ {
+ code: 'ERR_INVALID_ARG_TYPE',
+ name: 'TypeError [ERR_INVALID_ARG_TYPE]',
+ message: 'The "fd" argument must be of type integer'
+ }
+ );
+ });
});
-[false, 1, {}, [], null, undefined].forEach((i) => {
- common.expectsError(
- () => fs.lstat(i, common.mustNotCall()),
+[false, 1, {}, [], null, undefined].forEach((input) => {
+ assert.throws(
+ () => fs.lstat(input, common.mustNotCall()),
{
code: 'ERR_INVALID_ARG_TYPE',
- type: TypeError
+ name: 'TypeError [ERR_INVALID_ARG_TYPE]'
}
);
- common.expectsError(
- () => fs.lstatSync(i),
+ assert.throws(
+ () => fs.lstatSync(input),
{
code: 'ERR_INVALID_ARG_TYPE',
- type: TypeError
+ name: 'TypeError [ERR_INVALID_ARG_TYPE]'
}
);
- common.expectsError(
- () => fs.stat(i, common.mustNotCall()),
+ assert.throws(
+ () => fs.stat(input, common.mustNotCall()),
{
code: 'ERR_INVALID_ARG_TYPE',
- type: TypeError
+ name: 'TypeError [ERR_INVALID_ARG_TYPE]'
}
);
- common.expectsError(
- () => fs.statSync(i),
+ assert.throws(
+ () => fs.statSync(input),
{
code: 'ERR_INVALID_ARG_TYPE',
- type: TypeError
+ name: 'TypeError [ERR_INVALID_ARG_TYPE]'
}
);
});
diff --git a/test/parallel/test-fs-truncate.js b/test/parallel/test-fs-truncate.js
index 28a9852d82..e0d69defe7 100644
--- a/test/parallel/test-fs-truncate.js
+++ b/test/parallel/test-fs-truncate.js
@@ -182,12 +182,12 @@ function testFtruncate(cb) {
const fd = fs.openSync(file5, 'r+');
process.on('exit', () => fs.closeSync(fd));
- ['', false, null, {}, []].forEach((i) => {
- common.expectsError(
- () => fs.ftruncate(fd, i),
+ ['', false, null, {}, []].forEach((input) => {
+ assert.throws(
+ () => fs.ftruncate(fd, input),
{
code: 'ERR_INVALID_ARG_TYPE',
- type: TypeError,
+ name: 'TypeError [ERR_INVALID_ARG_TYPE]',
message: 'The "len" argument must be of type integer'
}
);
@@ -210,21 +210,15 @@ function testFtruncate(cb) {
}));
}
-['', false, null, undefined, {}, []].forEach((i) => {
- common.expectsError(
- () => fs.ftruncate(i),
- {
- code: 'ERR_INVALID_ARG_TYPE',
- type: TypeError,
- message: 'The "fd" argument must be of type integer'
- }
- );
- common.expectsError(
- () => fs.ftruncateSync(i),
- {
- code: 'ERR_INVALID_ARG_TYPE',
- type: TypeError,
- message: 'The "fd" argument must be of type integer'
- }
- );
+['', false, null, undefined, {}, []].forEach((input) => {
+ ['ftruncate', 'ftruncateSync'].forEach((fnName) => {
+ assert.throws(
+ () => fs[fnName](input),
+ {
+ code: 'ERR_INVALID_ARG_TYPE',
+ name: 'TypeError [ERR_INVALID_ARG_TYPE]',
+ message: 'The "fd" argument must be of type integer'
+ }
+ );
+ });
});
diff --git a/test/parallel/test-fs-watch.js b/test/parallel/test-fs-watch.js
index 24600b79ce..a6a14465e2 100644
--- a/test/parallel/test-fs-watch.js
+++ b/test/parallel/test-fs-watch.js
@@ -79,14 +79,14 @@ for (const testCase of cases) {
}, 100);
}
-[false, 1, {}, [], null, undefined].forEach((i) => {
+[false, 1, {}, [], null, undefined].forEach((input) => {
common.expectsError(
- () => fs.watch(i, common.mustNotCall()),
+ () => fs.watch(input, common.mustNotCall()),
{
code: 'ERR_INVALID_ARG_TYPE',
type: TypeError,
- message: 'The "filename" argument must be one of ' +
- 'type string, Buffer, or URL'
+ message: 'The "filename" argument must be one of type string, Buffer, ' +
+ `or URL. Received type ${typeof input}`
}
);
});
diff --git a/test/parallel/test-http-mutable-headers.js b/test/parallel/test-http-mutable-headers.js
index 2473a08eb1..0ff05f234c 100644
--- a/test/parallel/test-http-mutable-headers.js
+++ b/test/parallel/test-http-mutable-headers.js
@@ -71,7 +71,8 @@ const s = http.createServer(common.mustCall((req, res) => {
{
code: 'ERR_INVALID_ARG_TYPE',
type: TypeError,
- message: 'The "name" argument must be of type string'
+ message: 'The "name" argument must be of type string. ' +
+ 'Received type undefined'
}
);
common.expectsError(
@@ -79,7 +80,8 @@ const s = http.createServer(common.mustCall((req, res) => {
{
code: 'ERR_INVALID_ARG_TYPE',
type: TypeError,
- message: 'The "name" argument must be of type string'
+ message: 'The "name" argument must be of type string. ' +
+ 'Received type undefined'
}
);
@@ -122,7 +124,8 @@ const s = http.createServer(common.mustCall((req, res) => {
{
code: 'ERR_INVALID_ARG_TYPE',
type: TypeError,
- message: 'The "name" argument must be of type string'
+ message: 'The "name" argument must be of type string. ' +
+ `Received type ${typeof val}`
}
);
});
diff --git a/test/parallel/test-http-outgoing-proto.js b/test/parallel/test-http-outgoing-proto.js
index f223bc5b9d..0070f53994 100644
--- a/test/parallel/test-http-outgoing-proto.js
+++ b/test/parallel/test-http-outgoing-proto.js
@@ -79,7 +79,8 @@ common.expectsError(() => {
}, {
code: 'ERR_INVALID_ARG_TYPE',
type: TypeError,
- message: 'The first argument must be one of type string or Buffer'
+ message: 'The first argument must be one of type string or Buffer. ' +
+ 'Received type undefined'
});
common.expectsError(() => {
@@ -88,7 +89,8 @@ common.expectsError(() => {
}, {
code: 'ERR_INVALID_ARG_TYPE',
type: TypeError,
- message: 'The first argument must be one of type string or Buffer'
+ message: 'The first argument must be one of type string or Buffer. ' +
+ 'Received type number'
});
// addTrailers()
diff --git a/test/parallel/test-http2-client-setNextStreamID-errors.js b/test/parallel/test-http2-client-setNextStreamID-errors.js
index 0c982061b8..3fb4728b7d 100644
--- a/test/parallel/test-http2-client-setNextStreamID-errors.js
+++ b/test/parallel/test-http2-client-setNextStreamID-errors.js
@@ -48,7 +48,8 @@ server.listen(0, common.mustCall(() => {
{
type: TypeError,
code: 'ERR_INVALID_ARG_TYPE',
- message: 'The "id" argument must be of type number'
+ message: 'The "id" argument must be of type number. Received type ' +
+ typeof value
}
);
});
diff --git a/test/parallel/test-http2-compat-serverrequest-headers.js b/test/parallel/test-http2-compat-serverrequest-headers.js
index 5843104c01..f445dc46d8 100644
--- a/test/parallel/test-http2-compat-serverrequest-headers.js
+++ b/test/parallel/test-http2-compat-serverrequest-headers.js
@@ -53,11 +53,11 @@ server.listen(0, common.mustCall(function() {
message: 'The "method" argument must be of type string'
}
);
- common.expectsError(
+ assert.throws(
() => request.method = true,
{
code: 'ERR_INVALID_ARG_TYPE',
- type: TypeError,
+ name: 'TypeError [ERR_INVALID_ARG_TYPE]',
message: 'The "method" argument must be of type string'
}
);
diff --git a/test/parallel/test-http2-compat-serverresponse-headers.js b/test/parallel/test-http2-compat-serverresponse-headers.js
index 7b5313b8e7..8c8c4867dd 100644
--- a/test/parallel/test-http2-compat-serverresponse-headers.js
+++ b/test/parallel/test-http2-compat-serverresponse-headers.js
@@ -41,30 +41,17 @@ server.listen(0, common.mustCall(function() {
response.removeHeader(denormalised);
assert.strictEqual(response.hasHeader(denormalised), false);
- common.expectsError(
- () => response.hasHeader(),
- {
- code: 'ERR_INVALID_ARG_TYPE',
- type: TypeError,
- message: 'The "name" argument must be of type string'
- }
- );
- common.expectsError(
- () => response.getHeader(),
- {
- code: 'ERR_INVALID_ARG_TYPE',
- type: TypeError,
- message: 'The "name" argument must be of type string'
- }
- );
- common.expectsError(
- () => response.removeHeader(),
- {
- code: 'ERR_INVALID_ARG_TYPE',
- type: TypeError,
- message: 'The "name" argument must be of type string'
- }
- );
+ ['hasHeader', 'getHeader', 'removeHeader'].forEach((fnName) => {
+ assert.throws(
+ () => response[fnName](),
+ {
+ code: 'ERR_INVALID_ARG_TYPE',
+ name: 'TypeError [ERR_INVALID_ARG_TYPE]',
+ message: 'The "name" argument must be of type string. Received ' +
+ 'type undefined'
+ }
+ );
+ });
[
':status',
@@ -95,11 +82,12 @@ server.listen(0, common.mustCall(function() {
message: 'Invalid value "undefined" for header "foo-bar"'
});
common.expectsError(
- () => response.setHeader(), // header name undefined
+ () => response.setHeader(), // Header name undefined
{
code: 'ERR_INVALID_ARG_TYPE',
type: TypeError,
- message: 'The "name" argument must be of type string'
+ message: 'The "name" argument must be of type string. Received type ' +
+ 'undefined'
}
);
common.expectsError(
diff --git a/test/parallel/test-http2-compat-serverresponse-trailers.js b/test/parallel/test-http2-compat-serverresponse-trailers.js
index 66ad8843fa..fe722c84ee 100644
--- a/test/parallel/test-http2-compat-serverresponse-trailers.js
+++ b/test/parallel/test-http2-compat-serverresponse-trailers.js
@@ -40,11 +40,12 @@ server.listen(0, common.mustCall(() => {
}
);
common.expectsError(
- () => response.setTrailer(), // trailer name undefined
+ () => response.setTrailer(), // Trailer name undefined
{
code: 'ERR_INVALID_ARG_TYPE',
type: TypeError,
- message: 'The "name" argument must be of type string'
+ message: 'The "name" argument must be of type string. Received type ' +
+ 'undefined'
}
);
common.expectsError(
diff --git a/test/parallel/test-http2-createsecureserver-nooptions.js b/test/parallel/test-http2-createsecureserver-nooptions.js
index 71764f5783..767797febc 100644
--- a/test/parallel/test-http2-createsecureserver-nooptions.js
+++ b/test/parallel/test-http2-createsecureserver-nooptions.js
@@ -4,19 +4,19 @@ const common = require('../common');
if (!common.hasCrypto)
common.skip('missing crypto');
+const assert = require('assert');
const http2 = require('http2');
-const invalidOptions = [() => {}, 1, 'test', null];
-const invalidArgTypeError = {
- type: TypeError,
- code: 'ERR_INVALID_ARG_TYPE',
- message: 'The "options" argument must be of type Object'
-};
-
// Error if options are not passed to createSecureServer
+const invalidOptions = [() => {}, 1, 'test', null];
invalidOptions.forEach((invalidOption) => {
- common.expectsError(
+ assert.throws(
() => http2.createSecureServer(invalidOption),
- invalidArgTypeError
+ {
+ name: 'TypeError [ERR_INVALID_ARG_TYPE]',
+ code: 'ERR_INVALID_ARG_TYPE',
+ message: 'The "options" argument must be of type Object. Received ' +
+ `type ${typeof invalidOption}`
+ }
);
});
diff --git a/test/parallel/test-http2-getpackedsettings.js b/test/parallel/test-http2-getpackedsettings.js
index 56b9632113..77c8cf442f 100644
--- a/test/parallel/test-http2-getpackedsettings.js
+++ b/test/parallel/test-http2-getpackedsettings.js
@@ -99,14 +99,15 @@ http2.getPackedSettings({ enablePush: false });
0x00, 0x00, 0x00, 0x64, 0x00, 0x06, 0x00, 0x00, 0x00, 0x64,
0x00, 0x02, 0x00, 0x00, 0x00, 0x01]);
- [1, true, '', [], {}, NaN].forEach((i) => {
+ [1, true, '', [], {}, NaN].forEach((input) => {
common.expectsError(() => {
- http2.getUnpackedSettings(i);
+ http2.getUnpackedSettings(input);
}, {
code: 'ERR_INVALID_ARG_TYPE',
type: TypeError,
message:
- 'The "buf" argument must be one of type Buffer, TypedArray, or DataView'
+ 'The "buf" argument must be one of type Buffer, TypedArray, or ' +
+ `DataView. Received type ${typeof input}`
});
});
diff --git a/test/parallel/test-http2-invalidargtypes-errors.js b/test/parallel/test-http2-invalidargtypes-errors.js
index ff189a2977..d7c451569e 100644
--- a/test/parallel/test-http2-invalidargtypes-errors.js
+++ b/test/parallel/test-http2-invalidargtypes-errors.js
@@ -13,7 +13,8 @@ server.on('stream', common.mustCall((stream) => {
{
code: 'ERR_INVALID_ARG_TYPE',
type: TypeError,
- message: 'The "code" argument must be of type number'
+ message: 'The "code" argument must be of type number. ' +
+ 'Received type string'
}
);
stream.respond();
diff --git a/test/parallel/test-http2-misc-util.js b/test/parallel/test-http2-misc-util.js
index 993424f771..14dc4a5366 100644
--- a/test/parallel/test-http2-misc-util.js
+++ b/test/parallel/test-http2-misc-util.js
@@ -35,7 +35,7 @@ common.expectsError(
{
code: 'ERR_INVALID_ARG_TYPE',
type: TypeError,
- message: 'The "test" argument must be of type Object'
+ message: 'The "test" argument must be of type Object. Received type string'
});
common.expectsError(
@@ -43,7 +43,7 @@ common.expectsError(
{
code: 'ERR_INVALID_ARG_TYPE',
type: TypeError,
- message: 'The "test" argument must be of type Date'
+ message: 'The "test" argument must be of type Date. Received type string'
});
assertIsObject({}, 'test');
diff --git a/test/parallel/test-http2-ping.js b/test/parallel/test-http2-ping.js
index 0280f656d0..87c8c29d1b 100644
--- a/test/parallel/test-http2-ping.js
+++ b/test/parallel/test-http2-ping.js
@@ -81,14 +81,14 @@ server.listen(0, common.mustCall(() => {
// should throw if payload is not of type ArrayBufferView
{
- [1, true, {}, []].forEach((invalidPayload) =>
+ [1, true, {}, []].forEach((payload) =>
common.expectsError(
- () => client.ping(invalidPayload),
+ () => client.ping(payload),
{
type: TypeError,
code: 'ERR_INVALID_ARG_TYPE',
- message: 'The "payload" argument must be one of type' +
- ' Buffer, TypedArray, or DataView'
+ message: 'The "payload" argument must be one of type Buffer, ' +
+ `TypedArray, or DataView. Received type ${typeof payload}`
}
)
);
diff --git a/test/parallel/test-http2-respond-file-fd-errors.js b/test/parallel/test-http2-respond-file-fd-errors.js
index 44876b60e1..5532e81855 100644
--- a/test/parallel/test-http2-respond-file-fd-errors.js
+++ b/test/parallel/test-http2-respond-file-fd-errors.js
@@ -43,7 +43,8 @@ server.on('stream', common.mustCall((stream) => {
{
type: TypeError,
code: 'ERR_INVALID_ARG_TYPE',
- message: 'The "fd" argument must be of type number'
+ message: 'The "fd" argument must be of type number. Received type ' +
+ typeof types[type]
}
);
});
diff --git a/test/parallel/test-http2-server-shutdown-options-errors.js b/test/parallel/test-http2-server-shutdown-options-errors.js
index 6cee8f2572..95849411a2 100644
--- a/test/parallel/test-http2-server-shutdown-options-errors.js
+++ b/test/parallel/test-http2-server-shutdown-options-errors.js
@@ -18,30 +18,32 @@ const types = [
server.on('stream', common.mustCall((stream) => {
const session = stream.session;
- types.forEach((i) => {
+ types.forEach((input) => {
common.expectsError(
- () => session.goaway(i),
+ () => session.goaway(input),
{
code: 'ERR_INVALID_ARG_TYPE',
type: TypeError,
- message: 'The "code" argument must be of type number'
+ message: 'The "code" argument must be of type number. Received type ' +
+ typeof input
}
);
common.expectsError(
- () => session.goaway(0, i),
+ () => session.goaway(0, input),
{
code: 'ERR_INVALID_ARG_TYPE',
type: TypeError,
- message: 'The "lastStreamID" argument must be of type number'
+ message: 'The "lastStreamID" argument must be of type number. ' +
+ `Received type ${typeof input}`
}
);
common.expectsError(
- () => session.goaway(0, 0, i),
+ () => session.goaway(0, 0, input),
{
code: 'ERR_INVALID_ARG_TYPE',
type: TypeError,
message: 'The "opaqueData" argument must be one of type Buffer, ' +
- 'TypedArray, or DataView'
+ `TypedArray, or DataView. Received type ${typeof input}`
}
);
});
diff --git a/test/parallel/test-http2-util-asserts.js b/test/parallel/test-http2-util-asserts.js
index bfed09de4f..3db74e2f2e 100644
--- a/test/parallel/test-http2-util-asserts.js
+++ b/test/parallel/test-http2-util-asserts.js
@@ -25,11 +25,12 @@ const {
Infinity,
[],
[{}]
-].forEach((i) => {
- common.expectsError(() => assertIsObject(i, 'foo', 'Object'),
+].forEach((input) => {
+ common.expectsError(() => assertIsObject(input, 'foo', 'Object'),
{
code: 'ERR_INVALID_ARG_TYPE',
- message: /^The "foo" argument must be of type Object$/
+ message: 'The "foo" argument must be of type Object. ' +
+ `Received type ${typeof input}`
});
});
diff --git a/test/parallel/test-https-options-boolean-check.js b/test/parallel/test-https-options-boolean-check.js
index fa223aa887..cefa9c1d0a 100644
--- a/test/parallel/test-https-options-boolean-check.js
+++ b/test/parallel/test-https-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 https = require('https');
function toArrayBuffer(buf) {
@@ -38,8 +39,6 @@ const caArrBuff = toArrayBuffer(caCert);
const keyDataView = toDataView(keyBuff);
const certDataView = toDataView(certBuff);
const caArrDataView = toDataView(caCert);
-const invalidKeyRE = /^The "key" argument must be one of type string, Buffer, TypedArray, or DataView$/;
-const invalidCertRE = /^The "cert" argument must be one of type string, Buffer, TypedArray, or DataView$/;
// Checks to ensure https.createServer doesn't throw an error
// Format ['key', 'cert']
@@ -63,50 +62,59 @@ const invalidCertRE = /^The "cert" argument must be one of type string, Buffer,
[false, [certStr, certStr2]],
[[{ pem: keyBuff }], false],
[[{ pem: keyBuff }, { pem: keyBuff }], false]
-].forEach((params) => {
- https.createServer({
- key: params[0],
- cert: params[1]
- });
+].forEach(([key, cert]) => {
+ https.createServer({ key, cert });
});
// Checks to ensure https.createServer predictably throws an error
// Format ['key', 'cert', 'expected message']
[
- [true, certBuff, invalidKeyRE],
- [keyBuff, true, invalidCertRE],
- [true, certStr, invalidKeyRE],
- [keyStr, true, invalidCertRE],
- [true, certArrBuff, invalidKeyRE],
- [keyArrBuff, true, invalidCertRE],
- [true, certDataView, invalidKeyRE],
- [keyDataView, true, invalidCertRE],
- [true, true, invalidCertRE],
- [true, false, invalidKeyRE],
- [false, true, invalidCertRE],
- [true, false, invalidKeyRE],
- [{ pem: keyBuff }, false, invalidKeyRE],
- [false, { pem: keyBuff }, invalidCertRE],
- [1, false, invalidKeyRE],
- [false, 1, invalidCertRE],
- [[keyBuff, true], [certBuff, certBuff2], invalidKeyRE],
- [[true, keyStr2], [certStr, certStr2], invalidKeyRE],
- [[keyBuff, keyBuff2], [true, certBuff2], invalidCertRE],
- [[keyStr, keyStr2], [certStr, true], invalidCertRE],
- [[true, false], [certBuff, certBuff2], invalidKeyRE],
- [[keyStr, keyStr2], [true, false], invalidCertRE],
- [[keyStr, keyStr2], true, invalidCertRE],
- [true, [certBuff, certBuff2], invalidKeyRE]
-].forEach((params) => {
- common.expectsError(() => {
- https.createServer({
- key: params[0],
- cert: params[1]
- });
+ [true, certBuff],
+ [true, certStr],
+ [true, certArrBuff],
+ [true, certDataView],
+ [true, false],
+ [true, false],
+ [{ pem: keyBuff }, false, 'pem'],
+ [1, false],
+ [[keyBuff, true], [certBuff, certBuff2], 1],
+ [[true, keyStr2], [certStr, certStr2], 0],
+ [[true, false], [certBuff, certBuff2], 0],
+ [true, [certBuff, certBuff2]]
+].forEach(([key, cert, index]) => {
+ const type = typeof (index === undefined ? key : key[index]);
+ assert.throws(() => {
+ https.createServer({ key, cert });
+ }, {
+ code: 'ERR_INVALID_ARG_TYPE',
+ name: 'TypeError [ERR_INVALID_ARG_TYPE]',
+ message: 'The "key" argument must be one of type string, Buffer, ' +
+ `TypedArray, or DataView. Received type ${type}`
+ });
+});
+
+[
+ [keyBuff, true],
+ [keyStr, true],
+ [keyArrBuff, true],
+ [keyDataView, true],
+ [true, true],
+ [false, true],
+ [false, { pem: keyBuff }, 'pem'],
+ [false, 1],
+ [[keyBuff, keyBuff2], [true, certBuff2], 0],
+ [[keyStr, keyStr2], [certStr, true], 1],
+ [[keyStr, keyStr2], [true, false], 0],
+ [[keyStr, keyStr2], true],
+].forEach(([key, cert, index]) => {
+ const type = typeof (index === undefined ? cert : cert[index]);
+ assert.throws(() => {
+ https.createServer({ key, cert });
}, {
code: 'ERR_INVALID_ARG_TYPE',
- type: TypeError,
- message: params[2]
+ name: 'TypeError [ERR_INVALID_ARG_TYPE]',
+ message: 'The "cert" argument must be one of type string, Buffer, ' +
+ `TypedArray, or DataView. Received type ${type}`
});
});
@@ -120,12 +128,8 @@ const invalidCertRE = /^The "cert" argument must be one of type string, Buffer,
[keyBuff, certBuff, caArrBuff],
[keyBuff, certBuff, caArrDataView],
[keyBuff, certBuff, false],
-].forEach((params) => {
- https.createServer({
- key: params[0],
- cert: params[1],
- ca: params[2]
- });
+].forEach(([key, cert, ca]) => {
+ https.createServer({ key, cert, ca });
});
// Checks to ensure https.createServer throws an error for CA assignment
@@ -135,17 +139,15 @@ const invalidCertRE = /^The "cert" argument must be one of type string, Buffer,
[keyBuff, certBuff, {}],
[keyBuff, certBuff, 1],
[keyBuff, certBuff, true],
- [keyBuff, certBuff, [caCert, true]]
-].forEach((params) => {
- common.expectsError(() => {
- https.createServer({
- key: params[0],
- cert: params[1],
- ca: params[2]
- });
+ [keyBuff, certBuff, [caCert, true], 1]
+].forEach(([key, cert, ca, index]) => {
+ const type = typeof (index ? ca[index] : ca);
+ assert.throws(() => {
+ https.createServer({ key, cert, ca });
}, {
code: 'ERR_INVALID_ARG_TYPE',
- type: TypeError,
- message: /^The "ca" argument must be one of type string, Buffer, TypedArray, or DataView$/
+ name: 'TypeError [ERR_INVALID_ARG_TYPE]',
+ message: 'The "ca" argument must be one of type string, Buffer, ' +
+ `TypedArray, or DataView. Received type ${type}`
});
});
diff --git a/test/parallel/test-icu-transcode.js b/test/parallel/test-icu-transcode.js
index 4f51e72304..07a7f07324 100644
--- a/test/parallel/test-icu-transcode.js
+++ b/test/parallel/test-icu-transcode.js
@@ -47,7 +47,7 @@ common.expectsError(
type: TypeError,
code: 'ERR_INVALID_ARG_TYPE',
message: 'The "source" argument must be one of type Buffer ' +
- 'or Uint8Array. Received type null'
+ 'or Uint8Array. Received type object'
}
);
diff --git a/test/parallel/test-internal-errors.js b/test/parallel/test-internal-errors.js
index dd6491ebce..7521633c62 100644
--- a/test/parallel/test-internal-errors.js
+++ b/test/parallel/test-internal-errors.js
@@ -90,36 +90,6 @@ common.expectsError(() => {
message: /.+ does not match \S/
});
-// // Test ERR_INVALID_ARG_TYPE
-assert.strictEqual(errors.message('ERR_INVALID_ARG_TYPE', ['a', 'b']),
- 'The "a" argument must be of type b');
-assert.strictEqual(errors.message('ERR_INVALID_ARG_TYPE', ['a', ['b']]),
- 'The "a" argument must be of type b');
-assert.strictEqual(errors.message('ERR_INVALID_ARG_TYPE', ['a', ['b', 'c']]),
- 'The "a" argument must be one of type b or c');
-assert.strictEqual(errors.message('ERR_INVALID_ARG_TYPE',
- ['a', ['b', 'c', 'd']]),
- 'The "a" argument must be one of type b, c, or d');
-assert.strictEqual(errors.message('ERR_INVALID_ARG_TYPE', ['a', 'b', 'c']),
- 'The "a" argument must be of type b. Received type string');
-assert.strictEqual(errors.message('ERR_INVALID_ARG_TYPE',
- ['a', 'b', undefined]),
- 'The "a" argument must be of type b. Received type ' +
- 'undefined');
-assert.strictEqual(errors.message('ERR_INVALID_ARG_TYPE',
- ['a', 'b', null]),
- 'The "a" argument must be of type b. Received type null');
-assert.strictEqual(errors.message('ERR_INVALID_ARG_TYPE', ['a', 'not b']),
- 'The "a" argument must not be of type b');
-assert.strictEqual(errors.message('ERR_INVALID_ARG_TYPE', ['a.b', 'not c']),
- 'The "a.b" property must not be of type c');
-assert.strictEqual(
- errors.message('ERR_INVALID_ARG_TYPE', ['first argument', 'c']),
- 'The first argument must be of type c');
-assert.strictEqual(
- errors.message('ERR_INVALID_ARG_TYPE', [['a', 'b', 'c'], 'not d']),
- 'The "a", "b", "c" arguments must not be of type d');
-
// Test ERR_INVALID_FD_TYPE
assert.strictEqual(errors.message('ERR_INVALID_FD_TYPE', ['a']),
'Unsupported fd type: a');
diff --git a/test/parallel/test-net-connect-buffer.js b/test/parallel/test-net-connect-buffer.js
index 028ea22183..f58820d58e 100644
--- a/test/parallel/test-net-connect-buffer.js
+++ b/test/parallel/test-net-connect-buffer.js
@@ -62,16 +62,16 @@ tcp.listen(0, common.mustCall(function() {
undefined,
1,
1.0,
- 1 / 0,
+Infinity,
-Infinity,
[],
{}
- ].forEach((v) => {
- common.expectsError(() => socket.write(v), {
+ ].forEach((value) => {
+ common.expectsError(() => socket.write(value), {
code: 'ERR_INVALID_ARG_TYPE',
type: TypeError,
- message: 'The "chunk" argument must be one of type string or Buffer'
+ message: 'The "chunk" argument must be one of type string or Buffer. ' +
+ `Received type ${typeof value}`
});
});
diff --git a/test/parallel/test-path-parse-format.js b/test/parallel/test-path-parse-format.js
index 3586ebece1..c50093301f 100644
--- a/test/parallel/test-path-parse-format.js
+++ b/test/parallel/test-path-parse-format.js
@@ -220,10 +220,6 @@ function checkFormat(path, testCases) {
assert.strictEqual(path.format(testCase[0]), testCase[1]);
});
- function typeName(value) {
- return value === null ? 'null' : typeof value;
- }
-
[null, undefined, 1, true, false, 'string'].forEach((pathObject) => {
common.expectsError(() => {
path.format(pathObject);
@@ -231,7 +227,7 @@ function checkFormat(path, testCases) {
code: 'ERR_INVALID_ARG_TYPE',
type: TypeError,
message: 'The "pathObject" argument must be of type Object. ' +
- `Received type ${typeName(pathObject)}`
+ `Received type ${typeof pathObject}`
});
});
}
diff --git a/test/parallel/test-performance-function.js b/test/parallel/test-performance-function.js
index 0deaa0e057..57dd2871ee 100644
--- a/test/parallel/test-performance-function.js
+++ b/test/parallel/test-performance-function.js
@@ -70,12 +70,13 @@ const {
}
{
- [1, {}, [], null, undefined, Infinity].forEach((i) => {
- common.expectsError(() => performance.timerify(i),
+ [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'
+ message: 'The "fn" argument must be of type ' +
+ `Function. Received type ${typeof input}`
});
});
}
diff --git a/test/parallel/test-performanceobserver.js b/test/parallel/test-performanceobserver.js
index 2a62999522..08e07a1518 100644
--- a/test/parallel/test-performanceobserver.js
+++ b/test/parallel/test-performanceobserver.js
@@ -37,14 +37,14 @@ assert.strictEqual(counts[NODE_PERFORMANCE_ENTRY_TYPE_FUNCTION], 0);
});
const observer = new PerformanceObserver(common.mustNotCall());
- [1, null, undefined].forEach((i) => {
- //observer.observe(i);
+ [1, null, undefined].forEach((input) => {
common.expectsError(
- () => observer.observe(i),
+ () => observer.observe(input),
{
code: 'ERR_INVALID_ARG_TYPE',
type: TypeError,
- message: 'The "options" argument must be of type Object'
+ message: 'The "options" argument must be of type Object. ' +
+ `Received type ${typeof input}`
});
});
diff --git a/test/parallel/test-process-exception-capture-errors.js b/test/parallel/test-process-exception-capture-errors.js
index 7053497ada..d2f5b86177 100644
--- a/test/parallel/test-process-exception-capture-errors.js
+++ b/test/parallel/test-process-exception-capture-errors.js
@@ -6,7 +6,8 @@ common.expectsError(
{
code: 'ERR_INVALID_ARG_TYPE',
type: TypeError,
- message: 'The "fn" argument must be one of type Function or null'
+ message: 'The "fn" argument must be one of type Function or null. ' +
+ 'Received type number'
}
);
diff --git a/test/parallel/test-process-kill-pid.js b/test/parallel/test-process-kill-pid.js
index 594a2a6a0b..e69be183fb 100644
--- a/test/parallel/test-process-kill-pid.js
+++ b/test/parallel/test-process-kill-pid.js
@@ -38,24 +38,14 @@ const assert = require('assert');
//
// process.pid, String(process.pid): ourself
-const invalidPidArgument = common.expectsError({
- code: 'ERR_INVALID_ARG_TYPE',
- type: TypeError,
- message: 'The "pid" argument must be of type number'
-}, 6);
-
-assert.throws(function() { process.kill('SIGTERM'); },
- invalidPidArgument);
-assert.throws(function() { process.kill(null); },
- invalidPidArgument);
-assert.throws(function() { process.kill(undefined); },
- invalidPidArgument);
-assert.throws(function() { process.kill(+'not a number'); },
- invalidPidArgument);
-assert.throws(function() { process.kill(1 / 0); },
- invalidPidArgument);
-assert.throws(function() { process.kill(-1 / 0); },
- invalidPidArgument);
+['SIGTERM', null, undefined, NaN, Infinity, -Infinity].forEach((val) => {
+ assert.throws(() => process.kill(val), {
+ code: 'ERR_INVALID_ARG_TYPE',
+ name: 'TypeError [ERR_INVALID_ARG_TYPE]',
+ message: 'The "pid" argument must be of type number. ' +
+ `Received type ${typeof val}`
+ });
+});
// Test that kill throws an error for unknown signal names
common.expectsError(() => process.kill(0, 'test'), {
diff --git a/test/parallel/test-tls-basic-validations.js b/test/parallel/test-tls-basic-validations.js
index 501cfd91d0..a2f7c8d461 100644
--- a/test/parallel/test-tls-basic-validations.js
+++ b/test/parallel/test-tls-basic-validations.js
@@ -26,7 +26,8 @@ common.expectsError(() => tls.createServer({ handshakeTimeout: 'abcd' }),
{
code: 'ERR_INVALID_ARG_TYPE',
type: TypeError,
- message: 'The "timeout" argument must be of type number'
+ message: 'The "timeout" argument must ' +
+ 'be of type number'
}
);
diff --git a/test/parallel/test-tls-error-servername.js b/test/parallel/test-tls-error-servername.js
index 8f6d1c5c6d..c42ff2fe73 100644
--- a/test/parallel/test-tls-error-servername.js
+++ b/test/parallel/test-tls-error-servername.js
@@ -27,7 +27,8 @@ const client = connect({
client.setServername(value);
}, {
code: 'ERR_INVALID_ARG_TYPE',
- message: 'The "name" argument must be of type string'
+ message: 'The "name" argument must be of type string. ' +
+ `Received type ${typeof value}`
});
});
diff --git a/test/parallel/test-tls-no-cert-required.js b/test/parallel/test-tls-no-cert-required.js
index c6ad117831..ef1d366c91 100644
--- a/test/parallel/test-tls-no-cert-required.js
+++ b/test/parallel/test-tls-no-cert-required.js
@@ -43,7 +43,8 @@ common.expectsError(() => tls.createServer('this is not valid'),
{
code: 'ERR_INVALID_ARG_TYPE',
type: TypeError,
- message: 'The "options" argument must be of type Object'
+ message: 'The "options" argument must be of type ' +
+ 'Object. Received type string'
}
);
diff --git a/test/parallel/test-tls-options-boolean-check.js b/test/parallel/test-tls-options-boolean-check.js
index 53f595e0de..de21da63ff 100644
--- a/test/parallel/test-tls-options-boolean-check.js
+++ b/test/parallel/test-tls-options-boolean-check.js
@@ -38,8 +38,6 @@ const caArrBuff = toArrayBuffer(caCert);
const keyDataView = toDataView(keyBuff);
const certDataView = toDataView(certBuff);
const caArrDataView = toDataView(caCert);
-const invalidKeyRE = /^The "key" argument must be one of type string, Buffer, TypedArray, or DataView$/;
-const invalidCertRE = /^The "cert" argument must be one of type string, Buffer, TypedArray, or DataView$/;
// Checks to ensure tls.createServer doesn't throw an error
// Format ['key', 'cert']
@@ -70,37 +68,51 @@ const invalidCertRE = /^The "cert" argument must be one of type string, Buffer,
// Checks to ensure tls.createServer predictably throws an error
// Format ['key', 'cert', 'expected message']
[
- [true, certBuff, invalidKeyRE],
- [keyBuff, true, invalidCertRE],
- [true, certStr, invalidKeyRE],
- [keyStr, true, invalidCertRE],
- [true, certArrBuff, invalidKeyRE],
- [keyArrBuff, true, invalidCertRE],
- [true, certDataView, invalidKeyRE],
- [keyDataView, true, invalidCertRE],
- [true, true, invalidCertRE],
- [true, false, invalidKeyRE],
- [false, true, invalidCertRE],
- [true, false, invalidKeyRE],
- [{ pem: keyBuff }, false, invalidKeyRE],
- [false, { pem: keyBuff }, invalidCertRE],
- [1, false, invalidKeyRE],
- [false, 1, invalidCertRE],
- [[keyBuff, true], [certBuff, certBuff2], invalidKeyRE],
- [[true, keyStr2], [certStr, certStr2], invalidKeyRE],
- [[keyBuff, keyBuff2], [true, certBuff2], invalidCertRE],
- [[keyStr, keyStr2], [certStr, true], invalidCertRE],
- [[true, false], [certBuff, certBuff2], invalidKeyRE],
- [[keyStr, keyStr2], [true, false], invalidCertRE],
- [[keyStr, keyStr2], true, invalidCertRE],
- [true, [certBuff, certBuff2], invalidKeyRE]
-].forEach(([key, cert, message]) => {
+ [true, certBuff],
+ [true, certStr],
+ [true, certArrBuff],
+ [true, certDataView],
+ [true, false],
+ [true, false],
+ [{ pem: keyBuff }, false, 'pem'],
+ [[keyBuff, true], [certBuff, certBuff2], 1],
+ [[true, keyStr2], [certStr, certStr2], 0],
+ [[true, false], [certBuff, certBuff2], 0],
+ [true, [certBuff, certBuff2]]
+].forEach(([key, cert, index]) => {
+ const type = typeof (index === undefined ? key : key[index]);
common.expectsError(() => {
tls.createServer({ key, cert });
}, {
code: 'ERR_INVALID_ARG_TYPE',
type: TypeError,
- message
+ message: 'The "key" argument must be one of type string, Buffer, ' +
+ `TypedArray, or DataView. Received type ${type}`
+ });
+});
+
+[
+ [keyBuff, true],
+ [keyStr, true],
+ [keyArrBuff, true],
+ [keyDataView, true],
+ [true, true],
+ [false, true],
+ [false, { pem: keyBuff }, 'pem'],
+ [false, 1],
+ [[keyBuff, keyBuff2], [true, certBuff2], 0],
+ [[keyStr, keyStr2], [certStr, true], 1],
+ [[keyStr, keyStr2], [true, false], 0],
+ [[keyStr, keyStr2], true]
+].forEach(([key, cert, index]) => {
+ const type = typeof (index === undefined ? cert : cert[index]);
+ common.expectsError(() => {
+ tls.createServer({ key, cert });
+ }, {
+ code: 'ERR_INVALID_ARG_TYPE',
+ type: TypeError,
+ message: 'The "cert" argument must be one of type string, Buffer, ' +
+ `TypedArray, or DataView. Received type ${type}`
});
});
@@ -125,32 +137,16 @@ const invalidCertRE = /^The "cert" argument must be one of type string, Buffer,
[keyBuff, certBuff, {}],
[keyBuff, certBuff, 1],
[keyBuff, certBuff, true],
- [keyBuff, certBuff, [caCert, true]]
-].forEach(([key, cert, ca]) => {
- common.expectsError(() => {
- tls.createServer({ key, cert, ca });
- }, {
- code: 'ERR_INVALID_ARG_TYPE',
- type: TypeError,
- message: /^The "ca" argument must be one of type string, Buffer, TypedArray, or DataView$/
- });
-});
-
-// Checks to ensure tls.createServer throws an error for CA assignment
-// Format ['key', 'cert', 'ca']
-[
- [keyBuff, certBuff, true],
- [keyBuff, certBuff, {}],
- [keyBuff, certBuff, 1],
- [keyBuff, certBuff, true],
- [keyBuff, certBuff, [caCert, true]]
-].forEach(([key, cert, ca]) => {
+ [keyBuff, certBuff, [caCert, true], 1]
+].forEach(([key, cert, ca, index]) => {
+ const type = typeof (index === undefined ? ca : ca[index]);
common.expectsError(() => {
tls.createServer({ key, cert, ca });
}, {
code: 'ERR_INVALID_ARG_TYPE',
type: TypeError,
- message: /^The "ca" argument must be one of type string, Buffer, TypedArray, or DataView$/
+ message: 'The "ca" argument must be one of type string, Buffer, ' +
+ `TypedArray, or DataView. Received type ${type}`
});
});
diff --git a/test/parallel/test-url-format-invalid-input.js b/test/parallel/test-url-format-invalid-input.js
index 4f0f1a11d7..1a0df32657 100644
--- a/test/parallel/test-url-format-invalid-input.js
+++ b/test/parallel/test-url-format-invalid-input.js
@@ -5,7 +5,7 @@ const url = require('url');
const throwsObjsAndReportTypes = new Map([
[undefined, 'undefined'],
- [null, 'null'],
+ [null, 'object'],
[true, 'boolean'],
[false, 'boolean'],
[0, 'number'],
diff --git a/test/parallel/test-url-format-whatwg.js b/test/parallel/test-url-format-whatwg.js
index c26000cb56..26cef6063c 100644
--- a/test/parallel/test-url-format-whatwg.js
+++ b/test/parallel/test-url-format-whatwg.js
@@ -21,15 +21,17 @@ assert.strictEqual(
);
{
- const expectedErr = common.expectsError({
- code: 'ERR_INVALID_ARG_TYPE',
- type: TypeError,
- message: 'The "options" argument must be of type Object'
- }, 4);
- assert.throws(() => url.format(myURL, true), expectedErr);
- assert.throws(() => url.format(myURL, 1), expectedErr);
- assert.throws(() => url.format(myURL, 'test'), expectedErr);
- assert.throws(() => url.format(myURL, Infinity), expectedErr);
+ [true, 1, 'test', Infinity].forEach((value) => {
+ assert.throws(
+ () => url.format(myURL, value),
+ {
+ code: 'ERR_INVALID_ARG_TYPE',
+ name: 'TypeError [ERR_INVALID_ARG_TYPE]',
+ message: 'The "options" argument must be of type Object. ' +
+ `Received type ${typeof value}`
+ }
+ );
+ });
}
// Any falsy value other than undefined will be treated as false.
diff --git a/test/parallel/test-url-parse-invalid-input.js b/test/parallel/test-url-parse-invalid-input.js
index d2c7a1135a..0f113862c7 100644
--- a/test/parallel/test-url-parse-invalid-input.js
+++ b/test/parallel/test-url-parse-invalid-input.js
@@ -6,7 +6,7 @@ const url = require('url');
// https://github.com/joyent/node/issues/568
[
[undefined, 'undefined'],
- [null, 'null'],
+ [null, 'object'],
[true, 'boolean'],
[false, 'boolean'],
[0.0, 'number'],
diff --git a/test/parallel/test-util-callbackify.js b/test/parallel/test-util-callbackify.js
index d8b2de314c..9be3b132f9 100644
--- a/test/parallel/test-util-callbackify.js
+++ b/test/parallel/test-util-callbackify.js
@@ -236,7 +236,8 @@ const values = [
}, {
code: 'ERR_INVALID_ARG_TYPE',
type: TypeError,
- message: 'The "original" argument must be of type Function'
+ message: 'The "original" argument must be of type Function. ' +
+ `Received type ${typeof value}`
});
});
}
@@ -257,7 +258,8 @@ const values = [
}, {
code: 'ERR_INVALID_ARG_TYPE',
type: TypeError,
- message: 'The last argument must be of type Function'
+ message: 'The last argument must be of type Function. ' +
+ `Received type ${typeof value}`
});
});
}
diff --git a/test/parallel/test-util-deprecate-invalid-code.js b/test/parallel/test-util-deprecate-invalid-code.js
index 057e095424..635bab4252 100644
--- a/test/parallel/test-util-deprecate-invalid-code.js
+++ b/test/parallel/test-util-deprecate-invalid-code.js
@@ -7,6 +7,7 @@ const util = require('util');
common.expectsError(() => util.deprecate(() => {}, 'message', notString), {
code: 'ERR_INVALID_ARG_TYPE',
type: TypeError,
- message: 'The "code" argument must be of type string'
+ message: 'The "code" argument must be of type string. ' +
+ `Received type ${typeof notString}`
});
});
diff --git a/test/parallel/test-util-inherits.js b/test/parallel/test-util-inherits.js
index afbd504beb..9d89022088 100644
--- a/test/parallel/test-util-inherits.js
+++ b/test/parallel/test-util-inherits.js
@@ -74,13 +74,14 @@ assert.strictEqual(e.d(), 'd');
assert.strictEqual(e.e(), 'e');
assert.strictEqual(e.constructor, E);
-// should throw with invalid arguments
+// Should throw with invalid arguments
common.expectsError(function() {
inherits(A, {});
}, {
code: 'ERR_INVALID_ARG_TYPE',
type: TypeError,
- message: 'The "superCtor.prototype" property must be of type Function'
+ message: 'The "superCtor.prototype" property must be of type Function. ' +
+ 'Received type undefined'
});
common.expectsError(function() {
@@ -88,7 +89,8 @@ common.expectsError(function() {
}, {
code: 'ERR_INVALID_ARG_TYPE',
type: TypeError,
- message: 'The "superCtor" argument must be of type Function'
+ message: 'The "superCtor" argument must be of type Function. ' +
+ 'Received type object'
});
common.expectsError(function() {
@@ -96,5 +98,5 @@ common.expectsError(function() {
}, {
code: 'ERR_INVALID_ARG_TYPE',
type: TypeError,
- message: 'The "ctor" argument must be of type Function'
+ message: 'The "ctor" argument must be of type Function. Received type object'
});
diff --git a/test/parallel/test-util-inspect.js b/test/parallel/test-util-inspect.js
index b2c8207de5..0dd1ad74c0 100644
--- a/test/parallel/test-util-inspect.js
+++ b/test/parallel/test-util-inspect.js
@@ -1134,7 +1134,8 @@ if (typeof Symbol !== 'undefined') {
}, {
code: 'ERR_INVALID_ARG_TYPE',
type: TypeError,
- message: 'The "options" argument must be of type Object'
+ message: 'The "options" argument must be of type Object. ' +
+ 'Received type object'
}
);
@@ -1143,7 +1144,8 @@ if (typeof Symbol !== 'undefined') {
}, {
code: 'ERR_INVALID_ARG_TYPE',
type: TypeError,
- message: 'The "options" argument must be of type Object'
+ message: 'The "options" argument must be of type Object. ' +
+ 'Received type string'
}
);
}
diff --git a/test/parallel/test-util-promisify.js b/test/parallel/test-util-promisify.js
index 235d5c40db..5e1994a730 100644
--- a/test/parallel/test-util-promisify.js
+++ b/test/parallel/test-util-promisify.js
@@ -191,6 +191,7 @@ const stat = promisify(fs.stat);
{
code: 'ERR_INVALID_ARG_TYPE',
type: TypeError,
- message: 'The "original" argument must be of type Function'
+ message: 'The "original" argument must be of type Function. ' +
+ `Received type ${typeof input}`
});
});
diff --git a/test/parallel/test-v8-flag-type-check.js b/test/parallel/test-v8-flag-type-check.js
index 67a34b51f2..1dcdee928b 100644
--- a/test/parallel/test-v8-flag-type-check.js
+++ b/test/parallel/test-v8-flag-type-check.js
@@ -2,13 +2,14 @@
const common = require('../common');
const v8 = require('v8');
-[ 1, undefined ].forEach((i) => {
+[1, undefined].forEach((value) => {
common.expectsError(
- () => v8.setFlagsFromString(i),
+ () => v8.setFlagsFromString(value),
{
code: 'ERR_INVALID_ARG_TYPE',
type: TypeError,
- message: 'The "flags" argument must be of type string'
+ message: 'The "flags" argument must be of type string. ' +
+ `Received type ${typeof value}`
}
);
});
diff --git a/test/parallel/test-vm-basic.js b/test/parallel/test-vm-basic.js
index 3a74cb38d2..bf1532cacc 100644
--- a/test/parallel/test-vm-basic.js
+++ b/test/parallel/test-vm-basic.js
@@ -71,54 +71,35 @@ const context2 = vm.createContext(sandbox3);
assert.strictEqual(sandbox3, context2);
// Test 6: invalid arguments
-common.expectsError(() => {
- vm.createContext({}, null);
-}, {
- code: 'ERR_INVALID_ARG_TYPE',
- type: TypeError,
- message: 'The "options" argument must be of type object. Received type null'
+[null, 'string'].forEach((input) => {
+ common.expectsError(() => {
+ vm.createContext({}, input);
+ }, {
+ code: 'ERR_INVALID_ARG_TYPE',
+ type: TypeError,
+ message: 'The "options" argument must be of type object. ' +
+ `Received type ${typeof input}`
+ });
});
-common.expectsError(() => {
- vm.createContext({}, 'string');
-}, {
- code: 'ERR_INVALID_ARG_TYPE',
- type: TypeError,
- message: 'The "options" argument must be of type object. Received type string'
+['name', 'origin'].forEach((propertyName) => {
+ common.expectsError(() => {
+ vm.createContext({}, { [propertyName]: null });
+ }, {
+ code: 'ERR_INVALID_ARG_TYPE',
+ type: TypeError,
+ message: `The "options.${propertyName}" property must be of type string. ` +
+ 'Received type object'
+ });
});
-common.expectsError(() => {
- vm.createContext({}, { name: null });
-}, {
- code: 'ERR_INVALID_ARG_TYPE',
- type: TypeError,
- message: 'The "options.name" property must be of type string. ' +
- 'Received type null'
-});
-
-common.expectsError(() => {
- vm.createContext({}, { origin: null });
-}, {
- code: 'ERR_INVALID_ARG_TYPE',
- type: TypeError,
- message: 'The "options.origin" property must be of type string. ' +
- 'Received type null'
-});
-
-common.expectsError(() => {
- vm.runInNewContext('', {}, { contextName: null });
-}, {
- code: 'ERR_INVALID_ARG_TYPE',
- type: TypeError,
- message: 'The "options.contextName" property must be of type string. ' +
- 'Received type null'
-});
-
-common.expectsError(() => {
- vm.runInNewContext('', {}, { contextOrigin: null });
-}, {
- code: 'ERR_INVALID_ARG_TYPE',
- type: TypeError,
- message: 'The "options.contextOrigin" property must be of type string. ' +
- 'Received type null'
+['contextName', 'contextOrigin'].forEach((propertyName) => {
+ common.expectsError(() => {
+ vm.runInNewContext('', {}, { [propertyName]: null });
+ }, {
+ code: 'ERR_INVALID_ARG_TYPE',
+ type: TypeError,
+ message: `The "options.${propertyName}" property must be of type string. ` +
+ 'Received type object'
+ });
});
diff --git a/test/parallel/test-zlib-not-string-or-buffer.js b/test/parallel/test-zlib-not-string-or-buffer.js
index 489bc07f5d..bf59e86d5c 100644
--- a/test/parallel/test-zlib-not-string-or-buffer.js
+++ b/test/parallel/test-zlib-not-string-or-buffer.js
@@ -6,14 +6,24 @@
const common = require('../common');
const zlib = require('zlib');
-[undefined, null, true, false, 0, 1, [1, 2, 3], { foo: 'bar' }].forEach((i) => {
+[
+ undefined,
+ null,
+ true,
+ false,
+ 0,
+ 1,
+ [1, 2, 3],
+ { foo: 'bar' }
+].forEach((input) => {
common.expectsError(
- () => zlib.deflateSync(i),
+ () => zlib.deflateSync(input),
{
code: 'ERR_INVALID_ARG_TYPE',
type: TypeError,
message: 'The "buffer" argument must be one of type string, Buffer, ' +
- 'TypedArray, DataView, or ArrayBuffer'
+ 'TypedArray, DataView, or ArrayBuffer. ' +
+ `Received type ${typeof input}`
}
);
});