0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-02-03 23:00:14 -05:00

Improve the performance of prepareContentFolder

refs: https://github.com/TryGhost/Toolbox/issues/150

Instead of loading all themes for each set of tests in the e2e suite, only load the frontend at all for frontend tests, and only load themes for the theme tests.
This commit is contained in:
Sam Lord 2022-01-04 09:27:04 +00:00
parent cc7f527a6a
commit bfacca3035
4 changed files with 22 additions and 17 deletions

View file

@ -12,7 +12,10 @@ describe('Settings API', function () {
let request;
before(async function () {
await localUtils.startGhost();
await localUtils.startGhost({
redirectsFile: true,
copySettings: true
});
request = supertest.agent(config.get('url'));
await localUtils.doAuth(request);
});

View file

@ -5,7 +5,6 @@ const fs = require('fs');
const _ = require('lodash');
const supertest = require('supertest');
const nock = require('nock');
const testUtils = require('../../utils');
const config = require('../../../core/shared/config');
const localUtils = require('./utils');
const settingsCache = require('../../../core/shared/settings-cache');
@ -26,10 +25,9 @@ describe('Themes API', function () {
};
before(async function () {
// NOTE: this flag should not be here! the URL service re-initialization should be fixed instead
// The reason why this init doesn't work without "forceStart" is because during the "restartModeGhostStart"
// the routing.routerManager is never called with "start". That's why a full boot is needed
await localUtils.startGhost();
await localUtils.startGhost({
copyThemes: true
});
ownerRequest = supertest.agent(config.get('url'));
await localUtils.doAuth(ownerRequest);
});

View file

@ -51,7 +51,9 @@ describe('Front-end members behaviour', function () {
return originalSettingsCacheGetFn(key, options);
});
await testUtils.startGhost();
await testUtils.startGhost({
copyThemes: true
});
await testUtils.initFixtures('members');
request = supertest.agent(configUtils.config.get('url'));
});

View file

@ -81,6 +81,9 @@ const prepareContentFolder = (options) => {
if (options.copyThemes) {
// Copy all themes into the new test content folder. Default active theme is always casper. If you want to use a different theme, you have to set the active theme (e.g. stub)
fs.copySync(path.join(__dirname, 'fixtures', 'themes'), path.join(contentFolderForTests, 'themes'));
} else if (options.frontend) {
// Just copy Casper
fs.copySync(path.join(__dirname, 'fixtures', 'themes', 'casper'), path.join(contentFolderForTests, 'themes', 'casper'));
}
if (options.redirectsFile) {
@ -99,7 +102,7 @@ const prepareContentFolder = (options) => {
// - truncate database
// - re-run default fixtures
// - reload affected services
const restartModeGhostStart = async ({frontend}) => {
const restartModeGhostStart = async ({frontend, copyThemes, copySettings}) => {
debug('Reload Mode');
// TODO: figure out why we need this if we reset again later?
@ -113,11 +116,12 @@ const restartModeGhostStart = async ({frontend}) => {
await settingsService.init();
debug('settings done');
if (frontend) {
// Load the frontend-related components
if (copySettings) {
await routeSettingsService.init();
}
if (copyThemes) {
await themeService.init();
debug('frontend done');
await themeService.loadInactiveThemes();
}
// Reload the URL service & wait for it to be ready again
@ -195,19 +199,17 @@ const startGhost = async (options) => {
options = _.merge({
backend: true,
frontend: true,
redirectsFile: true,
redirectsFile: false,
redirectsFileExt: '.json',
forceStart: false,
copyThemes: true,
copySettings: true,
copyThemes: false,
copySettings: false,
contentFolder: path.join(os.tmpdir(), uuid.v4(), 'ghost-test'),
subdir: false
}, options);
// Ensure we have tmp content folders populated ready for testing
// @TODO: tidy up the tmp folders after tests
prepareContentFolder(options);
if (ghostServer && ghostServer.httpServer && !options.forceStart) {
await restartModeGhostStart(options);
} else {