Skip to content

Instantly share code, notes, and snippets.

@eriktrom
Created February 12, 2016 14:45
Show Gist options
  • Save eriktrom/62577d6b13f3fc857b01 to your computer and use it in GitHub Desktop.
Save eriktrom/62577d6b13f3fc857b01 to your computer and use it in GitHub Desktop.
portfinder test for localhost
/*
* portfinder-test.js: Tests for the `portfinder` module.
*
* (C) 2011, Charlie Robbins
*
*/
var vows = require('vows'),
assert = require('assert'),
portfinder = require('../lib/portfinder'),
testHelper = require('./helper');
portfinder.basePort = 32768;
var servers = [];
vows.describe('portfinder').addBatch({
"When using portfinder module": {
"with 5 existing servers": {
topic: function () {
testHelper(servers, this.callback);
},
"the getPort() method": {
topic: function () {
portfinder.getPort(this.callback);
},
"should respond with the first free port (32773)": function (err, port) {
assert.isTrue(!err);
assert.equal(port, 32773);
}
}
}
}
}).addBatch({
"When using portfinder module": {
"with 5 existing servers": {
topic: function () {
servers.forEach(function (server) {
server.close();
});
servers = [];
testHelper(servers, this.callback);
},
"the getPort() method with host option set to localhost": {
topic: function () {
portfinder.getPort({ host: 'localhost' }, this.callback);
},
"should respond with the first free port (32773)": function (err, port) {
assert.isTrue(!err);
assert.equal(port, 32773);
}
}
}
}
}).addBatch({
"When using portfinder module": {
"with no existing servers": {
topic: function () {
servers.forEach(function (server) {
server.close();
});
return null;
},
"the getPort() method": {
topic: function () {
portfinder.getPort(this.callback);
},
"should respond with the first free port (32768)": function (err, port) {
assert.isTrue(!err);
assert.equal(port, 32768);
}
}
}
}
}).export(module);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment