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

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
This commit is contained in:
Hannah Wolfe 2022-02-11 10:34:43 +00:00
parent dabf143cae
commit 3e7039c47d
No known key found for this signature in database
GPG key ID: AB586C3B5AE5C037
3 changed files with 11 additions and 3 deletions

View file

@ -148,5 +148,8 @@ module.exports = {
let result = await getStorage().delete(themeName); let result = await getStorage().delete(themeName);
list.del(themeName); list.del(themeName);
return result; return result;
},
updateStoragePath: function (storagePath) {
getStorage().storagePath = storagePath;
} }
}; };

View file

@ -25,20 +25,23 @@ const redirectsUtils = require('./redirects');
const configUtils = require('./configUtils'); const configUtils = require('./configUtils');
const mockManager = require('./e2e-framework-mock-manager'); const mockManager = require('./e2e-framework-mock-manager');
const themeStorage = require('../../core/server/services/themes/storage');
const boot = require('../../core/boot'); const boot = require('../../core/boot');
const TestAgent = require('./test-agent'); const TestAgent = require('./test-agent');
const db = require('./db-utils'); const db = require('./db-utils');
const startGhost = async () => { const startGhost = async () => {
/** /**
* We never use the root content folder for testing! * We never use the root content folder for testing!
* We use a tmp folder. * We use a tmp folder.
*/ */
const contentFolder = path.join(os.tmpdir(), uuid.v4(), 'ghost-test'); const contentFolder = path.join(os.tmpdir(), uuid.v4(), 'ghost-test');
await prepareContentFolder({contentFolder}); await prepareContentFolder({contentFolder});
// NOTE: need to pass this config to the server instance // NOTE: need to pass this config to the server instance
configUtils.set('paths:contentPath', contentFolder); configUtils.set('paths:contentPath', contentFolder);
themeStorage.updateStoragePath(configUtils.config.getContentPath('themes'));
const defaults = { const defaults = {
backend: true, backend: true,

View file

@ -18,6 +18,7 @@ const urlService = require('../../core/server/services/url');
const settingsService = require('../../core/server/services/settings'); const settingsService = require('../../core/server/services/settings');
const routeSettingsService = require('../../core/server/services/route-settings'); const routeSettingsService = require('../../core/server/services/route-settings');
const themeService = require('../../core/server/services/themes'); const themeService = require('../../core/server/services/themes');
const themeStorage = require('../../core/server/services/themes/storage');
const limits = require('../../core/server/services/limits'); const limits = require('../../core/server/services/limits');
const customRedirectsService = require('../../core/server/services/redirects'); const customRedirectsService = require('../../core/server/services/redirects');
@ -69,6 +70,7 @@ const prepareContentFolder = (options) => {
* We use a tmp folder. * We use a tmp folder.
*/ */
configUtils.set('paths:contentPath', contentFolderForTests); configUtils.set('paths:contentPath', contentFolderForTests);
themeStorage.updateStoragePath(configUtils.config.getContentPath('themes'));
fs.ensureDirSync(contentFolderForTests); fs.ensureDirSync(contentFolderForTests);
fs.ensureDirSync(path.join(contentFolderForTests, 'data')); fs.ensureDirSync(path.join(contentFolderForTests, 'data'));