jest-diff
Advanced tools
Comparing version 17.0.3 to 18.0.0
@@ -15,4 +15,4 @@ /** | ||
const ReactElementPlugin = require('pretty-format/plugins/ReactElement'); | ||
const ReactTestComponentPlugin = require('pretty-format/plugins/ReactTestComponent'); | ||
const ReactElementPlugin = require('pretty-format/build/plugins/ReactElement'); | ||
const ReactTestComponentPlugin = require('pretty-format/build/plugins/ReactTestComponent'); | ||
@@ -64,32 +64,49 @@ const chalk = require('chalk'); | ||
return null; | ||
case 'map': | ||
return compareObjects(sortMap(a), sortMap(b), options); | ||
case 'set': | ||
return compareObjects(sortSet(a), sortSet(b), options); | ||
default: | ||
let diffMessage; | ||
let hasThrown = false; | ||
return compareObjects(a, b, options);} | ||
try { | ||
diffMessage = diffStrings( | ||
prettyFormat(a, FORMAT_OPTIONS), | ||
prettyFormat(b, FORMAT_OPTIONS), | ||
options); | ||
} | ||
} catch (e) { | ||
hasThrown = true; | ||
} | ||
function sortMap(map) { | ||
return new Map(Array.from(map.entries()).sort()); | ||
} | ||
// If the comparison yields no results, compare again but this time | ||
// without calling `toJSON`. It's also possible that toJSON might throw. | ||
if (!diffMessage || diffMessage === NO_DIFF_MESSAGE) { | ||
diffMessage = diffStrings( | ||
prettyFormat(a, FALLBACK_FORMAT_OPTIONS), | ||
prettyFormat(b, FALLBACK_FORMAT_OPTIONS), | ||
options); | ||
function sortSet(set) { | ||
return new Set(Array.from(set.values()).sort()); | ||
} | ||
if (diffMessage !== NO_DIFF_MESSAGE && !hasThrown) { | ||
diffMessage = SIMILAR_MESSAGE + '\n\n' + diffMessage; | ||
} | ||
} | ||
return diffMessage;} | ||
function compareObjects(a, b, options) { | ||
let diffMessage; | ||
let hasThrown = false; | ||
try { | ||
diffMessage = diffStrings( | ||
prettyFormat(a, FORMAT_OPTIONS), | ||
prettyFormat(b, FORMAT_OPTIONS), | ||
options); | ||
} catch (e) { | ||
hasThrown = true; | ||
} | ||
// If the comparison yields no results, compare again but this time | ||
// without calling `toJSON`. It's also possible that toJSON might throw. | ||
if (!diffMessage || diffMessage === NO_DIFF_MESSAGE) { | ||
diffMessage = diffStrings( | ||
prettyFormat(a, FALLBACK_FORMAT_OPTIONS), | ||
prettyFormat(b, FALLBACK_FORMAT_OPTIONS), | ||
options); | ||
if (diffMessage !== NO_DIFF_MESSAGE && !hasThrown) { | ||
diffMessage = SIMILAR_MESSAGE + '\n\n' + diffMessage; | ||
} | ||
} | ||
return diffMessage; | ||
} | ||
module.exports = diff; |
{ | ||
"name": "jest-diff", | ||
"version": "17.0.3", | ||
"version": "18.0.0", | ||
"repository": { | ||
@@ -13,4 +13,4 @@ "type": "git", | ||
"diff": "^3.0.0", | ||
"jest-matcher-utils": "^17.0.3", | ||
"pretty-format": "~4.2.1" | ||
"jest-matcher-utils": "^18.0.0", | ||
"pretty-format": "^18.0.0" | ||
}, | ||
@@ -17,0 +17,0 @@ "scripts": { |
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
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
6768
180
+ Addedjest-matcher-utils@18.1.0(transitive)
+ Addedpretty-format@18.1.0(transitive)
- Removedjest-matcher-utils@17.0.3(transitive)
- Removedpretty-format@4.2.3(transitive)
Updatedjest-matcher-utils@^18.0.0
Updatedpretty-format@^18.0.0