Skip to content
This repository was archived by the owner on May 13, 2026. It is now read-only.
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,27 @@ import fs from 'fs';
const COVERAGE_FILE = './coverage/coverage-summary.json';
const MIN_COVERAGE = 80;

interface CoverageMetric {
total: number;
covered: number;
skipped: number;
pct: number;
}

interface FileCoverage {
lines: CoverageMetric;
functions: CoverageMetric;
statements: CoverageMetric;
branches: CoverageMetric;
}

interface CoverageSummary {
total: FileCoverage;
[filePath: string]: FileCoverage;
}

type MetricKey = keyof FileCoverage;

// Color codes for console output
const colors = {
red: '\x1b[31m',
Expand All @@ -20,50 +41,51 @@ const colors = {
bold: '\x1b[1m'
};

function log(message, color = colors.reset) {
function log(message: string, color: string = colors.reset): void {
console.log(`${color}${message}${colors.reset}`);
}

function checkCoverageFile() {
function checkCoverageFile(): void {
if (!fs.existsSync(COVERAGE_FILE)) {
log(`❌ Coverage file not found: ${COVERAGE_FILE}`, colors.red);
log('Run "npm run test:coverage:threshold" first to generate coverage data.', colors.yellow);
process.exit(1);
}
}

function readCoverageData() {
function readCoverageData(): CoverageSummary {
try {
const coverageData = JSON.parse(fs.readFileSync(COVERAGE_FILE, 'utf8'));
const coverageData = JSON.parse(fs.readFileSync(COVERAGE_FILE, 'utf8')) as CoverageSummary;
return coverageData;
} catch (error) {
log(`❌ Error reading coverage file: ${error.message}`, colors.red);
const message = error instanceof Error ? error.message : String(error);
log(`❌ Error reading coverage file: ${message}`, colors.red);
process.exit(1);
}
}

function formatPercentage(value) {
function formatPercentage(value: number): string {
return `${value.toFixed(2)}%`;
}

function checkThreshold(actual, threshold, name) {
function checkThreshold(actual: number, threshold: number, name: string): boolean {
const status = actual >= threshold;
const symbol = status ? '✅' : '❌';
const color = status ? colors.green : colors.red;

log(`${symbol} ${name}: ${formatPercentage(actual)} (min: ${formatPercentage(threshold)})`, color);
return status;
}

function analyzeCoverage(coverageData) {
function analyzeCoverage(coverageData: CoverageSummary): boolean {
log(`\n${colors.bold}📊 Coverage Analysis${colors.reset}`);
log('═'.repeat(50));

const total = coverageData.total;
const metrics = ['lines', 'functions', 'statements', 'branches'];
const metrics: MetricKey[] = ['lines', 'functions', 'statements', 'branches'];

let allPassed = true;

// Check global coverage
log(`\n${colors.blue}Global Coverage:${colors.reset}`);
for (const metric of metrics) {
Expand All @@ -73,11 +95,11 @@ function analyzeCoverage(coverageData) {
}

// Detailed file-by-file analysis if any files are below threshold
const problematicFiles = [];
const problematicFiles: Array<{ path: string; data: FileCoverage }> = [];

for (const [filePath, fileData] of Object.entries(coverageData)) {
if (filePath === 'total') continue;

const hasLowCoverage = metrics.some(metric => fileData[metric].pct < MIN_COVERAGE);
if (hasLowCoverage) {
problematicFiles.push({ path: filePath, data: fileData });
Expand All @@ -87,7 +109,7 @@ function analyzeCoverage(coverageData) {
if (problematicFiles.length > 0) {
log(`\n${colors.yellow}Files Below Threshold:${colors.reset}`);
log('-'.repeat(50));

for (const file of problematicFiles) {
log(`\n📄 ${file.path}`, colors.yellow);
for (const metric of metrics) {
Expand All @@ -102,15 +124,15 @@ function analyzeCoverage(coverageData) {
// Coverage summary
log(`\n${colors.bold}Summary:${colors.reset}`);
log('═'.repeat(50));

const totalFiles = Object.keys(coverageData).length - 1; // Exclude 'total'
const filesBelowThreshold = problematicFiles.length;
const filesPassingThreshold = totalFiles - filesBelowThreshold;

log(`📁 Total files: ${totalFiles}`);
log(`✅ Files passing (≥${MIN_COVERAGE}%): ${filesPassingThreshold}`, colors.green);
log(`❌ Files below threshold: ${filesBelowThreshold}`, filesBelowThreshold > 0 ? colors.red : colors.green);

// Overall result
if (allPassed) {
log(`\n🎉 All coverage thresholds met! Minimum ${MIN_COVERAGE}% achieved.`, colors.green);
Expand All @@ -126,7 +148,7 @@ function analyzeCoverage(coverageData) {
}
}

function main() {
function main(): void {
log(`${colors.bold}🧪 Coverage Threshold Checker${colors.reset}`);
log(`Minimum required coverage: ${MIN_COVERAGE}%\n`);

Expand All @@ -137,4 +159,4 @@ function main() {
process.exit(passed ? 0 : 1);
}

main();
main();
2 changes: 1 addition & 1 deletion src/server/static-react/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,6 @@
"@generated/*": ["../../../bindings/src/fold_node/static-react/src/types/*"]
}
},
"include": ["src/**/*.ts", "src/**/*.tsx"],
"include": ["src/**/*.ts", "src/**/*.tsx", "scripts/**/*.ts"],
"exclude": ["node_modules", "dist", "src/types/openapi.ts"]
}
Loading