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

Add Gif Snapshot Handler #21

Merged
merged 5 commits into from
Feb 20, 2024
Merged

Add Gif Snapshot Handler #21

merged 5 commits into from
Feb 20, 2024

Conversation

stevePanella
Copy link

The gif() function in paparazzi creates multiple images per test. The resulting files each have an appended index, for example:

  • myGifTest0.png
  • myGifTest1.png
  • myGifTest2.png
    etc...

When validating against existing snapshots, Paparazzi currently looks for the file name without the appended index, since this is what non-gif snapshots need to validate against. For example:

  • mySnapshotTest.png

To solve this problem, this PR creates a GifSnapshotHandler which will ensure that the correct index is appended to each file name before validating against the golden images. We can easily hook this up into gif tests by overriding the snapshotHandler in our test rule

@get: Rule
    val paparazzi = Paparazzi(
        ...
        snapshotHandler = determineGifHandler(),
    )
    

Comment on lines +663 to +668
fun determineGifHandler(maxPercentDifference: Double = 0.1): SnapshotHandler =
if (isVerifying) {
GifSnapshotHandler(maxPercentDifference)
} else {
HtmlReportWriter()
}

Choose a reason for hiding this comment

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

Where are you using this method?

Copy link
Author

Choose a reason for hiding this comment

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

this will be used to override the regular snapshot handler when we actually go to use this in our test rule. Like this:

@get: Rule
    val paparazzi = Paparazzi(
        ...
        snapshotHandler = determineGifHandler(),
    )

@stevePanella stevePanella merged commit 2ac6a34 into master Feb 20, 2024
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants