1.1.0 • Published 3 years ago

@foxify/inject v1.1.0

Weekly downloads
47
License
MIT
Repository
github
Last release
3 years ago

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).

NPM Version Node Version TypeScript Version Tested With Jest Pull Requests License Build Status Coverage Status Package Quality Dependencies Status NPM Total Downloads NPM Monthly Downloads Open Issues Closed Issues known vulnerabilities Github Stars Github Forks

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)
})