mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-04-08 02:52:39 -05:00
Added comments and TODOs to startGhost test util
This commit is contained in:
parent
c7a29b4e7c
commit
9f718750b4
1 changed files with 39 additions and 2 deletions
|
@ -191,24 +191,39 @@ const startGhost = async function startGhost(options) {
|
|||
fs.copySync(path.join(__dirname, 'fixtures', 'settings', 'routes.yaml'), path.join(contentFolderForTests, 'settings', 'routes.yaml'));
|
||||
}
|
||||
|
||||
// truncate database and re-run fixtures
|
||||
// we have to ensure that some components in Ghost are reloaded
|
||||
// CASE: Ghost Server is Running
|
||||
// In this case we need to reset things so it's as though Ghost just booted:
|
||||
// - truncate database
|
||||
// - re-run default fixtures
|
||||
//
|
||||
// - reload affected services
|
||||
if (ghostServer && ghostServer.httpServer && !options.forceStart) {
|
||||
// Teardown truncates all tables and also calls urlServiceUtils.reset();
|
||||
await dbUtils.teardown();
|
||||
|
||||
// The tables have been truncated, this runs the fixture init task (init file 2) to re-add our default fixtures
|
||||
await knexMigrator.init({only: 2});
|
||||
|
||||
// Reset the settings cache
|
||||
// @TODO: Prob A: why/how is this different to using settingsCache.reset()
|
||||
settingsCache.shutdown();
|
||||
await settingsService.init();
|
||||
|
||||
// Reload the frontend
|
||||
await frontendSettingsService.init();
|
||||
await themes.init();
|
||||
|
||||
// Reload the URL service & wait for it to be ready again
|
||||
// @TODO: Prob B: why/how is this different to urlService.resetGenerators?
|
||||
urlServiceUtils.reset();
|
||||
await urlServiceUtils.isFinished();
|
||||
// @TODO: why does this happen _after_ URL service
|
||||
web.shared.middlewares.customRedirects.reload();
|
||||
|
||||
// Trigger server start, which is ONLY used for theme reload
|
||||
events.emit('server.start');
|
||||
|
||||
// Expose some data, wrap-up and return
|
||||
await dirtyDataFunction();
|
||||
console.log('Restart Mode'); // eslint-disable-line no-console
|
||||
console.timeEnd('Start Ghost'); // eslint-disable-line no-console
|
||||
|
@ -216,24 +231,42 @@ const startGhost = async function startGhost(options) {
|
|||
return ghostServer;
|
||||
}
|
||||
|
||||
// CASE: Ghost Server needs Starting
|
||||
// In this case we need to ensure that Ghost is started cleanly:
|
||||
// - ensure the DB is reset
|
||||
// - CASE: If we are in force start mode the server is already running so we
|
||||
// - stop the server (if we are in force start mode it will be running)
|
||||
// - reload affected services - just settings and not the frontend!?
|
||||
// - Start Ghost: Uses OLD Boot process
|
||||
|
||||
// Reset the DB
|
||||
await knexMigrator.reset({force: true});
|
||||
|
||||
// Stop the serve (forceStart Mode)
|
||||
if (ghostServer && ghostServer.httpServer) {
|
||||
await ghostServer.stop();
|
||||
}
|
||||
|
||||
// Reset the settings cache
|
||||
// @TODO: Prob A: why/how is this different to using settingsService.init() and why to do we need this?
|
||||
settingsCache.shutdown();
|
||||
settingsCache.reset();
|
||||
|
||||
// Do a full database initialisation
|
||||
await knexMigrator.init();
|
||||
|
||||
if (config.get('database:client') === 'sqlite3') {
|
||||
await db.knex.raw('PRAGMA journal_mode = TRUNCATE;');
|
||||
}
|
||||
|
||||
// Reset the URL service generators
|
||||
// @TODO: Prob B: why/how is this different to urlService.reset?
|
||||
urlService.resetGenerators();
|
||||
|
||||
// Require Ghost
|
||||
ghostServer = await ghost();
|
||||
|
||||
// Mount Ghost & Start Server
|
||||
if (options.subdir) {
|
||||
parentApp = express('test parent');
|
||||
parentApp.use(urlUtils.getSubdir(), ghostServer.rootApp);
|
||||
|
@ -242,9 +275,13 @@ const startGhost = async function startGhost(options) {
|
|||
await ghostServer.start();
|
||||
}
|
||||
|
||||
// Ensure readiness was called (this is idempotent)
|
||||
GhostServer.announceServerReadiness();
|
||||
|
||||
// Wait for the URL service to be ready, which happens after boot, but don't re-trigger db.ready
|
||||
await urlServiceUtils.isFinished({disableDbReadyEvent: true});
|
||||
|
||||
// Expose some data, wrap-up and return
|
||||
await dirtyDataFunction();
|
||||
console.log('Fresh Start Mode'); // eslint-disable-line no-console
|
||||
console.timeEnd('Start Ghost'); // eslint-disable-line no-console
|
||||
|
|
Loading…
Add table
Reference in a new issue