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

SX Design: test Storybook via Playwright #4392

Merged
merged 1 commit into from
May 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .github/workflows/continuous-integration-javascript.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ env:
BABEL_DISABLE_CACHE: '1'

jobs:
build:
javascript-test:
name: JavaScript test
runs-on: ubuntu-latest

strategy:
Expand Down
4 changes: 3 additions & 1 deletion .github/workflows/continuous-integration-rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ name: Continuous Integration (Rust)
on: [push]

jobs:
build-all-targets:
rust-test:
name: Rust test

strategy:
fail-fast: true
matrix:
Expand Down
33 changes: 27 additions & 6 deletions .github/workflows/playwright.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,32 +5,53 @@ name: Playwright
on: [push]

jobs:
build:
playwright-test:
name: Playwright test
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
if: steps.paths-filter.outputs.src == 'true'
uses: actions/setup-node@v3.2.0
with:
node-version: 18.x
cache: 'yarn'

- name: Install Yarn dependencies
if: steps.paths-filter.outputs.src == 'true'
run: yarn install --immutable

# We currently don't have any other project using `playwright` so let's keep it simple:
- name: Install Playwright
if: steps.paths-filter.outputs.src == 'true'
run: yarn workspace ${{ matrix.repository }} playwright install --with-deps

- name: Run Playwright tests
run: yarn workspace @adeira/abacus-kochka playwright test
if: steps.paths-filter.outputs.src == 'true'
run: yarn workspace ${{ matrix.repository }} playwright test
env:
# See: https://github.com/storybookjs/storybook/issues/16555
NODE_OPTIONS: --openssl-legacy-provider

# TODO: upload Playwright artifacts, see: https://playwright.dev/docs/next/ci#github-actions
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.18.0",
"@fbtjs/default-collection-transform": "^1.0.0",
"@playwright/test": "^1.21.1",
"@storybook/addon-a11y": "^6.5.3",
"@storybook/addon-actions": "^6.5.3",
"@storybook/addon-essentials": "^6.5.3",
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
29 changes: 29 additions & 0 deletions src/sx-design/playwright.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// eslint-disable-next-line ft-flow/require-valid-file-annotation,import/no-extraneous-dependencies
const { devices } = require('@playwright/test');

const config = {
timeout: 60000,
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 --quiet',
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$/);
});
6 changes: 4 additions & 2 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,7 @@ __metadata:
"@babel/core": ^7.18.0
"@babel/runtime": ^7.18.0
"@fbtjs/default-collection-transform": ^1.0.0
"@playwright/test": ^1.21.1
"@storybook/addon-a11y": ^6.5.3
"@storybook/addon-actions": ^6.5.3
"@storybook/addon-essentials": ^6.5.3
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 Expand Up @@ -3052,7 +3054,7 @@ __metadata:
languageName: node
linkType: hard

"@playwright/test@npm:^1.22.1":
"@playwright/test@npm:^1.21.1, @playwright/test@npm:^1.22.1":
version: 1.22.1
resolution: "@playwright/test@npm:1.22.1"
dependencies:
Expand Down Expand Up @@ -15849,7 +15851,7 @@ __metadata:
languageName: node
linkType: hard

"playwright@npm:^1.22.1":
"playwright@npm:^1.21.1, playwright@npm:^1.22.1":
version: 1.22.1
resolution: "playwright@npm:1.22.1"
dependencies:
Expand Down