From 03bae50cbaa3c32d1dc97fc75d726a9cfa318223 Mon Sep 17 00:00:00 2001 From: Sarthak Shyngle <50234097+Sarthak160@users.noreply.github.com> Date: Wed, 15 May 2024 17:32:41 +0530 Subject: [PATCH] feat: expose middleware for dist usage (#113) * chore: add debug for wednesday Signed-off-by: Sarthak Shyngle <50234097+Sarthak160@users.noreply.github.com> * chore: add debug for wednesday Signed-off-by: Sarthak Shyngle <50234097+Sarthak160@users.noreply.github.com> * chore: add khook in register Signed-off-by: Sarthak Shyngle <50234097+Sarthak160@users.noreply.github.com> * chore: add khook in register Signed-off-by: Sarthak Shyngle <50234097+Sarthak160@users.noreply.github.com> * chore: add khook in register Signed-off-by: Sarthak Shyngle <50234097+Sarthak160@users.noreply.github.com> * chore: add khook in register Signed-off-by: Sarthak Shyngle <50234097+Sarthak160@users.noreply.github.com> * chore: add khook in register Signed-off-by: Sarthak Shyngle <50234097+Sarthak160@users.noreply.github.com> * refactor: add support for normal middleware Signed-off-by: Sarthak Shyngle <50234097+Sarthak160@users.noreply.github.com> --------- Signed-off-by: Sarthak Shyngle <50234097+Sarthak160@users.noreply.github.com> --- v2/dedup/middleware.ts | 6 ++++-- v2/dedup/register.ts | 9 +++++---- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/v2/dedup/middleware.ts b/v2/dedup/middleware.ts index f36126b..e9ab2e4 100644 --- a/v2/dedup/middleware.ts +++ b/v2/dedup/middleware.ts @@ -80,7 +80,7 @@ export function afterMiddleware(req: Request, res: Response) { let count = 0; const executedLinebyEachTest = new Array(); function GetCoverage() { - console.log("Inside GetCoverage"); + console.log("Calculating per request coverage..."); count++; let executedLinesByFile = {}; // iterate over global.__coverage__ @@ -123,8 +123,10 @@ function GetCoverage() { // @ts-ignore executedLinebyEachTest.push({ ...hitCounts }); - console.log("Executed lines by file:", executedLinesByFile); + // console.log("Executed lines by file:", executedLinesByFile); // extract s from the coverage data } return executedLinesByFile; } + +module.exports = middleware; \ No newline at end of file diff --git a/v2/dedup/register.ts b/v2/dedup/register.ts index f93aa38..d00427a 100644 --- a/v2/dedup/register.ts +++ b/v2/dedup/register.ts @@ -3,11 +3,12 @@ import Hook from "require-in-the-middle"; import expressMiddleware from "./middleware"; import bodyParser from "body-parser"; import cors from "cors"; -// import mixin from "merge-descriptors"; -const _ = require('lodash'); +const _ = require('lodash'); +const khook = "keployWrappedExpress"; // @ts-ignore Hook(["express"], function (exports) { + // console.log("Inside keploy hook..."); const expressApp = exports; function keployWrappedExpress() { const keployApp = expressApp(); @@ -18,7 +19,7 @@ Hook(["express"], function (exports) { keployApp.appliedMiddleware = true; return keployApp; } - + // copy the properties and methods of exported Function object into wrapped Funtion(keployWrappedExpress). // In order to prevent "express._Method_ or express._Field_ is not declared" error. // mixin(keployWrappedExpress, expressApp, false); @@ -26,4 +27,4 @@ Hook(["express"], function (exports) { exports = keployWrappedExpress; return exports; }); -export { }; +export { khook };