From 891e0cb7a487a030c7179b4948592304fe82672d Mon Sep 17 00:00:00 2001 From: lhokktyn <810615+lhokktyn@users.noreply.github.com> Date: Sat, 5 Oct 2024 10:10:04 +0100 Subject: [PATCH] refactor: align before/afterEach function design --- src/dsl/verifier/proxy/hooks.ts | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/dsl/verifier/proxy/hooks.ts b/src/dsl/verifier/proxy/hooks.ts index dd4a1024c..18bd60a3f 100644 --- a/src/dsl/verifier/proxy/hooks.ts +++ b/src/dsl/verifier/proxy/hooks.ts @@ -8,21 +8,21 @@ export const registerBeforeHook = ( config: ProxyOptions, stateSetupPath: string ): void => { + logger.trace("registered 'beforeEach' hook"); app.use(async (req, res, next) => { - if (config.beforeEach !== undefined) { - logger.trace("registered 'beforeEach' hook"); - if (req.path === stateSetupPath) { - logger.debug("executing 'beforeEach' hook"); - try { - await config.beforeEach(); - } catch (e) { - logger.error(`error executing 'beforeEach' hook: ${e.message}`); - logger.debug(`Stack trace was: ${e.stack}`); - next(new Error(`error executing 'beforeEach' hook: ${e.message}`)); - } + if (req.path === stateSetupPath && config.beforeEach) { + logger.debug("executing 'beforeEach' hook"); + try { + await config.beforeEach(); + next(); + } catch (e) { + logger.error(`error executing 'beforeEach' hook: ${e.message}`); + logger.debug(`Stack trace was: ${e.stack}`); + next(new Error(`error executing 'beforeEach' hook: ${e.message}`)); } + } else { + next(); } - next(); }); };