0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-01-20 22:42:53 -05:00

Added settingsCache handling to e2e-framework

refs: https://github.com/Ghost/Ghost/commit/b5ee17b25

- When moving the site tests into e2e-api they broke because they were getting the changed settings value from the settings test
- The solution is to ensure the settingsCache is reset between tests, which is what this commit does
- This commit also renames the shutdown method to reset, because this is not a permanent operation
- It also renames the resetDb method to resetData, because the concept is we want the internal data to be reset, not just the DB
This commit is contained in:
Hannah Wolfe 2022-02-11 16:19:07 +00:00
parent b5ee17b25f
commit 0ab2f36c22
No known key found for this signature in database
GPG key ID: AB586C3B5AE5C037
3 changed files with 21 additions and 8 deletions

View file

@ -30,9 +30,9 @@ module.exports = {
},
/**
* Shutdown the cache, used in force boot during testing
* Restore the cache, used during e2e testing only
*/
shutdown() {
reset() {
SettingsCache.reset(events);
},

View file

@ -30,6 +30,9 @@ const boot = require('../../core/boot');
const TestAgent = require('./test-agent');
const db = require('./db-utils');
// Services that need resetting
const settingsService = require('../../core/server/services/settings');
/**
* @param {Object} [options={}]
* @param {Boolean} [options.backend] Boot the backend
@ -54,8 +57,8 @@ const startGhost = async (options = {}) => {
server: false
};
// Ensure the DB state
await resetDb();
// Ensure the state of all data, including DB and caches
await resetData();
const bootOptions = Object.assign({}, defaults, options);
@ -124,8 +127,18 @@ const getFixture = (type, index = 0) => {
return fixtureUtils.DataGenerator.forKnex[type][index];
};
const resetDb = async () => {
await db.reset();
/**
* This function ensures that Ghost's data is reset back to "factory settings"
*
*/
const resetData = async () => {
// Calling reset on the database also causes the fixtures to be re-run
// We need to unhook the settings events and restore the cache before we do this
// Otherwise, the fixtures being restored will refer to the old settings cache data
settingsService.reset();
// Clear out the database
await db.reset({truncate: true});
};
/**
@ -198,7 +211,7 @@ module.exports = {
get: getFixture,
getCurrentOwnerUser: fixtureUtils.getCurrentOwnerUser,
init: initFixtures,
reset: resetDb
restore: resetData
},
matchers: {
anyString: any(String),

View file

@ -155,7 +155,7 @@ const freshModeGhostStart = async (options) => {
await stopGhost();
// Reset the settings cache and disable listeners so they don't get triggered further
settingsService.shutdown();
settingsService.reset();
await dbUtils.reset();