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
User | Most Recent Commit | # Commits |
---|
Other Committers
User | Most Recent Commit | # Commits |
---|
URLs with ephemeral ports. async
/await
ready.
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')