-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add visual regression tests with Playwright (#345)
Closes #208. ## How snapshots work Playwright snapshot tests take screenshots of certain portions of our site, such as the footer. They save that screenshot to Git, so that we all have the exact copy. Then, for every PR, our tests will retake a new screenshot and make sure it's the exact same as before. That way, we always know when we make a change. When there was a change, Playwright will output this: ![Screenshot 2023-05-26 at 12 09 19 PM](https://github.com/Qiskit/qiskit_sphinx_theme/assets/14852634/a5157d1d-f9de-4e0a-a93b-93c413dba848) As stated there, Playwright will generate a before, after, and diff photo. In CI, we upload those as GitHub artifacts. If the change was intentional, then the author copies the updated screenshot to overwrite the old file. ## Uses Docker for consistency Websites render slightly differently between operating systems, e.g. Linux and macOS. Naively, this would cause visual regression tests to fail when running the tests locally on a mac. So, we use Docker to make sure we always use the same environment. If users don't want to run Docker locally, they can rely on CI to get the updated snapshots via GitHub Actions Artifacts. More advanced users can also run the tests locally. They need to install Docker and have the Docker daemon running. But otherwise, our scripts automate everything. They don't need to know how to use Docker. They only need to run `npm test`. ## How to run locally (Reminder that contributors can rely on CI for visual regression testing.) The user has to first build the docs with `THEME=_qiskit_furo tox -e docs`. Then, they only run `npm test` (after originally running `npm install` & starting Docker). Playwright will start up a server for us. If the user changed the theme, they must rebuild the docs with Tox. ## Switches from Jest to Playwright I originally tried doing this change via Jest, a common JavaScript test runner. But I had major issues getting the browser automation library Puppeteer #341 to work properly on my M1. So, this changes our test runner to [Playwright](https://playwright.dev), a test runner from Microsoft optimized for visual regression testing like we're doing. It can do things like click buttons, e.g. our Translations menu. ## Only Furo To keep things simple, this only adds infrastructure to snapshot test Furo. Given that our goal is to migrate ASAP, this seemed okay to me.
- Loading branch information
1 parent
887b3af
commit f5b9bbc
Showing
11 changed files
with
440 additions
and
2,999 deletions.
There are no files selected for viewing
This file contains 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 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 |
---|---|---|
|
@@ -133,3 +133,4 @@ dmypy.json | |
|
||
# JavaScript | ||
/node_modules | ||
/snapshot_results |
This file contains 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 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
Oops, something went wrong.