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

ADR 009: Guidelines for interaction tests in primer-react #2223

Merged
merged 4 commits into from
Aug 22, 2022

Conversation

pksjce
Copy link
Collaborator

@pksjce pksjce commented Aug 9, 2022

Describe your changes here.

This ADR proposes some instructions for how we should write interaction tests. Feedback welcome!

@pksjce pksjce requested review from a team and colebemis August 9, 2022 11:33
@changeset-bot
Copy link

changeset-bot bot commented Aug 9, 2022

⚠️ No Changeset found

Latest commit: 3a99ca0

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@pksjce pksjce added the skip changeset This change does not need a changelog label Aug 9, 2022
@github-actions
Copy link
Contributor

github-actions bot commented Aug 9, 2022

size-limit report 📦

Path Size
dist/browser.esm.js 75.62 KB (0%)
dist/browser.umd.js 76.23 KB (0%)

@pksjce pksjce temporarily deployed to github-pages August 9, 2022 11:39 Inactive
@pksjce pksjce temporarily deployed to github-pages August 9, 2022 11:39 Inactive
@pksjce pksjce temporarily deployed to github-pages August 11, 2022 06:16 Inactive
@pksjce pksjce temporarily deployed to github-pages August 11, 2022 06:16 Inactive
@lesliecdubs
Copy link
Member

Thanks for contributing this ADR, @pksjce!

In order to help move a decision forward, I'm assigning the following:

ADR decision maker: @colebemis
Decision deadline: EOD Monday, 22 August

Your role as decision maker is to gather feedback, probe for discussion and disagreement, and then make an informed decision based on the feedback, identified risks, and trade-offs about whether to adopt the ADR or not. Your role is not to decide based on your own personally preferred approach.

Keep in mind that ADR decisions can be reversed or changed in the future if new information is exposed that make the ADR worth revisiting.

You can fulfill your decision maker role by doing the following:

  • review the ADR, comments, and feedback closely
  • seek additional feedback from any necessary parties, as needed; for example, request a review from any individuals or teams that you know would be unduly affected by this ADR, or who have extensive experience in using either the preferred or non-preferred approach and may have perspective to share about it
  • follow up on any remaining concerns, questions, or unexamined risks around accepting the proposed approach
  • on or before the deadline, make a decision as to whether the ADR is accepted ✅ , which you should signal by approving this PR, or rejected 🚫 , which you should signal by closing this PR with a comment explaining the reason(s)

Our testing infrastructure consists of Jest "unit" tests and automatic Chromatic visual testing. Both of these are super useful but we have been experiencing a few setbacks.
Unofficially we test more complex interactive scenarios using our storybooks setup.

1. Repeated markup in storybooks and jest tests - Since there is not automation of interaction in storybooks, we tend to test them out manually in stories and then transfer to jest. This results in us constructing similar test case scenarios in storybooks and in tests.
Copy link
Member

Choose a reason for hiding this comment

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

10/10 can confirm. Feel like a caveman doing this.

Going forward, we can use [storybook's play functions](https://storybook.js.org/docs/react/writing-stories/play-function) to write interactive tests for our components. Here's a document that describes h[ow to add and run these tests](../storybook-tests.md).
Guidelines to make this easier -

1. Create a new storybook file for your components and call them "interactions". Inside these files, we can import the stories from "examples" or "fixtures" and tack on play functions to them. This will create duplicate stories but with the added benefit of the tests appearing in the interactions add-on tab. This tab will let you step through your tests step by step, increasing visibility and debuggability.
Copy link
Member

Choose a reason for hiding this comment

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

For me, it was useful to see the demo in #2172 to understand this part. Live demo

Copy link
Member

Choose a reason for hiding this comment

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

Thanks for sharing this @siddharthkp 🙌🏼

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@siddharthkp - Do you think I should link this stuff in the ADR?

Copy link
Member

@siddharthkp siddharthkp left a comment

Choose a reason for hiding this comment

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

Approved! from my side

I like the approach a lot more than writing interactive tests that run with jest. My only fear (probably irrational?) with this approach is that by going deeper into the storybook ecosystem, we might get locked in with the features they do or don't provide?

(The other visual alternative would be to use playwright which run a chromium instance that can be intercepted to debug (memex uses this approach), but the dev experience is not as smooth as the one in @pksjce's demo)

Finally, an unsolved problem that we'll need to figure out: How do we add results from these tests to our coverage metrics?

@broccolinisoup
Copy link
Member

Thanks so much for putting this ADR together @pksjce ! It helped me understand where we are at testing and what our options are. I haven't used Storybook's interaction tests before but I like the approach. Are we thinking them as an alternative to E2E testing or are we thinking starting with Storybook play functions and down the road, we can introduce a more comprehensive tool for E2E and integrate into our CI/CD?


## Decisions

Going forward, we can use [storybook's play functions](https://storybook.js.org/docs/react/writing-stories/play-function) to write interactive tests for our components. Here's a document that describes h[ow to add and run these tests](../storybook-tests.md).
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
Going forward, we can use [storybook's play functions](https://storybook.js.org/docs/react/writing-stories/play-function) to write interactive tests for our components. Here's a document that describes h[ow to add and run these tests](../storybook-tests.md).
Going forward, we can use [storybook's play functions](https://storybook.js.org/docs/react/writing-stories/play-function) to write interactive tests for our components. Here's a document that describes [how to add and run these tests](../storybook-tests.md).

Typo :)


2. Port complex jest tests onto interactive tests. This is up to developer discretion. My recommendation is to have basic "unit" tests like component existence and axe tests in jest. Anything that can benefit from a visual aspect to it can be moved to interaction tests.

3. Interaction tests are not perfect. Some aspects like mocking can be challenging and we will find solutions to these as when the need arises.
Copy link
Member

Choose a reason for hiding this comment

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

Out of curiosity, did we consider any alternative options to Storybook play functions?

If so, it'd be nice to add a section about what else we considered. If not, all good.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This is a good idea. I did have thoughts around cypress and playwright before this. Not sure how much in detail I should mention them. Will add to this draft.

@pksjce
Copy link
Collaborator Author

pksjce commented Aug 18, 2022

@siddharthkp - Thanks so much for your comments.

Re- Deep storybook integration.
We are already pretty deep into storybooks. We use them for all primer properties, most people are familiar with them, chromatic runs on top of it etc. Also Storybook is a pretty active project with pretty responsive maintainers. So we know they are going to evolve pretty fast with the general javascript ecosystem. eg - They are working on vitejs integration which could make the storybook build itself super fast.
There's been no pushback or nobody has really proposed an alternative to storybook in our team or in the general community so far IMO. Most component libs use storybooks too.
So, I kinda feel like its in our benefit to grow with them and make use of all their new features eg play functions. You can see that they are really working on it and some exciting updates are coming in 7.0.0 too.

Re- Test Coverage - I've been looking into this since the last time you mentioned it in chat. I'm having a slightly hard time coming up with a solution for this. Maybe we could pair sometime next week and brainstorm what to do for this?

@pksjce pksjce temporarily deployed to github-pages August 18, 2022 09:10 Inactive
@pksjce pksjce temporarily deployed to github-pages August 19, 2022 08:13 Inactive
@pksjce pksjce merged commit bd74c2a into main Aug 22, 2022
@pksjce pksjce deleted the pk/adr-interaction-tests branch August 22, 2022 02:03
@siddharthkp
Copy link
Member

Re- Test Coverage - I've been looking into this since the last time you mentioned it in chat. I'm having a slightly hard time coming up with a solution for this. Maybe we could pair sometime next week and brainstorm what to do for this?

Yep, I'm pretty clueless as well, let's do that :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
skip changeset This change does not need a changelog
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants