Skip to content
This repository was archived by the owner on Mar 4, 2020. It is now read-only.

Commit b3e9e1b

Browse files
authored
Docs: Add Perf Test documentation (#2158)
* Add documentation for adding and running perf tests. * Tweak example. * Clarify output.
1 parent fb0b262 commit b3e9e1b

File tree

2 files changed

+49
-2
lines changed

2 files changed

+49
-2
lines changed

.github/add-a-feature.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
- [Using prop interfaces and propTypes](#using-prop-interfaces-and-proptypes)
1515
- [State](#state)
1616
- [Conformance Test](#conformance-test)
17+
- [Performance Test](#performance-test)
1718
- [Add doc site example](#add-doc-site-example)
1819
- [Commit Messages](#commit-messages)
1920
- [Open PR](#open-pr)
@@ -163,6 +164,10 @@ class MyComponent extends AutoControlledComponent<MyComponentProps> {
163164

164165
Review [common tests](test-a-feature.md#common-tests) below. You should now add the [`isConformant()`](test-a-feature.md#isconformant-required) common test and get it to pass. This will validate the `displayName` and `className` and multiple other aspects to help you get your component off the ground.
165166

167+
### Performance Test
168+
169+
Add a [performance test](test-a-feature.md#performance-tests) to set a baseline performance measurement for your component and guard against future regressions.
170+
166171
### Add doc site example
167172

168173
Create a new documentation example that demonstrates usage of the new feature.

.github/test-a-feature.md

Lines changed: 44 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,17 @@ Test a feature
1717
- [Important mentions:](#important-mentions)
1818
- [Run Screener tests](#run-screener-tests)
1919
- [Local run command](#local-run-command)
20-
- [Behavior tets](#behavior-tets)
20+
- [Behavior Tests](#behavior-tests)
2121
- [Adding test(s)](#adding-tests)
2222
- [Running test(s)](#running-tests)
2323
- [Troubleshooting](#troubleshooting)
2424
- [I am not sure if my line under `@specification` was process correctly](#i-am-not-sure-if-my-line-under-specification-was-process-correctly)
2525
- [I am not sure if my line was executed](#i-am-not-sure-if-my-line-was-executed)
2626
- [I want to add any description which should not be consider as unit test](#i-want-to-add-any-description-which-should-not-be-consider-as-unit-test)
2727
- [I want to create unit tests in separate file not through the regex](#i-want-to-create-unit-tests-in-separate-file-not-through-the-regex)
28+
- [Performance Tests](#performance-tests)
29+
- [Adding a Perf Test](#adding-a-perf-test)
30+
- [Running Perf Tests](#running-perf-tests)
2831

2932
<!-- END doctoc generated TOC please keep comment here to allow auto update -->
3033

@@ -172,7 +175,7 @@ When ran locally, not all the tests may be needed to run, only the ones added/ed
172175
yarn test:visual
173176
```
174177

175-
## Behavior tets
178+
## Behavior Tests
176179

177180
Behavior unit tests are generated from the specification written in each behavior file.
178181
Each line under the `@specification` tag is taken and matched against the regex expression written in `testDefinitions.ts` file.
@@ -236,3 +239,42 @@ Add description under the `@description` tag. Like:
236239

237240
#### I want to create unit tests in separate file not through the regex
238241
Add your spec file into the array of files `skipSpecChecksForFiles` in `testHelper.tsx`. And put description in behavior file under `@description` tag.
242+
243+
## Performance Tests
244+
245+
Performance tests will measure performance, set a baseline for performance and help guard against regressions.
246+
247+
### Adding a Perf Test
248+
249+
- To add a perf test, simply add a file with `.perf.` in its naming. (As of writing, `.perf.` files in `docs/src` and `packages/perf-test` are automatically consumed.)
250+
- Formatting follows [Storybook CSF convention](https://storybook.js.org/docs/formats/component-story-format/) with special support for `iterations` metadata which tells the performance testing package how many iterations of your component to render:
251+
252+
```tsx
253+
// If this file is named ButtonBasic.perf.tsx, it will be picked up as kind of 'ButtonBasic' with story names of 'Blank' and 'WithText'.
254+
export default {
255+
iterations: 5000,
256+
}
257+
258+
export const Blank = () => <Button />
259+
export const WithText = () => <Button content="Click here" />
260+
```
261+
262+
Finding the right number of `iterations` is a balancing act between having a fast test and getting enough information from the results. For more complex scenarios and components 1 iteration may be enough, while simple components with simple stories may need as many as 5,000.
263+
264+
### Running Perf Tests
265+
266+
Run test and watch:
267+
```
268+
cd packages/perf-test
269+
yarn just perf-test
270+
```
271+
272+
After running `perf-test`, results can be viewed in the `packages/perf-test/dist` folder with the main entry file being `packages/perf-test/dist/perfCounts.html`.
273+
274+
There are more detailed commands as well (these must be run from `packages/perf-test` directory):
275+
276+
| Command | Description |
277+
|---------|-------------|
278+
| `yarn just perf-test:bundle` | Recreates story bundle. Required if perf stories are added or modified. |
279+
| `yarn just perf-test:run` | Runs flamegrill against story bundle and generates results. |
280+
| `yarn just perf-test` | Executes both `:bundle` and `:run`. |

0 commit comments

Comments
 (0)