zeit/test-listen

Name: test-listen

Owner: ZEIT

Description: Quick ephemeral URLs for your tests

Created: 2016-02-05 01:26:02.0

Updated: 2018-05-18 07:13:38.0

Pushed: 2018-05-23 22:34:26.0

Homepage: https://npmjs.com/test-listen

Size: 25

Language: JavaScript

GitHub Committers

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

test-listen

Build Status XO code style

URLs with ephemeral ports. async/await ready.

Usage

Install it:

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:

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

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

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

Authors

This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.