karma-jasmine-diff-reporter
Advanced tools
Comparing version 0.5.0 to 0.6.0
@@ -32,2 +32,6 @@ describe('Matcher', function () { | ||
it('should diff strings with single space diff', function () { | ||
expect('foo bar').toBe('foo bar'); | ||
}); | ||
it('should diff arrays', function () { | ||
@@ -34,0 +38,0 @@ var a = [1, 2, 3]; |
{ | ||
"name": "karma-jasmine-diff-reporter", | ||
"version": "0.5.0", | ||
"version": "0.6.0", | ||
"description": "Karma reporter to highlight diffs of failed equality expectations for Jasmine", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -112,8 +112,10 @@ karma-jasmine-diff-reporter [![Build status](https://travis-ci.org/mradionov/karma-jasmine-diff-reporter.svg?branch=master)](https://travis-ci.org/mradionov/karma-jasmine-diff-reporter) | ||
color: { | ||
expectedBg: 'bgYellow', // default 'bgRed' | ||
expectedFg: 'black', // default 'white' | ||
actualBg: 'bgCyan', // default 'bgGreen' | ||
actualFg: 'red', // default 'white', | ||
defaultBg: 'white', // default - none | ||
defaultFg: 'grey' // default - none | ||
expectedBg: 'bgYellow', // default 'bgRed' | ||
expectedFg: 'black', // default 'white' | ||
actualBg: 'bgCyan', // default 'bgGreen' | ||
actualFg: 'red', // default 'white', | ||
defaultBg: 'white', // default - none | ||
defaultFg: 'grey' // default - none, | ||
expectedWhitespaceBg: 'bgYellow', // default 'bgRed' | ||
actualWhitespaceBg: 'bgCyan' // default 'bgGreen' | ||
} | ||
@@ -130,5 +132,7 @@ } | ||
Defaults for "expected" message is red background with white text and for "actual" - green background with white text. Default background and foreground is for a part of Jasmine object that was not changed, it allows to highlight the rest of the object and distinguish it from matcher text. | ||
* Defaults for "expected" message is red background with white text and for "actual" - green background with white text. | ||
* `defaultBg` and `defaultFg` - for parts of the diff that were not changed, it allows to highlight the rest of the object and distinguish it from matcher text | ||
* `expectedWhitespaceBg` and `actualWhitespaceBg` - for the cases when you have a diff background of the same color as a terminal and only foreground color is used to identify diffs. In this case whitespace diffs won't be visible, when diff background has the same color as a terminal. To workaround it, it is possible to set a separate background for whitespace only using these options. | ||
To use default color use empty value: | ||
To use default terminal color use empty value: | ||
```js | ||
@@ -320,13 +324,4 @@ // karma.conf.js | ||
### Changelog | ||
### License | ||
- 0.5.0 - Added JSON option. Fixed pretty print for Karma 1.x | ||
- 0.4.0 - Add multiline feature, add tests | ||
- 0.3.4 - Remove weird characters around strings in Windows terminals | ||
- 0.3.3 - Detect stack trace for PhantomJS | ||
- 0.3.2 - Override default colors | ||
- 0.3.1 - Detect newlines in strings | ||
- 0.3.0 - Pretty print, default color | ||
- 0.2.2 - Fix duplicate console.logs | ||
- 0.2.0 - Diff for custom matchers | ||
- 0.1.0 - Initial | ||
[MIT](LICENSE) |
@@ -10,2 +10,7 @@ 'use strict'; | ||
function getOwnProperty(object, prop, defaultValue) { | ||
return object.hasOwnProperty(prop) ? object[prop] : defaultValue; | ||
} | ||
function createColorFormatter(options) { | ||
@@ -33,4 +38,4 @@ options = options || {}; | ||
var styles = [ | ||
options.hasOwnProperty('actualBg') ? options.actualBg : 'bgGreen', | ||
options.hasOwnProperty('actualFg') ? options.actualFg : 'white' | ||
getOwnProperty(options, 'actualBg', 'bgGreen'), | ||
getOwnProperty(options, 'actualFg', 'white') | ||
]; | ||
@@ -42,4 +47,4 @@ return addStyles(string, styles); | ||
var styles = [ | ||
options.hasOwnProperty('expectedBg') ? options.expectedBg : 'bgRed', | ||
options.hasOwnProperty('expectedFg') ? options.expectedFg : 'white' | ||
getOwnProperty(options, 'expectedBg', 'bgRed'), | ||
getOwnProperty(options, 'expectedFg', 'white') | ||
]; | ||
@@ -57,6 +62,22 @@ return addStyles(string, styles); | ||
function actualWhitespace(string) { | ||
var styles = [ | ||
getOwnProperty(options, 'actualWhitespaceBg', 'bgGreen') | ||
]; | ||
return addStyles(string, styles); | ||
} | ||
function expectedWhitespace(string) { | ||
var styles = [ | ||
getOwnProperty(options, 'expectedWhitespaceBg', 'bgRed') | ||
]; | ||
return addStyles(string, styles); | ||
} | ||
return { | ||
actual: actual, | ||
expected: expected, | ||
defaults: defaults | ||
defaults: defaults, | ||
actualWhitespace: actualWhitespace, | ||
expectedWhitespace: expectedWhitespace | ||
}; | ||
@@ -63,0 +84,0 @@ } |
@@ -323,15 +323,24 @@ 'use strict'; | ||
var value = part.value; | ||
var formattedValue = value; | ||
if (part.added) { | ||
actualDiff += formatter.actual(part.value); | ||
formattedValue = formattedValue.replace(/\S+/g, formatter.actual); | ||
formattedValue = formattedValue.replace(/\s+/g, formatter.actualWhitespace); | ||
actualDiff += formattedValue; | ||
} else if (part.removed) { | ||
expectedDiff += formatter.expected(part.value); | ||
formattedValue = formattedValue.replace(/\S+/g, formatter.expected); | ||
formattedValue = formattedValue.replace(/\s+/g, formatter.expectedWhitespace); | ||
expectedDiff += formattedValue; | ||
} else { | ||
// add unmodified part to both outputs | ||
expectedDiff += formatter.defaults(part.value); | ||
actualDiff += formatter.defaults(part.value); | ||
expectedDiff += formatter.defaults(value); | ||
actualDiff += formatter.defaults(value); | ||
@@ -338,0 +347,0 @@ } |
@@ -17,6 +17,16 @@ 'use strict'; | ||
function actualWhitespace(string) { | ||
return '<aw>' + string + '</aw>'; | ||
} | ||
function expectedWhitespace(string) { | ||
return '<ew>' + string + '</ew>'; | ||
} | ||
return { | ||
actual: actual, | ||
expected: expected, | ||
defaults: defaults | ||
defaults: defaults, | ||
actualWhitespace: actualWhitespace, | ||
expectedWhitespace: expectedWhitespace | ||
}; | ||
@@ -23,0 +33,0 @@ } |
@@ -70,4 +70,4 @@ 'use strict'; | ||
var expected = | ||
"Expected <d>'space</d><a> </a><d>space'</d>" + | ||
" to be <d>'space</d><e>\n</e><d>space'</d>." + | ||
"Expected <d>'space</d><aw> </aw><d>space'</d>" + | ||
" to be <d>'space</d><ew>\n</ew><d>space'</d>." + | ||
stack; | ||
@@ -87,4 +87,4 @@ | ||
var expected = | ||
"Expected <d>'space.</d><a> </a><d>dot'</d>" + | ||
" to be <d>'space.</d><e>\n</e><d>dot'</d>." + | ||
"Expected <d>'space.</d><aw> </aw><d>dot'</d>" + | ||
" to be <d>'space.</d><ew>\n</ew><d>dot'</d>." + | ||
stack; | ||
@@ -119,3 +119,3 @@ | ||
var expected = | ||
"Expected <a>undefined</a> to be <e>'space\nspace'</e>." + | ||
"Expected <a>undefined</a> to be <e>'space</e><ew>\n</ew><e>space'</e>." + | ||
stack; | ||
@@ -122,0 +122,0 @@ |
@@ -19,3 +19,3 @@ 'use strict'; | ||
" but it threw" + | ||
" <a>ReferenceError</a><d>: </d><a>a is not defined</a>." + | ||
" <a>ReferenceError</a><d>: </d><a>a</a><aw> </aw><a>is</a><aw> </aw><a>not</a><aw> </aw><a>defined</a>." + | ||
stack; | ||
@@ -22,0 +22,0 @@ |
@@ -66,3 +66,3 @@ 'use strict'; | ||
"\n" + | ||
" <a>ReferenceError</a><d>: </d><a>a is not defined</a>\n" + | ||
" <a>ReferenceError</a><d>: </d><a>a</a><aw> </aw><a>is</a><aw> </aw><a>not</a><aw> </aw><a>defined</a>\n" + | ||
"\n" + | ||
@@ -69,0 +69,0 @@ "." + |
69301
35
1694
325