-
Notifications
You must be signed in to change notification settings - Fork 22
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
feat: add Playwright package for screenshot testing #327
Conversation
package.json
Outdated
@@ -51,7 +51,7 @@ | |||
"deps:install": "npm ci", | |||
"deps:truncate": "npm prune --production", | |||
"typecheck": "tsc -p . --noEmit", | |||
"test": "exit 0", | |||
"test": "npx playwright 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.
the launch of the storybook should happen before the playwright 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.
If i run "npm run test", playwright runs the storybook before tests.
I configured it in playwright.config.ts (webServer property):
437c10b#diff-f679bf1e58e8dddfc6cff0fa37c8e755c8d2cfc9e6b5dc5520a5800beba59a92R14
tests/utils.ts
Outdated
@@ -0,0 +1,3 @@ | |||
export const URL_SEGMENT = 'http://localhost:6006/iframe.html?args=&id='; |
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.
maybe these are constants and not utilities
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.
It is also necessary to make it so that the domain can be specified through an environment variable
package.json
Outdated
@@ -51,7 +51,7 @@ | |||
"deps:install": "npm ci", | |||
"deps:truncate": "npm prune --production", | |||
"typecheck": "tsc -p . --noEmit", | |||
"test": "exit 0", | |||
"test": "npx playwright 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.
It is necessary to add a section about tests in the readme, how to run them and how to update them
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.
Added more info about testing in README: fb2595c
playwright.config.ts
Outdated
testDir: './tests', | ||
fullyParallel: true, | ||
forbidOnly: Boolean(process.env.CI), | ||
retries: process.env.CI ? 2 : 0, |
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 is process.env.CI needed?
README.md
Outdated
|
||
`**.spec.ts` files contain test code. | ||
|
||
`**.spec.ts-snapshots` folders contain screenshots which are used for comparison with test screenshots. If screenshot is incorrect you can delete it and after the tests playwright will replace it with test screenshot. |
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.
to update screenshot you need to run
npx playwright test --update-snapshots
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.
Commit: 10b491b
README.md
Outdated
|
||
### Preparation | ||
|
||
You need to add `.env` file in repository's root directory with the data below: |
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.
You need to add
.env
This should not be necessary by default, tests should be started by this variable. It should be written that by default such and such domain is used, but if you want to change it, you can fix it through the environment variable.
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.
Commit: eb75627
package.json
Outdated
@@ -73,8 +73,10 @@ | |||
"@gravity-ui/icons": "^2.5.0", | |||
"@gravity-ui/page-constructor": "^5.22.0", | |||
"@gravity-ui/uikit": "^6.2.0", | |||
"@playwright/test": "^1.48.2", |
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.
dev dependency
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.
package.json
Outdated
"@popperjs/core": "^2.11.2", | ||
"bem-cn-lite": "4.1.0", | ||
"dotenv": "^16.4.5", |
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.
Also, it probably should be a development dependency.
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.
folder name for tests __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.
Commit: b9a1629
tests/MiniToc/MiniToc.spec.ts
Outdated
test.beforeEach(async ({page}) => { | ||
await page.goto(DOC_PAGE_URL); | ||
await page.waitForSelector(ROOT_ELEMENT_SELECTOR); | ||
}); |
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.
if you have repetitive actions before each test, then it is worth taking them out into a separate function for test setup in utils.ts
and reusing them
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.
Commit: b9bd607
workflows: ['CI'] | ||
types: | ||
- completed | ||
branches: [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.
master
Add webServer property in config. Before starting the tests playwright will run and wait for the launch of storybook dev server (if storybook is not running). Server URL is stored in .env file. Dotenv package needs for reading URL from .env.
Change "utils.ts" to "constants.ts". Combined URL variables in "DOC_PAGE_URL" variable. Change snapshot for DocPage test to correct image (for Chrome).
If .env file with 'BASE_URL' variable doesn't exist, playwright will use 'http://localhost:6006' as base URL
Dotenv package was used in playwright config only to get env variable (BASE_URL). Now config gets variable from tests/constants.ts file.
Change playwright to dev dependency. Remove dotenv
Rename files with snapshots to "__screenshots__"
Function waits for fonts to load
Add pr-visual-tests-report.yml for test report. Move downloading browser files in separate stage.
No description provided.