test-listen
Advanced tools
Comparing version 1.0.2 to 1.1.0
@@ -1,2 +0,2 @@ | ||
module.exports = srv => new Promise((resolve, reject) => { | ||
module.exports = (srv, hostname = 'localhost') => new Promise((resolve, reject) => { | ||
srv.on('error', reject) | ||
@@ -6,4 +6,4 @@ | ||
const {port} = srv.address() | ||
resolve(`http://localhost:${port}`) | ||
resolve(`http://${hostname}:${port}`) | ||
}) | ||
}) |
{ | ||
"name": "test-listen", | ||
"version": "1.0.2", | ||
"version": "1.1.0", | ||
"description": "Produce URLs to test HTTP servers with ephemeral ports", | ||
@@ -5,0 +5,0 @@ "main": "./index", |
@@ -18,2 +18,5 @@ # test-listen | ||
The second parameter can optionally be a hostname to return in the URL | ||
instead of `localhost`. | ||
Useful for running HTTP server testsuites: | ||
@@ -20,0 +23,0 @@ |
@@ -9,2 +9,3 @@ // eslint-disable-next-line ava/no-ignored-test-files | ||
const srv2 = http.createServer((req, res) => res.end('2')) | ||
const srv3 = http.createServer((req, res) => res.end('3')) | ||
@@ -22,2 +23,8 @@ test('it works', async t => { | ||
t.deepEqual('2', data2) | ||
const url3 = await listen(srv3, '127.0.0.1') | ||
t.true(url3 !== url) | ||
t.true(/http:\/\/127.0.0.1:\d+/.test(url3)) | ||
const data3 = await request(url3) | ||
t.deepEqual('3', data3) | ||
}) |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
138336
31
42