diff --git a/test/compression.js b/test/compression.js index 6975ea0b..eb5a5b6d 100644 --- a/test/compression.js +++ b/test/compression.js @@ -657,6 +657,60 @@ describe('compression()', function () { .end() }) }) + + describe('defaultEncoding', function () { + it('should compress the provided encoding and not the default encoding', function (done) { + var server = createServer({ threshold: 0, defaultEncoding: 'deflate' }, function (req, res) { + res.setHeader('Content-Type', 'text/plain') + res.end('hello, world') + }) + + request(server) + .get('/') + .set('Accept-Encoding', 'gzip') + .expect('Content-Encoding', 'gzip') + .expect(200, 'hello, world', done) + }) + + it('should not compress when defaultEncoding is identity', function (done) { + var server = createServer({ threshold: 0, defaultEncoding: 'identity' }, function (req, res) { + res.setHeader('Content-Type', 'text/plain') + res.end('hello, world') + }) + + request(server) + .get('/') + .unset('Accept-Encoding') + .expect('Content-Encoding', 'identity') + .expect(200, 'hello, world', done) + }) + + it('should compress when defaultEncoding is gzip', function (done) { + var server = createServer({ threshold: 0, defaultEncoding: 'gzip' }, function (req, res) { + res.setHeader('Content-Type', 'text/plain') + res.end('hello, world') + }) + + request(server) + .get('/') + .unset('Accept-Encoding') + .expect('Content-Encoding', 'gzip') + .expect(200, 'hello, world', done) + }) + + it('should compress when defaultEncoding is deflate', function (done) { + var server = createServer({ threshold: 0, defaultEncoding: 'deflate' }, function (req, res) { + res.setHeader('Content-Type', 'text/plain') + res.end('hello, world') + }) + + request(server) + .get('/') + .unset('Accept-Encoding') + .expect('Content-Encoding', 'deflate') + .expect(200, 'hello, world', done) + }) + }) }) function createServer (opts, fn) {