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

Refactor SEO tests by removing InlineSnapshot testing #571

Merged
merged 1 commit into from Feb 23, 2023

Conversation

cartogram
Copy link
Contributor

@cartogram cartogram commented Feb 23, 2023

WHY are these changes introduced?

In the lead up to release, I added a lot of tests using toMatchInlineSnapshot. This was helpful for driving the development of features and getting a lot of test coverage in quickly.

However, I don't feel snapshot tests are the right approach. They just end up looking like a mess of text. Failures are hard to understand. Test intentions are hard to understand. I think developers will find themselves updating these snapshots out of either frustration or unintentional clumsiness.

WHAT is this pull request doing?

This PR removes the inline snapshots from the SEO tests and replaces them with more specific assertions directly on the array values we expect to exist.

HOW to test your changes?

Passing CI should be enough.

Post-merge steps

Checklist

  • I've read the Contributing Guidelines
  • I've considered possible cross-platform impacts (Mac, Linux, Windows)
  • I've added a changeset if this PR contains user-facing or noteworthy changes
  • I've added tests to cover my changes

@github-actions
Copy link
Contributor

We detected some changes in packages/*/package.json or packages/*/src, and there are no updates in the .changeset.
If the changes are user-facing and should cause a version bump, run npm run changeset add to track your changes and include them in the next release CHANGELOG.
If you are making simple updates to examples or documentation, you do not need to add a changeset.

@cartogram cartogram requested review from a team and juanpprieto February 23, 2023 01:48
Copy link
Contributor

@lordofthecactus lordofthecactus left a comment

Choose a reason for hiding this comment

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

✅ cool. Agree with your thoughts.

IMHO I would have kept the snapshots since the tests could be painful to change if we move a bit the structure.

It can be reverted anyway.

@cartogram
Copy link
Contributor Author

IMHO I would have kept the snapshots since the tests could be painful to change if we move a bit the structure.

Yeah, I think this is part of the problem with snapshots, they are easy and quick. You press a key and all your tests pass.

If you change the structure, you should expect your tests will need to be updated. I think expect.arrayContaining strikes a nicer balance where the outer structure is free to change, but your assertion is still specific and readable.

@Shopify/hydrogen should we form a consensus on this before merging?

@cartogram cartogram merged commit cbfd80c into 2023-01 Feb 23, 2023
@cartogram cartogram deleted the @cartogram/remove-inline-snapshots branch February 23, 2023 17:53
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.

None yet

2 participants