From b9d9c3f16ab0e10a3e1320d03efb52e81675d2aa Mon Sep 17 00:00:00 2001 From: Goverdhan Biradar Date: Tue, 25 Jul 2023 23:38:25 +0530 Subject: [PATCH] fix: only updatePassedSnapshot if updateSnapshot is also true (#327) * chore(deps): bump qs from 6.5.2 to 6.5.3 (#320) * chore(deps): make jest optional peerDependency (#322) * chore(deps): bump http-cache-semantics from 4.1.0 to 4.1.1 (#324) Bumps [http-cache-semantics](https://github.com/kornelski/http-cache-semantics) from 4.1.0 to 4.1.1. - [Release notes](https://github.com/kornelski/http-cache-semantics/releases) - [Commits](https://github.com/kornelski/http-cache-semantics/compare/v4.1.0...v4.1.1) --- updated-dependencies: - dependency-name: http-cache-semantics dependency-type: indirect ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * fix: updatePassedSnapshot to only update passed snapshots when jest --updatesnapshot flag is present * fix: fixed indentations * fix: added unit test case * removed package.json file * Revert "removed package.json file" This reverts commit 6cf2343696f91bea7cbd2c7fa69b55507fbd8710. --------- Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- __tests__/diff-snapshot.spec.js | 16 ++++++++++++++++ package-lock.json | 2 +- src/diff-snapshot.js | 5 ++--- 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/__tests__/diff-snapshot.spec.js b/__tests__/diff-snapshot.spec.js index bb5a868..e635fcd 100644 --- a/__tests__/diff-snapshot.spec.js +++ b/__tests__/diff-snapshot.spec.js @@ -693,6 +693,22 @@ describe('diff-snapshot', () => { expect(diffResult).toHaveProperty('diffOutputPath', path.join(mockSnapshotsDir, '__diff_output__', `${mockSnapshotIdentifier}-diff.png`)); }); + describe('diffImageToSnapshot', () => { + it('should fail if snapshot already exists', () => { + const { diffImageToSnapshot } = setupTest({ snapshotExists: true }); + const options = { + receivedImageBuffer: mockFailImageBuffer, + snapshotIdentifier: mockSnapshotIdentifier, + snapshotsDir: mockSnapshotsDir, + updateSnapshot: false, + }; + + expect(() => { + diffImageToSnapshot(options); + }).toThrow(); + }); + }); + it('should throw an error if an unknown threshold type is supplied', () => { const diffImageToSnapshot = setupTest({ snapshotExists: true }); diff --git a/package-lock.json b/package-lock.json index 371a51d..4250e8a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -11785,4 +11785,4 @@ "dev": true } } -} +} \ No newline at end of file diff --git a/src/diff-snapshot.js b/src/diff-snapshot.js index aa3c62c..8ce841b 100644 --- a/src/diff-snapshot.js +++ b/src/diff-snapshot.js @@ -147,9 +147,8 @@ const alignImagesToSameSize = (firstImage, secondImage) => { const isFailure = ({ pass, updateSnapshot }) => !pass && !updateSnapshot; -const shouldUpdate = ({ pass, updateSnapshot, updatePassedSnapshot }) => ( - (!pass && updateSnapshot) || (pass && updatePassedSnapshot) -); +const shouldUpdate = ({ pass, updateSnapshot, updatePassedSnapshot }) => + updateSnapshot && (!pass || (pass && updatePassedSnapshot)); const shouldFail = ({ totalPixels,