test: use common.expectsError in tests

PR-URL: https://github.com/nodejs/node/pull/17484
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Anatoli Papirovski <apapirovski@mac.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Jon Moss <me@jonathanmoss.me>
This commit is contained in:
Mithun Sasidharan 2017-12-06 14:07:52 +05:30 committed by Anatoli Papirovski
parent eae0c05697
commit d8c896cac5
No known key found for this signature in database
GPG Key ID: 614E2E1ABEB4B2C0
10 changed files with 30 additions and 29 deletions

View File

@ -58,13 +58,13 @@ const bufferMaxSizeMsg = common.expectsError({
assert.throws(function() { assert.throws(function() {
SlowBuffer(Infinity); SlowBuffer(Infinity);
}, bufferMaxSizeMsg); }, bufferMaxSizeMsg);
assert.throws(function() { common.expectsError(function() {
SlowBuffer(-1); SlowBuffer(-1);
}, common.expectsError({ }, {
code: 'ERR_INVALID_OPT_VALUE', code: 'ERR_INVALID_OPT_VALUE',
type: RangeError, type: RangeError,
message: 'The value "-1" is invalid for option "size"' message: 'The value "-1" is invalid for option "size"'
})); });
assert.throws(function() { assert.throws(function() {
SlowBuffer(buffer.kMaxLength + 1); SlowBuffer(buffer.kMaxLength + 1);

View File

@ -84,17 +84,17 @@ assert.strictEqual(rangeBuffer.toString({ toString: function() {
} }), 'abc'); } }), 'abc');
// try toString() with 0 and null as the encoding // try toString() with 0 and null as the encoding
assert.throws(() => { common.expectsError(() => {
rangeBuffer.toString(0, 1, 2); rangeBuffer.toString(0, 1, 2);
}, common.expectsError({ }, {
code: 'ERR_UNKNOWN_ENCODING', code: 'ERR_UNKNOWN_ENCODING',
type: TypeError, type: TypeError,
message: 'Unknown encoding: 0' message: 'Unknown encoding: 0'
})); });
assert.throws(() => { common.expectsError(() => {
rangeBuffer.toString(null, 1, 2); rangeBuffer.toString(null, 1, 2);
}, common.expectsError({ }, {
code: 'ERR_UNKNOWN_ENCODING', code: 'ERR_UNKNOWN_ENCODING',
type: TypeError, type: TypeError,
message: 'Unknown encoding: null' message: 'Unknown encoding: null'
})); });

View File

@ -5,9 +5,9 @@ const assert = require('assert');
const cp = require('child_process'); const cp = require('child_process');
function fail(proc, args) { function fail(proc, args) {
assert.throws(() => { common.expectsError(() => {
proc.send.apply(proc, args); proc.send.apply(proc, args);
}, common.expectsError({ code: 'ERR_INVALID_ARG_TYPE', type: TypeError })); }, { code: 'ERR_INVALID_ARG_TYPE', type: TypeError });
} }
let target = process; let target = process;

View File

@ -29,9 +29,9 @@ if (process.argv[2] === 'child') {
} }
// Verify that an error is thrown for unknown signals. // Verify that an error is thrown for unknown signals.
assert.throws(() => { common.expectsError(() => {
spawn('SIG_NOT_A_REAL_SIGNAL'); spawn('SIG_NOT_A_REAL_SIGNAL');
}, common.expectsError({ code: 'ERR_UNKNOWN_SIGNAL', type: TypeError })); }, { code: 'ERR_UNKNOWN_SIGNAL', type: TypeError });
// Verify that the default kill signal is SIGTERM. // Verify that the default kill signal is SIGTERM.
{ {

View File

@ -40,6 +40,6 @@ options = { stdio: 'ignore' };
child = spawnSync('cat', [], options); child = spawnSync('cat', [], options);
assert.deepStrictEqual(options, { stdio: 'ignore' }); assert.deepStrictEqual(options, { stdio: 'ignore' });
assert.throws(() => { common.expectsError(() => {
common.spawnPwd({ stdio: ['pipe', 'pipe', 'pipe', 'ipc', 'ipc'] }); common.spawnPwd({ stdio: ['pipe', 'pipe', 'pipe', 'ipc', 'ipc'] });
}, common.expectsError({ code: 'ERR_IPC_ONE_PIPE', type: Error })); }, { code: 'ERR_IPC_ONE_PIPE', type: Error });

View File

@ -26,8 +26,9 @@ assert.throws(() => _validateStdio(600), expectedError);
// should throw if stdio has ipc and sync is true // should throw if stdio has ipc and sync is true
const stdio2 = ['ipc', 'ipc', 'ipc']; const stdio2 = ['ipc', 'ipc', 'ipc'];
assert.throws(() => _validateStdio(stdio2, true), common.expectsError(() => _validateStdio(stdio2, true),
common.expectsError({ code: 'ERR_IPC_SYNC_FORK', type: Error })); { code: 'ERR_IPC_SYNC_FORK', type: Error }
);
{ {
const stdio3 = [process.stdin, process.stdout, process.stderr]; const stdio3 = [process.stdin, process.stdout, process.stderr];

View File

@ -45,12 +45,12 @@ assert.throws(function() {
}, /^TypeError: Invalid minimum value: \/foo\/$/); }, /^TypeError: Invalid minimum value: \/foo\/$/);
// assert.fail() tests // assert.fail() tests
assert.throws( common.expectsError(
() => { assert.fail('fhqwhgads'); }, () => { assert.fail('fhqwhgads'); },
common.expectsError({ {
code: 'ERR_ASSERTION', code: 'ERR_ASSERTION',
message: /^fhqwhgads$/ message: /^fhqwhgads$/
})); });
const fnOnce = common.mustCall(() => {}); const fnOnce = common.mustCall(() => {});
fnOnce(); fnOnce();

View File

@ -37,13 +37,13 @@ assert.strictEqual('function', typeof Console);
// make sure that the Console constructor throws // make sure that the Console constructor throws
// when not given a writable stream instance // when not given a writable stream instance
assert.throws( common.expectsError(
() => { new Console(); }, () => { new Console(); },
common.expectsError({ {
code: 'ERR_CONSOLE_WRITABLE_STREAM', code: 'ERR_CONSOLE_WRITABLE_STREAM',
type: TypeError, type: TypeError,
message: /stdout/ message: /stdout/
}) }
); );
// Console constructor should throw if stderr exists but is not writable // Console constructor should throw if stderr exists but is not writable

View File

@ -27,13 +27,13 @@ const dgram = require('dgram');
const socket = dgram.createSocket('udp4'); const socket = dgram.createSocket('udp4');
socket.on('listening', common.mustCall(() => { socket.on('listening', common.mustCall(() => {
assert.throws(() => { common.expectsError(() => {
socket.bind(); socket.bind();
}, common.expectsError({ }, {
code: 'ERR_SOCKET_ALREADY_BOUND', code: 'ERR_SOCKET_ALREADY_BOUND',
type: Error, type: Error,
message: /^Socket is already bound$/ message: /^Socket is already bound$/
})); });
socket.close(); socket.close();
})); }));

View File

@ -6,12 +6,12 @@ const UDP = process.binding('udp_wrap').UDP;
const _createSocketHandle = dgram._createSocketHandle; const _createSocketHandle = dgram._createSocketHandle;
// Throws if an "existing fd" is passed in. // Throws if an "existing fd" is passed in.
assert.throws(() => { common.expectsError(() => {
_createSocketHandle(common.localhostIPv4, 0, 'udp4', 42); _createSocketHandle(common.localhostIPv4, 0, 'udp4', 42);
}, common.expectsError({ }, {
code: 'ERR_ASSERTION', code: 'ERR_ASSERTION',
message: /^false == true$/ message: /^false == true$/
})); });
{ {
// Create a handle that is not bound. // Create a handle that is not bound.