Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: on the test mode #84

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions integrations/express/middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ export default function middleware(

const id = req.get("KEPLOY_TEST_ID");
// test mode

if (id != undefined && id != "") {
createExecutionContext({
mode: MODE_TEST,
Expand All @@ -94,6 +95,19 @@ export default function middleware(
return;
}

// the user is makiing the request so we made the fun - off , i.e the keploy server is in off mode
const fun = keploy.mode.GetMode();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are correct. we should also set mode in ctx to off.
Can you do the logic expression for if stmt in a single line of code here.

if (fun == MODE_TEST) {
createExecutionContext({ mode: MODE_OFF });
next();
return;
}






// record mode
createExecutionContext({ mode: MODE_RECORD, deps: [], mocks: [] });
captureResp(req, res, next);
Expand Down Expand Up @@ -130,6 +144,9 @@ function captureResp(
return;
}




export function afterMiddleware(keploy: Keploy, req: Request, res: Response) {
if (keploy.mode.GetMode() == MODE_OFF) {
return;
Expand All @@ -151,6 +168,14 @@ export function afterMiddleware(keploy: Keploy, req: Request, res: Response) {
return;
}



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(
Expand Down