@@ -3,12 +3,23 @@ import { Request, Response, NextFunction } from "express";
33const fs = require ( 'fs' ) ;
44const yaml = require ( 'js-yaml' ) ;
55
6+ const filePath = 'dedupData.yaml' ;
7+
68
79// middleware
810export 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) {
6676let count = 0 ;
6777const executedLinebyEachTest = new Array ( ) ;
6878function 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