Socket
Socket
Sign inDemoInstall

test-listen

Package Overview
Dependencies
0
Maintainers
2
Versions
4
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    test-listen

Produce URLs to test HTTP servers with ephemeral ports


Version published
Weekly downloads
39K
decreased by-6.66%
Maintainers
2
Install size
136 kB
Created
Weekly downloads
 

Readme

Source

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

FAQs

Last updated on 01 Dec 2017

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc