Skip to content

armgit / mocha

Public Imported from GitHub
0

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

Allow override of test links in HTML reporter (close #776)

Teddy Zeenny4c16dbf22878
diff --git a/lib/reporters/html.js b/lib/reporters/html.js
index f09279be..873f024d 100644
--- a/lib/reporters/html.js
+++ b/lib/reporters/html.js
@@ -19,7 +19,7 @@ var Date = global.Date
, clearInterval = global.clearInterval;
/**
- * Expose `Doc`.
+ * Expose `HTML`.
*/
exports = module.exports = HTML;
@@ -36,7 +36,7 @@ var statsTemplate = '<ul id="mocha-stats">'
+ '</ul>';
/**
- * Initialize a new `Doc` reporter.
+ * Initialize a new `HTML` reporter.
*
* @param {Runner} runner
* @api public
@@ -101,7 +101,7 @@ function HTML(runner, root) {
if (suite.root) return;
// suite
- var url = '?grep=' + encodeURIComponent(suite.fullTitle());
+ var url = self.suiteURL(suite);
var el = fragment('<li class="suite"><h1><a href="%s">%s</a></h1></li>', url, escape(suite.title));
// container
@@ -132,7 +132,8 @@ function HTML(runner, root) {
// test
if ('passed' == test.state) {
- var el = fragment('<li class="test pass %e"><h2>%e<span class="duration">%ems</span> <a href="?grep=%e" class="replay">‣</a></h2></li>', test.speed, test.title, test.duration, encodeURIComponent(test.fullTitle()));
+ var url = self.testURL(test);
+ var el = fragment('<li class="test pass %e"><h2>%e<span class="duration">%ems</span> <a href="%s" class="replay">‣</a></h2></li>', test.speed, test.title, test.duration, url);
} else if (test.pending) {
var el = fragment('<li class="test pass pending"><h2>%e</h2></li>', test.title);
} else {
@@ -177,6 +178,26 @@ function HTML(runner, root) {
});
}
+/**
+ * Provide suite URL
+ *
+ * @param {Object} [suite]
+ */
+
+HTML.prototype.suiteURL = function(suite){
+ return '?grep=' + encodeURIComponent(suite.fullTitle());
+};
+
+/**
+ * Provide test URL
+ *
+ * @param {Object} [test]
+ */
+
+HTML.prototype.testURL = function(test){
+ return '?grep=' + encodeURIComponent(test.fullTitle());
+};
+
/**
* Display error `msg`.
*/