jest-diff
Advanced tools
Comparing version 14.2.2-alpha.22bd3c33 to 14.3.0-alpha.d13c163e
@@ -14,9 +14,17 @@ /** | ||
const chalk = require('chalk'); | ||
const jsDiff = require('diff'); | ||
const jsDiff = require('diff');var _require = | ||
const ANNOTATION = `${ chalk.red('- expected') } ${ chalk.green('+ actual') }\n\n`; | ||
const NO_DIFF_MESSAGE = require('./constants.js').NO_DIFF_MESSAGE; | ||
require('./constants.js');const NO_DIFF_MESSAGE = _require.NO_DIFF_MESSAGE; | ||
const getAnnotation = options => | ||
chalk.green('- ' + (options && options.aAnnotation || 'Expected')) + '\n' + | ||
chalk.red('+ ' + (options && options.bAnnotation || 'Received')) + '\n\n'; | ||
// diff characters if oneliner and diff lines if multiline | ||
function diffStrings(a, b) { | ||
function diffStrings(a, b, options) { | ||
const multiline = a.match(/[\r\n]/) !== -1 && b.indexOf('\n') !== -1; | ||
@@ -38,4 +46,4 @@ let isDifferent = false; | ||
const color = part.added ? | ||
chalk.green : | ||
part.removed ? chalk.red : chalk.white; | ||
chalk.red : | ||
part.removed ? chalk.green : chalk.white; | ||
@@ -47,8 +55,6 @@ if (lines[lines.length - 1] === '') { | ||
return lines.map(line => { | ||
const mark = part.added ? | ||
chalk.green('+') : | ||
part.removed ? chalk.red('-') : ' '; | ||
const mark = color(part.added ? '+' : part.removed ? '-' : ' '); | ||
return mark + ' ' + color(line) + '\n'; | ||
}).join(''); | ||
}).join(''); | ||
}).join('').trim(); | ||
} else { | ||
@@ -68,3 +74,3 @@ result = jsDiff.diffChars(a, b).map(part => { | ||
if (isDifferent) { | ||
return ANNOTATION + result; | ||
return getAnnotation(options) + result; | ||
} else { | ||
@@ -71,0 +77,0 @@ return NO_DIFF_MESSAGE; |
@@ -13,2 +13,4 @@ /** | ||
const chalk = require('chalk'); | ||
@@ -24,3 +26,3 @@ const diffStrings = require('./diffStrings');var _require = | ||
// with green and red. (similar to how github does code diffing) | ||
function diff(a, b) { | ||
function diff(a, b, options) { | ||
if (a === b) { | ||
@@ -31,7 +33,6 @@ return NO_DIFF_MESSAGE; | ||
if (getType(a) !== getType(b)) { | ||
return chalk.reset.gray( | ||
'Comparing different types of values.\n' + | ||
`Actual: '${ chalk.cyan(getType(b)) }'` + | ||
', ' + | ||
`Expected: '${ chalk.cyan(getType(a)) }'`); | ||
return ( | ||
'Comparing two different types of values:\n' + | ||
` Expected: ${ chalk.green(getType(a)) }\n` + | ||
` Received: ${ chalk.red(getType(b)) }`); | ||
@@ -42,12 +43,10 @@ } | ||
case 'string': | ||
return diffStrings(String(a), String(b)); | ||
return diffStrings(String(a), String(b), options); | ||
case 'number': | ||
case 'boolean': | ||
return chalk.gray('Actual: ') + chalk.red(b) + | ||
'\n' + | ||
chalk.gray('Expected: ') + chalk.green(a); | ||
return null; | ||
default: | ||
return diffStrings( | ||
prettyFormat(a, { plugins: [jsxLikeExtension] }), | ||
prettyFormat(b, { plugins: [jsxLikeExtension] }));} | ||
prettyFormat(a, { plugins: [jsxLikeExtension] }, options), | ||
prettyFormat(b, { plugins: [jsxLikeExtension] }, options));} | ||
@@ -54,0 +53,0 @@ |
{ | ||
"name": "jest-diff", | ||
"version": "14.2.2-alpha.22bd3c33", | ||
"version": "14.3.0-alpha.d13c163e", | ||
"repository": { | ||
@@ -13,4 +13,4 @@ "type": "git", | ||
"diff": "^2.2.3", | ||
"jest-matcher-utils": "^14.2.2-alpha.22bd3c33", | ||
"pretty-format": "^3.5.0" | ||
"jest-matcher-utils": "^14.3.0-alpha.d13c163e", | ||
"pretty-format": "^3.6.0" | ||
}, | ||
@@ -17,0 +17,0 @@ "scripts": { |
4511
110
+ Addedjest-matcher-utils@14.3.0-alpha.d13c163e(transitive)
- Removedjest-matcher-utils@14.2.2-alpha.22bd3c33(transitive)
Updatedpretty-format@^3.6.0