0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-01-20 22:42:53 -05:00
ghost/test/utils/old-integration-utils.js
Hannah Wolfe 2ff6fdfab8
Fixed broken "mock express" style e2e tests
- done a fastest-possible overhaul on this style of tests to try to get them to work independently again

This is a pattern that was introduced a while ago to try to speed up our e2e tests and I'm not sure if it's staying or going
It uses a minimal frontend-only version of the boot process and a custom-built express testing tool
However it's really old and out of date because of the boot refactor and several changes since
This highlights the key problem with it - it doesn't rely on any of our "core" boot process, it makes it up, and therefore how reliable are these tests?
Ideally we need to get these tests working with the real boot process in some capacity
We would then need to make sure we have all the tests in e2e-frontend written in this style
2021-10-20 13:18:33 +01:00

73 lines
2.6 KiB
JavaScript

// Utility Packages
const path = require('path');
// Ghost Internals
const models = require('../../core/server/models');
const routingService = require('../../core/frontend/services/routing');
const settingsService = require('../../core/server/services/settings');
const settingsCache = require('../../core/shared/settings-cache');
const imageLib = require('../../core/server/lib/image');
const themeService = require('../../core/server/services/themes');
const helperService = require('../../core/frontend/services/helpers');
const appService = require('../../core/frontend/services/apps');
const siteApp = require('../../core/server/web/parent/app');
// Other Test Utilities
const configUtils = require('./configUtils');
const urlServiceUtils = require('./url-service-utils');
module.exports = {
overrideGhostConfig: (utils) => {
utils.set('paths:contentPath', path.join(__dirname, 'fixtures'));
utils.set('times:getImageSizeTimeoutInMS', 1);
},
defaultMocks: (sandbox, options) => {
options = options || {};
configUtils.set('paths:contentPath', path.join(__dirname, 'fixtures'));
const cacheStub = sandbox.stub(settingsCache, 'get');
cacheStub.withArgs('active_theme').returns(options.theme || 'casper');
cacheStub.withArgs('timezone').returns('Etc/UTC');
cacheStub.withArgs('permalinks').returns('/:slug/');
cacheStub.withArgs('ghost_private_key').returns('-----BEGIN RSA PRIVATE KEY-----\nMB8CAQACAgPBAgMBAAECAgMFAgEfAgEfAgEXAgEXAgEA\n-----END RSA PRIVATE KEY-----\n');
cacheStub.withArgs('ghost_public_key').returns('-----BEGIN RSA PUBLIC KEY-----\nMAkCAgPBAgMBAAE=\n-----END RSA PUBLIC KEY-----\n');
if (options.amp) {
cacheStub.withArgs('amp').returns(true);
}
sandbox.stub(imageLib.imageSize, 'getImageSizeFromUrl').resolves();
},
/**
* This is a really rough frontend-only version of Ghost boot
* In order for this test pattern to be really considered the right pattern this needs to be replaced
* With something based on the real boot
* @returns {object} express App
*/
initGhost: async () => {
models.init();
await settingsService.init();
urlServiceUtils.init();
await themeService.init();
await helperService.init();
const app = siteApp({start: true});
await appService.init();
await urlServiceUtils.isFinished();
return app;
},
routing: {
reset: function () {
routingService.registry.resetAll();
}
},
urlService: urlServiceUtils
};