Verified Commit ba7f7c0b authored by Camil Staps's avatar Camil Staps 🚀

Add test results HTML file

parent 5bd08daa
node_modules/
package-lock.json
test_results.html
......@@ -63,6 +63,20 @@ function parseResult(result) {
return parsedResult;
}
function resultToHTML(result) {
var html = '';
var result = result.split('\n');
for (var i in result) {
var elems = result[i].split('\t');
var cls = elems.shift().replace(/,/g, ' ');
var content = elems.join('\t').replace(/\\n/g, '\n');
html += '<span class="' + cls + '">' + content + '</span>';
}
return html;
}
var htmlResults;
function runTestCase(testcase) {
var f = undefined;
......@@ -78,7 +92,15 @@ function runTestCase(testcase) {
var result = f(testcase.test, function(span,cls,str){return span}, testcase.entry);
result = parseResult(result);
if (result == testcase.result) {
var passed = result == testcase.result;
htmlResults += '<tr class="testcase ' + (passed ? 'passed' : 'failed') + '">';
htmlResults += '<td>' + testcase.name + '</td>';
htmlResults += '<td><pre>' + resultToHTML(testcase.result) + '</pre></td>';
htmlResults += '<td><pre>' + resultToHTML(result) + '</pre></td>';
htmlResults += '</tr>';
if (passed) {
process.stderr.write(GREEN + testcase.name + ' passed.' + RESET + '\n');
} else {
process.stderr.write(RED + testcase.name + ' failed.' + RESET + '\n');
......@@ -94,12 +116,39 @@ function runTestCase(testcase) {
});
process.stderr.write('\n');
}
return passed;
}
fs.readdir('tests', function(err, files) {
htmlResults = '<!DOCTYPE html>\
<html>\
<head>\
<link rel="stylesheet" href="clean.css" type="text/css"/>\
<link rel="stylesheet" href="test_results.css" type="text/css"/>\
<title>clean.js test results</title>\
</head>\
<body>\
<h1>clean.js test results</h1>\
<h3 class="{{{RESULTCLASS}}}">{{{RESULTS}}}</h3>\
<table cellspacing="0">\
<tr><th>Test case</th><th>Expected result</th><th>Actual result</th></tr>';
var passed = 0;
var failed = 0;
for (var i in files) {
var contents = fs.readFileSync(path.join('tests', files[i])).toString();
var testcase = parseTestCase(files[i], contents);
runTestCase(testcase);
if (runTestCase(testcase))
passed++;
else
failed++;
}
htmlResults = htmlResults.replace('{{{RESULTCLASS}}}', failed > 0 ? 'failed' : 'passed');
htmlResults = htmlResults.replace('{{{RESULTS}}}', passed + ' passed, ' + failed + ' failed');
htmlResults += '</table></body></html>';
fs.writeFileSync('test_results.html', htmlResults);
});
h1, h3 {
text-align: center;
}
h3.failed {
color: #e32;
}
h3.passed {
color: #181;
}
table {
border-collapse: separate;
border-spacing: 0 2px;
margin: 0 auto;
}
tr {
padding-bottom: 10px;
}
td {
border-color: #666;
border-style: solid;
border-width: 1px 0;
padding: 0 2em 0 .5em;
vertical-align: top;
}
tr.failed td:first-child {
background-color: #e32;
}
tr.passed td:first-child {
background-color: #181;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment