Skip to content

Commit 8880f40

Browse files
committed
add test for default encoding
1 parent f3e6f38 commit 8880f40

File tree

1 file changed

+54
-0
lines changed

1 file changed

+54
-0
lines changed

test/compression.js

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -657,6 +657,60 @@ describe('compression()', function () {
657657
.end()
658658
})
659659
})
660+
661+
describe('defaultEncoding', function () {
662+
it('should compress the provided encoding and not the default encoding', function (done) {
663+
var server = createServer({ threshold: 0, defaultEncoding: 'deflate' }, function (req, res) {
664+
res.setHeader('Content-Type', 'text/plain')
665+
res.end('hello, world')
666+
})
667+
668+
request(server)
669+
.get('/')
670+
.set('Accept-Encoding', 'gzip')
671+
.expect('Content-Encoding', 'gzip')
672+
.expect(200, 'hello, world', done)
673+
})
674+
675+
it('should not compress when defaultEncoding is identity', function (done) {
676+
var server = createServer({ threshold: 0, defaultEncoding: 'identity' }, function (req, res) {
677+
res.setHeader('Content-Type', 'text/plain')
678+
res.end('hello, world')
679+
})
680+
681+
request(server)
682+
.get('/')
683+
.set('Accept-Encoding', '')
684+
.expect('Content-Encoding', 'identity')
685+
.expect(200, 'hello, world', done)
686+
})
687+
688+
it('should compress when defaultEncoding is gzip', function (done) {
689+
var server = createServer({ threshold: 0, defaultEncoding: 'gzip' }, function (req, res) {
690+
res.setHeader('Content-Type', 'text/plain')
691+
res.end('hello, world')
692+
})
693+
694+
request(server)
695+
.get('/')
696+
.set('Accept-Encoding', '')
697+
.expect('Content-Encoding', 'gzip')
698+
.expect(200, 'hello, world', done)
699+
})
700+
701+
it('should compress when defaultEncoding is deflate', function (done) {
702+
var server = createServer({ threshold: 0, defaultEncoding: 'deflate' }, function (req, res) {
703+
res.setHeader('Content-Type', 'text/plain')
704+
res.end('hello, world')
705+
})
706+
707+
request(server)
708+
.get('/')
709+
.set('Accept-Encoding', '')
710+
.expect('Content-Encoding', 'deflate')
711+
.expect(200, 'hello, world', done)
712+
})
713+
})
660714
})
661715

662716
function createServer (opts, fn) {

0 commit comments

Comments
 (0)