Skip to content
This repository has been archived by the owner on Nov 6, 2022. It is now read-only.

foxifyjs/inject

Repository files navigation

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