psake / PowerShellBuild

Common build tasks for psake and Invoke-Build that build and test PowerShell modules
MIT License
133 stars 24 forks source link

Running the Test task fails when $PSBPreference.Test.CodeCoverage.Enabled is set to $true #61

Closed OpsM0nkey closed 1 year ago

OpsM0nkey commented 2 years ago

Executing the Test task fails when processing the Code Coverage results with error:

System.Management.Automation.RuntimeException: CodeCoverage.CoverageFormat must be 'JaCoCo' or 'CoverageGutters', but it was , please review your configuration.

Expected Behavior

Expect to get the Code Coverage results in line with:

Code Coverage:

Type: [Instruction]: 0.00%
Type: [Line]: 0.00%
Type: [Method]: 100.00%
Type: [Class]: 100.00%

Current Behavior

Looking at the code for the latest release of the module (version 0.6.1), there seems to be a typo in the Task Pester declaration when setting the CodeCoverageOutputFileFormat value:

CodeCoverageOutputFileFormat = $PSBPreference.Test.CodeCoverage.OutputFormat

Looking at the build.properties.ps1 file, that particular Ordered dictionary key is set to:

 # The code coverage output format to use
OutputFileFormat = 'JaCoCo'

Possible Solution

It's a simple Typo fix - update the psakeFile.ps1 Task Pester entry from:

CodeCoverageOutputFileFormat = $PSBPreference.Test.CodeCoverage.OutputFormat

To

CodeCoverageOutputFileFormat = $PSBPreference.Test.CodeCoverage.OutputFileFormat

Alternative (and temporary) workaround - update the invoking psakeFile.ps1 properties section to call the override of the mis-named property:

$PSBPreference.Test.CodeCoverage.OutputFormat = 'JaCoCo'

This has the desired effect.

Steps to Reproduce (for bugs)

  1. In your invoking module's psakeFile.ps1 properties section, include:
    properties {
    $PSBPreference.Test.ScriptAnalysisEnabled = $true
    $PSBPreference.Test.CodeCoverage.Enabled  = $true
    }
  2. Run the Test Task
  3. Tests run, failure occurs on the Code Coverage step

Context

I'm still in the early stages of incorporating the scaffolding on offer by this module into our development workflow. This is clearly not a critical bug (there's a simple enough workaround), but it's also low hanging fruit for fixing (I can do a PR)

Your Environment