From 523e270ffa14564deb140fc6dbd0317f04191039 Mon Sep 17 00:00:00 2001 From: G0maa Date: Sat, 18 Mar 2023 10:35:32 +0200 Subject: [PATCH] fix: record even on test mode - Solves https://github.com/keploy/keploy/issues/430 - Methodology: Treat as MODE_OFF in middleware and afterMiddleware functions Signed-off-by: G0maa --- integrations/express/middleware.ts | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/integrations/express/middleware.ts b/integrations/express/middleware.ts index 70eb2be..3f085c1 100644 --- a/integrations/express/middleware.ts +++ b/integrations/express/middleware.ts @@ -94,6 +94,14 @@ export default function middleware( return; } + // Test mode but user is the one who sent the request, not Keploy client + // treat as OFF for this particular request + if (keploy.mode.GetMode() == MODE_TEST) { + createExecutionContext({ mode: MODE_OFF }); + next(); + return; + } + // record mode createExecutionContext({ mode: MODE_RECORD, deps: [], mocks: [] }); captureResp(req, res, next); @@ -151,6 +159,10 @@ export function afterMiddleware(keploy: Keploy, req: Request, res: Response) { return; } + // Test mode but user is the one who sent the request, not Keploy client. + // What's after this condition is related to Record mode. + if (keploy.mode.GetMode() == MODE_TEST) return; + // req.headers // Since, JSON.stingify trims spaces. Therefore, content-length of request header should be updated req.headers["content-length"] = JSON.stringify(