Skip to content

Accessibility test Kitchen Sink with Playwright #1260

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

Merged
merged 56 commits into from
Apr 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
56 commits
Select commit Hold shift + click to select a range
e3ed101
Add core-js so dev build works
gabalafou Mar 20, 2023
a16cc88
add more pages, test server
gabalafou Mar 21, 2023
68079b2
add documentation
gabalafou Mar 21, 2023
5030606
add prerequisites to nox test
gabalafou Mar 21, 2023
423ed5d
update package-lock.json via stb
gabalafou Mar 21, 2023
de4e2dd
update package-lock.json via nox -s compile
gabalafou Mar 22, 2023
310f171
streamline, update docs
gabalafou Mar 22, 2023
09906c1
typo
gabalafou Mar 22, 2023
2480b00
sync lockfile (remove core-js)
gabalafou Mar 22, 2023
6f938ba
Update tests/utils.py
gabalafou Mar 27, 2023
b5b57ca
Update tests/README.md
gabalafou Mar 27, 2023
f47a60a
Update docs/community/topics/accessibility.md
gabalafou Mar 27, 2023
62b6ae7
Update tests/README.md
gabalafou Mar 27, 2023
fc04acf
Update tests/utils.py
gabalafou Mar 27, 2023
23be214
Update tests/utils.py
gabalafou Mar 27, 2023
66fac74
- nox session a11y
gabalafou Mar 28, 2023
bc311db
update docs
gabalafou Mar 28, 2023
94fb49f
Merge branch 'main' into playwright-a11y-test-kitchen-sink
gabalafou Mar 28, 2023
9436844
uncomment commented-out tests
gabalafou Mar 28, 2023
e5a8814
regenerate package-lock.json via:
gabalafou Mar 28, 2023
3f86b11
oops finish updating tests
gabalafou Mar 28, 2023
700b64a
do not include a11y tests in main test session
gabalafou Mar 28, 2023
c57011d
remove redundant decorator
gabalafou Mar 29, 2023
ced281d
Update tests/README.md
gabalafou Apr 12, 2023
33b10ac
Update tests/README.md
gabalafou Apr 12, 2023
f8cee2c
Update tests/README.md
gabalafou Apr 12, 2023
9df077a
Remove base-url Pytest plugin
gabalafou Apr 12, 2023
1c2b8d5
Update tests/utils/pretty_axe_results.py
gabalafou Apr 12, 2023
a4325f5
Apply suggestions from code review
gabalafou Apr 12, 2023
72dfedc
Merge branch 'main' into playwright-a11y-test-kitchen-sink
gabalafou Apr 12, 2023
f1c8007
fix pretty_axe_results
gabalafou Apr 12, 2023
0317729
Generate each test run from parameters
gabalafou Apr 12, 2023
744fc94
remove unused marker url_path
gabalafou Apr 12, 2023
5e06478
undo multiline
gabalafou Apr 12, 2023
6820864
update doc string
gabalafou Apr 12, 2023
419d9e8
Add CI check for --with-deps suggested by Tony
gabalafou Apr 12, 2023
c18dbd6
oops, rm extra playwright install line
gabalafou Apr 12, 2023
e63d3e7
update comment
gabalafou Apr 12, 2023
83af9ac
update docstring
gabalafou Apr 12, 2023
178a689
Merge remote-tracking branch 'upstream/main' into playwright-a11y-tes…
drammock Apr 12, 2023
f7b92ea
testing the pytest-axe mark
drammock Apr 12, 2023
926d426
run prettier
drammock Apr 12, 2023
49c15a9
Revert "testing the pytest-axe mark"
drammock Apr 12, 2023
036506b
Fix D104
drammock Apr 12, 2023
0f0d599
skip a11y tests on CI runs
drammock Apr 12, 2023
2176326
run a11y tests on one CI worker only
drammock Apr 12, 2023
ec6a9d7
:white_check_mark: Register a11y mark and separate dependencies
trallard Apr 14, 2023
452ef73
:construction_worker: Update CI - delegate playwright install and cache
trallard Apr 14, 2023
71a86ac
📝 Update test docs
trallard Apr 14, 2023
645202c
:white_check_mark: Ensure a11y tests are skipped unles called
trallard Apr 14, 2023
07b9566
:construction_worker: Ensure CI installs all deps
trallard Apr 14, 2023
19ccd1b
:rewind: Revert to installing playwright
trallard Apr 14, 2023
112a27a
:construction_worker: Forgot to re-add a11y deps
trallard Apr 14, 2023
00005d2
:pencil2: Fix typo
trallard Apr 14, 2023
b9d83f6
:wrench: Fix path - seems to have been messed up when moving things
trallard Apr 14, 2023
22953ed
Update tests/test_a11y.py
drammock Apr 14, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/prerelease.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ jobs:

- name: Check that there are no unexpected Sphinx warnings
if: matrix.python-version == '3.10'
run: python tests/check_warnings.py
run: python tests/utils/check_warnings.py

- name: Run the tests
run: |
Expand Down
23 changes: 21 additions & 2 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ jobs:
# windows test
- os: windows-latest
python-version: "3.11"
# needed to cache the browsers for the accessibility tests
env:
PLAYWRIGHT_BROWSERS_PATH: ${{ github.workspace }}/pw-browsers
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v3
Expand Down Expand Up @@ -90,14 +93,30 @@ jobs:
pip install nox
nox -s compile
- name: Run tests
run: pytest --color=yes --cov pydata_sphinx_theme --cov-branch --cov-report xml:cov.xml --cov-report= --cov-fail-under ${{ env.COVERAGE_THRESHOLD }}
run: pytest -m "not a11y" --color=yes --cov pydata_sphinx_theme --cov-branch --cov-report xml:cov.xml --cov-report= --cov-fail-under ${{ env.COVERAGE_THRESHOLD }}
- name: Upload to Codecov
if: matrix.python-version == '3.11' && matrix.os == 'ubuntu-latest'
uses: codecov/[email protected]
with:
files: cov.xml
fail_ci_if_error: true

# note I am setting this on top of the Python cache as I could not find
# how to set the hash key on the python one
- name: Set up browser cache (for accessibility tests)
uses: actions/cache@v3
with:
path: |
${{ github.workspace }}/pw-browsers
key: ${{ runner.os }}-pw-${{ hashFiles('pyproject.toml') }}
restore-keys: |
${{ runner.os }}-pw-

- name: Run accessibility tests with playwright
if: matrix.python-version == '3.11' && matrix.os == 'ubuntu-latest'
run: |
nox -s a11y

# Build our site on the 3 major OSes and check for Sphinx warnings
build-site:
needs: [lint]
Expand All @@ -124,7 +143,7 @@ jobs:
- name: Build docs
run: sphinx-build -b html docs/ docs/_build/html --keep-going -w warnings.txt
- name: Check for unexpected Sphinx warnings
run: python tests/check_warnings.py
run: python tests/utils/check_warnings.py

# Run local Lighthouse audit against built site
audit:
Expand Down
50 changes: 32 additions & 18 deletions docs/community/setup.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ The sections below cover the steps to do this in more detail.

## Clone the repository

First off you'll need your own copy of the `pydata-sphinx-theme` codebase.
First off you'll need your copy of the `pydata-sphinx-theme` codebase.
You can clone it for local development like so:

1. **Fork the repository** so you have your own copy on GitHub.
1. **Fork the repository**, so you have your own copy on GitHub.
See [the GitHub forking guide](https://docs.github.com/en/get-started/quickstart/fork-a-repo) for more information.
2. **Clone the repository locally** so that you have a local copy to work from:

Expand All @@ -36,14 +36,14 @@ You can clone it for local development like so:

## Install your tools

Building a Sphinx site uses a combination of Python and Jinja to manage HTML, SCSS, and Javascript.
Building a Sphinx site uses a combination of Python and Jinja to manage HTML, SCSS, and JavaScript.
To simplify this process, we use a few helper tools:

- [The Sphinx Theme Builder](https://sphinx-theme-builder.readthedocs.io/en/latest/) to automatically perform compilation of web assets.
- [The Sphinx Theme Builder](https://sphinx-theme-builder.readthedocs.io/en/latest/) compiles web assets in an automated way.
- [pre-commit](https://pre-commit.com/) for automatically enforcing code standards and quality checks before commits.
- [nox](https://nox.thea.codes/), for automating common development tasks.
- [nox](https://nox.thea.codes/) for automating common development tasks.

In particular, `nox` can be used to automatically create isolated local development environments with all of the correct packages installed to work on the theme.
In particular, `nox` can be used to automatically create isolated local development environments with all the correct packages installed to work on the theme.
The rest of this guide focuses on using `nox` to start with a basic environment.

```{seealso}
Expand All @@ -58,9 +58,9 @@ To start, install `nox`:
$ pip install nox
```

You can call `nox` from the command line in order to perform common actions that are needed in building the theme.
You can call `nox` from the command line to perform common actions that are needed in building the theme.
`nox` operates with isolated environments, so each action has its own packages installed in a local directory (`.nox`).
For common development actions, you'll simply need to use `nox` and won't need to set up any other packages.
For common development actions, you'll only need to use `nox` and won't need to set up any other packages.

### Setup `pre-commit`

Expand Down Expand Up @@ -116,7 +116,7 @@ Now that you've built the documentation, edit one of the source files to see how
1. **Make an edit to a page**. For example, add a word or fix a typo on any page.
2. **Rebuild the documentation** with `nox -s docs`

It should go much faster this time, because `nox` is re-using the old environment, and because Sphinx has cached the pages that you didn't change.
It should go much faster this time because `nox` is re-using the previously created environment, and because Sphinx has cached the pages that you didn't change.

## Compile the CSS/JS assets

Expand All @@ -138,15 +138,15 @@ The `sphinx-theme-builder` will bundle these assets automatically when we make a

## Run a development server

You can combine the above two actions and run a development server so that changes to `src/` are automatically bundled with the package, and the documentation is immediately reloaded in a live preview window.
You can combine the above two actions (build the docs and compile JS/CSS assets) and run a development server so that changes to `src/` are automatically bundled with the package, and the documentation is immediately reloaded in a live preview window.

To run the development server with `nox`, run the following command:

```console
$ nox -s docs-live
```

When working on the theme, saving changes to any of these directories:
When working on the theme, making changes to any of these directories:

- `src/js/index.js`
- `src/scss/index.scss`
Expand All @@ -161,19 +161,33 @@ will cause the development server to do the following:

## Run the tests

This theme uses `pytest` for its testing, with a lightweight fixture defined
in the `test_build.py` script that makes it easy to run a Sphinx build using
this theme and inspect the results.
This theme uses `pytest` for its testing. There is a lightweight fixture defined
in the `test_build.py` script that makes it straightforward to run a Sphinx build using
this theme and inspect the results. There are also several automated accessibility checks in
`test_a11y.py`.

In addition, we use [pytest-regressions](https://pytest-regressions.readthedocs.io/en/latest/)
to ensure that the HTML generated by the theme is what we'd expect. This module
```{warning}
Currently, the automated accessibility tests check the Kitchen Sink page only.
We are working on extending coverage to the rest of the theme.
```

In addition, we use
[pytest-regressions](https://pytest-regressions.readthedocs.io/en/latest/) to
ensure that the HTML generated by the theme is what we'd expect. This module
provides a `file_regression` fixture that will check the contents of an object
against a reference file on disk. If the structure of the two differs, then the
test will fail. If we _expect_ the structure to differ, then delete the file on
disk and run the test. A new file will be created, and subsequent tests will pass.
disk and run the test. A new file will be created, and subsequent tests will
pass.

To run the tests with `nox`, run the following command:
To run the build tests with `nox`, run the following command:

```console
$ nox -s test
```

To run the accessibility checks:

```console
$ nox -s a11y
```
17 changes: 12 additions & 5 deletions docs/community/topics/accessibility.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
# Accessibility checks

The accessibility checking tools can find a number of common HTML patterns which
```{note}
April-2023: we are currently
[re-evaluating how we do accessibility checks](https://github.com/pydata/pydata-sphinx-theme/issues/1168)
and reporting, so this may change soon.
```

In general, accessibility-checking tools can find a limited number of common HTML patterns which
assistive technology can't help users understand.
We run a [Lighthouse](https://developers.google.com/web/tools/lighthouse) job in our CI/CD, which generates a "score" for all pages in our **Kitchen Sink** example documentation.
The configuration for Lighthouse is in:

- `.github/workflows/lighthouserc.json`
## Accessibility checks as part of our development process

We run a [Lighthouse](https://developers.google.com/web/tools/lighthouse) job in our CI/CD, which generates a "score" for all pages in our **Kitchen Sink** example documentation.
The configuration for Lighthouse can be found in the `.github/workflows/lighthouserc.json` file.

For more information about configuring lighthouse, see [the lighthouse documentation](https://github.com/GoogleChrome/lighthouse-ci/blob/main/docs/configuration.md).
For more information about configuring Lighthouse, see [the Lighthouse documentation](https://github.com/GoogleChrome/lighthouse-ci/blob/main/docs/configuration.md).
For more information about Accessibility in general, see [](../../user_guide/accessibility.rst).
24 changes: 23 additions & 1 deletion noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

nox -s docs -- -r
"""
import os
import shutil as sh
import tempfile
from pathlib import Path
Expand Down Expand Up @@ -87,7 +88,28 @@ def test(session: nox.Session) -> None:
if _should_install(session):
session.install("-e", ".[test]")
session.run(*split("pybabel compile -d src/pydata_sphinx_theme/locale -D sphinx"))
session.run("pytest", *session.posargs)
session.run("pytest", "-m", "not a11y", *session.posargs)


@nox.session()
def a11y(session: nox.Session) -> None:
"""Run the accessibility test suite only."""
if _should_install(session):
session.install("-e", ".[test, a11y]")
# Install the drivers that Playwright needs to control the browsers.
if os.environ.get("CI") or os.environ.get("GITPOD_WORKSPACE_ID"):
# CI and other cloud environments are potentially missing system
# dependencies, so we tell Playwright to also install the system
# dependencies
session.run("playwright", "install", "--with-deps")
Comment on lines +100 to +104
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had initially removed this until I had to update the CI tests and realised I duplicated a lot of code trying to use pytest directly like in other tests.
So, for now, I am leaving this here and calling tests through nox.

Note: I am unsure if we should keep the GITPOD_WORKSPACE_ID bit. I am a Gitpod user, but I wonder if it will confuse the rest of the folks who do not use Gitpod.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I hadn't heard of Gitpod, but I wasn't confused :) I figured "probably some containerized thing" (I've since looked it up).

else:
# But most dev environments have the needed system dependencies
session.run("playwright", "install")
# Build the docs so we can run accessibility tests against them.
session.run("nox", "-s", "docs")
# The next step would be to open a server to the docs for Playwright, but
# that is done in the test file, along with the accessibility checks.
session.run("pytest", "-m", "a11y", *session.posargs)


@nox.session(name="test-sphinx")
Expand Down
56 changes: 38 additions & 18 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"build": "webpack"
},
"devDependencies": {
"axe-core": "^4.6.3",
"copy-webpack-plugin": "^11.0.0",
"css-loader": "^3.4.2",
"css-minimizer-webpack-plugin": "^4.2.2",
Expand Down
Loading