Permalink
Browse files

Recovered the test cases

  • Loading branch information...
1 parent c7cb418 commit 5514692696fca835ee7d33a8f07db1e65af43d54 @iwillwen committed Mar 15, 2013
View
@@ -14,7 +14,7 @@ var middlewares = ['basicAuth', 'bodyParser', 'cookieParser', 'cookieSession', '
function method (web) {
//Method
- web.version = '0.6.0';
+ web.version = '0.6.1';
/**
* return a middlewaves collection iterator.
@@ -118,9 +118,10 @@ function method (web) {
*
*/
web.route = function (method, handler) {
+ var patch = web.patch();
web.use(function (req, res, next) {
if (req.method.toLowerCase() !== method.toLowerCase()) return next();
- web.patch(req, res, function () {
+ patch(req, res, function() {
handler(req, res, next);
});
});
@@ -277,7 +278,7 @@ function method (web) {
*/
web.run = function (port, host) {
port = port || 80;
- host = host || '127.0.0.1';
+ host = host || '0.0.0.0';
var server = connect.createServer();
server.setRouter = false;
server.self = server.listen(port, host);
@@ -295,7 +296,7 @@ function method (web) {
*/
web.runHttps = function (opt, port, host) {
port = port || 80;
- host = host || '127.0.0.1';
+ host = host || '0.0.0.0';
var server = connect.createServer();
var httpsServer = https.createServer(opt, server);
server.setRouter = false;
@@ -11,6 +11,7 @@ var utils = require('../utils');
var url = require('url');
module.exports = function (_req, _res, out) {
+
var server = global.web.server;
var handlers = server.handlers;
var rules = server.rules;
View
@@ -41,6 +41,7 @@ function Response(res, req) {
return req;
};
for (var key in res) if (navites.indexOf(key) === -1) this[key] = res[key];
+
}
util.inherits(Response, dataStream);
@@ -71,6 +72,7 @@ Response.prototype.send = function(data, _charset) {
// response object
var self = this;
+ var res = self.self;
// emit 'send' event
this.emit('send');
@@ -88,7 +90,7 @@ Response.prototype.send = function(data, _charset) {
this.header('X-Server', 'webjs');
// if the data param is not undefined, push it to the dataStream
- if (data) this.write(data);
+ if (data) self.write(data);
// fetch the response pipelining streams
var pipes = this.listeners('pipelining');
@@ -98,7 +100,7 @@ Response.prototype.send = function(data, _charset) {
// begin setting the stream pipelining
var last = this;
pipes.push(function() {
- return self.self;
+ return res;
});
for (var i = 0; i < pipes.length; i++) {
var newone = pipes[i]();
@@ -127,6 +129,7 @@ Response.prototype.long = function() {
// response object
var self = this;
+ var res = self.self;
// emit 'send' event
this.emit('long');
@@ -139,7 +142,7 @@ Response.prototype.long = function() {
// begin setting the stream pipelining
var last = this;
pipes.push(function() {
- return self.self;
+ return res;
});
for (var i = 0; i < pipes.length; i++) {
var newone = pipes[i]();
@@ -605,4 +608,4 @@ function sendfile (_fileName, res, found, _charset) {
});
}
-var navites = ["output","outputEncodings","writable","_last","chunkedEncoding","shouldKeepAlive","useChunkedEncodingByDefault","sendDate","_hasBody","_trailer","finished","socket","connection","_events","statusCode","assignSocket","detachSocket","writeContinue","_implicitHeader","writeHead","writeHeader","headerSent","setHeader","_renderHeaders","_hasConnectPatch","destroy","_send","_writeRaw","_buffer","_storeHeader","getHeader","removeHeader","write","addTrailers","end","_finish","_flush","pipe","setMaxListeners","emit","addListener","on","once","removeListener","removeAllListeners","listeners"];
+var navites = ["buffer", "output","outputEncodings","writable","_last","chunkedEncoding","shouldKeepAlive","useChunkedEncodingByDefault","sendDate","_hasBody","_trailer","finished","socket","connection","_events","statusCode","assignSocket","detachSocket","writeContinue","_implicitHeader","writeHead","writeHeader","headerSent","setHeader","_renderHeaders","_hasConnectPatch","destroy","_send","_writeRaw","_buffer","_storeHeader","getHeader","removeHeader","write","addTrailers","end","_finish","_flush","pipe","setMaxListeners","emit","addListener","on","once","removeListener","removeAllListeners","listeners"];
View
@@ -35,7 +35,7 @@
"crc": "latest"
},
"scripts": {
- "test": "mocha -R spec"
+ "test": "mocha -R spec --globals server,httpsServer"
},
"bin": {
"webjs": "./bin/webjs"
@@ -7,7 +7,6 @@ var host = '127.0.0.1';
web.run(port)
.get({
'/test': function (req, res) {
- console.log('a')
res.send('ok');
}
});
View
@@ -12,7 +12,7 @@ describe('req.body', function () {
});
var test = new Tester(app);
- test.post('http://127.0.0.1/', { foo: 'foobar' }, function (msg) {
+ test.post('/', { foo: 'foobar' }, function (msg) {
assert.equal('foobar', msg);
});
});
View
@@ -11,32 +11,35 @@ function test (app) {
test.prototype.get = function (url, callback) {
var res = new dataStream();
- res.on('complete', function () {
- callback(res.body().toString());
+ res.on('complete', function (body) {
+ callback(body);
});
res.headers = {};
res.setHeader = res.header = function (key, value) {
this.headers[key] = value;
};
+ res.sign = 'self';
var req = new dataStream();
req.method = 'GET';
req.url = url;
+ req.sign = 'self';
this.target.emit('request', req, res);
return this;
};
test.prototype.post = function (url, data, callback) {
var res = new dataStream();
- res.on('complete', function () {
- callback(res.body().toString());
+ res.on('complete', function (body) {
+ callback(body);
});
res.headers = {};
res.setHeader = function (key, value) {
this.headers[key] = value;
};
res.setEncoding = function () {};
+ res.sign = 'self';
var req = new dataStream();
req.setEncoding = function () {};
@@ -46,6 +49,7 @@ test.prototype.post = function (url, data, callback) {
}
req.method = 'POST';
req.url = url;
+ req.sign = 'self';
this.target.emit('request', req, res);
if (data) req.end();
@@ -62,6 +66,7 @@ test.prototype.request = function (method, url, data, callback) {
this.headers[key] = value;
};
res.setEncoding = function () {};
+ res.sign = 'self';
var req = new dataStream();
req.setEncoding = function () {};
@@ -71,6 +76,7 @@ test.prototype.request = function (method, url, data, callback) {
}
req.method = method.toUpperCase();
req.url = url;
+ req.sign = 'self';
this.target.emit('request', req, res);
if (data) req.ok().end();
View
@@ -17,8 +17,8 @@ describe('res.sendfile', function () {
});
var test = new Tester(app);
- test.get('http://127.0.0.1/', function (msg) {
- assert.equal('ffoooobbaarr', msg);
+ test.get('/', function (msg) {
+ assert.equal('foobar', msg);
});
});
});
@@ -10,7 +10,7 @@ describe('res.sendFile', function () {
});
var test = new Tester(app);
- test.get('http://127.0.0.1/', function (msg) {
+ test.get('/', function (msg) {
assert.equal('foobar', msg);
});
});
View
@@ -39,7 +39,7 @@ describe('web.create https', function () {
});
var test = new Tester(app);
- test.get('https://127.0.0.1/', function (msg) {
+ test.get('/', function (msg) {
assert.equal('foobar', msg);
});
});
View
@@ -10,7 +10,7 @@ describe('web.get', function () {
});
var test = new Tester(app);
- test.get('http://127.0.0.1/', function (msg) {
+ test.get('/', function (msg) {
assert.equal('foobar', msg);
});
});
View
@@ -29,12 +29,12 @@ describe('web.use route', function () {
res.data = 'foobar';
next();
})
- .route('get', function (req, res) {
+ .get('/foo', function (req, res) {
res.send(res.data);
});
var test = new Tester(app);
- test.get('http://127.0.0.1/foo', function (msg) {
+ test.get('/foo', function (msg) {
assert.equal('foobar', msg);
});
});

0 comments on commit 5514692

Please sign in to comment.