pester / Pester

Pester is the ubiquitous test and mock framework for PowerShell.
https://pester.dev/
Other
3.07k stars 469 forks source link

TestResults.OutputEncoding option ignored #2452

Open fflaten opened 3 months ago

fflaten commented 3 months ago

Checklist

What is the issue?

TestResults.OutputEncoding configuration option is ignored. XML delcaration is hardcoded to utf-8 and file is written in default encoding.

Expected Behavior

Configuration option should be properly typed to valid encodings and be effective.

Steps To Reproduce

$c = New-PesterConfiguration
$c.Run.ScriptBlock = {
    Describe 'd' {
        It 'i' { }
    }
}
$c.TestResult.Enabled = $true
$c.TestResult.OutputFormat = 'NUnit3'
$c.TestResult.OutputEncoding = 'utf-16'
$c.TestResult.TestSuiteName = 'TestResult.OutputEncoding Demo'
$c.TestResult.OutputPath = "./demoOutputEncoding.xml"
$c.Output.Verbosity = 'Detailed'
Invoke-Pester -Configuration $c

demoOutputEncoding.xml is written in UTF-8 and incldues encoding="utf-8".

Describe your environment

Pester version : 5.6.0-beta1 /workspaces/Pester/bin/Pester.psm1 PowerShell version : 7.4.1 OS version : Unix 5.15.133.1

Possible Solution?

Improve type or early validation for configuration option to only allow valid encodings. Then pass it to Encoding-option here:

https://github.com/pester/Pester/blob/93c661020d666c7c07577c46b8ad756b8aa74aec/src/functions/TestResults.ps1#L169-L172