Skip to content

Commit 8c7cef6

Browse files
committed
fix: support async afterEach hook
Currently a asynchronous afterEach hook will execute concurrently with the underlying express request lifecycle. This fix allows async hooks to complete before allowing the express request to continue through its middleware stack. Fixes #1241
1 parent 1a3815e commit 8c7cef6

File tree

1 file changed

+10
-12
lines changed

1 file changed

+10
-12
lines changed

src/dsl/verifier/proxy/hooks.ts

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -31,19 +31,17 @@ export const registerAfterHook = (
3131
config: ProxyOptions,
3232
stateSetupPath: string
3333
): void => {
34+
logger.trace("registered 'afterEach' hook");
3435
app.use(async (req, res, next) => {
35-
if (config.afterEach !== undefined) {
36-
logger.trace("registered 'afterEach' hook");
37-
next();
38-
if (req.path !== stateSetupPath) {
39-
logger.debug("executing 'afterEach' hook");
40-
try {
41-
await config.afterEach();
42-
} catch (e) {
43-
logger.error(`error executing 'afterEach' hook: ${e.message}`);
44-
logger.debug(`Stack trace was: ${e.stack}`);
45-
next(new Error(`error executing 'afterEach' hook: ${e.message}`));
46-
}
36+
if (req.path !== stateSetupPath && config.afterEach) {
37+
logger.debug("executing 'afterEach' hook");
38+
try {
39+
await config.afterEach();
40+
next();
41+
} catch (e) {
42+
logger.error(`error executing 'afterEach' hook: ${e.message}`);
43+
logger.debug(`Stack trace was: ${e.stack}`);
44+
next(new Error(`error executing 'afterEach' hook: ${e.message}`));
4745
}
4846
} else {
4947
next();

0 commit comments

Comments
 (0)