From 008b6e0faed1ef1c82c057669a2d3ba18ed89705 Mon Sep 17 00:00:00 2001 From: Naz Date: Wed, 17 Nov 2021 20:14:08 +0400 Subject: [PATCH] Optimized e2e-api tests using boot with no frontend refs https://github.com/TryGhost/Toolbox/issues/135 - When running e2e-API test in most cases there's no need to boot Ghost instance with full frontend. This should improve the boot time which should reflect on the speed of running test suites - The tests where the "forceStart" and "withFrontend" are used together indicate that there's still some work to do to fully separate frontend/backend boot line. The force start is also unnecessary, but was needed to reinitialize all services properly - should be investigated! --- .../admin/custom_theme_settings.test.js | 6 +++++- test/e2e-api/admin/themes.test.js | 5 ++++- test/utils/e2e-utils.js | 20 +++++++++++++------ test/utils/url-service-utils.js | 4 ++-- 4 files changed, 25 insertions(+), 10 deletions(-) diff --git a/test/e2e-api/admin/custom_theme_settings.test.js b/test/e2e-api/admin/custom_theme_settings.test.js index f2f0a82166..f55e0cf794 100644 --- a/test/e2e-api/admin/custom_theme_settings.test.js +++ b/test/e2e-api/admin/custom_theme_settings.test.js @@ -9,7 +9,11 @@ describe('Custom Theme Settings API', function () { let request; before(async function () { - await testUtils.startGhost(); + // NOTE: needs force start to be able to reinitialize Ghost process with frontend services - custom-theme-settings, to be specific + await testUtils.startGhost({ + forceStart: true, + withFrontend: true + }); request = supertest.agent(config.get('url')); await localUtils.doAuth(request, 'users:extra', 'custom_theme_settings'); diff --git a/test/e2e-api/admin/themes.test.js b/test/e2e-api/admin/themes.test.js index 0c6cd318ed..618d47832b 100644 --- a/test/e2e-api/admin/themes.test.js +++ b/test/e2e-api/admin/themes.test.js @@ -26,7 +26,10 @@ describe('Themes API', function () { }; before(async function () { - await testUtils.startGhost(); + await testUtils.startGhost({ + forceStart: true, // NOTE: this flag should not be here! the URL service re-initialization should be fixe instead + withFrontend: true + }); ownerRequest = supertest.agent(config.get('url')); await localUtils.doAuth(ownerRequest); }); diff --git a/test/utils/e2e-utils.js b/test/utils/e2e-utils.js index 6a0dd918e9..c7dcdc7327 100644 --- a/test/utils/e2e-utils.js +++ b/test/utils/e2e-utils.js @@ -96,7 +96,7 @@ const prepareContentFolder = (options) => { // - truncate database // - re-run default fixtures // - reload affected services -const restartModeGhostStart = async () => { +const restartModeGhostStart = async ({withFrontend}) => { debug('Reload Mode'); // Teardown truncates all tables and also calls urlServiceUtils.reset(); await dbUtils.teardown(); @@ -117,8 +117,12 @@ const restartModeGhostStart = async () => { // Reload the URL service & wait for it to be ready again // @TODO: why/how is this different to urlService.resetGenerators? urlServiceUtils.reset(); - urlServiceUtils.init(); - await urlServiceUtils.isFinished(); + urlServiceUtils.init({urlCache: !withFrontend}); + + if (withFrontend) { + await urlServiceUtils.isFinished(); + } + debug('routes done'); await customRedirectsService.init(); @@ -127,8 +131,8 @@ const restartModeGhostStart = async () => { limits.init(); }; -const bootGhost = async () => { - ghostServer = await boot(); +const bootGhost = async ({withBackend, withFrontend}) => { + ghostServer = await boot({withBackend, withFrontend}); }; // CASE: Ghost Server needs Starting @@ -168,13 +172,17 @@ const freshModeGhostStart = async (options) => { await bootGhost(options); // Wait for the URL service to be ready, which happens after bootYou - await urlServiceUtils.isFinished(); + if (options.withFrontend) { + await urlServiceUtils.isFinished(); + } }; const startGhost = async (options) => { const startTime = Date.now(); debug('Start Ghost'); options = _.merge({ + withBackend: true, + withFrontend: false, redirectsFile: true, redirectsFileExt: '.json', forceStart: false, diff --git a/test/utils/url-service-utils.js b/test/utils/url-service-utils.js index 599d9d9036..459a340f41 100644 --- a/test/utils/url-service-utils.js +++ b/test/utils/url-service-utils.js @@ -17,8 +17,8 @@ module.exports.isFinished = async (options = {disableDbReadyEvent: false}) => { }; // @TODO: unify all the reset/softTeset helpers so they either work how the main code works or the reasons why they are different are clear -module.exports.init = () => { - urlService.init(); +module.exports.init = ({urlCache}) => { + urlService.init({urlCache}); }; module.exports.reset = () => {