-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Adds file based coverage report (#8)
* feat: Adds first implementation of uncovered lines * refactor: Generalizes summary-function to be reused for file-based reports * feat: Adds detailed file report * feat: switches to use own html table template * ci: Try actions checkout v3 to have correct sha * chore: Adds error-handling for json file parsing * docs: Adjusts action icon * docs: Adds new image and describes new file-report * docs: Replaces thresholds image
- Loading branch information
1 parent
415a009
commit 34f51ec
Showing
23 changed files
with
507 additions
and
108 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import * as path from 'path'; | ||
import { generateBlobFileUrl } from './generateFileUrl'; | ||
import { getUncoveredLinesFromStatements } from './getUncoveredLinesFromStatements'; | ||
import { JsonFinal } from './types/JsonFinal'; | ||
import { JsonSummary } from './types/JsonSummary'; | ||
import { Thresholds } from './types/Threshold'; | ||
import { oneLine } from 'common-tags'; | ||
|
||
type Sources = { | ||
jsonSummary: JsonSummary; | ||
jsonFinal: JsonFinal; | ||
} | ||
|
||
const workspacePath = process.cwd(); | ||
const generateFileCoverageHtml = ({ jsonSummary, jsonFinal }: Sources) => { | ||
const filePaths = Object.keys(jsonSummary).filter((key) => key !== 'total'); | ||
const reportData: string = filePaths.map((filePath) => { | ||
const coverageSummary = jsonSummary[filePath]; | ||
const lineCoverage = jsonFinal[filePath]; | ||
|
||
// LineCoverage might be empty if coverage-final.json was not provided. | ||
const uncoveredLines = lineCoverage ? getUncoveredLinesFromStatements(jsonFinal[filePath]) : []; | ||
const relativeFilePath = path.relative(workspacePath, filePath); | ||
const url = generateBlobFileUrl(relativeFilePath); | ||
|
||
return ` | ||
<tr> | ||
<td align="left"><a href="${url}">${relativeFilePath}</a></td> | ||
<td align="right">${coverageSummary.statements.pct}%</td> | ||
<td align="right">${coverageSummary.branches.pct}%</td> | ||
<td align="right">${coverageSummary.functions.pct}%</td> | ||
<td align="right">${coverageSummary.lines.pct}%</td> | ||
<td align="left">${uncoveredLines.map((range) => { | ||
let end = ''; | ||
let endUrl = ''; | ||
if(range.start !== range.end) { | ||
end = `-${range.end}`; | ||
endUrl = `-L${range.end}`; | ||
} | ||
const rangeUrl = `${url}#L${range.start}${endUrl}`; | ||
return `<a href="${rangeUrl}">${range.start}${end}</a>`; | ||
}).join(', ')}</td> | ||
</tr>` | ||
}).join(''); | ||
|
||
return oneLine` | ||
<table> | ||
<thead> | ||
<tr> | ||
<th align="left">File</th> | ||
<th align="right">Stmts</th> | ||
<th align="right">% Branch</th> | ||
<th align="right">% Funcs</th> | ||
<th align="right">% Lines</th> | ||
<th align="left">Uncovered Lines</th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
${ reportData } | ||
</tbody> | ||
</table> | ||
` | ||
} | ||
|
||
export { | ||
generateFileCoverageHtml | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import * as github from '@actions/github'; | ||
|
||
const generateBlobFileUrl = (relativeFilePath: string) => { | ||
const sha = github.context.payload.pull_request ? | ||
github.context.payload.pull_request.head.sha | ||
: github.context.sha | ||
|
||
return [ | ||
github.context.serverUrl, | ||
github.context.repo.owner, | ||
github.context.repo.repo, | ||
'blob', | ||
sha, | ||
relativeFilePath | ||
].join('/') | ||
}; | ||
|
||
export { generateBlobFileUrl }; |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.