pester / Pester

Pester is the ubiquitous test and mock framework for PowerShell.

Home Page:https://pester.dev/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

TestResults.OutputEncoding option ignored

fflaten opened this issue · comments

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:

$settings = [Xml.XmlWriterSettings] @{
Indent = $true
NewLineOnAttributes = $false
}