Skip to content
This repository has been archived by the owner on Jun 28, 2022. It is now read-only.
/ PSCoverage Public archive

📔 Create Coveralls.io Coverage Reports for your PowerShell Modules

License

Notifications You must be signed in to change notification settings

OCram85/PSCoverage

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

45 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

AppVeyor branch AppVeyor tests branch Coveralls github codecov PowerShell Gallery PowerShell Gallery

forthebadge forthebadge

General

PSCoverage is an interface for coveralls.io. It enables you to run your known pester tests and its coverage report. Furthermore it formats the coverage report and uploads it to coveralls.io.

To get started read the about_PSCoverage page.

Installation

PowerShellGallery.com (Recommended Way)

  • Make sure you use PowerShell 5.0 or higher with $PSVersionTable.
  • Use the builtin PackageManagement and install with: Install-Module PSCoverage -AllowPrerelease
  • Done. Start exploring the Module with Import-Module PSCoverage ; Get-Command -Module PSCoverage

Manual Way

  • Take a look at the Latest Release page.
  • Download the PSCoverage.zip.
  • Unpack the Zip and put it in your Powershell Module path.
    • Don't forget to change the NTFS permission flag in the context menu.
  • Start with Import-Module PSCoverage

Usage

Navigate to your module/ repository root. Your module structure needs to be like this:

~\src\
      Private\
              Invoke-Foobar.ps1
      Functions\
      External\
~\tests\
        Private\
                Invoke-Foobar.Tests.ps1
        Functions\
        External\
~\ModuleManifest.psd1
~\ModuleScript.psm1

1. First you need a list of all your src files:

$srcFiles = Get-ChildItem -Path ".\src\*.ps1" -Recurse | Sort-Object -Property 'Name' | Select-Object -ExpandProperty 'FullName'

2. Next you need a list with all your pester tests files:

$testFiles = Get-ChildItem -Path ".\tests\*.Tests.ps1" -Recurse | Sort-Object -Property 'Name' | Select-Object -ExpandProperty 'FullName'

3. The simplest way to get you code coverage is by creating it with your unit tests. This avoids rerunning all the test with PSCoverage:

$TestResults = Invoke-Pester -Path $testFiles -CodeCoverage $srcFiles -PassThru

4. And then passthru the code coverage to create a new report:

$CoverallsIOReport = New-CoverageReport -CodeCoverage $TestResults.CodeCoverage -RepoToken '123456' -ModuleRoot $PWD

5. Finally we can upload the coverage report to coveralls.io:

Publish-CoverageReport -CoverageReport $CoverallsIOReport