Skip to content
/ comets Public

Create a one-off server for testing http request listener

License

Notifications You must be signed in to change notification settings

amio/comets

Repository files navigation

comets

npm version package size

Create a one-off server from http request handler for testing.

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 server
  • count: the number of requests allowed before server closed (default: 1)

returns Promise<string>: the server address (https://localhost:<PORT>).

License

License

About

Create a one-off server for testing http request listener

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published