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.

Revisions

  1. eriktrom created this gist Feb 12, 2016.
    78 changes: 78 additions & 0 deletions port-finder-test.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,78 @@
    /*
    * 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);