Skip to content

Commit c372948

Browse files
committed
tests: add large body tests
closes #20
1 parent d834956 commit c372948

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed

test/test.js

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
var bytes = require('bytes');
12
var crypto = require('crypto');
23
var http = require('http');
34
var request = require('supertest');
@@ -275,6 +276,52 @@ describe('compress()', function(){
275276
.end()
276277
})
277278

279+
it('should transfer large bodies', function (done) {
280+
var len = bytes('1mb')
281+
var buf = new Buffer(len)
282+
var server = createServer({ threshold: 0 }, function (req, res) {
283+
res.setHeader('Content-Type', 'text/plain')
284+
res.end(buf)
285+
})
286+
287+
buf.fill('.')
288+
289+
request(server)
290+
.get('/')
291+
.set('Accept-Encoding', 'gzip')
292+
.expect('Transfer-Encoding', 'chunked')
293+
.expect('Content-Encoding', 'gzip', function (err, res) {
294+
if (err) return done(err)
295+
should(res.text).equal(buf.toString())
296+
res.text.length.should.equal(len)
297+
done()
298+
})
299+
})
300+
301+
it('should transfer large bodies with multiple writes', function (done) {
302+
var len = bytes('40kb')
303+
var buf = new Buffer(len)
304+
var server = createServer({ threshold: 0 }, function (req, res) {
305+
res.setHeader('Content-Type', 'text/plain')
306+
res.write(buf)
307+
res.write(buf)
308+
res.write(buf)
309+
res.end(buf)
310+
})
311+
312+
buf.fill('.')
313+
314+
request(server)
315+
.get('/')
316+
.set('Accept-Encoding', 'gzip')
317+
.expect('Transfer-Encoding', 'chunked')
318+
.expect('Content-Encoding', 'gzip', function (err, res) {
319+
if (err) return done(err)
320+
res.text.length.should.equal(len * 4)
321+
done()
322+
})
323+
})
324+
278325
describe('threshold', function(){
279326
it('should not compress responses below the threshold size', function(done){
280327
var server = createServer({ threshold: '1kb' }, function (req, res) {

0 commit comments

Comments
 (0)