Updating NPM dependencies
This commit is contained in:
579
node_modules/jest-snapshot/build/index.js
generated
vendored
579
node_modules/jest-snapshot/build/index.js
generated
vendored
@@ -1,71 +1,81 @@
|
||||
'use strict';
|
||||
|
||||
var _fs = _interopRequireDefault(require('fs'));
|
||||
var fs = _interopRequireWildcard(require('graceful-fs'));
|
||||
|
||||
var _jestMatcherUtils = require('jest-matcher-utils');
|
||||
|
||||
var _snapshot_resolver = require('./snapshot_resolver');
|
||||
var _SnapshotResolver = require('./SnapshotResolver');
|
||||
|
||||
var _State = _interopRequireDefault(require('./State'));
|
||||
|
||||
var _plugins = require('./plugins');
|
||||
|
||||
var _print = require('./print');
|
||||
var _printSnapshot = require('./printSnapshot');
|
||||
|
||||
var utils = _interopRequireWildcard(require('./utils'));
|
||||
|
||||
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];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
newObj.default = obj;
|
||||
return newObj;
|
||||
}
|
||||
}
|
||||
|
||||
function _interopRequireDefault(obj) {
|
||||
return obj && obj.__esModule ? obj : {default: obj};
|
||||
}
|
||||
|
||||
var Symbol = global['jest-symbol-do-not-touch'] || global.Symbol;
|
||||
var Symbol = global['jest-symbol-do-not-touch'] || global.Symbol;
|
||||
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;
|
||||
}
|
||||
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;
|
||||
if (cache) {
|
||||
cache.set(obj, newObj);
|
||||
}
|
||||
return newObj;
|
||||
}
|
||||
|
||||
var Symbol = global['jest-symbol-do-not-touch'] || global.Symbol;
|
||||
var Symbol = global['jest-symbol-do-not-touch'] || global.Symbol;
|
||||
var jestExistsFile =
|
||||
global[Symbol.for('jest-native-exists-file')] || _fs.default.existsSync;
|
||||
|
||||
global[Symbol.for('jest-native-exists-file')] || fs.existsSync;
|
||||
const DID_NOT_THROW = 'Received function did not throw'; // same as toThrow
|
||||
|
||||
const NOT_SNAPSHOT_MATCHERS = `.${(0, _jestMatcherUtils.BOLD_WEIGHT)(
|
||||
'not'
|
||||
)} cannot be used with snapshot matchers`;
|
||||
const HINT_ARG = 'hint';
|
||||
const HINT_COLOR = _jestMatcherUtils.BOLD_WEIGHT;
|
||||
const INLINE_SNAPSHOT_ARG = 'snapshot';
|
||||
const PROPERTY_MATCHERS_ARG = 'properties';
|
||||
const NOT_SNAPSHOT_MATCHERS = `Snapshot matchers cannot be used with ${(0,
|
||||
_jestMatcherUtils.BOLD_WEIGHT)('not')}`;
|
||||
const INDENTATION_REGEX = /^([^\S\n]*)\S/m; // Display name in report when matcher fails same as in snapshot file,
|
||||
// but with optional hint argument in bold weight.
|
||||
|
||||
const printName = (concatenatedBlockNames = '', hint = '', count) => {
|
||||
const printSnapshotName = (concatenatedBlockNames = '', hint = '', count) => {
|
||||
const hasNames = concatenatedBlockNames.length !== 0;
|
||||
const hasHint = hint.length !== 0;
|
||||
return (
|
||||
'`' +
|
||||
'Snapshot name: `' +
|
||||
(hasNames ? utils.escapeBacktickString(concatenatedBlockNames) : '') +
|
||||
(hasNames && hasHint ? ': ' : '') +
|
||||
(hasHint
|
||||
@@ -123,7 +133,7 @@ const fileExists = (filePath, hasteFS) =>
|
||||
hasteFS.exists(filePath) || jestExistsFile(filePath);
|
||||
|
||||
const cleanup = (hasteFS, update, snapshotResolver, testPathIgnorePatterns) => {
|
||||
const pattern = '\\.' + _snapshot_resolver.EXTENSION + '$';
|
||||
const pattern = '\\.' + _SnapshotResolver.EXTENSION + '$';
|
||||
const files = hasteFS.matchFiles(pattern);
|
||||
let testIgnorePatternsRegex = null;
|
||||
|
||||
@@ -140,7 +150,7 @@ const cleanup = (hasteFS, update, snapshotResolver, testPathIgnorePatterns) => {
|
||||
|
||||
if (!fileExists(testPath, hasteFS)) {
|
||||
if (update === 'all') {
|
||||
_fs.default.unlinkSync(snapshotFile);
|
||||
fs.unlinkSync(snapshotFile);
|
||||
}
|
||||
|
||||
return true;
|
||||
@@ -154,142 +164,181 @@ const cleanup = (hasteFS, update, snapshotResolver, testPathIgnorePatterns) => {
|
||||
};
|
||||
};
|
||||
|
||||
const toMatchSnapshot = function toMatchSnapshot(
|
||||
received,
|
||||
propertyMatchers,
|
||||
hint
|
||||
) {
|
||||
const toMatchSnapshot = function (received, propertiesOrHint, hint) {
|
||||
const matcherName = 'toMatchSnapshot';
|
||||
let expectedArgument = '';
|
||||
let secondArgument = '';
|
||||
let properties;
|
||||
const length = arguments.length;
|
||||
|
||||
if (typeof propertyMatchers === 'object' && propertyMatchers !== null) {
|
||||
expectedArgument = PROPERTY_MATCHERS_ARG;
|
||||
if (length === 2 && typeof propertiesOrHint === 'string') {
|
||||
hint = propertiesOrHint;
|
||||
} else if (length >= 2) {
|
||||
if (typeof propertiesOrHint !== 'object' || propertiesOrHint === null) {
|
||||
const options = {
|
||||
isNot: this.isNot,
|
||||
promise: this.promise
|
||||
};
|
||||
let printedWithType = (0, _jestMatcherUtils.printWithType)(
|
||||
'Expected properties',
|
||||
propertiesOrHint,
|
||||
_printSnapshot.printExpected
|
||||
);
|
||||
|
||||
if (typeof hint === 'string' && hint.length !== 0) {
|
||||
secondArgument = HINT_ARG;
|
||||
}
|
||||
} else if (
|
||||
typeof propertyMatchers === 'string' &&
|
||||
propertyMatchers.length !== 0
|
||||
) {
|
||||
expectedArgument = HINT_ARG;
|
||||
}
|
||||
if (length === 3) {
|
||||
options.secondArgument = 'hint';
|
||||
options.secondArgumentColor = _jestMatcherUtils.BOLD_WEIGHT;
|
||||
|
||||
const options = {
|
||||
isNot: this.isNot,
|
||||
promise: this.promise,
|
||||
secondArgument
|
||||
};
|
||||
if (propertiesOrHint == null) {
|
||||
printedWithType += `\n\nTo provide a hint without properties: toMatchSnapshot('hint')`;
|
||||
}
|
||||
}
|
||||
|
||||
if (expectedArgument === HINT_ARG) {
|
||||
options.expectedColor = HINT_COLOR;
|
||||
}
|
||||
throw new Error(
|
||||
(0, _jestMatcherUtils.matcherErrorMessage)(
|
||||
(0, _jestMatcherUtils.matcherHint)(
|
||||
matcherName,
|
||||
undefined,
|
||||
_printSnapshot.PROPERTIES_ARG,
|
||||
options
|
||||
),
|
||||
`Expected ${(0, _jestMatcherUtils.EXPECTED_COLOR)(
|
||||
'properties'
|
||||
)} must be an object`,
|
||||
printedWithType
|
||||
)
|
||||
);
|
||||
} // Future breaking change: Snapshot hint must be a string
|
||||
// if (arguments.length === 3 && typeof hint !== 'string') {}
|
||||
|
||||
if (secondArgument === HINT_ARG) {
|
||||
options.secondArgumentColor = HINT_COLOR;
|
||||
}
|
||||
|
||||
if (arguments.length === 3 && !propertyMatchers) {
|
||||
throw new Error(
|
||||
'Property matchers must be an object.\n\nTo provide a snapshot test name without property matchers, use: toMatchSnapshot("name")'
|
||||
);
|
||||
properties = propertiesOrHint;
|
||||
}
|
||||
|
||||
return _toMatchSnapshot({
|
||||
context: this,
|
||||
expectedArgument,
|
||||
hint,
|
||||
isInline: false,
|
||||
matcherName,
|
||||
options,
|
||||
propertyMatchers,
|
||||
properties,
|
||||
received
|
||||
});
|
||||
};
|
||||
|
||||
const toMatchInlineSnapshot = function toMatchInlineSnapshot(
|
||||
const toMatchInlineSnapshot = function (
|
||||
received,
|
||||
propertyMatchersOrInlineSnapshot,
|
||||
propertiesOrSnapshot,
|
||||
inlineSnapshot
|
||||
) {
|
||||
const matcherName = 'toMatchInlineSnapshot';
|
||||
let expectedArgument = '';
|
||||
let secondArgument = '';
|
||||
let properties;
|
||||
const length = arguments.length;
|
||||
|
||||
if (typeof propertyMatchersOrInlineSnapshot === 'string') {
|
||||
expectedArgument = INLINE_SNAPSHOT_ARG;
|
||||
} else if (
|
||||
typeof propertyMatchersOrInlineSnapshot === 'object' &&
|
||||
propertyMatchersOrInlineSnapshot !== null
|
||||
) {
|
||||
expectedArgument = PROPERTY_MATCHERS_ARG;
|
||||
if (length === 2 && typeof propertiesOrSnapshot === 'string') {
|
||||
inlineSnapshot = propertiesOrSnapshot;
|
||||
} else if (length >= 2) {
|
||||
const options = {
|
||||
isNot: this.isNot,
|
||||
promise: this.promise
|
||||
};
|
||||
|
||||
if (typeof inlineSnapshot === 'string') {
|
||||
secondArgument = INLINE_SNAPSHOT_ARG;
|
||||
if (length === 3) {
|
||||
options.secondArgument = _printSnapshot.SNAPSHOT_ARG;
|
||||
options.secondArgumentColor = _printSnapshot.noColor;
|
||||
}
|
||||
}
|
||||
|
||||
const options = {
|
||||
isNot: this.isNot,
|
||||
promise: this.promise,
|
||||
secondArgument
|
||||
};
|
||||
let propertyMatchers;
|
||||
if (
|
||||
typeof propertiesOrSnapshot !== 'object' ||
|
||||
propertiesOrSnapshot === null
|
||||
) {
|
||||
throw new Error(
|
||||
(0, _jestMatcherUtils.matcherErrorMessage)(
|
||||
(0, _jestMatcherUtils.matcherHint)(
|
||||
matcherName,
|
||||
undefined,
|
||||
_printSnapshot.PROPERTIES_ARG,
|
||||
options
|
||||
),
|
||||
`Expected ${(0, _jestMatcherUtils.EXPECTED_COLOR)(
|
||||
'properties'
|
||||
)} must be an object`,
|
||||
(0, _jestMatcherUtils.printWithType)(
|
||||
'Expected properties',
|
||||
propertiesOrSnapshot,
|
||||
_printSnapshot.printExpected
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
if (typeof propertyMatchersOrInlineSnapshot === 'string') {
|
||||
inlineSnapshot = propertyMatchersOrInlineSnapshot;
|
||||
} else {
|
||||
propertyMatchers = propertyMatchersOrInlineSnapshot;
|
||||
if (length === 3 && typeof inlineSnapshot !== 'string') {
|
||||
throw new Error(
|
||||
(0, _jestMatcherUtils.matcherErrorMessage)(
|
||||
(0, _jestMatcherUtils.matcherHint)(
|
||||
matcherName,
|
||||
undefined,
|
||||
_printSnapshot.PROPERTIES_ARG,
|
||||
options
|
||||
),
|
||||
`Inline snapshot must be a string`,
|
||||
(0, _jestMatcherUtils.printWithType)(
|
||||
'Inline snapshot',
|
||||
inlineSnapshot,
|
||||
utils.serialize
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
properties = propertiesOrSnapshot;
|
||||
}
|
||||
|
||||
return _toMatchSnapshot({
|
||||
context: this,
|
||||
expectedArgument,
|
||||
inlineSnapshot: stripAddedIndentation(inlineSnapshot || ''),
|
||||
inlineSnapshot:
|
||||
inlineSnapshot !== undefined
|
||||
? stripAddedIndentation(inlineSnapshot)
|
||||
: undefined,
|
||||
isInline: true,
|
||||
matcherName,
|
||||
options,
|
||||
propertyMatchers,
|
||||
properties,
|
||||
received
|
||||
});
|
||||
};
|
||||
|
||||
const _toMatchSnapshot = ({
|
||||
context,
|
||||
expectedArgument,
|
||||
hint,
|
||||
inlineSnapshot,
|
||||
matcherName,
|
||||
options,
|
||||
propertyMatchers,
|
||||
received
|
||||
}) => {
|
||||
const _toMatchSnapshot = config => {
|
||||
const {
|
||||
context,
|
||||
hint,
|
||||
inlineSnapshot,
|
||||
isInline,
|
||||
matcherName,
|
||||
properties
|
||||
} = config;
|
||||
let {received} = config;
|
||||
context.dontThrow && context.dontThrow();
|
||||
hint = typeof propertyMatchers === 'string' ? propertyMatchers : hint;
|
||||
const currentTestName = context.currentTestName,
|
||||
isNot = context.isNot,
|
||||
snapshotState = context.snapshotState;
|
||||
const {currentTestName, isNot, snapshotState} = context;
|
||||
|
||||
if (isNot) {
|
||||
throw new Error(
|
||||
(0, _jestMatcherUtils.matcherHint)(
|
||||
matcherName,
|
||||
undefined,
|
||||
expectedArgument,
|
||||
options
|
||||
) +
|
||||
'\n\n' +
|
||||
(0, _jestMatcherUtils.matcherErrorMessage)(
|
||||
(0, _printSnapshot.matcherHintFromConfig)(config, false),
|
||||
NOT_SNAPSHOT_MATCHERS
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
if (!snapshotState) {
|
||||
if (snapshotState == null) {
|
||||
// Because the state is the problem, this is not a matcher error.
|
||||
// Call generic stringify from jest-matcher-utils package
|
||||
// because uninitialized snapshot state does not need snapshot serializers.
|
||||
throw new Error(
|
||||
(0, _jestMatcherUtils.matcherHint)(
|
||||
matcherName,
|
||||
undefined,
|
||||
expectedArgument,
|
||||
options
|
||||
) + '\n\nsnapshot state must be initialized'
|
||||
(0, _printSnapshot.matcherHintFromConfig)(config, false) +
|
||||
'\n\n' +
|
||||
`Snapshot state must be initialized` +
|
||||
'\n\n' +
|
||||
(0, _jestMatcherUtils.printWithType)(
|
||||
'Snapshot state',
|
||||
snapshotState,
|
||||
_jestMatcherUtils.stringify
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -298,12 +347,25 @@ const _toMatchSnapshot = ({
|
||||
? `${currentTestName}: ${hint}`
|
||||
: currentTestName || ''; // future BREAKING change: || hint
|
||||
|
||||
if (typeof propertyMatchers === 'object') {
|
||||
if (propertyMatchers === null) {
|
||||
throw new Error(`Property matchers must be an object.`);
|
||||
if (typeof properties === 'object') {
|
||||
if (typeof received !== 'object' || received === null) {
|
||||
throw new Error(
|
||||
(0, _jestMatcherUtils.matcherErrorMessage)(
|
||||
(0, _printSnapshot.matcherHintFromConfig)(config, false),
|
||||
`${(0, _jestMatcherUtils.RECEIVED_COLOR)(
|
||||
'received'
|
||||
)} value must be an object when the matcher has ${(0,
|
||||
_jestMatcherUtils.EXPECTED_COLOR)('properties')}`,
|
||||
(0, _jestMatcherUtils.printWithType)(
|
||||
'Received',
|
||||
received,
|
||||
_printSnapshot.printReceived
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
const propertyPass = context.equals(received, propertyMatchers, [
|
||||
const propertyPass = context.equals(received, properties, [
|
||||
context.utils.iterableEquality,
|
||||
context.utils.subsetEquality
|
||||
]);
|
||||
@@ -313,176 +375,192 @@ const _toMatchSnapshot = ({
|
||||
const matched = /(\d+)$/.exec(key);
|
||||
const count = matched === null ? 1 : Number(matched[1]);
|
||||
|
||||
const report = () =>
|
||||
`Snapshot name: ${printName(currentTestName, hint, count)}\n` +
|
||||
'\n' +
|
||||
`Expected properties: ${context.utils.printExpected(
|
||||
propertyMatchers
|
||||
)}\n` +
|
||||
`Received value: ${context.utils.printReceived(received)}`;
|
||||
const message = () =>
|
||||
(0, _printSnapshot.matcherHintFromConfig)(config, false) +
|
||||
'\n\n' +
|
||||
printSnapshotName(currentTestName, hint, count) +
|
||||
'\n\n' +
|
||||
(0, _printSnapshot.printPropertiesAndReceived)(
|
||||
properties,
|
||||
received,
|
||||
snapshotState.expand
|
||||
);
|
||||
|
||||
return {
|
||||
message: () =>
|
||||
(0, _jestMatcherUtils.matcherHint)(
|
||||
matcherName,
|
||||
undefined,
|
||||
expectedArgument,
|
||||
options
|
||||
) +
|
||||
'\n\n' +
|
||||
report(),
|
||||
message,
|
||||
name: matcherName,
|
||||
pass: false,
|
||||
report
|
||||
pass: false
|
||||
};
|
||||
} else {
|
||||
received = utils.deepMerge(received, propertyMatchers);
|
||||
received = utils.deepMerge(received, properties);
|
||||
}
|
||||
}
|
||||
|
||||
const result = snapshotState.match({
|
||||
error: context.error,
|
||||
inlineSnapshot,
|
||||
isInline,
|
||||
received,
|
||||
testName: fullTestName
|
||||
});
|
||||
const count = result.count,
|
||||
pass = result.pass;
|
||||
let actual = result.actual,
|
||||
expected = result.expected;
|
||||
let report;
|
||||
const {actual, count, expected, pass} = result;
|
||||
|
||||
if (pass) {
|
||||
return {
|
||||
message: () => '',
|
||||
pass: true
|
||||
};
|
||||
} else if (!expected) {
|
||||
report = () =>
|
||||
`New snapshot was ${(0, _jestMatcherUtils.RECEIVED_COLOR)(
|
||||
'not written'
|
||||
)}. The update flag ` +
|
||||
`must be explicitly passed to write a new snapshot.\n\n` +
|
||||
`This is likely because this test is run in a continuous integration ` +
|
||||
`(CI) environment in which snapshots are not written by default.\n\n` +
|
||||
`${(0, _jestMatcherUtils.RECEIVED_COLOR)('Received value')} ` +
|
||||
`${actual}`;
|
||||
} else {
|
||||
expected = (expected || '').trim();
|
||||
actual = (actual || '').trim(); // Assign to local variable because of declaration let expected:
|
||||
// TypeScript thinks it could change before report function is called.
|
||||
}
|
||||
|
||||
const printed = (0, _print.printDiffOrStringified)(
|
||||
expected,
|
||||
actual,
|
||||
received,
|
||||
'Snapshot',
|
||||
'Received',
|
||||
snapshotState.expand
|
||||
);
|
||||
|
||||
report = () =>
|
||||
`Snapshot name: ${printName(currentTestName, hint, count)}\n\n` + printed;
|
||||
} // Passing the actual and expected objects so that a custom reporter
|
||||
const message =
|
||||
expected === undefined
|
||||
? () =>
|
||||
(0, _printSnapshot.matcherHintFromConfig)(config, true) +
|
||||
'\n\n' +
|
||||
printSnapshotName(currentTestName, hint, count) +
|
||||
'\n\n' +
|
||||
`New snapshot was ${(0, _jestMatcherUtils.BOLD_WEIGHT)(
|
||||
'not written'
|
||||
)}. The update flag ` +
|
||||
`must be explicitly passed to write a new snapshot.\n\n` +
|
||||
`This is likely because this test is run in a continuous integration ` +
|
||||
`(CI) environment in which snapshots are not written by default.\n\n` +
|
||||
`Received:${actual.includes('\n') ? '\n' : ' '}${(0,
|
||||
_printSnapshot.bReceivedColor)(actual)}`
|
||||
: () =>
|
||||
(0, _printSnapshot.matcherHintFromConfig)(config, true) +
|
||||
'\n\n' +
|
||||
printSnapshotName(currentTestName, hint, count) +
|
||||
'\n\n' +
|
||||
(0, _printSnapshot.printSnapshotAndReceived)(
|
||||
expected,
|
||||
actual,
|
||||
received,
|
||||
snapshotState.expand
|
||||
); // Passing the actual and expected objects so that a custom reporter
|
||||
// could access them, for example in order to display a custom visual diff,
|
||||
// or create a different error message
|
||||
|
||||
return {
|
||||
actual,
|
||||
expected,
|
||||
message: () =>
|
||||
(0, _jestMatcherUtils.matcherHint)(
|
||||
matcherName,
|
||||
undefined,
|
||||
expectedArgument,
|
||||
options
|
||||
) +
|
||||
'\n\n' +
|
||||
report(),
|
||||
message,
|
||||
name: matcherName,
|
||||
pass: false,
|
||||
report
|
||||
pass: false
|
||||
};
|
||||
};
|
||||
|
||||
const toThrowErrorMatchingSnapshot = function toThrowErrorMatchingSnapshot(
|
||||
const toThrowErrorMatchingSnapshot = function (
|
||||
received,
|
||||
hint, // because error TS1016 for hint?: string
|
||||
fromPromise
|
||||
) {
|
||||
const matcherName = 'toThrowErrorMatchingSnapshot';
|
||||
const expectedArgument =
|
||||
typeof hint === 'string' && hint.length !== 0 ? HINT_ARG : '';
|
||||
const options = {
|
||||
expectedColor: HINT_COLOR,
|
||||
isNot: this.isNot,
|
||||
promise: this.promise,
|
||||
secondArgument: ''
|
||||
};
|
||||
const matcherName = 'toThrowErrorMatchingSnapshot'; // Future breaking change: Snapshot hint must be a string
|
||||
// if (hint !== undefined && typeof hint !== string) {}
|
||||
|
||||
return _toThrowErrorMatchingSnapshot(
|
||||
{
|
||||
context: this,
|
||||
expectedArgument,
|
||||
hint,
|
||||
isInline: false,
|
||||
matcherName,
|
||||
options,
|
||||
received
|
||||
},
|
||||
fromPromise
|
||||
);
|
||||
};
|
||||
|
||||
const toThrowErrorMatchingInlineSnapshot = function toThrowErrorMatchingInlineSnapshot(
|
||||
const toThrowErrorMatchingInlineSnapshot = function (
|
||||
received,
|
||||
inlineSnapshot,
|
||||
fromPromise
|
||||
) {
|
||||
const matcherName = 'toThrowErrorMatchingInlineSnapshot';
|
||||
const expectedArgument =
|
||||
typeof inlineSnapshot === 'string' ? INLINE_SNAPSHOT_ARG : '';
|
||||
const options = {
|
||||
isNot: this.isNot,
|
||||
promise: this.promise,
|
||||
secondArgument: ''
|
||||
};
|
||||
|
||||
if (inlineSnapshot !== undefined && typeof inlineSnapshot !== 'string') {
|
||||
const options = {
|
||||
expectedColor: _printSnapshot.noColor,
|
||||
isNot: this.isNot,
|
||||
promise: this.promise
|
||||
};
|
||||
throw new Error(
|
||||
(0, _jestMatcherUtils.matcherErrorMessage)(
|
||||
(0, _jestMatcherUtils.matcherHint)(
|
||||
matcherName,
|
||||
undefined,
|
||||
_printSnapshot.SNAPSHOT_ARG,
|
||||
options
|
||||
),
|
||||
`Inline snapshot must be a string`,
|
||||
(0, _jestMatcherUtils.printWithType)(
|
||||
'Inline snapshot',
|
||||
inlineSnapshot,
|
||||
utils.serialize
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
return _toThrowErrorMatchingSnapshot(
|
||||
{
|
||||
context: this,
|
||||
expectedArgument,
|
||||
inlineSnapshot: inlineSnapshot || '',
|
||||
inlineSnapshot:
|
||||
inlineSnapshot !== undefined
|
||||
? stripAddedIndentation(inlineSnapshot)
|
||||
: undefined,
|
||||
isInline: true,
|
||||
matcherName,
|
||||
options,
|
||||
received
|
||||
},
|
||||
fromPromise
|
||||
);
|
||||
};
|
||||
|
||||
const _toThrowErrorMatchingSnapshot = (
|
||||
{
|
||||
const _toThrowErrorMatchingSnapshot = (config, fromPromise) => {
|
||||
const {
|
||||
context,
|
||||
expectedArgument,
|
||||
hint,
|
||||
inlineSnapshot,
|
||||
isInline,
|
||||
matcherName,
|
||||
options,
|
||||
received,
|
||||
hint
|
||||
},
|
||||
fromPromise
|
||||
) => {
|
||||
received
|
||||
} = config;
|
||||
context.dontThrow && context.dontThrow();
|
||||
const isNot = context.isNot;
|
||||
const {isNot, promise} = context;
|
||||
|
||||
if (!fromPromise) {
|
||||
if (typeof received !== 'function') {
|
||||
const options = {
|
||||
isNot,
|
||||
promise
|
||||
};
|
||||
throw new Error(
|
||||
(0, _jestMatcherUtils.matcherErrorMessage)(
|
||||
(0, _jestMatcherUtils.matcherHint)(
|
||||
matcherName,
|
||||
undefined,
|
||||
'',
|
||||
options
|
||||
),
|
||||
`${(0, _jestMatcherUtils.RECEIVED_COLOR)(
|
||||
'received'
|
||||
)} value must be a function`,
|
||||
(0, _jestMatcherUtils.printWithType)(
|
||||
'Received',
|
||||
received,
|
||||
_printSnapshot.printReceived
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if (isNot) {
|
||||
throw new Error(
|
||||
(0, _jestMatcherUtils.matcherHint)(
|
||||
matcherName,
|
||||
undefined,
|
||||
expectedArgument,
|
||||
options
|
||||
) +
|
||||
'\n\n' +
|
||||
(0, _jestMatcherUtils.matcherErrorMessage)(
|
||||
(0, _printSnapshot.matcherHintFromConfig)(config, false),
|
||||
NOT_SNAPSHOT_MATCHERS
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -499,13 +577,9 @@ const _toThrowErrorMatchingSnapshot = (
|
||||
}
|
||||
|
||||
if (error === undefined) {
|
||||
// Because the received value is a function, this is not a matcher error.
|
||||
throw new Error(
|
||||
(0, _jestMatcherUtils.matcherHint)(
|
||||
matcherName,
|
||||
undefined,
|
||||
expectedArgument,
|
||||
options
|
||||
) +
|
||||
(0, _printSnapshot.matcherHintFromConfig)(config, false) +
|
||||
'\n\n' +
|
||||
DID_NOT_THROW
|
||||
);
|
||||
@@ -513,29 +587,26 @@ const _toThrowErrorMatchingSnapshot = (
|
||||
|
||||
return _toMatchSnapshot({
|
||||
context,
|
||||
expectedArgument,
|
||||
hint,
|
||||
inlineSnapshot,
|
||||
isInline,
|
||||
matcherName,
|
||||
options,
|
||||
received: error.message
|
||||
});
|
||||
};
|
||||
|
||||
const JestSnapshot = {
|
||||
EXTENSION: _snapshot_resolver.EXTENSION,
|
||||
EXTENSION: _SnapshotResolver.EXTENSION,
|
||||
SnapshotState: _State.default,
|
||||
addSerializer: _plugins.addSerializer,
|
||||
buildSnapshotResolver: _snapshot_resolver.buildSnapshotResolver,
|
||||
buildSnapshotResolver: _SnapshotResolver.buildSnapshotResolver,
|
||||
cleanup,
|
||||
getSerializers: _plugins.getSerializers,
|
||||
isSnapshotPath: _snapshot_resolver.isSnapshotPath,
|
||||
isSnapshotPath: _SnapshotResolver.isSnapshotPath,
|
||||
toMatchInlineSnapshot,
|
||||
toMatchSnapshot,
|
||||
toThrowErrorMatchingInlineSnapshot,
|
||||
toThrowErrorMatchingSnapshot,
|
||||
utils
|
||||
};
|
||||
/* eslint-disable-next-line no-redeclare */
|
||||
|
||||
module.exports = JestSnapshot;
|
||||
|
||||
Reference in New Issue
Block a user