Skip to content

Commit 00a2a82

Browse files
authored
Merge pull request #87 from hapijs/async
Migrate to async/await
2 parents c959bcc + a50e9bc commit 00a2a82

File tree

5 files changed

+194
-341
lines changed

5 files changed

+194
-341
lines changed

.travis.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
language: node_js
22

33
node_js:
4-
- "4"
5-
- "6"
64
- "8"
75
- "node"
86

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Copyright (c) 2012-2016, Project contributors
1+
Copyright (c) 2012-2017, Project contributors
22
Copyright (c) 2012-2014, Walmart
33
All rights reserved.
44

lib/index.js

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,19 +40,27 @@ internals.options = Joi.object().keys({
4040
});
4141

4242

43-
exports.inject = function (dispatchFunc, options, callback) {
43+
exports.inject = function (dispatchFunc, options) {
4444

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

4747
if (options.validate !== false) { // Defaults to true
48-
Hoek.assert(typeof dispatchFunc === 'function', 'Invalid dispatch function');
49-
Joi.assert(options, internals.options);
48+
try {
49+
Hoek.assert(typeof dispatchFunc === 'function', 'Invalid dispatch function');
50+
Joi.assert(options, internals.options);
51+
}
52+
catch (err) {
53+
return Promise.reject(err);
54+
}
5055
}
5156

52-
const req = new Request(options);
53-
const res = new Response(req, callback);
57+
return new Promise((resolve) => {
5458

55-
return req.prepare(() => dispatchFunc(req, res));
59+
const req = new Request(options);
60+
const res = new Response(req, resolve);
61+
62+
req.prepare(() => dispatchFunc(req, res));
63+
});
5664
};
5765

5866

package.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "shot",
33
"description": "Injects a fake HTTP request/response into a node HTTP server",
4-
"version": "3.4.2",
4+
"version": "4.0.0",
55
"repository": "git://github.com/hapijs/shot",
66
"main": "lib/index.js",
77
"keywords": [
@@ -11,15 +11,15 @@
1111
"test"
1212
],
1313
"engines": {
14-
"node": ">=4.5.0"
14+
"node": ">=8.0.0"
1515
},
1616
"dependencies": {
1717
"hoek": "4.x.x",
18-
"joi": "10.x.x"
18+
"joi": "11.x.x"
1919
},
2020
"devDependencies": {
21-
"code": "4.x.x",
22-
"lab": "13.x.x"
21+
"code": "5.x.x",
22+
"lab": "14.x.x"
2323
},
2424
"scripts": {
2525
"test": "lab -a code -t 100 -L",

0 commit comments

Comments
 (0)