From 77b58804b7bbe980d255b3ad7afa56428fad5a6e Mon Sep 17 00:00:00 2001 From: Aileen Nowak Date: Wed, 13 Sep 2017 16:08:16 +0700 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20=20Replace=20http=20and=20https=20w?= =?UTF-8?q?ith=20got?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit closes #99 - Used [`got`](https://github.com/sindresorhus/got) for image-size requests, which is more lightweight and has the huge advantage of following redirects - Added and updated test - indents - Added dependencies: - [validator](https://github.com/chriso/validator.js) - [lodash](https://github.com/lodash/lodash) - [got](https://github.com/sindresorhus/got) --- lib/.DS_Store | Bin 0 -> 6148 bytes lib/amperize.js | 123 +++++++++++++++++++++++------------------- package.json | 5 +- test/amperize.test.js | 90 ++++++++++++++++++++++++++++--- 4 files changed, 155 insertions(+), 63 deletions(-) create mode 100644 lib/.DS_Store diff --git a/lib/.DS_Store b/lib/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..5008ddfcf53c02e82d7eee2e57c38e5672ef89f6 GIT binary patch literal 6148 zcmeH~Jr2S!425mzP>H1@V-^m;4Wg<&0T*E43hX&L&p$$qDprKhvt+--jT7}7np#A3 zem<@ulZcFPQ@L2!n>{z**++&mCkOWA81W14cNZlEfg7;MkzE(HCqgga^y>{tEnwC%0;vJ&^%eQ zLs35+`xjp>T0' + body: '' }); sizeOfStub.returns({width: 50, height: 50, type: 'jpg'}); @@ -118,7 +119,7 @@ describe('Amperize', function () { sizeOfMock = nock('http://static.wixstatic.com') .get('/media/355241_d31358572a2542c5a44738ddcb59e7ea.jpg_256') .reply(200, { - data: '' + body: '' }); sizeOfStub.returns({width: 350, height: 200, type: 'jpg'}); @@ -137,11 +138,44 @@ describe('Amperize', function () { }); }); + it('returns largest image value for .ico files', function (done) { + sizeOfMock = nock('https://somewebsite.com') + .get('/favicon.ico') + .reply(200, { + body: '' + }); + + sizeOfStub.returns({ + width: 32, + height: 32, + type: 'ico', + images: [ + {width: 48, height: 48}, + {width: 32, height: 32}, + {width: 16, height: 16} + ] + }); + Amperize.__set__('sizeOf', sizeOfStub); + + amperize.parse('', function (error, result) { + expect(result).to.exist; + expect(Amperize.__get__('called')).to.be.equal(false); + expect(result).to.contain(''); + done(); + }); + }); + + it('transforms .gif with only height property into with full dimensions by overriding them', function (done) { sizeOfMock = nock('https://media.giphy.com') .get('/media/l46CtzgjhTm29Cbjq/giphy.gif') .reply(200, { - data: '' + body: '' }); sizeOfStub.returns({width: 800, height: 600, type: 'gif'}); @@ -230,6 +264,15 @@ describe('Amperize', function () { }); }); + it('can handle invalid URLs', function (done) { + amperize.parse('', function (error, result) { + expect(result).to.exist; + expect(Amperize.__get__('called')).to.be.equal(true); + expect(result).to.be.equal(''); + done(); + }); + }); + it('can handle