Skip to content

Commit

Permalink
Merge pull request #4 from adamgruber/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
adamgruber committed Feb 20, 2015
2 parents 0abc3cc + dbb4545 commit fee0fcc
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 6 deletions.
27 changes: 23 additions & 4 deletions lib/mochawesome.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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;
}

Expand All @@ -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.
Expand All @@ -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];
Expand All @@ -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) {
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -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"
Expand Down

0 comments on commit fee0fcc

Please sign in to comment.