Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: replace assert.throws with common.expectsError #17498

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions test/parallel/test-http2-compat-serverresponse-headers.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,28 +72,28 @@ server.listen(0, common.mustCall(function() {
':path',
':authority',
':scheme'
].forEach((header) => assert.throws(
].forEach((header) => common.expectsError(
() => response.setHeader(header, 'foobar'),
common.expectsError({
{
code: 'ERR_HTTP2_PSEUDOHEADER_NOT_ALLOWED',
type: Error,
message: 'Cannot set HTTP/2 pseudo-headers'
})
));
assert.throws(function() {
);
common.expectsError(function() {
response.setHeader(real, null);
}, common.expectsError({
}, {
code: 'ERR_HTTP2_INVALID_HEADER_VALUE',
type: TypeError,
message: 'Invalid value "null" for header "foo-bar"'
}));
assert.throws(function() {
});
common.expectsError(function() {
response.setHeader(real, undefined);
}, common.expectsError({
}, {
code: 'ERR_HTTP2_INVALID_HEADER_VALUE',
type: TypeError,
message: 'Invalid value "undefined" for header "foo-bar"'
}));
});
common.expectsError(
() => response.setHeader(), // header name undefined
{
Expand Down
18 changes: 9 additions & 9 deletions test/parallel/test-http2-compat-serverresponse-statuscode.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,24 +34,24 @@ server.listen(0, common.mustCall(function() {
response.statusCode = realStatusCodes.internalServerError;
});

assert.throws(function() {
common.expectsError(function() {
response.statusCode = realStatusCodes.continue;
}, common.expectsError({
}, {
code: 'ERR_HTTP2_INFO_STATUS_NOT_ALLOWED',
type: RangeError
}));
assert.throws(function() {
});
common.expectsError(function() {
response.statusCode = fakeStatusCodes.tooLow;
}, common.expectsError({
}, {
code: 'ERR_HTTP2_STATUS_INVALID',
type: RangeError
}));
assert.throws(function() {
});
common.expectsError(function() {
response.statusCode = fakeStatusCodes.tooHigh;
}, common.expectsError({
}, {
code: 'ERR_HTTP2_STATUS_INVALID',
type: RangeError
}));
});

response.on('finish', common.mustCall(function() {
server.close();
Expand Down
36 changes: 18 additions & 18 deletions test/parallel/test-http2-getpackedsettings.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,25 +44,25 @@ assert.doesNotThrow(() => http2.getPackedSettings({ enablePush: false }));
['maxHeaderListSize', -1],
['maxHeaderListSize', 2 ** 32]
].forEach((i) => {
assert.throws(() => {
common.expectsError(() => {
http2.getPackedSettings({ [i[0]]: i[1] });
}, common.expectsError({
}, {
code: 'ERR_HTTP2_INVALID_SETTING_VALUE',
type: RangeError,
message: `Invalid value for setting "${i[0]}": ${i[1]}`
}));
});
});

[
1, null, '', Infinity, new Date(), {}, NaN, [false]
].forEach((i) => {
assert.throws(() => {
common.expectsError(() => {
http2.getPackedSettings({ enablePush: i });
}, common.expectsError({
}, {
code: 'ERR_HTTP2_INVALID_SETTING_VALUE',
type: TypeError,
message: `Invalid value for setting "enablePush": ${i}`
}));
});
});

{
Expand Down Expand Up @@ -99,23 +99,23 @@ assert.doesNotThrow(() => http2.getPackedSettings({ enablePush: false }));
0x00, 0x02, 0x00, 0x00, 0x00, 0x01]);

[1, true, '', [], {}, NaN].forEach((i) => {
assert.throws(() => {
common.expectsError(() => {
http2.getUnpackedSettings(i);
}, common.expectsError({
}, {
code: 'ERR_INVALID_ARG_TYPE',
type: TypeError,
message:
'The "buf" argument must be one of type Buffer, TypedArray, or DataView'
}));
});
});

assert.throws(() => {
common.expectsError(() => {
http2.getUnpackedSettings(packed.slice(5));
}, common.expectsError({
}, {
code: 'ERR_HTTP2_INVALID_PACKED_SETTINGS_LENGTH',
type: RangeError,
message: 'Packed settings length must be a multiple of six'
}));
});

const settings = http2.getUnpackedSettings(packed);

Expand Down Expand Up @@ -160,24 +160,24 @@ assert.doesNotThrow(() => http2.getPackedSettings({ enablePush: false }));
{
const packed = Buffer.from([0x00, 0x05, 0x01, 0x00, 0x00, 0x00]);

assert.throws(() => {
common.expectsError(() => {
http2.getUnpackedSettings(packed, { validate: true });
}, common.expectsError({
}, {
code: 'ERR_HTTP2_INVALID_SETTING_VALUE',
type: RangeError,
message: 'Invalid value for setting "maxFrameSize": 16777216'
}));
});
}

// check for maxConcurrentStreams failing the max number
{
const packed = Buffer.from([0x00, 0x03, 0xFF, 0xFF, 0xFF, 0xFF]);

assert.throws(() => {
common.expectsError(() => {
http2.getUnpackedSettings(packed, { validate: true });
}, common.expectsError({
}, {
code: 'ERR_HTTP2_INVALID_SETTING_VALUE',
type: RangeError,
message: 'Invalid value for setting "maxConcurrentStreams": 4294967295'
}));
});
}
38 changes: 19 additions & 19 deletions test/parallel/test-http2-info-headers.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,19 @@ const afterRespondregex =

function onStream(stream, headers, flags) {

assert.throws(() => stream.additionalHeaders({ ':status': 201 }),
common.expectsError({
code: 'ERR_HTTP2_INVALID_INFO_STATUS',
type: RangeError,
message: /^Invalid informational status code: 201$/
}));

assert.throws(() => stream.additionalHeaders({ ':status': 101 }),
common.expectsError({
code: 'ERR_HTTP2_STATUS_101',
type: Error,
message: status101regex
}));
common.expectsError(() => stream.additionalHeaders({ ':status': 201 }),
{
code: 'ERR_HTTP2_INVALID_INFO_STATUS',
type: RangeError,
message: /^Invalid informational status code: 201$/
});

common.expectsError(() => stream.additionalHeaders({ ':status': 101 }),
{
code: 'ERR_HTTP2_STATUS_101',
type: Error,
message: status101regex
});

common.expectsError(
() => stream.additionalHeaders({ ':method': 'POST' }),
Expand All @@ -50,12 +50,12 @@ function onStream(stream, headers, flags) {
':status': 200
});

assert.throws(() => stream.additionalHeaders({ abc: 123 }),
common.expectsError({
code: 'ERR_HTTP2_HEADERS_AFTER_RESPOND',
type: Error,
message: afterRespondregex
}));
common.expectsError(() => stream.additionalHeaders({ abc: 123 }),
{
code: 'ERR_HTTP2_HEADERS_AFTER_RESPOND',
type: Error,
message: afterRespondregex
});

stream.end('hello world');
}
Expand Down
9 changes: 4 additions & 5 deletions test/parallel/test-http2-misused-pseudoheaders.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
const common = require('../common');
if (!common.hasCrypto)
common.skip('missing crypto');
const assert = require('assert');
const h2 = require('http2');

const server = h2.createServer();
Expand All @@ -19,10 +18,10 @@ function onStream(stream, headers, flags) {
':method',
':scheme'
].forEach((i) => {
assert.throws(() => stream.respond({ [i]: '/' }),
common.expectsError({
code: 'ERR_HTTP2_INVALID_PSEUDOHEADER'
}));
common.expectsError(() => stream.respond({ [i]: '/' }),
{
code: 'ERR_HTTP2_INVALID_PSEUDOHEADER'
});
});

stream.respond({
Expand Down
10 changes: 5 additions & 5 deletions test/parallel/test-http2-too-many-settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ let clients = 2;
function doTest(session) {
for (let n = 0; n < maxPendingAck; n++)
assert.doesNotThrow(() => session.settings({ enablePush: false }));
assert.throws(() => session.settings({ enablePush: false }),
common.expectsError({
code: 'ERR_HTTP2_MAX_PENDING_SETTINGS_ACK',
type: Error
}));
common.expectsError(() => session.settings({ enablePush: false }),
{
code: 'ERR_HTTP2_MAX_PENDING_SETTINGS_ACK',
type: Error
});
}

server.on('stream', common.mustNotCall());
Expand Down
20 changes: 10 additions & 10 deletions test/parallel/test-http2-util-asserts.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,17 @@ const {
[],
[{}]
].forEach((i) => {
assert.throws(() => assertIsObject(i, 'foo', 'Object'),
common.expectsError({
code: 'ERR_INVALID_ARG_TYPE',
message: /^The "foo" argument must be of type Object$/
}));
common.expectsError(() => assertIsObject(i, 'foo', 'Object'),
{
code: 'ERR_INVALID_ARG_TYPE',
message: /^The "foo" argument must be of type Object$/
});
});

assert.doesNotThrow(() => assertWithinRange('foo', 1, 0, 2));

assert.throws(() => assertWithinRange('foo', 1, 2, 3),
common.expectsError({
code: 'ERR_HTTP2_INVALID_SETTING_VALUE',
message: /^Invalid value for setting "foo": 1$/
}));
common.expectsError(() => assertWithinRange('foo', 1, 2, 3),
{
code: 'ERR_HTTP2_INVALID_SETTING_VALUE',
message: /^Invalid value for setting "foo": 1$/
});
Loading