mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-01-03 08:25:06 +03:00
Tests: Stub image request for dimensions (#8973)
no issue - test cases were trying to fetch image sizes for `localhost:port/favicon.ico` but no server is running so they time out - stub the `getImageSizeFromUrl` method so it resolves instantly
This commit is contained in:
parent
5c2e1161f6
commit
1fe87a6110
@ -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]);
|
||||
|
@ -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'}
|
||||
]
|
||||
|
@ -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 () {
|
||||
|
Loading…
Reference in New Issue
Block a user