Write the code coverage report in the configured encoding and match the xml declaration#2749
Merged
Conversation
…and match the xml declaration The coverage report is cast to [xml] (which carries a hard-coded encoding="UTF-8" declaration) and then written through a StringWriter and Out-File -Encoding, so the bytes on disk used CodeCoverage.OutputEncoding but the declaration always said utf-8 - they did not match. Write the report straight to the file in the configured encoding and set the declaration to match, the same way TestResult.OutputEncoding now works (#2452). The encoding-name to [Text.Encoding] mapping moved to Get-OutputEncodingFromName in Pester.Utility so both report writers share it; an invalid encoding still falls back to utf8 and warns (#2451), now up front instead of after a failed write. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
nohwnd
commented
Jun 26, 2026
| } | ||
| } | ||
|
|
||
| function Get-OutputEncodingFromName { |
Member
Author
There was a problem hiding this comment.
looks like the same function, it just moved? put it back
Member
Author
There was a problem hiding this comment.
Put it back in 5bd7268 - kept it in TestResults.ps1 and just added an optional OptionName param so the coverage caller gets the right name in the warning. Utility.ps1 is untouched now.
It's inlined module-wide anyway, so no need to move it to Pester.Utility.ps1. Just add an optional OptionName param so the coverage caller gets the right option name in the warning. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fix #2450
The code coverage report is built by casting the JaCoCo/Cobertura string to
[xml], which carries a hard-codedencoding="UTF-8"declaration, and then written through aStringWriterandOut-File -Encoding. So the bytes on disk usedCodeCoverage.OutputEncodingbut the declaration always said utf-8 - they didn't match.Write the report straight to the file in the configured encoding and set the declaration to match, the same way
TestResult.OutputEncodingnow works (#2452). The encoding-name to[Text.Encoding]mapping moved toGet-OutputEncodingFromNameinPester.Utilityso both report writers share it; an invalid encoding still falls back to utf8 and warns (#2451), now up front instead of after a failed write.