Skip to content

Commit 92827da

Browse files
Introduce Playwright Component Testing (#857)
I introduced Playwright Component Testing as replacement for Jest and RTL. Those tests must be run within `playwright` docker container with pre-installed browsers to ensure uniform testing environment. `.env.playwright` is created using `postinstall` script to follow zero-config setup. `.env.playwright` can be used to tween parameters for local development if needed. Currently, only tests for `Alert` and `Button` components are migrated to Playwright CT as this commit is supposed to be proof-of-concept. Rest should be migrated in later pull request. All visual tests use prop tests concept we already have for Jest to simplify testing and to make it DRY. `mixPropTests()` is introduced to mix those to create combinations to be tested.
1 parent e2721ea commit 92827da

File tree

144 files changed

+10531
-6642
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

144 files changed

+10531
-6642
lines changed

.env.playwright.dist

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
###########################
2+
# Playwright configuration #
3+
###########################
4+
5+
# Number of workers to use to run Playwright tests
6+
PW_WORKERS=1
7+
8+
# Port used by Playwright Component Testing to serve the test files
9+
PW_CT_PORT=3100

.github/workflows/release-management.yml

+6
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,18 @@ jobs:
2424
- name: Install
2525
run: npm ci
2626

27+
- name: Install Playwright Browsers
28+
run: npx playwright install --with-deps
29+
2730
- name: Lint
2831
run: npm run lint
2932

3033
- name: Test
3134
run: npm test
3235

36+
- name: Test Playwright
37+
run: npm run test:playwright-ct:all
38+
3339
- name: Build
3440
run: npm run build
3541

.github/workflows/test.yml

+14
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,22 @@ jobs:
2525
- name: Install
2626
run: npm ci
2727

28+
- name: Install Playwright Browsers
29+
run: npx playwright install --with-deps
30+
2831
- name: Test and generate code coverage info
2932
run: npm test
3033

34+
- name: Test Playwright and generate test report
35+
run: npm run test:playwright-ct:all
36+
3137
- name: Upload code coverage info to Coveralls
3238
uses: coverallsapp/github-action@v2
39+
40+
- name: Upload Playwright test report
41+
uses: actions/upload-artifact@v4
42+
if: ${{ !cancelled() }}
43+
with:
44+
name: playwright-report
45+
path: playwright-report/
46+
retention-days: 30

.gitignore

+5
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,8 @@
66
.env
77
statistics.html
88
!.gitkeep
9+
10+
# Playwright
11+
.env.playwright
12+
/playwright-report/
13+
/tests/playwright/.temp/

CONTRIBUTING.md

+21-4
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,23 @@ docker compose run --rm node_shell
7070
docker compose run --rm mkdocs_build_site
7171
```
7272

73+
#### Playwright
74+
75+
You need to run npm commands such as `test:playwright-ct:all` and
76+
`test:playwright-ct:all-with-update` within `playwright` docker container.
77+
78+
To log into the container, run:
79+
80+
```bash
81+
docker compose run --rm playwright
82+
```
83+
84+
and then run the commands within the `playwright` container:
85+
86+
```bash
87+
npm run test:playwright-ct:all
88+
```
89+
7390
## Git Workflow
7491

7592
In order for the automation to work in the best possible way (we use GitHub
@@ -156,13 +173,13 @@ To keep React UI consistent and predictable the following guidelines should be o
156173
1. If component accepts the `children` prop it should be either required or the element
157174
should return `null` when no children are provided.
158175
2. When forwarding HTML attributes to the component the following rules should
159-
be observed:
176+
be observed:
160177
1. If the component internally instantiates one or more interactive
161-
(clickable/editable) elements, the attributes should be forwarded to
178+
(clickable/editable) elements, the attributes should be forwarded to
162179
all of them.
163180
2. If the component does not internally instantiate an interactive
164-
(clickable/editable) element, the attributes should be forwarded to the
165-
root element of the component.
181+
(clickable/editable) element, the attributes should be forwarded to the
182+
root element of the component.
166183
167184
## Documenting
168185

docker-compose.yml

+7
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,13 @@ services:
2424
extends: node
2525
entrypoint: bash
2626

27+
# For running Playwright tests
28+
playwright:
29+
build: docker/playwright
30+
user: ${COMPOSE_UID-1000}:${COMPOSE_GID-1000}
31+
volumes:
32+
- .:/workspace:z
33+
2734
# Build services
2835
mkdocs_build_site:
2936
extends: mkdocs

docker/playwright/Dockerfile

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
FROM mcr.microsoft.com/playwright:v1.50.1
2+
RUN mkdir /workspace
3+
WORKDIR /workspace

jest.config.js

+3
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ module.exports = {
1414
'<rootDir>/tests/jest/setupTestingLibrary.js',
1515
],
1616
testEnvironment: 'jsdom',
17+
testMatch: [
18+
'**/*.test.{js,jsx}',
19+
],
1720
transformIgnorePatterns: [
1821
'node_modules/(?!(@react-ui-org))',
1922
],

0 commit comments

Comments
 (0)