jest-diff
Advanced tools
Comparing version 21.1.0 to 21.2.0
@@ -10,3 +10,2 @@ 'use strict';Object.defineProperty(exports, "__esModule", { value: true });exports.SIMILAR_MESSAGE = exports.NO_DIFF_MESSAGE = undefined; | ||
var _chalk = require('chalk');var _chalk2 = _interopRequireDefault(_chalk);function _interopRequireDefault(obj) {return obj && obj.__esModule ? obj : { default: obj };} | ||
@@ -16,9 +15,8 @@ | ||
'Compared values have no visual difference.'); /** | ||
* Copyright (c) 2014, Facebook, Inc. All rights reserved. | ||
* Copyright (c) 2014-present, Facebook, Inc. All rights reserved. | ||
* | ||
* This source code is licensed under the BSD-style license found in the | ||
* LICENSE file in the root directory of this source tree. An additional grant | ||
* of patent rights can be found in the PATENTS file in the same directory. | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
* | ||
* | ||
*/const SIMILAR_MESSAGE = exports.SIMILAR_MESSAGE = _chalk2.default.dim('Compared values serialize to the same structure.\n' + 'Printing internal object structure without calling `toJSON` instead.'); |
@@ -251,8 +251,2 @@ 'use strict';Object.defineProperty(exports, "__esModule", { value: true });exports.default = | ||
diffStrings;var _chalk = require('chalk');var _chalk2 = _interopRequireDefault(_chalk);var _diff = require('diff');var _constants = require('./constants.js');function _interopRequireDefault(obj) {return obj && obj.__esModule ? obj : { default: obj };}const DIFF_CONTEXT_DEFAULT = 5; // removed | added | equal | ||
@@ -263,7 +257,6 @@ // Given diff digit, return array which consists of: | ||
/** | ||
* Copyright (c) 2014, Facebook, Inc. All rights reserved. | ||
* Copyright (c) 2014-present, Facebook, Inc. All rights reserved. | ||
* | ||
* This source code is licensed under the BSD-style license found in the | ||
* LICENSE file in the root directory of this source tree. An additional grant | ||
* of patent rights can be found in the PATENTS file in the same directory. | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
* | ||
@@ -297,9 +290,10 @@ * | ||
// 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 _chalk2.default.yellow(`@@ ${markOld} ${markNew} @@\n`);}; // Given original lines, return callback function which given indexes for hunk, | ||
const shouldShowPatchMarks = (hunk, oldLinesCount) => oldLinesCount > hunk.oldLines;const createPatchMark = hunk => {const markOld = `-${hunk.oldStart},${hunk.oldLines}`;const markNew = `+${hunk.newStart},${hunk.newLines}`;return _chalk2.default.yellow(`@@ ${markOld} ${markNew} @@`);}; // Given original lines, return callback function which given indexes for hunk, | ||
// returns another callback function which given diff digit, returns array. | ||
const getterForHunks = original => {const linesExpected = splitIntoLines(original.a);const linesReceived = splitIntoLines(original.b);return (iExpected, iReceived) => digit => {if (digit === -1) {return [linesExpected[iExpected++]];}if (digit === 1) {return [linesReceived[iReceived++]];} // Because compared line is equal: original received and expected lines. | ||
return [linesReceived[iReceived++], linesExpected[iExpected++]];};}; // jest --no-expand | ||
const formatHunks = (a, b, contextLines, original) => {const options = { context: typeof contextLines === 'number' && contextLines >= 0 ? contextLines : DIFF_CONTEXT_DEFAULT }; // Make sure the strings end with a newline. | ||
if (!a.endsWith('\n')) {a += '\n';}if (!b.endsWith('\n')) {b += '\n';}var _structuredPatch = (0, _diff.structuredPatch)('', '', a, b, '', '', options);const hunks = _structuredPatch.hunks;if (hunks.length === 0) {return null;}const getter = original && getterForHunks(original);const oldLinesCount = (a.match(/\n/g) || []).length;return hunks.map(hunk => {// Hunk properties are one-based but index args are zero-based. | ||
const getOriginal = getter && getter(hunk.oldStart - 1, hunk.newStart - 1);const lines = hunk.lines.map(line => formatLine(line[0], line.slice(1), getOriginal)).join('\n');return shouldShowPatchMarks(hunk, oldLinesCount) ? createPatchMark(hunk) + lines : lines;}).join('\n');};function diffStrings(a, b, options, original) {// `diff` uses the Myers LCS diff algorithm which runs in O(n+d^2) time | ||
const formatHunks = (a, b, contextLines, original) => {const options = { context: typeof contextLines === 'number' && contextLines >= 0 ? contextLines : DIFF_CONTEXT_DEFAULT };var _structuredPatch = (0, _diff.structuredPatch)('', '', a, b, '', '', options);const hunks = _structuredPatch.hunks;if (hunks.length === 0) {return null;}const getter = original && getterForHunks(original);const oldLinesCount = (a.match(/\n/g) || []).length;return hunks.reduce((lines, hunk) => {if (shouldShowPatchMarks(hunk, oldLinesCount)) {lines.push(createPatchMark(hunk));} // Hunk properties are one-based but index args are zero-based. | ||
const getOriginal = getter && getter(hunk.oldStart - 1, hunk.newStart - 1);hunk.lines.forEach(line => {lines.push(formatLine(line[0], line.slice(1), getOriginal));});return lines;}, []).join('\n');};function diffStrings(a, b, options, original) {// Because `formatHunks` and `formatChunks` ignore one trailing newline, | ||
// always append newline to strings: | ||
a += '\n';b += '\n'; // `diff` uses the Myers LCS diff algorithm which runs in O(n+d^2) time | ||
// (where "d" is the edit distance) and can get very slow for large edit | ||
@@ -306,0 +300,0 @@ // distances. Mitigate the cost by switching to a lower-resolution diff |
@@ -12,3 +12,2 @@ 'use strict'; | ||
var _prettyFormat = require('pretty-format');var _prettyFormat2 = _interopRequireDefault(_prettyFormat); | ||
@@ -19,10 +18,10 @@ var _chalk = require('chalk');var _chalk2 = _interopRequireDefault(_chalk); | ||
var _constants = require('./constants');function _interopRequireDefault(obj) {return obj && obj.__esModule ? obj : { default: obj };} /** | ||
* Copyright (c) 2014, Facebook, Inc. All rights reserved. | ||
* Copyright (c) 2014-present, Facebook, Inc. All rights reserved. | ||
* | ||
* This source code is licensed under the BSD-style license found in the | ||
* LICENSE file in the root directory of this source tree. An additional grant | ||
* of patent rights can be found in the PATENTS file in the same directory. | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
* | ||
* | ||
*/var _prettyFormat$plugins = _prettyFormat2.default.plugins;const AsymmetricMatcher = _prettyFormat$plugins.AsymmetricMatcher,DOMElement = _prettyFormat$plugins.DOMElement,Immutable = _prettyFormat$plugins.Immutable,ReactElement = _prettyFormat$plugins.ReactElement,ReactTestComponent = _prettyFormat$plugins.ReactTestComponent; | ||
*/var _prettyFormat$plugins = | ||
_prettyFormat2.default.plugins;const AsymmetricMatcher = _prettyFormat$plugins.AsymmetricMatcher,DOMElement = _prettyFormat$plugins.DOMElement,Immutable = _prettyFormat$plugins.Immutable,ReactElement = _prettyFormat$plugins.ReactElement,ReactTestComponent = _prettyFormat$plugins.ReactTestComponent; | ||
@@ -29,0 +28,0 @@ const PLUGINS = [ |
{ | ||
"name": "jest-diff", | ||
"version": "21.1.0", | ||
"version": "21.2.0", | ||
"repository": { | ||
@@ -8,3 +8,3 @@ "type": "git", | ||
}, | ||
"license": "BSD-3-Clause", | ||
"license": "MIT", | ||
"main": "build/index.js", | ||
@@ -14,5 +14,5 @@ "dependencies": { | ||
"diff": "^3.2.0", | ||
"jest-get-type": "^21.0.2", | ||
"pretty-format": "^21.1.0" | ||
"jest-get-type": "^21.2.0", | ||
"pretty-format": "^21.2.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
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 3 instances in 1 package
0
100
14373
Updatedjest-get-type@^21.2.0
Updatedpretty-format@^21.2.0