@foxify/inject
v1.1.0
Published
Fake HTTP injection library
Downloads
4,731
Maintainers
Readme
inject
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).
Example
const http = require('http')
const inject = require('@foxify/inject').default
const dispatch = function (req, res) {
const reply = 'Hello World'
res.writeHead(200, { 'Content-Type': 'text/plain', 'Content-Length': reply.length })
res.end(reply)
}
// Nah, you don't need this anymore :)
// const server = http.createServer(dispatch)
inject(dispatch, { method: 'get', url: '/' }, (err, res) => {
console.log(res.body)
})