test: unflake some net specs (#18782)

This commit is contained in:
Jeremy Apthorp 2019-06-14 16:26:07 -07:00 committed by GitHub
parent 45f5f2ba1a
commit 7b26048d9e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 1304 additions and 1716 deletions

View file

@ -96,11 +96,11 @@ class IncomingMessage extends Readable {
} }
get rawTrailers () { get rawTrailers () {
throw new Error('HTTP trailers are not supported.') throw new Error('HTTP trailers are not supported')
} }
get trailers () { get trailers () {
throw new Error('HTTP trailers are not supported.') throw new Error('HTTP trailers are not supported')
} }
_storeInternalData (chunk) { _storeInternalData (chunk) {
@ -161,7 +161,7 @@ class ClientRequest extends EventEmitter {
const urlObj = {} const urlObj = {}
const protocol = options.protocol || 'http:' const protocol = options.protocol || 'http:'
if (!kSupportedProtocols.has(protocol)) { if (!kSupportedProtocols.has(protocol)) {
throw new Error('Protocol "' + protocol + '" not supported. ') throw new Error('Protocol "' + protocol + '" not supported')
} }
urlObj.protocol = protocol urlObj.protocol = protocol
@ -186,7 +186,7 @@ class ClientRequest extends EventEmitter {
// well, and b) possibly too restrictive for real-world usage. That's // well, and b) possibly too restrictive for real-world usage. That's
// why it only scans for spaces because those are guaranteed to create // why it only scans for spaces because those are guaranteed to create
// an invalid request. // an invalid request.
throw new TypeError('Request path contains unescaped characters.') throw new TypeError('Request path contains unescaped characters')
} }
const pathObj = url.parse(options.path || '/') const pathObj = url.parse(options.path || '/')
urlObj.pathname = pathObj.pathname urlObj.pathname = pathObj.pathname
@ -209,13 +209,13 @@ class ClientRequest extends EventEmitter {
if (options.session instanceof Session) { if (options.session instanceof Session) {
urlRequestOptions.session = options.session urlRequestOptions.session = options.session
} else { } else {
throw new TypeError('`session` should be an instance of the Session class.') throw new TypeError('`session` should be an instance of the Session class')
} }
} else if (options.partition) { } else if (options.partition) {
if (typeof options.partition === 'string') { if (typeof options.partition === 'string') {
urlRequestOptions.partition = options.partition urlRequestOptions.partition = options.partition
} else { } else {
throw new TypeError('`partition` should be an a string.') throw new TypeError('`partition` should be a string')
} }
} }
@ -276,20 +276,20 @@ class ClientRequest extends EventEmitter {
set chunkedEncoding (value) { set chunkedEncoding (value) {
if (!this.urlRequest.notStarted) { if (!this.urlRequest.notStarted) {
throw new Error('Can\'t set the transfer encoding, headers have been sent.') throw new Error('Can\'t set the transfer encoding, headers have been sent')
} }
this.chunkedEncodingEnabled = value this.chunkedEncodingEnabled = value
} }
setHeader (name, value) { setHeader (name, value) {
if (typeof name !== 'string') { if (typeof name !== 'string') {
throw new TypeError('`name` should be a string in setHeader(name, value).') throw new TypeError('`name` should be a string in setHeader(name, value)')
} }
if (value == null) { if (value == null) {
throw new Error('`value` required in setHeader("' + name + '", value).') throw new Error('`value` required in setHeader("' + name + '", value)')
} }
if (!this.urlRequest.notStarted) { if (!this.urlRequest.notStarted) {
throw new Error('Can\'t set headers after they are sent.') throw new Error('Can\'t set headers after they are sent')
} }
const key = name.toLowerCase() const key = name.toLowerCase()
@ -299,7 +299,7 @@ class ClientRequest extends EventEmitter {
getHeader (name) { getHeader (name) {
if (name == null) { if (name == null) {
throw new Error('`name` is required for getHeader(name).') throw new Error('`name` is required for getHeader(name)')
} }
if (!this.extraHeaders) { if (!this.extraHeaders) {
@ -312,11 +312,11 @@ class ClientRequest extends EventEmitter {
removeHeader (name) { removeHeader (name) {
if (name == null) { if (name == null) {
throw new Error('`name` is required for removeHeader(name).') throw new Error('`name` is required for removeHeader(name)')
} }
if (!this.urlRequest.notStarted) { if (!this.urlRequest.notStarted) {
throw new Error('Can\'t remove headers after they are sent.') throw new Error('Can\'t remove headers after they are sent')
} }
const key = name.toLowerCase() const key = name.toLowerCase()
@ -328,7 +328,7 @@ class ClientRequest extends EventEmitter {
const chunkIsString = typeof chunk === 'string' const chunkIsString = typeof chunk === 'string'
const chunkIsBuffer = chunk instanceof Buffer const chunkIsBuffer = chunk instanceof Buffer
if (!chunkIsString && !chunkIsBuffer) { if (!chunkIsString && !chunkIsBuffer) {
throw new TypeError('First argument must be a string or Buffer.') throw new TypeError('First argument must be a string or Buffer')
} }
if (chunkIsString) { if (chunkIsString) {
@ -357,7 +357,7 @@ class ClientRequest extends EventEmitter {
write (data, encoding, callback) { write (data, encoding, callback) {
if (this.urlRequest.finished) { if (this.urlRequest.finished) {
const error = new Error('Write after end.') const error = new Error('Write after end')
process.nextTick(writeAfterEndNT, this, error, callback) process.nextTick(writeAfterEndNT, this, error, callback)
return true return true
} }

1289
spec-main/api-net-spec.ts Normal file

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff