Skip to content

Commit

Permalink
SX Design: test Storybook via Playwright
Browse files Browse the repository at this point in the history
Just to make sure it still works after updating Storybook dependencies as it gets broken _very_ often.
  • Loading branch information
mrtnzlml committed May 10, 2022
1 parent 323b79b commit 4a898c4
Show file tree
Hide file tree
Showing 7 changed files with 72 additions and 5 deletions.
18 changes: 13 additions & 5 deletions .github/workflows/playwright.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,29 @@ on: [push]

jobs:
build:
strategy:
matrix:
repository:
- '@adeira/abacus-kochka'
- '@adeira/sx-design'
include:
- repository: '@adeira/abacus-kochka'
source: 'src/abacus-kochka/**'
- repository: '@adeira/sx-design'
source: 'src/sx-design/**'

runs-on: ubuntu-latest

steps:
# https://github.com/actions/checkout
- uses: actions/checkout@v3.0.2

# https://github.com/dorny/paths-filter
# TODO: expand as needed
- uses: dorny/paths-filter@v2.10.2
id: paths-filter
with:
filters: |
src:
- 'src/abacus-kochka/**'
src: ${{ matrix.source }}
# https://github.com/actions/setup-node
- name: Use Node.js 18.x
Expand All @@ -31,6 +40,5 @@ jobs:
- name: Install Yarn dependencies
run: yarn install --immutable

# We currently don't have any other project using `playwright` so let's keep it simple:
- name: Run Playwright tests
run: yarn workspace @adeira/abacus-kochka playwright test
run: yarn workspace ${{ matrix.repository }} playwright test
2 changes: 2 additions & 0 deletions src/sx-design/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
"@adeira/sx-jest-snapshot-serializer": "^0.1.0",
"@babel/core": "^7.17.10",
"@fbtjs/default-collection-transform": "^1.0.0",
"@playwright/test": "^1.21.1",
"@storybook/addon-a11y": "^6.4.22",
"@storybook/addon-actions": "^6.4.22",
"@storybook/addon-essentials": "^6.4.22",
Expand All @@ -53,6 +54,7 @@
"babel-loader": "^8.2.5",
"babel-plugin-fbt": "^1.0.0",
"babel-plugin-fbt-runtime": "^1.0.0",
"playwright": "^1.21.1",
"react": "^17.0.2",
"react-dom": "^17.0.2"
},
Expand Down
28 changes: 28 additions & 0 deletions src/sx-design/playwright.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// eslint-disable-next-line ft-flow/require-valid-file-annotation,import/no-extraneous-dependencies
const { devices } = require('@playwright/test');

const config = {
testDir: 'tests',
testMatch: '**.play.js',
forbidOnly: !!process.env.CI,
reporter: process.env.CI ? 'github' : 'list',
retries: process.env.CI ? 2 : 0,
webServer: {
command: 'yarn storybook',
port: 6006,
timeout: 120 * 1000, // milliseconds
reuseExistingServer: !process.env.CI,
},
use: {
trace: 'on-first-retry',
screenshot: 'only-on-failure',
},
projects: [
{
name: 'Desktop Chrome',
use: devices['Desktop Chrome'],
},
],
};

module.exports = config;
16 changes: 16 additions & 0 deletions src/sx-design/tests/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// @flow strict

/* eslint-disable no-unused-vars */
const OFF = 0;
const WARN = 1;
const ERROR = 2;
/* eslint-enable no-unused-vars */

module.exports = {
rules: {
// Jest rules incompatible with Playwright:
'jest/no-disabled-tests': OFF,
'jest/no-standalone-expect': OFF,
'jest/valid-title': OFF,
},
};
3 changes: 3 additions & 0 deletions src/sx-design/tests/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```
yarn workspace @adeira/sx-design playwright test
```
8 changes: 8 additions & 0 deletions src/sx-design/tests/ui/homepage.play.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// eslint-disable-next-line ft-flow/require-valid-file-annotation,import/no-extraneous-dependencies
const { test, expect } = require('@playwright/test');

test('that storybook works', async ({ page, baseURL }) => {
// This is here just to make sure that our Storybook works as it gets broken very often.
await page.goto(baseURL);
await expect(page).toHaveTitle(/^Styleguide \/ Colors - Page ⋅ Storybook$/);
});
2 changes: 2 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,7 @@ __metadata:
"@babel/core": ^7.17.10
"@babel/runtime": ^7.17.9
"@fbtjs/default-collection-transform": ^1.0.0
"@playwright/test": ^1.21.1
"@storybook/addon-a11y": ^6.4.22
"@storybook/addon-actions": ^6.4.22
"@storybook/addon-essentials": ^6.4.22
Expand All @@ -448,6 +449,7 @@ __metadata:
fbt: ^1.0.0
flow-enums-runtime: ^0.0.6
focus-trap-react: ^8.11.1
playwright: ^1.21.1
prop-types: ^15.8.1
react: ^17.0.2
react-blurhash: ^0.1.3
Expand Down

0 comments on commit 4a898c4

Please sign in to comment.