light-my-request
Advanced tools
Comparing version 3.0.0 to 3.1.0
@@ -47,3 +47,4 @@ 'use strict' | ||
var payload = options.payload || null | ||
// we keep both payload and body for compatibility reasons | ||
var payload = options.payload || options.body || null | ||
if (payload && typeof payload !== 'string' && !(typeof payload.resume === 'function') && !Buffer.isBuffer(payload)) { | ||
@@ -50,0 +51,0 @@ payload = JSON.stringify(payload) |
@@ -104,3 +104,6 @@ 'use strict' | ||
res.rawPayload = rawBuffer | ||
// we keep both of them for compatibility reasons | ||
res.payload = rawBuffer.toString() | ||
res.body = res.payload | ||
res.trailers = response._lightMyRequest.trailers | ||
@@ -107,0 +110,0 @@ |
{ | ||
"name": "light-my-request", | ||
"version": "3.0.0", | ||
"version": "3.1.0", | ||
"description": "Fake HTTP injection library", | ||
@@ -13,3 +13,3 @@ "main": "index.js", | ||
"pre-commit": "^1.2.2", | ||
"standard": "^11.0.0", | ||
"standard": "^12.0.0", | ||
"tap": "^12.0.0" | ||
@@ -16,0 +16,0 @@ }, |
@@ -63,2 +63,3 @@ # Light my Request | ||
- `payload` - an optional request payload. Can be a string, Buffer, Stream or object. | ||
- `body` - alias for payload. | ||
- `simulate` - an object containing flags to simulate various conditions: | ||
@@ -81,2 +82,3 @@ - `end` - indicates whether the request will fire an `end` event. Defaults to `undefined`, meaning an `end` event will fire. | ||
- `payload` - the payload as a UTF-8 encoded string. | ||
- `body` - alias for payload. | ||
- `rawPayload` - the raw payload as a Buffer. | ||
@@ -83,0 +85,0 @@ - `trailers` - an object containing the response trailers. |
@@ -387,2 +387,16 @@ 'use strict' | ||
test('supports body option in Request and property in Response', (t) => { | ||
t.plan(3) | ||
const dispatch = function (req, res) { | ||
res.writeHead(200, { 'content-type': req.headers['content-type'] }) | ||
req.pipe(res) | ||
} | ||
inject(dispatch, { method: 'POST', url: '/test', body: { a: 1 } }, (err, res) => { | ||
t.error(err) | ||
t.equal(res.headers['content-type'], 'application/json') | ||
t.equal(res.body, '{"a":1}') | ||
}) | ||
}) | ||
test('echos buffer payload', (t) => { | ||
@@ -389,0 +403,0 @@ t.plan(2) |
39205
1037
99