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

[passion week] Interaction tests with storybook's play function #2172

Merged
merged 15 commits into from
Jul 27, 2022
Merged
25 changes: 25 additions & 0 deletions .github/workflows/storybook-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: 'Storybook Tests'
on:
pull_request:
push:
branches:
- main

jobs:
test:
timeout-minutes: 60
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
- name: Install dependencies
run: npm i
- name: Install Playwright
run: npx playwright install --with-deps
- name: Build Storybook
run: npm run build:storybook:visual-testing --quiet
- name: Serve Storybook and run tests
run: |
npx concurrently -k -s first -n "SB,TEST" -c "magenta,blue" \
"npx http-server storybook-static --port 6006 --silent" \
"npx wait-on tcp:6006 && npm run test:storybook"
4 changes: 4 additions & 0 deletions .storybook/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ module.exports = {
addons: [
'@storybook/addon-a11y',
'@storybook/addon-links',
'@storybook/addon-interactions',
{name: '@storybook/addon-essentials', options: {backgrounds: false}},
'storybook-addon-performance/register',
{name: 'storybook-addon-turbo-build', options: {optimizationLevel: 2}},
Expand All @@ -13,5 +14,8 @@ module.exports = {
babel: options => {
options.plugins.push(['open-source', {editor: process.env.NODE_ENV === 'production' ? 'github' : 'vscode'}])
return options
},
features: {
interactionsDebugger: true
}
}
13 changes: 13 additions & 0 deletions contributor-docs/storybook-tests.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
Storybook tests utilize the storybook feature called [Play functions](https://storybook.js.org/docs/react/writing-stories/play-function).

### Writing a new play function.

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.

### Debugging the play function

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.

### On local CI

`npm run test:storybook` will do a quick pass of all storybooks and inform of any breaking tests.
Loading