Skip to content

Commit

Permalink
Wrap table summary headers into a helper function
Browse files Browse the repository at this point in the history
  • Loading branch information
jgillick committed Jan 6, 2023
1 parent 27b9198 commit b0fffc2
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 18 deletions.
10 changes: 10 additions & 0 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -27040,6 +27040,7 @@ function getTemplateVars(report, failureMessage, inputs) {
commitSha,
commitUrl,
prIdentifier: PR_COMMENT_IDENTIFIER,
renderFileSummaryTableHeader: renderFileSummaryTableHeader,
renderFileSummaryTableRow: renderFileSummaryFactory(inputs),
};
const { stripPathPrefix } = inputs;
Expand Down Expand Up @@ -27167,6 +27168,15 @@ function createSummary(output, failed, inputs) {
});
}
exports.createSummary = createSummary;
/**
* Create the markdown file table headers
*/
function renderFileSummaryTableHeader() {
return [
"| | Name | Stmts | Branch | Funcs | Lines |",
"| ---- | ---- | ----- | ------ | ----- | ----- |",
].join("\n");
}
/**
* Create the markdown for a filepath row
*/
Expand Down
2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

13 changes: 5 additions & 8 deletions dist/summary.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ Commit: <%= commitSha %>
<% } %>

<!-- Summary -->

Summary

| Name | Stmts | Branch | Funcs | Lines |
| ---- | ----- | ------ | ----- | ----- |
<%= renderFileSummaryTableHeader() %>
<%= renderFileSummaryTableRow(total) %>

<!-- All files, if diffs aren't present -->
Expand All @@ -30,8 +30,7 @@ Summary
All files
</summary>

| Name | Stmts | Branch | Funcs | Lines | |
| ---- | ----- | ------ | ----- | ----- | ----- |
<%= renderFileSummaryTableHeader() %>
<%= all.map((fileSummary) => renderFileSummaryTableRow(fileSummary)).join('\n') %>

</details>
Expand All @@ -43,8 +42,7 @@ All files

Changed files

| Name | Stmts | Branch | Funcs | Lines | |
| ---- | ----- | ------ | ----- | ----- | ----- |
<%= renderFileSummaryTableHeader() %>
<%= changed.map((fileSummary) => renderFileSummaryTableRow(fileSummary)).join('\n') %>
<% } %>

Expand All @@ -57,8 +55,7 @@ Changed files
Unchanged files
</summary>

| Name | Stmts | Branch | Funcs | Lines |
| ---- | ----- | ------ | ----- | ----- |
<%= renderFileSummaryTableHeader() %>
<%= unchanged.map((fileSummary) => renderFileSummaryTableRow(fileSummary)).join('\n') %>

</details>
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "test-coverage-reporter",
"version": "1.0.8",
"version": "1.0.9",
"description": "Generate a test coverage report for a PR",
"main": "dist/index.js",
"scripts": {
Expand Down
11 changes: 11 additions & 0 deletions src/output.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ export function getTemplateVars(
commitUrl,
prIdentifier: PR_COMMENT_IDENTIFIER,

renderFileSummaryTableHeader: renderFileSummaryTableHeader,
renderFileSummaryTableRow: renderFileSummaryFactory(inputs),
};
const { stripPathPrefix } = inputs;
Expand Down Expand Up @@ -230,6 +231,16 @@ export function createSummary(output: string, failed: boolean, inputs: Inputs) {
});
}

/**
* Create the markdown file table headers
*/
function renderFileSummaryTableHeader() {
return [
"| | Name | Stmts | Branch | Funcs | Lines |",
"| ---- | ---- | ----- | ------ | ----- | ----- |",
].join("\n");
}

/**
* Create the markdown for a filepath row
*/
Expand Down
13 changes: 5 additions & 8 deletions src/summary.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ Commit: <%= commitSha %>
<% } %>

<!-- Summary -->

Summary

| Name | Stmts | Branch | Funcs | Lines |
| ---- | ----- | ------ | ----- | ----- |
<%= renderFileSummaryTableHeader() %>
<%= renderFileSummaryTableRow(total) %>

<!-- All files, if diffs aren't present -->
Expand All @@ -30,8 +30,7 @@ Summary
All files
</summary>

| Name | Stmts | Branch | Funcs | Lines | |
| ---- | ----- | ------ | ----- | ----- | ----- |
<%= renderFileSummaryTableHeader() %>
<%= all.map((fileSummary) => renderFileSummaryTableRow(fileSummary)).join('\n') %>

</details>
Expand All @@ -43,8 +42,7 @@ All files

Changed files

| Name | Stmts | Branch | Funcs | Lines | |
| ---- | ----- | ------ | ----- | ----- | ----- |
<%= renderFileSummaryTableHeader() %>
<%= changed.map((fileSummary) => renderFileSummaryTableRow(fileSummary)).join('\n') %>
<% } %>

Expand All @@ -57,8 +55,7 @@ Changed files
Unchanged files
</summary>

| Name | Stmts | Branch | Funcs | Lines |
| ---- | ----- | ------ | ----- | ----- |
<%= renderFileSummaryTableHeader() %>
<%= unchanged.map((fileSummary) => renderFileSummaryTableRow(fileSummary)).join('\n') %>

</details>
Expand Down
1 change: 1 addition & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ export type TemplateVars = {
unchanged: TemplateDiffSummary[];
all: TemplateDiffSummary[];

renderFileSummaryTableHeader: Function;
renderFileSummaryTableRow: Function;
};

Expand Down

0 comments on commit b0fffc2

Please sign in to comment.