Socket
Socket
Sign inDemoInstall

jest-image-snapshot

Package Overview
Dependencies
Maintainers
5
Versions
46
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

jest-image-snapshot - npm Package Compare versions

Comparing version 6.2.0 to 6.3.0

7

CHANGELOG.md

@@ -0,1 +1,8 @@

# [6.3.0](https://github.com/americanexpress/jest-image-snapshot/compare/v6.2.0...v6.3.0) (2023-11-28)
### Features
* Add `runtimeHooksPath` options ([#337](https://github.com/americanexpress/jest-image-snapshot/issues/337)) ([57741a2](https://github.com/americanexpress/jest-image-snapshot/commit/57741a242cd2192c453a87c34fa89c7c35a0763c))
# [6.2.0](https://github.com/americanexpress/jest-image-snapshot/compare/v6.1.1...v6.2.0) (2023-07-25)

@@ -2,0 +9,0 @@

8

package.json
{
"name": "jest-image-snapshot",
"version": "6.2.0",
"version": "6.3.0",
"description": "Jest matcher for image comparisons. Most commonly used for visual regression testing.",

@@ -33,3 +33,3 @@ "main": "src/index.js",

"testMatch": [
"<rootDir>/__tests__/**/*.js"
"<rootDir>/__tests__/**/*.spec.js"
],

@@ -48,4 +48,4 @@ "coveragePathIgnorePatterns": [

"devDependencies": {
"@commitlint/cli": "^8.3.5",
"@commitlint/config-conventional": "^8.3.4",
"@commitlint/cli": "^17.6.5",
"@commitlint/config-conventional": "^17.7.0",
"@semantic-release/changelog": "^5.0.0",

@@ -52,0 +52,0 @@ "@semantic-release/git": "^9.0.0",

@@ -127,2 +127,5 @@ <h1 align="center">

* `allowSizeMismatch`: (default `false`) If set to true, the build will not fail when the screenshots to compare have different sizes.
* `runtimeHooksPath`: (default `undefined`) This needs to be set to a existing file, like `require.resolve('./runtimeHooksPath.cjs')`. This file can expose a few hooks:
* `onBeforeWriteToDisc`: before saving any image to the disc, this function will be called (can be used to write EXIF data to images for instance)
`onBeforeWriteToDisc: (arguments: { buffer: Buffer; destination: string; testPath: string; currentTestName: string }) => Buffer`

@@ -129,0 +132,0 @@ ```javascript

@@ -203,2 +203,34 @@ /*

function writeFileWithHooks({
pathToFile,
content,
runtimeHooksPath,
testPath,
currentTestName,
}) {
let finalContent = content;
if (runtimeHooksPath) {
let runtimeHooks;
try {
// As `diffImageToSnapshot` can be called in a worker, and as we cannot pass a function
// to a worker, we need to use an external file path that can be imported
// eslint-disable-next-line import/no-dynamic-require, global-require
runtimeHooks = require(runtimeHooksPath);
} catch (e) {
throw new Error(`Couldn't import ${runtimeHooksPath}: ${e.message}`);
}
try {
finalContent = runtimeHooks.onBeforeWriteToDisc({
buffer: content,
destination: pathToFile,
testPath,
currentTestName,
});
} catch (e) {
throw new Error(`Couldn't execute onBeforeWriteToDisc: ${e.message}`);
}
}
fs.writeFileSync(pathToFile, finalContent);
}
function diffImageToSnapshot(options) {

@@ -223,2 +255,5 @@ const {

comparisonMethod = 'pixelmatch',
testPath,
currentTestName,
runtimeHooksPath,
} = options;

@@ -231,3 +266,9 @@

fs.mkdirSync(path.dirname(baselineSnapshotPath), { recursive: true });
fs.writeFileSync(baselineSnapshotPath, receivedImageBuffer);
writeFileWithHooks({
pathToFile: baselineSnapshotPath,
content: receivedImageBuffer,
runtimeHooksPath,
testPath,
currentTestName,
});
result = { added: true };

@@ -300,3 +341,9 @@ } else {

fs.mkdirSync(path.dirname(receivedSnapshotPath), { recursive: true });
fs.writeFileSync(receivedSnapshotPath, receivedImageBuffer);
writeFileWithHooks({
pathToFile: receivedSnapshotPath,
content: receivedImageBuffer,
runtimeHooksPath,
testPath,
currentTestName,
});
result = { receivedSnapshotPath };

@@ -327,3 +374,9 @@ }

const pngBuffer = PNG.sync.write(compositeResultImage, { filterType: 4 });
fs.writeFileSync(diffOutputPath, pngBuffer);
writeFileWithHooks({
pathToFile: diffOutputPath,
content: pngBuffer,
runtimeHooksPath,
testPath,
currentTestName,
});

@@ -342,3 +395,9 @@ result = {

fs.mkdirSync(path.dirname(baselineSnapshotPath), { recursive: true });
fs.writeFileSync(baselineSnapshotPath, receivedImageBuffer);
writeFileWithHooks({
pathToFile: baselineSnapshotPath,
content: receivedImageBuffer,
runtimeHooksPath,
testPath,
currentTestName,
});
result = { updated: true };

@@ -345,0 +404,0 @@ } else {

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

onlyDiff: commonOnlyDiff = false,
runtimeHooksPath: commonRuntimeHooksPath = undefined,
diffDirection: commonDiffDirection = 'horizontal',

@@ -164,2 +165,3 @@ noColors: commonNoColors,

onlyDiff = commonOnlyDiff,
runtimeHooksPath = commonRuntimeHooksPath,
diffDirection = commonDiffDirection,

@@ -229,2 +231,4 @@ customDiffConfig = {},

diffDirection,
testPath,
currentTestName,
onlyDiff,

@@ -240,2 +244,3 @@ snapshotIdentifier,

comparisonMethod,
runtimeHooksPath,
});

@@ -242,0 +247,0 @@

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