@@ -3,12 +3,23 @@ import { Request, Response, NextFunction } from "express";
3
3
const fs = require ( 'fs' ) ;
4
4
const yaml = require ( 'js-yaml' ) ;
5
5
6
+ const filePath = 'dedupData.yaml' ;
7
+
6
8
7
9
// middleware
8
10
export default function middleware (
9
11
10
12
) : ( req : Request , res : Response , next : NextFunction ) => void {
11
13
// 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
+ } ) ;
12
23
return ( req : Request , res : Response , next : NextFunction ) => {
13
24
res . on ( "finish" , ( ) => {
14
25
@@ -33,7 +44,6 @@ export function afterMiddleware(req: Request, res: Response) {
33
44
executedLinesByFile : executedLinesByFile
34
45
} ;
35
46
36
- const filePath = 'dedupData.yaml' ;
37
47
38
48
let existingData = [ ] ;
39
49
@@ -42,7 +52,7 @@ export function afterMiddleware(req: Request, res: Response) {
42
52
existingData = yaml . load ( fileContent ) || [ ] ;
43
53
} catch ( error ) {
44
54
// 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 ) ;
46
56
}
47
57
48
58
@@ -66,7 +76,7 @@ export function afterMiddleware(req: Request, res: Response) {
66
76
let count = 0 ;
67
77
const executedLinebyEachTest = new Array ( ) ;
68
78
function GetCoverage ( ) {
69
- // console.log("Inside GetCoverage");
79
+ console . log ( "Inside GetCoverage" ) ;
70
80
count ++ ;
71
81
let executedLinesByFile = { } ;
72
82
// iterate over global.__coverage__
@@ -109,7 +119,7 @@ function GetCoverage() {
109
119
// @ts -ignore
110
120
executedLinebyEachTest . push ( { ...hitCounts } ) ;
111
121
112
- // console.log("Executed lines by file:", executedLinesByFile);
122
+ console . log ( "Executed lines by file:" , executedLinesByFile ) ;
113
123
// extract s from the coverage data
114
124
}
115
125
return executedLinesByFile ;
0 commit comments