diff --git a/index.js b/index.js index 0e8b829..da4a967 100644 --- a/index.js +++ b/index.js @@ -70,7 +70,7 @@ module.exports = async options => { lockedPorts.young.add(availablePort); return availablePort; } catch (error) { - if (error.code !== 'EADDRINUSE' && !(error instanceof Locked)) { + if (!['EADDRINUSE', 'EACCES'].includes(error.code) && !(error instanceof Locked)) { throw error; } } diff --git a/test.js b/test.js index 8981ae1..ba4c794 100644 --- a/test.js +++ b/test.js @@ -32,6 +32,15 @@ test('preferred port unavailable', async t => { t.not(port, desiredPort); }); +test('preferred port privileged', async t => { + const desiredPort = 80; + const port = await getPort({host: '127.0.0.1', port: desiredPort}); + + t.is(typeof port, 'number'); + t.true(port > 0); + t.not(port, desiredPort); +}); + test('port can be bound to IPv4 host when promise resolves', async t => { const port = await getPort({host: '0.0.0.0'}); t.is(typeof port, 'number');