Skip to content

Commit

Permalink
fix: cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
sakulstra committed Nov 13, 2024
1 parent 0cd0c0c commit 9db3e50
Show file tree
Hide file tree
Showing 10 changed files with 9,358 additions and 1,133 deletions.
5,177 changes: 4,641 additions & 536 deletions dist/action.js

Large diffs are not rendered by default.

5,177 changes: 4,641 additions & 536 deletions dist/action.mjs

Large diffs are not rendered by default.

5 changes: 4 additions & 1 deletion dist/lib.d.mts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ type Lcov = {
};
}[];

declare function generateCoverageDiff(before: Lcov, after: Lcov): string;
type Options = {
rootUrl: string;
};
declare function generateCoverageDiff(before: Lcov, after: Lcov, { rootUrl }: Options): string;

export { generateCoverageDiff };
5 changes: 4 additions & 1 deletion dist/lib.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ type Lcov = {
};
}[];

declare function generateCoverageDiff(before: Lcov, after: Lcov): string;
type Options = {
rootUrl: string;
};
declare function generateCoverageDiff(before: Lcov, after: Lcov, { rootUrl }: Options): string;

export { generateCoverageDiff };
12 changes: 6 additions & 6 deletions dist/lib.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ function formatCoverage(coverage) {
if (coverage > 0.8) color = "orange";
if (coverage > 0.95) color = "lightgreen";
if (coverage === 1) color = "green";
return "{\\color{" + color + "}" + percent + "%}";
return "{\\\\color{" + color + "}" + percent + "\\\\\\\\%}";
}
var UP = `\u2191`;
var DOWN = `\u2193`;
Expand All @@ -42,29 +42,29 @@ function formatCoverageLine({ hit, found }, previousCoverage) {
if (diff)
formattedString = `^{${diff > 0 ? UP : DOWN}` + new Intl.NumberFormat("en-US", {
maximumSignificantDigits: 2
}).format(diff) + "%}" + formattedString;
return `$${formattedString}$<br />$${hit} / ${found}$`;
}).format(diff) + "\\\\\\\\%}" + formattedString;
return `\\$${formattedString}\\$<br />\\$${hit} / ${found}\\$`;
}
function findFile(report, file) {
return report.find((r) => r.file === file);
}
function getCoverage({ hit, found }) {
return found == 0 ? 1 : hit / found;
}
function generateCoverageDiff(before, after) {
function generateCoverageDiff(before, after, { rootUrl }) {
let content = "| File | Line Coverage | Function Coverage | Branch Coverage |\n| --- | ---: | ---: | ---: |\n";
for (const report of after) {
const previousRunResult = findFile(before, report.file);
const lineCoverage = formatCoverageLine(
report.lines,
previousRunResult ? getCoverage(previousRunResult.lines) : 0
);
const missedLines = report.lines.details.filter((line) => line.hit === 0).map((line) => `[${line.line}](${report.file}#L${line.line})`).join(",");
const missedLines = report.lines.details.filter((line) => line.hit === 0).map((line) => `[${line.line}](${rootUrl}${report.file}#L${line.line})`).join(", ");
const functionCoverage = formatCoverageLine(
report.functions,
previousRunResult ? getCoverage(previousRunResult.functions) : 0
);
const missedFunctions = report.functions.details.filter((line) => line.hit === 0).map((line) => `[${line.name}](${report.file}#L${line.line})`).join(",");
const missedFunctions = report.functions.details.filter((line) => line.hit === 0).map((line) => `[${line.name}](${rootUrl}${report.file}#L${line.line})`).join("<br />");
const branchCoverage = formatCoverageLine(
report.branches,
previousRunResult ? getCoverage(previousRunResult.branches) : 0
Expand Down
12 changes: 6 additions & 6 deletions dist/lib.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ function formatCoverage(coverage) {
if (coverage > 0.8) color = "orange";
if (coverage > 0.95) color = "lightgreen";
if (coverage === 1) color = "green";
return "{\\color{" + color + "}" + percent + "%}";
return "{\\\\color{" + color + "}" + percent + "\\\\\\\\%}";
}
var UP = `\u2191`;
var DOWN = `\u2193`;
Expand All @@ -18,29 +18,29 @@ function formatCoverageLine({ hit, found }, previousCoverage) {
if (diff)
formattedString = `^{${diff > 0 ? UP : DOWN}` + new Intl.NumberFormat("en-US", {
maximumSignificantDigits: 2
}).format(diff) + "%}" + formattedString;
return `$${formattedString}$<br />$${hit} / ${found}$`;
}).format(diff) + "\\\\\\\\%}" + formattedString;
return `\\$${formattedString}\\$<br />\\$${hit} / ${found}\\$`;
}
function findFile(report, file) {
return report.find((r) => r.file === file);
}
function getCoverage({ hit, found }) {
return found == 0 ? 1 : hit / found;
}
function generateCoverageDiff(before, after) {
function generateCoverageDiff(before, after, { rootUrl }) {
let content = "| File | Line Coverage | Function Coverage | Branch Coverage |\n| --- | ---: | ---: | ---: |\n";
for (const report of after) {
const previousRunResult = findFile(before, report.file);
const lineCoverage = formatCoverageLine(
report.lines,
previousRunResult ? getCoverage(previousRunResult.lines) : 0
);
const missedLines = report.lines.details.filter((line) => line.hit === 0).map((line) => `[${line.line}](${report.file}#L${line.line})`).join(",");
const missedLines = report.lines.details.filter((line) => line.hit === 0).map((line) => `[${line.line}](${rootUrl}${report.file}#L${line.line})`).join(", ");
const functionCoverage = formatCoverageLine(
report.functions,
previousRunResult ? getCoverage(previousRunResult.functions) : 0
);
const missedFunctions = report.functions.details.filter((line) => line.hit === 0).map((line) => `[${line.name}](${report.file}#L${line.line})`).join(",");
const missedFunctions = report.functions.details.filter((line) => line.hit === 0).map((line) => `[${line.name}](${rootUrl}${report.file}#L${line.line})`).join("<br />");
const branchCoverage = formatCoverageLine(
report.branches,
previousRunResult ? getCoverage(previousRunResult.branches) : 0
Expand Down
Loading

0 comments on commit 9db3e50

Please sign in to comment.