Skip to content

Commit

Permalink
test: fix tests for changed error messages
Browse files Browse the repository at this point in the history
  • Loading branch information
BridgeAR committed Jul 10, 2017
1 parent c5b1ba5 commit 1717cb9
Show file tree
Hide file tree
Showing 15 changed files with 107 additions and 67 deletions.
4 changes: 2 additions & 2 deletions lib/internal/child_process.js
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ ChildProcess.prototype.spawn = function(options) {
options.envPairs = [];
else if (!Array.isArray(options.envPairs)) {
throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'options.envPairs',
'array', options.envPairs);
'Array', options.envPairs);
}

options.envPairs.push('NODE_CHANNEL_FD=' + ipcFd);
Expand All @@ -301,7 +301,7 @@ ChildProcess.prototype.spawn = function(options) {
else if (options.args === undefined)
this.spawnargs = [];
else
throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'options.args', 'array',
throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'options.args', 'Array',
options.args);

var err = this._handle.spawn(options);
Expand Down
4 changes: 2 additions & 2 deletions lib/path.js
Original file line number Diff line number Diff line change
Expand Up @@ -959,7 +959,7 @@ const win32 = {

format: function format(pathObject) {
if (pathObject === null || typeof pathObject !== 'object') {
throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'pathObject', 'Object',
throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'pathObject', 'object',
pathObject);
}
return _format('\\', pathObject);
Expand Down Expand Up @@ -1502,7 +1502,7 @@ const posix = {

format: function format(pathObject) {
if (pathObject === null || typeof pathObject !== 'object') {
throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'pathObject', 'Object',
throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'pathObject', 'object',
pathObject);
}
return _format('/', pathObject);
Expand Down
13 changes: 10 additions & 3 deletions test/parallel/test-assert.js
Original file line number Diff line number Diff line change
Expand Up @@ -676,7 +676,14 @@ try {
{
// Verify that throws() and doesNotThrow() throw on non-function block
function typeName(value) {
return value === null ? 'null' : typeof value;
if (value == null) {
return value;
}
const type = typeof value;
if (type !== 'object') {
return `type ${type}`;
}
return `instance of ${value.constructor.name}`;
}

const testBlockTypeError = (method, block) => {
Expand All @@ -690,7 +697,7 @@ try {
code: 'ERR_INVALID_ARG_TYPE',
type: TypeError,
message: 'The "block" argument must be of type function. Received ' +
'type ' + typeName(block)
typeName(block)
})(e);
}

Expand Down Expand Up @@ -732,7 +739,7 @@ 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$/;
const re = /^The "options" argument must be of type object\. Received /;
args.forEach((input) => {
assert.throws(
() => new assert.AssertionError(input),
Expand Down
21 changes: 14 additions & 7 deletions test/parallel/test-child-process-constructor.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,14 @@ const { ChildProcess } = require('child_process');
assert.strictEqual(typeof ChildProcess, 'function');

function typeName(value) {
return value === null ? 'null' : typeof value;
if (value == null) {
return value;
}
const type = typeof value;
if (type !== 'object') {
return `type ${type}`;
}
return `instance of ${value.constructor.name}`;
}

{
Expand All @@ -19,7 +26,7 @@ function typeName(value) {
}, common.expectsError({
code: 'ERR_INVALID_ARG_TYPE',
type: TypeError,
message: 'The "options" argument must be of type object. Received type ' +
message: 'The "options" argument must be of type object. Received ' +
typeName(options)
}));
});
Expand All @@ -36,7 +43,7 @@ function typeName(value) {
code: 'ERR_INVALID_ARG_TYPE',
type: TypeError,
message: 'The "options.file" property must be of type string. Received ' +
'type ' + typeName(file)
typeName(file)
}));
});
}
Expand All @@ -51,8 +58,8 @@ function typeName(value) {
}, common.expectsError({
code: 'ERR_INVALID_ARG_TYPE',
type: TypeError,
message: 'The "options.envPairs" property must be of type array. ' +
'Received type ' + typeName(envPairs)
message: 'The "options.envPairs" property must be instance of Array. ' +
'Received ' + typeName(envPairs)
}));
});
}
Expand All @@ -67,8 +74,8 @@ function typeName(value) {
}, common.expectsError({
code: 'ERR_INVALID_ARG_TYPE',
type: TypeError,
message: 'The "options.args" property must be of type array. Received ' +
'type ' + typeName(args)
message: 'The "options.args" property must be instance of Array. ' +
'Received ' + typeName(args)
}));
});
}
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-dgram-send-address-types.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const onMessage = common.mustCall((err, bytes) => {
const expectedError = { code: 'ERR_INVALID_ARG_TYPE',
type: TypeError,
message:
/^The "address" argument must be one of type string or falsy$/
/^The "address" argument must be of type string or falsy\. Received /
};

const client = dgram.createSocket('udp4').bind(0, () => {
Expand Down
8 changes: 4 additions & 4 deletions test/parallel/test-dgram-sendto.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const dgram = require('dgram');
const socket = dgram.createSocket('udp4');

const errorMessageOffset =
/^The "offset" argument must be of type number$/;
/^The "offset" argument must be of type number\. Received /;

assert.throws(() => {
socket.sendto();
Expand All @@ -20,7 +20,7 @@ assert.throws(() => {
}, common.expectsError({
code: 'ERR_INVALID_ARG_TYPE',
type: TypeError,
message: /^The "length" argument must be of type number$/
message: /^The "length" argument must be of type number\. Received /
}));

assert.throws(() => {
Expand All @@ -36,13 +36,13 @@ assert.throws(() => {
}, common.expectsError({
code: 'ERR_INVALID_ARG_TYPE',
type: TypeError,
message: /^The "address" argument must be of type string$/
message: /^The "address" argument must be of type string\. Received /
}));

assert.throws(() => {
socket.sendto('buffer', 1, 1, false, 'address', 'cb');
}, common.expectsError({
code: 'ERR_INVALID_ARG_TYPE',
type: TypeError,
message: /^The "port" argument must be of type number$/
message: /^The "port" argument must be of type number\. Received /
}));
58 changes: 38 additions & 20 deletions test/parallel/test-internal-errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -181,34 +181,52 @@ assert.throws(() => {
}));

// // 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');
const specialArray = [];
Object.defineProperty(specialArray, 'constructor', {
enumerable: false,
configurable: false,
writable: false,
value: null
});
assert.strictEqual(
errors.message('ERR_INVALID_ARG_TYPE', ['a', 'b', specialArray]),
'The "a" argument must be of type b. Received a plain object'
);
assert.strictEqual(
errors.message('ERR_INVALID_ARG_TYPE', ['a', ['b'], new Error()]),
'The "a" argument must be of type b. Received instance of Error'
);
assert.strictEqual(
errors.message('ERR_INVALID_ARG_TYPE',
['a', ['b', 'Array'], Object.create(null)]),
'The "a" argument must be of type b or Array. Received a plain object'
);
assert.strictEqual(
errors.message('ERR_INVALID_ARG_TYPE', ['a', ['Array', 'c', 'd'], null]),
'The "a" argument must be instance of Array, c, or d. Received null'
);
assert.strictEqual(
errors.message('ERR_INVALID_ARG_TYPE', ['a', 'B', 'c']),
'The "a" argument must be instance of B. Received type string'
);
assert.strictEqual(
errors.message('ERR_INVALID_ARG_TYPE', ['a', 'b', undefined]),
'The "a" argument must be of type b. Received undefined'
);
assert.strictEqual(
errors.message('ERR_INVALID_ARG_TYPE', ['a', 'b', /a/]),
'The "a" argument must be of type b. Received instance of RegExp'
);

// Test ERR_INVALID_URL_SCHEME
assert.strictEqual(errors.message('ERR_INVALID_URL_SCHEME', ['file']),
'The URL must be of scheme file');
assert.strictEqual(errors.message('ERR_INVALID_URL_SCHEME', [['file']]),
'The URL must be of scheme file');
assert.strictEqual(errors.message('ERR_INVALID_URL_SCHEME', [['http', 'ftp']]),
'The URL must be one of scheme http or ftp');
'The URL must be of scheme http or ftp');
assert.strictEqual(errors.message('ERR_INVALID_URL_SCHEME', [['a', 'b', 'c']]),
'The URL must be one of scheme a, b, or c');
'The URL must be of scheme a, b, or c');
assert.throws(
() => errors.message('ERR_INVALID_URL_SCHEME', [[]]),
common.expectsError({
Expand Down
13 changes: 10 additions & 3 deletions test/parallel/test-path-parse-format.js
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,14 @@ function checkFormat(path, testCases) {
});

function typeName(value) {
return value === null ? 'null' : typeof value;
if (value == null) {
return value;
}
const type = typeof value;
if (type !== 'object') {
return `type ${type}`;
}
return `instance of ${value.constructor.name}`;
}

[null, undefined, 1, true, false, 'string'].forEach((pathObject) => {
Expand All @@ -218,8 +225,8 @@ function checkFormat(path, testCases) {
}, common.expectsError({
code: 'ERR_INVALID_ARG_TYPE',
type: TypeError,
message: 'The "pathObject" argument must be of type Object. Received ' +
'type ' + typeName(pathObject)
message: 'The "pathObject" argument must be of type object. Received ' +
typeName(pathObject)
}));
});
}
3 changes: 2 additions & 1 deletion test/parallel/test-process-hrtime.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ assert.throws(() => {
}, common.expectsError({
code: 'ERR_INVALID_ARG_TYPE',
type: TypeError,
message: 'The "time" argument must be of type Array. Received type number'
message: 'The "time" argument must be instance of Array. ' +
'Received type number'
}));
assert.throws(() => {
process.hrtime([]);
Expand Down
14 changes: 7 additions & 7 deletions test/parallel/test-url-format-invalid-input.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,19 @@ const url = require('url');
const throwsObjsAndReportTypes = new Map([
[undefined, 'undefined'],
[null, 'null'],
[true, 'boolean'],
[false, 'boolean'],
[0, 'number'],
[function() {}, 'function'],
[Symbol('foo'), 'symbol']
[true, 'type boolean'],
[false, 'type boolean'],
[0, 'type number'],
[function() {}, 'type function'],
[Symbol('foo'), 'type symbol']
]);

for (const [urlObject, type] of throwsObjsAndReportTypes) {
const error = common.expectsError({
code: 'ERR_INVALID_ARG_TYPE',
type: TypeError,
message: 'The "urlObject" argument must be one of type object or string. ' +
`Received type ${type}`
message: 'The "urlObject" argument must be of type object or string. ' +
`Received ${type}`
});
assert.throws(function() { url.format(urlObject); }, error);
}
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-url-format-whatwg.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ assert.strictEqual(
const expectedErr = common.expectsError({
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 /
}, 4);
assert.throws(() => url.format(myURL, true), expectedErr);
assert.throws(() => url.format(myURL, 1), expectedErr);
Expand Down
18 changes: 9 additions & 9 deletions test/parallel/test-url-parse-invalid-input.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,19 @@ const url = require('url');
[
[undefined, 'undefined'],
[null, 'null'],
[true, 'boolean'],
[false, 'boolean'],
[0.0, 'number'],
[0, 'number'],
[[], 'object'],
[{}, 'object'],
[() => {}, 'function'],
[Symbol('foo'), 'symbol']
[true, 'type boolean'],
[false, 'type boolean'],
[0.0, 'type number'],
[0, 'type number'],
[[], 'instance of Array'],
[{}, 'instance of Object'],
[() => {}, 'type function'],
[Symbol('foo'), 'type symbol']
].forEach(([val, type]) => {
const error = common.expectsError({
code: 'ERR_INVALID_ARG_TYPE',
type: TypeError,
message: `The "url" argument must be of type string. Received type ${type}`
message: `The "url" argument must be of type string. Received ${type}`
});
assert.throws(() => { url.parse(val); }, error);
});
Expand Down
4 changes: 2 additions & 2 deletions test/parallel/test-util-callbackify.js
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ const values = [
}, common.expectsError({
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 /
}));
});
}
Expand All @@ -255,7 +255,7 @@ const values = [
}, common.expectsError({
code: 'ERR_INVALID_ARG_TYPE',
type: TypeError,
message: 'The "last argument" argument must be of type function'
message: /^The "last argument" argument must be of type function\./
}));
});
}
6 changes: 3 additions & 3 deletions test/parallel/test-util-inherits.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const inherits = require('util').inherits;
const errCheck = common.expectsError({
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/
});

// super constructor
Expand Down Expand Up @@ -85,7 +85,7 @@ assert.throws(function() {
}, common.expectsError({
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\./
})
);
assert.throws(function() {
Expand All @@ -96,6 +96,6 @@ assert.throws(function() {
}, common.expectsError({
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 null'
})
);
Loading

0 comments on commit 1717cb9

Please sign in to comment.