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 sdk records test case in record mode #63

Open
wants to merge 5 commits 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
19 changes: 16 additions & 3 deletions integrations/express/middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
getExecutionContext,
} from "../../src/context";
import { StrArr } from "../../proto/services/StrArr";
import { MODE_OFF, MODE_RECORD, MODE_TEST } from "../../src/mode";
import { MODE_TEST, MODE_RECORD, MODE_OFF } from "../../src/mode";

class ResponseBody {
static responseMap = new WeakMap<Request, ResponseBody>();
Expand Down Expand Up @@ -75,7 +75,11 @@ export default function middleware(
res.on("finish", () => {
afterMiddleware(keploy, req, res);
});
if (keploy.mode.GetMode() == MODE_OFF) {
if (
(process.env.KEPLOY_MODE != undefined &&
keploy.mode.GetMode() == MODE_OFF) ||
keploy == undefined
) {
createExecutionContext({ mode: MODE_OFF });
next();
return;
Expand Down Expand Up @@ -131,7 +135,11 @@ function captureResp(
}

export function afterMiddleware(keploy: Keploy, req: Request, res: Response) {
if (keploy.mode.GetMode() == MODE_OFF) {
if (
(process.env.KEPLOY_MODE != undefined &&
keploy.mode.GetMode() == MODE_OFF) ||
keploy == undefined
) {
return;
}

Expand All @@ -151,6 +159,11 @@ export function afterMiddleware(keploy: Keploy, req: Request, res: Response) {
return;
}

//to avoid recording tests in the test mode and only recording in the record mode
if (keploy.mode.GetMode() == MODE_OFF && id === undefined) {
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