jest-diff
Advanced tools
Comparing version 14.3.1-alpha.410cb91a to 14.3.2-alpha.83c25417
@@ -29,5 +29,3 @@ /** | ||
function diffStrings(a, b, options) { | ||
const multiline = a.match(/[\r\n]/) !== -1 && b.indexOf('\n') !== -1; | ||
let isDifferent = false; | ||
let result; | ||
@@ -38,34 +36,21 @@ // `diff` uses the Myers LCS diff algorithm which runs in O(n+d^2) time | ||
// whenever linebreaks are involved. | ||
if (multiline) { | ||
result = jsDiff.diffLines(a, b).map(part => { | ||
if (part.added || part.removed) { | ||
isDifferent = true; | ||
} | ||
const result = jsDiff.diffLines(a, b).map(part => { | ||
if (part.added || part.removed) { | ||
isDifferent = true; | ||
} | ||
const lines = part.value.split('\n'); | ||
const color = part.added ? | ||
chalk.red : | ||
part.removed ? chalk.green : chalk.white; | ||
const lines = part.value.split('\n'); | ||
const color = part.added ? | ||
chalk.red : | ||
part.removed ? chalk.green : chalk.white; | ||
if (lines[lines.length - 1] === '') { | ||
lines.pop(); | ||
} | ||
if (lines[lines.length - 1] === '') { | ||
lines.pop(); | ||
} | ||
return lines.map(line => { | ||
const mark = color(part.added ? '+' : part.removed ? '-' : ' '); | ||
return mark + ' ' + color(line) + '\n'; | ||
}).join(''); | ||
}).join('').trim(); | ||
} else { | ||
result = jsDiff.diffChars(a, b).map(part => { | ||
if (part.added || part.removed) { | ||
isDifferent = true; | ||
} | ||
const color = part.added ? | ||
chalk.green : | ||
part.removed ? chalk.red : chalk.dim; | ||
return color(part.value); | ||
return lines.map(line => { | ||
const mark = color(part.added ? '+' : part.removed ? '-' : ' '); | ||
return mark + ' ' + color(line) + '\n'; | ||
}).join(''); | ||
} | ||
}).join('').trim(); | ||
@@ -72,0 +57,0 @@ if (isDifferent) { |
@@ -40,3 +40,7 @@ /** | ||
case 'string': | ||
return diffStrings(String(a), String(b), options); | ||
const multiline = a.match(/[\r\n]/) !== -1 && b.indexOf('\n') !== -1; | ||
if (multiline) { | ||
return diffStrings(String(a), String(b), options); | ||
} | ||
return null; | ||
case 'number': | ||
@@ -43,0 +47,0 @@ case 'boolean': |
{ | ||
"name": "jest-diff", | ||
"version": "14.3.1-alpha.410cb91a", | ||
"version": "14.3.2-alpha.83c25417", | ||
"repository": { | ||
@@ -13,3 +13,3 @@ "type": "git", | ||
"diff": "^3.0.0", | ||
"jest-matcher-utils": "^14.3.1-alpha.410cb91a", | ||
"jest-matcher-utils": "^14.3.2-alpha.83c25417", | ||
"pretty-format": "^3.6.0" | ||
@@ -16,0 +16,0 @@ }, |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Unidentified License
License(Experimental) Something that seems like a license was found, but its contents could not be matched with a known license.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Unidentified License
License(Experimental) Something that seems like a license was found, but its contents could not be matched with a known license.
Found 1 instance in 1 package
4218
100
+ Addedjest-matcher-utils@14.3.2-alpha.83c25417(transitive)
- Removedjest-matcher-utils@14.3.1-alpha.410cb91a(transitive)