Created
March 22, 2018 15:06
-
-
Save iamkoch/7e70c5b9b1724983c5a45451b69db22a to your computer and use it in GitHub Desktop.
This takes XUnit output and generates an HTML file with @tags above it. The trait it looks for it "Story"
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
param( | |
$configuration = "Debug" | |
) | |
[Void][System.Reflection.Assembly]::LoadWithPartialName("System.xml.linq") | |
$ScriptDir = Split-Path $script:MyInvocation.MyCommand.Path | |
Set-Location $ScriptDir | |
$doc = [System.Xml.Linq.XDocument]::Parse([System.IO.File]::ReadAllText("$ScriptDir/xunit-results-xbehave.xml")) | |
$collections = $doc.Descendants("collection") | |
$html = New-Object -TypeName "System.Text.StringBuilder" | |
[void]$html.AppendLine("<html>") | |
[void]$html.AppendLine("<head><title>Fast Test Results</title><style type='text/css'>html {font-family: verdana; font-size: 16px; line-height: 24px;} .collection-name {font-weight: bold; color: #666;} .collection-name span { color: #bbb; } .Pass{color: green;} .Fail{color: red;} .collection { margin: 0px 0 20px 10px; } .scenario { padding-left: 10px; margin-bottom: 15px;border-left: 3px solid #ccc;width: 50%;margin-top: 10px; }</style></head>") | |
[void]$html.AppendLine("<body>") | |
[Void][System.Reflection.Assembly]::LoadWithPartialName("System.web") | |
[Void][System.Reflection.Assembly]::LoadWithPartialName("System.Text") | |
function htmlencode($val) { | |
[system.web.httputility]::htmlencode($val.Trim()) | |
} | |
foreach($collection in $collections) { | |
$collectionName = $collection.Attribute("name").Value | |
$parts = $collectionName -split "\." | |
$featureName = $parts[$parts.length -1] | |
$niceName = ($featureName.substring(0,1).toupper() + $featureName.substring(1) -creplace '[A-Z]', ' $&').Trim() | |
$tests = $collection.Descendants("test") | |
$count = 1 | |
$b = New-Object -TypeName "System.Text.StringBuilder" | |
[void]$b.AppendLine("<div class='collection'><div class='collection-name'>$niceName <span>($collectionName)</span></div><div class='scenario'>") | |
$found = $false | |
foreach($test in $tests) { | |
$name = $test.Attribute("name").Value | |
$result = $test.Attribute("result").Value | |
$method = $test.Attribute("method").Value | |
$traits = $test.Descendants("traits") | |
$stories = @() | |
foreach($trait in $traits) { | |
foreach($t in $trait.Descendants("trait")) { | |
if ($t.Attribute("name").Value -eq "Story") { | |
$stories += "@" + $t.Attribute("value").Value | |
} | |
} | |
} | |
$storiesString = [String]::Join(" ", $stories) | |
$niceMethodName = ($method.substring(0,1).toupper() + $method.substring(1) -creplace '[A-Z]', ' $&').Trim() | |
$countAsString = $count.ToString().PadLeft(2, '0') | |
$split = $name -split "\[$countAsString\]" | |
$story = | |
if ($split.length -gt 1) { | |
$found = $true | |
$pretty = htmlencode $split[1] | |
if ($count -eq 1) { | |
[void]$b.AppendLine("<div class='scenario-tags'>$storiesString</div>") | |
[void]$b.AppendLine("<div class='scenario-name'>Scenario: $niceMethodName</div>") | |
} | |
[void]$b.AppendLine("<div class='result-row $result'>[$countAsString] $pretty</div>") | |
$count++ | |
} else { | |
if ($found -eq $true) { | |
[Void]$b.AppendLine("</div>") | |
[Void]$html.AppendLine($b.ToString()) | |
$found = $false | |
} | |
$b = New-Object -TypeName "System.Text.StringBuilder" | |
$count = 1 | |
$countAsString = $count.ToString().PadLeft(2, '0') | |
$split = $name -split "\[$countAsString\]" | |
if ($split.length -gt 1) { | |
$found = $true | |
$pretty = htmlencode $split[1] | |
[void]$b.AppendLine("<div class='scenario'>") | |
[void]$b.AppendLine("<div class='scenario-tags'>$storiesString</div>") | |
[void]$b.AppendLine("<div class='scenario-name'>Scenario: $niceMethodName</div>") | |
[Void]$b.AppendLine("<div class='result-row $result'>[$countAsString] $pretty</div>") | |
$count++ | |
} else { | |
} | |
} | |
} | |
if ($found -eq $true) { | |
[void]$b.AppendLine("</div></div>") | |
[Void]$html.AppendLine($b.ToString()) | |
} | |
} | |
[void]$html.AppendLine("</body></html>") | |
[System.IO.File]::WriteAllText("$ScriptDir\xbehave.html", $html.ToString()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment