karma-jasmine-diff-reporter
Advanced tools
Comparing version 0.6.2 to 0.6.3
### Changelog | ||
- 0.6.3 - Revert 0.6.2 and bring diffs for jasmine.objectCOntaining back, even though it's buggy | ||
- 0.6.2 - Do not diff with jasmine.objectContaining | ||
@@ -4,0 +5,0 @@ - 0.6.1 - Sort object properties before comparing |
@@ -44,12 +44,4 @@ describe('Matcher', function () { | ||
it('should NOT diff with jasmine.objectContaining', function () { | ||
var a = { | ||
foo: 42, | ||
bar: 'baz' | ||
}; | ||
expect(a).toEqual(jasmine.objectContaining({ foo: 43 })); | ||
}); | ||
}); | ||
}); |
{ | ||
"name": "karma-jasmine-diff-reporter", | ||
"version": "0.6.2", | ||
"version": "0.6.3", | ||
"description": "Karma reporter to highlight diffs of failed equality expectations for Jasmine", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -21,3 +21,3 @@ 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) | ||
*Note: there are matchers like `toBeTruthy` or `toBeDefined` in Jasmine, but they won't be highlighted because the messages outputed are `Expected 0 to be truthy` or `Expected undefined to be defined` respectively, and words `truthy` and `defined` are not the part of JavaScript. When using jasmine.objectContaining() message won't be highlighted too.* | ||
*Note: there are matchers like `toBeTruthy` or `toBeDefined` in Jasmine, but they won't be highlighted because the messages outputed are `Expected 0 to be truthy` or `Expected undefined to be defined` respectively, and words `truthy` and `defined` are not the part of JavaScript.* | ||
@@ -24,0 +24,0 @@ *Note: if you use custom matchers, they also might be accidently highlighted, if their messages match the patterns I use to extract the data for comparison. There is no a solution to disable it yet. You can find more about custom matchers below.* |
@@ -114,24 +114,2 @@ 'use strict'; | ||
function findIndexUntil(string, sub, predicate) { | ||
var index = 0; | ||
do { | ||
index = string.indexOf(sub, index - 1); | ||
if (predicate(index, string)) { | ||
break; | ||
} | ||
} while (index !== -1); | ||
return index; | ||
} | ||
function findLastIndexUntil(string, sub, predicate) { | ||
var index = string.length; | ||
do { | ||
index = string.lastIndexOf(sub, index - 1); | ||
if (predicate(index, string)) { | ||
break; | ||
} | ||
} while (index !== -1); | ||
return index; | ||
} | ||
function pretty(str, indent, commonIndent, options) { | ||
@@ -224,5 +202,9 @@ var out = ''; | ||
// of a stack trace for sure. | ||
var dotIndex = findLastIndexUntil(message, '.\n', function (index) { | ||
return !isInsideString(message, index); | ||
}); | ||
var dotIndex = message.length; | ||
do { | ||
dotIndex = message.lastIndexOf('.\n', dotIndex - 1); | ||
if (!isInsideString(message, dotIndex)) { | ||
break; | ||
} | ||
} while (dotIndex != -1); | ||
@@ -337,55 +319,34 @@ // If stacktrace start position found - separate it from Jasmine message | ||
// Find out if jasmine.objectContaining is used | ||
var objectContainingIndex = findIndexUntil( | ||
expected, | ||
'<jasmine.objectContaining', | ||
function (index) { | ||
return !isInsideString(expected, index); | ||
} | ||
); | ||
var hasObjectContaining = objectContainingIndex > -1; | ||
var diff = jsDiff.diffWordsWithSpace(expectedTmp, actualTmp); | ||
var expectedDiff = '', actualDiff = ''; | ||
// If jasmine.objectContaining is used do not diff the message, but still | ||
// use pretty and multiline options if they are turned on. | ||
if (hasObjectContaining) { | ||
diff.forEach(function (part) { | ||
expectedDiff = expectedTmp; | ||
actualDiff = actualTmp; | ||
var value = part.value; | ||
var formattedValue = value; | ||
} else { | ||
if (part.added) { | ||
var diff = jsDiff.diffWordsWithSpace(expectedTmp, actualTmp); | ||
formattedValue = formattedValue.replace(/\S+/g, formatter.actual); | ||
formattedValue = formattedValue.replace(/\s+/g, formatter.actualWhitespace); | ||
diff.forEach(function (part) { | ||
actualDiff += formattedValue; | ||
var value = part.value; | ||
var formattedValue = value; | ||
} else if (part.removed) { | ||
if (part.added) { | ||
formattedValue = formattedValue.replace(/\S+/g, formatter.expected); | ||
formattedValue = formattedValue.replace(/\s+/g, formatter.expectedWhitespace); | ||
formattedValue = formattedValue.replace(/\S+/g, formatter.actual); | ||
formattedValue = formattedValue.replace(/\s+/g, formatter.actualWhitespace); | ||
expectedDiff += formattedValue; | ||
actualDiff += formattedValue; | ||
} else { | ||
} else if (part.removed) { | ||
// add unmodified part to both outputs | ||
expectedDiff += formatter.defaults(value); | ||
actualDiff += formatter.defaults(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(value); | ||
actualDiff += formatter.defaults(value); | ||
} | ||
}); | ||
} | ||
// Use multiline options declared earlier and append newlines/indent to result | ||
@@ -392,0 +353,0 @@ if (multilineOptions) { |
@@ -23,4 +23,2 @@ 'use strict'; | ||
// Note: this behavior is a bit weird comparing to toBeUndefined and others - | ||
// that equal parts are highlighted with default colors. Not critical | ||
test('toEqual: no diff for equal objects', function (assert) { | ||
@@ -40,15 +38,1 @@ var input = | ||
}); | ||
test('toEqual: no diff for objectContaining', function (assert) { | ||
var input = | ||
"Expected Object({ foo: 'bar' }) to equal " + | ||
"<jasmine.objectContaining(Object({ foo: 'qux' }))>."; | ||
var expected = | ||
"Expected Object({ foo: 'bar' }) to equal " + | ||
"<jasmine.objectContaining(Object({ foo: 'qux' }))>."; | ||
var out = diff(input, formatter); | ||
assert.equal(out, expected); | ||
assert.end(); | ||
}); |
71789
1757