Skip to content

armgit / mocha

Public Imported from GitHub
0

☕️ Classic, reliable, trusted test framework for Node.js and the browser

added passes/failures toggles

Ian Storm Taylor1bbc1e3738a1
diff --git a/lib/reporters/html.js b/lib/reporters/html.js
index da44579d..f3177673 100644
--- a/lib/reporters/html.js
+++ b/lib/reporters/html.js
@@ -30,8 +30,8 @@ exports = module.exports = HTML;
var statsTemplate = '<ul id="stats">'
+ '<li class="progress"><canvas width="40" height="40"></canvas></li>'
- + '<li class="passes">passes: <em>0</em></li>'
- + '<li class="failures">failures: <em>0</em></li>'
+ + '<li class="passes"><a>passes:</a> <em>0</em></li>'
+ + '<li class="failures"><a>failures:</a> <em>0</em></li>'
+ '<li class="duration">duration: <em>0</em>s</li>'
+ '</ul>';
@@ -52,7 +52,9 @@ function HTML(runner) {
, stat = fragment(statsTemplate)
, items = stat.getElementsByTagName('li')
, passes = items[1].getElementsByTagName('em')[0]
+ , passesLink = items[1].getElementsByTagName('a')[0]
, failures = items[2].getElementsByTagName('em')[0]
+ , failuresLink = items[2].getElementsByTagName('a')[0]
, duration = items[3].getElementsByTagName('em')[0]
, canvas = stat.getElementsByTagName('canvas')[0]
, report = fragment('<ul id="report"></ul>')
@@ -67,6 +69,16 @@ function HTML(runner) {
if (!root) return error('#mocha div missing, add it to your document');
+ // passes/failures toggles
+ on(passesLink, 'click', function () {
+ var className = /pass/.test(report.className) ? '' : ' pass';
+ report.className = report.className.replace(/fail|pass/g, '') + className;
+ });
+ on(failuresLink, 'click', function () {
+ var className = /fail/.test(report.className) ? '' : ' fail';
+ report.className = report.className.replace(/fail|pass/g, '') + className;
+ });
+
root.appendChild(stat);
root.appendChild(report);
diff --git a/mocha.css b/mocha.css
index cdfea1a2..2a574e5d 100644
--- a/mocha.css
+++ b/mocha.css
@@ -143,6 +143,14 @@ body {
-webkit-box-shadow: 0 1px 3px #eee;
}
+#report.pass .test.fail {
+ display: none;
+}
+
+#report.fail .test.pass {
+ display: none;
+}
+
#error {
color: #c00;
font-size: 1.5 em;