Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

refactor test

  • Loading branch information...
commit 88944d1568ea9d53dde6bbc7bf1052b1856c00c4 1 parent 6ed44ac
@tj tj authored
Showing with 11 additions and 13 deletions.
  1. +11 −13 test/server.js
View
24 test/server.js
@@ -54,30 +54,28 @@ describe('app', function(){
res.end('Ok');
}];
- // execute handlers one after another
- var curHandler = 0;
- var execHandler = function(req, res){
- if (handlers[curHandler])
- handlers[curHandler++](req, res, function(){
- execHandler(req, res);
+ // execute callbacks in sequence
+ var n = 0;
+ function run(req, res){
+ if (handlers[n]) {
+ handlers[n++](req, res, function(){
+ run(req, res);
});
+ }
}
// create a non-connect server
- var server = http.createServer(execHandler).listen(5556, function(){
- // test it out
+ var server = http.createServer(run).listen(5556, function(){
http.get({
host: 'localhost',
port: 5556,
path: '/'
}, function(res){
+ var buf = '';
res.setEncoding('utf8');
- var data = '';
- res.on('data', function(chunk){
- data += chunk;
- });
+ res.on('data', function(s){ buf += s });
res.on('end', function(){
- data.should.eql('Ok');
+ buf.should.eql('Ok');
server.close();
done();
});
Please sign in to comment.
Something went wrong with that request. Please try again.