| 1 |
// spell-checker:ignore hljs |
| 2 |
function progressBar(totals) { |
| 3 |
const bar = document.createElement("div"); |
| 4 |
bar.className = "progress-bar"; |
| 5 |
let totalTests = 0; |
| 6 |
for (const [key, value] of Object.entries(totals)) { |
| 7 |
totalTests += value; |
| 8 |
} |
| 9 |
const passPercentage = Math.round(100 * totals["PASS"] / totalTests); |
| 10 |
const skipPercentage = passPercentage + Math.round(100 * totals["SKIP"] / totalTests); |
| 11 |
|
| 12 |
// The ternary expressions are used for some edge-cases where there are no failing test, |
| 13 |
// but still a red (or beige) line shows up because of how CSS draws gradients. |
| 14 |
bar.style = `background: linear-gradient( |
| 15 |
to right, |
| 16 |
var(--PASS) ${passPercentage}%` |
| 17 |
+ ( passPercentage === 100 ? ", var(--PASS)" : |
| 18 |
`, var(--SKIP) ${passPercentage}%, |
| 19 |
var(--SKIP) ${skipPercentage}%` |
| 20 |
) |
| 21 |
+ (skipPercentage === 100 ? ")" : ", var(--FAIL) 0)"); |
| 22 |
|
| 23 |
const progress = document.createElement("div"); |
| 24 |
progress.className = "progress" |
| 25 |
progress.innerHTML = ` |
| 26 |
<span class="counts"> |
| 27 |
<span class="PASS">${totals["PASS"]}</span> |
| 28 |
/ |
| 29 |
<span class="SKIP">${totals["SKIP"]}</span> |
| 30 |
/ |
| 31 |
<span class="FAIL">${totals["FAIL"] + totals["ERROR"]}</span> |
| 32 |
</span> |
| 33 |
`; |
| 34 |
progress.appendChild(bar); |
| 35 |
return progress |
| 36 |
} |
| 37 |
|
| 38 |
function parse_result(parent, obj) { |
| 39 |
const totals = { |
| 40 |
PASS: 0, |
| 41 |
SKIP: 0, |
| 42 |
FAIL: 0, |
| 43 |
ERROR: 0, |
| 44 |
}; |
| 45 |
for (const [category, content] of Object.entries(obj)) { |
| 46 |
if (typeof content === "string") { |
| 47 |
const p = document.createElement("p"); |
| 48 |
p.className = "result-line"; |
| 49 |
totals[content]++; |
| 50 |
p.innerHTML = `<span class="result" style="color: var(--${content})">${content}</span> ${category}`; |
| 51 |
parent.appendChild(p); |
| 52 |
} else { |
| 53 |
const categoryName = document.createElement("code"); |
| 54 |
categoryName.innerHTML = category; |
| 55 |
categoryName.className = "hljs"; |
| 56 |
|
| 57 |
const details = document.createElement("details"); |
| 58 |
const subtotals = parse_result(details, content); |
| 59 |
for (const [subtotal, count] of Object.entries(subtotals)) { |
| 60 |
totals[subtotal] += count; |
| 61 |
} |
| 62 |
const summaryDiv = document.createElement("div"); |
| 63 |
summaryDiv.className = "testSummary"; |
| 64 |
summaryDiv.appendChild(categoryName); |
| 65 |
summaryDiv.appendChild(progressBar(subtotals)); |
| 66 |
|
| 67 |
const summary = document.createElement("summary"); |
| 68 |
summary.appendChild(summaryDiv); |
| 69 |
|
| 70 |
details.appendChild(summary); |
| 71 |
parent.appendChild(details); |
| 72 |
} |
| 73 |
} |
| 74 |
return totals; |
| 75 |
} |
| 76 |
|
| 77 |
fetch("https://raw.githubusercontent.com/uutils/coreutils-tracking/main/aggregated-result.json") |
| 78 |
.then((r) => r.json()) |
| 79 |
.then((obj) => { |
| 80 |
let parent = document.getElementById("test-cov"); |
| 81 |
parse_result(parent, obj); |
| 82 |
}); |