Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Changes to consider only updatePassedSnapshot if updateSnapshot is also true #327

Merged
merged 9 commits into from
Jul 25, 2023
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 }) =>
goverdhan07 marked this conversation as resolved.
Show resolved Hide resolved
updateSnapshot && (!pass || (pass && updatePassedSnapshot));

const shouldFail = ({
totalPixels,
Expand Down
Loading