Revert "Improve the performance of prepareContentFolder"

This reverts commit bfacca3035.
This commit is contained in:
Sam Lord 2022-01-04 11:34:42 +00:00
parent 30c27ee1c3
commit af075c063e
4 changed files with 17 additions and 22 deletions

View File

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

View File

@ -5,6 +5,7 @@ const fs = require('fs');
const _ = require('lodash'); const _ = require('lodash');
const supertest = require('supertest'); const supertest = require('supertest');
const nock = require('nock'); const nock = require('nock');
const testUtils = require('../../utils');
const config = require('../../../core/shared/config'); const config = require('../../../core/shared/config');
const localUtils = require('./utils'); const localUtils = require('./utils');
const settingsCache = require('../../../core/shared/settings-cache'); const settingsCache = require('../../../core/shared/settings-cache');
@ -25,9 +26,10 @@ describe('Themes API', function () {
}; };
before(async function () { before(async function () {
await localUtils.startGhost({ // NOTE: this flag should not be here! the URL service re-initialization should be fixed instead
copyThemes: true // 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();
ownerRequest = supertest.agent(config.get('url')); ownerRequest = supertest.agent(config.get('url'));
await localUtils.doAuth(ownerRequest); await localUtils.doAuth(ownerRequest);
}); });

View File

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

View File

@ -81,9 +81,6 @@ const prepareContentFolder = (options) => {
if (options.copyThemes) { 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) // 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')); 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) { if (options.redirectsFile) {
@ -102,7 +99,7 @@ const prepareContentFolder = (options) => {
// - truncate database // - truncate database
// - re-run default fixtures // - re-run default fixtures
// - reload affected services // - reload affected services
const restartModeGhostStart = async ({frontend, copyThemes, copySettings}) => { const restartModeGhostStart = async ({frontend}) => {
debug('Reload Mode'); debug('Reload Mode');
// TODO: figure out why we need this if we reset again later? // TODO: figure out why we need this if we reset again later?
@ -116,12 +113,11 @@ const restartModeGhostStart = async ({frontend, copyThemes, copySettings}) => {
await settingsService.init(); await settingsService.init();
debug('settings done'); debug('settings done');
if (copySettings) { if (frontend) {
// Load the frontend-related components
await routeSettingsService.init(); await routeSettingsService.init();
}
if (copyThemes) {
await themeService.init(); await themeService.init();
await themeService.loadInactiveThemes(); debug('frontend done');
} }
// Reload the URL service & wait for it to be ready again // Reload the URL service & wait for it to be ready again
@ -199,17 +195,19 @@ const startGhost = async (options) => {
options = _.merge({ options = _.merge({
backend: true, backend: true,
frontend: true, frontend: true,
redirectsFile: false, redirectsFile: true,
redirectsFileExt: '.json', redirectsFileExt: '.json',
forceStart: false, forceStart: false,
copyThemes: false, copyThemes: true,
copySettings: false, copySettings: true,
contentFolder: path.join(os.tmpdir(), uuid.v4(), 'ghost-test'), contentFolder: path.join(os.tmpdir(), uuid.v4(), 'ghost-test'),
subdir: false subdir: false
}, options); }, options);
// Ensure we have tmp content folders populated ready for testing
// @TODO: tidy up the tmp folders after tests
prepareContentFolder(options); prepareContentFolder(options);
if (ghostServer && ghostServer.httpServer && !options.forceStart) { if (ghostServer && ghostServer.httpServer && !options.forceStart) {
await restartModeGhostStart(options); await restartModeGhostStart(options);
} else { } else {