diff --git a/lib/mochawesome.js b/lib/mochawesome.js index 1976de4..4798529 100755 --- a/lib/mochawesome.js +++ b/lib/mochawesome.js @@ -10,7 +10,6 @@ var util = require('util'), templates = require('./templates.js'); var Base = mocha.reporters.Base, - utils = mocha.utils, generateReport = reportGen.generateReport, saveToFile = reportGen.saveToFile; @@ -237,7 +236,7 @@ function cleanTest (test) { var code = '', err = test.err ? _.pick( test.err, ['name', 'message', 'stack'] ) : test.err; if(test.fn){ - code = utils.clean(test.fn.toString()); + code = cleanCode(test.fn.toString()); code = Highlight.highlightAuto(code, ['javascript']).value; } @@ -263,6 +262,26 @@ function cleanTest (test) { return cleaned; } +/** + * Strip the function definition from `str`, + * and re-indent for pre whitespace. + */ + +function cleanCode (str) { + str = str + .replace(/\r\n?|[\n\u2028\u2029]/g, '\n').replace(/^\uFEFF/, '') + .replace(/^function *\(.*\) *{|\(.*\) *=> *{?/, '') + .replace(/\s+\}$/, ''); + + var spaces = str.match(/^\n?( *)/)[1].length, + tabs = str.match(/^\n?(\t*)/)[1].length, + re = new RegExp('^\n?' + (tabs ? '\t' : ' ') + '{' + (tabs ? tabs : spaces) + '}', 'gm'); + + str = str.replace(re, ''); + str = str.replace(/^\s+|\s+$/g, ''); + return str; +} + /** * Remove all properties from an object except * those that are in the propsToKeep array. @@ -272,7 +291,7 @@ function cleanTest (test) { * @api private */ -function removeAllPropsFromObjExcept(obj, propsToKeep) { +function removeAllPropsFromObjExcept (obj, propsToKeep) { _.forOwn(obj, function(val, prop) { if (propsToKeep.indexOf(prop) === -1) { delete obj[prop]; @@ -287,7 +306,7 @@ function removeAllPropsFromObjExcept(obj, propsToKeep) { * @api private */ -function _getPercentClass(pct) { +function _getPercentClass (pct) { if (pct <= 50) { return 'danger'; } else if (pct > 50 && pct < 80) { diff --git a/package.json b/package.json index 26182af..2b00f34 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "mochawesome", - "version": "1.0.4", + "version": "1.0.5", "description": "A Gorgeous HTML/CSS Reporter for Mocha.js", "scripts": { "test": "gulp build" @@ -25,7 +25,7 @@ "highlight.js": "^8.4.0", "json-stringify-safe": "^5.0.0", "lodash": "^3.1.0", - "mocha": "^2.1.0", + "mocha": "*", "moment": "^2.9.0", "ncp": "^1.0.1", "node-uuid": "^1.4.1"