Skip to content

✨ Allow snapshotting a list of pages to utilize the base-url flag#382

Merged
wwilsman merged 6 commits intomasterfrom
ww/cli-snapshot-tweaks
Jun 21, 2021
Merged

✨ Allow snapshotting a list of pages to utilize the base-url flag#382
wwilsman merged 6 commits intomasterfrom
ww/cli-snapshot-tweaks

Conversation

@wwilsman
Copy link
Copy Markdown
Contributor

What is this?

This PR refactors and tweaks the percy snapshot command to be a little more friendly.

First, a page listing no longer needs to be a list of objects containing at least a url property. Now the file can contain just a list of URLs in the appropriate format:

# snapshots.yml
- https://example.com
- https://example.com/about
- https://example.com/contact

Second, the --base-url flag was made to work with page listings in addition to the existing static directory usage. Since usage differs between page listings and static directories however, some other small adjustments were necessary.

For static directories, the base URL should be the base PATHNAME that the site would be hosted at. Most sites are hosted at the domain root (/), however some sites might be hosted at other paths (e.g. /blog). This requirement has been present since the @percy/agent snapshot command and continues to remain a requirement.

For page listings, the base URL should be the entire base URL including the protocol and hostname. For example, the above list of URLs can be simplified to remove the common base URL:

# snapshots.yml
- /
- /about
- /contact
$ percy snapshot --base-url https://example.com snapshots.yml

To prevent mixing up the static.base-url configuration option with the page listing flag, a couple other changes were also made. The flag is no longer auto-mapped to the configuration option via the percyrc flag property. Instead, it is passed along to the .percyrc() method which now accepts an initial overrides argument.

The static.base-url configuration option was no longer being checked for the leading forward slash (only the flag is checked by the command now). A pattern requirement was added to the schema, and custom errors messages were added to config validation to print a better error message than what is normally printed for pattern failures. We can also utilize this pattern to do other better config validations in the future such as for certain discovery options.

The --dry-run flag will now print a better list of snapshots, however the default name in core is only created when calling the snapshot method. The default name was also added here so dry runs can properly print it. When adding the default name here, I discovered a small bug in the core implementation in which uri.path needed to be replaced with uri.pathname.

@wwilsman wwilsman added the ✨ enhancement New feature or request label Jun 21, 2021
@wwilsman wwilsman requested a review from Robdel12 June 21, 2021 19:49
@wwilsman wwilsman enabled auto-merge (squash) June 21, 2021 19:56
Copy link
Copy Markdown
Contributor

@Robdel12 Robdel12 left a comment

Choose a reason for hiding this comment

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

Slick! And then we can ship the new snapshot docs 🏁

@wwilsman wwilsman merged commit f7f73d1 into master Jun 21, 2021
@wwilsman wwilsman deleted the ww/cli-snapshot-tweaks branch June 21, 2021 21:11
samarsault pushed a commit that referenced this pull request Mar 3, 2023
Bumps [cypress](https://github.com/cypress-io/cypress) from 7.7.0 to 8.0.0.
- [Release notes](https://github.com/cypress-io/cypress/releases)
- [Changelog](https://github.com/cypress-io/cypress/blob/develop/.releaserc.base.js)
- [Commits](cypress-io/cypress@v7.7.0...v8.0.0)

---
updated-dependencies:
- dependency-name: cypress
  dependency-type: direct:development
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
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