Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: add logs to debug #109

Merged
merged 1 commit into from
May 13, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading