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

jest-snapshot

Package Overview
Dependencies
Maintainers
4
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 14.0.0 to 14.2.0-alpha.ca8bfb6e

97

build/index.js

@@ -32,8 +32,8 @@ /**

if (onStart) {
onStart(context);}};}(
onStart(context);
}
};
}(attr.onStart);
};
attr.onStart);};
const patchJasmine = (jasmine, state) => {

@@ -43,41 +43,41 @@ jasmine.Spec = (realSpec => {

patchAttr(attr, state);
realSpec.call(this, attr);};
realSpec.call(this, attr);
};
Spec.prototype = realSpec.prototype;
for (const statics in realSpec) {
if (Object.prototype.hasOwnProperty.call(realSpec, statics)) {
Spec[statics] = realSpec[statics];}}
Spec[statics] = realSpec[statics];
}
}
return Spec;
})(jasmine.Spec);
};
return Spec;})(
jasmine.Spec);};
module.exports = {
EXTENSION,
cleanup(hasteContext, update) {
module.exports = {
EXTENSION,
SnapshotFile: SnapshotFile.SnapshotFile,
cleanup(hasteFS, update) {
const pattern = '\\.' + EXTENSION + '$';
return hasteContext.instance.matchFiles(pattern).then(files => {
const filesRemoved = files.
filter(snapshotFile => !fileExists(
path.resolve(
path.dirname(snapshotFile),
'..',
path.basename(snapshotFile, '.' + EXTENSION)),
const files = hasteFS.matchFiles(pattern);
const filesRemoved = files.
filter(snapshotFile => !fileExists(
path.resolve(
path.dirname(snapshotFile),
'..',
path.basename(snapshotFile, '.' + EXTENSION)),
hasteContext.moduleMap.files)).
hasteFS)).
map(snapshotFile => {
if (update) {
fs.unlinkSync(snapshotFile);}}).
map(snapshotFile => {
if (update) {
fs.unlinkSync(snapshotFile);
}
}).
length;
return {
filesRemoved };
length;
return {
filesRemoved };});},
matcher,
},
matcher,
getSnapshotState: (jasmine, filePath) => {

@@ -87,16 +87,16 @@ let _index = 0;

/* $FlowFixMe */
const state = Object.assign(Object.create(null), {
getCounter: () => _index,
getSpecName: () => _name,
incrementCounter: () => ++_index,
const state = Object.assign(Object.create(null), {
getCounter: () => _index,
getSpecName: () => _name,
incrementCounter: () => ++_index,
setCounter(index) {
_index = index;},
_index = index;
},
setSpecName(name) {
_name = name;},
snapshot: SnapshotFile.forFile(filePath),
added: 0,
updated: 0,
matched: 0,
_name = name;
},
snapshot: SnapshotFile.forFile(filePath),
added: 0,
updated: 0,
matched: 0,
unmatched: 0 });

@@ -106,2 +106,3 @@

patchJasmine(jasmine, state);
return state;} };
return state;
} };

@@ -24,20 +24,20 @@ /**

module.exports = (
filePath,
options,
jasmine,
snapshotState) =>
filePath,
options,
jasmine,
snapshotState) =>
(util, customEquality) => {
return {
return {
negativeCompare() {
throw new Error(
'Jest: `.not` can not be used with `.toMatchSnapshot()`.');},
'Jest: `.not` can not be used with `.toMatchSnapshot()`.');
},
compare(actual, expected) {
if (expected !== undefined) {
throw new Error(
'Jest: toMatchSnapshot() does not accept parameters.');}
'Jest: toMatchSnapshot() does not accept parameters.');
}
const snapshot = snapshotState.snapshot;

@@ -51,5 +51,5 @@ const count = snapshotState.incrementCounter();

if (
!snapshot.fileExists() ||
hasSnapshot && options.updateSnapshot ||
!hasSnapshot)
!snapshot.fileExists() ||
hasSnapshot && options.updateSnapshot ||
!hasSnapshot)
{

@@ -59,16 +59,16 @@ if (options.updateSnapshot) {

if (hasSnapshot) {
snapshotState.updated++;} else
{
snapshotState.added++;}
snapshot.add(key, actual);} else
{
snapshotState.matched++;}} else
{
snapshotState.updated++;
} else {
snapshotState.added++;
}
snapshot.add(key, actual);
} else {
snapshotState.matched++;
}
} else {
snapshot.add(key, actual);
snapshotState.added++;}
pass = true;} else
{
snapshotState.added++;
}
pass = true;
} else {
const matches = snapshot.matches(key, actual);

@@ -78,12 +78,16 @@ pass = matches.pass;

snapshotState.unmatched++;
message =
`expected value to match snapshot ${ count }\n` +
diff(matches.expected.trim(), matches.actual.trim());} else
{
snapshotState.matched++;}}
message =
`expected value to match snapshot ${ count }\n` +
diff(matches.expected.trim(), matches.actual.trim());
} else {
snapshotState.matched++;
}
}
return {
pass,
message };
} };
return {
pass,
message };} };};
};

@@ -40,6 +40,6 @@ /**

try {
createDirectory(path.join(path.dirname(filePath)));}
catch (e) {}};
createDirectory(path.join(path.dirname(filePath)));
} catch (e) {}
};
const escape = string => string.replace(/\`/g, '\\\`');

@@ -50,3 +50,3 @@ const unescape = string => string.replace(/\\(\"|\\|\')/g, '$1');

// to make the content of the snapshot easier to read
const addExtraLineBreaks =
const addExtraLineBreaks =
string => string.includes('\n') ? `\n${ string }\n` : string;

@@ -70,16 +70,16 @@

Object.assign(this._content, require.call(null, filename));
/* eslint-enable no-useless-call */}
catch (e) {}}
/* eslint-enable no-useless-call */
} catch (e) {}
}
this._uncheckedKeys = new Set(Object.keys(this._content));
}
this._uncheckedKeys = new Set(Object.keys(this._content));}
hasUncheckedKeys() {
return this._uncheckedKeys.size > 0;}
return this._uncheckedKeys.size > 0;
}
fileExists() {
return fileExists(this._filename);}
return fileExists(this._filename);
}
removeUncheckedKeys() {

@@ -89,15 +89,15 @@ if (this._uncheckedKeys.size) {

this._uncheckedKeys.forEach(key => delete this._content[key]);
this._uncheckedKeys.clear();}}
this._uncheckedKeys.clear();
}
}
serialize(data) {
return addExtraLineBreaks(prettyFormat(data, {
plugins: [jsxLikeExtension] }));}
return addExtraLineBreaks(prettyFormat(data, {
plugins: [jsxLikeExtension] }));
}
save(update) {
const status = {
deleted: false,
const status = {
deleted: false,
saved: false };

@@ -108,4 +108,4 @@

if ((this._dirty || this._uncheckedKeys.size) && !isEmpty) {
const snapshots = Object.keys(this._content).sort().map(key =>
'exports[`' + escape(key) + '`] = `' +
const snapshots = Object.keys(this._content).sort().map(key =>
'exports[`' + escape(key) + '`] = `' +
escape(this._content[key]) + '`;');

@@ -116,21 +116,21 @@

fs.writeFileSync(this._filename, snapshots.join('\n\n') + '\n');
status.saved = true;} else
if (isEmpty && this.fileExists()) {
status.saved = true;
} else if (isEmpty && this.fileExists()) {
if (update) {
fs.unlinkSync(this._filename);}
fs.unlinkSync(this._filename);
}
status.deleted = true;
}
status.deleted = true;}
return status;
}
return status;}
has(key) {
return this._content[key] !== undefined;}
return this._content[key] !== undefined;
}
get(key) {
return this._content[key];}
return this._content[key];
}
matches(key, value) {

@@ -149,21 +149,21 @@ this._uncheckedKeys.delete(key);

// flag is set.
this._content[key] = serialized;}
this._content[key] = serialized;
}
return {
actual,
expected,
pass };
return {
actual,
expected,
pass };}
}
add(key, value) {
this._dirty = true;
this._uncheckedKeys.delete(key);
this._content[key] = this.serialize(value);}}
this._content[key] = this.serialize(value);
}}
module.exports = {
SNAPSHOT_EXTENSION,
module.exports = {
SNAPSHOT_EXTENSION,
forFile(testPath) {

@@ -173,6 +173,8 @@ const snapshotsPath = path.join(path.dirname(testPath), '__snapshots__');

const snapshotFilename = path.join(
snapshotsPath,
snapshotsPath,
path.basename(testPath) + '.' + SNAPSHOT_EXTENSION);
return new SnapshotFile(snapshotFilename);} };
return new SnapshotFile(snapshotFilename);
},
SnapshotFile };
{
"name": "jest-snapshot",
"version": "14.0.0",
"version": "14.2.0-alpha.ca8bfb6e",
"repository": {

@@ -11,12 +11,7 @@ "type": "git",

"dependencies": {
"jest-diff": "^14.0.0",
"jest-file-exists": "^14.0.0",
"jest-util": "^14.0.0",
"jest-diff": "^14.2.0-alpha.ca8bfb6e",
"jest-file-exists": "^14.2.0-alpha.ca8bfb6e",
"jest-util": "^14.2.0-alpha.ca8bfb6e",
"pretty-format": "^3.5.0"
},
"jest": {
"rootDir": "./src",
"scriptPreprocessor": "../../babel-jest",
"testEnvironment": "node"
},
"scripts": {

@@ -23,0 +18,0 @@ "test": "../jest-cli/bin/jest.js"

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