Skip to content
Permalink
Browse files
Fixed failing tests
  • Loading branch information
Prithvirajbilla committed Aug 6, 2018
1 parent 90be7f1 commit 3ec21f07e902b3e767ca934e898eb0a928fe611e
Showing 3 changed files with 16 additions and 6 deletions.
@@ -12,7 +12,10 @@ interface PortFinderOptions{
*/
host?: string;
/**
* search start port (equals to basePort when not provided)
* search start port (equals to port when not provided)
* This exists because getPort and getPortPromise mutates port state in
* recursive calls and doesn't have a way to retrieve begininng port while
* searching.
*/
startPort?: number;
/**
@@ -97,10 +97,17 @@ exports.getPort = function (options, callback) {

options.port = Number(options.port) || Number(exports.basePort);
options.host = options.host || null;
options.stopPort = Number(options.stopPort) || Number(exports.highestPort)
options.stopPort = Number(options.stopPort) || Number(exports.highestPort);

if(!options.startPort) {
options.startPort = options.port
options.startPort = Number(options.port);
if(options.startPort < 1024) {
// ports < 1024 are system/well-known ports - need super user privilege to bind to them.
throw Error(`Provided options.startPort(${options.startPort}) is less than 1024, which are cannot be bound.`)
}
if(options.stopPort < options.startPort) {
throw Error(`Provided options.stopPort(${options.stopPort}) is less than options.startPort (${options.startPort})`)
}
}

if (options.host) {
@@ -174,7 +181,7 @@ exports.getPort = function (options, callback) {
return callback(null, openPorts[0]);
}
else {
var msg = 'No open ports found in between '+ options.startPort + ' and ' + options.stopPort;
var msg = `No open ports found in between ${options.startPort} and ${options.stopPort}`;
return callback(Error(msg));
}
} else {
@@ -52,7 +52,7 @@ vows.describe('portfinder').addBatch({
// stopPort: 32722 is smaller than available port 32773 (32768 + 5)
setTimeout(function() {
portfinder.getPort({ stopPort: 32772 }, this.callback);
}.bind(this), 3000); //wait for cleanup of bound hosts.
}.bind(this), 6000); //wait for cleanup of bound hosts.
},
"should return error": function(err, port) {
assert.isTrue(!!err);
@@ -68,7 +68,7 @@ vows.describe('portfinder').addBatch({
// stopPort: 32774 is greater than available port 32773 (32768 + 5)
setTimeout(function() {
portfinder.getPort({ stopPort: 32774 }, this.callback);
}.bind(this), 3000); //wait for cleanup of bound hosts.
}.bind(this), 9000); //wait for cleanup of bound hosts.
},
"should respond with the first free port (32773) less than provided stopPort": function(err, port) {
if (err) { debugVows(err); }

0 comments on commit 3ec21f0

Please sign in to comment.