Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

jest-snapshot

Package Overview
Dependencies
Maintainers
3
Versions
280
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

jest-snapshot - npm Package Compare versions

Comparing version 19.1.0-alpha.eed82034 to 19.2.0-alpha.993e64af

69

build/index.js

@@ -15,2 +15,3 @@ /**

const diff = require('jest-diff');

@@ -49,3 +50,3 @@ const fs = require('fs');

map(snapshotFile => {
if (update) {
if (update === 'all') {
fs.unlinkSync(snapshotFile);

@@ -60,9 +61,2 @@ }

const initializeSnapshotState = (
testFile,
update,
testPath,
expand) =>
new SnapshotState(testFile, update, testPath, expand);
const toMatchSnapshot = function (received, testName) {

@@ -81,13 +75,22 @@ this.dontThrow && this.dontThrow();const

const result = snapshotState.match(testName || currentTestName, received);const
pass = result.pass;
const result = snapshotState.match(
testName || currentTestName || '',
received);const
count = result.count,pass = result.pass;let
actual = result.actual,expected = result.expected;
let report;
if (pass) {
return { message: '', pass: true };
} else {const
count = result.count,expected = result.expected,actual = result.actual;
const expectedString = expected.trim();
const actualString = actual.trim();
const diffMessage = diff(expectedString, actualString, {
} else if (!expected) {
report = () =>
`New snapshot was ${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.`;
} else {
expected = (expected || '').trim();
actual = (actual || '').trim();
const diffMessage = diff(expected, actual, {
aAnnotation: 'Snapshot',

@@ -98,25 +101,22 @@ bAnnotation: 'Received',

const report = () =>
report = () =>
`${RECEIVED_COLOR('Received value')} does not match ` +
`${EXPECTED_COLOR('stored snapshot ' + count)}.\n\n` + (
diffMessage ||
RECEIVED_COLOR('- ' + expectedString) +
RECEIVED_COLOR('- ' + (expected || '')) +
'\n' +
EXPECTED_COLOR('+ ' + actualString));
EXPECTED_COLOR('+ ' + actual));
}
// Passing the 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: () =>
matcherHint('.toMatchSnapshot', 'value', '') + '\n\n' + report(),
name: 'toMatchSnapshot',
pass: false,
report };
const message = () =>
matcherHint('.toMatchSnapshot', 'value', '') + '\n\n' + report();
// Passing the 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: actualString,
expected: expectedString,
message,
name: 'toMatchSnapshot',
pass: false,
report };
}
};

@@ -162,4 +162,3 @@

getSerializers,
initializeSnapshotState,
toMatchSnapshot,
toThrowErrorMatchingSnapshot };

@@ -10,12 +10,15 @@ /**

*/
'use strict';
'use strict';var _require$plugins =
const ReactElementPlugin = require('pretty-format/build/plugins/ReactElement');
const ReactTestComponentPlugin = require('pretty-format/build/plugins/ReactTestComponent');
const ImmutablePlugins = require('pretty-format/build/plugins/ImmutablePlugins');
let PLUGINS = [ReactElementPlugin, ReactTestComponentPlugin].concat(
ImmutablePlugins);
require('pretty-format').plugins;const HTMLElement = _require$plugins.HTMLElement,Immutable = _require$plugins.Immutable,ReactElement = _require$plugins.ReactElement,ReactTestComponent = _require$plugins.ReactTestComponent;
let PLUGINS = [HTMLElement, ReactElement, ReactTestComponent].concat(Immutable);
// Prepend to list so the last added is the first tested.

@@ -22,0 +25,0 @@ exports.addSerializer = plugin => {

@@ -26,2 +26,8 @@ /**

class SnapshotState {

@@ -41,12 +47,8 @@

constructor(testPath, options) {
this._snapshotPath = options.snapshotPath || getSnapshotPath(testPath);var _getSnapshotData =
getSnapshotData(
this._snapshotPath,
options.updateSnapshot);const data = _getSnapshotData.data,dirty = _getSnapshotData.dirty;
constructor(
testPath,
update,
snapshotPath,
expand)
{
this._snapshotPath = snapshotPath || getSnapshotPath(testPath);var _getSnapshotData =
getSnapshotData(this._snapshotPath, update);const data = _getSnapshotData.data,dirty = _getSnapshotData.dirty;
this._snapshotData = data;

@@ -57,10 +59,8 @@ this._dirty = dirty;

this._index = 0;
this.expand = expand || false;
this.expand = options.expand || false;
this.added = 0;
this.matched = 0;
this.unmatched = 0;
this.update = update;
this._updateSnapshot = options.updateSnapshot;
this.updated = 0;
this.skippedTests = new Set();
this.failedTests = new Set();
}

@@ -81,3 +81,4 @@

save(update) {
save() {
const isEmpty = Object.keys(this._snapshotData).length === 0;
const status = {

@@ -88,4 +89,2 @@ deleted: false,

const isEmpty = Object.keys(this._snapshotData).length === 0;
if ((this._dirty || this._uncheckedKeys.size) && !isEmpty) {

@@ -95,3 +94,3 @@ saveSnapshotFile(this._snapshotData, this._snapshotPath);

} else if (isEmpty && fs.existsSync(this._snapshotPath)) {
if (update) {
if (this._updateSnapshot === 'all') {
fs.unlinkSync(this._snapshotPath);

@@ -110,3 +109,3 @@ }

removeUncheckedKeys() {
if (this._uncheckedKeys.size) {
if (this._updateSnapshot === 'all' && this._uncheckedKeys.size) {
this._dirty = true;

@@ -143,25 +142,37 @@ this._uncheckedKeys.forEach(key => delete this._snapshotData[key]);

// These are the conditions on when to write snapshots:
// * There's no snapshot file in a non-CI environment.
// * There is a snapshot file and we decided to update the snapshot.
// * There is a snapshot file, but it doesn't have this snaphsot.
// These are the conditions on when not to write snapshots:
// * The update flag is set to 'none'.
// * There's no snapshot file or a file without this snapshot on a CI environment.
if (
!fs.existsSync(this._snapshotPath) || // there's no snapshot file
hasSnapshot && this.update || // there is a file, but we're updating
!hasSnapshot // there is a file, but it doesn't have this snaphsot
) {
if (this.update) {
if (!pass) {
if (hasSnapshot) {
this.updated++;
} else {
this.added++;
}
this._addSnapshot(key, receivedSerialized);
hasSnapshot && this._updateSnapshot === 'all' ||
(!hasSnapshot || !fs.existsSync(this._snapshotPath)) && (
this._updateSnapshot === 'new' || this._updateSnapshot === 'all'))
{
if (this._updateSnapshot === 'all') {
if (!pass) {
if (hasSnapshot) {
this.updated++;
} else {
this.matched++;
this.added++;
}
this._addSnapshot(key, receivedSerialized);
} else {
this._addSnapshot(key, receivedSerialized);
this.added++;
this.matched++;
}
} else {
this._addSnapshot(key, receivedSerialized);
this.added++;
}
return { pass: true };
} else {
return {
actual: '',
count,
expected: '',
pass: true };
} else {
if (!pass) {

@@ -172,3 +183,3 @@ this.unmatched++;

count,
expected: unescape(expected),
expected: expected ? unescape(expected) : null,
pass: false };

@@ -178,3 +189,8 @@

this.matched++;
return { pass: true };
return {
actual: '',
count,
expected: '',
pass: true };
}

@@ -181,0 +197,0 @@ }

@@ -117,7 +117,7 @@ /**

if (!update && isInvalid) {
if (update === 'none' && isInvalid) {
throw validationResult;
}
if (update && isInvalid) {
if ((update === 'all' || update === 'new') && isInvalid) {
dirty = true;

@@ -124,0 +124,0 @@ }

{
"name": "jest-snapshot",
"version": "19.1.0-alpha.eed82034",
"version": "19.2.0-alpha.993e64af",
"repository": {

@@ -12,8 +12,8 @@ "type": "git",

"chalk": "^1.1.3",
"jest-diff": "^19.1.0-alpha.eed82034",
"jest-matcher-utils": "^19.1.0-alpha.eed82034",
"jest-util": "^19.1.0-alpha.eed82034",
"jest-diff": "^19.2.0-alpha.993e64af",
"jest-matcher-utils": "^19.2.0-alpha.993e64af",
"jest-util": "^19.2.0-alpha.993e64af",
"natural-compare": "^1.4.0",
"pretty-format": "^19.1.0-alpha.eed82034"
"pretty-format": "^19.2.0-alpha.993e64af"
}
}

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc