From af075c063e77acacce91bdef80a12cec12ae1b90 Mon Sep 17 00:00:00 2001 From: Sam Lord Date: Tue, 4 Jan 2022 11:34:42 +0000 Subject: [PATCH] Revert "Improve the performance of prepareContentFolder" This reverts commit bfacca3035e579f2dc8b16e873b7cc0d35aad566. --- test/e2e-api/admin/settings.test.js | 5 +---- test/e2e-api/admin/themes.test.js | 8 +++++--- test/e2e-frontend/members.test.js | 4 +--- test/utils/e2e-utils.js | 22 ++++++++++------------ 4 files changed, 17 insertions(+), 22 deletions(-) diff --git a/test/e2e-api/admin/settings.test.js b/test/e2e-api/admin/settings.test.js index 5c46d0bce4..5e72dca61f 100644 --- a/test/e2e-api/admin/settings.test.js +++ b/test/e2e-api/admin/settings.test.js @@ -12,10 +12,7 @@ describe('Settings API', function () { let request; before(async function () { - await localUtils.startGhost({ - redirectsFile: true, - copySettings: true - }); + await localUtils.startGhost(); request = supertest.agent(config.get('url')); await localUtils.doAuth(request); }); diff --git a/test/e2e-api/admin/themes.test.js b/test/e2e-api/admin/themes.test.js index 9fda25aa9d..b153dd8003 100644 --- a/test/e2e-api/admin/themes.test.js +++ b/test/e2e-api/admin/themes.test.js @@ -5,6 +5,7 @@ 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'); @@ -25,9 +26,10 @@ describe('Themes API', function () { }; before(async function () { - await localUtils.startGhost({ - copyThemes: true - }); + // 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(); ownerRequest = supertest.agent(config.get('url')); await localUtils.doAuth(ownerRequest); }); diff --git a/test/e2e-frontend/members.test.js b/test/e2e-frontend/members.test.js index 4a9ab37157..6f7647f53f 100644 --- a/test/e2e-frontend/members.test.js +++ b/test/e2e-frontend/members.test.js @@ -51,9 +51,7 @@ describe('Front-end members behaviour', function () { return originalSettingsCacheGetFn(key, options); }); - await testUtils.startGhost({ - copyThemes: true - }); + await testUtils.startGhost(); await testUtils.initFixtures('members'); request = supertest.agent(configUtils.config.get('url')); }); diff --git a/test/utils/e2e-utils.js b/test/utils/e2e-utils.js index 55abf5b145..aa0566d1f4 100644 --- a/test/utils/e2e-utils.js +++ b/test/utils/e2e-utils.js @@ -81,9 +81,6 @@ 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) { @@ -102,7 +99,7 @@ const prepareContentFolder = (options) => { // - truncate database // - re-run default fixtures // - reload affected services -const restartModeGhostStart = async ({frontend, copyThemes, copySettings}) => { +const restartModeGhostStart = async ({frontend}) => { debug('Reload Mode'); // 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(); debug('settings done'); - if (copySettings) { + if (frontend) { + // Load the frontend-related components await routeSettingsService.init(); - } - if (copyThemes) { await themeService.init(); - await themeService.loadInactiveThemes(); + debug('frontend done'); } // Reload the URL service & wait for it to be ready again @@ -199,17 +195,19 @@ const startGhost = async (options) => { options = _.merge({ backend: true, frontend: true, - redirectsFile: false, + redirectsFile: true, redirectsFileExt: '.json', forceStart: false, - copyThemes: false, - copySettings: false, + copyThemes: true, + copySettings: true, 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 {