Skip to content

Commit

Permalink
fix: only updatePassedSnapshot if updateSnapshot is also true (#327)
Browse files Browse the repository at this point in the history
* 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](kornelski/http-cache-semantics@v4.1.0...v4.1.1)

---
updated-dependencies:
- dependency-name: http-cache-semantics
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <[email protected]>
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 6cf2343.

---------

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
  • Loading branch information
goverdhan07 and dependabot[bot] authored Jul 25, 2023
1 parent ce33742 commit b9d9c3f
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 4 deletions.
16 changes: 16 additions & 0 deletions __tests__/diff-snapshot.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 });

Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 2 additions & 3 deletions src/diff-snapshot.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit b9d9c3f

Please sign in to comment.