Skip to content

Write the code coverage report in the configured encoding and match the xml declaration#2749

Merged
nohwnd merged 2 commits into
mainfrom
fix/2450-cc-output-encoding
Jun 27, 2026
Merged

Write the code coverage report in the configured encoding and match the xml declaration#2749
nohwnd merged 2 commits into
mainfrom
fix/2450-cc-output-encoding

Conversation

@nohwnd

@nohwnd nohwnd commented Jun 25, 2026

Copy link
Copy Markdown
Member

Fix #2450

The code coverage report is built by casting the JaCoCo/Cobertura string 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 didn't 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.

…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>
Comment thread src/Pester.Utility.ps1 Outdated
}
}

function Get-OutputEncodingFromName {

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks like the same function, it just moved? put it back

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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>
@nohwnd nohwnd marked this pull request as ready for review June 27, 2026 07:50
@nohwnd nohwnd merged commit 2f2f208 into main Jun 27, 2026
13 checks passed
@nohwnd nohwnd deleted the fix/2450-cc-output-encoding branch June 27, 2026 07:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

CodeCoverage.OutputEncoding ignored in xml encoding-attribute

1 participant