(rootPath)
| 97 | } |
| 98 | |
| 99 | export async function analyzeCoverageArtifacts(rootPath) { |
| 100 | const checks = []; |
| 101 | const metrics = []; |
| 102 | const artifacts = []; |
| 103 | const coverageFiles = await findCoverageFiles(rootPath); |
| 104 | |
| 105 | metrics.push( |
| 106 | createMetric({ |
| 107 | id: "coverage_artifact_count", |
| 108 | category: "coverage", |
| 109 | value: coverageFiles.length, |
| 110 | unit: "files", |
| 111 | band: coverageFiles.length > 0 ? "good" : "info", |
| 112 | }), |
| 113 | ); |
| 114 | |
| 115 | if (coverageFiles.length === 0) { |
| 116 | checks.push( |
| 117 | createCheck({ |
| 118 | id: "coverage-artifacts-unavailable", |
| 119 | category: "coverage", |
| 120 | severity: "info", |
| 121 | status: "info", |
| 122 | message: "No coverage artifacts were found for this target.", |
| 123 | evidence: [relativePath(process.cwd(), rootPath)], |
| 124 | remediation: ["Generate `lcov.info`, `coverage.xml`, or an Istanbul coverage JSON file if you want coverage scoring."], |
| 125 | }), |
| 126 | ); |
| 127 | return { checks, metrics, artifacts }; |
| 128 | } |
| 129 | |
| 130 | const fileSummaries = []; |
| 131 | for (const filePath of coverageFiles) { |
| 132 | const coverage = await parseCoverageFile(filePath); |
| 133 | if (coverage != null) { |
| 134 | fileSummaries.push({ |
| 135 | path: relativePath(rootPath, filePath), |
| 136 | coverage, |
| 137 | }); |
| 138 | } |
| 139 | } |
| 140 | |
| 141 | if (fileSummaries.length > 0) { |
| 142 | const bestCoverage = Math.max(...fileSummaries.map((item) => item.coverage)); |
| 143 | metrics.push( |
| 144 | createMetric({ |
| 145 | id: "coverage_percent", |
| 146 | category: "coverage", |
| 147 | value: bestCoverage, |
| 148 | unit: "percent", |
| 149 | band: bestCoverage >= 85 ? "good" : bestCoverage >= 70 ? "moderate" : "heavy", |
| 150 | }), |
| 151 | ); |
| 152 | if (bestCoverage < 70) { |
| 153 | checks.push( |
| 154 | createCheck({ |
| 155 | id: "coverage-low", |
| 156 | category: "coverage", |
no test coverage detected