Skip to content

Commit 48f195c

Browse files
committed
test: add callback invocation check for flush in brotli compression
1 parent 3d64772 commit 48f195c

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

test/compression.js

+37
Original file line numberDiff line numberDiff line change
@@ -872,6 +872,43 @@ describe('compression()', function () {
872872
.end()
873873
})
874874

875+
it('should invoke flush callback when supplied for brotli', function (done) {
876+
var chunks = 0, callbackInvoked = false;
877+
var resp
878+
var server = createServer({ threshold: 0 }, function (req, res) {
879+
resp = res
880+
res.setHeader('Content-Type', 'text/plain')
881+
write()
882+
})
883+
884+
function flushCallback() {
885+
callbackInvoked = true;
886+
}
887+
888+
function write() {
889+
chunks++
890+
if (chunks === 20) return resp.end()
891+
if (chunks > 20) return chunks--
892+
resp.write('..')
893+
resp.flush(flushCallback)
894+
}
895+
896+
request(server)
897+
.get('/')
898+
.set('Accept-Encoding', 'br')
899+
.request()
900+
.on('response', function (res) {
901+
assert.equal(res.headers['content-encoding'], 'br')
902+
res.on('data', write)
903+
res.on('end', function(){
904+
assert.equal(chunks, 20)
905+
assert.equal(callbackInvoked, true)
906+
done()
907+
})
908+
})
909+
.end()
910+
})
911+
875912
it('should invoke flush callback when supplied for deflate', function (done) {
876913
var chunks = 0, callbackInvoked = false;
877914
var resp

0 commit comments

Comments
 (0)