Helper to use in CI to convert test coverage data emitted by Pester to JSON understood by codecov.io.
Requires git
to be installed and in the PATH
(this is true for Travis and AppVeyor).
# ...
install:
# Install modules
- pwsh -c '& {
Install-Module Pester;
Install-Module PSCodeCovIo;
}'
script:
# Run tests and generate coverage report
- pwsh -c '& {
$res = Invoke-Pester -PassThru -CodeCoverage;
Export-CodeCovIoJson -CodeCoverage $res.CodeCoverage -RepoRoot $pwd -Path coverage.json;
if ($res.FailedCount -gt 0) {
throw "$($res.FailedCount) tests failed."
}
}'
after_success:
# Upload coverage report to codecov
- bash <(curl -s https://codecov.io/bash) -f coverage.json
# ...
install:
- ps: Install-Module Pester -Scope CurrentUser -Force -SkipPublisherCheck
test_script:
# Run tests and generate coverage report
- ps: |
$testResultsFile = ".\TestsResults.xml"
$res = Invoke-Pester -PassThru -CodeCoverage;
Export-CodeCovIoJson -CodeCoverage $res.CodeCoverage -RepoRoot $pwd -Path coverage.json
if ($res.FailedCount -gt 0) {
throw "$($res.FailedCount) tests failed."
}
after_test:
# Upload coverage report to codecov
- ps: |
$env:PATH = 'C:\msys64\usr\bin;' + $env:PATH
Invoke-WebRequest -Uri 'https://codecov.io/bash' -OutFile codecov.sh
bash codecov.sh -f coverage.json
Export-CodeCovIoJson [-CodeCoverage] <Object> [-RepoRoot] <String> [[-Path] <String>] [<CommonParameters>]
-CodeCoverage <Object>
The CodeCoverage property of the output of Invoke-Pester with the -PassThru and -CodeCoverage options-RepoRoot <String>
The path to the root of the repo. This part of the path will not be included in the report. Needed to normalize all the reports.-Path <String>
The path of the file to write the report to.