Skip to content

Commit

Permalink
move Test to lib/test.js
Browse files Browse the repository at this point in the history
  • Loading branch information
tj committed Jun 26, 2012
1 parent b1abb67 commit fbf3b1d
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 44 deletions.
46 changes: 2 additions & 44 deletions index.js
Expand Up @@ -3,9 +3,8 @@
* Module dependencies.
*/

var request = require('superagent')
, methods = require('./lib/methods')
, Request = request.Request
var methods = require('./lib/methods')
, Test = require('./lib/test')
, http = require('http');

module.exports = function(app){
Expand All @@ -25,44 +24,3 @@ module.exports = function(app){

return obj;
};

/**
* Initialize a new `Test` with the given `app`,
* request `method` and `path`.
*
* @param {Server} app
* @param {String} method
* @param {String} path
* @api public
*/

function Test(app, method, path) {
Request.call(this, method, path);
this.app = app;
}

/**
* Inherits from `Request.prototype`.
*/

Test.prototype.__proto__ = Request.prototype;

/**
* Defer invoking superagent's `.end()` until
* the server is listening.
*
* @param {Function} fn
* @api public
*/

Test.prototype.end = function(fn){
var self = this;
var end = Request.prototype.end;
var app = this.app;
var addr = app.address();
if (!addr) return app.listen(0, function(){ self.end(fn); });
this.url = 'http://' + addr.address + ':' + addr.port + this.url;
end.call(this, fn);
};


53 changes: 53 additions & 0 deletions lib/test.js
@@ -0,0 +1,53 @@


/**
* Module dependencies.
*/

var request = require('superagent')
, Request = request.Request;

/**
* Expose `Test`.
*/

module.exports = Test;

/**
* Initialize a new `Test` with the given `app`,
* request `method` and `path`.
*
* @param {Server} app
* @param {String} method
* @param {String} path
* @api public
*/

function Test(app, method, path) {
Request.call(this, method, path);
this.app = app;
}

/**
* Inherits from `Request.prototype`.
*/

Test.prototype.__proto__ = Request.prototype;

/**
* Defer invoking superagent's `.end()` until
* the server is listening.
*
* @param {Function} fn
* @api public
*/

Test.prototype.end = function(fn){
var self = this;
var end = Request.prototype.end;
var app = this.app;
var addr = app.address();
if (!addr) return app.listen(0, function(){ self.end(fn); });
this.url = 'http://' + addr.address + ':' + addr.port + this.url;
end.call(this, fn);
};

0 comments on commit fbf3b1d

Please sign in to comment.