Skip to content

Commit

Permalink
add test for default encoding
Browse files Browse the repository at this point in the history
  • Loading branch information
bjohansebas committed Sep 27, 2024
1 parent f3e6f38 commit 37d0789
Showing 1 changed file with 54 additions and 0 deletions.
54 changes: 54 additions & 0 deletions test/compression.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 37d0789

Please sign in to comment.