Skip to content

Commit

Permalink
refactor: add logs to debug (#109)
Browse files Browse the repository at this point in the history
Signed-off-by: Sarthak Shyngle <[email protected]>
  • Loading branch information
Sarthak160 authored May 13, 2024
1 parent c8fd07a commit bf86665
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions v2/dedup/middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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", () => {

Expand All @@ -33,7 +44,6 @@ export function afterMiddleware(req: Request, res: Response) {
executedLinesByFile: executedLinesByFile
};

const filePath = 'dedupData.yaml';

let existingData = [];

Expand All @@ -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);
}


Expand All @@ -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__
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit bf86665

Please sign in to comment.