Pester icon indicating copy to clipboard operation
Pester copied to clipboard

Can't set CoveragePercentTarget in New-PesterConfiguration

Open Jaykul opened this issue 2 years ago • 2 comments

Can't set CoveragePercentTarget in New-PesterConfiguration

$Config = New-PesterConfiguration @{ CodeCoverage = @{ CoveragePercentTarget = 90 }}
$Config.Codecoverage.CoveragePercentTarget
Default Description                                                            Value
------- -----------                                                            -----
     75 Target percent of code coverage that you want to achieve, default 75%.    75

I'm really unhappy with this command, if I'm honest. How is it possible that this doesn't produce an error:

$Config = New-PesterConfiguration @{ Nonsense = @{ NobobyCares = 90 }}

I can't figure out any way to make this command actually set the coverage target. I had to manually set the .Value on the output object.

Jaykul avatar Nov 19 '21 22:11 Jaykul

Something is wired incorrectly in there, this also does not work $c = [PesterConfiguration] @{ CodeCoverage = @{ CoveragePercentTarget = 90 }}, but $c.CodeCoverage.CoveragePercentTarget = 90 works.

nohwnd avatar Nov 22 '21 06:11 nohwnd

It's probably configuration.GetValueOrNull<decimal>("CoveragePercentTarget") used in config merging returning null (-> default value) unless you explicitly provide a decimal. This works:

$Config = New-PesterConfiguration @{ CodeCoverage = @{ CoveragePercentTarget = [decimal]91 }}
$Config.Codecoverage.CoveragePercentTarget                                                   

Default Description                                                            Value
------- -----------                                                            -----
     75 Target percent of code coverage that you want to achieve, default 75%.    91

$c.CodeCoverage.CoveragePercentTarget = 90 is solved by implicit cast for int in the DecimalOption class.

Might need to add some conversions in GetValueOrNull<T>

fflaten avatar Feb 05 '22 18:02 fflaten