karma-mocha-reporter
Advanced tools
Comparing version
@@ -0,1 +1,11 @@ | ||
<a name="2.2.0"></a> | ||
# [2.2.0](https://github.com/litixsoft/karma-mocha-reporter/compare/v2.1.0...v2.2.0) (2016-09-19) | ||
### Features | ||
* add option "maxLogLines" to control the number of lines which are printed for the failures ([0c484df](https://github.com/litixsoft/karma-mocha-reporter/commit/0c484df)), closes [#75](https://github.com/litixsoft/karma-mocha-reporter/issues/75) | ||
<a name="2.1.0"></a> | ||
@@ -2,0 +12,0 @@ # [2.1.0](https://github.com/litixsoft/karma-mocha-reporter/compare/v2.0.5...v2.1.0) (2016-07-31) |
67
index.js
@@ -29,3 +29,3 @@ 'use strict'; | ||
*/ | ||
function repeatString (text, n) { | ||
function repeatString(text, n) { | ||
var res = []; | ||
@@ -79,2 +79,10 @@ var i; | ||
// init max number of log lines | ||
config.mochaReporter.maxLogLines = config.mochaReporter.maxLogLines || 999; | ||
if (isNaN(config.mochaReporter.maxLogLines)) { | ||
self.write(colors.warning.print('Option "config.mochaReporter.maxLogLines" must be of type number. Default value 999 is used!')); | ||
config.mochaReporter.maxLogLines = 999; | ||
} | ||
// check if mocha is installed when showDiff is enabled | ||
@@ -91,3 +99,3 @@ if (config.mochaReporter.showDiff) { | ||
function getLogSymbol (color) { | ||
function getLogSymbol(color) { | ||
return chalk.enabled ? color.print(color.symbol) : chalk.stripColor(color.symbol); | ||
@@ -102,6 +110,6 @@ } | ||
*/ | ||
function unifiedDiff (err) { | ||
function unifiedDiff(err) { | ||
var indent = ' '; | ||
function cleanUp (line) { | ||
function cleanUp(line) { | ||
if (line[0] === '+') { | ||
@@ -122,3 +130,3 @@ return indent + colors.success.print(line); | ||
function notBlank (line) { | ||
function notBlank(line) { | ||
return line !== null; | ||
@@ -143,3 +151,3 @@ } | ||
*/ | ||
function errorDiff (err, type) { | ||
function errorDiff(err, type) { | ||
var actual = err.actual; | ||
@@ -165,3 +173,3 @@ var expected = err.expected; | ||
*/ | ||
function pad (str, len) { | ||
function pad(str, len) { | ||
str = String(str); | ||
@@ -177,3 +185,3 @@ return Array(len - str.length + 1).join(' ') + str; | ||
*/ | ||
function inlineDiff (err) { | ||
function inlineDiff(err) { | ||
var msg = errorDiff(err, 'WordsWithSpace'); | ||
@@ -210,3 +218,3 @@ | ||
*/ | ||
function formatTimeInterval (time) { | ||
function formatTimeInterval(time) { | ||
var mins = Math.floor(time / 60000); | ||
@@ -229,7 +237,7 @@ var secs = (time - mins * 60000) / 1000; | ||
*/ | ||
function allChildItemsAreCompleted (items) { | ||
function allChildItemsAreCompleted(items) { | ||
var item; | ||
var isCompleted = true; | ||
Object.keys(items).forEach(function(key){ | ||
Object.keys(items).forEach(function (key) { | ||
item = items[key]; | ||
@@ -254,3 +262,3 @@ | ||
*/ | ||
function printItem (item, depth) { | ||
function printItem(item, depth) { | ||
// only print to output once | ||
@@ -294,3 +302,3 @@ if (item.name && !item.printed && (!item.skipped || !ignoreSkipped)) { | ||
*/ | ||
function print (suite, depth) { | ||
function print(suite, depth) { | ||
var keys = Object.keys(suite); | ||
@@ -331,3 +339,3 @@ var length = keys.length; | ||
*/ | ||
function printFailures (suite, depth) { | ||
function printFailures(suite, depth) { | ||
var keys = Object.keys(suite); | ||
@@ -363,6 +371,13 @@ var length = keys.length; | ||
item.log = item.log || []; | ||
var log = item.log[0].split('\n'); | ||
var linesToLog = config.mochaReporter.maxLogLines; | ||
var ii = 0; | ||
// set number of lines to output | ||
if (log.length < linesToLog) { | ||
linesToLog = log.length; | ||
} | ||
// print diff | ||
if (config.mochaReporter.showDiff && item.assertionErrors && item.assertionErrors[0]) { | ||
var log = item.log[0].split('\n'); | ||
var errorMessage = log.splice(0, 1)[0]; | ||
@@ -385,3 +400,3 @@ | ||
err.expected = JSON.parse(err.expected); | ||
} catch(e) {} | ||
} catch (e) { } | ||
} | ||
@@ -401,9 +416,9 @@ | ||
// print formatted stack trace after diff | ||
log.forEach(function (err) { | ||
line += colors.error.print(formatError(err)); | ||
}); | ||
for (ii; ii < linesToLog; ii++) { | ||
line += colors.error.print(formatError(log[ii])); | ||
} | ||
} else { | ||
item.log.forEach(function (err) { | ||
line += colors.error.print(formatError(err, repeatString(' ', depth))); | ||
}); | ||
for (ii; ii < linesToLog; ii++) { | ||
line += colors.error.print(formatError(log[ii], repeatString(' ', depth))); | ||
} | ||
} | ||
@@ -429,3 +444,3 @@ } | ||
*/ | ||
function listAllObjectProperties (obj) { | ||
function listAllObjectProperties(obj) { | ||
var objectToInspect; | ||
@@ -447,3 +462,3 @@ var result = []; | ||
*/ | ||
function getTestNounFor (testCount) { | ||
function getTestNounFor(testCount) { | ||
if (testCount === 1) { | ||
@@ -462,3 +477,3 @@ return 'test'; | ||
*/ | ||
function isReservedProperty (obj, property) { | ||
function isReservedProperty(obj, property) { | ||
return listAllObjectProperties(Object.getPrototypeOf(obj)).indexOf(property) > -1; | ||
@@ -473,3 +488,3 @@ } | ||
*/ | ||
function specComplete (browser, result) { | ||
function specComplete(browser, result) { | ||
// complete path of the test | ||
@@ -476,0 +491,0 @@ var path = [].concat(result.suite, result.description); |
{ | ||
"name": "karma-mocha-reporter", | ||
"description": "Karma reporter with mocha style logging.", | ||
"version": "2.1.0", | ||
"homepage": "http://www.litixsoft.de/modules-karmamochareporter", | ||
"version": "2.2.0", | ||
"homepage": "http://www.litixsoft.de/index.php?lang=en#modules", | ||
"author": "Litixsoft GmbH <info@litixsoft.de> (http://www.litixsoft.de)", | ||
@@ -39,3 +39,6 @@ "maintainers": [ | ||
"karma-reporter", | ||
"mocha" | ||
"mocha", | ||
"chai", | ||
"diff", | ||
"symbols" | ||
], | ||
@@ -62,4 +65,4 @@ "license": "MIT", | ||
"grunt-karma": "^2.0.0", | ||
"grunt-shell": "^1.3.0", | ||
"jasmine-core": "^2.4.1", | ||
"grunt-shell": "^1.3.1", | ||
"jasmine-core": "^2.5.2", | ||
"karma": ">=0.13", | ||
@@ -71,11 +74,11 @@ "karma-chai": "^0.1.0", | ||
"karma-ie-launcher": "*", | ||
"karma-jasmine": "^1.0.2", | ||
"karma-mocha": "^1.0.1", | ||
"karma-jasmine": "*", | ||
"karma-mocha": "*", | ||
"karma-opera-launcher": "*", | ||
"karma-phantomjs-launcher": "^1.0.1", | ||
"karma-phantomjs-launcher": "*", | ||
"karma-safari-launcher": "*", | ||
"karma-safaritechpreview-launcher": "*", | ||
"load-grunt-tasks": "^3.5.0", | ||
"mocha": "^2.5.3", | ||
"phantomjs-prebuilt": "^2.1.9" | ||
"load-grunt-tasks": "^3.5.2", | ||
"mocha": "^3.0.2", | ||
"phantomjs-prebuilt": "^2.1.12" | ||
}, | ||
@@ -82,0 +85,0 @@ "dependencies": { |
@@ -55,3 +55,2 @@ # karma-mocha-reporter | ||
`error` | error messages | red | ||
`false` | disable colors | | ||
@@ -86,2 +85,19 @@ ```js | ||
To disable the colors please use the `colors` option in the karma config. | ||
```js | ||
// karma.conf.js | ||
module.exports = function(config) { | ||
config.set({ | ||
frameworks: ['jasmine'], | ||
// reporters configuration | ||
reporters: ['mocha'], | ||
// disable colors | ||
colors: false | ||
}); | ||
}; | ||
``` | ||
### symbols | ||
@@ -220,3 +236,8 @@ **Type:** Object | ||
### maxLogLines | ||
**Type:** Number | ||
Let's you set the maximum number of lines which are printed for a failure. The default value is 999. Helps to cut long stack traces. | ||
## Contributing | ||
@@ -223,0 +244,0 @@ In lieu of a formal styleguide take care to maintain the existing coding style. Lint and test your code using [grunt](http://gruntjs.com/). |
58090
2.62%1059
1.15%271
8.4%