Skip to content

Commit

Permalink
Update docs, deps, cleanup. Closes #97. Closes #100
Browse files Browse the repository at this point in the history
  • Loading branch information
hueniverse committed Nov 1, 2018
1 parent 17da8f2 commit 949e40b
Show file tree
Hide file tree
Showing 9 changed files with 36 additions and 77 deletions.
23 changes: 7 additions & 16 deletions .gitignore
@@ -1,18 +1,9 @@
.idea
*.iml
npm-debug.log
dump.rdb
node_modules
results.tap
results.xml
config.json
.DS_Store
*/.DS_Store
*/*/.DS_Store
._*
*/._*
*/*/._*
**/node_modules
**/package-lock.json

coverage.*
.settings
package-lock.json

**/.DS_Store
**/._*

**/*.pem
3 changes: 2 additions & 1 deletion .travis.yml
Expand Up @@ -2,7 +2,8 @@ language: node_js

node_js:
- "8"
- "9"
- "10"
- "11"
- "node"

sudo: false
26 changes: 14 additions & 12 deletions API.md
@@ -1,6 +1,7 @@
# API Reference

### `Shot.inject(dispatchFunc, options, callback)`

### `await Shot.inject(dispatchFunc, options)`

Injects a fake request into an HTTP server.

Expand All @@ -21,17 +22,18 @@ Injects a fake request into an HTTP server.
- `error` - whether the request will emit an `error` event. Defaults to `undefined`, meaning no `error` event will be emitted. If set to `true`, the emitted error will have a message of `'Simulated'`.
- `close` - whether the request will emit a `close` event. Defaults to `undefined`, meaning no `close` event will be emitted.
- `validate` - Optional flag to validate this options object. Defaults to `true`.
- `callback` - the callback function using the signature `function (res)` where:
- `res` - a response object where:
- `raw` - an object containing the raw request and response objects where:
- `req` - the simulated request object.
- `res` - the simulated response object.
- `headers` - an object containing the response headers.
- `statusCode` - the HTTP status code.
- `statusMessage` - the HTTP status message.
- `payload` - the payload as a UTF-8 encoded string.
- `rawPayload` - the raw payload as a Buffer.
- `trailers` - an object containing the response trailers.

Returns a response object where:
- `raw` - an object containing the raw request and response objects where:
- `req` - the simulated request object.
- `res` - the simulated response object.
- `headers` - an object containing the response headers.
- `statusCode` - the HTTP status code.
- `statusMessage` - the HTTP status message.
- `payload` - the payload as a UTF-8 encoded string.
- `rawPayload` - the raw payload as a Buffer.
- `trailers` - an object containing the response trailers.


### `Shot.isInjection(obj)`

Expand Down
6 changes: 1 addition & 5 deletions LICENSE
@@ -1,4 +1,4 @@
Copyright (c) 2012-2017, Project contributors
Copyright (c) 2012-2018, Project contributors
Copyright (c) 2012-2014, Walmart
All rights reserved.

Expand All @@ -23,7 +23,3 @@ LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

* * *

The complete list of contributors can be found at: https://github.com/hapijs/shot/graphs/contributors
8 changes: 3 additions & 5 deletions README.md
Expand Up @@ -21,7 +21,7 @@ const Shot = require('shot');
const internals = {};


internals.main = function () {
internals.main = async function () {

const dispatch = function (req, res) {

Expand All @@ -32,10 +32,8 @@ internals.main = function () {

const server = Http.createServer(dispatch);

Shot.inject(dispatch, { method: 'get', url: '/' }, (res) => {

console.log(res.payload);
});
const res = await Shot.inject(dispatch, { method: 'get', url: '/' });
console.log(res.payload);
};


Expand Down
29 changes: 0 additions & 29 deletions examples/http.js

This file was deleted.

6 changes: 3 additions & 3 deletions lib/response.js
Expand Up @@ -30,9 +30,9 @@ exports = module.exports = internals.Response = class extends Http.ServerRespons
});
}

writeHead() {
writeHead(...args) {

const result = super.writeHead.apply(this, arguments);
const result = super.writeHead(...args);

this._shot.headers = Object.assign({}, this._headers); // Should be .getHeaders() since node v7.7

Expand All @@ -53,7 +53,7 @@ exports = module.exports = internals.Response = class extends Http.ServerRespons
write(data, encoding, callback) {

super.write(data, encoding, callback);
this._shot.payloadChunks.push(new Buffer(data, encoding));
this._shot.payloadChunks.push(Buffer.from(data, encoding));
return true; // Write always returns false when disconnected
}

Expand Down
8 changes: 4 additions & 4 deletions package.json
Expand Up @@ -11,15 +11,15 @@
"test"
],
"engines": {
"node": ">=8.9.0"
"node": ">=8.12.0"
},
"dependencies": {
"hoek": "5.x.x",
"joi": "13.x.x"
"hoek": "6.x.x",
"joi": "14.x.x"
},
"devDependencies": {
"code": "5.x.x",
"lab": "15.x.x"
"lab": "17.x.x"
},
"scripts": {
"test": "lab -a code -t 100 -L",
Expand Down
4 changes: 2 additions & 2 deletions test/index.js
Expand Up @@ -267,7 +267,7 @@ describe('inject()', () => {

res.writeHead(200);
res.write('a');
res.write(new Buffer('b'));
res.write(Buffer.from('b'));
res.end();
};

Expand Down Expand Up @@ -380,7 +380,7 @@ describe('inject()', () => {
req.pipe(res);
};

const res = await Shot.inject(dispatch, { method: 'post', url: '/test', payload: new Buffer('test!') });
const res = await Shot.inject(dispatch, { method: 'post', url: '/test', payload: Buffer.from('test!') });
expect(res.payload).to.equal('test!');
});

Expand Down

0 comments on commit 949e40b

Please sign in to comment.