☕️ Classic, reliable, trusted test framework for Node.js and the browser
Refactored to utilize utils.clean()
TJ Holowaychukd69ba34ac339
diff --git a/lib/reporters/doc.js b/lib/reporters/doc.jsindex cf7e7128..071f36aa 100644--- a/lib/reporters/doc.js+++ b/lib/reporters/doc.js@@ -50,25 +50,7 @@ function Doc(runner) {runner.on('pass', function(test){console.log('%s <dt>%s</dt>', indent(), test.title);- var code = utils.escape(clean(test.fn.toString()));+ var code = utils.escape(utils.clean(test.fn.toString()));console.log('%s <dd><pre><code>%s</code></pre></dd>', indent(), code);});}--/**- * Strip the function definition from `str`,- * and re-indent for pre whitespace.- */--function clean(str) {- str = str- .replace(/^function *\(.*\) *{/, '')- .replace(/\s+\}$/, '');-- var spaces = str.match(/^\n?( *)/)[1].length- , re = new RegExp('^ {' + spaces + '}', 'gm');-- str = str.replace(re, '');-- return str;-}\ No newline at end of filediff --git a/lib/reporters/html-cov.js b/lib/reporters/html-cov.jsindex 6669bb0d..bfb27ffd 100644--- a/lib/reporters/html-cov.js+++ b/lib/reporters/html-cov.js@@ -36,6 +36,13 @@ function HTMLCov(runner) {});}+/**+ * Return coverage class for `n`.+ *+ * @return {String}+ * @api private+ */+function coverageClass(n) {if (n >= 75) return 'high';if (n >= 50) return 'medium';diff --git a/lib/reporters/html.js b/lib/reporters/html.jsindex c3f21b93..f55733d7 100644--- a/lib/reporters/html.js+++ b/lib/reporters/html.js@@ -143,7 +143,7 @@ function HTML(runner) {// code// TODO: deferif (!test.pending) {- var pre = fragment('<pre><code>%e</code></pre>', clean(test.fn.toString()));+ var pre = fragment('<pre><code>%e</code></pre>', utils.clean(test.fn.toString()));el.appendChild(pre);pre.style.display = 'none';}@@ -201,24 +201,4 @@ function on(el, event, fn) {} else {el.attachEvent('on' + event, fn);}-}--/**- * Strip the function definition from `str`,- * and re-indent for pre whitespace.- */--function clean(str) {- str = str- .replace(/^function *\(.*\) *{/, '')- .replace(/\s+\}$/, '');-- var spaces = str.match(/^\n?( *)/)[1].length- , re = new RegExp('^ {' + spaces + '}', 'gm');-- str = str- .replace(re, '')- .replace(/^\s+/, '');-- return str;-}+}\ No newline at end of filediff --git a/lib/reporters/markdown.js b/lib/reporters/markdown.jsindex 7eeae856..111b111a 100644--- a/lib/reporters/markdown.js+++ b/lib/reporters/markdown.js@@ -78,7 +78,7 @@ function Markdown(runner) {});runner.on('pass', function(test){- var code = clean(test.fn.toString());+ var code = utils.clean(test.fn.toString());buf += test.title + '.\n';buf += '\n```js';buf += code + '\n';@@ -90,22 +90,4 @@ function Markdown(runner) {process.stdout.write(generateTOC(runner.suite));process.stdout.write(buf);});-}--/**- * Strip the function definition from `str`,- * and re-indent for pre whitespace.- */--function clean(str) {- str = str- .replace(/^function *\(.*\) *{/, '')- .replace(/\s+\}$/, '');-- var spaces = str.match(/^\n?( *)/)[1].length- , re = new RegExp('^ {' + spaces + '}', 'gm');-- str = str.replace(re, '');-- return str;}\ No newline at end of file