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;