From 3e7039c47d5b7fdf52fe36517e8180aaa7e562c5 Mon Sep 17 00:00:00 2001 From: Hannah Wolfe Date: Fri, 11 Feb 2022 10:34:43 +0000 Subject: [PATCH] Fixed theme storage getting confused between tests - When starting ghost for e2e tests we create a content folder in the os tmp dir - This means that the folder can change between suites as ghost is started and restarted - For the most part this is fine, but theme storage caches the path to config (which makes sense, it's not meant to change whilst Ghost is in-memory) - This is a quick-n-dirty fix that just makes it possible to update that path in the tests, so we know it's in sync - Ideally we'd not cache the path, use a function to fetch it etc, or fully reset the theme storage layer, but this is the fix I have working today and so it's going in to unblock things for now --- core/server/services/themes/storage.js | 3 +++ test/utils/e2e-framework.js | 9 ++++++--- test/utils/e2e-utils.js | 2 ++ 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/core/server/services/themes/storage.js b/core/server/services/themes/storage.js index 9a95981c30..390b81a0d3 100644 --- a/core/server/services/themes/storage.js +++ b/core/server/services/themes/storage.js @@ -148,5 +148,8 @@ module.exports = { let result = await getStorage().delete(themeName); list.del(themeName); return result; + }, + updateStoragePath: function (storagePath) { + getStorage().storagePath = storagePath; } }; diff --git a/test/utils/e2e-framework.js b/test/utils/e2e-framework.js index 35ca864047..54ed95924f 100644 --- a/test/utils/e2e-framework.js +++ b/test/utils/e2e-framework.js @@ -25,20 +25,23 @@ const redirectsUtils = require('./redirects'); const configUtils = require('./configUtils'); const mockManager = require('./e2e-framework-mock-manager'); +const themeStorage = require('../../core/server/services/themes/storage'); + const boot = require('../../core/boot'); const TestAgent = require('./test-agent'); const db = require('./db-utils'); const startGhost = async () => { /** - * We never use the root content folder for testing! - * We use a tmp folder. - */ + * We never use the root content folder for testing! + * We use a tmp folder. + */ const contentFolder = path.join(os.tmpdir(), uuid.v4(), 'ghost-test'); await prepareContentFolder({contentFolder}); // NOTE: need to pass this config to the server instance configUtils.set('paths:contentPath', contentFolder); + themeStorage.updateStoragePath(configUtils.config.getContentPath('themes')); const defaults = { backend: true, diff --git a/test/utils/e2e-utils.js b/test/utils/e2e-utils.js index bd04863a44..1e24aba1c3 100644 --- a/test/utils/e2e-utils.js +++ b/test/utils/e2e-utils.js @@ -18,6 +18,7 @@ const urlService = require('../../core/server/services/url'); const settingsService = require('../../core/server/services/settings'); const routeSettingsService = require('../../core/server/services/route-settings'); const themeService = require('../../core/server/services/themes'); +const themeStorage = require('../../core/server/services/themes/storage'); const limits = require('../../core/server/services/limits'); const customRedirectsService = require('../../core/server/services/redirects'); @@ -69,6 +70,7 @@ const prepareContentFolder = (options) => { * We use a tmp folder. */ configUtils.set('paths:contentPath', contentFolderForTests); + themeStorage.updateStoragePath(configUtils.config.getContentPath('themes')); fs.ensureDirSync(contentFolderForTests); fs.ensureDirSync(path.join(contentFolderForTests, 'data'));