-
Notifications
You must be signed in to change notification settings - Fork 99
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
test: add visual tests infra #1047
Conversation
Preview is ready. |
@NasgulNexus I think doing test for each component variation is not very efficient, e.g. Button has hundreds of props combination Why don't we take screenshots of component stories from storybook preview instead? |
cace10e
to
a5fc240
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it will be better to separate unit and snapshot tests. I suggest the next hierarchy:
> Component/
> __tests__/
> __snapshot-tests__/
> {Component}.{case-scope}/
> snapshots/
> {Component}.{case-scope}.test.tsx
What do u think about it?
I would suggest this structure, folder Now it itself generates the name of the folder where it will put screenshots, depending on the name of the test. If there are several tests in a folder where screenshots are taken, then I would not put them in one folder. What’s a plus is the ability to quickly find the required screenshot and perform any actions with it. |
env: | ||
CI: 'true' | ||
- name: Upload Playwright playwright report to GitHub Actions Artifacts | ||
if: always() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This line needed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I made it so that the report was always shown and during development it was clear whether new tests appeared or not
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I mean isnt's if: always()
equal to not specifing if
statement at all?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://github.com/gravity-ui/uikit/actions/runs/6888720871/job/18738258388#step:6:4712 tested without if it doesn't work.
because the test crashes and then does not perform other tasks. Without if he will do it only when everything went well
playwright/README.md
Outdated
## How to write a test | ||
|
||
1. You need to select the component for which you want to write tests | ||
2. In the component folder, create a folder `__tests__` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
2. In the component folder, create a folder `__tests__` | |
2. Inside the component folder, create the `__tests__` folder |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why new name is __snapshots__?
playwright/playwright.config.ts
Outdated
testMatch: '*/__tests__/*.visual.test.tsx', | ||
updateSnapshots: process.env.UPDATE_REQUEST ? 'all' : 'missing', | ||
snapshotPathTemplate: | ||
'{testDir}/{testFileDir}/{testFileName}-snapshots/{arg}{-projectName}-linux{ext}', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's do this in the Jest manner:
'{testDir}/{testFileDir}/{testFileName}-snapshots/{arg}{-projectName}-linux{ext}', | |
'{testDir}/{testFileDir}/__snapshots__/{arg}{-projectName}-linux{ext}', |
</head> | ||
<body> | ||
<div id="root" class="g-root g-root_theme_light"></div> | ||
<script type="module" src="./index.tsx"></script> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I assume styles can be import like so, no scripts needed:
<link rel="stylesheet" href="index.scss" />
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
without index ts, the tests do not work, through this file it mounts the component
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can it be empty?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, you can leave the file empty. But in the dock they recommend connecting from index tsx
@korvin89 @NasgulNexus I suggest to keep the Jest structure with
|
Playwright Test Component is ready. |
package.json
Outdated
"playwright": "playwright test --config=playwright/playwright.config.ts", | ||
"playwright:update": "npm run playwright -- -u", | ||
"playwright:docker": "docker run --rm --network host -v $(pwd):/work/ -w /work/ -it mcr.microsoft.com/playwright:v1.39.0-jammy /bin/bash -c 'npm ci && npx playwright install && npm run playwright'", | ||
"playwright:update:docker": " docker run --rm --network host -v $(pwd):/work/ -w /work/ -it mcr.microsoft.com/playwright:v1.39.0-jammy /bin/bash -c 'npm ci && npx playwright install && npm run playwright:update'" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
playwright:docker:update
playwright/README.md
Outdated
import {MyTestedComponent} from '../MyTestedComponent'; | ||
``` | ||
|
||
5. Writing a test: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've meant get code from 4 and put it into 5. Title In the file to make imports
should be removed also
playwright/README.md
Outdated
## How to write a test | ||
|
||
1. You need to select the component for which you want to write tests | ||
2. In the component folder, create a folder `__tests__` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why new name is __snapshots__?
8a1886c
to
a0a8580
Compare
@NasgulNexus Why in the recent update all screenshots updated and shifted by 1 pixel? |
for the ci test, I took screenshots locally. And then I took screenshots through the docker image for linux. And because of the font difference, this happened. |
285fe30
to
9d7d11a
Compare
No description provided.