Skip to content

Commit 6b9a748

Browse files
author
haoxin
committedSep 25, 2017
fix tests
1 parent 2f27769 commit 6b9a748

File tree

2 files changed

+19
-10
lines changed

2 files changed

+19
-10
lines changed
 

‎index.js

+1
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ async function send (ctx, path, opts = {}) {
138138
}
139139
ctx.type = type(path, encodingExt)
140140
ctx.body = fs.createReadStream(path)
141+
141142
return path
142143
}
143144

‎test/index.js

+18-10
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,18 @@ describe('send(ctx, file)', function () {
373373
})
374374

375375
describe('or .br version when requested and if possible', function () {
376+
function parser(res, cb) {
377+
const chunks = []
378+
res.on('data', chunk => {
379+
chunks.push(chunk)
380+
})
381+
res.on('end', () => {
382+
decompress(Buffer.concat(chunks), (err, data) => {
383+
cb(err, data.toString())
384+
})
385+
})
386+
}
387+
376388
it('should return path', function (done) {
377389
const app = new Koa()
378390

@@ -397,15 +409,13 @@ describe('send(ctx, file)', function () {
397409

398410
request(app.listen())
399411
.get('/')
412+
.parse(parser)
400413
.set('Accept-Encoding', 'br, deflate, identity')
401414
.expect('Content-Length', '22')
402415
.expect(200)
403416
.then(({body}) => {
404-
decompress(body, (err, output) => {
405-
assert.strictEqual(err, null)
406-
assert.deepStrictEqual(output.toString(), '{ "name": "tobi" }')
407-
done()
408-
})
417+
assert.deepStrictEqual(body, '{ "name": "tobi" }')
418+
done()
409419
})
410420
})
411421

@@ -418,15 +428,13 @@ describe('send(ctx, file)', function () {
418428

419429
request(app.listen())
420430
.get('/')
431+
.parse(parser)
421432
.set('Accept-Encoding', 'br, deflate, identity')
422433
.expect('Content-Length', '22')
423434
.expect(200)
424435
.then(({body}) => {
425-
decompress(body, (err, output) => {
426-
assert.strictEqual(err, null)
427-
assert.deepStrictEqual(output.toString(), '{ "name": "tobi" }')
428-
done()
429-
})
436+
assert.deepStrictEqual(body, '{ "name": "tobi" }')
437+
done()
430438
})
431439
})
432440

0 commit comments

Comments
 (0)
Please sign in to comment.