Injects a fake HTTP request/response into your node server logic
Latest commit 435e8e0 Jun 12, 2018
Permalink
Failed to load latest commit information.
examples es6. Closes #52 Nov 2, 2015
images image Mar 6, 2013
lib Use ES6 classes Jun 8, 2018
test Use ES6 classes Jun 8, 2018
.gitignore Update lab Nov 3, 2017
.npmignore npmignore. Closes #72 Jul 28, 2016
.travis.yml Update lab Nov 3, 2017
API.md Updated API docs to reflect new validate flag Aug 29, 2016
CONTRIBUTING.md Create CONTRIBUTING.md Aug 11, 2014
LICENSE Migrate to async/await Sep 23, 2017
README.md Updated README for ES6 styles Dec 30, 2015
package.json 4.0.5 Feb 15, 2018

README.md

shot Logo

Injects a fake HTTP request/response into a node HTTP server for simulating server logic, writing tests, or debugging. Does not use a socket connection so can be run against an inactive server (server not in listen mode).

Build Status

Lead Maintainer: Matt Harrison

Example

// Load modules

const Http = require('http');
const Shot = require('shot');


// Declare internals

const internals = {};


internals.main = function () {

    const dispatch = function (req, res) {

        const reply = 'Hello World';
        res.writeHead(200, { 'Content-Type': 'text/plain', 'Content-Length': reply.length });
        res.end(reply);
    };

    const server = Http.createServer(dispatch);

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

        console.log(res.payload);
    });
};


internals.main();

Note how server.listen is never called.

API

See the API Reference