Skip to content

Commit

Permalink
feat: expose middleware for dist usage (#113)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
Sarthak160 authored May 15, 2024
1 parent 40f10a0 commit 03bae50
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
6 changes: 4 additions & 2 deletions v2/dedup/middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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__
Expand Down Expand Up @@ -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;
9 changes: 5 additions & 4 deletions v2/dedup/register.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -18,12 +19,12 @@ 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);
_.assign(keployWrappedExpress, expressApp);
exports = keployWrappedExpress;
return exports;
});
export { };
export { khook };

0 comments on commit 03bae50

Please sign in to comment.