JSPM

test-listen

1.1.0
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 163396
  • Score
    100M100P100Q160514F
  • License MIT

Produce URLs to test HTTP servers with ephemeral ports

Package Exports

  • test-listen

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (test-listen) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

test-listen

Build Status XO code style

URLs with ephemeral ports. async/await ready.

Usage

Install it:

npm install --save-dev test-listen

Pass a http.Server to test-listen and it will return an URL in the format http://localhost:{port}.

The second parameter can optionally be a hostname to return in the URL instead of localhost.

Useful for running HTTP server testsuites:

const http = require('http');
const listen = require('test-listen');

const srv = http.createServer((req, res) => res.end('1'))
const srv2 = http.createServer((req, res) => res.end('2'))

test('urls', async t => {
  let url = await listen(srv)
  t.ok(url == 'http://localhost:11401')
  let url = await listen(srv2)
  t.ok(url == 'http://localhost:42333')
})

Authors