Last active
May 29, 2019 15:51
-
-
Save ahamilton9/354cde66869b9e44defac521e6547745 to your computer and use it in GitHub Desktop.
Simple JUnit Renderer
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
#! /usr/bin/php | |
<?php | |
// Load the content | |
$content = file_get_contents('junit.xml'); | |
$xml = simplexml_load_string($content); | |
// Include: Tablesort | |
echo '<script src="https://cdnjs.cloudflare.com/ajax/libs/tablesort/5.1.0/tablesort.min.js"></script>'; | |
// Include: Tablesort, Number Sort | |
echo '<script>!function(){var a=function(a){return a.replace(/[^\-?0-9.]/g,"")},b=function(a,b){return a=parseFloat(a),b=parseFloat(b),a=isNaN(a)?0:a,b=isNaN(b)?0:b,a-b};Tablesort.extend("number",function(a){return a.match(/^[-+]?[£\x24Û¢´€]?\d+\s*([,\.]\d{0,2})/)||a.match(/^[-+]?\d+\s*([,\.]\d{0,2})?[£\x24Û¢´€]/)||a.match(/^[-+]?(\d)*-?([,\.]){0,1}-?(\d)+([E,e][\-+][\d]+)?%?$/)},function(c,d){return c=a(c),d=a(d),b(d,c)})}();</script>'; | |
// Styles | |
echo <<<DOC | |
<style> | |
body { | |
font-family: sans-serif; | |
} | |
th { | |
cursor: pointer; | |
text-align: left; | |
} | |
table {border-collapse: collapse;} | |
td {border: 1px solid #ccc;} | |
</style> | |
DOC; | |
foreach($xml as $suite) { | |
// For each suite | |
echo '<h1>' . $suite['name'] . '</h1>'; | |
echo '<p>' . (int)$suite['time'] . ' seconds</p>'; | |
echo '<table><thead><tr><th>Test</th><th table-sort-method="number" style="text-align: right;">Sec.</th><th style="text-align: center;">Stat.</th></tr></thead>'; | |
foreach($suite as $case) { | |
// For each case | |
$status = '<span style="color: green;">✓</span>'; | |
if((string)$case['errors'] !== '0') {$status = '<span style="color: red;">✗</span>';} | |
if((string)$case['skipped'] !== '0') {$status = '<span style="color: goldenrod;">⇒</span>';} | |
echo '<tr><td>' . $case['name'] . '</td><td style="text-align: right;">' . (int)$case['time'] . '</td><td style="text-align: center;">' . $status . '</td></tr>'; | |
} | |
echo '</table>'; | |
} | |
echo '<script>var tables = document.getElementsByTagName("table"); for(var i = 0; i < tables.length; i++) {new Tablesort(tables[i]);}</script>'; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment