jest-diff
Advanced tools
Comparing version 18.1.0 to 18.5.0-alpha.7da3df39
@@ -27,2 +27,10 @@ /** | ||
const getColor = (added, removed) => | ||
@@ -72,2 +80,16 @@ added ? | ||
// Only show patch marks ("@@ ... @@") if the diff is big. | ||
// To determine this, we need to compare either the original string (a) to | ||
// `hunk.oldLines` or a new string to `hunk.newLines`. | ||
// If the `oldLinesCount` is greater than `hunk.oldLines` | ||
// we can be sure that at least 1 line has been "hidden". | ||
const shouldShowPatchMarks = | ||
(hunk, oldLinesCount) => oldLinesCount > hunk.oldLines; | ||
const createPatchMark = hunk => { | ||
const markOld = `-${hunk.oldStart},${hunk.oldLines}`; | ||
const markNew = `+${hunk.newStart},${hunk.newLines}`; | ||
return chalk.yellow(`@@ ${markOld} ${markNew} @@\n`); | ||
}; | ||
const structuredPatch = (a, b) => { | ||
@@ -84,9 +106,7 @@ const options = { context: DIFF_CONTEXT }; | ||
const oldLinesCount = (a.match(/\n/g) || []).length; | ||
return { | ||
diff: diff.structuredPatch('', '', a, b, '', '', options). | ||
hunks.map(hunk => { | ||
const diffMarkOld = `-${ hunk.oldStart },${ hunk.oldLines }`; | ||
const diffMarkNew = `+${ hunk.newStart },${ hunk.newLines }`; | ||
const diffMark = chalk.yellow(`@@ ${ diffMarkOld } ${ diffMarkNew } @@\n`); | ||
const lines = hunk.lines.map(line => { | ||
@@ -104,3 +124,5 @@ const added = line[0] === '+'; | ||
isDifferent = true; | ||
return diffMark + lines; | ||
return shouldShowPatchMarks(hunk, oldLinesCount) ? | ||
createPatchMark(hunk) + lines : | ||
lines; | ||
}).join('').trim(), | ||
@@ -107,0 +129,0 @@ isDifferent }; |
@@ -17,2 +17,3 @@ /** | ||
const ReactTestComponentPlugin = require('pretty-format/build/plugins/ReactTestComponent'); | ||
const AsymmetricMatcherPlugin = require('pretty-format/build/plugins/AsymmetricMatcher'); | ||
@@ -29,3 +30,7 @@ const chalk = require('chalk'); | ||
const PLUGINS = [ReactTestComponentPlugin, ReactElementPlugin]; | ||
const PLUGINS = [ | ||
ReactTestComponentPlugin, | ||
ReactElementPlugin, | ||
AsymmetricMatcherPlugin]; | ||
const FORMAT_OPTIONS = { | ||
@@ -47,11 +52,33 @@ plugins: PLUGINS }; | ||
if (getType(a) !== getType(b)) { | ||
const aType = getType(a); | ||
let expectedType = aType; | ||
let omitDifference = false; | ||
if (aType === 'object' && typeof a.asymmetricMatch === 'function') { | ||
if (a.$$typeof !== Symbol.for('jest.asymmetricMatcher')) { | ||
// Do not know expected type of user-defined asymmetric matcher. | ||
return null; | ||
} | ||
if (typeof a.getExpectedType !== 'function') { | ||
// For example, expect.anything() matches either null or undefined | ||
return null; | ||
} | ||
expectedType = a.getExpectedType(); | ||
// Primitive types boolean and number omit difference below. | ||
// For example, omit difference for expect.stringMatching(regexp) | ||
omitDifference = expectedType === 'string'; | ||
} | ||
if (expectedType !== getType(b)) { | ||
return ( | ||
' Comparing two different types of values.' + | ||
` Expected ${ chalk.green(getType(a)) } but ` + | ||
`received ${ chalk.red(getType(b)) }.`); | ||
` Expected ${chalk.green(expectedType)} but ` + | ||
`received ${chalk.red(getType(b))}.`); | ||
} | ||
switch (getType(a)) { | ||
if (omitDifference) { | ||
return null; | ||
} | ||
switch (aType) { | ||
case 'string': | ||
@@ -58,0 +85,0 @@ const multiline = a.match(/[\r\n]/) !== -1 && b.indexOf('\n') !== -1; |
{ | ||
"name": "jest-diff", | ||
"version": "18.1.0", | ||
"version": "18.5.0-alpha.7da3df39", | ||
"repository": { | ||
@@ -13,8 +13,5 @@ "type": "git", | ||
"diff": "^3.0.0", | ||
"jest-matcher-utils": "^18.1.0", | ||
"pretty-format": "^18.1.0" | ||
}, | ||
"scripts": { | ||
"test": "../../packages/jest-cli/bin/jest.js" | ||
"jest-matcher-utils": "^18.5.0-alpha.7da3df39", | ||
"pretty-format": "^18.5.0-alpha.7da3df39" | ||
} | ||
} |
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
8631
227
2
+ Addedansi-styles@3.2.1(transitive)
+ Addedcolor-convert@1.9.3(transitive)
+ Addedcolor-name@1.1.3(transitive)
+ Addedjest-matcher-utils@18.5.0-alpha.7da3df39(transitive)
+ Addedpretty-format@18.5.0-alpha.7da3df39(transitive)
- Removedjest-matcher-utils@18.1.0(transitive)
- Removedpretty-format@18.1.0(transitive)