light-my-request
Advanced tools
Comparing version 4.2.1 to 4.3.0
@@ -89,3 +89,3 @@ import * as stream from 'stream' | ||
interface Chain { | ||
interface Chain extends Promise<Response> { | ||
delete: (url: string) => Chain | ||
@@ -104,3 +104,4 @@ get: (url: string) => Chain | ||
cookies: (query: object) => Chain | ||
end: (callback?: CallbackFunc) => Promise<Response> | ||
end(): Promise<Response> | ||
end(callback: CallbackFunc): void | ||
} | ||
@@ -107,0 +108,0 @@ } |
@@ -96,3 +96,3 @@ 'use strict' | ||
// we keep both payload and body for compatibility reasons | ||
var payload = options.payload || options.body || null | ||
let payload = options.payload || options.body || null | ||
if (payload && typeof payload !== 'string' && !(typeof payload.resume === 'function') && !Buffer.isBuffer(payload)) { | ||
@@ -99,0 +99,0 @@ payload = JSON.stringify(payload) |
{ | ||
"name": "light-my-request", | ||
"version": "4.2.1", | ||
"version": "4.3.0", | ||
"description": "Fake HTTP injection library", | ||
@@ -20,3 +20,3 @@ "main": "index.js", | ||
"pre-commit": "^1.2.2", | ||
"standard": "^14.3.3", | ||
"standard": "^16.0.1", | ||
"tap": "^14.0.0", | ||
@@ -23,0 +23,0 @@ "tsd": "^0.13.1" |
'use strict' | ||
function asyncAwaitTest (t, inject) { | ||
t.plan(3) | ||
t.plan(4) | ||
@@ -47,4 +47,18 @@ t.test('basic async await', async t => { | ||
}) | ||
t.test('chainable api with async await without end()', async t => { | ||
const dispatch = function (req, res) { | ||
res.writeHead(200, { 'Content-Type': 'text/plain' }) | ||
res.end('hello') | ||
} | ||
try { | ||
const res = await inject(dispatch).get('http://example.com:8080/hello') | ||
t.equal(res.payload, 'hello') | ||
} catch (err) { | ||
t.fail(err) | ||
} | ||
}) | ||
} | ||
module.exports = asyncAwaitTest |
@@ -61,8 +61,16 @@ import * as http from 'http' | ||
expectType<void>( | ||
inject(dispatch) | ||
.get('/') | ||
.end((err, res) => { | ||
expectType<Error>(err) | ||
expectType<Response>(res) | ||
console.log(res.payload) | ||
}) | ||
) | ||
inject(dispatch) | ||
.get('/') | ||
.end((err, res) => { | ||
expectType<Error>(err) | ||
expectType<Response>(res) | ||
console.log(res.payload) | ||
.then((value) => { | ||
expectType<Response>(value) | ||
}) | ||
@@ -69,0 +77,0 @@ |
@@ -12,2 +12,3 @@ 'use strict' | ||
const eos = require('end-of-stream') | ||
const semver = require('semver') | ||
@@ -849,3 +850,3 @@ const inject = require('../index') | ||
test('async wait support', t => { | ||
if (Number(process.versions.node[0]) >= 8) { | ||
if (semver.gt(process.versions.node, '8.0.0')) { | ||
require('./async-await')(t, inject) | ||
@@ -852,0 +853,0 @@ } else { |
78110
16
2153