Skip to content
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: Bring accessibility up to 100% in Lighthouse check #606

Merged
merged 15 commits into from
Apr 3, 2023

Conversation

PGrad
Copy link
Contributor

@PGrad PGrad commented Apr 2, 2023

Fixes #438.

Abstract

There are two parts to this: fixing the outstanding accessibility issues that Lighthouse reports, and then adding Lighthouse to our CI to ensure that there are no regressions to accessibility in the future.

Fixing accessibility issues

client/src/
    - index.html
    - components/Header/Header.js
    - tests/__snapshots__/Header.test.js.snap
    
    pages/
        - NewTree/NewTreeButton.js
        - UserLocation/GeolocateControl.js

There were two types of errors. The first one has to do with some buttons not having a name which can be seen by screen readers. There are multiple ways to fix this, and my solution was to add a title attribute to the buttons. The side effect of this is that these buttons now also show tooltip text matching the title. @ri0nardo for reference, these are the buttons changed:

The Menu button:
Screen recording 2023-03-30 16.55.30.webm

the Geolocate button:
Screen recording 2023-03-30 16.54.58.webm

and the NewTreeButton:
Screen recording 2023-03-30 16.56.13.webm

Adding the title required updating the Header.test.js snapshot.

The other type of error was that zoom should be enabled on the map.

Adding Lighthouse to CI

lighthouserc.js
.github/workflows/lighthouse-ci.yaml
server/index.js

It's great to be able to fix these issues, but the only way you can make the fix last is to add regression testing. I accomplish this by adding Lighthouse to our CI pre-flight. The Lighthouse test will fail if the scores for accessibility or best practices are under 100, so future developers submitting PRs will need to make sure that their UI features meet the standards of Lighthouse. The best, recommended practice for Lighthouse CI is to require 100 from the SEO and PWA scores as well, as performance can give variable results, but fixing those issues is a whole separate issue of work.

To see the results of our Lighthouse runs in pre-flight, I installed the Lighthouse Github app and run the action with the LHCI_GITHUB_APP_TOKEN env variable. You should be seeing a status in the pre-flight with the Lighthouse scores and the icon below.

Actually getting the github action to work was quite difficult, mainly because Lighthouse needs to have chrome installed and the different solutions I tried to install Chrome didn't seem to work (using a docker image, using a github action) etc. In the end, just manually downloading the chrome .deb debian file worked best, although I fear pulling the .deb by wget could be flaky if it 404s.

I used nektos/act to test my github action locally, so I could get faster turn-around and not submit a hundred github commits just to test my github action. That approach has its limits too though, as the action would fail due to a PROTOCOL_TIMEOUT error that is apparently the #1 most common issue with Lighthouse.

Overall, I like that we can do automated testing with Lighthouse CI, but the tool seems a lot buggier than I would expect from Google devs. It's good enough.

PGrad added 11 commits March 30, 2023 13:44
Fix the errors reported by Lighthouse.
Added the Lighthouse CI config file.
I had to tweak the info message
server/index.js emits, because Lighthouse
needs to see something like "Listening on..."
to detect that the server has started.
Lighthouse CI should now run in
pre-flight. The scores for accessibility
and best practices need to be 100 for CI
to pass.
Adding a title for accessibility to Header
changed its test snapshot, so it had to be
updated.
Pull the latest version of @lhci/cli
at major version 11.
Some of the dev dependencies are needed
for the webpack build, so let's just
install everything.
Lighthouse needs chromium, but trying
to test its installation in a Github
action is exceedingly difficult even
with nektos/act. Let's see if this works.
Pulls in browserless/chrome docker image
to have chrome pre-installed. I'm having
a lot of trouble with the PROTOCOL_TIMEOUT
error during lhci autorun, which is still
unresolved by Lighthouse (it's the #1
issue on the GoogleChrome/lighthouse
repo).
I do not want to deal with git auth
in docker images.
Added the Lighthouse token so we
can see status checks. The
lighthouse github action I pulled
in has some issue with CHROME_PATH,
so I'm going back to running
lhci autorun by itself.
lighthouserc.js Outdated Show resolved Hide resolved
reviewify recommended I remove it,
so I did. The machines tell us
what to do now.
@PGrad PGrad marked this pull request as ready for review April 2, 2023 00:45
@PGrad PGrad requested a review from zoobot April 2, 2023 00:48
lighthouserc.js Show resolved Hide resolved
zoobot
zoobot approved these changes Apr 3, 2023
@zoobot zoobot merged commit 72bb94c into main Apr 3, 2023
@zoobot zoobot deleted the pgrad/test/lighthouse-accessibility-check branch April 3, 2023 04:25
zoobot added a commit that referenced this pull request Apr 5, 2023
* fix: resolve accessibility issues

Fix the errors reported by Lighthouse.

* test: Add Lighthouse CI locally

Added the Lighthouse CI config file.
I had to tweak the info message
server/index.js emits, because Lighthouse
needs to see something like "Listening on..."
to detect that the server has started.

* ci: Added Lighthouse CI github action

Lighthouse CI should now run in
pre-flight. The scores for accessibility
and best practices need to be 100 for CI
to pass.

* test: Update snapshots

Adding a title for accessibility to Header
changed its test snapshot, so it had to be
updated.

* fix: pull the right @lhci/cli version

Pull the latest version of @lhci/cli
at major version 11.

* fix: install all npm dependencies

Some of the dev dependencies are needed
for the webpack build, so let's just
install everything.

* fix: install chromium in github action

Lighthouse needs chromium, but trying
to test its installation in a Github
action is exceedingly difficult even
with nektos/act. Let's see if this works.

* test: Use a docker image for chrome

Pulls in browserless/chrome docker image
to have chrome pre-installed. I'm having
a lot of trouble with the PROTOCOL_TIMEOUT
error during lhci autorun, which is still
unresolved by Lighthouse (it's the #1
issue on the GoogleChrome/lighthouse
repo).

* test: just download chrome manually

I do not want to deal with git auth
in docker images.

* test: Add Lighthouse token

Added the Lighthouse token so we
can see status checks. The
lighthouse github action I pulled
in has some issue with CHROME_PATH,
so I'm going back to running
lhci autorun by itself.

* fix: remove disable-storage-reset

reviewify recommended I remove it,
so I did. The machines tell us
what to do now.

* test: Use latest github actions

---------

Co-authored-by: Rose <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Bring accessibility up to 100% in Lighthouse check
2 participants