Updating NPM dependencies
This commit is contained in:
328
node_modules/jest-matcher-utils/build/index.js
generated
vendored
328
node_modules/jest-matcher-utils/build/index.js
generated
vendored
@@ -3,45 +3,62 @@
|
||||
Object.defineProperty(exports, '__esModule', {
|
||||
value: true
|
||||
});
|
||||
Object.defineProperty(exports, 'DiffOptions', {
|
||||
enumerable: true,
|
||||
get: function get() {
|
||||
return _jestDiff.DiffOptions;
|
||||
}
|
||||
});
|
||||
exports.matcherHint = exports.matcherErrorMessage = exports.getLabelPrinter = exports.pluralize = exports.diff = exports.printDiffOrStringify = exports.ensureExpectedIsNonNegativeInteger = exports.ensureNumbers = exports.ensureExpectedIsNumber = exports.ensureActualIsNumber = exports.ensureNoExpected = exports.printWithType = exports.printExpected = exports.printReceived = exports.highlightTrailingWhitespace = exports.stringify = exports.SUGGEST_TO_CONTAIN_EQUAL = exports.DIM_COLOR = exports.BOLD_WEIGHT = exports.INVERTED_COLOR = exports.RECEIVED_COLOR = exports.EXPECTED_COLOR = void 0;
|
||||
|
||||
var _chalk = _interopRequireDefault(require('chalk'));
|
||||
|
||||
var _jestDiff = _interopRequireWildcard(require('jest-diff'));
|
||||
|
||||
var _jestGetType = _interopRequireWildcard(require('jest-get-type'));
|
||||
var _jestGetType = _interopRequireDefault(require('jest-get-type'));
|
||||
|
||||
var _prettyFormat = _interopRequireDefault(require('pretty-format'));
|
||||
|
||||
var _Replaceable = _interopRequireDefault(require('./Replaceable'));
|
||||
|
||||
var _deepCyclicCopyReplaceable = _interopRequireDefault(
|
||||
require('./deepCyclicCopyReplaceable')
|
||||
);
|
||||
|
||||
function _getRequireWildcardCache() {
|
||||
if (typeof WeakMap !== 'function') return null;
|
||||
var cache = new WeakMap();
|
||||
_getRequireWildcardCache = function () {
|
||||
return cache;
|
||||
};
|
||||
return cache;
|
||||
}
|
||||
|
||||
function _interopRequireWildcard(obj) {
|
||||
if (obj && obj.__esModule) {
|
||||
return obj;
|
||||
} else {
|
||||
var newObj = {};
|
||||
if (obj != null) {
|
||||
for (var key in obj) {
|
||||
if (Object.prototype.hasOwnProperty.call(obj, key)) {
|
||||
var desc =
|
||||
Object.defineProperty && Object.getOwnPropertyDescriptor
|
||||
? Object.getOwnPropertyDescriptor(obj, key)
|
||||
: {};
|
||||
if (desc.get || desc.set) {
|
||||
Object.defineProperty(newObj, key, desc);
|
||||
} else {
|
||||
newObj[key] = obj[key];
|
||||
}
|
||||
}
|
||||
}
|
||||
if (obj === null || (typeof obj !== 'object' && typeof obj !== 'function')) {
|
||||
return {default: obj};
|
||||
}
|
||||
var cache = _getRequireWildcardCache();
|
||||
if (cache && cache.has(obj)) {
|
||||
return cache.get(obj);
|
||||
}
|
||||
var newObj = {};
|
||||
var hasPropertyDescriptor =
|
||||
Object.defineProperty && Object.getOwnPropertyDescriptor;
|
||||
for (var key in obj) {
|
||||
if (Object.prototype.hasOwnProperty.call(obj, key)) {
|
||||
var desc = hasPropertyDescriptor
|
||||
? Object.getOwnPropertyDescriptor(obj, key)
|
||||
: null;
|
||||
if (desc && (desc.get || desc.set)) {
|
||||
Object.defineProperty(newObj, key, desc);
|
||||
} else {
|
||||
newObj[key] = obj[key];
|
||||
}
|
||||
}
|
||||
newObj.default = obj;
|
||||
return newObj;
|
||||
}
|
||||
newObj.default = obj;
|
||||
if (cache) {
|
||||
cache.set(obj, newObj);
|
||||
}
|
||||
return newObj;
|
||||
}
|
||||
|
||||
function _interopRequireDefault(obj) {
|
||||
@@ -54,13 +71,16 @@ function _interopRequireDefault(obj) {
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
const _prettyFormat$plugins = _prettyFormat.default.plugins,
|
||||
AsymmetricMatcher = _prettyFormat$plugins.AsymmetricMatcher,
|
||||
DOMCollection = _prettyFormat$plugins.DOMCollection,
|
||||
DOMElement = _prettyFormat$plugins.DOMElement,
|
||||
Immutable = _prettyFormat$plugins.Immutable,
|
||||
ReactElement = _prettyFormat$plugins.ReactElement,
|
||||
ReactTestComponent = _prettyFormat$plugins.ReactTestComponent;
|
||||
|
||||
/* eslint-disable local/ban-types-eventually */
|
||||
const {
|
||||
AsymmetricMatcher,
|
||||
DOMCollection,
|
||||
DOMElement,
|
||||
Immutable,
|
||||
ReactElement,
|
||||
ReactTestComponent
|
||||
} = _prettyFormat.default.plugins;
|
||||
const PLUGINS = [
|
||||
ReactTestComponent,
|
||||
ReactElement,
|
||||
@@ -115,7 +135,7 @@ const stringify = (object, maxDepth = 10) => {
|
||||
min: true,
|
||||
plugins: PLUGINS
|
||||
});
|
||||
} catch (e) {
|
||||
} catch {
|
||||
result = (0, _prettyFormat.default)(object, {
|
||||
callToJSON: false,
|
||||
maxDepth,
|
||||
@@ -150,11 +170,7 @@ const printExpected = value =>
|
||||
|
||||
exports.printExpected = printExpected;
|
||||
|
||||
const printWithType = (
|
||||
name,
|
||||
value,
|
||||
print // printExpected or printReceived
|
||||
) => {
|
||||
const printWithType = (name, value, print) => {
|
||||
const type = (0, _jestGetType.default)(value);
|
||||
const hasType =
|
||||
type !== 'null' && type !== 'undefined'
|
||||
@@ -173,44 +189,54 @@ const ensureNoExpected = (expected, matcherName, options) => {
|
||||
throw new Error(
|
||||
matcherErrorMessage(
|
||||
matcherHint(matcherString, undefined, '', options), // Because expected is omitted in hint above,
|
||||
// expected is black instead of green in message below.
|
||||
'this matcher must not have an expected argument',
|
||||
printWithType('Expected', expected, printExpected)
|
||||
)
|
||||
);
|
||||
}
|
||||
};
|
||||
/**
|
||||
* Ensures that `actual` is of type `number | bigint`
|
||||
*/
|
||||
|
||||
exports.ensureNoExpected = ensureNoExpected;
|
||||
|
||||
const ensureActualIsNumber = (actual, matcherName, options) => {
|
||||
if (typeof actual !== 'number') {
|
||||
if (typeof actual !== 'number' && typeof actual !== 'bigint') {
|
||||
// Prepend maybe not only for backward compatibility.
|
||||
const matcherString = (options ? '' : '[.not]') + matcherName;
|
||||
throw new Error(
|
||||
matcherErrorMessage(
|
||||
matcherHint(matcherString, undefined, undefined, options),
|
||||
`${RECEIVED_COLOR('received')} value must be a number`,
|
||||
`${RECEIVED_COLOR('received')} value must be a number or bigint`,
|
||||
printWithType('Received', actual, printReceived)
|
||||
)
|
||||
);
|
||||
}
|
||||
};
|
||||
/**
|
||||
* Ensures that `expected` is of type `number | bigint`
|
||||
*/
|
||||
|
||||
exports.ensureActualIsNumber = ensureActualIsNumber;
|
||||
|
||||
const ensureExpectedIsNumber = (expected, matcherName, options) => {
|
||||
if (typeof expected !== 'number') {
|
||||
if (typeof expected !== 'number' && typeof expected !== 'bigint') {
|
||||
// Prepend maybe not only for backward compatibility.
|
||||
const matcherString = (options ? '' : '[.not]') + matcherName;
|
||||
throw new Error(
|
||||
matcherErrorMessage(
|
||||
matcherHint(matcherString, undefined, undefined, options),
|
||||
`${EXPECTED_COLOR('expected')} value must be a number`,
|
||||
`${EXPECTED_COLOR('expected')} value must be a number or bigint`,
|
||||
printWithType('Expected', expected, printExpected)
|
||||
)
|
||||
);
|
||||
}
|
||||
};
|
||||
/**
|
||||
* Ensures that `actual` & `expected` are of type `number | bigint`
|
||||
*/
|
||||
|
||||
exports.ensureExpectedIsNumber = ensureExpectedIsNumber;
|
||||
|
||||
@@ -237,10 +263,28 @@ const ensureExpectedIsNonNegativeInteger = (expected, matcherName, options) => {
|
||||
)
|
||||
);
|
||||
}
|
||||
};
|
||||
}; // Given array of diffs, return concatenated string:
|
||||
// * include common substrings
|
||||
// * exclude change substrings which have opposite op
|
||||
// * include change substrings which have argument op
|
||||
// with inverse highlight only if there is a common substring
|
||||
|
||||
exports.ensureExpectedIsNonNegativeInteger = ensureExpectedIsNonNegativeInteger;
|
||||
|
||||
const getCommonAndChangedSubstrings = (diffs, op, hasCommonDiff) =>
|
||||
diffs.reduce(
|
||||
(reduced, diff) =>
|
||||
reduced +
|
||||
(diff[0] === _jestDiff.DIFF_EQUAL
|
||||
? diff[1]
|
||||
: diff[0] !== op
|
||||
? ''
|
||||
: hasCommonDiff
|
||||
? INVERTED_COLOR(diff[1])
|
||||
: diff[1]),
|
||||
''
|
||||
);
|
||||
|
||||
const isLineDiffable = (expected, received) => {
|
||||
const expectedType = (0, _jestGetType.default)(expected);
|
||||
const receivedType = (0, _jestGetType.default)(received);
|
||||
@@ -249,9 +293,10 @@ const isLineDiffable = (expected, received) => {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ((0, _jestGetType.isPrimitive)(expected)) {
|
||||
if (_jestGetType.default.isPrimitive(expected)) {
|
||||
// Print generic line diff for strings only:
|
||||
// * if neither string is empty
|
||||
// * if either string has more than one line
|
||||
return (
|
||||
typeof expected === 'string' &&
|
||||
typeof received === 'string' &&
|
||||
@@ -290,6 +335,8 @@ const isLineDiffable = (expected, received) => {
|
||||
return true;
|
||||
};
|
||||
|
||||
const MAX_DIFF_STRING_LENGTH = 20000;
|
||||
|
||||
const printDiffOrStringify = (
|
||||
expected,
|
||||
received,
|
||||
@@ -297,31 +344,72 @@ const printDiffOrStringify = (
|
||||
receivedLabel,
|
||||
expand
|
||||
) => {
|
||||
if (typeof expected === 'string' && typeof received === 'string') {
|
||||
const result = (0, _jestDiff.getStringDiff)(expected, received, {
|
||||
aAnnotation: expectedLabel,
|
||||
bAnnotation: receivedLabel,
|
||||
expand
|
||||
});
|
||||
|
||||
if (result !== null) {
|
||||
if (result.isMultiline) {
|
||||
return result.annotatedDiff;
|
||||
}
|
||||
|
||||
const printLabel = getLabelPrinter(expectedLabel, receivedLabel);
|
||||
const expectedLine = printLabel(expectedLabel) + printExpected(result.a);
|
||||
const receivedLine = printLabel(receivedLabel) + printReceived(result.b);
|
||||
return expectedLine + '\n' + receivedLine;
|
||||
if (
|
||||
typeof expected === 'string' &&
|
||||
typeof received === 'string' &&
|
||||
expected.length !== 0 &&
|
||||
received.length !== 0 &&
|
||||
expected.length <= MAX_DIFF_STRING_LENGTH &&
|
||||
received.length <= MAX_DIFF_STRING_LENGTH &&
|
||||
expected !== received
|
||||
) {
|
||||
if (expected.includes('\n') || received.includes('\n')) {
|
||||
return (0, _jestDiff.diffStringsUnified)(expected, received, {
|
||||
aAnnotation: expectedLabel,
|
||||
bAnnotation: receivedLabel,
|
||||
changeLineTrailingSpaceColor: _chalk.default.bgYellow,
|
||||
commonLineTrailingSpaceColor: _chalk.default.bgYellow,
|
||||
emptyFirstOrLastLinePlaceholder: '↵',
|
||||
// U+21B5
|
||||
expand,
|
||||
includeChangeCounts: true
|
||||
});
|
||||
}
|
||||
|
||||
const diffs = (0, _jestDiff.diffStringsRaw)(expected, received, true);
|
||||
const hasCommonDiff = diffs.some(diff => diff[0] === _jestDiff.DIFF_EQUAL);
|
||||
const printLabel = getLabelPrinter(expectedLabel, receivedLabel);
|
||||
const expectedLine =
|
||||
printLabel(expectedLabel) +
|
||||
printExpected(
|
||||
getCommonAndChangedSubstrings(
|
||||
diffs,
|
||||
_jestDiff.DIFF_DELETE,
|
||||
hasCommonDiff
|
||||
)
|
||||
);
|
||||
const receivedLine =
|
||||
printLabel(receivedLabel) +
|
||||
printReceived(
|
||||
getCommonAndChangedSubstrings(
|
||||
diffs,
|
||||
_jestDiff.DIFF_INSERT,
|
||||
hasCommonDiff
|
||||
)
|
||||
);
|
||||
return expectedLine + '\n' + receivedLine;
|
||||
}
|
||||
|
||||
if (isLineDiffable(expected, received)) {
|
||||
const difference = (0, _jestDiff.default)(expected, received, {
|
||||
aAnnotation: expectedLabel,
|
||||
bAnnotation: receivedLabel,
|
||||
expand
|
||||
});
|
||||
const {
|
||||
replacedExpected,
|
||||
replacedReceived
|
||||
} = replaceMatchedToAsymmetricMatcher(
|
||||
(0, _deepCyclicCopyReplaceable.default)(expected),
|
||||
(0, _deepCyclicCopyReplaceable.default)(received),
|
||||
[],
|
||||
[]
|
||||
);
|
||||
const difference = (0, _jestDiff.default)(
|
||||
replacedExpected,
|
||||
replacedReceived,
|
||||
{
|
||||
aAnnotation: expectedLabel,
|
||||
bAnnotation: receivedLabel,
|
||||
expand,
|
||||
includeChangeCounts: true
|
||||
}
|
||||
);
|
||||
|
||||
if (
|
||||
typeof difference === 'string' &&
|
||||
@@ -351,6 +439,10 @@ const shouldPrintDiff = (actual, expected) => {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (typeof actual === 'bigint' && typeof expected === 'bigint') {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (typeof actual === 'boolean' && typeof expected === 'boolean') {
|
||||
return false;
|
||||
}
|
||||
@@ -358,6 +450,68 @@ const shouldPrintDiff = (actual, expected) => {
|
||||
return true;
|
||||
};
|
||||
|
||||
function replaceMatchedToAsymmetricMatcher(
|
||||
replacedExpected,
|
||||
replacedReceived,
|
||||
expectedCycles,
|
||||
receivedCycles
|
||||
) {
|
||||
if (!_Replaceable.default.isReplaceable(replacedExpected, replacedReceived)) {
|
||||
return {
|
||||
replacedExpected,
|
||||
replacedReceived
|
||||
};
|
||||
}
|
||||
|
||||
if (
|
||||
expectedCycles.includes(replacedExpected) ||
|
||||
receivedCycles.includes(replacedReceived)
|
||||
) {
|
||||
return {
|
||||
replacedExpected,
|
||||
replacedReceived
|
||||
};
|
||||
}
|
||||
|
||||
expectedCycles.push(replacedExpected);
|
||||
receivedCycles.push(replacedReceived);
|
||||
const expectedReplaceable = new _Replaceable.default(replacedExpected);
|
||||
const receivedReplaceable = new _Replaceable.default(replacedReceived);
|
||||
expectedReplaceable.forEach((expectedValue, key) => {
|
||||
const receivedValue = receivedReplaceable.get(key);
|
||||
|
||||
if (isAsymmetricMatcher(expectedValue)) {
|
||||
if (expectedValue.asymmetricMatch(receivedValue)) {
|
||||
receivedReplaceable.set(key, expectedValue);
|
||||
}
|
||||
} else if (isAsymmetricMatcher(receivedValue)) {
|
||||
if (receivedValue.asymmetricMatch(expectedValue)) {
|
||||
expectedReplaceable.set(key, receivedValue);
|
||||
}
|
||||
} else if (
|
||||
_Replaceable.default.isReplaceable(expectedValue, receivedValue)
|
||||
) {
|
||||
const replaced = replaceMatchedToAsymmetricMatcher(
|
||||
expectedValue,
|
||||
receivedValue,
|
||||
expectedCycles,
|
||||
receivedCycles
|
||||
);
|
||||
expectedReplaceable.set(key, replaced.replacedExpected);
|
||||
receivedReplaceable.set(key, replaced.replacedReceived);
|
||||
}
|
||||
});
|
||||
return {
|
||||
replacedExpected: expectedReplaceable.object,
|
||||
replacedReceived: receivedReplaceable.object
|
||||
};
|
||||
}
|
||||
|
||||
function isAsymmetricMatcher(data) {
|
||||
const type = (0, _jestGetType.default)(data);
|
||||
return type === 'object' && typeof data.asymmetricMatch === 'function';
|
||||
}
|
||||
|
||||
const diff = (a, b, options) =>
|
||||
shouldPrintDiff(a, b) ? (0, _jestDiff.default)(a, b, options) : null;
|
||||
|
||||
@@ -381,14 +535,10 @@ const getLabelPrinter = (...strings) => {
|
||||
|
||||
exports.getLabelPrinter = getLabelPrinter;
|
||||
|
||||
const matcherErrorMessage = (
|
||||
hint,
|
||||
generic,
|
||||
specific // incorrect value returned from call to printWithType
|
||||
) =>
|
||||
`${hint}\n\n${_chalk.default.bold(
|
||||
'Matcher error'
|
||||
)}: ${generic}\n\n${specific}`; // Display assertion for the report when a test fails.
|
||||
const matcherErrorMessage = (hint, generic, specific) =>
|
||||
`${hint}\n\n${_chalk.default.bold('Matcher error')}: ${generic}${
|
||||
typeof specific === 'string' ? '\n\n' + specific : ''
|
||||
}`; // Display assertion for the report when a test fails.
|
||||
// New format: rejects/resolves, not, and matcher name have black color
|
||||
// Old format: matcher name has dim color
|
||||
|
||||
@@ -400,29 +550,17 @@ const matcherHint = (
|
||||
expected = 'expected',
|
||||
options = {}
|
||||
) => {
|
||||
const _options$comment = options.comment,
|
||||
comment = _options$comment === void 0 ? '' : _options$comment,
|
||||
_options$expectedColo = options.expectedColor,
|
||||
expectedColor =
|
||||
_options$expectedColo === void 0 ? EXPECTED_COLOR : _options$expectedColo,
|
||||
_options$isDirectExpe = options.isDirectExpectCall,
|
||||
isDirectExpectCall =
|
||||
_options$isDirectExpe === void 0 ? false : _options$isDirectExpe,
|
||||
_options$isNot = options.isNot,
|
||||
isNot = _options$isNot === void 0 ? false : _options$isNot,
|
||||
_options$promise = options.promise,
|
||||
promise = _options$promise === void 0 ? '' : _options$promise,
|
||||
_options$receivedColo = options.receivedColor,
|
||||
receivedColor =
|
||||
_options$receivedColo === void 0 ? RECEIVED_COLOR : _options$receivedColo,
|
||||
_options$secondArgume = options.secondArgument,
|
||||
secondArgument =
|
||||
_options$secondArgume === void 0 ? '' : _options$secondArgume,
|
||||
_options$secondArgume2 = options.secondArgumentColor,
|
||||
secondArgumentColor =
|
||||
_options$secondArgume2 === void 0
|
||||
? EXPECTED_COLOR
|
||||
: _options$secondArgume2;
|
||||
const {
|
||||
comment = '',
|
||||
expectedColor = EXPECTED_COLOR,
|
||||
isDirectExpectCall = false,
|
||||
// seems redundant with received === ''
|
||||
isNot = false,
|
||||
promise = '',
|
||||
receivedColor = RECEIVED_COLOR,
|
||||
secondArgument = '',
|
||||
secondArgumentColor = EXPECTED_COLOR
|
||||
} = options;
|
||||
let hint = '';
|
||||
let dimString = 'expect'; // concatenate adjacent dim substrings
|
||||
|
||||
|
||||
Reference in New Issue
Block a user