Skip to content

Commit ed09360

Browse files
authored
[passion week] Interaction tests with storybook's play function (#2172)
* Add storybook play function for autocomplete * Add github workflow * Must run on pull-request and push to main * Package.lock revert * update workflow * configure static directories * Build storybooks correctly * A more complete autocomplete test * Fix up packge lock? * Fix up packge lock? * Add some documentation * Fix up autocomplete tests by adding data-testid
1 parent 75d2174 commit ed09360

File tree

6 files changed

+7482
-3347
lines changed

6 files changed

+7482
-3347
lines changed

.github/workflows/storybook-tests.yml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
name: 'Storybook Tests'
2+
on:
3+
pull_request:
4+
push:
5+
branches:
6+
- main
7+
8+
jobs:
9+
test:
10+
timeout-minutes: 60
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: actions/checkout@v2
14+
- uses: actions/setup-node@v2
15+
- name: Install dependencies
16+
run: npm i
17+
- name: Install Playwright
18+
run: npx playwright install --with-deps
19+
- name: Build Storybook
20+
run: npm run build:storybook:visual-testing --quiet
21+
- name: Serve Storybook and run tests
22+
run: |
23+
npx concurrently -k -s first -n "SB,TEST" -c "magenta,blue" \
24+
"npx http-server storybook-static --port 6006 --silent" \
25+
"npx wait-on tcp:6006 && npm run test:storybook"

.storybook/main.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ module.exports = {
33
addons: [
44
'@storybook/addon-a11y',
55
'@storybook/addon-links',
6+
'@storybook/addon-interactions',
67
{name: '@storybook/addon-essentials', options: {backgrounds: false}},
78
'storybook-addon-performance/register',
89
{name: 'storybook-addon-turbo-build', options: {optimizationLevel: 2}},
@@ -13,5 +14,8 @@ module.exports = {
1314
babel: options => {
1415
options.plugins.push(['open-source', {editor: process.env.NODE_ENV === 'production' ? 'github' : 'vscode'}])
1516
return options
17+
},
18+
features: {
19+
interactionsDebugger: true
1620
}
1721
}

contributor-docs/storybook-tests.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
Storybook tests utilize the storybook feature called [Play functions](https://storybook.js.org/docs/react/writing-stories/play-function).
2+
3+
### Writing a new play function.
4+
5+
For every storybook, we can write a play function which gets executed after the story renders. By combining jest and testing-library API, we can effectively write something like an integration tests. Here, we will call them interactive tests.
6+
7+
### Debugging the play function
8+
9+
The new addon for [storybook interactions](https://storybook.js.org/addons/@storybook/addon-interactions) allows you to debug the play function step by step. We can step back and forth or replay the interactions too.
10+
11+
### On local CI
12+
13+
`npm run test:storybook` will do a quick pass of all storybooks and inform of any breaking tests.

0 commit comments

Comments
 (0)