test-listen
DefinitelyTyped icon, indicating that this package has TypeScript declarations provided by the separate @types/test-listen package

1.1.0 • Public • Published

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

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 1.1.0
    88,175
    • latest

Version History

  • Version
    Downloads (Last 7 Days)
    • Published
  • 1.1.0
    88,175
  • 1.0.2
    589
  • 1.0.1
    5
  • 1.0.0
    8

Package Sidebar

Install

npm i test-listen

Weekly Downloads

54,584

Version

1.1.0

License

MIT

Last publish

Collaborators

  • leo
  • rauchg