Skip to content

Commit 50ca417

Browse files
test(compression): add ERR_STREAM_ALREADY_FINISHED
1 parent 3493e8c commit 50ca417

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

test/compression.js

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ describe('compression()', function () {
111111
})
112112
})
113113

114-
it('res.write() should throw ERR_STREAM_DESTROYED when destoyed stream', function (done) {
114+
it('res.write() should throw ERR_STREAM_DESTROYED when stream is already destroyed', function (done) {
115115
var server = createServer({ threshold: 0 }, function (req, res) {
116116
res.setHeader('Content-Type', 'text/plain')
117117
res.end('hello world')
@@ -131,6 +131,26 @@ describe('compression()', function () {
131131
.expect(200, done)
132132
})
133133

134+
it('res.write() should throw ERR_STREAM_ALREADY_FINISHED when stream is already finished', function (done) {
135+
var server = createServer({ threshold: 0 }, function (req, res) {
136+
res.setHeader('Content-Type', 'text/plain')
137+
res.end('hello world')
138+
139+
server.on('close', function () {
140+
res.end(function (err) {
141+
assert.ok(err.code === 'ERR_STREAM_ALREADY_FINISHED')
142+
})
143+
})
144+
})
145+
146+
request(server)
147+
.get('/')
148+
.set('Accept-Encoding', 'gzip')
149+
.expect(shouldHaveHeader('Content-Encoding'))
150+
.expect(shouldHaveBodyLength('hello world'.length))
151+
.expect(200, done)
152+
})
153+
134154
it('res.write() should call callback if passsed', function (done) {
135155
var server = createServer({ threshold: 0 }, function (req, res) {
136156
res.setHeader('Content-Type', 'text/plain')

0 commit comments

Comments
 (0)