Create a one-off server from http request handler for testing.
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')
}
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 (https://localhost:<PORT>
).