diff --git a/core/server/utils/cached-image-size-from-url.js b/core/server/utils/cached-image-size-from-url.js index 3e1a85333c..6499f1dd5e 100644 --- a/core/server/utils/cached-image-size-from-url.js +++ b/core/server/utils/cached-image-size-from-url.js @@ -1,8 +1,7 @@ var Promise = require('bluebird'), - sizeOf = require('./image-size'), + imageSize = require('./image-size'), logging = require('../logging'), errors = require('../errors'), - getImageSizeFromUrl = sizeOf.getImageSizeFromUrl, imageSizeCache = {}; /** @@ -20,7 +19,7 @@ function getCachedImageSizeFromUrl(url) { // image size is not in cache if (!imageSizeCache[url]) { - return getImageSizeFromUrl(url).then(function (res) { + return imageSize.getImageSizeFromUrl(url).then(function (res) { imageSizeCache[url] = res; return Promise.resolve(imageSizeCache[url]); diff --git a/core/test/unit/server_helpers/ghost_head_spec.js b/core/test/unit/server_helpers/ghost_head_spec.js index 2f77cdab40..081c0cb1f2 100644 --- a/core/test/unit/server_helpers/ghost_head_spec.js +++ b/core/test/unit/server_helpers/ghost_head_spec.js @@ -5,6 +5,7 @@ var should = require('should'), // jshint ignore:line moment = require('moment'), configUtils = require('../../utils/configUtils'), helpers = require('../../../server/helpers'), + imageSize = require('../../../server/utils/image-size'), proxy = require('../../../server/helpers/proxy'), settingsCache = proxy.settingsCache, api = proxy.api, @@ -18,9 +19,15 @@ describe('{{ghost_head}} helper', function () { configUtils.restore(); }); - // TODO: stub `getImageDimensions` to make things faster beforeEach(function () { - sandbox.stub(api.clients, 'read').returns(new Promise.resolve({ + /** + * Each test case here requests the image dimensions. + * The image path is e.g. localhost:port/favicon.ico, but no server is running. + * If we don't mock the image size utility, we run into lot's of timeouts. + */ + sandbox.stub(imageSize, 'getImageSizeFromUrl').returns(Promise.resolve()); + + sandbox.stub(api.clients, 'read').returns(Promise.resolve({ clients: [ {slug: 'ghost-frontend', secret: 'a1bcde23cfe5', status: 'enabled'} ] diff --git a/core/test/unit/utils/cached-image-size-from-url_spec.js b/core/test/unit/utils/cached-image-size-from-url_spec.js index 2581696b87..33596be958 100644 --- a/core/test/unit/utils/cached-image-size-from-url_spec.js +++ b/core/test/unit/utils/cached-image-size-from-url_spec.js @@ -3,7 +3,7 @@ var should = require('should'), Promise = require('bluebird'), rewire = require('rewire'), -// Stuff we are testing + // Stuff we are testing getCachedImageSizeFromUrl = rewire('../../../server/utils/cached-image-size-from-url'), sandbox = sinon.sandbox.create(); @@ -30,7 +30,7 @@ describe('getCachedImageSizeFromUrl', function () { type: 'jpg' })); - getCachedImageSizeFromUrl.__set__('getImageSizeFromUrl', sizeOfStub); + getCachedImageSizeFromUrl.__set__('imageSize.getImageSizeFromUrl', sizeOfStub); getCachedImageSizeFromUrl(url).then(function () { // first call to get result from `getImageSizeFromUrl` @@ -61,7 +61,7 @@ describe('getCachedImageSizeFromUrl', function () { sizeOfStub.returns(new Promise.reject('error')); - getCachedImageSizeFromUrl.__set__('getImageSizeFromUrl', sizeOfStub); + getCachedImageSizeFromUrl.__set__('imageSize.getImageSizeFromUrl', sizeOfStub); getCachedImageSizeFromUrl(url) .then(function () {