test: replace assert.throws w/ common.expectsError
PR-URL: https://github.com/nodejs/node/pull/17557 Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
This commit is contained in:
parent
4df7c190bf
commit
094bfaf769
@ -17,12 +17,12 @@ common.expectsError(
|
|||||||
code: 'ERR_INVALID_ARG_TYPE',
|
code: 'ERR_INVALID_ARG_TYPE',
|
||||||
type: TypeError,
|
type: TypeError,
|
||||||
});
|
});
|
||||||
assert.throws(() => {
|
common.expectsError(() => {
|
||||||
new AsyncResource('invalid_trigger_id', { triggerAsyncId: null });
|
new AsyncResource('invalid_trigger_id', { triggerAsyncId: null });
|
||||||
}, common.expectsError({
|
}, {
|
||||||
code: 'ERR_INVALID_ASYNC_ID',
|
code: 'ERR_INVALID_ASYNC_ID',
|
||||||
type: RangeError,
|
type: RangeError,
|
||||||
}));
|
});
|
||||||
|
|
||||||
assert.strictEqual(
|
assert.strictEqual(
|
||||||
new AsyncResource('default_trigger_id').triggerAsyncId(),
|
new AsyncResource('default_trigger_id').triggerAsyncId(),
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
|
/* eslint-disable prefer-common-expectserror */
|
||||||
|
|
||||||
const common = require('../common');
|
const common = require('../common');
|
||||||
const assert = require('assert');
|
const assert = require('assert');
|
||||||
|
|
||||||
|
@ -20,6 +20,9 @@
|
|||||||
// USE OR OTHER DEALINGS IN THE SOFTWARE.
|
// USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
|
/* eslint-disable prefer-common-expectserror */
|
||||||
|
|
||||||
const common = require('../common');
|
const common = require('../common');
|
||||||
const assert = require('assert');
|
const assert = require('assert');
|
||||||
const a = assert;
|
const a = assert;
|
||||||
|
@ -974,12 +974,11 @@ assert.strictEqual(SlowBuffer.prototype.offset, undefined);
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ParseArrayIndex() should reject values that don't fit in a 32 bits size_t.
|
// ParseArrayIndex() should reject values that don't fit in a 32 bits size_t.
|
||||||
assert.throws(() => {
|
common.expectsError(() => {
|
||||||
const a = Buffer.alloc(1);
|
const a = Buffer.alloc(1);
|
||||||
const b = Buffer.alloc(1);
|
const b = Buffer.alloc(1);
|
||||||
a.copy(b, 0, 0x100000000, 0x100000001);
|
a.copy(b, 0, 0x100000000, 0x100000001);
|
||||||
}, common.expectsError(
|
}, { code: undefined, type: RangeError, message: 'Index out of range' });
|
||||||
{ code: undefined, type: RangeError, message: 'Index out of range' }));
|
|
||||||
|
|
||||||
// Unpooled buffer (replaces SlowBuffer)
|
// Unpooled buffer (replaces SlowBuffer)
|
||||||
{
|
{
|
||||||
|
@ -424,21 +424,19 @@ common.expectsError(() => {
|
|||||||
|
|
||||||
// Testing process.binding. Make sure "end" is properly checked for -1 wrap
|
// Testing process.binding. Make sure "end" is properly checked for -1 wrap
|
||||||
// around.
|
// around.
|
||||||
assert.throws(() => {
|
common.expectsError(() => {
|
||||||
process.binding('buffer').fill(Buffer.alloc(1), 1, 1, -2, 1);
|
process.binding('buffer').fill(Buffer.alloc(1), 1, 1, -2, 1);
|
||||||
}, common.expectsError(
|
}, { code: undefined, type: RangeError, message: 'Index out of range' });
|
||||||
{ code: undefined, type: RangeError, message: 'Index out of range' }));
|
|
||||||
|
|
||||||
// Test that bypassing 'length' won't cause an abort.
|
// Test that bypassing 'length' won't cause an abort.
|
||||||
assert.throws(() => {
|
common.expectsError(() => {
|
||||||
const buf = new Buffer('w00t');
|
const buf = new Buffer('w00t');
|
||||||
Object.defineProperty(buf, 'length', {
|
Object.defineProperty(buf, 'length', {
|
||||||
value: 1337,
|
value: 1337,
|
||||||
enumerable: true
|
enumerable: true
|
||||||
});
|
});
|
||||||
buf.fill('');
|
buf.fill('');
|
||||||
}, common.expectsError(
|
}, { code: undefined, type: RangeError, message: 'Index out of range' });
|
||||||
{ code: undefined, type: RangeError, message: 'Index out of range' }));
|
|
||||||
|
|
||||||
assert.deepStrictEqual(
|
assert.deepStrictEqual(
|
||||||
Buffer.allocUnsafeSlow(16).fill('ab', 'utf16le'),
|
Buffer.allocUnsafeSlow(16).fill('ab', 'utf16le'),
|
||||||
|
@ -47,17 +47,17 @@ common.expectsError(
|
|||||||
);
|
);
|
||||||
|
|
||||||
// Console constructor should throw if stderr exists but is not writable
|
// Console constructor should throw if stderr exists but is not writable
|
||||||
assert.throws(
|
common.expectsError(
|
||||||
() => {
|
() => {
|
||||||
out.write = () => {};
|
out.write = () => {};
|
||||||
err.write = undefined;
|
err.write = undefined;
|
||||||
new Console(out, err);
|
new Console(out, err);
|
||||||
},
|
},
|
||||||
common.expectsError({
|
{
|
||||||
code: 'ERR_CONSOLE_WRITABLE_STREAM',
|
code: 'ERR_CONSOLE_WRITABLE_STREAM',
|
||||||
type: TypeError,
|
type: TypeError,
|
||||||
message: /stderr/
|
message: /stderr/
|
||||||
})
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
out.write = err.write = (d) => {};
|
out.write = err.write = (d) => {};
|
||||||
|
@ -205,20 +205,20 @@ assert.doesNotThrow(() => {
|
|||||||
}, common.mustCall());
|
}, common.mustCall());
|
||||||
});
|
});
|
||||||
|
|
||||||
assert.throws(() => dns.lookupService('0.0.0.0'), common.expectsError({
|
common.expectsError(() => dns.lookupService('0.0.0.0'), {
|
||||||
code: 'ERR_MISSING_ARGS',
|
code: 'ERR_MISSING_ARGS',
|
||||||
type: TypeError,
|
type: TypeError,
|
||||||
message: 'The "host", "port", and "callback" arguments must be specified'
|
message: 'The "host", "port", and "callback" arguments must be specified'
|
||||||
}));
|
});
|
||||||
|
|
||||||
const invalidHost = 'fasdfdsaf';
|
const invalidHost = 'fasdfdsaf';
|
||||||
assert.throws(() => {
|
common.expectsError(() => {
|
||||||
dns.lookupService(invalidHost, 0, common.mustNotCall());
|
dns.lookupService(invalidHost, 0, common.mustNotCall());
|
||||||
}, common.expectsError({
|
}, {
|
||||||
code: 'ERR_INVALID_OPT_VALUE',
|
code: 'ERR_INVALID_OPT_VALUE',
|
||||||
type: TypeError,
|
type: TypeError,
|
||||||
message: `The value "${invalidHost}" is invalid for option "host"`
|
message: `The value "${invalidHost}" is invalid for option "host"`
|
||||||
}));
|
});
|
||||||
|
|
||||||
const portErr = (port) => {
|
const portErr = (port) => {
|
||||||
common.expectsError(
|
common.expectsError(
|
||||||
@ -238,9 +238,9 @@ portErr(undefined);
|
|||||||
portErr(65538);
|
portErr(65538);
|
||||||
portErr('test');
|
portErr('test');
|
||||||
|
|
||||||
assert.throws(() => {
|
common.expectsError(() => {
|
||||||
dns.lookupService('0.0.0.0', 80, null);
|
dns.lookupService('0.0.0.0', 80, null);
|
||||||
}, common.expectsError({
|
}, {
|
||||||
code: 'ERR_INVALID_CALLBACK',
|
code: 'ERR_INVALID_CALLBACK',
|
||||||
type: TypeError
|
type: TypeError
|
||||||
}));
|
});
|
||||||
|
@ -21,80 +21,80 @@ assert.strictEqual(
|
|||||||
typeof ServerResponse.prototype._implicitHeader, 'function');
|
typeof ServerResponse.prototype._implicitHeader, 'function');
|
||||||
|
|
||||||
// validateHeader
|
// validateHeader
|
||||||
assert.throws(() => {
|
common.expectsError(() => {
|
||||||
const outgoingMessage = new OutgoingMessage();
|
const outgoingMessage = new OutgoingMessage();
|
||||||
outgoingMessage.setHeader();
|
outgoingMessage.setHeader();
|
||||||
}, common.expectsError({
|
}, {
|
||||||
code: 'ERR_INVALID_HTTP_TOKEN',
|
code: 'ERR_INVALID_HTTP_TOKEN',
|
||||||
type: TypeError,
|
type: TypeError,
|
||||||
message: 'Header name must be a valid HTTP token ["undefined"]'
|
message: 'Header name must be a valid HTTP token ["undefined"]'
|
||||||
}));
|
});
|
||||||
|
|
||||||
assert.throws(() => {
|
common.expectsError(() => {
|
||||||
const outgoingMessage = new OutgoingMessage();
|
const outgoingMessage = new OutgoingMessage();
|
||||||
outgoingMessage.setHeader('test');
|
outgoingMessage.setHeader('test');
|
||||||
}, common.expectsError({
|
}, {
|
||||||
code: 'ERR_HTTP_INVALID_HEADER_VALUE',
|
code: 'ERR_HTTP_INVALID_HEADER_VALUE',
|
||||||
type: TypeError,
|
type: TypeError,
|
||||||
message: 'Invalid value "undefined" for header "test"'
|
message: 'Invalid value "undefined" for header "test"'
|
||||||
}));
|
});
|
||||||
|
|
||||||
assert.throws(() => {
|
common.expectsError(() => {
|
||||||
const outgoingMessage = new OutgoingMessage();
|
const outgoingMessage = new OutgoingMessage();
|
||||||
outgoingMessage.setHeader(404);
|
outgoingMessage.setHeader(404);
|
||||||
}, common.expectsError({
|
}, {
|
||||||
code: 'ERR_INVALID_HTTP_TOKEN',
|
code: 'ERR_INVALID_HTTP_TOKEN',
|
||||||
type: TypeError,
|
type: TypeError,
|
||||||
message: 'Header name must be a valid HTTP token ["404"]'
|
message: 'Header name must be a valid HTTP token ["404"]'
|
||||||
}));
|
});
|
||||||
|
|
||||||
assert.throws(() => {
|
common.expectsError(() => {
|
||||||
const outgoingMessage = new OutgoingMessage();
|
const outgoingMessage = new OutgoingMessage();
|
||||||
outgoingMessage.setHeader.call({ _header: 'test' }, 'test', 'value');
|
outgoingMessage.setHeader.call({ _header: 'test' }, 'test', 'value');
|
||||||
}, common.expectsError({
|
}, {
|
||||||
code: 'ERR_HTTP_HEADERS_SENT',
|
code: 'ERR_HTTP_HEADERS_SENT',
|
||||||
type: Error,
|
type: Error,
|
||||||
message: 'Cannot set headers after they are sent to the client'
|
message: 'Cannot set headers after they are sent to the client'
|
||||||
}));
|
});
|
||||||
|
|
||||||
assert.throws(() => {
|
common.expectsError(() => {
|
||||||
const outgoingMessage = new OutgoingMessage();
|
const outgoingMessage = new OutgoingMessage();
|
||||||
outgoingMessage.setHeader('200', 'あ');
|
outgoingMessage.setHeader('200', 'あ');
|
||||||
}, common.expectsError({
|
}, {
|
||||||
code: 'ERR_INVALID_CHAR',
|
code: 'ERR_INVALID_CHAR',
|
||||||
type: TypeError,
|
type: TypeError,
|
||||||
message: 'Invalid character in header content ["200"]'
|
message: 'Invalid character in header content ["200"]'
|
||||||
}));
|
});
|
||||||
|
|
||||||
// write
|
// write
|
||||||
assert.throws(() => {
|
common.expectsError(() => {
|
||||||
const outgoingMessage = new OutgoingMessage();
|
const outgoingMessage = new OutgoingMessage();
|
||||||
outgoingMessage.write();
|
outgoingMessage.write();
|
||||||
}, common.expectsError({
|
}, {
|
||||||
code: 'ERR_METHOD_NOT_IMPLEMENTED',
|
code: 'ERR_METHOD_NOT_IMPLEMENTED',
|
||||||
type: Error,
|
type: Error,
|
||||||
message: 'The _implicitHeader() method is not implemented'
|
message: 'The _implicitHeader() method is not implemented'
|
||||||
}));
|
});
|
||||||
|
|
||||||
assert(OutgoingMessage.prototype.write.call({ _header: 'test' }));
|
assert(OutgoingMessage.prototype.write.call({ _header: 'test' }));
|
||||||
|
|
||||||
assert.throws(() => {
|
common.expectsError(() => {
|
||||||
const outgoingMessage = new OutgoingMessage();
|
const outgoingMessage = new OutgoingMessage();
|
||||||
outgoingMessage.write.call({ _header: 'test', _hasBody: 'test' });
|
outgoingMessage.write.call({ _header: 'test', _hasBody: 'test' });
|
||||||
}, common.expectsError({
|
}, {
|
||||||
code: 'ERR_INVALID_ARG_TYPE',
|
code: 'ERR_INVALID_ARG_TYPE',
|
||||||
type: TypeError,
|
type: TypeError,
|
||||||
message: 'The first argument must be one of type string or Buffer'
|
message: 'The first argument must be one of type string or Buffer'
|
||||||
}));
|
});
|
||||||
|
|
||||||
assert.throws(() => {
|
common.expectsError(() => {
|
||||||
const outgoingMessage = new OutgoingMessage();
|
const outgoingMessage = new OutgoingMessage();
|
||||||
outgoingMessage.write.call({ _header: 'test', _hasBody: 'test' }, 1);
|
outgoingMessage.write.call({ _header: 'test', _hasBody: 'test' }, 1);
|
||||||
}, common.expectsError({
|
}, {
|
||||||
code: 'ERR_INVALID_ARG_TYPE',
|
code: 'ERR_INVALID_ARG_TYPE',
|
||||||
type: TypeError,
|
type: TypeError,
|
||||||
message: 'The first argument must be one of type string or Buffer'
|
message: 'The first argument must be one of type string or Buffer'
|
||||||
}));
|
});
|
||||||
|
|
||||||
// addTrailers()
|
// addTrailers()
|
||||||
// The `Error` comes from the JavaScript engine so confirm that it is a
|
// The `Error` comes from the JavaScript engine so confirm that it is a
|
||||||
@ -105,20 +105,20 @@ assert.throws(() => {
|
|||||||
outgoingMessage.addTrailers();
|
outgoingMessage.addTrailers();
|
||||||
}, TypeError);
|
}, TypeError);
|
||||||
|
|
||||||
assert.throws(() => {
|
common.expectsError(() => {
|
||||||
const outgoingMessage = new OutgoingMessage();
|
const outgoingMessage = new OutgoingMessage();
|
||||||
outgoingMessage.addTrailers({ 'あ': 'value' });
|
outgoingMessage.addTrailers({ 'あ': 'value' });
|
||||||
}, common.expectsError({
|
}, {
|
||||||
code: 'ERR_INVALID_HTTP_TOKEN',
|
code: 'ERR_INVALID_HTTP_TOKEN',
|
||||||
type: TypeError,
|
type: TypeError,
|
||||||
message: 'Trailer name must be a valid HTTP token ["あ"]'
|
message: 'Trailer name must be a valid HTTP token ["あ"]'
|
||||||
}));
|
});
|
||||||
|
|
||||||
assert.throws(() => {
|
common.expectsError(() => {
|
||||||
const outgoingMessage = new OutgoingMessage();
|
const outgoingMessage = new OutgoingMessage();
|
||||||
outgoingMessage.addTrailers({ 404: 'あ' });
|
outgoingMessage.addTrailers({ 404: 'あ' });
|
||||||
}, common.expectsError({
|
}, {
|
||||||
code: 'ERR_INVALID_CHAR',
|
code: 'ERR_INVALID_CHAR',
|
||||||
type: TypeError,
|
type: TypeError,
|
||||||
message: 'Invalid character in trailer content ["404"]'
|
message: 'Invalid character in trailer content ["404"]'
|
||||||
}));
|
});
|
||||||
|
@ -3,7 +3,6 @@
|
|||||||
const common = require('../common');
|
const common = require('../common');
|
||||||
if (!common.hasCrypto)
|
if (!common.hasCrypto)
|
||||||
common.skip('missing crypto');
|
common.skip('missing crypto');
|
||||||
const assert = require('assert');
|
|
||||||
const http2 = require('http2');
|
const http2 = require('http2');
|
||||||
|
|
||||||
// Check if correct errors are emitted when wrong type of data is passed
|
// Check if correct errors are emitted when wrong type of data is passed
|
||||||
@ -40,19 +39,19 @@ server.listen(0, common.mustCall(() => {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
assert.throws(
|
common.expectsError(
|
||||||
() => client.request({
|
() => client.request({
|
||||||
':method': 'CONNECT',
|
':method': 'CONNECT',
|
||||||
':authority': `localhost:${port}`
|
':authority': `localhost:${port}`
|
||||||
}, {
|
}, {
|
||||||
[option]: types[type]
|
[option]: types[type]
|
||||||
}),
|
}),
|
||||||
common.expectsError({
|
{
|
||||||
type: TypeError,
|
type: TypeError,
|
||||||
code: 'ERR_INVALID_OPT_VALUE',
|
code: 'ERR_INVALID_OPT_VALUE',
|
||||||
message: `The value "${String(types[type])}" is invalid ` +
|
message: `The value "${String(types[type])}" is invalid ` +
|
||||||
`for option "${option}"`
|
`for option "${option}"`
|
||||||
})
|
}
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -55,36 +55,36 @@ server.listen(0, common.mustCall(() => {
|
|||||||
const client = http2.connect(`http://localhost:${proxy.address().port}`);
|
const client = http2.connect(`http://localhost:${proxy.address().port}`);
|
||||||
|
|
||||||
// confirm that :authority is required and :scheme & :path are forbidden
|
// confirm that :authority is required and :scheme & :path are forbidden
|
||||||
assert.throws(
|
common.expectsError(
|
||||||
() => client.request({
|
() => client.request({
|
||||||
[HTTP2_HEADER_METHOD]: 'CONNECT'
|
[HTTP2_HEADER_METHOD]: 'CONNECT'
|
||||||
}),
|
}),
|
||||||
common.expectsError({
|
{
|
||||||
code: 'ERR_HTTP2_CONNECT_AUTHORITY',
|
code: 'ERR_HTTP2_CONNECT_AUTHORITY',
|
||||||
message: ':authority header is required for CONNECT requests'
|
message: ':authority header is required for CONNECT requests'
|
||||||
})
|
}
|
||||||
);
|
);
|
||||||
assert.throws(
|
common.expectsError(
|
||||||
() => client.request({
|
() => client.request({
|
||||||
[HTTP2_HEADER_METHOD]: 'CONNECT',
|
[HTTP2_HEADER_METHOD]: 'CONNECT',
|
||||||
[HTTP2_HEADER_AUTHORITY]: `localhost:${port}`,
|
[HTTP2_HEADER_AUTHORITY]: `localhost:${port}`,
|
||||||
[HTTP2_HEADER_SCHEME]: 'http'
|
[HTTP2_HEADER_SCHEME]: 'http'
|
||||||
}),
|
}),
|
||||||
common.expectsError({
|
{
|
||||||
code: 'ERR_HTTP2_CONNECT_SCHEME',
|
code: 'ERR_HTTP2_CONNECT_SCHEME',
|
||||||
message: 'The :scheme header is forbidden for CONNECT requests'
|
message: 'The :scheme header is forbidden for CONNECT requests'
|
||||||
})
|
}
|
||||||
);
|
);
|
||||||
assert.throws(
|
common.expectsError(
|
||||||
() => client.request({
|
() => client.request({
|
||||||
[HTTP2_HEADER_METHOD]: 'CONNECT',
|
[HTTP2_HEADER_METHOD]: 'CONNECT',
|
||||||
[HTTP2_HEADER_AUTHORITY]: `localhost:${port}`,
|
[HTTP2_HEADER_AUTHORITY]: `localhost:${port}`,
|
||||||
[HTTP2_HEADER_PATH]: '/'
|
[HTTP2_HEADER_PATH]: '/'
|
||||||
}),
|
}),
|
||||||
common.expectsError({
|
{
|
||||||
code: 'ERR_HTTP2_CONNECT_PATH',
|
code: 'ERR_HTTP2_CONNECT_PATH',
|
||||||
message: 'The :path header is forbidden for CONNECT requests'
|
message: 'The :path header is forbidden for CONNECT requests'
|
||||||
})
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
// valid CONNECT request
|
// valid CONNECT request
|
||||||
|
@ -5,7 +5,6 @@ if (!common.hasCrypto)
|
|||||||
common.skip('missing crypto');
|
common.skip('missing crypto');
|
||||||
const fixtures = require('../common/fixtures');
|
const fixtures = require('../common/fixtures');
|
||||||
const http2 = require('http2');
|
const http2 = require('http2');
|
||||||
const assert = require('assert');
|
|
||||||
|
|
||||||
const {
|
const {
|
||||||
HTTP2_HEADER_CONTENT_TYPE,
|
HTTP2_HEADER_CONTENT_TYPE,
|
||||||
@ -16,16 +15,16 @@ const fname = fixtures.path('elipses.txt');
|
|||||||
|
|
||||||
const server = http2.createServer();
|
const server = http2.createServer();
|
||||||
server.on('stream', (stream) => {
|
server.on('stream', (stream) => {
|
||||||
assert.throws(() => {
|
common.expectsError(() => {
|
||||||
stream.respondWithFile(fname, {
|
stream.respondWithFile(fname, {
|
||||||
[HTTP2_HEADER_STATUS]: 204,
|
[HTTP2_HEADER_STATUS]: 204,
|
||||||
[HTTP2_HEADER_CONTENT_TYPE]: 'text/plain'
|
[HTTP2_HEADER_CONTENT_TYPE]: 'text/plain'
|
||||||
});
|
});
|
||||||
}, common.expectsError({
|
}, {
|
||||||
code: 'ERR_HTTP2_PAYLOAD_FORBIDDEN',
|
code: 'ERR_HTTP2_PAYLOAD_FORBIDDEN',
|
||||||
type: Error,
|
type: Error,
|
||||||
message: 'Responses with 204 status must not have a payload'
|
message: 'Responses with 204 status must not have a payload'
|
||||||
}));
|
});
|
||||||
stream.respond({});
|
stream.respond({});
|
||||||
stream.end();
|
stream.end();
|
||||||
});
|
});
|
||||||
|
@ -21,16 +21,16 @@ server.on('stream', common.mustCall((stream) => {
|
|||||||
// and pushStream() must throw.
|
// and pushStream() must throw.
|
||||||
assert.strictEqual(stream.pushAllowed, false);
|
assert.strictEqual(stream.pushAllowed, false);
|
||||||
|
|
||||||
assert.throws(() => {
|
common.expectsError(() => {
|
||||||
stream.pushStream({
|
stream.pushStream({
|
||||||
':scheme': 'http',
|
':scheme': 'http',
|
||||||
':path': '/foobar',
|
':path': '/foobar',
|
||||||
':authority': `localhost:${server.address().port}`,
|
':authority': `localhost:${server.address().port}`,
|
||||||
}, common.mustNotCall());
|
}, common.mustNotCall());
|
||||||
}, common.expectsError({
|
}, {
|
||||||
code: 'ERR_HTTP2_PUSH_DISABLED',
|
code: 'ERR_HTTP2_PUSH_DISABLED',
|
||||||
type: Error
|
type: Error
|
||||||
}));
|
});
|
||||||
|
|
||||||
stream.respond({ ':status': 200 });
|
stream.respond({ ':status': 200 });
|
||||||
stream.end('test');
|
stream.end('test');
|
||||||
|
@ -14,15 +14,15 @@ server.on('stream', common.mustCall(onStream));
|
|||||||
function onStream(stream, headers, flags) {
|
function onStream(stream, headers, flags) {
|
||||||
stream.rstStream();
|
stream.rstStream();
|
||||||
|
|
||||||
assert.throws(() => {
|
common.expectsError(() => {
|
||||||
stream.additionalHeaders({
|
stream.additionalHeaders({
|
||||||
':status': 123,
|
':status': 123,
|
||||||
abc: 123
|
abc: 123
|
||||||
});
|
});
|
||||||
}, common.expectsError({
|
}, {
|
||||||
code: 'ERR_HTTP2_INVALID_STREAM',
|
code: 'ERR_HTTP2_INVALID_STREAM',
|
||||||
message: /^The stream has been destroyed$/
|
message: /^The stream has been destroyed$/
|
||||||
}));
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
server.listen(0);
|
server.listen(0);
|
||||||
|
@ -101,16 +101,16 @@ const invalidCertRE = /^The "cert" argument must be one of type string, Buffer,
|
|||||||
[[keyStr, keyStr2], true, invalidCertRE],
|
[[keyStr, keyStr2], true, invalidCertRE],
|
||||||
[true, [certBuff, certBuff2], invalidKeyRE]
|
[true, [certBuff, certBuff2], invalidKeyRE]
|
||||||
].map((params) => {
|
].map((params) => {
|
||||||
assert.throws(() => {
|
common.expectsError(() => {
|
||||||
https.createServer({
|
https.createServer({
|
||||||
key: params[0],
|
key: params[0],
|
||||||
cert: params[1]
|
cert: params[1]
|
||||||
});
|
});
|
||||||
}, common.expectsError({
|
}, {
|
||||||
code: 'ERR_INVALID_ARG_TYPE',
|
code: 'ERR_INVALID_ARG_TYPE',
|
||||||
type: TypeError,
|
type: TypeError,
|
||||||
message: params[2]
|
message: params[2]
|
||||||
}));
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
// Checks to ensure https.createServer works with the CA parameter
|
// Checks to ensure https.createServer works with the CA parameter
|
||||||
@ -142,15 +142,15 @@ const invalidCertRE = /^The "cert" argument must be one of type string, Buffer,
|
|||||||
[keyBuff, certBuff, true],
|
[keyBuff, certBuff, true],
|
||||||
[keyBuff, certBuff, [caCert, true]]
|
[keyBuff, certBuff, [caCert, true]]
|
||||||
].map((params) => {
|
].map((params) => {
|
||||||
assert.throws(() => {
|
common.expectsError(() => {
|
||||||
https.createServer({
|
https.createServer({
|
||||||
key: params[0],
|
key: params[0],
|
||||||
cert: params[1],
|
cert: params[1],
|
||||||
ca: params[2]
|
ca: params[2]
|
||||||
});
|
});
|
||||||
}, common.expectsError({
|
}, {
|
||||||
code: 'ERR_INVALID_ARG_TYPE',
|
code: 'ERR_INVALID_ARG_TYPE',
|
||||||
type: TypeError,
|
type: TypeError,
|
||||||
message: /^The "ca" argument must be one of type string, Buffer, TypedArray, or DataView$/
|
message: /^The "ca" argument must be one of type string, Buffer, TypedArray, or DataView$/
|
||||||
}));
|
});
|
||||||
});
|
});
|
||||||
|
@ -141,29 +141,29 @@ common.expectsError(
|
|||||||
|
|
||||||
// Tests for common.expectsError
|
// Tests for common.expectsError
|
||||||
assert.doesNotThrow(() => {
|
assert.doesNotThrow(() => {
|
||||||
assert.throws(() => {
|
common.expectsError(() => {
|
||||||
throw new errors.TypeError('TEST_ERROR_1', 'a');
|
throw new errors.TypeError('TEST_ERROR_1', 'a');
|
||||||
}, common.expectsError({ code: 'TEST_ERROR_1' }));
|
}, { code: 'TEST_ERROR_1' });
|
||||||
});
|
});
|
||||||
|
|
||||||
assert.doesNotThrow(() => {
|
assert.doesNotThrow(() => {
|
||||||
assert.throws(() => {
|
common.expectsError(() => {
|
||||||
throw new errors.TypeError('TEST_ERROR_1', 'a');
|
throw new errors.TypeError('TEST_ERROR_1', 'a');
|
||||||
}, common.expectsError({ code: 'TEST_ERROR_1',
|
}, { code: 'TEST_ERROR_1',
|
||||||
type: TypeError,
|
type: TypeError,
|
||||||
message: /^Error for testing/ }));
|
message: /^Error for testing/ });
|
||||||
});
|
});
|
||||||
|
|
||||||
assert.doesNotThrow(() => {
|
assert.doesNotThrow(() => {
|
||||||
assert.throws(() => {
|
common.expectsError(() => {
|
||||||
throw new errors.TypeError('TEST_ERROR_1', 'a');
|
throw new errors.TypeError('TEST_ERROR_1', 'a');
|
||||||
}, common.expectsError({ code: 'TEST_ERROR_1', type: TypeError }));
|
}, { code: 'TEST_ERROR_1', type: TypeError });
|
||||||
});
|
});
|
||||||
|
|
||||||
assert.doesNotThrow(() => {
|
assert.doesNotThrow(() => {
|
||||||
assert.throws(() => {
|
common.expectsError(() => {
|
||||||
throw new errors.TypeError('TEST_ERROR_1', 'a');
|
throw new errors.TypeError('TEST_ERROR_1', 'a');
|
||||||
}, common.expectsError({ code: 'TEST_ERROR_1', type: Error }));
|
}, { code: 'TEST_ERROR_1', type: Error });
|
||||||
});
|
});
|
||||||
|
|
||||||
common.expectsError(() => {
|
common.expectsError(() => {
|
||||||
|
@ -68,12 +68,13 @@ assert.strictEqual(typeof performance.timeOrigin, 'number');
|
|||||||
});
|
});
|
||||||
|
|
||||||
[undefined, null, 'foo', 1].forEach((i) => {
|
[undefined, null, 'foo', 1].forEach((i) => {
|
||||||
assert.throws(() => performance.measure('test', 'A', i),
|
common.expectsError(
|
||||||
common.expectsError({
|
() => performance.measure('test', 'A', i),
|
||||||
code: 'ERR_INVALID_PERFORMANCE_MARK',
|
{
|
||||||
type: Error,
|
code: 'ERR_INVALID_PERFORMANCE_MARK',
|
||||||
message: `The "${i}" performance mark has not been set`
|
type: Error,
|
||||||
}));
|
message: `The "${i}" performance mark has not been set`
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
performance.clearMeasures();
|
performance.clearMeasures();
|
||||||
|
@ -28,33 +28,34 @@ assert.strictEqual(counts[NODE_PERFORMANCE_ENTRY_TYPE_FUNCTION], 0);
|
|||||||
|
|
||||||
{
|
{
|
||||||
[1, null, undefined, {}, [], Infinity].forEach((i) => {
|
[1, null, undefined, {}, [], Infinity].forEach((i) => {
|
||||||
assert.throws(() => new PerformanceObserver(i),
|
common.expectsError(() => new PerformanceObserver(i),
|
||||||
common.expectsError({
|
{
|
||||||
code: 'ERR_INVALID_CALLBACK',
|
code: 'ERR_INVALID_CALLBACK',
|
||||||
type: TypeError,
|
type: TypeError,
|
||||||
message: 'Callback must be a function'
|
message: 'Callback must be a function'
|
||||||
}));
|
});
|
||||||
});
|
});
|
||||||
const observer = new PerformanceObserver(common.mustNotCall());
|
const observer = new PerformanceObserver(common.mustNotCall());
|
||||||
|
|
||||||
[1, null, undefined].forEach((i) => {
|
[1, null, undefined].forEach((i) => {
|
||||||
//observer.observe(i);
|
//observer.observe(i);
|
||||||
assert.throws(() => observer.observe(i),
|
common.expectsError(
|
||||||
common.expectsError({
|
() => observer.observe(i),
|
||||||
code: 'ERR_INVALID_ARG_TYPE',
|
{
|
||||||
type: TypeError,
|
code: 'ERR_INVALID_ARG_TYPE',
|
||||||
message: 'The "options" argument must be of type Object'
|
type: TypeError,
|
||||||
}));
|
message: 'The "options" argument must be of type Object'
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
[1, undefined, null, {}, Infinity].forEach((i) => {
|
[1, undefined, null, {}, Infinity].forEach((i) => {
|
||||||
assert.throws(() => observer.observe({ entryTypes: i }),
|
common.expectsError(() => observer.observe({ entryTypes: i }),
|
||||||
common.expectsError({
|
{
|
||||||
code: 'ERR_INVALID_OPT_VALUE',
|
code: 'ERR_INVALID_OPT_VALUE',
|
||||||
type: TypeError,
|
type: TypeError,
|
||||||
message: 'The value "[object Object]" is invalid for ' +
|
message: 'The value "[object Object]" is invalid ' +
|
||||||
'option "entryTypes"'
|
'for option "entryTypes"'
|
||||||
}));
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -357,46 +357,46 @@ function isWarned(emitter) {
|
|||||||
// constructor throws if completer is not a function or undefined
|
// constructor throws if completer is not a function or undefined
|
||||||
{
|
{
|
||||||
const fi = new FakeInput();
|
const fi = new FakeInput();
|
||||||
assert.throws(function() {
|
common.expectsError(function() {
|
||||||
readline.createInterface({
|
readline.createInterface({
|
||||||
input: fi,
|
input: fi,
|
||||||
completer: 'string is not valid'
|
completer: 'string is not valid'
|
||||||
});
|
});
|
||||||
}, common.expectsError({
|
}, {
|
||||||
type: TypeError,
|
type: TypeError,
|
||||||
code: 'ERR_INVALID_OPT_VALUE'
|
code: 'ERR_INVALID_OPT_VALUE'
|
||||||
}));
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// constructor throws if historySize is not a positive number
|
// constructor throws if historySize is not a positive number
|
||||||
{
|
{
|
||||||
const fi = new FakeInput();
|
const fi = new FakeInput();
|
||||||
assert.throws(function() {
|
common.expectsError(function() {
|
||||||
readline.createInterface({
|
readline.createInterface({
|
||||||
input: fi, historySize: 'not a number'
|
input: fi, historySize: 'not a number'
|
||||||
});
|
});
|
||||||
}, common.expectsError({
|
}, {
|
||||||
type: RangeError,
|
type: RangeError,
|
||||||
code: 'ERR_INVALID_OPT_VALUE'
|
code: 'ERR_INVALID_OPT_VALUE'
|
||||||
}));
|
});
|
||||||
|
|
||||||
assert.throws(function() {
|
common.expectsError(function() {
|
||||||
readline.createInterface({
|
readline.createInterface({
|
||||||
input: fi, historySize: -1
|
input: fi, historySize: -1
|
||||||
});
|
});
|
||||||
}, common.expectsError({
|
}, {
|
||||||
type: RangeError,
|
type: RangeError,
|
||||||
code: 'ERR_INVALID_OPT_VALUE'
|
code: 'ERR_INVALID_OPT_VALUE'
|
||||||
}));
|
});
|
||||||
|
|
||||||
assert.throws(function() {
|
common.expectsError(function() {
|
||||||
readline.createInterface({
|
readline.createInterface({
|
||||||
input: fi, historySize: NaN
|
input: fi, historySize: NaN
|
||||||
});
|
});
|
||||||
}, common.expectsError({
|
}, {
|
||||||
type: RangeError,
|
type: RangeError,
|
||||||
code: 'ERR_INVALID_OPT_VALUE'
|
code: 'ERR_INVALID_OPT_VALUE'
|
||||||
}));
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// duplicate lines are removed from history when
|
// duplicate lines are removed from history when
|
||||||
|
@ -13,12 +13,12 @@ const tls = require('tls');
|
|||||||
lookup: input
|
lookup: input
|
||||||
};
|
};
|
||||||
|
|
||||||
assert.throws(function() {
|
common.expectsError(function() {
|
||||||
tls.connect(opts);
|
tls.connect(opts);
|
||||||
}, common.expectsError({
|
}, {
|
||||||
code: 'ERR_INVALID_ARG_TYPE',
|
code: 'ERR_INVALID_ARG_TYPE',
|
||||||
type: TypeError
|
type: TypeError
|
||||||
}));
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
connectDoesNotThrow(common.mustCall(() => {}));
|
connectDoesNotThrow(common.mustCall(() => {}));
|
||||||
|
Loading…
x
Reference in New Issue
Block a user