-
Notifications
You must be signed in to change notification settings - Fork 622
Add the framework required to run component stress tests #5929
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very excited for this! Just two non-blocking questions
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for putting this together! Really the only question I had with this was around StressTest and afterframe and what differences there are between setting up a harness with this versus using something like Profiler
with React.
Co-authored-by: Jon Rohan <yes@jonrohan.codes>
Changelog
New
This PR adds the framework required to run component stress tests and a couple of examples.
The tests run on Storybook and measure the time it takes for a component to react to a state change.
This is how one of them looks like:
Screen.Recording.2025-04-15.at.21.10.00.mov
I tried to make the code self explanatory but I'll give a brief overview of how the pieces fit together here.
StressTest.tsx
is a helper component to be used in Storybook, that takes care of all the performance measuring part of the stress tests. It has a very simple API so that defining the tests is as simple as possible.It uses
afterframe
and a React state update to do this. We trigger a state update, which the component will react to and rerender appropriately according to the test defined. The afterFrame library calls the function when the next frame starts and measures the elapsed time. The reasoning behind this approach is well explained in this article.[Component].stress.stories.tsx
contain the stress tests for a few components. The components will react to the state change by interacting with thecount
prop provided in the render function. This reaction is what the stress test will measure.stress-tests.yml
defines the workflow that runs the stress tests. It runs the Playwright tests against the Storybook server and stores the results in a file. This file is stored in the cache and compared to the previous results. Each commit will generate a new result in the cache.If the result of any commit is slower than the alert threshold defined there, the workflow will fail and a comment will be added to the commit with the results.
StressTests.test.ts
is where the Playwright tests are defined. The tests just run the Storybook story and grab the mean result from them.stress-test-reporter.ts
gets the results from the Playwright tests and stores them in a file, in a format thatbenchmark-action/github-action-benchmark
expects.FAQ
How much of a stable environment do you need for this to be reliable?
So far, defining
runs-on: ubuntu-latest-4-cores
on the workflow has been very reliable. Running the tests locally is also very consistent from run to run but, as you can imagine, it will only be useful to compare numbers between runs on the same hardware.How accurate is it at detecting regressions?
Very accurate according to my tests. Here's an example of enabling and disabling CSS modules on ActionList:
Screen.Recording.2025-04-14.at.19.39.26.mov
Rollout strategy
Testing & Reviewing
Merge checklist