comets
v1.0.0
Published
Create a one-off server for testing
Downloads
18
Readme
comets
Create a one-off server for testing http request listener.
Usage
npm install comets
import assert from 'assert'
import fetch from 'node-fetch'
import { createServer } from 'comets'
async function test () {
// The handler to test
const requestHandler = (req, res) => res.end('yo')
// Create a one-off server for testing
const address = await createServer(requestHandler)
// Send test request, the server will close after this request
const result = await fetch(address).then(res => res.text())
assert.equal(result, 'yo')
}
API
createServer()
async createServer(handler: http.RequestListener, count: number = 1) => Promise<string>
handler
: the request listener for creating http servercount
: the number of requests allowed before server closed (default: 1)
returns Promise<string>
: the server address (http://localhost:<PORT>
).