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

feat: allow storing received screenshot on failure #298

Conversation

ablok
Copy link
Contributor

@ablok ablok commented May 12, 2022

Description

Currently, when a screenshot test fails, the actual (received) image is not stored, other than in a diff image. This PR allows users to set 2 variables: storeReceivedOnFailure and customReceivedDir.
When a test fails, and storeReceivedOnFailure is set to true, the received image will also be stored. You can optionally specify a custom location where to store these images by setting customReceivedDir.
Not really sure about the naming. Could also use actual instead of received. The feature is currently an addition, but could also be a toggle between storing the composed diff image or storing seperate images. 🤷‍♂️

Motivation and Context

This fixes #260 .
This is useful when running in CI. If a screenshot test fails. you can get a new baseline image directly from the build and commit it as the new baseline if the change is as expected.

How Has This Been Tested?

Added unit tests. Tested it locally.

Types of Changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation (adding or updating documentation)
  • Dependency update

Checklist:

  • My change requires a change to the documentation and I have updated the documentation accordingly.
  • My changes are in sync with the code style of this project.
  • There aren't any other open Pull Requests for the same issue/update.
  • These changes should be applied to a maintenance branch.
  • I have added the Apache 2.0 license header to any new files created.

What is the Impact to Developers Using Jest-Image-Snapshot?

Impact should be none. Use of this feature is optional.

@ablok ablok requested a review from a team as a code owner May 12, 2022 19:20
@CLAassistant
Copy link

CLAassistant commented May 12, 2022

CLA assistant check
All committers have signed the CLA.

@ablok
Copy link
Contributor Author

ablok commented May 12, 2022

Feedback why this is a good/bad idea would be appreciated.

Copy link
Member

@Matthew-Mallimo Matthew-Mallimo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is a useful change. thanks for the contribution

@@ -219,12 +223,38 @@ describe('diff-snapshot', () => {
expect(mockWriteFileSync).toHaveBeenCalledTimes(1);
});

it('should write a received image if the test fails and storeReceivedOnFailure = true', () => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add another test for when storeReceivedOnFailure is false

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added an explicit test case for this situation. However, this was already tested implicitly since false is the default. I did change the implementation a little bit so that it also does not return the receivedSnapshotPath if storeReceivedOnFailure is set to false.

snapshotIdentifier: mockSnapshotIdentifier,
snapshotsDir: mockSnapshotsDir,
storeReceivedOnFailure: true,
receivedDir: mockReceivedDir,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we also add a case for when receivedDir is undefined

Copy link
Contributor Author

@ablok ablok May 13, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The check for undefined receivedDir and other custom paths is handled in the index.js file. There did not seem to be a specific test that checked for default values, so I added that in the index.spec.js file.

@Matthew-Mallimo Matthew-Mallimo requested a review from a team May 13, 2022 13:48
@ablok
Copy link
Contributor Author

ablok commented May 18, 2022

@Matthew-Mallimo could you check the changes I made?

@Matthew-Mallimo Matthew-Mallimo requested a review from a team May 23, 2022 13:19
@10xLaCroixDrinker 10xLaCroixDrinker merged commit cfb81c9 into americanexpress:main May 30, 2022
oneamexbot added a commit that referenced this pull request May 30, 2022
# [5.1.0](v5.0.0...v5.1.0) (2022-05-30)

### Features

* allow storing received screenshot on failure ([#298](#298)) ([cfb81c9](cfb81c9))
@oneamexbot
Copy link
Contributor

🎉 This PR is included in version 5.1.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

goverdhan07 pushed a commit to goverdhan07/jest-image-snapshot that referenced this pull request Jul 23, 2023
goverdhan07 pushed a commit to goverdhan07/jest-image-snapshot that referenced this pull request Jul 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Feature: New Option to save current snapshots in a separate folder
5 participants