Skip to content

Commit d15cdc6

Browse files
mithunsasidharanMylesBorins
authored andcommitted
test: replace assert.throws w/ common.expectsError
PR-URL: #17498 Reviewed-By: Anatoli Papirovski <[email protected]> Reviewed-By: Jon Moss <[email protected]>
1 parent 993b1cb commit d15cdc6

File tree

48 files changed

+358
-369
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+358
-369
lines changed

test/parallel/test-http2-compat-serverresponse-headers.js

+9-9
Original file line numberDiff line numberDiff line change
@@ -72,28 +72,28 @@ server.listen(0, common.mustCall(function() {
7272
':path',
7373
':authority',
7474
':scheme'
75-
].forEach((header) => assert.throws(
75+
].forEach((header) => common.expectsError(
7676
() => response.setHeader(header, 'foobar'),
77-
common.expectsError({
77+
{
7878
code: 'ERR_HTTP2_PSEUDOHEADER_NOT_ALLOWED',
7979
type: Error,
8080
message: 'Cannot set HTTP/2 pseudo-headers'
8181
})
82-
));
83-
assert.throws(function() {
82+
);
83+
common.expectsError(function() {
8484
response.setHeader(real, null);
85-
}, common.expectsError({
85+
}, {
8686
code: 'ERR_HTTP2_INVALID_HEADER_VALUE',
8787
type: TypeError,
8888
message: 'Invalid value "null" for header "foo-bar"'
89-
}));
90-
assert.throws(function() {
89+
});
90+
common.expectsError(function() {
9191
response.setHeader(real, undefined);
92-
}, common.expectsError({
92+
}, {
9393
code: 'ERR_HTTP2_INVALID_HEADER_VALUE',
9494
type: TypeError,
9595
message: 'Invalid value "undefined" for header "foo-bar"'
96-
}));
96+
});
9797
common.expectsError(
9898
() => response.setHeader(), // header name undefined
9999
{

test/parallel/test-http2-compat-serverresponse-statuscode.js

+9-9
Original file line numberDiff line numberDiff line change
@@ -34,24 +34,24 @@ server.listen(0, common.mustCall(function() {
3434
response.statusCode = realStatusCodes.internalServerError;
3535
});
3636

37-
assert.throws(function() {
37+
common.expectsError(function() {
3838
response.statusCode = realStatusCodes.continue;
39-
}, common.expectsError({
39+
}, {
4040
code: 'ERR_HTTP2_INFO_STATUS_NOT_ALLOWED',
4141
type: RangeError
42-
}));
43-
assert.throws(function() {
42+
});
43+
common.expectsError(function() {
4444
response.statusCode = fakeStatusCodes.tooLow;
45-
}, common.expectsError({
45+
}, {
4646
code: 'ERR_HTTP2_STATUS_INVALID',
4747
type: RangeError
48-
}));
49-
assert.throws(function() {
48+
});
49+
common.expectsError(function() {
5050
response.statusCode = fakeStatusCodes.tooHigh;
51-
}, common.expectsError({
51+
}, {
5252
code: 'ERR_HTTP2_STATUS_INVALID',
5353
type: RangeError
54-
}));
54+
});
5555

5656
response.on('finish', common.mustCall(function() {
5757
server.close();

test/parallel/test-http2-getpackedsettings.js

+18-18
Original file line numberDiff line numberDiff line change
@@ -44,25 +44,25 @@ assert.doesNotThrow(() => http2.getPackedSettings({ enablePush: false }));
4444
['maxHeaderListSize', -1],
4545
['maxHeaderListSize', 2 ** 32]
4646
].forEach((i) => {
47-
assert.throws(() => {
47+
common.expectsError(() => {
4848
http2.getPackedSettings({ [i[0]]: i[1] });
49-
}, common.expectsError({
49+
}, {
5050
code: 'ERR_HTTP2_INVALID_SETTING_VALUE',
5151
type: RangeError,
5252
message: `Invalid value for setting "${i[0]}": ${i[1]}`
53-
}));
53+
});
5454
});
5555

5656
[
5757
1, null, '', Infinity, new Date(), {}, NaN, [false]
5858
].forEach((i) => {
59-
assert.throws(() => {
59+
common.expectsError(() => {
6060
http2.getPackedSettings({ enablePush: i });
61-
}, common.expectsError({
61+
}, {
6262
code: 'ERR_HTTP2_INVALID_SETTING_VALUE',
6363
type: TypeError,
6464
message: `Invalid value for setting "enablePush": ${i}`
65-
}));
65+
});
6666
});
6767

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

101101
[1, true, '', [], {}, NaN].forEach((i) => {
102-
assert.throws(() => {
102+
common.expectsError(() => {
103103
http2.getUnpackedSettings(i);
104-
}, common.expectsError({
104+
}, {
105105
code: 'ERR_INVALID_ARG_TYPE',
106106
type: TypeError,
107107
message:
108108
'The "buf" argument must be one of type Buffer, TypedArray, or DataView'
109-
}));
109+
});
110110
});
111111

112-
assert.throws(() => {
112+
common.expectsError(() => {
113113
http2.getUnpackedSettings(packed.slice(5));
114-
}, common.expectsError({
114+
}, {
115115
code: 'ERR_HTTP2_INVALID_PACKED_SETTINGS_LENGTH',
116116
type: RangeError,
117117
message: 'Packed settings length must be a multiple of six'
118-
}));
118+
});
119119

120120
const settings = http2.getUnpackedSettings(packed);
121121

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

163-
assert.throws(() => {
163+
common.expectsError(() => {
164164
http2.getUnpackedSettings(packed, { validate: true });
165-
}, common.expectsError({
165+
}, {
166166
code: 'ERR_HTTP2_INVALID_SETTING_VALUE',
167167
type: RangeError,
168168
message: 'Invalid value for setting "maxFrameSize": 16777216'
169-
}));
169+
});
170170
}
171171

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

176-
assert.throws(() => {
176+
common.expectsError(() => {
177177
http2.getUnpackedSettings(packed, { validate: true });
178-
}, common.expectsError({
178+
}, {
179179
code: 'ERR_HTTP2_INVALID_SETTING_VALUE',
180180
type: RangeError,
181181
message: 'Invalid value for setting "maxConcurrentStreams": 4294967295'
182-
}));
182+
});
183183
}

test/parallel/test-http2-info-headers.js

+19-19
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,19 @@ const afterRespondregex =
1818

1919
function onStream(stream, headers, flags) {
2020

21-
assert.throws(() => stream.additionalHeaders({ ':status': 201 }),
22-
common.expectsError({
23-
code: 'ERR_HTTP2_INVALID_INFO_STATUS',
24-
type: RangeError,
25-
message: /^Invalid informational status code: 201$/
26-
}));
27-
28-
assert.throws(() => stream.additionalHeaders({ ':status': 101 }),
29-
common.expectsError({
30-
code: 'ERR_HTTP2_STATUS_101',
31-
type: Error,
32-
message: status101regex
33-
}));
21+
common.expectsError(() => stream.additionalHeaders({ ':status': 201 }),
22+
{
23+
code: 'ERR_HTTP2_INVALID_INFO_STATUS',
24+
type: RangeError,
25+
message: /^Invalid informational status code: 201$/
26+
});
27+
28+
common.expectsError(() => stream.additionalHeaders({ ':status': 101 }),
29+
{
30+
code: 'ERR_HTTP2_STATUS_101',
31+
type: Error,
32+
message: status101regex
33+
});
3434

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

53-
assert.throws(() => stream.additionalHeaders({ abc: 123 }),
54-
common.expectsError({
55-
code: 'ERR_HTTP2_HEADERS_AFTER_RESPOND',
56-
type: Error,
57-
message: afterRespondregex
58-
}));
53+
common.expectsError(() => stream.additionalHeaders({ abc: 123 }),
54+
{
55+
code: 'ERR_HTTP2_HEADERS_AFTER_RESPOND',
56+
type: Error,
57+
message: afterRespondregex
58+
});
5959

6060
stream.end('hello world');
6161
}

test/parallel/test-http2-misused-pseudoheaders.js

+4-5
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
const common = require('../common');
44
if (!common.hasCrypto)
55
common.skip('missing crypto');
6-
const assert = require('assert');
76
const h2 = require('http2');
87

98
const server = h2.createServer();
@@ -19,10 +18,10 @@ function onStream(stream, headers, flags) {
1918
':method',
2019
':scheme'
2120
].forEach((i) => {
22-
assert.throws(() => stream.respond({ [i]: '/' }),
23-
common.expectsError({
24-
code: 'ERR_HTTP2_INVALID_PSEUDOHEADER'
25-
}));
21+
common.expectsError(() => stream.respond({ [i]: '/' }),
22+
{
23+
code: 'ERR_HTTP2_INVALID_PSEUDOHEADER'
24+
});
2625
});
2726

2827
stream.respond({

test/parallel/test-http2-too-many-settings.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@ let clients = 2;
1717
function doTest(session) {
1818
for (let n = 0; n < maxPendingAck; n++)
1919
assert.doesNotThrow(() => session.settings({ enablePush: false }));
20-
assert.throws(() => session.settings({ enablePush: false }),
21-
common.expectsError({
22-
code: 'ERR_HTTP2_MAX_PENDING_SETTINGS_ACK',
23-
type: Error
24-
}));
20+
common.expectsError(() => session.settings({ enablePush: false }),
21+
{
22+
code: 'ERR_HTTP2_MAX_PENDING_SETTINGS_ACK',
23+
type: Error
24+
});
2525
}
2626

2727
server.on('stream', common.mustNotCall());

test/parallel/test-http2-util-asserts.js

+10-10
Original file line numberDiff line numberDiff line change
@@ -27,17 +27,17 @@ const {
2727
[],
2828
[{}]
2929
].forEach((i) => {
30-
assert.throws(() => assertIsObject(i, 'foo', 'Object'),
31-
common.expectsError({
32-
code: 'ERR_INVALID_ARG_TYPE',
33-
message: /^The "foo" argument must be of type Object$/
34-
}));
30+
common.expectsError(() => assertIsObject(i, 'foo', 'Object'),
31+
{
32+
code: 'ERR_INVALID_ARG_TYPE',
33+
message: /^The "foo" argument must be of type Object$/
34+
});
3535
});
3636

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

39-
assert.throws(() => assertWithinRange('foo', 1, 2, 3),
40-
common.expectsError({
41-
code: 'ERR_HTTP2_INVALID_SETTING_VALUE',
42-
message: /^Invalid value for setting "foo": 1$/
43-
}));
39+
common.expectsError(() => assertWithinRange('foo', 1, 2, 3),
40+
{
41+
code: 'ERR_HTTP2_INVALID_SETTING_VALUE',
42+
message: /^Invalid value for setting "foo": 1$/
43+
});

0 commit comments

Comments
 (0)