Skip to content

Commit bf86665

Browse files
authored
refactor: add logs to debug (#109)
Signed-off-by: Sarthak Shyngle <50234097+Sarthak160@users.noreply.github.com>
1 parent c8fd07a commit bf86665

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

v2/dedup/middleware.ts

+14-4
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,23 @@ import { Request, Response, NextFunction } from "express";
33
const fs = require('fs');
44
const yaml = require('js-yaml');
55

6+
const filePath = 'dedupData.yaml';
7+
68

79
// middleware
810
export default function middleware(
911

1012
): (req: Request, res: Response, next: NextFunction) => void {
1113
// console.log("Inside middleware...");
14+
15+
// @ts-ignore
16+
fs.access(filePath, fs.constants.F_OK, (err) => {
17+
console.log(err ? 'File does not exist' : 'File exists');
18+
if (err) {
19+
// Create the file if it doesn't exist
20+
fs.writeFileSync(filePath, '', 'utf-8');
21+
}
22+
});
1223
return (req: Request, res: Response, next: NextFunction) => {
1324
res.on("finish", () => {
1425

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

36-
const filePath = 'dedupData.yaml';
3747

3848
let existingData = [];
3949

@@ -42,7 +52,7 @@ export function afterMiddleware(req: Request, res: Response) {
4252
existingData = yaml.load(fileContent) || [];
4353
} catch (error) {
4454
// Handle the case where the file doesn't exist or is not valid YAML
45-
// console.error("Error reading existing file:", error);
55+
console.error("Error reading existing file:", error);
4656
}
4757

4858

@@ -66,7 +76,7 @@ export function afterMiddleware(req: Request, res: Response) {
6676
let count = 0;
6777
const executedLinebyEachTest = new Array();
6878
function GetCoverage() {
69-
// console.log("Inside GetCoverage");
79+
console.log("Inside GetCoverage");
7080
count++;
7181
let executedLinesByFile = {};
7282
// iterate over global.__coverage__
@@ -109,7 +119,7 @@ function GetCoverage() {
109119
// @ts-ignore
110120
executedLinebyEachTest.push({ ...hitCounts });
111121

112-
// console.log("Executed lines by file:", executedLinesByFile);
122+
console.log("Executed lines by file:", executedLinesByFile);
113123
// extract s from the coverage data
114124
}
115125
return executedLinesByFile;

0 commit comments

Comments
 (0)