Pester
Pester copied to clipboard
Can't set CoveragePercentTarget in New-PesterConfiguration
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.
Something is wired incorrectly in there, this also does not work $c = [PesterConfiguration] @{ CodeCoverage = @{ CoveragePercentTarget = 90 }}
, but $c.CodeCoverage.CoveragePercentTarget = 90
works.
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>