Permalink
Browse files

add test to check if response acts as a readable stream

  • Loading branch information...
1 parent c307360 commit cc7cf3b9a3523d43168b36197064cfde73c8e974 @lbdremy lbdremy committed Feb 3, 2013
Showing with 37 additions and 0 deletions.
  1. +37 −0 test/node/response-readable-stream.js
@@ -0,0 +1,37 @@
+
+var request = require('../../')
+ , express = require('express')
+ , app = express()
+ , fs = require('fs');
+
+app.get('/', function(req, res){
+ fs.createReadStream('test/node/fixtures/user.json').pipe(res);
+});
+
+app.listen(3025);
+
+describe('response', function(){
+ it('should act as a readable stream', function(done){
+ var req = request
+ .get('http://localhost:3025')
+ .buffer(false);
+
+ req.end(function(err,res){
+ if(err) return done(err);
+ var trackEndEvent = 0;
+ var trackCloseEvent = 0;
+ res.on('end',function(){
+ trackEndEvent++;
+ });
+ res.on('close',function(){
+ trackCloseEvent++;
+ trackEndEvent.should.equal(1);
+ trackCloseEvent.should.equal(1);
+ done();
+ });
+ (function(){res.pause();}).should.not.throw();
+ (function(){res.resume();}).should.not.throw();
+ (function(){res.destroy();}).should.not.throw();
+ });
+ });
+});

0 comments on commit cc7cf3b

Please sign in to comment.