⬆️ 🚨 Update Amperize dep and fix test (#7374)

no issue

Updates Amperize dep to v0.3.1 and fixes test for `amp_content`.
This commit is contained in:
Aileen Nowak 2016-09-14 13:30:37 +02:00 committed by Hannah Wolfe
parent 8c1e5fbc61
commit a4427952e2
3 changed files with 32 additions and 7 deletions

View File

@ -126,7 +126,7 @@ function getAmperizeHTML(html, post) {
amperize.parse(html, function (err, res) {
if (err) {
if (err.src) {
errors.logError(err.message, 'AMP HTML couldn\'t get parsed:' + err.src);
errors.logError(err.message, 'AMP HTML couldn\'t get parsed: ' + err.src);
} else {
errors.logError(err);
}

View File

@ -5,6 +5,8 @@ var should = require('should'),
// Stuff we are testing
ampContentHelper = rewire('../lib/helpers/amp_content');
// TODO: Amperize really needs to get stubbed, so we can test returning errors
// properly and make this test faster!
describe('{{amp_content}} helper', function () {
afterEach(function () {
ampContentHelper.__set__('amperizeCache', {});
@ -109,7 +111,7 @@ describe('{{amp_content}} helper', function () {
describe('Transforms and sanitizes HTML', function () {
beforeEach(function () {
configUtils.set({url: 'https://my-awesome-blog.com/'});
configUtils.set({url: 'https://blog.ghost.org/'});
});
afterEach(function () {
@ -119,11 +121,11 @@ describe('{{amp_content}} helper', function () {
it('can transform img tags to amp-img', function (done) {
var testData = {
html: '<img src="/content/images/ghost.png" alt="The Ghost Logo" />',
html: '<img src="/content/images/2016/08/scheduled2-1.jpg" alt="The Ghost Logo" />',
updated_at: 'Wed Jul 27 2016 18:17:22 GMT+0200 (CEST)',
id: 1
},
expectedResult = '<amp-img src="https://my-awesome-blog.com/content/images/ghost.png" alt="The Ghost Logo" width="600" height="400" layout="responsive"></amp-img>',
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>',
ampResult = ampContentHelper.call(testData);
ampResult.then(function (rendered) {
@ -183,7 +185,7 @@ describe('{{amp_content}} helper', function () {
updated_at: 'Wed Jul 27 2016 18:17:22 GMT+0200 (CEST)',
id: 1
},
expectedResult = '<amp-img src="https://my-awesome-blog.com/content/images/2016/08/aileen_small.jpg" width="50" ' +
expectedResult = '<amp-img src="https://blog.ghost.org/content/images/2016/08/aileen_small.jpg" width="50" ' +
'height="50" layout="responsive"></amp-img><p align="right">Hello</p>' +
'<table><tr bgcolor="tomato"><th>Name:</th> ' +
'<td colspan="2">Bill Gates</td></tr><tr><th rowspan="2" valign="center">Telephone:</th> ' +
@ -215,7 +217,7 @@ describe('{{amp_content}} helper', function () {
}).catch(done);
});
it('can handle incomplete HTML tags', function (done) {
it('can handle incomplete HTML tags by returning not Amperized HTML', function (done) {
var testData = {
html: '<img><///img>',
updated_at: 'Wed Jul 27 2016 18:17:22 GMT+0200 (CEST)',
@ -238,6 +240,29 @@ describe('{{amp_content}} helper', function () {
}).catch(done);
});
it('can handle not existing img src by returning not Amperized HTML', function (done) {
var testData = {
html: '<img src="/content/images/does-not-exist.jpg" alt="The Ghost Logo" />',
updated_at: 'Wed Jul 27 2016 18:17:22 GMT+0200 (CEST)',
id: 1
},
ampResult = ampContentHelper.call(testData),
sanitizedHTML,
ampedHTML;
ampResult.then(function (rendered) {
sanitizedHTML = ampContentHelper.__get__('cleanHTML');
ampedHTML = ampContentHelper.__get__('ampHTML');
should.exist(rendered);
rendered.string.should.equal('');
should.exist(ampedHTML);
ampedHTML.should.be.equal('<img src="https://blog.ghost.org/content/images/does-not-exist.jpg" alt="The Ghost Logo">');
should.exist(sanitizedHTML);
sanitizedHTML.should.be.equal('');
done();
}).catch(done);
});
it('sanitizes remaining and not valid tags', function (done) {
var testData = {
html: '<form<input type="text" placeholder="Hi AMP tester"></form>' +

View File

@ -26,7 +26,7 @@
"node": "~0.10.0 || ~0.12.0 || ^4.2.0"
},
"dependencies": {
"amperize": "https://github.com/AileenCGN/amperize/tarball/error-handling-on-timeout",
"amperize": "0.3.1",
"archiver": "1.0.1",
"bcryptjs": "2.3.0",
"bluebird": "3.4.1",