Skip to content

Commit

Permalink
Merge pull request #87 from hapijs/async
Browse files Browse the repository at this point in the history
Migrate to async/await
  • Loading branch information
hueniverse authored Sep 23, 2017
2 parents c959bcc + a50e9bc commit 00a2a82
Show file tree
Hide file tree
Showing 5 changed files with 194 additions and 341 deletions.
2 changes: 0 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
language: node_js

node_js:
- "4"
- "6"
- "8"
- "node"

Expand Down
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright (c) 2012-2016, Project contributors
Copyright (c) 2012-2017, Project contributors
Copyright (c) 2012-2014, Walmart
All rights reserved.

Expand Down
20 changes: 14 additions & 6 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,19 +40,27 @@ internals.options = Joi.object().keys({
});


exports.inject = function (dispatchFunc, options, callback) {
exports.inject = function (dispatchFunc, options) {

options = (typeof options === 'string' ? { url: options } : options);

if (options.validate !== false) { // Defaults to true
Hoek.assert(typeof dispatchFunc === 'function', 'Invalid dispatch function');
Joi.assert(options, internals.options);
try {
Hoek.assert(typeof dispatchFunc === 'function', 'Invalid dispatch function');
Joi.assert(options, internals.options);
}
catch (err) {
return Promise.reject(err);
}
}

const req = new Request(options);
const res = new Response(req, callback);
return new Promise((resolve) => {

return req.prepare(() => dispatchFunc(req, res));
const req = new Request(options);
const res = new Response(req, resolve);

req.prepare(() => dispatchFunc(req, res));
});
};


Expand Down
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "shot",
"description": "Injects a fake HTTP request/response into a node HTTP server",
"version": "3.4.2",
"version": "4.0.0",
"repository": "git://github.com/hapijs/shot",
"main": "lib/index.js",
"keywords": [
Expand All @@ -11,15 +11,15 @@
"test"
],
"engines": {
"node": ">=4.5.0"
"node": ">=8.0.0"
},
"dependencies": {
"hoek": "4.x.x",
"joi": "10.x.x"
"joi": "11.x.x"
},
"devDependencies": {
"code": "4.x.x",
"lab": "13.x.x"
"code": "5.x.x",
"lab": "14.x.x"
},
"scripts": {
"test": "lab -a code -t 100 -L",
Expand Down
Loading

0 comments on commit 00a2a82

Please sign in to comment.