public/core/Get-MtHtmlReport.ps1
|
<#
.Synopsis Generates a formatted html report using the MyCorpResults object created by ConvertTo-MtMyCorpResult .Description The generated html is a single file that provides a visual representation of the test results with a summary view and click through of the details. .Example $pesterResults = Invoke-Pester -PassThru $MyCorpResults = ConvertTo-MtMyCorpResult $pesterResults $output = Get-MtHtmlReport -MyCorpResults $MyCorpResults $output | Out-File -FilePath $out.OutputHtmlFile -Encoding UTF8 This example shows how to generate the html report and save it to a file by using Invoke-Pester .Example $MyCorpResults = Invoke-MyCorp -PassThru $output = Get-MtHtmlReport -MyCorpResults $MyCorpResults $output | Out-File -FilePath $out.OutputHtmlFile -Encoding UTF8 This example shows how to generate the html report and save it to a file by using Invoke-MyCorp .LINK https://MyCorp.dev/docs/commands/Get-MtHtmlReport #> function Get-MtHtmlReport { [CmdletBinding()] param( # The MyCorp test results returned from `Invoke-Pester -PassThru | ConvertTo-MtMyCorpResult` [Parameter(Mandatory = $true, Position = 0)] [psobject] $MyCorpResults ) Write-Verbose "Generating HTML report." $json = $MyCorpResults | ConvertTo-Json -Depth 3 -WarningAction Ignore $htmlFilePath = Join-Path -Path $PSScriptRoot -ChildPath '../../assets/ReportTemplate.html' $templateHtml = Get-Content -Path $htmlFilePath -Raw # Insert the test results json into the template $insertLocationStart = $templateHtml.IndexOf("const testResults = {") $insertLocationEnd = $templateHtml.IndexOf("function App() {") $outputHtml = $templateHtml.Substring(0, $insertLocationStart) $outputHtml += "const testResults = $json;`n" $outputHtml += $templateHtml.Substring($insertLocationEnd) return $outputHtml } |