Skip to content

Commit 17e6933

Browse files
fix(test): add code coverage
1 parent 8d9fb6c commit 17e6933

File tree

2 files changed

+42
-1
lines changed

2 files changed

+42
-1
lines changed

index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ function compression (options) {
171171

172172
if (chunk) {
173173
chunk = toBuffer(chunk, encoding)
174-
if (/^v0\.8\./.test(process.version) && stream && chunk) {
174+
if (/^v0\.8\./.test(process.version) && stream) {
175175
encoding = callback
176176
}
177177
}

test/compression.js

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,47 @@ describe('compression()', function () {
3737
.expect(200, done)
3838
})
3939

40+
it('res.end(cb)', function (done) {
41+
var callbackCalled = false
42+
43+
var server = createServer({ threshold: 0 }, function (req, res) {
44+
res.setHeader('Content-Type', 'text/plain')
45+
res.write(Buffer.from('hello world'))
46+
res.end(function () {
47+
callbackCalled = true
48+
})
49+
})
50+
51+
request(server)
52+
.get('/')
53+
.set('Accept-Encoding', 'gzip')
54+
.expect('Content-Encoding', 'gzip')
55+
.expect(200, function () {
56+
assert.ok(callbackCalled)
57+
done()
58+
})
59+
})
60+
61+
it('res.end(string, cb)', function (done) {
62+
var callbackCalled = false
63+
64+
var server = createServer({ threshold: 0 }, function (req, res) {
65+
res.setHeader('Content-Type', 'text/plain')
66+
res.end(Buffer.from('hello world'), function () {
67+
callbackCalled = true
68+
})
69+
})
70+
71+
request(server)
72+
.get('/')
73+
.set('Accept-Encoding', 'gzip')
74+
.expect('Content-Encoding', 'gzip')
75+
.expect(200, function () {
76+
assert.ok(callbackCalled)
77+
done()
78+
})
79+
})
80+
4081
var run = /^v0\.12\./.test(process.version) ? it : it.skip
4182
run('res.write(Uint8Array)', function (done) {
4283
var server = createServer({ threshold: 0 }, function (req, res) {

0 commit comments

Comments
 (0)