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:
parent
eae0c05697
commit
d8c896cac5
@ -58,13 +58,13 @@ const bufferMaxSizeMsg = common.expectsError({
|
||||
assert.throws(function() {
|
||||
SlowBuffer(Infinity);
|
||||
}, bufferMaxSizeMsg);
|
||||
assert.throws(function() {
|
||||
common.expectsError(function() {
|
||||
SlowBuffer(-1);
|
||||
}, common.expectsError({
|
||||
}, {
|
||||
code: 'ERR_INVALID_OPT_VALUE',
|
||||
type: RangeError,
|
||||
message: 'The value "-1" is invalid for option "size"'
|
||||
}));
|
||||
});
|
||||
|
||||
assert.throws(function() {
|
||||
SlowBuffer(buffer.kMaxLength + 1);
|
||||
|
@ -84,17 +84,17 @@ assert.strictEqual(rangeBuffer.toString({ toString: function() {
|
||||
} }), 'abc');
|
||||
|
||||
// try toString() with 0 and null as the encoding
|
||||
assert.throws(() => {
|
||||
common.expectsError(() => {
|
||||
rangeBuffer.toString(0, 1, 2);
|
||||
}, common.expectsError({
|
||||
}, {
|
||||
code: 'ERR_UNKNOWN_ENCODING',
|
||||
type: TypeError,
|
||||
message: 'Unknown encoding: 0'
|
||||
}));
|
||||
assert.throws(() => {
|
||||
});
|
||||
common.expectsError(() => {
|
||||
rangeBuffer.toString(null, 1, 2);
|
||||
}, common.expectsError({
|
||||
}, {
|
||||
code: 'ERR_UNKNOWN_ENCODING',
|
||||
type: TypeError,
|
||||
message: 'Unknown encoding: null'
|
||||
}));
|
||||
});
|
||||
|
@ -5,9 +5,9 @@ const assert = require('assert');
|
||||
const cp = require('child_process');
|
||||
|
||||
function fail(proc, args) {
|
||||
assert.throws(() => {
|
||||
common.expectsError(() => {
|
||||
proc.send.apply(proc, args);
|
||||
}, common.expectsError({ code: 'ERR_INVALID_ARG_TYPE', type: TypeError }));
|
||||
}, { code: 'ERR_INVALID_ARG_TYPE', type: TypeError });
|
||||
}
|
||||
|
||||
let target = process;
|
||||
|
@ -29,9 +29,9 @@ if (process.argv[2] === 'child') {
|
||||
}
|
||||
|
||||
// Verify that an error is thrown for unknown signals.
|
||||
assert.throws(() => {
|
||||
common.expectsError(() => {
|
||||
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.
|
||||
{
|
||||
|
@ -40,6 +40,6 @@ options = { stdio: 'ignore' };
|
||||
child = spawnSync('cat', [], options);
|
||||
assert.deepStrictEqual(options, { stdio: 'ignore' });
|
||||
|
||||
assert.throws(() => {
|
||||
common.expectsError(() => {
|
||||
common.spawnPwd({ stdio: ['pipe', 'pipe', 'pipe', 'ipc', 'ipc'] });
|
||||
}, common.expectsError({ code: 'ERR_IPC_ONE_PIPE', type: Error }));
|
||||
}, { code: 'ERR_IPC_ONE_PIPE', type: Error });
|
||||
|
@ -26,8 +26,9 @@ assert.throws(() => _validateStdio(600), expectedError);
|
||||
|
||||
// should throw if stdio has ipc and sync is true
|
||||
const stdio2 = ['ipc', 'ipc', 'ipc'];
|
||||
assert.throws(() => _validateStdio(stdio2, true),
|
||||
common.expectsError({ code: 'ERR_IPC_SYNC_FORK', type: Error }));
|
||||
common.expectsError(() => _validateStdio(stdio2, true),
|
||||
{ code: 'ERR_IPC_SYNC_FORK', type: Error }
|
||||
);
|
||||
|
||||
{
|
||||
const stdio3 = [process.stdin, process.stdout, process.stderr];
|
||||
|
@ -45,12 +45,12 @@ assert.throws(function() {
|
||||
}, /^TypeError: Invalid minimum value: \/foo\/$/);
|
||||
|
||||
// assert.fail() tests
|
||||
assert.throws(
|
||||
common.expectsError(
|
||||
() => { assert.fail('fhqwhgads'); },
|
||||
common.expectsError({
|
||||
{
|
||||
code: 'ERR_ASSERTION',
|
||||
message: /^fhqwhgads$/
|
||||
}));
|
||||
});
|
||||
|
||||
const fnOnce = common.mustCall(() => {});
|
||||
fnOnce();
|
||||
|
@ -37,13 +37,13 @@ assert.strictEqual('function', typeof Console);
|
||||
|
||||
// make sure that the Console constructor throws
|
||||
// when not given a writable stream instance
|
||||
assert.throws(
|
||||
common.expectsError(
|
||||
() => { new Console(); },
|
||||
common.expectsError({
|
||||
{
|
||||
code: 'ERR_CONSOLE_WRITABLE_STREAM',
|
||||
type: TypeError,
|
||||
message: /stdout/
|
||||
})
|
||||
}
|
||||
);
|
||||
|
||||
// Console constructor should throw if stderr exists but is not writable
|
||||
|
@ -27,13 +27,13 @@ const dgram = require('dgram');
|
||||
const socket = dgram.createSocket('udp4');
|
||||
|
||||
socket.on('listening', common.mustCall(() => {
|
||||
assert.throws(() => {
|
||||
common.expectsError(() => {
|
||||
socket.bind();
|
||||
}, common.expectsError({
|
||||
}, {
|
||||
code: 'ERR_SOCKET_ALREADY_BOUND',
|
||||
type: Error,
|
||||
message: /^Socket is already bound$/
|
||||
}));
|
||||
});
|
||||
|
||||
socket.close();
|
||||
}));
|
||||
|
@ -6,12 +6,12 @@ const UDP = process.binding('udp_wrap').UDP;
|
||||
const _createSocketHandle = dgram._createSocketHandle;
|
||||
|
||||
// Throws if an "existing fd" is passed in.
|
||||
assert.throws(() => {
|
||||
common.expectsError(() => {
|
||||
_createSocketHandle(common.localhostIPv4, 0, 'udp4', 42);
|
||||
}, common.expectsError({
|
||||
}, {
|
||||
code: 'ERR_ASSERTION',
|
||||
message: /^false == true$/
|
||||
}));
|
||||
});
|
||||
|
||||
{
|
||||
// Create a handle that is not bound.
|
||||
|
Loading…
x
Reference in New Issue
Block a user