You're Invited:Meet the Socket Team at RSAC and BSidesSF 2026, March 23–26.RSVP
Socket
Book a DemoSign in
Socket

@jest/snapshot-utils

Package Overview
Dependencies
Maintainers
5
Versions
17
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@jest/snapshot-utils - npm Package Compare versions

Comparing version
30.0.5
to
30.1.0
+11
-5
build/index.js

@@ -82,9 +82,10 @@ /*!

const SNAPSHOT_VERSION = exports.SNAPSHOT_VERSION = '1';
const SNAPSHOT_VERSION_REGEXP = /^\/\/ Jest Snapshot v(.+),/;
const SNAPSHOT_HEADER_REGEXP = /^\/\/ Jest Snapshot v(.+), (.+)\n/;
const SNAPSHOT_GUIDE_LINK = exports.SNAPSHOT_GUIDE_LINK = 'https://jestjs.io/docs/snapshot-testing';
const SNAPSHOT_VERSION_WARNING = exports.SNAPSHOT_VERSION_WARNING = _chalk.default.yellow(`${_chalk.default.bold('Warning')}: Before you upgrade snapshots, ` + 'we recommend that you revert any local changes to tests or other code, ' + 'to ensure that you do not store invalid state.');
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];
const validateSnapshotHeader = snapshotContents => {
const headerTest = SNAPSHOT_HEADER_REGEXP.exec(snapshotContents);
const version = headerTest && headerTest[1];
const guideLink = headerTest && headerTest[2];
if (!version) {

@@ -103,2 +104,7 @@ return new Error(_chalk.default.red(`${_chalk.default.bold('Outdated snapshot')}: No snapshot header found. ` + 'Jest 19 introduced versioned snapshots to ensure all developers ' + 'on a project are using the same version of Jest. ' + 'Please update all snapshots during this upgrade of Jest.\n\n') + SNAPSHOT_VERSION_WARNING);

}
if (guideLink !== SNAPSHOT_GUIDE_LINK) {
return new Error(
// eslint-disable-next-line prefer-template
_chalk.default.red(`${_chalk.default.red.bold('Outdated guide link')}: The snapshot guide link is outdated.` + 'Please update all snapshots while upgrading of Jest') + '\n\n' + `Expected: ${SNAPSHOT_GUIDE_LINK}\n` + `Received: ${guideLink}`);
}
return null;

@@ -152,3 +158,3 @@ };

}
const validationResult = validateSnapshotVersion(snapshotContents);
const validationResult = validateSnapshotHeader(snapshotContents);
const isInvalid = snapshotContents && validationResult;

@@ -155,0 +161,0 @@ if (update === 'none' && isInvalid) {

{
"name": "@jest/snapshot-utils",
"version": "30.0.5",
"version": "30.1.0",
"repository": {

@@ -37,3 +37,3 @@ "type": "git",

},
"gitHead": "22236cf58b66039f81893537c90dee290bab427f"
"gitHead": "4d5f41d0885c1d9630c81b4fd47f74ab0615e18f"
}

@@ -160,2 +160,22 @@ /**

test('getSnapshotData() throws for deprecated snapshot guide link', () => {
const deprecatedGuideLink = 'https://goo.gl/fbAQLP';
const filename = path.join(__dirname, 'old-snapshot.snap');
jest
.mocked(fs.readFileSync)
.mockReturnValue(
`// Jest Snapshot v1, ${deprecatedGuideLink}\n\n` +
'exports[`myKey`] = `<div>\n</div>`;\n',
);
const update = 'none';
expect(() => getSnapshotData(filename, update)).toThrow(
`${chalk.red(
`${chalk.red.bold('Outdated guide link')}: The snapshot guide link is outdated.` +
'Please update all snapshots while upgrading of Jest',
)}\n\nExpected: ${SNAPSHOT_GUIDE_LINK}\n` +
`Received: ${deprecatedGuideLink}`,
);
});
test('getSnapshotData() does not throw for when updating', () => {

@@ -162,0 +182,0 @@ const filename = path.join(__dirname, 'old-snapshot.snap');

@@ -16,3 +16,3 @@ /**

export const SNAPSHOT_VERSION = '1';
const SNAPSHOT_VERSION_REGEXP = /^\/\/ Jest Snapshot v(.+),/;
const SNAPSHOT_HEADER_REGEXP = /^\/\/ Jest Snapshot v(.+), (.+)\n/;
export const SNAPSHOT_GUIDE_LINK = 'https://jestjs.io/docs/snapshot-testing';

@@ -28,5 +28,6 @@ export const SNAPSHOT_VERSION_WARNING = chalk.yellow(

const validateSnapshotVersion = (snapshotContents: string) => {
const versionTest = SNAPSHOT_VERSION_REGEXP.exec(snapshotContents);
const version = versionTest && versionTest[1];
const validateSnapshotHeader = (snapshotContents: string) => {
const headerTest = SNAPSHOT_HEADER_REGEXP.exec(snapshotContents);
const version = headerTest && headerTest[1];
const guideLink = headerTest && headerTest[2];

@@ -77,2 +78,15 @@ if (!version) {

if (guideLink !== SNAPSHOT_GUIDE_LINK) {
return new Error(
// eslint-disable-next-line prefer-template
chalk.red(
`${chalk.red.bold('Outdated guide link')}: The snapshot guide link is outdated.` +
'Please update all snapshots while upgrading of Jest',
) +
'\n\n' +
`Expected: ${SNAPSHOT_GUIDE_LINK}\n` +
`Received: ${guideLink}`,
);
}
return null;

@@ -140,3 +154,3 @@ };

const validationResult = validateSnapshotVersion(snapshotContents);
const validationResult = validateSnapshotHeader(snapshotContents);
const isInvalid = snapshotContents && validationResult;

@@ -143,0 +157,0 @@