diff --git a/integrations/express/middleware.ts b/integrations/express/middleware.ts index 55cf762..7f7cdbc 100644 --- a/integrations/express/middleware.ts +++ b/integrations/express/middleware.ts @@ -4,6 +4,7 @@ import Keploy, { HTTP } from "../../src/keploy"; import { Request, Response, NextFunction } from "express"; import { createExecutionContext, getExecutionContext } from "../../src/context"; import { StrArr } from "../../proto/services/StrArr"; +import { MODE_TEST, MODE_RECORD, MODE_OFF } from "../../src/mode"; class ResponseBody { static responseMap = new WeakMap(); @@ -72,10 +73,10 @@ export default function middleware( }); if ( (process.env.KEPLOY_MODE != undefined && - process.env.KEPLOY_MODE == "off") || + process.env.KEPLOY_MODE == MODE_OFF) || keploy == undefined ) { - createExecutionContext({ mode: "off" }); + createExecutionContext({ mode: MODE_OFF }); next(); return; } @@ -84,7 +85,7 @@ export default function middleware( // test mode if (id != undefined && id != "") { createExecutionContext({ - mode: "test", + mode: MODE_TEST, testId: id, deps: keploy.getDependencies(id), mocks: keploy.getMocks(id), @@ -94,7 +95,7 @@ export default function middleware( } // record mode - createExecutionContext({ mode: "record", deps: [], mocks: [] }); + createExecutionContext({ mode: MODE_RECORD, deps: [], mocks: [] }); captureResp(req, res, next); }; } @@ -118,7 +119,7 @@ function captureResp( export function afterMiddleware(keploy: Keploy, req: Request, res: Response) { if ( (process.env.KEPLOY_MODE != undefined && - process.env.KEPLOY_MODE == "off") || + process.env.KEPLOY_MODE == MODE_OFF) || keploy == undefined ) { return; @@ -140,7 +141,7 @@ export function afterMiddleware(keploy: Keploy, req: Request, res: Response) { } //to avoid recording tests in the test mode and only recording in the record mode - if (process.env.KEPLOY_MODE == "test" && id === undefined) { + if (process.env.KEPLOY_MODE == MODE_TEST && id === undefined) { return; }