From 245230911497f1f42b69f91a30618a16261d156f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kornel=20Lesin=CC=81ski?= Date: Wed, 25 Jan 2017 23:09:59 +0000 Subject: [PATCH] Test octet-stream --- test/node/image.js | 15 +++++++++++++++ test/support/server.js | 10 ++++++++-- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/test/node/image.js b/test/node/image.js index ec428f048..73d8929b0 100644 --- a/test/node/image.js +++ b/test/node/image.js @@ -13,6 +13,21 @@ describe('res.body', function(){ request .get(base + '/image') .end(function(err, res){ + res.type.should.equal('image/png'); + Buffer.isBuffer(res.body).should.be.true(); + (res.body.length - img.length).should.equal(0); + done(); + }); + }); + }); + describe('application/octet-stream', function(){ + it('should parse the body', function(done){ + request + .get(base + '/image-as-octets') + .buffer(true) // that's tech debt :( + .end(function(err, res){ + res.type.should.equal('application/octet-stream'); + Buffer.isBuffer(res.body).should.be.true(); (res.body.length - img.length).should.equal(0); done(); }); diff --git a/test/support/server.js b/test/support/server.js index c6157a25c..807071fba 100644 --- a/test/support/server.js +++ b/test/support/server.js @@ -386,10 +386,16 @@ app.get('/manny', function(req, res){ res.status(200).json({name:"manny"}); }); -app.get('/image', function(req, res){ +function serveImageWithType(res, type) { var img = fs.readFileSync(__dirname + '/../node/fixtures/test.png'); - res.writeHead(200, {'Content-Type': 'image/png' }); + res.writeHead(200, {'Content-Type': type }); res.end(img, 'binary'); +} +app.get('/image', function(req, res){ + serveImageWithType(res, 'image/png'); +}); +app.get('/image-as-octets', function(req, res){ + serveImageWithType(res, 'application/octet-stream'); }); app.get('/chunked-json', function(req, res){