Skip to content

Commit

Permalink
fix issue with numbers in file name
Browse files Browse the repository at this point in the history
  • Loading branch information
imadx committed Jul 18, 2022
1 parent 5c06437 commit d99ad55
Show file tree
Hide file tree
Showing 8 changed files with 54 additions and 12 deletions.
1 change: 1 addition & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -93,3 +93,4 @@ jobs:
github-token: "${{ secrets.PERSONAL_ACCESS_TOKEN }}"
command: "merge-coverage"
shard-count: "2"
show-all-files-in-summary: true
8 changes: 4 additions & 4 deletions dist/index.js

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions src/sample/add2.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { add2 } from "./add2";

describe("add2", () => {
it("should add 2 numbers", () => {
expect(add2(1, 2)).toBe(3);
});
});
3 changes: 3 additions & 0 deletions src/sample/add2.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export const add2 = (a: number, b: number) => {
return a + b;
};
2 changes: 1 addition & 1 deletion src/steps/__sample__/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s
All files | 25.51 | 18.51 | 16.66 | 21.25 |
src | 0 | 0 | 0 | 0 |
index.ts | 0 | 0 | 0 | 0 | 1-34
run.ts | 0 | 0 | 0 | 0 | 1-33
run3.ts | 0 | 0 | 0 | 0 | 1-33
src/steps | 23.94 | 0 | 40 | 21.53 |
merge-coverage.ts | 36.95 | 0 | 66.66 | 33.33 | 21-24,33-60,67-85
run-tests.ts | 0 | 0 | 0 | 0 | 1-42
Expand Down
15 changes: 15 additions & 0 deletions src/steps/__snapshots__/merge-coverage.spec.ts.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`getCoverageDetailsTable should return formatted table 1`] = `
"File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s
---|--:|---:|--:|--:|---
All files | \`25.51\` | \`18.51\` | \`16.66\` | \`21.25\` |
── src | \`0.00\` | \`0.00\` | \`0.00\` | \`0.00\` |
──── index.ts | \`0.00\` | \`0.00\` | \`0.00\` | \`0.00\` | \`1-34\`
──── run3.ts | \`0.00\` | \`0.00\` | \`0.00\` | \`0.00\` | \`1-33\`
── src/steps | \`23.94\` | \`0.00\` | \`40.00\` | \`21.53\` |
──── merge-coverage.ts | \`36.95\` | \`0.00\` | \`66.66\` | \`33.33\` | \`21-24\`,\`33-60\`,\`67-85\`
──── run-tests.ts | \`0.00\` | \`0.00\` | \`0.00\` | \`0.00\` | \`1-42\`
── src/utils | \`48.78\` | \`62.50\` | \`10.00\` | \`41.93\` |
──── index.ts | \`48.78\` | \`62.50\` | \`10.00\` | \`41.93\` | \`7\`,\`11\`,\`21-36\`,\`40-43\`,\`47\`,\`51\` "
`;
11 changes: 10 additions & 1 deletion src/steps/merge-coverage.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as mockedFs from "fs";
import { mergeCoverage } from "./merge-coverage";
import { getCoverageDetailsTable, mergeCoverage } from "./merge-coverage";
import { coverageSummary, execSyncOutput } from "./__sample__";
import * as mockedOctokit from "../utils/octokit";
import * as mockedUtils from "../utils";
Expand Down Expand Up @@ -80,3 +80,12 @@ describe("merge-coverage", () => {
});
});
});

describe("getCoverageDetailsTable", () => {
it("should return formatted table", () => {
const coverageSummary = execSyncOutput;
const table = getCoverageDetailsTable(coverageSummary);

expect(table).toMatchSnapshot();
});
});
19 changes: 13 additions & 6 deletions src/steps/merge-coverage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ export const getCommentBody = (
output.push("");
output.push("### Code Coverage on All Files");

const _textSummaryBody = getCoverageDetailsTable(textSummary, showAllFilesInSummary);
const _textSummaryBody = getCoverageDetailsTable(textSummary);
output.push(_textSummaryBody);

output.push(`</details>`);
Expand All @@ -97,7 +97,7 @@ export const getCommentBody = (
return output.join("\n");
};

const getCoverageDetailsTable = (textSummary: string, showAllFilesInSummary: boolean) => {
export const getCoverageDetailsTable = (textSummary: string) => {
let lines = textSummary.split("\n").slice(1).filter(Boolean);
lines.pop();
lines = lines
Expand All @@ -122,16 +122,23 @@ const getCoverageDetailsTable = (textSummary: string, showAllFilesInSummary: boo
return lines.join("\n");
};

export const getFormattedValue = (value: string, ...args) => {
export const getFormattedValue = (
value: string,
match: string,
_nestedMatch: string,
matchedIndex: number,
line: string
) => {
if (!value) return "";

const matchedIndex = args[2];
const line = args[3];

const lastColumnOffset = getNthIndexOfCharacter(line, "|", 5);
if (lastColumnOffset < matchedIndex) {
return `\`${value}\``;
}

if (line.charAt(matchedIndex - 1).match("[A-z]")) {
return value;
}

return `\`${Number(value).toFixed(2)}\``;
};

1 comment on commit d99ad55

@imadx
Copy link
Owner Author

@imadx imadx commented on d99ad55 Jul 18, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Coverage Summary

Covered/Total Percentage
Statements 158/174 90.8% 🟢
Branches 26/32 81.25% 🟢
Functions 23/23 100% 🟢
Lines 135/150 90% 🟢
Code Coverage on All Files

Code Coverage on All Files

File % Stmts % Branch % Funcs % Lines Uncovered Line #s
All files 90.80 81.25 100.00 90.00
── src 100.00 100.00 100.00 100.00
──── run.ts 100.00 100.00 100.00 100.00
── src/sample 100.00 100.00 100.00 100.00
──── add2.ts 100.00 100.00 100.00 100.00
── src/steps 83.67 68.42 100.00 83.33
──── merge-coverage.ts 84.50 70.00 100.00 84.61 31,52,85-94
──── run-tests.ts 81.48 66.66 100.00 80.00 29-30,43-47
── src/utils 100.00 100.00 100.00 100.00
──── index.ts 100.00 100.00 100.00 100.00
──── octokit.ts 100.00 100.00 100.00 100.00

Please sign in to comment.