in-process-request
Advanced tools
Comparing version 0.0.2 to 0.0.3
@@ -30,8 +30,18 @@ "use strict"; | ||
const addChunk = (chunk, encoding) => chunks.push(toBuffer(chunk, encoding)); | ||
res.write = (chunk) => { | ||
addChunk(chunk); | ||
res.write = (chunk, encodingOrCallback, maybeCallback) => { | ||
const encoding = typeof encodingOrCallback === 'string' ? encodingOrCallback : undefined; | ||
const callback = typeof maybeCallback === 'function' ? maybeCallback : encodingOrCallback; | ||
addChunk(chunk, encoding); | ||
if (typeof callback === 'function') { | ||
callback(); | ||
} | ||
return true; | ||
}; | ||
const overriddenEnd = (chunk, encoding) => { | ||
const overriddenEnd = (chunk, encodingOrCallback, maybeCallback) => { | ||
const encoding = typeof encodingOrCallback === 'string' ? encodingOrCallback : undefined; | ||
const callback = typeof maybeCallback === 'function' ? maybeCallback : encodingOrCallback; | ||
addChunk(chunk, encoding); | ||
if (typeof callback === 'function') { | ||
callback(); | ||
} | ||
const body = Buffer.concat(chunks); | ||
@@ -53,3 +63,8 @@ const headers = getHeaders_1.default(res); | ||
exports.createMockRequest = (opts) => { | ||
const req = new http_1.IncomingMessage(undefined); | ||
const socket = { | ||
remoteAddress: opts.remoteAddress || '123.123.123.123', | ||
remotePort: opts.remotePort || 5757, | ||
encrypted: opts.ssl ? true : false, | ||
}; | ||
const req = new http_1.IncomingMessage(socket); | ||
const body = toBuffer(opts.body); | ||
@@ -60,7 +75,2 @@ const contentLength = Buffer.byteLength(body); | ||
req.headers = keysToLowerCase(opts.headers || {}); | ||
req.connection = { | ||
remoteAddress: opts.remoteAddress || '123.123.123.123', | ||
remotePort: opts.remotePort || 5757, | ||
encrypted: opts.ssl ? true : false, | ||
}; | ||
if (contentLength > 0 && !req.headers['content-length']) { | ||
@@ -67,0 +77,0 @@ req.headers['content-length'] = contentLength.toString(); |
{ | ||
"name": "in-process-request", | ||
"version": "0.0.2", | ||
"version": "0.0.3", | ||
"license": "(MIT OR Apache-2.0)", | ||
@@ -5,0 +5,0 @@ "scripts": { |
@@ -11,2 +11,3 @@ # in-process-request | ||
* Connect v3 | ||
* Koa v2 | ||
* More to come... | ||
@@ -13,0 +14,0 @@ |
10829
162
171