Skip to content

armgit / mocha

Public Imported from GitHub
0

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

Fixes #47 Added support for showing test duration in HTML reporter

Brendan Nee6f405d93823b
diff --git a/lib/reporters/html.js b/lib/reporters/html.js
index 2c3791ce..b7ebcbfd 100644
--- a/lib/reporters/html.js
+++ b/lib/reporters/html.js
@@ -94,7 +94,7 @@ function HTML(runner) {
// test
if ('passed' == test.state) {
- var el = fragment('<div class="test pass"><h2>%e</h2></div>', test.title);
+ var el = fragment('<div class="test pass %e"><h2>%e<span class="duration">%ems</span></h2></div>', test.speed, test.title, test.duration);
} else if (test.pending) {
var el = fragment('<div class="test pass pending"><h2>%e</h2></div>', test.title);
} else {
diff --git a/mocha.css b/mocha.css
index b49d91d5..496e7f21 100644
--- a/mocha.css
+++ b/mocha.css
@@ -48,13 +48,35 @@ body {
font-family: arial;
}
+#mocha .test.pass.fast {
+ color: #468847;
+}
+
+#mocha .test.pass.medium {
+ color: #C09853;
+}
+
+#mocha .test.pass.slow {
+ color: #B94A48;
+}
+
#mocha .test.pass::before {
content: '✓';
font-size: 12px;
display: block;
float: left;
margin-right: 5px;
- color: #00c41c;
+}
+
+#mocha .test.pass .duration {
+ color: #999999;
+ font-style: italic;
+ padding-left: 7px;
+ font-size: 10px;
+}
+
+#mocha .test.pass.fast .duration {
+ display: none;
}
#mocha .test.pending {
diff --git a/mocha.js b/mocha.js
index b001169c..ea6485f1 100644
--- a/mocha.js
+++ b/mocha.js
@@ -1637,7 +1637,7 @@ function HTML(runner) {
// test
if ('passed' == test.state) {
- var el = fragment('<div class="test pass"><h2>%e</h2></div>', test.title);
+ var el = fragment('<div class="test pass %e"><h2>%e<span class="duration">%ems</span></h2></div>', test.speed, test.title, test.duration);
} else if (test.pending) {
var el = fragment('<div class="test pass pending"><h2>%e</h2></div>', test.title);
} else {
@@ -4109,4 +4109,4 @@ window.mocha = require('mocha');
return runner.run(fn);
};
})();
-})();
\ No newline at end of file
+})();