From 9a1b89955a5ff021eb6c945b4972a9c3225a7727 Mon Sep 17 00:00:00 2001 From: Sarthak Shyngle <50234097+Sarthak160@users.noreply.github.com> Date: Mon, 13 May 2024 09:26:05 +0530 Subject: [PATCH 1/4] refactor: add logs to debug Signed-off-by: Sarthak Shyngle <50234097+Sarthak160@users.noreply.github.com> --- v2/dedup/middleware.ts | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/v2/dedup/middleware.ts b/v2/dedup/middleware.ts index 754fdba..6058a00 100644 --- a/v2/dedup/middleware.ts +++ b/v2/dedup/middleware.ts @@ -3,12 +3,23 @@ import { Request, Response, NextFunction } from "express"; const fs = require('fs'); const yaml = require('js-yaml'); +const filePath = 'dedupData.yaml'; + // middleware export default function middleware( ): (req: Request, res: Response, next: NextFunction) => void { // console.log("Inside middleware..."); + + // @ts-ignore + fs.access(filePath, fs.constants.F_OK, (err) => { + console.log(err ? 'File does not exist' : 'File exists'); + if (err) { + // Create the file if it doesn't exist + fs.writeFileSync(filePath, '', 'utf-8'); + } + }); return (req: Request, res: Response, next: NextFunction) => { res.on("finish", () => { @@ -33,7 +44,6 @@ export function afterMiddleware(req: Request, res: Response) { executedLinesByFile: executedLinesByFile }; - const filePath = 'dedupData.yaml'; let existingData = []; @@ -42,7 +52,7 @@ export function afterMiddleware(req: Request, res: Response) { existingData = yaml.load(fileContent) || []; } catch (error) { // Handle the case where the file doesn't exist or is not valid YAML - // console.error("Error reading existing file:", error); + console.error("Error reading existing file:", error); } @@ -66,7 +76,7 @@ export function afterMiddleware(req: Request, res: Response) { let count = 0; const executedLinebyEachTest = new Array(); function GetCoverage() { - // console.log("Inside GetCoverage"); + console.log("Inside GetCoverage"); count++; let executedLinesByFile = {}; // iterate over global.__coverage__ @@ -109,7 +119,7 @@ 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; From 09bff4cb9a27a5e2e73e9f92780b2b64beed1eb0 Mon Sep 17 00:00:00 2001 From: Sarthak Shyngle <50234097+Sarthak160@users.noreply.github.com> Date: Mon, 13 May 2024 10:13:20 +0530 Subject: [PATCH 2/4] refactor: add list check Signed-off-by: Sarthak Shyngle <50234097+Sarthak160@users.noreply.github.com> --- v2/dedup/middleware.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/v2/dedup/middleware.ts b/v2/dedup/middleware.ts index 6058a00..5fb4278 100644 --- a/v2/dedup/middleware.ts +++ b/v2/dedup/middleware.ts @@ -56,7 +56,10 @@ export function afterMiddleware(req: Request, res: Response) { } - + if (!Array.isArray(existingData)) { + console.error('Expected an array for existingData, but got:', typeof existingData); + existingData = []; // Reset to an empty array or handle accordingly + } // Add or update the entry for the current id existingData.push(currentData); From 11f9806a56894d81070f5c17f7c22d9f474b9d1c Mon Sep 17 00:00:00 2001 From: Sarthak Shyngle <50234097+Sarthak160@users.noreply.github.com> Date: Mon, 13 May 2024 11:50:34 +0530 Subject: [PATCH 3/4] refactor: add log Signed-off-by: Sarthak Shyngle <50234097+Sarthak160@users.noreply.github.com> --- v2/dedup/middleware.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/v2/dedup/middleware.ts b/v2/dedup/middleware.ts index 5fb4278..02ab3d1 100644 --- a/v2/dedup/middleware.ts +++ b/v2/dedup/middleware.ts @@ -1,4 +1,5 @@ /* eslint-disable @typescript-eslint/no-explicit-any */ +import { log } from "console"; import { Request, Response, NextFunction } from "express"; const fs = require('fs'); const yaml = require('js-yaml'); @@ -60,6 +61,8 @@ export function afterMiddleware(req: Request, res: Response) { console.error('Expected an array for existingData, but got:', typeof existingData); existingData = []; // Reset to an empty array or handle accordingly } + console.log("CURRENT DATA", currentData); + // Add or update the entry for the current id existingData.push(currentData); From 906c03d69aa96be588350f10cd920f005e70e7b6 Mon Sep 17 00:00:00 2001 From: Sarthak Shyngle <50234097+Sarthak160@users.noreply.github.com> Date: Mon, 13 May 2024 13:18:15 +0530 Subject: [PATCH 4/4] fix: req per coverage for docker Signed-off-by: Sarthak Shyngle <50234097+Sarthak160@users.noreply.github.com> --- v2/dedup/middleware.ts | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/v2/dedup/middleware.ts b/v2/dedup/middleware.ts index 02ab3d1..8d40d1f 100644 --- a/v2/dedup/middleware.ts +++ b/v2/dedup/middleware.ts @@ -15,7 +15,7 @@ export default function middleware( // @ts-ignore fs.access(filePath, fs.constants.F_OK, (err) => { - console.log(err ? 'File does not exist' : 'File exists'); + // console.log(err ? 'File does not exist' : 'File exists'); if (err) { // Create the file if it doesn't exist fs.writeFileSync(filePath, '', 'utf-8'); @@ -61,7 +61,6 @@ export function afterMiddleware(req: Request, res: Response) { console.error('Expected an array for existingData, but got:', typeof existingData); existingData = []; // Reset to an empty array or handle accordingly } - console.log("CURRENT DATA", currentData); // Add or update the entry for the current id existingData.push(currentData); @@ -82,7 +81,7 @@ export function afterMiddleware(req: Request, res: Response) { let count = 0; const executedLinebyEachTest = new Array(); function GetCoverage() { - console.log("Inside GetCoverage"); + // console.log("Inside GetCoverage"); count++; let executedLinesByFile = {}; // iterate over global.__coverage__ @@ -125,7 +124,7 @@ 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;