jest-snapshot
Advanced tools
Comparing version 29.1.2 to 29.2.0
@@ -15,3 +15,2 @@ 'use strict'; | ||
void 0; | ||
/** | ||
@@ -23,3 +22,5 @@ * Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. | ||
*/ | ||
// https://jonasjacek.github.io/colors/ | ||
const aForeground2 = 90; | ||
@@ -26,0 +27,0 @@ exports.aForeground2 = aForeground2; |
@@ -7,3 +7,2 @@ 'use strict'; | ||
exports.dedentLines = void 0; | ||
/** | ||
@@ -15,2 +14,3 @@ * Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. | ||
*/ | ||
const getIndentationLength = line => { | ||
@@ -20,11 +20,10 @@ const result = /^( {2})+/.exec(line); | ||
}; | ||
const dedentLine = line => line.slice(getIndentationLength(line)); | ||
const dedentLine = line => line.slice(getIndentationLength(line)); // Return true if: | ||
// Return true if: | ||
// "key": "value has multiple lines\n… | ||
// "key has multiple lines\n… | ||
const hasUnmatchedDoubleQuoteMarks = string => { | ||
let n = 0; | ||
let i = string.indexOf('"', 0); | ||
while (i !== -1) { | ||
@@ -34,10 +33,10 @@ if (i === 0 || string[i - 1] !== '\\') { | ||
} | ||
i = string.indexOf('"', i + 1); | ||
} | ||
return n % 2 !== 0; | ||
}; | ||
const isFirstLineOfTag = line => /^( {2})*</.test(line); | ||
const isFirstLineOfTag = line => /^( {2})*</.test(line); // The length of the output array is the index of the next input line. | ||
// The length of the output array is the index of the next input line. | ||
// Push dedented lines of start tag onto output and return true; | ||
@@ -47,14 +46,10 @@ // otherwise return false because: | ||
// * start tag does not close | ||
const dedentStartTag = (input, output) => { | ||
let line = input[output.length]; | ||
output.push(dedentLine(line)); | ||
if (line.includes('>')) { | ||
return true; | ||
} | ||
while (output.length < input.length) { | ||
line = input[output.length]; | ||
if (hasUnmatchedDoubleQuoteMarks(line)) { | ||
@@ -69,3 +64,2 @@ return false; // because props include a multiline string | ||
output.push(dedentLine(line)); | ||
if (line.includes('>')) { | ||
@@ -76,5 +70,6 @@ return true; | ||
} | ||
return false; | ||
}; | ||
return false; | ||
}; // Push dedented lines of markup onto output and return true; | ||
// Push dedented lines of markup onto output and return true; | ||
// otherwise return false because: | ||
@@ -84,21 +79,15 @@ // * props include a multiline string | ||
// * markup does not close | ||
const dedentMarkup = (input, output) => { | ||
let line = input[output.length]; | ||
if (!dedentStartTag(input, output)) { | ||
return false; | ||
} | ||
if (input[output.length - 1].includes('/>')) { | ||
return true; | ||
} | ||
let isText = false; | ||
const stack = []; | ||
stack.push(getIndentationLength(line)); | ||
while (stack.length > 0 && output.length < input.length) { | ||
line = input[output.length]; | ||
if (isFirstLineOfTag(line)) { | ||
@@ -112,3 +101,2 @@ if (line.includes('</')) { | ||
} | ||
if (!input[output.length - 1].includes('/>')) { | ||
@@ -118,3 +106,2 @@ stack.push(getIndentationLength(line)); | ||
} | ||
isText = false; | ||
@@ -131,5 +118,6 @@ } else { | ||
} | ||
return stack.length === 0; | ||
}; | ||
return stack.length === 0; | ||
}; // Return lines unindented by heuristic; | ||
// Return lines unindented by heuristic; | ||
// otherwise return null because: | ||
@@ -139,9 +127,6 @@ // * props include a multiline string | ||
// * markup does not close | ||
const dedentLines = input => { | ||
const output = []; | ||
while (output.length < input.length) { | ||
const line = input[output.length]; | ||
if (hasUnmatchedDoubleQuoteMarks(line)) { | ||
@@ -157,6 +142,4 @@ return null; | ||
} | ||
return output; | ||
}; | ||
exports.dedentLines = dedentLines; |
@@ -48,21 +48,12 @@ 'use strict'; | ||
void 0; | ||
var fs = _interopRequireWildcard(require('graceful-fs')); | ||
var _jestMatcherUtils = require('jest-matcher-utils'); | ||
var _SnapshotResolver = require('./SnapshotResolver'); | ||
var _printSnapshot = require('./printSnapshot'); | ||
var _utils = require('./utils'); | ||
var _plugins = require('./plugins'); | ||
var _State = _interopRequireDefault(require('./State')); | ||
function _interopRequireDefault(obj) { | ||
return obj && obj.__esModule ? obj : {default: obj}; | ||
} | ||
function _getRequireWildcardCache(nodeInterop) { | ||
@@ -76,3 +67,2 @@ if (typeof WeakMap !== 'function') return null; | ||
} | ||
function _interopRequireWildcard(obj, nodeInterop) { | ||
@@ -110,3 +100,2 @@ if (!nodeInterop && obj && obj.__esModule) { | ||
} | ||
var Symbol = globalThis['jest-symbol-do-not-touch'] || globalThis.Symbol; | ||
@@ -117,8 +106,8 @@ var Symbol = globalThis['jest-symbol-do-not-touch'] || globalThis.Symbol; | ||
const DID_NOT_THROW = 'Received function did not throw'; // same as toThrow | ||
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, | ||
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 printSnapshotName = (concatenatedBlockNames = '', hint = '', count) => { | ||
@@ -137,7 +126,5 @@ const hasNames = concatenatedBlockNames.length !== 0; | ||
}; | ||
function stripAddedIndentation(inlineSnapshot) { | ||
// Find indentation if exists. | ||
const match = inlineSnapshot.match(INDENTATION_REGEX); | ||
if (!match || !match[1]) { | ||
@@ -147,6 +134,4 @@ // No indentation. | ||
} | ||
const indentation = match[1]; | ||
const lines = inlineSnapshot.split('\n'); | ||
if (lines.length <= 2) { | ||
@@ -156,3 +141,2 @@ // Must be at least 3 lines. | ||
} | ||
if (lines[0].trim() !== '' || lines[lines.length - 1].trim() !== '') { | ||
@@ -162,3 +146,2 @@ // If not blank first and last lines, abort. | ||
} | ||
for (let i = 1; i < lines.length - 1; i++) { | ||
@@ -172,17 +155,16 @@ if (lines[i] !== '') { | ||
} | ||
lines[i] = lines[i].substring(indentation.length); | ||
} | ||
} // Last line is a special case because it won't have the same indent as others | ||
} | ||
// Last line is a special case because it won't have the same indent as others | ||
// but may still have been given some indent to line up. | ||
lines[lines.length - 1] = ''; | ||
lines[lines.length - 1] = ''; // Return inline snapshot, now at indent 0. | ||
// Return inline snapshot, now at indent 0. | ||
inlineSnapshot = lines.join('\n'); | ||
return inlineSnapshot; | ||
} | ||
const fileExists = (filePath, hasteFS) => | ||
hasteFS.exists(filePath) || jestExistsFile(filePath); | ||
const cleanup = (hasteFS, update, snapshotResolver, testPathIgnorePatterns) => { | ||
@@ -192,14 +174,12 @@ const pattern = `\\.${_SnapshotResolver.EXTENSION}$`; | ||
let testIgnorePatternsRegex = null; | ||
if (testPathIgnorePatterns && testPathIgnorePatterns.length > 0) { | ||
testIgnorePatternsRegex = new RegExp(testPathIgnorePatterns.join('|')); | ||
} | ||
const list = files.filter(snapshotFile => { | ||
const testPath = snapshotResolver.resolveTestPath(snapshotFile); // ignore snapshots of ignored tests | ||
const testPath = snapshotResolver.resolveTestPath(snapshotFile); | ||
// ignore snapshots of ignored tests | ||
if (testIgnorePatternsRegex && testIgnorePatternsRegex.test(testPath)) { | ||
return false; | ||
} | ||
if (!fileExists(testPath, hasteFS)) { | ||
@@ -209,6 +189,4 @@ if (update === 'all') { | ||
} | ||
return true; | ||
} | ||
return false; | ||
@@ -221,5 +199,3 @@ }); | ||
}; | ||
exports.cleanup = cleanup; | ||
const toMatchSnapshot = function (received, propertiesOrHint, hint) { | ||
@@ -229,3 +205,2 @@ const matcherName = 'toMatchSnapshot'; | ||
const length = arguments.length; | ||
if (length === 2 && typeof propertiesOrHint === 'string') { | ||
@@ -248,7 +223,5 @@ hint = propertiesOrHint; | ||
); | ||
if (length === 3) { | ||
options.secondArgument = 'hint'; | ||
options.secondArgumentColor = _jestMatcherUtils.BOLD_WEIGHT; | ||
if (propertiesOrHint == null) { | ||
@@ -259,3 +232,2 @@ printedWithType += | ||
} | ||
throw new Error( | ||
@@ -275,3 +247,5 @@ (0, _jestMatcherUtils.matcherErrorMessage)( | ||
); | ||
} // Future breaking change: Snapshot hint must be a string | ||
} | ||
// Future breaking change: Snapshot hint must be a string | ||
// if (arguments.length === 3 && typeof hint !== 'string') {} | ||
@@ -281,3 +255,2 @@ | ||
} | ||
return _toMatchSnapshot({ | ||
@@ -292,5 +265,3 @@ context: this, | ||
}; | ||
exports.toMatchSnapshot = toMatchSnapshot; | ||
const toMatchInlineSnapshot = function ( | ||
@@ -304,3 +275,2 @@ received, | ||
const length = arguments.length; | ||
if (length === 2 && typeof propertiesOrSnapshot === 'string') { | ||
@@ -313,3 +283,2 @@ inlineSnapshot = propertiesOrSnapshot; | ||
}; | ||
if (length === 3) { | ||
@@ -319,3 +288,2 @@ options.secondArgument = _printSnapshot.SNAPSHOT_ARG; | ||
} | ||
if ( | ||
@@ -345,3 +313,2 @@ Array.isArray(propertiesOrSnapshot) || | ||
} | ||
if (length === 3 && typeof inlineSnapshot !== 'string') { | ||
@@ -365,6 +332,4 @@ throw new Error( | ||
} | ||
properties = propertiesOrSnapshot; | ||
} | ||
return _toMatchSnapshot({ | ||
@@ -382,5 +347,3 @@ context: this, | ||
}; | ||
exports.toMatchInlineSnapshot = toMatchInlineSnapshot; | ||
const _toMatchSnapshot = config => { | ||
@@ -392,3 +355,2 @@ const {context, hint, inlineSnapshot, isInline, matcherName, properties} = | ||
const {currentTestName, isNot, snapshotState} = context; | ||
if (isNot) { | ||
@@ -402,3 +364,2 @@ throw new Error( | ||
} | ||
if (snapshotState == null) { | ||
@@ -418,3 +379,2 @@ // Because the state is the problem, this is not a matcher error. | ||
} | ||
const fullTestName = | ||
@@ -442,3 +402,2 @@ currentTestName && hint | ||
} | ||
const propertyPass = context.equals(received, properties, [ | ||
@@ -448,3 +407,2 @@ context.utils.iterableEquality, | ||
]); | ||
if (!propertyPass) { | ||
@@ -454,3 +412,2 @@ const key = snapshotState.fail(fullTestName, received); | ||
const count = matched === null ? 1 : Number(matched[1]); | ||
const message = () => | ||
@@ -466,3 +423,2 @@ `${(0, _printSnapshot.matcherHintFromConfig)( | ||
)}`; | ||
return { | ||
@@ -477,3 +433,2 @@ message, | ||
} | ||
const result = snapshotState.match({ | ||
@@ -487,3 +442,2 @@ error: context.error, | ||
const {actual, count, expected, pass} = result; | ||
if (pass) { | ||
@@ -495,3 +449,2 @@ return { | ||
} | ||
const message = | ||
@@ -523,6 +476,7 @@ expected === undefined | ||
snapshotState.snapshotFormat | ||
)}`; // Passing the actual and expected objects so that a custom reporter | ||
)}`; | ||
// 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 { | ||
@@ -536,5 +490,6 @@ actual, | ||
}; | ||
const toThrowErrorMatchingSnapshot = function (received, hint, fromPromise) { | ||
const matcherName = 'toThrowErrorMatchingSnapshot'; | ||
const toThrowErrorMatchingSnapshot = function (received, hint, fromPromise) { | ||
const matcherName = 'toThrowErrorMatchingSnapshot'; // Future breaking change: Snapshot hint must be a string | ||
// Future breaking change: Snapshot hint must be a string | ||
// if (hint !== undefined && typeof hint !== string) {} | ||
@@ -553,5 +508,3 @@ | ||
}; | ||
exports.toThrowErrorMatchingSnapshot = toThrowErrorMatchingSnapshot; | ||
const toThrowErrorMatchingInlineSnapshot = function ( | ||
@@ -563,3 +516,2 @@ received, | ||
const matcherName = 'toThrowErrorMatchingInlineSnapshot'; | ||
if (inlineSnapshot !== undefined && typeof inlineSnapshot !== 'string') { | ||
@@ -588,3 +540,2 @@ const options = { | ||
} | ||
return _toThrowErrorMatchingSnapshot( | ||
@@ -604,5 +555,3 @@ { | ||
}; | ||
exports.toThrowErrorMatchingInlineSnapshot = toThrowErrorMatchingInlineSnapshot; | ||
const _toThrowErrorMatchingSnapshot = (config, fromPromise) => { | ||
@@ -613,3 +562,2 @@ const {context, hint, inlineSnapshot, isInline, matcherName, received} = | ||
const {isNot, promise} = context; | ||
if (!fromPromise) { | ||
@@ -641,3 +589,2 @@ if (typeof received !== 'function') { | ||
} | ||
if (isNot) { | ||
@@ -651,5 +598,3 @@ throw new Error( | ||
} | ||
let error; | ||
if (fromPromise) { | ||
@@ -664,3 +609,2 @@ error = received; | ||
} | ||
if (error === undefined) { | ||
@@ -675,3 +619,2 @@ // Because the received value is a function, this is not a matcher error. | ||
} | ||
return _toMatchSnapshot({ | ||
@@ -678,0 +621,0 @@ context, |
@@ -7,17 +7,10 @@ 'use strict'; | ||
exports.saveInlineSnapshots = saveInlineSnapshots; | ||
var path = _interopRequireWildcard(require('path')); | ||
var _types = require('@babel/types'); | ||
var fs = _interopRequireWildcard(require('graceful-fs')); | ||
var _semver = _interopRequireDefault(require('semver')); | ||
var _utils = require('./utils'); | ||
function _interopRequireDefault(obj) { | ||
return obj && obj.__esModule ? obj : {default: obj}; | ||
} | ||
function _getRequireWildcardCache(nodeInterop) { | ||
@@ -31,3 +24,2 @@ if (typeof WeakMap !== 'function') return null; | ||
} | ||
function _interopRequireWildcard(obj, nodeInterop) { | ||
@@ -65,3 +57,2 @@ if (!nodeInterop && obj && obj.__esModule) { | ||
} | ||
var Symbol = globalThis['jest-symbol-do-not-touch'] || globalThis.Symbol; | ||
@@ -74,3 +65,2 @@ var Symbol = globalThis['jest-symbol-do-not-touch'] || globalThis.Symbol; | ||
globalThis[Symbol.for('jest-native-read-file')] || fs.readFileSync; | ||
// prettier-ignore | ||
@@ -80,11 +70,9 @@ const babelTraverse = // @ts-expect-error requireOutside Babel transform | ||
[(globalThis['jest-symbol-do-not-touch'] || globalThis.Symbol).for('jest-resolve-outside-vm-option')]: true | ||
})).default; // prettier-ignore | ||
})).default; | ||
// prettier-ignore | ||
const generate = // @ts-expect-error requireOutside Babel transform | ||
require(require.resolve('@babel/generator', { | ||
[(globalThis['jest-symbol-do-not-touch'] || globalThis.Symbol).for( | ||
'jest-resolve-outside-vm-option' | ||
)]: true | ||
})).default; // @ts-expect-error requireOutside Babel transform | ||
require(require.resolve('@babel/generator', { | ||
[(globalThis['jest-symbol-do-not-touch'] || globalThis.Symbol).for('jest-resolve-outside-vm-option')]: true | ||
})).default; | ||
// @ts-expect-error requireOutside Babel transform | ||
const {file, templateElement, templateLiteral} = require(require.resolve( | ||
@@ -97,4 +85,4 @@ '@babel/types', | ||
} | ||
)); // @ts-expect-error requireOutside Babel transform | ||
)); | ||
// @ts-expect-error requireOutside Babel transform | ||
const {parseSync} = require(require.resolve('@babel/core', { | ||
@@ -105,6 +93,4 @@ [(globalThis['jest-symbol-do-not-touch'] || globalThis.Symbol).for( | ||
})); | ||
function saveInlineSnapshots(snapshots, rootDir, prettierPath) { | ||
let prettier = null; | ||
if (prettierPath) { | ||
@@ -122,5 +108,3 @@ try { | ||
} | ||
const snapshotsByFile = groupSnapshotsByFile(snapshots); | ||
for (const sourceFilePath of Object.keys(snapshotsByFile)) { | ||
@@ -137,9 +121,8 @@ saveSnapshotsForFile( | ||
} | ||
const saveSnapshotsForFile = (snapshots, sourceFilePath, rootDir, prettier) => { | ||
const sourceFile = jestReadFile(sourceFilePath, 'utf8'); // TypeScript projects may not have a babel config; make sure they can be parsed anyway. | ||
const sourceFile = jestReadFile(sourceFilePath, 'utf8'); | ||
// TypeScript projects may not have a babel config; make sure they can be parsed anyway. | ||
const presets = [require.resolve('babel-preset-current-node-syntax')]; | ||
const plugins = []; | ||
if (/\.tsx?$/.test(sourceFilePath)) { | ||
@@ -150,11 +133,12 @@ plugins.push([ | ||
isTSX: sourceFilePath.endsWith('x') | ||
}, // unique name to make sure Babel does not complain about a possible duplicate plugin. | ||
}, | ||
// unique name to make sure Babel does not complain about a possible duplicate plugin. | ||
'TypeScript syntax plugin added by Jest snapshot' | ||
]); | ||
} // Record the matcher names seen during traversal and pass them down one | ||
} | ||
// Record the matcher names seen during traversal and pass them down one | ||
// by one to formatting parser. | ||
const snapshotMatcherNames = []; | ||
let ast = null; | ||
try { | ||
@@ -173,3 +157,4 @@ ast = parseSync(sourceFile, { | ||
require.resolve('@babel/plugin-syntax-jsx'), | ||
{}, // unique name to make sure Babel does not complain about a possible duplicate plugin. | ||
{}, | ||
// unique name to make sure Babel does not complain about a possible duplicate plugin. | ||
'JSX syntax plugin added by Jest snapshot' | ||
@@ -190,9 +175,8 @@ ]; | ||
} | ||
if (!ast) { | ||
throw new Error(`jest-snapshot: Failed to parse ${sourceFilePath}`); | ||
} | ||
traverseAst(snapshots, ast, snapshotMatcherNames); | ||
traverseAst(snapshots, ast, snapshotMatcherNames); // substitute in the snapshots in reverse order, so slice calculations aren't thrown off. | ||
// substitute in the snapshots in reverse order, so slice calculations aren't thrown off. | ||
const sourceFileWithSnapshots = snapshots.reduceRight( | ||
@@ -207,3 +191,2 @@ (sourceSoFar, nextSnapshot) => { | ||
} | ||
return ( | ||
@@ -227,3 +210,2 @@ sourceSoFar.slice(0, nextSnapshot.node.start) + | ||
: sourceFileWithSnapshots; | ||
if (newSourceFile !== sourceFile) { | ||
@@ -233,9 +215,10 @@ jestWriteFile(sourceFilePath, newSourceFile); | ||
}; | ||
const groupSnapshotsBy = createKey => snapshots => | ||
snapshots.reduce((object, inlineSnapshot) => { | ||
const key = createKey(inlineSnapshot); | ||
return {...object, [key]: (object[key] || []).concat(inlineSnapshot)}; | ||
return { | ||
...object, | ||
[key]: (object[key] || []).concat(inlineSnapshot) | ||
}; | ||
}, {}); | ||
const groupSnapshotsByFrame = groupSnapshotsBy(({frame: {line, column}}) => | ||
@@ -247,6 +230,5 @@ typeof line === 'number' && typeof column === 'number' | ||
const groupSnapshotsByFile = groupSnapshotsBy(({frame: {file}}) => file); | ||
const indent = (snapshot, numIndents, indentation) => { | ||
const lines = snapshot.split('\n'); // Prevent re-indentation of inline snapshots. | ||
const lines = snapshot.split('\n'); | ||
// Prevent re-indentation of inline snapshots. | ||
if ( | ||
@@ -258,3 +240,2 @@ lines.length >= 2 && | ||
} | ||
return lines | ||
@@ -269,4 +250,5 @@ .map((line, index) => { | ||
return line; | ||
} // Not last line, indent one level deeper than expect call. | ||
} | ||
// Not last line, indent one level deeper than expect call. | ||
return indentation.repeat(numIndents + 1) + line; | ||
@@ -280,7 +262,5 @@ } else { | ||
}; | ||
const resolveAst = fileOrProgram => { | ||
// Flow uses a 'Program' parent node, babel expects a 'File'. | ||
let ast = fileOrProgram; | ||
if (ast.type !== 'File') { | ||
@@ -290,6 +270,4 @@ ast = file(ast, ast.comments, ast.tokens); | ||
} | ||
return ast; | ||
}; | ||
const traverseAst = (snapshots, fileOrProgram, snapshotMatcherNames) => { | ||
@@ -302,3 +280,2 @@ const ast = resolveAst(fileOrProgram); | ||
const {arguments: args, callee} = node; | ||
if ( | ||
@@ -311,10 +288,7 @@ callee.type !== 'MemberExpression' || | ||
} | ||
const {line, column} = callee.property.loc.start; | ||
const snapshotsForFrame = groupedSnapshots[`${line}:${column}`]; | ||
if (!snapshotsForFrame) { | ||
return; | ||
} | ||
if (snapshotsForFrame.length > 1) { | ||
@@ -325,3 +299,2 @@ throw new Error( | ||
} | ||
snapshotMatcherNames.push(callee.property.name); | ||
@@ -345,3 +318,2 @@ const snapshotIndex = args.findIndex( | ||
const replacementNode = values[0]; | ||
if (snapshotIndex > -1) { | ||
@@ -354,3 +326,2 @@ args[snapshotIndex] = replacementNode; | ||
}); | ||
if (remainingSnapshots.size) { | ||
@@ -360,3 +331,2 @@ throw new Error("Jest: Couldn't locate all inline snapshots."); | ||
}; | ||
const runPrettier = ( | ||
@@ -374,7 +344,8 @@ prettier, | ||
}) | ||
: null; // Prioritize parser found in the project config. | ||
: null; | ||
// Prioritize parser found in the project config. | ||
// If not found detect the parser for the test file. | ||
// For older versions of Prettier, fallback to a simple parser detection. | ||
// @ts-expect-error - `inferredParser` is `string` | ||
const inferredParser = | ||
@@ -385,3 +356,2 @@ (config && typeof config.parser === 'string' && config.parser) || | ||
: simpleDetectParser(sourceFilePath)); | ||
if (!inferredParser) { | ||
@@ -391,3 +361,5 @@ throw new Error( | ||
); | ||
} // Snapshots have now been inserted. Run prettier to make sure that the code is | ||
} | ||
// Snapshots have now been inserted. Run prettier to make sure that the code is | ||
// formatted, except snapshot indentation. Snapshots cannot be formatted until | ||
@@ -397,3 +369,2 @@ // after the initial format because we don't know where the call expression | ||
// prettier.format calls back-to-back. | ||
return prettier.format( | ||
@@ -410,4 +381,5 @@ prettier.format(sourceFileWithSnapshots, { | ||
); | ||
}; // This parser formats snapshots to the correct indentation. | ||
}; | ||
// This parser formats snapshots to the correct indentation. | ||
const createFormattingParser = | ||
@@ -429,9 +401,6 @@ (snapshotMatcherNames, inferredParser) => (text, parsers, options) => { | ||
} | ||
let snapshotIndex; | ||
let snapshot; | ||
for (let i = 0; i < args.length; i++) { | ||
const node = args[i]; | ||
if (node.type === 'TemplateLiteral') { | ||
@@ -442,7 +411,5 @@ snapshotIndex = i; | ||
} | ||
if (snapshot === undefined || snapshotIndex === undefined) { | ||
return; | ||
} | ||
const startColumn = | ||
@@ -457,4 +424,5 @@ (0, _types.isAwaitExpression)(parent) && parent.loc | ||
useSpaces | ||
? startColumn / (options.tabWidth ?? 1) // Each tab is 2 characters. | ||
: startColumn / 2 | ||
? startColumn / (options.tabWidth ?? 1) | ||
: // Each tab is 2 characters. | ||
startColumn / 2 | ||
), | ||
@@ -476,11 +444,8 @@ useSpaces ? ' '.repeat(options.tabWidth ?? 1) : '\t' | ||
}; | ||
const simpleDetectParser = filePath => { | ||
const extname = path.extname(filePath); | ||
if (/\.tsx?$/.test(extname)) { | ||
return 'typescript'; | ||
} | ||
return 'babel'; | ||
}; |
@@ -7,3 +7,2 @@ 'use strict'; | ||
exports.test = exports.serialize = exports.default = void 0; | ||
/** | ||
@@ -15,2 +14,3 @@ * Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. | ||
*/ | ||
const serialize = (val, config, indentation, depth, refs, printer) => { | ||
@@ -21,3 +21,2 @@ // Serialize a non-default name, even if config.printFunctionName is false. | ||
let callsString = ''; | ||
if (val.mock.calls.length !== 0) { | ||
@@ -41,10 +40,6 @@ const indentationNext = indentation + config.indent; | ||
} | ||
return `[MockFunction${nameString}]${callsString}`; | ||
}; | ||
exports.serialize = serialize; | ||
const test = val => val && !!val._isMockFunction; | ||
exports.test = test; | ||
@@ -51,0 +46,0 @@ const plugin = { |
@@ -7,11 +7,7 @@ 'use strict'; | ||
exports.getSerializers = exports.addSerializer = void 0; | ||
var _prettyFormat = require('pretty-format'); | ||
var _mockSerializer = _interopRequireDefault(require('./mockSerializer')); | ||
function _interopRequireDefault(obj) { | ||
return obj && obj.__esModule ? obj : {default: obj}; | ||
} | ||
/** | ||
@@ -23,2 +19,3 @@ * Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. | ||
*/ | ||
const { | ||
@@ -40,12 +37,10 @@ DOMCollection, | ||
AsymmetricMatcher | ||
]; // Prepend to list so the last added is the first tested. | ||
]; | ||
// Prepend to list so the last added is the first tested. | ||
const addSerializer = plugin => { | ||
PLUGINS = [plugin].concat(PLUGINS); | ||
}; | ||
exports.addSerializer = addSerializer; | ||
const getSerializers = () => PLUGINS; | ||
exports.getSerializers = getSerializers; |
@@ -20,25 +20,14 @@ 'use strict'; | ||
void 0; | ||
var _chalk = _interopRequireDefault(require('chalk')); | ||
var _expectUtils = require('@jest/expect-utils'); | ||
var _jestDiff = require('jest-diff'); | ||
var _jestGetType = require('jest-get-type'); | ||
var _jestMatcherUtils = require('jest-matcher-utils'); | ||
var _prettyFormat = require('pretty-format'); | ||
var _colors = require('./colors'); | ||
var _dedentLines = require('./dedentLines'); | ||
var _utils = require('./utils'); | ||
function _interopRequireDefault(obj) { | ||
return obj && obj.__esModule ? obj : {default: obj}; | ||
} | ||
/** | ||
@@ -50,5 +39,5 @@ * Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. | ||
*/ | ||
const getSnapshotColorForChalkInstance = chalkInstance => { | ||
const level = chalkInstance.level; | ||
if (level === 3) { | ||
@@ -67,3 +56,2 @@ return chalkInstance | ||
} | ||
if (level === 2) { | ||
@@ -74,11 +62,7 @@ return chalkInstance | ||
} | ||
return chalkInstance.magenta.bgYellowBright; | ||
}; | ||
exports.getSnapshotColorForChalkInstance = getSnapshotColorForChalkInstance; | ||
const getReceivedColorForChalkInstance = chalkInstance => { | ||
const level = chalkInstance.level; | ||
if (level === 3) { | ||
@@ -97,3 +81,2 @@ return chalkInstance | ||
} | ||
if (level === 2) { | ||
@@ -104,6 +87,4 @@ return chalkInstance | ||
} | ||
return chalkInstance.cyan.bgWhiteBright; // also known as teal | ||
}; | ||
exports.getReceivedColorForChalkInstance = getReceivedColorForChalkInstance; | ||
@@ -114,5 +95,3 @@ const aSnapshotColor = getSnapshotColorForChalkInstance(_chalk.default); | ||
exports.bReceivedColor = bReceivedColor; | ||
const noColor = string => string; | ||
exports.noColor = noColor; | ||
@@ -125,3 +104,2 @@ const HINT_ARG = 'hint'; | ||
exports.PROPERTIES_ARG = PROPERTIES_ARG; | ||
const matcherHintFromConfig = ( | ||
@@ -135,16 +113,11 @@ {context: {isNot, promise}, hint, inlineSnapshot, matcherName, properties}, | ||
}; | ||
if (isUpdatable) { | ||
options.receivedColor = bReceivedColor; | ||
} | ||
let expectedArgument = ''; | ||
if (typeof properties === 'object') { | ||
expectedArgument = PROPERTIES_ARG; | ||
if (isUpdatable) { | ||
options.expectedColor = noColor; | ||
} | ||
if (typeof hint === 'string' && hint.length !== 0) { | ||
@@ -155,3 +128,2 @@ options.secondArgument = HINT_ARG; | ||
options.secondArgument = SNAPSHOT_ARG; | ||
if (isUpdatable) { | ||
@@ -169,3 +141,2 @@ options.secondArgumentColor = aSnapshotColor; | ||
expectedArgument = SNAPSHOT_ARG; | ||
if (isUpdatable) { | ||
@@ -176,3 +147,2 @@ options.expectedColor = aSnapshotColor; | ||
} | ||
return (0, _jestMatcherUtils.matcherHint)( | ||
@@ -184,3 +154,5 @@ matcherName, | ||
); | ||
}; // Given array of diffs, return string: | ||
}; | ||
// Given array of diffs, return string: | ||
// * include common substrings | ||
@@ -190,5 +162,3 @@ // * exclude change substrings which have opposite op | ||
// with change color only if there is a common substring | ||
exports.matcherHintFromConfig = matcherHintFromConfig; | ||
const joinDiffs = (diffs, op, hasCommon) => | ||
@@ -207,10 +177,7 @@ diffs.reduce( | ||
); | ||
const isLineDiffable = received => { | ||
const receivedType = (0, _jestGetType.getType)(received); | ||
if ((0, _jestGetType.isPrimitive)(received)) { | ||
return typeof received === 'string'; | ||
} | ||
if ( | ||
@@ -223,7 +190,5 @@ receivedType === 'date' || | ||
} | ||
if (received instanceof Error) { | ||
return false; | ||
} | ||
if ( | ||
@@ -235,16 +200,10 @@ receivedType === 'object' && | ||
} | ||
return true; | ||
}; | ||
const printExpected = val => | ||
(0, _jestMatcherUtils.EXPECTED_COLOR)((0, _utils.minify)(val)); | ||
exports.printExpected = printExpected; | ||
const printReceived = val => | ||
(0, _jestMatcherUtils.RECEIVED_COLOR)((0, _utils.minify)(val)); | ||
exports.printReceived = printReceived; | ||
const printPropertiesAndReceived = ( | ||
@@ -257,3 +216,2 @@ properties, | ||
const bAnnotation = 'Received value'; | ||
if (isLineDiffable(properties) && isLineDiffable(received)) { | ||
@@ -279,3 +237,2 @@ return (0, _jestDiff.diffLinesUnified)( | ||
} | ||
const printLabel = (0, _jestMatcherUtils.getLabelPrinter)( | ||
@@ -289,6 +246,4 @@ aAnnotation, | ||
}; | ||
exports.printPropertiesAndReceived = printPropertiesAndReceived; | ||
const MAX_DIFF_STRING_LENGTH = 20000; | ||
const printSnapshotAndReceived = (a, b, received, expand, snapshotFormat) => { | ||
@@ -311,3 +266,2 @@ const aAnnotation = 'Snapshot'; | ||
}; | ||
if (typeof received === 'string') { | ||
@@ -322,2 +276,3 @@ if ( | ||
// and received is string which has default serialization. | ||
if (!a.includes('\n') && !b.includes('\n')) { | ||
@@ -328,3 +283,2 @@ // If neither string is multiline, | ||
let bQuoted = b; | ||
if ( | ||
@@ -345,3 +299,2 @@ a.length - 2 <= MAX_DIFF_STRING_LENGTH && | ||
} | ||
const printLabel = (0, _jestMatcherUtils.getLabelPrinter)( | ||
@@ -354,8 +307,9 @@ aAnnotation, | ||
)}${bColor(bQuoted)}`; | ||
} // Else either string is multiline, so display as unquoted strings. | ||
} | ||
// Else either string is multiline, so display as unquoted strings. | ||
a = (0, _utils.deserializeString)(a); // hypothetical expected string | ||
b = received; // not serialized | ||
} // Else expected had custom serialization or was not a string | ||
} | ||
// Else expected had custom serialization or was not a string | ||
// or received has custom serialization. | ||
@@ -368,13 +322,11 @@ | ||
} | ||
if (isLineDiffable(received)) { | ||
const aLines2 = a.split('\n'); | ||
const bLines2 = b.split('\n'); // Fall through to fix a regression for custom serializers | ||
const bLines2 = b.split('\n'); | ||
// Fall through to fix a regression for custom serializers | ||
// like jest-snapshot-serializer-raw that ignore the indent option. | ||
const b0 = (0, _utils.serialize)(received, 0, snapshotFormat); | ||
if (b0 !== b) { | ||
const aLines0 = (0, _dedentLines.dedentLines)(aLines2); | ||
if (aLines0 !== null) { | ||
@@ -391,10 +343,10 @@ // Compare lines without indentation. | ||
} | ||
} // Fall back because: | ||
} | ||
// Fall back because: | ||
// * props include a multiline string | ||
// * text has more than one adjacent line | ||
// * markup does not close | ||
return (0, _jestDiff.diffLinesUnified)(aLines2, bLines2, options); | ||
} | ||
const printLabel = (0, _jestMatcherUtils.getLabelPrinter)( | ||
@@ -408,3 +360,2 @@ aAnnotation, | ||
}; | ||
exports.printSnapshotAndReceived = printSnapshotAndReceived; |
@@ -11,15 +11,9 @@ 'use strict'; | ||
void 0; | ||
var path = _interopRequireWildcard(require('path')); | ||
var _chalk = _interopRequireDefault(require('chalk')); | ||
var _transform = require('@jest/transform'); | ||
var _jestUtil = require('jest-util'); | ||
function _interopRequireDefault(obj) { | ||
return obj && obj.__esModule ? obj : {default: obj}; | ||
} | ||
function _getRequireWildcardCache(nodeInterop) { | ||
@@ -33,3 +27,2 @@ if (typeof WeakMap !== 'function') return null; | ||
} | ||
function _interopRequireWildcard(obj, nodeInterop) { | ||
@@ -67,3 +60,2 @@ if (!nodeInterop && obj && obj.__esModule) { | ||
} | ||
/** | ||
@@ -75,2 +67,3 @@ * Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. | ||
*/ | ||
const EXTENSION = 'snap'; | ||
@@ -80,8 +73,5 @@ exports.EXTENSION = EXTENSION; | ||
exports.DOT_EXTENSION = DOT_EXTENSION; | ||
const isSnapshotPath = path => path.endsWith(DOT_EXTENSION); | ||
exports.isSnapshotPath = isSnapshotPath; | ||
const cache = new Map(); | ||
const buildSnapshotResolver = async ( | ||
@@ -98,11 +88,8 @@ config, | ||
}; | ||
exports.buildSnapshotResolver = buildSnapshotResolver; | ||
async function createSnapshotResolver(localRequire, snapshotResolverPath) { | ||
return typeof snapshotResolverPath === 'string' | ||
? await createCustomSnapshotResolver(snapshotResolverPath, localRequire) | ||
? createCustomSnapshotResolver(snapshotResolverPath, localRequire) | ||
: createDefaultSnapshotResolver(); | ||
} | ||
function createDefaultSnapshotResolver() { | ||
@@ -128,3 +115,2 @@ return { | ||
} | ||
async function createCustomSnapshotResolver( | ||
@@ -157,3 +143,2 @@ snapshotResolverPath, | ||
} | ||
function mustImplement(propName, requiredType) { | ||
@@ -164,3 +149,2 @@ return `${_chalk.default.bold( | ||
} | ||
function verifyConsistentTransformations(custom) { | ||
@@ -171,3 +155,2 @@ const resolvedSnapshotPath = custom.resolveSnapshotPath( | ||
const resolvedTestPath = custom.resolveTestPath(resolvedSnapshotPath); | ||
if (resolvedTestPath !== custom.testPathForConsistencyCheck) { | ||
@@ -174,0 +157,0 @@ throw new Error( |
@@ -7,11 +7,6 @@ 'use strict'; | ||
exports.default = void 0; | ||
var fs = _interopRequireWildcard(require('graceful-fs')); | ||
var _jestMessageUtil = require('jest-message-util'); | ||
var _InlineSnapshots = require('./InlineSnapshots'); | ||
var _utils = require('./utils'); | ||
function _getRequireWildcardCache(nodeInterop) { | ||
@@ -25,3 +20,2 @@ if (typeof WeakMap !== 'function') return null; | ||
} | ||
function _interopRequireWildcard(obj, nodeInterop) { | ||
@@ -59,3 +53,2 @@ if (!nodeInterop && obj && obj.__esModule) { | ||
} | ||
var Symbol = globalThis['jest-symbol-do-not-touch'] || globalThis.Symbol; | ||
@@ -65,7 +58,6 @@ var Symbol = globalThis['jest-symbol-do-not-touch'] || globalThis.Symbol; | ||
globalThis[Symbol.for('jest-native-exists-file')] || fs.existsSync; | ||
class SnapshotState { | ||
_counters; | ||
_dirty; // @ts-expect-error - seemingly unused? | ||
_dirty; | ||
// @ts-expect-error - seemingly unused? | ||
_index; | ||
@@ -86,3 +78,2 @@ _updateSnapshot; | ||
updated; | ||
constructor(snapshotPath, options) { | ||
@@ -111,3 +102,2 @@ this._snapshotPath = snapshotPath; | ||
} | ||
markSnapshotsAsCheckedForTest(testName) { | ||
@@ -120,6 +110,4 @@ this._uncheckedKeys.forEach(uncheckedKey => { | ||
} | ||
_addSnapshot(key, receivedSerialized, options) { | ||
this._dirty = true; | ||
if (options.isInline) { | ||
@@ -131,3 +119,2 @@ const error = options.error || new Error(); | ||
const frame = (0, _jestMessageUtil.getTopFrame)(lines); | ||
if (!frame) { | ||
@@ -138,3 +125,2 @@ throw new Error( | ||
} | ||
this._inlineSnapshots.push({ | ||
@@ -148,3 +134,2 @@ frame, | ||
} | ||
clear() { | ||
@@ -160,3 +145,2 @@ this._snapshotData = this._initialData; | ||
} | ||
save() { | ||
@@ -170,3 +154,2 @@ const hasExternalSnapshots = Object.keys(this._snapshotData).length; | ||
}; | ||
if ((this._dirty || this._uncheckedKeys.size) && !isEmpty) { | ||
@@ -176,3 +159,2 @@ if (hasExternalSnapshots) { | ||
} | ||
if (hasInlineSnapshots) { | ||
@@ -185,3 +167,2 @@ (0, _InlineSnapshots.saveInlineSnapshots)( | ||
} | ||
status.saved = true; | ||
@@ -192,42 +173,32 @@ } else if (!hasExternalSnapshots && jestExistsFile(this._snapshotPath)) { | ||
} | ||
status.deleted = true; | ||
} | ||
return status; | ||
} | ||
getUncheckedCount() { | ||
return this._uncheckedKeys.size || 0; | ||
} | ||
getUncheckedKeys() { | ||
return Array.from(this._uncheckedKeys); | ||
} | ||
removeUncheckedKeys() { | ||
if (this._updateSnapshot === 'all' && this._uncheckedKeys.size) { | ||
this._dirty = true; | ||
this._uncheckedKeys.forEach(key => delete this._snapshotData[key]); | ||
this._uncheckedKeys.clear(); | ||
} | ||
} | ||
match({testName, received, key, inlineSnapshot, isInline, error}) { | ||
this._counters.set(testName, (this._counters.get(testName) || 0) + 1); | ||
const count = Number(this._counters.get(testName)); | ||
if (!key) { | ||
key = (0, _utils.testNameToKey)(testName, count); | ||
} // Do not mark the snapshot as "checked" if the snapshot is inline and | ||
} | ||
// Do not mark the snapshot as "checked" if the snapshot is inline and | ||
// there's an external snapshot. This way the external snapshot can be | ||
// removed with `--updateSnapshot`. | ||
if (!(isInline && this._snapshotData[key] !== undefined)) { | ||
this._uncheckedKeys.delete(key); | ||
} | ||
const receivedSerialized = (0, _utils.addExtraLineBreaks)( | ||
@@ -240,3 +211,2 @@ (0, _utils.serialize)(received, undefined, this.snapshotFormat) | ||
const snapshotIsPersisted = isInline || fs.existsSync(this._snapshotPath); | ||
if (pass && !isInline) { | ||
@@ -250,3 +220,5 @@ // Executing a snapshot file as JavaScript and writing the strings back | ||
this._snapshotData[key] = receivedSerialized; | ||
} // These are the conditions on when to write snapshots: | ||
} | ||
// These are the conditions on when to write snapshots: | ||
// * There's no snapshot file in a non-CI environment. | ||
@@ -258,3 +230,2 @@ // * There is a snapshot file and we decided to update the snapshot. | ||
// * There's no snapshot file or a file without this snapshot on a CI environment. | ||
if ( | ||
@@ -272,3 +243,2 @@ (hasSnapshot && this._updateSnapshot === 'all') || | ||
} | ||
this._addSnapshot(key, receivedSerialized, { | ||
@@ -286,6 +256,4 @@ error, | ||
}); | ||
this.added++; | ||
} | ||
return { | ||
@@ -323,14 +291,9 @@ actual: '', | ||
} | ||
fail(testName, _received, key) { | ||
this._counters.set(testName, (this._counters.get(testName) || 0) + 1); | ||
const count = Number(this._counters.get(testName)); | ||
if (!key) { | ||
key = (0, _utils.testNameToKey)(testName, count); | ||
} | ||
this._uncheckedKeys.delete(key); | ||
this.unmatched++; | ||
@@ -340,3 +303,2 @@ return key; | ||
} | ||
exports.default = SnapshotState; |
@@ -23,19 +23,11 @@ 'use strict'; | ||
void 0; | ||
var path = _interopRequireWildcard(require('path')); | ||
var _chalk = _interopRequireDefault(require('chalk')); | ||
var fs = _interopRequireWildcard(require('graceful-fs')); | ||
var _naturalCompare = _interopRequireDefault(require('natural-compare')); | ||
var _prettyFormat = require('pretty-format'); | ||
var _plugins = require('./plugins'); | ||
function _interopRequireDefault(obj) { | ||
return obj && obj.__esModule ? obj : {default: obj}; | ||
} | ||
function _getRequireWildcardCache(nodeInterop) { | ||
@@ -49,3 +41,2 @@ if (typeof WeakMap !== 'function') return null; | ||
} | ||
function _interopRequireWildcard(obj, nodeInterop) { | ||
@@ -83,3 +74,2 @@ if (!nodeInterop && obj && obj.__esModule) { | ||
} | ||
var Symbol = globalThis['jest-symbol-do-not-touch'] || globalThis.Symbol; | ||
@@ -100,3 +90,2 @@ var Symbol = globalThis['jest-symbol-do-not-touch'] || globalThis.Symbol; | ||
exports.SNAPSHOT_GUIDE_LINK = SNAPSHOT_GUIDE_LINK; | ||
const SNAPSHOT_VERSION_WARNING = _chalk.default.yellow( | ||
@@ -107,12 +96,8 @@ `${_chalk.default.bold('Warning')}: Before you upgrade snapshots, ` + | ||
); | ||
exports.SNAPSHOT_VERSION_WARNING = SNAPSHOT_VERSION_WARNING; | ||
const writeSnapshotVersion = () => | ||
`// Jest Snapshot v${SNAPSHOT_VERSION}, ${SNAPSHOT_GUIDE_LINK}`; | ||
const validateSnapshotVersion = snapshotContents => { | ||
const versionTest = SNAPSHOT_VERSION_REGEXP.exec(snapshotContents); | ||
const version = versionTest && versionTest[1]; | ||
if (!version) { | ||
@@ -130,5 +115,5 @@ return new Error( | ||
} | ||
if (version < SNAPSHOT_VERSION) { | ||
return new Error( // eslint-disable-next-line prefer-template | ||
return new Error( | ||
// eslint-disable-next-line prefer-template | ||
_chalk.default.red( | ||
@@ -149,5 +134,5 @@ `${_chalk.default.red.bold( | ||
} | ||
if (version > SNAPSHOT_VERSION) { | ||
return new Error( // eslint-disable-next-line prefer-template | ||
return new Error( | ||
// eslint-disable-next-line prefer-template | ||
_chalk.default.red( | ||
@@ -167,14 +152,9 @@ `${_chalk.default.red.bold( | ||
} | ||
return null; | ||
}; | ||
function isObject(item) { | ||
return item != null && typeof item === 'object' && !Array.isArray(item); | ||
} | ||
const testNameToKey = (testName, count) => `${testName} ${count}`; | ||
exports.testNameToKey = testNameToKey; | ||
const keyToTestName = key => { | ||
@@ -184,8 +164,5 @@ if (!/ \d+$/.test(key)) { | ||
} | ||
return key.replace(/ \d+$/, ''); | ||
}; | ||
exports.keyToTestName = keyToTestName; | ||
const getSnapshotData = (snapshotPath, update) => { | ||
@@ -195,7 +172,6 @@ const data = Object.create(null); | ||
let dirty = false; | ||
if (jestExistsFile(snapshotPath)) { | ||
try { | ||
snapshotContents = jestReadFile(snapshotPath, 'utf8'); // eslint-disable-next-line no-new-func | ||
snapshotContents = jestReadFile(snapshotPath, 'utf8'); | ||
// eslint-disable-next-line no-new-func | ||
const populate = new Function('exports', snapshotContents); | ||
@@ -205,14 +181,10 @@ populate(data); | ||
} | ||
const validationResult = validateSnapshotVersion(snapshotContents); | ||
const isInvalid = snapshotContents && validationResult; | ||
if (update === 'none' && isInvalid) { | ||
throw validationResult; | ||
} | ||
if ((update === 'all' || update === 'new') && isInvalid) { | ||
dirty = true; | ||
} | ||
return { | ||
@@ -222,14 +194,14 @@ data, | ||
}; | ||
}; // Add extra line breaks at beginning and end of multiline snapshot | ||
}; | ||
// Add extra line breaks at beginning and end of multiline snapshot | ||
// to make the content easier to read. | ||
exports.getSnapshotData = getSnapshotData; | ||
const addExtraLineBreaks = string => | ||
string.includes('\n') ? `\n${string}\n` : string; | ||
const addExtraLineBreaks = string => | ||
string.includes('\n') ? `\n${string}\n` : string; // Remove extra line breaks at beginning and end of multiline snapshot. | ||
// Remove extra line breaks at beginning and end of multiline snapshot. | ||
// Instead of trim, which can remove additional newlines or spaces | ||
// at beginning or end of the content from a custom serializer. | ||
exports.addExtraLineBreaks = addExtraLineBreaks; | ||
const removeExtraLineBreaks = string => | ||
@@ -239,8 +211,5 @@ string.length > 2 && string.startsWith('\n') && string.endsWith('\n') | ||
: string; | ||
exports.removeExtraLineBreaks = removeExtraLineBreaks; | ||
const removeLinesBeforeExternalMatcherTrap = stack => { | ||
const lines = stack.split('\n'); | ||
for (let i = 0; i < lines.length; i += 1) { | ||
@@ -253,6 +222,4 @@ // It's a function name specified in `packages/expect/src/index.ts` | ||
} | ||
return stack; | ||
}; | ||
exports.removeLinesBeforeExternalMatcherTrap = | ||
@@ -262,3 +229,2 @@ removeLinesBeforeExternalMatcherTrap; | ||
const printFunctionName = false; | ||
const serialize = (val, indent = 2, formatOverrides = {}) => | ||
@@ -274,5 +240,3 @@ normalizeNewlines( | ||
); | ||
exports.serialize = serialize; | ||
const minify = val => | ||
@@ -284,17 +248,12 @@ (0, _prettyFormat.format)(val, { | ||
printFunctionName | ||
}); // Remove double quote marks and unescape double quotes and backslashes. | ||
}); | ||
// Remove double quote marks and unescape double quotes and backslashes. | ||
exports.minify = minify; | ||
const deserializeString = stringified => | ||
stringified.slice(1, -1).replace(/\\("|\\)/g, '$1'); | ||
exports.deserializeString = deserializeString; | ||
const escapeBacktickString = str => str.replace(/`|\\|\${/g, '\\$&'); | ||
exports.escapeBacktickString = escapeBacktickString; | ||
const printBacktickString = str => `\`${escapeBacktickString(str)}\``; | ||
const ensureDirectoryExists = filePath => { | ||
@@ -307,7 +266,4 @@ try { | ||
}; | ||
exports.ensureDirectoryExists = ensureDirectoryExists; | ||
const normalizeNewlines = string => string.replace(/\r\n|\r/g, '\n'); | ||
const saveSnapshotFile = (snapshotData, snapshotPath) => { | ||
@@ -328,5 +284,3 @@ const snapshots = Object.keys(snapshotData) | ||
}; | ||
exports.saveSnapshotFile = saveSnapshotFile; | ||
const deepMergeArray = (target, source) => { | ||
@@ -336,3 +290,2 @@ const mergedOutput = Array.from(target); | ||
const targetElement = mergedOutput[index]; | ||
if (Array.isArray(target[index])) { | ||
@@ -348,7 +301,10 @@ mergedOutput[index] = deepMergeArray(target[index], sourceElement); | ||
return mergedOutput; | ||
}; // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types | ||
}; | ||
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types | ||
const deepMerge = (target, source) => { | ||
if (isObject(target) && isObject(source)) { | ||
const mergedOutput = {...target}; | ||
const mergedOutput = { | ||
...target | ||
}; | ||
Object.keys(source).forEach(key => { | ||
@@ -373,6 +329,4 @@ if (isObject(source[key]) && !source[key].$$typeof) { | ||
} | ||
return target; | ||
}; | ||
exports.deepMerge = deepMerge; |
{ | ||
"name": "jest-snapshot", | ||
"version": "29.1.2", | ||
"version": "29.2.0", | ||
"repository": { | ||
@@ -26,5 +26,5 @@ "type": "git", | ||
"@babel/types": "^7.3.3", | ||
"@jest/expect-utils": "^29.1.2", | ||
"@jest/transform": "^29.1.2", | ||
"@jest/types": "^29.1.2", | ||
"@jest/expect-utils": "^29.2.0", | ||
"@jest/transform": "^29.2.0", | ||
"@jest/types": "^29.2.0", | ||
"@types/babel__traverse": "^7.0.6", | ||
@@ -34,12 +34,12 @@ "@types/prettier": "^2.1.5", | ||
"chalk": "^4.0.0", | ||
"expect": "^29.1.2", | ||
"expect": "^29.2.0", | ||
"graceful-fs": "^4.2.9", | ||
"jest-diff": "^29.1.2", | ||
"jest-get-type": "^29.0.0", | ||
"jest-haste-map": "^29.1.2", | ||
"jest-matcher-utils": "^29.1.2", | ||
"jest-message-util": "^29.1.2", | ||
"jest-util": "^29.1.2", | ||
"jest-diff": "^29.2.0", | ||
"jest-get-type": "^29.2.0", | ||
"jest-haste-map": "^29.2.0", | ||
"jest-matcher-utils": "^29.2.0", | ||
"jest-message-util": "^29.2.0", | ||
"jest-util": "^29.2.0", | ||
"natural-compare": "^1.4.0", | ||
"pretty-format": "^29.1.2", | ||
"pretty-format": "^29.2.0", | ||
"semver": "^7.3.5" | ||
@@ -50,3 +50,3 @@ }, | ||
"@babel/preset-react": "^7.12.1", | ||
"@jest/test-utils": "^29.1.2", | ||
"@jest/test-utils": "^29.2.0", | ||
"@tsd/typescript": "~4.8.2", | ||
@@ -67,3 +67,3 @@ "@types/graceful-fs": "^4.1.3", | ||
}, | ||
"gitHead": "3c31dd619e8c022cde53f40fa12ea2a67f4752ce" | ||
"gitHead": "ee5b37a4f4433afcfffb0356cea47739d8092287" | ||
} |
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
2447
82641
Updated@jest/expect-utils@^29.2.0
Updated@jest/transform@^29.2.0
Updated@jest/types@^29.2.0
Updatedexpect@^29.2.0
Updatedjest-diff@^29.2.0
Updatedjest-get-type@^29.2.0
Updatedjest-haste-map@^29.2.0
Updatedjest-matcher-utils@^29.2.0
Updatedjest-message-util@^29.2.0
Updatedjest-util@^29.2.0
Updatedpretty-format@^29.2.0