Skip to content

Commit 7e77546

Browse files
authored
ci: Show percentage diff for Node compat tests (#29310)
This is for internal Slack automation
1 parent be5396e commit 7e77546

File tree

1 file changed

+58
-9
lines changed

1 file changed

+58
-9
lines changed

tests/node_compat/slack.ts

Lines changed: 58 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,27 +18,76 @@ const client = new WebClient(token, {
1818
logLevel: LogLevel.DEBUG,
1919
});
2020

21-
function formatRatio(report: { pass: number; total: number } | undefined) {
21+
function getRatio(report: { pass: number; total: number } | undefined) {
2222
if (!report) {
23+
return -1;
24+
}
25+
26+
return (report.pass / report.total) * 100;
27+
}
28+
29+
function formatRatio(ratio: number) {
30+
if (ratio === -1) {
2331
return "N/A";
2432
}
25-
const ratio = (report.pass / report.total) * 100;
2633
return ratio.toFixed(2) + "%";
2734
}
2835

36+
function formatDiff(diff: number) {
37+
if (diff === 0) {
38+
return `±0% 🟨`;
39+
}
40+
41+
const diffStr = diff.toFixed(2);
42+
43+
if (diff > 0) {
44+
return `+${diffStr}% 🟩`;
45+
} else {
46+
return `-${diffStr}% 🟥`;
47+
}
48+
}
49+
2950
function createMessage(monthSummary: MonthSummary) {
30-
const daySummary = Object.values(monthSummary.reports).sort((a, b) =>
51+
const sortedMonthSummary = Object.values(monthSummary.reports).sort((a, b) =>
3152
new Date(a.date).getTime() - new Date(b.date).getTime()
32-
).at(-1);
53+
);
54+
55+
const daySummary = sortedMonthSummary.at(-1);
3356
if (!daySummary) {
3457
throw new Error("No summary data found");
3558
}
59+
const prevDaySummary = sortedMonthSummary.at(-2);
3660
const { date, linux, windows, darwin } = daySummary;
37-
const linuxRatio = formatRatio(linux);
38-
const windowsRatio = formatRatio(windows);
39-
const darwinRatio = formatRatio(darwin);
40-
const mrkdwn =
41-
`Linux *${linuxRatio}* / Windows *${windowsRatio}* / Darwin *${darwinRatio}* <https://node-test-viewer.deno.dev/results/${date}|(Full report)>`;
61+
let mrkdwn = "";
62+
63+
const currentLinuxRatio = getRatio(linux);
64+
const prevLinuxRatio = getRatio(prevDaySummary?.linux);
65+
const linuxRatioDiff = prevLinuxRatio !== -1
66+
? currentLinuxRatio - prevLinuxRatio
67+
: 0;
68+
mrkdwn += `Linux *${formatRatio(currentLinuxRatio)}* (${
69+
formatDiff(linuxRatioDiff)
70+
})\n`;
71+
72+
const currentWindowsRatio = getRatio(windows);
73+
const prevWindowsRatio = getRatio(prevDaySummary?.windows);
74+
const windowsRatioDiff = prevWindowsRatio !== -1
75+
? currentWindowsRatio - prevWindowsRatio
76+
: 0;
77+
mrkdwn += `Windows *${formatRatio(currentWindowsRatio)}* (${
78+
formatDiff(windowsRatioDiff)
79+
})\n`;
80+
81+
const currentDarwinRatio = getRatio(darwin);
82+
const prevDarwinRatio = getRatio(prevDaySummary?.darwin);
83+
const darwinRatioDiff = prevDarwinRatio !== -1
84+
? currentDarwinRatio - prevDarwinRatio
85+
: 0;
86+
mrkdwn += `Darwin *${formatRatio(currentDarwinRatio)}* (${
87+
formatDiff(darwinRatioDiff)
88+
})\n`;
89+
90+
mrkdwn += `<https://node-test-viewer.deno.dev/results/${date}|(Full report)>`;
4291

4392
return [
4493
{

0 commit comments

Comments
 (0)