Repository navigation
Expand file tree
/
Copy pathcombine-coverage.js
More file actions
executable file
·267 lines (239 loc) · 7.64 KB
/
Copy pathcombine-coverage.js
File metadata and controls
executable file
·267 lines (239 loc) · 7.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
#!/usr/bin/env node
const fs = require("node:fs");
const path = require("node:path");
const { execSync } = require("node:child_process");
// Create directories for reports
const combinedDir = path.join(__dirname, "coverage-combined");
const codecovDir = path.join(__dirname, "coverage");
if (!fs.existsSync(combinedDir)) {
fs.mkdirSync(combinedDir);
}
if (!fs.existsSync(codecovDir)) {
fs.mkdirSync(codecovDir);
}
// Function to check if a file exists
function fileExists(filePath) {
try {
return fs.statSync(filePath).isFile();
} catch (err) {
return false;
}
}
// Function to copy a directory recursively
function copyDir(src, dest) {
if (!fs.existsSync(dest)) {
fs.mkdirSync(dest, { recursive: true });
}
const entries = fs.readdirSync(src, { withFileTypes: true });
for (const entry of entries) {
const srcPath = path.join(src, entry.name);
const destPath = path.join(dest, entry.name);
if (entry.isDirectory()) {
copyDir(srcPath, destPath);
} else {
fs.copyFileSync(srcPath, destPath);
}
}
}
// Check if frontend coverage exists
const frontendCoverageDir = path.join(__dirname, "frontend", "coverage");
const frontendLcovReport = path.join(frontendCoverageDir, "lcov-report");
const frontendLcovInfo = path.join(frontendCoverageDir, "lcov.info");
const frontendCoverageFinal = path.join(frontendCoverageDir, "coverage-final.json");
// Check if backend coverage exists
const backendCoverageFile = path.join(__dirname, "backend", "coverage.out");
const backendCoverageHtml = path.join(__dirname, "backend", "coverage.html");
// Create index.html for the combined report
let indexHtml = `
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>PixelMap.io Combined Coverage Report</title>
<style>
body {
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
line-height: 1.6;
color: #333;
max-width: 1200px;
margin: 0 auto;
padding: 20px;
}
h1, h2 {
color: #2c3e50;
}
.report-container {
display: flex;
flex-wrap: wrap;
gap: 20px;
margin-top: 20px;
}
.report-card {
flex: 1;
min-width: 300px;
border: 1px solid #ddd;
border-radius: 8px;
padding: 20px;
box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}
.report-card h2 {
margin-top: 0;
border-bottom: 1px solid #eee;
padding-bottom: 10px;
}
.btn {
display: inline-block;
background-color: #3498db;
color: white;
padding: 10px 15px;
text-decoration: none;
border-radius: 4px;
font-weight: bold;
margin-top: 15px;
}
.btn:hover {
background-color: #2980b9;
}
.summary {
background-color: #f8f9fa;
border-radius: 8px;
padding: 15px;
margin-bottom: 20px;
}
.codecov-badge {
display: inline-block;
margin-top: 15px;
}
</style>
</head>
<body>
<h1>PixelMap.io Combined Coverage Report</h1>
<div class="summary">
<p>This page provides access to coverage reports for both frontend and backend components of PixelMap.io.</p>
<div class="codecov-badge">
<a href="https://codecov.io/gh/username/pixelmap.io">
<img src="https://codecov.io/gh/username/pixelmap.io/branch/main/graph/badge.svg" alt="Codecov" />
</a>
</div>
</div>
<div class="report-container">
`;
// Process frontend coverage
if (fileExists(frontendLcovInfo) && fs.existsSync(frontendLcovReport)) {
// Copy frontend coverage report to combined directory
const frontendDestDir = path.join(combinedDir, "frontend");
copyDir(frontendLcovReport, frontendDestDir);
// Copy lcov.info to codecov directory
fs.copyFileSync(frontendLcovInfo, path.join(codecovDir, "frontend-lcov.info"));
// Copy coverage-final.json if it exists
if (fileExists(frontendCoverageFinal)) {
fs.copyFileSync(frontendCoverageFinal, path.join(codecovDir, "frontend-coverage.json"));
}
// Add frontend section to index.html
indexHtml += `
<div class="report-card">
<h2>Frontend Coverage</h2>
<p>Coverage report for the Next.js/React frontend application.</p>
<a href="./frontend/index.html" class="btn">View Frontend Coverage</a>
</div>
`;
console.log("✅ Frontend coverage report processed");
} else {
console.log(
"⚠️ Frontend coverage report not found. Run frontend tests with coverage first.",
);
indexHtml += `
<div class="report-card">
<h2>Frontend Coverage</h2>
<p>Frontend coverage report not available. Run frontend tests with coverage first:</p>
<pre>./run-tests.sh -f -c</pre>
</div>
`;
}
// Process backend coverage
if (fileExists(backendCoverageFile)) {
// Create backend coverage directory in combined
const backendDestDir = path.join(combinedDir, "backend");
if (!fs.existsSync(backendDestDir)) {
fs.mkdirSync(backendDestDir, { recursive: true });
}
// Copy backend coverage HTML if it exists, or generate it
if (fileExists(backendCoverageHtml)) {
fs.copyFileSync(
backendCoverageHtml,
path.join(backendDestDir, "index.html"),
);
} else {
try {
// Try to generate HTML from coverage.out
execSync(
`cd backend && go tool cover -html=coverage.out -o ${path.join(backendDestDir, "index.html")}`,
);
console.log("✅ Generated backend coverage HTML from coverage.out");
} catch (error) {
console.error(
"❌ Failed to generate backend coverage HTML:",
error.message,
);
fs.writeFileSync(
path.join(backendDestDir, "index.html"),
"<html><body><h1>Backend Coverage</h1><p>Failed to generate HTML report from coverage.out</p></body></html>",
);
}
}
// Copy Go's native coverage profile for Codecov and generate a readable summary.
try {
fs.copyFileSync(
backendCoverageFile,
path.join(codecovDir, "backend-coverage.out"),
);
execSync(
`cd backend && go tool cover -func=coverage.out > ${path.join(codecovDir, "backend-coverage.txt")}`,
);
console.log("✅ Generated backend coverage reports for Codecov");
} catch (error) {
console.error(
"❌ Failed to generate backend coverage for Codecov:",
error.message,
);
}
// Add backend section to index.html
indexHtml += `
<div class="report-card">
<h2>Backend Coverage</h2>
<p>Coverage report for the Go backend application.</p>
<a href="./backend/index.html" class="btn">View Backend Coverage</a>
</div>
`;
console.log("✅ Backend coverage report processed");
} else {
console.log(
"⚠️ Backend coverage report not found. Run backend tests with coverage first.",
);
indexHtml += `
<div class="report-card">
<h2>Backend Coverage</h2>
<p>Backend coverage report not available. Run backend tests with coverage first:</p>
<pre>./run-tests.sh -b -c</pre>
</div>
`;
}
// Close HTML tags
indexHtml += `
</div>
<div class="summary" style="margin-top: 20px;">
<h2>Codecov Integration</h2>
<p>Coverage reports are also uploaded to Codecov for tracking over time.</p>
<p>View the project on Codecov: <a href="https://codecov.io/gh/username/pixelmap.io">https://codecov.io/gh/username/pixelmap.io</a></p>
</div>
</body>
</html>
`;
// Write the index.html file
fs.writeFileSync(path.join(combinedDir, "index.html"), indexHtml);
console.log(`
✨ Combined coverage report generated at: ${path.join(combinedDir, "index.html")}
✨ Codecov-ready coverage reports generated in: ${codecovDir}
Open the combined report in your browser to view the coverage details.
`);