Skip to content

Commit 437fa80

Browse files
committed
fix compliance check errors 2
1 parent 142ce63 commit 437fa80

1 file changed

Lines changed: 14 additions & 2 deletions

File tree

scripts/unit-coverage.mjs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,13 @@ function normalizeCoveragePath(filePath) {
6565
.trim();
6666
}
6767

68+
/**
69+
* Remove ANSI escape sequences so coverage parsing is stable across terminals/CI.
70+
*/
71+
function stripAnsi(text) {
72+
return text.replace(/\u001b\[[0-9;]*m/g, "");
73+
}
74+
6875
/**
6976
* Resolve a tracked/advisory file to a parsed coverage metric.
7077
* Some Node versions emit absolute paths while others emit project-relative paths.
@@ -88,8 +95,13 @@ function resolveMetricForFile(metricsByFile, filePath) {
8895
}
8996

9097
const metricsByFile = new Map();
91-
for (const line of nodeResult.stdout.split("\n")) {
92-
const normalizedLine = line.replace(/^[#]\s*/, "").trim();
98+
/**
99+
* Parse coverage from combined stdout/stderr because some Node reporter setups
100+
* emit diagnostics to stderr in CI while using stdout locally.
101+
*/
102+
const rawCoverageOutput = `${nodeResult.stdout ?? ""}\n${nodeResult.stderr ?? ""}`;
103+
for (const line of stripAnsi(rawCoverageOutput).split("\n")) {
104+
const normalizedLine = line.replace(/^[#>\s]+/, "").trim();
93105
if (!normalizedLine) continue;
94106
if (normalizedLine.includes("start of coverage report")) continue;
95107
if (normalizedLine.includes("end of coverage report")) continue;

0 commit comments

Comments
 (0)