Revisions
-
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -5,10 +5,6 @@ * Module dependencies. */ var EventEmitter = require('events').EventEmitter , should = require('should') , methods = ['get','post','put','delete','head'] -
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -5,22 +5,26 @@ * Module dependencies. */ /** * Module dependencies. */ var EventEmitter = require('events').EventEmitter , should = require('should') , methods = ['get','post','put','delete','head'] , http = require('http') , server , addr; exports.createServer = function(app,fn){ if(server){ return fn(); } server = app; server.listen(0, function(){ addr = server.address(); fn(); }); } -
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,105 @@ /** * Modified version of TJ's http support file from the Express repo: * https://github.com/visionmedia/express/blob/master/test/support/http.js * * Module dependencies. */ var EventEmitter = require('events').EventEmitter , should = require('should') , methods = ['get','post','put','delete','head'] , http = require('http') , server , addr; exports.createServer = function(app,fn){ if(server){ return fn(); } server = app; server.listen(0, function(){ addr = server.address(); fn(); }); } exports.request = function() { return new Request(); } function Request() { var self = this; this.data = []; this.header = {}; } /** * Inherit from `EventEmitter.prototype`. */ Request.prototype.__proto__ = EventEmitter.prototype; methods.forEach(function(method){ Request.prototype[method] = function(path){ return this.request(method, path); }; }); Request.prototype.set = function(field, val){ this.header[field] = val; return this; }; Request.prototype.write = function(data){ this.data.push(data); return this; }; Request.prototype.request = function(method, path){ this.method = method; this.path = path; return this; }; Request.prototype.expect = function(body, fn){ this.end(function(res){ if ('number' == typeof body) { res.statusCode.should.equal(body); } else if (body instanceof RegExp) { res.body.should.match(body); } else { res.body.should.equal(body); } fn(); }); }; Request.prototype.end = function(fn){ var req = http.request({ method: this.method , port: addr.port , host: addr.address , path: this.path , headers: this.header }); this.data.forEach(function(chunk){ req.write(chunk); }); req.on('response', function(res){ var buf = ''; res.setEncoding('utf8'); res.on('data', function(chunk){ buf += chunk }); res.on('end', function(){ res.body = buf; fn(res); }); }); req.end(); return this; };