Skip to content

Commit

Permalink
Mocked network access for {{amp_content}} img unit test (#10792)
Browse files Browse the repository at this point in the history
no issue

- unit test was fetching images over the network which could cause random test failures on poor connections
  • Loading branch information
kevinansfield authored and allouis committed Jun 19, 2019
1 parent abda6e6 commit 3069f5f
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions core/test/unit/apps/amp/amp_content_spec.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
var should = require('should'),
rewire = require('rewire'),
nock = require('nock'),
urlUtils = require('../../../../test/utils/urlUtils'),
ampContentHelper = rewire('../../../../server/apps/amp/lib/helpers/amp_content');

Expand Down Expand Up @@ -117,12 +118,18 @@ describe('{{amp_content}} helper', function () {
});

it('can transform img tags to amp-img', function (done) {
const GIF1x1 = Buffer.from('R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==', 'base64');

nock('https://blog.ghost.org')
.get('/content/images/2019/06/test.jpg')
.reply(200, GIF1x1);

var testData = {
html: '<img src="/content/images/2016/08/scheduled2-1.jpg" alt="The Ghost Logo" />',
html: '<img src="/content/images/2019/06/test.jpg" alt="The Ghost Logo" />',
updated_at: 'Wed Jul 27 2016 18:17:22 GMT+0200 (CEST)',
id: 1
},
expectedResult = '<amp-img src="https://blog.ghost.org/content/images/2016/08/scheduled2-1.jpg" alt="The Ghost Logo" width="1000" height="281" layout="responsive"></amp-img>',
expectedResult = '<amp-img src="https://blog.ghost.org/content/images/2019/06/test.jpg" alt="The Ghost Logo" width="1" height="1" layout="fixed"></amp-img>',
ampResult = ampContentHelper.call(testData);

ampResult.then(function (rendered) {
Expand Down

0 comments on commit 3069f5f

Please sign in to comment.