-
Notifications
You must be signed in to change notification settings - Fork 13.3k
docs(contributing): update screenshot commands and Docker usage #31441
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
Open
brandyscarney
wants to merge
2
commits into
main
Choose a base branch
from
docs/contributing-screenshots
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+113
−32
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -80,12 +80,14 @@ macOS uses [XQuartz](https://www.xquartz.org) to use XServer on macOS. | |
|
|
||
| 1. Install [Homebrew](https://brew.sh) if not already installed. You can run `brew --version` to check if Homebrew is installed. | ||
| 2. Install XQuartz: `brew install --cask xquartz` | ||
| 3. Open XQuartz, go to `Preferences > Security`, and check "Allow connections from network clients". | ||
| 3. Open XQuartz, go to `Settings → Security`, and check "Allow connections from network clients". | ||
| 4. Restart your computer. | ||
| 5. Start XQuartz from the command line: `xhost +localhost` | ||
| 6. Open Docker Desktop and edit settings to give access to `/tmp/.X11-unix` in `Preferences > Resources > File sharing`. | ||
| 7. In the `core` directory run `echo host.docker.internal:0 > docker-display.txt`. This information is used to set the `DISPLAY` environment variable which tells Playwright how to render a headed UI from the Docker container. | ||
| 8. In the `core` directory run `echo /tmp/.X11-unix:/tmp/.X11-unix > docker-display-volume.txt`. This information is used to make XServer available inside of the Docker container. | ||
| 6. In the `core` directory run `echo host.docker.internal:0 > docker-display.txt`. This information is used to set the `DISPLAY` environment variable which tells Playwright how to render a headed UI from the Docker container. | ||
| 7. In the `core` directory run `echo /tmp/.X11-unix:/tmp/.X11-unix > docker-display-volume.txt`. This information is used to make XServer available inside of the Docker container. | ||
|
|
||
| > [!NOTE] | ||
| > Unlike Docker Desktop, Rancher Desktop needs no file sharing configuration for this. It shares `/private/tmp` by default, which is where `/tmp` points on macOS. | ||
|
|
||
| #### Windows | ||
|
|
||
|
|
@@ -99,44 +101,58 @@ Windows has a native XServer called [WSLg](https://github.com/microsoft/wslg#rea | |
|
|
||
| ## Running Tests | ||
|
|
||
| ### Running All Test Files | ||
| Tests are run from the `core` directory with `npm run test.e2e.docker`, which runs them inside the Docker environment provided by the Ionic team through [Rancher Desktop](#installing-rancher-desktop). Any test that takes a screenshot must be run this way so that it compares against the ground truths committed to the repository. See [Managing Screenshots](#managing-screenshots) for more information. | ||
|
|
||
| All E2E tests can be run using the following command: | ||
| This command builds a Docker image before tests run. It will also re-build the Docker image in the event that a Playwright update was merged into the repo. | ||
|
|
||
| ```shell | ||
| npm run test.e2e | ||
| ``` | ||
| Note that the Playwright report will not automatically open in your web browser when tests are complete because the tests were run in Docker. Run `npx playwright show-report` outside of Docker to open the most recent test report. | ||
|
|
||
| > [!NOTE] | ||
| > This command is a wrapper for `npx playwright test`. All data passed to `npm run test.e2e` can also be passed to `npx playwright test`. | ||
| > Additional setup is needed to run Playwright tests with headed mode in Docker. See [Configuring Docker for Headed Tests](#configuring-docker-for-headed-tests-optional) for more information. | ||
|
|
||
| ### Running Specific Test Files | ||
|
|
||
| Specific test files can be run by passing the file paths or a directory that contains multiple test files. See [Managing Screenshots](#managing-screenshots) for generating ground truths before running screenshot tests. | ||
| Scope each run to the tests you are working on by passing file paths, a directory that contains multiple test files, or a component name. | ||
|
|
||
| **Specific Test Files** | ||
|
|
||
| ```shell | ||
| npm run test.e2e src/components/button/test/basic/button.e2e.ts src/components/button/test/a11y/button.e2e.ts | ||
| npm run test.e2e.docker src/components/button/test/basic/button.e2e.ts src/components/button/test/a11y/button.e2e.ts | ||
| ``` | ||
|
|
||
| **Test Directory with Multiple Files** | ||
|
|
||
| ```shell | ||
| # Will run all the test files in the `test` directory | ||
| npm run test.e2e src/components/button/test | ||
| npm run test.e2e.docker src/components/button/test | ||
| ``` | ||
|
|
||
| ### Running Tests Inside Docker | ||
| **Component Names** | ||
|
|
||
| While `npm run test.e2e` can be used to run tests in the same environment that you are developing in, `npm run test.e2e.docker` can be used to run tests in a Docker environment provided by the Ionic team through [Rancher Desktop](#installing-rancher-desktop). This command supports all the same features as `npm run test.e2e` detailed in the previous section. | ||
| The argument is a Playwright filter, so a bare component name matches every test file whose path contains it. | ||
|
|
||
| This command builds a Docker image before tests run. It will also re-build the Docker image in the event that a Playwright update was merged into the repo. | ||
| ```shell | ||
| npm run test.e2e.docker checkbox radio toggle | ||
| ``` | ||
|
|
||
| Note that the Playwright report will not automatically open in your web browser when tests are complete because the tests were run in Docker. Run `npx playwright show-report` outside of Docker to open the most recent test report. | ||
| ### Running All Test Files | ||
|
|
||
| Omitting the filter runs every E2E test file: | ||
|
|
||
| ```shell | ||
| npm run test.e2e.docker | ||
| ``` | ||
|
|
||
| There are over 400 E2E test files, which CI runs in parallel across 20 shards. A single machine runs them one shard at a time, so prefer scoping a local run to the component you changed and let CI cover the rest. | ||
|
|
||
| ### Running Tests Outside of Docker | ||
|
|
||
| `npm run test.e2e` runs the tests directly in the environment you are developing in. It accepts all of the same arguments as `npm run test.e2e.docker`. | ||
|
|
||
| > [!NOTE] | ||
| > Additional setup is needed to run Playwright tests with headed mode in Docker. See [Configuring Docker for Headed Tests](#configuring-docker-for-headed-tests-optional) for more information. | ||
| > This command is a wrapper for `npx playwright test`. All data passed to `npm run test.e2e` can also be passed to `npx playwright test`. | ||
|
|
||
| Use this only for tests that take no screenshots. Because screenshots are resolved per platform, a screenshot test run outside of Docker compares against a ground truth that is not in the repository. See [Managing Screenshots](#managing-screenshots) for why this passes locally and fails on CI. | ||
|
|
||
| ### Headed vs. Headless Tests | ||
|
|
||
|
|
@@ -146,14 +162,14 @@ No additional steps are needed in order to run the tests in headless mode: | |
|
|
||
| ```shell | ||
| # Will run tests in headless mode | ||
| npm run test.e2e src/components/chip | ||
| npm run test.e2e.docker src/components/chip | ||
| ``` | ||
|
|
||
| Playwright supports the `--headed` flag to run in headed mode which causes the visual representation of the browser to appear: | ||
|
|
||
| ```shell | ||
| # Will run tests in headed mode | ||
| npm run test.e2e src/components/chip -- --headed | ||
| npm run test.e2e.docker src/components/chip -- --headed | ||
| ``` | ||
|
|
||
| ### Debugging Tests | ||
|
|
@@ -205,11 +221,18 @@ This is especially useful when CI reports a failure you cannot reproduce on your | |
| **Example:** | ||
|
|
||
| ```shell | ||
| npm run test.e2e.docker.update-snapshots src/components/radio/test/a11y/radio.e2e.ts -- --repeat-each=10 | ||
| npm run test.e2e.docker src/components/radio/test/a11y/radio.e2e.ts -- --repeat-each=10 | ||
| ``` | ||
|
|
||
| This runs the test 10 times, increasing the chance of catching the flaky behavior. | ||
|
|
||
| > [!WARNING] | ||
| > Reproduce a flaky failure with `test.e2e.docker`, not | ||
| > `test.e2e.docker.update-snapshots`. On a mismatch the update variant overwrites | ||
| > the ground truth and reports the test as **passing**, so the run goes green with | ||
| > no diff images and the flaky screenshot is left in your working tree. Check | ||
| > `git status` if you suspect this happened. | ||
|
|
||
| #### 4. Pausing Test Execution | ||
|
|
||
| Additionally, you can pause execution of a test by using the `page.pause()` method. This pauses the script execution and allows you to manually inspect the page in the browser. | ||
|
|
@@ -238,6 +261,10 @@ test('example test', async ({ page }) => { | |
|
|
||
| If you are running a test that takes a screenshot, you must first generate the reference screenshot from your reference branch. This is known as generating a "ground truth screenshot". All other screenshots will be compared to this ground truth. | ||
|
|
||
| Playwright appends the browser and platform to every screenshot name, so the same test resolves a different file per operating system. Example: `button-expand-md-ltr-Mobile-Chrome-linux.png`. The ground truths committed to the repository are the `-linux.png` files generated in Docker, and `.gitignore` excludes every other platform's. | ||
|
|
||
| This is why screenshot tests should be run with `npm run test.e2e.docker`. Running them natively on macOS or Windows looks for a `-darwin.png` or `-win32.png` ground truth that is not in the repository. Playwright writes that file, fails the test once, and passes on every run afterward against a baseline that git ignores and CI never sees. The result is a test that passes locally and fails on CI. | ||
|
|
||
| ### Generating or Updating Ground Truths With Docker (Local Development) | ||
|
|
||
| We recommend generating ground truths inside of [Docker](https://www.docker.com) using [Rancher Desktop](#installing-rancher-desktop). This allows anyone contributing to Ionic Framework to create or update ground truths in a consistent environment. | ||
|
|
@@ -319,7 +346,7 @@ test-results-[current shard]-[total shards] | |
|
|
||
| Example: | ||
|
|
||
| test-results-2-5 --> Test results from job runner 2 out of 5. | ||
| test-results-2-5 -→ Test results from job runner 2 out of 5. | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looks weird with the first one being a dash then an arrow. |
||
| ``` | ||
|
|
||
| Download the appropriate artifact and unzip the file. | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
We should also add a link directly to Playwright so people can read more about it.