Skip to content

✨ Add comparisons API for future SDK usage#1087

Merged
wwilsman merged 5 commits into
masterfrom
ww/upload-comparisons
Oct 6, 2022
Merged

✨ Add comparisons API for future SDK usage#1087
wwilsman merged 5 commits into
masterfrom
ww/upload-comparisons

Conversation

@wwilsman

@wwilsman wwilsman commented Sep 27, 2022

Copy link
Copy Markdown
Contributor

What is this?

Soon, the Percy API will be able to accept specific snapshot comparisons to upload and associate with a build. This PR adds methods to @percy/client and @percy/core to enable SDKs to communicate with this upcoming API.

Client

Comparison methods added to client mirror other snapshot methods already present, with a few changes. For example, comparison creation and finalization is similar to snapshot creation and finalization, but with different endpoints and payloads. Likewise for snapshot resources and comparison tiles. The only major difference between the two APIs, is the comparisons flow includes creating a parent snapshot first, but not finalizing it.

Other small changes were made such as repurposing the build ID validation function to validate any type of ID, and using fs.promises to read resources and tiles from the filesystem.

Core queue

With recent work refactoring and isolating the internal queue responsibilities, adding comparison uploads to the existing queue was actually a very small change. When a snapshot payload includes a tag it is assumed to be a comparison and client.sendComparison() is used in place of client.sendSnapshot()

Core API

Also with the recent refactor work came the addition of the core percy.upload() method used by the upload command. Thanks to this method, a new /percy/comparisons endpoint can utilize it to facilitate comparison uploads. Now when the method detects the presence of a tag or tiles property, it will validate all options against a newly added comparison schema, and throw an error when missing the required snapshot name or comparison tag name. This new endpoint also returns a generated link to the comparison redirect API which will redirect to the comparison's web-url when available.

SDK utils

A new comparison posting utility function was added to mirror the snapshot posting utility function. These two functions, including their tests, are nearly identical with the only differences being the endpoint used by the function and payload used for the tests. Any JavaScript SDKs that would use the new comparison API should use this new utility function.

@wwilsman
wwilsman force-pushed the ww/upload-comparisons branch 4 times, most recently from 2b2b33b to a0b2c14 Compare September 29, 2022 16:17
@wwilsman
wwilsman requested a review from Robdel12 October 3, 2022 15:25
@wwilsman wwilsman added the ✨ enhancement New feature or request label Oct 3, 2022
@wwilsman
wwilsman marked this pull request as ready for review October 3, 2022 15:25
@wwilsman
wwilsman force-pushed the ww/upload-comparisons branch from a0b2c14 to c7502d1 Compare October 3, 2022 15:35

@Robdel12 Robdel12 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🏁

@wwilsman
wwilsman force-pushed the ww/upload-comparisons branch 2 times, most recently from 04ab633 to 4360c7d Compare October 5, 2022 18:07

@Robdel12 Robdel12 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🏁

@wwilsman
wwilsman force-pushed the ww/upload-comparisons branch from 4360c7d to 2954a62 Compare October 6, 2022 15:42
@wwilsman
wwilsman force-pushed the ww/upload-comparisons branch from 2954a62 to 875f7ce Compare October 6, 2022 16:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

✨ enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants