Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 49d6628

Browse filesBrowse files
apapirovskiMylesBorins
authored andcommitted
test: replace assert.throws w/ common.expectsError
PR-URL: #17557 Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
1 parent cbd0be5 commit 49d6628
Copy full SHA for 49d6628
Expand file treeCollapse file tree

20 files changed

+140
-140
lines changed
Open diff view settings
Collapse file

‎test/async-hooks/test-embedder.api.async-resource.js‎

Copy file name to clipboardExpand all lines: test/async-hooks/test-embedder.api.async-resource.js
+3-3Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@ common.expectsError(
1717
code: 'ERR_INVALID_ARG_TYPE',
1818
type: TypeError,
1919
});
20-
assert.throws(() => {
20+
common.expectsError(() => {
2121
new AsyncResource('invalid_trigger_id', { triggerAsyncId: null });
22-
}, common.expectsError({
22+
}, {
2323
code: 'ERR_INVALID_ASYNC_ID',
2424
type: RangeError,
25-
}));
25+
});
2626

2727
assert.strictEqual(
2828
new AsyncResource('default_trigger_id').triggerAsyncId(),
Collapse file

‎test/parallel/test-assert-fail.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-assert-fail.js
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
'use strict';
22

3+
/* eslint-disable prefer-common-expectserror */
4+
35
const common = require('../common');
46
const assert = require('assert');
57

Collapse file

‎test/parallel/test-assert.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-assert.js
+3Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@
2020
// USE OR OTHER DEALINGS IN THE SOFTWARE.
2121

2222
'use strict';
23+
24+
/* eslint-disable prefer-common-expectserror */
25+
2326
const common = require('../common');
2427
const assert = require('assert');
2528
const a = assert;
Collapse file

‎test/parallel/test-buffer-alloc.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-buffer-alloc.js
+2-3Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -974,12 +974,11 @@ assert.strictEqual(SlowBuffer.prototype.offset, undefined);
974974
}
975975

976976
// ParseArrayIndex() should reject values that don't fit in a 32 bits size_t.
977-
assert.throws(() => {
977+
common.expectsError(() => {
978978
const a = Buffer.alloc(1);
979979
const b = Buffer.alloc(1);
980980
a.copy(b, 0, 0x100000000, 0x100000001);
981-
}, common.expectsError(
982-
{ code: undefined, type: RangeError, message: 'Index out of range' }));
981+
}, { code: undefined, type: RangeError, message: 'Index out of range' });
983982

984983
// Unpooled buffer (replaces SlowBuffer)
985984
{
Collapse file

‎test/parallel/test-buffer-fill.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-buffer-fill.js
+4-6Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -421,21 +421,19 @@ common.expectsError(() => {
421421

422422
// Testing process.binding. Make sure "end" is properly checked for -1 wrap
423423
// around.
424-
assert.throws(() => {
424+
common.expectsError(() => {
425425
process.binding('buffer').fill(Buffer.alloc(1), 1, 1, -2, 1);
426-
}, common.expectsError(
427-
{ code: undefined, type: RangeError, message: 'Index out of range' }));
426+
}, { code: undefined, type: RangeError, message: 'Index out of range' });
428427

429428
// Test that bypassing 'length' won't cause an abort.
430-
assert.throws(() => {
429+
common.expectsError(() => {
431430
const buf = new Buffer('w00t');
432431
Object.defineProperty(buf, 'length', {
433432
value: 1337,
434433
enumerable: true
435434
});
436435
buf.fill('');
437-
}, common.expectsError(
438-
{ code: undefined, type: RangeError, message: 'Index out of range' }));
436+
}, { code: undefined, type: RangeError, message: 'Index out of range' });
439437

440438
assert.deepStrictEqual(
441439
Buffer.allocUnsafeSlow(16).fill('ab', 'utf16le'),
Collapse file

‎test/parallel/test-console-instance.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-console-instance.js
+3-3Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,17 +47,17 @@ common.expectsError(
4747
);
4848

4949
// Console constructor should throw if stderr exists but is not writable
50-
assert.throws(
50+
common.expectsError(
5151
() => {
5252
out.write = () => {};
5353
err.write = undefined;
5454
new Console(out, err);
5555
},
56-
common.expectsError({
56+
{
5757
code: 'ERR_CONSOLE_WRITABLE_STREAM',
5858
type: TypeError,
5959
message: /stderr/
60-
})
60+
}
6161
);
6262

6363
out.write = err.write = (d) => {};
Collapse file

‎test/parallel/test-dns.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-dns.js
+8-8Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -205,20 +205,20 @@ assert.doesNotThrow(() => {
205205
}, common.mustCall());
206206
});
207207

208-
assert.throws(() => dns.lookupService('0.0.0.0'), common.expectsError({
208+
common.expectsError(() => dns.lookupService('0.0.0.0'), {
209209
code: 'ERR_MISSING_ARGS',
210210
type: TypeError,
211211
message: 'The "host", "port", and "callback" arguments must be specified'
212-
}));
212+
});
213213

214214
const invalidHost = 'fasdfdsaf';
215-
assert.throws(() => {
215+
common.expectsError(() => {
216216
dns.lookupService(invalidHost, 0, common.mustNotCall());
217-
}, common.expectsError({
217+
}, {
218218
code: 'ERR_INVALID_OPT_VALUE',
219219
type: TypeError,
220220
message: `The value "${invalidHost}" is invalid for option "host"`
221-
}));
221+
});
222222

223223
const portErr = (port) => {
224224
common.expectsError(
@@ -238,9 +238,9 @@ portErr(undefined);
238238
portErr(65538);
239239
portErr('test');
240240

241-
assert.throws(() => {
241+
common.expectsError(() => {
242242
dns.lookupService('0.0.0.0', 80, null);
243-
}, common.expectsError({
243+
}, {
244244
code: 'ERR_INVALID_CALLBACK',
245245
type: TypeError
246-
}));
246+
});
Collapse file

‎test/parallel/test-http-outgoing-proto.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-http-outgoing-proto.js
+30-30Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -21,80 +21,80 @@ assert.strictEqual(
2121
typeof ServerResponse.prototype._implicitHeader, 'function');
2222

2323
// validateHeader
24-
assert.throws(() => {
24+
common.expectsError(() => {
2525
const outgoingMessage = new OutgoingMessage();
2626
outgoingMessage.setHeader();
27-
}, common.expectsError({
27+
}, {
2828
code: 'ERR_INVALID_HTTP_TOKEN',
2929
type: TypeError,
3030
message: 'Header name must be a valid HTTP token ["undefined"]'
31-
}));
31+
});
3232

33-
assert.throws(() => {
33+
common.expectsError(() => {
3434
const outgoingMessage = new OutgoingMessage();
3535
outgoingMessage.setHeader('test');
36-
}, common.expectsError({
36+
}, {
3737
code: 'ERR_MISSING_ARGS',
3838
type: TypeError,
3939
message: 'The "value" argument must be specified'
40-
}));
40+
});
4141

42-
assert.throws(() => {
42+
common.expectsError(() => {
4343
const outgoingMessage = new OutgoingMessage();
4444
outgoingMessage.setHeader(404);
45-
}, common.expectsError({
45+
}, {
4646
code: 'ERR_INVALID_HTTP_TOKEN',
4747
type: TypeError,
4848
message: 'Header name must be a valid HTTP token ["404"]'
49-
}));
49+
});
5050

51-
assert.throws(() => {
51+
common.expectsError(() => {
5252
const outgoingMessage = new OutgoingMessage();
5353
outgoingMessage.setHeader.call({ _header: 'test' }, 'test', 'value');
54-
}, common.expectsError({
54+
}, {
5555
code: 'ERR_HTTP_HEADERS_SENT',
5656
type: Error,
5757
message: 'Cannot set headers after they are sent to the client'
58-
}));
58+
});
5959

60-
assert.throws(() => {
60+
common.expectsError(() => {
6161
const outgoingMessage = new OutgoingMessage();
6262
outgoingMessage.setHeader('200', 'あ');
63-
}, common.expectsError({
63+
}, {
6464
code: 'ERR_INVALID_CHAR',
6565
type: TypeError,
6666
message: 'Invalid character in header content ["200"]'
67-
}));
67+
});
6868

6969
// write
70-
assert.throws(() => {
70+
common.expectsError(() => {
7171
const outgoingMessage = new OutgoingMessage();
7272
outgoingMessage.write();
73-
}, common.expectsError({
73+
}, {
7474
code: 'ERR_METHOD_NOT_IMPLEMENTED',
7575
type: Error,
7676
message: 'The _implicitHeader() method is not implemented'
77-
}));
77+
});
7878

7979
assert(OutgoingMessage.prototype.write.call({ _header: 'test' }));
8080

81-
assert.throws(() => {
81+
common.expectsError(() => {
8282
const outgoingMessage = new OutgoingMessage();
8383
outgoingMessage.write.call({ _header: 'test', _hasBody: 'test' });
84-
}, common.expectsError({
84+
}, {
8585
code: 'ERR_INVALID_ARG_TYPE',
8686
type: TypeError,
8787
message: 'The first argument must be one of type string or Buffer'
88-
}));
88+
});
8989

90-
assert.throws(() => {
90+
common.expectsError(() => {
9191
const outgoingMessage = new OutgoingMessage();
9292
outgoingMessage.write.call({ _header: 'test', _hasBody: 'test' }, 1);
93-
}, common.expectsError({
93+
}, {
9494
code: 'ERR_INVALID_ARG_TYPE',
9595
type: TypeError,
9696
message: 'The first argument must be one of type string or Buffer'
97-
}));
97+
});
9898

9999
// addTrailers()
100100
// The `Error` comes from the JavaScript engine so confirm that it is a
@@ -105,20 +105,20 @@ assert.throws(() => {
105105
outgoingMessage.addTrailers();
106106
}, TypeError);
107107

108-
assert.throws(() => {
108+
common.expectsError(() => {
109109
const outgoingMessage = new OutgoingMessage();
110110
outgoingMessage.addTrailers({ 'あ': 'value' });
111-
}, common.expectsError({
111+
}, {
112112
code: 'ERR_INVALID_HTTP_TOKEN',
113113
type: TypeError,
114114
message: 'Trailer name must be a valid HTTP token ["あ"]'
115-
}));
115+
});
116116

117-
assert.throws(() => {
117+
common.expectsError(() => {
118118
const outgoingMessage = new OutgoingMessage();
119119
outgoingMessage.addTrailers({ 404: 'あ' });
120-
}, common.expectsError({
120+
}, {
121121
code: 'ERR_INVALID_CHAR',
122122
type: TypeError,
123123
message: 'Invalid character in trailer content ["404"]'
124-
}));
124+
});
Collapse file

‎test/parallel/test-http2-client-request-options-errors.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-http2-client-request-options-errors.js
+3-4Lines changed: 3 additions & 4 deletions
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 http2 = require('http2');
87

98
// Check if correct errors are emitted when wrong type of data is passed
@@ -40,19 +39,19 @@ server.listen(0, common.mustCall(() => {
4039
return;
4140
}
4241

43-
assert.throws(
42+
common.expectsError(
4443
() => client.request({
4544
':method': 'CONNECT',
4645
':authority': `localhost:${port}`
4746
}, {
4847
[option]: types[type]
4948
}),
50-
common.expectsError({
49+
{
5150
type: TypeError,
5251
code: 'ERR_INVALID_OPT_VALUE',
5352
message: `The value "${String(types[type])}" is invalid ` +
5453
`for option "${option}"`
55-
})
54+
}
5655
);
5756
});
5857
});
Collapse file

‎test/parallel/test-http2-connect-method.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-http2-connect-method.js
+9-9Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -55,36 +55,36 @@ server.listen(0, common.mustCall(() => {
5555
const client = http2.connect(`http://localhost:${proxy.address().port}`);
5656

5757
// confirm that :authority is required and :scheme & :path are forbidden
58-
assert.throws(
58+
common.expectsError(
5959
() => client.request({
6060
[HTTP2_HEADER_METHOD]: 'CONNECT'
6161
}),
62-
common.expectsError({
62+
{
6363
code: 'ERR_HTTP2_CONNECT_AUTHORITY',
6464
message: ':authority header is required for CONNECT requests'
65-
})
65+
}
6666
);
67-
assert.throws(
67+
common.expectsError(
6868
() => client.request({
6969
[HTTP2_HEADER_METHOD]: 'CONNECT',
7070
[HTTP2_HEADER_AUTHORITY]: `localhost:${port}`,
7171
[HTTP2_HEADER_SCHEME]: 'http'
7272
}),
73-
common.expectsError({
73+
{
7474
code: 'ERR_HTTP2_CONNECT_SCHEME',
7575
message: 'The :scheme header is forbidden for CONNECT requests'
76-
})
76+
}
7777
);
78-
assert.throws(
78+
common.expectsError(
7979
() => client.request({
8080
[HTTP2_HEADER_METHOD]: 'CONNECT',
8181
[HTTP2_HEADER_AUTHORITY]: `localhost:${port}`,
8282
[HTTP2_HEADER_PATH]: '/'
8383
}),
84-
common.expectsError({
84+
{
8585
code: 'ERR_HTTP2_CONNECT_PATH',
8686
message: 'The :path header is forbidden for CONNECT requests'
87-
})
87+
}
8888
);
8989

9090
// valid CONNECT request

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.