Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Small change to way ports managed.

  • Loading branch information...
commit e3845d1633812b290af0bd97d01318a7a5fa3240 1 parent faa3774
@colin-jack authored
View
1  README.md
@@ -1,5 +1,6 @@
# test resources
[![Build Status](https://travis-ci.org/colin-jack/testresources.png)](https://travis-ci.org/#!/colin-jack/testresources)
+
This project is an early alpha, not yet fully functional.
Similiar to super test, in other words wrapping superagent to make it easy to test an HTTP API matches conventions.
View
5 lib/closeExpress.js
@@ -1,6 +1,9 @@
-var winston = require('winston')
+var winston = require('winston'),
+ portManager = require('./portManager');
var closeExpress = function(expressApp) {
+ portManager.releasePort();
+
try {
// TODO: Likely to be because another request in the chain has already closed it.
if (expressApp === undefined) {
View
2  lib/ensureExpressListening.js
@@ -3,7 +3,7 @@ var winston = require('winston'),
var ensureExpressListening = function ensureExpressListening(expressApp) {
var addr = expressApp.address();
- var currentPort = portManager.getPortForToListenOn(addr);
+ var currentPort = portManager.getPortToListenOn(addr);
if (!addr) {
winston.info("Port '" + currentPort + "' listening.")
View
35 lib/portManager.js
@@ -1,22 +1,23 @@
var port = 3550;
-var getPortForToListenOn = function getPortForToListenOn(addr) {
- var currentPort;
-
- if (addr)
- {
- currentPort = addr.port;
- }
- else
- {
- port = port + 1;
- currentPort = port;
- }
+var getPortToListenOn = function getPortToListenOn(addr) {
+ return addr ? arr.port : port;
+}
+
+// When we are done with an instance of express we increment the port counter,
+// ensuring that even if we don't close the express instance we don't end up
+// trying to open another instance listening on the same port
+var releasePort = function releasePort() {
+ port = port + 1;
+}
- return currentPort;
+var portManager = {
+ getPortToListenOn: getPortToListenOn,
+ releasePort: releasePort
}
-module.exports = {
- port: port,
- getPortForToListenOn: getPortForToListenOn
-}
+portManager.__defineGetter__("port", function() {
+ return port;
+});
+
+module.exports = portManager;
View
2  package.json
@@ -1,5 +1,5 @@
{
- "version": "0.0.90",
+ "version": "0.0.91",
"name": "testresources",
"description": "Adds some conventions to superagent to make testing HTTP APIs quicker.",
Please sign in to comment.
Something went wrong with that request. Please try again.