From bf86665d11caca129bef0be16ee779cdc7fa3283 Mon Sep 17 00:00:00 2001 From: Sarthak Shyngle <50234097+Sarthak160@users.noreply.github.com> Date: Mon, 13 May 2024 09:52:24 +0530 Subject: [PATCH 1/2] refactor: add logs to debug (#109) 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 37c90a3c94d666e6b68c5a2b1d34d46631a61cf2 Mon Sep 17 00:00:00 2001 From: Sarthak Shyngle <50234097+Sarthak160@users.noreply.github.com> Date: Mon, 13 May 2024 13:20:54 +0530 Subject: [PATCH 2/2] fix: req per coverage for docker (#110) * refactor: add logs to debug Signed-off-by: Sarthak Shyngle <50234097+Sarthak160@users.noreply.github.com> * refactor: add list check Signed-off-by: Sarthak Shyngle <50234097+Sarthak160@users.noreply.github.com> * refactor: add log Signed-off-by: Sarthak Shyngle <50234097+Sarthak160@users.noreply.github.com> * fix: req per coverage for docker 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 | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/v2/dedup/middleware.ts b/v2/dedup/middleware.ts index 6058a00..1d09feb 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'); @@ -14,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'); + if (err) { // Create the file if it doesn't exist fs.writeFileSync(filePath, '', 'utf-8'); @@ -56,6 +57,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);